@did-btcr2/bitcoin 0.3.4 → 0.5.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.
Files changed (113) hide show
  1. package/dist/cjs/client/http.js +9 -0
  2. package/dist/cjs/client/http.js.map +1 -0
  3. package/dist/cjs/client/rest/address.js +20 -28
  4. package/dist/cjs/client/rest/address.js.map +1 -1
  5. package/dist/cjs/client/rest/block.js +23 -22
  6. package/dist/cjs/client/rest/block.js.map +1 -1
  7. package/dist/cjs/client/rest/index.js +31 -84
  8. package/dist/cjs/client/rest/index.js.map +1 -1
  9. package/dist/cjs/client/rest/protocol.js +129 -0
  10. package/dist/cjs/client/rest/protocol.js.map +1 -0
  11. package/dist/cjs/client/rest/transaction.js +19 -21
  12. package/dist/cjs/client/rest/transaction.js.map +1 -1
  13. package/dist/cjs/client/rpc/index.js +79 -337
  14. package/dist/cjs/client/rpc/index.js.map +1 -1
  15. package/dist/cjs/client/rpc/interface.js +1 -6
  16. package/dist/cjs/client/rpc/interface.js.map +1 -1
  17. package/dist/cjs/client/rpc/json-rpc.js +40 -63
  18. package/dist/cjs/client/rpc/json-rpc.js.map +1 -1
  19. package/dist/cjs/client/rpc/protocol.js +134 -0
  20. package/dist/cjs/client/rpc/protocol.js.map +1 -0
  21. package/dist/cjs/connection.js +104 -0
  22. package/dist/cjs/connection.js.map +1 -0
  23. package/dist/cjs/constants.js +16 -5
  24. package/dist/cjs/constants.js.map +1 -1
  25. package/dist/cjs/errors.js.map +1 -1
  26. package/dist/cjs/index.js +21 -13
  27. package/dist/cjs/index.js.map +1 -1
  28. package/dist/cjs/types.js +5 -55
  29. package/dist/cjs/types.js.map +1 -1
  30. package/dist/esm/client/http.js +9 -0
  31. package/dist/esm/client/http.js.map +1 -0
  32. package/dist/esm/client/rest/address.js +20 -28
  33. package/dist/esm/client/rest/address.js.map +1 -1
  34. package/dist/esm/client/rest/block.js +23 -22
  35. package/dist/esm/client/rest/block.js.map +1 -1
  36. package/dist/esm/client/rest/index.js +31 -84
  37. package/dist/esm/client/rest/index.js.map +1 -1
  38. package/dist/esm/client/rest/protocol.js +129 -0
  39. package/dist/esm/client/rest/protocol.js.map +1 -0
  40. package/dist/esm/client/rest/transaction.js +19 -21
  41. package/dist/esm/client/rest/transaction.js.map +1 -1
  42. package/dist/esm/client/rpc/index.js +79 -337
  43. package/dist/esm/client/rpc/index.js.map +1 -1
  44. package/dist/esm/client/rpc/interface.js +1 -6
  45. package/dist/esm/client/rpc/interface.js.map +1 -1
  46. package/dist/esm/client/rpc/json-rpc.js +40 -63
  47. package/dist/esm/client/rpc/json-rpc.js.map +1 -1
  48. package/dist/esm/client/rpc/protocol.js +134 -0
  49. package/dist/esm/client/rpc/protocol.js.map +1 -0
  50. package/dist/esm/connection.js +104 -0
  51. package/dist/esm/connection.js.map +1 -0
  52. package/dist/esm/constants.js +16 -5
  53. package/dist/esm/constants.js.map +1 -1
  54. package/dist/esm/errors.js.map +1 -1
  55. package/dist/esm/index.js +21 -13
  56. package/dist/esm/index.js.map +1 -1
  57. package/dist/esm/types.js +5 -55
  58. package/dist/esm/types.js.map +1 -1
  59. package/dist/types/client/http.d.ts +22 -0
  60. package/dist/types/client/http.d.ts.map +1 -0
  61. package/dist/types/client/rest/address.d.ts +17 -19
  62. package/dist/types/client/rest/address.d.ts.map +1 -1
  63. package/dist/types/client/rest/block.d.ts +25 -16
  64. package/dist/types/client/rest/block.d.ts.map +1 -1
  65. package/dist/types/client/rest/index.d.ts +21 -51
  66. package/dist/types/client/rest/index.d.ts.map +1 -1
  67. package/dist/types/client/rest/protocol.d.ts +59 -0
  68. package/dist/types/client/rest/protocol.d.ts.map +1 -0
  69. package/dist/types/client/rest/transaction.d.ts +17 -17
  70. package/dist/types/client/rest/transaction.d.ts.map +1 -1
  71. package/dist/types/client/rpc/index.d.ts +112 -253
  72. package/dist/types/client/rpc/index.d.ts.map +1 -1
  73. package/dist/types/client/rpc/interface.d.ts +42 -6
  74. package/dist/types/client/rpc/interface.d.ts.map +1 -1
  75. package/dist/types/client/rpc/json-rpc.d.ts +21 -18
  76. package/dist/types/client/rpc/json-rpc.d.ts.map +1 -1
  77. package/dist/types/client/rpc/protocol.d.ts +83 -0
  78. package/dist/types/client/rpc/protocol.d.ts.map +1 -0
  79. package/dist/types/client/utils.d.ts +1 -0
  80. package/dist/types/connection.d.ts +82 -0
  81. package/dist/types/connection.d.ts.map +1 -0
  82. package/dist/types/constants.d.ts +17 -5
  83. package/dist/types/constants.d.ts.map +1 -1
  84. package/dist/types/errors.d.ts +5 -3
  85. package/dist/types/errors.d.ts.map +1 -1
  86. package/dist/types/index.d.ts +21 -13
  87. package/dist/types/index.d.ts.map +1 -1
  88. package/dist/types/network.d.ts +1 -0
  89. package/dist/types/types.d.ts +99 -696
  90. package/dist/types/types.d.ts.map +1 -1
  91. package/package.json +3 -3
  92. package/src/client/http.ts +28 -0
  93. package/src/client/rest/address.ts +24 -30
  94. package/src/client/rest/block.ts +29 -26
  95. package/src/client/rest/index.ts +38 -94
  96. package/src/client/rest/protocol.ts +153 -0
  97. package/src/client/rest/transaction.ts +23 -23
  98. package/src/client/rpc/index.ts +146 -379
  99. package/src/client/rpc/interface.ts +88 -53
  100. package/src/client/rpc/json-rpc.ts +53 -60
  101. package/src/client/rpc/protocol.ts +160 -0
  102. package/src/connection.ts +136 -0
  103. package/src/constants.ts +17 -5
  104. package/src/errors.ts +10 -3
  105. package/src/index.ts +81 -13
  106. package/src/types.ts +332 -972
  107. package/dist/cjs/bitcoin.js +0 -105
  108. package/dist/cjs/bitcoin.js.map +0 -1
  109. package/dist/esm/bitcoin.js +0 -105
  110. package/dist/esm/bitcoin.js.map +0 -1
  111. package/dist/types/bitcoin.d.ts +0 -60
  112. package/dist/types/bitcoin.d.ts.map +0 -1
  113. package/src/bitcoin.ts +0 -149
