@did-btcr2/bitcoin 0.1.2 → 0.2.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 (135) hide show
  1. package/dist/cjs/{bitcoin.browser.js → bitcoin.js} +39 -16
  2. package/dist/cjs/bitcoin.js.map +1 -0
  3. package/dist/cjs/client/rest/address.js +76 -0
  4. package/dist/cjs/client/rest/address.js.map +1 -0
  5. package/dist/cjs/client/rest/block.js +50 -0
  6. package/dist/cjs/client/rest/block.js.map +1 -0
  7. package/dist/cjs/client/rest/index.js +118 -0
  8. package/dist/cjs/client/rest/index.js.map +1 -0
  9. package/dist/cjs/client/rest/transaction.js +56 -0
  10. package/dist/cjs/client/rest/transaction.js.map +1 -0
  11. package/dist/cjs/client/rpc/index.js +394 -0
  12. package/dist/cjs/client/rpc/index.js.map +1 -0
  13. package/dist/cjs/client/rpc/interface.js.map +1 -0
  14. package/dist/cjs/client/rpc/json-rpc.js +78 -0
  15. package/dist/cjs/client/rpc/json-rpc.js.map +1 -0
  16. package/dist/cjs/client/utils.js +28 -0
  17. package/dist/cjs/client/utils.js.map +1 -0
  18. package/dist/cjs/constants.js +34 -13
  19. package/dist/cjs/constants.js.map +1 -1
  20. package/dist/cjs/errors.js +8 -0
  21. package/dist/cjs/errors.js.map +1 -1
  22. package/dist/cjs/index.js +15 -0
  23. package/dist/cjs/index.js.map +1 -0
  24. package/dist/cjs/types.js +2 -2
  25. package/dist/cjs/types.js.map +1 -1
  26. package/dist/esm/{bitcoin.browser.js → bitcoin.js} +39 -16
  27. package/dist/esm/bitcoin.js.map +1 -0
  28. package/dist/esm/client/rest/address.js +76 -0
  29. package/dist/esm/client/rest/address.js.map +1 -0
  30. package/dist/esm/client/rest/block.js +50 -0
  31. package/dist/esm/client/rest/block.js.map +1 -0
  32. package/dist/esm/client/rest/index.js +118 -0
  33. package/dist/esm/client/rest/index.js.map +1 -0
  34. package/dist/esm/client/rest/transaction.js +56 -0
  35. package/dist/esm/client/rest/transaction.js.map +1 -0
  36. package/dist/esm/client/rpc/index.js +394 -0
  37. package/dist/esm/client/rpc/index.js.map +1 -0
  38. package/dist/esm/client/rpc/interface.js.map +1 -0
  39. package/dist/esm/client/rpc/json-rpc.js +78 -0
  40. package/dist/esm/client/rpc/json-rpc.js.map +1 -0
  41. package/dist/esm/client/utils.js +28 -0
  42. package/dist/esm/client/utils.js.map +1 -0
  43. package/dist/esm/constants.js +34 -13
  44. package/dist/esm/constants.js.map +1 -1
  45. package/dist/esm/errors.js +8 -0
  46. package/dist/esm/errors.js.map +1 -1
  47. package/dist/esm/index.js +15 -0
  48. package/dist/esm/index.js.map +1 -0
  49. package/dist/esm/types.js +2 -2
  50. package/dist/esm/types.js.map +1 -1
  51. package/dist/types/{bitcoin.browser.d.ts → bitcoin.d.ts} +23 -8
  52. package/dist/types/bitcoin.d.ts.map +1 -0
  53. package/dist/types/client/rest/address.d.ts +56 -0
  54. package/dist/types/client/rest/address.d.ts.map +1 -0
  55. package/dist/types/client/rest/block.d.ts +32 -0
  56. package/dist/types/client/rest/block.d.ts.map +1 -0
  57. package/dist/types/client/rest/index.d.ts +149 -0
  58. package/dist/types/client/rest/index.d.ts.map +1 -0
  59. package/dist/types/client/rest/transaction.d.ts +44 -0
  60. package/dist/types/client/rest/transaction.d.ts.map +1 -0
  61. package/dist/types/client/rpc/index.d.ts +276 -0
  62. package/dist/types/client/rpc/index.d.ts.map +1 -0
  63. package/dist/types/client/rpc/interface.d.ts +27 -0
  64. package/dist/types/client/rpc/interface.d.ts.map +1 -0
  65. package/dist/types/client/rpc/json-rpc.d.ts +24 -0
  66. package/dist/types/client/rpc/json-rpc.d.ts.map +1 -0
  67. package/dist/types/client/utils.d.ts +12 -0
  68. package/dist/types/client/utils.d.ts.map +1 -0
  69. package/dist/types/constants.d.ts +46 -13
  70. package/dist/types/constants.d.ts.map +1 -1
  71. package/dist/types/errors.d.ts +4 -0
  72. package/dist/types/errors.d.ts.map +1 -1
  73. package/dist/types/index.d.ts +14 -0
  74. package/dist/types/index.d.ts.map +1 -0
  75. package/dist/types/types.d.ts +8 -8
  76. package/dist/types/types.d.ts.map +1 -1
  77. package/package.json +9 -15
  78. package/src/{bitcoin.browser.ts → bitcoin.ts} +48 -16
  79. package/src/client/rest/address.ts +84 -0
  80. package/src/client/rest/block.ts +58 -0
  81. package/src/client/rest/index.ts +217 -0
  82. package/src/client/rest/transaction.ts +64 -0
  83. package/src/client/rpc/index.ts +479 -0
  84. package/src/client/rpc/interface.ts +58 -0
  85. package/src/client/rpc/json-rpc.ts +82 -0
  86. package/src/client/utils.ts +21 -0
  87. package/src/constants.ts +35 -14
  88. package/src/errors.ts +9 -0
  89. package/src/index.ts +14 -0
  90. package/src/types.ts +9 -9
  91. package/dist/cjs/bitcoin.browser.js.map +0 -1
  92. package/dist/cjs/bitcoin.node.js +0 -85
  93. package/dist/cjs/bitcoin.node.js.map +0 -1
  94. package/dist/cjs/index.browser.js +0 -10
  95. package/dist/cjs/index.browser.js.map +0 -1
  96. package/dist/cjs/index.node.js +0 -10
  97. package/dist/cjs/index.node.js.map +0 -1
  98. package/dist/cjs/interface.js.map +0 -1
  99. package/dist/cjs/rest-client.js +0 -294
  100. package/dist/cjs/rest-client.js.map +0 -1
  101. package/dist/cjs/rpc-client.js +0 -722
  102. package/dist/cjs/rpc-client.js.map +0 -1
  103. package/dist/esm/bitcoin.browser.js.map +0 -1
  104. package/dist/esm/bitcoin.node.js +0 -85
  105. package/dist/esm/bitcoin.node.js.map +0 -1
  106. package/dist/esm/index.browser.js +0 -10
  107. package/dist/esm/index.browser.js.map +0 -1
  108. package/dist/esm/index.node.js +0 -10
  109. package/dist/esm/index.node.js.map +0 -1
  110. package/dist/esm/interface.js.map +0 -1
  111. package/dist/esm/rest-client.js +0 -294
  112. package/dist/esm/rest-client.js.map +0 -1
  113. package/dist/esm/rpc-client.js +0 -722
  114. package/dist/esm/rpc-client.js.map +0 -1
  115. package/dist/types/bitcoin.browser.d.ts.map +0 -1
  116. package/dist/types/bitcoin.node.d.ts +0 -47
  117. package/dist/types/bitcoin.node.d.ts.map +0 -1
  118. package/dist/types/index.browser.d.ts +0 -9
  119. package/dist/types/index.browser.d.ts.map +0 -1
  120. package/dist/types/index.node.d.ts +0 -9
  121. package/dist/types/index.node.d.ts.map +0 -1
  122. package/dist/types/interface.d.ts +0 -86
  123. package/dist/types/interface.d.ts.map +0 -1
  124. package/dist/types/rest-client.d.ts +0 -273
  125. package/dist/types/rest-client.d.ts.map +0 -1
  126. package/dist/types/rpc-client.d.ts +0 -506
  127. package/dist/types/rpc-client.d.ts.map +0 -1
  128. package/src/bitcoin.node.ts +0 -121
  129. package/src/index.browser.ts +0 -9
  130. package/src/index.node.ts +0 -9
  131. package/src/interface.ts +0 -160
  132. package/src/rest-client.ts +0 -420
  133. package/src/rpc-client.ts +0 -888
  134. /package/dist/cjs/{interface.js → client/rpc/interface.js} +0 -0
  135. /package/dist/esm/{interface.js → client/rpc/interface.js} +0 -0
