@meshsdk/wallet 1.9.0 → 2.0.0-beta.10

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/index.d.ts CHANGED
@@ -1,7 +1,151 @@
1
- import { DataSignature, ISigner, ISubmitter, IFetcher, IWallet, Wallet, Extension, Asset, UTxO, AssetExtended } from '@meshsdk/common';
2
- import { Ed25519PublicKeyHex, TransactionUnspentOutput, Address, Ed25519PrivateKey, DRepID, Ed25519KeyHashHex, VkeyWitness } from '@meshsdk/core-cst';
3
- import * as _simplewebauthn_browser from '@simplewebauthn/browser';
1
+ import { DataSignature, Extension as Extension$1, UTxO as UTxO$1, Asset, IFetcher, ISubmitter } from '@meshsdk/common';
2
+ import { Network, Signer, Psbt } from 'bitcoinjs-lib';
3
+ import { BIP32Interface } from 'bip32';
4
4
 
5
+ interface ISigner {
6
+ getPublicKey(): Promise<string>;
7
+ getPublicKeyHash(): Promise<string>;
8
+ sign(data: string): Promise<string>;
9
+ verify(data: string, signature: string): Promise<boolean>;
10
+ }
11
+
12
+ type DerivationPath = number[] | string;
13
+ interface ISecretManager {
14
+ getPublicKey(derivationPath: DerivationPath): Promise<string>;
15
+ getSigner(derivationPath: DerivationPath): Promise<ISigner>;
16
+ }
17
+
18
+ declare class CardanoInMemoryBip32 implements ISecretManager {
19
+ private bip32PrivateKey;
20
+ private constructor();
21
+ static fromMnemonic(mnemonic: string[], password?: string): Promise<CardanoInMemoryBip32>;
22
+ static fromEntropy(entropy: string, password?: string): Promise<CardanoInMemoryBip32>;
23
+ static fromKeyHex(keyHex: string): CardanoInMemoryBip32;
24
+ static fromBech32(bech32: string): CardanoInMemoryBip32;
25
+ /**
26
+ * Get the Bip32 public key in hex format.
27
+ * @returns {Promise<string>} A promise that resolves to the public key in hex format.
28
+ */
29
+ getPublicKey(): Promise<string>;
30
+ /**
31
+ * Get an ISigner instance initialized with the current Bip32 private key.
32
+ * @returns {Promise<ISigner>} A promise that resolves to an ISigner instance initialized with the current Bip32 private key.
33
+ */
34
+ getSigner(derivationPath: DerivationPath): Promise<ISigner>;
35
+ }
36
+
37
+ declare class BitcoinInMemoryBip32 {
38
+ private root;
39
+ private constructor();
40
+ static fromMnemonic(mnemonic: string[], password?: string): Promise<BitcoinInMemoryBip32>;
41
+ static fromEntropy(entropy: string, password?: string): Promise<BitcoinInMemoryBip32>;
42
+ /**
43
+ * Get the private key (hex) for the provided derivation path.
44
+ */
45
+ getPrivateKey(derivationPath: DerivationPath): string;
46
+ /**
47
+ * Get the public key (hex) for the provided derivation path.
48
+ */
49
+ getPublicKey(derivationPath: DerivationPath): string;
50
+ }
51
+
52
+ /**
53
+ * BaseSigner provides functionalities to sign and verify data using Ed25519 keys.
54
+ * It supports construction from both extended and normal private key hex formats.
55
+ */
56
+ declare class BaseSigner implements ISigner {
57
+ private ed25519PrivateKey;
58
+ private constructor();
59
+ /**
60
+ * Create a BaseSigner instance from an Ed25519 private key in extended hex format.
61
+ * @param keyHex Ed25519 private key in extended hex format
62
+ * @returns {BaseSigner} A BaseSigner instance
63
+ */
64
+ static fromExtendedKeyHex(keyHex: string): BaseSigner;
65
+ /**
66
+ * Create a BaseSigner instance from an Ed25519 private key in normal hex format.
67
+ * @param keyHex Ed25519 private key in normal hex format
68
+ * @returns {BaseSigner} A BaseSigner instance
69
+ */
70
+ static fromNormalKeyHex(keyHex: string): BaseSigner;
71
+ static fromKeyHex(keyHex: string): BaseSigner;
72
+ /**
73
+ * Get the Ed25519 public key in hex format.
74
+ * @returns {Promise<string>} A promise that resolves to the public key in hex format.
75
+ */
76
+ getPublicKey(): Promise<string>;
77
+ /**
78
+ * Get the Ed25519 public key hash in hex format.
79
+ * @returns {Promise<string>} A promise that resolves to the public key hash in hex format.
80
+ */
81
+ getPublicKeyHash(): Promise<string>;
82
+ /**
83
+ * Sign data using the Ed25519 private key.
84
+ * @param data data to be signed in hex format
85
+ * @returns {Promise<string>} A promise that resolves to the signature in hex format.
86
+ */
87
+ sign(data: string): Promise<string>;
88
+ /**
89
+ * Verify a signature using the Ed25519 public key.
90
+ * @param data The original data in hex format.
91
+ * @param signature The signature to verify in hex format.
92
+ * @returns {Promise<boolean>} A promise that resolves to true if the signature is valid, false otherwise.
93
+ */
94
+ verify(data: string, signature: string): Promise<boolean>;
95
+ }
96
+
97
+ declare enum CredentialType {
98
+ KeyHash = 0,
99
+ ScriptHash = 1
100
+ }
101
+ type Credential = {
102
+ type: CredentialType;
103
+ hash: string;
104
+ };
105
+ declare enum AddressType$1 {
106
+ Enterprise = 0,
107
+ Base = 1,
108
+ Reward = 2
109
+ }
110
+ declare class CardanoAddress {
111
+ addressType: AddressType$1;
112
+ networkId: number;
113
+ paymentCredential: Credential;
114
+ stakeCredential?: Credential;
115
+ constructor(addressType: AddressType$1, networkId: number, paymentCredential: Credential, stakeCredential?: Credential);
116
+ getAddressBech32(): string;
117
+ getAddressHex(): string;
118
+ private getEnterpriseAddressBech32;
119
+ private getEnterpriseAddressHex;
120
+ private getBaseAddressBech32;
121
+ private getBaseAddressHex;
122
+ private getRewardAddressBech32;
123
+ private getRewardAddressHex;
124
+ }
125
+
126
+ interface ICardanoWallet {
127
+ getExtensions(): Promise<{
128
+ cip: number;
129
+ }[]>;
130
+ getNetworkId(): Promise<number>;
131
+ getUtxos(): Promise<string[]>;
132
+ getCollateral(): Promise<string[]>;
133
+ getBalance(): Promise<string>;
134
+ getUsedAddresses(): Promise<string[]>;
135
+ getUnusedAddresses(): Promise<string[]>;
136
+ getRewardAddresses(): Promise<string[]>;
137
+ getChangeAddress(): Promise<string>;
138
+ signTx(data: string, partialSign: boolean): Promise<string>;
139
+ signData(addressHex: string, data: string): Promise<DataSignature>;
140
+ submitTx(tx: string): Promise<string>;
141
+ }
142
+
143
+ type Wallet = {
144
+ id: string;
145
+ name: string;
146
+ icon: string;
147
+ version: string;
148
+ };
5
149
  type Cardano = {
6
150
  [key: string]: {
7
151
  name: string;
@@ -11,130 +155,32 @@ type Cardano = {
11
155
  extensions: {
12
156
  cip: number;
13
157
  }[];
14
- }) => Promise<WalletInstance>;
158
+ }) => Promise<ICardanoWallet>;
15
159
  supportedExtensions?: {
16
160
  cip: number;
17
161
  }[];
18
162
  };
19
163
  };
