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

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