beignet 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +23 -12
  2. package/dist/cli/beignet-node.js +289 -163
  3. package/dist/cli/beignet-node.js.map +1 -1
  4. package/dist/cli/cli.js +61 -11
  5. package/dist/cli/cli.js.map +1 -1
  6. package/dist/cli/config.js +28 -4
  7. package/dist/cli/config.js.map +1 -1
  8. package/dist/cli/daemon.js +155 -24
  9. package/dist/cli/daemon.js.map +1 -1
  10. package/dist/cli/errors.js +9 -1
  11. package/dist/cli/errors.js.map +1 -1
  12. package/dist/cli/fs-utils.js +73 -0
  13. package/dist/cli/fs-utils.js.map +1 -0
  14. package/dist/cli/instance-lock.js +1 -1
  15. package/dist/cli/instance-lock.js.map +1 -1
  16. package/dist/cli/openapi.js +48 -5
  17. package/dist/cli/openapi.js.map +1 -1
  18. package/dist/cli/process-faults.js +37 -0
  19. package/dist/cli/process-faults.js.map +1 -0
  20. package/dist/cli/restore.js +4 -0
  21. package/dist/cli/restore.js.map +1 -1
  22. package/dist/lightning/channel/channel-state.js.map +1 -1
  23. package/dist/lightning/channel/channel.js +367 -9
  24. package/dist/lightning/channel/channel.js.map +1 -1
  25. package/dist/lightning/channel/commitment-builder.js +2 -1
  26. package/dist/lightning/channel/commitment-builder.js.map +1 -1
  27. package/dist/lightning/channel/types.js.map +1 -1
  28. package/dist/lightning/gossip/pathfinding.js +5 -1
  29. package/dist/lightning/gossip/pathfinding.js.map +1 -1
  30. package/dist/lightning/node/lightning-node.js +90 -12
  31. package/dist/lightning/node/lightning-node.js.map +1 -1
  32. package/dist/lightning/node/types.js.map +1 -1
  33. package/dist/lightning/storage/serialization.js +16 -0
  34. package/dist/lightning/storage/serialization.js.map +1 -1
  35. package/dist/lightning/storage/sqlite-storage.js +46 -0
  36. package/dist/lightning/storage/sqlite-storage.js.map +1 -1
  37. package/dist/transaction/index.js +25 -8
  38. package/dist/transaction/index.js.map +1 -1
  39. package/dist/types/cli/beignet-node.d.ts +11 -4
  40. package/dist/types/cli/daemon.d.ts +8 -0
  41. package/dist/types/cli/errors.d.ts +5 -1
  42. package/dist/types/cli/fs-utils.d.ts +11 -0
  43. package/dist/types/cli/process-faults.d.ts +9 -0
  44. package/dist/types/cli/types.d.ts +2 -0
  45. package/dist/types/lightning/channel/channel-state.d.ts +1 -0
  46. package/dist/types/lightning/channel/channel.d.ts +14 -0
  47. package/dist/types/lightning/channel/commitment-builder.d.ts +4 -0
  48. package/dist/types/lightning/channel/types.d.ts +2 -0
  49. package/dist/types/lightning/node/lightning-node.d.ts +4 -1
  50. package/dist/types/lightning/node/types.d.ts +2 -0
  51. package/dist/types/lightning/storage/serialization.d.ts +4 -0
  52. package/dist/types/lightning/storage/sqlite-storage.d.ts +1 -0
  53. package/dist/types/transaction/index.d.ts +3 -0
  54. package/dist/types/wallet/index.d.ts +1 -0
  55. package/dist/wallet/index.js +127 -100
  56. package/dist/wallet/index.js.map +1 -1
  57. package/docs/AI_AGENT_GUIDE.md +16 -4
  58. package/package.json +1 -1
package/README.md CHANGED
@@ -284,7 +284,7 @@ coordinator.exportDescriptors();
284
284
  <details>
285
285
  <summary><b>Encrypted storage and leveled logging</b></summary>
286
286
 