20
- type TransactionSignatureRequest = {
21
- cbor: string;
22
- partialSign: boolean;
164
+ type Extension = {
165
+ cip: number;
23
166
  };
24
- interface Cip30WalletApi {
25
- experimental: ExperimentalFeatures;
26
- getBalance(): Promise<string>;
27
- getChangeAddress(): Promise<string>;
167
+ declare class CardanoBrowserWallet implements ICardanoWallet {
168
+ walletInstance: ICardanoWallet;
169
+ constructor(walletInstance: ICardanoWallet);
28
170
  getExtensions(): Promise<{
29
171
  cip: number;
30
172
  }[]>;
31
- getCollateral(): Promise<string[] | undefined>;
32
173
  getNetworkId(): Promise<number>;
33
- getRewardAddresses(): Promise<string[]>;
34
- getUnusedAddresses(): Promise<string[]>;
174
+ getUtxos(): Promise<string[]>;
175
+ getCollateral(): Promise<string[]>;
176
+ getBalance(): Promise<string>;
35
177
  getUsedAddresses(): Promise<string[]>;
36
- getUtxos(): Promise<string[] | undefined>;
37
- signData(address: string, payload: string): Promise<DataSignature>;
38
- signTx(tx: string, partialSign: boolean): Promise<string>;
39
- signTxs?(txs: TransactionSignatureRequest[]): Promise<string[]>;
40
- signTxs?(txs: string[], partialSign: boolean): Promise<string[]>;
41
- submitTx(tx: string): Promise<string>;
42
- cip95?: Cip95WalletApi;
43
- }
44
- interface Cip95WalletApi {
45
- getRegisteredPubStakeKeys: () => Promise<Ed25519PublicKeyHex[]>;
46
- getUnregisteredPubStakeKeys: () => Promise<Ed25519PublicKeyHex[]>;
47
- getPubDRepKey: () => Promise<Ed25519PublicKeyHex>;
48
- signData(address: string, payload: string): Promise<DataSignature>;
49
- }
50
- type WalletInstance = Cip30WalletApi & Cip95WalletApi;
51
- type ExperimentalFeatures = {
52
- getCollateral(): Promise<string[] | undefined>;
53
- signTxs?(txs: TransactionSignatureRequest[]): Promise<string[]>;
54
- signTxs?(txs: string[], partialSign: boolean): Promise<string[]>;
55
- };
56
- type GetAddressType = "enterprise" | "payment";
57
-
58
- type AppWalletKeyType = {
59
- type: "root";
60
- bech32: string;
61
- } | {
62
- type: "cli";
63
- payment: string;
64
- stake?: string;
65
- } | {
66
- type: "mnemonic";
67
- words: string[];
68
- };
69
- type CreateAppWalletOptions = {
70
- networkId: number;
71
- fetcher?: IFetcher;
72
- submitter?: ISubmitter;
73
- key: AppWalletKeyType;
74
- };
75
- declare class AppWallet implements ISigner, ISubmitter {
76
- private readonly _fetcher?;
77
- private readonly _submitter?;
78
- private readonly _wallet;
79
- constructor(options: CreateAppWalletOptions);
80
- /**
81
- * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
82
- * @returns void
83
- */
84
- init(): Promise<void>;
85
- /**
86
- * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
87
- *
88
- * This is used in transaction building.
89
- *
90
- * @returns a list of UTXOs
91
- */
92
- getCollateralUnspentOutput(accountIndex?: number, addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
93
- getEnterpriseAddress(accountIndex?: number, keyIndex?: number): string;
94
- getPaymentAddress(accountIndex?: number, keyIndex?: number): string;
95
- getRewardAddress(accountIndex?: number, keyIndex?: number): string;
96
- getNetworkId(): number;
97
- getUsedAddress(accountIndex?: number, keyIndex?: number, addressType?: GetAddressType): Address;
98
- getUnspentOutputs(accountIndex?: number, addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
99
- signData(address: string, payload: string, accountIndex?: number, keyIndex?: number): Promise<DataSignature>;
100
- signTx(unsignedTx: string, partialSign?: boolean, returnFullTx?: boolean, accountIndex?: number, keyIndex?: number): Promise<string>;
101
- signTxSync(unsignedTx: string, partialSign?: boolean, accountIndex?: number, keyIndex?: number): string;
102
- signTxs(unsignedTxs: string[], partialSign: boolean): Promise<string[]>;
178
+ getUnusedAddresses(): Promise<string[]>;
179
+ getRewardAddresses(): Promise<string[]>;
180
+ getChangeAddress(): Promise<string>;
181
+ signTx(data: string, partialSign: boolean): Promise<string>;
182
+ signData(addressBech32: string, data: string): Promise<DataSignature>;
103
183
  submitTx(tx: string): Promise<string>;
104
- static brew(strength?: number): string[];
105
- }
106
-
107
- declare global {
108
- interface Window {
109
- cardano: Cardano;
110
- }
111
- }
112
- /**
113
- * Browser Wallet provides a set of APIs to interact with the blockchain. This wallet is compatible with Mesh transaction builders.
114
- *
115
- * These wallets APIs are in accordance to CIP-30, which defines the API for apps to communicate with the user's wallet. Additional utility functions provided for developers that are useful for building applications.
116
- * ```javascript
117
- * import { BrowserWallet } from '@meshsdk/core';
118
- *
119
- * const wallet = await BrowserWallet.enable('eternl');
120
- * ```
121
- */
122
- declare class BrowserWallet implements IWallet {
123
- readonly _walletInstance: WalletInstance;
124
- readonly _walletName: string;
125
- walletInstance: WalletInstance;
126
- private constructor();
127
- /**
128
- * Returns a list of wallets installed on user's device. Each wallet is an object with the following properties:
129
- * - A name is provided to display wallet's name on the user interface.
130
- * - A version is provided to display wallet's version on the user interface.
131
- * - An icon is provided to display wallet's icon on the user interface.
132
- *
133
- * @returns a list of wallet names
134
- */
135
- static getAvailableWallets({ injectFn, }?: {
136
- injectFn?: () => Promise<void>;
137
- }): Promise<Wallet[]>;
138
184
  /**
139
185
  * Returns a list of wallets installed on user's device. Each wallet is an object with the following properties:
140
186
  * - A name is provided to display wallet's name on the user interface.
@@ -153,650 +199,1061 @@ declare class BrowserWallet implements IWallet {
153
199
  * @param extensions - optional, a list of CIPs that the wallet should support
154
200
  * @returns WalletInstance
155
201
  */
156
- static enable(walletName: string, extensions?: Extension[]): Promise<BrowserWallet>;
202
+ static enable(walletName: string, extensions?: Extension[]): Promise<ICardanoWallet>;
203
+ }
204
+
205
+ declare class MeshCardanoBrowserWallet extends CardanoBrowserWallet {
206
+ constructor(walletInstance: ICardanoWallet);
207
+ static enable(walletName: string, extensions?: Extension$1[]): Promise<MeshCardanoBrowserWallet>;
208
+ getUtxosMesh(): Promise<UTxO$1[]>;
209
+ getCollateralMesh(): Promise<UTxO$1[]>;
210
+ getBalanceMesh(): Promise<Asset[]>;
211
+ getUsedAddressesBech32(): Promise<string[]>;
212
+ getUnusedAddressesBech32(): Promise<string[]>;
213
+ getChangeAddressBech32(): Promise<string>;
214
+ getRewardAddressesBech32(): Promise<string[]>;
215
+ signTxReturnFullTx(tx: string, partialSign?: boolean): Promise<string>;
216
+ }
217
+
218
+ type CredentialSource = {
219
+ type: "signer";
220
+ signer: ISigner;
221
+ } | {
222
+ type: "scriptHash";
223
+ scriptHash: string;
224
+ };
225
+ interface AddressManagerConfig {
226
+ addressSource: AddressSource;
227
+ networkId: number;
228
+ }
229
+ type AddressSource = {
230
+ type: "secretManager";
231
+ secretManager: ISecretManager;
232
+ } | {
233
+ type: "credentials";
234
+ paymentCredential: CredentialSource;
235
+ stakeCredential?: CredentialSource;
236
+ drepCredential?: CredentialSource;
237
+ };
238
+ declare class AddressManager {
239
+ private readonly paymentCredential;
240
+ private readonly stakeCredential;
241
+ private readonly drepCredential;
242
+ private readonly paymentSigner;
243
+ private readonly stakeSigner?;
244
+ private readonly drepSigner?;
245
+ private readonly networkId;
246
+ static create(config: AddressManagerConfig): Promise<AddressManager>;
247
+ private constructor();
248
+ getNextAddress(addressType: AddressType$1): Promise<CardanoAddress>;
249
+ getChangeAddress(addressType: AddressType$1): Promise<CardanoAddress>;
250
+ getRewardAccount(): Promise<CardanoAddress>;
251
+ asyncGetAllUsedAddresses(): Promise<CardanoAddress[]>;
252
+ getCredentialsSigners(pubkeyHashes: Set<string>): Promise<Map<string, ISigner>>;
253
+ }
254
+
255
+ type WalletAddressType = AddressType$1.Base | AddressType$1.Enterprise;
256
+ /**
257
+ * Configuration for creating a CardanoHeadlessWallet instance.
258
+ */
259
+ interface CardanoHeadlessWalletConfig {
260
+ /**
261
+ * The source for wallet's signing keys and addresses. Could either be a secret manager or explicit credentials.
262
+ */
263
+ addressSource: AddressSource;
157
264
  /**
158
- * Returns a list of assets in the wallet. This API will return every assets in the wallet. Each asset is an object with the following properties:
159
- * - A unit is provided to display asset's name on the user interface.
160
- * - A quantity is provided to display asset's quantity on the user interface.
161
- *
162
- * @returns a list of assets and their quantities
265
+ * The network ID (0 for testnet, 1 for mainnet).
163
266
  */
164
- getBalance(): Promise<Asset[]>;
267
+ networkId: number;
165
268
  /**
166
- * Returns an address owned by the wallet that should be used as a change address to return leftover assets during transaction creation back to the connected wallet.
167
- *
168
- * @returns an address
269
+ * The type of wallet address to use (Base or Enterprise).
270
+ * Base addresses include staking capabilities, while Enterprise addresses do not.
169
271
  */
170
- getChangeAddress(): Promise<string>;
272
+ walletAddressType: WalletAddressType;
171
273
  /**
172
- * This function shall return a list of one or more UTXOs (unspent transaction outputs) controlled by the wallet that are required to reach AT LEAST the combined ADA value target specified in amount AND the best suitable to be used as collateral inputs for transactions with plutus script inputs (pure ADA-only UTXOs).
173
- *
174
- * If this cannot be attained, an error message with an explanation of the blocking problem shall be returned. NOTE: wallets are free to return UTXOs that add up to a greater total ADA value than requested in the amount parameter, but wallets must never return any result where UTXOs would sum up to a smaller total ADA value, instead in a case like that an error message must be returned.
175
- *
176
- * @param limit
177
- * @returns a list of UTXOs
274
+ * Optional fetcher instance for querying blockchain data (UTxOs, protocol parameters, etc.).
178
275
  */
179
- getCollateral(): Promise<UTxO[]>;
276
+ fetcher?: IFetcher;
180
277
  /**
181
- * Return a list of supported CIPs of the wallet.
182
- *
183
- * @returns a list of CIPs
278
+ * Optional submitter instance for submitting transactions to the blockchain.
184
279
  */
185
- getExtensions(): Promise<number[]>;
280
+ submitter?: ISubmitter;
281
+ }
282
+ declare class CardanoHeadlessWallet implements ICardanoWallet {
283
+ protected networkId: number;
284
+ protected addressManager: AddressManager;
285
+ protected fetcher?: IFetcher;
286
+ protected submitter?: ISubmitter;
287
+ protected walletAddressType: WalletAddressType;
288
+ protected constructor(networkId: number, addressManager: AddressManager, walletAddressType: WalletAddressType, fetcher?: IFetcher, submitter?: ISubmitter);
289
+ static create(config: CardanoHeadlessWalletConfig): Promise<CardanoHeadlessWallet>;
186
290
  /**
187
- * Returns the network ID of the currently connected account. 0 is testnet and 1 is mainnet but other networks can possibly be returned by wallets. Those other network ID values are not governed by CIP-30. This result will stay the same unless the connected account has changed.
188
- *
189
- * @returns network ID
291
+ * Create a CardanoHeadlessWallet instance from a Bip32 root in Bech32 format.
292
+ * @param config The configuration object
293
+ * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
294
+ */
295
+ static fromBip32Root(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
296
+ bech32: string;
297
+ }): Promise<CardanoHeadlessWallet>;
298
+ /**
299
+ * Create a CardanoHeadlessWallet instance from a Bip32 root in hex format.
300
+ * @param config The configuration object
301
+ * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
302
+ */
303
+ static fromBip32RootHex(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
304
+ hex: string;
305
+ }): Promise<CardanoHeadlessWallet>;
306
+ /**
307
+ * Create a CardanoHeadlessWallet instance from a mnemonic phrase.
308
+ * @param config The configuration object
309
+ * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
310
+ */
311
+ static fromMnemonic(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
312
+ mnemonic: string[];
313
+ password?: string;
314
+ }): Promise<CardanoHeadlessWallet>;
315
+ static fromCredentialSources(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
316
+ paymentCredentialSource: CredentialSource;
317
+ stakeCredentialSource?: CredentialSource;
318
+ drepCredentialSource?: CredentialSource;
319
+ }): Promise<CardanoHeadlessWallet>;
320
+ /**
321
+ * Submit a transaction to the network, using the submitter instance.
322
+ * @param tx The transaction in CBOR hex format
323
+ * @returns {Promise<string>} A promise that resolves to the transaction ID
324
+ */
325
+ submitTx(tx: string): Promise<string>;
326
+ /**
327
+ * Get the list of extensions enabled for this wallet.
328
+ * @returns {Promise<{ cip: number }[]>} A promise that resolves to an array of enabled extensions
329
+ */
330
+ getExtensions(): Promise<{
331
+ cip: number;
332
+ }[]>;
333
+ /**
334
+ * Get the network ID.
335
+ * @returns {number} The network ID
190
336
  */
191
337
  getNetworkId(): Promise<number>;
192
338
  /**
193
- * Returns a list of reward addresses owned by the wallet. A reward address is a stake address that is used to receive rewards from staking, generally starts from `stake` prefix.
339
+ * Get the UTxOs for the wallet.
340
+ *
341
+ * NOTE: This method is only an approximation to CIP-30 getUtxos, as this wallet is completely
342
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
343
+ * will be overlap between getUtxos() and getCollateral() results. This can result in the collateral being
344
+ * spent between transactions.
194
345
  *
195
- * @returns a list of reward addresses
346
+ * The method also does not perform pagination, nor is there a coin selection mechanism.
347
+ * @returns {Promise<string[]>} A promise that resolves to an array of UTxOs in CBOR hex format
196
348
  */
197
- getRewardAddresses(): Promise<string[]>;
349
+ getUtxos(): Promise<string[]>;
198
350
  /**
199
- * Returns a list of unused addresses controlled by the wallet.
351
+ * Get the collateral UTxOs for the wallet.
200
352
  *
201
- * @returns a list of unused addresses
353
+ * NOTE: This method is only an approximation to CIP-30 getCollateral, as this wallet is completely
354
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
355
+ * will be overlap between getUtxos() and getCollateral() results.
356
+ *
357
+ * The basic strategy is to return the smallest pure ADA UTxO that is at least 5 ADA belonging to the wallet.
358
+ * @returns {Promise<string[]>} A promise that resolves to an array of UTxOs in CBOR hex format
202
359
  */
203
- getUnusedAddresses(): Promise<string[]>;
360
+ getCollateral(): Promise<string[]>;
204
361
  /**
205
- * Returns a list of used addresses controlled by the wallet.
362
+ * Get the balance of the wallet.
206
363
  *
207
- * @returns a list of used addresses
364
+ * NOTE: This method is only an approximation to CIP-30 getBalance, as this wallet is completely
365
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means the balance
366
+ * returned includes all UTxOs, including those that may be used as collateral.
367
+ * @returns {Promise<string>} A promise that resolves to the balance in CBOR hex format
208
368
  */
209
- getUsedAddresses(): Promise<string[]>;
369
+ getBalance(): Promise<string>;
210
370
  /**
211
- * Return a list of all UTXOs (unspent transaction outputs) controlled by the wallet.
371
+ * Get the used addresses for the wallet.
372
+ *
373
+ * NOTE: This method completely deviates from CIP-30 getUsedAddresses, as this wallet is stateless
374
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
212
375
  *
213
- * @returns a list of UTXOs
376
+ * It will be effective to be used as a single address wallet.
377
+ *
378
+ * @returns {Promise<string[]>} A promise that resolves to an array of used addresses in hex format
214
379
  */
215
- getUtxos(): Promise<UTxO[]>;
380
+ getUsedAddresses(): Promise<string[]>;
216
381
  /**
217
- * This endpoint utilizes the [CIP-8 - Message Signing](https://cips.cardano.org/cips/cip8/) to sign arbitrary data, to verify the data was signed by the owner of the private key.
382
+ * Get the unused addresses for the wallet.
218
383
  *
219
- * @param payload - the data to be signed
220
- * @param address - optional, if not provided, the first staking address will be used
221
- * @returns a signature
384
+ * NOTE: This method completely deviates from CIP-30 getUnusedAddresses, as this wallet is stateless
385
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
386
+ *
387
+ * It will be effective to be used as a single address wallet.
388
+ *
389
+ * @returns {Promise<string[]>} A promise that resolves to an array of unused addresses in hex format
222
390
  */
223
- signData(payload: string, address?: string | undefined, convertFromUTF8?: boolean): Promise<DataSignature>;
391
+ getUnusedAddresses(): Promise<string[]>;
224
392
  /**
225
- * Requests user to sign the provided transaction (tx). The wallet should ask the user for permission, and if given, try to sign the supplied body and return a signed transaction. partialSign should be true if the transaction provided requires multiple signatures.
393
+ * Get the change address for the wallet.
394
+ * NOTE: This method deviates from CIP-30 getChangeAddress, as this wallet is stateless
395
+ * it does not track which addresses has been previously used as change address. This method simply
396
+ * returns the wallet's main address.
226
397
  *
227
- * @param unsignedTx - a transaction in CBOR
228
- * @param partialSign - if the transaction is signed partially
229
- * @param returnFullTx - if the full tx should be returned or only the witness set (default: true)
230
- * @returns a signed transaction in CBOR
398
+ * It will be effective to be used as a single address wallet.
399
+ *
400
+ * @returns {Promise<string>} A promise that resolves to the change address in hex format
231
401
  */
232
- signTx(unsignedTx: string, partialSign?: boolean, returnFullTx?: boolean): Promise<string>;
402
+ getChangeAddress(): Promise<string>;
233
403
  /**
234
- * Experimental feature - sign multiple transactions at once (Supported wallet(s): Typhon)
404
+ * Get the reward address for the wallet.
235
405
  *
236
- * @param unsignedTxs - array of unsigned transactions in CborHex string
237
- * @param partialSign - if the transactions are signed partially
238
- * @returns array of signed transactions CborHex string
406
+ * @returns {Promise<string[]>} A promise that resolves an array of reward addresses in hex format
239
407
  */
240
- signTxs(unsignedTxs: string[], partialSign?: boolean): Promise<string[]>;
408
+ getRewardAddresses(): Promise<string[]>;
241
409
  /**
242
- * Submits the signed transaction to the blockchain network.
410
+ * Sign a transaction with the wallet.
243
411
  *
244
- * As wallets should already have this ability to submit transaction, we allow apps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the app to track. The wallet can return error messages or failure if there was an error in sending it.
412
+ * NOTE: This method requires a fetcher to resolve input UTxOs for determining required signers.
245
413
  *
246
- * @param tx
247
- * @returns a transaction hash
248
- */
249
- submitTx(tx: string): Promise<string>;
250
- /**
251
- * Get a used address of type Address from the wallet.
414
+ * It is also only an approximation to CIP-30 signTx, as this wallet is stateless and does not repeatedly
415
+ * derive keys, it is unable to sign for multiple derived key indexes.
252
416
  *
253
- * This is used in transaction building.
417
+ * It will be effective to be used as a single address wallet.
254
418
  *
255
- * @returns an Address object
419
+ * @param tx The transaction in CBOR hex format
420
+ * @returns A promise that resolves to a witness set with the signatures in CBOR hex format
256
421
  */
257
- getUsedAddress(): Promise<Address>;
422
+ signTx(tx: string, partialSign?: boolean): Promise<string>;
423
+ signData(addressBech32: string, data: string): Promise<DataSignature>;
424
+ fetchAccountUtxos(): Promise<UTxO$1[]>;
425
+ }
426
+
427
+ /**
428
+ * MeshCardanoHeadlessWallet provides additional convenience methods on top of CardanoHeadlessWallet,
429
+ * such as returning results in Mesh-compatible formats and Bech32 addresses.
430
+ */
431
+ declare class MeshCardanoHeadlessWallet extends CardanoHeadlessWallet {
432
+ static create(config: CardanoHeadlessWalletConfig): Promise<MeshCardanoHeadlessWallet>;
433
+ static fromMnemonic(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
434
+ mnemonic: string[];
435
+ password?: string;
436
+ }): Promise<MeshCardanoHeadlessWallet>;
437
+ static fromBip32Root(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
438
+ bech32: string;
439
+ }): Promise<MeshCardanoHeadlessWallet>;
440
+ static fromBip32RootHex(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
441
+ hex: string;
442
+ }): Promise<MeshCardanoHeadlessWallet>;
443
+ static fromCredentialSources(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
444
+ paymentCredentialSource: CredentialSource;
445
+ stakeCredentialSource?: CredentialSource;
446
+ drepCredentialSource?: CredentialSource;
447
+ }): Promise<MeshCardanoHeadlessWallet>;
258
448
  /**
259
- * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
449
+ * Get the UTxOs for the wallet.
260
450
  *
261
- * This is used in transaction building.
451
+ * NOTE: This method is only an approximation to CIP-30 getUtxos, as this wallet is completely
452
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
453
+ * will be overlap between getUtxos() and getCollateral() results. This can result in the collateral being
454
+ * spent between transactions.
262
455
  *
263
- * @returns a list of UTXOs
456
+ * The method also does not perform pagination, nor is there a coin selection mechanism.
457
+ * @returns {Promise<UTxO[]>} A promise that resolves to an array of UTxOs in the Mesh UTxO format
264
458
  */
