Repository navigation
ENG-631: reclaim mint-settled spent card slots on the top-up load tap - #759
Merged
Merged
Conversation
…(ENG-631) Add the CLEAR_SPENT (0x31) APDU and `isProofShaped`, the card file's slot checks that tell a CLEAR_SPENT remnant from a proof. A card read now reads every occupied slot (`readCardSlots`) and carries the spent slots on `CashuCardInfo.spentSlots`, so the next top-up can ask the mint about them before its load tap. The Flashcard context re-reads the slots after an op that moved the balance or the spent count, so a clear shows at once. `getUnspentByKeyset` still reads unspent slots only; nothing here sends CLEAR_SPENT. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6
…tap (ENG-631) `reclaimVerdicts` asks the mint (NUT-07) about the card's proof-shaped spent slots before the tap; `reclaimPlan` says what a reclaim will do with them; `reclaimSpentSlots` re-reads the spent slots in the session and sends CLEAR_SPENT only when every one is a remnant or mint-SPENT, otherwise sends nothing and counts what is still settling. `prepareTopUp` counts `card.reclaimable` as room; `loadTopUp` itself still never clears, and its inventory no longer takes a torn spent slot's nonce as the record's proof. `TopUpError` can carry the reclaim's result with a refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6
… (ENG-631) The load tap now runs VERIFY_PIN, the reclaim, then the load in one session; the mint is asked about the spent slots before the tap, and a mint that cannot answer costs no tap. The amount step counts the slots the tap will free as room (`reclaimable`), the done step says how many were freed, and a no-room refusal says how many spent slots are still settling. The card screen shows unspent, spent and free counts with a note on spent slots. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6
…drop the retry note from the done step (ENG-631) Review fixes on #759. - `reclaimSpentSlots` hands on what it read (`inventory`: the slot statuses and each spent slot's proof) when it sent no CLEAR_SPENT, and `loadTopUp` takes that in place of a read of its own. A first load in the same tap now sends no GET_SLOT_STATUS; a resumed load reads only the unspent slots, taking the spent ones from the reclaim. After a clear the read is stale and the load reads the card afresh, which after a full clear means the unspent slots alone. On a resumed load of a card with k spent and u unspent slots that is u GET_PROOFs before the first LOAD_PROOF instead of 1 + k + u. - The done step's settling note no longer reuses `topUpSlotsSettling`, whose "Try again later." belongs to the `slots` refusal: a load that went through has nothing to try again. New `topUpSettlingNote`. Tests: engine tests count the tap's APDUs for a first and a resumed load with and without a clear, and assert the inventory handed on (or not); the hook test checks the hand-off; the screen test asserts the new note and that it carries no retry imperative. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6
Mirror the five new FlashcardV2 keys (slotsSpentNote, topUpSlotsReclaim, topUpReclaimed, topUpSlotsSettling, topUpSettlingNote) and the updated slotSummary into all 23 locale files, the same way #746/#747/#755 did, so check:translation-drift passes. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6
…t field, and rethrow the engine's own refusal (ENG-631) Review fixes on #759: - The amount field waited for the unfinished-top-ups read but not for the reclaim plan. On a card with no empty slot and every slot spent, the room was 0 until the mint answered, so the field refused every amount ("try a smaller amount") and then changed its mind a round-trip later. The screen now tracks the plan settling (`reclaimRead`), set at once when there is nothing to ask about and in a `finally` otherwise, and the field waits on both reads. - `useCardTopUp.load` built a fresh TopUpError to attach the reclaim, so a refused load's stack pointed at the catch block rather than the engine's own check. `TopUpError.reclaim` is now writable and the original error is rethrown with it set. Tests: two screen tests hold the plan (resolve / reject) and assert no field mounts until it settles; a hook test asserts the rejected error is the very one the engine threw. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6
… reclaim plan (ENG-631) Review fix on #759: - The amount field waits for the reclaim plan, and that plan is a mint round-trip over the phone's network with no timeout. On a card with spent slots the amount step showed the unit caption, "Paid from" and a disabled Continue around a blank gap for as long as the mint took to answer, or RN fetch took to fail. An ActivityIndicator now sits in the field's slot (`topup-amount-loading`) until both the unfinished-top-ups read and the plan have settled, matching the screen's own loading step. - The held-plan, held-read and refused-mint screen tests assert the indicator is present before settle/refuse and gone after. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6
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.
Problem
A Cashu card's spent slots stay occupied for good:
loadTopUponly ever wrote into empty slots and never sent CLEAR_SPENT, so a card that had been spent down to 0 empty slots could never take another top-up, even once the mint had settled every one of those spends. The card screen showed "loaded · free" only, so the holder could not see where the slots had gone either.A spent slot is owed until the mint settles it: a burn whose signature never left the card (a POS tap cut short) can be recovered only from its slot, and the applet's CLEAR_SPENT is all-or-nothing. So the clear can only run once the mint vouches for every spent slot.
Fix (flash-mobile, ENG-631)
Card reads harvest spent slots.
readCashuCardnow reads every occupied slot (readCardSlots) and carries the spent ones onCashuCardInfo.spentSlots;getUnspentByKeysetis unchanged. The Flashcard context re-reads the slots after an op that moved the balance or the spent count, so a clear shows at once (app/utils/cashu-card.ts,app/contexts/Flashcard.tsx).Mint check before the tap, verified in-session.
reclaimVerdictsasks the mint (NUT-07) about each proof-shaped spent slot's Y before the tap, like the existingproofStatesForLoad. Safe because SPENT is terminal: a stale verdict can only withhold a clear. Inside the tap,reclaimSpentSlotsre-reads GET_SLOT_STATUS/GET_PROOF and sendsB0 31 00 00 01only when every spent slot is mint-SPENT or a CLEAR_SPENT remnant (isProofShapedfalse: the applet zeroes keyset → amount → nonce → C before marking the slot empty, D14). One UNSPENT or PENDING slot blocks the whole clear and is counted assettling. A mint that cannot be asked costs no tap: no slot is freed.CLEAR_SPENT runs in exactly one place: the top-up load tap, between VERIFY_PIN and
loadTopUp(useCardTopUp.load).loadTopUpitself still never clears; its resumed-load inventory now also ignores a torn spent slot whose nonce survived but whose data is not a proof, and lets the mint decide whether the record's proof is written again.Reclaimable slots are room.
prepareTopUptakescard.reclaimable(never inflatingempty), the amount step counts it, and a card at 0 empty slots can top up again. If the in-session re-check skips the clear,loadTopUprefuses withslotsas before, the record staysminted, and the refusal says how many spent slots are still settling. The done step says how many slots were freed.Copy. Card screen:
{unspent} loaded · {spent} spent · {free} free of {max}plus a note under the row when spent > 0. Top-up:topUpSlotsReclaim,topUpReclaimed,topUpSlotsSettling(yarn update-translationsrun).Cross-checked against the getfoxy/card fork's
spec/APDU.md: CLEAR_SPENT is unchanged there (0x31, Le 01, D14 write order); its recent applet changes (sign-before-burn, daily limit, change tap) touch the spend path, not this.How it was tested
yarn test: 164 suites, 1969 tests, all green.yarn tsc:check,yarn check:translations: clean.eslinton every changed file: 0 errors (whole-repo count unchanged from main: 1187 pre-existing errors);prettier --check(pinned 2.8.8) andtyposon the changed files: clean.__tests__/utils/cashu-card.spec.ts: CLEAR_SPENT bytes, 1-byte parse, wrong length, PIN refusal;isProofShapedtable (zero/non-pow2/over-range amount, off-curve and zeroed C, zero nonce, zero keyset);readCardSlotsreads every occupied slot and reports disagreeing status bytes as neither;readKeysetSplitruns with unspent = 0, spent > 0; a read sends no SPEND/LOAD/CLEAR.__tests__/utils/cashu-card-topup.spec.ts(fake signing mint + fake card): all SPENT ⇒14, 13…, 31, count returned, slots empty; one UNSPENT / one PENDING / nonce missing from verdicts / verdicts undefined ⇒ no 0x31 andsettling; remnant clears without a verdict; no spent slots ⇒ no GET_PROOF, no 0x31; a short freed count is logged; full card (32 settled spends) reclaimed then loaded in one session (14, 13×32, 31, 14, 30×6); full card with one unsettled spend refuses withslots, record staysminted;reclaimVerdictsandreclaimPlantables;reclaimablecounted inprepareTopUproom (and against holds); torn spent slot keeping its nonce is written again when the mint says UNSPENT and not when SPENT.__tests__/hooks/use-card-top-up.spec.tsx: ordermint → tap → verify → reclaim → load; no spent slots ⇒ no verdict call; verdict failure ⇒ tap still runs withverdicts: undefined; a refused load keeps its reason and carries the reclaim;proofStatesForLoadfailure still aborts before any mint call about spent slots;reclaimPlanFor.__tests__/screens/flashcard-v2-topup.spec.tsx: unsettled spent slots are not room; 0-empty card with all-SPENT slots tops up (reclaimable: 32reachesprepareTopUp); no mint call on a card with no spent slots or on a resume; mint failure leaves them out; done step shows freed / settling notes;slotsrefusal appends the settling note.__tests__/screens/flashcard-v2.spec.tsx:3 loaded · 5 spent · 24 free of 32and the spent note.14, 13×8), never CLEAR_SPENT; an op that frees spent slots re-reads them and keeps the per-unit figures; an op that changes nothing reads no slots.Follow-ups
🤖 Generated with Claude Code
https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6