Repository navigation
feat(cashu): read a Cashu card's balance from the Flashcard settings flow - #738
Merged
Merged
Conversation
…flow Settings → Ways to get paid → Flashcard now recognises the Cashu NFC card (lnflash/cashu-javacard, an IsoDep JavaCard applet — a different physical card from the NDEF BoltCards) and shows its balance on tap. - Tag handling is IsoDep-first: requestTechnology(IsoDep) → select the Cashu AID → GET_INFO + GET_BALANCE; a tag without the applet resolves null and falls through to the existing NDEF flow, and a failed IsoDep attempt falls back harmlessly. - app/utils/cashu-card.ts: the read-only client (SELECT/GET_INFO/ GET_BALANCE wire format mirrors cardctl, the reference driver) with a parser spec. - iOS: the Cashu AIDs join the Info.plist select-identifiers so CoreNFC delivers the tag to the app. Read-only by design: no PIN, no spending — balance display only.
… dep - Flashcard.tsx: the isoDepHandler access is cast (this repo's react-native-nfc-manager typings predate the field on TagEvent — CI's tsc -p . caught what a root-level tsc missed); the negated else-if inverted; the persistent-store anys documented and disabled; the NfcScan inline style moved to useStyles; the empty catch commented. - package.json/yarn.lock: react-native-animatable ^1.4.0 added as a direct dependency (the context imports it; it was only transitive). - cashu-card.ts: no-bitwise file disable — APDU assembly is bitwise by nature.
…C session Review fixes for #738. - handleTag read `isoDepHandler` off the tag returned by getTag(), but the library only exposes it as a getter on the manager, so the field was always undefined and every tap fell into the NDEF flow. Gate on the tech that requestTechnology resolved with and transceive through NfcManager.isoDepHandler. - One session per tap: request [IsoDep, Ndef] once, read the tag once, and parse its NDEF message when the applet SELECT is refused. A rejected request (user cancel) now propagates instead of opening a second session. - SELECT retries with the full 8-byte applet AID when the card declines the 7-byte package prefix, as the spec mandates and cardctl does. - GET_INFO carries Le=00 as the spec table and cardctl send it. - parseBalance reinterprets the result as uint32 (`>>> 0`). - Drop the half-wired `cashuCard` context field and the orphaned comment. Tests: exact-APDU scripted card in the client spec (Le byte, AID fallback, uint32 boundary, order of every command) and a new provider spec that renders FlashcardProvider and pins the call site: manager handler, single requestTechnology per tap, cancel opens no second session, mid-read failure is not re-read as a BoltCard. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Review fixes for #738: - A Cashu read that failed after a successful SELECT (tag lifted so transceive rejects, or a non-9000 GET_INFO/GET_BALANCE) landed in handleTag's outer catch with no user feedback: the sheet closed and the spec asserted the silence. It now toasts an error and rethrows, so the outer catch stays the single logging site and the finally the single session release. The mid-read spec now expects the error toast, and a new case covers the transport-reject path. - Drop the dead setLoading(false) in the Cashu success branch; nothing on that path ever set loading true. - Extract __tests__/contexts/flashcard-harness.tsx (renderProvider + PROVIDER_RENDER_TIMEOUT_MS) and use it from both FlashcardProvider specs instead of two copies of the Probe/provider wrapper. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Review fixes on the Cashu card balance read, checked against cashu-javacard spec/APDU.md, cardctl and flash-pos: - Flashcard.tsx: getTag() now runs after the Cashu probe, on the NDEF path only. On iOS getTag() is a live Type-4 NDEF read (NfcManager.m readNDEFWithCompletionHandler) that SELECTs the NDEF application, so it was the first thing sent to a card that has none; neither cardctl nor flash-pos sends anything before the applet SELECT. Android was unaffected (it returns the NDEF message cached at discovery). - cashu-card.ts: a double SELECT refusal still resolves null, but only a 6A82/6A82 answer (BoltCard/NTAG 424, the NDEF fall-through case) stays silent. Any other status word (6999 select() failure, 6283/6A81 locked instance) is logged in hex before the null instead of reaching the user as an unreadable card with nothing in the log. Tests: the orchestration spec pins getTag() never running on a Cashu read (success or mid-read failure) and running once, after both SELECTs, on the fall-through; the unit spec adds [6999, 6A82] and [6283, 6283] scripted cards that resolve null and warn, and pins the 6A82/6A82 case as silent. Co-Authored-By: Claude Fable 5.1 <[email protected]>
islandbitcoin
pushed a commit
that referenced
this pull request
Sep 27, 2026
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
added a commit
that referenced
this pull request
Sep 30, 2026
… it (#745) * feat(flashcard): Cashu card screen — read the card, remember it, show it 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]> * fix(flashcard): address review findings on the Cashu card screen - 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]> * fix(flashcard): address round-2 review findings on the Cashu card screen - 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]> --------- Co-authored-by: Dread <[email protected]> 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.
Summary
Settings → Ways to get paid → Flashcard now recognises the Cashu NFC card (the lnflash/cashu-javacard applet — an IsoDep JavaCard applet, a different physical card from the NDEF BoltCards) and shows its balance on tap.
app/utils/cashu-card.ts— the read-only client; the wire format mirrorscardctl(the reference driver in cashu-javacard) and carries a parser spec (6 tests).D2760000850102,D276000085010201) join the Info.plist select-identifiers.Read-only by design: no PIN, no spending — balance display only. The POS-side charging flow lives in flash-pos (shipped separately).
Test plan