Inspiration
People are starting to let AI agents act for them: paying invoices, buying API credits, settling subscriptions. Today the only options are "share your wallet and pray" (the agent gets unlimited, invisible access) or "manually approve every micro-payment" (unsustainable). There is no standard primitive for delegated, bounded, revocable Bitcoin spending. We wanted to build that primitive — and to make every "no" provable.
What it does
SatsGuard lets a human delegate a Lightning budget to an AI agent under cryptographic caveats, signed with their own key:
- a total cap in sats (e.g. 500,000), a per-payment ceiling, a recipient whitelist, an expiry;
- the agent pays autonomously over NIP-47 (Nostr Wallet Connect), NIP-44 v2 encrypted;
- every payment is checked before it is sent — an over-limit attempt is rejected locally, with zero network traffic, because the agent never holds the issuer key and cannot touch the gate code;
- every decision leaves a trace: signed receipts (nostr event kind 1339) for payments, refusal records for rejections;
- one tap revokes everything — a signed revocation event the agent cannot fake or undo.
How we built it
- Crypto core in pure JavaScript: BIP-340 schnorr + SHA-256, validated byte-identical against the 19 official BIP-340 test vectors (bitcoin/bips CSV) and cross-checked against @noble/curves.
- Mandate engine: Macaroon-style caveats + append-only hash-chained ledger
(
entryHash = H(prevHash ‖ canonical entry)) + anauthorizeSpend()gate shared by the wallet app and the agent CLI — the same code enforces both sides. - Wallet app: a single-file PWA (50 KB, zero dependencies, offline-capable), designed for mid-range phones and low bandwidth: dark high-contrast UI, tabular numerals, custom SVG icon system, no external fonts or CDNs.
- Agent CLI: NIP-47 client that pays via
pay_invoiceonly after the engine approves; deterministic simulator for the demo, live mode for real wallets. - STRIDE threat model rendered in-app: every threat mapped to its cryptographic defense.
Challenges we ran into
Implementing BIP-340 verification in pure JS from the spec alone (x-only keys, negated
keys, sha256(tag ‖ tag ‖ msg)), then proving it byte-identical on official vectors;
keeping one mandate engine enforced identically in the browser and in Node; designing
revocation as a separate issuer-signed event that dominates everything the agent holds.
Accomplishments that we're proud of
- 390 automated tests, 0 failures: official BIP-340 vectors, cross-validation against an audited library, engine invariants (tamper → detect, revoke → zero rights), and a headless-browser end-to-end test of the PWA (11/11) with zero page errors.
- The whole wallet is one 50 KB HTML file a judge can open locally — no install, no build, no account.
- A judge can re-run everything in 30 seconds:
npm install && npm test && node agent/cli.js --sim
What we learned
Delegation is a crypto problem before it is a UX problem: the hard part is making "revoked" and "over budget" mathematically true, not UI states. Building on an existing standard (NIP-47) beats inventing a new protocol — wallet vendors could adopt this layer without changing their transport.
What's next for SatsGuard
Mutinynet live payments end-to-end, third-party caveats (a service provider issues its own capped sub-mandate), agent identity via nostr npub, and a wallet-vendor review of the mandate engine as a shared standard.
Built With
- ai-agents
- bip-340
- bitcoin
- cryptography
- hash-chain
- javascript
- lightning
- nip-44
- nip-47
- noble-curves
- node.js
- nostr
- pwa
- schnorr-signatures