@metamask-previews/keyring-controller 25.2.0-preview-6b4f746 → 25.2.0-preview-6e596eb
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/CHANGELOG.md +0 -10
- package/dist/KeyringController-method-action-types.cjs.map +1 -1
- package/dist/KeyringController-method-action-types.d.cts +1 -67
- package/dist/KeyringController-method-action-types.d.cts.map +1 -1
- package/dist/KeyringController-method-action-types.d.mts +1 -67
- package/dist/KeyringController-method-action-types.d.mts.map +1 -1
- package/dist/KeyringController-method-action-types.mjs.map +1 -1
- package/dist/KeyringController.cjs +39 -206
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts +1 -92
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts +1 -92
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +37 -207
- package/dist/KeyringController.mjs.map +1 -1
- package/dist/constants.cjs +0 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +1 -2
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +1 -2
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +0 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -33,14 +33,17 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
33
33
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
34
34
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
35
35
|
};
|
|
36
|
-
var
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_encryptor, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_encryptionKey, _KeyringController_getKeyringForAccount, _KeyringController_findKeyringIndexForAccount, _KeyringController_assertNoUnsafeDirectKeyringAccess, _KeyringController_registerMessageHandlers, _KeyringController_selectKeyring, _KeyringController_getKeyringById, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringMetadata, _KeyringController_getKeyringBuilderForType, _KeyringController_createNewVaultWithKeyring, _KeyringController_deriveAndSetEncryptionKey, _KeyringController_setEncryptionKey, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_getSessionState, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_isNewEncryptionAvailable, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_createKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_assertNoDuplicateAccounts, _KeyringController_setUnlocked, _KeyringController_assertIsUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
|
|
37
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
41
|
exports.KeyringController = exports.getDefaultKeyringState = exports.keyringBuilderFactory = exports.SignTypedDataVersion = exports.AccountImportStrategy = exports.isCustodyKeyring = exports.KeyringTypes = void 0;
|
|
39
42
|
const util_1 = require("@ethereumjs/util");
|
|
40
43
|
const base_controller_1 = require("@metamask/base-controller");
|
|
41
44
|
const eth_hd_keyring_1 = require("@metamask/eth-hd-keyring");
|
|
42
45
|
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
43
|
-
const eth_simple_keyring_1 =
|
|
46
|
+
const eth_simple_keyring_1 = __importDefault(require("@metamask/eth-simple-keyring"));
|
|
44
47
|
const utils_1 = require("@metamask/utils");
|
|
45
48
|
const async_mutex_1 = require("async-mutex");
|
|
46
49
|
const ethereumjs_wallet_1 = __importStar(require("ethereumjs-wallet"));
|
|
@@ -68,8 +71,6 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
68
71
|
'addNewAccount',
|
|
69
72
|
'withKeyring',
|
|
70
73
|
'withKeyringUnsafe',
|
|
71
|
-
'withKeyringV2',
|
|
72
|
-
'withKeyringV2Unsafe',
|
|
73
74
|
'addNewKeyring',
|
|
74
75
|
'createNewVaultAndKeychain',
|
|
75
76
|
'createNewVaultAndRestore',
|
|
@@ -148,17 +149,6 @@ const defaultKeyringBuilders = [
|
|
|
148
149
|
keyringBuilderFactory(eth_simple_keyring_1.default),
|
|
149
150
|
keyringBuilderFactory(eth_hd_keyring_1.HdKeyring),
|
|
150
151
|
];
|
|
151
|
-
const hdKeyringV2Builder = Object.assign((keyring, metadata) => new eth_hd_keyring_1.HdKeyringV2({
|
|
152
|
-
legacyKeyring: keyring,
|
|
153
|
-
entropySource: metadata.id,
|
|
154
|
-
}), { type: KeyringTypes.hd });
|
|
155
|
-
const simpleKeyringV2Builder = Object.assign((keyring) => new eth_simple_keyring_1.SimpleKeyringV2({
|
|
156
|
-
legacyKeyring: keyring,
|
|
157
|
-
}), { type: KeyringTypes.simple });
|
|
158
|
-
const defaultKeyringV2Builders = [
|
|
159
|
-
simpleKeyringV2Builder,
|
|
160
|
-
hdKeyringV2Builder,
|
|
161
|
-
];
|
|
162
152
|
const getDefaultKeyringState = () => {
|
|
163
153
|
return {
|
|
164
154
|
isUnlocked: false,
|
|
@@ -284,7 +274,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
284
274
|
* @param options.state - Initial state to set on this controller.
|
|
285
275
|
*/
|
|
286
276
|
constructor(options) {
|
|
287
|
-
const { encryptor, keyringBuilders,
|
|
277
|
+
const { encryptor, keyringBuilders, messenger, state } = options;
|
|
288
278
|
super({
|
|
289
279
|
name,
|
|
290
280
|
metadata: {
|
|
@@ -329,7 +319,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
329
319
|
_KeyringController_controllerOperationMutex.set(this, new async_mutex_1.Mutex());
|
|
330
320
|
_KeyringController_vaultOperationMutex.set(this, new async_mutex_1.Mutex());
|
|
331
321
|
_KeyringController_keyringBuilders.set(this, void 0);
|
|
332
|
-
_KeyringController_keyringV2Builders.set(this, void 0);
|
|
333
322
|
_KeyringController_encryptor.set(this, void 0);
|
|
334
323
|
_KeyringController_keyrings.set(this, void 0);
|
|
335
324
|
_KeyringController_unsupportedKeyrings.set(this, void 0);
|
|
@@ -337,9 +326,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
337
326
|
__classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
|
|
338
327
|
? keyringBuilders.concat(defaultKeyringBuilders)
|
|
339
328
|
: defaultKeyringBuilders, "f");
|
|
340
|
-
__classPrivateFieldSet(this, _KeyringController_keyringV2Builders, keyringV2Builders
|
|
341
|
-
? keyringV2Builders.concat(defaultKeyringV2Builders)
|
|
342
|
-
: defaultKeyringV2Builders, "f");
|
|
343
329
|
__classPrivateFieldSet(this, _KeyringController_encryptor, encryptor, "f");
|
|
344
330
|
__classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
|
|
345
331
|
__classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
|
|
@@ -584,7 +570,9 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
584
570
|
*/
|
|
585
571
|
getKeyringsByType(type) {
|
|
586
572
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
587
|
-
return __classPrivateFieldGet(this,
|
|
573
|
+
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")
|
|
574
|
+
.filter(({ keyring }) => keyring.type === type)
|
|
575
|
+
.map(({ keyring }) => keyring);
|
|
588
576
|
}
|
|
589
577
|
/**
|
|
590
578
|
* Persist all serialized keyrings in the vault.
|
|
@@ -673,7 +661,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
673
661
|
if (keyringIndex === -1) {
|
|
674
662
|
throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.NoKeyring);
|
|
675
663
|
}
|
|
676
|
-
const { keyring
|
|
664
|
+
const { keyring } = __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
|
|
677
665
|
const isPrimaryKeyring = keyringIndex === 0;
|
|
678
666
|
const shouldRemoveKeyring = (await keyring.getAccounts()).length === 1;
|
|
679
667
|
// Primary keyring should never be removed, so we need to keep at least one account in it
|
|
@@ -694,7 +682,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
694
682
|
await keyring.removeAccount(address);
|
|
695
683
|
if (shouldRemoveKeyring) {
|
|
696
684
|
__classPrivateFieldGet(this, _KeyringController_keyrings, "f").splice(keyringIndex, 1);
|
|
697
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring
|
|
685
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
|
|
698
686
|
}
|
|
699
687
|
});
|
|
700
688
|
this.messenger.publish(`${name}:accountRemoved`, address);
|
|
@@ -1052,109 +1040,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
1052
1040
|
metadata: __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, keyring),
|
|
1053
1041
|
}), keyring);
|
|
1054
1042
|
}
|
|
1055
|
-
/**
|
|
1056
|
-
* Select a keyring, wrap it in a `KeyringV2` adapter, and execute
|
|
1057
|
-
* the given operation with the wrapped keyring as a mutually
|
|
1058
|
-
* exclusive atomic operation.
|
|
1059
|
-
*
|
|
1060
|
-
* We re-wrap the keyring in a `KeyringV2` adapter on each invocation,
|
|
1061
|
-
* since V2 wrappers are ephemeral adapters created on-the-fly, and cheap to create.
|
|
1062
|
-
*
|
|
1063
|
-
* The method automatically persists changes at the end of the
|
|
1064
|
-
* function execution, or rolls back the changes if an error
|
|
1065
|
-
* is thrown.
|
|
1066
|
-
*
|
|
1067
|
-
* A `KeyringV2Builder` for the selected keyring's type must exist
|
|
1068
|
-
* (either as a default or registered via the `keyringV2Builders`
|
|
1069
|
-
* constructor option); otherwise an error is thrown.
|
|
1070
|
-
*
|
|
1071
|
-
* Selection is performed against the V1 keyrings in `#keyrings`, since
|
|
1072
|
-
* V2 wrappers are ephemeral adapters created on-the-fly.
|
|
1073
|
-
*
|
|
1074
|
-
* @param selector - Keyring selector object.
|
|
1075
|
-
* @param operation - Function to execute with the wrapped V2 keyring.
|
|
1076
|
-
* @returns Promise resolving to the result of the function execution.
|
|
1077
|
-
* @template CallbackResult - The type of the value resolved by the callback function.
|
|
1078
|
-
*/
|
|
1079
|
-
async withKeyringV2(selector, operation) {
|
|
1080
|
-
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
1081
|
-
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
|
|
1082
|
-
const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
|
|
1083
|
-
v2: true,
|
|
1084
|
-
selector,
|
|
1085
|
-
});
|
|
1086
|
-
if (!entry) {
|
|
1087
|
-
throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringNotFound);
|
|
1088
|
-
}
|
|
1089
|
-
if (!entry.keyringV2) {
|
|
1090
|
-
throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringV2NotSupported);
|
|
1091
|
-
}
|
|
1092
|
-
const { metadata } = entry;
|
|
1093
|
-
const keyring = entry.keyringV2;
|
|
1094
|
-
const result = await operation({
|
|
1095
|
-
keyring,
|
|
1096
|
-
metadata,
|
|
1097
|
-
});
|
|
1098
|
-
if (Object.is(result, keyring)) {
|
|
1099
|
-
throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.UnsafeDirectKeyringAccess);
|
|
1100
|
-
}
|
|
1101
|
-
return result;
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Select a keyring, wrap it in a `KeyringV2` adapter, and execute
|
|
1106
|
-
* the given read-only operation **without** acquiring the controller's
|
|
1107
|
-
* mutual exclusion lock.
|
|
1108
|
-
*
|
|
1109
|
-
* ## When to use this method
|
|
1110
|
-
*
|
|
1111
|
-
* This method is an escape hatch for read-only access to keyring data that
|
|
1112
|
-
* is immutable once the keyring is initialized. A typical safe use case is
|
|
1113
|
-
* reading immutable fields from a `KeyringV2` adapter: data that is set
|
|
1114
|
-
* during initialization and never mutated afterwards.
|
|
1115
|
-
*
|
|
1116
|
-
* ## Why it is "unsafe"
|
|
1117
|
-
*
|
|
1118
|
-
* The "unsafe" designation mirrors the semantics of `unsafe { }` blocks in
|
|
1119
|
-
* Rust: the method itself does not enforce thread-safety guarantees. By
|
|
1120
|
-
* calling this method the **caller** explicitly takes responsibility for
|
|
1121
|
-
* ensuring that:
|
|
1122
|
-
*
|
|
1123
|
-
* - The operation is **read-only** — no state is mutated.
|
|
1124
|
-
* - The data being read is **immutable** after the keyring is initialized,
|
|
1125
|
-
* so concurrent locked operations cannot alter it while this callback
|
|
1126
|
-
* runs.
|
|
1127
|
-
*
|
|
1128
|
-
* Do **not** use this method to:
|
|
1129
|
-
* - Mutate keyring state (add accounts, sign, etc.) — use `withKeyringV2`.
|
|
1130
|
-
* - Read mutable fields that could change during concurrent operations.
|
|
1131
|
-
*
|
|
1132
|
-
* @param selector - Keyring selector object.
|
|
1133
|
-
* @param operation - Read-only function to execute with the wrapped V2 keyring.
|
|
1134
|
-
* @returns Promise resolving to the result of the function execution.
|
|
1135
|
-
* @template SelectedKeyring - The type of the selected V2 keyring.
|
|
1136
|
-
* @template CallbackResult - The type of the value resolved by the callback function.
|
|
1137
|
-
*/
|
|
1138
|
-
async withKeyringV2Unsafe(selector, operation) {
|
|
1139
|
-
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
1140
|
-
const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
|
|
1141
|
-
v2: true,
|
|
1142
|
-
selector,
|
|
1143
|
-
});
|
|
1144
|
-
if (!entry) {
|
|
1145
|
-
throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringNotFound);
|
|
1146
|
-
}
|
|
1147
|
-
if (!entry.keyringV2) {
|
|
1148
|
-
throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringV2NotSupported);
|
|
1149
|
-
}
|
|
1150
|
-
const { metadata } = entry;
|
|
1151
|
-
const keyring = entry.keyringV2;
|
|
1152
|
-
const result = await operation({ keyring, metadata });
|
|
1153
|
-
if (Object.is(result, keyring)) {
|
|
1154
|
-
throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.UnsafeDirectKeyringAccess);
|
|
1155
|
-
}
|
|
1156
|
-
return result;
|
|
1157
|
-
}
|
|
1158
1043
|
async getAccountKeyringType(account) {
|
|
1159
1044
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
1160
1045
|
const keyring = (await this.getKeyringForAccount(account));
|
|
@@ -1162,15 +1047,11 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
1162
1047
|
}
|
|
1163
1048
|
}
|
|
1164
1049
|
exports.KeyringController = KeyringController;
|
|
1165
|
-
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(),
|
|
1166
|
-
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
1167
|
-
const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryForAccount).call(this, account);
|
|
1168
|
-
return entry?.keyring;
|
|
1169
|
-
}, _KeyringController_getKeyringEntryForAccount = async function _KeyringController_getKeyringEntryForAccount(account) {
|
|
1050
|
+
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_encryptionKey = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_getKeyringForAccount = async function _KeyringController_getKeyringForAccount(account) {
|
|
1170
1051
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
1171
1052
|
const keyringIndex = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_findKeyringIndexForAccount).call(this, account);
|
|
1172
1053
|
if (keyringIndex > -1) {
|
|
1173
|
-
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
|
|
1054
|
+
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex].keyring;
|
|
1174
1055
|
}
|
|
1175
1056
|
return undefined;
|
|
1176
1057
|
}, _KeyringController_findKeyringIndexForAccount = async function _KeyringController_findKeyringIndexForAccount(account) {
|
|
@@ -1178,9 +1059,6 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
|
|
|
1178
1059
|
const address = account.toLowerCase();
|
|
1179
1060
|
const accountsPerKeyring = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(({ keyring }) => keyring.getAccounts()));
|
|
1180
1061
|
return accountsPerKeyring.findIndex((accounts) => accounts.map((a) => a.toLowerCase()).includes(address));
|
|
1181
|
-
}, _KeyringController_getKeyringEntriesByType = function _KeyringController_getKeyringEntriesByType(type) {
|
|
1182
|
-
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
1183
|
-
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").filter(({ keyring }) => keyring.type === type);
|
|
1184
1062
|
}, _KeyringController_assertNoUnsafeDirectKeyringAccess = function _KeyringController_assertNoUnsafeDirectKeyringAccess(value, keyring) {
|
|
1185
1063
|
if (Object.is(value, keyring)) {
|
|
1186
1064
|
// Access to a keyring instance outside of controller safeguards
|
|
@@ -1192,60 +1070,32 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
|
|
|
1192
1070
|
return value;
|
|
1193
1071
|
}, _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
|
|
1194
1072
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
1195
|
-
},
|
|
1073
|
+
}, _KeyringController_selectKeyring =
|
|
1196
1074
|
/**
|
|
1197
|
-
* Select a keyring
|
|
1075
|
+
* Select a keyring using a selector without acquiring the controller lock.
|
|
1198
1076
|
*
|
|
1199
|
-
* @param
|
|
1200
|
-
* @
|
|
1201
|
-
* @param options.selector - Keyring selector object.
|
|
1202
|
-
* @returns The selected keyring entry, or `undefined` if no match is found.
|
|
1077
|
+
* @param selector - Keyring selector object.
|
|
1078
|
+
* @returns The selected keyring, or `undefined` if no match is found.
|
|
1203
1079
|
* @template SelectedKeyring - The expected type of the selected keyring.
|
|
1204
|
-
* @template SelectedKeyringV2 - The expected type of the selected keyring (v2).
|
|
1205
1080
|
*/
|
|
1206
|
-
async function
|
|
1207
|
-
let
|
|
1081
|
+
async function _KeyringController_selectKeyring(selector) {
|
|
1082
|
+
let keyring;
|
|
1208
1083
|
if ('address' in selector) {
|
|
1209
|
-
|
|
1084
|
+
keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringForAccount).call(this, selector.address));
|
|
1210
1085
|
}
|
|
1211
1086
|
else if ('type' in selector) {
|
|
1212
|
-
|
|
1087
|
+
keyring = this.getKeyringsByType(selector.type)[selector.index ?? 0];
|
|
1213
1088
|
}
|
|
1214
1089
|
else if ('id' in selector) {
|
|
1215
|
-
|
|
1090
|
+
keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, selector.id);
|
|
1216
1091
|
}
|
|
1217
1092
|
else if ('filter' in selector) {
|
|
1218
|
-
|
|
1219
|
-
// If v2, then we'll use the v2 selector which expects a `KeyringV2` instance.
|
|
1220
|
-
if (v2) {
|
|
1221
|
-
// However, some keyrings do not have a v2 wrapper, so we just skip them.
|
|
1222
|
-
if (!keyringV2) {
|
|
1223
|
-
return false;
|
|
1224
|
-
}
|
|
1225
|
-
return selector.filter(keyringV2, metadata);
|
|
1226
|
-
}
|
|
1227
|
-
return selector.filter(keyring, metadata);
|
|
1228
|
-
});
|
|
1093
|
+
keyring = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ keyring: filteredKeyring, metadata }) => selector.filter(filteredKeyring, metadata))?.keyring;
|
|
1229
1094
|
}
|
|
1230
|
-
return
|
|
1231
|
-
}, _KeyringController_selectKeyring =
|
|
1232
|
-
/**
|
|
1233
|
-
* Select a keyring using a selector without acquiring the controller lock.
|
|
1234
|
-
*
|
|
1235
|
-
* @param selector - Keyring selector object.
|
|
1236
|
-
* @returns The selected keyring, or `undefined` if no match is found.
|
|
1237
|
-
* @template SelectedKeyring - The expected type of the selected keyring.
|
|
1238
|
-
*/
|
|
1239
|
-
async function _KeyringController_selectKeyring(selector) {
|
|
1240
|
-
const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
|
|
1241
|
-
v2: false,
|
|
1242
|
-
selector,
|
|
1243
|
-
});
|
|
1244
|
-
return entry?.keyring;
|
|
1095
|
+
return keyring;
|
|
1245
1096
|
}, _KeyringController_getKeyringById = function _KeyringController_getKeyringById(keyringId) {
|
|
1246
|
-
return __classPrivateFieldGet(this,
|
|
1247
|
-
|
|
1248
|
-
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ metadata }) => metadata.id === keyringId);
|
|
1097
|
+
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ metadata }) => metadata.id === keyringId)
|
|
1098
|
+
?.keyring;
|
|
1249
1099
|
}, _KeyringController_getKeyringByIdOrDefault = function _KeyringController_getKeyringByIdOrDefault(keyringId) {
|
|
1250
1100
|
if (!keyringId) {
|
|
1251
1101
|
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0]?.keyring;
|
|
@@ -1259,8 +1109,6 @@ async function _KeyringController_selectKeyring(selector) {
|
|
|
1259
1109
|
return keyringWithMetadata.metadata;
|
|
1260
1110
|
}, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
|
|
1261
1111
|
return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
|
|
1262
|
-
}, _KeyringController_getKeyringV2BuilderForType = function _KeyringController_getKeyringV2BuilderForType(type) {
|
|
1263
|
-
return __classPrivateFieldGet(this, _KeyringController_keyringV2Builders, "f").find((builder) => builder.type === type);
|
|
1264
1112
|
}, _KeyringController_createNewVaultWithKeyring =
|
|
1265
1113
|
/**
|
|
1266
1114
|
* Create new vault with an initial keyring
|
|
@@ -1584,8 +1432,8 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
|
|
|
1584
1432
|
* @throws If the keyring includes duplicated accounts.
|
|
1585
1433
|
*/
|
|
1586
1434
|
async function _KeyringController_newKeyring(type, data) {
|
|
1587
|
-
const
|
|
1588
|
-
__classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({ keyring,
|
|
1435
|
+
const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
|
|
1436
|
+
__classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({ keyring, metadata: getDefaultKeyringMetadata() });
|
|
1589
1437
|
return keyring;
|
|
1590
1438
|
}, _KeyringController_createKeyring =
|
|
1591
1439
|
/**
|
|
@@ -1602,13 +1450,11 @@ async function _KeyringController_newKeyring(type, data) {
|
|
|
1602
1450
|
*
|
|
1603
1451
|
* @param type - The type of keyring to add.
|
|
1604
1452
|
* @param data - Keyring initialization options.
|
|
1605
|
-
* @param metadata - Keyring metadata if available.
|
|
1606
1453
|
* @returns The new keyring.
|
|
1607
1454
|
* @throws If the keyring includes duplicated accounts.
|
|
1608
1455
|
*/
|
|
1609
|
-
async function _KeyringController_createKeyring(type, data
|
|
1456
|
+
async function _KeyringController_createKeyring(type, data) {
|
|
1610
1457
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1611
|
-
const keyringMetadata = metadata ?? getDefaultKeyringMetadata();
|
|
1612
1458
|
const keyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, type);
|
|
1613
1459
|
if (!keyringBuilder) {
|
|
1614
1460
|
throw new errors_1.KeyringControllerError(`${constants_1.KeyringControllerErrorMessage.NoKeyringBuilder}. Keyring type: ${type}`);
|
|
@@ -1632,13 +1478,7 @@ async function _KeyringController_createKeyring(type, data, metadata) {
|
|
|
1632
1478
|
await keyring.generateRandomMnemonic();
|
|
1633
1479
|
await keyring.addAccounts(1);
|
|
1634
1480
|
}
|
|
1635
|
-
|
|
1636
|
-
const keyringBuilderV2 = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringV2BuilderForType).call(this, type);
|
|
1637
|
-
let keyringV2;
|
|
1638
|
-
if (keyringBuilderV2) {
|
|
1639
|
-
keyringV2 = keyringBuilderV2(keyring, keyringMetadata);
|
|
1640
|
-
}
|
|
1641
|
-
return { keyring, keyringV2, metadata: keyringMetadata };
|
|
1481
|
+
return keyring;
|
|
1642
1482
|
}, _KeyringController_clearKeyrings =
|
|
1643
1483
|
/**
|
|
1644
1484
|
* Remove all managed keyrings, destroying all their
|
|
@@ -1646,8 +1486,8 @@ async function _KeyringController_createKeyring(type, data, metadata) {
|
|
|
1646
1486
|
*/
|
|
1647
1487
|
async function _KeyringController_clearKeyrings() {
|
|
1648
1488
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1649
|
-
for (const { keyring
|
|
1650
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring
|
|
1489
|
+
for (const { keyring } of __classPrivateFieldGet(this, _KeyringController_keyrings, "f")) {
|
|
1490
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
|
|
1651
1491
|
}
|
|
1652
1492
|
__classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
|
|
1653
1493
|
__classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
|
|
@@ -1663,8 +1503,11 @@ async function _KeyringController_restoreKeyring(serialized) {
|
|
|
1663
1503
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1664
1504
|
try {
|
|
1665
1505
|
const { type, data, metadata: serializedMetadata } = serialized;
|
|
1666
|
-
|
|
1667
|
-
|
|
1506
|
+
const oldState = JSON.stringify(data);
|
|
1507
|
+
const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
|
|
1508
|
+
const newState = JSON.stringify(await keyring.serialize());
|
|
1509
|
+
let hasChanged = oldState !== newState;
|
|
1510
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this, [keyring]);
|
|
1668
1511
|
// If metadata is missing, assume the data is from an installation before we had
|
|
1669
1512
|
// keyring metadata.
|
|
1670
1513
|
let metadata = serializedMetadata;
|
|
@@ -1672,19 +1515,13 @@ async function _KeyringController_restoreKeyring(serialized) {
|
|
|
1672
1515
|
hasChanged = true;
|
|
1673
1516
|
metadata = getDefaultKeyringMetadata();
|
|
1674
1517
|
}
|
|
1675
|
-
const oldState = JSON.stringify(data);
|
|
1676
|
-
const { keyring, keyringV2 } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data, metadata);
|
|
1677
|
-
const newState = JSON.stringify(await keyring.serialize());
|
|
1678
|
-
hasChanged || (hasChanged = oldState !== newState);
|
|
1679
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this, [keyring]);
|
|
1680
1518
|
// The keyring is added to the keyrings array only if it's successfully restored
|
|
1681
1519
|
// and the metadata is successfully added to the controller
|
|
1682
1520
|
__classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({
|
|
1683
1521
|
keyring,
|
|
1684
|
-
keyringV2,
|
|
1685
1522
|
metadata,
|
|
1686
1523
|
});
|
|
1687
|
-
return { keyring,
|
|
1524
|
+
return { keyring, metadata, hasChanged };
|
|
1688
1525
|
}
|
|
1689
1526
|
catch (error) {
|
|
1690
1527
|
console.error(error);
|
|
@@ -1700,13 +1537,9 @@ async function _KeyringController_restoreKeyring(serialized) {
|
|
|
1700
1537
|
* clears the keyring bridge iframe from the DOM.
|
|
1701
1538
|
*
|
|
1702
1539
|
* @param keyring - The keyring to destroy.
|
|
1703
|
-
* @param keyringV2 - The keyring v2 to destroy (if any).
|
|
1704
1540
|
*/
|
|
1705
|
-
async function _KeyringController_destroyKeyring(keyring
|
|
1541
|
+
async function _KeyringController_destroyKeyring(keyring) {
|
|
1706
1542
|
await keyring.destroy?.();
|
|
1707
|
-
if (keyringV2) {
|
|
1708
|
-
await keyringV2.destroy?.();
|
|
1709
|
-
}
|
|
1710
1543
|
}, _KeyringController_assertNoDuplicateAccounts =
|
|
1711
1544
|
/**
|
|
1712
1545
|
* Assert that there are no duplicate accounts in the keyrings.
|