@did-btcr2/bitcoin 0.3.4 → 0.5.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 (113) hide show
  1. package/dist/cjs/client/http.js +9 -0
  2. package/dist/cjs/client/http.js.map +1 -0
  3. package/dist/cjs/client/rest/address.js +20 -28
  4. package/dist/cjs/client/rest/address.js.map +1 -1
  5. package/dist/cjs/client/rest/block.js +23 -22
  6. package/dist/cjs/client/rest/block.js.map +1 -1
  7. package/dist/cjs/client/rest/index.js +31 -84
  8. package/dist/cjs/client/rest/index.js.map +1 -1
  9. package/dist/cjs/client/rest/protocol.js +129 -0
  10. package/dist/cjs/client/rest/protocol.js.map +1 -0
  11. package/dist/cjs/client/rest/transaction.js +19 -21
  12. package/dist/cjs/client/rest/transaction.js.map +1 -1
  13. package/dist/cjs/client/rpc/index.js +79 -337
  14. package/dist/cjs/client/rpc/index.js.map +1 -1
  15. package/dist/cjs/client/rpc/interface.js +1 -6
  16. package/dist/cjs/client/rpc/interface.js.map +1 -1
  17. package/dist/cjs/client/rpc/json-rpc.js +40 -63
  18. package/dist/cjs/client/rpc/json-rpc.js.map +1 -1
  19. package/dist/cjs/client/rpc/protocol.js +134 -0
  20. package/dist/cjs/client/rpc/protocol.js.map +1 -0
  21. package/dist/cjs/connection.js +104 -0
  22. package/dist/cjs/connection.js.map +1 -0
  23. package/dist/cjs/constants.js +16 -5
  24. package/dist/cjs/constants.js.map +1 -1
  25. package/dist/cjs/errors.js.map +1 -1
  26. package/dist/cjs/index.js +21 -13
  27. package/dist/cjs/index.js.map +1 -1
  28. package/dist/cjs/types.js +5 -55
  29. package/dist/cjs/types.js.map +1 -1
  30. package/dist/esm/client/http.js +9 -0
  31. package/dist/esm/client/http.js.map +1 -0
  32. package/dist/esm/client/rest/address.js +20 -28
  33. package/dist/esm/client/rest/address.js.map +1 -1
  34. package/dist/esm/client/rest/block.js +23 -22
  35. package/dist/esm/client/rest/block.js.map +1 -1
  36. package/dist/esm/client/rest/index.js +31 -84
  37. package/dist/esm/client/rest/index.js.map +1 -1
  38. package/dist/esm/client/rest/protocol.js +129 -0
  39. package/dist/esm/client/rest/protocol.js.map +1 -0
  40. package/dist/esm/client/rest/transaction.js +19 -21
  41. package/dist/esm/client/rest/transaction.js.map +1 -1
  42. package/dist/esm/client/rpc/index.js +79 -337
  43. package/dist/esm/client/rpc/index.js.map +1 -1
  44. package/dist/esm/client/rpc/interface.js +1 -6
  45. package/dist/esm/client/rpc/interface.js.map +1 -1
  46. package/dist/esm/client/rpc/json-rpc.js +40 -63
  47. package/dist/esm/client/rpc/json-rpc.js.map +1 -1
  48. package/dist/esm/client/rpc/protocol.js +134 -0
  49. package/dist/esm/client/rpc/protocol.js.map +1 -0
  50. package/dist/esm/connection.js +104 -0
  51. package/dist/esm/connection.js.map +1 -0
  52. package/dist/esm/constants.js +16 -5
  53. package/dist/esm/constants.js.map +1 -1
  54. package/dist/esm/errors.js.map +1 -1
  55. package/dist/esm/index.js +21 -13
  56. package/dist/esm/index.js.map +1 -1
  57. package/dist/esm/types.js +5 -55
  58. package/dist/esm/types.js.map +1 -1
  59. package/dist/types/client/http.d.ts +22 -0
  60. package/dist/types/client/http.d.ts.map +1 -0
  61. package/dist/types/client/rest/address.d.ts +17 -19
  62. package/dist/types/client/rest/address.d.ts.map +1 -1
  63. package/dist/types/client/rest/block.d.ts +25 -16
  64. package/dist/types/client/rest/block.d.ts.map +1 -1
  65. package/dist/types/client/rest/index.d.ts +21 -51
  66. package/dist/types/client/rest/index.d.ts.map +1 -1
  67. package/dist/types/client/rest/protocol.d.ts +59 -0
  68. package/dist/types/client/rest/protocol.d.ts.map +1 -0
  69. package/dist/types/client/rest/transaction.d.ts +17 -17
  70. package/dist/types/client/rest/transaction.d.ts.map +1 -1
  71. package/dist/types/client/rpc/index.d.ts +112 -253
  72. package/dist/types/client/rpc/index.d.ts.map +1 -1
  73. package/dist/types/client/rpc/interface.d.ts +42 -6
  74. package/dist/types/client/rpc/interface.d.ts.map +1 -1
  75. package/dist/types/client/rpc/json-rpc.d.ts +21 -18
  76. package/dist/types/client/rpc/json-rpc.d.ts.map +1 -1
  77. package/dist/types/client/rpc/protocol.d.ts +83 -0
  78. package/dist/types/client/rpc/protocol.d.ts.map +1 -0
  79. package/dist/types/client/utils.d.ts +1 -0
  80. package/dist/types/connection.d.ts +82 -0
  81. package/dist/types/connection.d.ts.map +1 -0
  82. package/dist/types/constants.d.ts +17 -5
  83. package/dist/types/constants.d.ts.map +1 -1
  84. package/dist/types/errors.d.ts +5 -3
  85. package/dist/types/errors.d.ts.map +1 -1
  86. package/dist/types/index.d.ts +21 -13
  87. package/dist/types/index.d.ts.map +1 -1
  88. package/dist/types/network.d.ts +1 -0
  89. package/dist/types/types.d.ts +99 -696
  90. package/dist/types/types.d.ts.map +1 -1
  91. package/package.json +3 -3
  92. package/src/client/http.ts +28 -0
  93. package/src/client/rest/address.ts +24 -30
  94. package/src/client/rest/block.ts +29 -26
  95. package/src/client/rest/index.ts +38 -94
  96. package/src/client/rest/protocol.ts +153 -0
  97. package/src/client/rest/transaction.ts +23 -23
  98. package/src/client/rpc/index.ts +146 -379
  99. package/src/client/rpc/interface.ts +88 -53
  100. package/src/client/rpc/json-rpc.ts +53 -60
  101. package/src/client/rpc/protocol.ts +160 -0
  102. package/src/connection.ts +136 -0
  103. package/src/constants.ts +17 -5
  104. package/src/errors.ts +10 -3
  105. package/src/index.ts +81 -13
  106. package/src/types.ts +332 -972
  107. package/dist/cjs/bitcoin.js +0 -105
  108. package/dist/cjs/bitcoin.js.map +0 -1
  109. package/dist/esm/bitcoin.js +0 -105
  110. package/dist/esm/bitcoin.js.map +0 -1
  111. package/dist/types/bitcoin.d.ts +0 -60
  112. package/dist/types/bitcoin.d.ts.map +0 -1
  113. package/src/bitcoin.ts +0 -149
