Repository navigation
fix(flashcard): sign NUT-20 mint quotes with the current message, not the legacy one - #758
Merged
Merged
Conversation
… the legacy one Every card top-up made the mint log "Using legacy NUT-20 signature verification. This fallback is deprecated since version 0.20.2". The top-up engine signs the quote with cashu-ts 4.11's exported signMintQuote, which still hashes the quote id and blinded points as concatenated text. cashu-ts's own Wallet signs the current, domain-separated message, but that signer is not exported, and the engine works below the Wallet. When Nutshell drops the fallback, every top-up fails at the mint call. nut20.ts builds the message Nutshell's construct_message builds — SHA-256 over "Cashu_MintQuoteSig_v1", the quote id, and each output's minimal amount bytes and blinded point, every field length-prefixed — and signs it BIP-340. The digest and a signature are pinned to values produced by the Flash Forge mint's own interpreter (Nutshell 0.20.3.1) over the same outputs, and the legacy digest is pinned beside them so the two cannot be confused again. The test mint fake now accepts only the current form, as Nutshell will. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Review nits for #758. The spec compared two string literals to say the legacy digest differs; now it signs with cashu-ts 4.11's exported signMintQuote, the one the engine used to call, and asserts the new verifier rejects it — the assertion that would have caught this bug. The fake mint's import moves beside the file's other local imports. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Every Cashu card top-up made the Flash Forge mint log:
The top-up engine signs the quote with cashu-ts 4.11.0's exported
signMintQuote, which still hashes the quote id and blinded points as concatenated text (the original NUT-20 message). cashu-ts's ownWalletsigns the current, domain-separated message, but that signer is not exported, and the engine deliberately works below theWallet. When Nutshell removes the fallback, every top-up fails at the final mint call. Upstream cashu-ts switches the export to the current message in 5.0 (signMintQuotecurrent,signMintQuoteLegacykept for old mints).How
app/utils/cashu-card-topup/nut20.tsbuilds the message Nutshell'sconstruct_messagebuilds, byte for byte: SHA-256 over the tagCashu_MintQuoteSig_v1, the quote id, then each output's minimal big-endian amount bytes (none for zero) and its blinded point, every field after the tag prefixed with its 4-byte big-endian length. It signs that with BIP-340, and the engine now calls it instead of the cashu-ts export. AverifyMintQuoteSignaturelives beside it for the test fake.Tests
__tests__/utils/nut20.spec.tspins the digest and a signature produced by the mint's own interpreter (Nutshell 0.20.3.1 on forge) over the same quote id and three outputs, including a zero amount. The legacy digest is pinned next to it, and a test signs with cashu-ts 4.11's exportedsignMintQuote(the one the engine used to call) and asserts the new verifier rejects it, so a regression to the legacy signer fails here. (Swapping the engine back to the library export also fails 26 of the 71 top-up tests withSignature for mint request invalid.) The app's signature verifies with the same check; a tampered output or another quote id does not; garbage input returns false.FakeMintin__tests__/helpers/fake-cashu.tsnow accepts only the current form, as Nutshell will once the fallback goes; the top-up suite (71 tests) passes against it; its only change is that the one test which signs a quote itself now uses the new signer too.Verifying on the mint
After this lands, a top-up should no longer produce the warning above in
journalctl -u cashu-mint. The current flash-mobile build on the Pixel and iPhone still produces it; I'll confirm the absence on the first top-up with this code.Scope
flash-pos is unaffected: it swaps and melts but never mints, so it never signs a quote.
🤖 Generated with Claude Code