@@ -1,56 +1,54 @@
1
- import { AddressInfo, AddressUtxo, RawTransactionRest, RestApiCallParams } from '../../types.js';
1
+ import { AddressInfo, AddressUtxo, RawTransactionRest } from '../../types.js';
2
+ import { HttpRequest } from '../http.js';
3
+ import { EsploraProtocol } from './protocol.js';
2
4
  /**
3
- * Implements a strongly-typed BitcoinRest to connect to remote bitcoin node via REST API for address-related operations.
4
- * @class BitcoinAddress
5
- * @type {BitcoinAddress}
5
+ * Address-related Esplora REST API operations.
6
6
  */
7
7
  export declare class BitcoinAddress {
8
- private api;
9
- constructor(api: (params: RestApiCallParams) => Promise<any>);
8
+ private readonly protocol;
9
+ private readonly exec;
10
+ constructor(protocol: EsploraProtocol, exec: (req: HttpRequest) => Promise<any>);
10
11
  /**
11
12
  * Get transaction history for the specified address/scripthash, sorted with newest first.
12
13
  * Returns up to 50 mempool transactions plus the first 25 confirmed transactions.
13
14
  * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-addressaddresstxs | Esplora GET /address/:address/txs } for details.
14
15
  * @param {string} addressOrScripthash The address or scripthash to check.
15
- * @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
16
+ * @returns {Promise<Array<RawTransactionRest>>} Transaction history.
16
17
  */
17
18
  getTxs(addressOrScripthash: string): Promise<Array<RawTransactionRest>>;
18
19
  /**
19
- * Calls getAddressTxs and checks if any funds come back.
20
- * Toggle if those funds are confirmed.
20
+ * Checks if an address has any confirmed funded transactions.
21
21
  * @param {string} addressOrScripthash The address or scripthash to check.
22
- * @returns {Promise<boolean>} True if the address has any funds, false otherwise.
22
+ * @returns {Promise<boolean>} True if the address has confirmed funds.
23
23
  */
24
24
  isFundedAddress(addressOrScripthash: string): Promise<boolean>;
25
25
  /**
26
26
  * Get unconfirmed transaction history for the specified address/scripthash.
27
27
  * Returns up to 50 transactions (no paging).
28
28
  * @param {string} addressOrScripthash The address or scripthash to check.
29
- * @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
29
+ * @returns {Promise<Array<RawTransactionRest>>} Unconfirmed transactions.
30
30
  */
31
31
  getTxsMempool(addressOrScripthash: string): Promise<Array<RawTransactionRest>>;
32
32
  /**
33
33
  * Get information about an address/scripthash.
34
- * Available fields: address/scripthash, chain_stats and mempool_stats.
35
- * {chain,mempool}_stats each contain an object with tx_count, funded_txo_count, funded_txo_sum, spent_txo_count and spent_txo_sum.
36
- * Elements-based chains don't have the {funded,spent}_txo_sum fields.
37
34
  * @param {string} addressOrScripthash The address or scripthash to check.
38
- * @returns {Promise<AddressInfo>} A promise resolving to an {@link AddressInfo} object.
35
+ * @returns {Promise<AddressInfo>} Address information.
39
36
  */
40
37
  getInfo(addressOrScripthash: string): Promise<AddressInfo>;
41
38
  /**
42
39
  * Get confirmed transaction history for the specified address/scripthash, sorted with newest first.
43
- * Returns 25 transactions per page. More can be requested by specifying the last txid seen by the previous query.
40
+ * Returns 25 transactions per page.
44
41
  * @param {string} addressOrScripthash The address or scripthash to check.
45
- * @param lastSeenTxId The last transaction id seen by the previous query (optional).
46
- * @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
42
+ * @param {string} [lastSeenTxId] The last transaction id seen by the previous query for pagination.
43
+ * @returns {Promise<Array<RawTransactionRest>>} Confirmed transactions.
47
44
  */
48
45
  getConfirmedTxs(addressOrScripthash: string, lastSeenTxId?: string): Promise<Array<RawTransactionRest>>;
49
46
  /**
50
47
  * Get the list of unspent transaction outputs associated with the address/scripthash.
51
48
  * See {@link https://github.com/Blockstream/esplora/blob/master/API.md#get-addressaddressutxo | Esplora GET /address/:address/utxo } for details.
52
49
  * @param {string} addressOrScripthash The address or scripthash to check.
53
- * @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
50
+ * @returns {Promise<Array<AddressUtxo>>} Unspent transaction outputs.
54
51
  */
55
52
  getUtxos(addressOrScripthash: string): Promise<Array<AddressUtxo>>;
56
53
  }
