Skip to content

Commit

Permalink
Rename and reorder functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgardo committed Mar 8, 2024
1 parent 18ff9a7 commit 19bc9c7
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 75 deletions.
50 changes: 25 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,99 +31,99 @@ pub enum ConcordiumWalletCryptoError {
CallFailed { call: String, msg: String },
}

pub fn account_credential_signing_key_hex(
pub fn identity_cred_sec_hex(
seed_hex: String,
net: String,
identity_provider_index: u32,
identity_index: u32,
credential_counter: u32,
) -> Result<String, ConcordiumWalletCryptoError> {
get_account_signing_key_aux(seed_hex, net.as_str(), identity_provider_index, identity_index, credential_counter)
get_id_cred_sec_aux(seed_hex, net.as_str(), identity_provider_index, identity_index)
.map_err(|e| ConcordiumWalletCryptoError::CallFailed {
call: format!("account_credential_signing_key_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index}, credential_counter={credential_counter})"),
call: format!("identity_cred_sec_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index})"),
msg: format!("{:#}", e),
})
}

pub fn account_credential_public_key_hex(
pub fn identity_prf_key_hex(
seed_hex: String,
net: String,
identity_provider_index: u32,
identity_index: u32,
credential_counter: u32,
) -> Result<String, ConcordiumWalletCryptoError> {
get_account_public_key_aux(seed_hex, net.as_str(), identity_provider_index, identity_index, credential_counter)
get_prf_key_aux(seed_hex, net.as_str(), identity_provider_index, identity_index)
.map_err(|e| ConcordiumWalletCryptoError::CallFailed {
call: format!("account_credential_public_key_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index}, credential_counter={credential_counter})"),
call: format!("identity_prf_key_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index})"),
msg: format!("{:#}", e),
})
}

pub fn id_cred_sec_hex(
pub fn identity_attributes_signature_blinding_randomness_hex(
seed_hex: String,
net: String,
identity_provider_index: u32,
identity_index: u32,
) -> Result<String, ConcordiumWalletCryptoError> {
get_id_cred_sec_aux(seed_hex, net.as_str(), identity_provider_index, identity_index)
get_signature_blinding_randomness_aux(seed_hex, net.as_str(), identity_provider_index, identity_index)
.map_err(|e| ConcordiumWalletCryptoError::CallFailed {
call: format!("id_cred_sec_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index})"),
call: format!("identity_attributes_signature_blinding_randomness_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index})"),
msg: format!("{:#}", e),
})
}

pub fn prf_key_hex(
pub fn account_credential_signing_key_hex(
seed_hex: String,
net: String,
identity_provider_index: u32,
identity_index: u32,
credential_counter: u8,
) -> Result<String, ConcordiumWalletCryptoError> {
get_prf_key_aux(seed_hex, net.as_str(), identity_provider_index, identity_index)
get_account_signing_key_aux(seed_hex, net.as_str(), identity_provider_index, identity_index, credential_counter.into())
.map_err(|e| ConcordiumWalletCryptoError::CallFailed {
call: format!("prf_key_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index})"),
call: format!("account_credential_signing_key_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index}, credential_counter={credential_counter})"),
msg: format!("{:#}", e),
})
}

pub fn account_credential_id_hex(
pub fn account_credential_public_key_hex(
seed_hex: String,
net: String,
identity_provider_index: u32,
identity_index: u32,
credential_counter: u8,
commitment_key: String,
) -> Result<String, ConcordiumWalletCryptoError> {
get_credential_id_aux(seed_hex, net.as_str(), identity_provider_index, identity_index, credential_counter, commitment_key.as_str())
get_account_public_key_aux(seed_hex, net.as_str(), identity_provider_index, identity_index, credential_counter.into())
.map_err(|e| ConcordiumWalletCryptoError::CallFailed {
call: format!("account_credential_id_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index}, credential_counter={credential_counter}, commitment_key={commitment_key})"),
call: format!("account_credential_public_key_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index}, credential_counter={credential_counter})"),
msg: format!("{:#}", e),
})
}

pub fn signature_blinding_randomness_hex(
pub fn account_credential_id_hex(
seed_hex: String,
net: String,
identity_provider_index: u32,
identity_index: u32,
credential_counter: u8,
commitment_key: String,
) -> Result<String, ConcordiumWalletCryptoError> {
get_signature_blinding_randomness_aux(seed_hex, net.as_str(), identity_provider_index, identity_index)
get_credential_id_aux(seed_hex, net.as_str(), identity_provider_index, identity_index, credential_counter, commitment_key.as_str())
.map_err(|e| ConcordiumWalletCryptoError::CallFailed {
call: format!("signature_blinding_randomness_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index})"),
call: format!("account_credential_id_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index}, credential_counter={credential_counter}, commitment_key={commitment_key})"),
msg: format!("{:#}", e),
})
}

pub fn attribute_commitment_randomness_hex(
pub fn account_credential_attribute_commitment_randomness_hex(
seed_hex: String,
net: String,
identity_provider_index: u32,
identity_index: u32,
credential_counter: u32,
credential_counter: u8,
attribute: u8,
) -> Result<String, ConcordiumWalletCryptoError> {
get_attribute_commitment_randomness_aux(seed_hex, net.as_str(), identity_provider_index, identity_index, credential_counter, attribute)
get_attribute_commitment_randomness_aux(seed_hex, net.as_str(), identity_provider_index, identity_index, credential_counter.into(), attribute)
.map_err(|e| ConcordiumWalletCryptoError::CallFailed {
call: format!("attribute_commitment_randomness_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index}, credential_counter={credential_counter}, attribute={attribute})"),
call: format!("account_credential_attribute_commitment_randomness_hex(seed_hex, net={net}, identity_provider_index={identity_provider_index}, identity_index={identity_index}, credential_counter={credential_counter}, attribute={attribute})"),
msg: format!("{:#}", e),
})
}
Expand Down
17 changes: 10 additions & 7 deletions src/lib.udl
Original file line number Diff line number Diff line change
Expand Up @@ -157,29 +157,32 @@ dictionary SignedAccountCredential {

namespace crypto {
[Throws=ConcordiumWalletCryptoError]
string account_credential_signing_key_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index, u32 credential_counter);
string identity_cred_sec_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index);
[Throws=ConcordiumWalletCryptoError]
string account_credential_public_key_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index, u32 credential_counter);
string identity_prf_key_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index);
[Throws=ConcordiumWalletCryptoError]
string id_cred_sec_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index);
string identity_attributes_signature_blinding_randomness_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index);
[Throws=ConcordiumWalletCryptoError]
string prf_key_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index);
string account_credential_signing_key_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index, u8 credential_counter);
[Throws=ConcordiumWalletCryptoError]
string account_credential_id_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index, u8 credential_counter, string commitment_key);
string account_credential_public_key_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index, u8 credential_counter);
[Throws=ConcordiumWalletCryptoError]
string signature_blinding_randomness_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index);
string account_credential_id_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index, u8 credential_counter, string commitment_key);
[Throws=ConcordiumWalletCryptoError]
string attribute_commitment_randomness_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index, u32 credential_counter, u8 attribute);
string account_credential_attribute_commitment_randomness_hex(string seed_hex, string network, u32 identity_provider_index, u32 identity_index, u8 credential_counter, u8 attribute);

