@metamask-previews/eth-snap-keyring 20.0.0-ea8175e → 21.0.1-7275dbc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +25 -2
  2. package/README.md +0 -7
  3. package/dist/SnapIdMap.cjs +0 -2
  4. package/dist/SnapIdMap.cjs.map +1 -1
  5. package/dist/SnapIdMap.d.cts.map +1 -1
  6. package/dist/SnapIdMap.d.mts.map +1 -1
  7. package/dist/SnapIdMap.mjs +0 -2
  8. package/dist/SnapIdMap.mjs.map +1 -1
  9. package/dist/SnapKeyring.cjs +1 -2
  10. package/dist/SnapKeyring.cjs.map +1 -1
  11. package/dist/SnapKeyring.d.cts +1 -1
  12. package/dist/SnapKeyring.d.cts.map +1 -1
  13. package/dist/SnapKeyring.d.mts +1 -1
  14. package/dist/SnapKeyring.d.mts.map +1 -1
  15. package/dist/SnapKeyring.mjs +1 -2
  16. package/dist/SnapKeyring.mjs.map +1 -1
  17. package/dist/SnapKeyringV1.cjs.map +1 -1
  18. package/dist/SnapKeyringV1.d.cts +1 -1
  19. package/dist/SnapKeyringV1.d.cts.map +1 -1
  20. package/dist/SnapKeyringV1.d.mts +1 -1
  21. package/dist/SnapKeyringV1.d.mts.map +1 -1
  22. package/dist/SnapKeyringV1.mjs.map +1 -1
  23. package/dist/account.cjs +4 -0
  24. package/dist/account.cjs.map +1 -1
  25. package/dist/account.d.cts +4 -3
  26. package/dist/account.d.cts.map +1 -1
  27. package/dist/account.d.mts +4 -3
  28. package/dist/account.d.mts.map +1 -1
  29. package/dist/account.mjs +5 -1
  30. package/dist/account.mjs.map +1 -1
  31. package/dist/events.d.cts +12 -12
  32. package/dist/events.d.cts.map +1 -1
  33. package/dist/events.d.mts +12 -12
  34. package/dist/events.d.mts.map +1 -1
  35. package/dist/migrations/v1.cjs +4 -0
  36. package/dist/migrations/v1.cjs.map +1 -1
  37. package/dist/migrations/v1.d.cts +1 -1
  38. package/dist/migrations/v1.d.cts.map +1 -1
  39. package/dist/migrations/v1.d.mts +1 -1
  40. package/dist/migrations/v1.d.mts.map +1 -1
  41. package/dist/migrations/v1.mjs +5 -1
  42. package/dist/migrations/v1.mjs.map +1 -1
  43. package/dist/v2/SnapKeyring.d.cts +4 -4
  44. package/dist/v2/SnapKeyring.d.cts.map +1 -1
  45. package/dist/v2/SnapKeyring.d.mts +4 -4
  46. package/dist/v2/SnapKeyring.d.mts.map +1 -1
  47. package/package.json +47 -30
  48. package/v2.js +3 -0