54
+ //# sourceMappingURL=address.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../../src/client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OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqC;gBAE9C,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,GAAG,CAAC;IAK/E;;;;;;OAMG;IACU,MAAM,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAIpF;;;;OAIG;IACU,eAAe,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM3E;;;;;OAKG;IACU,aAAa,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAI3F;;;;OAIG;IACU,OAAO,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAIvE;;;;;;OAMG;IACU,eAAe,CAAC,mBAAmB,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAIpH;;;;;OAKG;IACU,QAAQ,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;CAGhF"}
@@ -1,31 +1,40 @@
1
- import { RestApiCallParams, BlockResponse, GetBlockParams } from '../../types.js';
1
+ import { EsploraBlock } from '../../types.js';
2
+ import { HttpRequest } from '../http.js';
3
+ import { EsploraProtocol } from './protocol.js';
2
4
  /**
3
- * Implements a strongly-typed BitcoinRest to connect to remote bitcoin node via REST API for block-related operations.
4
- * @class BitcoinBlock
5
- * @type {BitcoinBlock}
5
+ * Block-related Esplora REST API operations.
6
+ *
7
+ * Note: The Esplora API always returns the same block format regardless
8
+ * of any "verbosity" setting (unlike Bitcoin Core RPC). Use the RPC
9
+ * client if you need verbosity-controlled block responses.
6
10
  */
