@metamask-previews/keyring-controller 19.0.4-preview-f726fb6 → 19.0.4-preview-3da4ce1b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/KeyringController.cjs +40 -4
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts +26 -1
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts +26 -1
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +39 -6
- package/dist/KeyringController.mjs.map +1 -1
- package/dist/constants.cjs +1 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +2 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +1 -0
- package/dist/constants.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
};
|
|
39
39
|
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_password, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_checkForDuplicate, _KeyringController_setUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.KeyringController = exports.getDefaultKeyringState = exports.keyringBuilderFactory = exports.SignTypedDataVersion = exports.AccountImportStrategy = exports.isCustodyKeyring = exports.KeyringTypes = void 0;
|
|
41
|
+
exports.KeyringController = exports.getKeyringByFingerprint = exports.displayForKeyring = exports.getDefaultKeyringState = exports.keyringBuilderFactory = exports.SignTypedDataVersion = exports.AccountImportStrategy = exports.isCustodyKeyring = exports.KeyringTypes = void 0;
|
|
42
42
|
const util_1 = require("@ethereumjs/util");
|
|
43
43
|
const base_controller_1 = require("@metamask/base-controller");
|
|
44
44
|
const encryptorUtils = __importStar(require("@metamask/browser-passworder"));
|
|
@@ -204,8 +204,26 @@ async function displayForKeyring(keyring) {
|
|
|
204
204
|
// Cast to `string[]` here is safe here because `accounts` has no nullish
|
|
205
205
|
// values, and `normalize` returns `string` unless given a nullish value
|
|
206
206
|
accounts: accounts.map(normalize),
|
|
207
|
+
// @ts-expect-error TODO: update type in @metamask/utils
|
|
208
|
+
fingerprint: keyring?.getFingerprint?.(),
|
|
207
209
|
};
|
|
208
210
|
}
|
|
211
|
+
exports.displayForKeyring = displayForKeyring;
|
|
212
|
+
/**
|
|
213
|
+
* Retrieves a keyring from an array of keyrings based on its fingerprint.
|
|
214
|
+
*
|
|
215
|
+
* @param keyrings - Array of keyrings to search through.
|
|
216
|
+
* @param fingerprint - The fingerprint to match against.
|
|
217
|
+
* @returns Promise resolving to the matching keyring, or undefined if not found.
|
|
218
|
+
*/
|
|
219
|
+
async function getKeyringByFingerprint(keyrings, fingerprint) {
|
|
220
|
+
const fingerprints = await Promise.all(
|
|
221
|
+
// @ts-expect-error TODO: update type in @metamask/utils
|
|
222
|
+
keyrings.map((kr) => kr?.getFingerprint?.()));
|
|
223
|
+
const index = fingerprints.indexOf(fingerprint);
|
|
224
|
+
return keyrings[index];
|
|
225
|
+
}
|
|
226
|
+
exports.getKeyringByFingerprint = getKeyringByFingerprint;
|
|
209
227
|
/**
|
|
210
228
|
* Check if address is an ethereum address
|
|
211
229
|
*
|
|
@@ -431,12 +449,27 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
431
449
|
* Gets the seed phrase of the HD keyring.
|
|
432
450
|
*
|
|
433
451
|
* @param password - Password of the keyring.
|
|
452
|
+
* @param keyringId - The keyring identifier.
|
|
434
453
|
* @returns Promise resolving to the seed phrase.
|
|
435
454
|
*/
|
|
436
|
-
async exportSeedPhrase(password) {
|
|
455
|
+
async exportSeedPhrase(password, keyringId) {
|
|
437
456
|
await this.verifyPassword(password);
|
|
438
|
-
|
|
439
|
-
|
|
457
|
+
let keyring;
|
|
458
|
+
if (keyringId) {
|
|
459
|
+
keyring = await getKeyringByFingerprint(__classPrivateFieldGet(this, _KeyringController_keyrings, "f"), keyringId);
|
|
460
|
+
if (!keyring) {
|
|
461
|
+
throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
|
|
462
|
+
}
|
|
463
|
+
if (keyring.type !== KeyringTypes.hd) {
|
|
464
|
+
throw new Error(constants_1.KeyringControllerError.UnsupportedExportSeedPhrase);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
// There will always be an HD keyring
|
|
469
|
+
keyring = this.getKeyringsByType(KeyringTypes.hd)[0];
|
|
470
|
+
}
|
|
471
|
+
assertHasUint8ArrayMnemonic(keyring);
|
|
472
|
+
return keyring.mnemonic;
|
|
440
473
|
}
|
|
441
474
|
/**
|
|
442
475
|
* Gets the private key from the keyring controlling an address.
|
|
@@ -850,6 +883,9 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
850
883
|
if ('address' in selector) {
|
|
851
884
|
keyring = (await this.getKeyringForAccount(selector.address));
|
|
852
885
|
}
|
|
886
|
+
else if ('fingerprint' in selector) {
|
|
887
|
+
keyring = (await getKeyringByFingerprint(__classPrivateFieldGet(this, _KeyringController_keyrings, "f"), selector.fingerprint));
|
|
888
|
+
}
|
|
853
889
|
else {
|
|
854
890
|
keyring = this.getKeyringsByType(selector.type)[selector.index || 0];
|
|
855
891
|
if (!keyring && options.createIfMissing) {
|