@mr-zwets/bchn-api-wrapper 1.0.1 → 1.0.2

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 (45) hide show
  1. package/.claude/settings.local.json +8 -0
  2. package/.github/workflows/ci.yaml +36 -0
  3. package/CLAUDE.md +70 -0
  4. package/README.md +121 -129
  5. package/dist/interfaces/interfaces.d.ts +13 -0
  6. package/dist/interfaces/restInterfaces/interfaces.d.ts +124 -18
  7. package/dist/interfaces/rpcInterfaces/blockchain.d.ts +293 -102
  8. package/dist/interfaces/rpcInterfaces/control.d.ts +6 -0
  9. package/dist/interfaces/rpcInterfaces/generating.d.ts +2 -0
  10. package/dist/interfaces/rpcInterfaces/mining.d.ts +9 -0
  11. package/dist/interfaces/rpcInterfaces/network.d.ts +18 -0
  12. package/dist/interfaces/rpcInterfaces/rawtransactions.d.ts +21 -0
  13. package/dist/interfaces/rpcInterfaces/util.d.ts +5 -0
  14. package/dist/interfaces/rpcInterfaces/wallet.d.ts +54 -0
  15. package/dist/interfaces/rpcInterfaces/zmq.d.ts +1 -0
  16. package/dist/restClient.d.ts +13 -1
  17. package/dist/restClient.js +19 -6
  18. package/dist/rpcClient.d.ts +7 -0
  19. package/dist/rpcClient.js +7 -0
  20. package/package.json +7 -8
  21. package/pnpm-lock.yaml +1279 -0
  22. package/src/index.ts +3 -3
  23. package/src/interfaces/interfaces.ts +96 -86
  24. package/src/interfaces/restInterfaces/interfaces.ts +235 -116
  25. package/src/interfaces/rpcInterfaces/blockchain.ts +932 -758
  26. package/src/interfaces/rpcInterfaces/control.ts +68 -62
  27. package/src/interfaces/rpcInterfaces/generating.ts +23 -21
  28. package/src/interfaces/rpcInterfaces/index.ts +13 -13
  29. package/src/interfaces/rpcInterfaces/mining.ts +151 -143
  30. package/src/interfaces/rpcInterfaces/network.ts +213 -195
  31. package/src/interfaces/rpcInterfaces/rawtransactions.ts +332 -314
  32. package/src/interfaces/rpcInterfaces/util.ts +56 -52
  33. package/src/interfaces/rpcInterfaces/wallet.ts +728 -674
  34. package/src/interfaces/rpcInterfaces/zmq.ts +12 -11
  35. package/src/restClient.ts +134 -119
  36. package/src/rpcClient.ts +100 -93
  37. package/src/utils/errors.ts +6 -6
  38. package/src/utils/utils.ts +55 -55
  39. package/test/restClient.test.ts +33 -31
  40. package/test/rpcClient.test.ts +119 -115
  41. package/test/setupTests.ts +56 -54
  42. package/test/tsconfig.json +4 -4
  43. package/tsconfig.json +13 -13
  44. package/vitest.config.ts +8 -8
  45. package/CHANGELOG.md +0 -7