7
11
  export declare class BitcoinBlock {
8
- private api;
9
- constructor(api: (params: RestApiCallParams) => Promise<any>);
12
+ private readonly protocol;
13
+ private readonly exec;
14
+ constructor(protocol: EsploraProtocol, exec: (req: HttpRequest) => Promise<any>);
10
15
  /**
11
- * Returns the blockheight of the most-work fully-validated chain. The genesis block has height 0.
12
- * @returns {Blockheight} The number of the blockheight with the most-work of the fully-validated chain.
16
+ * Returns the blockheight of the most-work fully-validated chain.
17
+ * @returns {Promise<number>} The current block height.
13
18
  */
14
19
  count(): Promise<number>;
15
20
  /**
16
- * Returns the block data associated with a `blockhash` of a valid block.
17
- * @param {GetBlockParams} params See {@link GetBlockParams} for details.
18
- * @param {?string} params.blockhash The blockhash of the block to query.
19
- * @param {?number} params.height The block height of the block to query.
20
- * @returns {BlockResponse} A promise resolving to a {@link BlockResponse} formatted depending on `verbosity` level.
21
- * @throws {BitcoinRpcError} If neither `blockhash` nor `height` is provided.
21
+ * Returns the Esplora block data for a given blockhash or height.
22
+ * @param {object} params The block hash or height.
23
+ * @param {string} [params.blockhash] The blockhash of the block to query.
24
+ * @param {number} [params.height] The block height of the block to query.
25
+ * @returns {Promise<EsploraBlock | undefined>} The block data.
26
+ * @throws {BitcoinRestError} If neither blockhash nor height is provided.
22
27
  */
23
- get({ blockhash, height }: GetBlockParams): Promise<BlockResponse | undefined>;
28
+ get({ blockhash, height }: {
29
+ blockhash?: string;
30
+ height?: number;
31
+ }): Promise<EsploraBlock | undefined>;
24
32
  /**
25
33
  * Get the block hash for a given block height.
26
34
  * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-block-heightheight | Esplora GET /block-height/:height } for details.
27
35
  * @param {number} height The block height (required).
28
- * @returns {Promise<string>} The hash of the block currently at height..
36
+ * @returns {Promise<string>} The hash of the block at the given height.
29
37
  */
30
38
  getHash(height: number): Promise<string>;
31
39
  }
