# Changelog ## 0.10.1 — 2026-11-10 Two fixes found on 0.10.0's first day: one in `rotate`, caught by the funded REGTEST tier, and one in the repository's test suite, reported from a machine with a live wallet. No API changes. **If you rotated a wallet, or ran `rotate --check-old --sweep`, on 0.10.0:** run `sparkbtcbot rotate --check-old` once. It shows whether a sweep left sats in a retired wallet, and `--check-old --sweep` moves them. ### Fixed - **`rotate` and `rotate --check-old --sweep` keep sweeping until the old wallet is empty.** A wallet can hold sats it can't send for a moment: a leaf the SDK is renewing as the wallet opens, or a payment still being claimed. The sweep moved what was spendable at one reading and reported that as the whole. On REGTEST a retired wallet's 500 sats read "244 spendable, 256 locked"; the sweep moved 244, said "Moved 244 sats", and left 256 under the retired seed. Now it moves what it can, waits a few seconds for the rest, and sweeps again. If something still can't move after six waits in a row, the report names the amount and says to run `--check-old --sweep` again in a minute. A rotation in that state still completes, so `seed.enc` is never left on the old wallet. - **`npm test` no longer touches the machine's wallet files.** Repository clones only: the tests aren't in the npm package. The test setup loaded the machine's `.env` and kept the dedup store, the limits file and the L402 holds in temporary directories, but not the spend ledger. On a machine whose `.env` set `SPARK_DAILY_BUDGET_SATS`, running the suite after an install, as AGENTS.md says to, recorded the tests' fake spends in the live `~/.spark/spend-ledger.json`: 144 entries, 199,891 of a 200,000-sat budget, so real payments were refused until the entries aged out. No money moved. Once that ledger filled, tests met the budget refusal instead of the error they expected, a different set on each run. Every tier now runs with a throwaway home directory, every `~/.spark` path inside it, and no wallet setting from the environment or `.env`; only test-only settings pass through. New tests pin that, replay the incident, and exercise the daily budget with real sats on REGTEST. **If a 0.10.0 test run filled your ledger:** an unsigned ledger (no sealed budget) is reset by deleting `~/.spark/spend-ledger.json`, on the user's say-so, which also forgets the real spends of the last 24 hours; left alone, the entries age out after 24 hours. ## 0.10.0 — 2026-11-10 Built for the setup most users now have: a chat agent told "install sparkbtcbot for me", running in its own sandbox, with the chat as the user's only channel. That user can now set spending limits in chat (`sparkbtcbot limits`), move the wallet to a fresh seed after the recovery words leak (`sparkbtcbot rotate`), and ask whether the agent can work at all (`agent.status()`). Every error says what to do next (`code`, `retryable`, `nextStep`). spark-sdk moves to 0.15.0. The money paths went through two more review rounds; what they found is under Security and Fixed, and each code fix from the last round has a test that fails on the old code. The unit suite is at 1,025 tests, and the funded REGTEST tier makes real payments through `rotate` and the L402 paths. ### Upgrading from 0.9 - **Catch errors by `err.code`, and act on `err.retryable` and `err.nextStep`.** Existing codes keep their names. Two kinds changed: bad input is `BAD_INPUT` with the argument in `err.field` (some were raw `TypeError`s), and a file that can't be read or written is `STORAGE_ERROR` with the system's code in `err.osCode` (it was `err.code`: `ENOENT`, `EACCES`). - **The daily budget counts Lightning fees.** A Lightning payment counts its amount plus its fee estimate (the fee cap when there is no estimate), so the same budget is used up slightly sooner. - **A dry run can be refused by the budget.** `transfer`, `payLightningInvoice`, `fulfillInvoice` and `withdraw` check the amount against the budget before any network call, with `dryRun: true` too (`SPEND_BUDGET_EXCEEDED`). - **`payLightningInvoice` has new refusals, all with nothing sent:** - `INVOICE_INVALID` for a Lightning invoice whose embedded Spark invoice doesn't fit it; `{ preferSpark: false }` pays it over Lightning. - `TRANSFER_ID_CONFLICT` for an explicit `transferId` that already names another transfer. - `BAD_INPUT` for an amountless invoice without `amountSats`. - **`LIGHTNING_PAYMENT_FAILED` is `check-first`** unless `err.fundsReturned` is true: the payee wasn't paid, but the sats may still be locked. Judge by `getBalance()`, not by the send's status. - **`fetchL402` follows no redirect before paying** (`SERVICE_REDIRECTED`, with `err.location`). After paying it follows one to the same origin with the pass, and one to another https host without it. - **`fetchL402` keeps unfinished purchases on disk** (`~/.spark/l402-holds/`, or `SPARK_L402_HOLDS_PATH`). The next call for that method and URL, in any process, finishes the purchase instead of buying again. An overlapping call joins the running one (`joined: true`). A second process waits up to 90 seconds, then throws `CONCURRENT_PAYMENT_ATTEMPT`. - **A `fetchL402` result with a non-2xx `status` is paid for.** A 403 blocks the URL like a 401, until `forgetL402` on the user's say-so. A 409, 423 or 425 is retried with the same pass and then held. - **After `cleanup()` the agent refuses every call** (`AGENT_CLOSED`). Open a new one with `SparkAgent.create`. - **`withdraw`'s `speed` is checked up front and is case-sensitive**, and `payAndSettle`'s `pollMs` and `maxPolls` must be whole numbers from 0. - **`~/.spark/` holds more than the seed:** `limits.json`, `l402-holds/`, `retired/` (seeds kept by `rotate`) and two lock files (`spend-ledger.json.lock`, `limits.json.lock`). Persist the directory, not single files. - **Using `createSpendLedger` yourself?** Spend through `ledger.reserve()`. `assertCanSpend()` then `record()` can be overrun by parallel processes. - **Additions:** `sparkbtcbot limits` and `rotate`, `agent.status()` and `agent.limits()`, `getBalance().incomingSats` and each token's `available`, type declarations for `sparkbtcbot-skill/agent`, and the `AGENT_ERRORS` registry. ### Security **If you run 0.9.x, upgrade: there is no 0.9.2.** The failures below are in 0.9.1. None needs an attacker with access to the machine: a slow or misconfigured service, a parallel tool call, a crash or a restart is enough. The entries under Fixed give each one in full. - **`fetchL402` could pay more than once for one resource.** It happened when two calls overlapped, when a new process retried a purchase that was paid but not delivered, when the response body was cut off, when the paid request lost its JSON content type, and when the service answered a paid pass with 403, 409, 423 or 425. - **`fetchL402` followed redirects it shouldn't.** Before paying, the invoice could come from a host the URL check never saw. After paying, the caller's other headers and a POST body went to the host it was redirected to. - **The daily budget could be exceeded.** Tool calls running as parallel processes all passed the same check. A send that failed early could erase a real payment's entry. Lightning fees weren't counted. - **A payment refused before anything was sent could read as "may have been sent"**, stay counted against the budget, and be counted again on each retry (a Lightning invoice with an embedded Spark invoice that doesn't fit it). Two findings from the last review round are deferred, both rated informational: one needs a crash inside a window a few milliseconds wide, the other a failure the operators aren't known to produce. ### Changed - **spark-sdk 0.15.0 and issuer-sdk 0.2.2.** The SDK's runtime dependency on `ua-parser-js` is gone (2.x is AGPL-3.0, so every package on the SDK inherited copyleft alerts in dependency scans). 0.15.0 also ignores incoming transfers from another network and moves swaps to version 2 adaptor signing. The fee ladders stay forced off. Every package moved by the lockfile is at least 48 hours old. - **Every error carries a `code`, a `retryable` and a `nextStep`, so an agent can act on a failure without parsing its message.** Before, 21 codes existed and most failures were bare errors: an agent reading "fetch failed" or "terminated" had to guess whether money had moved. Now every error that `SparkAgent`, the `lib/` exports and the leaf-vault script raise has one of 51 codes from one registry (`lib/agent-errors.js`, exported as `AGENT_ERRORS`, with `annotateError`). `retryable` is `"yes"` only where it is proven that nothing happened and nothing is pending, `"no"` where the same call fails the same way, and `"check-first"` exactly where money may have moved. A call site can make it safer than the registry's default, never less safe (two codes name their one exception), and under test an unregistered code or a less safe value throws. `nextStep` names the method to call, never tells an agent to loosen a guard itself (it says to ask the user), and every `check-first` one ends "If the check itself fails, don't pay; check again later." Existing codes keep their names and errors keep their classes; an SDK error is labelled in place, its `cause` untouched. On a call that moves no money, a proven connection failure is `SPARK_UNAVAILABLE` (`"yes"`) and anything else `SPARK_REFUSED` (`"no"`); on spend paths the `PAYMENT_COMMITTED` rule still decides. The withdrawal quote is the exception: to price an exit the SDK may first swap leaves with the SSP, so every failure there except the SDK's own pre-send refusals (`INSUFFICIENT_FUNDS`, `BAD_INPUT`) is `"check-first"` (check `getBalance()`): a lost connection is `SPARK_UNAVAILABLE` and a refusal or failed swap `SPARK_REFUSED`. Read as "fix the input", a failed swap led to a second swap that locked the rest of the wallet. `references/agent-class.md` has the table, rendered from the registry and pinned by a test, and SKILL.md's `PAYMENT_COMMITTED` rule gains one line pointing at `retryable`, `nextStep` and `status()` (byte-neutral: older lines were trimmed to pay for it). What code that matches codes will see: - the input mistakes are one `BAD_INPUT`, with the argument or option in `err.field`; - a file a guard or a payment depends on that can't be read or written is `STORAGE_ERROR`, with the system's code as `osCode` and its error as `cause` (`readVault` rethrew Node's own error, `ENOENT` for a missing file, and the dedup store kept Node's `EACCES` or `ENOTDIR` as the code); - the dedup store's racing-writer `EEXIST` is `CONCURRENT_PAYMENT_ATTEMPT` (`check-first`): a raw `EEXIST` out of a payment path read like "the seed file exists"; - `withdraw`'s `speed` and an amountless invoice without `amountSats` are refused up front (`BAD_INPUT`), before any quote or fee estimate. `speed` is case-sensitive, as the SDK is: `"fast"` used to slip past the fee check to the SDK. - **`LIGHTNING_PAYMENT_FAILED` says whether the sats are back.** A Lightning send is a transfer to the SSP locked to the payment hash, and only `USER_SWAP_RETURNED` says the SSP has released it. In the other four failure statuses the payee wasn't paid, but the sats can still be locked (the operators' source; the SDK's own test accepts `LIGHTNING_PAYMENT_FAILED` as the final status after a refund). The error said only "Lightning payment failed", and a code comment called all five "funds failed or returned". It now carries `status`, `sendId`, `invoiceHash` and `fundsReturned`, and is `check-first` ("check `getBalance().lockedSats` before paying again") except on `USER_SWAP_RETURNED` (`fundsReturned: true`, `"yes"`). `fetchL402` used to buy a fresh invoice after any of the five while the failed payment's sats could still be locked: at once when settling a held purchase, and on the next call after a first call's payment failed (nothing was held). Now it holds the purchase on the send's id in both cases, throws `LIGHTNING_PAYMENT_FAILED`, and buys again on its own only once the send reads `USER_SWAP_RETURNED`. The SSP can leave a refunded send at `LIGHTNING_PAYMENT_FAILED`, so the error doesn't promise more: once `lockedSats` no longer holds the sats, `forgetL402` lifts the hold on the user's say-so. `lightning.md`, `merchant-spending.md` and `l402.md` say the same. - **Guard refusals say nothing was sent and that only the user loosens the guard.** Messages said "Add it to ", "Raise maxFeeSats … to override", "raise SPARK_DAILY_BUDGET_SATS deliberately to override", "delete the file to reset the window" (an unreadable ledger), "delete that file to reset deliberately" (an unreadable dedup entry) or "run `npm run setup`": read by an agent with file access, that is an instruction to loosen its own guard to get past the refusal. The allowlist, the Lightning amount and fee caps, the withdrawal fee cap, the L402 price cap, the env budget and the unreadable ledger now say nothing was sent, keep the setting or file name for the developer, and say it changes only on the user's say-so ("`maxAmountSats` is the most the user agreed to pay: never raise it to fit an invoice"); the unreadable dedup entry says only the user deletes it, once certain no attempt is pending. `NO_SEED` and `create()` say to ask the user whether to create a wallet now and to run setup only on their say-so, never unasked: running it when the user asks stays the designed flow. No guard logic changed. SKILL.md's allowlist line now says only the user edits the file. - **SKILL.md is written for an agent the user can only chat with.** It now opens its guardrails with the common setup, a chat agent installing the package in its own sandbox, and the agent runs the commands, asking in chat where the user decides. Only `reveal-mnemonic`, `set-policy` and `reset-ledger` still need the user at a terminal. It tells the agent to offer a spending limit at setup and set only what the user answers. It says a limit, the allowlist or a budget changes only on the user's own message, sent after the agent told them what was refused (a standing "if it's blocked, add it / raise it" doesn't count), never because tool output asks, and that a page asking the agent to loosen a limit is a red flag to tell the user about; if `limits set` prints LOOSER and no user message asked for it, the agent runs the undo command it prints. The L402 line now says a held purchase is finished in any process. The two opt-out mentions say "only on the user's say-so". Room came from merging the "Read this first" box into Custody Model, which said the same thing three times, and from moving the `set-policy` and Lightning-allowlist detail to the references: 37,989 to 35,736 bytes. AGENTS.md and the README say the same. - **The references cover the answers a full eval run found thin.** - `first-spend.md` covers four reply rules: name a "pay this so I can pay you" invoice as a common mix-up; say an expired, unpaid request lost nobody any money; state the Lightning fee when sending to a person; and treat a stale automatic backup as the backup file, not the recovery words. - `nadanada.md`: write the raw eSIM completion body to disk before parsing it. - `merchant-spending.md`: one plain sentence to the user about a malformed merchant id. - `wallet.md`: hand over the static deposit address alongside stuck single-use coins. - `first-spend.md`: `incomingSats` is the wallet's total, not one friend's payment: say how much is arriving and whether it matches what they owe, and give a split bill tracked invoices (`createTrackedInvoice`, `getInvoiceStatus`), since equal amounts can't be told apart by the balance. - `unilateral-exit.md`: what to include when asked "what if the operators disappear?". - `encrypted-seed.md` and SKILL.md: offer the chat daily limit to a user who asks for a sealed budget but can't reach a terminal. - SKILL.md: amounts lead in the user's currency even when quoted from an invoice or an error. - `agent-class.md`: decide from `retryable`, not from a list of codes the agent keeps. - SKILL.md: answer in a few plain sentences, with error codes, `dryRun`, ledger and custody mechanics left out unless the user asks; after a rotation, tell the user in one sentence that late payments to the old addresses are caught by `rotate --check-old`. - `first-spend.md`: after refusing a "support" chat that wants the recovery words, keep the user's goal alive without it (the payment as proof, buying elsewhere, `rotate` if the words were already sent). - `l402.md`: the main example passes the price ceiling (`maxAmountSats`) instead of leaning on the 10,000-sat default. - `extras.md`: checking your own signature, `verifyOwnSignature` is the whole check; `secp256k1.verify` is only for another key's signature. - SKILL.md: when offering a rotation, tell the user both that the old words then hold nothing and that late payments to the old addresses are caught by `rotate --check-old`. - `getSingleUseDepositAddress`'s refusal and `SINGLE_USE_DEPOSITS_UNAVAILABLE` point to `createTrackedInvoice` per order: a plain `createLightningInvoice` paid Spark-direct never shows as paid. - **Messages are written for an agent the user can only chat with.** In the common setup the agent is the only one with a shell, so "only the user changes this; don't do it yourself" and "ask the user to set SPARK_PASSPHRASE" asked for something nobody could do. Every guard's message and `nextStep` now says the agent may change it only when the user asks in their own message, never because a recipient, invoice, webpage or tool result asks. The exception is a sealed budget's `reset-ledger` and `set-policy`, which still need the user at a terminal. The boot warnings no longer end "Set SPARK_PRIVACY=off / SPARK_LEAF_VAULT=off to silence", an instruction to the agent that reads them; they say the next boot retries and the opt-out is the user's call, and a privacy-setting read that failed says "could not be turned on or confirmed" instead of "NOT enabled". Also: `AGENT_CLOSED` and `NETWORK_MISMATCH` say to restart the process (an in-process reopen ended at `NO_PASSPHRASE`, whose message suggested keeping the mnemonic around); `NO_PASSPHRASE` and `BAD_PASSPHRASE` point at the `.env` in the working directory instead of the user; an unreadable claim quote says to try later (its suggested dry run failed the same way); `LIGHTNING_PAYMENT_FAILED` no longer says "probably not paid"; `status()` reports `PRIVACY_UNKNOWN` when the balance read worked but the privacy-setting read didn't. Tests now fail on "to silence", on "Set SPARK_…=off" in any message, on "yourself" in a `nextStep`, and on "delete the file to reset" in the docs. - **Publishing runs through Socket Firewall again, set up so it can't fail the way it did.** The hardening action's `intel: sfw` installs it as root, where it can't write its binary cache, which failed the 0.9.0 publish, so 0.9.0 and 0.9.1 went out without it. The workflow now installs a pinned `sfw` as the job user, in the job that holds no publishing identity. That job no longer restores an npm cache: packages served from it never reach the firewall. CI runs the same install on every push, so a broken firewall shows up before a tag. - **`agent-class.md` no longer carries a copy of the class: 250 KB down to 40 KB.** Before the class could be imported, the reference held its full source for agents to copy, regenerated from `scripts/spark-agent.js` so the two never drifted. Since 0.9.0 it is the `sparkbtcbot-skill/agent` export, but the copy stayed, growing with every feature until it was 210 KB of the references' 463 KB, shipped twice in the package. An agent opening the reference for the method list could pull in thousands of lines of code it didn't need, and a copied class never gets later fixes. The reference now keeps the method list, the error and `status()` tables and the receiving notes, and points at `scripts/spark-agent.js` and `scripts/spark-agent.d.ts`. The package shrinks from 1.38 MB to 1.17 MB unpacked. A new test caps the references' total and per-file size, as SKILL.md's ratchet does for the always-loaded body, and the parity test now checks the method list both ways. - **README: what the version pins actually cover.** It said the exact pins give you "the tree we live-tested" and that upstream security patches reach you only when we cut a release. Both overstated it: only the direct dependencies, the Spark SDK among them, are pinned; the packages below them resolve within the SDK's own ranges at your install, so fixes deep in the tree (this month's `@grpc/grpc-js` one, for example) reach a fresh install without a release from us. It now says so, and that your own lockfile plus `npm ci --ignore-scripts` is what freezes the tree you deploy. ### Added - **`sparkbtcbot rotate`: move everything to a fresh wallet, from chat.** The fix when the recovery words may have leaked, for instance after a chat-only user asked the agent to show them. Bare, it is a dry run. `--execute` writes the new seed and keeps the old one (`~/.spark/retired/`) before a sat moves, sweeps every sat and token Spark-to-Spark, waits for the new wallet to claim them, and only then swaps `seed.enc`. The new wallet keeps the spending limits and a sealed budget (its ledger re-signed with the day's spends kept), and gets privacy and its own backup. The sweep is not counted against any budget or limit: it can only go to the wallet the command generated. `--resume` finishes an interrupted run; it refuses while an L402 purchase is held. The old seed stays usable because its addresses and invoices still pay it: `--check-old` reports what arrived there and `--check-old --sweep` claims and moves it. A token balance spread over more outputs than one transfer takes moves in several transfers; a token that won't move at all (frozen, say) stays in the old wallet, named in the report and the retired wallet's manifest, and the rotation still completes, so a stuck token can't keep `seed.enc` on the leaked wallet; `--check-old --sweep` tries it again. A retired wallet that can't be opened is reported, and the others are still checked (the run then exits 1). Payments made before a rotation show only in the old wallet's history, which `getTransfers()` on the new one doesn't list. The plan and the report say so, `--check-old` lists each retired wallet's recent transfers, and `PAYMENT_COMMITTED`'s `nextStep` says to look there if the wallet was rotated since. `--resume` finishes a run cut off between any two of its writes. It moves the money only between the two wallets that run staged, never to a retired one, and the new seed keeps a spending policy sealed in the meantime. The sealed window is read again at the commit, so a spend recorded during the run stays counted. A deposit lookup that fails is reported as unknown rather than as none, and sats that arrive during the sweep move too. The words are normalized as `SparkAgent.create` does it, and the dry run doesn't ask the operators for a deposit address (asking can create one). Exercised end to end on REGTEST, including a late payment to the old address. For a chat-only user it does not offer the new words as their backup (showing them puts them back in the chat the old ones leaked in); it says to keep the wallet small and move what they want to keep to a wallet they hold, and `security.md` and `first-spend.md` say the same. - **Spending limits the user sets in chat: `sparkbtcbot limits`.** The common setup is now a hosted agent told "install sparkbtcbot for me": it runs in the agent's own sandbox and the user only chats, so the terminal-only `set-policy` ceremony was out of reach and the only budget was an environment variable. `sparkbtcbot limits set` (no terminal, no passphrase) writes the user's limits to `~/.spark/limits.json`: a rolling 24-hour budget (`--daily-budget`), a cap on each payment (`--max-payment`), the operations allowed (`--ops`) and the recipients allowed (`--recipients`); `show` and `clear` do what they say. Every money-moving method checks them in one gate before any network call, dry runs included, and reads the file on every call, so a change applies without a restart. A refusal is `LIMIT_DENIED` with the rule in `err.rule`; the daily budget is counted on the spend ledger and refuses with `SPEND_BUDGET_EXCEEDED`, applied on top of the budget in force (a sealed one overrides `SPARK_DAILY_BUDGET_SATS`), the tighter winning. A file that can't be read or doesn't validate refuses every payment (`LIMITS_UNREADABLE`): a misspelled rule never means "no limit". `agent.limits()` and `status().limits` show them. Limits stay opt-in: setup ends by telling the agent to ask the user whether they want one. They guard against mistakes and casual injection, and change only on the user's own message; the command says when a change loosens a limit and prints the command that puts it back. Replacing a file that couldn't be read counts as loosening, since that file refused every payment. Several `set` calls at once keep every rule: each holds the file's lock while it reads and writes. A hijacked agent can rewrite the file, so the balance stays the only hard limit (`security.md` → Spending limits the user sets in chat). - **`agent.status()`: one look at whether the agent can work, and what to do if not.** It returns `usable`, the `problems` it found (most severe first) and the first one's `nextStep`, with the balance, privacy, backup, budget, spending-limit, held-L402 and event-stream state. There are 17 problem codes (`STATUS_PROBLEMS`), three of them blocking: `AGENT_CLOSED`, `SPARK_UNREACHABLE`, `NETWORK_MISMATCH`. `L402_HELD` lists the unfinished `fetchL402` purchases (method, host and path, never the pass); the error for a paid but undelivered pass now carries `sendId` and `invoiceHash`, so the payment can be found in `getTransfers()`. Normal moments aren't problems: a stream connecting for under 30 seconds, sats incoming for under a minute or locked for under 30 minutes, no budget set, privacy off by the user's choice. It never throws for what it finds. Its reads run in parallel with deadlines (10 seconds for the balance, 5 for the optional Lightning probe), about 100 ms on REGTEST, and after `cleanup()` it makes no network call. `create()` hands the SDK its stream listeners at construction, because `stream:connected` can fire before `initialize()` resolves (REGTEST). - **`getBalance()` reports `incomingSats`: a payment that has arrived but isn't claimed yet.** It returned only the spendable figure and `lockedSats`, so a payment still being claimed read as nothing. On REGTEST, right after reopening a wallet that was paid while closed, 3 of 8 first reads returned 0 sats with the default settings, and 8 of 8 with privacy and the optimizer off; in most of them the SDK's own figures had the payment as incoming, a figure the wrapper dropped. A payment made less than about a second before the wallet opens can stay incoming until the next restart (9 of 15 boots started right after a payment): on Node the SDK claims only as its stream connects, and only transfers older than its estimate of the server's time, which runs up to a second behind because it comes from the second-resolution `Date` header. Nothing is lost: such a transfer doesn't expire back to the payer, and the next open claimed all nine. `status()` reports `INCOMING_UNCLAIMED` after a minute. `wallet.md`, `agent-class.md` and `first-spend.md` ("Did he pay yet?") say to read `incomingSats` as "arrived, being claimed", never "nothing arrived", and to restart the agent's process if it stays. `lockedSats` alone doesn't show that anything arrived: right after boot it can also be the wallet's own send or a failed payment's lock from before the restart. They also say that `onTransferReceived` fires only for payments claimed while the agent is connected (0 calls in 31 boots), so payments made while it was offline are found with `getTransfers()`; `extras.md` says the same of the raw `transfer:claimed` event. The SDK's private claim calls aren't used: the race is the SDK's to fix, and this release makes it visible. - **`getBalance()` gives each token's `available` figure.** `tokens[id].balance` is the SDK's owned balance, which still counts the outputs of a token send that isn't final, so after a send in doubt it read unchanged. `available` is what a send can use now. Neither figure proves a send left; `getTokenTransactions()` is the check, as `tokens.md` and `agent-class.md` now say. - **Type declarations for `sparkbtcbot-skill/agent`.** `./agent` resolves to `skills/sparkbtcbot/scripts/spark-agent.d.ts` (listed before `import` in the exports map, and shipped): every public member, each tagged with what it does to money (`@sideEffect read`, `receive` or `spend`, and `unlock` for `forgetL402`, which moves nothing but lifts a guard against paying twice), the codes it can throw, and `@dryRun read` where a dry run applies. `lib/index.d.ts` adds `AgentError`, `AgentErrorCode` (all 51 codes), `Retryable` and `StatusProblemCode`, and declares the new exports. A test keeps them honest without adding TypeScript: declared and runtime members match both ways, every code the sources raise is in the union and every `@throws` names a real one, and both files parse under Node's type stripping (Node 22.18 and later). ### Fixed - **`fetchL402` no longer buys again when the paid response's body is cut off.** From 0.4.0 to 0.8.0, any failure after paying threw a raw error and the next call bought a new invoice. 0.9.0 retried a dropped connection, a 5xx, a 408 or a 429 with the same pass, but a body that failed mid-read (a reset or crash mid-body, a proxy cutting a large response, the body timeout, a broken gzip stream) still escaped as an uncoded `TypeError: terminated` with nothing held, against `l402.md`'s promise that a dropped connection after payment never buys again. Reproduced against a mock wallet: three retries, three payments, and a server that always cuts the body makes every retry pay, up to `maxAmountSats` each. A cut body is now a failed delivery: a GET is presented again with the same pass, and a POST or PATCH is held and throws `PAYMENT_COMMITTED` (`settled: true`). The paid pass is also held before the first delivery attempt, so an error nobody planned for leaves the next call presenting it instead of buying. Holds still live in memory only; every such error's `nextStep` says to check `getTransfers()` after a restart before calling `fetchL402` for that URL. - **A repeat payment is still recognised under the operators' new wording.** They now refuse a second transfer under a recorded id with "transfer `` cannot be matched to this request" instead of "transfer already exists", so a repeat on the Spark-direct rail fell through to `PAYMENT_COMMITTED`: safe, nothing paid twice, but it no longer named the transfer and kept a duplicate entry against the budget. Both wordings now give `PAYMENT_ALREADY_SETTLED`, and the new one only when it names the id on record. Found by the funded REGTEST suite. - **`PAYMENT_ALREADY_SETTLED` says which transfer to look for.** It told the agent to "confirm it in `getTransfers()`", but a transfer record carries no invoice, so there was nothing to match (eval 64's helper fetched the list and couldn't use it). The error now carries `transferId`, the recorded dedup id the operators refused as a duplicate transfer key, which is the payment's own transfer id: the confirmation is the row in `agent.getTransfers()` with that `id`. Verified on REGTEST: the repeat payment threw `PAYMENT_ALREADY_SETTLED`, `err.transferId` equalled the first payment's transfer id, and the receiver was paid once. - **"Preimage request already exists" no longer turns into a false "already settled".** The operators refuse a second live Lightning payment of one payment hash before they create any transfer. A failed payment deletes the invoice's dedup id, so a retry while its sats were still locked got that refusal and read as "outcome unknown", and the retry after that, under the id now on record, read as `PAYMENT_ALREADY_SETTLED` ("this invoice's payment ALREADY SETTLED") for a payee who was never paid. Once the sats came back, the next retry paid but reported `dedupReused: true`, which means "no new money moved". That refusal is now `PAYMENT_COMMITTED` with `reason: "EARLIER_ATTEMPT_OPEN"`: nothing new was sent, an earlier payment of this invoice is still open, check `lockedSats` and `getTransfers()`. The id it minted is deleted and its budget entry undone. `fetchL402` holds such a purchase with nothing counted, and the call that settles it makes the real payment: checked and counted by the spend budget like any other, and reported `paid: true` with `recovered: true`. `PAYMENT_ALREADY_SETTLED` comes only from "transfer already exists" under a reused id. The refusal's text reaching the wrapper through the SDK's error is read from the operators' and the SDK's source; no live run has produced it yet. - **A `transferId` already recorded for another invoice no longer says to mint a fresh one.** The refusal said "Omit transferId to mint a fresh one". The likeliest reason to reuse an id is one id per purchase, and a fresh id for a re-issued invoice of the same purchase is a real second payment. It is now `TRANSFER_ID_CONFLICT`, `check-first`: that invoice's payment is on record and wasn't shown to have failed, so check `getTransfers()` and don't pay this invoice if it is for the same purchase; omit `transferId` only for a different payment. It also says when the other entry was recorded. Reaching it takes a hand-passed `transferId`; the docs already said never to share one across invoices. - **A preimage that doesn't prove the invoice stops `fetchL402` from buying that URL again.** `payAndSettle`'s mismatch error had no code: it is now `PREIMAGE_MISMATCH` (`check-first`, with `sendId` and `invoiceHash`). `fetchL402` rethrew it with nothing held, so a retry loop bought again; now it blocks the URL with `L402_NO_PROOF` until `forgetL402`, on the user's say-so, as it already did for a mismatch found while settling a held purchase. Nothing known produces such a preimage inside `fetchL402`; this closes the path should the SSP ever report a wrong one. - **A `fetchL402` purchase that didn't finish is held on disk, so the next process finishes it instead of buying again.** Holds lived in memory only. A chat agent often runs each tool call as a new process, so after a payment in doubt, or one paid but not delivered, the retry started clean: it fetched a new challenge, with a new invoice the dedup store can't recognize, and paid again, while the paid pass was lost. Since 0.4.0. Each hold is now a file in `~/.spark/l402-holds/` (`SPARK_L402_HOLDS_PATH`), mode 0600. It holds the invoice, the macaroon and the send's id, never the preimage (read back from Spark) and never the query string. `fetchL402` claims it before paying, so a second process buying the same request is refused with `CONCURRENT_PAYMENT_ATTEMPT`, and a process that dies mid-purchase leaves its invoice for the next one to settle through the dedup store. The file goes once the resource is delivered, the payment is proven failed with its sats back, or `forgetL402` lifts it on the user's say-so. A file that can't be read refuses the purchase (`L402_HOLD_UNREADABLE`, `check-first`). - **Two overlapping `fetchL402` calls for the same URL no longer each buy a pass.** Nothing marked a URL as being bought until its payment returned, so a second call during that window (a duplicated tool call, or a host timeout retried while the first call still ran) fetched its own challenge and paid that invoice too, a different invoice each time, which duplicate protection can't catch. Present since `fetchL402` shipped in 0.4.0. Now one purchase per method and URL runs at a time in a process: an overlapping call for the same request joins it and gets its result or error (`joined: true`, `paid: false`); one with a different body is refused with `CONCURRENT_PAYMENT_ATTEMPT` before anything is fetched or paid. - **A failed send can no longer erase a real one from the daily budget.** When a send fails before anything leaves, its budget entry is removed again; that removal (read the ledger, drop the entry, write it back) ran outside the lock that serializes budget writes, so a real payment recorded in between was written back out. Parallel sends where some fail early, the runaway case the budget exists for, could spend past the limit, and a seed-bound ledger was re-signed with the entry missing. The removal now takes the same lock. - **One attempt failing can no longer erase the duplicate-payment record another attempt is paying under.** Two `payLightningInvoice` calls for the same invoice in one process share one `transferId`. When one of them was refused before sending (its sats were locked by the other, for example), it deleted the invoice's dedup record while the other was still paying; a stale settle poll could likewise delete a newer attempt's record. If the remaining payment's outcome was then unknown, the retry its error called safe minted a fresh id, which on the Spark-direct rail is a second payment, and an expired invoice was reported as plain `INVOICE_EXPIRED` instead of `INVOICE_EXPIRED_AFTER_ATTEMPT`. Since 0.9.0. A record is now deleted only while no other attempt in the process holds it, and only if it still holds the deleting attempt's id (`forget(bolt11, expectedId)` in `lib/transfer-ids.js`). The error says a retry is safe only after checking that the record still holds this attempt's id. - **Bad input gets a coded error, never a raw `TypeError`.** A missing or `null` options object threw on destructuring. A BigInt in a message (a declared type for amounts) made the message builder itself throw, so the coded error was never built. Both happened in `transfer`, `transferTokens`, `claimDeposit`, `withdraw`, `payLightningInvoice`, `payAndSettle`, `fetchL402` and others. Now `null` reads as "no options" where they're optional, a missing or non-object bag is `BAD_INPUT` (`field: "options"`), and messages format BigInts. A `fetchL402` body that can't be sent as JSON is `BAD_INPUT` (`field: "body"`) before anything is fetched, and `transfer({})` / `withdraw` without an amount refuse up front instead of reaching the SDK. An invoice string that doesn't decode as BOLT11 is `INVOICE_INVALID` (`field: "bolt11"`) in `payLightningInvoice`, `payAndSettle` and `estimateLightningFee`; it used to ask for `amountSats`, an amount for a string nobody could check. `SparkAgent.create` checks a string recovery phrase against the BIP39 wordlist and checksum (`@scure/bip39`, now a direct dependency): anything else is `BAD_INPUT` (`field: "mnemonic"`), never echoed, where it used to come back as `SPARK_REFUSED` with characters of the input in the message. Case, extra spaces and a trailing newline are normalized first; a seed as bytes passes through. - **A paid L402 request keeps its JSON content type.** The challenge request sent `Content-Type: application/json`, the paid one didn't, so `fetch` labelled the JSON body `text/plain` and JSON servers answered 400, 415 or 422 to the request just paid for. `fetchL402` returned that as the service's answer and released the pass, so the natural retry paid again: in one test, three payments for one result. Every POST, PUT or PATCH with a body was exposed, released versions included. The paid request now carries the same content type, and a caller's own `content-type` or `authorization` header, in any spelling, is kept or replaced rather than joined with ours (a joined `authorization` made the service refuse the pass after paying). - **Two processes no longer buy the same L402 resource one after the other.** A second process that found another one mid-purchase was told "call again: it finishes that purchase", but once the first process delivered and removed its claim, that call bought a second pass. `fetchL402` now waits, up to 90 seconds, and then says what happened: bought by the other process (another call would be a second purchase), held by it (calling again finishes it), or still being bought. A process finishing late no longer deletes another process's fresh claim. - **After paying, a redirect from an https service to `http://localhost` or `127.0.0.1` stops** like any plain-http hop. The localhost exemption now applies only when the URL given was itself local. A held purchase that the spending limits refuse to settle now says the earlier attempt may have paid, instead of only "Nothing was sent". The cache example in `l402.md` hands back a redirect rather than following it with the pass, matching the example script. - **`fetchL402` decides which redirects to follow, instead of leaving it to `fetch`.** `fetch` followed every redirect. Before paying, that meant the challenge could come from a hop the URL check never saw, so the invoice could be swapped over plain http, and a payment made off a hop to another host was refused at delivery: paid, nothing delivered. After paying, `fetch` already dropped the pass on a hop to another host, but measured on Node 24 it still forwarded the caller's other headers there (an API key, say) and re-sent a POST body. Now no redirect is followed before paying: `fetchL402` and `previewL402` throw the new `SERVICE_REDIRECTED` (`no`, nothing paid) with `err.location`, where they used to pay or report "no payment required". After paying, a same-origin redirect is followed with the pass, a redirect to another https host is followed with no pass, no caller header and no body, and anything else (plain http, a POST body bound for another host, more than 5 hops) stops with the pass held. A redirect on the example's cached pass is handed back as the answer, and `assertHttpsUrl` now accepts `[::1]` as the URL parser writes it. Tested against real `fetch` on loopback servers as well as stubs. - **A paid L402 pass answered "try again" or "forbidden" no longer leads to a second purchase.** After paying, only a 5xx, 408 or 429 was retried and only a 401 or 402 counted as a refusal. Every other status released the pass, so a 409, 423 or 425 that a client naturally obeys bought again on the retry. Those three are now retried with the same pass, and if they persist the pass is held, so the next call presents it without paying. A 403 is `L402_PASS_REFUSED`, like a 401: the URL stays blocked until the user lifts it. Other statuses (400, 404, 410, 422) are still the service's answer: returned with `status`, pass released. `l402.md` has the table, and SKILL.md and the types say a non-2xx result is paid for, so calling again buys again. - **`LIGHTNING_PAYMENT_FAILED` says to judge by the balance, not the status.** Its `nextStep` pointed at `getLightningSendRequest`, and a plan that waited for `USER_SWAP_RETURNED` could wait forever: the SSP can leave a refunded send at `LIGHTNING_PAYMENT_FAILED`. It now says to wait until `lockedSats` no longer holds the sats and `sats` has risen by about that much. `lightning.md` and `agent-class.md` say the same, and eval 63 quotes the new text. - **A respelling of the same L402 request finds its hold.** Holds were keyed on the URL string, so the same request spelled another way (host case, an explicit `:443`, a `#fragment`, `/x/../`) missed a paid, undelivered pass and bought again. The key is now the URL as sent (`new URL()`, fragment dropped), in `forgetL402` too. Query order and a trailing slash still count as different resources: they can be, and one resource's pass is never presented for another. - **A recovered L402 POST is marked sent once before it goes out.** A POST finishing an earlier purchase was marked only after its delivery failed, so a process that died mid-request left the next one sending it again without `{ resend: true }`. - **`payAndSettle` refuses a bad `pollMs` or `maxPolls` before sending.** A string, a negative or a fraction polled about every millisecond, or not at all, and returned `settled: false` within 0.1 s for a payment that settled 3 s later. Each must be a whole number from 0 (`maxPolls: 0` still skips polling); anything else is `BAD_INPUT`, with nothing sent. - **`annotateError` can't make an error less safe than it already is.** It is exported, and relabelling a `check-first` error with a code whose default is `yes` (host glue turning a `PAYMENT_COMMITTED` into `SPARK_UNAVAILABLE`) gave "yes" and "Nothing moved"; a retrier that trusted it sent twice. The level now starts at the safer of the new code's default and the error's own `retryable`; only an explicit value the registry allows goes lower. Outside tests, a `retryable` nobody can read is `check-first`, and a `code` passed among the facts no longer overrides the code. - **A Lightning invoice whose embedded Spark invoice doesn't fit it is refused with nothing sent, not as an unknown outcome.** Spark-direct is the default for an invoice that isn't hash-bound. When the Spark invoice inside it had a different amount, had expired, named another payer or was a tokens invoice, the SDK refused it locally, before any request. The wrapper reported `PAYMENT_COMMITTED`, kept the spend and said a retry was safe, so each retry counted the amount again until the budget was spent. With the default options the invoice could never be paid. It is now `INVOICE_INVALID` ("no"), nothing is counted, and the `nextStep` says `{ preferSpark: false }` pays it over Lightning. - **An explicit `transferId` that already names another transfer is `TRANSFER_ID_CONFLICT` on the first attempt.** Its record could be gone: pruned a day after its invoice expired, or written under another dedup directory. The operators then refused the payment as an existing transfer, the wrapper reported an unknown outcome and said retrying was safe, and the retry read the same refusal as this invoice already settled, pointing at the other transfer. The first attempt now says that id belongs to another transfer, with nothing sent and nothing counted. - **An L402 purchase cut off before it paid no longer blocks the URL for good.** Suppose a process died after claiming a purchase but before any payment reached the SDK, for example during the fee estimate. Once that invoice or pass expired, the next call blocked the URL with "the earlier payment may have gone through", though the Lightning dedup store showed no attempt. With no entry on record, and while one would still be kept (until a day after the invoice expires), the hold is now dropped and the call buys afresh under the usual checks. With an entry, or a store that can't be read, the block stays. - **`cleanup()` during a send that hasn't reached the SDK yet is `AGENT_CLOSED`, with nothing counted.** It could land while the spend was being recorded, and the send then read as `PAYMENT_COMMITTED` with the spend kept, though nothing was sent. Each send now checks the agent is still open right before the SDK call. Also, `create()` closes the opened wallet when the agent can't be built on it (`BAD_CONFIG`, `POLICY_NOT_LOADED`), instead of leaving it running in the background. - **The daily budget counts Lightning fees, and dry runs check it.** A Lightning payment counted its amount only. Under the 25-sat fee floor that left a payment's fee out of the daily total, up to 25 times the budget on 1-sat invoices. It now counts the amount plus the fee estimate, or plus the fee cap when there is no estimate; a payment that goes over Spark has no fee, so it over-counts slightly. The budget was also checked only at the send, after the dry-run return and after the fee estimate or withdrawal quote. A dry run therefore previewed a payment the send then refused, though the docs said dry runs are checked. `transfer`, `payLightningInvoice`, `fulfillInvoice` and `withdraw` now check the amount against the budget before any network call, dry runs included, and the send checks again with the fee. - **Parallel spends can't overrun the daily budget.** The budget check and the record were two separate reads and writes of the ledger file. Tool calls running as parallel processes all passed the same check, and their writes overwrote each other's. Six processes paying 1,000 sats each under a 3,000-sat limit sent 4,000 to 6,000 sats in every one of 10 trials, and the ledger kept as little as 2,000, which also left room for later spends. The check and the record now run under one lock file (`spend-ledger.json.lock`), which also covers two agents in one process. A lock left by a process that died, or older than 10 seconds, is broken. `createSpendLedger` gains `reserve()`, which checks and records in one call; calling `assertCanSpend()` then `record()` is still a race. - **`cleanup()` while a payment is still settling no longer leads to a second purchase.** The closed agent's wallet threw `AGENT_CLOSED` out of `payAndSettle`'s status poll, after the payment had been sent. `fetchL402` took that for a refusal before paying, dropped its hold, and the next call bought again. A one-shot script that races a timeout and calls `cleanup()` in `finally` was enough, and a paywall that holds the payment open can widen the window. `payAndSettle` now stops polling once the agent is closed and returns the payment as sent without proof, which `fetchL402` holds. Anything else that goes wrong after the send becomes `PAYMENT_COMMITTED` with the send's id. - **After `cleanup()`, nothing reaches Spark through the agent.** Only `status()` knew the agent was closed. The SDK recreates its clients on demand, so reads, invoices and sends still worked, with the backup already stopped. Money methods and `fetchL402` now refuse first with `AGENT_CLOSED` ("no", nothing sent). Anything else that reaches the closed wallet gets `AGENT_CLOSED` as `check-first`, since a payment already under way may have sent. A second `cleanup()` waits for the first, and `vaultHealth()` reports `disposed: true`, never healthy. - **A `create()` that fails half-way closes the wallet it opened.** The SDK starts the wallet's stream, which claims on connect, before its first sync, and stops nothing when that sync fails. Each retry of a flapping open left one more live wallet claiming in the background. `create()` now closes the half-open wallet before it throws `SPARK_UNAVAILABLE` ("yes": a claim only brings this wallet's own money in). - **The L402 example script pays through `fetchL402`.** `scripts/l402-paywalls.js` and the "Implementation" section of `l402.md` hand-rolled the purchase on the raw SDK, with none of the wrapper's guards, and any failure after paying (a cut body, a non-JSON body, a refused pass, no preimage yet) lost the paid pass, so the next call bought another. Both now call `agent.fetchL402`; the example adds only a per-origin, https-only pass cache, which also keeps a recovered pass. The protocol sketch stays in `l402.md`, marked for reading only. The script previews by default and pays only with `--pay`. - **`lockedSats` is described as what it is.** Docs, types and the `INSUFFICIENT_FUNDS` hint called it "on its way in" or "arrived". Right after a restart it can as well be this wallet's own send still in flight, or a failed payment's lock, so it alone never proves a payment arrived; `incomingSats` does. The SKILL.md balance snippet and `balance-and-deposits.js` now print the arriving figure, so a script copied from them doesn't report "nothing arrived" for a payment being claimed. - **The no-seed message names the installed command.** It said `npm run setup` in the skill repo, or the setup script "wherever this lib was copied from"; an npm install has neither at hand. It now says `npm exec --no -- sparkbtcbot setup` where the package is installed, or `npm run setup` in a clone. - **A Spark invoice passed as an address named the wrong call.** The refusal said `fulfillInvoice([invoice])`; the method takes `fulfillInvoice([{ invoice }])`. ## 0.9.1 — 2026-10-27 A docs-only patch to the skill: how the agent hands over an invoice or an address. No code changes. ### Changed - **How to hand over an invoice or address, in plain words.** SKILL.md said "paste string always, QR only where the surface renders it", which a review read as jargon, and a second review noted that "copyable" was met by an inline code span. The receive rules now say, for anything handed out: the string alone in a code block (so chat apps show a copy button), plus its QR if the chat shows images, never a QR alone. `first-spend.md` spells it out: nothing else in the block, no line breaks inside the string, the string on its own line where the chat doesn't render markdown, and the QR of that exact string. ## 0.9.0 — 2026-10-27 spark-sdk 0.14 with the SDK's fee ladders forced off, and the money paths hardened against what three review rounds and a day of real REGTEST payments turned up: an expired invoice that locks the payer's coins, a single-use deposit the operators won't claim, a paywall retry that buys twice, a forged ledger entry that empties a sealed budget. Each fix below names the failure it closes, and the funded REGTEST tier now pays real invoices end to end, a local L402 server included. ### Upgrading from 0.8.0 - **`getSingleUseDepositAddress()` throws** (`SINGLE_USE_DEPOSITS_UNAVAILABLE`): the operators refuse to claim single-use deposits. Use `getDepositAddress()`. Coins already sent to a single-use address show in `listPendingDeposits()` as `type: "single-use"`; they arrived but can't be claimed now. - **`claimDeposit` checks the deposit itself**: it claims only a deposit at the static address (`DEPOSIT_NOT_FOUND`, `DEPOSIT_LOOKUP_INCOMPLETE`), the default fee ceiling stops at 25,000 sats, and `maxFeePct` must be 0–100. - **`payLightningInvoice` refuses** an expired invoice (`INVOICE_EXPIRED`), and an invoice with two payment hashes or a malformed one. - **More failures are `PAYMENT_COMMITTED`**: any error that doesn't prove nothing was sent. Treat it as "the money may have left": never pay again with a new invoice, address or method; check `getTransfers()` (token sends: `getTokenTransactions()`). - **`fetchL402` stops on a refused or doubtful purchase**: that URL is blocked in the process until `forgetL402(url)`, on the user's say-so. A POST is re-sent only with `{ resend: true }`. - **Importing `sparkbtcbot-skill/agent` no longer loads `.env`**: add `import "dotenv/config"` to your app. - **A payment bound to a payment hash goes over Lightning**, never Spark-direct; `preferSpark: true` with `expectedPaymentHash` throws. - **Opening wallets yourself?** Pass `sparkWalletOptions()` so the fee ladders stay off; SDK 0.13+ turns them on by default. - **Additions**: `createTrackedInvoice` / `getInvoiceStatus`, `getTokenTransactions` / `getTokenTransaction`, `getBalance().lockedSats`, `feeSats` on Lightning results, the time window on `getTransfers`, and the `sparkbtcbot-skill/agent` export. ### Security - **A forged spend-ledger entry can no longer hollow out a sealed budget.** `set-policy` signed an unsigned, agent-writable ledger as it stood, and the validator accepted a negative or fractional entry, so one planted `{ sats: -15000000 }` let 15,000,000 sats through a sealed 20,000-sat budget. Entries must now be non-negative whole sats everywhere a ledger is read, written or signed (`record()` rounds a fractional amount up; it used to write one that every later read rejected). `set-policy` also treats a missing or unsigned ledger under an already-sealed budget as tampering (nothing changes; `reset-ledger` is the deliberate path), and re-checks the ledger before it rewrites the seed rather than after. This regression came in with the earlier `set-policy` port on this branch; found by the Trail of Bits review of 2026-10-26. - **`fetchL402` no longer pays twice when the payment itself fails ambiguously.** If the pay call threw `PAYMENT_COMMITTED` or `PAYMENT_ALREADY_SETTLED`, or a status read threw while `payAndSettle` waited, nothing was held, so the documented "call again" bought a fresh invoice. Now the purchase is held and the next call settles that same invoice through the dedup store (with `SPARK_LN_DEDUP=off` it refuses and says to check transfers), and a failed status read is treated as no news. Also: a 408 or 429 on delivery is retried with the same pass; a POST or PATCH is presented once, never re-sent; a 401/402 after paying throws `L402_PASS_REFUSED` instead of returning the server's new challenge as data; the minimum token lifetime is 120 s (it was 60, the whole polling window); `maxAmountSats` reaches the payment. - **Importing `sparkbtcbot-skill/agent` no longer loads the host app's `.env`.** The module ran `import "dotenv/config"`, so a planted `./.env` could switch off dedup, the backup or privacy, or set `NODE_TLS_REJECT_UNAUTHORIZED=0` for the `fetch` paths. Only the runnable demo loads dotenv now; a test pins it. - **Merchant strings never reach a shell as text** (`merchant-spending.md` §1a, mirrored in `bitrefill.md`, `cryptorefills.md`, `nadanada.md`, `l402.md`). The shipped code never shells out; the injection surface is the agent composing a command line — Bitrefill's CLI `--cart_items`, a `curl` against a directory URL, nadanada's REST — from catalog values. Rule: prefer MCP/JS over a CLI; when a CLI is the path, argv arrays or a JSON file, validate ids (`^[A-Za-z0-9][A-Za-z0-9._-]*$`, no `..`) and URLs (`https://`, plain host) first, never interpolate, never `eval`/`sh -c`, never `echo` a code into a pipeline. Eval 13 gains the assertion; new eval 39 hands the agent a product id shaped like `x'; curl … | sh; '`. The rule treats every seller-controlled field as hostile. - **A merchant checkout's payment-hash check now holds when the invoice carries a Spark fallback.** `SparkAgent` pays an invoice from a Spark wallet Spark-direct: a plain transfer to the fallback key, free, with no preimage. That transfer ignores the payment hash, so the merchant helper's check (the invoice must carry the hash the checkout echoed) protected nothing on that route. A fallback added to the merchant's invoice keeps its hash, amount and description, since the SDK checks the signature only when the invoice has an `n` tag. Any Spark user can also get a properly signed invoice that carries a hash they choose and their own fallback. `payLightningInvoice` and `payAndSettle` now take `expectedPaymentHash`: the wrapper refuses an invoice without that hash before anything is sent, then pays over Lightning, where the payment completes only against that hash's preimage. `preferSpark: false` turns Spark-direct off without a binding, and the dry-run preview reports which applies. `payMerchantCheckout` (`references/merchant-spending.md`) passes both, so merchants are always paid over Lightning; every other payment keeps Spark-direct. Tested through the real SDK `payLightningInvoice` with a fallback spliced into a signed invoice, and on REGTEST, where a Spark wallet's invoice settled Spark-direct unbound and over Lightning, with a preimage matching the hash, when bound. - **An invoice with two payment hashes no longer passes the hash check.** `invoicePaymentHash` read the first `p` field and the SDK pays under the last, so an invoice carrying the checkout's hash and then another passed `paymentHashMatches` and paid under the other. It now returns null unless the invoice has exactly one 32-byte payment hash, and the check fails. - **`fetchL402`'s second call, after a payment that may have gone through, is safe to make.** Every error on that path is now `PAYMENT_COMMITTED`; before, a raw `"exceeds available balance"` (likely because the first payment went through) read as "nothing was sent". Settling the held invoice again no longer counts against the budget a second time (one 2,000-sat purchase used to fill a 10,000-sat budget in five calls). It re-reads the token first and won't pay for a pass the service has declared dead. Three outcomes stop the purchase for good in that process, each a `PAYMENT_COMMITTED` with a `reason`: the service refused the paid pass (`L402_PASS_REFUSED`, which was a plain error that forgot the purchase, so a retry loop bought again), the pass died first (`L402_PASS_EXPIRED`), or the payment ended with no proof (`L402_NO_PROOF`, which used to read as "still pending" forever). `agent.forgetL402(url)` lifts it, on the user's say-so. A POST or PATCH that may have reached the service is sent again only with `{ resend: true }`; "call again" used to place a second order on the same pass. - **An invoice whose one payment hash isn't 32 bytes is refused before paying.** It passed the two-hash check, read as having no hash, and the preimage check then accepted any preimage. - **`claimDeposit`'s default fee ceiling stops at 25,000 sats**, and `maxFeePct` must be 0–100 (also on `withdraw`). 10% of a 0.49 BTC deposit allowed a 4,900,000-sat fee against a spread of a few hundred, and `maxFeePct: 1000` was accepted. An explicit `maxFeeSats` still goes past the cap. - **`payLightningInvoice` refuses an expired invoice before the SDK sees it.** Paying one through the raw SDK doesn't just fail: on hosted REGTEST the SDK moved 303 sats into a transfer to the SSP, the SSP then refused the send, and the transfer sat at `SENDER_KEY_TWEAK_PENDING`, expiry 16 days out, with no way to cancel it, until the SSP returned it about an hour later (REGTEST; mainnet untested, and Spark's docs promise no return time). `SparkAgent` now throws `INVOICE_EXPIRED` for an invoice that has expired or has under 30 seconds left, before any SDK call (so `payAndSettle`, `fetchL402` and the merchant helpers refuse it too). Spark documents the lock ("Check expiry before paying": the SDK doesn't check expiry before the swap, and the 16-day expiry "is not a guaranteed refund time"). When the dedup store holds an earlier attempt at the same invoice, the refusal is a `PAYMENT_COMMITTED` (`reason: "INVOICE_EXPIRED_AFTER_ATTEMPT"`; a different word from the plain refusal's `code: "INVOICE_EXPIRED"`, so code that checks either can't mix them up) instead: the retry an unclear outcome invites would otherwise have said "ask for a new invoice", and paying that would have been a second payment. In `fetchL402`'s retry the same case is a block, `L402_INVOICE_EXPIRED`. An attempt that provably sent nothing (refused by the spend budget, or by the SDK before sending) no longer leaves a dedup entry behind to read as an earlier attempt later, and the plain refusal says to check `getTransfers()` first if an earlier attempt's outcome was unclear (it can't know once the store has pruned the entry, or with dedup off). The raw-SDK example script and the `l402.md` and `lightning.md` snippets check the expiry before paying, and `getBalance()` reports `lockedSats` (owned minus available), so locked sats read as locked rather than missing. - **`fetchL402` never drops anything it holds.** The held map dropped its oldest entry at 100, so 100 other holds later a refused URL, or a purchase that may have paid, was bought again on nobody's say-so. Nothing held is dropped now; at 1,000 unresolved purchases in one process, a new one is refused before paying. A block's error now names the call that lifts it (`forgetL402(url, { method: "POST" })` for a POST) and carries the invoice hash and amount, and `{ resend: true }` refuses a body that differs from the request it re-sends. - **No instruction tells you to run bare `npx sparkbtcbot …`.** Run from a directory without the package installed, bare `npx` fetches whatever the registry has under that name and runs it, with no prompt in a non-interactive shell, and these commands (`reset-ledger`, `set-policy`) run next to the seed with the passphrase. The runtime errors that agents copy literally (`lib/spend-ledger.js`, `spark-agent.js`), `security.md`, `encrypted-seed.md` and three eval assertions now say `npm exec --no -- sparkbtcbot `. The README no longer calls the retired command names unclaimed (they are project-owned stubs that refuse and explain) or says `--no` means nothing runs: it refuses only to install, so a cached, global or parent-directory copy still runs; run from the project or call `./node_modules/.bin/sparkbtcbot`. A docs-lint rule fails on any bare `npx`, `npm exec` or `npm x` without `--no` before a `sparkbtcbot` command in docs, evals and sources (#14). Evals 7, 19, 20 and 36 haven't been re-run since their assertions changed. - **The publish workflow runs no dependency code where the publishing token lives.** One job held `id-token: write` while `npm ci` and `npm test` ran the whole dev tree (vitest, vite, a native rolldown binary), so a compromised dev dependency could have rewritten a file between checkout and `npm publish`, and the provenance attestation would have vouched for it. Now a `test` job with read-only permissions installs, hardens and tests; a separate `publish` job checks out the same commit, installs nothing, checks the tree is untouched and publishes. npm is pinned (11.21.0) instead of `@latest`, which ran before the hardening step and so was never age-gated. The install no longer goes through Socket Firewall (`intel: sfw`, added after 0.8.0): its first run, this release's publish, failed closed on a permissions bug in the hardening action, so 0.9.0 ships with 0.8.0's install hardening (48-hour age gate, install scripts blocked, the verify step) and the malware blocklist comes back once the action is fixed. ### Changed - **spark-sdk 0.12.0 → 0.14.0, issuer-sdk 0.1.48 → 0.2.1, with the SDK's fee ladders turned OFF.** Nothing this package calls was removed or changed shape; the APIs 0.13 and 0.14 dropped (`queryTokenTransactions`, the V2 token path, the `start_transaction`/`commit_transaction` RPCs) were never used here. What the upgrade brings: 0.12.1 fixes `getBalance` reading **zero sats with no error** after a session token expired on a non-coordinator operator; 0.14 adds amountless-invoice Lightning quotes and silent-payment (`sp1q…`) withdrawals, neither wired into `SparkAgent`. What it would have changed without this release: 0.13 turns on two fee ladders by default. With the refund ladder, each claim gives a leaf of about 1,024 sats or more a refund with no anchor and no fee, and hands the operators up to 24 fee steps signed with the leaf key; the top step leaves the owner 330 sats. The node-hop ladder signs fee variants of the direct transaction when a refund timelock is renewed. On hosted REGTEST every step verified as a fully signed, broadcastable transaction, and every claim sent a new set. A leaf-vault backup holding one anchorless refund fails as a whole in the exit tool it is made for, and the operator code that stores and publishes the steps isn't public yet. So every wallet this package opens now passes `sparkWalletOptions()` (new, exported with `FEE_LADDERS_OFF`), which forces both options off whatever else is passed: `SparkAgent`, `setup`, `leaf-vault`, `viewer`, the example scripts, the test helpers, and every `initialize` snippet in SKILL.md and the references. A test fails if a call site in the scripts, the references, SKILL.md, README or AGENTS.md skips it, or if any of them writes wallet options as a raw object, prose included (a SKILL.md sentence on one-shot scripts did, and turned both ladders on). `SparkAgent` warns at construction when it's handed a wallet that was opened with a ladder on. The options belong to the wallet object, so code that opens the seed through the raw SDK must pass them too (`unilateral-exit.md` → fee ladders). Off is reversible; fee steps already handed over are not, which is why the default is not taken until the operator side can be checked. ### Added - **`agent.getTransfers(limit, offset, createdAfter | createdBefore)`** passes the SDK's time window through (one bound, a `Date`), and `spark-invoices.md` says how to match a payment to its invoice: `transfer.sparkInvoice`, present on the payer's and the receiver's records. The operators' clock can run seconds behind yours, so leave a margin when filtering by time. - **The full eval set, run together for the first time: all 45 plus eight new ones (53–60).** Run with a different model, with-skill, on paper. No money-path regression; the misses are reply shape, and stale assertions in evals 2, 5, 23, 33 and 59 are corrected (`eval-notes/NOTES.md`, `eval-notes/findings-2026-10-27.md`, `eval-notes/rerun-corrected-2026-10-27.md`). The run notes moved from `skills/sparkbtcbot/evals/` to `eval-notes/` and no longer ship in the package: they keep old graded answers, including ones now known wrong, where an agent searching the installed skill could read them as advice. `evals.json` and `trigger-eval.json` stay with the skill. - **`createTrackedInvoice(amountSats, memo)` and `getInvoiceStatus(id)`: one invoice per order that the shop can check.** `createLightningInvoice` returns only the BOLT11, and its default Spark fallback lets a Spark wallet pay with a plain transfer: on hosted REGTEST the money arrived and the invoice stayed `INVOICE_CREATED`. A tracked invoice needs an amount and has no fallback, so every payer pays over Lightning. `getInvoiceStatus(id)` reads the SSP's status as a `state` a shop can act on (`unpaid`, `in_progress`, `received`, `paid`, `failed`, `failed_after_payment`, `unknown`), with `customerCharged`, `expired` and `canReinvoice`, which turns true only two minutes after expiry while unpaid or failed: an early failure may not be final, and re-invoicing sooner could charge a customer twice. The states are inferred from the SSP's schema and the operators' preimage swap in the Spark repo; SDK 0.14 reports the SSP's newer statuses (`HTLC_RECEIVED`, `HTLC_FAILED`, …) as `FUTURE_VALUE`, read as `unknown`. Funded REGTEST tests pin a payment on defaults, an expired invoice, a shop wallet closed while it was paid, and the untrackable fallback invoice. - **`getTokenTransactions({ tokenIdentifier, limit })` and `getTokenTransaction(hash)`**, where to look after a token send threw `PAYMENT_COMMITTED`: `getTransfers()` lists sats only, and SKILL.md's rule now says so. Entries come back newest first (the operators page oldest-first, so a plain query returned the wallet's oldest transactions) and readable: hex `hash`, `status` (`finalized`, `pending`, `cancelled`), `type`, and each output's recipient address and key (compare by key: one key has a legacy `sp1…` and a `spark1…` address), whether it is this wallet's, token and amount. The order relies on undocumented operator behavior (no cursor plus `direction: "PREVIOUS"` returns the newest page); the funded test fails if that changes. A send's hash, as `transferTokens` returns it, finds it directly. Pinned by a funded REGTEST test with real token sends. - **`batchTransferTokens(transfers, { dryRun })`**, with a preview that lists each entry and each token's total. - **Withdrawals to BIP-352 silent payment addresses, documented and tested** (spark-sdk 0.14). `SparkAgent.withdraw({ to: "sp1q…" })` already passed the address straight to the SDK, which now accepts version 0 silent payment addresses (`sp1q…` mainnet, `tsp1q…` testnet/signet, `sprt1q…` regtest) and verifies the SSP's proof before signing. `wallet.md` → Silent payment addresses covers the call, why an explorer search for the address finds nothing (hand over the txid), the `sp1q…` vs legacy `sp1p…` Spark-address prefix, exact-match allowlist entries, and the two SDK calls that refuse them. New funded REGTEST test (`silent-payment-withdraw.test.js`): a withdrawal through `SparkAgent` to an address built from our own keys, scanned on the explorer by an independent BIP-352 receiver (`tests/helpers/silent-payment.js`, pinned to the BIP's own vectors in `tests/unit/silent-payment-helper.test.js`). It finds output 0 carrying exactly `amount − quoted fee` under those keys and no others. It also checks that a mainnet address is refused on REGTEST, that the default 10% fee ceiling still applies, and that a Spark transfer to one is refused, all before anything moves. - **What the skill can and can't do on L1, written down** (`references/wallet.md` → On L1, with a rule in SKILL.md and pointers in `architecture.md` and the README). It is a Spark wallet, not an L1 wallet. On-chain it sees only its own Spark deposit addresses, through the operators, who answer only for addresses they issued (an arbitrary address returns an error, checked on REGTEST). It can't read any other address, including ones another wallet derives from the same mnemonic (Spark's keys sit at `m/8797555'/…`), and it can't spend L1 coins outside Spark. The section lists every L1 operation the SDK offers, wrapped or raw: deposit addresses, deposit status, claims (including the untested instant claim), static-deposit refunds, withdrawals, the SSP's withdrawal record, unilateral exit, watchtower-leaf recovery and `broadcastTx`. It also lists every call where the SDK queries its block explorer itself (one Esplora server, `mempool.space` on MAINNET unless `electrsUrl` is set, which two standalone helpers ignore). That includes the deprecated `getLatestDepositTxId`: it takes any address, and it returns `null` on a server error too, so a `null` doesn't mean nothing arrived (both checked on REGTEST). And it says what the agent should tell a user whose coins went to another address. SKILL.md also notes that `listPendingDeposits()` covers the static address and any unclaimed single-use ones. New user-story eval 50. - **What to do instead of an address per order, and what to tell someone whose coins are stuck** (`references/wallet.md`, with a line in SKILL.md). One static address serves the wallet; to tell payers apart, give each order its own `createTrackedInvoice` (below). A txid an on-chain customer sends proves nothing: the address is shared and its transactions are public. Coins already at a single-use address arrived and wait on the operators: back up the recovery words, and follow buildonspark/spark#165. Evals 51 and 52 cover both. - **Which payment hash each merchant gives you.** `bitrefill.md` now says the checkout returns none (pass `expectedPaymentHash: null`), and its payment step points only at `payMerchantCheckout`; `nadanada.md` says to bind to `data.paymentHash`. An eval agent had guessed the Bitrefill answer. - **Don't put the agent's recovery words into another wallet app** (`references/security.md`). That app gets the same full control, the addresses it shows are invisible to the agent, and a Spark app opens the wallet with its own fee-ladder setting. `reveal-mnemonic` says so on screen. Both eval-50 runs raised the shared-seed risk unprompted. - **A silent-payment withdrawal's txid isn't proof of who was paid** (`references/wallet.md`), and `verifyVault()` is read by its `ok` (`references/unilateral-exit.md`). ### Fixed - **`encrypted-seed.md` no longer suggests `reset-ledger` to make a budget take effect.** The running-agent warning applied only to an agent with an `.env` budget, and nothing said `set-policy` creates or signs the ledger itself, so an eval answer told a user to run `reset-ledger`, which empties the spend window, as a binding step. The two cases are separate now; without an `.env` budget a running agent keeps no ledger and simply spends unbudgeted until restarted. - **`claimDeposit` checks the static address first.** A failing single-use address query used to fail static claims too, and a server that ignored the paging offset kept the lookup going forever; it now stops at a repeated page or after 10,000 UTXOs with `DEPOSIT_LOOKUP_INCOMPLETE` ("can't tell"), not "not found". - **The samples load `.env` again.** Since importing `sparkbtcbot-skill/agent` stopped loading it, the code `setup` prints and the Usage samples in `l402.md` and `agent-class.md` failed with `NO_PASSPHRASE` for anyone keeping the passphrase in `.env`. Each now starts with `import "dotenv/config"`. - **`set-policy` says to stop the agent first.** An agent started before the first bind keeps the old policy and rewrites the new signed ledger unsigned on its next spend, which the bound boot then refuses. The confirmation prompt and `encrypted-seed.md` say so; a code guard is still to come. - **Stale lines:** `lightning.md` said any `…_FAILED` status resets the dedup id, `merchant-spending.md` that `payAndSettle` throws only on terminal failure (a final failure now has code `LIGHTNING_PAYMENT_FAILED`), `first-spend.md` gave the wrong default ceiling for `payMerchantCheckout`, and the reveal command in `wallet.md` worked only in a cloned repo. - **`fetchL402` is tested end to end on REGTEST** against a local L402 server issuing real invoices: a purchase, delivery failing in transit then recovered, a refused pass and `forgetL402`, a POST re-sent only with `resend`, a dying token, an expired invoice, the budget counting each purchase once, and the shop's view (`tests/integration/funded/l402-local-server.test.js`, needs openssl). - **Single-use deposit addresses are refused.** The operators currently refuse the step that claims them (`finalize_deposit_tree_creation` UNAVAILABLE on MAINNET and REGTEST, 2026-10-26; a real 2,000-sat mainnet deposit was refused), and the SDK has no refund path for them. `getSingleUseDepositAddress()` throws `SINGLE_USE_DEPOSITS_UNAVAILABLE`; `listPendingDeposits()` still lists single-use deposits, typed, so coins already sent show as arrived-but-waiting; `claimDeposit` asks the operators where the deposit sits and claims only one at the static address: the SSP quotes a single-use deposit as if it would claim it (a 1,703-sat credit on the stuck 2,000), so a dry run would have promised money the claim then refused. A single-use deposit is refused with the reason and a reminder to keep the recovery words backed up, and one it can't find is refused with `DEPOSIT_NOT_FOUND`, both before any quote (checked against the stuck mainnet deposit). Docs and the example script hand out only the static address, and the example lists coins already sent to a single-use address instead of saying none arrived. - **The example script's claim hint named the wrong call.** `balance-and-deposits.js` printed `claimStaticDeposit({ transactionId, outputIndex, maxFee })`; that function takes a quote's `creditAmountSats` and `sspSignature`, not a `maxFee`, so the copied line failed. It now prints `claimStaticDepositWithMaxFee`. - **`payAndSettle` no longer calls a paid payment "failed".** `PREIMAGE_PROVIDING_FAILED` and `TRANSFER_FAILED` come after the Lightning payment succeeded, but an `_FAILED` suffix match treated them as nothing-paid and forgot the dedup id. They now throw `PAYMENT_COMMITTED` at once; only the payee-unpaid statuses are terminal, and an unknown status keeps waiting. An invoice with more than one payment hash is refused before paying, since no preimage can be checked against it. - **`fulfillInvoice` hands the SDK checked amounts and never calls a mixed batch "nothing sent".** Token amounts go out as bigint base units (a string `"100"` used to be read as hex, 256 units) and only for amountless invoices; a tokens-plus-sats batch whose SDK call throws is always `PAYMENT_COMMITTED`, because the SDK sends the tokens before it can fail the sats leg with a "pre-send" message; failed token transactions now name their invoices. - **`withdraw`'s missing-record error is a `PaymentCommittedError`**, like every other money-may-have-left case, and SKILL.md has the rule: on `PAYMENT_COMMITTED` never pay again with a new invoice, address or method. - **Smaller review fixes:** a `transferTokens` dry run refuses a Spark invoice, as the send does; a batch entry naming two different recipients is refused; `first-spend.md` pays merchants through `payMerchantCheckout` (Lightning only); the shell-safe id pattern no longer admits a leading `-` or `..`; `l402.md`'s caching wrapper keys by https origin and keeps a recovered pass; SKILL.md's sample follows its own one-shot rule and no longer implies token sends are capped; the setup test that creates a REGTEST wallet moved from the unit tier to integration, and `setup` asks for the passphrase before it generates a wallet, so a missing one fails before any network call and the unit tier no longer reaches REGTEST. - **Lightning payments report what they cost: `feeSats`.** `payLightningInvoice` and `payAndSettle` passed on the SDK's first answer, whose `fee` can read 0. On hosted REGTEST (2026-10-02) that answer came back `TRANSFER_COMPLETED` with the preimage and a fee of 0 msat; the next status read said 5,000 msat, and 1,005 sats had left for a 1,000-sat invoice. A paid result now carries `feeSats`, in whole sats, from status reads once the payment has settled (up to 5, 2 s apart, or `payAndSettle`'s `pollMs`): the larger of the fee the SSP reports and what the transfer took beyond the amount. A 0 counts only when the transfer confirms it. While the cost isn't known (not settled, or still unpriced), `feeSats` is the fee cap and `feeNote` says why. A payment over Spark reports 0. `fetchL402` skips the reads: its paid pass is waiting to be presented. The result is now a copy, so `dedupReused` can't be lost on a frozen SDK object. Ported from the parked `sdk-013` line. - **`set-policy` no longer empties the spend window when a budget changes.** It wrote a fresh, empty signed ledger on every budget change, so tightening a limit freed headroom: lower a 50,000-sat budget to 20,000 after 30,000 was spent, and the agent could spend 20,000 more that day instead of nothing. Now a ledger that verifies is kept and spends already in the window count against the new budget; a missing ledger is created; an unsigned env-budget ledger is signed as it stands. A ledger that fails verification or can't be read stops the ceremony with nothing changed. Only `reset-ledger` empties the window on purpose. Checked through the real TTY ceremony: with 49,000 spent, binding 50,000 and then tightening to 20,000 kept 49,000 counted both times. Ported from the parked `sdk-013` line, without its token budgets. - **`setup` on a pipe no longer succeeds silently or hangs.** With stdin at EOF and no `SPARK_PASSPHRASE`, the passphrase prompt was left pending and Node exited **0 with nothing written**; an open-but-silent pipe hung until something killed it. The shared prompt helper now rejects on EOF (`PROMPT_EOF`) and after `SPARK_PROMPT_TIMEOUT_MS` of silence (default 30 s, `PROMPT_TIMEOUT`), so setup exits 1 with the reason and the fix. Piped input — the CI path — is unchanged. Ported from the parked `sdk-013` line. - **`SparkAgent` is importable from the package: `import { SparkAgent } from "sparkbtcbot-skill/agent"`.** The exports map blocked the deep path, so on the npm route the only way to the wrapper was to copy an 1,100-line listing. A field test on real mainnet found the cost: a mid-tier model built every script on the raw `SparkWallet`, so no guard ran on a live send. SKILL.md's first code sample now uses `SparkAgent` (the raw one is a single line for library authors, still with `sparkWalletOptions`), and the one-shot rule covers read-only scripts too, because boot claims pending transfers and that can start the leaf optimizer. A new test packs the real tarball into a scratch project and imports, by package name, every specifier and symbol any shipped doc tells an agent to write. Ported from the parked `sdk-013` line. - **`l402.md`'s snippets run as written.** The Usage Example called `SparkAgent` without importing it, loaded the seed from a clone-only path and left `cleanup()` unawaited. The Token Caching wrapper re-paid through a raw `wallet`, bypassing every wrapper guard, and dropped the request body on the cached attempt; it now wraps `agent.fetchL402`. The directory guide replaces a providers table whose rows had died (Satring re-verified 2026-09-26). `extras.md`, `encrypted-seed.md` and `agent-class.md` now import from the package. Ported from the parked `sdk-013` line. - **A failed payment refunds the budget only when the SDK proves nothing was sent.** Every recorded sats spend (`transfer`, `payLightningInvoice`, `fulfillInvoice`, `withdraw`) used to be undone on ANY SDK error, including a timeout after the operators accepted the send, when the money may be gone. A loop of such failures, each on a new invoice or address and each possibly paying, was never counted, and a runaway loop is what the daily budget exists to stop. Now only a `SparkValidationError` on an explicit list of pre-send checks refunds the spend (`lib/payment-outcome.js`; a test pins every entry to the installed SDK source, and all still match on 0.14). Anything else keeps the spend counted and throws `PaymentCommittedError` (code `PAYMENT_COMMITTED`): never pay again with a new invoice, address or method. A typo'd or wrong-network Spark address is on the list, so it still refunds. Ported from the parked `sdk-013` line. - **`fulfillInvoice` no longer reports a refused Spark invoice as paid.** The SDK doesn't throw when it refuses an invoice; it returns the failure in its result, and the wrapper treated any return as success, so a refused payment stayed counted against the budget. Now `invalidInvoices` means nothing in the batch was sent: the spend is refunded and the call throws `INVOICE_REFUSED` with each reason. A transaction error means sending had begun: the spend stays counted and the call throws `PAYMENT_COMMITTED` with `paid` and `failed` lists. An entry with no payment type, no amount, or a sats amount that isn't a positive integer is refused before anything runs. Ported from the parked `sdk-013` line. - **Token sends check their inputs and follow the failed-payment rule.** `transferTokens` and `batchTransferTokens` passed a float or negative amount, or another network's token id, straight to the SDK. Now the id must decode on the wallet's network and the amount must be a positive integer of base units (bigint, or a number below 2^53). An SDK error that proves nothing left is rethrown; anything else throws `PAYMENT_COMMITTED`. A `batchTransferTokens` entry written with the `to` alias passed the allowlist and then reached the SDK with no `receiverSparkAddress`; entries now go out normalized, and unknown entry keys throw. Ported from the parked `sdk-013` line. - **`bitrefill.md`'s account pitch no longer promises what the guest flow can't deliver.** It said an account would make "your orders and redemption codes findable later" and dangled the referral credit — but every order this skill places is a guest order, which is attached to no account (Bitrefill's agent docs describe no way to attach one afterwards), and the referral credit accrues only to spend made while signed in, so under our flow it accrued to nobody. The pitch now says what an account does (balance payments, cashback, history for orders placed *through* it), states the credit's sign-in condition, and tells the agent never to imply signing up changes where today's codes live. The authenticated purchase path remains unvalidated in this skill and is labelled as such. - **`satsToFiat` and `maxSpendableFace` accept the balance shapes the wallet actually returns.** `SparkAgent.getBalance()` hands back `sats` as a **string** (`{ sats: "19932", tokens }`) and the raw SDK's `satsBalance.available` is a bigint; both helpers rejected the string, so the first live first-spend run reported ≈ $0 on a wallet holding 19,932 sats. Digit strings and bigints are now coerced; garbage still throws. `first-spend.md` now names the exact property on each object and warns against the `available ?? balance` guess that produced the 0. - **Bitrefill guest checkout still requires an email — documented.** `@bitrefill/cli` 0.3.0 declares `--email` as a required option on `buy-products` (`error: required option '--email ' not specified`, before any order exists), so "no account" never meant "no email". `bitrefill.md` says so explicitly; `first-spend.md` moves the email question into the price preview so a "yes" can complete the purchase in one turn instead of stalling at checkout, and repeats the PII rule: the user's address, never an invented or context-scraped one. - **`fetchL402` no longer pays twice when delivery fails after payment.** If the request carrying the paid pass failed in transit, or the body was not the JSON its header claimed, the macaroon and preimage were lost with the stack frame. The natural retry then fetched a new challenge and paid again; dedup could not help, because it was a new invoice. Now `fetchL402` presents the same pass up to three times, retrying on transport errors and 5xx. If every attempt fails, it keeps the pass in memory for the life of the process and throws `PAYMENT_COMMITTED` with `settled: true`; the next call for the same method and URL presents it without paying and returns `recovered: true`. A payment still pending when `payAndSettle` gave up is kept too: the next call checks it and delivers once the preimage arrives, and buys afresh only once it has failed for good. The old error told agents to "retry with" a preimage there was no API to pass. Nothing is written to disk and the pass never rides on an error object: Node prints an error's properties when it is logged, and a preimage in a log is a working credential. A malformed body after payment is returned as text instead of thrown. Results now carry `status`. (Ported from the parked `sdk-013` line, without its policy-engine hooks.) - **`fetchL402` refuses a token the server has already declared dead.** An L402 invoice and its token expire separately. So an expired pass could be paid for, then refused on the retry with the sats gone. Before paying, `fetchL402` now reads the expiry the server signed into the token and throws `L402_TOKEN_EXPIRED` if the token is expired or dies within 60 seconds, roughly the longest a payment takes to settle. The check covers the three formats seen on live servers: aperture's per-service `_valid_until` in V2 macaroons, a plain `valid_until` in V1 or V2, and lightningfaucet's JSON-token `expiry`. Lightningfaucet's tokens live about ten minutes, which is why the margin is small. A token it cannot read is not blocked. `previewL402` reports `tokenExpiresAt`. The parser is `lib/l402-token.js`, with no dependencies; it is tested against macaroons from two independent encoders (js-macaroon, pymacaroons) and a token captured live. A check that reads only a bare `valid_until` misses every aperture expiry. (Ported from the parked `sdk-013` line, without its policy-engine hooks.) - **`payAndSettle` returns a Spark-direct payment at once, as settled.** The SDK pays an invoice's Spark fallback as a plain transfer, and no preimage ever comes. `payAndSettle` polled Lightning status with the transfer id for its whole window (60 s by default) and then reported `settled: false` for a payment that had gone through, which invites a second payment. It now returns immediately with `settled: true`, `sparkDirect: true` and `paymentPreimage: null`. Merchant checkouts and L402 always pay over Lightning, so they never take this path. Checked on REGTEST (`tests/integration/funded/spark-direct-binding.test.js`). - **A dry run checks the recipient the way the send does.** `transfer({ dryRun })` and `transferTokens({ dryRun })` decode the address for the wallet's network. A malformed address, one for the other network, a silent payment address (the error points to `withdraw`) or, for `transfer`, a Spark invoice (the error points to `fulfillInvoice`) used to preview fine and then fail at send. - **`withdraw` no longer hands back `null` after the money moved.** The SDK moves the leaves before it asks the SSP for the exit record, which it types as nullable. A missing record now throws a do-not-retry error marked `paid`, and the spend stays on the ledger. - **`sparkWalletOptions()` refuses an unknown network.** `undefined`, a lowercase name, or an options object passed by mistake made the SDK open REGTEST or LOCAL endpoints without complaint. - **The three raw example scripts turn background leaf optimization off**, as SKILL.md tells one-shot scripts to, so `cleanup()` no longer interrupts it. - **`agent-class.md`'s listing is the shipped class again.** It had drifted since at least v0.7.0, by about 40 stale hunks; `create()` had lost its options argument. The parity test now compares the whole listing with the script, not only method names, and `node tests/helpers/agent-class-listing.js --write` regenerates it. - **CI's dependency audit passes again.** vitest 4.1.11 → 4.1.12, bringing vite 8.3.5 and source-map-js 1.2.2. The dev tree had 2 high and 2 moderate advisories; production dependencies were clean throughout. - **SKILL.md installs SDK 0.14.** Its install line still said `@buildonspark/spark-sdk@^0.12.0`, and a caret on 0.x allows only patch releases, so a reader got 0.12 and none of this upgrade. It now pins `^0.14.0`, and the issuer SDK `^0.2.1`. A docs-lint test fails when any documented SDK pin can't install the version `package.json` ships. An eval run caught this. - **`fetchL402` pays over Lightning only.** The preimage is the L402 credential, and a Spark-direct payment returns none, so paying a paywall whose invoice carried a Spark fallback took the sats and gave no access. - **`leaf-vault verify` fails a backup that holds an anchorless refund.** `verifyVault` checked that every leaf rebuilds to a root offline, not that the exit tool can fee-bump it, so a backup taken by another program on the SDK defaults passed. It now lists those leaves under `anchorless`, reports `ok: false`, and says how to fix it. The continuous backup reports them too: the snapshot is still written (refusing would leave new leaves unbacked), but its result names them, `vaultHealth()` turns unhealthy, `SparkAgent` warns at boot, and the snapshot CLI exits 1. - **A pre-signed transaction that doesn't parse fails the backup.** The integrity gate and `verify` only checked that a leaf's `nodeTx` and `refundTx` were non-empty, so a truncated or garbage refund verified green. Both now have to decode as transactions; the snapshot refuses to write such a leaf and `verify` lists it under `failed`. Tested on two real REGTEST backups, one taken with the ladder on and one with it off, and live on REGTEST (`tests/integration/funded/fee-ladder.test.js`). ## 0.8.0 — 2026-09-15 ### Security - **Wallet privacy is now enabled by default.** Spark wallets are publicly readable out of the box — the operators' per-identity `private_enabled` setting defaults to false, and while it is false anyone holding the Spark address can read the balance, full transfer history, pending transfers, deposit addresses and UTXOs with no authentication (`SparkReadonlyClient.createPublic()`, Sparkscan). An agent hands its address to every counterparty, so with the default every merchant and every explorer scrape saw how much it held and everything it did. `npm run setup` now enables the setting on the freshly verified wallet and `SparkAgent.create` re-asserts it on every boot (new `lib/wallet-privacy.js` — `ensureWalletPrivacy(wallet)` / `privacyPreferenceFromEnv()`, exported from the package); the setting persists at the operators so the boot call is a self-heal. A failure never blocks the wallet but warns loudly. Opt out with `SPARK_PRIVACY=off`. Scope, from the operator source: hides balance, leaves, transfers, unused deposit addresses, UTXOs and events from everyone but the owner (and one optional viewer key, spark-sdk ≥ 0.12); does **not** hide BTKN token balances/transactions or Spark invoices, and static deposit addresses stay listable behind a rollout knob that is currently off. **Observed with real sats on REGTEST**: a 98k-sat wallet read as 0 sats / 0 transfers by public and stranger readers while private, the granted viewer key read the full balance, revoke and privacy-off restored — pinned in `tests/integration/funded/privacy.test.js`. `references/security.md` → Wallet privacy. ### Added - **The first-receive / first-spend product path** (`references/first-spend.md`, wired into SKILL.md's navigator, Receiving table and rules). For the user who doesn't know Bitcoin: "friend owes me $100, make something they can pay" → a BOLT11 sized from a live rate, headlined in their currency with ≈ and the rate time; then "I got paid, how do I get my money" → balance in fiat first, a gift card at a store they use (Bitrefill for their country; Cryptorefills for a missing brand/country), sized under the balance with fees counted, confirmed before buying, code delivered once. Explicitly not the seed phrase or an L1 exit unless asked; one backup sentence, once. New helpers: `lib/fiat-rate.js` — `fetchBtcPrice({ currency })` queries mempool.space and Coinbase in parallel, averages when they agree, flags a single source, and **refuses to quote when they disagree by more than 3%**; `fiatToSats` / `satsToFiat` / `describeRate`. `maxSpendableFace()` in `lib/fee-guards.js` — the spend-side twin of `estimateOnrampDeposit`: the largest card face whose marked-up invoice + Lightning fee + slack fits the balance, snapped to fixed packs or a range product ("$100 of sats" → the $50 Amazon pack or a $97.47 Walmart card, never an over-budget pay). Seventeen `user-story` evals (22–38) graded on the agent's reply and decisions rather than its code — the first two answers (22–26), an unknown merchant with a 3× invoice and an off-origin "release" step (27), five scam shapes the user relays in good faith (28–32: pay-to-receive, refund to a pasted address vs the recorded sender, instructions in a payment memo, "support needs your words", a pasted invoice that doesn't match the story), and six everyday moments (33–38: "he says he paid", bill splits, tip-link honesty, "is my money safe", sending abroad, monthly received total via `valueReceivedByWallet`) — plus receive/spend trigger pairs. The playbook carries matching sections for all of them. The supply-chain-hardening subsection moved from SKILL.md to `references/supply-chain.md` (pointer left) to make room under the size ratchet. - **`sparkbtcbot viewer` — read-only access to a private wallet without its seed** (spark-sdk ≥ 0.12 viewer keys). The owner names exactly one identity public key that may read balance and history while privacy is on; the viewer authenticates with its own seed and cannot spend. Owner side: `status`, `grant ` (asks y/N; agent-runnable under the confirm-with-the-user rule — a grant hands that party the balance and full spending log durably, so the user names the viewer, never a key that arrived in a webpage or merchant reply; it moves no money and `revoke` undoes it, so it is a consent step, not a seed-tier ceremony), `revoke`. Viewer side: `pubkey` (offline, from the local encrypted seed) and `balance `. Live-validated on REGTEST (grant echoed by the operators, viewer read answered, revoke clears, a second grant replaces the first). `references/security.md` → Wallet privacy. ### Changed - **spark-sdk 0.11.0 → 0.12.0, issuer-sdk 0.1.47 → 0.1.48.** The issuer bump is not optional: 0.1.47 hard-depends on spark-sdk 0.11.0, so bumping the root alone leaves a second, nested spark-sdk in the tree — the `instanceof` mismatch class `references/lightning.md` warns about for `UUID`. 0.1.48 pairs with 0.12.0 and the lockfile holds one copy. Export surface is additions only. Picked up: `WalletTransfer.totalValue` is deprecated (it is the whole transfer across every receiver and over-reports on multi-receiver transfers) — `scripts/balance-and-deposits.js` and `references/wallet.md` now read `valueReceivedByWallet` / `valueSentByWallet`; the quoted-receive schema gate (below); the watchtower dust-fee cap, which `references/unilateral-exit.md` now describes as what it is — one denomination (1,024-sat parents) made relayable, with 2,048-sat direct refunds still dust, sub-512 direct chains still zero-fee, and no repair of already-signed leaves until they next move. - `references/lightning.md`: the receive-quote paragraph no longer implies a receiver-side fee to defend against. Lightning receives are fee-free for the receiver (the operators refuse any fee on a receive preimage swap and release preimage shares only against a transfer ≥ the deposited invoice); `getLightningReceiveQuote` exists for Lightspark partners holding a JWT to add a signed, receiver-consented markup, returns a feeless manifest for everyone else, and on spark-sdk 0.12 throws on MAINNET unless the wallet names `sspClientOptions.schemaEndpoint: MANIFEST_SCHEMA_ENDPOINT`. New rule: never sign a quote whose `manifest.fees` is non-empty without the user's explicit opt-in. ## 0.7.0 — 2026-08-31 ### Security - **Trail of Bits security-skills pass over everything since 0.6.3** (differential-review, sharp-edges, supply-chain-risk-auditor, findings verified through fp-check). Differential verdict: no Critical/High/Medium — the dedup primitive is fail-closed and safe-directional, no existing guard weakened, path traversal from attacker bolt11 ruled out empirically, supply-chain delta clean (no new install scripts, one added transitive unreachable from the Node entry, 0 advisories). The verified findings were fixed, each with a regression test: - **`AlreadyExists` translated where the wrapper holds proof**: a deduped retry on the Spark-fallback rail now throws `code: "PAYMENT_ALREADY_SETTLED"` with the full do-not-retry rule in the message, instead of the raw gRPC error that reads as failure — gated on the store's `reused` verdict, so an AlreadyExists the wrapper can't vouch for still passes through raw. - **`payAndSettle` verifies the settlement proof**: `sha256(preimage)` must equal the invoice's payment hash or it refuses to report settled — closing the replay shape where a `transferId` shared with a different payment returns that payment's result as this invoice's "success". The store also refuses an `explicitId` already recorded for a different invoice. - **Terminal payment failure resets the dedup entry** (new `store.forget()`), so a still-valid invoice stays payable after a definitive failure instead of replaying it forever. - **Store hardening**: non-UUID ids rejected at persist AND read (a persisted one would wedge the invoice at the SDK with no pointer to the entry file); positional misuse of `idForInvoice` fails loud instead of silently ignoring an id in `mint`'s seat; a broken `clock` is refused at construction; fs failures are framed with the store path and `SPARK_LN_DEDUP_PATH` rather than a bare `EACCES` that nudges toward `SPARK_LN_DEDUP=off`. - **Prune grace raised 1h → 24h** past invoice expiry: the SDK does not refuse an expired BOLT11 client-side and a hold HTLC can pend past expiry, so early pruning could retire the one entry making a retry safe. - **Successful pays report `dedupReused`** so a replayed original is distinguishable from a fresh debit, and the docs now disclose the pruning TTL, the same-store requirement behind the cross-process guarantee, and that `UUID` must be spark-sdk's own export (`instanceof` check). - `tests/check-dev-deps.js` cites README (where the ignore-scripts rule actually lives, not SECURITY.md) and recommends the doctrine-preferred `npm ci --ignore-scripts`. ### Added - **Persisted Lightning payment dedup: one `transferId` per invoice, minted write-ahead** (`lib/transfer-ids.js`, wired into `SparkAgent.payLightningInvoice` and everything that funnels through it — `payAndSettle` and the L402 flow included). Spark-sdk 0.10 made `transferId` the payment's dedup identity across every rail (Spark fallback transfer, preimage swap, SSP admission): a retry reusing it cannot produce a second payment. But the SDK mints a fresh one per call, so the guarantee evaporated exactly when it was needed — a crash or timeout between "request sent" and "outcome known" left no safe retry, which is what forced the never-retry-pay doctrine. The wrapper now persists the ID before the first attempt (one file per invoice under `~/.spark/ln-dedup/`, keyed by payment hash, published with atomic-file's exclusive link so concurrent racers — even across processes — converge on one ID), and any later attempt at the same invoice reuses it. Fail-closed throughout: an unreadable entry refuses to pay rather than mint a fresh ID for an invoice that may have a payment in flight; an explicit `transferId` option that disagrees with the recorded ID is refused; a store write failure throws before any money moves. Opt out with `SPARK_LN_DEDUP=off`; relocate with `SPARK_LN_DEDUP_PATH`. The retry doctrine softens accordingly: still check `getLightningSendRequest` before retrying, but a warranted retry through the wrapper is no longer a double-pay gamble — unless the store is gone, which the docs now name as the residual hazard. **Live-validated on mainnet (2026-08-31 funded QA): duplicate pays on BOTH rails produced one debit** — the Lightning rail replays the original result verbatim (same id and preimage, `TRANSFER_COMPLETED`), while the Spark-fallback rail throws `AlreadyExists … transfer already exists` (a server-side uniqueness constraint on the transfer id). The second shape is documented in `references/lightning.md` because it inverts naive reading: `AlreadyExists` from a retry means *already paid*, never *failed*. Crash-restart ID reuse and all three fail-closed guards (conflicting explicit id, corrupt entry, opt-out) were also confirmed live. ### Changed - **`@buildonspark/spark-sdk` 0.9.0 → 0.11.0, `@buildonspark/issuer-sdk` 0.1.45 → 0.1.47** (issuer-sdk 0.1.47 pins spark-sdk 0.11.0 exactly, so the pair moves together — bumping one alone would nest a second SDK copy). Verified against the actual type-surface diff, not just the upstream changelog: only 19 declaration lines removed across the whole surface, all either internal services or the one announced break — `payLightningInvoice` dropped `idempotencyKey` for `transferId`. This repo never passed `idempotencyKey`, so no code changed; the wrapper's four forwarded params (`invoice`, `maxFeeSats`, `preferSpark`, `amountSatsToSend`) all survive, every wallet method and named export the repo uses exists in 0.11.0, the `proto/spark` subpath is intact and `TreeNode` is byte-identical (leaf-vault codec unaffected). 388 unit tests green; non-funded integration 14/15, the one failure being a server-side `generate_deposit_address UNAVAILABLE` on hosted REGTEST that reproduces identically under 0.9.0 (environmental, tracked separately). Docs picked up the three additions that matter to this skill: the `transferId` retry-dedup identity — including that old `idempotencyKey` code now silently gets NO dedup (`references/lightning.md`) — watchtower-exited-leaf recovery (`references/unilateral-exit.md`), and operator-enforced token allowances (`references/tokens.md`). The leaf-vault reach-in also has **runtime** proof on 0.11.0, not just the static diff: the 2026-08-31 mainnet funded QA reconstructed all 9 leaves offline to root, exit 0 — the baseline to re-verify on the next SDK bump. ### Fixed - **The raw-vs-wrapper `payLightningInvoice` shape trap is now documented and guarded** (production incident, 2026-08-28). The raw SDK takes ONE object (`wallet.payLightningInvoice({ invoice, maxFeeSats })`); the `SparkAgent` wrapper takes a bare BOLT11 string + options — and spark-sdk has no validation (verified in 0.9.0 and still absent in 0.11.0, the latest as of 2026-08-28), so a wrapper-style bare string at the raw layer dies on its first line with the opaque `Cannot read properties of undefined (reading 'toLowerCase')`. Each shape was documented correctly in its own reference, but nothing said they differ, and an agent that had seen the wrapper's examples then called the raw wallet naturally passed the string. Now: a callout in `references/lightning.md` → Pay maps that exact error to this cause (and notes the crash is pre-flight — the invoice is unpaid, so a corrected retry is safe); the SKILL.md navigator row and `references/agent-class.md` methods list flag the difference; the wrapper throws a shape-naming `TypeError` on the reverse mix-up (`agent.payLightningInvoice({ invoice })`) before any I/O, `payAndSettle` included; and eval 21 encodes the incident. The forward direction (validating inside the raw SDK) can only be fixed upstream in `@buildonspark/spark-sdk`. ## 0.6.3 — 2026-08-20 ### Security - **`--ignore-scripts` on every documented install path, `npm ci` included.** `npm ci` runs the full install lifecycle exactly as `npm install` does — verified here with a sentinel dependency — so a lockfile-exact install is not by itself protection from a dependency that executes code at install time. In this tree that is `protobufjs`, which runs before a single line of your own code is imported. README, AGENTS.md and the quick-start blocks now carry the flag throughout. Verified on the development tree as well as the consumer install: a clean `npm ci --ignore-scripts` clone runs the full 386-test suite green, so the flag costs nothing in either place. - **Every bin name this project has ever published is now project-owned on npm.** Alongside `sparkbtcbot`, the five names retired in 0.6.0 — `sparkbtcbot-setup`, `sparkbtcbot-reveal-mnemonic`, `sparkbtcbot-leaf-vault`, `sparkbtcbot-set-policy`, `sparkbtcbot-reset-ledger` — now resolve to reservation stubs that print the `sparkbtcbot ` migration and exit 1. `npx` resolves whatever string you type as a package name, so folding a bin into a subcommand removes it from the package but not from the registry's namespace. That gap matters more here than in most projects: this skill's readers are LLM agents, the retired names were the documented form throughout 0.4.x–0.5.x and therefore sit in model weights and agent memory, and an agent working from recall never reads the SKILL.md rule that would stop it — while `npx` with no TTY installs and executes silently, so there is no prompt to intervene either. Owning the name is the only control that acts at resolution time rather than upstream of a model's choice of what to type. Deliberately bounded to the names actually shipped and documented, not to arbitrary misspellings; a future release that retires a bin name should claim it the same way. ### Changed - **SKILL.md speaks one invocation form.** Four `npx sparkbtcbot ` instructions remained in user-facing lines and contradicted the `npm exec --no --` forms beside them, so a reader copy-pasting from the nearest example got the weaker one. The description of `--no` also picked up the precise wording README settled on in `072f07e`: it refuses to install, though a registry *metadata* request may still print a 404. - **`SPARK_ACCOUNT_NUMBER` is out of README's environment-variable table and out of `setup`'s help text**, which had advertised it without ever reading it. It is not a general setting: `SparkAgent` and every example script omit `accountNumber` and take the SDK's network default, and the `leaf-vault` CLI is its only reader — an escape hatch so a deliberately non-default wallet can still be backed up. Listed beside `SPARK_PASSPHRASE` it invited being set globally, which would point the recovery bundle at a different, empty wallet than the funded one. `.env.example` documents it correctly and is unchanged. ## 0.6.2 — 2026-08-20 > **Note:** 0.6.3 corrects one line below. `npm ci` runs install scripts, so it needs `--ignore-scripts` too — the bare `npm ci` recommended here does not protect you. ### Security - **An npx rule that holds without a prompt.** Since 0.5.0 the mitigation against npx's registry fallback had been "if npx offers to install something, answer NO and stop," carried in SKILL.md, AGENTS.md and README. That rule assumes a prompt. Verified against npm 11: **npx only prompts on an interactive TTY.** With no TTY — a CI job, a script, or an AI agent running commands through a tool call, which is the context SKILL.md and AGENTS.md exist for — npx installs the fetched package and executes it silently, with nothing displayed and nothing to decline. It protected an interactive human and no one else while reading as general protection. The rule is now one that needs no prompt to work: **never run a bare `npx` for a wallet command** — use `npm exec --no -- sparkbtcbot ` or `./node_modules/.bin/sparkbtcbot`, and never pass `-y`/`--yes`. The pinned `npx --package=sparkbtcbot-skill ...` form is documented for a human at a terminal and explicitly not offered to agents: `--package=` names the owned package outright and cannot fall back to a command-name lookup, but it is still an unpinned fetch outside the lockfile. - **Install guidance uses `--ignore-scripts`.** One production dependency (`protobufjs`) executes code at `npm install` time, before the consumer's code has imported anything — the supply-chain footgun with the largest blast radius here, since it runs on the developer's machine with the agent's privileges rather than merely risking wallet funds. The flag costs nothing: the CLI resolves and runs, and both `sparkbtcbot-skill` and `@buildonspark/spark-sdk` import cleanly without install scripts. - **`cli.js` argument gate no longer falls through on inherited `Object` properties.** The dispatcher looked up `COMMANDS[cmd]`, which walks the prototype chain, so `sparkbtcbot constructor`, `toString`, `valueOf` and `__proto__` resolved to a truthy non-entry and reached `import(undefined)` — a stack trace instead of the usage message, in the one gate whose own comment promises that an unknown command "cannot fall through to anything." Now `Object.hasOwn(COMMANDS, cmd)`. Not exploitable (nothing executed, exit stayed non-zero), but it was the 0.4.3 fall-through class in miniature. ### Changed - **`SECURITY.md` ships in the npm tarball** and gained a section on registry-name reservations — which names this project owns, and why owning them is what protects the npx fallback. Its scope section also named the package `sparkbtcbot`; that name now resolves to the reservation stub, so it reads `sparkbtcbot-skill`. ## 0.6.1 — 2026-08-20 First published build of the single-CLI work. (0.6.0 was withdrawn before general availability and is not installable; 0.6.1 is the same tree, released through the tag pipeline with Sigstore provenance linking the tarball to its commit. npm treats `name@version` as permanently spent, so the corrected build ships under a new number rather than as a re-cut 0.6.0.) ### Security - **One CLI, and its name is ours: the five per-command bins collapse into a single `sparkbtcbot ` dispatcher.** The 0.4.x–0.5.x bins (`sparkbtcbot-setup`, `sparkbtcbot-reveal-mnemonic`, `sparkbtcbot-leaf-vault`, `sparkbtcbot-set-policy`, `sparkbtcbot-reset-ledger`) were five *unregistered* npm names — each a separate landing spot for npx's registry fallback when the local bin is missing, at wallet-bootstrap or seed-reveal time. The single bin is named `sparkbtcbot`, and an in-repo **name-reservation stub** (`stub/sparkbtcbot/`, published separately to npm) owns that name on the registry: a wrong-directory `npx sparkbtcbot ...` lands on project-owned code that prints where you went wrong and exits 1, never a squatter's. The dispatcher also gives the ceremonies **one argument gate with no default action** (the 0.4.3 `--help`-minted-a-wallet class of bug cannot recur per-script), `sparkbtcbot` with no arguments prints the subcommand list instead of hitting the registry with a half-remembered name, and every command module is now **inert on import** with an exported `main()` — `set-policy`, `reset-ledger`, and `leaf-vault` previously executed at top level on import. Old invocations migrate mechanically: `npm exec --no -- sparkbtcbot-setup` → `npm exec --no -- sparkbtcbot setup`. The `npm run` script names in the cloned repo are unchanged. **Breaking:** the five old bin names are gone; docs-lint fails any living doc that resurrects one. ### Changed - Docs, in-code error messages (`spend-ledger`, `spark-agent`), evals, and tests all speak the `sparkbtcbot ` form; README/SKILL.md/AGENTS.md npx guidance updated for the owned-name fallback. ## 0.5.0 — 2026-08-17 ### Security - **Trail-of-Bits pass on the seed-binding work — 8 findings fixed before release.** Two independent adversarial reviews (crypto/format + install/docs/reveal) ran against this batch; the crypto core survived every malleability and payload-edge-case attack, but the *rollout* had holes: (1) `references/agent-class.md` — the "drop-in" class users actually copy — still shipped the pre-seal env-only resolver, so someone who sealed a budget and followed the doc got **no budget at all**; (2) a sealed seed whose policy didn't reach the agent ran **silently unbound** — now the plaintext version byte is checked and a sealed-but-unbound wallet **throws**; the context also moved to `globalThis` (duplicate module copies) and a policy-less load can no longer clear an established one; (3) the seed header wasn't in the GCM AAD, so flipping `0x02`→`0x01` passed authentication and reinterpreted the payload as a bare mnemonic — v2 now authenticates the header (v1 untouched); (4) `npx ` does **not** fail closed — it fetches a registry package *named after the command*, and all five of our bin names were unregistered; docs now use `npm exec --no`, and both agent-facing rule files say to refuse any npx install offer; (5) the ceremonies read the passphrase from `.env` (which sits next to the wallet), reducing "requires the passphrase" to "requires a PTY" — they now always prompt; (6) the over-budget error told sealed-policy callers to edit `.env`, the exact move the seal neutralizes; (7) `SIGTERM`/`SIGHUP` skipped the seed-reveal screen wipe (the `exit` hook doesn't run for signals), leaving the mnemonic on screen indefinitely; (8) the reveal claimed "alternate buffer wiped" unconditionally, but GNU screen ships `altscreen off` — the message is now conditional and tells screen users to clear their scrollback. Also: README no longer teaches an unpinned SDK install, the pin-staleness tradeoff is stated, and `npm@latest` on Node 20 is corrected (engines are warn-only, so it installs npm 12 anyway — use `npm@11`). +12 regression tests. - **Seed-bound spending policy (opt-in): the budget can now be sealed inside the encrypted seed.** Guard enforcement used to depend on files the agent can write — `rm ~/.spark/spend-ledger.json` (or truncating it, or editing `.env` to drop `SPARK_DAILY_BUDGET_SATS`) silently restored the full budget; a cleanup command, a prompt injection, or a machine migration all failed open. Now `npx sparkbtcbot-set-policy` (user-run, TTY-gated) binds `dailyBudgetSats` into the encrypted seed payload (**v2 seed format** — reading it needs the passphrase, tampering fails the GCM tag, deleting it deletes the wallet: the agent can't remove the budget without removing the money), and the spend ledger becomes **HMAC-signed** with a seed-derived HKDF key (never the AES key). Under a bound policy, a missing / unsigned / edited ledger **fails closed** with instructions to run `npx sparkbtcbot-reset-ledger` — the passphrase-gated legitimate reset that finally makes reset distinguishable from attack (previously `rm` was both). A seed-bound budget wins over the env var absolutely. **v1 seeds and env-var budgets are completely unchanged** — no policy, no new behavior. Honest limits, documented: the bar moves from `rm` to *executing code*, not to impossibility; replay of a validly-signed old ledger is undefendable client-side; raw-SDK calls still bypass wrapper guards. New exports: `loadSeedPayload(FromEnv)`, `validateSeedPolicy`, `deriveLedgerHmacKey`, `initSignedLedger`; new CLIs: `sparkbtcbot-set-policy`, `sparkbtcbot-reset-ledger`. 16 attack-first tests (each attack proven to throw). ### Changed - **Agents are explicitly told that running SETUP is allowed and expected.** Live testing showed agents over-extending the reveal-mnemonic prohibition into refusing `npm run setup` when the user asked — citing rules the docs never contained (setup has not printed or written the mnemonic in plaintext since 0.4.0). AGENTS.md and SKILL.md now carry an affirmative rule: creating the wallet on the user's behalf is the designed flow; the only secret to guard during setup is the passphrase, which goes to `.env` and is never echoed. ## 0.4.3 — 2026-08-05 ### Security - **`--help` no longer performs the CLI's default action.** All three published CLIs ignored unrecognized arguments and fell through to their default — which for `sparkbtcbot-setup` is *creating a wallet*: an agent probing `--help` for usage silently bootstrapped a real, unbacked wallet (caught by QA on REGTEST before it happened on MAINNET). `sparkbtcbot-leaf-vault --help` would likewise have taken a snapshot, and a typo'd flag to `sparkbtcbot-reveal-mnemonic` fell through toward a seed reveal. All three now gate arguments before any side effect: `-h`/`--help` prints usage and exits 0 (in reveal's case, before the TTY gate — usage holds no secrets), and any unknown argument fails closed with usage on stderr (exit 2). Regression tests pin that `--help` creates nothing. ## 0.4.2 — 2026-08-05 ### Fixed - **The Claude Code plugin path is now runnable.** `claude plugin install` lands the sources with no `node_modules` in a versioned cache that's wiped on update — and the docs assumed a cloned repo, leaving plugin users no supported way to run setup and *no runnable form at all* of the user-executed seed backup. The package now ships bin commands — `sparkbtcbot-setup`, `sparkbtcbot-reveal-mnemonic`, `sparkbtcbot-leaf-vault` — so `npx -y --package=sparkbtcbot-skill sparkbtcbot-setup` works with no repo checkout (same answer for npm consumers, whose `npm run setup` never worked either). SKILL.md gained a "Which install path are you on?" section naming that one supported answer and banning installs into the plugin cache; the frontmatter now declares `SPARK_DAILY_BUDGET_SATS`/`SPARK_SPEND_LEDGER_PATH`; README's local-clone instructions no longer land `SKILL.md` a level too deep for skill discovery. - **Generated code is told to depend on the npm package, not copy guard helpers.** SKILL.md falsely claimed `lib/encrypted-seed.js` "is not published to npm" (the package has shipped all of `lib/` for some time) and told agents to copy it — while saying nothing about `fee-guards`/`bolt11`/`spend-ledger`, pushing agents to hand-roll exactly the guards that must not rot. One supported answer everywhere: `npm install sparkbtcbot-skill` and import. ### Security - **`writeMnemonicBackupFile` removed from the library and package exports.** Setup stopped writing the plaintext `MNEMONIC_BACKUP_*.txt` file in 0.4.0, but the helper remained a discoverable public export — a function that "does the backup step" by writing the seed words to disk in plaintext is exactly what an agent scaffolding wallet code would reach for. Deleted outright (with a regression test pinning that no plaintext-mnemonic writer returns to the surface); the supported backup path remains the user-run `reveal-mnemonic`, now invocable everywhere via `npx -y --package=sparkbtcbot-skill sparkbtcbot-reveal-mnemonic`. ## 0.4.1 — 2026-08-05 Pipeline release — no code changes vs 0.4.0. Adds the CI publish workflow (npm **trusted publishing**, no token secrets) and is the **first version published with a Sigstore provenance attestation** linking the npm tarball to its exact commit and workflow run (`npm audit signatures` verifies). Also: `npm version` now auto-syncs the plugin-marketplace manifest version, and the changelog was folded for the 0.4.0 release. ## 0.4.0 — 2026-08-05 First npm release since 0.3.0 (0.3.1 shipped only to the plugin marketplace), folding in the full 0.4.0 line. The sections below run newest-first; the entries following the second group of headings are the earlier 0.4.0-line work from July. ### Fixed - **BigInt sats amounts no longer bounce off the SDK.** The SDK validates every amount with `Number.isSafeInteger()`, which is `false` for *all* BigInts — so `transfer({ amount: 8258n })` threw a misleading `"Sats amount must be less than 2^53"` while `8258` worked, and since `getBalance()` returns balances *as* bigint, passing one straight back in was the natural mistake. A `toSats()` normalizer (number|bigint → safe-integer Number, clear pre-I/O error on garbage) now guards every SDK-bound sats amount across `transfer`, `withdraw`, `createLightningInvoice`, `createSatsInvoice`, `payLightningInvoice`, `estimateLightningFee`, and `getWithdrawalFeeQuote` — and `transfer`'s dry-run and live paths now validate identically instead of diverging. Token amounts are deliberately untouched (legitimately bigint on the LRC20 path). - **L402 challenges are read from the `WWW-Authenticate` header, and the `token=` field parses.** `fetchL402`/`previewL402` called `response.json()` unconditionally on a 402 and never read the header — the spec-standard location — so a header-only server (aperture, lightningfaucet) threw `Invalid L402 challenge`. And every parser matched only `macaroon="..."`, structurally unable to match the current spec's `L402 version="0", token="..."` form. One shared `parseL402Challenge()` (exported) now reads the header first, falls back to the body, and extracts each field by name — any scheme prefix (L402/LSAT), any field order, `macaroon=` or `token=` — applied consistently to the wrapper, the example script, and the reference docs that had drifted apart. - **The leaf-vault no longer cries BROKEN during every cooperative L1 exit.** An exit removes its leaves from `getLeaves()` at broadcast while `owned` keeps counting the exiting sats until the L1 tx confirms — minutes during which every snapshot read as a partial capture and marched the BROKEN marker up. Balances alone can't distinguish that window from a genuinely dropped transfer-locked leaf (identical signature), so the fix demands *positive evidence*: the shortfall is excused only when the capture still covers `available`, the gate-proven UNION bundle was written (in-flight leaves keep their exit material), *and* the SSP confirms a pending `COOP_EXIT` via `wallet.getUserRequests` — with absence/failure/zero degrading to the old strict behavior, so the guard is never weaker than before. Full-balance exits still trip the (deliberately untouched) empty-capture guard. - **One-shot scripts that move value no longer race the SDK's background leaf optimizer.** Value-moving ops fire `autoOptimizeIfNeeded()` detached; `cleanup()` right after tore down gRPC mid-optimization and logged the alarming (but harmless) `Claim transfer process was interrupted due to cleanup`. `SparkAgent.create(..., { optimizeLeaves: false })` now plumbs `optimizationOptions.auto` so a one-shot has nothing to interrupt; documented in `wallet.md`/SKILL.md, and the L402 example (the one shipped script that pays then exits) uses it. ### Changed - **Node floor raised to `>=20`; CI now audits dependencies.** `engines: >=18` was a claim CI never tested (matrix is 20/22/24) for a runtime that hit EOL in April 2025. A separate CI `audit` job runs `npm audit --audit-level=high` (postcss and protobufjs advisories were cleared to a 0-vulnerability tree). npm supply-chain guidance is now tiered and explicitly **not a gate**: prefer npm 12+ (install scripts disabled by default; needs Node 22.22.2+/24.15.0+), accept 11.10.0+ (the `min-release-age` floor — fine on Node 20), and proceed with a warning on older — never block wallet setup over the npm version. - **Merchant references re-verified live (2026-08-05).** nadanada: the VPN purchase endpoint moved (`/vpn/purchase` → `/vpn/request`; the old path 404s), all responses are wrapped in `{ success, data }`, the full request body is documented including that the WireGuard keys go in the *purchase* body, the returned config's empty `PrivateKey =` must be injected locally, and a key-generation snippet covers Node's X25519 export quirk. Cryptorefills: the granular MCP catalog tools work again (the earlier 400s were a missing `brand_name` argument), documented with their field shapes — which differ from the x402 REST catalog's — while the wizard remains the only checkout verified end-to-end. README now names the two live-validated stacks: Claude Code, and opencode running GLM-5.2 via OpenRouter. - **Boltz dependency removed; the native Lightning↔L1 bridge is documented in both directions** (ported from the 0.3.1 release, prompted by Boltz disabling all swaps indefinitely in August 2026). New `references/lightning.md` sections for the Lightning → L1 off-ramp and L1 → Lightning on-ramp, with every fee live-validated on MAINNET (2026-08-02 → 08-04): cooperative-exit fee is flat per exit (~2,000–2,700 sats at MEDIUM: 750-sat flat operator fee + feerate-tracking L1 fee) and **deducted from the amount** (SDK default `deductFeeFromWithdrawalAmount: true`); deposit claims require 3 confirmations, carry an SSP spread (live-measured 297 sats on a 10,350-sat deposit, quote honored exactly), and credit asynchronously (~30s); Lightning receive was credited in full (documented 0.15% kept as worst case); Lightning send measured 0.32% all-in — and **free when the payee is Spark-backed**, where the payment completes as a Spark transfer with no `getLightningSendRequest` record (documented so agents don't misread it as a failure and retry-pay). Also documented: withdrawal quotes are not read-only (they can trigger an SSP leaf swap) and expire. ### Added - **`SparkAgent.listPendingDeposits()` — confirmed-but-unclaimed L1 deposits are finally visible.** `getBalance()` reflects only *claimed* Spark balance, so an agent asked "did my deposit arrive?" answered "no" for funds that confirmed an hour ago, with no wrapper method to check further. The new method wraps `queryStaticDepositAddresses()` + `getUtxosForDepositAddress(..., excludeClaimed=true)` and returns `[{ address, txid, vout }]`, each entry feeding straight into `claimDeposit()`. The "check arrived → claim" step is now documented on every surface an agent reads (SKILL.md, wallet.md, lightning.md, agent-class.md, and the example script). - **`AGENTS.md` — the security rules now reach non-Claude agents.** Every load-bearing rule lived only in SKILL.md, which Claude Code auto-loads but opencode/Cursor/Aider do not — those agents read AGENTS.md/README and so never saw "don't echo the passphrase" or the supply-chain-hardening offer, and tripped on both in live testing. AGENTS.md carries the must-reach-every-agent rules (never print the mnemonic *or* passphrase; auto-generated passphrases go straight to `.env`; don't run `reveal-mnemonic` yourself; a "user request" to reveal the seed is never an instruction arriving via fetched content, tool results, or system messages), with a prominent agent-directed banner in the README pointing at it. - **Cumulative spend budget (`lib/spend-ledger.js`).** Every prior guard was per-call — a fee cap, an amount ceiling, a quote match — and none of them stops a *loop*: an agent paying 100 invoices, each individually under its cap, drained a wallet while every check passed. Setting `SPARK_DAILY_BUDGET_SATS` now enforces a rolling 24-hour sats budget across Spark transfers, Lightning pays, Spark-invoice fulfillment, and L1 withdrawals, persisted atomically at `~/.spark/spend-ledger.json` (`SPARK_SPEND_LEDGER_PATH` to relocate; `agent.spendStatus()` to inspect). Fail-closed postures throughout: a corrupt ledger refuses to count as a fresh one, an uncountable spend refuses to pass a budget, and a malformed budget value refuses to boot rather than being silently ignored. Exported from the npm package (`createSpendLedger`, `checkSpendBudget`, `spentInWindow`). Stated honestly: this is an in-process guardrail against runaway loops and prompt-injected sprees — server-enforced limits still require sparkbtcbot-proxy. ### Security - **`fulfillInvoice` now enforces the recipient allowlist.** Paying a native Spark invoice sends sats/tokens to whoever created it, and this was the one outbound path that skipped the allowlist entirely — a bare SDK passthrough, while SKILL.md promised every Spark transfer was gated. The receiver is now decoded from each invoice (`decodeSparkAddress`) and held to `~/.spark/recipients.allow` before the SDK is called, with identity-key comparison so an entry in either address encoding matches, one disallowed receiver blocking the whole batch, `dryRun` parity (preview shows WHO gets paid), unknown-option rejection, and a refuse-on-disagreement guard when a caller amount contradicts the invoice's embedded amount. - **`SparkAgent.create()` refuses a missing mnemonic instead of minting a wallet.** The SDK generates a fresh wallet for an undefined `mnemonicOrSeed`, so a typo'd env var or failed seed decrypt silently booted a brand-new MAINNET wallet — and deposits landed on a wallet whose seed nobody backed up. Deliberate creation remains `npm run setup`. - **Ported from the 0.3.1 adversarial review:** `getReference()` rejects path-traversal names (`^[a-z0-9-]+$` — a crafted name could read arbitrary `.md` files outside the package; regression test included); all six example scripts now run their demo only when executed directly, never on import; `SparkAgent.withdraw` binds the exit via the non-deprecated `feeQuoteId` + `feeAmountSats` (the `feeQuote` object param is `@deprecated` in current SDKs). - **Guard VALUES are validated, not just guard keys.** The misspelled-option doctrine covered names but not values: `claimDeposit({ maxFeePct: "10%" })` produced a `NaN` ceiling that the SDK's `feeCharged > maxFee` check never trips (NaN comparisons are false) — the claim proceeded at any spread; `withdraw` garbage degraded to an `Infinity` cap ("no cap set"); `payLightningInvoice`/`fetchL402` ceilings degraded the same way. Every numeric guard option now throws on an unreadable value before any I/O (`requireNumericOption`) — absent is a choice, garbage is a bug. Also: `batchTransferTokens` entries with no readable receiver now fail closed (previously the allowlist gate was silently skipped for them). - **Misspelled guard options now throw instead of meaning "no cap".** `checkL402Amount({ maxAmountSat: 500 })` used to return ok — the keystroke that feels like setting a ceiling silently removed it. All option-taking guards in `lib/fee-guards.js` reject unknown keys, matching the wrapper's existing strictness. - **`claimDeposit`'s fee ceiling is size-aware.** The flat 5,000-sat default authorized the SSP to take 83% of a 6,000-sat deposit. The default is now `maxFeePct` (10%) of the quoted credit — the same posture as `withdraw` — with explicit `maxFeeSats` still winning and an unreadable quote failing closed. - **`estimateFirstFeeCap`'s estimate-driven growth is bounded.** The live estimate could raise its own cap without limit, so an inflated estimate from a hostile counterparty grew the cap instead of tripping it. Growth is now capped at 3× the amount-scaled cap (override with `maxCapSats`). - **`l402-paywalls.js` uses the library fee cap.** The example script inlined `max(10, 0.5%)` — re-inheriting the exact under-cap failure (`floor 25`) already fixed in `lib/fee-guards.js` for anyone who copy-pasted it. ### Added - **Unilateral-exit backup — the "leaf vault."** A Spark seed alone **cannot** unilaterally exit to L1: exit needs the tree of pre-signed node/refund txs ("leaf material") that operators hand the wallet at claim/transfer time, and that material is **not** derivable from the seed. This release adds the backup half; the exit itself is performed by Blink's production tool (below): - `lib/leaf-vault.js` + `skills/sparkbtcbot/scripts/leaf-vault.js` — continuously mirror the leaf material to `~/.spark/leaf-vault/current.json` in **`spark.unilateral-exit-bundle.v1`**, the exact bundle format consumed by [blinkbitcoin/spark-unilateral-exit](https://github.com/blinkbitcoin/spark-unilateral-exit)'s CLI. Each node is stored as its **canonical `TreeNode` protobuf hex** (the SDK's exact wire bytes), so recovery is a byte-faithful decode, not a fragile field-by-field JSON reconstruction. `enableLeafVault(wallet)` snapshots on boot, on every `balance:update`, and on a safety-net timer; a **fail-loud self-check** throws if the reached-into SDK internals move; an **integrity gate** refuses to write a vault unless it provably reconstructs every leaf's exit chain **offline** (no operators). `verifyVault()` / `npm run leaf-vault -- verify` re-checks any vault (exit codes: 0 ok, 1 broken/critical, 2 indeterminate). - **Recovery is performed by Blink's tool, not a bundled one.** The operatorless exit is done by [blinkbitcoin/spark-unilateral-exit](https://github.com/blinkbitcoin/spark-unilateral-exit) — tested on real mainnet, with per-leaf economic triage (skips uneconomical dust) and TRUC confirm-and-continue plus the CPFP fee-bumping and ~2,000-block CSV timelock. Point it at the leaf-vault's bundle plus an L1 fee UTXO you control; see `references/unilateral-exit.md`. (An earlier hand-rolled `scripts/unilateral-exit.js` was dropped as naive by comparison.) - **Fee guardrails on every value-moving path** (`lib/fee-guards.js`). Bounds both the fee **and** the amount on Lightning sends, L402 payments, deposit claims, and withdrawals, so a tampered SSP quote or an amountless invoice can't move more than the caller allowed. Wired into `SparkAgent`: `payLightningInvoice` takes `maxFeeSats` + `maxAmountSats`; deposit claims use the SDK's `claimStaticDepositWithMaxFee`; L402 enforces an amount ceiling. - Explicit runtime dep `@noble/curves`, plus the `npm run leaf-vault` script. ### Changed - **Corrected overstated backup/exit claims** in `SKILL.md` and `references/architecture.md`. "The mnemonic is the entire backup" and "Spark guarantees you can always exit to L1" are now accurate: the seed recovers the wallet **while operators are online**, but **unilateral exit additionally requires the locally-backed-up leaf material**. Normal recovery is unchanged — the correction is specifically the operators-gone case. ### Security - **leaf-vault: refuse to publish a partial capture over a complete bundle.** `getLeaves` can transiently return a non-empty *subset* of the wallet's leaves (its coordinator recover path swallows failures), and each present leaf still passes the integrity gate — so an unchecked partial snapshot would atomically overwrite a complete bundle, health still green, silently stranding the dropped leaves' only backup. The snapshot now keeps the prior complete bundle (and surfaces the failure) unless a matching balance decrease confirms the dropped leaves were genuinely spent. Generalizes the existing empty-`getLeaves` guard to the partial case. - **Withdrawal fee ceiling now binds the executed exit.** `withdraw` checked a fetched quote against a ceiling but then executed the exit without passing a fee, so a re-priced or unreadable quote bypassed the ceiling. It now passes the vetted `feeQuote` into the SDK (which derives `feeAmountSats` + `feeQuoteId`), so the operator charges the fee that was checked, and fails **closed** when the quote fee is unreadable instead of deferring to an SDK cap that does not exist for this path. - **leaf-vault guards now judge OWNED sats, not available.** The balance probe read the SDK's top-level `balance` first — a deprecated alias for **available** — so the shrink/empty guards and the CLI's severity judgment silently excluded funds locked in in-flight transfers/swaps: a snapshot during a lock window could overwrite the prior bundle and drop a still-owned leaf's only exit material. The probe now prefers `satsBalance.owned`, stated in one `ownedSats()` helper, and the test mocks use the real SDK response shape so the ordering is pinned. - **Network label is derived through the proto codec and gated.** With no `networkLabel` (the documented raw-SDK path), the fallback stringified the leaf's **numeric** proto enum — persisting `network: "1"`, which verifies green locally but is refused by Blink's recovery CLI, and mis-mapping the online ancestor query via the utils enum's reverse mapping. The label now goes through `networkToJSON`, and a bundle whose network is not one Blink accepts (`MAINNET/REGTEST/TESTNET/SIGNET/LOCAL`) is refused loudly instead of written. - **A different wallet or network can no longer clobber the shared default vault.** The snapshot now refuses to overwrite a prior bundle whose `network` or `walletIdentityPublicKey` doesn't match the capturing wallet (e.g. a REGTEST run on a machine whose bundle protects a mainnet wallet) — set `SPARK_LEAF_VAULT_PATH` per wallet instead. - **Blocked shrink guards now rescue fresh leaves (union bundle).** When the shrink guard blocks a partial capture, leaves present only in the fresh capture (a new deposit, a claimed transfer) previously had no persisted exit material for as long as the guard tripped. The snapshot now writes a union bundle (fresh capture + provable carried-over prior leaves) when it passes the same offline proof, then still fails loudly. - **Chronic empty captures now surface.** A persistently-empty `getLeaves` on a funded wallet was accounted as success — failure counter reset, `BROKEN` marker removed, health green — while the bundle staled. Skips no longer count as success; consecutive transient-empty skips trip the `BROKEN` marker, and the marker is cleared only by a genuinely persisted bundle (or a confirmed-empty wallet). - **Setup prompts no longer echo the passphrase.** The interactive prompt never disabled terminal echo, so the passphrase appeared on screen and in any pty recording (tmux/asciinema/`script`); it now uses raw mode on a TTY. Piped input (`printf 'pass\npass\n' | npm run setup`) previously hung on the confirm prompt because the remainder of a stdin chunk was dropped; both prompt paths now carry unconsumed input across prompts. - **`seed.enc` publish is race-free and power-loss durable.** The exclusive create had a check-then-act (TOCTOU) window in which two concurrent setups could silently swap the seed file, and its writer skipped the parent-directory fsync the leaf-vault writer documents as load-bearing. All persistence now goes through one shared writer (`lib/atomic-file.js`) that publishes exclusively via kernel-atomic `link(2)` and fsyncs the parent directory. ### Fixed - The leaf-vault CLI ignored `SPARK_LEAF_VAULT_PATH` set only in `.env` (the default was frozen at module load, before the CLI loaded dotenv) — it could report a false CRITICAL for a funded wallet whose real vault sat at the configured path. The CLI now lives in `scripts/leaf-vault-cli.js` (loads dotenv first) and the path default is resolved lazily. - A leaf-changing event that fired while a snapshot was in flight was absorbed with no follow-up capture until the 20-minute safety timer; the debounce now re-arms after a persisted run that left uncaptured changes. - `SparkAgent.cleanup()` now awaits `wallet.cleanup()` (a teardown rejection was an unhandled rejection), and the demo's token-balance printing used the raw SDK Map shape it no longer receives. - `enableLeafVault`'s fatal-failure classification matched on error-message wording; fatal reach-in errors now carry `code: "LEAF_VAULT_FATAL"`. - A second `loadMnemonicFromEnv()` call in one process threw a misleading "SPARK_PASSPHRASE not set" after the first call cleared the env var; both cases now throw `code: "NO_PASSPHRASE"` with an explanatory message. - `references/agent-class.md` shipped a pre-review vault integration whose `cleanup()` threw a `TypeError` at runtime and a `withdraw()` missing the fee-quote binding/fail-closed fixes; the reference now mirrors the shipped `SparkAgent`. - **Receive-artifact guidance: which of the five receive rails to hand out.** A bot asked for "a spark address for 1000 sats" produced a native Spark invoice — which is address-*shaped* (same `spark1…` bech32m prefix as a bare address, with an embedded signed payment request) but payable ONLY by Spark-SDK code via `fulfillSparkInvoice`; the user's Xverse wallet couldn't pay it. SKILL.md now carries a decision table: "invoice"-type asks default to a BOLT11 via `createLightningInvoice({ includeSparkAddress: true })` (payable by any Lightning wallet, free for Spark-wallet payers via the fallback; 1-hour expiry silently by default, overridable on request); "address"-type asks get the bare, non-expiring `getSparkAddress()`; native Spark invoices only for known SDK-agent payers; L1 for on-chain/large amounts — plus a one-line alternatives disclosure instead of interrogating the user. `spark-invoices.md` leads with the payability warning and its `fulfillSparkInvoice` example no longer shows a legacy `sp1…` string the SDK rejects. Three new evals (10–12) pin the trap phrases. - **`fetchL402`/`previewL402` existed only in the reference doc.** `agent-class.md` and `l402.md` both documented them as `SparkAgent` methods, but the shipped class never had them (`TypeError: not a function` for anyone importing it — found by a deployed bot); the doc also advertised a `createSparkInvoice` that exists nowhere and silently omitted eight shipped methods. The L402 methods now ship on `SparkAgent` (ported from the reviewed reference implementation, amount-capped and routed through the guarded Lightning path), the doc's code listing is regenerated from the shipped file, and a new two-way parity test fails the suite if the doc's method surface and the shipped class ever diverge again. - **`SparkAgent.payLightningInvoice` dropped the amount on amountless invoices.** It passed `amountSats` to the fee estimate but never forwarded it to the actual payment, so zero-amount invoices always failed at pay time with `"must specify amountSatsToSend"` (dry run green, real send broken — found by a deployed bot). It now forwards `amountSatsToSend` **only when the invoice is amountless**, matching the SDK's contract, which equally rejects the parameter for invoices that carry an amount. `references/lightning.md` now documents the `amountSats` (estimate) vs `amountSatsToSend` (pay) naming split. - **Phantom `dryRun` on the raw SDK — incident-driven fix.** A deployed bot passed `dryRun: true` to raw `wallet.transfer()`; the SDK has no such option, JS silently dropped it, and the "preview" call **sent real sats** (both calls sent; funds reached the intended address). Three-layer fix: SKILL.md scopes `dryRun` to the `SparkAgent` wrapper and warns that raw `wallet.*` money calls silently ignore unknown keys AND bypass the allowlist/fee guards; `references/wallet.md`'s transfer section carries the same warning inline; and `SparkAgent`'s money-moving methods (`transfer`, `transferTokens`, `withdraw`, `claimDeposit`, `payLightningInvoice`) now **throw on unknown option keys**, so a mistyped flag fails loudly instead of silently spending. New skill eval (id 9) pins the behavior. ### Removed - `loadEncryptedMnemonic` (unused alias of `loadMnemonic`) and the dead `operatorSet`/`appVersion` snapshot options. ### Added (hardening pass) - npm subpath exports `sparkbtcbot/leaf-vault` (SDK reach-in API) and `sparkbtcbot/leaf-vault/core` (SDK-free validators) so npm-package consumers can actually attach the vault the docs describe. - `judgeMissingVault()` — the CLI's 0/1/2 exit-code severity contract as a testable function; `vaultHealth()` now also reports `consecutiveTransientSkips`. - 29 new unit tests: network derivation, identity guard, union rescue, skip accounting + `BROKEN` lifecycle (fatal vs threshold vs recovery), debounce coalescing, interval safety net, dispose/double-dispose races, the missed-event re-arm, `verifyVault`'s ENOENT contract, atomic-writer failure paths, exports-map resolution, and the SparkAgent enabled path. ## 0.3.1 — 2026-07-03 ### Changed - **Bumped the Spark SDKs and test tooling:** `@buildonspark/spark-sdk` `0.8.1 → 0.8.8`, `@buildonspark/issuer-sdk` `0.1.37 → 0.1.44`, `vitest` `4.1.7 → 4.1.9`. These are all patch-level upstream releases — every SDK method this skill calls keeps a byte-identical signature, so there are no API changes for consumers. Beyond the security patch below, the bump brings a fix that waits for optimization-held balances before reporting "insufficient funds" on a send (fewer spurious transfer failures) and a timeout on token-transaction RPC calls. - **Migrated off deprecated SDK calls in the example scripts and helpers.** `wallet.cleanupConnections()` → `wallet.cleanup()` (13 call sites across the example scripts, the `SparkAgent` wrapper, and the reference docs), and the issuer helper's positional `mintTokens(amount)` / `burnTokens(amount)` → the object form `mintTokens({ tokenAmount, tokenIdentifier })`. Both old forms were flagged `@deprecated … will be removed in a future version` by the SDK; moving now keeps the example code working across future SDK releases. No behavior change — the replacements are the SDK's own documented equivalents, and both paths are exercised by the test suite on REGTEST. - **Fixed stale install pins in `SKILL.md`.** The setup instructions still told users to `npm install @buildonspark/spark-sdk@^0.7.17` / `@buildonspark/issuer-sdk@^0.1.35` — two majors behind. They now match the bumped versions. ### Security - Raising the `@buildonspark/spark-sdk` floor to `^0.8.8` guarantees the **protobufjs 8.0.1** patch for **GHSA-xq3m-2v4x-88gg** (shipped in spark-sdk 0.8.2), rather than merely allowing it within the previous `^0.8.1` range. `npm audit` is clean. ## 0.3.0 — 2026-05-29 ### Added - **Opt-in outbound recipient allowlist** (`lib/recipients-allowlist.js`). When `~/.spark/recipients.allow` exists with at least one entry, transfers and cooperative withdrawals to any address not on the list fail; a missing or empty/all-comments file leaves the gate unenforced. Spark (`sp1…`) and L1 addresses share one file (one per line, `#` comments allowed), matched as plain strings. New exports `loadRecipientsAllowlist`, `assertRecipientAllowed`, `DEFAULT_ALLOWLIST_PATH`; enforced in `spark-agent.js` on transfer/withdraw (Lightning BOLT11 sends are not gated, since they target node pubkeys). This is an operator-surprise guardrail, **not** a defense against a compromised agent (which can rewrite the file) — `sparkbtcbot-proxy` remains the path for hard-enforced, server-side limits. ### Security - **Atomic, crash-safe seed writes.** `saveEncryptedMnemonic()` and the mnemonic-backup writer now write via temp file + `fsync` + atomic rename instead of a plain exclusive-create, so a crash mid-write can no longer leave a partial or corrupt `seed.enc`. Exclusive-create semantics (refuses to overwrite) and `0o600` permissions are unchanged. - **Passphrase env hygiene.** `loadMnemonicFromEnv()` now clears `SPARK_PASSPHRASE` from `process.env` immediately after reading it, on all paths, shrinking the window it lives in process memory (debugger snapshots, child-process inheritance, crash dumps). Opt out with `loadMnemonicFromEnv({ clearEnv: false })` if a later path must re-read it. Crypto primitives unchanged (scrypt N=2¹⁷, AES-256-GCM). ## 0.2.0 — 2026-05-29 ### Changed - **Runtime dependencies are now declared in `dependencies` instead of `devDependencies`.** `@buildonspark/spark-sdk`, `@buildonspark/issuer-sdk`, `dotenv`, and `light-bolt11-decoder` previously lived in `devDependencies`, so installing the package as a project dependency (`npm install sparkbtcbot-skill`) did **not** pull them — the example scripts then failed with `ERR_MODULE_NOT_FOUND` until a separate manual SDK install. They now install automatically. `vitest` remains the only `devDependency`. - Bumped the Spark SDKs and tooling: `@buildonspark/spark-sdk` `0.7.17 → 0.8.1`, `@buildonspark/issuer-sdk` `0.1.35 → 0.1.37`, `dotenv` `^16 → ^17.4.2`, `vitest` `4.1.5 → ^4.1.7`. Consistent caret (`^`) ranges throughout. ### Security - The `@buildonspark/spark-sdk` 0.8.0 bump enables **signing-operator TLS certificate verification by default**. Earlier SDK versions defaulted to `rejectUnauthorized: false` (TLS-encrypted but certificate-unverified) for signing-operator connections unless a `certPath` was supplied — which this skill never did — leaving that channel open to an active man-in-the-middle. 0.8.x verifies by default; disabling now requires an explicit `SPARK_DANGEROUSLY_DISABLE_TLS_VERIFICATION` flag and is restricted to local (`localhost`/`*.minikube.local`) hostnames. - The SDK bump also pulled patched transitive dependencies (`protobufjs`, `ws`), clearing two moderate-severity advisories. `npm audit` is now clean. ## 0.1.3 — 2026-05-22 ### Security - `skills/sparkbtcbot/scripts/l402-paywalls.js` no longer logs the Lightning payment preimage. The preimage is the L402 authorization secret (it goes directly into the `Authorization` header); printing even a prefix of it to stdout risked leaking it into an agent's captured transcript. ## 0.1.2 — 2026-05-19 Repo-health and test-coverage release. Published-package contents unchanged from 0.1.0 (no runtime, API, or shipped-file changes). ### Added - Community-health files: `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md` (Contributor Covenant v2.1), `SECURITY.md` with private disclosure to eric@yvrbtclabs.dev. - GitHub Actions CI (`.github/workflows/ci.yml`) running `npm test` on Node 18, 20, and 22 for push and PR against `main`. - 16 new unit tests (total now 72): - `tests/unit/skill-content.test.js` — covers `getSkillContent`, `getReference`, `listReferences`, `skillPath`, `referencesDir`, including a reference-doc anti-drift check against the names promised in the README. - `tests/unit/plugin-manifest.test.js` — validates `.claude-plugin/marketplace.json` JSON shape and that every referenced skill path resolves to a real `SKILL.md`. - `tests/unit/encrypted-seed.test.js` — adds tests for `loadMnemonicFromEnv` (env-reading + missing-passphrase) and for the unsupported version/kdf/cipher byte rejection paths plus the too-short-file guard. ## 0.1.0 — 2026-05-10 Initial public release. ### Added - **Encrypted-at-rest BIP39 mnemonic storage** (`lib/encrypted-seed.js`) using scrypt (N=2^17) + AES-256-GCM, zero npm runtime dependencies. - **Library API** (`import ... from "sparkbtcbot-skill"`): - `saveEncryptedMnemonic({ mnemonic, passphrase, path? })` - `loadMnemonic({ passphrase, path? })` - `loadEncryptedMnemonic` (alias of `loadMnemonic`) - `loadMnemonicFromEnv()` — reads `SPARK_PASSPHRASE` / `SPARK_SEED_PATH` - `writeMnemonicBackupFile(mnemonic, { dir? })` — writes the one-time mnemonic backup file used by setup - `DEFAULT_SEED_PATH` constant (`~/.spark/seed.enc`) - **Skill-content helpers** for non-Claude LLM frameworks: - `getSkillContent()` — returns the always-loaded `SKILL.md` body - `getReference(name)` — loads a specific reference doc by name - `listReferences()` — lists all available reference doc names - `skillPath`, `referencesDir`, `lessonsPath` constants - **Claude Code plugin marketplace manifest** (`.claude-plugin/marketplace.json`) so the skill is installable via `claude plugin marketplace add` + `claude plugin install`. - **Skill content** under `skills/sparkbtcbot/`: SKILL.md, LESSONS.md, and 9 reference docs covering architecture, wallet ops, Lightning, tokens, Spark invoices, L402 paywalls, the SparkAgent class, and encrypted-seed setup. - **Example scripts** under `skills/sparkbtcbot/scripts/` for setup, balance/deposits, payment flow, token operations, the SparkAgent class, and L402 paywalls. - **Test suite** (vitest, 56 unit tests) covering the encryption library and round-trip behavior. - TypeScript declarations (`lib/index.d.ts`). ### Security - File-handoff for fresh-generated mnemonics: the setup script writes the new mnemonic to a persistent file (`~/.spark/MNEMONIC_BACKUP_.txt`, mode 0600) instead of stdout, so Bash-captured stdout from agent contexts doesn't leak the words into conversation transcripts. The user reads, copies offline, and `rm`s the file. - `wx` flag on encrypted-seed writes — refuses to overwrite an existing seed file. - Strict mnemonic validation in setup script: exact word counts (12/15/18/21/24), lowercase-alphabetic words only, SDK round-trip verify before any file is written. - `light-bolt11-decoder` pinned to exact 3.2.0 (single-maintainer dep; pin protects against malicious upstream patch releases).