diff --git a/moksha-core/src/blind.rs b/moksha-core/src/blind.rs index 591aa345..0e40374e 100644 --- a/moksha-core/src/blind.rs +++ b/moksha-core/src/blind.rs @@ -33,11 +33,13 @@ pub struct BlindedMessage { #[serde(rename = "B_")] #[schema(value_type=String)] pub b_: PublicKey, + pub id: String, } impl BlindedMessage { pub fn blank( fee_reserve: Amount, + keyset_id: String, ) -> Result, MokshaCoreError> { if fee_reserve.0 == 0 { return Ok(vec![]); @@ -51,7 +53,15 @@ impl BlindedMessage { .map(|_| { let secret = generate_random_string(); let (b_, alice_secret_key) = dhke.step1_alice(secret.clone(), None).unwrap(); // FIXME - (BlindedMessage { amount: 0, b_ }, alice_secret_key, secret) + ( + BlindedMessage { + amount: 0, + b_, + id: keyset_id.clone(), + }, + alice_secret_key, + secret, + ) }) .collect::>(); @@ -81,7 +91,7 @@ mod tests { #[test] fn test_1000_sats() { - let result = BlindedMessage::blank(1000.into()); + let result = BlindedMessage::blank(1000.into(), "00ffd48b8f5ecf80".to_owned()); println!("{:?}", result); assert!(result.is_ok()); let result = result.unwrap(); @@ -91,7 +101,7 @@ mod tests { #[test] fn test_zero_sats() { - let result = BlindedMessage::blank(0.into()); + let result = BlindedMessage::blank(0.into(), "00ffd48b8f5ecf80".to_owned()); println!("{:?}", result); assert!(result.is_ok()); assert!(result.unwrap().is_empty()); diff --git a/moksha-core/src/primitives.rs b/moksha-core/src/primitives.rs index 727c7659..5307d004 100644 --- a/moksha-core/src/primitives.rs +++ b/moksha-core/src/primitives.rs @@ -123,7 +123,7 @@ impl KeysResponse { #[derive(serde::Deserialize, Serialize, Clone, Debug, PartialEq, Eq, ToSchema)] pub struct KeyResponse { - pub id: String, + pub id: String, // TODO use new type for keyset_id pub unit: CurrencyUnit, #[schema(value_type = HashMap)] pub keys: HashMap, diff --git a/moksha-mint/src/mint.rs b/moksha-mint/src/mint.rs index 98e2af5a..410351bb 100644 --- a/moksha-mint/src/mint.rs +++ b/moksha-mint/src/mint.rs @@ -324,6 +324,7 @@ mod tests { b_: dhke::public_key_from_hex( "02634a2c2b34bec9e8a4aba4361f6bf202d7fa2365379b0840afe249a7a9d71239", ), + id: "00ffd48b8f5ecf80".to_owned(), }]; let result = mint.create_blinded_signatures(&blinded_messages, &mint.keyset_legacy)?; diff --git a/moksha-wallet/src/wallet.rs b/moksha-wallet/src/wallet.rs index ce388016..950ef17b 100644 --- a/moksha-wallet/src/wallet.rs +++ b/moksha-wallet/src/wallet.rs @@ -84,8 +84,18 @@ impl WalletBuilder { // FIXME store all keysets let keys = client.get_keys(&mint_url).await?; - let key_response = keys.keysets.get(0).expect("keyset is empty"); - let mks = mint_keysets.keysets.get(0).expect("mint keyset is empty"); + + let key_response = keys + .keysets + .iter() + .find(|k| k.id.starts_with("00")) + .expect("no valid keyset found"); + + let mks = mint_keysets + .keysets + .iter() + .find(|k| k.id.starts_with("00")) + .expect("no valid keyset found"); Ok(Wallet::new( client as C, @@ -205,7 +215,8 @@ impl Wallet { split_result.1.proofs() }; - let fee_blind = BlindedMessage::blank(melt_quote.fee_reserve.into())?; + let fee_blind = + BlindedMessage::blank(melt_quote.fee_reserve.into(), self.keyset_id.clone().id)?; let msgs = fee_blind .iter() @@ -350,7 +361,14 @@ impl Wallet { .zip(secrets.clone()) .map(|(amount, secret)| { let (b_, alice_secret_key) = self.dhke.step1_alice(secret, None).unwrap(); // FIXME - (BlindedMessage { amount, b_ }, alice_secret_key) + ( + BlindedMessage { + amount, + b_, + id: self.keyset_id.clone().id, + }, + alice_secret_key, + ) }) .collect::>(); @@ -412,7 +430,14 @@ impl Wallet { .zip(secrets) .map(|(amount, secret)| { let (b_, alice_secret_key) = self.dhke.step1_alice(secret, None).unwrap(); // FIXME - (BlindedMessage { amount, b_ }, alice_secret_key) + ( + BlindedMessage { + amount, + b_, + id: self.keyset_id.clone().id, + }, + alice_secret_key, + ) }) .collect::>()) }