40
+ //# sourceMappingURL=block.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/client/rest/block.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,aAAa,EA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;CAGtD"}
@@ -1,66 +1,36 @@
1
1
  import { BitcoinAddress } from './address.js';
2
2
  import { BitcoinBlock } from './block.js';
3
3
  import { BitcoinTransaction } from './transaction.js';
4
- import { RestClientConfig, RestApiCallParams } from '../../types.js';
4
+ import { EsploraProtocol } from './protocol.js';
5
+ import { RestConfig } from '../../types.js';
6
+ import { HttpExecutor } from '../http.js';
5
7
  /**
6
- * Implements a strongly-typed BitcoinRestClient to connect to remote bitcoin node via REST API.
7
- * @class BitcoinRestClient
8
- * @type {BitcoinRestClient}
8
+ * Esplora REST API client for Bitcoin.
9
+ *
10
+ * Wraps the sans-I/O {@link EsploraProtocol} with an {@link HttpExecutor}
11
+ * for convenience. Users who want full control over I/O can access the
12
+ * protocol layer directly via the {@link protocol} property.
9
13
  */
10
14
  export declare class BitcoinRestClient {
11
- /**
12
- * The encapsulated {@link RestClientConfig} object.
13
- * @private
14
- * @type {RestClientConfig}
15
- */
16
15
  private _config;
17
16
  /**
18
- * The api calls related to bitcoin transactions.
19
- * @type {BitcoinTransaction}
17
+ * The sans-I/O protocol layer. Use this to build {@link HttpRequest}
18
+ * descriptors without performing any I/O.
20
19
  */
20
+ readonly protocol: EsploraProtocol;
21
+ private readonly executor;
22
+ /** Transaction-related API calls. */
21
23
  transaction: BitcoinTransaction;
22
- /**
23
- * The api calls related to bitcoin blocks.
24
- * @type {BitcoinBlock}
25
- */
24
+ /** Block-related API calls. */
26
25
  block: BitcoinBlock;
27
- /**
28
- * The api calls related to bitcoin addresses.
29
- * @type {BitcoinAddress}
30
- */
26
+ /** Address-related API calls. */
31
27
  address: BitcoinAddress;
28
+ constructor(config: RestConfig, executor?: HttpExecutor);
29
+ get config(): RestConfig;
32
30
  /**
33
- * The API call method that can be used to make requests to the REST API.
34
- * @returns {Promise<any>} A promise resolving to the response data.
35
- */
36
- api: (params: RestApiCallParams) => Promise<any>;
37
- constructor(config: RestClientConfig);
38
- /**
39
- * Get the configuration object.
40
- * @private
41
- */
42
- get config(): RestClientConfig;
43
- /**
44
- * Static method connects to a bitcoin node running a esplora REST API.
45
- *
46
- * @param {RestClientConfig} config The configuration object for the client (optional).
47
- * @returns {BitcoinRestClient} A new {@link BitcoinRestClient} instance.
48
- * @example
49
- * ```
50
- * const rest = BitcoinRestClient.connect();
51
- * ```
52
- */
53
- static connect(config?: RestClientConfig): BitcoinRestClient;
54
- /**
55
- * Make a REST API call to the configured Bitcoin node.
56
- * @private
57
- * @param {RestApiCallParams} params The parameters for the API call. See {@link RestApiCallParams} for details.
58
- * @param {string} [params.path] The path to the API endpoint (required).
59
- * @param {string} [params.url] The full URL to the API endpoint (optional).
60
- * @param {string} [params.method] The HTTP method to use (default is 'GET').
61
- * @param {any} [params.body] The body of the request (optional).
62
- * @param {any} [params.headers] Additional headers to include in the request (optional).
63
- * @returns {Promise<any>} A promise resolving to the response data.
31
+ * Execute an {@link HttpRequest} built by the protocol layer,
32
+ * parse the response, and throw on HTTP errors.
64
33
  */
65
- private call;
34
+ private executeRequest;
66
35
  }
