@metamask-previews/keyring-controller 12.0.0-preview.1ef189c → 12.0.0-preview.57d41d4

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.
@@ -3,9 +3,10 @@ import type { MetaMaskKeyring as QRKeyring, IKeyringState as IQRKeyringState } f
3
3
  import type { RestrictedControllerMessenger } from '@metamask/base-controller';
4
4
  import { BaseController } from '@metamask/base-controller';
5
5
  import type { ExportableKeyEncryptor, GenericEncryptor } from '@metamask/eth-keyring-controller/dist/types';
6
+ import type { EthBaseTransaction, EthBaseUserOperation, EthKeyring, EthUserOperation, EthUserOperationPatch } from '@metamask/keyring-api';
6
7
  import type { PersonalMessageParams, TypedMessageParams } from '@metamask/message-manager';
7
8
  import type { PreferencesController } from '@metamask/preferences-controller';
8
- import type { Eip1024EncryptedData, Hex, Keyring, Json } from '@metamask/utils';
9
+ import type { Eip1024EncryptedData, Hex, Json } from '@metamask/utils';
9
10
  import type { Patch } from 'immer';
10
11
  declare const name = "KeyringController";
11
12
  /**
@@ -19,7 +20,7 @@ export declare enum KeyringTypes {
19
20
  ledger = "Ledger Hardware",
20
21
  lattice = "Lattice Hardware",
21
22
  snap = "Snap Keyring",
22
- custody = "Custody"
23
+ custody = "Custody - JSONRPC"
23
24
  }
24
25
  /**
25
26
  * @type KeyringControllerState
@@ -80,6 +81,18 @@ export declare type KeyringControllerPersistAllKeyringsAction = {
80
81
  type: `${typeof name}:persistAllKeyrings`;
81
82
  handler: KeyringController['persistAllKeyrings'];
82
83
  };
84
+ export declare type KeyringControllerPrepareUserOperationAction = {
85
+ type: `${typeof name}:prepareUserOperation`;
86
+ handler: KeyringController['prepareUserOperation'];
87
+ };
88
+ export declare type KeyringControllerPatchUserOperationAction = {
89
+ type: `${typeof name}:patchUserOperation`;
90
+ handler: KeyringController['patchUserOperation'];
91
+ };
92
+ export declare type KeyringControllerSignUserOperationAction = {
93
+ type: `${typeof name}:signUserOperation`;
94
+ handler: KeyringController['signUserOperation'];
95
+ };
83
96
  export declare type KeyringControllerStateChangeEvent = {
84
97
  type: `${typeof name}:stateChange`;
85
98
  payload: [KeyringControllerState, Patch[]];
@@ -100,7 +113,7 @@ export declare type KeyringControllerQRKeyringStateChangeEvent = {
100
113
  type: `${typeof name}:qrKeyringStateChange`;
101
114
  payload: [ReturnType<IQRKeyringState['getState']>];
102
115
  };
103
- export declare type KeyringControllerActions = KeyringControllerGetStateAction | KeyringControllerSignMessageAction | KeyringControllerSignPersonalMessageAction | KeyringControllerSignTypedMessageAction | KeyringControllerDecryptMessageAction | KeyringControllerGetEncryptionPublicKeyAction | KeyringControllerGetAccountsAction | KeyringControllerGetKeyringsByTypeAction | KeyringControllerGetKeyringForAccountAction | KeyringControllerPersistAllKeyringsAction;
116
+ export declare type KeyringControllerActions = KeyringControllerGetStateAction | KeyringControllerSignMessageAction | KeyringControllerSignPersonalMessageAction | KeyringControllerSignTypedMessageAction | KeyringControllerDecryptMessageAction | KeyringControllerGetEncryptionPublicKeyAction | KeyringControllerGetAccountsAction | KeyringControllerGetKeyringsByTypeAction | KeyringControllerGetKeyringForAccountAction | KeyringControllerPersistAllKeyringsAction | KeyringControllerPrepareUserOperationAction | KeyringControllerPatchUserOperationAction | KeyringControllerSignUserOperationAction;
104
117
  export declare type KeyringControllerEvents = KeyringControllerStateChangeEvent | KeyringControllerLockEvent | KeyringControllerUnlockEvent | KeyringControllerAccountRemovedEvent | KeyringControllerQRKeyringStateChangeEvent;
105
118
  export declare type KeyringControllerMessenger = RestrictedControllerMessenger<typeof name, KeyringControllerActions, KeyringControllerEvents, string, string>;
106
119
  export declare type KeyringControllerOptions = {
@@ -109,7 +122,7 @@ export declare type KeyringControllerOptions = {
109
122
  setSelectedAddress: PreferencesController['setSelectedAddress'];
110
123
  setAccountLabel?: PreferencesController['setAccountLabel'];
111
124
  keyringBuilders?: {
112
- (): Keyring<Json>;
125
+ (): EthKeyring<Json>;
113
126
  type: string;
114
127
  }[];
115
128
  messenger: KeyringControllerMessenger;
@@ -201,7 +214,7 @@ export declare class KeyringController extends BaseController<typeof name, Keyri
201
214
  * @param accountCount - Number of accounts before adding a new one, used to make the method idempotent.
202
215
  * @returns Promise resolving to keyring current state and added account
203
216
  */
204
- addNewAccountForKeyring(keyring: Keyring<Json>, accountCount?: number): Promise<Hex>;
217
+ addNewAccountForKeyring(keyring: EthKeyring<Json>, accountCount?: number): Promise<Hex>;
205
218
  /**
206
219
  * Adds a new account to the default (first) HD seed phrase keyring without updating identities in preferences.
207
220
  *
@@ -376,6 +389,31 @@ export declare class KeyringController extends BaseController<typeof name, Keyri
376
389
  * @returns Promise resolving to a signed transaction string.
377
390
  */
378
391
  signTransaction(transaction: TypedTransaction, from: string, opts?: Record<string, unknown>): Promise<TxData>;
