@@ -110,7 +110,15 @@ const wallet = await createWallet({ network: 'main' })
110110| --------| --------| ---------| -------------|
111111| ` pay(options) ` | ` PaymentOptions ` | ` Promise<TransactionResult> ` | Payment via MessageBox P2P (PeerPayClient) |
112112| ` send(options) ` | ` SendOptions ` | ` Promise<SendResult> ` | Multi-output: P2PKH + OP_RETURN + PushDrop in one tx |
113- | ` fundServerWallet(request, basket?) ` | ` PaymentRequest, string? ` | ` Promise<TransactionResult> ` | Fund a ServerWallet using BRC-29 derivation |
113+ | ` fundServerWallet(request, basket?) ` | ` PaymentRequest, string? ` | ` Promise<TransactionResult> ` | Fund a ServerWallet using BRC-29 derivation (legacy) |
114+
115+ ### Direct Payments — BRC-29 Wallet Payment Internalization (WalletCore)
116+
117+ | Method | Params | Returns | Description |
118+ | --------| --------| ---------| -------------|
119+ | ` createPaymentRequest(options) ` | ` { satoshis, memo? } ` | ` PaymentRequest ` | Generate BRC-29 derivation data for someone to pay you |
120+ | ` sendDirectPayment(request) ` | ` PaymentRequest ` | ` Promise<DirectPaymentResult> ` | Create BRC-29 derived P2PKH tx + return remittance data |
121+ | ` receiveDirectPayment(payment) ` | ` IncomingPayment ` | ` Promise<void> ` | Internalize into wallet balance via ` wallet payment ` (NOT into a basket) |
114122
115123### Tokens (tokens module)
116124
@@ -193,12 +201,11 @@ const wallet = await ServerWallet.create({
193201
194202| Method | Params | Returns | Description |
195203| --------| --------| ---------| -------------|
196- | ` createPaymentRequest(options) ` | ` { satoshis, memo? } ` | ` PaymentRequest ` | Generate BRC-29 payment request for desktop client |
197- | ` receivePayment(payment) ` | ` IncomingPayment ` | ` Promise<void> ` | Internalize payment from desktop using ` wallet payment ` protocol |
204+ | ` receivePayment(payment) ` | ` IncomingPayment ` | ` Promise<void> ` | ** Deprecated.** Use ` receiveDirectPayment() ` (inherited from WalletCore). Kept for backward compat with ` server_funding ` label. |
198205
199206### Shared Methods
200207
201- ServerWallet has all the same methods as BrowserWallet (pay, send, createToken, inscribeText, etc.) via the same module composition pattern.
208+ ServerWallet has all the same methods as BrowserWallet (pay, send, createToken, inscribeText, createPaymentRequest, sendDirectPayment, receiveDirectPayment, etc.) via the same module composition pattern.
202209
203210---
204211
@@ -714,32 +721,64 @@ const incoming = await wallet.listIncomingPayments()
714721await wallet .acceptIncomingPayment (incoming [0 ], ' received-payments' )
715722```
716723
717- ### 7.8 Server Wallet: Create, Fund, Receive, Balance
724+ ### 7.8 Direct Payments (BRC-29 Wallet Payment Internalization)
718725
719726``` typescript
720- // Server side: create wallet
721- const { ServerWallet } = await import (' @bsv/simple/server' )
722- const server = await ServerWallet .create ({ privateKey: ' hex' , network: ' main' })
727+ // Direct payments work on BOTH browser and server wallets.
728+ // Funds go directly into the wallet's spendable balance (NOT into a basket).
729+
730+ // --- Flow: Browser pays Server ---
723731
724732// Server: generate payment request
725- const request = server .createPaymentRequest ({ satoshis: 50000 })
733+ const request = serverWallet .createPaymentRequest ({ satoshis: 2000 })
726734
727- // Client: fund server wallet
728- const result = await wallet . fundServerWallet (request , ' server-funding ' )
735+ // Browser: create BRC-29 derived P2PKH transaction
736+ const payment = await browserWallet . sendDirectPayment (request )
729737
730- // Client : send tx to server
731- await fetch (' /api/server-wallet?action= receive' , {
738+ // Browser : send tx + remittance to server (via API)
739+ await fetch (' /api/receive-payment ' , {
732740 method: ' POST' ,
741+ headers: { ' Content-Type' : ' application/json' },
733742 body: JSON .stringify ({
734- tx: Array .from (result .tx ),
735- senderIdentityKey: wallet . getIdentityKey () ,
736- derivationPrefix: request .derivationPrefix ,
737- derivationSuffix: request .derivationSuffix ,
738- outputIndex: 0
743+ tx: Array .from (payment .tx ),
744+ senderIdentityKey: payment . senderIdentityKey ,
745+ derivationPrefix: payment .derivationPrefix ,
746+ derivationSuffix: payment .derivationSuffix ,
747+ outputIndex: payment . outputIndex
739748 })
740749})
741750
742- // Server: receive payment
751+ // Server: internalize
752+ await serverWallet .receiveDirectPayment ({ tx , senderIdentityKey , derivationPrefix , derivationSuffix , outputIndex: 0 })
753+
754+ // --- Flow: Server pays Browser ---
755+
756+ // Browser: create payment request
757+ const request = browserWallet .createPaymentRequest ({ satoshis: 100 })
758+ // ... send request to server via API ...
759+
760+ // Server: create payment
761+ const payment = await serverWallet .sendDirectPayment (request )
762+ // ... return payment data to browser ...
763+
764+ // Browser: internalize into wallet balance
765+ await browserWallet .receiveDirectPayment ({
766+ tx: paymentData .tx ,
767+ senderIdentityKey: paymentData .senderIdentityKey ,
768+ derivationPrefix: paymentData .derivationPrefix ,
769+ derivationSuffix: paymentData .derivationSuffix ,
770+ outputIndex: paymentData .outputIndex
771+ })
772+ ```
773+
774+ ### 7.8b Server Wallet: Legacy Fund Flow
775+
776+ ``` typescript
777+ // Legacy pattern — prefer sendDirectPayment/receiveDirectPayment instead
778+ const { ServerWallet } = await import (' @bsv/simple/server' )
779+ const server = await ServerWallet .create ({ privateKey: ' hex' , network: ' main' })
780+ const request = server .createPaymentRequest ({ satoshis: 50000 })
781+ const result = await wallet .fundServerWallet (request , ' server-funding' )
743782await server .receivePayment ({ tx , senderIdentityKey , derivationPrefix , derivationSuffix , outputIndex: 0 })
744783```
745784
@@ -873,6 +912,7 @@ interface InscriptionResult extends TransactionResult { type: InscriptionType; d
873912interface ServerWalletConfig { privateKey: string ; network? : Network ; storageUrl? : string }
874913interface PaymentRequest { serverIdentityKey: string ; derivationPrefix: string ; derivationSuffix: string ; satoshis: number ; memo? : string }
875914interface IncomingPayment { tx: number [] | Uint8Array ; senderIdentityKey: string ; derivationPrefix: string ; derivationSuffix: string ; outputIndex: number ; description? : string }
915+ interface DirectPaymentResult extends TransactionResult { senderIdentityKey: string ; derivationPrefix: string ; derivationSuffix: string ; outputIndex: number }
876916```
877917
878918### DID Types
0 commit comments