@@ -1,293 +1,152 @@
1
- import { BitcoinRpcClientConfig, BlockResponse, ChainInfo, CreateRawTxInputs, CreateRawTxOutputs, DerivedAddresses, GetBlockParams, ListTransactionsParams, ListTransactionsResult, RawTransactionResponse, RawTransactionV2, RpcClientConfig, SignedRawTx, UnspentTxInfo, VerbosityLevel, WalletTransaction } from '../../types.js';
1
+ import { BlockResponse, ChainInfo, CreateRawTxInputs, CreateRawTxOutputs, DerivedAddresses, GetBlockParams, ListTransactionsParams, ListTransactionsResult, RawTransactionResponse, RawTransactionV2, RpcConfig, SignedRawTx, UnspentTxInfo, VerbosityLevel, WalletTransaction } from '../../types.js';
2
+ import { HttpExecutor } from '../http.js';
2
3
  import { BitcoinRpcClient } from './interface.js';
3
4
  import { JsonRpcTransport } from './json-rpc.js';
4
5
  /**
5
- * Class representing a Bitcoin Core RPC client.
6
- * @class BitcoinCoreRpcClient
7
- * @type {BitcoinCoreRpcClient}
6
+ * Maps Bitcoin Core JSON-RPC method names to their parameter and return types.
7
+ * Used by {@link BitcoinCoreRpcClient.executeRpc} for compile-time safety.
8
+ */
9
+ export interface RpcMethodMap {
10
+ getbestblockhash: {
11
+ params: [];
12
+ result: string;
13
+ };
14
+ getblock: {
15
+ params: [string, number?];
16
+ result: BlockResponse;
17
+ };
18
+ getblockchaininfo: {
19
+ params: [];
20
+ result: ChainInfo;
21
+ };
22
+ getblockcount: {
23
+ params: [];
24
+ result: number;
25
+ };
26
+ getblockhash: {
27
+ params: [number];
28
+ result: string;
29
+ };
30
+ getbalance: {
31
+ params: [];
32
+ result: number;
33
+ };
34
+ getnewaddress: {
35
+ params: [string?, string?];
36
+ result: string;
37
+ };
38
+ gettransaction: {
39
+ params: [string, boolean?];
40
+ result: WalletTransaction;
41
+ };
42
+ getrawtransaction: {
43
+ params: [string, number?, string?];
44
+ result: RawTransactionResponse;
45
+ };
46
+ createrawtransaction: {
47
+ params: [CreateRawTxInputs[], CreateRawTxOutputs[], number?, boolean?];
48
+ result: string;
49
+ };
50
+ signrawtransactionwithwallet: {
51
+ params: [string];
52
+ result: SignedRawTx;
53
+ };
54
+ sendrawtransaction: {
55
+ params: [string, (number | string)?, (number | string)?];
56
+ result: string;
57
+ };
58
+ listtransactions: {
59
+ params: [string?, number?, number?, boolean?];
60
+ result: ListTransactionsResult;
61
+ };
62
+ listunspent: {
63
+ params: [number?, number?, string[]?, boolean?];
64
+ result: UnspentTxInfo[];
65
+ };
66
+ sendtoaddress: {
67
+ params: [string, number];
68
+ result: string;
69
+ };
70
+ signmessage: {
71
+ params: [string, string];
72
+ result: string;
73
+ };
74
+ verifymessage: {
75
+ params: [string, string, string];
76
+ result: boolean;
77
+ };
78
+ deriveaddresses: {
79
+ params: [string, number[]?];
80
+ result: DerivedAddresses[];
81
+ };
82
+ generatetoaddress: {
83
+ params: [number, string];
84
+ result: string[];
85
+ };
86
+ }
87
+ /** Method names that have typed definitions in {@link RpcMethodMap}. */
88
+ export type TypedRpcMethod = keyof RpcMethodMap;
89
+ /**
90
+ * Bitcoin Core RPC client.
8
91
  * @implements {BitcoinRpcClient}
9
92
  */