36
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/rest/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAgB,MAAM,gBAAgB,CAAC;AAGnF;;;;GAIG;AACH,qBAAa,iBAAiB;IAC5B;;;;OAIG;IACH,OAAO,CAAC,OAAO,CAAmB;IAElC;;;OAGG;IACI,WAAW,EAAE,kBAAkB,CAAC;IAEvC;;;OAGG;IACI,KAAK,EAAE,YAAY,CAAC;IAE3B;;;OAGG;IACI,OAAO,EAAE,cAAc,CAAC;IAE/B;;;OAGG;IACI,GAAG,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,GAAG,CAAC,CAAa;gBAExD,MAAM,EAAE,gBAAgB;IAQpC;;;OAGG;IACH,IAAI,MAAM,IAAI,gBAAgB,CAG7B;IAED;;;;;;;;;OASG;WACW,OAAO,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,iBAAiB;IAInE;;;;;;;;;;OAUG;YACW,IAAI;CAyCnB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/rest/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAoC,MAAM,YAAY,CAAC;AAE5E;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAa;IAE5B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IAEnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IAExC,qCAAqC;IAC9B,WAAW,EAAE,kBAAkB,CAAC;IAEvC,+BAA+B;IACxB,KAAK,EAAE,YAAY,CAAC;IAE3B,iCAAiC;IAC1B,OAAO,EAAE,cAAc,CAAC;gBAEnB,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,YAAY;IAWvD,IAAI,MAAM,IAAI,UAAU,CAEvB;IAED;;;OAGG;YACW,cAAc;CAkB7B"}
@@ -0,0 +1,59 @@
1
+ import { RestConfig } from '../../types.js';
2
+ import { HttpRequest } from '../http.js';
3
+ /**
4
+ * Sans-I/O Esplora REST API protocol.
5
+ *
6
+ * Every method returns an {@link HttpRequest} descriptor — a plain object
7
+ * describing *what* to request — without performing any I/O. The caller
8
+ * is responsible for executing the request with an HTTP client of their
9
+ * choice and deserializing the response.
10
+ *
11
+ * This mirrors the pattern used by the Rust `esploda` crate where
12
+ * `Esplora` methods return `http::Request<()>` objects.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const protocol = new EsploraProtocol({ host: 'https://mempool.space/api' });
17
+ *
18
+ * // Build a request descriptor (no I/O)
19
+ * const req = protocol.getTx('abc123...');
20
+ *
21
+ * // Execute with any HTTP client
22
+ * const res = await fetch(req.url, req);
23
+ * const tx: RawTransactionRest = await res.json();
24
+ * ```
25
+ */
26
+ export declare class EsploraProtocol {
27
+ private readonly baseUrl;
28
+ private readonly defaultHeaders;
29
+ constructor(config: RestConfig);
30
+ private static assertHex64;
31
+ private static assertAddress;
32
+ private get;
33
+ private post;
34
+ /** GET /tx/:txid */
35
+ getTx(txid: string): HttpRequest;
36
+ /** GET /tx/:txid/hex */
37
+ getTxHex(txid: string): HttpRequest;
38
+ /** GET /tx/:txid/raw */
39
+ getTxRaw(txid: string): HttpRequest;
40
+ /** POST /tx */
41
+ postTx(hex: string): HttpRequest;
42
+ /** GET /blocks/tip/height */
43
+ getBlockTipHeight(): HttpRequest;
44
+ /** GET /block/:blockhash */
45
+ getBlock(blockhash: string): HttpRequest;
46
+ /** GET /block-height/:height */
47
+ getBlockHeight(height: number): HttpRequest;
48
+ /** GET /address/:address/txs */
49
+ getAddressTxs(address: string): HttpRequest;
50
+ /** GET /address/:address/txs/mempool */
51
+ getAddressTxsMempool(address: string): HttpRequest;
52
+ /** GET /address/:address/txs/chain[/:last_seen_txid] */
53
+ getAddressTxsChain(address: string, lastSeenTxId?: string): HttpRequest;
54
+ /** GET /address/:address */
55
+ getAddressInfo(address: string): HttpRequest;
56
+ /** GET /address/:address/utxo */
57
+ getAddressUtxos(address: string): HttpRequest;
58
+ }
59
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":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44 +1,44 @@
1
1
  import { Bytes } from '@did-btcr2/common';
