From 93c2d478f85aea76d0f71d4beae092cb38e3d726 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Mon, 18 Dec 2023 23:49:02 +0000 Subject: [PATCH] refactor: rename id to keyset_id where relevant on structs --- crates/cashu-sdk/src/mint.rs | 7 +++++-- crates/cashu-sdk/src/wallet.rs | 2 +- crates/cashu/src/dhke.rs | 2 +- crates/cashu/src/nuts/nut00.rs | 29 ++++++++++++++++++----------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/crates/cashu-sdk/src/mint.rs b/crates/cashu-sdk/src/mint.rs index a6b7c9de..a2887111 100644 --- a/crates/cashu-sdk/src/mint.rs +++ b/crates/cashu-sdk/src/mint.rs @@ -147,7 +147,7 @@ impl Mint { Ok(BlindedSignature { amount: *amount, c: c.into(), - id: keyset.id, + keyset_id: keyset.id, }) } @@ -198,7 +198,10 @@ impl Mint { return Err(Error::TokenSpent); } - let keyset = self.keysets.get(&proof.id).ok_or(Error::UnknownKeySet)?; + let keyset = self + .keysets + .get(&proof.keyset_id) + .ok_or(Error::UnknownKeySet)?; let Some(keypair) = keyset.keys.0.get(&proof.amount) else { return Err(Error::AmountKey); diff --git a/crates/cashu-sdk/src/wallet.rs b/crates/cashu-sdk/src/wallet.rs index adc38390..c8327527 100644 --- a/crates/cashu-sdk/src/wallet.rs +++ b/crates/cashu-sdk/src/wallet.rs @@ -205,7 +205,7 @@ impl Wallet { let unblinded_sig = unblind_message(blinded_c, premint.r.into(), a).unwrap(); let proof = Proof { - id: promise.id, + keyset_id: promise.keyset_id, amount: promise.amount, secret: premint.secret, c: unblinded_sig, diff --git a/crates/cashu/src/dhke.rs b/crates/cashu/src/dhke.rs index 546c99b5..95d6f8ce 100644 --- a/crates/cashu/src/dhke.rs +++ b/crates/cashu/src/dhke.rs @@ -89,7 +89,7 @@ mod wallet { let unblinded_signature = unblind_message(blinded_c, rs[i].clone().into(), a)?; let proof = Proof { - id: promise.id, + keyset_id: promise.keyset_id, amount: promise.amount, secret: secrets[i].clone(), c: unblinded_signature, diff --git a/crates/cashu/src/nuts/nut00.rs b/crates/cashu/src/nuts/nut00.rs index 611e012e..f72725d6 100644 --- a/crates/cashu/src/nuts/nut00.rs +++ b/crates/cashu/src/nuts/nut00.rs @@ -17,12 +17,12 @@ use crate::Amount; pub struct BlindedMessage { /// Amount pub amount: Amount, - /// encrypted secret message (B_) - #[serde(rename = "B_")] - pub b: PublicKey, /// Keyset Id #[serde(rename = "id")] pub keyset_id: Id, + /// encrypted secret message (B_) + #[serde(rename = "B_")] + pub b: PublicKey, } #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] @@ -345,8 +345,10 @@ impl MintProofs { /// Promise (BlindedSignature) [NUT-00] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct BlindedSignature { - pub id: Id, pub amount: Amount, + /// Keyset Id + #[serde(rename = "id")] + pub keyset_id: Id, /// blinded signature (C_) on the secret message `B_` of [BlindedMessage] #[serde(rename = "C_")] pub c: PublicKey, @@ -355,10 +357,11 @@ pub struct BlindedSignature { /// Proofs [NUT-00] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Proof { - /// `Keyset id` - pub id: Id, /// Amount in satoshi pub amount: Amount, + /// `Keyset id` + #[serde(rename = "id")] + pub keyset_id: Id, /// Secret message pub secret: Secret, /// Unblinded signature @@ -384,7 +387,7 @@ impl From for mint::Proof { amount: Some(proof.amount), secret: proof.secret, c: Some(proof.c), - id: Some(proof.id), + keyset_id: Some(proof.keyset_id), } } } @@ -394,7 +397,7 @@ impl TryFrom for Proof { fn try_from(mint_proof: mint::Proof) -> Result { Ok(Self { - id: mint_proof.id.ok_or(Error::MissingProofField)?, + keyset_id: mint_proof.keyset_id.ok_or(Error::MissingProofField)?, amount: mint_proof.amount.ok_or(Error::MissingProofField)?, secret: mint_proof.secret, c: mint_proof.c.ok_or(Error::MissingProofField)?, @@ -424,7 +427,8 @@ pub mod mint { pub c: Option, /// `Keyset id` #[serde(skip_serializing)] - pub id: Option, + #[serde(rename = "id")] + pub keyset_id: Option, } /// List of proofs @@ -447,7 +451,10 @@ mod tests { let proof = "[{\"id\":\"DSAl9nvvyfva\",\"amount\":2,\"secret\":\"EhpennC9qB3iFlW8FZ_pZw\",\"C\":\"02c020067db727d586bc3183aecf97fcb800c3f4cc4759f69c626c9db5d8f5b5d4\"},{\"id\":\"DSAl9nvvyfva\",\"amount\":8,\"secret\":\"TmS6Cv0YT5PU_5ATVKnukw\",\"C\":\"02ac910bef28cbe5d7325415d5c263026f15f9b967a079ca9779ab6e5c2db133a7\"}]"; let proof: Proofs = serde_json::from_str(proof).unwrap(); - assert_eq!(proof[0].clone().id, Id::from_str("DSAl9nvvyfva").unwrap()); + assert_eq!( + proof[0].clone().keyset_id, + Id::from_str("DSAl9nvvyfva").unwrap() + ); } #[test] @@ -461,7 +468,7 @@ mod tests { UncheckedUrl::from_str("https://8333.space:3338").unwrap() ); assert_eq!( - token.token[0].proofs[0].clone().id, + token.token[0].proofs[0].clone().keyset_id, Id::from_str("DSAl9nvvyfva").unwrap() );