@@ -1,9 +1,11 @@
1
1
  import { networks } from 'bitcoinjs-lib';
2
- import { BitcoinRest } from './rest-client.js';
2
+ import { BitcoinRestClient } from './client/rest/index.js';
3
+ import { BitcoinCoreRpcClient } from './client/rpc/index.js';
3
4
  import { AvailableNetworks, BitcoinClientConfig } from './types.js';
4
5
  export type BitcoinNetworkConfig = {
5
6
  name: keyof AvailableNetworks;
6
- rest: BitcoinRest;
7
+ rpc?: BitcoinCoreRpcClient;
8
+ rest: BitcoinRestClient;
7
9
  config: BitcoinClientConfig;
8
10
  data: networks.Network;
9
11
  };
@@ -11,14 +13,15 @@ export type BitcoinNetworkConfigMap = {
11
13
  [key in keyof AvailableNetworks]?: BitcoinNetworkConfig;
12
14
  };
13
15
  /**
14
- * General class to house the Bitcoin client connections, client config and various utility methods.
15
- * @name Bitcoin
16
- * @type {Bitcoin}
16
+ * The BitcoinNetworkConnection class contains relevant data and methods for interacting with different Bitcoin network.
17
+ * @name BitcoinNetworkConnection
18
+ * @type {BitcoinNetworkConnection}
17
19
  */
18
- export declare class Bitcoin {
20
+ export declare class BitcoinNetworkConnection {
19
21
  network: BitcoinNetworkConfig;
20
22
  mainnet?: BitcoinNetworkConfig;
21
- testnet?: BitcoinNetworkConfig;
23
+ testnet3?: BitcoinNetworkConfig;
24
+ testnet4?: BitcoinNetworkConfig;
22
25
  signet?: BitcoinNetworkConfig;
23
26
  mutinynet?: BitcoinNetworkConfig;
24
27
  regtest?: BitcoinNetworkConfig;
@@ -29,6 +32,18 @@ export declare class Bitcoin {
29
32
  * @throws {MethodError} If no configs is passed and BITCOIN_NETWORK_CONFIG is missing or invalid.
30
33
  */
31
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., 'mainnet', 'testnet3', 'signet', 'regtest').
38
+ * @returns {Bitcoin} The Bitcoin object.
39
+ */
40
+ getNetworkConnection(network: string): BitcoinNetworkConnection;
41
+ /**
42
+ * Sets the active Bitcoin network.
43
+ * @param {keyof AvailableNetworks} active - The Bitcoin network to set as active (e.g., 'mainnet', 'testnet3', 'signet', 'regtest').
44
+ * @throws {MethodError} If no configuration is found for the specified network.
45
+ */
46
+ setActiveNetwork(active: string): void;
32
47
  /**
33
48
  * Converts Bitcoin (BTC) to satoshis (SAT).
34
49
  * @param {number} btc - The amount in BTC.
@@ -42,4 +57,4 @@ export declare class Bitcoin {
42
57
  */
43
58
  static satsToBtc(sats: number): number;
44
59
  }
45
- export declare const bitcoin: Bitcoin;
60
+ export declare const bitcoin: BitcoinNetworkConnection;
@@ -0,0 +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,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGpE,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,iBAAiB,CAAC;IAC9B,GAAG,CAAC,EAAE,oBAAoB,CAAC;IAC3B,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;KACnC,GAAG,IAAI,MAAM,iBAAiB,CAAC,CAAC,EAAE,oBAAoB;CACxD,CAAC;AAEF;;;;GAIG;AACH,qBAAa,wBAAwB;IAC5B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAEtC;;;;;OAKG;gBACS,OAAO,CAAC,EAAE,uBAAuB;IAyD7C;;;;OAIG;IACI,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,wBAAwB;IAWtE;;;;OAIG;IACI,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAW7C;;;;OAIG;WACW,SAAS,CAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAI7C;;;;OAIG;WACW,SAAS,CAAE,IAAI,EAAE,MAAM,GAAG,MAAM;CAG/C;AAED,eAAO,MAAM,OAAO,0BAAiC,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { AddressInfo, AddressUtxo, RawTransactionRest, RestApiCallParams } from './index.js';
2
+ /**
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}
6
+ */
7
+ export declare class BitcoinAddress {
8
+ private api;
9
+ constructor(api: (params: RestApiCallParams) => Promise<any>);
10
+ /**
11
+ * Get transaction history for the specified address/scripthash, sorted with newest first.
12
+ * Returns up to 50 mempool transactions plus the first 25 confirmed transactions.
13
+ * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-addressaddresstxs | Esplora GET /address/:address/txs } for details.
14
+ * @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
+ */
17
+ getTxs(addressOrScripthash: string): Promise<Array<RawTransactionRest>>;
18
+ /**
19
+ * Calls getAddressTxs and checks if any funds come back.
20
+ * Toggle if those funds are confirmed.
21
+ * @param {string} addressOrScripthash The address or scripthash to check.
22
+ * @returns {Promise<boolean>} True if the address has any funds, false otherwise.
23
+ */
24
+ isFundedAddress(addressOrScripthash: string): Promise<boolean>;
25
+ /**
26
+ * Get unconfirmed transaction history for the specified address/scripthash.
27
+ * Returns up to 50 transactions (no paging).
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.
30
+ */
31
+ getTxsMempool(addressOrScripthash: string): Promise<Array<RawTransactionRest>>;
32
+ /**
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
+ * @param {string} addressOrScripthash The address or scripthash to check.
38
+ * @returns {Promise<AddressInfo>} A promise resolving to an {@link AddressInfo} object.
39
+ */
40
+ getInfo(addressOrScripthash: string): Promise<AddressInfo>;
41
+ /**
42
+ * 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.
44
+ * @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.
47
+ */
48
+ getConfirmedTxs(addressOrScripthash: string, lastSeenTxId?: string): Promise<Array<RawTransactionRest>>;
49
+ /**
50
+ * Get the list of unspent transaction outputs associated with the address/scripthash.
51
+ * See {@link https://github.com/Blockstream/esplora/blob/master/API.md#get-addressaddressutxo | Esplora GET /address/:address/utxo } for details.
52
+ * @param {string} addressOrScripthash The address or scripthash to check.
53
+ * @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
54
+ */
55
+ getUtxos(addressOrScripthash: string): Promise<Array<AddressUtxo>>;
56
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../../src/client/rest/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE7F;;;;GAIG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,GAAG,CAA8C;gBAE7C,GAAG,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,GAAG,CAAC;IAI5D;;;;;;OAMG;IACU,MAAM,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAIpF;;;;;OAKG;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;;;;;;;OAOG;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;IAQpH;;;;;OAKG;IACU,QAAQ,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;CAGhF"}
@@ -0,0 +1,32 @@
1
+ import { BlockResponse, GetBlockParams } from '../../types.js';
2
+ import { RestApiCallParams } from './index.js';
3
+ /**
4
+ * Implements a strongly-typed BitcoinRest to connect to remote bitcoin node via REST API for block-related operations.
5
+ * @class BitcoinBlock
6
+ * @type {BitcoinBlock}
7
+ */
8
+ export declare class BitcoinBlock {
9
+ private api;
10
+ constructor(api: (params: RestApiCallParams) => Promise<any>);
11
+ /**
12
+ * Returns the blockheight of the most-work fully-validated chain. The genesis block has height 0.
13
+ * @returns {Blockheight} The number of the blockheight with the most-work of the fully-validated chain.
14
+ */
15
+ count(): Promise<number>;
16
+ /**
17
+ * Returns the block data associated with a `blockhash` of a valid block.
18
+ * @param {GetBlockParams} params See {@link GetBlockParams} for details.
19
+ * @param {?string} params.blockhash The blockhash of the block to query.
20
+ * @param {?number} params.height The block height of the block to query.
21
+ * @returns {BlockResponse} A promise resolving to a {@link BlockResponse} formatted depending on `verbosity` level.
22
+ * @throws {BitcoinRpcError} If neither `blockhash` nor `height` is provided.
23
+ */
24
+ get({ blockhash, height }: GetBlockParams): Promise<BlockResponse | undefined>;
25
+ /**
26
+ * Get the block hash for a given block height.
27
+ * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-block-heightheight | Esplora GET /block-height/:height } for details.
28
+ * @param {number} height The block height (required).
29
+ * @returns {Promise<string>} The hash of the block currently at height..
30
+ */
31
+ getHash(height: number): Promise<string>;
32
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/client/rest/block.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAW,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,GAAG,CAA8C;gBAE7C,GAAG,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,GAAG,CAAC;IAI5D;;;OAGG;IACU,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC;;;;;;;OAOG;IACU,GAAG,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAgB3F;;;;;OAKG;IACU,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGtD"}
@@ -0,0 +1,149 @@
1
+ import { UnixTimestamp } from '@did-btcr2/common';
2
+ import { TxInPrevout } from '../../types.js';
3
+ import { BitcoinAddress } from './address.js';
4
+ import { BitcoinBlock } from './block.js';
5
+ import { BitcoinTransaction } from './transaction.js';
6
+ export type TransactionStatus = {
7
+ confirmed: boolean;
8
+ block_height: number;
9
+ block_hash: string;
10
+ block_time: UnixTimestamp;
11
+ };
12
+ export interface Vin {
13
+ txid: string;
14
+ vout: number;
15
+ prevout?: TxInPrevout;
16
+ scriptsig: string;
17
+ scriptsig_asm: string;
18
+ witness: string[];
19
+ is_coinbase: boolean;
20
+ sequence: number;
21
+ }
22
+ export interface Vout {
23
+ scriptpubkey: string;
24
+ scriptpubkey_asm: string;
25
+ scriptpubkey_type: string;
26
+ scriptpubkey_address?: string;
27
+ value: number;
28
+ }
29
+ export interface ChainStats {
30
+ funded_txo_count: number;
31
+ funded_txo_sum: number;
32
+ spent_txo_count: number;
33
+ spent_txo_sum: number;
34
+ tx_count: number;
35
+ }
36
+ export interface MempoolStats {
37
+ funded_txo_count: number;
38
+ funded_txo_sum: number;
39
+ spent_txo_count: number;
40
+ spent_txo_sum: number;
41
+ tx_count: number;
42
+ }
43
+ export interface AddressInfo {
44
+ address: string;
45
+ chain_stats: ChainStats;
46
+ mempool_stats: MempoolStats;
47
+ }
48
+ export interface RawTransactionRest {
49
+ txid: string;
50
+ version: number;
51
+ locktime: number;
52
+ vin: Array<Vin>;
53
+ vout: Array<Vout>;
54
+ size: number;
55
+ weight: number;
56
+ fee: number;
57
+ status: TransactionStatus;
58
+ }
59
+ export interface AddressUtxo {
60
+ txid: string;
61
+ vout: number;
62
+ status: TransactionStatus;
63
+ value: number;
64
+ }
65
+ export interface RestClientConfigParams {
66
+ host: string;
67
+ headers?: {
68
+ [key: string]: string;
69
+ };
70
+ }
71
+ export declare class RestClientConfig {
72
+ host: string;
73
+ headers?: {
74
+ [key: string]: string;
75
+ };
76
+ constructor({ host, headers }: RestClientConfigParams);
77
+ }
78
+ export interface RestApiCallParams {
79
+ path: string;
80
+ url?: string;
81
+ method?: string;
82
+ body?: any;
83
+ headers?: any;
84
+ }
85
+ export interface RestResponse extends Response {
86
+ [key: string]: any;
87
+ }
88
+ /**
89
+ * Implements a strongly-typed BitcoinRestClient to connect to remote bitcoin node via REST API.
90
+ * @class BitcoinRestClient
91
+ * @type {BitcoinRestClient}
92
+ */
93
+ export declare class BitcoinRestClient {
94
+ /**
95
+ * The encapsulated {@link RestClientConfig} object.
96
+ * @private
97
+ * @type {RestClientConfig}
98
+ */
99
+ private _config;
100
+ /**
101
+ * The api calls related to bitcoin transactions.
102
+ * @type {BitcoinTransaction}
103
+ */
104
+ transaction: BitcoinTransaction;
105
+ /**
106
+ * The api calls related to bitcoin blocks.
107
+ * @type {BitcoinBlock}
108
+ */
109
+ block: BitcoinBlock;
110
+ /**
111
+ * The api calls related to bitcoin addresses.
112
+ * @type {BitcoinAddress}
113
+ */
114
+ address: BitcoinAddress;
115
+ /**
116
+ * The API call method that can be used to make requests to the REST API.
117
+ * @returns {Promise<any>} A promise resolving to the response data.
118
+ */
119
+ api: (params: RestApiCallParams) => Promise<any>;
120
+ constructor(config: RestClientConfig);
121
+ /**
122
+ * Get the configuration object.
123
+ * @private
124
+ */
125
+ get config(): RestClientConfig;
126
+ /**
127
+ * Static method connects to a bitcoin node running a esplora REST API.
128
+ *
129
+ * @param {RestClientConfig} config The configuration object for the client (optional).
130
+ * @returns {BitcoinRestClient} A new {@link BitcoinRestClient} instance.
131
+ * @example
132
+ * ```
133
+ * const rest = BitcoinRestClient.connect();
134
+ * ```
135
+ */
136
+ static connect(config?: RestClientConfig): BitcoinRestClient;
137
+ /**
138
+ * Make a REST API call to the configured Bitcoin node.
139
+ * @private
140
+ * @param {RestApiCallParams} params The parameters for the API call. See {@link RestApiCallParams} for details.
141
+ * @param {string} [params.path] The path to the API endpoint (required).
142
+ * @param {string} [params.url] The full URL to the API endpoint (optional).
143
+ * @param {string} [params.method] The HTTP method to use (default is 'GET').
144
+ * @param {any} [params.body] The body of the request (optional).
145
+ * @param {any} [params.headers] Additional headers to include in the request (optional).
146
+ * @returns {Promise<any>} A promise resolving to the response data.
147
+ */
148
+ private call;
149
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/rest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGtD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,MAAM,CAA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AM,CAAC,EAAE,gBAAgB,GAAG,iBAAiB;IAInE;;;;;;;;;;OAUG;YACW,IAAI;CAyCnB"}
@@ -0,0 +1,44 @@
1
+ import { Bytes } from '@did-btcr2/common';
2
+ import { RawTransactionRest, RestApiCallParams } from './index.js';
3
+ export declare class BitcoinTransaction {
4
+ private api;
5
+ constructor(api: (params: RestApiCallParams) => Promise<any>);
6
+ /**
7
+ * Returns the transaction in JSON format.
8
+ * See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxid | Esplora GET /tx/:txid } for details.
9
+ * @param {string} txid The transaction id (required).
10
+ * @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
11
+ */
12
+ get(txid: string): Promise<RawTransactionRest>;
13
+ /**
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.
16
+ * @param {string} txid The transaction id (required).
17
+ * @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
18
+ */
19
+ isConfirmed(txid: string): Promise<boolean>;
20
+ /**
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.
24
+ * @param {string} txid The transaction id (required).
25
+ * @returns {Promise<RawTransactionRest | string>} A promise resolving to the raw transaction in the specified format.
26
+ */
27
+ getHex(txid: string): Promise<string>;
28
+ /**
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.
32
+ * @param {string} txid The transaction id (required).
33
+ * @returns {Promise<RawTransactionRest | string>} A promise resolving to the raw transaction in the specified format.
34
+ */
35
+ getRaw(txid: string): Promise<Bytes>;
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.
39
+ * See {@link https://github.com/blockstream/esplora/blob/master/API.md#post-tx | Esplora POST /tx } for details.
40
+ * @param {string} tx The raw transaction in hex format (required).
41
+ * @returns {Promise<string>} The transaction id of the broadcasted transaction.
42
+ */
43
+ send(tx: string): Promise<string>;
44
+ }
@@ -0,0 +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,YAAY,CAAC;AAEnE,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,CAAC,kBAAkB,CAAC;IAI3D;;;;;OAKG;IACU,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxD;;;;;;OAMG;IACU,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlD;;;;;;OAMG;IACU,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAIjD;;;;;;OAMG;IACU,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAG/C"}
@@ -0,0 +1,276 @@
1
+ import { BitcoinRpcClientConfig, BlockResponse, ChainInfo, CreateRawTxInputs, CreateRawTxOutputs, DerivedAddresses, GetBlockParams, ListTransactionsParams, ListTransactionsResult, RawTransactionResponse, RawTransactionV2, RpcClientConfig, SignedRawTx, UnspentTxInfo, VerbosityLevel, WalletTransaction } from '../../types.js';
2
+ import { BitcoinRpcClient } from './interface.js';
3
+ import { JsonRpcTransport } from './json-rpc.js';
4
+ /**
5
+ * Class representing a Bitcoin Core RPC client.
6
+ * @class BitcoinCoreRpcClient
7
+ * @type {BitcoinCoreRpcClient}
8
+ * @implements {BitcoinRpcClient}
9
+ */
10
+ export declare class BitcoinCoreRpcClient implements BitcoinRpcClient {
11
+ private _transport;
12
+ private _config;
13
+ /**
14
+ * Constructs a new {@link BitcoinCoreRpcClient} instance from a new {@link RpcClient | RpcClient}.
15
+ * @param {RpcClientConfig} config The bitcoin-core client instance.
16
+ * @example
17
+ * ```
18
+ * import BitcoinRpcClient from '@did-btcr2/method';
19
+ * const bob = BitcoinRpcClient.connect(); // To use default polar config, pass no args. Polar must run locally.
20
+ * ```
21
+ */
22
+ constructor(config: RpcClientConfig);
23
+ /**
24
+ * Get the config for the current BitcoinRpcClient object.
25
+ * @returns {BitcoinRpcClient} The encapsulated {@link BitcoinRpcClient} object.
26
+ * @example
27
+ * ```
28
+ * import BitcoinRpcClient from '@did-btcr2/method';
29
+ * const alice = BitcoinRpcClient.connect();
30
+ * const config = alice.config;
31
+ * ```
32
+ */
33
+ get config(): BitcoinRpcClientConfig;
34
+ /**
35
+ * Get the client for the current BitcoinRpcClient object.
36
+ * @returns {RpcClient} The encapsulated {@link RpcClient} object.
37
+ * @example
38
+ * ```
39
+ * const alice = BitcoinRpcClient.connect();
40
+ * const config = alice.client;
41
+ * ```
42
+ */
43
+ get client(): JsonRpcTransport;
44
+ /**
45
+ * Static method initializes a new BitcoinCoreRpcClient client with the given configuration.
46
+ * The RpcClient returned by this method does not have any named methods.
47
+ * Use this method to create and pass a new RpcClient instance to a BitcoinCoreRpcClient constructor.
48
+ *
49
+ * @param {RpcClientConfig} config The configuration object for the client (optional).
50
+ * @returns {BitcoinCoreRpcClient} A new RpcClient instance.
51
+ * @example
52
+ * ```
53
+ * const options: RpcClientConfig = {
54
+ * host: 'http://localhost:18443',
55
+ * username: 'alice',
56
+ * password: 'alicepass',
57
+ * version: '28.1.0',
58
+ * }
59
+ * const alice = BitcoinCoreRpcClient.initialize(options); // Client config required
60
+ * ```
61
+ */
62
+ static initialize(config?: RpcClientConfig): BitcoinRpcClientConfig;
63
+ /**
64
+ * Static method connects to a bitcoin node running the bitcoin core daemon (bitcoind).
65
+ * To use default polar config, do not pass a config. See {@link DEFAULT_BITCOIN_NETWORK_CONFIG} for default config.
66
+ * @required A locally running {@link https://github.com/jamaljsr/polar | Polar Lightning} regtest node.
67
+ *
68
+ * @param {?RpcClientConfig} config The configuration object for the client (optional).
69
+ * @returns A new {@link BitcoinRpcClient} instance.
70
+ * @example
71
+ * ```
72
+ * const alice = BitcoinRpcClient.connect();
73
+ * ```
74
+ */
75
+ static connect(config?: RpcClientConfig): BitcoinCoreRpcClient;
76
+ /**
77
+ * Check if the given error is a JSON-RPC error.
78
+ * @param {unknown} e The error to check.
79
+ * @returns {boolean} True if the error is a JSON-RPC error, false otherwise.
80
+ */
81
+ isJsonRpcError(e: unknown): e is Error & {
82
+ name: 'RpcError';
83
+ code?: number;
84
+ };
85
+ /**
86
+ * Executes a JSON-RPC command on the bitcoind node.
87
+ * @param {MethodNameInLowerCase} method The name of the method to call.
88
+ * @param {Array<any>} parameters The parameters to pass to the method.
89
+ * @returns {Promise<T>} A promise resolving to the result of the command.
90
+ */
91
+ private executeRpc;
92
+ /**
93
+ * Handle errors that occur while executing commands.
94
+ * @param methods An array of {@link BatchOption} objects.
95
+ * @param error The error that was thrown.
96
+ * @throws Throws a {@link BitcoinRpcError} with the error message.
97
+ */
98
+ private handleError;
99
+ /**
100
+ * Returns the block data associated with a `blockhash` of a valid block.
101
+ * @param {GetBlockParams} params See {@link GetBlockParams} for details.
102
+ * @param {?string} params.blockhash The blockhash of the block to query.
103
+ * @param {?number} params.height The block height of the block to query.
104
+ * @param {?VerbosityLevel} params.verbosity The verbosity level. See {@link VerbosityLevel}.
105
+ * @returns {BlockResponse} A promise resolving to a {@link BlockResponse} formatted depending on `verbosity` level.
106
+ * @throws {BitcoinRpcError} If neither `blockhash` nor `height` is provided.
107
+ */
108
+ getBlock({ blockhash, height, verbosity }: GetBlockParams): Promise<BlockResponse | undefined>;
109
+ /**
110
+ * Returns the blockheight of the most-work fully-validated chain. The genesis block has height 0.
111
+ * @returns {Blockheight} The number of the blockheight with the most-work of the fully-validated chain.
112
+ */
113
+ getBlockCount(): Promise<number>;
114
+ /**
115
+ * Returns the blockhash of the block at the given height in the active chain.
116
+ */
117
+ getBlockHash(height: number): Promise<string>;
118
+ /**
119
+ * Returns an object containing various blockchain state info.
120
+ */
121
+ getBlockchainInfo(): Promise<ChainInfo>;
122
+ /**
123
+ * Sign inputs for raw transaction (serialized, hex-encoded).
124
+ * The second optional argument (may be null) is an array of previous transaction outputs that
125
+ * this transaction depends on but may not yet be in the block chain.
126
+ * Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
127
+ * @param {string} hexstring The hex-encoded transaction to send.
128
+ */
129
+ signRawTransaction(hexstring: string): Promise<SignedRawTx>;
130
+ /**
131
+ * Submit a raw transaction (serialized, hex-encoded) to local node and network.
132
+ *
133
+ * The transaction will be sent unconditionally to all peers, so using sendrawtransaction
134
+ * for manual rebroadcast may degrade privacy by leaking the transaction's origin, as
135
+ * nodes will normally not rebroadcast non-wallet transactions already in their mempool.
136
+ *
137
+ * @param {string} hexstring The hex-encoded transaction to send.
138
+ * @param {numbner} [maxfeerate] If not passed, default is 0.10.
139
+ * @returns {Promise<string>} A promise resolving to the transaction hash in hex.
140
+ */
141
+ sendRawTransaction(hexstring: string, maxfeerate?: number | string, maxBurnAmount?: number | string): Promise<string>;
142
+ /**
143
+ * Combines calls to `signRawTransaction` and `sendRawTransaction`.
144
+ * @param {string} params.hexstring The hex-encoded transaction to send.
145
+ * @returns {Promise<string>} A promise resolving to the transaction hash in hex.
146
+ */
147
+ signAndSendRawTransaction(hexstring: string): Promise<string>;
148
+ /**
149
+ * Combines calls to `createRawTransaction`, `signRawTransaction` and `sendRawTransaction`.
150
+ * @param {CreateRawTxInputs[]} inputs The inputs to the transaction (required).
151
+ * @param {CreateRawTxOutputs[]} outputs The outputs of the transaction (required).
152
+ * @returns {Promise<string>} A promise resolving to the transaction hash in hex.
153
+ */
154
+ createSignSendRawTransaction(inputs: CreateRawTxInputs[], outputs: CreateRawTxOutputs[]): Promise<string>;
155
+ /**
156
+ * TODO: Comments
157
+ */
158
+ listTransactions(params: ListTransactionsParams): Promise<ListTransactionsResult>;
159
+ /**
160
+ * Create a transaction spending the given inputs and creating new outputs.
161
+ * Outputs can be addresses or data.
162
+ * Returns hex-encoded raw transaction.
163
+ * Note that the transaction's inputs are not signed, and
164
+ * it is not stored in the wallet or transmitted to the network.
165
+ * @param {TxInForCreateRaw[]} inputs The inputs to the transaction (required).
166
+ * @param {CreateRawTxOutputs[]} outputs The outputs of the transaction (required).
167
+ * @param {number} [locktime] The locktime of the transaction (optional).
168
+ * @param {boolean} [replacable] Whether the transaction is replaceable (optional).
169
+ * @returns {string} The hex-encoded raw transaction.
170
+ */
171
+ createRawTransaction(inputs: CreateRawTxInputs[], outputs: CreateRawTxOutputs[], locktime?: number, replacable?: boolean): Promise<string>;
172
+ /**
173
+ * Derives one or more addresses corresponding to an output descriptor.
174
+ * Examples of output descriptors are:
175
+ * pkh(<pubkey>) P2PKH outputs for the given pubkey
176
+ * wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey
177
+ * sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys
178
+ * raw(<hex script>) Outputs whose output script equals the specified hex-encoded bytes
179
+ * tr(<pubkey>,multi_a(<n>,<pubkey>,<pubkey>,...)) P2TR-multisig outputs for the given threshold and pubkeys
180
+ *
181
+ * In the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one
182
+ * or more path elements separated by "/", where "h" represents a hardened child key.
183
+ *
184
+ * See {@link https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md | github.com/bitcoin/bitcoin/descriptors.md}
185
+ * for more information.
186
+ * @param {string} descriptor The descriptor.
187
+ * @param {Array<number>} range If descriptor is ranged, must specify end or [begin,end] to derive.
188
+ * @returns {Array<DerivedAddresses>} a list of derived addresses
189
+ * @example First three native segwit receive addresses
190
+ * ```
191
+ * const bitcoind = BitcoinRpcClient.connect()
192
+ * const addresses = bitcoind.deriveAddresses("wpkh([d34db33f/84h/0h/0h]xpub6DJ2dN.../0/*)#cjjspncu", [0,2])
193
+ * ```
194
+ */
195
+ deriveAddresses(descriptor: string, range?: Array<number>): Promise<Array<DerivedAddresses>>;
196
+ /**
197
+ * Returns the total available balance. The available balance is what the wallet
198
+ * considers currently spendable, and is thus affected by options which limit
199
+ * spendability such as -spendzeroconfchange.
200
+ * @returns {Promise<number>} A promise resolving to the total available balance in BTC.
201
+ */
202
+ getBalance(): Promise<number>;
203
+ /**
204
+ * Returns a new Bitcoin address for receiving payments. If 'label' is specified,
205
+ * it is added to the address book so payments received with the address will be associated with 'label'.
206
+ * The 'address_type' can be one of "legacy", "p2sh-segwit", "bech32", or "bech32m".
207
+ * @param {string} addressType The address type to use (required, options=["legacy", "p2sh-segwit", "bech32", "bech32m"], default="bech32").
208
+ * @param {string} [label] The label to associate with the new address (optional).
209
+ * @returns {Promise<string>} A promise resolving to the new address.
210
+ */
211
+ getNewAddress(addressType: string, label?: string): Promise<string>;
212
+ /**
213
+ * Returns array of unspent transaction outputs with between minconf and maxconf (inclusive) confirmations.
214
+ * Optionally filter to only include txouts paid to specified addresses.
215
+ * @param {Object} params The parameters for the listUnspent command.
216
+ * @param {number} [params.minconf=0] The minimum number of confirmations an output must have to be included.
217
+ * @param {number} [params.maxconf=9999999] The maximum number of confirmations an output can have to be included.
218
+ * @param {string[]} [params.address] Only include outputs paid to these addresses.
219
+ * @param {boolean} [params.include_unsafe=true] Whether to include outputs that are not safe to spend.
220
+ * @returns {Promise<UnspentTxInfo[]>} A promise resolving to an array of {@link UnspentTxInfo} objects.
221
+ */
222
+ listUnspent(params: {
223
+ minconf?: number;
224
+ maxconf?: number;
225
+ address?: string[];
226
+ include_unsafe?: boolean;
227
+ }): Promise<UnspentTxInfo[]>;
228
+ /**
229
+ * Send an amount to a given address.
230
+ * @param {string} address The address to send to.
231
+ * @param {number} amount The amount to send in BTC.
232
+ * @returns {Promise<SendToAddressResult>} A promise resolving to the transaction id.
233
+ */
234
+ sendToAddress(address: string, amount: number): Promise<RawTransactionV2>;
235
+ /**
236
+ * Sign a message with the private key of an address.
237
+ * @param {string} address The address to sign the message with.
238
+ * @param {string} message The message to sign.
239
+ * @returns {Promise<string>} A promise resolving to the signature in base64.
240
+ */
241
+ signMessage(address: string, message: string): Promise<string>;
242
+ /**
243
+ * Verify a signed message.
244
+ * @param {string} address The address to verify the message with.
245
+ * @param {string} signature The signature to verify in base64.
246
+ * @param {string} message The message to verify.
247
+ * @returns {Promise<boolean>} A promise resolving to true if the signature is valid, false otherwise.
248
+ */
249
+ verifyMessage(address: string, signature: string, message: string): Promise<boolean>;
250
+ /**
251
+ * Get detailed information about in-wallet transaction <txid>.
252
+ * @param txid: The transaction id. (string, required)
253
+ * @param {boolean} include_watchonly Whether to include watch-only addresses in balance calculation and details.
254
+ * @returns {WalletTransaction} A promise resolving to a {@link WalletTransaction} object.
255
+ */
256
+ getTransaction(txid: string, include_watchonly?: boolean): Promise<WalletTransaction>;
257
+ /**
258
+ * Get detailed information about a transaction.
259
+ * By default, this call only returns a transaction if it is in the mempool. If -txindex is enabled
260
+ * and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block.
261
+ * If a blockhash argument is passed, it will return the transaction if the specified block is available and
262
+ * the transaction is in that block.
263
+ * @param {string} txid The transaction id (required).
264
+ * @param {?VerbosityLevel} verbosity Response format: 0 (hex), 1 (json) or 2 (jsonext).
265
+ * @param {?string} blockhash The block in which to look for the transaction (optional).
266
+ * @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
267
+ */
268
+ getRawTransaction(txid: string, verbosity?: VerbosityLevel, blockhash?: string): Promise<RawTransactionResponse>;
269
+ /**
270
+ * Get detailed information about multiple transactions. An extension of {@link getRawTransaction}.
271
+ * @param {Array<string>} txids An array of transaction ids.
272
+ * @param {?VerbosityLevel} verbosity Response format: 0 (hex), 1 (json) or 2 (jsonext).
273
+ * @returns {Promise<Array<RawTransactionResponse>>}
274
+ */
275
+ getRawTransactions(txids: string[], verbosity?: VerbosityLevel): Promise<RawTransactionResponse[]>;
276
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/rpc/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,sBAAsB,EACtB,aAAa,EAKb,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,sBAAsB,EAEtB,sBAAsB,EAGtB,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,aAAa,EACb,cAAc,EACd,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,gBAAgB;IAC3D,OAAO,CAAC,UAAU,CAAmB;IACrC,OAAO,CAAC,OAAO,CAAkB;IAEjC;;;;;;;;OAQG;gBACS,MAAM,EAAE,eAAe;IAKnC;;;;;;;;;OASG;IACH,IAAI,MAAM,IAAI,sBAAsB,CAGnC;IAED;;;;;;;;OAQG;IACH,IAAI,MAAM,IAAI,gBAAgB,CAG7B;IAED;;;;;;;;;;;;;;;;;OAiBG;WACW,UAAU,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,sBAAsB;IAI1E;;;;;;;;;;;OAWG;WACW,OAAO,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,oBAAoB;IA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