From ac40ea9bb6e6244934990e4f941a74d0f0dd17e3 Mon Sep 17 00:00:00 2001 From: Padreug Date: Sun, 6 Sep 2026 19:24:15 +0200 Subject: [PATCH] feat(lnbits): wrap the create_wallet RPC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The transport has exposed `create_wallet` (AUTH_ACCOUNT) since the RPC registry was written, but LnbitsClient never wrapped it — the ATM only ever needed the auto-created default wallet from `list_wallets`. Add `createWallet(name)` plus its `CreatedWallet` reply type. Account-scoped, so the envelope deliberately carries no `wallet_id`: that absence is what makes the server resolve auth to the Account rather than a Wallet. Not wrapped in `idempotent()` — a retry would mint a duplicate wallet, same reasoning as create_invoice. The reply carries the new wallet's adminkey/inkey, hence the type-level note not to log it verbatim. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_013A6683cCHnQxFUosx1krY4 --- packages/lnbits/src/client.ts | 12 ++++++++++++ packages/lnbits/src/index.ts | 1 + packages/lnbits/src/types.ts | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/packages/lnbits/src/client.ts b/packages/lnbits/src/client.ts index cb3645d..ad212a8 100644 --- a/packages/lnbits/src/client.ts +++ b/packages/lnbits/src/client.ts @@ -37,6 +37,7 @@ import type { CreateInvoiceBody, PayInvoiceBody, WalletInfo, + CreatedWallet, MachineConfigResponse, SubscribePaymentsBody, SubscribeAck, @@ -211,6 +212,17 @@ export class LnbitsClient { return data ?? [] } + /** + * Create an additional wallet on the calling account (`create_wallet`). + * + * Account-scoped (AUTH_ACCOUNT): the envelope carries no `wallet_id`, which + * is what makes the server resolve auth to the Account rather than a Wallet. + * NOT wrapped in `idempotent()` — a retry would mint a duplicate wallet. + */ + async createWallet(name: string): Promise { + return this.sendRpc('create_wallet', { body: { name } }) + } + /** Pull server-delivered machine config (operator pubkey + fee config) over * the authenticated transport — spirekeeper's `get_machine_config` RPC * (bitspire#70 P1). Lets a seed-only ATM configure itself with no per-machine diff --git a/packages/lnbits/src/index.ts b/packages/lnbits/src/index.ts index 9618a2f..e1e87c1 100644 --- a/packages/lnbits/src/index.ts +++ b/packages/lnbits/src/index.ts @@ -66,6 +66,7 @@ export type { CreateInvoiceBody, PayInvoiceBody, WalletInfo, + CreatedWallet, SubscribePaymentsBody, SubscribeAck, SubscribePush, diff --git a/packages/lnbits/src/types.ts b/packages/lnbits/src/types.ts index dd5e7a9..fdebb95 100644 --- a/packages/lnbits/src/types.ts +++ b/packages/lnbits/src/types.ts @@ -112,6 +112,15 @@ export interface WalletInfo { balance: number } +/** Reply shape of the `create_wallet` RPC — unlike WalletInfo it carries the + * fresh wallet's keys, so never log it verbatim. */ +export interface CreatedWallet { + id: string + name: string + adminkey: string + inkey: string +} + // ============================================================================ // Subscriptions // ============================================================================