287
- The wallet persists through the host-injected `TStorage` interface (`storage: { getData, setData }`), and values are handed over as-is, so by default they are stored in plaintext. Persisted data is addresses, indexes, UTXOs, transactions, balance and fee estimates: no private keys and no mnemonic are ever written, so exposure is a privacy concern (full wallet history), not fund loss.
287
+ The wallet persists through the host-injected `TStorage` interface (`storage: { getData, setData }`), and values are handed over as-is, so by default they are stored in plaintext. Persisted data is addresses, indexes, UTXOs, transactions, balance and fee estimates: no private keys and no mnemonic are ever written, so exposure is a privacy concern (full wallet history), not fund loss. The staged send (`transaction`) is written without signing keys, so a key pair handed to `sweepPrivateKey` or `addExternalInputs` never reaches storage, and `send`, `sendMany`, `sendMax`, `buildPsbt` and `sweepPrivateKey` reset the staged send when they return, so a restart never replays an earlier call's recipients.
288
288
 
289
289
  Wrap any `TStorage` with `createEncryptedStorage` to encrypt at rest with AES-256-GCM under an HKDF-derived key from the seed. Pre-existing plaintext values pass through unchanged and migrate lazily as they are rewritten.
290
290
 
@@ -442,14 +442,17 @@ CLI: `beignet watchtower list|add <pubkey@host:port>|remove <uri>`, daemon flag
442
442
  The same node runs as an HTTP/SSE daemon for language-agnostic integrations, driven by a JSON CLI.
443
443
 
444
444
  ```bash
445
- # 1. Generate a mnemonic + ~/.beignet/config.json
445
+ # 1. Generate a mnemonic, an API token and ~/.beignet/config.json
446
446
  npx beignet init --network regtest
447
+ # {"ok":true,"result":{"message":"Initialized","mnemonic":"...","network":"regtest",
448
+ # "apiToken":"3f9c...64 hex...","note":"apiToken was generated and saved to config.json; ..."}}
447
449
 
448
- # 2. Start the daemon (add --daemon to background it)
450
+ # 2. Start the daemon (add --daemon to background it). It reads the token from
451
+ # config.json; --api-token or BEIGNET_API_TOKEN override it.
449
452
  BEIGNET_ELECTRUM_HOST=127.0.0.1 BEIGNET_ELECTRUM_PORT=60001 BEIGNET_ELECTRUM_TLS=false \
450
- npx beignet start --network regtest --api-token mytoken
453
+ npx beignet start --network regtest
451
454
 
452
- # 3. Drive it with the CLI (thin HTTP client, JSON out)
455
+ # 3. Drive it with the CLI (thin HTTP client, JSON out; it sends the token itself)
453
456
  npx beignet info --pretty
454
457
  npx beignet address
455
458
  npx beignet channel connect-and-open <pubkey> <host> <port> 200000
@@ -459,22 +462,26 @@ npx beignet invoice pay <bolt11>
459
462
 
460
463
  Electrum and most other settings come from `~/.beignet/config.json` or the environment (`BEIGNET_MNEMONIC`, `BEIGNET_ELECTRUM_HOST`, `BEIGNET_ELECTRUM_PORT`, `BEIGNET_NETWORK`, ...). Run `npx beignet help` for the full command and flag list.
461
464
 
462
- Or over HTTP directly:
465
+ `config.json` holds the mnemonic, so everything under `~/.beignet` is created owner-only (`0700` directories, `0600` files: config, pid file, database and sidecars, backups, SCB exports), the CLI runs `init`, `start`, `backup` and `restore` under umask `077`, and a config file an earlier release left readable is tightened the next time it is read, with a notice on stderr. Details in [src/cli/README.md](src/cli/README.md#file-permissions).
466
+
467
+ Or over HTTP directly, with the token `init` printed (or `apiToken` from `~/.beignet/config.json`):
463
468
 
464
469
  ```bash
