@meshsdk/bitcoin 1.9.0-beta.50

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.
@@ -0,0 +1,261 @@
1
+ import * as ecpair from 'ecpair';
2
+ import * as _bip32 from 'bip32';
3
+ import * as bitcoin from 'bitcoinjs-lib';
4
+ export { bitcoin };
5
+ import * as bip39 from 'bip39';
6
+ export { bip39 };
7
+
8
+ declare const bip32: _bip32.BIP32API;
9
+ declare const ECPair: ecpair.ECPairAPI;
10
+
11
+ interface IBitcoinWallet {
12
+ getChangeAddress(): Promise<string>;
13
+ getNetworkId(): Promise<0 | 1>;
14
+ signTx(signedTx: string): Promise<string>;
15
+ submitTx(tx: string): Promise<string>;
16
+ }
17
+
18
+ type Address = {
19
+ address: string;
20
+ publicKey: string;
21
+ purpose: "payment" | "ordinals" | "stacks";
22
+ addressType: "p2tr" | "p2wpkh" | "p2sh" | "stacks";
23
+ };
24
+
25
+ type UTxO = {
26
+ status: {
27
+ block_hash: string;
28
+ block_height: number;
29
+ block_time: number;
30
+ confirmed: boolean;
31
+ };
32
+ txid: string;
33
+ value: number;
34
+ vout: number;
35
+ };
36
+
37
+ type ChainStats = {
38
+ funded_txo_count: number;
39
+ funded_txo_sum: number;
40
+ spent_txo_count: number;
41
+ spent_txo_sum: number;
42
+ tx_count: number;
43
+ };
44
+
45
+ type MempoolStats = {
46
+ funded_txo_count: number;
47
+ funded_txo_sum: number;
48
+ spent_txo_count: number;
49
+ spent_txo_sum: number;
50
+ tx_count: number;
51
+ };
52
+
53
+ type AddressInfo = {
54
+ address: string;
55
+ chain_stats: ChainStats;
56
+ mempool_stats: MempoolStats;
57
+ };
58
+
59
+ type ScriptInfo = {
60
+ scripthash: string;
61
+ chain_stats: ChainStats;
62
+ mempool_stats: MempoolStats;
63
+ };
64
+
65
+ type TransactionsStatus = {
66
+ confirmed: boolean;
67
+ block_height: number;
68
+ block_hash: string;
69
+ block_time: number;
70
+ };
71
+
72
+ type TransactionsInfo = {
73
+ txid: string;
74
+ version: number;
75
+ locktime: number;
76
+ vin: {
77
+ txid: string;
78
+ vout: number;
79
+ prevout: {
80
+ scriptpubkey: string;
81
+ scriptpubkey_asm: string;
82
+ scriptpubkey_type: string;
83
+ scriptpubkey_address: string;
84
+ value: number;
85
+ };
86
+ scriptsig: string;
87
+ scriptsig_asm: string;
88
+ witness: string[];
89
+ is_coinbase: boolean;
90
+ sequence: number;
91
+ }[];
92
+ vout: {
93
+ scriptpubkey: string;
94
+ scriptpubkey_asm: string;
95
+ scriptpubkey_type: string;
96
+ scriptpubkey_address: string;
97
+ value: number;
98
+ }[];
99
+ size: number;
100
+ weight: number;
101
+ fee: number;
102
+ status: TransactionsStatus;
103
+ };
104
+
105
+ interface IBitcoinProvider {
106
+ fetchAddress(address: string): Promise<AddressInfo>;
107
+ fetchAddressTransactions(address: string, last_seen_txid?: string): Promise<TransactionsInfo[]>;
108
+ fetchAddressUTxOs(address: string): Promise<UTxO[]>;
109
+ fetchScript(hash: string): Promise<ScriptInfo>;
110
+ fetchScriptTransactions(hash: string, last_seen_txid?: string): Promise<TransactionsInfo[]>;
111
+ fetchScriptUTxOs(hash: string): Promise<UTxO[]>;
112
+ fetchTransactionStatus(txid: string): Promise<TransactionsStatus>;
113
+ submitTx(tx: string): Promise<string>;
114
+ }
115
+
116
+ /**
117
+ * https://github.com/Blockstream/esplora/blob/master/API.md
118
+ */
119
+ declare class BlockstreamProvider implements IBitcoinProvider {
120
+ private readonly _axiosInstance;
121
+ constructor(network?: "mainnet" | "testnet");
122
+ /**
123
+ * Get information about an address.
124
+ * @param address - The address.
125
+ * @returns AddressInfo
126
+ */
127
+ fetchAddress(address: string): Promise<AddressInfo>;
128
+ /**
129
+ * Get transaction history for the specified address, sorted with newest first.
130
+ * Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using `last_seen_txid`.
131
+ * @param address - The address.
132
+ * @param last_seen_txid - The last seen transaction ID (optional).
133
+ * @returns TransactionsInfo[]
134
+ */
135
+ fetchAddressTransactions(address: string, last_seen_txid?: string): Promise<TransactionsInfo[]>;
136
+ /**
137
+ * Get the list of unspent transaction outputs associated with the address.
138
+ * @param address - The address.
139
+ * @returns UTxO[]
140
+ */
141
+ fetchAddressUTxOs(address: string): Promise<UTxO[]>;
142
+ /**
143
+ * Get information about a scripthash.
144
+ * @param hash - The hash of the script.
145
+ * @returns ScriptInfo
146
+ */
147
+ fetchScript(hash: string): Promise<ScriptInfo>;
148
+ /**
149
+ * Get transaction history for the specified scripthash, sorted with newest first.
150
+ * Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using `last_seen_txid`.
151
+ * @param hash - The hash of the script.
152
+ * @param last_seen_txid - The last seen transaction ID (optional).
153
+ * @returns TransactionsInfo[]
154
+ */
155
+ fetchScriptTransactions(hash: string, last_seen_txid?: string): Promise<TransactionsInfo[]>;
156
+ /**
157
+ * Get the list of unspent transaction outputs associated with the scripthash.
158
+ * @param hash - The hash of the script.
159
+ * @returns UTxO[]
160
+ */
161
+ fetchScriptUTxOs(hash: string): Promise<UTxO[]>;
162
+ /**
163
+ * Fetches the status of a transaction
164
+ * @param txid - The transaction ID.
165
+ * @returns TransactionsStatus
166
+ */
167
+ fetchTransactionStatus(txid: string): Promise<TransactionsStatus>;
168
+ /**
169
+ * Broadcast a raw transaction to the network.
170
+ * The transaction should be provided as hex in the request body. The txid will be returned on success.
171
+ * @param tx - The transaction in hex format.
172
+ * @returns The transaction ID.
173
+ */
174
+ submitTx(tx: string): Promise<string>;
175
+ }
176
+
177
+ declare class BrowserWallet implements IBitcoinWallet {
178
+ private readonly _purposes;
179
+ constructor(purposes: string[]);
180
+ /**
181
+ * This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the dApp to use.
182
+ * @param message - A message to display to the user when requesting permission to connect the wallet.
183
+ * @param purposes - An array of purposes for which the wallet is being connected. Default is `["payment"]`. Options are `["payment", "ordinals", "stacks"]`.
184
+ * @returns
185
+ */
186
+ static enable(message: string, purposes?: string[]): Promise<BrowserWallet>;
187
+ getAddresses(): Promise<Address[] | undefined>;
188
+ getChangeAddress(): Promise<string>;
189
+ getCollateral(): Promise<never[]>;
190
+ getNetworkId(): Promise<0 | 1>;
191
+ request(method: string, params?: any): Promise<any>;
192
+ signData(payload: string, address?: string, addressType?: "p2wpkh" | "p2tr" | "stacks"): Promise<{
193
+ address: string;
194
+ signature: string;
195
+ messageHash: string;
196
+ } | undefined>;
197
+ signTx(signedTx: string): Promise<string>;
198
+ submitTx(signedTx: string): Promise<string>;
199
+ }
200
+
201
+ type CreateBitcoinEmbeddedWalletOptions = {
202
+ networkId: 0 | 1;
203
+ key: {
204
+ type: "mnemonic";
205
+ words: string[];
206
+ };
207
+ provider?: IBitcoinProvider;
208
+ };
209
+ /**
210
+ * 0': Indicates the Bitcoin mainnet.
211
+ * 1': Indicates the Bitcoin testnet.
212
+ *
213
+ * EmbeddedWallet is a class that provides a simple interface to interact with Bitcoin wallets.
214
+ *
215
+ * @params options - The options to create an EmbeddedWallet.
216
+ * networkId - The network ID of the wallet.
217
+ * key - The key to create the wallet.
218
+ * provider - The Bitcoin provider to interact with the Bitcoin network.
219
+ */
220
+ declare class EmbeddedWallet {
221
+ private readonly _networkId;
222
+ private readonly _BIP32Interface;
223
+ private readonly _p2wpkh;
224
+ private readonly _provider?;
225
+ constructor(options: CreateBitcoinEmbeddedWalletOptions);
226
+ /**
227
+ * Get wallet network ID.
228
+ *
229
+ * @returns network ID
230
+ */
231
+ getNetworkId(): 0 | 1;
232
+ getPaymentAddress(): Address;
233
+ getPublicKey(): string;
234
+ /**
235
+ * Get UTXOs for the wallet address.
236
+ * @returns An array of UTXOs.
237
+ */
238
+ getUtxos(): Promise<UTxO[]>;
239
+ /**
240
+ * Signs a given message using the wallet's private key.
241
+ *
242
+ * @param message - The message to be signed.
243
+ * @returns The signature of the message as a string.
244
+ */
245
+ signData(message: string): string;
246
+ /**
247
+ * Sign a transaction payload.
248
+ * @param payload - The transaction payload to sign.
249
+ * @returns The signed transaction in hex format.
250
+ */
251
+ signTx(payload: bitcoin.Transaction): string;
252
+ /**
253
+ * Generate mnemonic or private key
254
+ *
255
+ * @param privateKey return private key if true
256
+ * @returns a transaction hash
257
+ */
258
+ static brew(strength?: number): string[];
259
+ }
260
+
261
+ export { type Address, BlockstreamProvider, BrowserWallet, type CreateBitcoinEmbeddedWalletOptions, ECPair, EmbeddedWallet, type IBitcoinWallet, type UTxO, bip32 };
@@ -0,0 +1,261 @@
1
+ import * as ecpair from 'ecpair';
2
+ import * as _bip32 from 'bip32';
3
+ import * as bitcoin from 'bitcoinjs-lib';
4
+ export { bitcoin };
5
+ import * as bip39 from 'bip39';
6
+ export { bip39 };
7
+
8
+ declare const bip32: _bip32.BIP32API;
9
+ declare const ECPair: ecpair.ECPairAPI;
10
+
11
+ interface IBitcoinWallet {
12
+ getChangeAddress(): Promise<string>;
13
+ getNetworkId(): Promise<0 | 1>;
14
+ signTx(signedTx: string): Promise<string>;
15
+ submitTx(tx: string): Promise<string>;
16
+ }
17
+
18
+ type Address = {
19
+ address: string;
20
+ publicKey: string;
21
+ purpose: "payment" | "ordinals" | "stacks";
22
+ addressType: "p2tr" | "p2wpkh" | "p2sh" | "stacks";
23
+ };
24
+
25
+ type UTxO = {
26
+ status: {
27
+ block_hash: string;
28
+ block_height: number;
29
+ block_time: number;
30
+ confirmed: boolean;
31
+ };
32
+ txid: string;
33
+ value: number;
34
+ vout: number;
35
+ };
36
+
37
+ type ChainStats = {
38
+ funded_txo_count: number;
39
+ funded_txo_sum: number;
40
+ spent_txo_count: number;
41
+ spent_txo_sum: number;
42
+ tx_count: number;
43
+ };
44
+
45
+ type MempoolStats = {
46
+ funded_txo_count: number;
47
+ funded_txo_sum: number;
48
+ spent_txo_count: number;
49
+ spent_txo_sum: number;
50
+ tx_count: number;
51
+ };
52
+
53
+ type AddressInfo = {
54
+ address: string;
55
+ chain_stats: ChainStats;
56
+ mempool_stats: MempoolStats;
57
+ };
58
+
59
+ type ScriptInfo = {
60
+ scripthash: string;
61
+ chain_stats: ChainStats;
62
+ mempool_stats: MempoolStats;
63
+ };
64
+
65
+ type TransactionsStatus = {
66
+ confirmed: boolean;
67
+ block_height: number;
68
+ block_hash: string;
69
+ block_time: number;
70
+ };
71
+
72
+ type TransactionsInfo = {
73
+ txid: string;
74
+ version: number;
75
+ locktime: number;
76
+ vin: {
77
+ txid: string;
78
+ vout: number;
79
+ prevout: {
80
+ scriptpubkey: string;
81
+ scriptpubkey_asm: string;
82
+ scriptpubkey_type: string;
83
+ scriptpubkey_address: string;
84
+ value: number;
85
+ };
86
+ scriptsig: string;
87
+ scriptsig_asm: string;
88
+ witness: string[];
89
+ is_coinbase: boolean;
90
+ sequence: number;
91
+ }[];
92
+ vout: {
93
+ scriptpubkey: string;
94
+ scriptpubkey_asm: string;
95
+ scriptpubkey_type: string;
96
+ scriptpubkey_address: string;
97
+ value: number;
98
+ }[];
99
+ size: number;
100
+ weight: number;
101
+ fee: number;
102
+ status: TransactionsStatus;
103
+ };
104
+
105
+ interface IBitcoinProvider {
106
+ fetchAddress(address: string): Promise<AddressInfo>;
107
+ fetchAddressTransactions(address: string, last_seen_txid?: string): Promise<TransactionsInfo[]>;
108
+ fetchAddressUTxOs(address: string): Promise<UTxO[]>;
109
+ fetchScript(hash: string): Promise<ScriptInfo>;
110
+ fetchScriptTransactions(hash: string, last_seen_txid?: string): Promise<TransactionsInfo[]>;
111
+ fetchScriptUTxOs(hash: string): Promise<UTxO[]>;
112
+ fetchTransactionStatus(txid: string): Promise<TransactionsStatus>;
113
+ submitTx(tx: string): Promise<string>;
114
+ }
115
+
116
+ /**
117
+ * https://github.com/Blockstream/esplora/blob/master/API.md
118
+ */
119
+ declare class BlockstreamProvider implements IBitcoinProvider {
120
+ private readonly _axiosInstance;
121
+ constructor(network?: "mainnet" | "testnet");
122
+ /**
123
+ * Get information about an address.
124
+ * @param address - The address.
125
+ * @returns AddressInfo
126
+ */
127
+ fetchAddress(address: string): Promise<AddressInfo>;
128
+ /**
129
+ * Get transaction history for the specified address, sorted with newest first.
130
+ * Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using `last_seen_txid`.
131
+ * @param address - The address.
132
+ * @param last_seen_txid - The last seen transaction ID (optional).
133
+ * @returns TransactionsInfo[]
134
+ */
135
+ fetchAddressTransactions(address: string, last_seen_txid?: string): Promise<TransactionsInfo[]>;
136
+ /**
137
+ * Get the list of unspent transaction outputs associated with the address.
138
+ * @param address - The address.
139
+ * @returns UTxO[]
140
+ */
141
+ fetchAddressUTxOs(address: string): Promise<UTxO[]>;
142
+ /**
143
+ * Get information about a scripthash.
144
+ * @param hash - The hash of the script.
145
+ * @returns ScriptInfo
146
+ */
147
+ fetchScript(hash: string): Promise<ScriptInfo>;
148
+ /**
149
+ * Get transaction history for the specified scripthash, sorted with newest first.
150
+ * Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using `last_seen_txid`.
151
+ * @param hash - The hash of the script.
152
+ * @param last_seen_txid - The last seen transaction ID (optional).
153
+ * @returns TransactionsInfo[]
154
+ */
155
+ fetchScriptTransactions(hash: string, last_seen_txid?: string): Promise<TransactionsInfo[]>;
156
+ /**
157
+ * Get the list of unspent transaction outputs associated with the scripthash.
158
+ * @param hash - The hash of the script.
159
+ * @returns UTxO[]
160
+ */
161
+ fetchScriptUTxOs(hash: string): Promise<UTxO[]>;
162
+ /**
163
+ * Fetches the status of a transaction
164
+ * @param txid - The transaction ID.
165
+ * @returns TransactionsStatus
166
+ */
167
+ fetchTransactionStatus(txid: string): Promise<TransactionsStatus>;
168
+ /**
169
+ * Broadcast a raw transaction to the network.
170
+ * The transaction should be provided as hex in the request body. The txid will be returned on success.
171
+ * @param tx - The transaction in hex format.
172
+ * @returns The transaction ID.
173
+ */
174
+ submitTx(tx: string): Promise<string>;
175
+ }
176
+
177
+ declare class BrowserWallet implements IBitcoinWallet {
178
+ private readonly _purposes;
179
+ constructor(purposes: string[]);
180
+ /**
181
+ * This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the dApp to use.
182
+ * @param message - A message to display to the user when requesting permission to connect the wallet.
183
+ * @param purposes - An array of purposes for which the wallet is being connected. Default is `["payment"]`. Options are `["payment", "ordinals", "stacks"]`.
184
+ * @returns
185
+ */
186
+ static enable(message: string, purposes?: string[]): Promise<BrowserWallet>;
187
+ getAddresses(): Promise<Address[] | undefined>;
188
+ getChangeAddress(): Promise<string>;
189
+ getCollateral(): Promise<never[]>;
190
+ getNetworkId(): Promise<0 | 1>;
191
+ request(method: string, params?: any): Promise<any>;
192
+ signData(payload: string, address?: string, addressType?: "p2wpkh" | "p2tr" | "stacks"): Promise<{
193
+ address: string;
194
+ signature: string;
195
+ messageHash: string;
196
+ } | undefined>;
197
+ signTx(signedTx: string): Promise<string>;
198
+ submitTx(signedTx: string): Promise<string>;
199
+ }
200
+
201
+ type CreateBitcoinEmbeddedWalletOptions = {
202
+ networkId: 0 | 1;
203
+ key: {
204
+ type: "mnemonic";
205
+ words: string[];
206
+ };
207
+ provider?: IBitcoinProvider;
208
+ };
209
+ /**
210
+ * 0': Indicates the Bitcoin mainnet.
211
+ * 1': Indicates the Bitcoin testnet.
212
+ *
213
+ * EmbeddedWallet is a class that provides a simple interface to interact with Bitcoin wallets.
214
+ *
215
+ * @params options - The options to create an EmbeddedWallet.
216
+ * networkId - The network ID of the wallet.
217
+ * key - The key to create the wallet.
218
+ * provider - The Bitcoin provider to interact with the Bitcoin network.
219
+ */
220
+ declare class EmbeddedWallet {
221
+ private readonly _networkId;
222
+ private readonly _BIP32Interface;
223
+ private readonly _p2wpkh;
224
+ private readonly _provider?;
225
+ constructor(options: CreateBitcoinEmbeddedWalletOptions);
226
+ /**
227
+ * Get wallet network ID.
228
+ *
229
+ * @returns network ID
230
+ */
231
+ getNetworkId(): 0 | 1;
232
+ getPaymentAddress(): Address;
233
+ getPublicKey(): string;
234
+ /**
235
+ * Get UTXOs for the wallet address.
236
+ * @returns An array of UTXOs.
237
+ */
238
+ getUtxos(): Promise<UTxO[]>;
239
+ /**
240
+ * Signs a given message using the wallet's private key.
241
+ *
242
+ * @param message - The message to be signed.
243
+ * @returns The signature of the message as a string.
244
+ */
245
+ signData(message: string): string;
246
+ /**
247
+ * Sign a transaction payload.
248
+ * @param payload - The transaction payload to sign.
249
+ * @returns The signed transaction in hex format.
250
+ */
251
+ signTx(payload: bitcoin.Transaction): string;
252
+ /**
253
+ * Generate mnemonic or private key
254
+ *
255
+ * @param privateKey return private key if true
256
+ * @returns a transaction hash
257
+ */
258
+ static brew(strength?: number): string[];
259
+ }
260
+
261
+ export { type Address, BlockstreamProvider, BrowserWallet, type CreateBitcoinEmbeddedWalletOptions, ECPair, EmbeddedWallet, type IBitcoinWallet, type UTxO, bip32 };