10
93
  export declare class BitcoinCoreRpcClient implements BitcoinRpcClient {
11
94
  #private;
12
- /**
13
- * Constructs a new {@link BitcoinCoreRpcClient} instance from a new {@link RpcClient | RpcClient}.
14
- * @param {RpcClientConfig} config The bitcoin-core client instance.
15
- * @example
16
- * ```
17
- * import BitcoinRpcClient from '@did-btcr2/method';
18
- * const bob = BitcoinRpcClient.connect(); // To use default polar config, pass no args. Polar must run locally.
19
- * ```
20
- */
21
- constructor(config: RpcClientConfig);
22
- /**
23
- * Get the config for the current BitcoinRpcClient object.
24
- * @returns {BitcoinRpcClient} The encapsulated {@link BitcoinRpcClient} object.
25
- * @example
26
- * ```
27
- * import BitcoinRpcClient from '@did-btcr2/method';
28
- * const alice = BitcoinRpcClient.connect();
29
- * const config = alice.config;
30
- * ```
31
- */
32
- get config(): BitcoinRpcClientConfig;
33
- /**
34
- * Get the client for the current BitcoinRpcClient object.
35
- * @returns {RpcClient} The encapsulated {@link RpcClient} object.
36
- * @example
37
- * ```
38
- * const alice = BitcoinRpcClient.connect();
39
- * const config = alice.client;
40
- * ```
41
- */
95
+ constructor(config: RpcConfig, executor?: HttpExecutor);
96
+ get config(): RpcConfig;
42
97
  get client(): JsonRpcTransport;
43
98
  /**
44
- * Static method initializes a static instance of BitcoinCoreRpcClient with the given configuration.
45
- * The RpcClient returned by this method does not have any named methods.
46
- * Use this method to create and pass a new RpcClient instance to a BitcoinCoreRpcClient constructor.
47
- *
48
- * @param {RpcClientConfig} config The configuration object for the client (optional).
49
- * @returns {BitcoinCoreRpcClient} A new RpcClient instance.
50
- * @example
51
- * ```
52
- * const options: RpcClientConfig = {
53
- * host: 'http://localhost:18443',
54
- * username: 'alice',
55
- * password: 'alicepass',
56
- * version: '28.1.0',
57
- * }
58
- * const alice = BitcoinCoreRpcClient.initialize(options); // Client config required
59
- * ```
60
- */
61
- static initialize(config?: RpcClientConfig): BitcoinCoreRpcClient;
62
- /**
63
- * Static method connects to a bitcoin node running the bitcoin core daemon (bitcoind).
64
- * To use default polar config, do not pass a config. See {@link DEFAULT_BITCOIN_NETWORK_CONFIG} for default config.
65
- * @required A locally running {@link https://github.com/jamaljsr/polar | Polar Lightning} regtest node.
66
- *
67
- * @param {?RpcClientConfig} config The configuration object for the client (optional).
68
- * @returns A new {@link BitcoinRpcClient} instance.
69
- * @example
70
- * ```
71
- * const alice = BitcoinRpcClient.connect();
72
- * ```
73
- */
74
- static connect(config?: RpcClientConfig): BitcoinCoreRpcClient;
75
- /**
76
- * Check if the given error is a JSON-RPC error.
77
- * @param {unknown} e The error to check.
78
- * @returns {boolean} True if the error is a JSON-RPC error, false otherwise.
79
- */
80
- isJsonRpcError(e: unknown): e is Error & {
81
- name: 'RpcError';
82
- code?: number;
83
- };
84
- /**
85
- * Executes a JSON-RPC command on the bitcoind node.
86
- * @param {MethodNameInLowerCase} method The name of the method to call.
87
- * @param {Array<any>} parameters The parameters to pass to the method.
88
- * @returns {Promise<T>} A promise resolving to the result of the command.
99
+ * Executes a typed JSON-RPC command on the bitcoind node.
89
100
  */
90
101
  private executeRpc;
91
- /**
92
- *
93
- * Map JSON-RPC error codes to HTTP status codes.
94
- * @param {number | undefined} code The JSON-RPC error code.
95
- * @returns {number} The corresponding HTTP status code.
96
- *
97
- * | Error type | HTTP code |
98
- * | -------------------------------| --------------------|
99
- * | Valid JSON-RPC failure | **400 / 404 / 422** |
100
- * | JSON-RPC authentication issues | **401 / 403** |
101
- * | Upstream bitcoind unreachable | **502** |
102
- * | Upstream timeout | **504** |
103
- * | Network transient errors | **503** |
104
- * | Unknown unexpected errors | **500** |
105
- */
106
- private mapRpcCodeToHttp;
107
- /**
108
- * Handle errors that occur while executing commands.
109
- * @param methods An array of {@link BatchOption} objects.
110
- * @param error The error that was thrown.
111
- * @throws Throws a {@link BitcoinRpcError} with the error message.
112
- */
113
- private handleError;
114
102
  /**
115
103
  * Returns the block data associated with a `blockhash` of a valid block.
116
- * @param {GetBlockParams} params See {@link GetBlockParams} for details.
117
- * @param {?string} params.blockhash The blockhash of the block to query.
118
- * @param {?number} params.height The block height of the block to query.
119
- * @param {?VerbosityLevel} params.verbosity The verbosity level. See {@link VerbosityLevel}.
120
- * @returns {BlockResponse} A promise resolving to a {@link BlockResponse} formatted depending on `verbosity` level.
121
- * @throws {BitcoinRpcError} If neither `blockhash` nor `height` is provided.
122
104
  */
123
105
  getBlock({ blockhash, height, verbosity }: GetBlockParams): Promise<BlockResponse | undefined>;
124
- /**
125
- * Returns the blockheight of the most-work fully-validated chain. The genesis block has height 0.
126
- * @returns {Blockheight} The number of the blockheight with the most-work of the fully-validated chain.
127
- */
106
+ /** Returns the blockheight of the most-work fully-validated chain. */
128
107
  getBlockCount(): Promise<number>;
129
- /**
130
- * Returns the blockhash of the block at the given height in the active chain.
131
- */
108
+ /** Returns the blockhash of the block at the given height. */
132
109
  getBlockHash(height: number): Promise<string>;
133
- /**
134
- * Returns an object containing various blockchain state info.
135
- */
110
+ /** Returns various blockchain state info. */
136
111
  getBlockchainInfo(): Promise<ChainInfo>;
137
- /**
138
- * Sign inputs for raw transaction (serialized, hex-encoded).
139
- * The second optional argument (may be null) is an array of previous transaction outputs that
140
- * this transaction depends on but may not yet be in the block chain.
141
- * Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
142
- * @param {string} hexstring The hex-encoded transaction to send.
143
- */
112
+ /** Sign inputs for raw transaction (serialized, hex-encoded). */
144
113
  signRawTransaction(hexstring: string): Promise<SignedRawTx>;
145
- /**
146
- * Submit a raw transaction (serialized, hex-encoded) to local node and network.
147
- *
148
- * The transaction will be sent unconditionally to all peers, so using sendrawtransaction
149
- * for manual rebroadcast may degrade privacy by leaking the transaction's origin, as
150
- * nodes will normally not rebroadcast non-wallet transactions already in their mempool.
151
- *
152
- * @param {string} hexstring The hex-encoded transaction to send.
153
- * @param {numbner} [maxfeerate] If not passed, default is 0.10.
154
- * @returns {Promise<string>} A promise resolving to the transaction hash in hex.
155
- */
114
+ /** Submit a raw transaction (serialized, hex-encoded) to local node and network. */
156
115
  sendRawTransaction(hexstring: string, maxfeerate?: number | string, maxBurnAmount?: number | string): Promise<string>;
157
- /**
158
- * Combines calls to `signRawTransaction` and `sendRawTransaction`.
159
- * @param {string} params.hexstring The hex-encoded transaction to send.
160
- * @returns {Promise<string>} A promise resolving to the transaction hash in hex.
161
- */
116
+ /** Signs and sends a raw transaction. */
162
117
  signAndSendRawTransaction(hexstring: string): Promise<string>;
163
- /**
164
- * Combines calls to `createRawTransaction`, `signRawTransaction` and `sendRawTransaction`.
165
- * @param {CreateRawTxInputs[]} inputs The inputs to the transaction (required).
166
- * @param {CreateRawTxOutputs[]} outputs The outputs of the transaction (required).
167
- * @returns {Promise<string>} A promise resolving to the transaction hash in hex.
168
- */
118
+ /** Creates, signs, and sends a raw transaction. */
169
119
  createSignSendRawTransaction(inputs: CreateRawTxInputs[], outputs: CreateRawTxOutputs[]): Promise<string>;
170
- /**
171
- * Returns up to 'count' most recent transactions skipping the first 'from' transactions for account 'label'.
172
- * @param {ListTransactionsParams} params The parameters for the listTransactions command.
173
- * @returns {Promise<ListTransactionsResult>} A promise resolving to a {@link ListTransactionsResult} object.
174
- */
120
+ /** Returns up to 'count' most recent transactions. */
175
121
  listTransactions(params: ListTransactionsParams): Promise<ListTransactionsResult>;
176
- /**
177
- * Create a transaction spending the given inputs and creating new outputs.
178
- * Outputs can be addresses or data.
179
- * Returns hex-encoded raw transaction.
180
- * Note that the transaction's inputs are not signed, and
181
- * it is not stored in the wallet or transmitted to the network.
182
- * @param {TxInForCreateRaw[]} inputs The inputs to the transaction (required).
183
- * @param {CreateRawTxOutputs[]} outputs The outputs of the transaction (required).
184
- * @param {number} [locktime] The locktime of the transaction (optional).
185
- * @param {boolean} [replacable] Whether the transaction is replaceable (optional).
186
- * @returns {string} The hex-encoded raw transaction.
187
- */
122
+ /** Create a transaction spending the given inputs and creating new outputs. */
188
123
  createRawTransaction(inputs: CreateRawTxInputs[], outputs: CreateRawTxOutputs[], locktime?: number, replacable?: boolean): Promise<string>;
189
- /**
190
- * Derives one or more addresses corresponding to an output descriptor.
191
- * Examples of output descriptors are:
192
- * pkh(<pubkey>) P2PKH outputs for the given pubkey
193
- * wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey
194
- * sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys
195
- * raw(<hex script>) Outputs whose output script equals the specified hex-encoded bytes
196
- * tr(<pubkey>,multi_a(<n>,<pubkey>,<pubkey>,...)) P2TR-multisig outputs for the given threshold and pubkeys
197
- *
198
- * In the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one
199
- * or more path elements separated by "/", where "h" represents a hardened child key.
200
- *
201
- * See {@link https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md | github.com/bitcoin/bitcoin/descriptors.md}
202
- * for more information.
203
- * @param {string} descriptor The descriptor.
204
- * @param {Array<number>} range If descriptor is ranged, must specify end or [begin,end] to derive.
205
- * @returns {Array<DerivedAddresses>} a list of derived addresses
206
- * @example First three native segwit receive addresses
207
- * ```
208
- * const bitcoind = BitcoinRpcClient.connect()
209
- * const addresses = bitcoind.deriveAddresses("wpkh([d34db33f/84h/0h/0h]xpub6DJ2dN.../0/*)#cjjspncu", [0,2])
210
- * ```
211
- */
124
+ /** Derives one or more addresses corresponding to an output descriptor. */
212
125
  deriveAddresses(descriptor: string, range?: Array<number>): Promise<Array<DerivedAddresses>>;
213
- /**
214
- * Returns the total available balance. The available balance is what the wallet
215
- * considers currently spendable, and is thus affected by options which limit
216
- * spendability such as -spendzeroconfchange.
217
- * @returns {Promise<number>} A promise resolving to the total available balance in BTC.
218
- */
126
+ /** Mines blocks to a given address (regtest/signet only). Returns array of block hashes. */
127
+ generateToAddress(nblocks: number, address: string): Promise<string[]>;
128
+ /** Returns the total available balance. */
219
129
  getBalance(): Promise<number>;
220
- /**
221
- * Returns a new Bitcoin address for receiving payments. If 'label' is specified,
222
- * it is added to the address book so payments received with the address will be associated with 'label'.
223
- * The 'address_type' can be one of "legacy", "p2sh-segwit", "bech32", or "bech32m".
224
- * @param {string} addressType The address type to use (required, options=["legacy", "p2sh-segwit", "bech32", "bech32m"], default="bech32").
225
- * @param {string} [label] The label to associate with the new address (optional).
226
- * @returns {Promise<string>} A promise resolving to the new address.
227
- */
130
+ /** Returns a new Bitcoin address for receiving payments. */
228
131
  getNewAddress(addressType: string, label?: string): Promise<string>;
229
- /**
230
- * Returns array of unspent transaction outputs with between minconf and maxconf (inclusive) confirmations.
231
- * Optionally filter to only include txouts paid to specified addresses.
232
- * @param {Object} params The parameters for the listUnspent command.
233
- * @param {number} [params.minconf=0] The minimum number of confirmations an output must have to be included.
234
- * @param {number} [params.maxconf=9999999] The maximum number of confirmations an output can have to be included.
235
- * @param {string[]} [params.address] Only include outputs paid to these addresses.
236
- * @param {boolean} [params.include_unsafe=true] Whether to include outputs that are not safe to spend.
237
- * @returns {Promise<UnspentTxInfo[]>} A promise resolving to an array of {@link UnspentTxInfo} objects.
238
- */
132
+ /** Returns array of unspent transaction outputs. */
239
133
  listUnspent(params: {
240
134
  minconf?: number;
241
135
  maxconf?: number;
242
136
  address?: string[];
243
137
  include_unsafe?: boolean;
244
138
  }): Promise<UnspentTxInfo[]>;
245
- /**
246
- * Send an amount to a given address.
247
- * @param {string} address The address to send to.
248
- * @param {number} amount The amount to send in BTC.
249
- * @returns {Promise<SendToAddressResult>} A promise resolving to the transaction id.
250
- */
139
+ /** Send an amount to a given address. */
251
140
  sendToAddress(address: string, amount: number): Promise<RawTransactionV2>;
252
- /**
253
- * Sign a message with the private key of an address.
254
- * @param {string} address The address to sign the message with.
255
- * @param {string} message The message to sign.
256
- * @returns {Promise<string>} A promise resolving to the signature in base64.
257
- */
141
+ /** Sign a message with the private key of an address. */
258
142
  signMessage(address: string, message: string): Promise<string>;
259
- /**
260
- * Verify a signed message.
261
- * @param {string} address The address to verify the message with.
262
- * @param {string} signature The signature to verify in base64.
263
- * @param {string} message The message to verify.
264
- * @returns {Promise<boolean>} A promise resolving to true if the signature is valid, false otherwise.
265
- */
143
+ /** Verify a signed message. */
266
144
  verifyMessage(address: string, signature: string, message: string): Promise<boolean>;
267
- /**
268
- * Get detailed information about in-wallet transaction <txid>.
269
- * @param txid: The transaction id. (string, required)
270
- * @param {boolean} include_watchonly Whether to include watch-only addresses in balance calculation and details.
271
- * @returns {WalletTransaction} A promise resolving to a {@link WalletTransaction} object.
272
- */
145
+ /** Get detailed information about in-wallet transaction. */
273
146
  getTransaction(txid: string, include_watchonly?: boolean): Promise<WalletTransaction>;
274
- /**
275
- * Get detailed information about a transaction.
276
- * By default, this call only returns a transaction if it is in the mempool. If -txindex is enabled
277
- * and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block.
278
- * If a blockhash argument is passed, it will return the transaction if the specified block is available and
279
- * the transaction is in that block.
280
- * @param {string} txid The transaction id (required).
281
- * @param {?VerbosityLevel} verbosity Response format: 0 (hex), 1 (json) or 2 (jsonext).
282
- * @param {?string} blockhash The block in which to look for the transaction (optional).
283
- * @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
284
- */
147
+ /** Get detailed information about a transaction. */
285
148
  getRawTransaction(txid: string, verbosity?: VerbosityLevel, blockhash?: string): Promise<RawTransactionResponse>;
286
- /**
287
- * Get detailed information about multiple transactions. An extension of {@link getRawTransaction}.
288
- * @param {Array<string>} txids An array of transaction ids.
289
- * @param {?VerbosityLevel} verbosity Response format: 0 (hex), 1 (json) or 2 (jsonext).
290
- * @returns {Promise<Array<RawTransactionResponse>>}
291
- */
149
+ /** Get detailed information about multiple transactions using JSON-RPC batching. */
292
150
  getRawTransactions(txids: string[], verbosity?: VerbosityLevel): Promise<RawTransactionResponse[]>;
293
151
  }
