@metamask-previews/keyring-controller 27.1.1-preview-8bfa290fb → 28.0.0-preview-0a30e47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/{KeyringController-method-action-types.d.mts → KeyringController-method-action-types.d.ts} +2 -2
  3. package/dist/KeyringController-method-action-types.d.ts.map +1 -0
  4. package/dist/{KeyringController-method-action-types.mjs → KeyringController-method-action-types.js} +1 -1
  5. package/dist/KeyringController-method-action-types.js.map +1 -0
  6. package/dist/{KeyringController.d.cts → KeyringController.d.ts} +13 -13
  7. package/dist/KeyringController.d.ts.map +1 -0
  8. package/dist/KeyringController.js +2102 -0
  9. package/dist/KeyringController.js.map +1 -0
  10. package/dist/{constants.d.cts → constants.d.ts} +1 -1
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/{constants.mjs → constants.js} +1 -1
  13. package/dist/constants.js.map +1 -0
  14. package/dist/{errors.d.mts → errors.d.ts} +1 -1
  15. package/dist/errors.d.ts.map +1 -0
  16. package/dist/{errors.mjs → errors.js} +19 -2
  17. package/dist/errors.js.map +1 -0
  18. package/dist/{index.d.cts → index.d.ts} +6 -6
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +4 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/{types.d.cts → types.d.ts} +2 -2
  23. package/dist/types.d.ts.map +1 -0
  24. package/dist/types.js +2 -0
  25. package/dist/types.js.map +1 -0
  26. package/package.json +17 -22
  27. package/dist/KeyringController-method-action-types.cjs +0 -7
  28. package/dist/KeyringController-method-action-types.cjs.map +0 -1
  29. package/dist/KeyringController-method-action-types.d.cts +0 -491
  30. package/dist/KeyringController-method-action-types.d.cts.map +0 -1
  31. package/dist/KeyringController-method-action-types.d.mts.map +0 -1
  32. package/dist/KeyringController-method-action-types.mjs.map +0 -1
  33. package/dist/KeyringController.cjs +0 -2018
  34. package/dist/KeyringController.cjs.map +0 -1
  35. package/dist/KeyringController.d.cts.map +0 -1
  36. package/dist/KeyringController.d.mts +0 -825
  37. package/dist/KeyringController.d.mts.map +0 -1
  38. package/dist/KeyringController.mjs +0 -1994
  39. package/dist/KeyringController.mjs.map +0 -1
  40. package/dist/constants.cjs +0 -48
  41. package/dist/constants.cjs.map +0 -1
  42. package/dist/constants.d.cts.map +0 -1
  43. package/dist/constants.d.mts +0 -44
  44. package/dist/constants.d.mts.map +0 -1
  45. package/dist/constants.mjs.map +0 -1
  46. package/dist/errors.cjs +0 -114
  47. package/dist/errors.cjs.map +0 -1
  48. package/dist/errors.d.cts +0 -91
  49. package/dist/errors.d.cts.map +0 -1
  50. package/dist/errors.d.mts.map +0 -1
  51. package/dist/errors.mjs.map +0 -1
  52. package/dist/index.cjs +0 -22
  53. package/dist/index.cjs.map +0 -1
  54. package/dist/index.d.cts.map +0 -1
  55. package/dist/index.d.mts +0 -6
  56. package/dist/index.d.mts.map +0 -1
  57. package/dist/index.mjs +0 -4
  58. package/dist/index.mjs.map +0 -1
  59. package/dist/types.cjs +0 -3
  60. package/dist/types.cjs.map +0 -1
  61. package/dist/types.d.cts.map +0 -1
  62. package/dist/types.d.mts +0 -80
  63. package/dist/types.d.mts.map +0 -1
  64. package/dist/types.mjs +0 -2
  65. package/dist/types.mjs.map +0 -1
