@meshsdk/wallet 1.5.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,511 @@
1
+ import { DataSignature, IFetcher, ISubmitter, ISigner, IInitiator, Wallet, Asset, UTxO, AssetExtended } from '@meshsdk/common';
2
+ import { TransactionUnspentOutput, Address, PrivateKey, VkeyWitness } from '@meshsdk/core-cst';
3
+
4
+ type Cardano = {
5
+ [key: string]: {
6
+ name: string;
7
+ icon: string;
8
+ apiVersion: string;
9
+ enable: () => Promise<WalletInstance>;
10
+ };
11
+ };
12
+ type TransactionSignatureRequest = {
13
+ cbor: string;
14
+ partialSign: boolean;
15
+ };
16
+ type WalletInstance = {
17
+ experimental: ExperimentalFeatures;
18
+ getBalance(): Promise<string>;
19
+ getChangeAddress(): Promise<string>;
20
+ getNetworkId(): Promise<number>;
21
+ getRewardAddresses(): Promise<string[]>;
22
+ getUnusedAddresses(): Promise<string[]>;
23
+ getUsedAddresses(): Promise<string[]>;
24
+ getUtxos(): Promise<string[] | undefined>;
25
+ signData(address: string, payload: string): Promise<DataSignature>;
26
+ signTx(tx: string, partialSign: boolean): Promise<string>;
27
+ signTxs?(txs: TransactionSignatureRequest[]): Promise<string[]>;
28
+ signTxs?(txs: string[], partialSign: boolean): Promise<string[]>;
29
+ submitTx(tx: string): Promise<string>;
30
+ };
31
+ type ExperimentalFeatures = {
32
+ getCollateral(): Promise<string[] | undefined>;
33
+ signTxs?(txs: TransactionSignatureRequest[]): Promise<string[]>;
34
+ signTxs?(txs: string[], partialSign: boolean): Promise<string[]>;
35
+ };
36
+ type GetAddressType = "enterprise" | "payment";
37
+
38
+ type AppWalletKeyType = {
39
+ type: "root";
40
+ bech32: string;
41
+ } | {
42
+ type: "cli";
43
+ payment: string;
44
+ stake?: string;
45
+ } | {
46
+ type: "mnemonic";
47
+ words: string[];
48
+ };
49
+ type CreateAppWalletOptions = {
50
+ networkId: number;
51
+ fetcher?: IFetcher;
52
+ submitter?: ISubmitter;
53
+ key: AppWalletKeyType;
54
+ };
55
+ declare class AppWallet implements ISigner, ISubmitter {
56
+ private readonly _fetcher?;
57
+ private readonly _submitter?;
58
+ private readonly _wallet;
59
+ constructor(options: CreateAppWalletOptions);
60
+ /**
61
+ * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
62
+ *
63
+ * This is used in transaction building.
64
+ *
65
+ * @returns a list of UTXOs
66
+ */
67
+ getCollateralUnspentOutput(accountIndex?: number, addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
68
+ getEnterpriseAddress(accountIndex?: number, keyIndex?: number): string;
69
+ getPaymentAddress(accountIndex?: number, keyIndex?: number): string;
70
+ getRewardAddress(accountIndex?: number, keyIndex?: number): string;
71
+ getNetworkId(): number;
72
+ getUsedAddress(accountIndex?: number, keyIndex?: number, addressType?: GetAddressType): Address;
73
+ getUnspentOutputs(accountIndex?: number, addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
74
+ signData(address: string, payload: string, accountIndex?: number, keyIndex?: number): DataSignature;
75
+ signTx(unsignedTx: string, partialSign?: boolean, accountIndex?: number, keyIndex?: number): string;
76
+ signTxSync(unsignedTx: string, partialSign?: boolean, accountIndex?: number, keyIndex?: number): string;
77
+ signTxs(unsignedTxs: string[], partialSign: boolean): Promise<string[]>;
78
+ submitTx(tx: string): Promise<string>;
79
+ static brew(strength?: number): string[];
80
+ }
81
+
82
+ declare global {
83
+ interface Window {
84
+ cardano: Cardano;
85
+ }
86
+ }
87
+ declare class BrowserWallet implements IInitiator, ISigner, ISubmitter {
88
+ readonly _walletInstance: WalletInstance;
89
+ readonly _walletName: string;
90
+ walletInstance: WalletInstance;
91
+ private constructor();
92
+ /**
93
+ * Returns a list of wallets installed on user's device. Each wallet is an object with the following properties:
94
+ * - A name is provided to display wallet's name on the user interface.
95
+ * - A version is provided to display wallet's version on the user interface.
96
+ * - An icon is provided to display wallet's icon on the user interface.
97
+ *
98
+ * @returns a list of wallet names
99
+ */
100
+ static getInstalledWallets(): Wallet[];
101
+ /**
102
+ * This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the dApp to use.
103
+ *
104
+ * 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.
105
+ *
106
+ * @param walletName
107
+ * @returns WalletInstance
108
+ */
109
+ static enable(walletName: string): Promise<BrowserWallet>;
110
+ /**
111
+ * Retrieves the total available balance of the wallet, encoded in CBOR.
112
+ * @returns {Promise<Value>} - The balance of the wallet.
113
+ */
114
+ /**
115
+ * 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:
116
+ * - A unit is provided to display asset's name on the user interface.
117
+ * - A quantity is provided to display asset's quantity on the user interface.
118
+ *
119
+ * @returns a list of assets and their quantities
120
+ */
121
+ getBalance(): Promise<Asset[]>;
122
+ /**
123
+ * 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.
124
+ *
125
+ * @returns an address
126
+ */
127
+ getChangeAddress(): Promise<string>;
128
+ /**
129
+ * 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).
130
+ *
131
+ * 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.
132
+ *
133
+ * @param limit
134
+ * @returns a list of UTXOs
135
+ */
136
+ getCollateral(): Promise<UTxO[]>;
137
+ /**
138
+ * 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.
139
+ *
140
+ * @returns network ID
141
+ */
142
+ getNetworkId(): Promise<number>;
143
+ /**
144
+ * 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.
145
+ *
146
+ * @returns a list of reward addresses
147
+ */
148
+ getRewardAddresses(): Promise<string[]>;
149
+ /**
150
+ * Returns a list of unused addresses controlled by the wallet.
151
+ *
152
+ * @returns a list of unused addresses
153
+ */
154
+ getUnusedAddresses(): Promise<string[]>;
155
+ /**
156
+ * Returns a list of used addresses controlled by the wallet.
157
+ *
158
+ * @returns a list of used addresses
159
+ */
160
+ getUsedAddresses(): Promise<string[]>;
161
+ /**
162
+ * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
163
+ *
164
+ * This is used in transaction building.
165
+ *
166
+ * @returns a list of UTXOs
167
+ */
168
+ getUsedCollateral(limit?: number): Promise<TransactionUnspentOutput[]>;
169
+ /**
170
+ * Return a list of all UTXOs (unspent transaction outputs) controlled by the wallet.
171
+ *
172
+ * @returns a list of UTXOs
173
+ */
174
+ getUtxos(): Promise<UTxO[]>;
175
+ /**
176
+ * This endpoint utilizes the [CIP-8 - Message Signing](https://github.com/cardano-foundation/CIPs/tree/master/CIP-0030) to sign arbitrary data, to verify the data was signed by the owner of the private key.
177
+ *
178
+ * Here, we get the first wallet's address with wallet.getUsedAddresses(), alternativelly you can use reward addresses (getRewardAddresses()) too. It's really up to you as the developer which address you want to use in your application.
179
+ *
180
+ * @param address
181
+ * @param payload
182
+ * @returns a signature
183
+ */
184
+ signData(address: string, payload: string): Promise<DataSignature>;
185
+ /**
186
+ * 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.
187
+ *
188
+ * @param unsignedTx
189
+ * @param partialSign
190
+ * @returns a signed transaction in CBOR
191
+ */
192
+ signTx(unsignedTx: string, partialSign?: boolean): Promise<string>;
193
+ /**
194
+ * Experimental feature - sign multiple transactions at once (Supported wallet(s): Typhon)
195
+ *
196
+ * @param unsignedTxs - array of unsigned transactions in CborHex string
197
+ * @param partialSign - if the transactions are signed partially
198
+ * @returns array of signed transactions CborHex string
199
+ */
200
+ signTxs(unsignedTxs: string[], partialSign?: boolean): Promise<string[]>;
201
+ /**
202
+ * Submits the signed transaction to the blockchain network.
203
+ *
204
+ * As wallets should already have this ability to submit transaction, we allow dApps 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 dApp to track. The wallet can return error messages or failure if there was an error in sending it.
205
+ *
206
+ * @param tx
207
+ * @returns a transaction hash
208
+ */
209
+ submitTx(tx: string): Promise<string>;
210
+ /**
211
+ * Get a used address of type Address from the wallet.
212
+ *
213
+ * This is used in transaction building.
214
+ *
215
+ * @returns an Address object
216
+ */
217
+ getUsedAddress(): Promise<Address>;
218
+ /**
219
+ * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
220
+ *
221
+ * This is used in transaction building.
222
+ *
223
+ * @returns a list of UTXOs
224
+ */
225
+ getCollateralUnspentOutput(): Promise<TransactionUnspentOutput[]>;
226
+ /**
227
+ * Get a list of UTXOs to be used for transaction building.
228
+ *
229
+ * This is used in transaction building.
230
+ *
231
+ * @returns a list of UTXOs
232
+ */
233
+ getUsedUTxOs(): Promise<TransactionUnspentOutput[]>;
234
+ /**
235
+ * A helper function to get the assets in the wallet.
236
+ *
237
+ * @returns a list of assets
238
+ */
239
+ getAssets(): Promise<AssetExtended[]>;
240
+ /**
241
+ * A helper function to get the lovelace balance in the wallet.
242
+ *
243
+ * @returns lovelace balance
244
+ */
245
+ getLovelace(): Promise<string>;
246
+ /**
247
+ * A helper function to get the assets of a specific policy ID in the wallet.
248
+ *
249
+ * @param policyId
250
+ * @returns a list of assets
251
+ */
252
+ getPolicyIdAssets(policyId: string): Promise<AssetExtended[]>;
253
+ /**
254
+ * A helper function to get the policy IDs of all the assets in the wallet.
255
+ *
256
+ * @returns a list of policy IDs
257
+ */
258
+ getPolicyIds(): Promise<string[]>;
259
+ private static resolveInstance;
260
+ static addBrowserWitnesses(unsignedTx: string, witnesses: string): string;
261
+ }
262
+
263
+ type Account = {
264
+ baseAddress: Address;
265
+ enterpriseAddress: Address;
266
+ rewardAddress: Address;
267
+ baseAddressBech32: string;
268
+ enterpriseAddressBech32: string;
269
+ rewardAddressBech32: string;
270
+ paymentKey: PrivateKey;
271
+ stakeKey: PrivateKey;
272
+ paymentKeyHex: string;
273
+ stakeKeyHex: string;
274
+ };
275
+ type EmbeddedWalletKeyType = {
276
+ type: "root";
277
+ bech32: string;
278
+ } | {
279
+ type: "cli";
280
+ payment: string;
281
+ stake?: string;
282
+ } | {
283
+ type: "mnemonic";
284
+ words: string[];
285
+ };
286
+ type CreateEmbeddedWalletOptions = {
287
+ networkId: number;
288
+ key: EmbeddedWalletKeyType;
289
+ };
290
+ declare class WalletStaticMethods {
291
+ static privateKeyToEntropy(bech32: string): string;
292
+ static mnemonicToEntropy(words: string[]): string;
293
+ static signingKeyToEntropy(paymentKey: string, stakeKey: string): [string, string];
294
+ static getAddresses(paymentKey: PrivateKey, stakingKey: PrivateKey, networkId?: number): {
295
+ baseAddress: Address;
296
+ enterpriseAddress: Address;
297
+ rewardAddress: Address;
298
+ };
299
+ static generateMnemonic(strength?: number): string[];
300
+ static addWitnessSets(txHex: string, witnesses: VkeyWitness[]): string;
301
+ }
302
+ declare class EmbeddedWallet extends WalletStaticMethods {
303
+ private readonly _entropy?;
304
+ private readonly _networkId;
305
+ constructor(options: CreateEmbeddedWalletOptions);
306
+ getAccount(accountIndex?: number, keyIndex?: number): Account;
307
+ getNetworkId(): number;
308
+ signData(address: string, payload: string, accountIndex?: number, keyIndex?: number): DataSignature;
309
+ signTx(unsignedTx: string, accountIndex?: number, keyIndex?: number): VkeyWitness;
310
+ }
311
+
312
+ type CreateMeshWalletOptions = {
313
+ networkId: number;
314
+ fetcher?: IFetcher;
315
+ submitter?: ISubmitter;
316
+ key: {
317
+ type: "root";
318
+ bech32: string;
319
+ } | {
320
+ type: "cli";
321
+ payment: string;
322
+ stake?: string;
323
+ } | {
324
+ type: "mnemonic";
325
+ words: string[];
326
+ };
327
+ };
328
+ /**
329
+ * Mesh Wallet provides a set of APIs to interact with the blockchain. This wallet is compatible with Mesh transaction builders.
330
+ *
331
+ * It is a single address wallet, a wrapper around the AppWallet class.
332
+ *
333
+ * ```javascript
334
+ * import { MeshWallet, BlockfrostProvider } from '@meshsdksdk/core';
335
+ *
336
+ * const blockchainProvider = new BlockfrostProvider('<BLOCKFROST_API_KEY>');
337
+ *
338
+ * const wallet = new MeshWallet({
339
+ * networkId: 0,
340
+ * fetcher: blockchainProvider,
341
+ * submitter: blockchainProvider,
342
+ * key: {
343
+ * type: 'mnemonic',
344
+ * words: ["solution","solution","solution","solution","solution",","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution"],
345
+ * },
346
+ * });
347
+ * ```
348
+ */
349
+ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
350
+ private readonly _wallet;
351
+ constructor(options: CreateMeshWalletOptions);
352
+ /**
353
+ * 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:
354
+ * - A unit is provided to display asset's name on the user interface.
355
+ * - A quantity is provided to display asset's quantity on the user interface.
356
+ *
357
+ * @returns a list of assets and their quantities
358
+ */
359
+ getBalance(): Promise<Asset[]>;
360
+ /**
361
+ * 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.
362
+ *
363
+ * @returns an address
364
+ */
365
+ getChangeAddress(): string;
366
+ /**
367
+ * 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).
368
+ *
369
+ * 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.
370
+ *
371
+ * @returns a list of UTXOs
372
+ */
373
+ getCollateral(addressType?: GetAddressType): Promise<UTxO[]>;
374
+ /**
375
+ * 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.
376
+ *
377
+ * @returns network ID
378
+ */
379
+ getNetworkId(): number;
380
+ /**
381
+ * 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.
382
+ *
383
+ * @returns a list of reward addresses
384
+ */
385
+ getRewardAddresses(): string[];
386
+ /**
387
+ * Returns a list of unused addresses controlled by the wallet.
388
+ *
389
+ * @returns a list of unused addresses
390
+ */
391
+ getUnusedAddresses(): string[];
392
+ /**
393
+ * Returns a list of used addresses controlled by the wallet.
394
+ *
395
+ * @returns a list of used addresses
396
+ */
397
+ getUsedAddresses(): string[];
398
+ /**
399
+ * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
400
+ *
401
+ * This is used in transaction building.
402
+ *
403
+ * @returns a list of UTXOs
404
+ */
405
+ getUsedCollateral(): Promise<TransactionUnspentOutput[]>;
406
+ /**
407
+ * Get a list of UTXOs to be used for transaction building.
408
+ *
409
+ * This is used in transaction building.
410
+ *
411
+ * @returns a list of UTXOs
412
+ */
413
+ getUsedUTxOs(addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
414
+ /**
415
+ * Return a list of all UTXOs (unspent transaction outputs) controlled by the wallet.
416
+ *
417
+ * @returns a list of UTXOs
418
+ */
419
+ getUtxos(addressType?: GetAddressType): Promise<UTxO[]>;
420
+ /**
421
+ * This endpoint utilizes the [CIP-8 - Message Signing](https://github.com/cardano-foundation/CIPs/tree/master/CIP-0030) to sign arbitrary data, to verify the data was signed by the owner of the private key.
422
+ *
423
+ * Here, we get the first wallet's address with wallet.getUsedAddresses(), alternativelly you can use reward addresses (getRewardAddresses()) too. It's really up to you as the developer which address you want to use in your application.
424
+ *
425
+ * @param address
426
+ * @param payload
427
+ * @returns a signature
428
+ */
429
+ signData(payload: string): DataSignature;
430
+ /**
431
+ * 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.
432
+ *
433
+ * @param unsignedTx
434
+ * @param partialSign
435
+ * @returns a signed transaction in CBOR
436
+ */
437
+ signTx(unsignedTx: string, partialSign?: boolean): string;
438
+ /**
439
+ * Experimental feature - sign multiple transactions at once.
440
+ *
441
+ * @param unsignedTxs - array of unsigned transactions in CborHex string
442
+ * @param partialSign - if the transactions are signed partially
443
+ * @returns array of signed transactions CborHex string
444
+ */
445
+ signTxs(unsignedTxs: string[], partialSign?: boolean): string[];
446
+ /**
447
+ * Submits the signed transaction to the blockchain network.
448
+ *
449
+ * As wallets should already have this ability to submit transaction, we allow dApps 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 dApp to track. The wallet can return error messages or failure if there was an error in sending it.
450
+ *
451
+ * @param tx
452
+ * @returns a transaction hash
453
+ */
454
+ submitTx(tx: string): Promise<string>;
455
+ /**
456
+ * Get a used address of type Address from the wallet.
457
+ *
458
+ * This is used in transaction building.
459
+ *
460
+ * @returns an Address object
461
+ */
462
+ getUsedAddress(addressType?: GetAddressType): Address;
463
+ /**
464
+ * Get a list of UTXOs to be used for transaction building.
465
+ *
466
+ * This is used in transaction building.
467
+ *
468
+ * @returns a list of UTXOs
469
+ */
470
+ getUnspentOutputs(addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
471
+ /**
472
+ * A helper function to get the assets in the wallet.
473
+ *
474
+ * @returns a list of assets
475
+ */
476
+ getAssets(): Promise<AssetExtended[]>;
477
+ /**
478
+ * A helper function to get the lovelace balance in the wallet.
479
+ *
480
+ * @returns lovelace balance
481
+ */
482
+ getLovelace(): Promise<string>;
483
+ /**
484
+ * A helper function to get the assets of a specific policy ID in the wallet.
485
+ *
486
+ * @param policyId
487
+ * @returns a list of assets
488
+ */
489
+ getPolicyIdAssets(policyId: string): Promise<AssetExtended[]>;
490
+ /**
491
+ * A helper function to get the policy IDs of all the assets in the wallet.
492
+ *
493
+ * @returns a list of policy IDs
494
+ */
495
+ getPolicyIds(): Promise<string[]>;
496
+ /**
497
+ * A helper function to create a collateral input for a transaction.
498
+ *
499
+ * @returns a transaction hash
500
+ */
501
+ createCollateral(): Promise<string>;
502
+ /**
503
+ * Generate mnemonic or private key
504
+ *
505
+ * @param privateKey return private key if true
506
+ * @returns a transaction hash
507
+ */
508
+ static brew(privateKey?: boolean, strength?: number): string[] | string;
509
+ }
510
+
511
+ export { type Account, AppWallet, type AppWalletKeyType, BrowserWallet, type CreateAppWalletOptions, type CreateEmbeddedWalletOptions, type CreateMeshWalletOptions, EmbeddedWallet, type EmbeddedWalletKeyType, MeshWallet, WalletStaticMethods };