265
- getCollateralUnspentOutput(limit?: number): Promise<TransactionUnspentOutput[]>;
459
+ getUtxosMesh(): Promise<UTxO$1[]>;
266
460
  /**
267
- * Get a list of UTXOs to be used for transaction building.
461
+ * Get the collateral UTxOs for the wallet.
268
462
  *
269
- * This is used in transaction building.
463
+ * NOTE: This method is only an approximation to CIP-30 getCollateral, as this wallet is completely
464
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
465
+ * will be overlap between getUtxos() and getCollateral() results.
270
466
  *
271
- * @returns a list of UTXOs
467
+ * The basic strategy is to return the smallest pure ADA UTxO that is at least 5 ADA belonging to the wallet.
468
+ * @returns {Promise<UTxO[]>} A promise that resolves to an array of UTxOs in the Mesh UTxO format
272
469
  */
273
- getUsedUTxOs(): Promise<TransactionUnspentOutput[]>;
470
+ getCollateralMesh(): Promise<UTxO$1[]>;
274
471
  /**
275
- * A helper function to get the assets in the wallet.
472
+ * Get the balance of the wallet.
276
473
  *
277
- * @returns a list of assets
474
+ * NOTE: This method is only an approximation to CIP-30 getBalance, as this wallet is completely
475
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means the balance
476
+ * returned includes all UTxOs, including those that may be used as collateral.
477
+ * @returns {Promise<Asset[]>} A promise that resolves to the balance in the Mesh Asset format
278
478
  */
279
- getAssets(): Promise<AssetExtended[]>;
479
+ getBalanceMesh(): Promise<Asset[]>;
280
480
  /**
281
- * A helper function to get the lovelace balance in the wallet.
481
+ * Get the used addresses for the wallet.
482
+ *
483
+ * NOTE: This method completely deviates from CIP-30 getUsedAddresses, as this wallet is stateless
484
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
485
+ *
486
+ * It will be effective to be used as a single address wallet.
282
487
  *
283
- * @returns lovelace balance
488
+ * @returns {Promise<string[]>} A promise that resolves to an array of used addresses in Bech32 format
284
489
  */
285
- getLovelace(): Promise<string>;
490
+ getUsedAddressesBech32(): Promise<string[]>;
286
491
  /**
287
- * A helper function to get the assets of a specific policy ID in the wallet.
492
+ * Get the unused addresses for the wallet.
288
493
  *
289
- * @param policyId
290
- * @returns a list of assets
494
+ * NOTE: This method completely deviates from CIP-30 getUnusedAddresses, as this wallet is stateless
495
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
496
+ *
497
+ * It will be effective to be used as a single address wallet.
498
+ *
499
+ * @returns {Promise<string[]>} A promise that resolves to an array of unused addresses in Bech32 format
291
500
  */
292
- getPolicyIdAssets(policyId: string): Promise<AssetExtended[]>;
501
+ getUnusedAddressesBech32(): Promise<string[]>;
293
502
  /**
294
- * A helper function to get the policy IDs of all the assets in the wallet.
503
+ * Get the change address for the wallet.
504
+ * NOTE: This method deviates from CIP-30 getChangeAddress, as this wallet is stateless
505
+ * it does not track which addresses has been previously used as change address. This method simply
506
+ * returns the wallet's main address.
507
+ *
508
+ * It will be effective to be used as a single address wallet.
295
509
  *
296
- * @returns a list of policy IDs
510
+ * @returns {Promise<string>} A promise that resolves to the change address in Bech32 format
511
+ */
512
+ getChangeAddressBech32(): Promise<string>;
513
+ /**
514
+ * Get the reward address for the wallet.
515
+ * @returns {Promise<string[]>} A promise that resolves an array of reward addresses in Bech32 format
297
516
  */
