@mr-zwets/bchn-api-wrapper 1.0.1

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 (60) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +129 -0
  3. package/dist/index.d.ts +4 -0
  4. package/dist/index.js +4 -0
  5. package/dist/interfaces/interfaces.d.ts +70 -0
  6. package/dist/interfaces/interfaces.js +1 -0
  7. package/dist/interfaces/restInterfaces/interfaces.d.ts +109 -0
  8. package/dist/interfaces/restInterfaces/interfaces.js +1 -0
  9. package/dist/interfaces/rpcInterfaces/blockchain.d.ts +692 -0
  10. package/dist/interfaces/rpcInterfaces/blockchain.js +3 -0
  11. package/dist/interfaces/rpcInterfaces/control.d.ts +54 -0
  12. package/dist/interfaces/rpcInterfaces/control.js +3 -0
  13. package/dist/interfaces/rpcInterfaces/generating.d.ts +17 -0
  14. package/dist/interfaces/rpcInterfaces/generating.js +3 -0
  15. package/dist/interfaces/rpcInterfaces/index.d.ts +9 -0
  16. package/dist/interfaces/rpcInterfaces/index.js +12 -0
  17. package/dist/interfaces/rpcInterfaces/mining.d.ts +131 -0
  18. package/dist/interfaces/rpcInterfaces/mining.js +3 -0
  19. package/dist/interfaces/rpcInterfaces/network.d.ts +179 -0
  20. package/dist/interfaces/rpcInterfaces/network.js +3 -0
  21. package/dist/interfaces/rpcInterfaces/rawtransactions.d.ts +283 -0
  22. package/dist/interfaces/rpcInterfaces/rawtransactions.js +3 -0
  23. package/dist/interfaces/rpcInterfaces/util.d.ts +44 -0
  24. package/dist/interfaces/rpcInterfaces/util.js +3 -0
  25. package/dist/interfaces/rpcInterfaces/wallet.d.ts +620 -0
  26. package/dist/interfaces/rpcInterfaces/wallet.js +3 -0
  27. package/dist/interfaces/rpcInterfaces/zmq.d.ts +8 -0
  28. package/dist/interfaces/rpcInterfaces/zmq.js +3 -0
  29. package/dist/restClient.d.ts +17 -0
  30. package/dist/restClient.js +100 -0
  31. package/dist/rpcClient.d.ts +12 -0
  32. package/dist/rpcClient.js +85 -0
  33. package/dist/utils/errors.d.ts +3 -0
  34. package/dist/utils/errors.js +6 -0
  35. package/dist/utils/utils.d.ts +11 -0
  36. package/dist/utils/utils.js +49 -0
  37. package/package.json +40 -0
  38. package/src/index.ts +4 -0
  39. package/src/interfaces/interfaces.ts +87 -0
  40. package/src/interfaces/restInterfaces/interfaces.ts +117 -0
  41. package/src/interfaces/rpcInterfaces/blockchain.ts +759 -0
  42. package/src/interfaces/rpcInterfaces/control.ts +62 -0
  43. package/src/interfaces/rpcInterfaces/generating.ts +21 -0
  44. package/src/interfaces/rpcInterfaces/index.ts +14 -0
  45. package/src/interfaces/rpcInterfaces/mining.ts +143 -0
  46. package/src/interfaces/rpcInterfaces/network.ts +195 -0
  47. package/src/interfaces/rpcInterfaces/rawtransactions.ts +314 -0
  48. package/src/interfaces/rpcInterfaces/util.ts +52 -0
  49. package/src/interfaces/rpcInterfaces/wallet.ts +674 -0
  50. package/src/interfaces/rpcInterfaces/zmq.ts +11 -0
  51. package/src/restClient.ts +119 -0
  52. package/src/rpcClient.ts +93 -0
  53. package/src/utils/errors.ts +6 -0
  54. package/src/utils/utils.ts +55 -0
  55. package/test/restClient.test.ts +32 -0
  56. package/test/rpcClient.test.ts +115 -0
  57. package/test/setupTests.ts +54 -0
  58. package/test/tsconfig.json +4 -0
  59. package/tsconfig.json +13 -0
  60. package/vitest.config.ts +9 -0
@@ -0,0 +1,54 @@
1
+ export interface GetMemoryInfo {
2
+ method: 'getmemoryinfo';
3
+ params: [
4
+ mode?: 'stats' | 'mallocinfo'
5
+ ];
6
+ response: {
7
+ locked: {
8
+ used: number;
9
+ free: number;
10
+ total: number;
11
+ locked: number;
12
+ chunks_used: number;
13
+ chunks_free: number;
14
+ };
15
+ };
16
+ }
17
+ export interface GetRpcInfo {
18
+ method: 'getrpcinfo';
19
+ params: [];
20
+ response: {
21
+ active_commands: {
22
+ method: string;
23
+ duration: number;
24
+ }[];
25
+ logpath: string;
26
+ };
27
+ }
28
+ export interface Help {
29
+ method: 'help';
30
+ params: [
31
+ command?: string
32
+ ];
33
+ response: string;
34
+ }
35
+ export interface Logging {
36
+ method: 'logging';
37
+ params: [
38
+ include_category?: string[],
39
+ exclude_category?: string[]
40
+ ];
41
+ response: {
42
+ [category: string]: boolean;
43
+ };
44
+ }
45
+ export interface Stop {
46
+ method: 'stop';
47
+ params: [];
48
+ response: string;
49
+ }
50
+ export interface Uptime {
51
+ method: 'uptime';
52
+ params: [];
53
+ response: number;
54
+ }
@@ -0,0 +1,3 @@
1
+ /* --- Control Commands --- */
2
+ // progress 6/6
3
+ export {};
@@ -0,0 +1,17 @@
1
+ export interface Generate {
2
+ method: 'generate';
3
+ params: [
4
+ nblocks: number,
5
+ maxtries?: number
6
+ ];
7
+ response: string[];
8
+ }
9
+ export interface GenerateToAddress {
10
+ method: 'generatetoaddress';
11
+ params: [
12
+ nblocks: number,
13
+ address: string,
14
+ maxtries?: number
15
+ ];
16
+ response: string[];
17
+ }
@@ -0,0 +1,3 @@
1
+ /* --- Generating Commands --- */
2
+ // progress 2/2
3
+ export {};
@@ -0,0 +1,9 @@
1
+ export * from './blockchain.js';
2
+ export * from './control.js';
3
+ export * from './generating.js';
4
+ export * from './mining.js';
5
+ export * from './network.js';
6
+ export * from './rawtransactions.js';
7
+ export * from './util.js';
8
+ export * from './wallet.js';
9
+ export * from './zmq.js';
@@ -0,0 +1,12 @@
1
+ // For the full list of commands see the documentation on
2
+ // https://docs.bitcoincashnode.org/doc/json-rpc/
3
+ // Total progress 136/136 (100%)
4
+ export * from './blockchain.js';
5
+ export * from './control.js';
6
+ export * from './generating.js';
7
+ export * from './mining.js';
8
+ export * from './network.js';
9
+ export * from './rawtransactions.js';
10
+ export * from './util.js';
11
+ export * from './wallet.js';
12
+ export * from './zmq.js';
@@ -0,0 +1,131 @@
1
+ export interface GetBlockTemplate {
2
+ method: 'getblocktemplate';
3
+ params: {
4
+ mode?: 'template' | 'proposal';
5
+ capabilities?: ('longpoll' | 'coinbasetxn' | 'coinbasevalue' | 'proposal' | 'serverlist' | 'workid')[];
6
+ longpollid?: string;
7
+ checkvalidity?: boolean;
8
+ ignorecache?: boolean;
9
+ };
10
+ response: {
11
+ version: number;
12
+ previousblockhash: string;
13
+ transactions: {
14
+ data: string;
15
+ txid: string;
16
+ hash: string;
17
+ depends: number[];
18
+ fee: number;
19
+ sigops: number;
20
+ required: boolean;
21
+ }[];
22
+ coinbaseaux: {
23
+ flags: string;
24
+ };
25
+ coinbasevalue: number;
26
+ coinbasetxn?: object;
27
+ target: string;
28
+ mintime: number;
29
+ mutable: string[];
30
+ noncerange: string;
31
+ sigoplimit: number;
32
+ sizelimit: number;
33
+ curtime: number;
34
+ bits: string;
35
+ height: number;
36
+ };
37
+ }
38
+ export interface GetBlockTemplateLight {
39
+ method: 'getblocktemplatelight';
40
+ params: [
41
+ {
42
+ mode?: 'template' | 'proposal';
43
+ capabilities?: ('longpoll' | 'coinbasetxn' | 'coinbasevalue' | 'proposal' | 'serverlist' | 'workid')[];
44
+ longpollid?: string;
45
+ checkvalidity?: boolean;
46
+ ignorecache?: boolean;
47
+ },
48
+ additional_txs?: string[]
49
+ ];
50
+ response: {
51
+ version: number;
52
+ previousblockhash: string;
53
+ job_id: string;
54
+ merkle: string[];
55
+ coinbaseaux: {
56
+ flags: string;
57
+ };
58
+ coinbasevalue: number;
59
+ coinbasetxn: object;
60
+ target: string;
61
+ mintime: number;
62
+ mutable: string[];
63
+ noncerange: string;
64
+ sigoplimit: number;
65
+ sizelimit: number;
66
+ curtime: number;
67
+ bits: string;
68
+ height: number;
69
+ };
70
+ }
71
+ export interface GetMiningInfo {
72
+ method: 'getmininginfo';
73
+ params: [];
74
+ response: {
75
+ blocks: number;
76
+ currentblocksize: number;
77
+ currentblocktx: number;
78
+ difficulty: number;
79
+ networkhashps: number;
80
+ miningblocksizelimit: number;
81
+ pooledtx: number;
82
+ chain: string;
83
+ warnings: string;
84
+ };
85
+ }
86
+ export interface GetNetworkHashps {
87
+ method: 'getnetworkhashps';
88
+ params: [
89
+ nblocks?: number,
90
+ height?: number
91
+ ];
92
+ response: number;
93
+ }
94
+ export interface PrioritiseTransaction {
95
+ method: 'prioritisetransaction';
96
+ params: [
97
+ txid: string,
98
+ fee_delta: number
99
+ ];
100
+ response: true;
101
+ }
102
+ export interface SubmitBlock {
103
+ method: 'submitblock';
104
+ params: [
105
+ hexdata: string,
106
+ dummy?: string
107
+ ];
108
+ response: {};
109
+ }
110
+ export interface SubmitBlockLight {
111
+ method: 'submitblocklight';
112
+ params: [
113
+ hexdata: string,
114
+ job_id: string
115
+ ];
116
+ response: {};
117
+ }
118
+ export interface SubmitHeader {
119
+ method: 'submitheader';
120
+ params: [
121
+ hexdata: string
122
+ ];
123
+ response: {};
124
+ }
125
+ export interface ValidateBlockTemplate {
126
+ method: 'validateblocktemplate';
127
+ params: [
128
+ hexdata: string
129
+ ];
130
+ response: true;
131
+ }
@@ -0,0 +1,3 @@
1
+ /* --- Mining Commands --- */
2
+ // progress 9/9
3
+ export {};
@@ -0,0 +1,179 @@
1
+ export interface AddNode {
2
+ method: 'addnode';
3
+ params: [
4
+ node: string,
5
+ command: 'add' | 'remove' | 'onetry'
6
+ ];
7
+ response: null;
8
+ }
9
+ export interface ClearBanned {
10
+ method: 'clearbanned';
11
+ params: [
12
+ manual?: boolean,
13
+ automatic?: boolean
14
+ ];
15
+ response: null;
16
+ }
17
+ export interface DisconnectNode {
18
+ method: 'disconnectnode';
19
+ params: [
20
+ address?: string,
21
+ nodeid?: number
22
+ ];
23
+ response: null;
24
+ }
25
+ export interface GetAddedNodeInfo {
26
+ method: 'getaddednodeinfo';
27
+ params: [
28
+ node?: string
29
+ ];
30
+ response: {
31
+ addednode: string;
32
+ connected: boolean;
33
+ addresses?: {
34
+ address: string;
35
+ connected: string;
36
+ }[];
37
+ }[];
38
+ }
39
+ export interface GetConnectionCount {
40
+ method: 'getconnectioncount';
41
+ params: [];
42
+ response: number;
43
+ }
44
+ export interface GetExcessiveBlock {
45
+ method: 'getexcessiveblock';
46
+ params: [];
47
+ response: number;
48
+ }
49
+ export interface GetNetTotals {
50
+ method: 'getnettotals';
51
+ params: [];
52
+ response: {
53
+ totalbytesrecv: number;
54
+ totalbytessent: number;
55
+ timemillis: number;
56
+ uploadtarget: {
57
+ timeframe: number;
58
+ target: number;
59
+ target_reached: boolean;
60
+ serve_historical_blocks: boolean;
61
+ bytes_left_in_cycle: number;
62
+ time_left_in_cycle: number;
63
+ };
64
+ };
65
+ }
66
+ export interface GetNetworkInfo {
67
+ method: 'getnetworkinfo';
68
+ params: [];
69
+ response: {
70
+ version: number;
71
+ subversion: string;
72
+ protocolversion: number;
73
+ localservices: string;
74
+ localrelay: boolean;
75
+ timeoffset: number;
76
+ connections: number;
77
+ networkactive: boolean;
78
+ networks: {
79
+ name: string;
80
+ limited: boolean;
81
+ reachable: boolean;
82
+ proxy: string;
83
+ proxy_randomize_credentials: boolean;
84
+ }[];
85
+ relayfee: number;
86
+ excessutxocharge: number;
87
+ localaddresses: {
88
+ address: string;
89
+ port: number;
90
+ score: number;
91
+ }[];
92
+ warnings: string;
93
+ };
94
+ }
95
+ export interface GetNodeAddresses {
96
+ method: 'getnodeaddresses';
97
+ params: [
98
+ count?: number
99
+ ];
100
+ response: {
101
+ time: number;
102
+ services: number;
103
+ address: string;
104
+ port: number;
105
+ }[];
106
+ }
107
+ export interface GetPeerInfo {
108
+ method: 'getpeerinfo';
109
+ params: [];
110
+ response: {
111
+ id: number;
112
+ addr: string;
113
+ addrbind: string;
114
+ addrlocal: string;
115
+ mapped_as: string;
116
+ services: string;
117
+ relaytxes: boolean;
118
+ lastsend: number;
119
+ lastrecv: number;
120
+ bytessent: number;
121
+ bytesrecv: number;
122
+ conntime: number;
123
+ timeoffset: number;
124
+ pingtime: number;
125
+ minping: number;
126
+ pingwait: number;
127
+ version: number;
128
+ subver: string;
129
+ inbound: boolean;
130
+ addnode: boolean;
131
+ startingheight: number;
132
+ banscore: number;
133
+ synced_headers: number;
134
+ synced_blocks: number;
135
+ inflight: number[];
136
+ addr_processed: number;
137
+ addr_rate_limited: number;
138
+ whitelisted: boolean;
139
+ minfeefilter: number;
140
+ bytessent_per_msg: {
141
+ [msg: string]: number;
142
+ };
143
+ bytesrecv_per_msg: {
144
+ [msg: string]: number;
145
+ };
146
+ }[];
147
+ }
148
+ export interface ListBanned {
149
+ method: 'listbanned';
150
+ params: [];
151
+ response: {
152
+ address: string;
153
+ banned_until: number;
154
+ ban_created: number;
155
+ ban_reason: string;
156
+ }[];
157
+ }
158
+ export interface Ping {
159
+ method: 'ping';
160
+ params: [];
161
+ response: null;
162
+ }
163
+ export interface SetBan {
164
+ method: 'setban';
165
+ params: [
166
+ subnet: string,
167
+ command: 'add' | 'remove',
168
+ bantime?: number,
169
+ absolute?: boolean
170
+ ];
171
+ response: null;
172
+ }
173
+ export interface SetNetworkActive {
174
+ method: 'setnetworkactive';
175
+ params: [
176
+ state: boolean
177
+ ];
178
+ response: null;
179
+ }
@@ -0,0 +1,3 @@
1
+ /* --- Network Commands --- */
2
+ // progress 14/14
3
+ export {};
@@ -0,0 +1,283 @@
1
+ import type { TokenData, Transaction, TransactionInput, TransactionOutput } from "../interfaces.js";
2
+ export interface CombinePsbt {
3
+ method: 'decoderawtransaction';
4
+ params: [
5
+ txs: string[]
6
+ ];
7
+ response: string;
8
+ }
9
+ export interface CombineRawTransaction {
10
+ method: 'combinerawtransaction';
11
+ params: [
12
+ txs: string[]
13
+ ];
14
+ response: string;
15
+ }
16
+ export interface ConvertToPsbt {
17
+ method: 'converttopsbt';
18
+ params: [
19
+ hexstring: string,
20
+ permitsigdata?: boolean
21
+ ];
22
+ response: string;
23
+ }
24
+ export interface CreatePsbt {
25
+ method: 'createpsbt';
26
+ params: [
27
+ inputs: {
28
+ txid: string;
29
+ vout: number;
30
+ sequence?: number;
31
+ }[],
32
+ outputs: {
33
+ [address: string]: number | {
34
+ amount: number;
35
+ tokendata: TokenData;
36
+ } | {
37
+ data: string;
38
+ };
39
+ }[],
40
+ locktime?: number
41
+ ];
42
+ response: string;
43
+ }
44
+ export interface CreateRawTransaction {
45
+ method: 'createrawtransaction';
46
+ params: [
47
+ inputs: {
48
+ txid: string;
49
+ vout: number;
50
+ sequence?: number;
51
+ }[],
52
+ outputs: {
53
+ [address: string]: number | {
54
+ amount: number;
55
+ tokendata: TokenData;
56
+ } | {
57
+ data: string;
58
+ };
59
+ }[],
60
+ locktime?: number
61
+ ];
62
+ response: string;
63
+ }
64
+ export interface DecodePsbt {
65
+ method: 'decodepsbt';
66
+ params: [
67
+ psbt: string
68
+ ];
69
+ response: {
70
+ tx: Transaction;
71
+ unknown: Record<string, string>;
72
+ inputs: PsbtInput[];
73
+ outputs: PsbtOutput[];
74
+ fee?: number;
75
+ };
76
+ }
77
+ interface PsbtInput {
78
+ utxo?: {
79
+ amount: number;
80
+ scriptPubKey: {
81
+ asm: string;
82
+ hex: string;
83
+ type: string;
84
+ addresses?: string[];
85
+ };
86
+ tokenData?: TokenData;
87
+ };
88
+ partial_signatures?: Record<string, string>;
89
+ sighash?: string;
90
+ redeem_script?: RedeemScript;
91
+ bip32_derivs?: Bip32Derivation[];
92
+ final_scriptsig?: {
93
+ asm: string;
94
+ hex: string;
95
+ };
96
+ unknown?: Record<string, string>;
97
+ }
98
+ interface PsbtOutput {
99
+ redeem_script?: RedeemScript;
100
+ bip32_derivs?: Bip32Derivation[];
101
+ unknown?: Record<string, string>;
102
+ }
103
+ interface RedeemScript {
104
+ asm: string;
105
+ hex: string;
106
+ type: string;
107
+ }
108
+ interface Bip32Derivation {
109
+ pubkey: string;
110
+ master_fingerprint: string;
111
+ path: string;
112
+ }
113
+ export interface DecodeRawTransaction {
114
+ method: 'decoderawtransaction';
115
+ params: [
116
+ hexstring: string
117
+ ];
118
+ response: Transaction;
119
+ }
120
+ export interface DecodeScript {
121
+ method: 'decodescript';
122
+ params: [
123
+ hexstring: string
124
+ ];
125
+ response: {
126
+ asm: string;
127
+ type: string;
128
+ reqSigs: number;
129
+ addresses: string[];
130
+ p2sh: string;
131
+ };
132
+ }
133
+ export interface FinalizePsbt {
134
+ method: 'finalizepsbt';
135
+ params: [
136
+ psbt: string,
137
+ extract?: boolean
138
+ ];
139
+ response: {
140
+ psbt: string;
141
+ hex: string;
142
+ complete: boolean;
143
+ };
144
+ }
145
+ export interface FundRawTransaction {
146
+ method: 'fundrawtransaction';
147
+ params: [
148
+ hexstring: string,
149
+ options?: {
150
+ include_unsafe?: boolean;
151
+ changeAddress?: string;
152
+ changePosition?: number;
153
+ includeWatching?: boolean;
154
+ lockUnspents?: boolean;
155
+ feeRate?: number | string;
156
+ subtractFeeFromOutputs?: number[];
157
+ }
158
+ ];
159
+ response: {
160
+ hex: string;
161
+ fee: number;
162
+ changepos: number;
163
+ };
164
+ }
165
+ interface GetRawTransactionBase {
166
+ method: 'getrawtransaction';
167
+ params: [
168
+ txid: string,
169
+ verbose?: boolean | number,
170
+ blockhash?: string
171
+ ];
172
+ }
173
+ export interface GetRawTransactionVerbosity0 extends GetRawTransactionBase {
174
+ params: [
175
+ txid: string,
176
+ verbose?: false | 0,
177
+ blockhash?: string
178
+ ];
179
+ response: string;
180
+ }
181
+ export interface GetRawTransactionVerbosity1 extends GetRawTransactionBase {
182
+ params: [
183
+ txid: string,
184
+ verbose?: true | 1,
185
+ blockhash?: string
186
+ ];
187
+ response: {
188
+ hex: string;
189
+ txid: string;
190
+ hash: string;
191
+ size: number;
192
+ version: number;
193
+ locktime: number;
194
+ vin: TransactionInput[];
195
+ vout: TransactionOutput[];
196
+ blockhash?: string;
197
+ confirmations?: number;
198
+ time?: number;
199
+ blocktime?: number;
200
+ in_active_chain?: boolean;
201
+ };
202
+ }
203
+ export interface GetRawTransactionVerbosity2 extends GetRawTransactionBase {
204
+ params: [
205
+ txid: string,
206
+ verbose?: 2,
207
+ blockhash?: string
208
+ ];
209
+ response: {
210
+ hex: string;
211
+ txid: string;
212
+ hash: string;
213
+ size: number;
214
+ version: number;
215
+ locktime: number;
216
+ vin: TransactionInputVerbosity2[];
217
+ vout: TransactionOutput[];
218
+ blockhash?: string;
219
+ confirmations?: number;
220
+ time?: number;
221
+ blocktime?: number;
222
+ in_active_chain?: boolean;
223
+ fee?: number;
224
+ };
225
+ }
226
+ interface TransactionInputVerbosity2 extends TransactionInput {
227
+ value?: number;
228
+ scriptPubKey?: {
229
+ asm: string;
230
+ hex: string;
231
+ type: string;
232
+ address?: string;
233
+ };
234
+ tokenData?: TokenData;
235
+ }
236
+ export interface SendRawTransaction {
237
+ method: 'sendrawtransaction';
238
+ params: [
239
+ hexstring: string,
240
+ allowhighfees?: boolean
241
+ ];
242
+ response: string;
243
+ }
244
+ export interface SignRawTransactionWithKey {
245
+ method: 'signrawtransactionwithkey';
246
+ params: [
247
+ hexstring: string,
248
+ privkeys: string[],
249
+ prevtxs?: {
250
+ txid: string;
251
+ vout: number;
252
+ scriptPubKey: string;
253
+ redeemScript?: string;
254
+ amount: number | string;
255
+ tokenData?: TokenData;
256
+ }[],
257
+ sighashtype?: string
258
+ ];
259
+ response: {
260
+ hex: string;
261
+ complete: boolean;
262
+ errors?: {
263
+ txid: string;
264
+ vout: number;
265
+ scriptSig: string;
266
+ sequence: number;
267
+ error: string;
268
+ }[];
269
+ };
270
+ }
271
+ export interface TestMempoolAccept {
272
+ method: 'testmempoolaccept';
273
+ params: [
274
+ rawtxs: string[],
275
+ allowhighfees?: boolean
276
+ ];
277
+ response: {
278
+ txid: string;
279
+ allowed: boolean;
280
+ 'reject-reason': string;
281
+ }[];
282
+ }
283
+ export {};
@@ -0,0 +1,3 @@
1
+ /* --- Rawtransactions Commands --- */
2
+ // progress 14/14
3
+ export {};