package/CHANGELOG.md CHANGED
@@ -7,8 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [21.0.1]
11
+
12
+ ### Changed
13
+
14
+ - Bump `@metamask/keyring-internal-api` from `^10.1.0` to `^10.1.1` ([#518](https://github.com/MetaMask/accounts/pull/518))
15
+ - Bump `@metamask/keyring-internal-snap-client` from `^10.0.0` to `^10.0.1` ([#518](https://github.com/MetaMask/accounts/pull/518))
16
+ - Bump `@metamask/keyring-sdk` from `^2.0.0` to `^2.0.1` ([#518](https://github.com/MetaMask/accounts/pull/518))
17
+ - Bump `@metamask/keyring-snap-sdk` from `^9.0.0` to `^9.0.1` ([#518](https://github.com/MetaMask/accounts/pull/518))
18
+
19
+ ### Fixed
20
+
21
+ - Workaround Browserify subpath export for `/v2` ([#516](https://github.com/MetaMask/accounts/pull/516))
22
+
23
+ ## [21.0.0]
24
+
10
25
  ### Added
11
26
 
27
+ - Support Stellar (`xlm:account`) accounts in account assertions and v1 migrations ([#483](https://github.com/MetaMask/accounts/pull/483))
12
28
  - Add `SnapKeyringV1` class, a per-snap keyring wrapper that implements the old keyring interface and flows ([#507](https://github.com/MetaMask/accounts/pull/507))
13
29
  - This will allow us to re-use the existing logic (that we still use today) as part of the new V2 implementation until we completely them.
14
30
  - Add `SnapKeyringV2` class, a per-snap keyring wrapper that implements `KeyringV2` with `createAccount`, `createAccounts`, `deleteAccount`, `submitRequest`, `getAccount`, and `getAccounts` ([#501](https://github.com/MetaMask/accounts/pull/501)), ([#507](https://github.com/MetaMask/accounts/pull/507))
@@ -21,12 +37,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21
37
 
22
38
  - **BREAKING:** Move and rename `SnapKeyringV2` to the new `./v2` subpath export ([#513](https://github.com/MetaMask/accounts/pull/513))
23
39
  - `SnapKeyringV2` is now `SnapKeyring` from `@metamask/keyring-snap-bridge/v2`.
40
+ - **BREAKING:** Bump `@metamask/keyring-api` from `^22.0.0` to `^23.0.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
24
41
  - Use `DeferredPromise` from `@metamask/utils` ([#508](https://github.com/MetaMask/accounts/pull/508))
25
42
  - Refactor `SnapKeyring` to store accounts in per-snap `SnapKeyringV2` wrappers instead of a single flat map ([#501](https://github.com/MetaMask/accounts/pull/501))
26
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))
27
44
  - Bump `@metamask/snaps-controllers` from `^19.0.0` to `^19.0.1` ([#500](https://github.com/MetaMask/accounts/pull/500))
28
45
  - Bump `@metamask/snaps-utils` from `^12.1.2` to `^12.1.3` ([#500](https://github.com/MetaMask/accounts/pull/500))
29
- - Bump `@metamask/utils` from `^11.1.0` to `^11.10.0` ([#489](https://github.com/MetaMask/accounts/pull/489))
46
+ - Bump `@metamask/utils` from `^11.10.0` to `^11.11.0` ([#483](https://github.com/MetaMask/accounts/pull/483))
47
+ - Bump `@metamask/keyring-internal-api` from `^10.0.1` to `^10.1.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
48
+ - Bump `@metamask/keyring-internal-snap-client` from `^9.0.1` to `^10.0.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
49
+ - Bump `@metamask/keyring-sdk` from `^1.2.0` to `^2.0.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
50
+ - Bump `@metamask/keyring-snap-sdk` from `^8.0.0` to `^9.0.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
30
51
 
31
52
  ## [20.0.0]
32
53
 
@@ -666,7 +687,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
666
687
 
667
688
  - Initial release.
668
689
 
669
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@20.0.0...HEAD
690
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@21.0.1...HEAD
691
+ [21.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@21.0.0...@metamask/eth-snap-keyring@21.0.1
692
+ [21.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@20.0.0...@metamask/eth-snap-keyring@21.0.0
670
693
  [20.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@19.0.0...@metamask/eth-snap-keyring@20.0.0
671
694
  [19.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@18.0.2...@metamask/eth-snap-keyring@19.0.0
672
695
  [18.0.2]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@18.0.1...@metamask/eth-snap-keyring@18.0.2
package/README.md CHANGED
@@ -37,35 +37,28 @@ Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and
37
37
  The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.
38
38
 
39
39
  1. Choose a release version.
40
-
41
40
  - The release version should be chosen according to SemVer. Analyze the changes to see whether they include any breaking changes, new features, or deprecations, then choose the appropriate SemVer version. See [the SemVer specification](https://semver.org/) for more information.
42
41
 
43
42
  2. If this release is backporting changes onto a previous release, then ensure there is a major version branch for that version (e.g. `1.x` for a `v1` backport release).
44
-
45
43
  - The major version branch should be set to the most recent release with that major version. For example, when backporting a `v1.0.2` release, you'd want to ensure there was a `1.x` branch that was set to the `v1.0.1` tag.
46
44
 
47
45
  3. Trigger the [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event [manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) for the `Create Release Pull Request` action to create the release PR.
48
-
49
46
  - For a backport release, the base branch should be the major version branch that you ensured existed in step 2. For a normal release, the base branch should be the main branch for that repository (which should be the default value).
50
47
  - This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.
51
48
 
52
49
  4. Update the changelog to move each change entry into the appropriate change category ([See here](https://keepachangelog.com/en/1.0.0/#types) for the full list of change categories, and the correct ordering), and edit them to be more easily understood by users of the package.
53
-
54
50
  - Generally any changes that don't affect consumers of the package (e.g. lockfile changes or development environment changes) are omitted. Exceptions may be made for changes that might be of interest despite not having an effect upon the published package (e.g. major test improvements, security improvements, improved documentation, etc.).
55
51
  - Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
56
52
  - Consolidate related changes into one change entry if it makes it easier to explain.
57
53
  - Run `yarn auto-changelog validate --rc` to check that the changelog is correctly formatted.
58
54
 
59
55
  5. Review and QA the release.
60
-
61
56
  - If changes are made to the base branch, the release branch will need to be updated with these changes and review/QA will need to restart again. As such, it's probably best to avoid merging other PRs into the base branch while review is underway.
62
57
 
63
58
  6. Squash & Merge the release.
64
-
65
59
  - This should trigger the [`action-publish-release`](https://github.com/MetaMask/action-publish-release) workflow to tag the final release commit and publish the release on GitHub.
66
60
 
67
61
  7. Publish the release on npm.
68
-
69
62
  - Wait for the `publish-release` GitHub Action workflow to finish. This should trigger a second job (`publish-npm`), which will wait for a run approval by the [`npm publishers`](https://github.com/orgs/MetaMask/teams/npm-publishers) team.
70
63
  - Approve the `publish-npm` job (or ask somebody on the npm publishers team to approve it for you).
71
64
  - Once the `publish-npm` job has finished, check npm to verify that it has been published.
@@ -220,7 +220,6 @@ class SnapIdMap {
220
220
  delete(snapId, key) {
221
221
  return this.has(snapId, key) && __classPrivateFieldGet(this, _SnapIdMap_map, "f").delete(key);
222
222
  }
223
- /* eslint-disable jsdoc/check-indentation */
224
223
  /**
225
224
  * Adds or updates a key-value pair in the map.
226
225
  *
@@ -239,7 +238,6 @@ class SnapIdMap {
239
238
  * @param value - Value of the element to add or update.
240
239
  * @returns The map itself.
241
240
  */
242
- /* eslint-enable jsdoc/check-indentation */
243
241
  set(key, value) {
244
242
  // If the key is present in the map but isn't associated with the given
245
243
  // Snap ID, it means that the item was added to the map by a different
@@ -1 +1 @@
1
- {"version":3,"file":"SnapIdMap.cjs","sourceRoot":"","sources":["../src/SnapIdMap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,iEAA0D;AAE1D;;GAEG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAW3C;;;;;OAKG;IACH,YAAY,MAAc,EAAE,GAAW;QACrC,KAAK,CAAC,SAAS,MAAM,4BAA4B,GAAG,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF;AAvBD,gDAuBC;AAED;;;;;;GAMG;AACH,MAAa,SAAS;IAGpB;;;;;;;;;;;;;;;OAeG;IACH,YAAY,QAA6C;QAlBhD,iCAAgC;QAmBvC,uBAAA,IAAI,kBAAQ,IAAI,uCAAkB,CAAC,QAAQ,CAAC,MAAA,CAAC;IAC/C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,QAAQ;QACN,OAAO,uBAAA,IAAI,sBAAK,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,UAAU,CACf,GAA0B;QAE1B,OAAO,IAAI,SAAS,CAAC,M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uBAAA,IAAI,sBAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC;IAED,4CAA4C;IAC5C;;;;;;;;;;;;;;;;;OAiBG;IACH,2CAA2C;IAC3C,GAAG,CAAC,GAAW,EAAE,KAAY;QAC3B,uEAAuE;QACvE,sEAAsE;QACtE,sCAAsC;QACtC,IAAI,uBAAA,IAAI,sBAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,kBAAkB,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAClD,CAAC;QACD,uBAAA,IAAI,sBAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM;QACJ,OAAO,uBAAA,IAAI,sBAAK,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,sBAAK,CAAC,IAAI,CAAC;IACxB,CAAC;CACF;AAhQD,8BAgQC","sourcesContent":["import type { SnapId } from '@metamask/snaps-sdk';\n\nimport { CaseInsensitiveMap } from './CaseInsensitiveMap';\n\n/**\n * Error thrown when an invalid Snap ID is encountered.\n */\nexport class InvalidSnapIdError extends Error {\n /**\n * The ID of the Snap that caused the error.\n */\n snapId: SnapId;\n\n /**\n * The key of the element that caused the error.\n */\n key: string;\n\n /**\n * Creates an instance of `InvalidSnapIdError`.\n *\n * @param snapId - The invalid Snap ID.\n * @param key - The key associated with the invalid Snap ID.\n */\n constructor(snapId: SnapId, key: string) {\n super(`Snap \"${snapId}\" is not allowed to set \"${key}\"`);\n this.name = 'InvalidSnapIdError';\n this.snapId = snapId;\n this.key = key;\n }\n}\n\n/**\n * A map that associates a string key with a value that has a `snapId`\n * property. Note that the key is case-insensitive.\n *\n * The `snapId` property is used to ensure that only the Snap that added an\n * item to the map can modify or delete it.\n */\nexport class SnapIdMap<Value extends { snapId: SnapId }> {\n readonly #map: CaseInsensitiveMap<Value>;\n\n /**\n * Creates a new `SnapIdMap` object.\n *\n * Example:\n *\n * ```ts\n * const items = [\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ];\n * const map = new SnapIdMap(items);\n * ```\n *\n * @param iterable - An iterable object whose elements are key-value pairs.\n * Each key-value pair will be added to the new map.\n */\n constructor(iterable?: Iterable<readonly [string, Value]>) {\n this.#map = new CaseInsensitiveMap(iterable);\n }\n\n /**\n * Returns a plain object with the same key-value pairs as this map.\n *\n * Example:\n *\n * ```ts\n * const items = [\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ];\n * const map = new SnapIdMap(items);\n * map.toObject();\n * // Returns\n * // {\n * // foo: { snapId: '1', name: 'foo' },\n * // bar: { snapId: '1', name: 'bar' },\n * // }\n * ```\n *\n * @returns A plain object with the same key-value pairs as this map.\n */\n toObject(): Record<string, Value> {\n return this.#map.toObject();\n }\n\n /**\n * Returns a new `SnapIdMap` object from an plain object.\n *\n * Example:\n *\n * ```ts\n * const obj = {\n * foo: { snapId: '1', name: 'foo' },\n * bar: { snapId: '1', name: 'bar' },\n * };\n * const map = SnapIdMap.fromObject(obj);\n * ```\n *\n * @param obj - A plain object whose elements will be added to the new map.\n * @returns A new `SnapIdMap` containing the elements of the given object.\n */\n static fromObject<Value extends { snapId: SnapId }>(\n obj: Record<string, Value>,\n ): SnapIdMap<Value> {\n return new SnapIdMap(Object.entries(obj));\n }\n\n /**\n * Gets a value from the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `undefined`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.get('1', 'foo'); // Returns { snapId: '1', name: 'foo' }\n * map.get('2', 'foo'); // Returns `undefined`\n * map.get('1', 'bar'); // Returns `undefined`\n * ```\n *\n * @param snapId - Snap ID present in the value to get.\n * @param key - Key of the element to get.\n * @returns The value associated with the given key and Snap ID.\n */\n get(snapId: SnapId, key: string): Value | undefined {\n const value = this.#map.get(key);\n return value?.snapId === snapId ? value : undefined;\n }\n\n /**\n * Gets a Snap ID that's associated with the given key from the map.\n *\n * @param key - Key of the element to get.\n * @returns The Snap ID associated with the given key.\n */\n getSnapId(key: string): SnapId | undefined {\n return this.#map.get(key)?.snapId;\n }\n\n /**\n * Gets and delete a value from the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `undefined`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.pop('1', 'foo'); // Returns { snapId: '1', name: 'foo' }\n * map.pop('1', 'foo'); // Returns `undefined` (already returned and deleted)\n * map.pop('1', 'bar'); // Returns `undefined`\n * ```\n *\n * @param snapId - Snap ID present in the value to get.\n * @param key - Key of the element to get.\n * @returns The value associated with the given key and Snap ID.\n */\n pop(snapId: SnapId, key: string): Value | undefined {\n const value = this.get(snapId, key);\n this.delete(snapId, key);\n return value;\n }\n\n /**\n * Checks if a key is present in the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `false`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.has('1', 'foo'); // Returns `true`\n * map.has('2', 'foo'); // Returns `false`\n * map.has('1', 'bar'); // Returns `false`\n * ```\n *\n * @param snapId - Snap ID present in the value to check.\n * @param key - Key of the element to check.\n * @returns `true` if the key is present in the map and the Snap ID of the\n * value is equal to the given Snap ID, `false` otherwise.\n */\n has(snapId: SnapId, key: string): boolean {\n return this.get(snapId, key) !== undefined;\n }\n\n /**\n * Checks if a snap ID exists in the map.\n *\n * @param snapId - Snap ID present in the value to check.\n * @returns `true` if the snap ID is present in the map, `false` otherwise.\n */\n hasSnapId(snapId: SnapId): boolean {\n // We could use a reverse-mapping to map Snap ID to their actual key too, but\n // for now, this will do the trick.\n return [...this.#map.values()].some((value) => value.snapId === snapId);\n }\n\n /**\n * Deletes a key from the map.\n *\n * If the given key is not present in the map or the Snap IDs don't match,\n * returns `false` and does nothing.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.delete('2', 'foo'); // Returns `false`\n * map.delete('1', 'bar'); // Returns `false`\n * map.delete('1', 'foo'); // Returns `true`\n * ```\n *\n * @param snapId - Snap ID present in the value to delete.\n * @param key - Key of the element to delete.\n * @returns `true` if the key was present in the map and the Snap ID of the\n * value was equal to the given Snap ID, `false` otherwise.\n */\n delete(snapId: SnapId, key: string): boolean {\n return this.has(snapId, key) && this.#map.delete(key);\n }\n\n /* eslint-disable jsdoc/check-indentation */\n /**\n * Adds or updates a key-value pair in the map.\n *\n * Note that this method has a different behavior from the `Map.set`.\n *\n * - If the given key is not already present in the map, this method adds the\n * key-value pair to the map.\n *\n * - If the given key is already present in the map and the Snap IDs match,\n * this method updates the value associated with the key.\n *\n * - However, if the given key is already present in the map but the Snap IDs\n * do not match, this method throws an error.\n *\n * @param key - Key of the element to add or update.\n * @param value - Value of the element to add or update.\n * @returns The map itself.\n */\n /* eslint-enable jsdoc/check-indentation */\n set(key: string, value: Value): this {\n // If the key is present in the map but isn't associated with the given\n // Snap ID, it means that the item was added to the map by a different\n // Snap. In this case, throw an error.\n if (this.#map.has(key) && !this.has(value.snapId, key)) {\n throw new InvalidSnapIdError(value.snapId, key);\n }\n this.#map.set(key, value);\n return this;\n }\n\n /**\n * Returns an iterable of the values in the map.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap([\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ]);\n * const values = [...map.values()];\n * // Returns\n * // [\n * // { snapId: '1', name: 'foo' },\n * // { snapId: '1', name: 'bar' },\n * // ]\n * ```\n *\n * @returns An iterable of the values in the map.\n */\n values(): IterableIterator<Value> {\n return this.#map.values();\n }\n\n /**\n * Returns the number of key-value pairs in the map.\n *\n * @returns The number of key-value pairs in the map.\n */\n get size(): number {\n return this.#map.size;\n }\n}\n"]}
1
+ {"version":3,"file":"SnapIdMap.cjs","sourceRoot":"","sources":["../src/SnapIdMap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,iEAA0D;AAE1D;;GAEG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAW3C;;;;;OAKG;IACH,YAAY,MAAc,EAAE,GAAW;QACrC,KAAK,CAAC,SAAS,MAAM,4BAA4B,GAAG,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF;AAvBD,gDAuBC;AAED;;;;;;GAMG;AACH,MAAa,SAAS;IAGpB;;;;;;;;;;;;;;;OAeG;IACH,YAAY,QAA6C;QAlBhD,iCAAgC;QAmBvC,uBAAA,IAAI,kBAAQ,IAAI,uCAAkB,CAAC,QAAQ,CAAC,MAAA,CAAC;IAC/C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,QAAQ;QACN,OAAO,uBAAA,IAAI,sBAAK,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,UAAU,CACf,GAA0B;QAE1B,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,GAAG,CAAC,MAAc,EAAE,GAAW;QAC7B,MAAM,KAAK,GAAG,uBAAA,I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E;QACtE,sCAAsC;QACtC,IAAI,uBAAA,IAAI,sBAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,kBAAkB,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAClD,CAAC;QACD,uBAAA,IAAI,sBAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM;QACJ,OAAO,uBAAA,IAAI,sBAAK,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,sBAAK,CAAC,IAAI,CAAC;IACxB,CAAC;CACF;AA9PD,8BA8PC","sourcesContent":["import type { SnapId } from '@metamask/snaps-sdk';\n\nimport { CaseInsensitiveMap } from './CaseInsensitiveMap';\n\n/**\n * Error thrown when an invalid Snap ID is encountered.\n */\nexport class InvalidSnapIdError extends Error {\n /**\n * The ID of the Snap that caused the error.\n */\n snapId: SnapId;\n\n /**\n * The key of the element that caused the error.\n */\n key: string;\n\n /**\n * Creates an instance of `InvalidSnapIdError`.\n *\n * @param snapId - The invalid Snap ID.\n * @param key - The key associated with the invalid Snap ID.\n */\n constructor(snapId: SnapId, key: string) {\n super(`Snap \"${snapId}\" is not allowed to set \"${key}\"`);\n this.name = 'InvalidSnapIdError';\n this.snapId = snapId;\n this.key = key;\n }\n}\n\n/**\n * A map that associates a string key with a value that has a `snapId`\n * property. Note that the key is case-insensitive.\n *\n * The `snapId` property is used to ensure that only the Snap that added an\n * item to the map can modify or delete it.\n */\nexport class SnapIdMap<Value extends { snapId: SnapId }> {\n readonly #map: CaseInsensitiveMap<Value>;\n\n /**\n * Creates a new `SnapIdMap` object.\n *\n * Example:\n *\n * ```ts\n * const items = [\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ];\n * const map = new SnapIdMap(items);\n * ```\n *\n * @param iterable - An iterable object whose elements are key-value pairs.\n * Each key-value pair will be added to the new map.\n */\n constructor(iterable?: Iterable<readonly [string, Value]>) {\n this.#map = new CaseInsensitiveMap(iterable);\n }\n\n /**\n * Returns a plain object with the same key-value pairs as this map.\n *\n * Example:\n *\n * ```ts\n * const items = [\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ];\n * const map = new SnapIdMap(items);\n * map.toObject();\n * // Returns\n * // {\n * // foo: { snapId: '1', name: 'foo' },\n * // bar: { snapId: '1', name: 'bar' },\n * // }\n * ```\n *\n * @returns A plain object with the same key-value pairs as this map.\n */\n toObject(): Record<string, Value> {\n return this.#map.toObject();\n }\n\n /**\n * Returns a new `SnapIdMap` object from an plain object.\n *\n * Example:\n *\n * ```ts\n * const obj = {\n * foo: { snapId: '1', name: 'foo' },\n * bar: { snapId: '1', name: 'bar' },\n * };\n * const map = SnapIdMap.fromObject(obj);\n * ```\n *\n * @param obj - A plain object whose elements will be added to the new map.\n * @returns A new `SnapIdMap` containing the elements of the given object.\n */\n static fromObject<Value extends { snapId: SnapId }>(\n obj: Record<string, Value>,\n ): SnapIdMap<Value> {\n return new SnapIdMap(Object.entries(obj));\n }\n\n /**\n * Gets a value from the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `undefined`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.get('1', 'foo'); // Returns { snapId: '1', name: 'foo' }\n * map.get('2', 'foo'); // Returns `undefined`\n * map.get('1', 'bar'); // Returns `undefined`\n * ```\n *\n * @param snapId - Snap ID present in the value to get.\n * @param key - Key of the element to get.\n * @returns The value associated with the given key and Snap ID.\n */\n get(snapId: SnapId, key: string): Value | undefined {\n const value = this.#map.get(key);\n return value?.snapId === snapId ? value : undefined;\n }\n\n /**\n * Gets a Snap ID that's associated with the given key from the map.\n *\n * @param key - Key of the element to get.\n * @returns The Snap ID associated with the given key.\n */\n getSnapId(key: string): SnapId | undefined {\n return this.#map.get(key)?.snapId;\n }\n\n /**\n * Gets and delete a value from the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `undefined`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.pop('1', 'foo'); // Returns { snapId: '1', name: 'foo' }\n * map.pop('1', 'foo'); // Returns `undefined` (already returned and deleted)\n * map.pop('1', 'bar'); // Returns `undefined`\n * ```\n *\n * @param snapId - Snap ID present in the value to get.\n * @param key - Key of the element to get.\n * @returns The value associated with the given key and Snap ID.\n */\n pop(snapId: SnapId, key: string): Value | undefined {\n const value = this.get(snapId, key);\n this.delete(snapId, key);\n return value;\n }\n\n /**\n * Checks if a key is present in the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `false`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.has('1', 'foo'); // Returns `true`\n * map.has('2', 'foo'); // Returns `false`\n * map.has('1', 'bar'); // Returns `false`\n * ```\n *\n * @param snapId - Snap ID present in the value to check.\n * @param key - Key of the element to check.\n * @returns `true` if the key is present in the map and the Snap ID of the\n * value is equal to the given Snap ID, `false` otherwise.\n */\n has(snapId: SnapId, key: string): boolean {\n return this.get(snapId, key) !== undefined;\n }\n\n /**\n * Checks if a snap ID exists in the map.\n *\n * @param snapId - Snap ID present in the value to check.\n * @returns `true` if the snap ID is present in the map, `false` otherwise.\n */\n hasSnapId(snapId: SnapId): boolean {\n // We could use a reverse-mapping to map Snap ID to their actual key too, but\n // for now, this will do the trick.\n return [...this.#map.values()].some((value) => value.snapId === snapId);\n }\n\n /**\n * Deletes a key from the map.\n *\n * If the given key is not present in the map or the Snap IDs don't match,\n * returns `false` and does nothing.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.delete('2', 'foo'); // Returns `false`\n * map.delete('1', 'bar'); // Returns `false`\n * map.delete('1', 'foo'); // Returns `true`\n * ```\n *\n * @param snapId - Snap ID present in the value to delete.\n * @param key - Key of the element to delete.\n * @returns `true` if the key was present in the map and the Snap ID of the\n * value was equal to the given Snap ID, `false` otherwise.\n */\n delete(snapId: SnapId, key: string): boolean {\n return this.has(snapId, key) && this.#map.delete(key);\n }\n\n /**\n * Adds or updates a key-value pair in the map.\n *\n * Note that this method has a different behavior from the `Map.set`.\n *\n * - If the given key is not already present in the map, this method adds the\n * key-value pair to the map.\n *\n * - If the given key is already present in the map and the Snap IDs match,\n * this method updates the value associated with the key.\n *\n * - However, if the given key is already present in the map but the Snap IDs\n * do not match, this method throws an error.\n *\n * @param key - Key of the element to add or update.\n * @param value - Value of the element to add or update.\n * @returns The map itself.\n */\n set(key: string, value: Value): this {\n // If the key is present in the map but isn't associated with the given\n // Snap ID, it means that the item was added to the map by a different\n // Snap. In this case, throw an error.\n if (this.#map.has(key) && !this.has(value.snapId, key)) {\n throw new InvalidSnapIdError(value.snapId, key);\n }\n this.#map.set(key, value);\n return this;\n }\n\n /**\n * Returns an iterable of the values in the map.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap([\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ]);\n * const values = [...map.values()];\n * // Returns\n * // [\n * // { snapId: '1', name: 'foo' },\n * // { snapId: '1', name: 'bar' },\n * // ]\n * ```\n *\n * @returns An iterable of the values in the map.\n */\n values(): IterableIterator<Value> {\n return this.#map.values();\n }\n\n /**\n * Returns the number of key-value pairs in the map.\n *\n * @returns The number of key-value pairs in the map.\n */\n get size(): number {\n return this.#map.size;\n }\n}\n"]}
@@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AAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzC;;;;;OAKG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAMlC;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAI5C;;;;;;;;;;;;;;;;;OAiBG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAWpC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,IAAI,gBAAgB,CAAC,KAAK,CAAC;IAIjC;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
@@ -216,7 +216,6 @@ export class SnapIdMap {
216
216
  delete(snapId, key) {
217
217
  return this.has(snapId, key) && __classPrivateFieldGet(this, _SnapIdMap_map, "f").delete(key);
218
218
  }
219
- /* eslint-disable jsdoc/check-indentation */
220
219
  /**
221
220
  * Adds or updates a key-value pair in the map.
222
221
  *
@@ -235,7 +234,6 @@ export class SnapIdMap {
235
234
  * @param value - Value of the element to add or update.
236
235
  * @returns The map itself.
237
236
  */
238
- /* eslint-enable jsdoc/check-indentation */
239
237
  set(key, value) {
240
238
  // If the key is present in the map but isn't associated with the given
241
239
  // Snap ID, it means that the item was added to the map by a different
@@ -1 +1 @@
1
- {"version":3,"file":"SnapIdMap.mjs","sourceRoot":"","sources":["../src/SnapIdMap.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAE1D;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAW3C;;;;;OAKG;IACH,YAAY,MAAc,EAAE,GAAW;QACrC,KAAK,CAAC,SAAS,MAAM,4BAA4B,GAAG,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,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AAI,CAAC;IACxB,CAAC;CACF","sourcesContent":["import type { SnapId } from '@metamask/snaps-sdk';\n\nimport { CaseInsensitiveMap } from './CaseInsensitiveMap';\n\n/**\n * Error thrown when an invalid Snap ID is encountered.\n */\nexport class InvalidSnapIdError extends Error {\n /**\n * The ID of the Snap that caused the error.\n */\n snapId: SnapId;\n\n /**\n * The key of the element that caused the error.\n */\n key: string;\n\n /**\n * Creates an instance of `InvalidSnapIdError`.\n *\n * @param snapId - The invalid Snap ID.\n * @param key - The key associated with the invalid Snap ID.\n */\n constructor(snapId: SnapId, key: string) {\n super(`Snap \"${snapId}\" is not allowed to set \"${key}\"`);\n this.name = 'InvalidSnapIdError';\n this.snapId = snapId;\n this.key = key;\n }\n}\n\n/**\n * A map that associates a string key with a value that has a `snapId`\n * property. Note that the key is case-insensitive.\n *\n * The `snapId` property is used to ensure that only the Snap that added an\n * item to the map can modify or delete it.\n */\nexport class SnapIdMap<Value extends { snapId: SnapId }> {\n readonly #map: CaseInsensitiveMap<Value>;\n\n /**\n * Creates a new `SnapIdMap` object.\n *\n * Example:\n *\n * ```ts\n * const items = [\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ];\n * const map = new SnapIdMap(items);\n * ```\n *\n * @param iterable - An iterable object whose elements are key-value pairs.\n * Each key-value pair will be added to the new map.\n */\n constructor(iterable?: Iterable<readonly [string, Value]>) {\n this.#map = new CaseInsensitiveMap(iterable);\n }\n\n /**\n * Returns a plain object with the same key-value pairs as this map.\n *\n * Example:\n *\n * ```ts\n * const items = [\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ];\n * const map = new SnapIdMap(items);\n * map.toObject();\n * // Returns\n * // {\n * // foo: { snapId: '1', name: 'foo' },\n * // bar: { snapId: '1', name: 'bar' },\n * // }\n * ```\n *\n * @returns A plain object with the same key-value pairs as this map.\n */\n toObject(): Record<string, Value> {\n return this.#map.toObject();\n }\n\n /**\n * Returns a new `SnapIdMap` object from an plain object.\n *\n * Example:\n *\n * ```ts\n * const obj = {\n * foo: { snapId: '1', name: 'foo' },\n * bar: { snapId: '1', name: 'bar' },\n * };\n * const map = SnapIdMap.fromObject(obj);\n * ```\n *\n * @param obj - A plain object whose elements will be added to the new map.\n * @returns A new `SnapIdMap` containing the elements of the given object.\n */\n static fromObject<Value extends { snapId: SnapId }>(\n obj: Record<string, Value>,\n ): SnapIdMap<Value> {\n return new SnapIdMap(Object.entries(obj));\n }\n\n /**\n * Gets a value from the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `undefined`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.get('1', 'foo'); // Returns { snapId: '1', name: 'foo' }\n * map.get('2', 'foo'); // Returns `undefined`\n * map.get('1', 'bar'); // Returns `undefined`\n * ```\n *\n * @param snapId - Snap ID present in the value to get.\n * @param key - Key of the element to get.\n * @returns The value associated with the given key and Snap ID.\n */\n get(snapId: SnapId, key: string): Value | undefined {\n const value = this.#map.get(key);\n return value?.snapId === snapId ? value : undefined;\n }\n\n /**\n * Gets a Snap ID that's associated with the given key from the map.\n *\n * @param key - Key of the element to get.\n * @returns The Snap ID associated with the given key.\n */\n getSnapId(key: string): SnapId | undefined {\n return this.#map.get(key)?.snapId;\n }\n\n /**\n * Gets and delete a value from the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `undefined`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.pop('1', 'foo'); // Returns { snapId: '1', name: 'foo' }\n * map.pop('1', 'foo'); // Returns `undefined` (already returned and deleted)\n * map.pop('1', 'bar'); // Returns `undefined`\n * ```\n *\n * @param snapId - Snap ID present in the value to get.\n * @param key - Key of the element to get.\n * @returns The value associated with the given key and Snap ID.\n */\n pop(snapId: SnapId, key: string): Value | undefined {\n const value = this.get(snapId, key);\n this.delete(snapId, key);\n return value;\n }\n\n /**\n * Checks if a key is present in the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `false`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.has('1', 'foo'); // Returns `true`\n * map.has('2', 'foo'); // Returns `false`\n * map.has('1', 'bar'); // Returns `false`\n * ```\n *\n * @param snapId - Snap ID present in the value to check.\n * @param key - Key of the element to check.\n * @returns `true` if the key is present in the map and the Snap ID of the\n * value is equal to the given Snap ID, `false` otherwise.\n */\n has(snapId: SnapId, key: string): boolean {\n return this.get(snapId, key) !== undefined;\n }\n\n /**\n * Checks if a snap ID exists in the map.\n *\n * @param snapId - Snap ID present in the value to check.\n * @returns `true` if the snap ID is present in the map, `false` otherwise.\n */\n hasSnapId(snapId: SnapId): boolean {\n // We could use a reverse-mapping to map Snap ID to their actual key too, but\n // for now, this will do the trick.\n return [...this.#map.values()].some((value) => value.snapId === snapId);\n }\n\n /**\n * Deletes a key from the map.\n *\n * If the given key is not present in the map or the Snap IDs don't match,\n * returns `false` and does nothing.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.delete('2', 'foo'); // Returns `false`\n * map.delete('1', 'bar'); // Returns `false`\n * map.delete('1', 'foo'); // Returns `true`\n * ```\n *\n * @param snapId - Snap ID present in the value to delete.\n * @param key - Key of the element to delete.\n * @returns `true` if the key was present in the map and the Snap ID of the\n * value was equal to the given Snap ID, `false` otherwise.\n */\n delete(snapId: SnapId, key: string): boolean {\n return this.has(snapId, key) && this.#map.delete(key);\n }\n\n /* eslint-disable jsdoc/check-indentation */\n /**\n * Adds or updates a key-value pair in the map.\n *\n * Note that this method has a different behavior from the `Map.set`.\n *\n * - If the given key is not already present in the map, this method adds the\n * key-value pair to the map.\n *\n * - If the given key is already present in the map and the Snap IDs match,\n * this method updates the value associated with the key.\n *\n * - However, if the given key is already present in the map but the Snap IDs\n * do not match, this method throws an error.\n *\n * @param key - Key of the element to add or update.\n * @param value - Value of the element to add or update.\n * @returns The map itself.\n */\n /* eslint-enable jsdoc/check-indentation */\n set(key: string, value: Value): this {\n // If the key is present in the map but isn't associated with the given\n // Snap ID, it means that the item was added to the map by a different\n // Snap. In this case, throw an error.\n if (this.#map.has(key) && !this.has(value.snapId, key)) {\n throw new InvalidSnapIdError(value.snapId, key);\n }\n this.#map.set(key, value);\n return this;\n }\n\n /**\n * Returns an iterable of the values in the map.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap([\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ]);\n * const values = [...map.values()];\n * // Returns\n * // [\n * // { snapId: '1', name: 'foo' },\n * // { snapId: '1', name: 'bar' },\n * // ]\n * ```\n *\n * @returns An iterable of the values in the map.\n */\n values(): IterableIterator<Value> {\n return this.#map.values();\n }\n\n /**\n * Returns the number of key-value pairs in the map.\n *\n * @returns The number of key-value pairs in the map.\n */\n get size(): number {\n return this.#map.size;\n }\n}\n"]}
1
+ {"version":3,"file":"SnapIdMap.mjs","sourceRoot":"","sources":["../src/SnapIdMap.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAE1D;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAW3C;;;;;OAKG;IACH,YAAY,MAAc,EAAE,GAAW;QACrC,KAAK,CAAC,SAAS,MAAM,4BAA4B,GAAG,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,SAAS;IAGpB;;;;;;;;;;;;;;;OAeG;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tB,6EAA6E;QAC7E,mCAAmC;QACnC,OAAO,CAAC,GAAG,uBAAA,IAAI,sBAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;IAC1E,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,MAAc,EAAE,GAAW;QAChC,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,uBAAA,IAAI,sBAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,GAAG,CAAC,GAAW,EAAE,KAAY;QAC3B,uEAAuE;QACvE,sEAAsE;QACtE,sCAAsC;QACtC,IAAI,uBAAA,IAAI,sBAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,kBAAkB,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAClD,CAAC;QACD,uBAAA,IAAI,sBAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM;QACJ,OAAO,uBAAA,IAAI,sBAAK,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,sBAAK,CAAC,IAAI,CAAC;IACxB,CAAC;CACF","sourcesContent":["import type { SnapId } from '@metamask/snaps-sdk';\n\nimport { CaseInsensitiveMap } from './CaseInsensitiveMap';\n\n/**\n * Error thrown when an invalid Snap ID is encountered.\n */\nexport class InvalidSnapIdError extends Error {\n /**\n * The ID of the Snap that caused the error.\n */\n snapId: SnapId;\n\n /**\n * The key of the element that caused the error.\n */\n key: string;\n\n /**\n * Creates an instance of `InvalidSnapIdError`.\n *\n * @param snapId - The invalid Snap ID.\n * @param key - The key associated with the invalid Snap ID.\n */\n constructor(snapId: SnapId, key: string) {\n super(`Snap \"${snapId}\" is not allowed to set \"${key}\"`);\n this.name = 'InvalidSnapIdError';\n this.snapId = snapId;\n this.key = key;\n }\n}\n\n/**\n * A map that associates a string key with a value that has a `snapId`\n * property. Note that the key is case-insensitive.\n *\n * The `snapId` property is used to ensure that only the Snap that added an\n * item to the map can modify or delete it.\n */\nexport class SnapIdMap<Value extends { snapId: SnapId }> {\n readonly #map: CaseInsensitiveMap<Value>;\n\n /**\n * Creates a new `SnapIdMap` object.\n *\n * Example:\n *\n * ```ts\n * const items = [\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ];\n * const map = new SnapIdMap(items);\n * ```\n *\n * @param iterable - An iterable object whose elements are key-value pairs.\n * Each key-value pair will be added to the new map.\n */\n constructor(iterable?: Iterable<readonly [string, Value]>) {\n this.#map = new CaseInsensitiveMap(iterable);\n }\n\n /**\n * Returns a plain object with the same key-value pairs as this map.\n *\n * Example:\n *\n * ```ts\n * const items = [\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ];\n * const map = new SnapIdMap(items);\n * map.toObject();\n * // Returns\n * // {\n * // foo: { snapId: '1', name: 'foo' },\n * // bar: { snapId: '1', name: 'bar' },\n * // }\n * ```\n *\n * @returns A plain object with the same key-value pairs as this map.\n */\n toObject(): Record<string, Value> {\n return this.#map.toObject();\n }\n\n /**\n * Returns a new `SnapIdMap` object from an plain object.\n *\n * Example:\n *\n * ```ts\n * const obj = {\n * foo: { snapId: '1', name: 'foo' },\n * bar: { snapId: '1', name: 'bar' },\n * };\n * const map = SnapIdMap.fromObject(obj);\n * ```\n *\n * @param obj - A plain object whose elements will be added to the new map.\n * @returns A new `SnapIdMap` containing the elements of the given object.\n */\n static fromObject<Value extends { snapId: SnapId }>(\n obj: Record<string, Value>,\n ): SnapIdMap<Value> {\n return new SnapIdMap(Object.entries(obj));\n }\n\n /**\n * Gets a value from the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `undefined`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.get('1', 'foo'); // Returns { snapId: '1', name: 'foo' }\n * map.get('2', 'foo'); // Returns `undefined`\n * map.get('1', 'bar'); // Returns `undefined`\n * ```\n *\n * @param snapId - Snap ID present in the value to get.\n * @param key - Key of the element to get.\n * @returns The value associated with the given key and Snap ID.\n */\n get(snapId: SnapId, key: string): Value | undefined {\n const value = this.#map.get(key);\n return value?.snapId === snapId ? value : undefined;\n }\n\n /**\n * Gets a Snap ID that's associated with the given key from the map.\n *\n * @param key - Key of the element to get.\n * @returns The Snap ID associated with the given key.\n */\n getSnapId(key: string): SnapId | undefined {\n return this.#map.get(key)?.snapId;\n }\n\n /**\n * Gets and delete a value from the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `undefined`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.pop('1', 'foo'); // Returns { snapId: '1', name: 'foo' }\n * map.pop('1', 'foo'); // Returns `undefined` (already returned and deleted)\n * map.pop('1', 'bar'); // Returns `undefined`\n * ```\n *\n * @param snapId - Snap ID present in the value to get.\n * @param key - Key of the element to get.\n * @returns The value associated with the given key and Snap ID.\n */\n pop(snapId: SnapId, key: string): Value | undefined {\n const value = this.get(snapId, key);\n this.delete(snapId, key);\n return value;\n }\n\n /**\n * Checks if a key is present in the map.\n *\n * If the given key is not present in the map or the Snap ID of the value is\n * different from the given Snap ID, returns `false`.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.has('1', 'foo'); // Returns `true`\n * map.has('2', 'foo'); // Returns `false`\n * map.has('1', 'bar'); // Returns `false`\n * ```\n *\n * @param snapId - Snap ID present in the value to check.\n * @param key - Key of the element to check.\n * @returns `true` if the key is present in the map and the Snap ID of the\n * value is equal to the given Snap ID, `false` otherwise.\n */\n has(snapId: SnapId, key: string): boolean {\n return this.get(snapId, key) !== undefined;\n }\n\n /**\n * Checks if a snap ID exists in the map.\n *\n * @param snapId - Snap ID present in the value to check.\n * @returns `true` if the snap ID is present in the map, `false` otherwise.\n */\n hasSnapId(snapId: SnapId): boolean {\n // We could use a reverse-mapping to map Snap ID to their actual key too, but\n // for now, this will do the trick.\n return [...this.#map.values()].some((value) => value.snapId === snapId);\n }\n\n /**\n * Deletes a key from the map.\n *\n * If the given key is not present in the map or the Snap IDs don't match,\n * returns `false` and does nothing.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap();\n * map.set('foo', { snapId: '1', name: 'foo' });\n * map.delete('2', 'foo'); // Returns `false`\n * map.delete('1', 'bar'); // Returns `false`\n * map.delete('1', 'foo'); // Returns `true`\n * ```\n *\n * @param snapId - Snap ID present in the value to delete.\n * @param key - Key of the element to delete.\n * @returns `true` if the key was present in the map and the Snap ID of the\n * value was equal to the given Snap ID, `false` otherwise.\n */\n delete(snapId: SnapId, key: string): boolean {\n return this.has(snapId, key) && this.#map.delete(key);\n }\n\n /**\n * Adds or updates a key-value pair in the map.\n *\n * Note that this method has a different behavior from the `Map.set`.\n *\n * - If the given key is not already present in the map, this method adds the\n * key-value pair to the map.\n *\n * - If the given key is already present in the map and the Snap IDs match,\n * this method updates the value associated with the key.\n *\n * - However, if the given key is already present in the map but the Snap IDs\n * do not match, this method throws an error.\n *\n * @param key - Key of the element to add or update.\n * @param value - Value of the element to add or update.\n * @returns The map itself.\n */\n set(key: string, value: Value): this {\n // If the key is present in the map but isn't associated with the given\n // Snap ID, it means that the item was added to the map by a different\n // Snap. In this case, throw an error.\n if (this.#map.has(key) && !this.has(value.snapId, key)) {\n throw new InvalidSnapIdError(value.snapId, key);\n }\n this.#map.set(key, value);\n return this;\n }\n\n /**\n * Returns an iterable of the values in the map.\n *\n * Example:\n *\n * ```ts\n * const map = new SnapIdMap([\n * ['foo', { snapId: '1', name: 'foo' }],\n * ['bar', { snapId: '1', name: 'bar' }],\n * ]);\n * const values = [...map.values()];\n * // Returns\n * // [\n * // { snapId: '1', name: 'foo' },\n * // { snapId: '1', name: 'bar' },\n * // ]\n * ```\n *\n * @returns An iterable of the values in the map.\n */\n values(): IterableIterator<Value> {\n return this.#map.values();\n }\n\n /**\n * Returns the number of key-value pairs in the map.\n *\n * @returns The number of key-value pairs in the map.\n */\n get size(): number {\n return this.#map.size;\n }\n}\n"]}
@@ -412,7 +412,6 @@ class SnapKeyring {
412
412
  bySnap.set(snapId, snapAccounts);
413
413
  }
414
414
  await Promise.all([...__classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").entries()].map(async ([snapId, keyring]) => keyring.setSelectedAccounts(
415
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
416
415
  /* istanbul ignore next */
417
416
  bySnap.get(snapId) ?? [])));
418
417
  }
@@ -486,7 +485,7 @@ _SnapKeyring_messenger = new WeakMap(), _SnapKeyring_snapKeyrings = new WeakMap(
486
485
  */
487
486
  async function _SnapKeyring_removeSnapKeyringIfEmpty(snapId) {
488
487
  const keyring = __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").get(snapId);
489
- if (keyring !== undefined && keyring.accounts().length === 0) {
488
+ if (keyring?.accounts().length === 0) {
490
489
  await keyring.destroy();
491
490
  __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").delete(snapId);
492
491
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.cjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yDAA8D;AAY9D,uDAAqE;AAMrE,6CAAoC;A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I,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;AArsBM,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 !== undefined && 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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\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;AAIpC,qEAA2D;AAG3D,qCAAqE;AACrE,sDAAgE;AAEnD,QAAA,iBAAiB,GAAG,cAAc,CAAC;AAwChD;;GAEG;AACH,MAAa,WAAW;IAuDtB;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,SAAS,EACT,uBAAuB,GAAG,KAAK,GAKhC;;QAnED,0DAA0D;QAC1D,SAAI,GAA6B,wCAAiB,CAAC;QAEnD,UAAK,GAAG,IAAI,CAAC;QAEb;;WAEG;QACM,yCAAiC;QAE1C;;;;WAIG;QACM,4C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O,EAAE,OAAO,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,IAAA,iBAAU,EAAC,YAAY,OAAO,aAAa,CAAC,CAAC;AACtD,CAAC,uDAsCQ,MAAc;IACrB,OAAO,uBAAA,IAAI,8BAAW,CAAC,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;AAChE,CAAC,uEASC,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,oDAAS,MAAb,IAAI,EAAU,MAAM,CAAC,CAAC;IACnC,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACzE,CAAC,CAAC,SAAS,CAAC;AAChB,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,8BAAuB,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;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"]}
@@ -6,7 +6,7 @@ import type { InternalAccount } from "@metamask/keyring-internal-api";
6
6
  import type { AccountId, JsonRpcRequest } from "@metamask/keyring-utils";
7
7
  import type { SnapId } from "@metamask/snaps-sdk";
8
8
  import type { Json } from "@metamask/utils";
9
- import { type SnapKeyringInternalOptions } from "./options.cjs";
9
+ import type { SnapKeyringInternalOptions } from "./options.cjs";
10
10
  import type { SnapKeyringMessenger } from "./SnapKeyringMessenger.cjs";
11
11
  import { SNAP_KEYRING_NAME } from "./SnapKeyringMessenger.cjs";
12
12
  import type { SnapMessage } from "./types.cjs";
@@ -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;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gCAAgC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;A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B,EACxB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC;IAKlB;;;;;;;;;;OAUG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,SAAS;IAI/D;;;;;;;OAOG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BnD;;;;;;OAMG;IACG,mBAAmB,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA6E/D;;;;;OAKG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAUjE;;;;;;OAMG;IACH,YAAY,IAAI,eAAe,EAAE;CASlC"}
@@ -6,7 +6,7 @@ import type { InternalAccount } from "@metamask/keyring-internal-api";
6
6
  import type { AccountId, JsonRpcRequest } from "@metamask/keyring-utils";
7
7
  import type { SnapId } from "@metamask/snaps-sdk";
8
8
  import type { Json } from "@metamask/utils";
9
- import { type SnapKeyringInternalOptions } from "./options.mjs";
9
+ import type { SnapKeyringInternalOptions } from "./options.mjs";
10
10
  import type { SnapKeyringMessenger } from "./SnapKeyringMessenger.mjs";
11
11
  import { SNAP_KEYRING_NAME } from "./SnapKeyringMessenger.mjs";
12
12
  import type { SnapMessage } from "./types.mjs";
@@ -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,8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EAAE,gBAAgB,EACxB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IAKjC;;;;;;;OAOG;IACG,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC;IAKlB;;;;;;;;;;OAUG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,SAAS;IAI/D;;;;;;;OAOG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BnD;;;;;;OAMG;IACG,mBAAmB,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA6E/D;;;;;OAKG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAUjE;;;;;;OAMG;IACH,YAAY,IAAI,eAAe,EAAE;CASlC"}
@@ -409,7 +409,6 @@ export class SnapKeyring {
409
409
  bySnap.set(snapId, snapAccounts);
410
410
  }
411
411
  await Promise.all([...__classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").entries()].map(async ([snapId, keyring]) => keyring.setSelectedAccounts(
412
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
413
412
  /* istanbul ignore next */
414
413
  bySnap.get(snapId) ?? [])));
415
414
  }
@@ -482,7 +481,7 @@ _SnapKeyring_messenger = new WeakMap(), _SnapKeyring_snapKeyrings = new WeakMap(
482
481
  */
483
482
  async function _SnapKeyring_removeSnapKeyringIfEmpty(snapId) {
484
483
  const keyring = __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").get(snapId);
485
- if (keyring !== undefined && keyring.accounts().length === 0) {
484
+ if (keyring?.accounts().length === 0) {
486
485
  await keyring.destroy();
487
486
  __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").delete(snapId);
488
487
  }