465
- curl -X POST http://localhost:2112/invoice/create -H 'Authorization: Bearer mytoken' \
470
+ TOKEN=3f9c... # the apiToken from beignet init
471
+ curl -X POST http://localhost:2112/invoice/create -H "Authorization: Bearer $TOKEN" \
466
472
  -H 'Content-Type: application/json' -d '{"amountSats": 1000, "description": "coffee"}'
467
473
 
468
- curl -X POST http://localhost:2112/invoice/pay -H 'Authorization: Bearer mytoken' \
474
+ curl -X POST http://localhost:2112/invoice/pay -H "Authorization: Bearer $TOKEN" \
469
475
  -H 'Content-Type: application/json' -d '{"bolt11": "lnbcrt10n1..."}'
470
476
 
471
- curl -N http://localhost:2112/events -H 'Authorization: Bearer mytoken' # SSE stream
472
- curl http://localhost:2112/ready # load-balancer probe
477
+ curl -N http://localhost:2112/events -H "Authorization: Bearer $TOKEN" # SSE stream
478
+ curl http://localhost:2112/ready # load-balancer probe
473
479
  ```
474
480
 
475
481
  - Responses are `{ "ok": true, "result": {...} }` or `{ "ok": false, "error": { "code": "...", "message": "..." } }`.
476
482
  - Full spec at `GET /openapi.json`.
477
- - `GET /health`, `/ready`, `/openapi.json` and `/metrics` are auth-exempt; everything else requires the bearer token **when one is configured**. Auth is off unless you set `apiToken` or `apiKeys` (named keys with `readonly`/`invoice`/`admin` scopes), so configure a token before exposing the daemon anywhere. It binds `127.0.0.1` by default.
483
+ - Authentication is on for every install `beignet init` creates (releases after 0.22.0): `init` mints a random `apiToken` and saves it in `config.json` (run `init` again on an older config to add one). Auth is off only for a config with neither `apiToken` nor `apiKeys` (named keys with `readonly`/`invoice`/`admin` scopes); `beignet start` warns on stderr in that case. `GET /health`, `/ready` and `/openapi.json` are auth-exempt; `/metrics` only with `metricsPublic`; everything else requires the bearer token. The daemon binds `127.0.0.1` by default.
484
+ - While auth is off, three browser guards keep a web page from driving the loopback daemon (issue #1005): a request body must be `Content-Type: application/json` (else `415 UNSUPPORTED_MEDIA_TYPE`), an `Origin` other than the configured `cors` origin or a `Sec-Fetch-Site: cross-site` request is refused (`403 CROSS_SITE_REQUEST_REFUSED`), and the `Host` header must be the loopback name the daemon is bound on (else `421 HOST_NOT_ALLOWED`, which also defeats DNS rebinding). They apply to every route but `OPTIONS`; plain clients (curl, the CLI, the SDKs) send none of those headers and are unaffected, and with a token configured the guards do not run at all.
478
485
  - Embed it instead of shelling out: `import { startDaemon } from 'beignet/cli'`.
479
486
 
480
487
  ### FFOR offline receive
@@ -740,9 +747,13 @@ Beignet is under active development. Known gaps and caveats:
740
747
 
741
748
  Recommended safeguards in production:
742
749
 
743
- - Cap exposure with `maxPaymentSats` and `dailySpendLimitSats`.
750
+ - Cap exposure with `maxPaymentSats` and `dailySpendLimitSats`. Both count a
751
+ payment's amount plus its routing-fee cap, so the fee cannot slip past them:
752
+ the cap is `maxFeeSats`/`maxFeeMsat` when you pass one, and 1% of the
753
+ amount (never below 50 sats) when you do not.
744
754
  - Call `validatePayment()` before every send.
745
755
  - Set `backupPath` for automated database backups, and keep an SCB (`beignet backup scb`).
756
+ - Keep `~/.beignet` and the data directory owner-only. The CLI creates them `0700`/`0600` and tightens an older config on load; check them again after copying files between hosts.
746
757
  - Pass multiple `electrumServers` for connection redundancy.
747
758
  - Configure watchtowers so breaches are punished while you are offline.
748
759
  - Monitor `node:error` events and the `/health` endpoint.