@@ -1,825 +0,0 @@
1
- import type { TypedTransaction, TypedTxData } from "@ethereumjs/tx";
2
- import { BaseController } from "@metamask/base-controller";
3
- import type * as encryptorUtils from "@metamask/browser-passworder";
4
- import type { KeyringExecutionContext, EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, KeyringAccount } from "@metamask/keyring-api";
5
- import type { Keyring as KeyringV2, KeyringType } from "@metamask/keyring-api/v2";
6
- import type { EthKeyring } from "@metamask/keyring-internal-api";
7
- import type { Keyring, KeyringClass } from "@metamask/keyring-utils";
8
- import type { Messenger } from "@metamask/messenger";
9
- import type { Eip1024EncryptedData, Hex, Json } from "@metamask/utils";
10
- import type { Patch } from "immer";
11
- import type { KeyringControllerMethodActions } from "./KeyringController-method-action-types.mjs";
12
- import type { Eip7702AuthorizationParams, Credentials, PersonalMessageParams, TypedMessageParams } from "./types.mjs";
13
- declare const name = "KeyringController";
14
- /**
15
- * Available keyring types
16
- *
17
- * @deprecated Use `KeyringType` from `@metamask/keyring-api/v2` instead. This enum will be removed
18
- * in a future release once V2 is fully adopted. Only use it if the keyring you are trying to access
19
- * has no V2 builder available yet.
20
- */
21
- export declare enum KeyringTypes {
22
- simple = "Simple Key Pair",
23
- hd = "HD Key Tree",
24
- qr = "QR Hardware Wallet Device",
25
- trezor = "Trezor Hardware",
26
- oneKey = "OneKey Hardware",
27
- ledger = "Ledger Hardware",
28
- lattice = "Lattice Hardware",
29
- snap = "Snap Keyring",
30
- money = "Money Keyring"
31
- }
32
- /**
33
- * Custody keyring types are a special case, as they are not a single type
34
- * but they all start with the prefix "Custody".
35
- *
36
- * @param keyringType - The type of the keyring.
37
- * @returns Whether the keyring type is a custody keyring.
38
- */
39
- export declare const isCustodyKeyring: (keyringType: string) => boolean;
40
- /**
41
- * The KeyringController state
42
- */
43
- export type KeyringControllerState = {
44
- /**
45
- * Encrypted array of serialized keyrings data.
46
- */
47
- vault?: string;
48
- /**
49
- * Whether the vault has been decrypted successfully and
50
- * keyrings contained within are deserialized and available.
51
- */
52
- isUnlocked: boolean;
53
- /**
54
- * Representations of managed keyrings.
55
- */
56
- keyrings: KeyringObject[];
57
- /**
58
- * The encryption key derived from the password and used to encrypt
59
- * the vault. This is only stored if the `cacheEncryptionKey` option
60
- * is enabled.
61
- */
62
- encryptionKey?: string;
63
- /**
64
- * The salt used to derive the encryption key from the password.
65
- */
66
- encryptionSalt?: string;
67
- };
68
- export type KeyringControllerMemState = Omit<KeyringControllerState, 'vault' | 'encryptionKey' | 'encryptionSalt'>;
69
- export type KeyringControllerGetStateAction = {
70
- type: `${typeof name}:getState`;
71
- handler: () => KeyringControllerState;
72
- };
73
- export type KeyringControllerStateChangeEvent = {
74
- type: `${typeof name}:stateChange`;
75
- payload: [KeyringControllerState, Patch[]];
76
- };
77
- export type KeyringControllerAccountRemovedEvent = {
78
- type: `${typeof name}:accountRemoved`;
79
- payload: [string];
80
- };
81
- export type KeyringControllerLockEvent = {
82
- type: `${typeof name}:lock`;
83
- payload: [];
84
- };
85
- export type KeyringControllerUnlockEvent = {
86
- type: `${typeof name}:unlock`;
87
- payload: [];
88
- };
89
- export type KeyringControllerActions = KeyringControllerGetStateAction | KeyringControllerMethodActions;
90
- export type KeyringControllerEvents = KeyringControllerStateChangeEvent | KeyringControllerLockEvent | KeyringControllerUnlockEvent | KeyringControllerAccountRemovedEvent;
91
- export type KeyringControllerMessenger = Messenger<typeof name, KeyringControllerActions, KeyringControllerEvents>;
92
- export type KeyringControllerOptions<EncryptionKey = encryptorUtils.EncryptionKey | CryptoKey, SupportedKeyDerivationOptions = encryptorUtils.KeyDerivationOptions, EncryptionResult extends EncryptionResultConstraint<SupportedKeyDerivationOptions> = DefaultEncryptionResult<SupportedKeyDerivationOptions>> = {
93
- keyringBuilders?: {
94
- (): EthKeyring;
95
- type: string;
96
- }[];
97
- keyringV2Builders?: KeyringV2Builder[];
98
- messenger: KeyringControllerMessenger;
99
- state?: {
100
- vault?: string;
101
- keyringsMetadata?: KeyringMetadata[];
102
- };
103
- encryptor: Encryptor<EncryptionKey, SupportedKeyDerivationOptions, EncryptionResult>;
104
- };
105
- /**
106
- * A keyring object representation.
107
- */
108
- export type KeyringObject = {
109
- /**
110
- * Accounts associated with the keyring.
111
- */
112
- accounts: string[];
113
- /**
114
- * Keyring type.
115
- */
116
- type: string;
117
- /**
118
- * Additional data associated with the keyring.
119
- */
120
- metadata: KeyringMetadata;
121
- };
122
- /**
123
- * Additional information related to a keyring.
124
- */
125
- export type KeyringMetadata = {
126
- /**
127
- * Keyring ID
128
- */
129
- id: string;
130
- /**
131
- * Keyring name
132
- */
133
- name: string;
134
- };
135
- /**
136
- * A keyring entry, including the keyring instance (+ v2 instance) and its metadata.
137
- */
138
- export type KeyringEntry = {
139
- /**
140
- * The keyring instance.
141
- */
142
- keyring: EthKeyring;
143
- /**
144
- * The keyring V2 instance, if available.
145
- */
146
- keyringV2?: KeyringV2;
147
- /**
148
- * The keyring metadata.
149
- */
150
- metadata: KeyringMetadata;
151
- };
152
- /**
153
- * A restricted view of the {@link KeyringController} exposed to the callback
154
- * passed to {@link KeyringController.withController}.
155
- *
156
- * It provides a read-only live view of all keyrings and the ability to stage
157
- * keyring additions and removals atomically within a single transaction.
158
- */
159
- export type RestrictedController = {
160
- /**
161
- * Read-only live view of all keyrings in the current transaction (original
162
- * keyrings plus any added, minus any removed so far in this callback).
163
- */
164
- readonly keyrings: readonly KeyringEntry[];
165
- /**
166
- * Create a new keyring of the given type and stage it for commit. The new
167
- * entry is immediately visible in {@link RestrictedController.keyrings}.
168
- *
169
- * @param type - The type of keyring to create.
170
- * @param opts - Optional data to pass to the keyring builder.
171
- * @returns The newly created `{ keyring, metadata }` entry.
172
- */
173
- addNewKeyring(type: string, opts?: unknown): Promise<KeyringEntry>;
174
- /**
175
- * Stage the keyring with the given id for removal. The keyring is
176
- * immediately removed from {@link RestrictedController.keyrings}.
177
- *
178
- * @param id - The id of the keyring to remove.
179
- */
180
- removeKeyring(id: string): Promise<void>;
181
- };
182
- /**
183
- * A strategy for importing an account
184
- */
185
- export declare enum AccountImportStrategy {
186
- privateKey = "privateKey",
187
- json = "json"
188
- }
189
- /**
190
- * The `signTypedMessage` version
191
- *
192
- * @see https://docs.metamask.io/guide/signing-data.html
193
- */
194
- export declare enum SignTypedDataVersion {
195
- V1 = "V1",
196
- V3 = "V3",
197
- V4 = "V4"
198
- }
199
- /**
200
- * A serialized keyring object.
201
- */
202
- export type SerializedKeyring = {
203
- type: string;
204
- data: Json;
205
- metadata?: KeyringMetadata;
206
- };
207
- export type EncryptionResultConstraint<SupportedKeyMetadata> = {
208
- salt?: string;
209
- keyMetadata?: SupportedKeyMetadata;
210
- };
211
- export type DefaultEncryptionResult<SupportedKeyMetadata> = {
212
- data: string;
213
- iv: string;
214
- salt?: string;
215
- keyMetadata?: SupportedKeyMetadata;
216
- };
217
- /**
218
- * An encryptor interface that supports encrypting and decrypting
219
- * serializable data with a password, and exporting and importing keys.
220
- */
221
- export type Encryptor<EncryptionKey = encryptorUtils.EncryptionKey | CryptoKey, SupportedKeyDerivationParams = encryptorUtils.KeyDerivationOptions, EncryptionResult extends EncryptionResultConstraint<SupportedKeyDerivationParams> = DefaultEncryptionResult<SupportedKeyDerivationParams>> = {
222
- /**
223
- * Encrypts the given object with the given password.
224
- *
225
- * @param password - The password to encrypt with.
226
- * @param object - The object to encrypt.
227
- * @returns The encrypted string.
228
- */
229
- encrypt: (password: string, object: Json) => Promise<string>;
230
- /**
231
- * Decrypts the given encrypted string with the given password.
232
- *
233
- * @param password - The password to decrypt with.
234
- * @param encryptedString - The encrypted string to decrypt.
235
- * @returns The decrypted object.
236
- */
237
- decrypt: (password: string, encryptedString: string) => Promise<unknown>;
238
- /**
239
- * Optional vault migration helper. Checks if the provided vault is up to date
240
- * with the desired encryption algorithm.
241
- *
242
- * @param vault - The encrypted string to check.
243
- * @param targetDerivationParams - The desired target derivation params.
244
- * @returns The updated encrypted string.
245
- */
246
- isVaultUpdated?: (vault: string, targetDerivationParams?: encryptorUtils.KeyDerivationOptions) => boolean;
247
- /**
248
- * Encrypts the given object with the given encryption key.
249
- *
250
- * @param key - The encryption key to encrypt with.
251
- * @param object - The object to encrypt.
252
- * @returns The encryption result.
253
- */
254
- encryptWithKey: (key: EncryptionKey, object: Json) => Promise<EncryptionResult>;
255
- /**
256
- * Encrypts the given object with the given password, and returns the
257
- * encryption result and the serialized key string.
258
- *
259
- * @param password - The password to encrypt with.
260
- * @param object - The object to encrypt.
261
- * @param salt - The optional salt to use for encryption.
262
- * @returns The encrypted string and the serialized key string.
263
- */
264
- encryptWithDetail: (password: string, object: Json, salt?: string) => Promise<encryptorUtils.DetailedEncryptionResult>;
265
- /**
266
- * Decrypts the given encrypted string with the given encryption key.
267
- *
268
- * @param key - The encryption key to decrypt with.
269
- * @param encryptedObject - The encrypted string to decrypt.
270
- * @returns The decrypted object.
271
- */
272
- decryptWithKey: (key: EncryptionKey, encryptedObject: EncryptionResult) => Promise<unknown>;
273
- /**
274
- * Decrypts the given encrypted string with the given password, and returns
275
- * the decrypted object and the salt and serialized key string used for
276
- * encryption.
277
- *
278
- * @param password - The password to decrypt with.
279
- * @param encryptedString - The encrypted string to decrypt.
280
- * @returns The decrypted object and the salt and serialized key string used for
281
- * encryption.
282
- */
283
- decryptWithDetail: (password: string, encryptedString: string) => Promise<encryptorUtils.DetailedDecryptResult>;
284
- /**
285
- * Generates an encryption key from a serialized key.
286
- *
287
- * @param key - The serialized key string.
288
- * @returns The encryption key.
289
- */
290
- importKey: (key: string) => Promise<EncryptionKey>;
291
- /**
292
- * Exports the encryption key as a string.
293
- *
294
- * @param key - The encryption key to export.
295
- * @returns The serialized key string.
296
- */
297
- exportKey: (key: EncryptionKey) => Promise<string>;
298
- /**
299
- * Derives an encryption key from a password.
300
- *
301
- * @param password - The password to derive the key from.
302
- * @param salt - The salt to use for key derivation.
303
- * @param exportable - Whether the key should be exportable or not.
304
- * @param options - Optional key derivation options.
305
- * @returns The derived encryption key.
306
- */
307
- keyFromPassword: (password: string, salt: string, exportable?: boolean, keyDerivationOptions?: SupportedKeyDerivationParams) => Promise<EncryptionKey>;
308
- /**
309
- * Generates a random salt for key derivation.
310
- */
311
- generateSalt: typeof encryptorUtils.generateSalt;
312
- };
313
- /**
314
- * Keyring selector used for `withKeyring`.
315
- */
316
- export type KeyringSelector<SelectedKeyring extends EthKeyring = EthKeyring> = {
317
- type: string;
318
- index?: number;
319
- } | {
320
- address: Hex;
321
- } | {
322
- id: string;
323
- } | {
324
- /**
325
- * A predicate function used to select a keyring. The first keyring for
326
- * which this function returns `true` will be selected.
327
- *
328
- * NOTE: The caller must not mutate the keyring instance passed to this
329
- * function. Mutations bypass the controller's state management
330
- * safeguards and will lead to inconsistent state. The instance is not
331
- * frozen for performance reasons, but treating it as read-only is a
332
- * firm requirement — any mutation is a bug in the caller.
333
- */
334
- filter: ((keyring: EthKeyring, metadata: KeyringMetadata) => boolean) | ((keyring: EthKeyring, metadata: KeyringMetadata) => keyring is SelectedKeyring);
335
- };
336
- /**
337
- * Keyring selector used for `withKeyringV2` (see {@link KeyringController#withKeyringV2} and {@link KeyringSelector}).
338
- */
339
- export type KeyringSelectorV2<SelectedKeyring extends KeyringV2 = KeyringV2> = {
340
- type: `${KeyringType}`;
341
- index?: number;
342
- } | {
343
- address: KeyringAccount['address'];
344
- } | {
345
- id: KeyringMetadata['id'];
346
- } | {
347
- /** Similar to {@link KeyringSelector.filter} but for `KeyringV2` instances. */
348
- filter: ((keyring: KeyringV2, metadata: KeyringMetadata) => boolean) | ((keyring: KeyringV2, metadata: KeyringMetadata) => keyring is SelectedKeyring);
349
- };
350
- /**
351
- * Keyring builder.
352
- */
353
- export type KeyringBuilder = {
354
- (): Keyring;
355
- type: string;
356
- };
357
- /**
358
- * A builder that wraps a legacy `Keyring` into a `KeyringV2` adapter.
359
- *
360
- * The controller calls the builder once when the V1 keyring is created
361
- * or restored; the resulting wrapper is cached for the keyring's lifetime.
362
- */
363
- export type KeyringV2Builder = {
364
- (keyring: Keyring, metadata: KeyringMetadata): KeyringV2;
365
- type: string;
366
- };
367
- /**
368
- * Get builder function for `Keyring`
369
- *
370
- * Returns a builder function for `Keyring` with a `type` property.
371
- *
372
- * @param KeyringConstructor - The Keyring class for the builder.
373
- * @returns A builder function for the given Keyring.
374
- */
375
- export declare function keyringBuilderFactory(KeyringConstructor: KeyringClass): KeyringBuilder;
376
- export declare const getDefaultKeyringState: () => KeyringControllerState;
377
- /**
378
- * Controller responsible for establishing and managing user identity.
379
- *
380
- * This class is a wrapper around the `eth-keyring-controller` package. The
381
- * `eth-keyring-controller` manages the "vault", which is an encrypted store of private keys, and
382
- * it manages the wallet "lock" state. This wrapper class has convenience methods for interacting
383
- * with the internal keyring controller and handling certain complex operations that involve the
384
- * keyrings.
385
- */
386
- export declare class KeyringController<EncryptionKey = encryptorUtils.EncryptionKey | CryptoKey, SupportedKeyDerivationOptions = encryptorUtils.KeyDerivationOptions, EncryptionResult extends EncryptionResultConstraint<SupportedKeyDerivationOptions> = DefaultEncryptionResult<SupportedKeyDerivationOptions>> extends BaseController<typeof name, KeyringControllerState, KeyringControllerMessenger> {
387
- #private;
388
- /**
389
- * Creates a KeyringController instance.
390
- *
391
- * @param options - Initial options used to configure this controller
392
- * @param options.encryptor - An optional object for defining encryption schemes.
393
- * @param options.keyringBuilders - Set a new name for account.
394
- * @param options.cacheEncryptionKey - Whether to cache or not encryption key.
395
- * @param options.messenger - A restricted messenger.
396
- * @param options.state - Initial state to set on this controller.
397
- */
398
- constructor(options: KeyringControllerOptions<EncryptionKey, SupportedKeyDerivationOptions, EncryptionResult>);
399
- /**
400
- * Adds a new account to the default (first) HD seed phrase keyring.
401
- *
402
- * @param accountCount - Number of accounts before adding a new one, used to
403
- * make the method idempotent.
404
- * @returns Promise resolving to the added account address.
405
- */
406
- addNewAccount(accountCount?: number): Promise<string>;
407
- /**
408
- * Adds a new account to the specified keyring.
409
- *
410
- * @param keyring - Keyring to add the account to.
411
- * @param accountCount - Number of accounts before adding a new one, used to make the method idempotent.
412
- * @returns Promise resolving to the added account address
413
- */
414
- addNewAccountForKeyring(keyring: EthKeyring, accountCount?: number): Promise<Hex>;
415
- /**
416
- * Effectively the same as creating a new keychain then populating it
417
- * using the given seed phrase.
418
- *
419
- * @param password - Password to unlock keychain.
420
- * @param seed - A BIP39-compliant seed phrase as Uint8Array,
421
- * either as a string or an array of UTF-8 bytes that represent the string.
422
- * @returns Promise resolving when the operation ends successfully.
423
- */
424
- createNewVaultAndRestore(password: string, seed: Uint8Array): Promise<void>;
425
- /**
426
- * Create a new vault and primary keyring.
427
- *
428
- * This only works if keyrings are empty. If there is a pre-existing unlocked vault, calling this will have no effect.
429
- * If there is a pre-existing locked vault, it will be replaced.
430
- *
431
- * @param password - Password to unlock the new vault.
432
- * @returns Promise resolving when the operation ends successfully.
433
- */
434
- createNewVaultAndKeychain(password: string): Promise<void>;
435
- /**
436
- * Adds a new keyring of the given `type`.
437
- *
438
- * @param type - Keyring type name.
439
- * @param opts - Keyring options.
440
- * @throws If a builder for the given `type` does not exist.
441
- * @returns Promise resolving to the new keyring metadata.
442
- */
443
- addNewKeyring(type: KeyringTypes | string, opts?: unknown): Promise<KeyringMetadata>;
444
- /**
445
- * Method to verify a given password validity. Throws an
446
- * error if the password is invalid.
447
- *
448
- * @param password - Password of the keyring.
449
- */
450
- verifyPassword(password: string): Promise<void>;
451
- /**
452
- * Returns the status of the vault.
453
- *
454
- * @returns Boolean returning true if the vault is unlocked.
455
- */
456
- isUnlocked(): boolean;
457
- /**
458
- * Gets the seed phrase of the HD keyring.
459
- *
460
- * @param credentials - Object holding either the `password` or the vault
461
- * `encryptionKey`.
462
- * @param keyringId - The id of the keyring.
463
- * @returns Promise resolving to the seed phrase.
464
- */
465
- exportSeedPhrase(credentials: Credentials, keyringId?: string): Promise<Uint8Array>;
466
- /**
467
- * Gets the private key from the keyring controlling an address.
468
- *
469
- * @param credentials - Object holding either the `password` or the vault
470
- * `encryptionKey`.
471
- * @param address - Address to export.
472
- * @returns Promise resolving to the private key for an address.
473
- */
474
- exportAccount(credentials: Credentials, address: string): Promise<string>;
475
- /**
476
- * Returns the public addresses of all accounts from every keyring.
477
- *
478
- * @returns A promise resolving to an array of addresses.
479
- */
480
- getAccounts(): Promise<string[]>;
481
- /**
482
- * Get encryption public key.
483
- *
484
- * @param account - An account address.
485
- * @param opts - Additional encryption options.
486
- * @throws If the `account` does not exist or does not support the `getEncryptionPublicKey` method
487
- * @returns Promise resolving to encyption public key of the `account` if one exists.
488
- */
489
- getEncryptionPublicKey(account: string, opts?: Record<string, unknown>): Promise<string>;
490
- /**
491
- * Attempts to decrypt the provided message parameters.
492
- *
493
- * @param messageParams - The decryption message parameters.
494
- * @param messageParams.from - The address of the account you want to use to decrypt the message.
495
- * @param messageParams.data - The encrypted data that you want to decrypt.
496
- * @returns The raw decryption result.
497
- */
498
- decryptMessage(messageParams: {
499
- from: string;
500
- data: Eip1024EncryptedData;
501
- }): Promise<string>;
502
- /**
503
- * Returns the currently initialized keyring that manages
504
- * the specified `address` if one exists.
505
- *
506
- * @deprecated Use of this method is discouraged as actions executed directly on
507
- * keyrings are not being reflected in the KeyringController state and not
508
- * persisted in the vault. Use `withKeyring` instead.
509
- * @param account - An account address.
510
- * @returns Promise resolving to keyring of the `account` if one exists.
511
- */
512
- getKeyringForAccount(account: string): Promise<unknown>;
513
- /**
514
- * Returns all keyrings of the given type.
515
- *
516
- * @deprecated Use of this method is discouraged as actions executed directly on
517
- * keyrings are not being reflected in the KeyringController state and not
518
- * persisted in the vault. Use `withKeyring` instead.
519
- * @param type - Keyring type name.
520
- * @returns An array of keyrings of the given type.
521
- */
522
- getKeyringsByType(type: KeyringTypes | string): unknown[];
523
- /**
524
- * Persist all serialized keyrings in the vault.
525
- *
526
- * @deprecated This method is being phased out in favor of `withKeyring`.
527
- * @returns Promise resolving with `true` value when the
528
- * operation completes.
529
- */
530
- persistAllKeyrings(): Promise<boolean>;
531
- /**
532
- * Imports an account with the specified import strategy.
533
- *
534
- * @param strategy - Import strategy name.
535
- * @param args - Array of arguments to pass to the underlying stategy.
536
- * @throws Will throw when passed an unrecognized strategy.
537
- * @returns Promise resolving to the imported account address.
538
- */
539
- importAccountWithStrategy(strategy: AccountImportStrategy, args: any[]): Promise<string>;
540
- /**
541
- * Removes an account from keyring state.
542
- *
543
- * @param address - Address of the account to remove.
544
- * @fires KeyringController:accountRemoved
545
- * @returns Promise resolving when the account is removed.
546
- */
547
- removeAccount(address: string): Promise<void>;
548
- /**
549
- * Deallocates all secrets and locks the wallet.
550
- *
551
- * @returns Promise resolving when the operation completes.
552
- */
553
- setLocked(): Promise<void>;
554
- /**
555
- * Signs message by calling down into a specific keyring.
556
- *
557
- * @param messageParams - PersonalMessageParams object to sign.
558
- * @returns Promise resolving to a signed message string.
559
- */
560
- signMessage(messageParams: PersonalMessageParams): Promise<string>;
561
- /**
562
- * Signs EIP-7702 Authorization message by calling down into a specific keyring.
563
- *
564
- * @param params - EIP7702AuthorizationParams object to sign.
565
- * @returns Promise resolving to an EIP-7702 Authorization signature.
566
- * @throws Will throw UnsupportedSignEIP7702Authorization if the keyring does not support signing EIP-7702 Authorization messages.
567
- */
568
- signEip7702Authorization(params: Eip7702AuthorizationParams): Promise<string>;
569
- /**
570
- * Signs personal message by calling down into a specific keyring.
571
- *
572
- * @param messageParams - PersonalMessageParams object to sign.
573
- * @returns Promise resolving to a signed message string.
574
- */
575
- signPersonalMessage(messageParams: PersonalMessageParams): Promise<string>;
576
- /**
577
- * Signs typed message by calling down into a specific keyring.
578
- *
579
- * @param messageParams - TypedMessageParams object to sign.
580
- * @param version - Compatibility version EIP712.
581
- * @throws Will throw when passed an unrecognized version.
582
- * @returns Promise resolving to a signed message string or an error if any.
583
- */
584
- signTypedMessage(messageParams: TypedMessageParams, version: SignTypedDataVersion): Promise<string>;
585
- /**
586
- * Signs a transaction by calling down into a specific keyring.
587
- *
588
- * @param transaction - Transaction object to sign. Must be a `ethereumjs-tx` transaction instance.
589
- * @param from - Address to sign from, should be in keychain.
590
- * @param opts - An optional options object.
591
- * @returns Promise resolving to a signed transaction string.
592
- */
593
- signTransaction(transaction: TypedTransaction, from: string, opts?: Record<string, unknown>): Promise<TypedTxData>;
594
- /**
595
- * Convert a base transaction to a base UserOperation.
596
- *
597
- * @param from - Address of the sender.
598
- * @param transactions - Base transactions to include in the UserOperation.
599
- * @param executionContext - The execution context to use for the UserOperation.
600
- * @returns A pseudo-UserOperation that can be used to construct a real.
601
- */
602
- prepareUserOperation(from: string, transactions: EthBaseTransaction[], executionContext: KeyringExecutionContext): Promise<EthBaseUserOperation>;
603
- /**
604
- * Patches properties of a UserOperation. Currently, only the
605
- * `paymasterAndData` can be patched.
606
- *
607
- * @param from - Address of the sender.
608
- * @param userOp - UserOperation to patch.
609
- * @param executionContext - The execution context to use for the UserOperation.
610
- * @returns A patch to apply to the UserOperation.
611
- */
612
- patchUserOperation(from: string, userOp: EthUserOperation, executionContext: KeyringExecutionContext): Promise<EthUserOperationPatch>;
613
- /**
614
- * Signs an UserOperation.
615
- *
616
- * @param from - Address of the sender.
617
- * @param userOp - UserOperation to sign.
618
- * @param executionContext - The execution context to use for the UserOperation.
619
- * @returns The signature of the UserOperation.
620
- */
621
- signUserOperation(from: string, userOp: EthUserOperation, executionContext: KeyringExecutionContext): Promise<string>;
622
- /**
623
- * Changes the password used to encrypt the vault.
624
- *
625
- * @param password - The new password.
626
- * @returns Promise resolving when the operation completes.
627
- */
628
- changePassword(password: string): Promise<void>;
629
- /**
630
- * Attempts to decrypt the current vault and load its keyrings, using the
631
- * given encryption key and salt. The optional salt can be used to check for
632
- * consistency with the vault salt.
633
- *
634
- * @param encryptionKey - Key to unlock the keychain.
635
- * @param encryptionSalt - Optional salt to unlock the keychain.
636
- * @returns Promise resolving when the operation completes.
637
- */
638
- submitEncryptionKey(encryptionKey: string, encryptionSalt?: string): Promise<void>;
639
- /**
640
- * Exports the vault encryption key.
641
- *
642
- * @returns The vault encryption key.
643
- */
644
- exportEncryptionKey(): Promise<string>;
645
- /**
646
- * Attempts to decrypt the current vault and load its keyrings,
647
- * using the given password.
648
- *
649
- * @param password - Password to unlock the keychain.
650
- * @returns Promise resolving when the operation completes.
651
- */
652
- submitPassword(password: string): Promise<void>;
653
- /**
654
- * Verifies the that the seed phrase restores the current keychain's accounts.
655
- *
656
- * @param keyringId - The id of the keyring to verify.
657
- * @returns Promise resolving to the seed phrase as Uint8Array.
658
- */
659
- verifySeedPhrase(keyringId?: string): Promise<Uint8Array>;
660
- /**
661
- * Select a keyring and execute the given operation with
662
- * the selected keyring, as a mutually exclusive atomic
663
- * operation.
664
- *
665
- * The method automatically persists changes at the end of the
666
- * function execution, or rolls back the changes if an error
667
- * is thrown.
668
- *
669
- * @param selector - Keyring selector object.
670
- * @param operation - Function to execute with the selected keyring.
671
- * @param options - Additional options.
672
- * @param options.createIfMissing - Whether to create a new keyring if the selected one is missing.
673
- * @param options.createWithData - Optional data to use when creating a new keyring.
674
- * @returns Promise resolving to the result of the function execution.
675
- * @template SelectedKeyring - The type of the selected keyring.
676
- * @template CallbackResult - The type of the value resolved by the callback function.
677
- * @deprecated This method overload is deprecated. Use `withKeyring` without options instead.
678
- */
679
- withKeyring<SelectedKeyring extends EthKeyring = EthKeyring, CallbackResult = void>(selector: KeyringSelector<SelectedKeyring>, operation: ({ keyring, metadata }: KeyringEntry) => Promise<CallbackResult>, options: {
680
- createIfMissing?: false;
681
- } | {
682
- createIfMissing: true;
683
- createWithData?: unknown;
684
- }): Promise<CallbackResult>;
685
- /**
686
- * Select a keyring and execute the given operation with
687
- * the selected keyring, as a mutually exclusive atomic
688
- * operation.
689
- *
690
- * The method automatically persists changes at the end of the
691
- * function execution, or rolls back the changes if an error
692
- * is thrown.
693
- *
694
- * @param selector - Keyring selector object.
695
- * @param operation - Function to execute with the selected keyring.
696
- * @returns Promise resolving to the result of the function execution.
697
- * @template SelectedKeyring - The type of the selected keyring.
698
- * @template CallbackResult - The type of the value resolved by the callback function.
699
- */
700
- withKeyring<SelectedKeyring extends EthKeyring = EthKeyring, CallbackResult = void>(selector: KeyringSelector<SelectedKeyring>, operation: ({ keyring, metadata }: KeyringEntry) => Promise<CallbackResult>): Promise<CallbackResult>;
701
- /**
702
- * Select a keyring and execute the given operation with the selected
703
- * keyring, **without** acquiring the controller's mutual exclusion lock.
704
- *
705
- * ## When to use this method
706
- *
707
- * This method is an escape hatch for read-only access to keyring data that
708
- * is immutable once the keyring is initialized. A typical safe use case is
709
- * reading the `mnemonic` from an `HdKeyring`: the mnemonic is set during
710
- * `deserialize()` and never mutated afterwards, so it can safely be read
711
- * without holding the lock.
712
- *
713
- * ## Why it is "unsafe"
714
- *
715
- * The "unsafe" designation mirrors the semantics of `unsafe { }` blocks in
716
- * Rust: the method itself does not enforce thread-safety guarantees. By
717
- * calling this method the **caller** explicitly takes responsibility for
718
- * ensuring that:
719
- *
720
- * - The operation is **read-only** — no state is mutated.
721
- * - The data being read is **immutable** after the keyring is initialized,
722
- * so concurrent locked operations cannot alter it while this callback
723
- * runs.
724
- *
725
- * Do **not** use this method to:
726
- * - Mutate keyring state (add accounts, sign, etc.) — use `withKeyring`.
727
- * - Read mutable fields that could change during concurrent operations.
728
- *
729
- * @param selector - Keyring selector object.
730
- * @param operation - Read-only function to execute with the selected keyring.
731
- * @returns Promise resolving to the result of the function execution.
732
- * @template SelectedKeyring - The type of the selected keyring.
733
- * @template CallbackResult - The type of the value resolved by the callback function.
734
- */
735
- withKeyringUnsafe<SelectedKeyring extends EthKeyring = EthKeyring, CallbackResult = void>(selector: KeyringSelector<SelectedKeyring>, operation: ({ keyring, metadata, }: {
736
- keyring: SelectedKeyring;
737
- metadata: KeyringMetadata;
738
- }) => Promise<CallbackResult>): Promise<CallbackResult>;
739
- /**
740
- * Select a keyring using its `KeyringV2` adapter, and execute
741
- * the given operation with the wrapped keyring as a mutually
742
- * exclusive atomic operation.
743
- *
744
- * The cached `KeyringV2` adapter is retrieved from the keyring
745
- * entry.
746
- *
747
- * A `KeyringV2Builder` for the selected keyring's type must exist
748
- * (either as a default or registered via the `keyringV2Builders`
749
- * constructor option); otherwise an error is thrown.
750
- *
751
- * The method automatically persists changes at the end of the
752
- * function execution, or rolls back the changes if an error
753
- * is thrown.
754
- *
755
- * @param selector - Keyring selector object.
756
- * @param operation - Function to execute with the wrapped V2 keyring.
757
- * @returns Promise resolving to the result of the function execution.
758
- * @template CallbackResult - The type of the value resolved by the callback function.
759
- */
760
- withKeyringV2<SelectedKeyring extends KeyringV2 = KeyringV2, CallbackResult = void>(selector: KeyringSelectorV2<SelectedKeyring>, operation: ({ keyring, metadata, }: {
761
- keyring: SelectedKeyring;
762
- metadata: KeyringMetadata;
763
- }) => Promise<CallbackResult>): Promise<CallbackResult>;
764
- /**
765
- * Select a keyring, wrap it in a `KeyringV2` adapter, and execute
766
- * the given read-only operation **without** acquiring the controller's
767
- * mutual exclusion lock.
768
- *
769
- * ## When to use this method
770
- *
771
- * This method is an escape hatch for read-only access to keyring data that
772
- * is immutable once the keyring is initialized. A typical safe use case is
773
- * reading immutable fields from a `KeyringV2` adapter: data that is set
774
- * during initialization and never mutated afterwards.
775
- *
776
- * ## Why it is "unsafe"
777
- *
778
- * The "unsafe" designation mirrors the semantics of `unsafe { }` blocks in
779
- * Rust: the method itself does not enforce thread-safety guarantees. By
780
- * calling this method the **caller** explicitly takes responsibility for
781
- * ensuring that:
782
- *
783
- * - The operation is **read-only** — no state is mutated.
784
- * - The data being read is **immutable** after the keyring is initialized,
785
- * so concurrent locked operations cannot alter it while this callback
786
- * runs.
787
- *
788
- * Do **not** use this method to:
789
- * - Mutate keyring state (add accounts, sign, etc.) — use `withKeyringV2`.
790
- * - Read mutable fields that could change during concurrent operations.
791
- *
792
- * @param selector - Keyring selector object.
793
- * @param operation - Read-only function to execute with the wrapped V2 keyring.
794
- * @returns Promise resolving to the result of the function execution.
795
- * @template SelectedKeyring - The type of the selected V2 keyring.
796
- * @template CallbackResult - The type of the value resolved by the callback function.
797
- */
798
- withKeyringV2Unsafe<SelectedKeyring extends KeyringV2 = KeyringV2, CallbackResult = void>(selector: KeyringSelectorV2<SelectedKeyring>, operation: ({ keyring, metadata, }: {
799
- keyring: SelectedKeyring;
800
- metadata: KeyringMetadata;
801
- }) => Promise<CallbackResult>): Promise<CallbackResult>;
802
- /**
803
- * Execute an operation against all keyrings as a mutually exclusive atomic
804
- * operation. The operation receives a {@link RestrictedController} instance
805
- * that exposes a read-only live view of all keyrings as well as
806
- * `addNewKeyring` and `removeKeyring` methods to stage mutations.
807
- *
808
- * The method automatically persists changes at the end of the function
809
- * execution, or rolls back the changes if an error is thrown.
810
- *
811
- * @param operation - Function to execute with the restricted controller.
812
- * @returns Promise resolving to the result of the function execution.
813
- * @template CallbackResult - The type of the value resolved by the callback function.
814
- */
815
- withController<CallbackResult = void>(operation: (restrictedController: RestrictedController) => Promise<CallbackResult>): Promise<CallbackResult>;
816
- /**
817
- * Gets the type of the keyring that manages the specified account.
818
- *
819
- * @param account - The account address to look up.
820
- * @returns A promise that resolves to the type of the keyring managing the account.
821
- */
822
- getAccountKeyringType(account: string): Promise<string>;
823
- }
824
- export default KeyringController;
825
- //# sourceMappingURL=KeyringController.d.mts.map