@did-btcr2/bitcoin 0.3.4 → 0.4.0
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/dist/cjs/bitcoin.js +83 -84
- package/dist/cjs/bitcoin.js.map +1 -1
- package/dist/cjs/client/http.js +9 -0
- package/dist/cjs/client/http.js.map +1 -0
- package/dist/cjs/client/rest/address.js +20 -28
- package/dist/cjs/client/rest/address.js.map +1 -1
- package/dist/cjs/client/rest/block.js +23 -22
- package/dist/cjs/client/rest/block.js.map +1 -1
- package/dist/cjs/client/rest/index.js +31 -84
- package/dist/cjs/client/rest/index.js.map +1 -1
- package/dist/cjs/client/rest/protocol.js +129 -0
- package/dist/cjs/client/rest/protocol.js.map +1 -0
- package/dist/cjs/client/rest/transaction.js +19 -21
- package/dist/cjs/client/rest/transaction.js.map +1 -1
- package/dist/cjs/client/rpc/index.js +75 -337
- package/dist/cjs/client/rpc/index.js.map +1 -1
- package/dist/cjs/client/rpc/interface.js +1 -6
- package/dist/cjs/client/rpc/interface.js.map +1 -1
- package/dist/cjs/client/rpc/json-rpc.js +40 -63
- package/dist/cjs/client/rpc/json-rpc.js.map +1 -1
- package/dist/cjs/client/rpc/protocol.js +134 -0
- package/dist/cjs/client/rpc/protocol.js.map +1 -0
- package/dist/cjs/constants.js +16 -5
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/index.js +21 -13
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types.js +5 -55
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/bitcoin.js +83 -84
- package/dist/esm/bitcoin.js.map +1 -1
- package/dist/esm/client/http.js +9 -0
- package/dist/esm/client/http.js.map +1 -0
- package/dist/esm/client/rest/address.js +20 -28
- package/dist/esm/client/rest/address.js.map +1 -1
- package/dist/esm/client/rest/block.js +23 -22
- package/dist/esm/client/rest/block.js.map +1 -1
- package/dist/esm/client/rest/index.js +31 -84
- package/dist/esm/client/rest/index.js.map +1 -1
- package/dist/esm/client/rest/protocol.js +129 -0
- package/dist/esm/client/rest/protocol.js.map +1 -0
- package/dist/esm/client/rest/transaction.js +19 -21
- package/dist/esm/client/rest/transaction.js.map +1 -1
- package/dist/esm/client/rpc/index.js +75 -337
- package/dist/esm/client/rpc/index.js.map +1 -1
- package/dist/esm/client/rpc/interface.js +1 -6
- package/dist/esm/client/rpc/interface.js.map +1 -1
- package/dist/esm/client/rpc/json-rpc.js +40 -63
- package/dist/esm/client/rpc/json-rpc.js.map +1 -1
- package/dist/esm/client/rpc/protocol.js +134 -0
- package/dist/esm/client/rpc/protocol.js.map +1 -0
- package/dist/esm/constants.js +16 -5
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.js +21 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.js +5 -55
- package/dist/esm/types.js.map +1 -1
- package/dist/types/bitcoin.d.ts +66 -45
- package/dist/types/bitcoin.d.ts.map +1 -1
- package/dist/types/client/http.d.ts +21 -0
- package/dist/types/client/http.d.ts.map +1 -0
- package/dist/types/client/rest/address.d.ts +16 -19
- package/dist/types/client/rest/address.d.ts.map +1 -1
- package/dist/types/client/rest/block.d.ts +24 -16
- package/dist/types/client/rest/block.d.ts.map +1 -1
- package/dist/types/client/rest/index.d.ts +20 -51
- package/dist/types/client/rest/index.d.ts.map +1 -1
- package/dist/types/client/rest/protocol.d.ts +58 -0
- package/dist/types/client/rest/protocol.d.ts.map +1 -0
- package/dist/types/client/rest/transaction.d.ts +16 -17
- package/dist/types/client/rest/transaction.d.ts.map +1 -1
- package/dist/types/client/rpc/index.d.ts +105 -253
- package/dist/types/client/rpc/index.d.ts.map +1 -1
- package/dist/types/client/rpc/interface.d.ts +1 -4
- package/dist/types/client/rpc/interface.d.ts.map +1 -1
- package/dist/types/client/rpc/json-rpc.d.ts +20 -18
- package/dist/types/client/rpc/json-rpc.d.ts.map +1 -1
- package/dist/types/client/rpc/protocol.d.ts +82 -0
- package/dist/types/client/rpc/protocol.d.ts.map +1 -0
- package/dist/types/constants.d.ts +16 -5
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/errors.d.ts +4 -3
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +20 -13
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +98 -696
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/bitcoin.ts +105 -118
- package/src/client/http.ts +28 -0
- package/src/client/rest/address.ts +24 -30
- package/src/client/rest/block.ts +29 -26
- package/src/client/rest/index.ts +38 -94
- package/src/client/rest/protocol.ts +153 -0
- package/src/client/rest/transaction.ts +23 -23
- package/src/client/rpc/index.ts +140 -379
- package/src/client/rpc/interface.ts +42 -51
- package/src/client/rpc/json-rpc.ts +53 -60
- package/src/client/rpc/protocol.ts +160 -0
- package/src/constants.ts +17 -5
- package/src/errors.ts +10 -3
- package/src/index.ts +81 -13
- package/src/types.ts +332 -972
|
@@ -1,77 +1,54 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BitcoinRpcError } from '../../errors.js';
|
|
2
|
+
import { defaultHttpExecutor } from '../http.js';
|
|
3
|
+
import { safeText } from '../utils.js';
|
|
4
|
+
import { JsonRpcProtocol } from './protocol.js';
|
|
2
5
|
export class JsonRpcTransport {
|
|
3
|
-
url;
|
|
4
|
-
authHeader;
|
|
5
|
-
id = 0;
|
|
6
|
-
constructor(cfg) {
|
|
7
|
-
this.url = (cfg.host || 'http://127.0.0.1:8332').replace(/\/+$/, '');
|
|
8
|
-
if (cfg.username && cfg.password) {
|
|
9
|
-
this.authHeader = `Basic ${toBase64(`${cfg.username}:${cfg.password}`)}`;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
try {
|
|
13
|
-
const u = new URL(this.url);
|
|
14
|
-
if (u.username || u.password) {
|
|
15
|
-
this.authHeader = `Basic ${toBase64(`${decodeURIComponent(u.username)}:${decodeURIComponent(u.password)}`)}`;
|
|
16
|
-
u.username = '';
|
|
17
|
-
u.password = '';
|
|
18
|
-
this.url = u.toString().replace(/\/+$/, '');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
console.error(`Invalid URL in Bitcoin RPC config: ${this.url}`, error);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
6
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @returns {Promise<any[] | any>} The result of the RPC call(s).
|
|
30
|
-
* @example
|
|
7
|
+
* The sans-I/O protocol layer. Use this to build {@link HttpRequest}
|
|
8
|
+
* descriptors without performing any I/O.
|
|
31
9
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return this.call(batch.method, batch.parameters ?? []);
|
|
42
|
-
}
|
|
10
|
+
protocol;
|
|
11
|
+
execute;
|
|
12
|
+
constructor(cfg, executor) {
|
|
13
|
+
this.protocol = new JsonRpcProtocol(cfg);
|
|
14
|
+
this.execute = executor ?? defaultHttpExecutor;
|
|
15
|
+
}
|
|
16
|
+
/** @internal Expose URL for tests that inspect transport state. */
|
|
17
|
+
get url() {
|
|
18
|
+
return this.protocol.url;
|
|
43
19
|
}
|
|
44
20
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @param {string} method The RPC method to call.
|
|
47
|
-
* @param {any[]} params The parameters for the RPC method.
|
|
48
|
-
* @returns {Promise<any>} The result of the RPC call.
|
|
21
|
+
* Execute a single JSON-RPC call.
|
|
49
22
|
*/
|
|
50
|
-
async call(method, params) {
|
|
51
|
-
const
|
|
52
|
-
const res = await
|
|
53
|
-
method: 'POST',
|
|
54
|
-
headers: {
|
|
55
|
-
'Content-Type': 'application/json',
|
|
56
|
-
...(this.authHeader ? { Authorization: this.authHeader } : {})
|
|
57
|
-
},
|
|
58
|
-
body: JSON.stringify(body)
|
|
59
|
-
});
|
|
23
|
+
async call(method, params = []) {
|
|
24
|
+
const request = this.protocol.buildRequest(method, params);
|
|
25
|
+
const res = await this.execute(request);
|
|
60
26
|
if (!res.ok) {
|
|
61
27
|
const text = await safeText(res);
|
|
62
|
-
|
|
63
|
-
err.code = res.status;
|
|
64
|
-
err.rpc = true;
|
|
65
|
-
throw err;
|
|
28
|
+
throw new BitcoinRpcError('HTTP_ERROR', res.status, text || `${res.status} ${res.statusText}`, { method });
|
|
66
29
|
}
|
|
67
30
|
const payload = await res.json();
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
31
|
+
return this.protocol.parseResponse(payload, method);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Execute a JSON-RPC batch in a single HTTP request.
|
|
35
|
+
* Returns results in the same order as the input calls.
|
|
36
|
+
*/
|
|
37
|
+
async batch(calls) {
|
|
38
|
+
if (calls.length === 0)
|
|
39
|
+
return [];
|
|
40
|
+
if (calls.length === 1) {
|
|
41
|
+
const result = await this.call(calls[0].method, calls[0].params);
|
|
42
|
+
return [result];
|
|
43
|
+
}
|
|
44
|
+
const request = this.protocol.buildBatchRequest(calls);
|
|
45
|
+
const res = await this.execute(request);
|
|
46
|
+
if (!res.ok) {
|
|
47
|
+
const text = await safeText(res);
|
|
48
|
+
throw new BitcoinRpcError('HTTP_ERROR', res.status, text || `${res.status} ${res.statusText}`, { methods: calls.map(c => c.method) });
|
|
73
49
|
}
|
|
74
|
-
|
|
50
|
+
const payloads = await res.json();
|
|
51
|
+
return this.protocol.parseBatchResponse(payloads, calls);
|
|
75
52
|
}
|
|
76
53
|
}
|
|
77
54
|
//# sourceMappingURL=json-rpc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.js","sourceRoot":"","sources":["../../../../src/client/rpc/json-rpc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"json-rpc.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protocol for Bitcoin Core.
|
|
5
|
+
*
|
|
6
|
+
* Builds {@link HttpRequest} descriptors for JSON-RPC method calls and
|
|
7
|
+
* provides response parsing — without performing any I/O.
|
|
8
|
+
*
|
|
9
|
+
* **Security note:** Built requests include an `Authorization` header when
|
|
10
|
+
* credentials are configured. Do not log or persist {@link HttpRequest}
|
|
11
|
+
* objects without redacting the `Authorization` header.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const protocol = new JsonRpcProtocol({
|
|
16
|
+
* host: 'http://localhost:18443',
|
|
17
|
+
* username: 'user',
|
|
18
|
+
* password: 'pass',
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Build a request descriptor (no I/O)
|
|
22
|
+
* const req = protocol.buildRequest('getblockcount', []);
|
|
23
|
+
*
|
|
24
|
+
* // Execute with any HTTP client
|
|
25
|
+
* const res = await fetch(req.url, req);
|
|
26
|
+
* const json = await res.json();
|
|
27
|
+
*
|
|
28
|
+
* // Parse the JSON-RPC response (throws on errors)
|
|
29
|
+
* const blockCount = protocol.parseResponse(json, 'getblockcount', []);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class JsonRpcProtocol {
|
|
33
|
+
url;
|
|
34
|
+
/** Whether this protocol instance has credentials configured. */
|
|
35
|
+
hasAuth;
|
|
36
|
+
_headers;
|
|
37
|
+
_id = 0;
|
|
38
|
+
constructor(cfg) {
|
|
39
|
+
let url = (cfg.host || 'http://127.0.0.1:8332').replace(/\/+$/, '');
|
|
40
|
+
let authHeader;
|
|
41
|
+
if (cfg.username && cfg.password) {
|
|
42
|
+
authHeader = `Basic ${toBase64(`${cfg.username}:${cfg.password}`)}`;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
try {
|
|
46
|
+
const u = new URL(url);
|
|
47
|
+
if (u.username || u.password) {
|
|
48
|
+
authHeader = `Basic ${toBase64(`${decodeURIComponent(u.username)}:${decodeURIComponent(u.password)}`)}`;
|
|
49
|
+
u.username = '';
|
|
50
|
+
u.password = '';
|
|
51
|
+
url = u.toString().replace(/\/+$/, '');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error(`Invalid URL in Bitcoin RPC config: ${url}`, error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
this.url = url;
|
|
59
|
+
this.hasAuth = authHeader !== undefined;
|
|
60
|
+
this._headers = {
|
|
61
|
+
'Content-Type': 'application/json',
|
|
62
|
+
...(authHeader ? { Authorization: authHeader } : {}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Build an {@link HttpRequest} for a JSON-RPC method call.
|
|
67
|
+
*/
|
|
68
|
+
buildRequest(method, params) {
|
|
69
|
+
const body = { jsonrpc: '2.0', id: ++this._id, method, params };
|
|
70
|
+
return {
|
|
71
|
+
url: this.url,
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: { ...this._headers },
|
|
74
|
+
body: JSON.stringify(body),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Build an {@link HttpRequest} for a JSON-RPC batch call.
|
|
79
|
+
* Sends all calls in a single HTTP request per the JSON-RPC 2.0 spec.
|
|
80
|
+
*/
|
|
81
|
+
buildBatchRequest(calls) {
|
|
82
|
+
const body = calls.map(c => ({
|
|
83
|
+
jsonrpc: '2.0',
|
|
84
|
+
id: ++this._id,
|
|
85
|
+
method: c.method,
|
|
86
|
+
params: c.params,
|
|
87
|
+
}));
|
|
88
|
+
return {
|
|
89
|
+
url: this.url,
|
|
90
|
+
method: 'POST',
|
|
91
|
+
headers: { ...this._headers },
|
|
92
|
+
body: JSON.stringify(body),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parse a JSON-RPC response payload, throwing {@link BitcoinRpcError}
|
|
97
|
+
* if the response contains an error.
|
|
98
|
+
*/
|
|
99
|
+
parseResponse(payload, method) {
|
|
100
|
+
if (payload.error) {
|
|
101
|
+
throw new BitcoinRpcError('RPC_ERROR', payload.error.code, payload.error.message, { method });
|
|
102
|
+
}
|
|
103
|
+
return payload.result;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Parse a JSON-RPC batch response payload.
|
|
107
|
+
* Returns results in the same order as the original calls.
|
|
108
|
+
*/
|
|
109
|
+
parseBatchResponse(payloads, calls) {
|
|
110
|
+
const byId = new Map(payloads.map(p => [p.id, p]));
|
|
111
|
+
// Batch responses may arrive out of order; re-sort by sequential id.
|
|
112
|
+
// IDs were assigned as (_id - calls.length + 1) .. _id
|
|
113
|
+
const startId = this._id - calls.length + 1;
|
|
114
|
+
return calls.map((call, i) => {
|
|
115
|
+
const payload = byId.get(startId + i);
|
|
116
|
+
if (!payload) {
|
|
117
|
+
throw new BitcoinRpcError('RPC_ERROR', -1, `Missing response for batch call ${call.method} (id ${startId + i})`, { method: call.method });
|
|
118
|
+
}
|
|
119
|
+
return this.parseResponse(payload, call.method);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Return a copy of the headers with the Authorization value redacted.
|
|
124
|
+
* Use this for logging or debugging.
|
|
125
|
+
*/
|
|
126
|
+
redactedHeaders() {
|
|
127
|
+
const copy = { ...this._headers };
|
|
128
|
+
if (copy.Authorization) {
|
|
129
|
+
copy.Authorization = 'Basic [REDACTED]';
|
|
130
|
+
}
|
|
131
|
+
return copy;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../../src/client/rpc/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;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
4
4
|
export const DEFAULT_BLOCK_CONFIRMATIONS = 7;
|
|
5
5
|
export const TXIN_WITNESS_COINBASE = '0000000000000000000000000000000000000000000000000000000000000000';
|
|
6
6
|
export const GENESIS_TX_ID = '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b';
|
|
7
|
+
/**
|
|
8
|
+
* Default endpoint configuration per Bitcoin network.
|
|
9
|
+
*
|
|
10
|
+
* **Regtest RPC:** Credentials are intentionally omitted — callers must
|
|
11
|
+
* provide `username` and `password` via overrides or explicit config.
|
|
12
|
+
* This prevents accidentally using hardcoded credentials in non-local
|
|
13
|
+
* environments.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Provide credentials explicitly
|
|
18
|
+
* BitcoinConnection.forNetwork('regtest', {
|
|
19
|
+
* rpc: { username: 'polaruser', password: 'polarpass' },
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
7
23
|
export const DEFAULT_BITCOIN_NETWORK_CONFIG = {
|
|
8
24
|
bitcoin: {
|
|
9
25
|
rpc: undefined,
|
|
@@ -27,13 +43,8 @@ export const DEFAULT_BITCOIN_NETWORK_CONFIG = {
|
|
|
27
43
|
},
|
|
28
44
|
regtest: {
|
|
29
45
|
rpc: {
|
|
30
|
-
network: 'regtest',
|
|
31
46
|
host: 'http://localhost:18443',
|
|
32
|
-
port: 18443,
|
|
33
|
-
username: 'polaruser',
|
|
34
|
-
password: 'polarpass',
|
|
35
47
|
allowDefaultWallet: true,
|
|
36
|
-
version: '28.1.0',
|
|
37
48
|
},
|
|
38
49
|
rest: { host: 'http://localhost:3000' }
|
|
39
50
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,gBAAgB,G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AkB,EAAG,IAAI;SAC1B;QACD,IAAI,EAAG,EAAE,IAAI,EAAE,uBAAuB,EAAE;KACzC;CACO,CAAC"}
|
package/dist/esm/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxB,IAAI,CAAe;IACnB,IAAI,CAAS;IACb,IAAI,CAAW;IAC/B,YAAY,IAAkB,EAAE,IAAY,EAAE,OAAe,EAAE,IAAc;QAC3E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzB,IAAI,CAAO;IAC3B,YAAY,OAAe,EAAE,IAAU;QACrC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
1
|
+
// Core
|
|
2
|
+
export { BitcoinConnection } from './bitcoin.js';
|
|
3
|
+
export { defaultHttpExecutor } from './client/http.js';
|
|
4
|
+
export { EsploraProtocol } from './client/rest/protocol.js';
|
|
5
|
+
export { JsonRpcProtocol } from './client/rpc/protocol.js';
|
|
6
|
+
// Clients (convenience wrappers around the protocol layer)
|
|
7
|
+
export { BitcoinRestClient } from './client/rest/index.js';
|
|
8
|
+
export { BitcoinCoreRpcClient } from './client/rpc/index.js';
|
|
9
|
+
// Sub-clients (for direct construction in tests or advanced use)
|
|
10
|
+
export { BitcoinAddress } from './client/rest/address.js';
|
|
11
|
+
export { BitcoinBlock } from './client/rest/block.js';
|
|
12
|
+
export { BitcoinTransaction } from './client/rest/transaction.js';
|
|
13
|
+
export { JsonRpcTransport } from './client/rpc/json-rpc.js';
|
|
14
|
+
// Errors
|
|
15
|
+
export { BitcoinRpcError, BitcoinRestError } from './errors.js';
|
|
16
|
+
// Helpers
|
|
17
|
+
export { getNetwork } from './network.js';
|
|
18
|
+
export { toBase64, safeText } from './client/utils.js';
|
|
19
|
+
// Constants
|
|
20
|
+
export { DEFAULT_BITCOIN_NETWORK_CONFIG, INITIAL_BLOCK_REWARD, HALVING_INTERVAL, COINBASE_MATURITY_DELAY, DEFAULT_BLOCK_CONFIRMATIONS, TXIN_WITNESS_COINBASE, GENESIS_TX_ID, } from './constants.js';
|
|
21
|
+
export { VerbosityLevel } from './types.js';
|
|
14
22
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO;AACP,OAAO,EAAE,iBAAiB,EAAiC,MAAM,cAAc,CAAC;AAIhF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,2DAA2D;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAI7D,iEAAiE;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,SAAS;AACT,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGhE,UAAU;AACV,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEvD,YAAY;AACZ,OAAO,EACL,8BAA8B,EAC9B,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,aAAa,GACd,MAAM,gBAAgB,CAAC;AA0CxB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/esm/types.js
CHANGED
|
@@ -1,69 +1,19 @@
|
|
|
1
1
|
;
|
|
2
|
-
export class RestClientConfig {
|
|
3
|
-
host;
|
|
4
|
-
headers;
|
|
5
|
-
constructor({ host, headers }) {
|
|
6
|
-
this.host = host;
|
|
7
|
-
this.headers = headers;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
;
|
|
11
|
-
export class BitcoinRpcClientConfig {
|
|
12
|
-
network;
|
|
13
|
-
headers;
|
|
14
|
-
host;
|
|
15
|
-
logger;
|
|
16
|
-
password;
|
|
17
|
-
timeout;
|
|
18
|
-
username;
|
|
19
|
-
version;
|
|
20
|
-
wallet;
|
|
21
|
-
allowDefaultWallet;
|
|
22
|
-
constructor(options = {
|
|
23
|
-
headers: {},
|
|
24
|
-
host: 'http://localhost',
|
|
25
|
-
logger: console,
|
|
26
|
-
password: '',
|
|
27
|
-
timeout: 30000,
|
|
28
|
-
username: '',
|
|
29
|
-
version: '0.21.1',
|
|
30
|
-
wallet: '',
|
|
31
|
-
allowDefaultWallet: false,
|
|
32
|
-
}) {
|
|
33
|
-
this.headers = options.headers;
|
|
34
|
-
this.host = options.host;
|
|
35
|
-
this.logger = options.logger;
|
|
36
|
-
this.password = options.password;
|
|
37
|
-
this.timeout = options.timeout;
|
|
38
|
-
this.username = options.username;
|
|
39
|
-
this.version = options.version;
|
|
40
|
-
this.wallet = options.wallet;
|
|
41
|
-
this.allowDefaultWallet = options.allowDefaultWallet;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
2
|
;
|
|
45
3
|
;
|
|
46
4
|
/**
|
|
47
5
|
* Defines verbosity levels for block and transaction outputs.
|
|
48
|
-
*
|
|
49
|
-
* @enum {number} VerbosityLevel for block and transaction outputs.
|
|
6
|
+
* @enum {number}
|
|
50
7
|
*/
|
|
51
8
|
export var VerbosityLevel;
|
|
52
9
|
(function (VerbosityLevel) {
|
|
53
|
-
/** Return
|
|
10
|
+
/** Return data in raw hex-encoded format */
|
|
54
11
|
VerbosityLevel[VerbosityLevel["hex"] = 0] = "hex";
|
|
55
|
-
/** Return
|
|
12
|
+
/** Return data in JSON object format */
|
|
56
13
|
VerbosityLevel[VerbosityLevel["json"] = 1] = "json";
|
|
57
|
-
/**
|
|
58
|
-
* Return block or transaction data in JSON object format with additional information.
|
|
59
|
-
* Returns block data with information about each transaction.
|
|
60
|
-
* Returns transaction data with information about the transaction including fee and prevout information.
|
|
61
|
-
*/
|
|
14
|
+
/** Return data in JSON format with additional information */
|
|
62
15
|
VerbosityLevel[VerbosityLevel["jsonext"] = 2] = "jsonext";
|
|
63
|
-
/**
|
|
64
|
-
* Return block data in JSON object format with additional information.
|
|
65
|
-
* Returns block data with information about each transaction, including prevout information for inputs.
|
|
66
|
-
*/
|
|
16
|
+
/** Return block data in JSON format with prevout information for inputs */
|
|
67
17
|
VerbosityLevel[VerbosityLevel["jsonextprev"] = 3] = "jsonextprev";
|
|
68
18
|
})(VerbosityLevel || (VerbosityLevel = {}));
|
|
69
19
|
//# sourceMappingURL=types.js.map
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AA6BC,CAAC;AA+ND,CAAC;AAKD,CAAC;AA4FF;;;GAGG;AACH,MAAM,CAAN,IAAY,cASX;AATD,WAAY,cAAc;IACxB,4CAA4C;IAC5C,iDAAO,CAAA;IACP,wCAAwC;IACxC,mDAAQ,CAAA;IACR,6DAA6D;IAC7D,yDAAW,CAAA;IACX,2EAA2E;IAC3E,iEAAe,CAAA;AACjB,CAAC,EATW,cAAc,KAAd,cAAc,QASzB"}
|
package/dist/types/bitcoin.d.ts
CHANGED
|
@@ -1,60 +1,81 @@
|
|
|
1
1
|
import { networks } from 'bitcoinjs-lib';
|
|
2
|
+
import { HttpExecutor } from './client/http.js';
|
|
2
3
|
import { BitcoinRestClient } from './client/rest/index.js';
|
|
3
4
|
import { BitcoinCoreRpcClient } from './client/rpc/index.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
import { NetworkName, RestConfig, RpcConfig } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Options for creating a BitcoinConnection.
|
|
8
|
+
*/
|
|
9
|
+
export type BitcoinConnectionOptions = {
|
|
10
|
+
network: NetworkName;
|
|
11
|
+
rest: RestConfig;
|
|
12
|
+
rpc?: RpcConfig;
|
|
13
|
+
/** Optional HTTP executor for sans-I/O usage. Defaults to global `fetch`. */
|
|
14
|
+
executor?: HttpExecutor;
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* Represents a connection to a single Bitcoin network.
|
|
18
|
+
* Holds the REST and optional RPC clients for that network.
|
|
19
|
+
*
|
|
20
|
+
* The underlying clients use a sans-I/O protocol layer that separates
|
|
21
|
+
* request construction from HTTP execution. By default, requests are
|
|
22
|
+
* executed via the global `fetch` function. Supply a custom
|
|
23
|
+
* {@link HttpExecutor} to use any HTTP client.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* // Quick setup with defaults (uses fetch)
|
|
28
|
+
* const btc = BitcoinConnection.forNetwork('regtest');
|
|
29
|
+
*
|
|
30
|
+
* // With a custom HTTP executor
|
|
31
|
+
* const btc = BitcoinConnection.forNetwork('testnet4', {
|
|
32
|
+
* rest: { host: 'https://my-mempool/api' },
|
|
33
|
+
* executor: myCustomExecutor,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Direct usage
|
|
37
|
+
* const tx = await btc.rest.transaction.get(txid);
|
|
38
|
+
* const block = await btc.rpc?.getBlock({ height: 100 });
|
|
39
|
+
*
|
|
40
|
+
* // Sans-I/O: build requests without performing I/O
|
|
41
|
+
* const req = btc.rest.protocol.getTx(txid);
|
|
42
|
+
* const res = await myHttpClient.execute(req);
|
|
43
|
+
* ```
|
|
19
44
|
*/
|
|
20
|
-
export declare class
|
|
21
|
-
network
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* @param {BitcoinNetworkConfigMap} configs Optional configuration object for the Bitcoin client. If not provided, it will
|
|
31
|
-
* be loaded from the BITCOIN_CLIENT_CONFIG environment variables.
|
|
32
|
-
* @throws {MethodError} If no configs is passed and BITCOIN_NETWORK_CONFIG is missing or invalid.
|
|
33
|
-
*/
|
|
34
|
-
constructor(configs?: BitcoinNetworkConfigMap);
|
|
35
|
-
/**
|
|
36
|
-
* Get the Bitcoin network configuration for a specific network.
|
|
37
|
-
* @param {keyof AvailableNetworks} network - The Bitcoin network (e.g., 'bitcoin', 'testnet3', 'signet', 'regtest').
|
|
38
|
-
* @returns {Bitcoin} The Bitcoin object.
|
|
39
|
-
*/
|
|
40
|
-
getNetworkConnection(network: string): BitcoinNetworkConnection;
|
|
45
|
+
export declare class BitcoinConnection {
|
|
46
|
+
/** The network this connection targets. */
|
|
47
|
+
readonly name: NetworkName;
|
|
48
|
+
/** REST client (Esplora API). */
|
|
49
|
+
readonly rest: BitcoinRestClient;
|
|
50
|
+
/** RPC client (Bitcoin Core). May be undefined if not configured. */
|
|
51
|
+
readonly rpc?: BitcoinCoreRpcClient;
|
|
52
|
+
/** bitcoinjs-lib network data (for address derivation, PSBT signing, etc.). */
|
|
53
|
+
readonly data: networks.Network;
|
|
54
|
+
constructor(options: BitcoinConnectionOptions);
|
|
41
55
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
56
|
+
* Create a connection for a single network with optional REST/RPC endpoint overrides.
|
|
57
|
+
* Merges overrides on top of defaults from DEFAULT_BITCOIN_NETWORK_CONFIG.
|
|
58
|
+
* Does not read environment variables.
|
|
59
|
+
*
|
|
60
|
+
* @param network The network name (e.g., 'regtest', 'testnet4', 'bitcoin').
|
|
61
|
+
* @param overrides Optional endpoint and executor overrides.
|
|
62
|
+
* @returns A BitcoinConnection for the requested network.
|
|
45
63
|
*/
|
|
46
|
-
|
|
64
|
+
static forNetwork(network: NetworkName, overrides?: {
|
|
65
|
+
rest?: Partial<RestConfig>;
|
|
66
|
+
rpc?: RpcConfig;
|
|
67
|
+
executor?: HttpExecutor;
|
|
68
|
+
}): BitcoinConnection;
|
|
47
69
|
/**
|
|
48
|
-
* Converts Bitcoin (BTC) to satoshis
|
|
49
|
-
*
|
|
50
|
-
* @
|
|
70
|
+
* Converts Bitcoin (BTC) to satoshis.
|
|
71
|
+
* Uses string-based arithmetic to avoid floating-point precision errors.
|
|
72
|
+
* @throws {RangeError} If the value has more than 8 decimal places.
|
|
51
73
|
*/
|
|
52
74
|
static btcToSats(btc: number): number;
|
|
53
75
|
/**
|
|
54
|
-
* Converts satoshis
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
76
|
+
* Converts satoshis to Bitcoin (BTC).
|
|
77
|
+
* Uses string-based arithmetic to avoid floating-point precision errors.
|
|
78
|
+
* @param sats Must be a non-negative integer.
|
|
57
79
|
*/
|
|
58
80
|
static satsToBtc(sats: number): number;
|
|
59
81
|
}
|
|
60
|
-
export declare const bitcoin: BitcoinNetworkConnection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin.d.ts","sourceRoot":"","sources":["../../src/bitcoin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"bitcoin.d.ts","sourceRoot":"","sources":["../../src/bitcoin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGhE;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,iBAAiB;IAC5B,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAE3B,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAEjC,qEAAqE;IACrE,QAAQ,CAAC,GAAG,CAAC,EAAE,oBAAoB,CAAC;IAEpC,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC;gBAEpB,OAAO,EAAE,wBAAwB;IAO7C;;;;;;;;OAQG;IACH,MAAM,CAAC,UAAU,CACf,OAAO,EAAE,WAAW,EACpB,SAAS,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAAC,GAAG,CAAC,EAAE,SAAS,CAAC;QAAC,QAAQ,CAAC,EAAE,YAAY,CAAA;KAAE,GACnF,iBAAiB;IA0BpB;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAUrC;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAQvC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP request descriptor. Represents a request that can be executed
|
|
3
|
+
* by any HTTP client — the library never performs I/O itself at the
|
|
4
|
+
* protocol layer.
|
|
5
|
+
*/
|
|
6
|
+
export interface HttpRequest {
|
|
7
|
+
url: string;
|
|
8
|
+
method: 'GET' | 'POST';
|
|
9
|
+
headers: Record<string, string>;
|
|
10
|
+
body?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A function that executes an {@link HttpRequest} and returns a standard
|
|
14
|
+
* {@link Response}. Users can supply their own implementation to use
|
|
15
|
+
* any HTTP client (e.g. `undici`, `axios`, a caching proxy, etc.).
|
|
16
|
+
*/
|
|
17
|
+
export type HttpExecutor = (request: HttpRequest) => Promise<Response>;
|
|
18
|
+
/**
|
|
19
|
+
* Default executor backed by the global `fetch` function.
|
|
20
|
+
*/
|
|
21
|
+
export declare const defaultHttpExecutor: HttpExecutor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/client/http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvE;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAK9B,CAAC"}
|