[Throws=ConcordiumWalletCryptoError]
string verifiable_credential_signing_key_hex(string seed_hex, string network, u64 issuer_index, u64 issuer_subindex, u32 verifiable_credential_index);
[Throws=ConcordiumWalletCryptoError]
string verifiable_credential_public_key_hex(string seed_hex, string network, u64 issuer_index, u64 issuer_subindex, u32 verifiable_credential_index);
[Throws=ConcordiumWalletCryptoError]
string verifiable_credential_backup_encryption_key_hex(string seed_hex, string network);

[Throws=ConcordiumWalletCryptoError]
string identity_issuance_request_json(IdentityIssuanceRequestParameters params);
[Throws=ConcordiumWalletCryptoError]
string identity_recovery_request_json(IdentityRecoveryRequestParameters params);

[Throws=ConcordiumWalletCryptoError]
AccountCredentialResult account_credential(AccountCredentialParameters params);
[Throws=ConcordiumWalletCryptoError]
Expand Down
114 changes: 71 additions & 43 deletions tests/lib_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,50 @@ const COMMITMENT_KEY: &str = "b14cbfe44a02c6b1f78711176d5f437295367aa4f2a8c2551e
*/

#[test]
fn mainnet_account_credential_signing_key() {
fn mainnet_identity_cred_sec() {
assert_eq!(
account_credential_signing_key_hex(SEED.to_string(), MAINNET.to_string(), 0, 55, 7)
.unwrap(),
"e4d1693c86eb9438feb9cbc3d561fbd9299e3a8b3a676eb2483b135f8dbf6eb1"
identity_cred_sec_hex(SEED.to_string(), MAINNET.to_string(), 2, 115).unwrap(),
"33b9d19b2496f59ed853eb93b9d374482d2e03dd0a12e7807929d6ee54781bb1"
);
}

#[test]
fn mainnet_account_credential_public_key() {
fn mainnet_identity_prf_key() {
assert_eq!(
account_credential_public_key_hex(SEED.to_string(), MAINNET.to_string(), 1, 341, 9)
identity_prf_key_hex(SEED.to_string(), MAINNET.to_string(), 3, 35).unwrap(),
"4409e2e4acffeae641456b5f7406ecf3e1e8bd3472e2df67a9f1e8574f211bc5"
);
}

#[test]
fn mainnet_attributes_signature_blinding_randomness() {
assert_eq!(
identity_attributes_signature_blinding_randomness_hex(
SEED.to_string(),
MAINNET.to_string(),
4,
5713
)
.unwrap(),
"d54aab7218fc683cbd4d822f7c2b4e7406c41ae08913012fab0fa992fa008e98"
"1e3633af2b1dbe5600becfea0324bae1f4fa29f90bdf419f6fba1ff520cb3167"
);
}

#[test]
fn mainnet_id_cred_sec() {
fn mainnet_account_credential_signing_key() {
assert_eq!(
id_cred_sec_hex(SEED.to_string(), MAINNET.to_string(), 2, 115).unwrap(),
"33b9d19b2496f59ed853eb93b9d374482d2e03dd0a12e7807929d6ee54781bb1"
account_credential_signing_key_hex(SEED.to_string(), MAINNET.to_string(), 0, 55, 7)
.unwrap(),
"e4d1693c86eb9438feb9cbc3d561fbd9299e3a8b3a676eb2483b135f8dbf6eb1"
);
}

#[test]
fn mainnet_prf_key() {
fn mainnet_account_credential_public_key() {
assert_eq!(
prf_key_hex(SEED.to_string(), MAINNET.to_string(), 3, 35).unwrap(),
"4409e2e4acffeae641456b5f7406ecf3e1e8bd3472e2df67a9f1e8574f211bc5"
account_credential_public_key_hex(SEED.to_string(), MAINNET.to_string(), 1, 341, 9)
.unwrap(),
"d54aab7218fc683cbd4d822f7c2b4e7406c41ae08913012fab0fa992fa008e98"
);
}

Expand All @@ -58,53 +72,66 @@ fn mainnet_account_credential_id() {
}

#[test]
fn mainnet_signature_blinding_randomness() {
fn mainnet_account_credential_attribute_commitment_randomness() {
assert_eq!(
signature_blinding_randomness_hex(SEED.to_string(), MAINNET.to_string(), 4, 5713).unwrap(),
"1e3633af2b1dbe5600becfea0324bae1f4fa29f90bdf419f6fba1ff520cb3167"
account_credential_attribute_commitment_randomness_hex(
SEED.to_string(),
MAINNET.to_string(),
5,
0,
4,
0
)
.unwrap(),
"6ef6ba6490fa37cd517d2b89a12b77edf756f89df5e6f5597440630cd4580b8f"
);
}

#[test]
fn mainnet_attribute_commitment_randomness() {
fn testnet_identity_cred_sec() {
assert_eq!(
attribute_commitment_randomness_hex(SEED.to_string(), MAINNET.to_string(), 5, 0, 4, 0)
.unwrap(),
"6ef6ba6490fa37cd517d2b89a12b77edf756f89df5e6f5597440630cd4580b8f"
identity_cred_sec_hex(SEED.to_string(), TESTNET.to_string(), 2, 115).unwrap(),
"33c9c538e362c5ac836afc08210f4b5d881ba65a0a45b7e353586dad0a0f56df"
);
}

#[test]
fn testnet_account_credential_signing_key() {
fn testnet_identity_prf_key() {
assert_eq!(
account_credential_signing_key_hex(SEED.to_string(), TESTNET.to_string(), 0, 55, 7)
.unwrap(),
"aff97882c6df085e91ae2695a32d39dccb8f4b8d68d2f0db9637c3a95f845e3c"
identity_prf_key_hex(SEED.to_string(), TESTNET.to_string(), 3, 35).unwrap(),
"41d794d0b06a7a31fb79bb76c44e6b87c63e78f9afe8a772fc64d20f3d9e8e82"
);
}

#[test]
fn testnet_account_credential_public_key() {
fn testnet_attributes_signature_blinding_randomness() {
assert_eq!(
account_credential_public_key_hex(SEED.to_string(), TESTNET.to_string(), 1, 341, 9)
identity_attributes_signature_blinding_randomness_hex(
SEED.to_string(),
TESTNET.to_string(),
4,
5713
)
.unwrap(),
"ef6fd561ca0291a57cdfee896245db9803a86da74c9a6c1bf0252b18f8033003"
"079eb7fe4a2e89007f411ede031543bd7f687d50341a5596e015c9f2f4c1f39b"
);
}

#[test]
fn testnet_id_cred_sec() {
fn testnet_account_credential_signing_key() {
assert_eq!(
id_cred_sec_hex(SEED.to_string(), TESTNET.to_string(), 2, 115).unwrap(),
"33c9c538e362c5ac836afc08210f4b5d881ba65a0a45b7e353586dad0a0f56df"
account_credential_signing_key_hex(SEED.to_string(), TESTNET.to_string(), 0, 55, 7)
.unwrap(),
"aff97882c6df085e91ae2695a32d39dccb8f4b8d68d2f0db9637c3a95f845e3c"
);
}

#[test]
fn testnet_prf_key() {
fn testnet_account_credential_public_key() {
assert_eq!(
prf_key_hex(SEED.to_string(), TESTNET.to_string(), 3, 35).unwrap(),
"41d794d0b06a7a31fb79bb76c44e6b87c63e78f9afe8a772fc64d20f3d9e8e82"
account_credential_public_key_hex(SEED.to_string(), TESTNET.to_string(), 1, 341, 9)
.unwrap(),
"ef6fd561ca0291a57cdfee896245db9803a86da74c9a6c1bf0252b18f8033003"
);
}

Expand All @@ -116,23 +143,24 @@ fn testnet_account_credential_id() {
);
}

#[test]
fn testnet_signature_blinding_randomness() {
assert_eq!(
signature_blinding_randomness_hex(SEED.to_string(), TESTNET.to_string(), 4, 5713).unwrap(),
"079eb7fe4a2e89007f411ede031543bd7f687d50341a5596e015c9f2f4c1f39b"
);
}

#[test]
fn testnet_attribute_commitment_randomness() {
assert_eq!(
attribute_commitment_randomness_hex(SEED.to_string(), TESTNET.to_string(), 5, 0, 4, 0)
.unwrap(),
account_credential_attribute_commitment_randomness_hex(
SEED.to_string(),
TESTNET.to_string(),
5,
0,
4,
0
)
.unwrap(),
"409fa90314ec8fb4a2ae812fd77fe58bfac81765cad3990478ff7a73ba6d88ae"
);
}

/* Verifiable credentials tests. */

#[test]
fn mainnet_verifiable_credential_signing_key() {
assert_eq!(
Expand Down

0 comments on commit 19bc9c7

Please sign in to comment.