Skip to content

fix(flashcard): sign NUT-20 mint quotes with the current message, not the legacy one - #758

Merged
islandbitcoin merged 2 commits into
mainfrom
jabariennis/nut20-mint-quote-sig
Oct 7, 2026
Merged

islandbitcoin merged 2 commits into
mainfrom
jabariennis/nut20-mint-quote-sig

Conversation

@islandbitcoin

@islandbitcoin islandbitcoin commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What

Every Cashu card top-up made the Flash Forge 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.0's exported signMintQuote, which still hashes the quote id and blinded points as concatenated text (the original NUT-20 message). cashu-ts's own Wallet signs the current, domain-separated message, but that signer is not exported, and the engine deliberately works below the Wallet. 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 (signMintQuote current, signMintQuoteLegacy kept for old mints).

How

app/utils/cashu-card-topup/nut20.ts builds the message Nutshell's construct_message builds, byte for byte: SHA-256 over the tag Cashu_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. A verifyMintQuoteSignature lives beside it for the test fake.

Tests

__tests__/utils/nut20.spec.ts pins 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 exported signMintQuote (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 with Signature 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.

FakeMint in __tests__/helpers/fake-cashu.ts now 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

Dread and others added 2 commits October 6, 2026 18:05
… 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]>
@islandbitcoin
islandbitcoin merged commit 7ae5c8b into main Oct 7, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant