@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
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './interfaces/interfaces.js'
2
- export * from './interfaces/rpcInterfaces/index.js'
3
- export { BchnRpcClient } from './rpcClient.js'
1
+ export * from './interfaces/interfaces.js'
2
+ export * from './interfaces/rpcInterfaces/index.js'
3
+ export { BchnRpcClient } from './rpcClient.js'
4
4
  export { BchnRestClient } from './restClient.js'
@@ -1,87 +1,97 @@
1
- export interface BaseRpcClientConfig {
2
- rpcUser: string;
3
- rpcPassword: string;
4
- maxRetries?: number;
5
- retryDelayMs?: number;
6
- logger?: typeof console ;
7
- timeoutMs?: number;
8
- }
9
-
10
- export interface RpcClientUrlConfig extends BaseRpcClientConfig {
11
- url: string;
12
- }
13
-
14
- export interface RpcClientHostConfig extends BaseRpcClientConfig {
15
- protocol: 'http' | 'https';
16
- host: string;
17
- port: number;
18
- }
19
-
20
- export type RpcClientConfig = RpcClientUrlConfig | RpcClientHostConfig
21
-
22
- export type RPCParameter = string | number | boolean | undefined | object;
23
- declare type RequestResponse = object | string | number | boolean | null | RequestResponse[];
24
-
25
- export interface RpcRequest {
26
- method: string;
27
- params: Array<RPCParameter>;
28
- response: RequestResponse;
29
- }
30
-
31
- export interface RestClientConfig {
32
- url: string;
33
- logger?: typeof console ;
34
- timeoutMs?: number;
35
- }
36
-
37
-
38
- export type formatOptions = 'bin' | 'hex' | 'json'
39
-
40
- // Conditional type to return the appropriate data type based on format
41
- export type ResponseType<TFormat extends formatOptions, TJson> =
42
- TFormat extends 'json' ? TJson :
43
- TFormat extends 'hex' | 'bin' ? string :
44
- never;
45
-
46
- // General interfaces used in both REST & RPC endpoints
47
- export interface Transaction {
48
- txid: string;
49
- hash: string;
50
- size: number;
51
- version: number;
52
- locktime: number;
53
- vin: TransactionInput[];
54
- vout: TransactionOutput[];
55
- }
56
-
57
- export interface TransactionInput {
58
- txid: string;
59
- vout: number;
60
- scriptSig: {
61
- asm: string;
62
- hex: string;
63
- };
64
- sequence: number;
65
- }
66
-
67
- export interface TransactionOutput {
68
- value: number;
69
- n: number;
70
- scriptPubKey: {
71
- asm: string;
72
- hex: string;
73
- reqSigs: number;
74
- type: string;
75
- addresses: string[];
76
- tokenData: TokenData;
77
- }
78
- }
79
-
80
- export interface TokenData {
81
- category : string;
82
- amount: string;
83
- nft?: {
84
- capability: 'none' | 'mutable' | 'minting';
85
- commitment: string;
86
- }
1
+ /** Base RPC client authentication and connection settings. */
2
+ export interface BaseRpcClientConfig {
3
+ rpcUser: string;
4
+ rpcPassword: string;
5
+ maxRetries?: number;
6
+ retryDelayMs?: number;
7
+ logger?: typeof console ;
8
+ timeoutMs?: number;
9
+ }
10
+
11
+ /** RPC client config using a full URL (e.g., "http://localhost:8332"). */
12
+ export interface RpcClientUrlConfig extends BaseRpcClientConfig {
13
+ url: string;
14
+ }
15
+
16
+ /** RPC client config using separate host, port, and protocol. */
17
+ export interface RpcClientHostConfig extends BaseRpcClientConfig {
18
+ protocol: 'http' | 'https';
19
+ host: string;
20
+ port: number;
21
+ }
22
+
23
+ /** RPC client configuration - either URL-based or host-based. */
24
+ export type RpcClientConfig = RpcClientUrlConfig | RpcClientHostConfig
25
+
26
+ /** Valid parameter types for RPC method calls. */
27
+ export type RPCParameter = string | number | boolean | undefined | object;
28
+ declare type RequestResponse = object | string | number | boolean | null | RequestResponse[];
29
+
30
+ /** Base interface for all RPC request types with method, params, and response. */
31
+ export interface RpcRequest {
32
+ method: string;
33
+ params: Array<RPCParameter>;
34
+ response: RequestResponse;
35
+ }
36
+
37
+ /** REST client configuration. */
38
+ export interface RestClientConfig {
39
+ url: string;
40
+ logger?: typeof console ;
41
+ timeoutMs?: number;
42
+ }
43
+
44
+ /** REST endpoint response format options. */
45
+ export type formatOptions = 'bin' | 'hex' | 'json'
46
+
47
+ /** Conditional return type based on format: JSON returns parsed object, hex/bin return string. */
48
+ export type ResponseType<TFormat extends formatOptions, TJson> =
49
+ TFormat extends 'json' ? TJson :
50
+ TFormat extends 'hex' | 'bin' ? string :
51
+ never;
52
+
53
+ /** Base transaction structure used in both REST and RPC responses. */
54
+ export interface Transaction {
55
+ txid: string;
56
+ hash: string;
57
+ size: number;
58
+ version: number;
59
+ locktime: number;
60
+ vin: TransactionInput[];
61
+ vout: TransactionOutput[];
62
+ }
63
+
64
+ /** Transaction input referencing a previous output (UTXO). */
65
+ export interface TransactionInput {
66
+ txid: string;
67
+ vout: number;
68
+ scriptSig: {
69
+ asm: string;
70
+ hex: string;
71
+ };
72
+ sequence: number;
73
+ }
74
+
75
+ /** Transaction output with value and locking script. */
76
+ export interface TransactionOutput {
77
+ value: number;
78
+ n: number;
79
+ scriptPubKey: {
80
+ asm: string;
81
+ hex: string;
82
+ reqSigs: number;
83
+ type: string;
84
+ addresses: string[];
85
+ tokenData: TokenData;
86
+ }
87
+ }
88
+
89
+ /** CashTokens data attached to a UTXO (fungible amount and/or NFT). */
90
+ export interface TokenData {
91
+ category : string;
92
+ amount: string;
93
+ nft?: {
94
+ capability: 'none' | 'mutable' | 'minting';
95
+ commitment: string;
96
+ }
87
97
  }
@@ -1,117 +1,236 @@
1
- import type { Transaction } from "../interfaces.js";
2
-
3
- export interface BlockInfoNoTxDetails {
4
- hash: string;
5
- confirmations: number;
6
- size: number;
7
- height: number;
8
- version: number;
9
- versionHex: string;
10
- merkleroot: string;
11
- tx : string[]
12
- time: number;
13
- mediantime: number;
14
- nonce: number;
15
- bits: string;
16
- difficulty: number;
17
- chainwork: string;
18
- nTx: number;
19
- previousblockhash: string;
20
- nextblockhash: string;
21
- ablastate: {
22
- epsilon: number;
23
- beta: number;
24
- blocksize: number;
25
- blocksizelimit: number;
26
- nextblocksizelimit: number;
27
- }
28
- }
29
-
30
- export interface BlockInfoTxDetails extends Omit<BlockInfoNoTxDetails, 'tx'>{
31
- tx: Transaction[]
32
- }
33
-
34
- export interface HeaderInfo {
35
- hash: string;
36
- confirmations: number;
37
- height: number;
38
- version: number;
39
- versionHex: string;
40
- merkleroot: string;
41
- time: number;
42
- mediantime: number;
43
- nonce: number;
44
- bits: string;
45
- difficulty: number;
46
- chainwork: string;
47
- nTx: number;
48
- previousblockhash: string;
49
- nextblockhash: string;
50
- ablastate: {
51
- epsilon: number;
52
- beta: number;
53
- blocksize: number;
54
- blocksizelimit: number;
55
- nextblocksizelimit: number;
56
- }
57
- }
58
-
59
- export interface ChainInfo {
60
- chain: 'main' | 'test' | 'regtest';
61
- blocks: number;
62
- headers: number;
63
- bestblockhash: string;
64
- difficulty: number;
65
- mediantime: number;
66
- verificationprogress: number;
67
- initialblockdownload: boolean,
68
- chainwork: string;
69
- size_on_disk: number;
70
- pruned: boolean;
71
- warnings: string;
72
- }
73
-
74
- export interface UtxosInfo {
75
- chaintipHash: string;
76
- chainHeight: number;
77
- utxos: {
78
- scriptPubKey: {
79
- addresses: string[];
80
- type: string;
81
- hex: string;
82
- reqSigs: number;
83
- asm: string;
84
- },
85
- value: number
86
- height: number
87
- txvers: number
88
- }[]
89
- bitmap: string;
90
- }
91
-
92
- export interface MempoolInfo {
93
- loaded: boolean;
94
- size: number;
95
- bytes: number;
96
- usage: number;
97
- maxmempool: number;
98
- mempoolminfee: number;
99
- minrelaytxfee: number;
100
- }
101
-
102
- export interface MempoolContent {
103
- [txid: string]: {
104
- fees: {
105
- base: number;
106
- modified: number;
107
- },
108
- size: number;
109
- time: number;
110
- depends: string[];
111
- spentby: string[];
112
- }
113
- }
114
-
115
- export interface TxDetails extends Transaction {
116
- blockhash: string;
1
+ import type { Transaction } from "../interfaces.js";
2
+
3
+ /** Adaptive Block Limit Algorithm state (activated May 2024). */
4
+ export interface AblaState {
5
+ epsilon: number;
6
+ beta: number;
7
+ blocksize: number;
8
+ blocksizelimit: number;
9
+ nextblocksizelimit: number;
10
+ }
11
+
12
+ /**
13
+ * Base block info fields shared across response types.
14
+ * @note `previousblockhash` not present on genesis block (height 0).
15
+ * @note `nextblockhash` not present on chain tip.
16
+ */
17
+ interface BlockInfoBase {
18
+ hash: string;
19
+ confirmations: number;
20
+ size: number;
21
+ height: number;
22
+ version: number;
23
+ versionHex: string;
24
+ merkleroot: string;
25
+ time: number;
26
+ mediantime: number;
27
+ nonce: number;
28
+ bits: string;
29
+ difficulty: number;
30
+ chainwork: string;
31
+ nTx: number;
32
+ previousblockhash: string;
33
+ nextblockhash: string;
34
+ }
35
+
36
+ /** Block info with tx IDs only - works for any block. */
37
+ export interface BlockInfoNoTxDetails extends BlockInfoBase {
38
+ tx: string[];
39
+ ablastate?: AblaState;
40
+ }
41
+
42
+ /** Block info with tx IDs only - for blocks before ABLA activation (May 2024). */
43
+ export interface BlockInfoNoTxDetailsPreAbla extends BlockInfoBase {
44
+ tx: string[];
45
+ }
46
+
47
+ /** Block info with tx IDs only - for blocks after ABLA activation (May 2024). */
48
+ export interface BlockInfoNoTxDetailsPostAbla extends BlockInfoBase {
49
+ tx: string[];
50
+ ablastate: AblaState;
51
+ }
52
+
53
+ /** Block info with full transaction objects - works for any block. */
54
+ export interface BlockInfoTxDetails extends BlockInfoBase {
55
+ tx: Transaction[];
56
+ ablastate?: AblaState;
57
+ }
58
+
59
+ /** Block info with full transaction objects - for blocks before ABLA activation (May 2024). */
60
+ export interface BlockInfoTxDetailsPreAbla extends BlockInfoBase {
61
+ tx: Transaction[];
62
+ }
63
+
64
+ /** Block info with full transaction objects - for blocks after ABLA activation (May 2024). */
65
+ export interface BlockInfoTxDetailsPostAbla extends BlockInfoBase {
66
+ tx: Transaction[];
67
+ ablastate: AblaState;
68
+ }
69
+
70
+ /**
71
+ * Base header info fields shared across response types.
72
+ * @note `previousblockhash` not present on genesis block (height 0).
73
+ * @note `nextblockhash` not present on chain tip.
74
+ */
75
+ interface HeaderInfoBase {
76
+ hash: string;
77
+ confirmations: number;
78
+ height: number;
79
+ version: number;
80
+ versionHex: string;
81
+ merkleroot: string;
82
+ time: number;
83
+ mediantime: number;
84
+ nonce: number;
85
+ bits: string;
86
+ difficulty: number;
87
+ chainwork: string;
88
+ nTx: number;
89
+ previousblockhash: string;
90
+ nextblockhash: string;
91
+ }
92
+
93
+ /** Block header info - works for any block. */
94
+ export interface HeaderInfo extends HeaderInfoBase {
95
+ ablastate?: AblaState;
96
+ }
97
+
98
+ /** Block header info - for blocks before ABLA activation (May 2024). */
99
+ export interface HeaderInfoPreAbla extends HeaderInfoBase {}
100
+
101
+ /** Block header info - for blocks after ABLA activation (May 2024). */
102
+ export interface HeaderInfoPostAbla extends HeaderInfoBase {
103
+ ablastate: AblaState;
104
+ }
105
+
106
+ /** Current blockchain state and synchronization status. */
107
+ export interface ChainInfo {
108
+ chain: 'main' | 'test' | 'regtest';
109
+ blocks: number;
110
+ headers: number;
111
+ bestblockhash: string;
112
+ difficulty: number;
113
+ mediantime: number;
114
+ verificationprogress: number;
115
+ initialblockdownload: boolean,
116
+ chainwork: string;
117
+ size_on_disk: number;
118
+ pruned: boolean;
119
+ warnings: string;
120
+ }
121
+
122
+ /** UTXO set query result with bitmap for checked outpoints. */
123
+ export interface UtxosInfo {
124
+ chaintipHash: string;
125
+ chainHeight: number;
126
+ utxos: {
127
+ scriptPubKey: {
128
+ addresses: string[];
129
+ type: string;
130
+ hex: string;
131
+ reqSigs: number;
132
+ asm: string;
133
+ },
134
+ value: number
135
+ height: number
136
+ txvers: number
137
+ }[]
138
+ bitmap: string;
139
+ }
140
+
141
+ /** Mempool configuration and size statistics. */
142
+ export interface MempoolInfo {
143
+ loaded: boolean;
144
+ size: number;
145
+ bytes: number;
146
+ usage: number;
147
+ maxmempool: number;
148
+ mempoolminfee: number;
149
+ minrelaytxfee: number;
150
+ permitbaremultisig: boolean;
151
+ maxdatacarriersize: number;
152
+ }
153
+
154
+ /** Mempool contents indexed by txid with fee and dependency info. */
155
+ export interface MempoolContent {
156
+ [txid: string]: {
157
+ fees: {
158
+ base: number;
159
+ modified: number;
160
+ },
161
+ size: number;
162
+ time: number;
163
+ depends: string[];
164
+ spentby: string[];
165
+ }
166
+ }
167
+
168
+ /** Transaction with block hash (for confirmed transactions). */
169
+ export interface TxDetails extends Transaction {
170
+ blockhash: string;
171
+ }
172
+
173
+ /** Script fingerprint and pattern info for bytecode analysis (v29.0.0+). */
174
+ export interface ByteCodePattern {
175
+ fingerprint: string;
176
+ pattern: string;
177
+ patternArgsInfo?: string[];
178
+ }
179
+
180
+ /** Script with optional bytecode pattern metadata (v29.0.0+). */
181
+ export interface ScriptPubKeyWithPattern {
182
+ asm: string;
183
+ hex: string;
184
+ type: string;
185
+ address?: string;
186
+ byteCodePattern?: ByteCodePattern;
187
+ }
188
+
189
+ /** Transaction input with prevout and pattern info (v29.0.0+). */
190
+ export interface TransactionInputWithPattern {
191
+ txid: string;
192
+ vout: number;
193
+ scriptSig: {
194
+ asm: string;
195
+ hex: string;
196
+ };
197
+ sequence: number;
198
+ prevout?: {
199
+ generated: boolean;
200
+ height: number;
201
+ value: number;
202
+ scriptPubKey: ScriptPubKeyWithPattern;
203
+ };
204
+ redeemScript?: {
205
+ asm: string;
206
+ hex: string;
207
+ type: string;
208
+ byteCodePattern?: ByteCodePattern;
209
+ p2shType?: string;
210
+ };
211
+ }
212
+
213
+ /** Transaction output with pattern-enabled scriptPubKey (v29.0.0+). */
214
+ export interface TransactionOutputWithPattern {
215
+ value: number;
216
+ n: number;
217
+ scriptPubKey: ScriptPubKeyWithPattern;
218
+ }
219
+
220
+ /** Transaction with bytecode patterns and optional fee (v29.0.0+). */
221
+ export interface TxDetailsWithPatterns {
222
+ txid: string;
223
+ hash: string;
224
+ size: number;
225
+ version: number;
226
+ locktime: number;
227
+ vin: TransactionInputWithPattern[];
228
+ vout: TransactionOutputWithPattern[];
229
+ blockhash: string;
230
+ fee?: number;
231
+ }
232
+
233
+ /** Block with pattern-enhanced transactions (v29.0.0+). */
234
+ export interface BlockInfoWithPatterns extends Omit<BlockInfoNoTxDetails, 'tx'> {
235
+ tx: TxDetailsWithPatterns[];
117
236
  }