298
- getPolicyIds(): Promise<string[]>;
517
+ getRewardAddressesBech32(): Promise<string[]>;
299
518
  /**
300
- * The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
301
- * These are used by the client to identify the user's on-chain CIP-1694 interactions, i.e. if a user has registered to be a DRep.
519
+ * Sign a transaction with the wallet.
302
520
  *
303
- * @returns DRep object
521
+ * NOTE: This method requires a fetcher to resolve input UTxOs for determining required signers.
522
+ *
523
+ * It is also only an approximation to CIP-30 signTx, as this wallet is stateless and does not repeatedly
524
+ * derive keys, it is unable to sign for multiple derived key indexes.
525
+ *
526
+ * It will be effective to be used as a single address wallet.
527
+ *
528
+ * @param tx The transaction in CBOR hex format
529
+ * @returns A promise that resolves to a full transaction with extra vkey witnesses added from the wallet
530
+ * to the witness set in CBOR hex format
304
531
  */
305
- getDRep(): Promise<{
306
- publicKey: string;
307
- publicKeyHash: string;
308
- dRepIDCip105: string;
309
- } | undefined>;
310
- /**
311
- * The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
312
- * These are used by the client to identify the user's on-chain CIP-1694 interactions, i.e. if a user has registered to be a DRep.
313
- *
314
- * @returns wallet account's public DRep Key
315
- */
316
- getPubDRepKey(): Promise<string | undefined>;
317
- getRegisteredPubStakeKeys(): Promise<{
318
- pubStakeKeys: string[];
319
- pubStakeKeyHashes: string[];
320
- } | undefined>;
321
- getUnregisteredPubStakeKeys(): Promise<{
322
- pubStakeKeys: string[];
323
- pubStakeKeyHashes: string[];
324
- } | undefined>;
325
- private static dRepKeyToDRepID;
326
- private static resolveInstance;
327
- static addBrowserWitnesses(unsignedTx: string, witnesses: string): any;
328
- static getSupportedExtensions(wallet: string): {
329
- cip: number;
330
- }[];
532
+ signTxReturnFullTx(tx: string, partialSign?: boolean): Promise<string>;
331
533
  }
332
534
 
333
- declare function connect({ username, password, serverUrl, }: {
334
- username: string;
335
- password: string;
336
- serverUrl: string;
337
- }): Promise<{
338
- success: boolean;
339
- wallet: {
340
- bech32PrivateKey: string;
341
- };
342
- error?: undefined;
343
- } | {
344
- success: boolean;
345
- error: any;
346
- wallet?: undefined;
347
- }>;
535
+ type TransactionsStatus = {
536
+ confirmed: boolean;
537
+ block_height: number;
538
+ block_hash: string;
539
+ block_time: number;
540
+ };
348
541
 
349
- declare function login({ serverUrl, username, }: {
350
- serverUrl: string;
351
- username: string;
352
- }): Promise<{
353
- success: boolean;
354
- error: any;
355
- errorCode: any;
356
- authJSON?: undefined;
357
- } | {
358
- success: boolean;
359
- error: any;
360
- errorCode?: undefined;
361
- authJSON?: undefined;
362
- } | {
363
- success: boolean;
364
- authJSON: _simplewebauthn_browser.AuthenticationResponseJSON;
365
- error?: undefined;
366
- errorCode?: undefined;
367
- }>;
542
+ type TransactionsInfo = {
543
+ txid: string;
544
+ version: number;
545
+ locktime: number;
546
+ vin: {
547
+ txid: string;
548
+ vout: number;
549
+ prevout: {
550
+ scriptpubkey: string;
551
+ scriptpubkey_asm: string;
552
+ scriptpubkey_type: string;
553
+ scriptpubkey_address: string;
554
+ value: number;
555
+ };
556
+ scriptsig: string;
557
+ scriptsig_asm: string;
558
+ witness: string[];
559
+ is_coinbase: boolean;
560
+ sequence: number;
561
+ }[];
562
+ vout: {
563
+ scriptpubkey: string;
564
+ scriptpubkey_asm: string;
565
+ scriptpubkey_type: string;
566
+ scriptpubkey_address: string;
567
+ value: number;
568
+ }[];
569
+ size: number;
570
+ weight: number;
571
+ fee: number;
572
+ status: TransactionsStatus;
573
+ };
368
574
 
369
- declare function register({ serverUrl, username, }: {
370
- serverUrl: string;
371
- username: string;
372
- }): Promise<{
373
- success: boolean;
374
- error: any;
375
- errorCode: any;
376
- } | {
377
- success: boolean;
378
- error?: undefined;
379
- errorCode?: undefined;
380
- }>;
575
+ type UTxO = {
576
+ status: {
577
+ block_hash: string;
578
+ block_height: number;
579
+ block_time: number;
580
+ confirmed: boolean;
581
+ };
582
+ txid: string;
583
+ value: number;
584
+ vout: number;
585
+ };
381
586
 