152
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/rpc/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,sBAAsB,EACtB,aAAa,EAKb,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,sBAAsB,EAEtB,sBAAsB,EAGtB,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,aAAa,EACb,cAAc,EACd,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,gBAAgB;;IAsB3D;;;;;;;;OAQG;gBACS,MAAM,EAAE,eAAe;IAKnC;;;;;;;;;OASG;IACH,IAAI,MAAM,IAAI,sBAAsB,CAGnC;IAED;;;;;;;;OAQG;IACH,IAAI,MAAM,IAAI,gBAAgB,CAG7B;IAED;;;;;;;;;;;;;;;;;OAiBG;WACW,UAAU,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,oBAAoB;IAMxE;;;;;;;;;;;OAWG;WACW,OAAO,CAAC,MAAM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C,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhF,oDAAoD;IACvC,WAAW,CAAC,MAAM,EAAE;QAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAS5B,yCAAyC;IAC5B,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAKtF,yDAAyD;IAC5C,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI3E,+BAA+B;IAClB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjG,4DAA4D;IAC/C,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAIlG,oDAAoD;IACvC,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAU7H,oFAAoF;IACvE,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC;CAehH"}
@@ -1,10 +1,43 @@
1
- import { BlockResponse, ChainInfo, CreateRawTxInputs, CreateRawTxOutputs, FeeEstimateMode, GetBlockParams, RawTransactionResponse } from '../../types.js';
1
+ import { BlockResponse, ChainInfo, CreateRawTxInputs, CreateRawTxOutputs, DerivedAddresses, GetBlockParams, ListTransactionsParams, ListTransactionsResult, RawTransactionV2, SignedRawTx, UnspentTxInfo } from '../../types.js';
2
2
  /**
3
- * General interface for a Bitcoin Core RPC client.\
4
- * @name BitcoinRpcClient
5
- * @type {BitcoinRpcClient}
3
+ * General interface for a Bitcoin Core RPC client.
6
4
  */