2
- import { RawTransactionRest, RestApiCallParams } from '../../types.js';
2
+ import { RawTransactionRest } from '../../types.js';
3
+ import { HttpRequest } from '../http.js';
4
+ import { EsploraProtocol } from './protocol.js';
3
5
  export declare class BitcoinTransaction {
4
- private api;
5
- constructor(api: (params: RestApiCallParams) => Promise<any>);
6
+ private readonly protocol;
7
+ private readonly exec;
8
+ constructor(protocol: EsploraProtocol, exec: (req: HttpRequest) => Promise<any>);
6
9
  /**
7
10
  * Returns the transaction in JSON format.
8
11
  * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxid | Esplora GET /tx/:txid } for details.
9
12
  * @param {string} txid The transaction id (required).
10
- * @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
13
+ * @returns {Promise<RawTransactionRest>} A promise resolving to data about a transaction.
11
14
  */
12
15
  get(txid: string): Promise<RawTransactionRest>;
13
16
  /**
14
- * Returns the transaction in JSON format.
15
- * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxid | Esplora GET /tx/:txid } for details.
17
+ * Checks if a transaction is confirmed.
16
18
  * @param {string} txid The transaction id (required).
17
- * @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
19
+ * @returns {Promise<boolean>} True if the transaction is confirmed.
18
20
  */
19
21
  isConfirmed(txid: string): Promise<boolean>;
20
22
  /**
21
- * Returns the raw transaction in hex or as binary data.
22
- * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidhex | Esplora GET /tx/:txid/hex } and
23
- * {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidraw | Esplora GET /tx/:txid/raw } for details.
23
+ * Returns the raw transaction as a hex string.
24
+ * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidhex | Esplora GET /tx/:txid/hex } for details.
24
25
  * @param {string} txid The transaction id (required).
25
- * @returns {Promise<RawTransactionRest | string>} A promise resolving to the raw transaction in the specified format.
26
+ * @returns {Promise<string>} A promise resolving to the raw transaction hex.
26
27
  */
27
28
  getHex(txid: string): Promise<string>;
28
29
  /**
29
- * Returns the raw transaction in hex or as binary data.
30
- * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidhex | Esplora GET /tx/:txid/hex } and
31
- * {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidraw | Esplora GET /tx/:txid/raw } for details.
30
+ * Returns the raw transaction as binary data.
31
+ * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidraw | Esplora GET /tx/:txid/raw } for details.
32
32
  * @param {string} txid The transaction id (required).
33
- * @returns {Promise<RawTransactionRest | string>} A promise resolving to the raw transaction in the specified format.
33
+ * @returns {Promise<Bytes>} A promise resolving to the raw transaction bytes.
34
34
  */
35
35
  getRaw(txid: string): Promise<Bytes>;
36
36
  /**
37
- * Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The txid
38
- * will be returned on success.
37
+ * Broadcast a raw transaction to the network.
39
38
  * See {@link https://github.com/blockstream/esplora/blob/master/API.md#post-tx | Esplora POST /tx } for details.
40
39
  * @param {string} tx The raw transaction in hex format (required).
41
40
  * @returns {Promise<string>} The transaction id of the broadcasted transaction.
42
41
  */
43
42
  send(tx: string): Promise<string>;
44
43
  }
44
+ //# sourceMappingURL=transaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../../src/client/rest/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEvE,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,GAAG,CAA8C;gBAE7C,GAAG,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,GAAG,CAAC;IAI5D;;;;;OAKG;IACU,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAA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