@metamask-previews/eth-snap-keyring 21.0.1-7275dbc → 22.1.0-4bf3baf
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 +53 -8
- package/dist/SnapKeyring.cjs +75 -26
- package/dist/SnapKeyring.cjs.map +1 -1
- package/dist/SnapKeyring.d.cts.map +1 -1
- package/dist/SnapKeyring.d.mts.map +1 -1
- package/dist/SnapKeyring.mjs +72 -23
- package/dist/SnapKeyring.mjs.map +1 -1
- package/dist/SnapKeyringV1.cjs +75 -21
- package/dist/SnapKeyringV1.cjs.map +1 -1
- package/dist/SnapKeyringV1.d.cts +44 -11
- package/dist/SnapKeyringV1.d.cts.map +1 -1
- package/dist/SnapKeyringV1.d.mts +44 -11
- package/dist/SnapKeyringV1.d.mts.map +1 -1
- package/dist/SnapKeyringV1.mjs +71 -17
- package/dist/SnapKeyringV1.mjs.map +1 -1
- package/dist/account.cjs +33 -3
- package/dist/account.cjs.map +1 -1
- package/dist/account.d.cts +17 -0
- package/dist/account.d.cts.map +1 -1
- package/dist/account.d.mts +17 -0
- package/dist/account.d.mts.map +1 -1
- package/dist/account.mjs +29 -1
- package/dist/account.mjs.map +1 -1
- package/dist/events.d.cts.map +1 -1
- package/dist/events.d.mts.map +1 -1
- package/dist/logger.d.cts +1 -0
- package/dist/logger.d.cts.map +1 -1
- package/dist/logger.d.mts +1 -0
- package/dist/logger.d.mts.map +1 -1
- package/dist/migrations/v1.cjs +5 -4
- package/dist/migrations/v1.cjs.map +1 -1
- package/dist/options.cjs +3 -2
- package/dist/options.cjs.map +1 -1
- package/dist/util.cjs +7 -22
- package/dist/util.cjs.map +1 -1
- package/dist/util.d.cts +0 -11
- package/dist/util.d.cts.map +1 -1
- package/dist/util.d.mts +0 -11
- package/dist/util.d.mts.map +1 -1
- package/dist/util.mjs +0 -15
- package/dist/util.mjs.map +1 -1
- package/dist/v2/SnapKeyring.cjs +16 -3
- package/dist/v2/SnapKeyring.cjs.map +1 -1
- package/dist/v2/SnapKeyring.d.cts +21 -4
- package/dist/v2/SnapKeyring.d.cts.map +1 -1
- package/dist/v2/SnapKeyring.d.mts +21 -4
- package/dist/v2/SnapKeyring.d.mts.map +1 -1
- package/dist/v2/SnapKeyring.mjs +16 -4
- package/dist/v2/SnapKeyring.mjs.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,48 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Normalize `KeyringAccount`'s address with `:accountCreated` and `setAccounts` ([#556](https://github.com/MetaMask/accounts/pull/556))
|
|
13
|
+
|
|
14
|
+
## [22.1.0]
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Add `isSnapKeyring` (v2) helper ([#549](https://github.com/MetaMask/accounts/pull/549))
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Bump `@metamask/keyring-sdk` from `^2.0.2` to `^2.1.1` ([#544](https://github.com/MetaMask/accounts/pull/544), [#546](https://github.com/MetaMask/accounts/pull/546))
|
|
23
|
+
- Bump `@metamask/keyring-utils` from `^3.2.0` to `^3.3.1` ([#544](https://github.com/MetaMask/accounts/pull/544), [#546](https://github.com/MetaMask/accounts/pull/546))
|
|
24
|
+
|
|
25
|
+
## [22.0.1]
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- Bump `@metamask/keyring-internal-snap-client` from `^10.0.2` to `^10.0.3` ([#538](https://github.com/MetaMask/accounts/pull/538))
|
|
30
|
+
- Bump `@metamask/keyring-sdk` from `^2.0.1` to `^2.0.2` ([#538](https://github.com/MetaMask/accounts/pull/538))
|
|
31
|
+
- Bump `@metamask/keyring-internal-api` from `^11.0.0` to `^11.0.1` ([#538](https://github.com/MetaMask/accounts/pull/538))
|
|
32
|
+
|
|
33
|
+
## [22.0.0]
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- **BREAKING:** Re-add `snapId` as part of the callbacks (`SnapKeyringCallbacks`) when building `SnapKeyring` v2 keyrings ([#520](https://github.com/MetaMask/accounts/pull/520))
|
|
38
|
+
- Since the `snapId` is now injected via `deserialize` we cannot auto-capture it at build-time.
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
- **BREAKING:** No longer use `snapId` as constructor parameter for `SnapKeyring` (v2) ([#519](https://github.com/MetaMask/accounts/pull/519))
|
|
43
|
+
- The `snapId` is now passed and bound to the keyring upon the first `deserialize` call, to better integrate with `KeyringController` keyrings lifecyle and keyring builders.
|
|
44
|
+
- Bump `@metamask/keyring-internal-api` from `^10.1.1` to `^11.0.0` ([#528](https://github.com/MetaMask/accounts/pull/528))
|
|
45
|
+
- Bump `@metamask/keyring-internal-snap-client` from `^10.0.1` to `^10.0.2` ([#528](https://github.com/MetaMask/accounts/pull/528))
|
|
46
|
+
|
|
47
|
+
### Removed
|
|
48
|
+
|
|
49
|
+
- **BREAKING:** Removed `snap.{name,enabled}` from `InternalAccount` metadata produced by `SnapKeyring` ([#525](https://github.com/MetaMask/accounts/pull/525))
|
|
50
|
+
- Use `SnapController:getSnap` to get those information instead (in combination with `InternalAccount.metadata.snap.id`).
|
|
51
|
+
|
|
10
52
|
## [21.0.1]
|
|
11
53
|
|
|
12
54
|
### Changed
|
|
@@ -40,7 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
40
82
|
- **BREAKING:** Bump `@metamask/keyring-api` from `^22.0.0` to `^23.0.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
|
|
41
83
|
- Use `DeferredPromise` from `@metamask/utils` ([#508](https://github.com/MetaMask/accounts/pull/508))
|
|
42
84
|
- Refactor `SnapKeyring` to store accounts in per-snap `SnapKeyringV2` wrappers instead of a single flat map ([#501](https://github.com/MetaMask/accounts/pull/501))
|
|
43
|
-
- Bump `@metamask/messenger` from `^0.3.0` to `^1.1.1` ([#489](https://github.com/MetaMask/accounts/pull/489), [#500](https://github.com/MetaMask/accounts/pull/500))
|
|
85
|
+
- Bump `@metamask/messenger` from `^0.3.0` to `^1.1.1` ([#489](https://github.com/MetaMask/accounts/pull/489)), ([#500](https://github.com/MetaMask/accounts/pull/500))
|
|
44
86
|
- Bump `@metamask/snaps-controllers` from `^19.0.0` to `^19.0.1` ([#500](https://github.com/MetaMask/accounts/pull/500))
|
|
45
87
|
- Bump `@metamask/snaps-utils` from `^12.1.2` to `^12.1.3` ([#500](https://github.com/MetaMask/accounts/pull/500))
|
|
46
88
|
- Bump `@metamask/utils` from `^11.10.0` to `^11.11.0` ([#483](https://github.com/MetaMask/accounts/pull/483))
|
|
@@ -357,7 +399,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
357
399
|
### Changed
|
|
358
400
|
|
|
359
401
|
- Bump `sinon` and `@types/sinon` to latest versions ([#51](https://github.com/MetaMask/accounts/pull/51))
|
|
360
|
-
- Add `syncpack` and sync dependencies ([#53](https://github.com/
|
|
402
|
+
- Add `syncpack` and sync dependencies ([#53](https://github.com/MetaMask/accounts/pull/53))
|
|
361
403
|
|
|
362
404
|
## [4.3.5]
|
|
363
405
|
|
|
@@ -378,10 +420,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
378
420
|
|
|
379
421
|
### Changed
|
|
380
422
|
|
|
381
|
-
- Bump `@metamask/snaps-controllers` from `^9.3.0` to `^9.6.0` ([#372](https://github.com/MetaMask/eth-snap-keyring/pull/372), [#389](https://github.com/MetaMask/eth-snap-keyring/pull/389))
|
|
423
|
+
- Bump `@metamask/snaps-controllers` from `^9.3.0` to `^9.6.0` ([#372](https://github.com/MetaMask/eth-snap-keyring/pull/372)), ([#389](https://github.com/MetaMask/eth-snap-keyring/pull/389))
|
|
382
424
|
- Bump `@metamask/snaps-sdk` from `^6.1.0` to `^6.4.0` ([#389](https://github.com/MetaMask/eth-snap-keyring/pull/389))
|
|
383
425
|
- Bump `@metamask/utils` from `^9.1.0` to `^9.2.1` ([#385](https://github.com/MetaMask/eth-snap-keyring/pull/385))
|
|
384
|
-
- Bump `@metamask/keyring-api` from `^8.0.1` to `^8.1.0` ([#374](https://github.com/MetaMask/eth-snap-keyring/pull/374), [#376](https://github.com/MetaMask/eth-snap-keyring/pull/376))
|
|
426
|
+
- Bump `@metamask/keyring-api` from `^8.0.1` to `^8.1.0` ([#374](https://github.com/MetaMask/eth-snap-keyring/pull/374)), ([#376](https://github.com/MetaMask/eth-snap-keyring/pull/376))
|
|
385
427
|
|
|
386
428
|
## [4.3.2]
|
|
387
429
|
|
|
@@ -389,9 +431,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
389
431
|
|
|
390
432
|
- Bump `@metamask/eth-sig-util` from `^7.0.1` to `^7.0.3` ([#311](https://github.com/MetaMask/eth-snap-keyring/pull/311))
|
|
391
433
|
- Bump `@metamask/keyring-api` from `^8.0.0` to `^8.0.1` ([#311](https://github.com/MetaMask/eth-snap-keyring/pull/311))
|
|
392
|
-
- Bump `@metamask/snaps-controllers` from `^8.1.1` to `^9.3.0` ([#311](https://github.com/MetaMask/eth-snap-keyring/pull/311), [#363](https://github.com/MetaMask/eth-snap-keyring/pull/363))
|
|
393
|
-
- Bump `@metamask/snaps-sdk` from `^4.2.0` to `^6.1.0` ([#311](https://github.com/MetaMask/eth-snap-keyring/pull/311), [#363](https://github.com/MetaMask/eth-snap-keyring/pull/363))
|
|
394
|
-
- Bump `@metamask/snaps-utils` from `^7.4.0` to `^7.8.0` ([#311](https://github.com/MetaMask/eth-snap-keyring/pull/311), [#363](https://github.com/MetaMask/eth-snap-keyring/pull/363))
|
|
434
|
+
- Bump `@metamask/snaps-controllers` from `^8.1.1` to `^9.3.0` ([#311](https://github.com/MetaMask/eth-snap-keyring/pull/311)), ([#363](https://github.com/MetaMask/eth-snap-keyring/pull/363))
|
|
435
|
+
- Bump `@metamask/snaps-sdk` from `^4.2.0` to `^6.1.0` ([#311](https://github.com/MetaMask/eth-snap-keyring/pull/311)), ([#363](https://github.com/MetaMask/eth-snap-keyring/pull/363))
|
|
436
|
+
- Bump `@metamask/snaps-utils` from `^7.4.0` to `^7.8.0` ([#311](https://github.com/MetaMask/eth-snap-keyring/pull/311)), ([#363](https://github.com/MetaMask/eth-snap-keyring/pull/363))
|
|
395
437
|
- Bump `@metamask/utils` from `^8.4.0` to `^9.1.0` ([#311](https://github.com/MetaMask/eth-snap-keyring/pull/311))
|
|
396
438
|
- Set tsconfig options `module`, `moduleResolution` to `Node16` ([#311](https://github.com/MetaMask/eth-snap-keyring/pull/311))
|
|
397
439
|
|
|
@@ -687,7 +729,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
687
729
|
|
|
688
730
|
- Initial release.
|
|
689
731
|
|
|
690
|
-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@
|
|
732
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@22.1.0...HEAD
|
|
733
|
+
[22.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@22.0.1...@metamask/eth-snap-keyring@22.1.0
|
|
734
|
+
[22.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@22.0.0...@metamask/eth-snap-keyring@22.0.1
|
|
735
|
+
[22.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@21.0.1...@metamask/eth-snap-keyring@22.0.0
|
|
691
736
|
[21.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@21.0.0...@metamask/eth-snap-keyring@21.0.1
|
|
692
737
|
[21.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@20.0.0...@metamask/eth-snap-keyring@21.0.0
|
|
693
738
|
[20.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@19.0.0...@metamask/eth-snap-keyring@20.0.0
|
package/dist/SnapKeyring.cjs
CHANGED
|
@@ -10,12 +10,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
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");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _SnapKeyring_instances, _SnapKeyring_messenger, _SnapKeyring_snapKeyrings, _SnapKeyring_accountIndex, _SnapKeyring_callbacks, _SnapKeyring_isAnyAccountTypeAllowed, _SnapKeyring_lock, _SnapKeyring_getOrCreateKeyring, _SnapKeyring_removeSnapKeyringIfEmpty, _SnapKeyring_assertAccountCanBeUsed, _SnapKeyring_getAccount, _SnapKeyring_resolveAddress, _SnapKeyring_getSnap, _SnapKeyring_getSnapMetadata, _SnapKeyring_transformToInternalAccount;
|
|
13
|
+
var _SnapKeyring_instances, _SnapKeyring_messenger, _SnapKeyring_snapKeyrings, _SnapKeyring_accountIndex, _SnapKeyring_callbacks, _SnapKeyring_isAnyAccountTypeAllowed, _SnapKeyring_lock, _SnapKeyring_getOrCreateKeyringLock, _SnapKeyring_getOrCreateKeyring, _SnapKeyring_removeSnapKeyringIfEmpty, _SnapKeyring_assertAccountCanBeUsed, _SnapKeyring_getAccount, _SnapKeyring_resolveAddress, _SnapKeyring_getSnap, _SnapKeyring_getSnapMetadata, _SnapKeyring_transformToInternalAccount;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SnapKeyring = exports.SNAP_KEYRING_TYPE = void 0;
|
|
16
16
|
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
17
17
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
18
18
|
const async_mutex_1 = require("async-mutex");
|
|
19
|
+
const account_1 = require("./account.cjs");
|
|
19
20
|
const SnapKeyringMessenger_1 = require("./SnapKeyringMessenger.cjs");
|
|
20
21
|
const util_1 = require("./util.cjs");
|
|
21
22
|
const SnapKeyring_1 = require("./v2/SnapKeyring.cjs");
|
|
@@ -77,6 +78,15 @@ class SnapKeyring {
|
|
|
77
78
|
* `withLock` callback.
|
|
78
79
|
*/
|
|
79
80
|
_SnapKeyring_lock.set(this, void 0);
|
|
81
|
+
/**
|
|
82
|
+
* Serializes lazy keyring initialization in {@link SnapKeyring.#getOrCreateKeyring}.
|
|
83
|
+
*
|
|
84
|
+
* Kept separate from {@link SnapKeyring.#lock} (which guards `createAccounts`
|
|
85
|
+
* uniqueness checks) to avoid mixing concerns. The lock is held only for the
|
|
86
|
+
* duration of a single keyring's initialization - released before the caller
|
|
87
|
+
* proceeds with its operation.
|
|
88
|
+
*/
|
|
89
|
+
_SnapKeyring_getOrCreateKeyringLock.set(this, void 0);
|
|
80
90
|
this.type = SnapKeyring.type;
|
|
81
91
|
__classPrivateFieldSet(this, _SnapKeyring_messenger, messenger, "f");
|
|
82
92
|
__classPrivateFieldSet(this, _SnapKeyring_snapKeyrings, new Map(), "f");
|
|
@@ -84,6 +94,7 @@ class SnapKeyring {
|
|
|
84
94
|
__classPrivateFieldSet(this, _SnapKeyring_callbacks, callbacks, "f");
|
|
85
95
|
__classPrivateFieldSet(this, _SnapKeyring_isAnyAccountTypeAllowed, isAnyAccountTypeAllowed, "f");
|
|
86
96
|
__classPrivateFieldSet(this, _SnapKeyring_lock, new async_mutex_1.Mutex(), "f");
|
|
97
|
+
__classPrivateFieldSet(this, _SnapKeyring_getOrCreateKeyringLock, new async_mutex_1.Mutex(), "f");
|
|
87
98
|
}
|
|
88
99
|
/**
|
|
89
100
|
* Handle a message from a Snap.
|
|
@@ -103,7 +114,7 @@ class SnapKeyring {
|
|
|
103
114
|
// We can create a new keyring if the message is an AccountCreated event.
|
|
104
115
|
const isAccountCreated = message.method === `${keyring_api_1.KeyringEvent.AccountCreated}`;
|
|
105
116
|
if (!keyring && isAccountCreated) {
|
|
106
|
-
keyring = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
|
|
117
|
+
keyring = await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
|
|
107
118
|
}
|
|
108
119
|
if (!keyring) {
|
|
109
120
|
throw new Error(`SnapKeyring - Received a message for an unknown snap keyring '${snapId}'`);
|
|
@@ -166,10 +177,11 @@ class SnapKeyring {
|
|
|
166
177
|
// Clear both indexes before rebuilding — they must always be consistent.
|
|
167
178
|
__classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").clear();
|
|
168
179
|
__classPrivateFieldGet(this, _SnapKeyring_accountIndex, "f").clear();
|
|
169
|
-
// Rebuild per-snap keyrings. Each
|
|
170
|
-
// and migration internally.
|
|
180
|
+
// Rebuild per-snap keyrings. Each keyring handles its own validation
|
|
181
|
+
// and migration internally. #getOrCreateKeyring initializes the keyring
|
|
182
|
+
// with an empty state; the second deserialize call loads the real accounts.
|
|
171
183
|
for (const [snapId, accounts] of bySnap) {
|
|
172
|
-
const keyring = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
|
|
184
|
+
const keyring = await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
|
|
173
185
|
await keyring.deserialize({ snapId, accounts });
|
|
174
186
|
// onRegister callbacks fired above have repopulated #accountIndex.
|
|
175
187
|
await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_removeSnapKeyringIfEmpty).call(this, snapId);
|
|
@@ -184,7 +196,7 @@ class SnapKeyring {
|
|
|
184
196
|
const addresses = [];
|
|
185
197
|
for (const keyring of __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").values()) {
|
|
186
198
|
for (const account of keyring.accounts()) {
|
|
187
|
-
addresses.push((0,
|
|
199
|
+
addresses.push((0, account_1.normalizeAccountAddress)(account));
|
|
188
200
|
}
|
|
189
201
|
}
|
|
190
202
|
return (0, util_1.unique)(addresses);
|
|
@@ -196,7 +208,7 @@ class SnapKeyring {
|
|
|
196
208
|
* @returns The addresses of the accounts associated with the given Snap.
|
|
197
209
|
*/
|
|
198
210
|
async getAccountsBySnapId(snapId) {
|
|
199
|
-
return (0, util_1.unique)((__classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").get(snapId)?.accounts() ?? []).map(
|
|
211
|
+
return (0, util_1.unique)((__classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").get(snapId)?.accounts() ?? []).map(account_1.normalizeAccountAddress));
|
|
200
212
|
}
|
|
201
213
|
/**
|
|
202
214
|
* Create an account (v1 event-driven flow).
|
|
@@ -209,7 +221,8 @@ class SnapKeyring {
|
|
|
209
221
|
* @returns The account object.
|
|
210
222
|
*/
|
|
211
223
|
async createAccount(snapId, options, internalOptions) {
|
|
212
|
-
|
|
224
|
+
const keyring = await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
|
|
225
|
+
return keyring.createAccount(options, internalOptions);
|
|
213
226
|
}
|
|
214
227
|
/**
|
|
215
228
|
* Creates one or more new accounts according to the provided options.
|
|
@@ -222,7 +235,8 @@ class SnapKeyring {
|
|
|
222
235
|
* @returns An array of the created account objects.
|
|
223
236
|
*/
|
|
224
237
|
async createAccounts(snapId, options) {
|
|
225
|
-
|
|
238
|
+
const keyring = await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
|
|
239
|
+
return keyring.createAccounts(options);
|
|
226
240
|
}
|
|
227
241
|
/**
|
|
228
242
|
* Checks if a Snap ID is known from the keyring.
|
|
@@ -248,7 +262,8 @@ class SnapKeyring {
|
|
|
248
262
|
if (!this.hasSnapId(snapId)) {
|
|
249
263
|
throw new Error(`Unable to resolve account address: unknown Snap ID: ${snapId}`);
|
|
250
264
|
}
|
|
251
|
-
|
|
265
|
+
const keyring = await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
|
|
266
|
+
return keyring.resolveAccountAddress(scope, request);
|
|
252
267
|
}
|
|
253
268
|
/**
|
|
254
269
|
* Submit a request to a Snap from an account ID.
|
|
@@ -448,31 +463,67 @@ class SnapKeyring {
|
|
|
448
463
|
}
|
|
449
464
|
}
|
|
450
465
|
exports.SnapKeyring = SnapKeyring;
|
|
451
|
-
_SnapKeyring_messenger = new WeakMap(), _SnapKeyring_snapKeyrings = new WeakMap(), _SnapKeyring_accountIndex = new WeakMap(), _SnapKeyring_callbacks = new WeakMap(), _SnapKeyring_isAnyAccountTypeAllowed = new WeakMap(), _SnapKeyring_lock = new WeakMap(),
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
466
|
+
_SnapKeyring_messenger = new WeakMap(), _SnapKeyring_snapKeyrings = new WeakMap(), _SnapKeyring_accountIndex = new WeakMap(), _SnapKeyring_callbacks = new WeakMap(), _SnapKeyring_isAnyAccountTypeAllowed = new WeakMap(), _SnapKeyring_lock = new WeakMap(), _SnapKeyring_getOrCreateKeyringLock = new WeakMap(), _SnapKeyring_instances = new WeakSet(), _SnapKeyring_getOrCreateKeyring =
|
|
467
|
+
/**
|
|
468
|
+
* Get the SnapKeyringEntry for a Snap, creating and initializing it if it
|
|
469
|
+
* does not exist yet.
|
|
470
|
+
*
|
|
471
|
+
* When a new keyring is created it is immediately initialized by calling
|
|
472
|
+
* `deserialize({ snapId, accounts: {} })` so that `snapId` and the internal
|
|
473
|
+
* snap client are available before any event handler or method runs.
|
|
474
|
+
*
|
|
475
|
+
* Both v1 and v2 share the same KeyringAccountRegistry instance. The
|
|
476
|
+
* onRegister / onUnregister callbacks keep #accountIndex in sync regardless
|
|
477
|
+
* of which class mutates the registry.
|
|
478
|
+
*
|
|
479
|
+
* @param snapId - Snap ID.
|
|
480
|
+
* @returns The SnapKeyringEntry for the given Snap.
|
|
481
|
+
*/
|
|
482
|
+
async function _SnapKeyring_getOrCreateKeyring(snapId) {
|
|
483
|
+
// Fast path: keyring already exists, no lock needed.
|
|
484
|
+
const existing = __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").get(snapId);
|
|
485
|
+
if (existing) {
|
|
486
|
+
return existing;
|
|
487
|
+
}
|
|
488
|
+
return __classPrivateFieldGet(this, _SnapKeyring_getOrCreateKeyringLock, "f").runExclusive(async () => {
|
|
489
|
+
// Double-check: a concurrent caller may have created the keyring while
|
|
490
|
+
// we were waiting for the lock.
|
|
491
|
+
const keyring = __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").get(snapId);
|
|
492
|
+
if (keyring) {
|
|
493
|
+
return keyring;
|
|
494
|
+
}
|
|
495
|
+
const newKeyring = new SnapKeyring_1.SnapKeyring({
|
|
456
496
|
messenger: __classPrivateFieldGet(this, _SnapKeyring_messenger, "f"),
|
|
457
497
|
isAnyAccountTypeAllowed: __classPrivateFieldGet(this, _SnapKeyring_isAnyAccountTypeAllowed, "f"),
|
|
458
498
|
callbacks: {
|
|
499
|
+
// Optional callbacks that mutate accounts are responsible for keeping
|
|
500
|
+
// #accountIndex in sync via these callbacks.
|
|
459
501
|
onRegister: (id) => {
|
|
502
|
+
// We can safely use `snapId` here because we create the keyring
|
|
503
|
+
// instance right away.
|
|
460
504
|
__classPrivateFieldGet(this, _SnapKeyring_accountIndex, "f").set(id, snapId);
|
|
461
505
|
},
|
|
462
506
|
onUnregister: (id) => {
|
|
463
507
|
__classPrivateFieldGet(this, _SnapKeyring_accountIndex, "f").delete(id);
|
|
464
508
|
},
|
|
465
|
-
|
|
466
|
-
|
|
509
|
+
// Required callbacks:
|
|
510
|
+
// NOTE: `keyringSnapId` and `snapId` are the same value. The `keyringSnapId` is coming from
|
|
511
|
+
// the `deserialize` call right after.
|
|
512
|
+
addAccount: async (address, keyringSnapId, handleUserInput, onceSaved, accountNameSuggestion, internalOptions) => __classPrivateFieldGet(this, _SnapKeyring_callbacks, "f").addAccount(address, keyringSnapId, handleUserInput, onceSaved, accountNameSuggestion, internalOptions),
|
|
513
|
+
removeAccount: async (address, keyringSnapId, handleUserInput) => __classPrivateFieldGet(this, _SnapKeyring_callbacks, "f").removeAccount(address, keyringSnapId, handleUserInput),
|
|
467
514
|
saveState: async () => __classPrivateFieldGet(this, _SnapKeyring_callbacks, "f").saveState(),
|
|
468
|
-
redirectUser: async (url, message) => __classPrivateFieldGet(this, _SnapKeyring_callbacks, "f").redirectUser(
|
|
515
|
+
redirectUser: async (id, url, message) => __classPrivateFieldGet(this, _SnapKeyring_callbacks, "f").redirectUser(id, url, message),
|
|
469
516
|
assertAccountCanBeUsed: async (account) => __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_assertAccountCanBeUsed).call(this, account),
|
|
470
517
|
withLock: async (callback) => __classPrivateFieldGet(this, _SnapKeyring_lock, "f").runExclusive(callback),
|
|
471
518
|
},
|
|
472
519
|
});
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
520
|
+
// Initialize the keyring with its snap ID (no accounts yet).
|
|
521
|
+
await newKeyring.deserialize({ snapId, accounts: {} });
|
|
522
|
+
// Keyring is fully initialized; register it before releasing the lock so
|
|
523
|
+
// that no concurrent caller can create a duplicate.
|
|
524
|
+
__classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").set(snapId, newKeyring);
|
|
525
|
+
return newKeyring;
|
|
526
|
+
});
|
|
476
527
|
}, _SnapKeyring_removeSnapKeyringIfEmpty =
|
|
477
528
|
/**
|
|
478
529
|
* Drop a per-snap keyring from {@link #snapKeyrings} when it has no accounts.
|
|
@@ -498,7 +549,7 @@ async function _SnapKeyring_removeSnapKeyringIfEmpty(snapId) {
|
|
|
498
549
|
* @throws If the account cannot be used.
|
|
499
550
|
*/
|
|
500
551
|
async function _SnapKeyring_assertAccountCanBeUsed(account) {
|
|
501
|
-
const address = (0,
|
|
552
|
+
const address = (0, account_1.normalizeAccountAddress)(account);
|
|
502
553
|
// The `AnyAccountType.Account` generic account type is allowed only during
|
|
503
554
|
// development, so we check whether it's allowed before continuing.
|
|
504
555
|
if (!__classPrivateFieldGet(this, _SnapKeyring_isAnyAccountTypeAllowed, "f") &&
|
|
@@ -538,9 +589,7 @@ async function _SnapKeyring_assertAccountCanBeUsed(account) {
|
|
|
538
589
|
return __classPrivateFieldGet(this, _SnapKeyring_messenger, "f").call('SnapController:getSnap', snapId);
|
|
539
590
|
}, _SnapKeyring_getSnapMetadata = function _SnapKeyring_getSnapMetadata(snapId) {
|
|
540
591
|
const snap = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getSnap).call(this, snapId);
|
|
541
|
-
return snap
|
|
542
|
-
? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }
|
|
543
|
-
: undefined;
|
|
592
|
+
return snap ? { id: snapId } : undefined;
|
|
544
593
|
}, _SnapKeyring_transformToInternalAccount = function _SnapKeyring_transformToInternalAccount(account, snapId) {
|
|
545
594
|
const snap = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getSnapMetadata).call(this, snapId);
|
|
546
595
|
return {
|
|
@@ -554,7 +603,7 @@ async function _SnapKeyring_assertAccountCanBeUsed(account) {
|
|
|
554
603
|
//
|
|
555
604
|
// NOTE: We convert the address only for EVM accounts, see
|
|
556
605
|
// `normalizeAccountAddress`.
|
|
557
|
-
address: (0,
|
|
606
|
+
address: (0, account_1.normalizeAccountAddress)(account),
|
|
558
607
|
metadata: {
|
|
559
608
|
name: '',
|
|
560
609
|
importTime: 0,
|
package/dist/SnapKeyring.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapKeyring.cjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":";;;;;;;;;;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AAE;YACR,IAAI,EAAE,EAAE;YACR,UAAU,EAAE,CAAC;YACb,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB;YACD,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC;SACpC;KACF,CAAC;AACJ,CAAC;AApsBM,gBAAI,GAAW,yBAAiB,AAA5B,CAA6B","sourcesContent":["import type { TypedTransaction } from '@ethereumjs/tx';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n ResolvedAccountAddress,\n CaipChainId,\n CreateAccountOptions,\n} from '@metamask/keyring-api';\nimport { AnyAccountType, KeyringEvent } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { AccountId, JsonRpcRequest } from '@metamask/keyring-utils';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport type { SnapKeyringInternalOptions } from './options';\nimport type { SnapKeyringMessenger } from './SnapKeyringMessenger';\nimport { SNAP_KEYRING_NAME } from './SnapKeyringMessenger';\nimport type { AccountMethod } from './SnapKeyringV1';\nimport type { SnapMessage } from './types';\nimport { normalizeAccountAddress, throwError, unique } from './util';\nimport { SnapKeyring as SnapKeyringV2 } from './v2/SnapKeyring';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n/**\n * Snap keyring state.\n *\n * This state is persisted by the keyring controller and passed to the Snap\n * keyring when it's created.\n */\nexport type KeyringState = {\n accounts: Record<string, { account: KeyringAccount; snapId: SnapId }>;\n};\n\n/**\n * Snap keyring callbacks.\n *\n * These callbacks are used to interact with other components.\n */\nexport type SnapKeyringCallbacks = {\n saveState: () => Promise<void>;\n\n addressExists(address: string): Promise<boolean>;\n\n addAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n onceSaved: Promise<AccountId>,\n accountNameSuggestion?: string,\n internalOptions?: SnapKeyringInternalOptions,\n ): Promise<void>;\n\n removeAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n ): Promise<void>;\n\n redirectUser(snapId: SnapId, url: string, message: string): Promise<void>;\n};\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n // Name and state are required for modular initialisation.\n name: typeof SNAP_KEYRING_NAME = SNAP_KEYRING_NAME;\n\n state = null;\n\n /**\n * Messenger to dispatch requests to the Snaps controller.\n */\n readonly #messenger: SnapKeyringMessenger;\n\n /**\n * Per-snap keyring instances. Each `SnapKeyringV2` (which extends\n * `SnapKeyringV1`) owns a single `KeyringAccountRegistry` and handles\n * both the event-driven v1 flow and the `KeyringV2` batch interface.\n */\n readonly #snapKeyrings: Map<SnapId, SnapKeyringV2>;\n\n /**\n * Reverse index from account ID to the owning Snap ID.\n *\n * Populated and kept in sync via the `onRegister` / `onUnregister`\n * callbacks injected into each entry. Enables O(1) routing for\n * any \"which snap owns this account?\" query.\n */\n readonly #accountIndex: Map<AccountId, SnapId>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Whether to allow the creation and update of generic accounts.\n *\n * Account deletion is not affected by this flag and is always allowed.\n */\n readonly #isAnyAccountTypeAllowed: boolean;\n\n /**\n * Global mutex that serializes `createAccounts` calls across all snaps.\n *\n * `assertAccountCanBeUsed` checks global state (`#accountIndex` for ID\n * uniqueness, `addressExists` for address uniqueness). Without serialization,\n * two concurrent `createAccounts` calls from different snaps could both pass\n * the uniqueness check before either one calls `setAccount`, leading to\n * duplicate accounts. Injected into each `SnapKeyringV2` via the optional\n * `withLock` callback.\n */\n readonly #lock: Mutex;\n\n /**\n * Create a new Snap keyring.\n *\n * @param options - Constructor options.\n * @param options.messenger - Snap keyring messenger.\n * @param options.callbacks - Callbacks used to interact with other components.\n * @param options.isAnyAccountTypeAllowed - Whether to allow the `AnyAccountType` generic account type.\n * @returns A new Snap keyring.\n */\n constructor({\n messenger,\n callbacks,\n isAnyAccountTypeAllowed = false,\n }: {\n messenger: SnapKeyringMessenger;\n callbacks: SnapKeyringCallbacks;\n isAnyAccountTypeAllowed?: boolean;\n }) {\n this.type = SnapKeyring.type;\n this.#messenger = messenger;\n this.#snapKeyrings = new Map();\n this.#accountIndex = new Map();\n this.#callbacks = callbacks;\n this.#isAnyAccountTypeAllowed = isAnyAccountTypeAllowed;\n this.#lock = new Mutex();\n }\n\n /**\n * Get the SnapKeyringEntry for a Snap, creating it if it does not exist yet.\n *\n * Both v1 and v2 share the same KeyringAccountRegistry instance. The\n * onRegister / onUnregister callbacks keep #accountIndex in sync regardless\n * of which class mutates the registry.\n *\n * @param snapId - Snap ID.\n * @returns The SnapKeyringEntry for the given Snap.\n */\n #getOrCreateKeyring(snapId: SnapId): SnapKeyringV2 {\n let keyring = this.#snapKeyrings.get(snapId);\n if (!keyring) {\n keyring = new SnapKeyringV2({\n snapId,\n messenger: this.#messenger,\n isAnyAccountTypeAllowed: this.#isAnyAccountTypeAllowed,\n callbacks: {\n onRegister: (id: AccountId): void => {\n this.#accountIndex.set(id, snapId);\n },\n onUnregister: (id: AccountId): void => {\n this.#accountIndex.delete(id);\n },\n addAccount: async (\n address,\n handleUserInput,\n onceSaved,\n accountNameSuggestion,\n internalOptions,\n ): Promise<void> =>\n this.#callbacks.addAccount(\n address,\n snapId,\n handleUserInput,\n onceSaved,\n accountNameSuggestion,\n internalOptions,\n ),\n removeAccount: async (address, handleUserInput): Promise<void> =>\n this.#callbacks.removeAccount(address, snapId, handleUserInput),\n saveState: async (): Promise<void> => this.#callbacks.saveState(),\n redirectUser: async (url, message): Promise<void> =>\n this.#callbacks.redirectUser(snapId, url, message),\n assertAccountCanBeUsed: async (account): Promise<void> =>\n this.#assertAccountCanBeUsed(account),\n withLock: async <Result>(\n callback: () => Promise<Result>,\n ): Promise<Result> => this.#lock.runExclusive(callback),\n },\n });\n\n this.#snapKeyrings.set(snapId, keyring);\n }\n return keyring;\n }\n\n /**\n * Drop a per-snap keyring from {@link #snapKeyrings} when it has no accounts.\n *\n * Without this, deleting every account for a Snap would leave an empty\n * `SnapKeyringV2` in the map for the rest of the session (unlike the old\n * `SnapIdMap`, which dropped entries on delete).\n *\n * @param snapId - Snap ID whose keyring may be removed.\n */\n async #removeSnapKeyringIfEmpty(snapId: SnapId): Promise<void> {\n const keyring = this.#snapKeyrings.get(snapId);\n if (keyring?.accounts().length === 0) {\n await keyring.destroy();\n this.#snapKeyrings.delete(snapId);\n }\n }\n\n /**\n * Asserts that an account can be used within the Snap keyring. (e.g. generic accounts, unique\n * addresses, etc...).\n *\n * @param account - The account to check.\n * @throws If the account cannot be used.\n */\n async #assertAccountCanBeUsed(account: KeyringAccount): Promise<void> {\n const address = normalizeAccountAddress(account);\n\n // The `AnyAccountType.Account` generic account type is allowed only during\n // development, so we check whether it's allowed before continuing.\n if (\n !this.#isAnyAccountTypeAllowed &&\n account.type === AnyAccountType.Account\n ) {\n throw new Error(`Cannot create generic account '${account.id}'`);\n }\n\n // A Snap could try to create an account with a different address but with\n // an existing ID, so the above test only is not enough.\n // Account IDs are globally unique across all snaps.\n if (this.#accountIndex.has(account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n // The UI still uses the account address to identify accounts, so we need\n // to block the creation of duplicate accounts for now to prevent accounts\n // from being overwritten.\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\n }\n }\n\n /**\n * Handle a message from a Snap.\n *\n * Only `AccountCreated` triggers lazy keyring creation via\n * `#getOrCreateKeyring`, since that is the single entry point for the v1\n * event-driven flow. All other events from unknown snaps throw an error.\n * After handling `AccountCreated`, `#removeSnapKeyringIfEmpty` always runs\n * (via `try/finally`) to clean up if account creation was rejected.\n *\n * @param snapId - ID of the Snap.\n * @param message - Message sent by the Snap.\n * @returns The execution result.\n */\n async handleKeyringSnapMessage(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<Json> {\n let keyring = this.#snapKeyrings.get(snapId);\n\n // We can create a new keyring if the message is an AccountCreated event.\n const isAccountCreated =\n message.method === `${KeyringEvent.AccountCreated}`;\n if (!keyring && isAccountCreated) {\n keyring = this.#getOrCreateKeyring(snapId);\n }\n\n if (!keyring) {\n throw new Error(\n `SnapKeyring - Received a message for an unknown snap keyring '${snapId}'`,\n );\n }\n\n try {\n return await keyring.handleKeyringSnapMessage(message);\n } finally {\n // Clean up if AccountCreated was rejected (e.g. duplicate address,\n // invalid account), leaving the snap with no registered accounts.\n if (isAccountCreated) {\n await this.#removeSnapKeyringIfEmpty(snapId);\n }\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * Delegates to each per-snap v2 keyring and flattens back into the original\n * external format so that `KeyringController` sees no change.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n const accounts: KeyringState['accounts'] = {};\n for (const keyring of this.#snapKeyrings.values()) {\n for (const account of keyring.accounts()) {\n accounts[account.id] = { account, snapId: keyring.snapId };\n }\n }\n return { accounts };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\n *\n * Groups the flat persisted state by `snapId`, clears both indexes, then\n * rebuilds each per-snap entry. The `onRegister` callbacks fired during\n * `v2.deserialize()` automatically repopulate `#accountIndex`.\n *\n * @param state - Serialized keyring state.\n */\n async deserialize(state: KeyringState | undefined): Promise<void> {\n // If the state is undefined, it means that this is a new keyring, so we\n // don't need to do anything.\n if (state === undefined) {\n return;\n }\n\n // Group flat state by snapId. Migrations and migration logging are handled\n // inside v2.deserialize().\n const bySnap = new Map<SnapId, Record<AccountId, KeyringAccount>>();\n for (const entry of Object.values(state.accounts)) {\n const snapAccounts = bySnap.get(entry.snapId) ?? {};\n snapAccounts[entry.account.id] = entry.account;\n bySnap.set(entry.snapId, snapAccounts);\n }\n\n // Destroy existing keyrings before clearing — rejects any pending requests.\n for (const keyring of this.#snapKeyrings.values()) {\n await keyring.destroy();\n }\n\n // Clear both indexes before rebuilding — they must always be consistent.\n this.#snapKeyrings.clear();\n this.#accountIndex.clear();\n\n // Rebuild per-snap keyrings. Each keyrings handles its own validation\n // and migration internally.\n for (const [snapId, accounts] of bySnap) {\n const keyring = this.#getOrCreateKeyring(snapId);\n await keyring.deserialize({ snapId, accounts });\n // onRegister callbacks fired above have repopulated #accountIndex.\n await this.#removeSnapKeyringIfEmpty(snapId);\n }\n }\n\n /**\n * Get an account and its associated Snap ID from its ID.\n *\n * @param id - Account ID.\n * @throws An error if the account could not be found.\n * @returns The account associated with the given account ID in this keyring.\n */\n #getAccount(id: string): { account: KeyringAccount; snapId: SnapId } {\n const snapId = this.#accountIndex.get(id);\n const account = snapId\n ? this.#snapKeyrings.get(snapId)?.lookupAccount(id)\n : undefined;\n\n if (!snapId || !account) {\n throw new Error(`Unable to get account: unknown account ID: '${id}'`);\n }\n return { account, snapId };\n }\n\n /**\n * Get the addresses of the accounts in this keyring.\n *\n * @returns The addresses of the accounts in this keyring.\n */\n async getAccounts(): Promise<string[]> {\n const addresses: string[] = [];\n for (const keyring of this.#snapKeyrings.values()) {\n for (const account of keyring.accounts()) {\n addresses.push(normalizeAccountAddress(account));\n }\n }\n return unique(addresses);\n }\n\n /**\n * Get the addresses of the accounts associated with a given Snap.\n *\n * @param snapId - Snap ID to filter by.\n * @returns The addresses of the accounts associated with the given Snap.\n */\n async getAccountsBySnapId(snapId: SnapId): Promise<string[]> {\n return unique(\n (this.#snapKeyrings.get(snapId)?.accounts() ?? []).map(\n normalizeAccountAddress,\n ),\n );\n }\n\n /**\n * Create an account (v1 event-driven flow).\n *\n * Delegates to the per-snap SnapKeyringV1 instance.\n *\n * @param snapId - Snap ID to create the account for.\n * @param options - Account creation options. Differs between keyrings.\n * @param internalOptions - Internal Snap keyring options.\n * @returns The account object.\n */\n async createAccount(\n snapId: SnapId,\n options: Record<string, Json>,\n internalOptions?: SnapKeyringInternalOptions,\n ): Promise<KeyringAccount> {\n return this.#getOrCreateKeyring(snapId).createAccount(\n options,\n internalOptions,\n );\n }\n\n /**\n * Creates one or more new accounts according to the provided options.\n *\n * Delegates to the per-snap SnapKeyringV2 instance which handles\n * idempotency, validation, batch tracking, state persistence, and rollback.\n *\n * @param snapId - Snap ID to create the account(s) for.\n * @param options - Options describing how to create the account(s).\n * @returns An array of the created account objects.\n */\n async createAccounts(\n snapId: SnapId,\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return this.#getOrCreateKeyring(snapId).createAccounts(options);\n }\n\n /**\n * Checks if a Snap ID is known from the keyring.\n *\n * @param snapId - Snap ID.\n * @returns `true` if the Snap ID is known, `false` otherwise.\n */\n hasSnapId(snapId: SnapId): boolean {\n const keyring = this.#snapKeyrings.get(snapId);\n return keyring !== undefined && keyring.accounts().length > 0;\n }\n\n /**\n * Resolve the Snap account's address associated from a signing request.\n *\n * @param snapId - Snap ID.\n * @param scope - CAIP-2 chain ID.\n * @param request - Signing request object.\n * @throws An error if the Snap ID is not known from the keyring.\n * @returns The resolved address if found, `null` otherwise.\n */\n async resolveAccountAddress(\n snapId: SnapId,\n scope: CaipChainId,\n request: JsonRpcRequest,\n ): Promise<ResolvedAccountAddress | null> {\n // We do check that the incoming Snap ID is known by the keyring.\n if (!this.hasSnapId(snapId)) {\n throw new Error(\n `Unable to resolve account address: unknown Snap ID: ${snapId}`,\n );\n }\n\n return this.#getOrCreateKeyring(snapId).resolveAccountAddress(\n scope,\n request,\n );\n }\n\n /**\n * Submit a request to a Snap from an account ID.\n *\n * This request cannot be an asynchronous keyring request.\n *\n * @param opts - Request options.\n * @param opts.origin - Send origin.\n * @param opts.account - Account ID.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.scope - Selected chain ID (CAIP-2).\n * @returns Promise that resolves to the result of the method call.\n */\n async submitRequest({\n origin,\n account: accountId,\n method,\n params,\n scope,\n }: {\n origin: string;\n // NOTE: We use `account` here rather than `id` to avoid ambiguity with a \"request ID\".\n // We already use this same field name for `KeyringAccount`s.\n account: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n scope: string;\n }): Promise<Json> {\n const { account, snapId } = this.#getAccount(accountId);\n /* istanbul ignore next */\n const keyring =\n this.#snapKeyrings.get(snapId) ??\n throwError(`No keyring found for snap '${snapId}'`);\n\n return await keyring.submitSnapRequest({\n origin,\n account,\n method: method as AccountMethod,\n params,\n scope,\n // For non-EVM (in the context of the multichain API and SIP-26), we enforce responses\n // to be synchronous.\n noPending: true,\n });\n }\n\n /**\n * Sign a transaction.\n *\n * @param address - Sender's address.\n * @param transaction - Transaction.\n * @param _opts - Transaction options (not used).\n * @returns A promise that resolves to the signed transaction.\n */\n async signTransaction(\n address: string,\n transaction: TypedTransaction,\n _opts = {},\n ): Promise<Json | TypedTransaction> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signTransaction(account, transaction, _opts);\n }\n\n /**\n * Sign a typed data message.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @param opts - Signing options.\n * @returns The signature.\n */\n async signTypedData(\n address: string,\n data: Record<string, unknown>[] | TypedDataV1 | TypedMessage<any>,\n opts = { version: SignTypedDataVersion.V1 },\n ): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signTypedData(account, data, opts);\n }\n\n /**\n * Sign a message.\n *\n * @param address - Signer's address.\n * @param hash - Data to sign.\n * @returns The signature.\n */\n async signMessage(address: string, hash: any): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signMessage(account, hash);\n }\n\n /**\n * Sign a personal message.\n *\n * Note: KeyringController says this should return a Buffer but it actually\n * expects a string.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @returns Promise of the signature.\n */\n async signPersonalMessage(address: string, data: any): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signPersonalMessage(account, data);\n }\n\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param context - Keyring execution context.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n async prepareUserOperation(\n address: string,\n transactions: EthBaseTransaction[],\n context: KeyringExecutionContext,\n ): Promise<EthBaseUserOperation> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.prepareUserOperation(account, transactions, context);\n }\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @param context - Keyring execution context.\n * @returns A patch to apply to the UserOperation.\n */\n async patchUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<EthUserOperationPatch> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.patchUserOperation(account, userOp, context);\n }\n\n /**\n * Signs a UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Keyring execution context.\n * @returns The signature of the UserOperation.\n */\n async signUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signUserOperation(account, userOp, context);\n }\n\n /**\n * Gets the private data associated with the given address so\n * that it may be exported.\n *\n * If this keyring contains duplicate public keys the first\n * matching address is exported.\n *\n * Used by the UI to export an account.\n *\n * @param _address - Address of the account to export.\n */\n exportAccount(_address: string): [Uint8Array, Json] | undefined {\n throw new Error('Exporting accounts from snaps is not supported.');\n }\n\n /**\n * Removes the account matching the given address.\n *\n * Delegates to the per-snap SnapKeyringV2 keyring which handles\n * registry removal, index cleanup, and snap communication.\n *\n * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, keyring } = this.#resolveAddress(address);\n await keyring.deleteAccount(account.id);\n await this.#removeSnapKeyringIfEmpty(keyring.snapId);\n }\n\n /**\n * Resolve an address to an account and its owning keyring entry.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and the per-snap keyring that owns it. Throws if not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n keyring: SnapKeyringV2;\n } {\n for (const keyring of this.#snapKeyrings.values()) {\n const account = keyring.lookupByAddress(address);\n if (account) {\n return { account, keyring };\n }\n }\n return throwError(`Account '${address}' not found`);\n }\n\n /**\n * Set the selected accounts.\n *\n * Distributes the global list by snap and forwards to each v1 instance.\n *\n * @param accounts - The accounts to set as selected.\n */\n async setSelectedAccounts(accounts: AccountId[]): Promise<void> {\n // Build per-snap distribution using the account index.\n const bySnap = new Map<SnapId, AccountId[]>();\n for (const accountId of accounts) {\n const snapId = this.#accountIndex.get(accountId);\n if (!snapId) {\n continue;\n }\n const snapAccounts = bySnap.get(snapId) ?? [];\n snapAccounts.push(accountId);\n bySnap.set(snapId, snapAccounts);\n }\n\n await Promise.all(\n [...this.#snapKeyrings.entries()].map(async ([snapId, keyring]) =>\n keyring.setSelectedAccounts(\n /* istanbul ignore next */\n bySnap.get(snapId) ?? [],\n ),\n ),\n );\n }\n\n /**\n * Get the Snap associated with the given Snap ID.\n *\n * @param snapId - Snap ID.\n * @returns The Snap or undefined if the Snap cannot be found.\n */\n #getSnap(snapId: SnapId): Snap | null {\n return this.#messenger.call('SnapController:getSnap', snapId);\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#getSnap(snapId);\n return snap\n ? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }\n : undefined;\n }\n\n #transformToInternalAccount(\n account: KeyringAccount,\n snapId: SnapId,\n ): InternalAccount {\n const snap = this.#getSnapMetadata(snapId);\n\n return {\n ...account,\n // TODO: Do not convert the address to lowercase.\n //\n // This is a workaround to support the current UI which expects the\n // account address to be lowercase. This workaround should be removed\n // once we migrated the UI to use the account ID instead of the account\n // address.\n //\n // NOTE: We convert the address only for EVM accounts, see\n // `normalizeAccountAddress`.\n address: normalizeAccountAddress(account),\n metadata: {\n name: '',\n importTime: 0,\n keyring: {\n type: this.type,\n },\n ...(snap !== undefined && { snap }),\n },\n };\n }\n\n /**\n * Return an internal account object for a given address.\n *\n * @param address - Address of the account to return.\n * @returns An internal account object for the given address.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n for (const [snapId, keyring] of this.#snapKeyrings) {\n const account = keyring.lookupByAddress(address);\n if (account) {\n return this.#transformToInternalAccount(account, snapId);\n }\n }\n return undefined;\n }\n\n /**\n * List all Snap keyring accounts.\n * This method is expensive on mobile devices and could takes tens or hundreds of milliseconds to complete.\n * Use with caution.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n const accounts: InternalAccount[] = [];\n for (const [snapId, keyring] of this.#snapKeyrings) {\n for (const account of keyring.accounts()) {\n accounts.push(this.#transformToInternalAccount(account, snapId));\n }\n }\n return accounts;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SnapKeyring.cjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yDAA8D;AAY9D,uDAAqE;AAMrE,6CAAoC;AAEpC,2CAAoD;AAGpD,qEAA2D;AAG3D,qCAA4C;AAC5C,sDAAgE;AAEnD,QAAA,iBAAiB,GAAG,cAAc,CAAC;AAwChD;;GAEG;AACH,MAAa,WAAW;IAiEtB;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,SAAS,EACT,uBAAuB,GAAG,KAAK,GAKhC;;QA7ED,0DAA0D;QAC1D,SAAI,GAA6B,wCAAiB,CAAC;QAEnD,UAAK,GAAG,IAAI,CAAC;QAEb;;WAEG;QACM,yCAAiC;QAE1C;;;;WAIG;QACM,4CAA0C;QAE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AAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3C,CAAC,6FAGC,OAAuB,EACvB,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,4DAAiB,MAArB,IAAI,EAAkB,MAAM,CAAC,CAAC;IAE3C,OAAO;QACL,GAAG,OAAO;QACV,iDAAiD;QACjD,EAAE;QACF,mEAAmE;QACnE,qEAAqE;QACrE,uEAAuE;QACvE,WAAW;QACX,EAAE;QACF,0DAA0D;QAC1D,6BAA6B;QAC7B,OAAO,EAAE,IAAA,iCAAuB,EAAC,OAAO,CAAC;QACzC,QAAQ,EAAE;YACR,IAAI,EAAE,EAAE;YACR,UAAU,EAAE,CAAC;YACb,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB;YACD,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC;SACpC;KACF,CAAC;AACJ,CAAC;AAjvBM,gBAAI,GAAW,yBAAiB,AAA5B,CAA6B","sourcesContent":["import type { TypedTransaction } from '@ethereumjs/tx';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n ResolvedAccountAddress,\n CaipChainId,\n CreateAccountOptions,\n} from '@metamask/keyring-api';\nimport { AnyAccountType, KeyringEvent } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { AccountId, JsonRpcRequest } from '@metamask/keyring-utils';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport { normalizeAccountAddress } from './account';\nimport type { SnapKeyringInternalOptions } from './options';\nimport type { SnapKeyringMessenger } from './SnapKeyringMessenger';\nimport { SNAP_KEYRING_NAME } from './SnapKeyringMessenger';\nimport type { AccountMethod } from './SnapKeyringV1';\nimport type { SnapMessage } from './types';\nimport { throwError, unique } from './util';\nimport { SnapKeyring as SnapKeyringV2 } from './v2/SnapKeyring';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n/**\n * Snap keyring state.\n *\n * This state is persisted by the keyring controller and passed to the Snap\n * keyring when it's created.\n */\nexport type KeyringState = {\n accounts: Record<string, { account: KeyringAccount; snapId: SnapId }>;\n};\n\n/**\n * Snap keyring callbacks.\n *\n * These callbacks are used to interact with other components.\n */\nexport type SnapKeyringCallbacks = {\n saveState: () => Promise<void>;\n\n addressExists(address: string): Promise<boolean>;\n\n addAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n onceSaved: Promise<AccountId>,\n accountNameSuggestion?: string,\n internalOptions?: SnapKeyringInternalOptions,\n ): Promise<void>;\n\n removeAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n ): Promise<void>;\n\n redirectUser(snapId: SnapId, url: string, message: string): Promise<void>;\n};\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n // Name and state are required for modular initialisation.\n name: typeof SNAP_KEYRING_NAME = SNAP_KEYRING_NAME;\n\n state = null;\n\n /**\n * Messenger to dispatch requests to the Snaps controller.\n */\n readonly #messenger: SnapKeyringMessenger;\n\n /**\n * Per-snap keyring instances. Each `SnapKeyringV2` (which extends\n * `SnapKeyringV1`) owns a single `KeyringAccountRegistry` and handles\n * both the event-driven v1 flow and the `KeyringV2` batch interface.\n */\n readonly #snapKeyrings: Map<SnapId, SnapKeyringV2>;\n\n /**\n * Reverse index from account ID to the owning Snap ID.\n *\n * Populated and kept in sync via the `onRegister` / `onUnregister`\n * callbacks injected into each entry. Enables O(1) routing for\n * any \"which snap owns this account?\" query.\n */\n readonly #accountIndex: Map<AccountId, SnapId>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Whether to allow the creation and update of generic accounts.\n *\n * Account deletion is not affected by this flag and is always allowed.\n */\n readonly #isAnyAccountTypeAllowed: boolean;\n\n /**\n * Global mutex that serializes `createAccounts` calls across all snaps.\n *\n * `assertAccountCanBeUsed` checks global state (`#accountIndex` for ID\n * uniqueness, `addressExists` for address uniqueness). Without serialization,\n * two concurrent `createAccounts` calls from different snaps could both pass\n * the uniqueness check before either one calls `setAccount`, leading to\n * duplicate accounts. Injected into each `SnapKeyringV2` via the optional\n * `withLock` callback.\n */\n readonly #lock: Mutex;\n\n /**\n * Serializes lazy keyring initialization in {@link SnapKeyring.#getOrCreateKeyring}.\n *\n * Kept separate from {@link SnapKeyring.#lock} (which guards `createAccounts`\n * uniqueness checks) to avoid mixing concerns. The lock is held only for the\n * duration of a single keyring's initialization - released before the caller\n * proceeds with its operation.\n */\n readonly #getOrCreateKeyringLock: Mutex;\n\n /**\n * Create a new Snap keyring.\n *\n * @param options - Constructor options.\n * @param options.messenger - Snap keyring messenger.\n * @param options.callbacks - Callbacks used to interact with other components.\n * @param options.isAnyAccountTypeAllowed - Whether to allow the `AnyAccountType` generic account type.\n * @returns A new Snap keyring.\n */\n constructor({\n messenger,\n callbacks,\n isAnyAccountTypeAllowed = false,\n }: {\n messenger: SnapKeyringMessenger;\n callbacks: SnapKeyringCallbacks;\n isAnyAccountTypeAllowed?: boolean;\n }) {\n this.type = SnapKeyring.type;\n this.#messenger = messenger;\n this.#snapKeyrings = new Map();\n this.#accountIndex = new Map();\n this.#callbacks = callbacks;\n this.#isAnyAccountTypeAllowed = isAnyAccountTypeAllowed;\n this.#lock = new Mutex();\n this.#getOrCreateKeyringLock = new Mutex();\n }\n\n /**\n * Get the SnapKeyringEntry for a Snap, creating and initializing it if it\n * does not exist yet.\n *\n * When a new keyring is created it is immediately initialized by calling\n * `deserialize({ snapId, accounts: {} })` so that `snapId` and the internal\n * snap client are available before any event handler or method runs.\n *\n * Both v1 and v2 share the same KeyringAccountRegistry instance. The\n * onRegister / onUnregister callbacks keep #accountIndex in sync regardless\n * of which class mutates the registry.\n *\n * @param snapId - Snap ID.\n * @returns The SnapKeyringEntry for the given Snap.\n */\n async #getOrCreateKeyring(snapId: SnapId): Promise<SnapKeyringV2> {\n // Fast path: keyring already exists, no lock needed.\n const existing = this.#snapKeyrings.get(snapId);\n if (existing) {\n return existing;\n }\n\n return this.#getOrCreateKeyringLock.runExclusive(async () => {\n // Double-check: a concurrent caller may have created the keyring while\n // we were waiting for the lock.\n const keyring = this.#snapKeyrings.get(snapId);\n if (keyring) {\n return keyring;\n }\n\n const newKeyring = new SnapKeyringV2({\n messenger: this.#messenger,\n isAnyAccountTypeAllowed: this.#isAnyAccountTypeAllowed,\n callbacks: {\n // Optional callbacks that mutate accounts are responsible for keeping\n // #accountIndex in sync via these callbacks.\n onRegister: (id: AccountId): void => {\n // We can safely use `snapId` here because we create the keyring\n // instance right away.\n this.#accountIndex.set(id, snapId);\n },\n onUnregister: (id: AccountId): void => {\n this.#accountIndex.delete(id);\n },\n // Required callbacks:\n // NOTE: `keyringSnapId` and `snapId` are the same value. The `keyringSnapId` is coming from\n // the `deserialize` call right after.\n addAccount: async (\n address,\n keyringSnapId,\n handleUserInput,\n onceSaved,\n accountNameSuggestion,\n internalOptions,\n ): Promise<void> =>\n this.#callbacks.addAccount(\n address,\n keyringSnapId,\n handleUserInput,\n onceSaved,\n accountNameSuggestion,\n internalOptions,\n ),\n removeAccount: async (\n address,\n keyringSnapId,\n handleUserInput,\n ): Promise<void> =>\n this.#callbacks.removeAccount(\n address,\n keyringSnapId,\n handleUserInput,\n ),\n saveState: async (): Promise<void> => this.#callbacks.saveState(),\n redirectUser: async (id, url, message): Promise<void> =>\n this.#callbacks.redirectUser(id, url, message),\n assertAccountCanBeUsed: async (account): Promise<void> =>\n this.#assertAccountCanBeUsed(account),\n withLock: async <Result>(\n callback: () => Promise<Result>,\n ): Promise<Result> => this.#lock.runExclusive(callback),\n },\n });\n\n // Initialize the keyring with its snap ID (no accounts yet).\n await newKeyring.deserialize({ snapId, accounts: {} });\n\n // Keyring is fully initialized; register it before releasing the lock so\n // that no concurrent caller can create a duplicate.\n this.#snapKeyrings.set(snapId, newKeyring);\n\n return newKeyring;\n });\n }\n\n /**\n * Drop a per-snap keyring from {@link #snapKeyrings} when it has no accounts.\n *\n * Without this, deleting every account for a Snap would leave an empty\n * `SnapKeyringV2` in the map for the rest of the session (unlike the old\n * `SnapIdMap`, which dropped entries on delete).\n *\n * @param snapId - Snap ID whose keyring may be removed.\n */\n async #removeSnapKeyringIfEmpty(snapId: SnapId): Promise<void> {\n const keyring = this.#snapKeyrings.get(snapId);\n if (keyring?.accounts().length === 0) {\n await keyring.destroy();\n this.#snapKeyrings.delete(snapId);\n }\n }\n\n /**\n * Asserts that an account can be used within the Snap keyring. (e.g. generic accounts, unique\n * addresses, etc...).\n *\n * @param account - The account to check.\n * @throws If the account cannot be used.\n */\n async #assertAccountCanBeUsed(account: KeyringAccount): Promise<void> {\n const address = normalizeAccountAddress(account);\n\n // The `AnyAccountType.Account` generic account type is allowed only during\n // development, so we check whether it's allowed before continuing.\n if (\n !this.#isAnyAccountTypeAllowed &&\n account.type === AnyAccountType.Account\n ) {\n throw new Error(`Cannot create generic account '${account.id}'`);\n }\n\n // A Snap could try to create an account with a different address but with\n // an existing ID, so the above test only is not enough.\n // Account IDs are globally unique across all snaps.\n if (this.#accountIndex.has(account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n // The UI still uses the account address to identify accounts, so we need\n // to block the creation of duplicate accounts for now to prevent accounts\n // from being overwritten.\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\n }\n }\n\n /**\n * Handle a message from a Snap.\n *\n * Only `AccountCreated` triggers lazy keyring creation via\n * `#getOrCreateKeyring`, since that is the single entry point for the v1\n * event-driven flow. All other events from unknown snaps throw an error.\n * After handling `AccountCreated`, `#removeSnapKeyringIfEmpty` always runs\n * (via `try/finally`) to clean up if account creation was rejected.\n *\n * @param snapId - ID of the Snap.\n * @param message - Message sent by the Snap.\n * @returns The execution result.\n */\n async handleKeyringSnapMessage(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<Json> {\n let keyring = this.#snapKeyrings.get(snapId);\n\n // We can create a new keyring if the message is an AccountCreated event.\n const isAccountCreated =\n message.method === `${KeyringEvent.AccountCreated}`;\n if (!keyring && isAccountCreated) {\n keyring = await this.#getOrCreateKeyring(snapId);\n }\n\n if (!keyring) {\n throw new Error(\n `SnapKeyring - Received a message for an unknown snap keyring '${snapId}'`,\n );\n }\n\n try {\n return await keyring.handleKeyringSnapMessage(message);\n } finally {\n // Clean up if AccountCreated was rejected (e.g. duplicate address,\n // invalid account), leaving the snap with no registered accounts.\n if (isAccountCreated) {\n await this.#removeSnapKeyringIfEmpty(snapId);\n }\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * Delegates to each per-snap v2 keyring and flattens back into the original\n * external format so that `KeyringController` sees no change.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n const accounts: KeyringState['accounts'] = {};\n for (const keyring of this.#snapKeyrings.values()) {\n for (const account of keyring.accounts()) {\n accounts[account.id] = { account, snapId: keyring.snapId };\n }\n }\n return { accounts };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\n *\n * Groups the flat persisted state by `snapId`, clears both indexes, then\n * rebuilds each per-snap entry. The `onRegister` callbacks fired during\n * `v2.deserialize()` automatically repopulate `#accountIndex`.\n *\n * @param state - Serialized keyring state.\n */\n async deserialize(state: KeyringState | undefined): Promise<void> {\n // If the state is undefined, it means that this is a new keyring, so we\n // don't need to do anything.\n if (state === undefined) {\n return;\n }\n\n // Group flat state by snapId. Migrations and migration logging are handled\n // inside v2.deserialize().\n const bySnap = new Map<SnapId, Record<AccountId, KeyringAccount>>();\n for (const entry of Object.values(state.accounts)) {\n const snapAccounts = bySnap.get(entry.snapId) ?? {};\n snapAccounts[entry.account.id] = entry.account;\n bySnap.set(entry.snapId, snapAccounts);\n }\n\n // Destroy existing keyrings before clearing — rejects any pending requests.\n for (const keyring of this.#snapKeyrings.values()) {\n await keyring.destroy();\n }\n\n // Clear both indexes before rebuilding — they must always be consistent.\n this.#snapKeyrings.clear();\n this.#accountIndex.clear();\n\n // Rebuild per-snap keyrings. Each keyring handles its own validation\n // and migration internally. #getOrCreateKeyring initializes the keyring\n // with an empty state; the second deserialize call loads the real accounts.\n for (const [snapId, accounts] of bySnap) {\n const keyring = await this.#getOrCreateKeyring(snapId);\n await keyring.deserialize({ snapId, accounts });\n // onRegister callbacks fired above have repopulated #accountIndex.\n await this.#removeSnapKeyringIfEmpty(snapId);\n }\n }\n\n /**\n * Get an account and its associated Snap ID from its ID.\n *\n * @param id - Account ID.\n * @throws An error if the account could not be found.\n * @returns The account associated with the given account ID in this keyring.\n */\n #getAccount(id: string): { account: KeyringAccount; snapId: SnapId } {\n const snapId = this.#accountIndex.get(id);\n const account = snapId\n ? this.#snapKeyrings.get(snapId)?.lookupAccount(id)\n : undefined;\n\n if (!snapId || !account) {\n throw new Error(`Unable to get account: unknown account ID: '${id}'`);\n }\n return { account, snapId };\n }\n\n /**\n * Get the addresses of the accounts in this keyring.\n *\n * @returns The addresses of the accounts in this keyring.\n */\n async getAccounts(): Promise<string[]> {\n const addresses: string[] = [];\n for (const keyring of this.#snapKeyrings.values()) {\n for (const account of keyring.accounts()) {\n addresses.push(normalizeAccountAddress(account));\n }\n }\n return unique(addresses);\n }\n\n /**\n * Get the addresses of the accounts associated with a given Snap.\n *\n * @param snapId - Snap ID to filter by.\n * @returns The addresses of the accounts associated with the given Snap.\n */\n async getAccountsBySnapId(snapId: SnapId): Promise<string[]> {\n return unique(\n (this.#snapKeyrings.get(snapId)?.accounts() ?? []).map(\n normalizeAccountAddress,\n ),\n );\n }\n\n /**\n * Create an account (v1 event-driven flow).\n *\n * Delegates to the per-snap SnapKeyringV1 instance.\n *\n * @param snapId - Snap ID to create the account for.\n * @param options - Account creation options. Differs between keyrings.\n * @param internalOptions - Internal Snap keyring options.\n * @returns The account object.\n */\n async createAccount(\n snapId: SnapId,\n options: Record<string, Json>,\n internalOptions?: SnapKeyringInternalOptions,\n ): Promise<KeyringAccount> {\n const keyring = await this.#getOrCreateKeyring(snapId);\n return keyring.createAccount(options, internalOptions);\n }\n\n /**\n * Creates one or more new accounts according to the provided options.\n *\n * Delegates to the per-snap SnapKeyringV2 instance which handles\n * idempotency, validation, batch tracking, state persistence, and rollback.\n *\n * @param snapId - Snap ID to create the account(s) for.\n * @param options - Options describing how to create the account(s).\n * @returns An array of the created account objects.\n */\n async createAccounts(\n snapId: SnapId,\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n const keyring = await this.#getOrCreateKeyring(snapId);\n return keyring.createAccounts(options);\n }\n\n /**\n * Checks if a Snap ID is known from the keyring.\n *\n * @param snapId - Snap ID.\n * @returns `true` if the Snap ID is known, `false` otherwise.\n */\n hasSnapId(snapId: SnapId): boolean {\n const keyring = this.#snapKeyrings.get(snapId);\n return keyring !== undefined && keyring.accounts().length > 0;\n }\n\n /**\n * Resolve the Snap account's address associated from a signing request.\n *\n * @param snapId - Snap ID.\n * @param scope - CAIP-2 chain ID.\n * @param request - Signing request object.\n * @throws An error if the Snap ID is not known from the keyring.\n * @returns The resolved address if found, `null` otherwise.\n */\n async resolveAccountAddress(\n snapId: SnapId,\n scope: CaipChainId,\n request: JsonRpcRequest,\n ): Promise<ResolvedAccountAddress | null> {\n // We do check that the incoming Snap ID is known by the keyring.\n if (!this.hasSnapId(snapId)) {\n throw new Error(\n `Unable to resolve account address: unknown Snap ID: ${snapId}`,\n );\n }\n\n const keyring = await this.#getOrCreateKeyring(snapId);\n return keyring.resolveAccountAddress(scope, request);\n }\n\n /**\n * Submit a request to a Snap from an account ID.\n *\n * This request cannot be an asynchronous keyring request.\n *\n * @param opts - Request options.\n * @param opts.origin - Send origin.\n * @param opts.account - Account ID.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.scope - Selected chain ID (CAIP-2).\n * @returns Promise that resolves to the result of the method call.\n */\n async submitRequest({\n origin,\n account: accountId,\n method,\n params,\n scope,\n }: {\n origin: string;\n // NOTE: We use `account` here rather than `id` to avoid ambiguity with a \"request ID\".\n // We already use this same field name for `KeyringAccount`s.\n account: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n scope: string;\n }): Promise<Json> {\n const { account, snapId } = this.#getAccount(accountId);\n /* istanbul ignore next */\n const keyring =\n this.#snapKeyrings.get(snapId) ??\n throwError(`No keyring found for snap '${snapId}'`);\n\n return await keyring.submitSnapRequest({\n origin,\n account,\n method: method as AccountMethod,\n params,\n scope,\n // For non-EVM (in the context of the multichain API and SIP-26), we enforce responses\n // to be synchronous.\n noPending: true,\n });\n }\n\n /**\n * Sign a transaction.\n *\n * @param address - Sender's address.\n * @param transaction - Transaction.\n * @param _opts - Transaction options (not used).\n * @returns A promise that resolves to the signed transaction.\n */\n async signTransaction(\n address: string,\n transaction: TypedTransaction,\n _opts = {},\n ): Promise<Json | TypedTransaction> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signTransaction(account, transaction, _opts);\n }\n\n /**\n * Sign a typed data message.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @param opts - Signing options.\n * @returns The signature.\n */\n async signTypedData(\n address: string,\n data: Record<string, unknown>[] | TypedDataV1 | TypedMessage<any>,\n opts = { version: SignTypedDataVersion.V1 },\n ): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signTypedData(account, data, opts);\n }\n\n /**\n * Sign a message.\n *\n * @param address - Signer's address.\n * @param hash - Data to sign.\n * @returns The signature.\n */\n async signMessage(address: string, hash: any): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signMessage(account, hash);\n }\n\n /**\n * Sign a personal message.\n *\n * Note: KeyringController says this should return a Buffer but it actually\n * expects a string.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @returns Promise of the signature.\n */\n async signPersonalMessage(address: string, data: any): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signPersonalMessage(account, data);\n }\n\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param context - Keyring execution context.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n async prepareUserOperation(\n address: string,\n transactions: EthBaseTransaction[],\n context: KeyringExecutionContext,\n ): Promise<EthBaseUserOperation> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.prepareUserOperation(account, transactions, context);\n }\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @param context - Keyring execution context.\n * @returns A patch to apply to the UserOperation.\n */\n async patchUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<EthUserOperationPatch> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.patchUserOperation(account, userOp, context);\n }\n\n /**\n * Signs a UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Keyring execution context.\n * @returns The signature of the UserOperation.\n */\n async signUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signUserOperation(account, userOp, context);\n }\n\n /**\n * Gets the private data associated with the given address so\n * that it may be exported.\n *\n * If this keyring contains duplicate public keys the first\n * matching address is exported.\n *\n * Used by the UI to export an account.\n *\n * @param _address - Address of the account to export.\n */\n exportAccount(_address: string): [Uint8Array, Json] | undefined {\n throw new Error('Exporting accounts from snaps is not supported.');\n }\n\n /**\n * Removes the account matching the given address.\n *\n * Delegates to the per-snap SnapKeyringV2 keyring which handles\n * registry removal, index cleanup, and snap communication.\n *\n * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, keyring } = this.#resolveAddress(address);\n await keyring.deleteAccount(account.id);\n await this.#removeSnapKeyringIfEmpty(keyring.snapId);\n }\n\n /**\n * Resolve an address to an account and its owning keyring entry.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and the per-snap keyring that owns it. Throws if not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n keyring: SnapKeyringV2;\n } {\n for (const keyring of this.#snapKeyrings.values()) {\n const account = keyring.lookupByAddress(address);\n if (account) {\n return { account, keyring };\n }\n }\n return throwError(`Account '${address}' not found`);\n }\n\n /**\n * Set the selected accounts.\n *\n * Distributes the global list by snap and forwards to each v1 instance.\n *\n * @param accounts - The accounts to set as selected.\n */\n async setSelectedAccounts(accounts: AccountId[]): Promise<void> {\n // Build per-snap distribution using the account index.\n const bySnap = new Map<SnapId, AccountId[]>();\n for (const accountId of accounts) {\n const snapId = this.#accountIndex.get(accountId);\n if (!snapId) {\n continue;\n }\n const snapAccounts = bySnap.get(snapId) ?? [];\n snapAccounts.push(accountId);\n bySnap.set(snapId, snapAccounts);\n }\n\n await Promise.all(\n [...this.#snapKeyrings.entries()].map(async ([snapId, keyring]) =>\n keyring.setSelectedAccounts(\n /* istanbul ignore next */\n bySnap.get(snapId) ?? [],\n ),\n ),\n );\n }\n\n /**\n * Get the Snap associated with the given Snap ID.\n *\n * @param snapId - Snap ID.\n * @returns The Snap or undefined if the Snap cannot be found.\n */\n #getSnap(snapId: SnapId): Snap | null {\n return this.#messenger.call('SnapController:getSnap', snapId);\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#getSnap(snapId);\n return snap ? { id: snapId } : undefined;\n }\n\n #transformToInternalAccount(\n account: KeyringAccount,\n snapId: SnapId,\n ): InternalAccount {\n const snap = this.#getSnapMetadata(snapId);\n\n return {\n ...account,\n // TODO: Do not convert the address to lowercase.\n //\n // This is a workaround to support the current UI which expects the\n // account address to be lowercase. This workaround should be removed\n // once we migrated the UI to use the account ID instead of the account\n // address.\n //\n // NOTE: We convert the address only for EVM accounts, see\n // `normalizeAccountAddress`.\n address: normalizeAccountAddress(account),\n metadata: {\n name: '',\n importTime: 0,\n keyring: {\n type: this.type,\n },\n ...(snap !== undefined && { snap }),\n },\n };\n }\n\n /**\n * Return an internal account object for a given address.\n *\n * @param address - Address of the account to return.\n * @returns An internal account object for the given address.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n for (const [snapId, keyring] of this.#snapKeyrings) {\n const account = keyring.lookupByAddress(address);\n if (account) {\n return this.#transformToInternalAccount(account, snapId);\n }\n }\n return undefined;\n }\n\n /**\n * List all Snap keyring accounts.\n * This method is expensive on mobile devices and could takes tens or hundreds of milliseconds to complete.\n * Use with caution.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n const accounts: InternalAccount[] = [];\n for (const [snapId, keyring] of this.#snapKeyrings) {\n for (const account of keyring.accounts()) {\n accounts.push(this.#transformToInternalAccount(account, snapId));\n }\n }\n return accounts;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapKeyring.d.cts","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,+BAA+B;AACxE,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAC9D,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,WAAW,EACX,oBAAoB,EACrB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAC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AMG;IACH,YAAY,IAAI,eAAe,EAAE;CASlC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapKeyring.d.mts","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,+BAA+B;AACxE,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAC9D,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,WAAW,EACX,oBAAoB,EACrB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gCAAgC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"SnapKeyring.d.mts","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,+BAA+B;AACxE,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAC9D,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,WAAW,EACX,oBAAoB,EACrB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gCAAgC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO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