7
5
  export interface BitcoinRpcClient {
6
+ /** Gets detailed information about a specific block. */
7
+ getBlock({ blockhash, height, verbosity }: GetBlockParams): Promise<BlockResponse | undefined>;
8
+ /** Returns the number of blocks in the longest blockchain. */
9
+ getBlockCount(): Promise<number>;
10
+ /** Gets the hash of a block at a given height. */
11
+ getBlockHash(height: number): Promise<string>;
12
+ /** Retrieves general blockchain state info. */
13
+ getBlockchainInfo(): Promise<ChainInfo>;
14
+ /** Signs a raw transaction with the wallet's private keys. */
15
+ signRawTransaction(hexstring: string): Promise<SignedRawTx>;
16
+ /** Sends a raw transaction hex to the Bitcoin network. */
17
+ sendRawTransaction(hexstring: string, maxfeerate?: number | string, maxBurnAmount?: number | string): Promise<string>;
18
+ /** Signs and sends a raw transaction in one step. */
19
+ signAndSendRawTransaction(hexstring: string): Promise<string>;
20
+ /** Creates, signs, and sends a raw transaction in one step. */
21
+ createSignSendRawTransaction(inputs: CreateRawTxInputs[], outputs: CreateRawTxOutputs[]): Promise<string>;
22
+ /** Lists transactions in the wallet. */
23
+ listTransactions(params: ListTransactionsParams): Promise<ListTransactionsResult>;
24
+ /** Creates a raw transaction spending specified inputs to specified outputs. */
25
+ createRawTransaction(inputs: CreateRawTxInputs[], outputs: CreateRawTxOutputs[], locktime?: number, replacable?: boolean): Promise<string>;
26
+ /** Derives addresses from a descriptor. */
27
+ deriveAddresses(descriptor: string, range?: Array<number>): Promise<Array<DerivedAddresses>>;
28
+ /** Mines a specified number of blocks to a given address. */
29
+ generateToAddress(nblocks: number, address: string): Promise<string[]>;
30
+ /** Gets the wallet's balance. */
31
+ getBalance(): Promise<number>;
32
+ /** Gets a new Bitcoin address for receiving payments. */
33
+ getNewAddress(addressType: string, label?: string): Promise<string>;
34
+ /** Lists unspent transaction outputs in the wallet. */
35
+ listUnspent(params: {
36
+ minconf?: number;
37
+ maxconf?: number;
38
+ address?: string[];
39
+ include_unsafe?: boolean;
40
+ }): Promise<UnspentTxInfo[]>;
8
41
  /** Creates a raw transaction spending specified inputs to specified outputs. */
9
42
  createRawTransaction(inputs: CreateRawTxInputs[], outputs: CreateRawTxOutputs[], locktime?: number, replacable?: boolean): Promise<string>;
10
43
  /** Returns the number of blocks in the longest blockchain. */
@@ -20,9 +53,12 @@ export interface BitcoinRpcClient {
20
53
  /** Sends raw transaction hex to the Bitcoin network. */
21
54
  sendRawTransaction(hexstring: string, maxfeerate?: number | string, maxBurnAmount?: number | string): Promise<string>;
22
55
  /** Sends bitcoins to a specified address. */
23
- sendToAddress(address: string, amount: number, comment?: string, comment_to?: string, subtreactfeefromamount?: boolean, replaceable?: boolean, conf_target?: number, estimate_mode?: FeeEstimateMode): Promise<RawTransactionResponse>;
56
+ sendToAddress(address: string, amount: number): Promise<RawTransactionV2>;
24
57
  /** Verifies a signed message. */
25
58
  verifyMessage(address: string, signature: string, message: string): Promise<boolean>;
59
+ /** Sign a message with the private key of an address. */
26
60
  signMessage(address: string, message: string): Promise<string>;
61
+ /** Mines a specified number of blocks to a given address. */
62
+ generateToAddress(nblocks: number, address: string): Promise<string[]>;
27
63
  }
28
- export declare function isBitcoinRpcClient(obj: any): obj is BitcoinRpcClient;
64
+ //# sourceMappingURL=interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../../src/client/rpc/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC7B,gFAAgF;I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ig } from '../../types.js';
2
+ import { HttpExecutor } from '../http.js';
3
+ import { JsonRpcProtocol } from './protocol.js';
2
4
  export declare class JsonRpcTransport {
3
- private url;
4
- private authHeader?;
5
- private id;
6
- constructor(cfg: RpcClientConfig);
7
5
  /**
8
- * Make a JSON-RPC call or batch of calls to the Bitcoin node.
9
- * @param {BatchOption[] | { method: string; parameters?: any[] }} batch A single RPC call or an array of calls to be made.
10
- * @returns {Promise<any[] | any>} The result of the RPC call(s).
11
- * @example
6
+ * The sans-I/O protocol layer. Use this to build {@link HttpRequest}
7
+ * descriptors without performing any I/O.
12
8
  */
13
- command(batch: BatchOption[] | {
14
- method: string;
15
- parameters?: any[];
16
- }): Promise<any[] | any>;
9
+ readonly protocol: JsonRpcProtocol;
10
+ private readonly execute;
11
+ constructor(cfg: RpcConfig, executor?: HttpExecutor);
12
+ /** @internal Expose URL for tests that inspect transport state. */
13
+ get url(): string;
14
+ /**
15
+ * Execute a single JSON-RPC call.
16
+ */
17
+ call(method: string, params?: unknown[]): Promise<unknown>;
17
18
  /**
18
- * Internal method to perform the actual JSON-RPC call.
19
- * @param {string} method The RPC method to call.
20
- * @param {any[]} params The parameters for the RPC method.
21
- * @returns {Promise<any>} The result of the RPC call.
19
+ * Execute a JSON-RPC batch in a single HTTP request.
20
+ * Returns results in the same order as the input calls.
22
21
  */
23
- private call;
22
+ batch(calls: Array<{
23
+ method: string;
24
+ params: unknown[];
25
+ }>): Promise<unknown[]>;
24
26
  }
27
+ //# sourceMappingURL=json-rpc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-rpc.d.ts","sourceRoot":"","sources":["../../../../src/client/rpc/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAG9D,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,EAAE,CAAK;gBAEH,GAAG,EAAE,eAAe;IAmBhC;;;;;OAKG;IACG,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC;IAYlG;;;;;OAKG;YACW,IAAI;CA6BnB"}
1
+ {"version":3,"file":"json-rpc.d.ts","sourceRoot":"","sources":["../../../../src/client/rpc/json-rpc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAuB,MAAM,YAAY,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,qBAAa,gBAAgB;IAC3B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IAEnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;gBAE3B,GAAG,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,YAAY;IAKnD,mEAAmE;IACnE,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED;;OAEG;IACG,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAkBpE;;;OAGG;IACG,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAuBrF"}
@@ -0,0 +1,83 @@
1
+ import { RpcConfig } from '../../types.js';
2
+ import { HttpRequest } from '../http.js';
3
+ /**
4
+ * Sans-I/O JSON-RPC protocol for Bitcoin Core.
5
+ *
6
+ * Builds {@link HttpRequest} descriptors for JSON-RPC method calls and
7
+ * provides response parsing — without performing any I/O.
8
+ *
9
+ * **Security note:** Built requests include an `Authorization` header when
10
+ * credentials are configured. Do not log or persist {@link HttpRequest}
11
+ * objects without redacting the `Authorization` header.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const protocol = new JsonRpcProtocol({
16
+ * host: 'http://localhost:18443',
17
+ * username: 'user',
18
+ * password: 'pass',
19
+ * });
20
+ *
21
+ * // Build a request descriptor (no I/O)
22
+ * const req = protocol.buildRequest('getblockcount', []);
23
+ *
24
+ * // Execute with any HTTP client
25
+ * const res = await fetch(req.url, req);
26
+ * const json = await res.json();
27
+ *
28
+ * // Parse the JSON-RPC response (throws on errors)
29
+ * const blockCount = protocol.parseResponse(json, 'getblockcount', []);
30
+ * ```
31
+ */
32
+ export declare class JsonRpcProtocol {
33
+ readonly url: string;
34
+ /** Whether this protocol instance has credentials configured. */
35
+ readonly hasAuth: boolean;
36
+ private readonly _headers;
37
+ private _id;
38
+ constructor(cfg: RpcConfig);
39
+ /**
40
+ * Build an {@link HttpRequest} for a JSON-RPC method call.
41
+ */
42
+ buildRequest(method: string, params: unknown[]): HttpRequest;
43
+ /**
44
+ * Build an {@link HttpRequest} for a JSON-RPC batch call.
45
+ * Sends all calls in a single HTTP request per the JSON-RPC 2.0 spec.
46
+ */
47
+ buildBatchRequest(calls: Array<{
48
+ method: string;
49
+ params: unknown[];
50
+ }>): HttpRequest;
51
+ /**
52
+ * Parse a JSON-RPC response payload, throwing {@link BitcoinRpcError}
53
+ * if the response contains an error.
54
+ */
55
+ parseResponse(payload: {
56
+ result?: unknown;
57
+ error?: {
58
+ code: number;
59
+ message: string;
60
+ };
61
+ }, method: string): unknown;
62
+ /**
63
+ * Parse a JSON-RPC batch response payload.
64
+ * Returns results in the same order as the original calls.
65
+ */
66
+ parseBatchResponse(payloads: Array<{
67
+ id: number;
68
+ result?: unknown;
69
+ error?: {
70
+ code: number;
71
+ message: string;
72
+ };
73
+ }>, calls: Array<{
74
+ method: string;
75
+ params: unknown[];
76
+ }>): unknown[];
77
+ /**
78
+ * Return a copy of the headers with the Authorization value redacted.
79
+ * Use this for logging or debugging.
80
+ */
81
+ redactedHeaders(): Record<string, string>;
82
+ }
83
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../../src/client/rpc/protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,eAAe;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAClD,OAAO,CAAC,GAAG,CAAK;gBAEJ,GAAG,EAAE,SAAS;IA2B1B;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW;IAU5D;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC,GAAG,WAAW;IAenF;;;OAGG;IACH,aAAa,CACX,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,EACxE,MAAM,EAAE,MAAM,GACb,OAAO;IAYV;;;OAGG;IACH,kBAAkB,CAChB,QAAQ,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,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