392
+ /**
393
+ * Convert a base transaction to a base UserOperation.
394
+ *
395
+ * @param from - Address of the sender.
396
+ * @param transactions - Base transactions to include in the UserOperation.
397
+ * @returns A pseudo-UserOperation that can be used to construct a real.
398
+ */
399
+ prepareUserOperation(from: string, transactions: EthBaseTransaction[]): Promise<EthBaseUserOperation>;
400
+ /**
401
+ * Patches properties of a UserOperation. Currently, only the
402
+ * `paymasterAndData` can be patched.
403
+ *
404
+ * @param from - Address of the sender.
405
+ * @param userOp - UserOperation to patch.
406
+ * @returns A patch to apply to the UserOperation.
407
+ */
408
+ patchUserOperation(from: string, userOp: EthUserOperation): Promise<EthUserOperationPatch>;
409
+ /**
410
+ * Signs an UserOperation.
411
+ *
412
+ * @param from - Address of the sender.
413
+ * @param userOp - UserOperation to sign.
414
+ * @returns The signature of the UserOperation.
415
+ */
416
+ signUserOperation(from: string, userOp: EthUserOperation): Promise<string>;
379
417
  /**
380
418
  * Attempts to decrypt the current vault and load its keyrings,
381
419
  * using the given encryption key and salt.
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringController.d.ts","sourceRoot":"","sources":["../src/KeyringController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,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lattice Hardware";
66
66
  KeyringTypes["snap"] = "Snap Keyring";
67
- KeyringTypes["custody"] = "Custody";
67
+ KeyringTypes["custody"] = "Custody - JSONRPC";
68
68
  })(KeyringTypes = exports.KeyringTypes || (exports.KeyringTypes = {}));
69
69
  /**
70
70
  * A strategy for importing an account
@@ -268,7 +268,13 @@ class KeyringController extends base_controller_1.BaseController {
268
268
  }
269
269
  try {
270
270
  this.updateIdentities([]);
271
- yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").createNewVaultAndRestore(password, seed);
271
+ yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").createNewVaultWithKeyring(password, {
272
+ type: eth_keyring_controller_1.KeyringType.HD,
273
+ opts: {
274
+ mnemonic: seed,
275
+ numberOfAccounts: 1,
276
+ },
277
+ });
272
278
  this.updateIdentities(yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts());
273
279
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getMemState).call(this);
274
280
  }
@@ -289,7 +295,9 @@ class KeyringController extends base_controller_1.BaseController {
289
295
  try {
290
296
  const accounts = yield this.getAccounts();
291
297
  if (!accounts.length) {
292
- yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").createNewVaultAndKeychain(password);
298
+ yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").createNewVaultWithKeyring(password, {
299
+ type: eth_keyring_controller_1.KeyringType.HD,
300
+ });
293
301
  this.updateIdentities(yield this.getAccounts());
294
302
  }
295
303
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getMemState).call(this);
@@ -584,6 +592,43 @@ class KeyringController extends base_controller_1.BaseController {
584
592
  signTransaction(transaction, from, opts) {
585
593
  return __classPrivateFieldGet(this, _KeyringController_keyring, "f").signTransaction(transaction, from, opts);
586
594
  }
595
+ /**
596
+ * Convert a base transaction to a base UserOperation.
597
+ *
598
+ * @param from - Address of the sender.
599
+ * @param transactions - Base transactions to include in the UserOperation.
600
+ * @returns A pseudo-UserOperation that can be used to construct a real.
601
+ */
602
+ prepareUserOperation(from, transactions) {
603
+ return __awaiter(this, void 0, void 0, function* () {
604
+ return yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").prepareUserOperation(from, transactions);
605
+ });
606
+ }
607
+ /**
608
+ * Patches properties of a UserOperation. Currently, only the
609
+ * `paymasterAndData` can be patched.
610
+ *
611
+ * @param from - Address of the sender.
612
+ * @param userOp - UserOperation to patch.
613
+ * @returns A patch to apply to the UserOperation.
614
+ */
615
+ patchUserOperation(from, userOp) {
616
+ return __awaiter(this, void 0, void 0, function* () {
617
+ return yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").patchUserOperation(from, userOp);
618
+ });
619
+ }
620
+ /**
621
+ * Signs an UserOperation.
622
+ *
623
+ * @param from - Address of the sender.
624
+ * @param userOp - UserOperation to sign.
625
+ * @returns The signature of the UserOperation.
626
+ */
627
+ signUserOperation(from, userOp) {
628
+ return __awaiter(this, void 0, void 0, function* () {
629
+ return yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").signUserOperation(from, userOp);
630
+ });
631
+ }
587
632
  /**
588
633
  * Attempts to decrypt the current vault and load its keyrings,
589
634
  * using the given encryption key and salt.
@@ -650,7 +695,7 @@ class KeyringController extends base_controller_1.BaseController {
650
695
  const hdKeyring = hdKeyringBuilder();
651
696
  // @ts-expect-error @metamask/eth-hd-keyring correctly handles
652
697
  // Uint8Array seed phrases in the `deserialize` method.
653
- hdKeyring.deserialize({
698
+ yield hdKeyring.deserialize({
654
699
  mnemonic: seedWords,
655
700
  numberOfAccounts: accounts.length,
656
701
  });
@@ -816,6 +861,9 @@ _KeyringController_keyring = new WeakMap(), _KeyringController_qrKeyringStateLis
816
861
  this.messagingSystem.registerActionHandler(`${name}:getKeyringsByType`, this.getKeyringsByType.bind(this));
817
862
  this.messagingSystem.registerActionHandler(`${name}:getKeyringForAccount`, this.getKeyringForAccount.bind(this));
818
863
  this.messagingSystem.registerActionHandler(`${name}:persistAllKeyrings`, this.persistAllKeyrings.bind(this));
864
+ this.messagingSystem.registerActionHandler(`${name}:prepareUserOperation`, this.prepareUserOperation.bind(this));
865
+ this.messagingSystem.registerActionHandler(`${name}:patchUserOperation`, this.patchUserOperation.bind(this));
866
+ this.messagingSystem.registerActionHandler(`${name}:signUserOperation`, this.signUserOperation.bind(this));
819
867
  }, _KeyringController_addQRKeyring = function _KeyringController_addQRKeyring() {
820
868
  return __awaiter(this, void 0, void 0, function* () {
821
869
  // QRKeyring is not yet compatible with Keyring type from @metamask/utils
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringController.js","sourceRoot":"","sources":["../src/KeyringController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,+DAA2D;AAC3D,6EAA6F;AAW7F,2CAAuE;AACvE,6CAAoC;AACpC,qDAOyB;AACzB,uEAAoE;AAGpE,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC;;GAEG;AACH,IAAY,YASX;AATD,WAAY,YAAY;IACtB,0CAA0B,CAAA;IAC1B,kCAAkB,CAAA;IAClB,gDAAgC,CAAA;IAChC,0CAA0B,CAAA;IAC1B,0CAA0B,CAAA;IAC1B,4CAA4B,CAAA;IAC5B,qCAAqB,CAAA;IACrB,mCAAmB,CAAA;AACrB,CAAC,EATW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QASvB;AA+JD;;GAEG;AACH,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,kDAAyB,CAAA;IACzB,sCAAa,CAAA;AACf,CAAC,EAHW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAGhC;AAED;;;;GAIG;AACH,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,iCAAS,CAAA;IACT,iCAAS,CAAA;IACT,iCAAS,CAAA;AACX,CAAC,EAJW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAI/B;AAED,MAAM,YAAY,GAA2B;IAC3C,UAAU,EAA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ACN,CAAC;IAQC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,CAAC;AAC/C,CAAC;IAQC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC;AACjD,CAAC;IAGC,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU;QACjC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ;KAC9B,CAAC;AACJ,CAAC;AAGH,kBAAe,iBAAiB,CAAC","sourcesContent":["import type { TxData, TypedTransaction } from '@ethereumjs/tx';\nimport type {\n MetaMaskKeyring as QRKeyring,\n IKeyringState as IQRKeyringState,\n} from '@keystonehq/metamask-airgapped-keyring';\nimport type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { KeyringController as EthKeyringController } from '@metamask/eth-keyring-controller';\nimport type {\n ExportableKeyEncryptor,\n GenericEncryptor,\n} from '@metamask/eth-keyring-controller/dist/types';\nimport type {\n PersonalMessageParams,\n TypedMessageParams,\n} from '@metamask/message-manager';\nimport type { PreferencesController } from '@metamask/preferences-controller';\nimport type { Eip1024EncryptedData, Hex, Keyring, Json } from '@metamask/utils';\nimport { assertIsStrictHexString, hasProperty } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport {\n addHexPrefix,\n bufferToHex,\n isValidPrivate,\n toBuffer,\n stripHexPrefix,\n getBinarySize,\n} from 'ethereumjs-util';\nimport Wallet, { thirdparty as importers } from 'ethereumjs-wallet';\nimport type { Patch } from 'immer';\n\nconst name = 'KeyringController';\n\n/**\n * Available keyring types\n */\nexport enum KeyringTypes {\n simple = 'Simple Key Pair',\n hd = 'HD Key Tree',\n qr = 'QR Hardware Wallet Device',\n trezor = 'Trezor Hardware',\n ledger = 'Ledger Hardware',\n lattice = 'Lattice Hardware',\n snap = 'Snap Keyring',\n custody = 'Custody',\n}\n\n/**\n * @type KeyringControllerState\n *\n * Keyring controller state\n * @property vault - Encrypted string representing keyring data\n * @property isUnlocked - Whether vault is unlocked\n * @property keyringTypes - Account types\n * @property keyrings - Group of accounts\n * @property encryptionKey - Keyring encryption key\n * @property encryptionSalt - Keyring encryption salt\n */\nexport type KeyringControllerState = {\n vault?: string;\n isUnlocked: boolean;\n keyrings: KeyringObject[];\n encryptionKey?: string;\n encryptionSalt?: string;\n};\n\nexport type KeyringControllerMemState = Omit<\n KeyringControllerState,\n 'vault' | 'encryptionKey' | 'encryptionSalt'\n>;\n\nexport type KeyringControllerGetStateAction = {\n type: `${typeof name}:getState`;\n handler: () => KeyringControllerState;\n};\n\nexport type KeyringControllerSignMessageAction = {\n type: `${typeof name}:signMessage`;\n handler: KeyringController['signMessage'];\n};\n\nexport type KeyringControllerSignPersonalMessageAction = {\n type: `${typeof name}:signPersonalMessage`;\n handler: KeyringController['signPersonalMessage'];\n};\n\nexport type KeyringControllerSignTypedMessageAction = {\n type: `${typeof name}:signTypedMessage`;\n handler: KeyringController['signTypedMessage'];\n};\n\nexport type KeyringControllerDecryptMessageAction = {\n type: `${typeof name}:decryptMessage`;\n handler: KeyringController['decryptMessage'];\n};\n\nexport type KeyringControllerGetEncryptionPublicKeyAction = {\n type: `${typeof name}:getEncryptionPublicKey`;\n handler: KeyringController['getEncryptionPublicKey'];\n};\n\nexport type KeyringControllerGetKeyringsByTypeAction = {\n type: `${typeof name}:getKeyringsByType`;\n handler: KeyringController['getKeyringsByType'];\n};\n\nexport type KeyringControllerGetKeyringForAccountAction = {\n type: `${typeof name}:getKeyringForAccount`;\n handler: KeyringController['getKeyringForAccount'];\n};\n\nexport type KeyringControllerGetAccountsAction = {\n type: `${typeof name}:getAccounts`;\n handler: KeyringController['getAccounts'];\n};\n\nexport type KeyringControllerPersistAllKeyringsAction = {\n type: `${typeof name}:persistAllKeyrings`;\n handler: KeyringController['persistAllKeyrings'];\n};\n\nexport type KeyringControllerStateChangeEvent = {\n type: `${typeof name}:stateChange`;\n payload: [KeyringControllerState, Patch[]];\n};\n\nexport type KeyringControllerAccountRemovedEvent = {\n type: `${typeof name}:accountRemoved`;\n payload: [string];\n};\n\nexport type KeyringControllerLockEvent = {\n type: `${typeof name}:lock`;\n payload: [];\n};\n\nexport type KeyringControllerUnlockEvent = {\n type: `${typeof name}:unlock`;\n payload: [];\n};\n\nexport type KeyringControllerQRKeyringStateChangeEvent = {\n type: `${typeof name}:qrKeyringStateChange`;\n payload: [ReturnType<IQRKeyringState['getState']>];\n};\n\nexport type KeyringControllerActions =\n | KeyringControllerGetStateAction\n | KeyringControllerSignMessageAction\n | KeyringControllerSignPersonalMessageAction\n | KeyringControllerSignTypedMessageAction\n | KeyringControllerDecryptMessageAction\n | KeyringControllerGetEncryptionPublicKeyAction\n | KeyringControllerGetAccountsAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetKeyringForAccountAction\n | KeyringControllerPersistAllKeyringsAction;\n\nexport type KeyringControllerEvents =\n | KeyringControllerStateChangeEvent\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n | KeyringControllerAccountRemovedEvent\n | KeyringControllerQRKeyringStateChangeEvent;\n\nexport type KeyringControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n KeyringControllerActions,\n KeyringControllerEvents,\n string,\n string\n>;\n\nexport type KeyringControllerOptions = {\n syncIdentities: PreferencesController['syncIdentities'];\n updateIdentities: PreferencesController['updateIdentities'];\n setSelectedAddress: PreferencesController['setSelectedAddress'];\n setAccountLabel?: PreferencesController['setAccountLabel'];\n keyringBuilders?: { (): Keyring<Json>; type: string }[];\n messenger: KeyringControllerMessenger;\n state?: { vault?: string };\n} & (\n | {\n cacheEncryptionKey: true;\n encryptor?: ExportableKeyEncryptor;\n }\n | {\n cacheEncryptionKey?: false;\n encryptor?: GenericEncryptor | ExportableKeyEncryptor;\n }\n);\n\n/**\n * @type KeyringObject\n *\n * Keyring object to return in fullUpdate\n * @property type - Keyring type\n * @property accounts - Associated accounts\n */\nexport type KeyringObject = {\n accounts: string[];\n type: string;\n};\n\n/**\n * A strategy for importing an account\n */\nexport enum AccountImportStrategy {\n privateKey = 'privateKey',\n json = 'json',\n}\n\n/**\n * The `signTypedMessage` version\n *\n * @see https://docs.metamask.io/guide/signing-data.html\n */\nexport enum SignTypedDataVersion {\n V1 = 'V1',\n V3 = 'V3',\n V4 = 'V4',\n}\n\nconst defaultState: KeyringControllerState = {\n isUnlocked: false,\n keyrings: [],\n};\n\n/**\n * Assert that the given keyring has an exportable\n * mnemonic.\n *\n * @param keyring - The keyring to check\n * @throws When the keyring does not have a mnemonic\n */\nfunction assertHasUint8ArrayMnemonic(\n keyring: Keyring<Json>,\n): asserts keyring is Keyring<Json> & { mnemonic: Uint8Array } {\n if (\n !(\n hasProperty(keyring, 'mnemonic') && keyring.mnemonic instanceof Uint8Array\n )\n ) {\n throw new Error(\"Can't get mnemonic bytes from keyring\");\n }\n}\n\n/**\n * Controller responsible for establishing and managing user identity.\n *\n * This class is a wrapper around the `eth-keyring-controller` package. The\n * `eth-keyring-controller` manages the \"vault\", which is an encrypted store of private keys, and\n * it manages the wallet \"lock\" state. This wrapper class has convenience methods for interacting\n * with the internal keyring controller and handling certain complex operations that involve the\n * keyrings.\n */\nexport class KeyringController extends BaseController<\n typeof name,\n KeyringControllerState,\n KeyringControllerMessenger\n> {\n private readonly mutex = new Mutex();\n\n private readonly syncIdentities: PreferencesController['syncIdentities'];\n\n private readonly updateIdentities: PreferencesController['updateIdentities'];\n\n private readonly setSelectedAddress: PreferencesController['setSelectedAddress'];\n\n private readonly setAccountLabel?: PreferencesController['setAccountLabel'];\n\n #keyring: EthKeyringController;\n\n #qrKeyringStateListener?: (\n state: ReturnType<IQRKeyringState['getState']>,\n ) => void;\n\n /**\n * Creates a KeyringController instance.\n *\n * @param options - Initial options used to configure this controller\n * @param options.syncIdentities - Sync identities with the given list of addresses.\n * @param options.updateIdentities - Generate an identity for each address given that doesn't already have an identity.\n * @param options.setSelectedAddress - Set the selected address.\n * @param options.setAccountLabel - Set a new name for account.\n * @param options.encryptor - An optional object for defining encryption schemes.\n * @param options.keyringBuilders - Set a new name for account.\n * @param options.cacheEncryptionKey - Whether to cache or not encryption key.\n * @param options.messenger - A restricted controller messenger.\n * @param options.state - Initial state to set on this controller.\n */\n constructor(options: KeyringControllerOptions) {\n const {\n syncIdentities,\n updateIdentities,\n setSelectedAddress,\n setAccountLabel,\n keyringBuilders,\n messenger,\n state,\n } = options;\n\n super({\n name,\n metadata: {\n vault: { persist: true, anonymous: false },\n isUnlocked: { persist: false, anonymous: true },\n keyrings: { persist: false, anonymous: false },\n encryptionKey: { persist: false, anonymous: false },\n encryptionSalt: { persist: false, anonymous: false },\n },\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n if (options.cacheEncryptionKey) {\n this.#keyring = new EthKeyringController({\n initState: state,\n encryptor: options.encryptor,\n keyringBuilders,\n cacheEncryptionKey: options.cacheEncryptionKey,\n });\n } else {\n this.#keyring = new EthKeyringController({\n initState: state,\n encryptor: options.encryptor,\n keyringBuilders,\n cacheEncryptionKey: options.cacheEncryptionKey ?? false,\n });\n }\n this.#keyring.memStore.subscribe(this.#fullUpdate.bind(this));\n this.#keyring.store.subscribe(this.#fullUpdate.bind(this));\n this.#keyring.on('lock', this.#handleLock.bind(this));\n this.#keyring.on('unlock', this.#handleUnlock.bind(this));\n\n this.syncIdentities = syncIdentities;\n this.updateIdentities = updateIdentities;\n this.setSelectedAddress = setSelectedAddress;\n this.setAccountLabel = setAccountLabel;\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Adds a new account to the default (first) HD seed phrase keyring.\n *\n * @param accountCount - Number of accounts before adding a new one, used to\n * make the method idempotent.\n * @returns Promise resolving to keyring current state and added account\n * address.\n */\n async addNewAccount(accountCount?: number): Promise<{\n keyringState: KeyringControllerMemState;\n addedAccountAddress: string;\n }> {\n const primaryKeyring = this.#keyring.getKeyringsByType('HD Key Tree')[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found');\n }\n const oldAccounts = await this.#keyring.getAccounts();\n\n if (accountCount && oldAccounts.length !== accountCount) {\n if (accountCount > oldAccounts.length) {\n throw new Error('Account out of sequence');\n }\n // we return the account already existing at index `accountCount`\n const primaryKeyringAccounts = await primaryKeyring.getAccounts();\n return {\n keyringState: this.#getMemState(),\n addedAccountAddress: primaryKeyringAccounts[accountCount],\n };\n }\n\n await this.#keyring.addNewAccount(primaryKeyring);\n const newAccounts = await this.#keyring.getAccounts();\n\n await this.verifySeedPhrase();\n\n this.updateIdentities(newAccounts);\n const addedAccountAddress = newAccounts.find(\n (selectedAddress: string) => !oldAccounts.includes(selectedAddress),\n );\n\n assertIsStrictHexString(addedAccountAddress);\n return {\n keyringState: this.#getMemState(),\n addedAccountAddress,\n };\n }\n\n /**\n * Adds a new account to the specified keyring.\n *\n * @param keyring - Keyring to add the account to.\n * @param accountCount - Number of accounts before adding a new one, used to make the method idempotent.\n * @returns Promise resolving to keyring current state and added account\n */\n async addNewAccountForKeyring(\n keyring: Keyring<Json>,\n accountCount?: number,\n ): Promise<Hex> {\n const oldAccounts = await this.getAccounts();\n\n if (accountCount && oldAccounts.length !== accountCount) {\n if (accountCount > oldAccounts.length) {\n throw new Error('Account out of sequence');\n }\n\n const existingAccount = oldAccounts[accountCount];\n assertIsStrictHexString(existingAccount);\n\n return existingAccount;\n }\n\n await this.#keyring.addNewAccount(keyring);\n const addedAccountAddress = (await this.getAccounts()).find(\n (selectedAddress) => !oldAccounts.includes(selectedAddress),\n );\n assertIsStrictHexString(addedAccountAddress);\n\n this.updateIdentities(await this.#keyring.getAccounts());\n\n return addedAccountAddress;\n }\n\n /**\n * Adds a new account to the default (first) HD seed phrase keyring without updating identities in preferences.\n *\n * @returns Promise resolving to current state when the account is added.\n */\n async addNewAccountWithoutUpdate(): Promise<KeyringControllerMemState> {\n const primaryKeyring = this.#keyring.getKeyringsByType('HD Key Tree')[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found');\n }\n await this.#keyring.addNewAccount(primaryKeyring);\n await this.verifySeedPhrase();\n return this.#getMemState();\n }\n\n /**\n * Effectively the same as creating a new keychain then populating it\n * using the given seed phrase.\n *\n * @param password - Password to unlock keychain.\n * @param seed - A BIP39-compliant seed phrase as Uint8Array,\n * either as a string or an array of UTF-8 bytes that represent the string.\n * @returns Promise resolving to the restored keychain object.\n */\n async createNewVaultAndRestore(\n password: string,\n seed: Uint8Array,\n ): Promise<KeyringControllerMemState> {\n const releaseLock = await this.mutex.acquire();\n if (!password || !password.length) {\n throw new Error('Invalid password');\n }\n\n try {\n this.updateIdentities([]);\n await this.#keyring.createNewVaultAndRestore(password, seed);\n this.updateIdentities(await this.#keyring.getAccounts());\n return this.#getMemState();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Create a new primary keychain and wipe any previous keychains.\n *\n * @param password - Password to unlock the new vault.\n * @returns Newly-created keychain object.\n */\n async createNewVaultAndKeychain(password: string) {\n const releaseLock = await this.mutex.acquire();\n try {\n const accounts = await this.getAccounts();\n if (!accounts.length) {\n await this.#keyring.createNewVaultAndKeychain(password);\n this.updateIdentities(await this.getAccounts());\n }\n return this.#getMemState();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Adds a new keyring of the given `type`.\n *\n * @param type - Keyring type name.\n * @param opts - Keyring options.\n * @throws If a builder for the given `type` does not exist.\n * @returns Promise resolving to the added keyring.\n */\n async addNewKeyring(\n type: KeyringTypes | string,\n opts?: unknown,\n ): Promise<unknown> {\n if (type === KeyringTypes.qr) {\n return this.getOrAddQRKeyring();\n }\n\n return this.#keyring.addNewKeyring(type, opts);\n }\n\n /**\n * Method to verify a given password validity. Throws an\n * error if the password is invalid.\n *\n * @param password - Password of the keyring.\n */\n async verifyPassword(password: string) {\n await this.#keyring.verifyPassword(password);\n }\n\n /**\n * Returns the status of the vault.\n *\n * @returns Boolean returning true if the vault is unlocked.\n */\n isUnlocked(): boolean {\n return this.state.isUnlocked;\n }\n\n /**\n * Gets the seed phrase of the HD keyring.\n *\n * @param password - Password of the keyring.\n * @returns Promise resolving to the seed phrase.\n */\n async exportSeedPhrase(password: string): Promise<Uint8Array> {\n await this.verifyPassword(password);\n assertHasUint8ArrayMnemonic(this.#keyring.keyrings[0]);\n return this.#keyring.keyrings[0].mnemonic;\n }\n\n /**\n * Gets the private key from the keyring controlling an address.\n *\n * @param password - Password of the keyring.\n * @param address - Address to export.\n * @returns Promise resolving to the private key for an address.\n */\n async exportAccount(password: string, address: string): Promise<string> {\n await this.verifyPassword(password);\n return this.#keyring.exportAccount(address);\n }\n\n /**\n * Returns the public addresses of all accounts for the current keyring.\n *\n * @returns A promise resolving to an array of addresses.\n */\n getAccounts(): Promise<string[]> {\n return this.#keyring.getAccounts();\n }\n\n /**\n * Get encryption public key.\n *\n * @param account - An account address.\n * @param opts - Additional encryption options.\n * @throws If the `account` does not exist or does not support the `getEncryptionPublicKey` method\n * @returns Promise resolving to encyption public key of the `account` if one exists.\n */\n async getEncryptionPublicKey(\n account: string,\n opts?: Record<string, unknown>,\n ): Promise<string> {\n return this.#keyring.getEncryptionPublicKey(account, opts);\n }\n\n /**\n * Attempts to decrypt the provided message parameters.\n *\n * @param messageParams - The decryption message parameters.\n * @param messageParams.from - The address of the account you want to use to decrypt the message.\n * @param messageParams.data - The encrypted data that you want to decrypt.\n * @returns The raw decryption result.\n */\n async decryptMessage(messageParams: {\n from: string;\n data: Eip1024EncryptedData;\n }): Promise<string> {\n return this.#keyring.decryptMessage(messageParams);\n }\n\n /**\n * Returns the currently initialized keyring that manages\n * the specified `address` if one exists.\n *\n * @deprecated Use of this method is discouraged as actions executed directly on\n * keyrings are not being reflected in the KeyringController state and not\n * persisted in the vault.\n * @param account - An account address.\n * @returns Promise resolving to keyring of the `account` if one exists.\n */\n async getKeyringForAccount(account: string): Promise<unknown> {\n return this.#keyring.getKeyringForAccount(account);\n }\n\n /**\n * Returns all keyrings of the given type.\n *\n * @deprecated Use of this method is discouraged as actions executed directly on\n * keyrings are not being reflected in the KeyringController state and not\n * persisted in the vault.\n * @param type - Keyring type name.\n * @returns An array of keyrings of the given type.\n */\n getKeyringsByType(type: KeyringTypes | string): unknown[] {\n return this.#keyring.getKeyringsByType(type);\n }\n\n /**\n * Persist all serialized keyrings in the vault.\n *\n * @returns Promise resolving with `true` value when the\n * operation completes.\n */\n async persistAllKeyrings(): Promise<boolean> {\n return this.#keyring.persistAllKeyrings();\n }\n\n /**\n * Imports an account with the specified import strategy.\n *\n * @param strategy - Import strategy name.\n * @param args - Array of arguments to pass to the underlying stategy.\n * @throws Will throw when passed an unrecognized strategy.\n * @returns Promise resolving to keyring current state and imported account\n * address.\n */\n async importAccountWithStrategy(\n strategy: AccountImportStrategy,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: any[],\n ): Promise<{\n keyringState: KeyringControllerMemState;\n importedAccountAddress: string;\n }> {\n let privateKey;\n switch (strategy) {\n case 'privateKey':\n const [importedKey] = args;\n if (!importedKey) {\n throw new Error('Cannot import an empty key.');\n }\n const prefixed = addHexPrefix(importedKey);\n\n let bufferedPrivateKey;\n try {\n bufferedPrivateKey = toBuffer(prefixed);\n } catch {\n throw new Error('Cannot import invalid private key.');\n }\n\n /* istanbul ignore if */\n if (\n !isValidPrivate(bufferedPrivateKey) ||\n // ensures that the key is 64 bytes long\n getBinarySize(prefixed) !== 64 + '0x'.length\n ) {\n throw new Error('Cannot import invalid private key.');\n }\n\n privateKey = stripHexPrefix(prefixed);\n break;\n case 'json':\n let wallet;\n const [input, password] = args;\n try {\n wallet = importers.fromEtherWallet(input, password);\n } catch (e) {\n wallet = wallet || (await Wallet.fromV3(input, password, true));\n }\n privateKey = bufferToHex(wallet.getPrivateKey());\n break;\n default:\n throw new Error(`Unexpected import strategy: '${strategy}'`);\n }\n const newKeyring = await this.#keyring.addNewKeyring(KeyringTypes.simple, [\n privateKey,\n ]);\n const accounts = await newKeyring.getAccounts();\n const allAccounts = await this.#keyring.getAccounts();\n this.updateIdentities(allAccounts);\n return {\n keyringState: this.#getMemState(),\n importedAccountAddress: accounts[0],\n };\n }\n\n /**\n * Removes an account from keyring state.\n *\n * @param address - Address of the account to remove.\n * @fires KeyringController:accountRemoved\n * @returns Promise resolving current state when this account removal completes.\n */\n async removeAccount(address: Hex): Promise<KeyringControllerMemState> {\n await this.#keyring.removeAccount(address);\n this.messagingSystem.publish(`${name}:accountRemoved`, address);\n return this.#getMemState();\n }\n\n /**\n * Deallocates all secrets and locks the wallet.\n *\n * @returns Promise resolving to current state.\n */\n async setLocked(): Promise<KeyringControllerMemState> {\n this.#unsubscribeFromQRKeyringsEvents();\n await this.#keyring.setLocked();\n return this.#getMemState();\n }\n\n /**\n * Signs message by calling down into a specific keyring.\n *\n * @param messageParams - PersonalMessageParams object to sign.\n * @returns Promise resolving to a signed message string.\n */\n signMessage(messageParams: PersonalMessageParams) {\n if (!messageParams.data) {\n throw new Error(\"Can't sign an empty message\");\n }\n return this.#keyring.signMessage(messageParams);\n }\n\n /**\n * Signs personal message by calling down into a specific keyring.\n *\n * @param messageParams - PersonalMessageParams object to sign.\n * @returns Promise resolving to a signed message string.\n */\n signPersonalMessage(messageParams: PersonalMessageParams) {\n return this.#keyring.signPersonalMessage(messageParams);\n }\n\n /**\n * Signs typed message by calling down into a specific keyring.\n *\n * @param messageParams - TypedMessageParams object to sign.\n * @param version - Compatibility version EIP712.\n * @throws Will throw when passed an unrecognized version.\n * @returns Promise resolving to a signed message string or an error if any.\n */\n async signTypedMessage(\n messageParams: TypedMessageParams,\n version: SignTypedDataVersion,\n ): Promise<string> {\n try {\n if (\n ![\n SignTypedDataVersion.V1,\n SignTypedDataVersion.V3,\n SignTypedDataVersion.V4,\n ].includes(version)\n ) {\n throw new Error(`Unexpected signTypedMessage version: '${version}'`);\n }\n\n return await this.#keyring.signTypedMessage(\n {\n from: messageParams.from,\n data:\n version !== SignTypedDataVersion.V1 &&\n typeof messageParams.data === 'string'\n ? JSON.parse(messageParams.data)\n : messageParams.data,\n },\n { version },\n );\n } catch (error) {\n throw new Error(`Keyring Controller signTypedMessage: ${error}`);\n }\n }\n\n /**\n * Signs a transaction by calling down into a specific keyring.\n *\n * @param transaction - Transaction object to sign. Must be a `ethereumjs-tx` transaction instance.\n * @param from - Address to sign from, should be in keychain.\n * @param opts - An optional options object.\n * @returns Promise resolving to a signed transaction string.\n */\n signTransaction(\n transaction: TypedTransaction,\n from: string,\n opts?: Record<string, unknown>,\n ): Promise<TxData> {\n return this.#keyring.signTransaction(transaction, from, opts);\n }\n\n /**\n * Attempts to decrypt the current vault and load its keyrings,\n * using the given encryption key and salt.\n *\n * @param encryptionKey - Key to unlock the keychain.\n * @param encryptionSalt - Salt to unlock the keychain.\n * @returns Promise resolving to the current state.\n */\n async submitEncryptionKey(\n encryptionKey: string,\n encryptionSalt: string,\n ): Promise<KeyringControllerMemState> {\n await this.#keyring.submitEncryptionKey(encryptionKey, encryptionSalt);\n\n const qrKeyring = this.getQRKeyring();\n if (qrKeyring) {\n // if there is a QR keyring, we need to subscribe\n // to its events after unlocking the vault\n this.#subscribeToQRKeyringEvents(qrKeyring);\n }\n\n return this.#getMemState();\n }\n\n /**\n * Attempts to decrypt the current vault and load its keyrings,\n * using the given password.\n *\n * @param password - Password to unlock the keychain.\n * @returns Promise resolving to the current state.\n */\n async submitPassword(password: string): Promise<KeyringControllerMemState> {\n await this.#keyring.submitPassword(password);\n const accounts = await this.#keyring.getAccounts();\n\n const qrKeyring = this.getQRKeyring();\n if (qrKeyring) {\n // if there is a QR keyring, we need to subscribe\n // to its events after unlocking the vault\n this.#subscribeToQRKeyringEvents(qrKeyring);\n }\n\n await this.syncIdentities(accounts);\n return this.#getMemState();\n }\n\n /**\n * Verifies the that the seed phrase restores the current keychain's accounts.\n *\n * @returns Promise resolving to the seed phrase as Uint8Array.\n */\n async verifySeedPhrase(): Promise<Uint8Array> {\n const primaryKeyring = this.#keyring.getKeyringsByType(KeyringTypes.hd)[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found.');\n }\n\n assertHasUint8ArrayMnemonic(primaryKeyring);\n\n const seedWords = primaryKeyring.mnemonic;\n const accounts = await primaryKeyring.getAccounts();\n /* istanbul ignore if */\n if (accounts.length === 0) {\n throw new Error('Cannot verify an empty keyring.');\n }\n\n // The HD Keyring Builder is a default keyring builder\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const hdKeyringBuilder = this.#keyring.getKeyringBuilderForType(\n KeyringTypes.hd,\n )!;\n\n const hdKeyring = hdKeyringBuilder();\n // @ts-expect-error @metamask/eth-hd-keyring correctly handles\n // Uint8Array seed phrases in the `deserialize` method.\n hdKeyring.deserialize({\n mnemonic: seedWords,\n numberOfAccounts: accounts.length,\n });\n const testAccounts = await hdKeyring.getAccounts();\n /* istanbul ignore if */\n if (testAccounts.length !== accounts.length) {\n throw new Error('Seed phrase imported incorrect number of accounts.');\n }\n\n testAccounts.forEach((account: string, i: number) => {\n /* istanbul ignore if */\n if (account.toLowerCase() !== accounts[i].toLowerCase()) {\n throw new Error('Seed phrase imported different accounts.');\n }\n });\n\n return seedWords;\n }\n\n // QR Hardware related methods\n\n /**\n * Get QR Hardware keyring.\n *\n * @returns The QR Keyring if defined, otherwise undefined\n */\n getQRKeyring(): QRKeyring | undefined {\n // QRKeyring is not yet compatible with Keyring type from @metamask/utils\n return this.#keyring.getKeyringsByType(\n KeyringTypes.qr,\n )[0] as unknown as QRKeyring;\n }\n\n /**\n * Get QR hardware keyring. If it doesn't exist, add it.\n *\n * @returns The added keyring\n */\n async getOrAddQRKeyring(): Promise<QRKeyring> {\n return this.getQRKeyring() || (await this.#addQRKeyring());\n }\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async restoreQRKeyring(serialized: any): Promise<void> {\n (await this.getOrAddQRKeyring()).deserialize(serialized);\n await this.#keyring.persistAllKeyrings();\n this.updateIdentities(await this.#keyring.getAccounts());\n }\n\n async resetQRKeyringState(): Promise<void> {\n (await this.getOrAddQRKeyring()).resetStore();\n }\n\n async getQRKeyringState(): Promise<IQRKeyringState> {\n return (await this.getOrAddQRKeyring()).getMemStore();\n }\n\n async submitQRCryptoHDKey(cryptoHDKey: string): Promise<void> {\n (await this.getOrAddQRKeyring()).submitCryptoHDKey(cryptoHDKey);\n }\n\n async submitQRCryptoAccount(cryptoAccount: string): Promise<void> {\n (await this.getOrAddQRKeyring()).submitCryptoAccount(cryptoAccount);\n }\n\n async submitQRSignature(\n requestId: string,\n ethSignature: string,\n ): Promise<void> {\n (await this.getOrAddQRKeyring()).submitSignature(requestId, ethSignature);\n }\n\n async cancelQRSignRequest(): Promise<void> {\n (await this.getOrAddQRKeyring()).cancelSignRequest();\n }\n\n /**\n * Cancels qr keyring sync.\n */\n async cancelQRSynchronization(): Promise<void> {\n // eslint-disable-next-line n/no-sync\n (await this.getOrAddQRKeyring()).cancelSync();\n }\n\n async connectQRHardware(\n page: number,\n ): Promise<{ balance: string; address: string; index: number }[]> {\n try {\n const keyring = await this.getOrAddQRKeyring();\n let accounts;\n switch (page) {\n case -1:\n accounts = await keyring.getPreviousPage();\n break;\n case 1:\n accounts = await keyring.getNextPage();\n break;\n default:\n accounts = await keyring.getFirstPage();\n }\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return accounts.map((account: any) => {\n return {\n ...account,\n balance: '0x0',\n };\n });\n } catch (e) {\n // TODO: Add test case for when keyring throws\n /* istanbul ignore next */\n throw new Error(`Unspecified error when connect QR Hardware, ${e}`);\n }\n }\n\n async unlockQRHardwareWalletAccount(index: number): Promise<void> {\n const keyring = await this.getOrAddQRKeyring();\n\n keyring.setAccountToUnlock(index);\n const oldAccounts = await this.#keyring.getAccounts();\n // QRKeyring is not yet compatible with Keyring from\n // @metamask/utils, but we can use the `addNewAccount` method\n // as it internally calls `addAccounts` from on the keyring instance,\n // which is supported by QRKeyring API.\n await this.#keyring.addNewAccount(keyring as unknown as Keyring<Json>);\n const newAccounts = await this.#keyring.getAccounts();\n this.updateIdentities(newAccounts);\n newAccounts.forEach((address: string) => {\n if (!oldAccounts.includes(address)) {\n if (this.setAccountLabel) {\n this.setAccountLabel(address, `${keyring.getName()} ${index}`);\n }\n this.setSelectedAddress(address);\n }\n });\n await this.#keyring.persistAllKeyrings();\n }\n\n async getAccountKeyringType(account: string): Promise<string> {\n return (await this.#keyring.getKeyringForAccount(account)).type;\n }\n\n async forgetQRDevice(): Promise<{\n removedAccounts: string[];\n remainingAccounts: string[];\n }> {\n const keyring = await this.getOrAddQRKeyring();\n const allAccounts = (await this.#keyring.getAccounts()) as string[];\n keyring.forgetDevice();\n const remainingAccounts = (await this.#keyring.getAccounts()) as string[];\n const removedAccounts = allAccounts.filter(\n (address: string) => !remainingAccounts.includes(address),\n );\n this.updateIdentities(remainingAccounts);\n await this.#keyring.persistAllKeyrings();\n return { removedAccounts, remainingAccounts };\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${name}:signMessage`,\n this.signMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:signPersonalMessage`,\n this.signPersonalMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:signTypedMessage`,\n this.signTypedMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:decryptMessage`,\n this.decryptMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getEncryptionPublicKey`,\n this.getEncryptionPublicKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getAccounts`,\n this.getAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getKeyringsByType`,\n this.getKeyringsByType.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getKeyringForAccount`,\n this.getKeyringForAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:persistAllKeyrings`,\n this.persistAllKeyrings.bind(this),\n );\n }\n\n /**\n * Add qr hardware keyring.\n *\n * @returns The added keyring\n * @throws If a QRKeyring builder is not provided\n * when initializing the controller\n */\n async #addQRKeyring(): Promise<QRKeyring> {\n // QRKeyring is not yet compatible with Keyring type from @metamask/utils\n const qrKeyring = (await this.#keyring.addNewKeyring(\n KeyringTypes.qr,\n )) as unknown as QRKeyring;\n\n this.#subscribeToQRKeyringEvents(qrKeyring);\n\n return qrKeyring;\n }\n\n /**\n * Subscribe to a QRKeyring state change events and\n * forward them through the messaging system.\n *\n * @param qrKeyring - The QRKeyring instance to subscribe to\n */\n #subscribeToQRKeyringEvents(qrKeyring: QRKeyring) {\n this.#qrKeyringStateListener = (state) => {\n this.messagingSystem.publish(`${name}:qrKeyringStateChange`, state);\n };\n\n qrKeyring.getMemStore().subscribe(this.#qrKeyringStateListener);\n }\n\n #unsubscribeFromQRKeyringsEvents() {\n const qrKeyrings = this.#keyring.getKeyringsByType(\n KeyringTypes.qr,\n ) as unknown as QRKeyring[];\n\n qrKeyrings.forEach((qrKeyring) => {\n if (this.#qrKeyringStateListener) {\n qrKeyring.getMemStore().unsubscribe(this.#qrKeyringStateListener);\n }\n });\n }\n\n /**\n * Sync controller state with current keyring store\n * and memStore states.\n *\n * @fires KeyringController:stateChange\n */\n #fullUpdate() {\n const { vault } = this.#keyring.store.getState();\n const { keyrings, isUnlocked, encryptionKey, encryptionSalt } =\n this.#keyring.memStore.getState();\n\n this.update(() => ({\n vault,\n keyrings,\n isUnlocked,\n encryptionKey,\n encryptionSalt,\n }));\n }\n\n /**\n * Handle keyring lock event.\n *\n * @fires KeyringController:lock\n */\n #handleLock() {\n this.messagingSystem.publish(`${name}:lock`);\n }\n\n /**\n * Handle keyring unlock event.\n *\n * @fires KeyringController:unlock\n */\n #handleUnlock() {\n this.messagingSystem.publish(`${name}:unlock`);\n }\n\n #getMemState(): KeyringControllerMemState {\n return {\n isUnlocked: this.state.isUnlocked,\n keyrings: this.state.keyrings,\n };\n }\n}\n\nexport default KeyringController;\n"]}
1
+ {"version":3,"file":"KeyringController.js","sourceRoot":"","sources":["../src/KeyringController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,+DAA2D;AAC3D,6EAG0C;AAkB1C,2CAAuE;AACvE,6CAAoC;AACpC,qDAOyB;AACzB,uEAAoE;AAGpE,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC;;GAEG;AACH,IAAY,YASX;AATD,WAAY,YAAY;IACtB,0CAA0B,CAAA;IAC1B,kCAAkB,CAAA;IAClB,gDAAgC,CAAA;IAChC,0CAA0B,CAAA;IAC1B,0CAA0B,CAAA;IAC1B,4CAA4B,CAAA;IAC5B,qCAAqB,CAAA;IACrB,6CAA6B,CAAA;AAC/B,CAAC,EATW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QASvB;AAiLD;;GAEG;AACH,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,kDAAyB,CAAA;IACzB,sCAAa,CAAA;AACf,CAAC,EAHW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAGhC;AAED;;;;GAIG;AACH,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,iCAAS,CAAA;IACT,iCAAS,CAAA;IACT,iCAAS,CAAA;AACX,CAAC,EAJW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAI/B;AAED,MAAM,YAAY,GAA2B;IAC3C,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,EAAE;CACb,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,2BAA2B,CAClC,OAAyB;IAEzB,IACE,CAAC,CACC,IAAA,mBAAW,EAAC,OAAO,EAAE,UAAU,CAAC,IAAI,OAAO,CAAC,QAAQ,YAAY,UAAU,CAC3E,EACD;QACA,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;KAC1D;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAa,iBAAk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S,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,uBAAA,IAAI,iDAAwB,CAAC,CAAC;AAClE,CAAC;IAGC,MAAM,UAAU,GAAG,uBAAA,IAAI,kCAAS,CAAC,iBAAiB,CAChD,YAAY,CAAC,EAAE,CACU,CAAC;IAE5B,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QAC/B,IAAI,uBAAA,IAAI,iDAAwB,EAAE;YAChC,SAAS,CAAC,WAAW,EAAE,CAAC,WAAW,CAAC,uBAAA,IAAI,iDAAwB,CAAC,CAAC;SACnE;IACH,CAAC,CAAC,CAAC;AACL,CAAC;IASC,MAAM,EAAE,KAAK,EAAE,GAAG,uBAAA,IAAI,kCAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IACjD,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,GAC3D,uBAAA,IAAI,kCAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAEpC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QACjB,KAAK;QACL,QAAQ;QACR,UAAU;QACV,aAAa;QACb,cAAc;KACf,CAAC,CAAC,CAAC;AACN,CAAC;IAQC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,CAAC;AAC/C,CAAC;IAQC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC;AACjD,CAAC;IAGC,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU;QACjC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ;KAC9B,CAAC;AACJ,CAAC;AAGH,kBAAe,iBAAiB,CAAC","sourcesContent":["import type { TxData, TypedTransaction } from '@ethereumjs/tx';\nimport type {\n MetaMaskKeyring as QRKeyring,\n IKeyringState as IQRKeyringState,\n} from '@keystonehq/metamask-airgapped-keyring';\nimport type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n KeyringController as EthKeyringController,\n KeyringType,\n} from '@metamask/eth-keyring-controller';\nimport type {\n ExportableKeyEncryptor,\n GenericEncryptor,\n} from '@metamask/eth-keyring-controller/dist/types';\nimport type {\n EthBaseTransaction,\n EthBaseUserOperation,\n EthKeyring,\n EthUserOperation,\n EthUserOperationPatch,\n} from '@metamask/keyring-api';\nimport type {\n PersonalMessageParams,\n TypedMessageParams,\n} from '@metamask/message-manager';\nimport type { PreferencesController } from '@metamask/preferences-controller';\nimport type { Eip1024EncryptedData, Hex, Json } from '@metamask/utils';\nimport { assertIsStrictHexString, hasProperty } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport {\n addHexPrefix,\n bufferToHex,\n isValidPrivate,\n toBuffer,\n stripHexPrefix,\n getBinarySize,\n} from 'ethereumjs-util';\nimport Wallet, { thirdparty as importers } from 'ethereumjs-wallet';\nimport type { Patch } from 'immer';\n\nconst name = 'KeyringController';\n\n/**\n * Available keyring types\n */\nexport enum KeyringTypes {\n simple = 'Simple Key Pair',\n hd = 'HD Key Tree',\n qr = 'QR Hardware Wallet Device',\n trezor = 'Trezor Hardware',\n ledger = 'Ledger Hardware',\n lattice = 'Lattice Hardware',\n snap = 'Snap Keyring',\n custody = 'Custody - JSONRPC',\n}\n\n/**\n * @type KeyringControllerState\n *\n * Keyring controller state\n * @property vault - Encrypted string representing keyring data\n * @property isUnlocked - Whether vault is unlocked\n * @property keyringTypes - Account types\n * @property keyrings - Group of accounts\n * @property encryptionKey - Keyring encryption key\n * @property encryptionSalt - Keyring encryption salt\n */\nexport type KeyringControllerState = {\n vault?: string;\n isUnlocked: boolean;\n keyrings: KeyringObject[];\n encryptionKey?: string;\n encryptionSalt?: string;\n};\n\nexport type KeyringControllerMemState = Omit<\n KeyringControllerState,\n 'vault' | 'encryptionKey' | 'encryptionSalt'\n>;\n\nexport type KeyringControllerGetStateAction = {\n type: `${typeof name}:getState`;\n handler: () => KeyringControllerState;\n};\n\nexport type KeyringControllerSignMessageAction = {\n type: `${typeof name}:signMessage`;\n handler: KeyringController['signMessage'];\n};\n\nexport type KeyringControllerSignPersonalMessageAction = {\n type: `${typeof name}:signPersonalMessage`;\n handler: KeyringController['signPersonalMessage'];\n};\n\nexport type KeyringControllerSignTypedMessageAction = {\n type: `${typeof name}:signTypedMessage`;\n handler: KeyringController['signTypedMessage'];\n};\n\nexport type KeyringControllerDecryptMessageAction = {\n type: `${typeof name}:decryptMessage`;\n handler: KeyringController['decryptMessage'];\n};\n\nexport type KeyringControllerGetEncryptionPublicKeyAction = {\n type: `${typeof name}:getEncryptionPublicKey`;\n handler: KeyringController['getEncryptionPublicKey'];\n};\n\nexport type KeyringControllerGetKeyringsByTypeAction = {\n type: `${typeof name}:getKeyringsByType`;\n handler: KeyringController['getKeyringsByType'];\n};\n\nexport type KeyringControllerGetKeyringForAccountAction = {\n type: `${typeof name}:getKeyringForAccount`;\n handler: KeyringController['getKeyringForAccount'];\n};\n\nexport type KeyringControllerGetAccountsAction = {\n type: `${typeof name}:getAccounts`;\n handler: KeyringController['getAccounts'];\n};\n\nexport type KeyringControllerPersistAllKeyringsAction = {\n type: `${typeof name}:persistAllKeyrings`;\n handler: KeyringController['persistAllKeyrings'];\n};\n\nexport type KeyringControllerPrepareUserOperationAction = {\n type: `${typeof name}:prepareUserOperation`;\n handler: KeyringController['prepareUserOperation'];\n};\n\nexport type KeyringControllerPatchUserOperationAction = {\n type: `${typeof name}:patchUserOperation`;\n handler: KeyringController['patchUserOperation'];\n};\n\nexport type KeyringControllerSignUserOperationAction = {\n type: `${typeof name}:signUserOperation`;\n handler: KeyringController['signUserOperation'];\n};\n\nexport type KeyringControllerStateChangeEvent = {\n type: `${typeof name}:stateChange`;\n payload: [KeyringControllerState, Patch[]];\n};\n\nexport type KeyringControllerAccountRemovedEvent = {\n type: `${typeof name}:accountRemoved`;\n payload: [string];\n};\n\nexport type KeyringControllerLockEvent = {\n type: `${typeof name}:lock`;\n payload: [];\n};\n\nexport type KeyringControllerUnlockEvent = {\n type: `${typeof name}:unlock`;\n payload: [];\n};\n\nexport type KeyringControllerQRKeyringStateChangeEvent = {\n type: `${typeof name}:qrKeyringStateChange`;\n payload: [ReturnType<IQRKeyringState['getState']>];\n};\n\nexport type KeyringControllerActions =\n | KeyringControllerGetStateAction\n | KeyringControllerSignMessageAction\n | KeyringControllerSignPersonalMessageAction\n | KeyringControllerSignTypedMessageAction\n | KeyringControllerDecryptMessageAction\n | KeyringControllerGetEncryptionPublicKeyAction\n | KeyringControllerGetAccountsAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetKeyringForAccountAction\n | KeyringControllerPersistAllKeyringsAction\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction;\n\nexport type KeyringControllerEvents =\n | KeyringControllerStateChangeEvent\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n | KeyringControllerAccountRemovedEvent\n | KeyringControllerQRKeyringStateChangeEvent;\n\nexport type KeyringControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n KeyringControllerActions,\n KeyringControllerEvents,\n string,\n string\n>;\n\nexport type KeyringControllerOptions = {\n syncIdentities: PreferencesController['syncIdentities'];\n updateIdentities: PreferencesController['updateIdentities'];\n setSelectedAddress: PreferencesController['setSelectedAddress'];\n setAccountLabel?: PreferencesController['setAccountLabel'];\n keyringBuilders?: { (): EthKeyring<Json>; type: string }[];\n messenger: KeyringControllerMessenger;\n state?: { vault?: string };\n} & (\n | {\n cacheEncryptionKey: true;\n encryptor?: ExportableKeyEncryptor;\n }\n | {\n cacheEncryptionKey?: false;\n encryptor?: GenericEncryptor | ExportableKeyEncryptor;\n }\n);\n\n/**\n * @type KeyringObject\n *\n * Keyring object to return in fullUpdate\n * @property type - Keyring type\n * @property accounts - Associated accounts\n */\nexport type KeyringObject = {\n accounts: string[];\n type: string;\n};\n\n/**\n * A strategy for importing an account\n */\nexport enum AccountImportStrategy {\n privateKey = 'privateKey',\n json = 'json',\n}\n\n/**\n * The `signTypedMessage` version\n *\n * @see https://docs.metamask.io/guide/signing-data.html\n */\nexport enum SignTypedDataVersion {\n V1 = 'V1',\n V3 = 'V3',\n V4 = 'V4',\n}\n\nconst defaultState: KeyringControllerState = {\n isUnlocked: false,\n keyrings: [],\n};\n\n/**\n * Assert that the given keyring has an exportable\n * mnemonic.\n *\n * @param keyring - The keyring to check\n * @throws When the keyring does not have a mnemonic\n */\nfunction assertHasUint8ArrayMnemonic(\n keyring: EthKeyring<Json>,\n): asserts keyring is EthKeyring<Json> & { mnemonic: Uint8Array } {\n if (\n !(\n hasProperty(keyring, 'mnemonic') && keyring.mnemonic instanceof Uint8Array\n )\n ) {\n throw new Error(\"Can't get mnemonic bytes from keyring\");\n }\n}\n\n/**\n * Controller responsible for establishing and managing user identity.\n *\n * This class is a wrapper around the `eth-keyring-controller` package. The\n * `eth-keyring-controller` manages the \"vault\", which is an encrypted store of private keys, and\n * it manages the wallet \"lock\" state. This wrapper class has convenience methods for interacting\n * with the internal keyring controller and handling certain complex operations that involve the\n * keyrings.\n */\nexport class KeyringController extends BaseController<\n typeof name,\n KeyringControllerState,\n KeyringControllerMessenger\n> {\n private readonly mutex = new Mutex();\n\n private readonly syncIdentities: PreferencesController['syncIdentities'];\n\n private readonly updateIdentities: PreferencesController['updateIdentities'];\n\n private readonly setSelectedAddress: PreferencesController['setSelectedAddress'];\n\n private readonly setAccountLabel?: PreferencesController['setAccountLabel'];\n\n #keyring: EthKeyringController;\n\n #qrKeyringStateListener?: (\n state: ReturnType<IQRKeyringState['getState']>,\n ) => void;\n\n /**\n * Creates a KeyringController instance.\n *\n * @param options - Initial options used to configure this controller\n * @param options.syncIdentities - Sync identities with the given list of addresses.\n * @param options.updateIdentities - Generate an identity for each address given that doesn't already have an identity.\n * @param options.setSelectedAddress - Set the selected address.\n * @param options.setAccountLabel - Set a new name for account.\n * @param options.encryptor - An optional object for defining encryption schemes.\n * @param options.keyringBuilders - Set a new name for account.\n * @param options.cacheEncryptionKey - Whether to cache or not encryption key.\n * @param options.messenger - A restricted controller messenger.\n * @param options.state - Initial state to set on this controller.\n */\n constructor(options: KeyringControllerOptions) {\n const {\n syncIdentities,\n updateIdentities,\n setSelectedAddress,\n setAccountLabel,\n keyringBuilders,\n messenger,\n state,\n } = options;\n\n super({\n name,\n metadata: {\n vault: { persist: true, anonymous: false },\n isUnlocked: { persist: false, anonymous: true },\n keyrings: { persist: false, anonymous: false },\n encryptionKey: { persist: false, anonymous: false },\n encryptionSalt: { persist: false, anonymous: false },\n },\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n if (options.cacheEncryptionKey) {\n this.#keyring = new EthKeyringController({\n initState: state,\n encryptor: options.encryptor,\n keyringBuilders,\n cacheEncryptionKey: options.cacheEncryptionKey,\n });\n } else {\n this.#keyring = new EthKeyringController({\n initState: state,\n encryptor: options.encryptor,\n keyringBuilders,\n cacheEncryptionKey: options.cacheEncryptionKey ?? false,\n });\n }\n this.#keyring.memStore.subscribe(this.#fullUpdate.bind(this));\n this.#keyring.store.subscribe(this.#fullUpdate.bind(this));\n this.#keyring.on('lock', this.#handleLock.bind(this));\n this.#keyring.on('unlock', this.#handleUnlock.bind(this));\n\n this.syncIdentities = syncIdentities;\n this.updateIdentities = updateIdentities;\n this.setSelectedAddress = setSelectedAddress;\n this.setAccountLabel = setAccountLabel;\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Adds a new account to the default (first) HD seed phrase keyring.\n *\n * @param accountCount - Number of accounts before adding a new one, used to\n * make the method idempotent.\n * @returns Promise resolving to keyring current state and added account\n * address.\n */\n async addNewAccount(accountCount?: number): Promise<{\n keyringState: KeyringControllerMemState;\n addedAccountAddress: string;\n }> {\n const primaryKeyring = this.#keyring.getKeyringsByType('HD Key Tree')[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found');\n }\n const oldAccounts = await this.#keyring.getAccounts();\n\n if (accountCount && oldAccounts.length !== accountCount) {\n if (accountCount > oldAccounts.length) {\n throw new Error('Account out of sequence');\n }\n // we return the account already existing at index `accountCount`\n const primaryKeyringAccounts = await primaryKeyring.getAccounts();\n return {\n keyringState: this.#getMemState(),\n addedAccountAddress: primaryKeyringAccounts[accountCount],\n };\n }\n\n await this.#keyring.addNewAccount(primaryKeyring);\n const newAccounts = await this.#keyring.getAccounts();\n\n await this.verifySeedPhrase();\n\n this.updateIdentities(newAccounts);\n const addedAccountAddress = newAccounts.find(\n (selectedAddress: string) => !oldAccounts.includes(selectedAddress),\n );\n\n assertIsStrictHexString(addedAccountAddress);\n return {\n keyringState: this.#getMemState(),\n addedAccountAddress,\n };\n }\n\n /**\n * Adds a new account to the specified keyring.\n *\n * @param keyring - Keyring to add the account to.\n * @param accountCount - Number of accounts before adding a new one, used to make the method idempotent.\n * @returns Promise resolving to keyring current state and added account\n */\n async addNewAccountForKeyring(\n keyring: EthKeyring<Json>,\n accountCount?: number,\n ): Promise<Hex> {\n const oldAccounts = await this.getAccounts();\n\n if (accountCount && oldAccounts.length !== accountCount) {\n if (accountCount > oldAccounts.length) {\n throw new Error('Account out of sequence');\n }\n\n const existingAccount = oldAccounts[accountCount];\n assertIsStrictHexString(existingAccount);\n\n return existingAccount;\n }\n\n await this.#keyring.addNewAccount(keyring);\n const addedAccountAddress = (await this.getAccounts()).find(\n (selectedAddress) => !oldAccounts.includes(selectedAddress),\n );\n assertIsStrictHexString(addedAccountAddress);\n\n this.updateIdentities(await this.#keyring.getAccounts());\n\n return addedAccountAddress;\n }\n\n /**\n * Adds a new account to the default (first) HD seed phrase keyring without updating identities in preferences.\n *\n * @returns Promise resolving to current state when the account is added.\n */\n async addNewAccountWithoutUpdate(): Promise<KeyringControllerMemState> {\n const primaryKeyring = this.#keyring.getKeyringsByType('HD Key Tree')[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found');\n }\n await this.#keyring.addNewAccount(primaryKeyring);\n await this.verifySeedPhrase();\n return this.#getMemState();\n }\n\n /**\n * Effectively the same as creating a new keychain then populating it\n * using the given seed phrase.\n *\n * @param password - Password to unlock keychain.\n * @param seed - A BIP39-compliant seed phrase as Uint8Array,\n * either as a string or an array of UTF-8 bytes that represent the string.\n * @returns Promise resolving to the restored keychain object.\n */\n async createNewVaultAndRestore(\n password: string,\n seed: Uint8Array,\n ): Promise<KeyringControllerMemState> {\n const releaseLock = await this.mutex.acquire();\n if (!password || !password.length) {\n throw new Error('Invalid password');\n }\n\n try {\n this.updateIdentities([]);\n await this.#keyring.createNewVaultWithKeyring(password, {\n type: KeyringType.HD,\n opts: {\n mnemonic: seed,\n numberOfAccounts: 1,\n },\n });\n this.updateIdentities(await this.#keyring.getAccounts());\n return this.#getMemState();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Create a new primary keychain and wipe any previous keychains.\n *\n * @param password - Password to unlock the new vault.\n * @returns Newly-created keychain object.\n */\n async createNewVaultAndKeychain(password: string) {\n const releaseLock = await this.mutex.acquire();\n try {\n const accounts = await this.getAccounts();\n if (!accounts.length) {\n await this.#keyring.createNewVaultWithKeyring(password, {\n type: KeyringType.HD,\n });\n this.updateIdentities(await this.getAccounts());\n }\n return this.#getMemState();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Adds a new keyring of the given `type`.\n *\n * @param type - Keyring type name.\n * @param opts - Keyring options.\n * @throws If a builder for the given `type` does not exist.\n * @returns Promise resolving to the added keyring.\n */\n async addNewKeyring(\n type: KeyringTypes | string,\n opts?: unknown,\n ): Promise<unknown> {\n if (type === KeyringTypes.qr) {\n return this.getOrAddQRKeyring();\n }\n\n return this.#keyring.addNewKeyring(type, opts);\n }\n\n /**\n * Method to verify a given password validity. Throws an\n * error if the password is invalid.\n *\n * @param password - Password of the keyring.\n */\n async verifyPassword(password: string) {\n await this.#keyring.verifyPassword(password);\n }\n\n /**\n * Returns the status of the vault.\n *\n * @returns Boolean returning true if the vault is unlocked.\n */\n isUnlocked(): boolean {\n return this.state.isUnlocked;\n }\n\n /**\n * Gets the seed phrase of the HD keyring.\n *\n * @param password - Password of the keyring.\n * @returns Promise resolving to the seed phrase.\n */\n async exportSeedPhrase(password: string): Promise<Uint8Array> {\n await this.verifyPassword(password);\n assertHasUint8ArrayMnemonic(this.#keyring.keyrings[0]);\n return this.#keyring.keyrings[0].mnemonic;\n }\n\n /**\n * Gets the private key from the keyring controlling an address.\n *\n * @param password - Password of the keyring.\n * @param address - Address to export.\n * @returns Promise resolving to the private key for an address.\n */\n async exportAccount(password: string, address: string): Promise<string> {\n await this.verifyPassword(password);\n return this.#keyring.exportAccount(address);\n }\n\n /**\n * Returns the public addresses of all accounts for the current keyring.\n *\n * @returns A promise resolving to an array of addresses.\n */\n getAccounts(): Promise<string[]> {\n return this.#keyring.getAccounts();\n }\n\n /**\n * Get encryption public key.\n *\n * @param account - An account address.\n * @param opts - Additional encryption options.\n * @throws If the `account` does not exist or does not support the `getEncryptionPublicKey` method\n * @returns Promise resolving to encyption public key of the `account` if one exists.\n */\n async getEncryptionPublicKey(\n account: string,\n opts?: Record<string, unknown>,\n ): Promise<string> {\n return this.#keyring.getEncryptionPublicKey(account, opts);\n }\n\n /**\n * Attempts to decrypt the provided message parameters.\n *\n * @param messageParams - The decryption message parameters.\n * @param messageParams.from - The address of the account you want to use to decrypt the message.\n * @param messageParams.data - The encrypted data that you want to decrypt.\n * @returns The raw decryption result.\n */\n async decryptMessage(messageParams: {\n from: string;\n data: Eip1024EncryptedData;\n }): Promise<string> {\n return this.#keyring.decryptMessage(messageParams);\n }\n\n /**\n * Returns the currently initialized keyring that manages\n * the specified `address` if one exists.\n *\n * @deprecated Use of this method is discouraged as actions executed directly on\n * keyrings are not being reflected in the KeyringController state and not\n * persisted in the vault.\n * @param account - An account address.\n * @returns Promise resolving to keyring of the `account` if one exists.\n */\n async getKeyringForAccount(account: string): Promise<unknown> {\n return this.#keyring.getKeyringForAccount(account);\n }\n\n /**\n * Returns all keyrings of the given type.\n *\n * @deprecated Use of this method is discouraged as actions executed directly on\n * keyrings are not being reflected in the KeyringController state and not\n * persisted in the vault.\n * @param type - Keyring type name.\n * @returns An array of keyrings of the given type.\n */\n getKeyringsByType(type: KeyringTypes | string): unknown[] {\n return this.#keyring.getKeyringsByType(type);\n }\n\n /**\n * Persist all serialized keyrings in the vault.\n *\n * @returns Promise resolving with `true` value when the\n * operation completes.\n */\n async persistAllKeyrings(): Promise<boolean> {\n return this.#keyring.persistAllKeyrings();\n }\n\n /**\n * Imports an account with the specified import strategy.\n *\n * @param strategy - Import strategy name.\n * @param args - Array of arguments to pass to the underlying stategy.\n * @throws Will throw when passed an unrecognized strategy.\n * @returns Promise resolving to keyring current state and imported account\n * address.\n */\n async importAccountWithStrategy(\n strategy: AccountImportStrategy,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: any[],\n ): Promise<{\n keyringState: KeyringControllerMemState;\n importedAccountAddress: string;\n }> {\n let privateKey;\n switch (strategy) {\n case 'privateKey':\n const [importedKey] = args;\n if (!importedKey) {\n throw new Error('Cannot import an empty key.');\n }\n const prefixed = addHexPrefix(importedKey);\n\n let bufferedPrivateKey;\n try {\n bufferedPrivateKey = toBuffer(prefixed);\n } catch {\n throw new Error('Cannot import invalid private key.');\n }\n\n /* istanbul ignore if */\n if (\n !isValidPrivate(bufferedPrivateKey) ||\n // ensures that the key is 64 bytes long\n getBinarySize(prefixed) !== 64 + '0x'.length\n ) {\n throw new Error('Cannot import invalid private key.');\n }\n\n privateKey = stripHexPrefix(prefixed);\n break;\n case 'json':\n let wallet;\n const [input, password] = args;\n try {\n wallet = importers.fromEtherWallet(input, password);\n } catch (e) {\n wallet = wallet || (await Wallet.fromV3(input, password, true));\n }\n privateKey = bufferToHex(wallet.getPrivateKey());\n break;\n default:\n throw new Error(`Unexpected import strategy: '${strategy}'`);\n }\n const newKeyring = await this.#keyring.addNewKeyring(KeyringTypes.simple, [\n privateKey,\n ]);\n const accounts = await newKeyring.getAccounts();\n const allAccounts = await this.#keyring.getAccounts();\n this.updateIdentities(allAccounts);\n return {\n keyringState: this.#getMemState(),\n importedAccountAddress: accounts[0],\n };\n }\n\n /**\n * Removes an account from keyring state.\n *\n * @param address - Address of the account to remove.\n * @fires KeyringController:accountRemoved\n * @returns Promise resolving current state when this account removal completes.\n */\n async removeAccount(address: Hex): Promise<KeyringControllerMemState> {\n await this.#keyring.removeAccount(address);\n this.messagingSystem.publish(`${name}:accountRemoved`, address);\n return this.#getMemState();\n }\n\n /**\n * Deallocates all secrets and locks the wallet.\n *\n * @returns Promise resolving to current state.\n */\n async setLocked(): Promise<KeyringControllerMemState> {\n this.#unsubscribeFromQRKeyringsEvents();\n await this.#keyring.setLocked();\n return this.#getMemState();\n }\n\n /**\n * Signs message by calling down into a specific keyring.\n *\n * @param messageParams - PersonalMessageParams object to sign.\n * @returns Promise resolving to a signed message string.\n */\n signMessage(messageParams: PersonalMessageParams) {\n if (!messageParams.data) {\n throw new Error(\"Can't sign an empty message\");\n }\n return this.#keyring.signMessage(messageParams);\n }\n\n /**\n * Signs personal message by calling down into a specific keyring.\n *\n * @param messageParams - PersonalMessageParams object to sign.\n * @returns Promise resolving to a signed message string.\n */\n signPersonalMessage(messageParams: PersonalMessageParams) {\n return this.#keyring.signPersonalMessage(messageParams);\n }\n\n /**\n * Signs typed message by calling down into a specific keyring.\n *\n * @param messageParams - TypedMessageParams object to sign.\n * @param version - Compatibility version EIP712.\n * @throws Will throw when passed an unrecognized version.\n * @returns Promise resolving to a signed message string or an error if any.\n */\n async signTypedMessage(\n messageParams: TypedMessageParams,\n version: SignTypedDataVersion,\n ): Promise<string> {\n try {\n if (\n ![\n SignTypedDataVersion.V1,\n SignTypedDataVersion.V3,\n SignTypedDataVersion.V4,\n ].includes(version)\n ) {\n throw new Error(`Unexpected signTypedMessage version: '${version}'`);\n }\n\n return await this.#keyring.signTypedMessage(\n {\n from: messageParams.from,\n data:\n version !== SignTypedDataVersion.V1 &&\n typeof messageParams.data === 'string'\n ? JSON.parse(messageParams.data)\n : messageParams.data,\n },\n { version },\n );\n } catch (error) {\n throw new Error(`Keyring Controller signTypedMessage: ${error}`);\n }\n }\n\n /**\n * Signs a transaction by calling down into a specific keyring.\n *\n * @param transaction - Transaction object to sign. Must be a `ethereumjs-tx` transaction instance.\n * @param from - Address to sign from, should be in keychain.\n * @param opts - An optional options object.\n * @returns Promise resolving to a signed transaction string.\n */\n signTransaction(\n transaction: TypedTransaction,\n from: string,\n opts?: Record<string, unknown>,\n ): Promise<TxData> {\n return this.#keyring.signTransaction(transaction, from, opts);\n }\n\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param from - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n async prepareUserOperation(\n from: string,\n transactions: EthBaseTransaction[],\n ): Promise<EthBaseUserOperation> {\n return await this.#keyring.prepareUserOperation(from, transactions);\n }\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param from - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @returns A patch to apply to the UserOperation.\n */\n async patchUserOperation(\n from: string,\n userOp: EthUserOperation,\n ): Promise<EthUserOperationPatch> {\n return await this.#keyring.patchUserOperation(from, userOp);\n }\n\n /**\n * Signs an UserOperation.\n *\n * @param from - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @returns The signature of the UserOperation.\n */\n async signUserOperation(\n from: string,\n userOp: EthUserOperation,\n ): Promise<string> {\n return await this.#keyring.signUserOperation(from, userOp);\n }\n\n /**\n * Attempts to decrypt the current vault and load its keyrings,\n * using the given encryption key and salt.\n *\n * @param encryptionKey - Key to unlock the keychain.\n * @param encryptionSalt - Salt to unlock the keychain.\n * @returns Promise resolving to the current state.\n */\n async submitEncryptionKey(\n encryptionKey: string,\n encryptionSalt: string,\n ): Promise<KeyringControllerMemState> {\n await this.#keyring.submitEncryptionKey(encryptionKey, encryptionSalt);\n\n const qrKeyring = this.getQRKeyring();\n if (qrKeyring) {\n // if there is a QR keyring, we need to subscribe\n // to its events after unlocking the vault\n this.#subscribeToQRKeyringEvents(qrKeyring);\n }\n\n return this.#getMemState();\n }\n\n /**\n * Attempts to decrypt the current vault and load its keyrings,\n * using the given password.\n *\n * @param password - Password to unlock the keychain.\n * @returns Promise resolving to the current state.\n */\n async submitPassword(password: string): Promise<KeyringControllerMemState> {\n await this.#keyring.submitPassword(password);\n const accounts = await this.#keyring.getAccounts();\n\n const qrKeyring = this.getQRKeyring();\n if (qrKeyring) {\n // if there is a QR keyring, we need to subscribe\n // to its events after unlocking the vault\n this.#subscribeToQRKeyringEvents(qrKeyring);\n }\n\n await this.syncIdentities(accounts);\n return this.#getMemState();\n }\n\n /**\n * Verifies the that the seed phrase restores the current keychain's accounts.\n *\n * @returns Promise resolving to the seed phrase as Uint8Array.\n */\n async verifySeedPhrase(): Promise<Uint8Array> {\n const primaryKeyring = this.#keyring.getKeyringsByType(KeyringTypes.hd)[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found.');\n }\n\n assertHasUint8ArrayMnemonic(primaryKeyring);\n\n const seedWords = primaryKeyring.mnemonic;\n const accounts = await primaryKeyring.getAccounts();\n /* istanbul ignore if */\n if (accounts.length === 0) {\n throw new Error('Cannot verify an empty keyring.');\n }\n\n // The HD Keyring Builder is a default keyring builder\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const hdKeyringBuilder = this.#keyring.getKeyringBuilderForType(\n KeyringTypes.hd,\n )!;\n\n const hdKeyring = hdKeyringBuilder();\n // @ts-expect-error @metamask/eth-hd-keyring correctly handles\n // Uint8Array seed phrases in the `deserialize` method.\n await hdKeyring.deserialize({\n mnemonic: seedWords,\n numberOfAccounts: accounts.length,\n });\n const testAccounts = await hdKeyring.getAccounts();\n /* istanbul ignore if */\n if (testAccounts.length !== accounts.length) {\n throw new Error('Seed phrase imported incorrect number of accounts.');\n }\n\n testAccounts.forEach((account: string, i: number) => {\n /* istanbul ignore if */\n if (account.toLowerCase() !== accounts[i].toLowerCase()) {\n throw new Error('Seed phrase imported different accounts.');\n }\n });\n\n return seedWords;\n }\n\n // QR Hardware related methods\n\n /**\n * Get QR Hardware keyring.\n *\n * @returns The QR Keyring if defined, otherwise undefined\n */\n getQRKeyring(): QRKeyring | undefined {\n // QRKeyring is not yet compatible with Keyring type from @metamask/utils\n return this.#keyring.getKeyringsByType(\n KeyringTypes.qr,\n )[0] as unknown as QRKeyring;\n }\n\n /**\n * Get QR hardware keyring. If it doesn't exist, add it.\n *\n * @returns The added keyring\n */\n async getOrAddQRKeyring(): Promise<QRKeyring> {\n return this.getQRKeyring() || (await this.#addQRKeyring());\n }\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async restoreQRKeyring(serialized: any): Promise<void> {\n (await this.getOrAddQRKeyring()).deserialize(serialized);\n await this.#keyring.persistAllKeyrings();\n this.updateIdentities(await this.#keyring.getAccounts());\n }\n\n async resetQRKeyringState(): Promise<void> {\n (await this.getOrAddQRKeyring()).resetStore();\n }\n\n async getQRKeyringState(): Promise<IQRKeyringState> {\n return (await this.getOrAddQRKeyring()).getMemStore();\n }\n\n async submitQRCryptoHDKey(cryptoHDKey: string): Promise<void> {\n (await this.getOrAddQRKeyring()).submitCryptoHDKey(cryptoHDKey);\n }\n\n async submitQRCryptoAccount(cryptoAccount: string): Promise<void> {\n (await this.getOrAddQRKeyring()).submitCryptoAccount(cryptoAccount);\n }\n\n async submitQRSignature(\n requestId: string,\n ethSignature: string,\n ): Promise<void> {\n (await this.getOrAddQRKeyring()).submitSignature(requestId, ethSignature);\n }\n\n async cancelQRSignRequest(): Promise<void> {\n (await this.getOrAddQRKeyring()).cancelSignRequest();\n }\n\n /**\n * Cancels qr keyring sync.\n */\n async cancelQRSynchronization(): Promise<void> {\n // eslint-disable-next-line n/no-sync\n (await this.getOrAddQRKeyring()).cancelSync();\n }\n\n async connectQRHardware(\n page: number,\n ): Promise<{ balance: string; address: string; index: number }[]> {\n try {\n const keyring = await this.getOrAddQRKeyring();\n let accounts;\n switch (page) {\n case -1:\n accounts = await keyring.getPreviousPage();\n break;\n case 1:\n accounts = await keyring.getNextPage();\n break;\n default:\n accounts = await keyring.getFirstPage();\n }\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return accounts.map((account: any) => {\n return {\n ...account,\n balance: '0x0',\n };\n });\n } catch (e) {\n // TODO: Add test case for when keyring throws\n /* istanbul ignore next */\n throw new Error(`Unspecified error when connect QR Hardware, ${e}`);\n }\n }\n\n async unlockQRHardwareWalletAccount(index: number): Promise<void> {\n const keyring = await this.getOrAddQRKeyring();\n\n keyring.setAccountToUnlock(index);\n const oldAccounts = await this.#keyring.getAccounts();\n // QRKeyring is not yet compatible with Keyring from\n // @metamask/utils, but we can use the `addNewAccount` method\n // as it internally calls `addAccounts` from on the keyring instance,\n // which is supported by QRKeyring API.\n await this.#keyring.addNewAccount(keyring as unknown as EthKeyring<Json>);\n const newAccounts = await this.#keyring.getAccounts();\n this.updateIdentities(newAccounts);\n newAccounts.forEach((address: string) => {\n if (!oldAccounts.includes(address)) {\n if (this.setAccountLabel) {\n this.setAccountLabel(address, `${keyring.getName()} ${index}`);\n }\n this.setSelectedAddress(address);\n }\n });\n await this.#keyring.persistAllKeyrings();\n }\n\n async getAccountKeyringType(account: string): Promise<string> {\n return (await this.#keyring.getKeyringForAccount(account)).type;\n }\n\n async forgetQRDevice(): Promise<{\n removedAccounts: string[];\n remainingAccounts: string[];\n }> {\n const keyring = await this.getOrAddQRKeyring();\n const allAccounts = (await this.#keyring.getAccounts()) as string[];\n keyring.forgetDevice();\n const remainingAccounts = (await this.#keyring.getAccounts()) as string[];\n const removedAccounts = allAccounts.filter(\n (address: string) => !remainingAccounts.includes(address),\n );\n this.updateIdentities(remainingAccounts);\n await this.#keyring.persistAllKeyrings();\n return { removedAccounts, remainingAccounts };\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${name}:signMessage`,\n this.signMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:signPersonalMessage`,\n this.signPersonalMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:signTypedMessage`,\n this.signTypedMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:decryptMessage`,\n this.decryptMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getEncryptionPublicKey`,\n this.getEncryptionPublicKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getAccounts`,\n this.getAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getKeyringsByType`,\n this.getKeyringsByType.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getKeyringForAccount`,\n this.getKeyringForAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:persistAllKeyrings`,\n this.persistAllKeyrings.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:prepareUserOperation`,\n this.prepareUserOperation.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:patchUserOperation`,\n this.patchUserOperation.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:signUserOperation`,\n this.signUserOperation.bind(this),\n );\n }\n\n /**\n * Add qr hardware keyring.\n *\n * @returns The added keyring\n * @throws If a QRKeyring builder is not provided\n * when initializing the controller\n */\n async #addQRKeyring(): Promise<QRKeyring> {\n // QRKeyring is not yet compatible with Keyring type from @metamask/utils\n const qrKeyring = (await this.#keyring.addNewKeyring(\n KeyringTypes.qr,\n )) as unknown as QRKeyring;\n\n this.#subscribeToQRKeyringEvents(qrKeyring);\n\n return qrKeyring;\n }\n\n /**\n * Subscribe to a QRKeyring state change events and\n * forward them through the messaging system.\n *\n * @param qrKeyring - The QRKeyring instance to subscribe to\n */\n #subscribeToQRKeyringEvents(qrKeyring: QRKeyring) {\n this.#qrKeyringStateListener = (state) => {\n this.messagingSystem.publish(`${name}:qrKeyringStateChange`, state);\n };\n\n qrKeyring.getMemStore().subscribe(this.#qrKeyringStateListener);\n }\n\n #unsubscribeFromQRKeyringsEvents() {\n const qrKeyrings = this.#keyring.getKeyringsByType(\n KeyringTypes.qr,\n ) as unknown as QRKeyring[];\n\n qrKeyrings.forEach((qrKeyring) => {\n if (this.#qrKeyringStateListener) {\n qrKeyring.getMemStore().unsubscribe(this.#qrKeyringStateListener);\n }\n });\n }\n\n /**\n * Sync controller state with current keyring store\n * and memStore states.\n *\n * @fires KeyringController:stateChange\n */\n #fullUpdate() {\n const { vault } = this.#keyring.store.getState();\n const { keyrings, isUnlocked, encryptionKey, encryptionSalt } =\n this.#keyring.memStore.getState();\n\n this.update(() => ({\n vault,\n keyrings,\n isUnlocked,\n encryptionKey,\n encryptionSalt,\n }));\n }\n\n /**\n * Handle keyring lock event.\n *\n * @fires KeyringController:lock\n */\n #handleLock() {\n this.messagingSystem.publish(`${name}:lock`);\n }\n\n /**\n * Handle keyring unlock event.\n *\n * @fires KeyringController:unlock\n */\n #handleUnlock() {\n this.messagingSystem.publish(`${name}:unlock`);\n }\n\n #getMemState(): KeyringControllerMemState {\n return {\n isUnlocked: this.state.isUnlocked,\n keyrings: this.state.keyrings,\n };\n }\n}\n\nexport default KeyringController;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/keyring-controller",
3
- "version": "12.0.0-preview.1ef189c",
3
+ "version": "12.0.0-preview.57d41d4",
4
4
  "description": "Stores identities seen in the wallet and manages interactions such as signing",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -33,8 +33,10 @@
33
33
  "dependencies": {
34
34
  "@keystonehq/metamask-airgapped-keyring": "^0.13.1",
35
35
  "@metamask/base-controller": "^4.1.0",
36
- "@metamask/eth-keyring-controller": "^15.1.0",
36
+ "@metamask/eth-keyring-controller": "^17.0.1",
37
+ "@metamask/keyring-api": "^3.0.0",
37
38
  "@metamask/message-manager": "^7.3.7",
39
+ "@metamask/preferences-controller": "^6.0.0",
38
40
  "@metamask/utils": "^8.3.0",
39
41
  "async-mutex": "^0.2.6",
40
42
  "ethereumjs-util": "^7.0.10",
@@ -45,9 +47,9 @@
45
47
  "@ethereumjs/common": "^3.2.0",
46
48
  "@ethereumjs/tx": "^4.2.0",
47
49
  "@keystonehq/bc-ur-registry-eth": "^0.9.0",
50
+ "@lavamoat/allow-scripts": "^2.3.1",
48
51
  "@metamask/auto-changelog": "^3.4.4",
49
52
  "@metamask/eth-sig-util": "^7.0.1",
50
- "@metamask/preferences-controller": "^6.0.0",
51
53
  "@metamask/scure-bip39": "^2.1.1",
52
54
  "@types/jest": "^27.4.1",
53
55
  "deepmerge": "^4.2.2",
@@ -69,5 +71,11 @@
69
71
  "publishConfig": {
70
72
  "access": "public",
71
73
  "registry": "https://registry.npmjs.org/"
74
+ },
75
+ "lavamoat": {
76
+ "allowScripts": {
77
+ "ethereumjs-util>ethereum-cryptography>keccak": false,
78
+ "ethereumjs-util>ethereum-cryptography>secp256k1": false
79
+ }
72
80
  }
73
81
  }