diff --git a/crates/cdk/src/nuts/nut01/mod.rs b/crates/cdk/src/nuts/nut01/mod.rs index 649e1ed9..c23f7936 100644 --- a/crates/cdk/src/nuts/nut01/mod.rs +++ b/crates/cdk/src/nuts/nut01/mod.rs @@ -37,16 +37,20 @@ pub enum Error { }, } -/// Mint Keys [NUT-01] +/// Mint public keys per amount. +/// +/// This is a variation of [MintKeys] that only exposes the public keys. +/// +/// See [NUT-01] #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] -pub struct Keys(BTreeMap); +pub struct Keys(BTreeMap); impl From for Keys { fn from(keys: MintKeys) -> Self { Self( keys.0 - .iter() - .map(|(amount, keypair)| (amount.to_string(), keypair.public_key)) + .into_iter() + .map(|(amount, keypair)| (amount, keypair.public_key)) .collect(), ) } @@ -55,25 +59,25 @@ impl From for Keys { impl Keys { /// Create new [`Keys`] #[inline] - pub fn new(keys: BTreeMap) -> Self { + pub fn new(keys: BTreeMap) -> Self { Self(keys) } /// Get [`Keys`] #[inline] - pub fn keys(&self) -> &BTreeMap { + pub fn keys(&self) -> &BTreeMap { &self.0 } /// Get [`PublicKey`] for [`Amount`] #[inline] pub fn amount_key(&self, amount: Amount) -> Option { - self.0.get(&amount.to_string()).copied() + self.0.get(&amount).copied() } /// Iterate through the (`Amount`, `PublicKey`) entries in the Map #[inline] - pub fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator { self.0.iter() } } @@ -87,7 +91,7 @@ pub struct KeysResponse { pub keysets: Vec, } -/// Mint keys +/// Mint key pairs per amount #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct MintKeys(BTreeMap); diff --git a/crates/cdk/src/nuts/nut02.rs b/crates/cdk/src/nuts/nut02.rs index fbe12ba7..f24ef057 100644 --- a/crates/cdk/src/nuts/nut02.rs +++ b/crates/cdk/src/nuts/nut02.rs @@ -197,9 +197,10 @@ impl From<&Keys> for Id { 5 - prefix it with a keyset ID version byte */ - let mut keys: Vec<(&String, &super::PublicKey)> = map.iter().collect(); + let mut keys: Vec<(&Amount, &super::PublicKey)> = map.iter() + .collect(); - keys.sort_by_key(|(k, _v)| u64::from_str(k).unwrap()); + keys.sort_by_key(|(&amt, _v)| u64::from(amt)); let pubkeys_concat: Vec = keys .iter()