Skip to content

Commit

Permalink
fix: add missing keyset_id
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Jan 9, 2024
1 parent f3ee387 commit ac77e1e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
16 changes: 13 additions & 3 deletions moksha-core/src/blind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<(BlindedMessage, SecretKey, String)>, MokshaCoreError> {
if fee_reserve.0 == 0 {
return Ok(vec![]);
Expand All @@ -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::<Vec<(BlindedMessage, SecretKey, String)>>();

Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion moksha-core/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64, String>)]
pub keys: HashMap<u64, PublicKey>,
Expand Down
1 change: 1 addition & 0 deletions moksha-mint/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
35 changes: 30 additions & 5 deletions moksha-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,18 @@ impl<C: Client, L: LocalStore> WalletBuilder<C, L> {

// 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,
Expand Down Expand Up @@ -205,7 +215,8 @@ impl<C: Client, L: LocalStore> Wallet<C, L> {
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()
Expand Down Expand Up @@ -350,7 +361,14 @@ impl<C: Client, L: LocalStore> Wallet<C, L> {
.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::<Vec<(BlindedMessage, SecretKey)>>();

Expand Down Expand Up @@ -412,7 +430,14 @@ impl<C: Client, L: LocalStore> Wallet<C, L> {
.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::<Vec<(BlindedMessage, SecretKey)>>())
}
Expand Down

0 comments on commit ac77e1e

Please sign in to comment.