Skip to content

Commit

Permalink
Merge pull request #559 from thesimplekid/fix_multi_mint_token_check
Browse files Browse the repository at this point in the history
fix: multi mint check
  • Loading branch information
thesimplekid authored Jan 24, 2025
2 parents 7aa83bf + b3a1c9f commit a66454c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* `Wallet::receive_raw` which receives raw binary tokens ([lollerfirst]).

### Fixed
* Multimint unit check when wallet receiving token ([thesimplekid])

### Removed

Expand Down
4 changes: 4 additions & 0 deletions crates/cashu/src/nuts/nut00/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ impl TokenV3 {

mint_urls
}

pub fn is_multi_mint(&self) -> bool {
self.token.len() > 1
}
}

impl FromStr for TokenV3 {
Expand Down
15 changes: 9 additions & 6 deletions crates/cdk/src/wallet/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,23 @@ impl Wallet {
p2pk_signing_keys: &[SecretKey],
preimages: &[String],
) -> Result<Amount, Error> {
let token_data = Token::from_str(encoded_token)?;
let token = Token::from_str(encoded_token)?;

let unit = token_data.unit().unwrap_or_default();
let unit = token.unit().unwrap_or_default();

if unit != self.unit {
return Err(Error::UnitUnsupported);
}

let proofs = token_data.proofs();
if proofs.len() != 1 {
return Err(Error::MultiMintTokenNotSupported);
let proofs = token.proofs();

if let Token::TokenV3(token) = &token {
if token.is_multi_mint() {
return Err(Error::MultiMintTokenNotSupported);
}
}

if self.mint_url != token_data.mint_url()? {
if self.mint_url != token.mint_url()? {
return Err(Error::IncorrectMint);
}

Expand Down

0 comments on commit a66454c

Please # to comment.