@meshsdk/wallet 2.0.0-beta.2 → 2.0.0-beta.3

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.cts CHANGED
@@ -1,3 +1,5 @@
1
+ import { DataSignature, Extension as Extension$1, UTxO, Asset, IFetcher, ISubmitter } from '@meshsdk/common';
2
+
1
3
  interface ISigner {
2
4
  getPublicKey(): Promise<string>;
3
5
  getPublicKeyHash(): Promise<string>;
@@ -104,4 +106,400 @@ declare class CardanoAddress {
104
106
  private getRewardAddressHex;
105
107
  }
106
108
 
107
- export { AddressType, BaseSigner, CardanoAddress, type Credential, CredentialType, InMemoryBip32 };
109
+ interface ICardanoWallet {
110
+ getNetworkId(): Promise<number>;
111
+ getUtxos(): Promise<string[]>;
112
+ getCollateral(): Promise<string[]>;
113
+ getBalance(): Promise<string>;
114
+ getUsedAddresses(): Promise<string[]>;
115
+ getUnusedAddresses(): Promise<string[]>;
116
+ getRewardAddresses(): Promise<string[]>;
117
+ getChangeAddress(): Promise<string>;
118
+ signTx(data: string, partialSign: boolean): Promise<string>;
119
+ signData(addressHex: string, data: string): Promise<DataSignature>;
120
+ submitTx(tx: string): Promise<string>;
121
+ }
122
+
123
+ type Wallet = {
124
+ id: string;
125
+ name: string;
126
+ icon: string;
127
+ version: string;
128
+ };
129
+ type Cardano = {
130
+ [key: string]: {
131
+ name: string;
132
+ icon: string;
133
+ apiVersion: string;
134
+ enable: (extensions?: {
135
+ extensions: {
136
+ cip: number;
137
+ }[];
138
+ }) => Promise<ICardanoWallet>;
139
+ supportedExtensions?: {
140
+ cip: number;
141
+ }[];
142
+ };
143
+ };
144
+ type Extension = {
145
+ cip: number;
146
+ };
147
+ declare class CardanoBrowserWallet implements ICardanoWallet {
148
+ walletInstance: ICardanoWallet;
149
+ constructor(walletInstance: ICardanoWallet);
150
+ getNetworkId(): Promise<number>;
151
+ getUtxos(): Promise<string[]>;
152
+ getCollateral(): Promise<string[]>;
153
+ getBalance(): Promise<string>;
154
+ getUsedAddresses(): Promise<string[]>;
155
+ getUnusedAddresses(): Promise<string[]>;
156
+ getRewardAddresses(): Promise<string[]>;
157
+ getChangeAddress(): Promise<string>;
158
+ signTx(data: string, partialSign: boolean): Promise<string>;
159
+ signData(addressBech32: string, data: string): Promise<DataSignature>;
160
+ submitTx(tx: string): Promise<string>;
161
+ /**
162
+ * Returns a list of wallets installed on user's device. Each wallet is an object with the following properties:
163
+ * - A name is provided to display wallet's name on the user interface.
164
+ * - A version is provided to display wallet's version on the user interface.
165
+ * - An icon is provided to display wallet's icon on the user interface.
166
+ *
167
+ * @returns a list of wallet names
168
+ */
169
+ static getInstalledWallets(): Wallet[];
170
+ /**
171
+ * 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 app to use.
172
+ *
173
+ * Query BrowserWallet.getInstalledWallets() to get a list of available wallets, then provide the wallet name for which wallet the user would like to connect with.
174
+ *
175
+ * @param walletName - the name of the wallet to enable (e.g. "eternl", "begin")
176
+ * @param extensions - optional, a list of CIPs that the wallet should support
177
+ * @returns WalletInstance
178
+ */
179
+ static enable(walletName: string, extensions?: Extension[]): Promise<ICardanoWallet>;
180
+ }
181
+
182
+ declare class MeshCardanoBrowserWallet extends CardanoBrowserWallet {
183
+ constructor(walletInstance: ICardanoWallet);
184
+ static enable(walletName: string, extensions?: Extension$1[]): Promise<MeshCardanoBrowserWallet>;
185
+ getUtxosMesh(): Promise<UTxO[]>;
186
+ getCollateralMesh(): Promise<UTxO[]>;
187
+ getBalanceMesh(): Promise<Asset[]>;
188
+ getUsedAddressesBech32(): Promise<string[]>;
189
+ getUnusedAddressesBech32(): Promise<string[]>;
190
+ getChangeAddressBech32(): Promise<string>;
191
+ getRewardAddressesBech32(): Promise<string[]>;
192
+ signTxReturnFullTx(tx: string, partialSign?: boolean): Promise<string>;
193
+ }
194
+
195
+ type CredentialSource = {
196
+ type: "signer";
197
+ signer: ISigner;
198
+ } | {
199
+ type: "scriptHash";
200
+ scriptHash: string;
201
+ };
202
+ interface AddressManagerConfig {
203
+ addressSource: AddressSource;
204
+ networkId: number;
205
+ }
206
+ type AddressSource = {
207
+ type: "secretManager";
208
+ secretManager: ISecretManager;
209
+ } | {
210
+ type: "credentials";
211
+ paymentCredential: CredentialSource;
212
+ stakeCredential?: CredentialSource;
213
+ drepCredential?: CredentialSource;
214
+ };
215
+ declare class AddressManager {
216
+ private readonly paymentCredential;
217
+ private readonly stakeCredential;
218
+ private readonly drepCredential;
219
+ private readonly paymentSigner;
220
+ private readonly stakeSigner?;
221
+ private readonly drepSigner?;
222
+ private readonly networkId;
223
+ static create(config: AddressManagerConfig): Promise<AddressManager>;
224
+ private constructor();
225
+ getNextAddress(addressType: AddressType): Promise<CardanoAddress>;
226
+ getChangeAddress(addressType: AddressType): Promise<CardanoAddress>;
227
+ getRewardAccount(): Promise<CardanoAddress>;
228
+ asyncGetAllUsedAddresses(): Promise<CardanoAddress[]>;
229
+ getCredentialsSigners(pubkeyHashes: Set<string>): Promise<Map<string, ISigner>>;
230
+ }
231
+
232
+ type WalletAddressType = AddressType.Base | AddressType.Enterprise;
233
+ /**
234
+ * Configuration for creating a CardanoHeadlessWallet instance.
235
+ */
236
+ interface CardanoHeadlessWalletConfig {
237
+ /**
238
+ * The source for wallet's signing keys and addresses. Could either be a secret manager or explicit credentials.
239
+ */
240
+ addressSource: AddressSource;
241
+ /**
242
+ * The network ID (0 for testnet, 1 for mainnet).
243
+ */
244
+ networkId: number;
245
+ /**
246
+ * The type of wallet address to use (Base or Enterprise).
247
+ * Base addresses include staking capabilities, while Enterprise addresses do not.
248
+ */
249
+ walletAddressType: WalletAddressType;
250
+ /**
251
+ * Optional fetcher instance for querying blockchain data (UTxOs, protocol parameters, etc.).
252
+ */
253
+ fetcher?: IFetcher;
254
+ /**
255
+ * Optional submitter instance for submitting transactions to the blockchain.
256
+ */
257
+ submitter?: ISubmitter;
258
+ }
259
+ declare class CardanoHeadlessWallet implements ICardanoWallet {
260
+ protected networkId: number;
261
+ protected addressManager: AddressManager;
262
+ protected fetcher?: IFetcher;
263
+ protected submitter?: ISubmitter;
264
+ protected walletAddressType: WalletAddressType;
265
+ protected constructor(networkId: number, addressManager: AddressManager, walletAddressType: WalletAddressType, fetcher?: IFetcher, submitter?: ISubmitter);
266
+ static create(config: CardanoHeadlessWalletConfig): Promise<CardanoHeadlessWallet>;
267
+ /**
268
+ * Create a CardanoHeadlessWallet instance from a Bip32 root in Bech32 format.
269
+ * @param config The configuration object
270
+ * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
271
+ */
272
+ static fromBip32Root(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
273
+ bech32: string;
274
+ }): Promise<CardanoHeadlessWallet>;
275
+ /**
276
+ * Create a CardanoHeadlessWallet instance from a Bip32 root in hex format.
277
+ * @param config The configuration object
278
+ * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
279
+ */
280
+ static fromBip32RootHex(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
281
+ hex: string;
282
+ }): Promise<CardanoHeadlessWallet>;
283
+ /**
284
+ * Create a CardanoHeadlessWallet instance from a mnemonic phrase.
285
+ * @param config The configuration object
286
+ * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
287
+ */
288
+ static fromMnemonic(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
289
+ mnemonic: string[];
290
+ password?: string;
291
+ }): Promise<CardanoHeadlessWallet>;
292
+ static fromCredentialSources(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
293
+ paymentCredentialSource: CredentialSource;
294
+ stakeCredentialSource?: CredentialSource;
295
+ drepCredentialSource?: CredentialSource;
296
+ }): Promise<CardanoHeadlessWallet>;
297
+ /**
298
+ * Submit a transaction to the network, using the submitter instance.
299
+ * @param tx The transaction in CBOR hex format
300
+ * @returns {Promise<string>} A promise that resolves to the transaction ID
301
+ */
302
+ submitTx(tx: string): Promise<string>;
303
+ /**
304
+ * Get the network ID.
305
+ * @returns {number} The network ID
306
+ */
307
+ getNetworkId(): Promise<number>;
308
+ /**
309
+ * Get the UTxOs for the wallet.
310
+ *
311
+ * NOTE: This method is only an approximation to CIP-30 getUtxos, as this wallet is completely
312
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
313
+ * will be overlap between getUtxos() and getCollateral() results. This can result in the collateral being
314
+ * spent between transactions.
315
+ *
316
+ * The method also does not perform pagination, nor is there a coin selection mechanism.
317
+ * @returns {Promise<string[]>} A promise that resolves to an array of UTxOs in CBOR hex format
318
+ */
319
+ getUtxos(): Promise<string[]>;
320
+ /**
321
+ * Get the collateral UTxOs for the wallet.
322
+ *
323
+ * NOTE: This method is only an approximation to CIP-30 getCollateral, as this wallet is completely
324
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
325
+ * will be overlap between getUtxos() and getCollateral() results.
326
+ *
327
+ * The basic strategy is to return the smallest pure ADA UTxO that is at least 5 ADA belonging to the wallet.
328
+ * @returns {Promise<string[]>} A promise that resolves to an array of UTxOs in CBOR hex format
329
+ */
330
+ getCollateral(): Promise<string[]>;
331
+ /**
332
+ * Get the balance of the wallet.
333
+ *
334
+ * NOTE: This method is only an approximation to CIP-30 getBalance, as this wallet is completely
335
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means the balance
336
+ * returned includes all UTxOs, including those that may be used as collateral.
337
+ * @returns {Promise<string>} A promise that resolves to the balance in CBOR hex format
338
+ */
339
+ getBalance(): Promise<string>;
340
+ /**
341
+ * Get the used addresses for the wallet.
342
+ *
343
+ * NOTE: This method completely deviates from CIP-30 getUsedAddresses, as this wallet is stateless
344
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
345
+ *
346
+ * It will be effective to be used as a single address wallet.
347
+ *
348
+ * @returns {Promise<string[]>} A promise that resolves to an array of used addresses in hex format
349
+ */
350
+ getUsedAddresses(): Promise<string[]>;
351
+ /**
352
+ * Get the unused addresses for the wallet.
353
+ *
354
+ * NOTE: This method completely deviates from CIP-30 getUnusedAddresses, as this wallet is stateless
355
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
356
+ *
357
+ * It will be effective to be used as a single address wallet.
358
+ *
359
+ * @returns {Promise<string[]>} A promise that resolves to an array of unused addresses in hex format
360
+ */
361
+ getUnusedAddresses(): Promise<string[]>;
362
+ /**
363
+ * Get the change address for the wallet.
364
+ * NOTE: This method deviates from CIP-30 getChangeAddress, as this wallet is stateless
365
+ * it does not track which addresses has been previously used as change address. This method simply
366
+ * returns the wallet's main address.
367
+ *
368
+ * It will be effective to be used as a single address wallet.
369
+ *
370
+ * @returns {Promise<string>} A promise that resolves to the change address in hex format
371
+ */
372
+ getChangeAddress(): Promise<string>;
373
+ /**
374
+ * Get the reward address for the wallet.
375
+ *
376
+ * @returns {Promise<string[]>} A promise that resolves an array of reward addresses in hex format
377
+ */
378
+ getRewardAddresses(): Promise<string[]>;
379
+ /**
380
+ * Sign a transaction with the wallet.
381
+ *
382
+ * NOTE: This method requires a fetcher to resolve input UTxOs for determining required signers.
383
+ *
384
+ * It is also only an approximation to CIP-30 signTx, as this wallet is stateless and does not repeatedly
385
+ * derive keys, it is unable to sign for multiple derived key indexes.
386
+ *
387
+ * It will be effective to be used as a single address wallet.
388
+ *
389
+ * @param tx The transaction in CBOR hex format
390
+ * @returns A promise that resolves to a witness set with the signatures in CBOR hex format
391
+ */
392
+ signTx(tx: string, partialSign?: boolean): Promise<string>;
393
+ signData(addressBech32: string, data: string): Promise<DataSignature>;
394
+ fetchAccountUtxos(): Promise<UTxO[]>;
395
+ }
396
+
397
+ /**
398
+ * MeshCardanoHeadlessWallet provides additional convenience methods on top of CardanoHeadlessWallet,
399
+ * such as returning results in Mesh-compatible formats and Bech32 addresses.
400
+ */
401
+ declare class MeshCardanoHeadlessWallet extends CardanoHeadlessWallet {
402
+ static create(config: CardanoHeadlessWalletConfig): Promise<MeshCardanoHeadlessWallet>;
403
+ static fromMnemonic(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
404
+ mnemonic: string[];
405
+ password?: string;
406
+ }): Promise<MeshCardanoHeadlessWallet>;
407
+ static fromBip32Root(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
408
+ bech32: string;
409
+ }): Promise<MeshCardanoHeadlessWallet>;
410
+ static fromBip32RootHex(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
411
+ hex: string;
412
+ }): Promise<MeshCardanoHeadlessWallet>;
413
+ static fromCredentialSources(config: Omit<CardanoHeadlessWalletConfig, "addressSource"> & {
414
+ paymentCredentialSource: CredentialSource;
415
+ stakeCredentialSource?: CredentialSource;
416
+ drepCredentialSource?: CredentialSource;
417
+ }): Promise<MeshCardanoHeadlessWallet>;
418
+ /**
419
+ * Get the UTxOs for the wallet.
420
+ *
421
+ * NOTE: This method is only an approximation to CIP-30 getUtxos, as this wallet is completely
422
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
423
+ * will be overlap between getUtxos() and getCollateral() results. This can result in the collateral being
424
+ * spent between transactions.
425
+ *
426
+ * The method also does not perform pagination, nor is there a coin selection mechanism.
427
+ * @returns {Promise<UTxO[]>} A promise that resolves to an array of UTxOs in the Mesh UTxO format
428
+ */
429
+ getUtxosMesh(): Promise<UTxO[]>;
430
+ /**
431
+ * Get the collateral UTxOs for the wallet.
432
+ *
433
+ * NOTE: This method is only an approximation to CIP-30 getCollateral, as this wallet is completely
434
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means that there
435
+ * will be overlap between getUtxos() and getCollateral() results.
436
+ *
437
+ * The basic strategy is to return the smallest pure ADA UTxO that is at least 5 ADA belonging to the wallet.
438
+ * @returns {Promise<UTxO[]>} A promise that resolves to an array of UTxOs in the Mesh UTxO format
439
+ */
440
+ getCollateralMesh(): Promise<UTxO[]>;
441
+ /**
442
+ * Get the balance of the wallet.
443
+ *
444
+ * NOTE: This method is only an approximation to CIP-30 getBalance, as this wallet is completely
445
+ * stateless and does not track which UTxOs are specifically set as collateral. Which means the balance
446
+ * returned includes all UTxOs, including those that may be used as collateral.
447
+ * @returns {Promise<Asset[]>} A promise that resolves to the balance in the Mesh Asset format
448
+ */
449
+ getBalanceMesh(): Promise<Asset[]>;
450
+ /**
451
+ * Get the used addresses for the wallet.
452
+ *
453
+ * NOTE: This method completely deviates from CIP-30 getUsedAddresses, as this wallet is stateless
454
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
455
+ *
456
+ * It will be effective to be used as a single address wallet.
457
+ *
458
+ * @returns {Promise<string[]>} A promise that resolves to an array of used addresses in Bech32 format
459
+ */
460
+ getUsedAddressesBech32(): Promise<string[]>;
461
+ /**
462
+ * Get the unused addresses for the wallet.
463
+ *
464
+ * NOTE: This method completely deviates from CIP-30 getUnusedAddresses, as this wallet is stateless
465
+ * it is impossible to track which addresses have been used. This method simply returns the wallet's main address.
466
+ *
467
+ * It will be effective to be used as a single address wallet.
468
+ *
469
+ * @returns {Promise<string[]>} A promise that resolves to an array of unused addresses in Bech32 format
470
+ */
471
+ getUnusedAddressesBech32(): Promise<string[]>;
472
+ /**
473
+ * Get the change address for the wallet.
474
+ * NOTE: This method deviates from CIP-30 getChangeAddress, as this wallet is stateless
475
+ * it does not track which addresses has been previously used as change address. This method simply
476
+ * returns the wallet's main address.
477
+ *
478
+ * It will be effective to be used as a single address wallet.
479
+ *
480
+ * @returns {Promise<string>} A promise that resolves to the change address in Bech32 format
481
+ */
482
+ getChangeAddressBech32(): Promise<string>;
483
+ /**
484
+ * Get the reward address for the wallet.
485
+ * @returns {Promise<string[]>} A promise that resolves an array of reward addresses in Bech32 format
486
+ */
487
+ getRewardAddressesBech32(): Promise<string[]>;
488
+ /**
489
+ * Sign a transaction with the wallet.
490
+ *
491
+ * NOTE: This method requires a fetcher to resolve input UTxOs for determining required signers.
492
+ *
493
+ * It is also only an approximation to CIP-30 signTx, as this wallet is stateless and does not repeatedly
494
+ * derive keys, it is unable to sign for multiple derived key indexes.
495
+ *
496
+ * It will be effective to be used as a single address wallet.
497
+ *
498
+ * @param tx The transaction in CBOR hex format
499
+ * @returns A promise that resolves to a full transaction with extra vkey witnesses added from the wallet
500
+ * to the witness set in CBOR hex format
501
+ */
502
+ signTxReturnFullTx(tx: string, partialSign?: boolean): Promise<string>;
503
+ }
504
+
505
+ export { AddressType, BaseSigner, type Cardano, CardanoAddress, CardanoBrowserWallet, CardanoHeadlessWallet, type CardanoHeadlessWalletConfig, type Credential, type CredentialSource, CredentialType, type ICardanoWallet, InMemoryBip32, MeshCardanoBrowserWallet, MeshCardanoHeadlessWallet, type WalletAddressType };