382
- type AccountType = "payment" | "stake" | "drep";
383
- type Account = {
384
- baseAddress: Address;
385
- enterpriseAddress: Address;
386
- rewardAddress: Address;
387
- baseAddressBech32: string;
388
- enterpriseAddressBech32: string;
389
- rewardAddressBech32: string;
390
- paymentKey: Ed25519PrivateKey;
391
- stakeKey: Ed25519PrivateKey;
392
- paymentKeyHex: string;
393
- stakeKeyHex: string;
394
- drepKey?: Ed25519PrivateKey;
395
- pubDRepKey?: string;
396
- dRepIDBech32?: DRepID;
397
- dRepIDHash?: Ed25519KeyHashHex;
398
- dRepIDCip105?: string;
587
+ declare enum AddressPurpose {
588
+ Ordinals = "ordinals",
589
+ Payment = "payment",
590
+ Stacks = "stacks",
591
+ Starknet = "starknet",
592
+ Spark = "spark"
593
+ }
594
+ declare enum AddressType {
595
+ p2pkh = "p2pkh",
596
+ p2sh = "p2sh",
597
+ p2wpkh = "p2wpkh",
598
+ p2wsh = "p2wsh",
599
+ p2tr = "p2tr",
600
+ stacks = "stacks",
601
+ starknet = "starknet",
602
+ spark = "spark"
603
+ }
604
+ type BitcoinAddress = {
605
+ address: string;
606
+ publicKey: string;
607
+ purpose: AddressPurpose;
608
+ addressType: AddressType;
609
+ walletType: "software" | "ledger" | "keystone";
399
610
  };
400
- type EmbeddedWalletKeyType = {
401
- type: "root";
402
- bech32: string;
403
- } | {
404
- type: "cli";
405
- payment: string;
406
- stake?: string;
407
- } | {
408
- type: "mnemonic";
409
- words: string[];
410
- } | {
411
- type: "bip32Bytes";
412
- bip32Bytes: Uint8Array;
611
+ type BitcoinAccount = {
612
+ walletType: "software" | "ledger" | "keystone";
613
+ address: string;
614
+ publicKey: string;
615
+ purpose: AddressPurpose;
616
+ addressType: AddressType;
413
617
  };
414
- type CreateEmbeddedWalletOptions = {
415
- networkId: number;
416
- key: EmbeddedWalletKeyType;
618
+ type BitcoinBalance = {
619
+ confirmed: string;
620
+ unconfirmed: string;
621
+ total: string;
417
622
  };
418
- declare class WalletStaticMethods {
419
- static privateKeyBech32ToPrivateKeyHex(_bech32: string): string;
420
- static mnemonicToPrivateKeyHex(words: string[]): string;
421
- static signingKeyToHexes(paymentKey: string, stakeKey: string): [string, string];
422
- static bip32BytesToPrivateKeyHex(bip32Bytes: Uint8Array): string;
423
- static getAddresses(paymentKey: Ed25519PrivateKey, stakingKey: Ed25519PrivateKey, networkId?: number): {
424
- baseAddress: Address;
425
- enterpriseAddress: Address;
426
- rewardAddress: Address;
427
- };
428
- static getDRepKey(dRepKey: Ed25519PrivateKey, networkId?: number): {
429
- pubDRepKey: string;
430
- dRepIDBech32: DRepID;
431
- dRepIDHash: Ed25519KeyHashHex;
432
- dRepIDCip105: string;
433
- };
434
- static generateMnemonic(strength?: number): string[];
435
- static addWitnessSets(txHex: string, witnesses: VkeyWitness[]): string;
623
+ declare enum MessageSigningProtocols {
624
+ ECDSA = "ECDSA",
625
+ BIP322 = "BIP322"
436
626
  }
437
- declare class EmbeddedWallet extends WalletStaticMethods {
438
- private readonly _walletSecret?;
439
- private readonly _networkId;
440
- cryptoIsReady: boolean;
441
- constructor(options: CreateEmbeddedWalletOptions);
442
- init(): Promise<void>;
443
- getAccount(accountIndex?: number, keyIndex?: number): Account;
444
- /**
445
- * Get wallet network ID.
446
- *
447
- * @returns network ID
448
- */
449
- getNetworkId(): number;
450
- /**
451
- * This endpoint utilizes the [CIP-8 - Message Signing](https://cips.cardano.org/cips/cip8/) to sign arbitrary data, to verify the data was signed by the owner of the private key.
452
- *
453
- * @param address - bech32 address to sign the data with
454
- * @param payload - the data to be signed
455
- * @param accountIndex account index (default: 0)
456
- * @returns a signature
457
- */
458
- signData(address: string, payload: string, accountIndex?: number, keyIndex?: number): DataSignature;
459
- /**
460
- * This endpoints sign the provided transaction (unsignedTx) with the private key of the owner.
461
- *
462
- * @param unsignedTx - a transaction in CBOR
463
- * @param accountIndex account index (default: 0)
464
- * @param keyIndex key index (default: 0)
465
- * @param accountType - type of the account (default: payment)
466
- * @returns VkeyWitness
467
- */
468
- signTx(unsignedTx: string, accountIndex?: number, keyIndex?: number, accountType?: AccountType): VkeyWitness;
627
+ type BitcoinSignature = {
628
+ signature: string;
629
+ messageHash: string;
630
+ address: string;
631
+ protocol: MessageSigningProtocols;
632
+ };
633
+ type VerifyMessageResult = {
634
+ valid: boolean;
635
+ recoveredPublicKey?: string;
636
+ reason?: string;
637
+ };
638
+ interface IBitcoinWallet {
639
+ getNetwork(): Promise<"Mainnet" | "Testnet4">;
640
+ getAddresses(addressPurposes: AddressPurpose[]): Promise<BitcoinAddress[]>;
641
+ getAccounts(addressPurposes: AddressPurpose[]): Promise<BitcoinAccount[]>;
642
+ getBalance(): Promise<BitcoinBalance>;
643
+ signMessage(address: string, message: string, protocol?: MessageSigningProtocols): Promise<BitcoinSignature>;
644
+ verifyMessage(address: string, message: string, signature: string): Promise<VerifyMessageResult>;
645
+ signTransfer(recipients: {
646
+ address: string;
647
+ amount: number;
648
+ }[]): Promise<string>;
649
+ signPsbt(signConfig: {
650
+ psbt: string;
651
+ signInputs?: {
652
+ [x: string]: number[];
653
+ } | undefined;
654
+ broadcast?: boolean | undefined;
655
+ }): Promise<string>;
656
+ fetchUTXOs(purposes?: AddressPurpose[]): Promise<(UTxO & {
657
+ address: string;
658
+ purpose: AddressPurpose;
659
+ })[]>;
660
+ getTransactionHistory(options?: {
661
+ purposes?: AddressPurpose[];
662
+ lastSeenTxid?: string;
663
+ }): Promise<(TransactionsInfo & {
664
+ address: string;
665
+ purpose: AddressPurpose;
666
+ })[]>;
469
667
  }
470
668
 
471
- type CreateMeshWalletOptions = {
472
- networkId: 0 | 1;
473
- fetcher?: IFetcher;
474
- submitter?: ISubmitter;
475
- key: {
476
- type: "root";
477
- bech32: string;
478
- } | {
479
- type: "cli";
480
- payment: string;
481
- stake?: string;
482
- } | {
483
- type: "mnemonic";
484
- words: string[];
485
- } | {
486
- type: "bip32Bytes";
487
- bip32Bytes: Uint8Array;
488
- } | {
489
- type: "address";
490
- address: string;
491
- };
492
- accountIndex?: number;
493
- keyIndex?: number;
494
- accountType?: AccountType;
669
+ type ChainStats = {
670
+ funded_txo_count: number;
671
+ funded_txo_sum: number;
672
+ spent_txo_count: number;
673
+ spent_txo_sum: number;
674
+ tx_count: number;
675
+ };
676
+
677
+ type MempoolStats = {
678
+ funded_txo_count: number;
679
+ funded_txo_sum: number;
680
+ spent_txo_count: number;
681
+ spent_txo_sum: number;
682
+ tx_count: number;
683
+ };
684
+
685
+ type AddressInfo = {
686
+ address: string;
687
+ chain_stats: ChainStats;
688
+ mempool_stats: MempoolStats;
689
+ };
690
+
691
+ type ScriptInfo = {
692
+ scripthash: string;
693
+ chain_stats: ChainStats;
694
+ mempool_stats: MempoolStats;
495
695
  };
696
+
496
697
  /**
497
- * Mesh Wallet provides a set of APIs to interact with the blockchain. This wallet is compatible with Mesh transaction builders.
498
- *
499
- * There are 4 types of keys that can be used to create a wallet:
500
- * - root: A private key in bech32 format, generally starts with `xprv1`
501
- * - cli: CLI generated keys starts with `5820`. Payment key is required, and the stake key is optional.
502
- * - mnemonic: A list of 24 words
503
- * - address: A bech32 address that can be used to create a read-only wallet, generally starts with `addr` or `addr_test1`
504
- *
505
- * ```javascript
506
- * import { MeshWallet, BlockfrostProvider } from '@meshsdk/core';
507
- *
508
- * const provider = new BlockfrostProvider('<BLOCKFROST_API_KEY>');
698
+ * Read-only chain data queries for Bitcoin addresses and scripts.
699
+ * Mirrors the Mesh `IFetcher` interface shape for Cardano, adapted to Bitcoin.
700
+ * Only the methods relevant to Bitcoin are included; script variants are optional
701
+ * because P2SH/P2WSH usage is uncommon in most dApp workflows.
702
+ */
703
+ interface IBitcoinFetcher {
704
+ fetchAddressInfo(address: string): Promise<AddressInfo>;
705
+ fetchAddressUTxOs(address: string): Promise<UTxO[]>;
706
+ fetchUTxO(txid: string, vout?: number): Promise<UTxO[]>;
707
+ fetchAddressTxs(address: string, lastSeenTxid?: string): Promise<TransactionsInfo[]>;
708
+ fetchTxInfo(txid: string): Promise<TransactionsStatus>;
709
+ fetchFeeEstimates(blocks: number): Promise<number>;
710
+ fetchScriptInfo?(hash: string): Promise<ScriptInfo>;
711
+ fetchScriptUTxOs?(hash: string): Promise<UTxO[]>;
712
+ fetchScriptTxs?(hash: string, lastSeenTxid?: string): Promise<TransactionsInfo[]>;
713
+ }
714
+ interface IBitcoinSubmitter {
715
+ submitTx(tx: string): Promise<string>;
716
+ }
717
+ interface IBitcoinProvider extends IBitcoinFetcher, IBitcoinSubmitter {
718
+ }
719
+
720
+ type RecoveryId = 0 | 1 | 2 | 3;
721
+
722
+ type BitcoinNetworkName = "Mainnet" | "Testnet4";
723
+ /**
724
+ * Map a friendly network name to a bitcoinjs `Network` object.
509
725
  *
510
- * const wallet = new MeshWallet({
511
- * networkId: 0,
512
- * fetcher: provider,
513
- * submitter: provider,
514
- * key: {
515
- * type: 'mnemonic',
516
- * words: ["solution","solution","solution","solution","solution",","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution"],
517
- * },
518
- * });
519
- * ```
726
+ * NOTE: bitcoinjs-lib does not currently ship a dedicated Testnet4 network object.
727
+ * Testnet4 and Testnet3 use identical address encoding (`tb` bech32/bech32m, same
728
+ * version/HRP/script-hash formats), so reusing `bitcoin.networks.testnet` is safe
729
+ * for address derivation and PSBT construction. Chain state differs, but that is
730
+ * the provider's responsibility, not the encoder's.
731
+ */
732
+ declare function networkFromName(name: BitcoinNetworkName): Network;
733
+ /**
734
+ * Drop the parity prefix byte of a compressed secp256k1 pubkey (33 bytes -> 32 bytes).
735
+ * Required for Taproot (BIP-340) which uses x-only public keys. Returns a copy so
736
+ * callers cannot accidentally mutate the source buffer.
737
+ */
738
+ declare function toXOnly(pubkey: Buffer): Buffer;
739
+ /**
740
+ * Derive the P2WPKH (native SegWit) payment address from a compressed public key.
741
+ */
742
+ declare function deriveP2wpkhAddress(publicKey: Buffer | Uint8Array, network: Network): {
743
+ address: string;
744
+ publicKey: string;
745
+ };
746
+ /**
747
+ * Derive the P2TR (Taproot, ordinals) address from a compressed public key.
748
+ * Uses the BIP-86 single-key spend path (no script tree).
749
+ */
750
+ declare function deriveP2trAddress(publicKey: Buffer | Uint8Array, network: Network): {
751
+ address: string;
752
+ publicKey: string;
753
+ };
754
+ /**
755
+ * Internal derived-address record. Holds the public-facing fields plus the
756
+ * derivation path so the manager can request signing from the right child node.
757
+ * Public wallet methods convert this to plain `BitcoinAddress` / `BitcoinAccount`
758
+ * shapes defined on `IBitcoinWallet`.
759
+ */
760
+ declare class DerivedBitcoinAddress {
761
+ readonly address: string;
762
+ readonly publicKey: string;
763
+ readonly purpose: AddressPurpose;
764
+ readonly addressType: AddressType;
765
+ readonly walletType: "software" | "ledger" | "keystone";
766
+ readonly derivationPath: string;
767
+ readonly change: number;
768
+ readonly index: number;
769
+ constructor(args: {
770
+ address: string;
771
+ publicKey: string;
772
+ purpose: AddressPurpose;
773
+ addressType: AddressType;
774
+ walletType?: "software" | "ledger" | "keystone";
775
+ derivationPath: string;
776
+ change: number;
777
+ index: number;
778
+ });
779
+ toBitcoinAddress(): BitcoinAddress;
780
+ toBitcoinAccount(): BitcoinAccount;
781
+ }
782
+
783
+ /**
784
+ * Standard BIP derivation paths used by the Mesh Bitcoin wallet:
785
+ * - BIP-84 native SegWit (P2WPKH) for the `payment` purpose
786
+ * - BIP-86 single-key Taproot (P2TR) for the `ordinals` purpose
520
787
  *
521
- * Please call `await wallet.init()` after creating the wallet to fetch the addresses from the wallet.
788
+ * `coinType` is 0 for mainnet, 1 for any testnet (including Testnet4).
522
789
  */
523
- declare class MeshWallet implements IWallet {
524
- private readonly _keyType;
525
- private readonly _accountType;
526
- private readonly _wallet;
527
- private readonly _accountIndex;
528
- private readonly _keyIndex;
529
- private readonly _fetcher?;
530
- private readonly _submitter?;
531
- private readonly _networkId;
532
- addresses: {
533
- baseAddress?: Address;
534
- enterpriseAddress?: Address;
535
- rewardAddress?: Address;
536
- baseAddressBech32?: string;
537
- enterpriseAddressBech32?: string;
538
- rewardAddressBech32?: string;
539
- pubDRepKey?: string;
540
- dRepIDBech32?: DRepID;
541
- dRepIDHash?: Ed25519KeyHashHex;
542
- dRepIDCip105?: string;
543
- };
544
- constructor(options: CreateMeshWalletOptions);
545
- /**
546
- * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
547
- * @returns void
548
- */
549
- init(): Promise<void>;
550
- /**
551
- * Returns all derived addresses from the wallet.
552
- * @returns a list of addresses
553
- */
554
- getAddresses(): {
555
- baseAddress?: Address;
556
- enterpriseAddress?: Address;
557
- rewardAddress?: Address;
558
- baseAddressBech32?: string;
559
- enterpriseAddressBech32?: string;
560
- rewardAddressBech32?: string;
561
- pubDRepKey?: string;
562
- dRepIDBech32?: any;
563
- dRepIDHash?: Ed25519KeyHashHex;
564
- dRepIDCip105?: string;
565
- };
790
+ declare function getCoinType(network: Network): 0 | 1;
791
+ declare function paymentPath(network: Network, account?: number, change?: number, index?: number): string;
792
+ declare function ordinalsPath(network: Network, account?: number, change?: number, index?: number): string;
793
+ interface BitcoinAddressManagerConfig {
794
+ network: Network;
566
795
  /**
567
- * Returns a list of assets in the wallet. This API will return every assets in the wallet. Each asset is an object with the following properties:
568
- * - A unit is provided to display asset's name on the user interface.
569
- * - A quantity is provided to display asset's quantity on the user interface.
570
- *
571
- * @returns a list of assets and their quantities
796
+ * BIP-32 root node (seed-derived). The manager owns derivation from this root.
797
+ * Optional when the manager is used in read-only mode (no key material available).
572
798
  */
573
- getBalance(): Promise<Asset[]>;
799
+ root?: BIP32Interface;
574
800
  /**
575
- * Returns an address owned by the wallet that should be used as a change address to return leftover assets during transaction creation back to the connected wallet.
576
- *
577
- * @returns an address
801
+ * Account index for hardened account derivation (defaults to 0).
578
802
  */
579
- getChangeAddress(addressType?: GetAddressType): Promise<string>;
803
+ account?: number;
804
+ }
805
+ /**
806
+ * Centralises address derivation for the Bitcoin wallet across purposes.
807
+ * Mirrors the role of Cardano's `AddressManager` — single source of truth for
808
+ * which addresses correspond to which purposes.
809
+ */
810
+ declare class BitcoinAddressManager {
811
+ private readonly network;
812
+ private readonly root?;
813
+ private readonly account;
814
+ constructor(config: BitcoinAddressManagerConfig);
815
+ static fromSeed(seed: Buffer, network: Network, account?: number): BitcoinAddressManager;
816
+ getNetwork(): Network;
817
+ private requireRoot;
580
818
  /**
581
- * Returns an address owned by the wallet that should be used as a change address to return leftover assets during transaction creation back to the connected wallet in hex format.
582
- *
583
- * @returns an address in hex format
819
+ * Get the address for a single purpose, deriving fresh from the root.
584
820
  */
585
- getChangeAddressHex(addressType?: GetAddressType): Promise<string>;
821
+ getAddress(purpose: AddressPurpose, change?: number, index?: number): DerivedBitcoinAddress;
586
822
  /**
587
- * This function shall return a list of one or more UTXOs (unspent transaction outputs) controlled by the wallet that are required to reach AT LEAST the combined ADA value target specified in amount AND the best suitable to be used as collateral inputs for transactions with plutus script inputs (pure ADA-only UTXOs).
588
- *
589
- * If this cannot be attained, an error message with an explanation of the blocking problem shall be returned. NOTE: wallets are free to return UTXOs that add up to a greater total ADA value than requested in the amount parameter, but wallets must never return any result where UTXOs would sum up to a smaller total ADA value, instead in a case like that an error message must be returned.
590
- *
591
- * @param addressType - the type of address to fetch UTXOs from (default: payment)
592
- * @returns a list of UTXOs
823
+ * Get addresses for an array of purposes (default: payment + ordinals).
824
+ * Skips unsupported purposes silently to remain forward-compatible with
825
+ * non-Bitcoin Sats Connect purposes (`stacks`, `starknet`, `spark`).
593
826
  */
594
- getCollateral(addressType?: GetAddressType): Promise<UTxO[]>;
827
+ getAddresses(purposes?: AddressPurpose[]): DerivedBitcoinAddress[];
595
828
  /**
596
- * This function shall return a list of one or more UTXOs (unspent transaction outputs) controlled by the wallet that are required to reach AT LEAST the combined ADA value target specified in amount AND the best suitable to be used as collateral inputs for transactions with plutus script inputs (pure ADA-only UTXOs).
597
- *
598
- * If this cannot be attained, an error message with an explanation of the blocking problem shall be returned. NOTE: wallets are free to return UTXOs that add up to a greater total ADA value than requested in the amount parameter, but wallets must never return any result where UTXOs would sum up to a smaller total ADA value, instead in a case like that an error message must be returned.
599
- *
600
- * @param addressType - the type of address to fetch UTXOs from (default: payment)
601
- * @returns a list of UTXOs in hex format
829
+ * Get the BIP-32 child node for a purpose needed for signing.
602
830
  */
603
- getCollateralHex(addressType?: GetAddressType): Promise<string[]>;
831
+ getChild(purpose: AddressPurpose, change?: number, index?: number): BIP32Interface;
604
832
  /**
605
- * Return a list of supported CIPs of the wallet.
606
- *
607
- * @returns a list of CIPs
833
+ * Derive a contiguous range of addresses for a single purpose/change level.
834
+ * Useful for gap-limit scanning: call with `start=0, count=20` to get the
835
+ * first gap-limit window (BIP-84 / BIP-86), then advance `start` if any are used.
836
+ *
837
+ * @param purpose Payment (BIP-84 P2WPKH) or Ordinals (BIP-86 P2TR).
838
+ * @param start First index in the range (default 0).
839
+ * @param count How many addresses to derive (default 20).
840
+ * @param change Change chain: 0 = external/receive, 1 = internal/change.
608
841
  */
609
- getExtensions(): Promise<number[]>;
842
+ getAddressesByPurpose(purpose: AddressPurpose, start?: number, count?: number, change?: number): DerivedBitcoinAddress[];
610
843
  /**
611
- * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
844
+ * Scan the derivation path for `address` up to `maxGap` indices, returning
845
+ * the matching `DerivedBitcoinAddress` (with correct `change` and `index`)
846
+ * or `undefined` if not found. Checks both the external (0) and internal (1)
847
+ * change chains.
612
848
  *
613
- * This is used in transaction building.
849
+ * BIP-32 recommends a gap limit of 20; use a higher value if you know the
850
+ * wallet has been used extensively.
851
+ */
852
+ findAddress(address: string, purpose: AddressPurpose, maxGap?: number): DerivedBitcoinAddress | undefined;
853
+ /**
854
+ * Return the BIP-32 account node (hardened, public-key-only) for the given
855
+ * purpose. This is the xpub you would share with a watch-only wallet.
614
856
  *
615
- * @param addressType - the type of address to fetch UTXOs from (default: payment)
616
- * @returns a list of UTXOs
857
+ * BIP-84: m/84'/coin_type'/account'
858
+ * BIP-86: m/86'/coin_type'/account'
617
859
  */
618
- getCollateralUnspentOutput(addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
860
+ private getAccountNode;
619
861
  /**
620
- * The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
621
- * These are used by the client to identify the user's on-chain CIP-1694 interactions, i.e. if a user has registered to be a DRep.
862
+ * Export the BIP-84 (P2WPKH) account public key as a standard base58 xpub
863
+ * (mainnet) or tpub (testnet).
622
864
  *
623
- * @returns DRep object
865
+ * Example: `xpub6CQdKacu...`
624
866
  */
625
- getDRep(): Promise<{
626
- publicKey: string;
627
- publicKeyHash: string;
628
- dRepIDCip105: string;
629
- } | undefined>;
867
+ getAccountXpub(): string;
630
868
  /**
631
- * Returns the network ID of the currently connected account. 0 is testnet and 1 is mainnet but other networks can possibly be returned by wallets. Those other network ID values are not governed by CIP-30. This result will stay the same unless the connected account has changed.
869
+ * Export the BIP-86 (P2TR / Taproot) account public key as a standard
870
+ * base58 xpub (mainnet) or tpub (testnet).
632
871
  *
633
- * @returns network ID
872
+ * Example: `xpub6D5r3aJk...`
634
873
  */
635
- getNetworkId(): Promise<number>;
874
+ getTaprootXpub(): string;
636
875
  /**
637
- * Returns a list of reward addresses owned by the wallet. A reward address is a stake address that is used to receive rewards from staking, generally starts from `stake` prefix.
876
+ * Export the BIP-84 account public key with the **zpub** (mainnet) or
877
+ * **vpub** (testnet) version prefix, as expected by wallet software that
878
+ * distinguishes BIP-84 SegWit accounts from BIP-44/49 accounts by the
879
+ * key prefix rather than the derivation path.
638
880
  *
639
- * @returns a list of reward addresses
881
+ * Conversion: decode the xpub/tpub base58check bytes, replace the first
882
+ * 4 version bytes, and re-encode. The 74 payload bytes are unchanged.
640
883
  */
641
- getRewardAddresses(): Promise<string[]>;
884
+ getAccountZpub(): string;
885
+ }
886
+
887
+ interface BitcoinHeadlessWalletConfig {
888
+ network: BitcoinNetworkName;
889
+ provider?: IBitcoinProvider;
890
+ password?: string;
891
+ account?: number;
892
+ }
893
+ interface InternalConfig {
894
+ network: BitcoinNetworkName;
895
+ bitcoinNetwork: Network;
896
+ root: BIP32Interface;
897
+ manager: BitcoinAddressManager;
898
+ provider?: IBitcoinProvider;
899
+ account: number;
900
+ }
901
+ /**
902
+ * Internal signer extension. Carries the optional BIP-341 internal x-only
903
+ * pubkey alongside the standard `Signer` surface so `signSingleInput` can
904
+ * populate `input.tapInternalKey` when signing Taproot inputs. ECDSA signers
905
+ * (P2WPKH) simply omit `internalPubkey`.
906
+ */
907
+ type TaprootCapableSigner = Signer & {
908
+ internalPubkey?: Buffer;
909
+ };
910
+ declare class BitcoinHeadlessWallet implements IBitcoinWallet {
911
+ protected readonly networkName: BitcoinNetworkName;
912
+ protected readonly bitcoinNetwork: Network;
913
+ protected readonly root: BIP32Interface;
914
+ protected readonly manager: BitcoinAddressManager;
915
+ protected readonly provider?: IBitcoinProvider;
916
+ protected readonly account: number;
917
+ protected constructor(cfg: InternalConfig);
642
918
  /**
643
- * Returns a list of reward addresses owned by the wallet. A reward address is a stake address that is used to receive rewards from staking.
644
- * @returns a list of reward addresses in hex format
919
+ * Create a headless wallet from an existing BIP-32 root and configuration.
645
920
  */
646
- getRewardAddressesHex(): Promise<string[]>;
921
+ static create(config: BitcoinHeadlessWalletConfig & {
922
+ root: BIP32Interface;
923
+ }): Promise<BitcoinHeadlessWallet>;
647
924
  /**
648
- * Returns a list of unused addresses controlled by the wallet.
649
- *
650
- * @returns a list of unused addresses
925
+ * Create a headless wallet from a BIP-39 mnemonic phrase.
651
926
  */
652
- getUnusedAddresses(): Promise<string[]>;
927
+ static fromMnemonic(config: BitcoinHeadlessWalletConfig & {
928
+ mnemonic: string[];
929
+ }): Promise<BitcoinHeadlessWallet>;
653
930
  /**
654
- * Returns a list of unused addresses controlled by the wallet.
655
- *
656
- * @returns a list of unused addresses in hex format
931
+ * Create a headless wallet from BIP-39 entropy (hex string).
657
932
  */
658
- getUnusedAddressesHex(): Promise<string[]>;
933
+ static fromEntropy(config: BitcoinHeadlessWalletConfig & {
934
+ entropy: string;
935
+ }): Promise<BitcoinHeadlessWallet>;
936
+ static fromPrivateKey(config: BitcoinHeadlessWalletConfig & {
937
+ privateKey: string;
938
+ }): Promise<BitcoinHeadlessWallet>;
939
+ getNetwork(): Promise<BitcoinNetworkName>;
940
+ getAddresses(addressPurposes: AddressPurpose[]): Promise<BitcoinAddress[]>;
941
+ getAccounts(addressPurposes: AddressPurpose[]): Promise<BitcoinAccount[]>;
942
+ getBalance(): Promise<BitcoinBalance>;
659
943
  /**
660
- * Returns a list of used addresses controlled by the wallet.
661
- *
662
- * @returns a list of used addresses
944
+ * Derive a contiguous range of addresses for a single purpose / change level.
945
+ * Delegates to `BitcoinAddressManager.getAddressesByPurpose`.
663
946
  */
664
- getUsedAddresses(): Promise<string[]>;
947
+ getAddressesByPurpose(purpose: AddressPurpose, start?: number, count?: number, change?: number): DerivedBitcoinAddress[];
665
948
  /**
666
- * Returns a list of used addresses controlled by the wallet.
667
- *
668
- * @returns a list of used addresses in hex format
949
+ * Scan the derivation path for `address` up to `maxGap` indices across both
950
+ * external and internal (change) chains. Returns the matching
951
+ * `DerivedBitcoinAddress` (with correct `change` and `index`) or `undefined`.
952
+ * Delegates to `BitcoinAddressManager.findAddress`.
669
953
  */
670
- getUsedAddressesHex(): Promise<string[]>;
954
+ findManagedAddress(address: string, purpose: AddressPurpose, maxGap?: number): DerivedBitcoinAddress | undefined;
671
955
  /**
672
- * Get a list of UTXOs to be used for transaction building.
673
- *
674
- * This is used in transaction building.
675
- *
676
- * @param addressType - the type of address to fetch UTXOs from (default: payment)
677
- * @returns a list of UTXOs
956
+ * Export the BIP-84 (P2WPKH) account public key as xpub (mainnet) / tpub (testnet).
957
+ * Delegates to `BitcoinAddressManager.getAccountXpub`.
678
958
  */
679
- getUsedUTxOs(addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
959
+ getAccountXpub(): string;
680
960
  /**
681
- * Return a list of all UTXOs (unspent transaction outputs) controlled by the wallet.
682
- *
683
- * @param addressType - the type of address to fetch UTXOs from (default: payment)
684
- * @returns a list of UTXOs
961
+ * Export the BIP-86 (P2TR / Taproot) account public key as xpub (mainnet) / tpub (testnet).
962
+ * Delegates to `BitcoinAddressManager.getTaprootXpub`.
685
963
  */
686
- getUtxos(addressType?: GetAddressType): Promise<UTxO[]>;
964
+ getTaprootXpub(): string;
687
965
  /**
688
- * Return a list of all UTXOs (unspent transaction outputs) controlled by the wallet.
689
- *
690
- * @param addressType - the type of address to fetch UTXOs from (default: payment)
691
- * @returns a list of UTXOs in hex format
966
+ * Export the BIP-84 account public key with the zpub (mainnet) / vpub (testnet)
967
+ * version prefix. Delegates to `BitcoinAddressManager.getAccountZpub`.
692
968
  */
693
- getUtxosHex(addressType?: GetAddressType): Promise<string[]>;
969
+ getAccountZpub(): string;
694
970
  /**
695
- * This endpoint utilizes the [CIP-8 - Message Signing](https://cips.cardano.org/cips/cip8/) to sign arbitrary data, to verify the data was signed by the owner of the private key.
696
- *
697
- * @param payload - the payload to sign
698
- * @param address - the address to use for signing (optional)
699
- * @returns a signature
971
+ * Fetch unspent transaction outputs (UTXOs) for one or both managed addresses.
972
+ *
973
+ * @param purposes - Which address(es) to query. Defaults to both Payment and
974
+ * Ordinals so callers get a unified view. Pass `[AddressPurpose.Payment]`
975
+ * to restrict to the P2WPKH address only (e.g. when building a send tx).
976
+ * @returns Flat array of UTXOs across all requested addresses, each annotated
977
+ * with the `address` and `purpose` it belongs to so callers can route
978
+ * inputs correctly (P2WPKH vs P2TR signing).
700
979
  */
701
- signData(payload: string, address?: string): Promise<DataSignature>;
980
+ fetchUTXOs(purposes?: AddressPurpose[]): Promise<(UTxO & {
981
+ address: string;
982
+ purpose: AddressPurpose;
983
+ })[]>;
702
984
  /**
703
- * Requests user to sign the provided transaction (tx). The wallet should ask the user for permission, and if given, try to sign the supplied body and return a signed transaction. partialSign should be true if the transaction provided requires multiple signatures.
704
- *
705
- * @param unsignedTx - a transaction in CBOR
706
- * @param partialSign - if the transaction is partially signed (default: false)
707
- * @param returnFullTx - if the full tx should be returned or only the witness set (default: true)
708
- * @returns a signed transaction in CBOR
985
+ * Fetch confirmed and mempool transaction history for one or both managed
986
+ * addresses, with optional pagination via `lastSeenTxid`.
987
+ *
988
+ * @param options.purposes - Which address(es) to query (default: both).
989
+ * @param options.lastSeenTxid - Cursor for page-based pagination: pass the
990
+ * last `txid` from a previous page to fetch the next batch (Esplora API
991
+ * returns at most 25 txs per page).
992
+ * @returns Transactions in reverse-chronological order (newest first),
993
+ * each annotated with `address` and `purpose` for easy filtering.
994
+ * If both addresses are queried the two lists are merged and re-sorted by
995
+ * block height descending (unconfirmed txs sort to the top).
709
996
  */
710
- signTx(unsignedTx: string, partialSign?: boolean, returnFullTx?: boolean): Promise<string>;
997
+ getTransactionHistory(options?: {
998
+ purposes?: AddressPurpose[];
999
+ lastSeenTxid?: string;
1000
+ }): Promise<(TransactionsInfo & {
1001
+ address: string;
1002
+ purpose: AddressPurpose;
1003
+ })[]>;
1004
+ signMessage(address: string, message: string, protocol?: MessageSigningProtocols): Promise<BitcoinSignature>;
1005
+ verifyMessage(address: string, message: string, signature: string): Promise<VerifyMessageResult>;
1006
+ signTransfer(recipients: {
1007
+ address: string;
1008
+ amount: number;
1009
+ }[]): Promise<string>;
1010
+ signPsbt(signConfig: {
1011
+ psbt: string;
1012
+ signInputs?: {
1013
+ [x: string]: number[];
1014
+ } | undefined;
1015
+ broadcast?: boolean | undefined;
1016
+ }): Promise<string>;
1017
+ protected findDerivedByAddress(address: string): DerivedBitcoinAddress;
1018
+ protected signerForPurpose(purpose: AddressPurpose, change?: number, index?: number): TaprootCapableSigner;
1019
+ protected signSingleInput(psbt: Psbt, index: number, entry: {
1020
+ signer: TaprootCapableSigner;
1021
+ purpose: AddressPurpose;
1022
+ }): void;
1023
+ }
1024
+ /**
1025
+ * Verify a Bitcoin signed-message (BIP-137 style, 65-byte compact recoverable ECDSA, base64).
1026
+ *
1027
+ * Cross-type acceptance: recovers the pubkey from the signature and matches against
1028
+ * P2PKH / P2SH-P2WPKH / P2WPKH / P2TR (BIP-86) addresses derived from that pubkey.
1029
+ * The header byte selects compression + recoveryId per BIP-137 but does not constrain
1030
+ * which address type the caller may verify against — matches how Sparrow/Leather behave.
1031
+ */
1032
+ declare function verifyBitcoinMessage(address: string, message: string, signature: string, network: Network): VerifyMessageResult;
1033
+
1034
+ type InstalledBitcoinWallet = {
1035
+ id: string;
1036
+ name: string;
1037
+ icon?: string;
1038
+ };
1039
+ /**
1040
+ * BitcoinBrowserWallet wraps an `IBitcoinWallet`-compatible browser provider
1041
+ * (e.g., Xverse). Mirrors `CardanoBrowserWallet` for the Bitcoin chain.
1042
+ *
1043
+ * Typical usage:
1044
+ * const wallets = BitcoinBrowserWallet.getInstalledWallets();
1045
+ * const wallet = await BitcoinBrowserWallet.enable("xverse", { persist: true });
1046
+ * const balance = await wallet.getBalance();
1047
+ *
1048
+ * To reconnect after a page reload without prompting the user again:
1049
+ * const wallet = await BitcoinBrowserWallet.restore();
1050
+ */
1051
+ declare class BitcoinBrowserWallet implements IBitcoinWallet {
1052
+ walletInstance: IBitcoinWallet;
1053
+ /** Lowercase registry key of the connected wallet (e.g. `"xverse"`). */
1054
+ readonly walletName: string;
1055
+ constructor(walletInstance: IBitcoinWallet, walletName?: string);
1056
+ getNetwork(): Promise<"Mainnet" | "Testnet4">;
1057
+ getAddresses(addressPurposes: AddressPurpose[]): Promise<BitcoinAddress[]>;
1058
+ getAccounts(addressPurposes: AddressPurpose[]): Promise<BitcoinAccount[]>;
1059
+ getBalance(): Promise<BitcoinBalance>;
1060
+ signMessage(address: string, message: string, protocol?: MessageSigningProtocols): Promise<BitcoinSignature>;
1061
+ verifyMessage(address: string, message: string, signature: string): Promise<VerifyMessageResult>;
1062
+ signTransfer(recipients: {
1063
+ address: string;
1064
+ amount: number;
1065
+ }[]): Promise<string>;
1066
+ signPsbt(signConfig: {
1067
+ psbt: string;
1068
+ signInputs?: {
1069
+ [x: string]: number[];
1070
+ } | undefined;
1071
+ broadcast?: boolean | undefined;
1072
+ }): Promise<string>;
1073
+ fetchUTXOs(purposes?: AddressPurpose[]): Promise<(UTxO & {
1074
+ address: string;
1075
+ purpose: AddressPurpose;
1076
+ })[]>;
1077
+ getTransactionHistory(options?: {
1078
+ purposes?: AddressPurpose[];
1079
+ lastSeenTxid?: string;
1080
+ }): Promise<(TransactionsInfo & {
1081
+ address: string;
1082
+ purpose: AddressPurpose;
1083
+ })[]>;
711
1084
  /**
712
- * Experimental feature - sign multiple transactions at once.
713
- *
714
- * @param unsignedTxs - array of unsigned transactions in CborHex string
715
- * @param partialSign - if the transactions are signed partially
716
- * @returns array of signed transactions CborHex string
1085
+ * Removes the persisted wallet selection so `restore()` returns `null` on
1086
+ * the next page load. Call this on an explicit user-initiated disconnect.
717
1087
  */
718
- signTxs(unsignedTxs: string[], partialSign?: boolean, returnFullTx?: boolean): Promise<string[]>;
1088
+ disconnect(): void;
719
1089
  /**
720
- * Submits the signed transaction to the blockchain network.
721
- *
722
- * As wallets should already have this ability to submit transaction, we allow apps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the app to track. The wallet can return error messages or failure if there was an error in sending it.
723
- *
724
- * @param tx - a signed transaction in CBOR
725
- * @returns a transaction hash
1090
+ * Returns a list of Bitcoin wallets the user has installed in the browser.
1091
+ * Throws when called outside a browser (SSR).
726
1092
  */
727
- submitTx(tx: string): Promise<string>;
1093
+ static getInstalledWallets(): InstalledBitcoinWallet[];
728
1094
  /**
729
- * Get a used address of type Address from the wallet.
730
- *
731
- * This is used in transaction building.
732
- *
733
- * @param addressType - the type of address to fetch UTXOs from (default: payment)
734
- * @returns an Address object
1095
+ * Returns `true` when a wallet session has been persisted and `restore()`
1096
+ * (or `enable()` with `persist: true`) can reconnect it silently.
735
1097
  */
736
- getUsedAddress(addressType?: GetAddressType): Address;
1098
+ static hasPersistedSession(): boolean;
737
1099
  /**
738
- * Get a list of UTXOs to be used for transaction building.
1100
+ * Connect to a wallet, returning a wrapped `BitcoinBrowserWallet`.
739
1101
  *
740
- * This is used in transaction building.
1102
+ * When `options.persist` is `true` the behaviour differs depending on
1103
+ * whether a prior session exists:
741
1104
  *
742
- * @param addressType - the type of address to fetch UTXOs from (default: payment)
743
- * @returns a list of UTXOs
1105
+ * **No existing session** runs the normal connect flow (may show the
1106
+ * wallet's approval popup)
1107
+ * • **Existing session for the same wallet** — silently reconnects without showing any popup.
1108
+ *
1109
+ * @param walletName Registry key of the wallet (e.g. `"xverse"`).
1110
+ * @param options.persist Opt-in to silent restore on subsequent page loads.
744
1111
  */
745
- getUnspentOutputs(addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
1112
+ static enable(walletName: string, options?: {
1113
+ persist?: boolean;
1114
+ }): Promise<BitcoinBrowserWallet>;
746
1115
  /**
747
- * A helper function to get the assets in the wallet.
1116
+ * Silently reconnects using the wallet name saved by a previous
1117
+ * `enable({ persist: true })` call.
748
1118
  *
749
- * @returns a list of assets
1119
+ * Returns `null` if nothing was persisted or the saved wallet is no longer
1120
+ * available (extension uninstalled / access revoked). The stale entry is
1121
+ * cleared automatically in the latter case.
750
1122
  */
751
- getAssets(): Promise<AssetExtended[]>;
1123
+ static restore(): Promise<BitcoinBrowserWallet | null>;
1124
+ }
1125
+
1126
+ /**
1127
+ * Shape of the Xverse `BitcoinProvider` reachable via `window.XverseProviders.BitcoinProvider`.
1128
+ * We only depend on the `request(method, params)` JSON-RPC-style surface, which is the public
1129
+ * Sats Connect protocol — no SDK dependency required.
1130
+ *
1131
+ * See: https://docs.xverse.app/sats-connect (`getAddresses`, `getAccounts`, `getBalance`,
1132
+ * `signMessage`, `sendTransfer`, `signPsbt`, `getNetwork`).
1133
+ */
1134
+ interface XverseBitcoinProvider {
1135
+ request<T = unknown>(method: string, params?: Record<string, unknown> | null): Promise<XverseResponse<T>>;
1136
+ }
1137
+ /**
1138
+ * The Xverse provider's `request()` returns one of two envelopes, depending on
1139
+ * whether the dApp went through the sats-connect-core library (which normalises
1140
+ * the wire format) or hit `window.XverseProviders.BitcoinProvider` directly
1141
+ * (raw JSON-RPC 2.0). We accept both so the adapter works either way.
1142
+ */
1143
+ type XverseResponse<T> = {
1144
+ status: "success";
1145
+ result: T;
1146
+ } | {
1147
+ status: "error";
1148
+ error: {
1149
+ code: number;
1150
+ message: string;
1151
+ };
1152
+ } | {
1153
+ jsonrpc: "2.0";
1154
+ result: T;
1155
+ id?: string | number | null;
1156
+ } | {
1157
+ jsonrpc: "2.0";
1158
+ error: {
1159
+ code: number;
1160
+ message: string;
1161
+ };
1162
+ id?: string | number | null;
1163
+ };
1164
+ /**
1165
+ * Typed error preserving the RPC error code so callers can distinguish
1166
+ * `USER_REJECTION` (-32000) from `ACCESS_DENIED` (-32002), etc.
1167
+ */
1168
+ /** Sats Connect `RpcErrorCode.ACCESS_DENIED` — app has not connected yet. */
1169
+ declare const XVERSE_ACCESS_DENIED = -32002;
1170
+ declare class XverseRpcError extends Error {
1171
+ readonly code: number;
1172
+ readonly method: string;
1173
+ constructor(method: string, code: number, message: string);
1174
+ }
1175
+ declare global {
1176
+ interface Window {
1177
+ XverseProviders?: {
1178
+ BitcoinProvider?: XverseBitcoinProvider;
1179
+ };
1180
+ BitcoinProvider?: XverseBitcoinProvider;
1181
+ }
1182
+ }
1183
+ declare function isXverseInstalled(): boolean;
1184
+ /**
1185
+ * Adapter that implements `IBitcoinWallet` against the Xverse / Sats Connect surface.
1186
+ * Created on `enable()` after the user authorizes the dApp.
1187
+ */
1188
+ declare class XverseAdapter implements IBitcoinWallet {
1189
+ private connected;
1190
+ private cachedAddresses;
1191
+ private constructor();
1192
+ static enable(): Promise<XverseAdapter>;
752
1193
  /**
753
- * A helper function to get the lovelace balance in the wallet.
754
- *
755
- * @returns lovelace balance
1194
+ * Establish a dApp connection per Sats Connect: `wallet_connect` grants read
1195
+ * permission and returns addresses. Older Xverse builds fall back to
1196
+ * `wallet_requestPermissions` + `getAddresses`.
756
1197
  */
757
- getLovelace(): Promise<string>;
1198
+ private connect;
1199
+ private connectViaWalletConnect;
1200
+ private connectViaPermissions;
1201
+ private requestPermissions;
1202
+ private requestAddresses;
1203
+ private fetchAddresses;
1204
+ getNetwork(): Promise<"Mainnet" | "Testnet4">;
1205
+ getAddresses(addressPurposes: AddressPurpose[]): Promise<BitcoinAddress[]>;
1206
+ getAccounts(addressPurposes: AddressPurpose[]): Promise<BitcoinAccount[]>;
1207
+ getBalance(): Promise<BitcoinBalance>;
1208
+ signMessage(address: string, message: string, protocol?: MessageSigningProtocols): Promise<BitcoinSignature>;
758
1209
  /**
759
- * A helper function to get the assets of a specific policy ID in the wallet.
760
- *
761
- * @param policyId
762
- * @returns a list of assets
1210
+ * Verify a Bitcoin signed-message locally. Trustless does not call the extension.
1211
+ * Supports the ECDSA 65-byte BIP-137 compact format. Non-ECDSA signatures (e.g. the
1212
+ * BIP-322 format Xverse produces for Taproot addresses) return `{ valid: false }` rather
1213
+ * than throwing, so callers can safely check `result.valid`.
763
1214
  */
764
- getPolicyIdAssets(policyId: string): Promise<AssetExtended[]>;
1215
+ verifyMessage(address: string, message: string, signature: string): Promise<VerifyMessageResult>;
765
1216
  /**
766
- * A helper function to get the policy IDs of all the assets in the wallet.
767
- *
768
- * @returns a list of policy IDs
1217
+ * Xverse's Sats Connect exposes `sendTransfer` which prompts the user to sign
1218
+ * AND broadcast in one step — there is no "sign-only" variant.
1219
+ * Returns the broadcast txid, satisfying the `IBitcoinWallet.signTransfer` contract.
769
1220
  */
770
- getPolicyIds(): Promise<string[]>;
771
- getRegisteredPubStakeKeys(): Promise<{
772
- pubStakeKeys: string[];
773
- pubStakeKeyHashes: string[];
774
- } | undefined>;
775
- getUnregisteredPubStakeKeys(): Promise<{
776
- pubStakeKeys: string[];
777
- pubStakeKeyHashes: string[];
778
- } | undefined>;
1221
+ signTransfer(recipients: {
1222
+ address: string;
1223
+ amount: number;
1224
+ }[]): Promise<string>;
1225
+ signPsbt(signConfig: {
1226
+ psbt: string;
1227
+ signInputs?: {
1228
+ [x: string]: number[];
1229
+ } | undefined;
1230
+ broadcast?: boolean | undefined;
1231
+ }): Promise<string>;
779
1232
  /**
780
- * A helper function to create a collateral input for a transaction.
781
- *
782
- * @returns a transaction hash
1233
+ * Fetch UTXOs for the connected wallet via Sats Connect.
1234
+ * Xverse exposes `wallet_getUtxos` on newer builds; for older builds that
1235
+ * don't support it this will throw a clear METHOD_NOT_FOUND error.
783
1236
  */
784
- createCollateral(): Promise<string>;
785
- getPubDRepKey(): {
786
- pubDRepKey: string | undefined;
787
- dRepIDBech32: string | undefined;
788
- dRepIDHash: string | undefined;
789
- dRepIDCip105: string | undefined;
790
- };
1237
+ fetchUTXOs(purposes?: AddressPurpose[]): Promise<(UTxO & {
1238
+ address: string;
1239
+ purpose: AddressPurpose;
1240
+ })[]>;
791
1241
  /**
792
- * Generate mnemonic or private key
793
- *
794
- * @param privateKey return private key if true
795
- * @returns a transaction hash
1242
+ * Fetch transaction history for the connected wallet via Sats Connect.
1243
+ * Xverse exposes `wallet_getTransactions` on newer builds.
796
1244
  */
797
- static brew(privateKey?: boolean, strength?: number): string[] | string;
798
- private getAddressesFromWallet;
799
- private buildAddressFromBech32Address;
1245
+ getTransactionHistory(options?: {
1246
+ purposes?: AddressPurpose[];
1247
+ lastSeenTxid?: string;
1248
+ }): Promise<(TransactionsInfo & {
1249
+ address: string;
1250
+ purpose: AddressPurpose;
1251
+ })[]>;
1252
+ }
1253
+
1254
+ interface IMultiChainWallet {
1255
+ cardanoWallet: ICardanoWallet;
1256
+ bitcoinWallet: IBitcoinWallet;
800
1257
  }
801
1258
 
802
- export { type Account, type AccountType, AppWallet, type AppWalletKeyType, BrowserWallet, type CreateAppWalletOptions, type CreateEmbeddedWalletOptions, type CreateMeshWalletOptions, EmbeddedWallet, type EmbeddedWalletKeyType, MeshWallet, WalletStaticMethods, connect, login, register };
1259
+ export { type AddressInfo, AddressPurpose, AddressType$1 as AddressType, BaseSigner, type BitcoinAccount, type BitcoinAddress, BitcoinAddressManager, type BitcoinAddressManagerConfig, AddressType as BitcoinAddressType, type BitcoinBalance, BitcoinBrowserWallet, BitcoinHeadlessWallet, type BitcoinHeadlessWalletConfig, BitcoinInMemoryBip32, type BitcoinNetworkName, type BitcoinSignature, type Cardano, CardanoAddress, CardanoBrowserWallet, CardanoHeadlessWallet, type CardanoHeadlessWalletConfig, CardanoInMemoryBip32, type ChainStats, type Credential, type CredentialSource, CredentialType, DerivedBitcoinAddress, type IBitcoinFetcher, type IBitcoinProvider, type IBitcoinSubmitter, type IBitcoinWallet, type ICardanoWallet, type IMultiChainWallet, type InstalledBitcoinWallet, type MempoolStats, MeshCardanoBrowserWallet, MeshCardanoHeadlessWallet, MessageSigningProtocols, type RecoveryId, type ScriptInfo, type TransactionsInfo, type TransactionsStatus, type UTxO, type VerifyMessageResult, type WalletAddressType, XVERSE_ACCESS_DENIED, XverseAdapter, type XverseBitcoinProvider, type XverseResponse, XverseRpcError, deriveP2trAddress, deriveP2wpkhAddress, getCoinType, isXverseInstalled, networkFromName, ordinalsPath, paymentPath, toXOnly, verifyBitcoinMessage };