diff options
| author | Adam Soltys <[email protected]> | 2026-08-01 19:38:30 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-08-01 19:38:30 -0700 |
| commit | 348a57004f94dd0f58c4e70769e65ca7ea3f7619 (patch) | |
| tree | 5f8cd2930abd9c1e05bb7c18e0bec239780281ef /tools/nwc-pouch-test.js | |
| parent | 9196f4804851a87c8356418b1c4cade6e87c54ba (diff) | |
| download | coinosv3-348a57004f94dd0f58c4e70769e65ca7ea3f7619.tar.gz coinosv3-348a57004f94dd0f58c4e70769e65ca7ea3f7619.zip | |
Simplify: one Lightning path, one balance, fewer features
Dropped: silent payments (feature, wallet chains, scan worker, indexer
config), Boltz submarine/reverse swaps (feature + swap.js + tools), the
third-party ark swap bridge (config, client flows, settings card — the
ASP's own Lightning send is the one path now), and the Consolidate
coins settings action.
The NWC pouch is gone with them: background answering now spends the
WHOLE ark balance. The IndexedDB record mirrors the real manager state
plus the chain-3 keys for its live coins and a change-index window; the
worker pays through the ASP exactly like the open app, and the app
folds the worker's spends, change, and key allocations back in on
connect (additive merge + reconcile against the server). A leftover
chain-6 pouch from the short-lived pouch era is swept home
automatically using the keys stored in its own record. The stated
tradeoff: same-origin script access now reaches the ark balance, not a
carve-out — the ark balance is walking-around money, the on-chain
wallet's keys are never mirrored, and per-connection NWC budgets remain
the enforced ceiling.
Bundle: 726KB -> 602KB.
Co-Authored-By: Claude Fable 5 <[email protected]>
Diffstat (limited to 'tools/nwc-pouch-test.js')
| -rw-r--r-- | tools/nwc-pouch-test.js | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/tools/nwc-pouch-test.js b/tools/nwc-pouch-test.js deleted file mode 100644 index 7846585..0000000 --- a/tools/nwc-pouch-test.js +++ /dev/null @@ -1,51 +0,0 @@ -// Pouch: key isolation + IndexedDB round trip (fake-indexeddb not available, -// so exercise the pure logic and assert the key branch is separate). -import { HDKey } from '@scure/bip32'; -import { mnemonicToSeedSync, generateMnemonic } from '@scure/bip39'; -import { wordlist } from '@scure/bip39/wordlists/english'; -import { hex } from '@scure/base'; -import { pouchKey, buildPouch, pouchBalance, POUCH_CHAIN } from '/home/adam/halwallet/src/nwc-pouch.js'; -import { secp256k1 } from '@noble/curves/secp256k1'; - -let ok = true; const check=(n,c,d='')=>{console.log(` ${c?'✓':'✗'} ${n}${d?' — '+d:''}`); if(!c) ok=false;}; -const account = HDKey.fromMasterSeed(mnemonicToSeedSync(generateMnemonic(wordlist))).derive("m/86'/0'/9'"); - -// the pouch branch must never collide with the branches that hold real coins -const arkKey = (i) => account.deriveChild(3).deriveChild(i).privateKey; -const mailbox = account.deriveChild(4).deriveChild(0).privateKey; -const preimg = account.deriveChild(5).deriveChild(0).privateKey; -check('pouch chain is 6', POUCH_CHAIN === 6); -const p0 = pouchKey(account, 0).privkey; -check('pouch key != ark vtxo key', hex.encode(p0) !== hex.encode(arkKey(0))); -check('pouch key != mailbox key', hex.encode(p0) !== hex.encode(mailbox)); -check('pouch key != ln preimage key', hex.encode(p0) !== hex.encode(preimg)); -check('pouch indices differ', hex.encode(pouchKey(account,0).privkey) !== hex.encode(pouchKey(account,1).privkey)); - -// buildPouch must export exactly the keys for the vtxos it carries — and no seed -const vtxos = [ - { id: 'a:0', bytes: 'deadbeef', keyIndex: 0, amountSat: 5000, expiryHeight: 100 }, - { id: 'b:0', bytes: 'cafebabe', keyIndex: 1, amountSat: 2000, expiryHeight: 100 }, -]; -const pouch = buildPouch({ - arkUrl: 'https://ark.coinos.io', esploraUrl: 'https://mempool.space/api', - network: 'mainnet', serverPubkey: '03ff', vtxos, account, - connections: [{ id:'c1', servicePk:'aa', serviceSk:'bb', clientPk:'cc', maxSat:1000, dailySat:5000 }], -}); -check('pouch carries both vtxos', pouch.vtxos.length === 2); -check('pouch balance sums', pouchBalance(pouch) === 7000, String(pouchBalance(pouch))); -// the worker can't derive, so the pouch ships a fixed key window covering -// funding indices and the worker's change/refund allocations -check('full key window shipped', Object.keys(pouch.keys).length === 50 && pouch.keys['0'] && pouch.keys['49']); -check('change base inside the window', pouch.nextKeyIndex === 20); -const blob = JSON.stringify(pouch); -check('NO seed/mnemonic in the pouch', !/mnemonic|seed|xprv/i.test(blob)); -// the exported keys must actually correspond to the pouch pubkeys -const derived = secp256k1.getPublicKey(hex.decode(pouch.keys['0']), true); -check('exported key matches its pouch pubkey', hex.encode(derived) === hex.encode(pouchKey(account,0).pubkey)); -// and must NOT be able to sign for an ordinary ark vtxo -check('pouch key cannot control chain-3 coins', - hex.encode(secp256k1.getPublicKey(hex.decode(pouch.keys['0']), true)) - !== hex.encode(secp256k1.getPublicKey(arkKey(0), true))); -check('connection service keys travel with it', pouch.connections[0].serviceSk === 'bb'); - -console.log(ok ? '\n✅ pouch isolates correctly' : '\n❌ failed'); process.exit(ok?0:1); |
