@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.
- package/.claude/settings.local.json +8 -0
- package/.github/workflows/ci.yaml +36 -0
- package/CLAUDE.md +70 -0
- package/README.md +121 -129
- package/dist/interfaces/interfaces.d.ts +13 -0
- package/dist/interfaces/restInterfaces/interfaces.d.ts +124 -18
- package/dist/interfaces/rpcInterfaces/blockchain.d.ts +293 -102
- package/dist/interfaces/rpcInterfaces/control.d.ts +6 -0
- package/dist/interfaces/rpcInterfaces/generating.d.ts +2 -0
- package/dist/interfaces/rpcInterfaces/mining.d.ts +9 -0
- package/dist/interfaces/rpcInterfaces/network.d.ts +18 -0
- package/dist/interfaces/rpcInterfaces/rawtransactions.d.ts +21 -0
- package/dist/interfaces/rpcInterfaces/util.d.ts +5 -0
- package/dist/interfaces/rpcInterfaces/wallet.d.ts +54 -0
- package/dist/interfaces/rpcInterfaces/zmq.d.ts +1 -0
- package/dist/restClient.d.ts +13 -1
- package/dist/restClient.js +19 -6
- package/dist/rpcClient.d.ts +7 -0
- package/dist/rpcClient.js +7 -0
- package/package.json +7 -8
- package/pnpm-lock.yaml +1279 -0
- package/src/index.ts +3 -3
- package/src/interfaces/interfaces.ts +96 -86
- package/src/interfaces/restInterfaces/interfaces.ts +235 -116
- package/src/interfaces/rpcInterfaces/blockchain.ts +932 -758
- package/src/interfaces/rpcInterfaces/control.ts +68 -62
- package/src/interfaces/rpcInterfaces/generating.ts +23 -21
- package/src/interfaces/rpcInterfaces/index.ts +13 -13
- package/src/interfaces/rpcInterfaces/mining.ts +151 -143
- package/src/interfaces/rpcInterfaces/network.ts +213 -195
- package/src/interfaces/rpcInterfaces/rawtransactions.ts +332 -314
- package/src/interfaces/rpcInterfaces/util.ts +56 -52
- package/src/interfaces/rpcInterfaces/wallet.ts +728 -674
- package/src/interfaces/rpcInterfaces/zmq.ts +12 -11
- package/src/restClient.ts +134 -119
- package/src/rpcClient.ts +100 -93
- package/src/utils/errors.ts +6 -6
- package/src/utils/utils.ts +55 -55
- package/test/restClient.test.ts +33 -31
- package/test/rpcClient.test.ts +119 -115
- package/test/setupTests.ts +56 -54
- package/test/tsconfig.json +4 -4
- package/tsconfig.json +13 -13
- package/vitest.config.ts +8 -8
- 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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export interface
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
ablastate:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
export interface
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
}
|