Repository navigation
feat(flashcard): Cashu card screen — read the card, remember it, show it - #745
Merged
islandbitcoin merged 3 commits intoSep 30, 2026
Conversation
Tapping a Cashu card (cashu-javacard applet, "Flashcard v2") now opens a card screen instead of a toast. First of the ENG-616 PRs; this one moves no money. What #738 left: a read that stored nothing. The `cashuCard` context field was dropped in its last review commit, and every route into CardScreen gates on the BoltCard `lnurl`, so a Cashu tap could never reach a screen. The hook's `ContextProps` was also a hand-copied shadow of `FlashcardInterface`, which is how a field could be added to the provider and stay invisible to every screen. The hook now uses the interface itself. The APDU codec is ported from flash-pos (src/services/cashuCard.ts) so both apps send byte-identical commands to the same card: CardError with the status word, CardProtocolError for framing, SELECT with the trailing Le that CoreNFC needs, GET_INFO with the PIN state, GET_PUBKEY, GET_BALANCE, GET_PROOF_COUNT, GET_SLOT_STATUS, GET_PROOF, VERIFY_PIN, LOAD_PROOF and SPEND_PROOF. Only the read path is called here; the write path lands with top-up and sweep. `readCashuCard` keeps #738's discriminator contract — null on 6A82 to both SELECT forms so a BoltCard falls through on the same tap — and now returns pubkey and PIN state too. `readFlashcard` resolves with what the tap produced, so the Settings row and the Home tile navigate to the new screen on a Cashu card and keep watching `lnurl` for a BoltCard. The screen shows the card's own unspent total (advisory — SIGN_ARBITRARY can witness a proof without burning it), slots, applet version, a short card id, and a PIN notice: none set warns that anyone holding the card can spend it; blocked says plainly that no unblock exists and the card must be replaced (ENG-617). It is shown as a plain number until the unit decision (D1) lands. A persisted `flashcardV2` slice records every card this phone has read and carries the typed ledger the top-up and sweep PRs write into — the applet keeps no history, so this device-local record is the only one until a backend registry exists (ENG-618). PERSIST_VERSION 1 → 2. Foundation: @cashu/cashu-ts pinned to flash-pos's 4.11.0 (Node ≥22.4; CI is on 24). It is ESM-only with exports-only resolution, so Metro gains `unstable_enablePackageExports` plus `unstable_conditionNames: ['require','react-native']` — the latter keeps tslib on CJS for Apollo. A bundle that imports cashu-ts and Apollo together was built to check the interaction; tslib's __extends is present, the bundle runs. The polyfills cashu-ts needs were already in index.js. New i18n keys are fanned to all 23 locales (the drift gate requires it). Tests: the codec byte for byte (71), the provider orchestration (7, now also pinning the store write and reset), the screen (10), the slice and migration (12). Full suite 1467. Co-Authored-By: Claude Fable 5.1 <[email protected]>
islandbitcoin
force-pushed
the
jabariennis/eng-616-flashcard-v2-cashu-card-screen-balance-top-up-pin-sweep
branch
from
September 27, 2026 19:17
26f086f to
023684b
Compare
- Drop @cashu/cashu-ts, its lockfile entries, the jest @CASHU pattern and the global Metro package-exports switch. Nothing here imports cashu-ts, and the review found the switch moves existing packages (the Breez SDK, redux, RTK, ...) onto other builds. The PR that first imports cashu-ts owns a resolver scoped to @cashu/*. - PIN copy keyed on the applet version (ENG-615). On v0.2.0 a blocked PIN stops gating SPEND_PROOF ([email protected]:587-591), and no version is confirmed to carry cashu-javacard#25, so a blocked card is shown as spendable by whoever holds it. The no-PIN notice no longer sells a PIN as protection; a PIN state byte the app cannot decode gets its own notice. - One routing point for every card tap (useTapFlashcard) and one rule for the Home tile and the Settings row (useOpenFlashcard): a Cashu card tapped anywhere opens FlashcardV2, a BoltCard opens Card. The unreachable Home branch and the get-started lnurl watcher are gone. - forgetCashuCard: Remove card, and leaving the screen signed out, forget the Cashu card in context and in the store and leave the BoltCard link alone. Only a signed-in read is recorded; logout resets the slice. - The balance always carries a unit: the read collects each unspent slot's keyset (GET_SLOT_STATUS + GET_PROOF), the mint's /v1/keysets names the unit, the screen shows a total per unit and labels anything unresolved "unit unknown". KnownCard.unit is filled from the mint. - One SELECT policy, the spec's any-error fallback (spec/APDU.md:26-27), shared by readCashuCard and selectApplet; the flash-pos divergence is documented. - VERIFY_PIN takes 4-8 ASCII digits only; LOAD_PROOF checks the amount and every hex field; buildApdu refuses any value that is not a byte. - Delete the ledger nothing writes (CardEvent, events, eventRecorded, cardLabelled, label); it lands with the flows that write it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A set PIN is no longer shown as protection. On applet v0.2.0 the third wrong VERIFY_PIN blocks the PIN ([email protected]:517-521) and a blocked PIN gates nothing (:587-591, ENG-615), so a set PIN won't stop whoever holds the card. The set state now gets its own notice (flashcard-v2-pin-bypassable), keyed on blockedPinGatesSpend exactly like the blocked copy; it stays silent only on a version confirmed to keep refusing once blocked (none yet). New keys in en and all 23 locales. - The Home tile's sync refreshes a BoltCard in place again, as on main. useTapFlashcard takes { openBoltCard: false } for a control that already shows the BoltCard; a Cashu card still opens FlashcardV2. - Screen readers hear the words on screen, not test ids. The PIN notice is one accessibility element labelled "<title>. <body>"; the balance, card id and refresh use a plain testID. The icon-only read controls (FlashcardV2 and BoltCard refresh, Get Started NFC icon) are buttons labelled with CardScreen.readNfcCard. - The keyset split is best effort once GET_BALANCE has answered. A card lost midway through GET_SLOT_STATUS / GET_PROOF, a refused slot read or a malformed slot map leaves keysets undefined and logs only the error name and status word; the read stands, the mint is not asked, and the screen shows the total as "unit unknown". The mandatory reads are the same four as flash-pos readCard. Unit policy is untouched: units still come from the mint. Co-Authored-By: Claude Opus 5.5 <[email protected]>
islandbitcoin
pushed a commit
that referenced
this pull request
Sep 28, 2026
runCardOperation no longer lets its re-read decide the outcome. Once the operation has succeeded, a card that leaves before GET_INFO/GET_BALANCE no longer rejects the call: the result stands, the lost re-read is logged by error name only, and what the operation proves (the caller's `assume`, `pinState: "set"` for both PIN commands) is applied instead. Before, a CHANGE_PIN that had landed came back as "No Cashu card found", and the holder then retyped the old PIN into 63C2, 63C1, 6983. A card that refused the operation (a CardError other than a failed SELECT) is re-read too, before the refusal is rethrown unchanged. The third wrong PIN now leaves the card "blocked" in context and on its record, so the card screen shows #745's blocked notice and no Change PIN button. A different card or a lost channel gets no re-read. The caller learns what the re-read said through `onReread`. `expectedPubkey` is required: the identity check always runs. The PIN screen maps outcomes against the firmware (CashuApplet.java at v0.2.0 and applet 0.3): - 63C0 says "blocked and must be replaced" on every firmware. It only ever comes from v0.2.0's CHANGE_PIN spending the last try, which never sets pinState 2 (:555-559), so the card is frozen, not open. - 6983 takes its copy from the re-read: pinState 2 follows blockedPinGatesSpend, pinState 1 is v0.2.0's frozen card, and no re-read falls back to the firmware. The copy no longer claims this tap spent the last try, since a card blocked earlier answers the same. - A blocked PIN ends the flow on a toast, announced, back to the card. - A tag without the applet, 6986 (LOCK_CARD) and any other refusal get plain words; the status word goes to a console.warn, never the screen. - A cancelled sheet (NfcError.UserCancel) shows no error and keeps the current and new PINs, as flash-pos does. - A tap lost after CHANGE_PIN went out says the new PIN may already be in use and to try it first. Accessibility: plain testIDs replace testProps on the step title, entry and error (a screen reader said "pin-error"); the title is a header, the entry reads "Digits entered: N", pad keys are buttons read as the digit, "Clear" or "Delete"; the status area is a live region on Android and errors are announced on iOS. A late mint answer no longer writes a unit to the record for a split an operation already dropped (the provider keeps a ref of the card and checks it), and an operation that moves value clears the record's unit. Tries-left copy no longer needs a plural. Seven new strings and four reworded ones fanned to all 23 locales. Tests: the Android timeout wired between requestTechnology and the first APDU (the shared NFC mock gains setTimeout and NfcError); a refusal re-read and rethrown as the same error; three wrong PINs against a scripted v0.2.0 card ending "blocked" in context and store; no re-read after a wrong card, a lost channel or a failed SELECT; a lost re-read after a successful op; the record's unit kept or cleared; one screen case per failure branch, every blocked-PIN case under both firmware behaviours, and screen-reader labels. Each checked against a mutant of the code it guards (24 mutants, all caught). Full suite 147 suites / 1630 tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
islandbitcoin
pushed a commit
that referenced
this pull request
Sep 30, 2026
runCardOperation no longer lets its re-read decide the outcome. Once the operation has succeeded, a card that leaves before GET_INFO/GET_BALANCE no longer rejects the call: the result stands, the lost re-read is logged by error name only, and what the operation proves (the caller's `assume`, `pinState: "set"` for both PIN commands) is applied instead. Before, a CHANGE_PIN that had landed came back as "No Cashu card found", and the holder then retyped the old PIN into 63C2, 63C1, 6983. A card that refused the operation (a CardError other than a failed SELECT) is re-read too, before the refusal is rethrown unchanged. The third wrong PIN now leaves the card "blocked" in context and on its record, so the card screen shows #745's blocked notice and no Change PIN button. A different card or a lost channel gets no re-read. The caller learns what the re-read said through `onReread`. `expectedPubkey` is required: the identity check always runs. The PIN screen maps outcomes against the firmware (CashuApplet.java at v0.2.0 and applet 0.3): - 63C0 says "blocked and must be replaced" on every firmware. It only ever comes from v0.2.0's CHANGE_PIN spending the last try, which never sets pinState 2 (:555-559), so the card is frozen, not open. - 6983 takes its copy from the re-read: pinState 2 follows blockedPinGatesSpend, pinState 1 is v0.2.0's frozen card, and no re-read falls back to the firmware. The copy no longer claims this tap spent the last try, since a card blocked earlier answers the same. - A blocked PIN ends the flow on a toast, announced, back to the card. - A tag without the applet, 6986 (LOCK_CARD) and any other refusal get plain words; the status word goes to a console.warn, never the screen. - A cancelled sheet (NfcError.UserCancel) shows no error and keeps the current and new PINs, as flash-pos does. - A tap lost after CHANGE_PIN went out says the new PIN may already be in use and to try it first. Accessibility: plain testIDs replace testProps on the step title, entry and error (a screen reader said "pin-error"); the title is a header, the entry reads "Digits entered: N", pad keys are buttons read as the digit, "Clear" or "Delete"; the status area is a live region on Android and errors are announced on iOS. A late mint answer no longer writes a unit to the record for a split an operation already dropped (the provider keeps a ref of the card and checks it), and an operation that moves value clears the record's unit. Tries-left copy no longer needs a plural. Seven new strings and four reworded ones fanned to all 23 locales. Tests: the Android timeout wired between requestTechnology and the first APDU (the shared NFC mock gains setTimeout and NfcError); a refusal re-read and rethrown as the same error; three wrong PINs against a scripted v0.2.0 card ending "blocked" in context and store; no re-read after a wrong card, a lost channel or a failed SELECT; a lost re-read after a successful op; the record's unit kept or cleared; one screen case per failure branch, every blocked-PIN case under both firmware behaviours, and screen-reader labels. Each checked against a mutant of the code it guards (24 mutants, all caught). Full suite 147 suites / 1630 tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
islandbitcoin
added a commit
that referenced
this pull request
Sep 30, 2026
* feat(flashcard): set or change the Cashu card PIN with one tap Second of the ENG-616 PRs, stacked on the card screen. Still moves no money; it is the first change that writes to the card. A card ships with no PIN, and until one is set anyone holding it can spend from it or load it. The card screen already says so; this PR gives that notice an action. "Set PIN" appears on a card with none, "Change PIN" on a card with one, and neither on a blocked card, which has no way back (ENG-617), or on a card whose PIN state the app cannot read. SET_PIN is a one-way door (a PIN can be changed but never removed, and the screen says that before the first entry), so the plan's "do not expose SET_PIN" is deliberately overridden for the unset case: a consumer card that nobody can PIN is a bearer card by accident. The flow: current PIN (change only), new PIN, confirm, then one tap. All three stay in the screen's local state and nowhere else: nothing is stored, and the spec asserts no message carries the digits. Inside the tap the provider's new `runCardOperation` opens an IsoDep-only session, raises Android's 618 ms transceive timeout (an on-card operation can outlive it, and flash-pos watched burns die and still burn), SELECTs the applet on the fresh channel, checks GET_PUBKEY against the card the screen is showing so the PIN never lands on a different card, runs VERIFY_PIN + CHANGE_PIN (or SET_PIN alone), re-reads the card so context shows the new PIN state, and releases exactly once whatever happened. This is the door every later card-changing flow (load, spend) goes through. It keeps the card screen's rules: signed out, the re-read stays in memory and nothing reaches the store; and an operation that moved value drops the tap's keyset split and the mint's per-unit figures rather than show them beside a new total, and a late mint answer cannot bring them back. Verifying before CHANGE_PIN also matters on v0.2.0 firmware, where CHANGE_PIN's own failed checks burn tries without ever marking the PIN blocked, freezing the card for its owner too. Errors say what the card said and what the card now does. A wrong current PIN reports the tries left (63CX). What the last try means depends on the firmware (`blockedPinGatesSpend`): a card confirmed to freeze once blocked is reported blocked; on v0.2.0, where three wrong entries switch the PIN check off (ENG-615), the screen says that instead, and so does the set-PIN warning. A different card is named as such; a cancelled or lost tap says to try again. The PIN pad is ported from flash-pos so both apps ask the same way. Codec: SET_PIN 0x41 and CHANGE_PIN 0x42 (oldLen ‖ old ‖ new), behind the card screen's 4-8 ASCII-digit check so nothing malformed reaches the card, and `triesLeft` for 63CX. Tests: the two commands byte for byte; `runCardOperation` against the provider harness (session shape, identity check, re-read, release on every path, signed out, the split kept or dropped); the PIN screen through every step and every failure under both firmware behaviours; the PIN actions on the card screen per PIN state; the Android timeout helper. 23 locales updated. Co-Authored-By: Claude Fable 5.1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(flashcard): address review findings on the Cashu card PIN flow runCardOperation no longer lets its re-read decide the outcome. Once the operation has succeeded, a card that leaves before GET_INFO/GET_BALANCE no longer rejects the call: the result stands, the lost re-read is logged by error name only, and what the operation proves (the caller's `assume`, `pinState: "set"` for both PIN commands) is applied instead. Before, a CHANGE_PIN that had landed came back as "No Cashu card found", and the holder then retyped the old PIN into 63C2, 63C1, 6983. A card that refused the operation (a CardError other than a failed SELECT) is re-read too, before the refusal is rethrown unchanged. The third wrong PIN now leaves the card "blocked" in context and on its record, so the card screen shows #745's blocked notice and no Change PIN button. A different card or a lost channel gets no re-read. The caller learns what the re-read said through `onReread`. `expectedPubkey` is required: the identity check always runs. The PIN screen maps outcomes against the firmware (CashuApplet.java at v0.2.0 and applet 0.3): - 63C0 says "blocked and must be replaced" on every firmware. It only ever comes from v0.2.0's CHANGE_PIN spending the last try, which never sets pinState 2 (:555-559), so the card is frozen, not open. - 6983 takes its copy from the re-read: pinState 2 follows blockedPinGatesSpend, pinState 1 is v0.2.0's frozen card, and no re-read falls back to the firmware. The copy no longer claims this tap spent the last try, since a card blocked earlier answers the same. - A blocked PIN ends the flow on a toast, announced, back to the card. - A tag without the applet, 6986 (LOCK_CARD) and any other refusal get plain words; the status word goes to a console.warn, never the screen. - A cancelled sheet (NfcError.UserCancel) shows no error and keeps the current and new PINs, as flash-pos does. - A tap lost after CHANGE_PIN went out says the new PIN may already be in use and to try it first. Accessibility: plain testIDs replace testProps on the step title, entry and error (a screen reader said "pin-error"); the title is a header, the entry reads "Digits entered: N", pad keys are buttons read as the digit, "Clear" or "Delete"; the status area is a live region on Android and errors are announced on iOS. A late mint answer no longer writes a unit to the record for a split an operation already dropped (the provider keeps a ref of the card and checks it), and an operation that moves value clears the record's unit. Tries-left copy no longer needs a plural. Seven new strings and four reworded ones fanned to all 23 locales. Tests: the Android timeout wired between requestTechnology and the first APDU (the shared NFC mock gains setTimeout and NfcError); a refusal re-read and rethrown as the same error; three wrong PINs against a scripted v0.2.0 card ending "blocked" in context and store; no re-read after a wrong card, a lost channel or a failed SELECT; a lost re-read after a successful op; the record's unit kept or cleared; one screen case per failure branch, every blocked-PIN case under both firmware behaviours, and screen-reader labels. Each checked against a mutant of the code it guards (24 mutants, all caught). Full suite 147 suites / 1630 tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(flashcard): settle a cut-short SET_PIN and keep PINs the card never saw Review fixes on the Cashu card PIN flow (ENG-616). - A tap cut short after SET_PIN went out said "No Cashu card found" and sent the holder back to pick a PIN, though SET_PIN saves the PIN before it answers ([email protected]:538-539; 0.3: 574-575). It now says the card may already use the PIN, keeps it, and asks only for the confirmation. The retry settles it: 9000 sets it, and a 6985 to the only PIN a cut-short tap carried means the earlier write landed, so the tap counts as a success (re-read, or `assume` when the card leaves first) and the card screen offers Change PIN. A different PIN still gets "already has a PIN"; after two cut-short taps with different PINs a 6985 claims neither. - A failure before any PIN reached the card (a different card, a tag without the applet, a tap lost before VERIFY_PIN or SET_PIN) keeps the PINs typed and asks only for the confirmation. A wrong current PIN, a refusal, or a lost answer after a PIN command went out still start over. - A cancel that cuts off a PIN command is a lost answer, not a quiet cancel: a quiet retry after a CHANGE_PIN that landed would verify the old PIN and spend a try. - The card screen spec asserts the PIN action is hidden when signed out. - New strings pinSetUncertain and pinSetEarlier in all 23 locales. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(flashcard): end a card's last-try outcome on screen; announce success Round-3 review findings on the PIN flow. The outcome that ends the flow (the last try: a PIN switched off on v0.2.0 firmware, or a frozen card) went into a toast, and this app's toasts show two ellipsized lines in a fixed box. The 177-character v0.2.0 message lost its last sentence, "anyone holding the card can spend its balance. Move the value off it.", which is the part that matters, and the frozen copy lost "replaced". When the card left before the re-read, the card screen could not make up for it. The flow now ends on this screen: the whole message stays in the status area (a live region on Android, announced on iOS), the pad and Continue give way to Close, and the card screen shows only when the holder presses it. Success went only to a toast, which is never announced, so a TalkBack or VoiceOver user heard nothing, including after the retry that finishes a cut-short SET_PIN. The screen now announces the same message before it goes back. Specs: every last-try case asserts the full message on screen, no pad, no toast, and goBack only on Close; the change, set and earlier-set successes assert the announcement. Reverting either fix fails them (9 and 3 cases). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Dread <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
islandbitcoin
pushed a commit
that referenced
this pull request
Sep 30, 2026
…onnected mint The engine for loading value onto a Cashu card (ENG-616 PR 2, D2): the app quotes at the mint it is connected to (CASHU_MINT_URL), the user's wallet pays the invoice, and the app mints outputs locked to the card and writes them with LOAD_PROOF. No Flash backend call mints anything. cashu-ts 4.11.0 (flash-pos's version) is the rail. It and the @noble/@Scure v2 packages nested under it are ESM-only, so Metro resolves package exports for requests FOR a @CASHU package or FROM a file inside one, and for nothing else: switching it on app-wide re-resolved hundreds of shipped modules (#745). - Card outputs (ported from flash-pos): the canonical P2PK secret, pinned to the silicon fixture; outputs built only from it; a proof is checked to rebuild on the card before it may be written. - CLEAR_SPENT (0x31) in the codec. - The store keeps unfinished top-ups in the Keychain, not redux-persist: a paid top-up not yet on the card is money only its record can deliver, so it survives sign-out. Reads are strict (a Keychain failure or an unreadable value throws, never reads as empty) and writes run one at a time. - The engine saves each step before its outside effect: - the quote (NUT-20 locked to a key only this app holds) and the blinding data are saved before the invoice is paid; - the payment is marked dispatched before the wallet is asked, and the mint's own quote state decides "paid", so a paid invoice is never paid again; - a mint answer that was lost is recovered with NUT-09 restore, never a second mint; - every proof is DLEQ-checked and checked to rebuild on this card before it is saved, and the saved proofs are what gets loaded; - a resumed load reads the card's inventory (spent slots too) because the applet accepts the same proof twice; CLEAR_SPENT runs only when the empty slots cannot take the rest. - runCardOperation: an operation that moves value re-reads the keyset split in the same session, so the card screen names the units again after a top-up; the old split's late mint answer still never lands. Tests run against a mint that really signs (BDHKE, DLEQ, NUT-20, NUT-09) and a card that stores slots like the applet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
islandbitcoin
added a commit
that referenced
this pull request
Sep 30, 2026
* feat(flashcard): Cashu card top-up engine, minted by the app at the connected mint The engine for loading value onto a Cashu card (ENG-616 PR 2, D2): the app quotes at the mint it is connected to (CASHU_MINT_URL), the user's wallet pays the invoice, and the app mints outputs locked to the card and writes them with LOAD_PROOF. No Flash backend call mints anything. cashu-ts 4.11.0 (flash-pos's version) is the rail. It and the @noble/@Scure v2 packages nested under it are ESM-only, so Metro resolves package exports for requests FOR a @CASHU package or FROM a file inside one, and for nothing else: switching it on app-wide re-resolved hundreds of shipped modules (#745). - Card outputs (ported from flash-pos): the canonical P2PK secret, pinned to the silicon fixture; outputs built only from it; a proof is checked to rebuild on the card before it may be written. - CLEAR_SPENT (0x31) in the codec. - The store keeps unfinished top-ups in the Keychain, not redux-persist: a paid top-up not yet on the card is money only its record can deliver, so it survives sign-out. Reads are strict (a Keychain failure or an unreadable value throws, never reads as empty) and writes run one at a time. - The engine saves each step before its outside effect: - the quote (NUT-20 locked to a key only this app holds) and the blinding data are saved before the invoice is paid; - the payment is marked dispatched before the wallet is asked, and the mint's own quote state decides "paid", so a paid invoice is never paid again; - a mint answer that was lost is recovered with NUT-09 restore, never a second mint; - every proof is DLEQ-checked and checked to rebuild on this card before it is saved, and the saved proofs are what gets loaded; - a resumed load reads the card's inventory (spent slots too) because the applet accepts the same proof twice; CLEAR_SPENT runs only when the empty slots cannot take the rest. - runCardOperation: an operation that moves value re-reads the keyset split in the same session, so the card screen names the units again after a top-up; the old split's late mint answer still never lands. Tests run against a mint that really signs (BDHKE, DLEQ, NUT-20, NUT-09) and a card that stores slots like the applet. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(flashcard): top up a Cashu card from the Cash wallet The top-up screen and its entry points, on the engine from the previous commit (ENG-616 PR 2). The card screen gets Top up, for a signed-in holder of a card whose PIN state it can read, and a line for each top-up that is paid for and not on the card yet (or whose payment may still land), with Finish to resume it. A quote that was never sent for payment is not shown: nothing was paid. The screen: amount → (PIN check) → confirm → pay → wait for the mint → load tap → done. - Unit (D1): sats by default. A card holding value tops up only in that unit, so a card is never mixed; an empty card may choose USD when the remote flag `cashuCardUsdEnabled` is on. It ships off: flash-pos prices every card proof as sats today (ENG-619), so a USD card would be over-charged at a till. - Refused before any amount: a blocked PIN (on v0.2.0 it spends for anyone; on 0.3 it never loads again, stranding what was paid), a PIN state or a unit this app cannot read, a card holding more than one unit. - The amount says how many of the card's slots it takes, and will not go past the slots (empty plus spent), the mint's 1,000,000 limit, or the Cash wallet's balance. - On a card with a PIN, the PIN is checked with a tap BEFORE anything is paid, then reused for the load tap. A wrong PIN found only at the load would spend tries on value already paid for. - Paid from the Cash wallet through the send flow's idempotent lnInvoicePaymentSend (a stable key, never re-sent keyless on a retry; the server replaying the key for other parameters is "unknown", never a failure). The mint's invoice sits on Flash, so the payment is intraledger. The fee comes from lnUsdInvoiceFeeProbe and is shown only when the probe answers. - A failed payment stays on confirm (nothing left the wallet); an unknown one says to check the history and retries through the engine, which asks the mint first. Leaving before paying drops the quote; leaving after a dispatch keeps it. - A mint that has not seen the payment after ~15 s is left for later; the card screen finishes it. A mint answer that fails verification loads nothing and says to contact support. A card with no room says so and keeps the top-up. Tests: the eligibility rules, every screen path, the hook's reading of each payment answer, and the card screen's Top up and unfinished list. Mutation checked: removing any of the money guarantees fails a test. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(flashcard): address review findings on the Cashu card top-up A payment read as refused no longer lets the top-up go, a paid quote is minted before the mint stops issuing it, and spent slots are never cleared. Payment answers (use-card-top-up.ts, engine.ts) - The top-up has its own lnInvoicePaymentSend document that selects each error's code. A FAILURE reads as "nothing left the wallet" only for a refusal made before execution (INSUFFICIENT_BALANCE, TRANSACTION_RESTRICTED, TOO_MANY_REQUEST, INVALID_INPUT, INVOICE_DECODE_ERROR) or for IBEX's own corroborated FAILED status with no error. The busy lock on a same-key request (ROUTE_FINDING_ERROR, empty message) and IBEX's generic error are unknown now. - A refusal of a RETRY is unknown too: the key and the retry flag stay. - New sticky payment.everDispatched. cancelTopUp drops a record that was ever sent only once the mint still holds its quote UNPAID 10 minutes past its expiry. Leaving the screen after a refusal no longer deletes the lock key. - A top-up is never paid without its key. wentKeyless is gone, along with the keyless fallback it was meant to guard. Expiry (engine.ts, minter.ts, app.tsx) - Nutshell refuses to mint a PAID quote after its expiry. advanceTopUps mints paid quotes without the card. It runs at launch, on foreground, on a nudge from the screen, and every 15 s while a payment may land, until the quote dies. It also runs when the card screen gets focus. - A quote never sent with under 2 minutes left is quoted again before paying. A quote already sent is never paid that late. - A PAID quote the mint no longer issues gets its own message. PENDING quote state now means wait, not restore. The fake mint refuses after expiry, as Nutshell does. Card slots (engine.ts, cashu-card.ts, flashcard-v2-topup.tsx) - Only empty slots count as room, and CLEAR_SPENT is never sent. A spent slot is owed until it settles (cashu-javacard spec/CARD-FILE.md). The clearSpent docstring now says so. - A resumed load asks the mint (NUT-07) about each proof before the tap. The card never gets back a proof the mint has seen spent. A PENDING proof waits for a later load. - Unfinished top-ups hold their slots and their unit, in prepareTopUp and on the screen. Store and card screen - advanceTopUps drops dead quotes, sent or not. The card screen can dismiss a dead sent quote, and the removal is conditional (store.removeIf). - Prepare failures say nothing was paid. Correction to 9a5df5c: a sat top-up is NOT intraledger. Forge's sat backend is phoenixd, so the payment is Lightning out of IBEX, where PENDING and route failures are normal. Only USD top-ups settle on Flash. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(flashcard): say what a failed top-up payment does, now that it keeps its record A refused first dispatch takes a fresh key; it no longer lets the record go (everDispatched keeps it until the mint says the quote died unpaid). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(flashcard): judge a top-up quote by its age, not the phone's clock Round-3 review fixes on the Cashu card top-up (ENG-616). Quote age (engine.ts, types.ts) - Every expiry decision compared the phone's clock with the mint's. On a phone about 70 minutes fast, a PENDING payment's record was dropped, lock key and all, and the payment then settled into a PAID quote nobody could mint. A slow clock paid late. A quote now saves quote.quotedAt (the phone's clock on arrival) and quote.lifeMs (its expiry less its bolt11 timestamp), and is judged by its age on the phone's own clock, as the send flow's isInvoiceExpired does. - quoteIsDead (drop, Dismiss, cancel) and quoteExpired (the mint no longer issues it) fire only when the age and the mint's expiry on the phone's clock agree. The pay window goes by the age alone: here the harmful answer is "there is time", so the absolute reading may neither hold it back (a slow phone would pay late) nor fire it alone (a fast phone could never pay). A clock set back since the quote arrived is not paid on. - The pay window is checked again after a re-quote. A quote whose invoice states no issue time is refused before anything is saved. A paid quote the mint no longer issues (engine.ts) - Any quote state but UNPAID now saves a quoted record as paid before it is minted (mintTopUp, cancelTopUp), conditional on the same quote. The card screen shows it as paid with Finish, never as expired with Dismiss. - A refusal the mint will repeat is saved on the record (mintRefused), and no card-free pass asks the mint about it again. Finish still asks. Payments (use-card-top-up.ts, engine.ts) - IBEX's FAILURE with no error is definitive: flash caches it under the key and replays it to every retry. A retry answered with it retires the key; the next Pay is a first dispatch under a fresh key. A retry refused before it ran stays unknown. - The busy lock is UNEXPECTED_CLIENT_ERROR "... (code: ResourceAttemptsLockServiceError: Unknown error)", not ROUTE_FINDING_ERROR with an empty message. Spec and comment corrected. Messages (flashcard-v2-topup.tsx, flashcard-v2.tsx) - A resumed load whose NUT-07 check could not reach the mint fails as mint-unreachable, before any tap. It no longer says "No Cashu card found". No TopUpError reads as a missing card any more. - A top-up gone from the store no longer says "Your top-up is saved". - A refused Dismiss reads the top-ups again and says why the top-up stays. CLEAR_SPENT (cashu-card.ts) - clearSpent and INS.CLEAR_SPENT are removed with their tests; the sweep adds them behind its NUT-07 gate. loadTopUp names the spec lines it does not follow (NUT-XX.md:193, APDU.md:278 and :453 at v0.2.0) and the spec fix, cashucard/javacard#27. The fake mint now quotes real signed bolt11 invoices. New i18n keys topUpMintUnreachable, topUpGone and topUpDismissRefused, in all 23 translations. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(flashcard): address the last review round on the card top-up - Size the pay window to the quote: a quarter of its life, between 10 s and 2 min. A forge USD quote lives 60 s (IBEX caps every non-sat Flash invoice at 60 s), so the fixed 2-min window re-quoted every USD Pay and then refused the new quote too. Nothing USD could be paid. - A paid quote the mint refuses as expired (NUT code 20007, or Nutshell 0.20.3's "quote expired" detail under code 11000) is final, whatever the phone's clock reads. Only a mint call that got no answer is judged by the quote's age and the phone's clock. A slow phone no longer POSTs a refused quote every 15 s, and Finish says to contact support. - With cashuCardUsdEnabled off, a card set to USD, by its value or by an unfinished top-up, takes no new top-up (new copy in all locales). An unfinished USD top-up still resumes and finishes. - Fake mint: a usd keyset with 60 s quotes, a unit check, and Nutshell's MintOperationError for an expired quote. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(flashcard): give a usd top-up quote 40 s to be paid and minted The 15 s window a 60 s usd quote got rested on its payment settling inside Flash. It doesn't: lnInvoicePaymentSend pays through IBEX, and the mint can mint only after its own check of the invoice, Flash's lnInvoicePaymentStatus asking IBEX. Flash's IBEX client sets no timeout on either call, so a slow IBEX could leave a paid quote the mint refuses as expired. - The least pay window is 40 s, up from 10 s: a 60 s usd quote is paid only in its first 20 s (Pay quotes again after that). Sat keeps its 2 min. - The pay window counts from just before the quote was asked for (`quote.requestedAt`), so the time the quote took to arrive counts against paying it. The drop and expired verdicts keep `quotedAt`, where reading the age low is the safe side. - The fake mint refuses as Nutshell main does, each refusal a MintOperationError with its code, so tests read them as the mint's answer. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Dread <[email protected]> Co-authored-by: Claude Opus 5.5 <[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.
First of the ENG-616 (Flashcard v2) PRs. Moves no money. The plan, the three audits behind it and the open decisions live in the ticket; this PR is the foundation the rest stand on.
What a Cashu tap does now
Every control that asks for a card tap (Get Started, the Home tile's sync, Settings, the Card screen's read and refresh, this screen's refresh) goes through one hook,
useTapFlashcard, which opens the screen for whatever was tapped: a Cashu card opens FlashcardV2, a BoltCard opens Card. One exception keeps main's behaviour: the Home tile's sync refreshes a linked BoltCard in place (useTapFlashcard({ openBoltCard: false })), since the tile body already opens Card; a Cashu card tapped there still opens FlashcardV2. The Home tile and the Settings row share one rule (useOpenFlashcard): a linked BoltCard first, then the Cashu card read this session, else a tap.The Cashu screen shows the card's unspent value per unit, proof slots (loaded / free of 32), applet version, a short card id, and a PIN notice. The card stores no unit and GET_BALANCE adds every keyset together, so the read also collects each unspent slot's keyset (GET_SLOT_STATUS + GET_PROOF) and the mint's public
/v1/keysetsnames the unit. Until it answers the figure reads "unit unknown", never bare. Nothing goes through the price feed and no unit is assumed (D1 stays open).PIN notices are keyed on the applet version GET_INFO reports. No PIN → "anyone holding this card can spend from it or load it", with no promise that setting one protects a balance. PIN set → on the same versions, a warning that three wrong entries turn the PIN off, after which anyone holding the card can spend from it; the notice stays silent only on a version confirmed to keep refusing once blocked (none yet). Blocked → on v0.2.0 a blocked PIN stops gating spends (ENG-615,
[email protected]:587-591) and no version is confirmed to carry cashu-javacard#25, so the screen says the card no longer asks for a PIN, anyone holding it can spend its balance, it can't be unblocked (ENG-617), and to move the value off it. A PIN state byte the app can't decode gets its own notice.Remove card forgets the Cashu card (context and this phone's record) and leaves a linked BoltCard alone. A card read while signed out is never recorded and is forgotten on leaving, as the BoltCard screen already does. Logout resets the record.
What #738 had actually left behind
A read that stored nothing. Its
cashuCardcontext field was dropped in the last review commit, and every route intoCardScreengates on the BoltCardlnurl, so a Cashu tap could never reach any screen — Settings just re-read the card each time. Underneath that,useFlashcard'sContextPropswas a hand-copied shadow ofFlashcardInterface, which is exactly how a field could be added to the provider and stay invisible to every screen. The hook now uses the interface itself; that class of bug is gone.The codec
app/utils/cashu-card.tsis ported from flash-possrc/services/cashuCard.ts: every command the two share is built byte for byte the same. The one deliberate divergence is SELECT's fallback. This app followsspec/APDU.md:26-27(the applet-AID SELECT after any refusal of the package AID, as cardctl does), where flash-pos falls back on 6A82 only;readCashuCardandselectAppletshare that one policy. SELECT carries the trailing Le that CoreNFC needs for a Case-4 command (flash-pos found this on hardware).CardErrorcarries the status word (63CXdecodes the tries left);CardProtocolErroris framing, or input the wire can't carry:buildApdurefuses any value that isn't a byte (both native bridges keep only the low byte), VERIFY_PIN takes 4-8 ASCII digits only (a non-ASCII digit would go out as the wrong byte and spend a try), and LOAD_PROOF checks its amount and every hex field before an APDU is built.readCashuCardkeeps #738's discriminator contract —nullon6A82to both SELECT forms so an NTAG 424 BoltCard falls through to NDEF on the same tap — and returns pubkey, PIN state and the balance, plus the per-keyset split best effort: if the split can't be read (the card left the field during the slot reads, or refused one), it is left out, the tap still succeeds, and the screen labels the card's total "unit unknown".Foundation
flashcardV2slice (PERSIST_VERSION 1 → 2): the cards this phone has read while signed in, with the unit the mint confirmed. The applet keeps no history of any kind, so this device-local record is the only one until a backend registry exists (ENG-618). The top-up/sweep ledger is not here; it lands with the flows that write it, with its own migration (autoMergeLevel1 does not fill nested keys).CASHU_MINT_URL(forge.flashapp.me, the mint in cashu-javacard's card-file spec and flash-pos's config) inapp/config/appinfo.ts. Only its public keyset list is read.@cashu/cashu-tsand the global package-exports switch were dropped in review. The PR that first imports cashu-ts owns a resolver scoped to@cashu/*.Deliberately not here
SIGN_ARBITRARYcan produce a valid witness without burning a slot — until reconciliation lands.app/store/redux/index.ts:2-3has a pre-existing duplicatereact-reduximport that eslint flags; untouched, outside the changed-lines gate.Tests
cashu-card.spec.ts— the wire format byte for byte, every command, every refusal and every input refused before the wire, the best-effort keyset split (116).cashu-mint.spec.ts— keyset parsing, the cached lookup and its refresh, per-unit totals (14).flashcard-cashu-card.spec.tsx— provider orchestration: one session per tap, SELECT first,getTagnever on the Cashu path, no second session on cancel; the read in context, in the tap's result and in the store only when signed in; units from the mint; each card forgotten on its own (15).flashcard-v2.spec.tsx— per-unit balance and the "unit unknown" label, every PIN notice by version including the set-PIN warning, screen-reader labels, refresh, remove, signed-out leave, no-card exit (27).flashcard-v2-forget.spec.tsx— the same screen on the real provider and store (2).use-tap-flashcard.spec.tsx(10) andflashcard-tap-call-sites.spec.tsx(one per call site, 8) — the routing, including the Home sync refreshing a BoltCard in place.flashcard-v2-slice.spec.ts— the slice and the v2 migration (12).Device check owed
Pixel 8 Pro and iPhone 13 Pro Max, TEST backend, a real v0.2.0 card: tap from Get Started, Settings → Flashcard, the Home tile's sync and the Card screen's refresh; confirm the Cashu screen opens with the right per-unit balance and slot counts (a tap now also sends GET_SLOT_STATUS and one GET_PROOF per unspent slot), the PIN notice matches the card's state, refresh re-reads, and a BoltCard still takes its own path on the same tap. Also: a linked BoltCard tapped on the Home tile's sync stays on Home and the tile updates; a PIN-set v0.2 card shows "Three wrong entries turn this PIN off"; a Cashu card lifted away during the slot reads still opens the screen with the total labelled "unit unknown".
🤖 Generated with Claude Code