@@ -1,314 +1,332 @@
1
- /* --- Rawtransactions Commands --- */
2
- // progress 14/14
3
-
4
- import type { TokenData, Transaction, TransactionInput, TransactionOutput } from "../interfaces.js";
5
-
6
- export interface CombinePsbt {
7
- method: 'decoderawtransaction';
8
- params: [
9
- txs: string[]
10
- ];
11
- response: string
12
- }
13
-
14
- export interface CombineRawTransaction {
15
- method: 'combinerawtransaction';
16
- params: [
17
- txs: string[]
18
- ];
19
- response: string;
20
- }
21
-
22
- export interface ConvertToPsbt {
23
- method: 'converttopsbt';
24
- params: [
25
- hexstring: string,
26
- permitsigdata?: boolean
27
- ];
28
- response: string;
29
- }
30
-
31
- export interface CreatePsbt {
32
- method: 'createpsbt';
33
- params: [
34
- inputs: {
35
- txid: string;
36
- vout: number;
37
- sequence?: number;
38
- }[],
39
- outputs: {
40
- [address: string]: number
41
- | {
42
- amount: number;
43
- tokendata: TokenData;
44
- }
45
- | {
46
- data: string;
47
- }
48
- }[],
49
- locktime?: number
50
- ];
51
- response: string;
52
- }
53
-
54
- export interface CreateRawTransaction {
55
- method: 'createrawtransaction';
56
- params: [
57
- inputs: {
58
- txid: string;
59
- vout: number;
60
- sequence?: number;
61
- }[],
62
- outputs: {
63
- [address: string]: number
64
- | {
65
- amount: number;
66
- tokendata: TokenData;
67
- }
68
- | {
69
- data: string;
70
- }
71
- }[],
72
- locktime?: number,
73
- ];
74
- response: string;
75
- }
76
-
77
- export interface DecodePsbt {
78
- method: 'decodepsbt';
79
- params: [
80
- psbt: string
81
- ];
82
- response: {
83
- tx: Transaction;
84
- unknown: Record<string, string>;
85
- inputs: PsbtInput[];
86
- outputs: PsbtOutput[];
87
- fee?: number;
88
- };
89
- }
90
-
91
- interface PsbtInput {
92
- utxo?: {
93
- amount: number;
94
- scriptPubKey: {
95
- asm: string;
96
- hex: string;
97
- type: string;
98
- addresses?: string[];
99
- };
100
- tokenData?: TokenData;
101
- };
102
- partial_signatures?: Record<string, string>;
103
- sighash?: string;
104
- redeem_script?: RedeemScript;
105
- bip32_derivs?: Bip32Derivation[];
106
- final_scriptsig?: {
107
- asm: string;
108
- hex: string;
109
- };
110
- unknown?: Record<string, string>;
111
- }
112
-
113
- interface PsbtOutput {
114
- redeem_script?: RedeemScript;
115
- bip32_derivs?: Bip32Derivation[];
116
- unknown?: Record<string, string>;
117
- }
118
-
119
- interface RedeemScript {
120
- asm: string;
121
- hex: string;
122
- type: string;
123
- }
124
-
125
- interface Bip32Derivation {
126
- pubkey: string;
127
- master_fingerprint: string;
128
- path: string;
129
- }
130
-
131
- export interface DecodeRawTransaction {
132
- method: 'decoderawtransaction';
133
- params: [
134
- hexstring: string
135
- ];
136
- response: Transaction
137
- }
138
-
139
- export interface DecodeScript {
140
- method: 'decodescript';
141
- params: [
142
- hexstring: string
143
- ];
144
- response: {
145
- asm: string;
146
- type: string;
147
- reqSigs: number;
148
- addresses: string[]
149
- p2sh: string;
150
- };
151
- }
152
-
153
- export interface FinalizePsbt {
154
- method: 'finalizepsbt';
155
- params: [
156
- psbt: string,
157
- extract?: boolean
158
- ];
159
- response: {
160
- psbt: string;
161
- hex: string;
162
- complete: boolean;
163
- }
164
- }
165
-
166
- export interface FundRawTransaction {
167
- method: 'fundrawtransaction';
168
- params: [
169
- hexstring: string,
170
- options?: {
171
- include_unsafe?: boolean;
172
- changeAddress?: string;
173
- changePosition?: number;
174
- includeWatching?: boolean;
175
- lockUnspents?: boolean;
176
- feeRate?: number | string;
177
- subtractFeeFromOutputs?: number[];
178
- }
179
- ];
180
- response: {
181
- hex: string;
182
- fee: number;
183
- changepos: number;
184
- };
185
- }
186
-
187
- interface GetRawTransactionBase {
188
- method: 'getrawtransaction';
189
- params: [
190
- txid: string,
191
- verbose?: boolean | number,
192
- blockhash?: string
193
- ];
194
- }
195
-
196
- export interface GetRawTransactionVerbosity0 extends GetRawTransactionBase {
197
- params: [
198
- txid: string,
199
- verbose?: false | 0,
200
- blockhash?: string
201
- ];
202
- response: string;
203
- }
204
-
205
- // Verbosity 1 (basic transaction info)
206
- export interface GetRawTransactionVerbosity1 extends GetRawTransactionBase {
207
- params: [
208
- txid: string,
209
- verbose?: true | 1,
210
- blockhash?: string
211
- ];
212
- response: {
213
- hex: string;
214
- txid: string;
215
- hash: string;
216
- size: number;
217
- version: number;
218
- locktime: number;
219
- vin: TransactionInput[];
220
- vout: TransactionOutput[];
221
- blockhash?: string;
222
- confirmations?: number;
223
- time?: number;
224
- blocktime?: number;
225
- in_active_chain?: boolean;
226
- };
227
- }
228
-
229
- // Verbosity 2 (includes input values and transaction fee)
230
- export interface GetRawTransactionVerbosity2 extends GetRawTransactionBase {
231
- params: [
232
- txid: string,
233
- verbose?: 2,
234
- blockhash?: string
235
- ];
236
- response: {
237
- hex: string;
238
- txid: string;
239
- hash: string;
240
- size: number;
241
- version: number;
242
- locktime: number;
243
- vin: TransactionInputVerbosity2[];
244
- vout: TransactionOutput[];
245
- blockhash?: string;
246
- confirmations?: number;
247
- time?: number;
248
- blocktime?: number;
249
- in_active_chain?: boolean;
250
- fee?: number;
251
- };
252
- }
253
-
254
- interface TransactionInputVerbosity2 extends TransactionInput {
255
- value?: number;
256
- scriptPubKey?: {
257
- asm: string;
258
- hex: string;
259
- type: string;
260
- address?: string;
261
- };
262
- tokenData?: TokenData;
263
- }
264
-
265
-
266
- export interface SendRawTransaction {
267
- method: 'sendrawtransaction';
268
- params: [
269
- hexstring: string,
270
- allowhighfees?: boolean
271
- ];
272
- response: string;
273
- }
274
-
275
- export interface SignRawTransactionWithKey {
276
- method: 'signrawtransactionwithkey';
277
- params: [
278
- hexstring: string,
279
- privkeys: string[],
280
- prevtxs?: {
281
- txid: string;
282
- vout: number;
283
- scriptPubKey: string;
284
- redeemScript?: string;
285
- amount: number | string;
286
- tokenData?: TokenData;
287
- }[],
288
- sighashtype?: string
289
- ];
290
- response: {
291
- hex: string;
292
- complete: boolean;
293
- errors?: {
294
- txid: string;
295
- vout: number;
296
- scriptSig: string;
297
- sequence: number;
298
- error: string;
299
- }[];
300
- };
301
- }
302
-
303
- export interface TestMempoolAccept {
304
- method: 'testmempoolaccept';
305
- params: [
306
- rawtxs: string[],
307
- allowhighfees?: boolean
308
- ];
309
- response: {
310
- txid: string
311
- allowed: boolean
312
- 'reject-reason': string
313
- }[];
314
- }
1
+ /* --- Rawtransactions Commands --- */
2
+ // progress 14/14
3
+
4
+ import type { TokenData, Transaction, TransactionInput, TransactionOutput } from "../interfaces.js";
5
+
6
+ /** Combines multiple PSBTs into one. */
7
+ export interface CombinePsbt {
8
+ method: 'decoderawtransaction';
9
+ params: [
10
+ txs: string[]
11
+ ];
12
+ response: string
13
+ }
14
+
15
+ /** Combines multiple raw transactions into one. */
16
+ export interface CombineRawTransaction {
17
+ method: 'combinerawtransaction';
18
+ params: [
19
+ txs: string[]
20
+ ];
21
+ response: string;
22
+ }
23
+
24
+ /** Converts a raw transaction to PSBT format. */
25
+ export interface ConvertToPsbt {
26
+ method: 'converttopsbt';
27
+ params: [
28
+ hexstring: string,
29
+ permitsigdata?: boolean
30
+ ];
31
+ response: string;
32
+ }
33
+
34
+ /** Creates an unsigned PSBT. */
35
+ export interface CreatePsbt {
36
+ method: 'createpsbt';
37
+ params: [
38
+ inputs: {
39
+ txid: string;
40
+ vout: number;
41
+ sequence?: number;
42
+ }[],
43
+ outputs: {
44
+ [address: string]: number
45
+ | {
46
+ amount: number;
47
+ tokendata: TokenData;
48
+ }
49
+ | {
50
+ data: string;
51
+ }
52
+ }[],
53
+ locktime?: number
54
+ ];
55
+ response: string;
56
+ }
57
+
58
+ /** Creates an unsigned raw transaction. */
59
+ export interface CreateRawTransaction {
60
+ method: 'createrawtransaction';
61
+ params: [
62
+ inputs: {
63
+ txid: string;
64
+ vout: number;
65
+ sequence?: number;
66
+ }[],
67
+ outputs: {
68
+ [address: string]: number
69
+ | {
70
+ amount: number;
71
+ tokendata: TokenData;
72
+ }
73
+ | {
74
+ data: string;
75
+ }
76
+ }[],
77
+ locktime?: number,
78
+ ];
79
+ response: string;
80
+ }
81
+
82
+ /** Decodes a PSBT to inspect its contents. */
83
+ export interface DecodePsbt {
84
+ method: 'decodepsbt';
85
+ params: [
86
+ psbt: string
87
+ ];
88
+ response: {
89
+ tx: Transaction;
90
+ unknown: Record<string, string>;
91
+ inputs: PsbtInput[];
92
+ outputs: PsbtOutput[];
93
+ fee?: number;
94
+ };
95
+ }
96
+
97
+ /** PSBT input structure. */
98
+ interface PsbtInput {
99
+ utxo?: {
100
+ amount: number;
101
+ scriptPubKey: {
102
+ asm: string;
103
+ hex: string;
104
+ type: string;
105
+ addresses?: string[];
106
+ };
107
+ tokenData?: TokenData;
108
+ };
109
+ partial_signatures?: Record<string, string>;
110
+ sighash?: string;
111
+ redeem_script?: RedeemScript;
112
+ bip32_derivs?: Bip32Derivation[];
113
+ final_scriptsig?: {
114
+ asm: string;
115
+ hex: string;
116
+ };
117
+ unknown?: Record<string, string>;
118
+ }
119
+
120
+ /** PSBT output structure. */
121
+ interface PsbtOutput {
122
+ redeem_script?: RedeemScript;
123
+ bip32_derivs?: Bip32Derivation[];
124
+ unknown?: Record<string, string>;
125
+ }
126
+
127
+ /** Redeem script in PSBT. */
128
+ interface RedeemScript {
129
+ asm: string;
130
+ hex: string;
131
+ type: string;
132
+ }
133
+
134
+ /** BIP32 derivation path info. */
135
+ interface Bip32Derivation {
136
+ pubkey: string;
137
+ master_fingerprint: string;
138
+ path: string;
139
+ }
140
+
141
+ /** Decodes a raw transaction hex string. */
142
+ export interface DecodeRawTransaction {
143
+ method: 'decoderawtransaction';
144
+ params: [
145
+ hexstring: string
146
+ ];
147
+ response: Transaction
148
+ }
149
+
150
+ /** Decodes a script hex string. */
151
+ export interface DecodeScript {
152
+ method: 'decodescript';
153
+ params: [
154
+ hexstring: string
155
+ ];
156
+ response: {
157
+ asm: string;
158
+ type: string;
159
+ reqSigs: number;
160
+ addresses: string[]
161
+ p2sh: string;
162
+ };
163
+ }
164
+
165
+ /** Finalizes a PSBT, extracting the raw transaction if complete. */
166
+ export interface FinalizePsbt {
167
+ method: 'finalizepsbt';
168
+ params: [
169
+ psbt: string,
170
+ extract?: boolean
171
+ ];
172
+ response: {
173
+ psbt: string;
174
+ hex: string;
175
+ complete: boolean;
176
+ }
177
+ }
178
+
179
+ /** Adds inputs to a raw transaction to meet output value. */
180
+ export interface FundRawTransaction {
181
+ method: 'fundrawtransaction';
182
+ params: [
183
+ hexstring: string,
184
+ options?: {
185
+ include_unsafe?: boolean;
186
+ changeAddress?: string;
187
+ changePosition?: number;
188
+ includeWatching?: boolean;
189
+ lockUnspents?: boolean;
190
+ feeRate?: number | string;
191
+ subtractFeeFromOutputs?: number[];
192
+ }
193
+ ];
194
+ response: {
195
+ hex: string;
196
+ fee: number;
197
+ changepos: number;
198
+ };
199
+ }
200
+
201
+ interface GetRawTransactionBase {
202
+ method: 'getrawtransaction';
203
+ params: [
204
+ txid: string,
205
+ verbose?: boolean | number,
206
+ blockhash?: string
207
+ ];
208
+ }
209
+
210
+ /** Verbosity 0: Returns raw transaction as hex string. */
211
+ export interface GetRawTransactionVerbosity0 extends GetRawTransactionBase {
212
+ params: [
213
+ txid: string,
214
+ verbose?: false | 0,
215
+ blockhash?: string
216
+ ];
217
+ response: string;
218
+ }
219
+
220
+ /** Verbosity 1: Returns decoded transaction with basic info. */
221
+ export interface GetRawTransactionVerbosity1 extends GetRawTransactionBase {
222
+ params: [
223
+ txid: string,
224
+ verbose?: true | 1,
225
+ blockhash?: string
226
+ ];
227
+ response: {
228
+ hex: string;
229
+ txid: string;
230
+ hash: string;
231
+ size: number;
232
+ version: number;
233
+ locktime: number;
234
+ vin: TransactionInput[];
235
+ vout: TransactionOutput[];
236
+ blockhash?: string;
237
+ confirmations?: number;
238
+ time?: number;
239
+ blocktime?: number;
240
+ in_active_chain?: boolean;
241
+ };
242
+ }
243
+
244
+ /** Verbosity 2: Returns decoded transaction with input values and fee. */
245
+ export interface GetRawTransactionVerbosity2 extends GetRawTransactionBase {
246
+ params: [
247
+ txid: string,
248
+ verbose?: 2,
249
+ blockhash?: string
250
+ ];
251
+ response: {
252
+ hex: string;
253
+ txid: string;
254
+ hash: string;
255
+ size: number;
256
+ version: number;
257
+ locktime: number;
258
+ vin: TransactionInputVerbosity2[];
259
+ vout: TransactionOutput[];
260
+ blockhash?: string;
261
+ confirmations?: number;
262
+ time?: number;
263
+ blocktime?: number;
264
+ in_active_chain?: boolean;
265
+ fee?: number;
266
+ };
267
+ }
268
+
269
+ /** Transaction input with previous output value (verbosity 2). */
270
+ interface TransactionInputVerbosity2 extends TransactionInput {
271
+ value?: number;
272
+ scriptPubKey?: {
273
+ asm: string;
274
+ hex: string;
275
+ type: string;
276
+ address?: string;
277
+ };
278
+ tokenData?: TokenData;
279
+ }
280
+
281
+ /** Broadcasts a signed raw transaction. */
282
+ export interface SendRawTransaction {
283
+ method: 'sendrawtransaction';
284
+ params: [
285
+ hexstring: string,
286
+ allowhighfees?: boolean
287
+ ];
288
+ response: string;
289
+ }
290
+
291
+ /** Signs a raw transaction with provided private keys. */
292
+ export interface SignRawTransactionWithKey {
293
+ method: 'signrawtransactionwithkey';
294
+ params: [
295
+ hexstring: string,
296
+ privkeys: string[],
297
+ prevtxs?: {
298
+ txid: string;
299
+ vout: number;
300
+ scriptPubKey: string;
301
+ redeemScript?: string;
302
+ amount: number | string;
303
+ tokenData?: TokenData;
304
+ }[],
305
+ sighashtype?: string
306
+ ];
307
+ response: {
308
+ hex: string;
309
+ complete: boolean;
310
+ errors?: {
311
+ txid: string;
312
+ vout: number;
313
+ scriptSig: string;
314
+ sequence: number;
315
+ error: string;
316
+ }[];
317
+ };
318
+ }
319
+
320
+ /** Tests if raw transactions would be accepted to mempool. */
321
+ export interface TestMempoolAccept {
322
+ method: 'testmempoolaccept';
323
+ params: [
324
+ rawtxs: string[],
325
+ allowhighfees?: boolean
326
+ ];
327
+ response: {
328
+ txid: string
329
+ allowed: boolean
330
+ 'reject-reason': string
331
+ }[];
332
+ }