Skip to content

Commit

Permalink
Don't use true and false to generate two different keys
Browse files Browse the repository at this point in the history
  • Loading branch information
weichweich committed Aug 31, 2023
1 parent 1969966 commit f5cba9b
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 232 deletions.
4 changes: 2 additions & 2 deletions pallets/did/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ benchmarks! {
where
T::DidIdentifier: From<AccountId32>,
<T as frame_system::Config>::RuntimeOrigin: From<RawOrigin<T::DidIdentifier>>,
<T as frame_system::Config>::AccountId: From<AccountId32>,
<T as Config>::Currency: Mutate<T::AccountId>
<T as frame_system::Config>::AccountId: From<AccountId32> + AsRef<[u8]> + AsRef<[u8;32]> + From<[u8; 32]>,
<T as Config>::Currency: Mutate<T::AccountId>,
}

/* create extrinsic */
Expand Down
96 changes: 28 additions & 68 deletions pallets/did/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ pub(crate) const ACCOUNT_00: AccountId = AccountId::new([1u8; 32]);
pub(crate) const ACCOUNT_01: AccountId = AccountId::new([2u8; 32]);
pub(crate) const ACCOUNT_FEE: AccountId = AccountId::new([u8::MAX; 32]);

const DEFAULT_AUTH_SEED: [u8; 32] = [4u8; 32];
const ALTERNATIVE_AUTH_SEED: [u8; 32] = [40u8; 32];
const DEFAULT_ENC_SEED: [u8; 32] = [254u8; 32];
const ALTERNATIVE_ENC_SEED: [u8; 32] = [255u8; 32];
const DEFAULT_ATT_SEED: [u8; 32] = [6u8; 32];
const ALTERNATIVE_ATT_SEED: [u8; 32] = [60u8; 32];
const DEFAULT_DEL_SEED: [u8; 32] = [7u8; 32];
const ALTERNATIVE_DEL_SEED: [u8; 32] = [70u8; 32];
pub(crate) const AUTH_SEED_0: [u8; 32] = [4u8; 32];
pub(crate) const AUTH_SEED_1: [u8; 32] = [40u8; 32];
pub(crate) const ENC_SEED_0: [u8; 32] = [254u8; 32];
pub(crate) const ENC_SEED_1: [u8; 32] = [255u8; 32];
pub(crate) const ATT_SEED_0: [u8; 32] = [6u8; 32];
pub(crate) const ATT_SEED_1: [u8; 32] = [60u8; 32];
pub(crate) const DEL_SEED_0: [u8; 32] = [7u8; 32];
pub(crate) const DEL_SEED_1: [u8; 32] = [70u8; 32];

/// Solely used to fill public keys in unit tests to check for correct error
/// throws. Thus, it does not matter whether the correct key types get added
Expand Down Expand Up @@ -269,84 +269,44 @@ pub fn get_did_identifier_from_ecdsa_key(public_key: ecdsa::Public) -> DidIdenti
MultiSigner::from(public_key).into_account()
}

pub fn get_ed25519_authentication_key(default: bool) -> ed25519::Pair {
if default {
ed25519::Pair::from_seed(&DEFAULT_AUTH_SEED)
} else {
ed25519::Pair::from_seed(&ALTERNATIVE_AUTH_SEED)
}
pub fn get_ed25519_authentication_key(seed: &[u8; 32]) -> ed25519::Pair {
ed25519::Pair::from_seed(seed)
}

pub fn get_sr25519_authentication_key(default: bool) -> sr25519::Pair {
if default {
sr25519::Pair::from_seed(&DEFAULT_AUTH_SEED)
} else {
sr25519::Pair::from_seed(&ALTERNATIVE_AUTH_SEED)
}
pub fn get_sr25519_authentication_key(seed: &[u8; 32]) -> sr25519::Pair {
sr25519::Pair::from_seed(seed)
}

pub fn get_ecdsa_authentication_key(default: bool) -> ecdsa::Pair {
if default {
ecdsa::Pair::from_seed(&DEFAULT_AUTH_SEED)
} else {
ecdsa::Pair::from_seed(&ALTERNATIVE_AUTH_SEED)
}
pub fn get_ecdsa_authentication_key(seed: &[u8; 32]) -> ecdsa::Pair {
ecdsa::Pair::from_seed(seed)
}

pub fn get_x25519_encryption_key(default: bool) -> DidEncryptionKey {
if default {
DidEncryptionKey::X25519(DEFAULT_ENC_SEED)
} else {
DidEncryptionKey::X25519(ALTERNATIVE_ENC_SEED)
}
pub fn get_x25519_encryption_key(seed: &[u8; 32]) -> DidEncryptionKey {
DidEncryptionKey::X25519(*seed)
}

pub fn get_ed25519_attestation_key(default: bool) -> ed25519::Pair {
if default {
ed25519::Pair::from_seed(&DEFAULT_ATT_SEED)
} else {
ed25519::Pair::from_seed(&ALTERNATIVE_ATT_SEED)
}
pub fn get_ed25519_attestation_key(seed: &[u8; 32]) -> ed25519::Pair {
ed25519::Pair::from_seed(seed)
}

pub fn get_sr25519_attestation_key(default: bool) -> sr25519::Pair {
if default {
sr25519::Pair::from_seed(&DEFAULT_ATT_SEED)
} else {
sr25519::Pair::from_seed(&ALTERNATIVE_ATT_SEED)
}
pub fn get_sr25519_attestation_key(seed: &[u8; 32]) -> sr25519::Pair {
sr25519::Pair::from_seed(seed)
}

pub fn get_ecdsa_attestation_key(default: bool) -> ecdsa::Pair {
if default {
ecdsa::Pair::from_seed(&DEFAULT_ATT_SEED)
} else {
ecdsa::Pair::from_seed(&ALTERNATIVE_ATT_SEED)
}
pub fn get_ecdsa_attestation_key(seed: &[u8; 32]) -> ecdsa::Pair {
ecdsa::Pair::from_seed(seed)
}

pub fn get_ed25519_delegation_key(default: bool) -> ed25519::Pair {
if default {
ed25519::Pair::from_seed(&DEFAULT_DEL_SEED)
} else {
ed25519::Pair::from_seed(&ALTERNATIVE_DEL_SEED)
}
pub fn get_ed25519_delegation_key(seed: &[u8; 32]) -> ed25519::Pair {
ed25519::Pair::from_seed(seed)
}

pub fn get_sr25519_delegation_key(default: bool) -> sr25519::Pair {
if default {
sr25519::Pair::from_seed(&DEFAULT_DEL_SEED)
} else {
sr25519::Pair::from_seed(&ALTERNATIVE_DEL_SEED)
}
pub fn get_sr25519_delegation_key(seed: &[u8; 32]) -> sr25519::Pair {
sr25519::Pair::from_seed(seed)
}

pub fn get_ecdsa_delegation_key(default: bool) -> ecdsa::Pair {
if default {
ecdsa::Pair::from_seed(&DEFAULT_DEL_SEED)
} else {
ecdsa::Pair::from_seed(&ALTERNATIVE_DEL_SEED)
}
pub fn get_ecdsa_delegation_key(seed: &[u8; 32]) -> ecdsa::Pair {
ecdsa::Pair::from_seed(seed)
}

pub fn generate_key_id(key: &DidPublicKey<AccountId>) -> KeyIdOf<Test> {
Expand Down
Loading

0 comments on commit f5cba9b

Please sign in to comment.