@metamask-previews/eth-snap-keyring 22.3.0-e51c895 → 22.4.0-5951828

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Changed
11
+
12
+ - **BREAKING:** `SnapKeyring` (v2) no longer inherits `SnapKeyringV1` ([#584](https://github.com/MetaMask/accounts/pull/584))
13
+ - Use `.v1` getter to access a v1 instance instead.
14
+ - `.v1` will yield `undefined` if the Snap declares v2 `capabilities` in its `endowment:keyring`.
15
+
16
+ ## [22.4.0]
17
+
18
+ ### Added
19
+
20
+ - Populate v2 `SnapKeyring` `capabilities` from the Snap manifest (`endowment:keyring`) on `deserialize` ([#581](https://github.com/MetaMask/accounts/pull/581))
21
+ - Guard v2 `SnapKeyring` operations until `deserialize` has run (throws "SnapKeyring has not been initialized") ([#581](https://github.com/MetaMask/accounts/pull/581))
22
+
23
+ ### Changed
24
+
25
+ - Bump `@metamask/snaps-utils` from `^12.1.3` to `^12.2.1` ([#581](https://github.com/MetaMask/accounts/pull/581))
26
+ - Bump `@metamask/keyring-internal-snap-client` from `^10.0.3` to `^10.0.4` ([#583](https://github.com/MetaMask/accounts/pull/583))
27
+ - Bump `@metamask/keyring-snap-sdk` from `^9.0.2` to `^9.1.0` ([#583](https://github.com/MetaMask/accounts/pull/583))
28
+
10
29
  ## [22.3.0]
11
30
 
12
31
  ### Added
@@ -745,7 +764,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
745
764
 
746
765
  - Initial release.
747
766
 
748
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@22.3.0...HEAD
767
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@22.4.0...HEAD
768
+ [22.4.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@22.3.0...@metamask/eth-snap-keyring@22.4.0
749
769
  [22.3.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@22.2.0...@metamask/eth-snap-keyring@22.3.0
750
770
  [22.2.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@22.1.0...@metamask/eth-snap-keyring@22.2.0
751
771
  [22.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@22.0.1...@metamask/eth-snap-keyring@22.1.0
@@ -20,6 +20,18 @@ const account_1 = require("./account.cjs");
20
20
  const SnapKeyringMessenger_1 = require("./SnapKeyringMessenger.cjs");
21
21
  const util_1 = require("./util.cjs");
22
22
  const SnapKeyring_1 = require("./v2/SnapKeyring.cjs");
23
+ /**
24
+ * Return the v1 instance of a per-snap keyring, throwing if the snap only
25
+ * supports the v2 protocol.
26
+ *
27
+ * @param keyring - The per-snap v2 keyring.
28
+ * @param feature - Human-readable feature name used in the error message.
29
+ * @returns The v1 instance.
30
+ */
31
+ function getKeyringV1For(keyring, feature) {
32
+ return (keyring.v1 ??
33
+ (0, util_1.throwError)(`Snap '${keyring.snapId}' does not support v1 ${feature}`));
34
+ }
23
35
  exports.SNAP_KEYRING_TYPE = 'Snap Keyring';
24
36
  /**
25
37
  * Keyring bridge implementation to support Snaps.
@@ -44,9 +56,10 @@ class SnapKeyring {
44
56
  */
45
57
  _SnapKeyring_messenger.set(this, void 0);
46
58
  /**
47
- * Per-snap keyring instances. Each `SnapKeyringV2` (which extends
48
- * `SnapKeyringV1`) owns a single `KeyringAccountRegistry` and handles
49
- * both the event-driven v1 flow and the `KeyringV2` batch interface.
59
+ * Per-snap keyring instances. Each `SnapKeyringV2` owns the
60
+ * `KeyringAccountRegistry` and handles the `KeyringV2` batch interface.
61
+ * For v1 snaps, `SnapKeyringV2.v1` holds a `SnapKeyringV1` instance
62
+ * (with a shared registry reference) for the event-driven flow.
50
63
  */
51
64
  _SnapKeyring_snapKeyrings.set(this, void 0);
52
65
  /**
@@ -120,7 +133,7 @@ class SnapKeyring {
120
133
  throw new Error(`SnapKeyring - Received a message for an unknown snap keyring '${snapId}'`);
121
134
  }
122
135
  try {
123
- return await keyring.handleKeyringSnapMessage(message);
136
+ return await getKeyringV1For(keyring, 'messages').handleKeyringSnapMessage(message);
124
137
  }
125
138
  finally {
126
139
  // Clean up if AccountCreated was rejected (e.g. duplicate address,
@@ -213,7 +226,7 @@ class SnapKeyring {
213
226
  /**
214
227
  * Create an account (v1 event-driven flow).
215
228
  *
216
- * Delegates to the per-snap SnapKeyringV1 instance.
229
+ * Delegates to the per-snap SnapKeyringV2 instance (v1 flow).
217
230
  *
218
231
  * @param snapId - Snap ID to create the account for.
219
232
  * @param options - Account creation options. Differs between keyrings.
@@ -222,7 +235,7 @@ class SnapKeyring {
222
235
  */
223
236
  async createAccount(snapId, options, internalOptions) {
224
237
  const keyring = await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
225
- return keyring.createAccount(options, internalOptions);
238
+ return getKeyringV1For(keyring, 'account creation').createAccount(options, internalOptions);
226
239
  }
227
240
  /**
228
241
  * Creates one or more new accounts according to the provided options.
@@ -263,7 +276,7 @@ class SnapKeyring {
263
276
  throw new Error(`Unable to resolve account address: unknown Snap ID: ${snapId}`);
264
277
  }
265
278
  const keyring = await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
266
- return keyring.resolveAccountAddress(scope, request);
279
+ return getKeyringV1For(keyring, 'address resolution').resolveAccountAddress(scope, request);
267
280
  }
268
281
  /**
269
282
  * Submit a request to a Snap from an account ID.
@@ -283,7 +296,7 @@ class SnapKeyring {
283
296
  /* istanbul ignore next */
284
297
  const keyring = __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").get(snapId) ??
285
298
  (0, util_1.throwError)(`No keyring found for snap '${snapId}'`);
286
- return await keyring.submitSnapRequest({
299
+ return await getKeyringV1For(keyring, 'requests').submitSnapRequest({
287
300
  origin,
288
301
  account,
289
302
  method: method,
@@ -304,7 +317,7 @@ class SnapKeyring {
304
317
  */
305
318
  async signTransaction(address, transaction, _opts = {}) {
306
319
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
307
- return keyring.signTransaction(account, transaction, _opts);
320
+ return getKeyringV1For(keyring, 'signing').signTransaction(account, transaction, _opts);
308
321
  }
309
322
  /**
310
323
  * Sign a typed data message.
@@ -316,7 +329,7 @@ class SnapKeyring {
316
329
  */
317
330
  async signTypedData(address, data, opts = { version: eth_sig_util_1.SignTypedDataVersion.V1 }) {
318
331
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
319
- return keyring.signTypedData(account, data, opts);
332
+ return getKeyringV1For(keyring, 'signing').signTypedData(account, data, opts);
320
333
  }
321
334
  /**
322
335
  * Sign a message.
@@ -327,7 +340,7 @@ class SnapKeyring {
327
340
  */
328
341
  async signMessage(address, hash) {
329
342
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
330
- return keyring.signMessage(account, hash);
343
+ return getKeyringV1For(keyring, 'signing').signMessage(account, hash);
331
344
  }
332
345
  /**
333
346
  * Sign a personal message.
@@ -341,7 +354,7 @@ class SnapKeyring {
341
354
  */
342
355
  async signPersonalMessage(address, data) {
343
356
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
344
- return keyring.signPersonalMessage(account, data);
357
+ return getKeyringV1For(keyring, 'signing').signPersonalMessage(account, data);
345
358
  }
346
359
  /**
347
360
  * Convert a base transaction to a base UserOperation.
@@ -353,7 +366,7 @@ class SnapKeyring {
353
366
  */
354
367
  async prepareUserOperation(address, transactions, context) {
355
368
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
356
- return keyring.prepareUserOperation(account, transactions, context);
369
+ return getKeyringV1For(keyring, 'prepareUserOperation').prepareUserOperation(account, transactions, context);
357
370
  }
358
371
  /**
359
372
  * Patches properties of a UserOperation. Currently, only the
@@ -366,7 +379,7 @@ class SnapKeyring {
366
379
  */
367
380
  async patchUserOperation(address, userOp, context) {
368
381
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
369
- return keyring.patchUserOperation(account, userOp, context);
382
+ return getKeyringV1For(keyring, 'patchUserOperation').patchUserOperation(account, userOp, context);
370
383
  }
371
384
  /**
372
385
  * Signs a UserOperation.
@@ -378,7 +391,7 @@ class SnapKeyring {
378
391
  */
379
392
  async signUserOperation(address, userOp, context) {
380
393
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
381
- return keyring.signUserOperation(account, userOp, context);
394
+ return getKeyringV1For(keyring, 'signUserOperation').signUserOperation(account, userOp, context);
382
395
  }
383
396
  /**
384
397
  * Gets the private data associated with the given address so
@@ -426,7 +439,9 @@ class SnapKeyring {
426
439
  snapAccounts.push(accountId);
427
440
  bySnap.set(snapId, snapAccounts);
428
441
  }
429
- await Promise.all([...__classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").entries()].map(async ([snapId, keyring]) => keyring.setSelectedAccounts(
442
+ // v1 snaps receive a keyring_setSelectedAccounts notification; v2 snaps
443
+ // have no equivalent concept in the protocol so they are intentionally skipped.
444
+ await Promise.all([...__classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").entries()].map(async ([snapId, keyring]) => keyring.v1?.setSelectedAccounts(
430
445
  /* istanbul ignore next */
431
446
  bySnap.get(snapId) ?? [])));
432
447
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.cjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings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D,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,EAAE,OAAO,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,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3C,CAAC,6FAGC,OAAuB,EACvB,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,4DAAiB,MAArB,IAAI,EAAkB,MAAM,CAAC,CAAC;IAE3C,OAAO;QACL,GAAG,OAAO;QACV,iDAAiD;QACjD,EAAE;QACF,mEAAmE;QACnE,qEAAqE;QACrE,uEAAuE;QACvE,WAAW;QACX,EAAE;QACF,0DAA0D;QAC1D,6BAA6B;QAC7B,OAAO,EAAE,IAAA,iCAAuB,EAAC,OAAO,CAAC;QACzC,QAAQ,EAAE;YACR,IAAI,EAAE,EAAE;YACR,UAAU,EAAE,CAAC;YACb,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB;YACD,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC;SACpC;KACF,CAAC;AACJ,CAAC;AAjvBM,gBAAI,GAAW,yBAAiB,AAA5B,CAA6B","sourcesContent":["import type { TypedTransaction } from '@ethereumjs/tx';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n ResolvedAccountAddress,\n CaipChainId,\n CreateAccountOptions,\n} from '@metamask/keyring-api';\nimport { AnyAccountType, KeyringEvent } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { AccountId, JsonRpcRequest } from '@metamask/keyring-utils';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport { normalizeAccountAddress } from './account';\nimport type { SnapKeyringInternalOptions } from './options';\nimport type { SnapKeyringMessenger } from './SnapKeyringMessenger';\nimport { SNAP_KEYRING_NAME } from './SnapKeyringMessenger';\nimport type { AccountMethod } from './SnapKeyringV1';\nimport type { SnapMessage } from './types';\nimport { throwError, unique } from './util';\nimport { SnapKeyring as SnapKeyringV2 } from './v2/SnapKeyring';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n/**\n * Snap keyring state.\n *\n * This state is persisted by the keyring controller and passed to the Snap\n * keyring when it's created.\n */\nexport type KeyringState = {\n accounts: Record<string, { account: KeyringAccount; snapId: SnapId }>;\n};\n\n/**\n * Snap keyring callbacks.\n *\n * These callbacks are used to interact with other components.\n */\nexport type SnapKeyringCallbacks = {\n saveState: () => Promise<void>;\n\n addressExists(address: string): Promise<boolean>;\n\n addAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n onceSaved: Promise<AccountId>,\n accountNameSuggestion?: string,\n internalOptions?: SnapKeyringInternalOptions,\n ): Promise<void>;\n\n removeAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n ): Promise<void>;\n\n redirectUser(snapId: SnapId, url: string, message: string): Promise<void>;\n};\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n // Name and state are required for modular initialisation.\n name: typeof SNAP_KEYRING_NAME = SNAP_KEYRING_NAME;\n\n state = null;\n\n /**\n * Messenger to dispatch requests to the Snaps controller.\n */\n readonly #messenger: SnapKeyringMessenger;\n\n /**\n * Per-snap keyring instances. Each `SnapKeyringV2` (which extends\n * `SnapKeyringV1`) owns a single `KeyringAccountRegistry` and handles\n * both the event-driven v1 flow and the `KeyringV2` batch interface.\n */\n readonly #snapKeyrings: Map<SnapId, SnapKeyringV2>;\n\n /**\n * Reverse index from account ID to the owning Snap ID.\n *\n * Populated and kept in sync via the `onRegister` / `onUnregister`\n * callbacks injected into each entry. Enables O(1) routing for\n * any \"which snap owns this account?\" query.\n */\n readonly #accountIndex: Map<AccountId, SnapId>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Whether to allow the creation and update of generic accounts.\n *\n * Account deletion is not affected by this flag and is always allowed.\n */\n readonly #isAnyAccountTypeAllowed: boolean;\n\n /**\n * Global mutex that serializes `createAccounts` calls across all snaps.\n *\n * `assertAccountCanBeUsed` checks global state (`#accountIndex` for ID\n * uniqueness, `addressExists` for address uniqueness). Without serialization,\n * two concurrent `createAccounts` calls from different snaps could both pass\n * the uniqueness check before either one calls `setAccount`, leading to\n * duplicate accounts. Injected into each `SnapKeyringV2` via the optional\n * `withLock` callback.\n */\n readonly #lock: Mutex;\n\n /**\n * Serializes lazy keyring initialization in {@link SnapKeyring.#getOrCreateKeyring}.\n *\n * Kept separate from {@link SnapKeyring.#lock} (which guards `createAccounts`\n * uniqueness checks) to avoid mixing concerns. The lock is held only for the\n * duration of a single keyring's initialization - released before the caller\n * proceeds with its operation.\n */\n readonly #getOrCreateKeyringLock: Mutex;\n\n /**\n * Create a new Snap keyring.\n *\n * @param options - Constructor options.\n * @param options.messenger - Snap keyring messenger.\n * @param options.callbacks - Callbacks used to interact with other components.\n * @param options.isAnyAccountTypeAllowed - Whether to allow the `AnyAccountType` generic account type.\n * @returns A new Snap keyring.\n */\n constructor({\n messenger,\n callbacks,\n isAnyAccountTypeAllowed = false,\n }: {\n messenger: SnapKeyringMessenger;\n callbacks: SnapKeyringCallbacks;\n isAnyAccountTypeAllowed?: boolean;\n }) {\n this.type = SnapKeyring.type;\n this.#messenger = messenger;\n this.#snapKeyrings = new Map();\n this.#accountIndex = new Map();\n this.#callbacks = callbacks;\n this.#isAnyAccountTypeAllowed = isAnyAccountTypeAllowed;\n this.#lock = new Mutex();\n this.#getOrCreateKeyringLock = new Mutex();\n }\n\n /**\n * Get the SnapKeyringEntry for a Snap, creating and initializing it if it\n * does not exist yet.\n *\n * When a new keyring is created it is immediately initialized by calling\n * `deserialize({ snapId, accounts: {} })` so that `snapId` and the internal\n * snap client are available before any event handler or method runs.\n *\n * Both v1 and v2 share the same KeyringAccountRegistry instance. The\n * onRegister / onUnregister callbacks keep #accountIndex in sync regardless\n * of which class mutates the registry.\n *\n * @param snapId - Snap ID.\n * @returns The SnapKeyringEntry for the given Snap.\n */\n async #getOrCreateKeyring(snapId: SnapId): Promise<SnapKeyringV2> {\n // Fast path: keyring already exists, no lock needed.\n const existing = this.#snapKeyrings.get(snapId);\n if (existing) {\n return existing;\n }\n\n return this.#getOrCreateKeyringLock.runExclusive(async () => {\n // Double-check: a concurrent caller may have created the keyring while\n // we were waiting for the lock.\n const keyring = this.#snapKeyrings.get(snapId);\n if (keyring) {\n return keyring;\n }\n\n const newKeyring = new SnapKeyringV2({\n messenger: this.#messenger,\n isAnyAccountTypeAllowed: this.#isAnyAccountTypeAllowed,\n callbacks: {\n // Optional callbacks that mutate accounts are responsible for keeping\n // #accountIndex in sync via these callbacks.\n onRegister: (id: AccountId): void => {\n // We can safely use `snapId` here because we create the keyring\n // instance right away.\n this.#accountIndex.set(id, snapId);\n },\n onUnregister: (id: AccountId): void => {\n this.#accountIndex.delete(id);\n },\n // Required callbacks:\n // NOTE: `keyringSnapId` and `snapId` are the same value. The `keyringSnapId` is coming from\n // the `deserialize` call right after.\n addAccount: async (\n address,\n keyringSnapId,\n handleUserInput,\n onceSaved,\n accountNameSuggestion,\n internalOptions,\n ): Promise<void> =>\n this.#callbacks.addAccount(\n address,\n keyringSnapId,\n handleUserInput,\n onceSaved,\n accountNameSuggestion,\n internalOptions,\n ),\n removeAccount: async (\n address,\n keyringSnapId,\n handleUserInput,\n ): Promise<void> =>\n this.#callbacks.removeAccount(\n address,\n keyringSnapId,\n handleUserInput,\n ),\n saveState: async (): Promise<void> => this.#callbacks.saveState(),\n redirectUser: async (id, url, message): Promise<void> =>\n this.#callbacks.redirectUser(id, url, message),\n assertAccountCanBeUsed: async (account): Promise<void> =>\n this.#assertAccountCanBeUsed(account),\n withLock: async <Result>(\n callback: () => Promise<Result>,\n ): Promise<Result> => this.#lock.runExclusive(callback),\n },\n });\n\n // Initialize the keyring with its snap ID (no accounts yet).\n await newKeyring.deserialize({ snapId, accounts: {} });\n\n // Keyring is fully initialized; register it before releasing the lock so\n // that no concurrent caller can create a duplicate.\n this.#snapKeyrings.set(snapId, newKeyring);\n\n return newKeyring;\n });\n }\n\n /**\n * Drop a per-snap keyring from {@link #snapKeyrings} when it has no accounts.\n *\n * Without this, deleting every account for a Snap would leave an empty\n * `SnapKeyringV2` in the map for the rest of the session (unlike the old\n * `SnapIdMap`, which dropped entries on delete).\n *\n * @param snapId - Snap ID whose keyring may be removed.\n */\n async #removeSnapKeyringIfEmpty(snapId: SnapId): Promise<void> {\n const keyring = this.#snapKeyrings.get(snapId);\n if (keyring?.accounts().length === 0) {\n await keyring.destroy();\n this.#snapKeyrings.delete(snapId);\n }\n }\n\n /**\n * Asserts that an account can be used within the Snap keyring. (e.g. generic accounts, unique\n * addresses, etc...).\n *\n * @param account - The account to check.\n * @throws If the account cannot be used.\n */\n async #assertAccountCanBeUsed(account: KeyringAccount): Promise<void> {\n const address = normalizeAccountAddress(account);\n\n // The `AnyAccountType.Account` generic account type is allowed only during\n // development, so we check whether it's allowed before continuing.\n if (\n !this.#isAnyAccountTypeAllowed &&\n account.type === AnyAccountType.Account\n ) {\n throw new Error(`Cannot create generic account '${account.id}'`);\n }\n\n // A Snap could try to create an account with a different address but with\n // an existing ID, so the above test only is not enough.\n // Account IDs are globally unique across all snaps.\n if (this.#accountIndex.has(account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n // The UI still uses the account address to identify accounts, so we need\n // to block the creation of duplicate accounts for now to prevent accounts\n // from being overwritten.\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\n }\n }\n\n /**\n * Handle a message from a Snap.\n *\n * Only `AccountCreated` triggers lazy keyring creation via\n * `#getOrCreateKeyring`, since that is the single entry point for the v1\n * event-driven flow. All other events from unknown snaps throw an error.\n * After handling `AccountCreated`, `#removeSnapKeyringIfEmpty` always runs\n * (via `try/finally`) to clean up if account creation was rejected.\n *\n * @param snapId - ID of the Snap.\n * @param message - Message sent by the Snap.\n * @returns The execution result.\n */\n async handleKeyringSnapMessage(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<Json> {\n let keyring = this.#snapKeyrings.get(snapId);\n\n // We can create a new keyring if the message is an AccountCreated event.\n const isAccountCreated =\n message.method === `${KeyringEvent.AccountCreated}`;\n if (!keyring && isAccountCreated) {\n keyring = await this.#getOrCreateKeyring(snapId);\n }\n\n if (!keyring) {\n throw new Error(\n `SnapKeyring - Received a message for an unknown snap keyring '${snapId}'`,\n );\n }\n\n try {\n return await keyring.handleKeyringSnapMessage(message);\n } finally {\n // Clean up if AccountCreated was rejected (e.g. duplicate address,\n // invalid account), leaving the snap with no registered accounts.\n if (isAccountCreated) {\n await this.#removeSnapKeyringIfEmpty(snapId);\n }\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * Delegates to each per-snap v2 keyring and flattens back into the original\n * external format so that `KeyringController` sees no change.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n const accounts: KeyringState['accounts'] = {};\n for (const keyring of this.#snapKeyrings.values()) {\n for (const account of keyring.accounts()) {\n accounts[account.id] = { account, snapId: keyring.snapId };\n }\n }\n return { accounts };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\n *\n * Groups the flat persisted state by `snapId`, clears both indexes, then\n * rebuilds each per-snap entry. The `onRegister` callbacks fired during\n * `v2.deserialize()` automatically repopulate `#accountIndex`.\n *\n * @param state - Serialized keyring state.\n */\n async deserialize(state: KeyringState | undefined): Promise<void> {\n // If the state is undefined, it means that this is a new keyring, so we\n // don't need to do anything.\n if (state === undefined) {\n return;\n }\n\n // Group flat state by snapId. Migrations and migration logging are handled\n // inside v2.deserialize().\n const bySnap = new Map<SnapId, Record<AccountId, KeyringAccount>>();\n for (const entry of Object.values(state.accounts)) {\n const snapAccounts = bySnap.get(entry.snapId) ?? {};\n snapAccounts[entry.account.id] = entry.account;\n bySnap.set(entry.snapId, snapAccounts);\n }\n\n // Destroy existing keyrings before clearing — rejects any pending requests.\n for (const keyring of this.#snapKeyrings.values()) {\n await keyring.destroy();\n }\n\n // Clear both indexes before rebuilding — they must always be consistent.\n this.#snapKeyrings.clear();\n this.#accountIndex.clear();\n\n // Rebuild per-snap keyrings. Each keyring handles its own validation\n // and migration internally. #getOrCreateKeyring initializes the keyring\n // with an empty state; the second deserialize call loads the real accounts.\n for (const [snapId, accounts] of bySnap) {\n const keyring = await this.#getOrCreateKeyring(snapId);\n await keyring.deserialize({ snapId, accounts });\n // onRegister callbacks fired above have repopulated #accountIndex.\n await this.#removeSnapKeyringIfEmpty(snapId);\n }\n }\n\n /**\n * Get an account and its associated Snap ID from its ID.\n *\n * @param id - Account ID.\n * @throws An error if the account could not be found.\n * @returns The account associated with the given account ID in this keyring.\n */\n #getAccount(id: string): { account: KeyringAccount; snapId: SnapId } {\n const snapId = this.#accountIndex.get(id);\n const account = snapId\n ? this.#snapKeyrings.get(snapId)?.lookupAccount(id)\n : undefined;\n\n if (!snapId || !account) {\n throw new Error(`Unable to get account: unknown account ID: '${id}'`);\n }\n return { account, snapId };\n }\n\n /**\n * Get the addresses of the accounts in this keyring.\n *\n * @returns The addresses of the accounts in this keyring.\n */\n async getAccounts(): Promise<string[]> {\n const addresses: string[] = [];\n for (const keyring of this.#snapKeyrings.values()) {\n for (const account of keyring.accounts()) {\n addresses.push(normalizeAccountAddress(account));\n }\n }\n return unique(addresses);\n }\n\n /**\n * Get the addresses of the accounts associated with a given Snap.\n *\n * @param snapId - Snap ID to filter by.\n * @returns The addresses of the accounts associated with the given Snap.\n */\n async getAccountsBySnapId(snapId: SnapId): Promise<string[]> {\n return unique(\n (this.#snapKeyrings.get(snapId)?.accounts() ?? []).map(\n normalizeAccountAddress,\n ),\n );\n }\n\n /**\n * Create an account (v1 event-driven flow).\n *\n * Delegates to the per-snap SnapKeyringV1 instance.\n *\n * @param snapId - Snap ID to create the account for.\n * @param options - Account creation options. Differs between keyrings.\n * @param internalOptions - Internal Snap keyring options.\n * @returns The account object.\n */\n async createAccount(\n snapId: SnapId,\n options: Record<string, Json>,\n internalOptions?: SnapKeyringInternalOptions,\n ): Promise<KeyringAccount> {\n const keyring = await this.#getOrCreateKeyring(snapId);\n return keyring.createAccount(options, internalOptions);\n }\n\n /**\n * Creates one or more new accounts according to the provided options.\n *\n * Delegates to the per-snap SnapKeyringV2 instance which handles\n * idempotency, validation, batch tracking, state persistence, and rollback.\n *\n * @param snapId - Snap ID to create the account(s) for.\n * @param options - Options describing how to create the account(s).\n * @returns An array of the created account objects.\n */\n async createAccounts(\n snapId: SnapId,\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n const keyring = await this.#getOrCreateKeyring(snapId);\n return keyring.createAccounts(options);\n }\n\n /**\n * Checks if a Snap ID is known from the keyring.\n *\n * @param snapId - Snap ID.\n * @returns `true` if the Snap ID is known, `false` otherwise.\n */\n hasSnapId(snapId: SnapId): boolean {\n const keyring = this.#snapKeyrings.get(snapId);\n return keyring !== undefined && keyring.accounts().length > 0;\n }\n\n /**\n * Resolve the Snap account's address associated from a signing request.\n *\n * @param snapId - Snap ID.\n * @param scope - CAIP-2 chain ID.\n * @param request - Signing request object.\n * @throws An error if the Snap ID is not known from the keyring.\n * @returns The resolved address if found, `null` otherwise.\n */\n async resolveAccountAddress(\n snapId: SnapId,\n scope: CaipChainId,\n request: JsonRpcRequest,\n ): Promise<ResolvedAccountAddress | null> {\n // We do check that the incoming Snap ID is known by the keyring.\n if (!this.hasSnapId(snapId)) {\n throw new Error(\n `Unable to resolve account address: unknown Snap ID: ${snapId}`,\n );\n }\n\n const keyring = await this.#getOrCreateKeyring(snapId);\n return keyring.resolveAccountAddress(scope, request);\n }\n\n /**\n * Submit a request to a Snap from an account ID.\n *\n * This request cannot be an asynchronous keyring request.\n *\n * @param opts - Request options.\n * @param opts.origin - Send origin.\n * @param opts.account - Account ID.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.scope - Selected chain ID (CAIP-2).\n * @returns Promise that resolves to the result of the method call.\n */\n async submitRequest({\n origin,\n account: accountId,\n method,\n params,\n scope,\n }: {\n origin: string;\n // NOTE: We use `account` here rather than `id` to avoid ambiguity with a \"request ID\".\n // We already use this same field name for `KeyringAccount`s.\n account: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n scope: string;\n }): Promise<Json> {\n const { account, snapId } = this.#getAccount(accountId);\n /* istanbul ignore next */\n const keyring =\n this.#snapKeyrings.get(snapId) ??\n throwError(`No keyring found for snap '${snapId}'`);\n\n return await keyring.submitSnapRequest({\n origin,\n account,\n method: method as AccountMethod,\n params,\n scope,\n // For non-EVM (in the context of the multichain API and SIP-26), we enforce responses\n // to be synchronous.\n noPending: true,\n });\n }\n\n /**\n * Sign a transaction.\n *\n * @param address - Sender's address.\n * @param transaction - Transaction.\n * @param _opts - Transaction options (not used).\n * @returns A promise that resolves to the signed transaction.\n */\n async signTransaction(\n address: string,\n transaction: TypedTransaction,\n _opts = {},\n ): Promise<Json | TypedTransaction> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signTransaction(account, transaction, _opts);\n }\n\n /**\n * Sign a typed data message.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @param opts - Signing options.\n * @returns The signature.\n */\n async signTypedData(\n address: string,\n data: Record<string, unknown>[] | TypedDataV1 | TypedMessage<any>,\n opts = { version: SignTypedDataVersion.V1 },\n ): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signTypedData(account, data, opts);\n }\n\n /**\n * Sign a message.\n *\n * @param address - Signer's address.\n * @param hash - Data to sign.\n * @returns The signature.\n */\n async signMessage(address: string, hash: any): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signMessage(account, hash);\n }\n\n /**\n * Sign a personal message.\n *\n * Note: KeyringController says this should return a Buffer but it actually\n * expects a string.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @returns Promise of the signature.\n */\n async signPersonalMessage(address: string, data: any): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signPersonalMessage(account, data);\n }\n\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param context - Keyring execution context.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n async prepareUserOperation(\n address: string,\n transactions: EthBaseTransaction[],\n context: KeyringExecutionContext,\n ): Promise<EthBaseUserOperation> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.prepareUserOperation(account, transactions, context);\n }\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @param context - Keyring execution context.\n * @returns A patch to apply to the UserOperation.\n */\n async patchUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<EthUserOperationPatch> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.patchUserOperation(account, userOp, context);\n }\n\n /**\n * Signs a UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Keyring execution context.\n * @returns The signature of the UserOperation.\n */\n async signUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<string> {\n const { account, keyring } = this.#resolveAddress(address);\n return keyring.signUserOperation(account, userOp, context);\n }\n\n /**\n * Gets the private data associated with the given address so\n * that it may be exported.\n *\n * If this keyring contains duplicate public keys the first\n * matching address is exported.\n *\n * Used by the UI to export an account.\n *\n * @param _address - Address of the account to export.\n */\n exportAccount(_address: string): [Uint8Array, Json] | undefined {\n throw new Error('Exporting accounts from snaps is not supported.');\n }\n\n /**\n * Removes the account matching the given address.\n *\n * Delegates to the per-snap SnapKeyringV2 keyring which handles\n * registry removal, index cleanup, and snap communication.\n *\n * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, keyring } = this.#resolveAddress(address);\n await keyring.deleteAccount(account.id);\n await this.#removeSnapKeyringIfEmpty(keyring.snapId);\n }\n\n /**\n * Resolve an address to an account and its owning keyring entry.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and the per-snap keyring that owns it. Throws if not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n keyring: SnapKeyringV2;\n } {\n for (const keyring of this.#snapKeyrings.values()) {\n const account = keyring.lookupByAddress(address);\n if (account) {\n return { account, keyring };\n }\n }\n return throwError(`Account '${address}' not found`);\n }\n\n /**\n * Set the selected accounts.\n *\n * Distributes the global list by snap and forwards to each v1 instance.\n *\n * @param accounts - The accounts to set as selected.\n */\n async setSelectedAccounts(accounts: AccountId[]): Promise<void> {\n // Build per-snap distribution using the account index.\n const bySnap = new Map<SnapId, AccountId[]>();\n for (const accountId of accounts) {\n const snapId = this.#accountIndex.get(accountId);\n if (!snapId) {\n continue;\n }\n const snapAccounts = bySnap.get(snapId) ?? [];\n snapAccounts.push(accountId);\n bySnap.set(snapId, snapAccounts);\n }\n\n await Promise.all(\n [...this.#snapKeyrings.entries()].map(async ([snapId, keyring]) =>\n keyring.setSelectedAccounts(\n /* istanbul ignore next */\n bySnap.get(snapId) ?? [],\n ),\n ),\n );\n }\n\n /**\n * Get the Snap associated with the given Snap ID.\n *\n * @param snapId - Snap ID.\n * @returns The Snap or undefined if the Snap cannot be found.\n */\n #getSnap(snapId: SnapId): Snap | null {\n return this.#messenger.call('SnapController:getSnap', snapId);\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#getSnap(snapId);\n return snap ? { id: snapId } : undefined;\n }\n\n #transformToInternalAccount(\n account: KeyringAccount,\n snapId: SnapId,\n ): InternalAccount {\n const snap = this.#getSnapMetadata(snapId);\n\n return {\n ...account,\n // TODO: Do not convert the address to lowercase.\n //\n // This is a workaround to support the current UI which expects the\n // account address to be lowercase. This workaround should be removed\n // once we migrated the UI to use the account ID instead of the account\n // address.\n //\n // NOTE: We convert the address only for EVM accounts, see\n // `normalizeAccountAddress`.\n address: normalizeAccountAddress(account),\n metadata: {\n name: '',\n importTime: 0,\n keyring: {\n type: this.type,\n },\n ...(snap !== undefined && { snap }),\n },\n };\n }\n\n /**\n * Return an internal account object for a given address.\n *\n * @param address - Address of the account to return.\n * @returns An internal account object for the given address.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n for (const [snapId, keyring] of this.#snapKeyrings) {\n const account = keyring.lookupByAddress(address);\n if (account) {\n return this.#transformToInternalAccount(account, snapId);\n }\n }\n return undefined;\n }\n\n /**\n * List all Snap keyring accounts.\n * This method is expensive on mobile devices and could takes tens or hundreds of milliseconds to complete.\n * Use with caution.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n const accounts: InternalAccount[] = [];\n for (const [snapId, keyring] of this.#snapKeyrings) {\n for (const account of keyring.accounts()) {\n accounts.push(this.#transformToInternalAccount(account, snapId));\n }\n }\n return accounts;\n }\n}\n"]}
1
+ {"version":3,"file":"SnapKeyring.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iDAAiD;QACjD,EAAE;QACF,mEAAmE;QACnE,qEAAqE;QACrE,uEAAuE;QACvE,WAAW;QACX,EAAE;QACF,0DAA0D;QAC1D,6BAA6B;QAC7B,OAAO,EAAE,IAAA,iCAAuB,EAAC,OAAO,CAAC;QACzC,QAAQ,EAAE;YACR,IAAI,EAAE,EAAE;YACR,UAAU,EAAE,CAAC;YACb,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB;YACD,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC;SACpC;KACF,CAAC;AACJ,CAAC;AAnxBM,gBAAI,GAAW,yBAAiB,AAA5B,CAA6B","sourcesContent":["import type { TypedTransaction } from '@ethereumjs/tx';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n ResolvedAccountAddress,\n CaipChainId,\n CreateAccountOptions,\n} from '@metamask/keyring-api';\nimport { AnyAccountType, KeyringEvent } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { AccountId, JsonRpcRequest } from '@metamask/keyring-utils';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport { normalizeAccountAddress } from './account';\nimport type { SnapKeyringInternalOptions } from './options';\nimport type { SnapKeyringMessenger } from './SnapKeyringMessenger';\nimport { SNAP_KEYRING_NAME } from './SnapKeyringMessenger';\nimport type { AccountMethod, SnapKeyringV1 } from './SnapKeyringV1';\nimport type { SnapMessage } from './types';\nimport { throwError, unique } from './util';\nimport { SnapKeyring as SnapKeyringV2 } from './v2/SnapKeyring';\n\n/**\n * Return the v1 instance of a per-snap keyring, throwing if the snap only\n * supports the v2 protocol.\n *\n * @param keyring - The per-snap v2 keyring.\n * @param feature - Human-readable feature name used in the error message.\n * @returns The v1 instance.\n */\nfunction getKeyringV1For(\n keyring: SnapKeyringV2,\n feature: string,\n): SnapKeyringV1 {\n return (\n keyring.v1 ??\n throwError(`Snap '${keyring.snapId}' does not support v1 ${feature}`)\n );\n}\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` owns the\n * `KeyringAccountRegistry` and handles the `KeyringV2` batch interface.\n * For v1 snaps, `SnapKeyringV2.v1` holds a `SnapKeyringV1` instance\n * (with a shared registry reference) for the event-driven flow.\n */\n readonly #snapKeyrings: Map<SnapId, SnapKeyringV2>;\n\n /**\n * Reverse index from account ID to the owning Snap ID.\n *\n * Populated and kept in sync via the `onRegister` / `onUnregister`\n * callbacks injected into each entry. Enables O(1) routing for\n * any \"which snap owns this account?\" query.\n */\n readonly #accountIndex: Map<AccountId, SnapId>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Whether to allow the creation and update of generic accounts.\n *\n * Account deletion is not affected by this flag and is always allowed.\n */\n readonly #isAnyAccountTypeAllowed: boolean;\n\n /**\n * Global mutex that serializes `createAccounts` calls across all snaps.\n *\n * `assertAccountCanBeUsed` checks global state (`#accountIndex` for ID\n * uniqueness, `addressExists` for address uniqueness). Without serialization,\n * two concurrent `createAccounts` calls from different snaps could both pass\n * the uniqueness check before either one calls `setAccount`, leading to\n * duplicate accounts. Injected into each `SnapKeyringV2` via the optional\n * `withLock` callback.\n */\n readonly #lock: Mutex;\n\n /**\n * Serializes lazy keyring initialization in {@link SnapKeyring.#getOrCreateKeyring}.\n *\n * Kept separate from {@link SnapKeyring.#lock} (which guards `createAccounts`\n * uniqueness checks) to avoid mixing concerns. The lock is held only for the\n * duration of a single keyring's initialization - released before the caller\n * proceeds with its operation.\n */\n readonly #getOrCreateKeyringLock: Mutex;\n\n /**\n * Create a new Snap keyring.\n *\n * @param options - Constructor options.\n * @param options.messenger - Snap keyring messenger.\n * @param options.callbacks - Callbacks used to interact with other components.\n * @param options.isAnyAccountTypeAllowed - Whether to allow the `AnyAccountType` generic account type.\n * @returns A new Snap keyring.\n */\n constructor({\n messenger,\n callbacks,\n isAnyAccountTypeAllowed = false,\n }: {\n messenger: SnapKeyringMessenger;\n callbacks: SnapKeyringCallbacks;\n isAnyAccountTypeAllowed?: boolean;\n }) {\n this.type = SnapKeyring.type;\n this.#messenger = messenger;\n this.#snapKeyrings = new Map();\n this.#accountIndex = new Map();\n this.#callbacks = callbacks;\n this.#isAnyAccountTypeAllowed = isAnyAccountTypeAllowed;\n this.#lock = new Mutex();\n this.#getOrCreateKeyringLock = new Mutex();\n }\n\n /**\n * Get the SnapKeyringEntry for a Snap, creating and initializing it if it\n * does not exist yet.\n *\n * When a new keyring is created it is immediately initialized by calling\n * `deserialize({ snapId, accounts: {} })` so that `snapId` and the internal\n * snap client are available before any event handler or method runs.\n *\n * Both v1 and v2 share the same KeyringAccountRegistry instance. The\n * onRegister / onUnregister callbacks keep #accountIndex in sync regardless\n * of which class mutates the registry.\n *\n * @param snapId - Snap ID.\n * @returns The SnapKeyringEntry for the given Snap.\n */\n async #getOrCreateKeyring(snapId: SnapId): Promise<SnapKeyringV2> {\n // Fast path: keyring already exists, no lock needed.\n const existing = this.#snapKeyrings.get(snapId);\n if (existing) {\n return existing;\n }\n\n return this.#getOrCreateKeyringLock.runExclusive(async () => {\n // Double-check: a concurrent caller may have created the keyring while\n // we were waiting for the lock.\n const keyring = this.#snapKeyrings.get(snapId);\n if (keyring) {\n return keyring;\n }\n\n const newKeyring = new SnapKeyringV2({\n messenger: this.#messenger,\n isAnyAccountTypeAllowed: this.#isAnyAccountTypeAllowed,\n callbacks: {\n // Optional callbacks that mutate accounts are responsible for keeping\n // #accountIndex in sync via these callbacks.\n onRegister: (id: AccountId): void => {\n // We can safely use `snapId` here because we create the keyring\n // instance right away.\n this.#accountIndex.set(id, snapId);\n },\n onUnregister: (id: AccountId): void => {\n this.#accountIndex.delete(id);\n },\n // Required callbacks:\n // NOTE: `keyringSnapId` and `snapId` are the same value. The `keyringSnapId` is coming from\n // the `deserialize` call right after.\n addAccount: async (\n address,\n keyringSnapId,\n handleUserInput,\n onceSaved,\n accountNameSuggestion,\n internalOptions,\n ): Promise<void> =>\n this.#callbacks.addAccount(\n address,\n keyringSnapId,\n handleUserInput,\n onceSaved,\n accountNameSuggestion,\n internalOptions,\n ),\n removeAccount: async (\n address,\n keyringSnapId,\n handleUserInput,\n ): Promise<void> =>\n this.#callbacks.removeAccount(\n address,\n keyringSnapId,\n handleUserInput,\n ),\n saveState: async (): Promise<void> => this.#callbacks.saveState(),\n redirectUser: async (id, url, message): Promise<void> =>\n this.#callbacks.redirectUser(id, url, message),\n assertAccountCanBeUsed: async (account): Promise<void> =>\n this.#assertAccountCanBeUsed(account),\n withLock: async <Result>(\n callback: () => Promise<Result>,\n ): Promise<Result> => this.#lock.runExclusive(callback),\n },\n });\n\n // Initialize the keyring with its snap ID (no accounts yet).\n await newKeyring.deserialize({ snapId, accounts: {} });\n\n // Keyring is fully initialized; register it before releasing the lock so\n // that no concurrent caller can create a duplicate.\n this.#snapKeyrings.set(snapId, newKeyring);\n\n return newKeyring;\n });\n }\n\n /**\n * Drop a per-snap keyring from {@link #snapKeyrings} when it has no accounts.\n *\n * Without this, deleting every account for a Snap would leave an empty\n * `SnapKeyringV2` in the map for the rest of the session (unlike the old\n * `SnapIdMap`, which dropped entries on delete).\n *\n * @param snapId - Snap ID whose keyring may be removed.\n */\n async #removeSnapKeyringIfEmpty(snapId: SnapId): Promise<void> {\n const keyring = this.#snapKeyrings.get(snapId);\n if (keyring?.accounts().length === 0) {\n await keyring.destroy();\n this.#snapKeyrings.delete(snapId);\n }\n }\n\n /**\n * Asserts that an account can be used within the Snap keyring. (e.g. generic accounts, unique\n * addresses, etc...).\n *\n * @param account - The account to check.\n * @throws If the account cannot be used.\n */\n async #assertAccountCanBeUsed(account: KeyringAccount): Promise<void> {\n const address = normalizeAccountAddress(account);\n\n // The `AnyAccountType.Account` generic account type is allowed only during\n // development, so we check whether it's allowed before continuing.\n if (\n !this.#isAnyAccountTypeAllowed &&\n account.type === AnyAccountType.Account\n ) {\n throw new Error(`Cannot create generic account '${account.id}'`);\n }\n\n // A Snap could try to create an account with a different address but with\n // an existing ID, so the above test only is not enough.\n // Account IDs are globally unique across all snaps.\n if (this.#accountIndex.has(account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n // The UI still uses the account address to identify accounts, so we need\n // to block the creation of duplicate accounts for now to prevent accounts\n // from being overwritten.\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\n }\n }\n\n /**\n * Handle a message from a Snap.\n *\n * Only `AccountCreated` triggers lazy keyring creation via\n * `#getOrCreateKeyring`, since that is the single entry point for the v1\n * event-driven flow. All other events from unknown snaps throw an error.\n * After handling `AccountCreated`, `#removeSnapKeyringIfEmpty` always runs\n * (via `try/finally`) to clean up if account creation was rejected.\n *\n * @param snapId - ID of the Snap.\n * @param message - Message sent by the Snap.\n * @returns The execution result.\n */\n async handleKeyringSnapMessage(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<Json> {\n let keyring = this.#snapKeyrings.get(snapId);\n\n // We can create a new keyring if the message is an AccountCreated event.\n const isAccountCreated =\n message.method === `${KeyringEvent.AccountCreated}`;\n if (!keyring && isAccountCreated) {\n keyring = await this.#getOrCreateKeyring(snapId);\n }\n\n if (!keyring) {\n throw new Error(\n `SnapKeyring - Received a message for an unknown snap keyring '${snapId}'`,\n );\n }\n\n try {\n return await getKeyringV1For(\n keyring,\n 'messages',\n ).handleKeyringSnapMessage(message);\n } finally {\n // Clean up if AccountCreated was rejected (e.g. duplicate address,\n // invalid account), leaving the snap with no registered accounts.\n if (isAccountCreated) {\n await this.#removeSnapKeyringIfEmpty(snapId);\n }\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * Delegates to each per-snap v2 keyring and flattens back into the original\n * external format so that `KeyringController` sees no change.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n const accounts: KeyringState['accounts'] = {};\n for (const keyring of this.#snapKeyrings.values()) {\n for (const account of keyring.accounts()) {\n accounts[account.id] = { account, snapId: keyring.snapId };\n }\n }\n return { accounts };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\n *\n * Groups the flat persisted state by `snapId`, clears both indexes, then\n * rebuilds each per-snap entry. The `onRegister` callbacks fired during\n * `v2.deserialize()` automatically repopulate `#accountIndex`.\n *\n * @param state - Serialized keyring state.\n */\n async deserialize(state: KeyringState | undefined): Promise<void> {\n // If the state is undefined, it means that this is a new keyring, so we\n // don't need to do anything.\n if (state === undefined) {\n return;\n }\n\n // Group flat state by snapId. Migrations and migration logging are handled\n // inside v2.deserialize().\n const bySnap = new Map<SnapId, Record<AccountId, KeyringAccount>>();\n for (const entry of Object.values(state.accounts)) {\n const snapAccounts = bySnap.get(entry.snapId) ?? {};\n snapAccounts[entry.account.id] = entry.account;\n bySnap.set(entry.snapId, snapAccounts);\n }\n\n // Destroy existing keyrings before clearing — rejects any pending requests.\n for (const keyring of this.#snapKeyrings.values()) {\n await keyring.destroy();\n }\n\n // Clear both indexes before rebuilding — they must always be consistent.\n this.#snapKeyrings.clear();\n this.#accountIndex.clear();\n\n // Rebuild per-snap keyrings. Each keyring handles its own validation\n // and migration internally. #getOrCreateKeyring initializes the keyring\n // with an empty state; the second deserialize call loads the real accounts.\n for (const [snapId, accounts] of bySnap) {\n const keyring = await this.#getOrCreateKeyring(snapId);\n await keyring.deserialize({ snapId, accounts });\n // onRegister callbacks fired above have repopulated #accountIndex.\n await this.#removeSnapKeyringIfEmpty(snapId);\n }\n }\n\n /**\n * Get an account and its associated Snap ID from its ID.\n *\n * @param id - Account ID.\n * @throws An error if the account could not be found.\n * @returns The account associated with the given account ID in this keyring.\n */\n #getAccount(id: string): { account: KeyringAccount; snapId: SnapId } {\n const snapId = this.#accountIndex.get(id);\n const account = snapId\n ? this.#snapKeyrings.get(snapId)?.lookupAccount(id)\n : undefined;\n\n if (!snapId || !account) {\n throw new Error(`Unable to get account: unknown account ID: '${id}'`);\n }\n return { account, snapId };\n }\n\n /**\n * Get the addresses of the accounts in this keyring.\n *\n * @returns The addresses of the accounts in this keyring.\n */\n async getAccounts(): Promise<string[]> {\n const addresses: string[] = [];\n for (const keyring of this.#snapKeyrings.values()) {\n for (const account of keyring.accounts()) {\n addresses.push(normalizeAccountAddress(account));\n }\n }\n return unique(addresses);\n }\n\n /**\n * Get the addresses of the accounts associated with a given Snap.\n *\n * @param snapId - Snap ID to filter by.\n * @returns The addresses of the accounts associated with the given Snap.\n */\n async getAccountsBySnapId(snapId: SnapId): Promise<string[]> {\n return unique(\n (this.#snapKeyrings.get(snapId)?.accounts() ?? []).map(\n normalizeAccountAddress,\n ),\n );\n }\n\n /**\n * Create an account (v1 event-driven flow).\n *\n * Delegates to the per-snap SnapKeyringV2 instance (v1 flow).\n *\n * @param snapId - Snap ID to create the account for.\n * @param options - Account creation options. Differs between keyrings.\n * @param internalOptions - Internal Snap keyring options.\n * @returns The account object.\n */\n async createAccount(\n snapId: SnapId,\n options: Record<string, Json>,\n internalOptions?: SnapKeyringInternalOptions,\n ): Promise<KeyringAccount> {\n const keyring = await this.#getOrCreateKeyring(snapId);\n return getKeyringV1For(keyring, 'account creation').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 const keyring = await this.#getOrCreateKeyring(snapId);\n return keyring.createAccounts(options);\n }\n\n /**\n * Checks if a Snap ID is known from the keyring.\n *\n * @param snapId - Snap ID.\n * @returns `true` if the Snap ID is known, `false` otherwise.\n */\n hasSnapId(snapId: SnapId): boolean {\n const keyring = this.#snapKeyrings.get(snapId);\n return keyring !== undefined && keyring.accounts().length > 0;\n }\n\n /**\n * Resolve the Snap account's address associated from a signing request.\n *\n * @param snapId - Snap ID.\n * @param scope - CAIP-2 chain ID.\n * @param request - Signing request object.\n * @throws An error if the Snap ID is not known from the keyring.\n * @returns The resolved address if found, `null` otherwise.\n */\n async resolveAccountAddress(\n snapId: SnapId,\n scope: CaipChainId,\n request: JsonRpcRequest,\n ): Promise<ResolvedAccountAddress | null> {\n // We do check that the incoming Snap ID is known by the keyring.\n if (!this.hasSnapId(snapId)) {\n throw new Error(\n `Unable to resolve account address: unknown Snap ID: ${snapId}`,\n );\n }\n\n const keyring = await this.#getOrCreateKeyring(snapId);\n return getKeyringV1For(keyring, 'address resolution').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 getKeyringV1For(keyring, 'requests').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 getKeyringV1For(keyring, 'signing').signTransaction(\n account,\n transaction,\n _opts,\n );\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 getKeyringV1For(keyring, 'signing').signTypedData(\n account,\n data,\n opts,\n );\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 getKeyringV1For(keyring, 'signing').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 getKeyringV1For(keyring, 'signing').signPersonalMessage(\n account,\n data,\n );\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 getKeyringV1For(\n keyring,\n 'prepareUserOperation',\n ).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 getKeyringV1For(keyring, 'patchUserOperation').patchUserOperation(\n account,\n userOp,\n context,\n );\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 getKeyringV1For(keyring, 'signUserOperation').signUserOperation(\n account,\n userOp,\n context,\n );\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 // v1 snaps receive a keyring_setSelectedAccounts notification; v2 snaps\n // have no equivalent concept in the protocol so they are intentionally skipped.\n await Promise.all(\n [...this.#snapKeyrings.entries()].map(async ([snapId, keyring]) =>\n keyring.v1?.setSelectedAccounts(\n /* istanbul ignore next */\n bySnap.get(snapId) ?? [],\n ),\n ),\n );\n }\n\n /**\n * Get the Snap associated with the given Snap ID.\n *\n * @param snapId - Snap ID.\n * @returns The Snap or undefined if the Snap cannot be found.\n */\n #getSnap(snapId: SnapId): Snap | null {\n return this.#messenger.call('SnapController:getSnap', snapId);\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#getSnap(snapId);\n return snap ? { id: snapId } : undefined;\n }\n\n #transformToInternalAccount(\n account: KeyringAccount,\n snapId: SnapId,\n ): InternalAccount {\n const snap = this.#getSnapMetadata(snapId);\n\n return {\n ...account,\n // TODO: Do not convert the address to lowercase.\n //\n // This is a workaround to support the current UI which expects the\n // account address to be lowercase. This workaround should be removed\n // once we migrated the UI to use the account ID instead of the account\n // address.\n //\n // NOTE: We convert the address only for EVM accounts, see\n // `normalizeAccountAddress`.\n address: normalizeAccountAddress(account),\n metadata: {\n name: '',\n importTime: 0,\n keyring: {\n type: this.type,\n },\n ...(snap !== undefined && { snap }),\n },\n };\n }\n\n /**\n * Return an internal account object for a given address.\n *\n * @param address - Address of the account to return.\n * @returns An internal account object for the given address.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n for (const [snapId, keyring] of this.#snapKeyrings) {\n const account = keyring.lookupByAddress(address);\n if (account) {\n return this.#transformToInternalAccount(account, snapId);\n }\n }\n return undefined;\n }\n\n /**\n * List all Snap keyring accounts.\n * This method is expensive on mobile devices and could takes tens or hundreds of milliseconds to complete.\n * Use with caution.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n const accounts: InternalAccount[] = [];\n for (const [snapId, keyring] of this.#snapKeyrings) {\n for (const account of keyring.accounts()) {\n accounts.push(this.#transformToInternalAccount(account, snapId));\n }\n }\n return accounts;\n }\n}\n"]}
@@ -107,7 +107,7 @@ export declare class SnapKeyring {
107
107
  /**
108
108
  * Create an account (v1 event-driven flow).
109
109
  *
110
- * Delegates to the per-snap SnapKeyringV1 instance.
110
+ * Delegates to the per-snap SnapKeyringV2 instance (v1 flow).
111
111
  *
112
112
  * @param snapId - Snap ID to create the account for.
113
113
  * @param options - Account creation options. Differs between keyrings.
@@ -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;AAElD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO,KAAK,EAAE,0BAA0B,EAAE,sBAAkB;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAAE,mCAA+B;AACnE,OAAO,EAAE,iBAAiB,EAAE,mCAA+B;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAgB;AAI3C,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,C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;;;;;;OAMG;IACH,YAAY,IAAI,eAAe,EAAE;CASlC"}
@@ -107,7 +107,7 @@ export declare class SnapKeyring {
107
107
  /**
108
108
  * Create an account (v1 event-driven flow).
109
109
  *
110
- * Delegates to the per-snap SnapKeyringV1 instance.
110
+ * Delegates to the per-snap SnapKeyringV2 instance (v1 flow).
111
111
  *
112
112
  * @param snapId - Snap ID to create the account for.
113
113
  * @param options - Account creation options. Differs between keyrings.
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.d.mts","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,+BAA+B;AACxE,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAC9D,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,WAAW,EACX,oBAAoB,EACrB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gCAAgC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO,KAAK,EAAE,0BAA0B,EAAE,sBAAkB;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAAE,mCAA+B;AACnE,OAAO,EAAE,iBAAiB,EAAE,mCAA+B;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAgB;AAI3C,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA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G,SAAS;IAUjE;;;;;;OAMG;IACH,YAAY,IAAI,eAAe,EAAE;CASlC"}
@@ -17,6 +17,18 @@ import { normalizeAccountAddress } from "./account.mjs";
17
17
  import { SNAP_KEYRING_NAME } from "./SnapKeyringMessenger.mjs";
18
18
  import { throwError, unique } from "./util.mjs";
19
19
  import { SnapKeyring as SnapKeyringV2 } from "./v2/SnapKeyring.mjs";
20
+ /**
21
+ * Return the v1 instance of a per-snap keyring, throwing if the snap only
22
+ * supports the v2 protocol.
23
+ *
24
+ * @param keyring - The per-snap v2 keyring.
25
+ * @param feature - Human-readable feature name used in the error message.
26
+ * @returns The v1 instance.
27
+ */
28
+ function getKeyringV1For(keyring, feature) {
29
+ return (keyring.v1 ??
30
+ throwError(`Snap '${keyring.snapId}' does not support v1 ${feature}`));
31
+ }
20
32
  export const SNAP_KEYRING_TYPE = 'Snap Keyring';
21
33
  /**
22
34
  * Keyring bridge implementation to support Snaps.
@@ -41,9 +53,10 @@ export class SnapKeyring {
41
53
  */
42
54
  _SnapKeyring_messenger.set(this, void 0);
43
55
  /**
44
- * Per-snap keyring instances. Each `SnapKeyringV2` (which extends
45
- * `SnapKeyringV1`) owns a single `KeyringAccountRegistry` and handles
46
- * both the event-driven v1 flow and the `KeyringV2` batch interface.
56
+ * Per-snap keyring instances. Each `SnapKeyringV2` owns the
57
+ * `KeyringAccountRegistry` and handles the `KeyringV2` batch interface.
58
+ * For v1 snaps, `SnapKeyringV2.v1` holds a `SnapKeyringV1` instance
59
+ * (with a shared registry reference) for the event-driven flow.
47
60
  */
48
61
  _SnapKeyring_snapKeyrings.set(this, void 0);
49
62
  /**
@@ -117,7 +130,7 @@ export class SnapKeyring {
117
130
  throw new Error(`SnapKeyring - Received a message for an unknown snap keyring '${snapId}'`);
118
131
  }
119
132
  try {
120
- return await keyring.handleKeyringSnapMessage(message);
133
+ return await getKeyringV1For(keyring, 'messages').handleKeyringSnapMessage(message);
121
134
  }
122
135
  finally {
123
136
  // Clean up if AccountCreated was rejected (e.g. duplicate address,
@@ -210,7 +223,7 @@ export class SnapKeyring {
210
223
  /**
211
224
  * Create an account (v1 event-driven flow).
212
225
  *
213
- * Delegates to the per-snap SnapKeyringV1 instance.
226
+ * Delegates to the per-snap SnapKeyringV2 instance (v1 flow).
214
227
  *
215
228
  * @param snapId - Snap ID to create the account for.
216
229
  * @param options - Account creation options. Differs between keyrings.
@@ -219,7 +232,7 @@ export class SnapKeyring {
219
232
  */
220
233
  async createAccount(snapId, options, internalOptions) {
221
234
  const keyring = await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
222
- return keyring.createAccount(options, internalOptions);
235
+ return getKeyringV1For(keyring, 'account creation').createAccount(options, internalOptions);
223
236
  }
224
237
  /**
225
238
  * Creates one or more new accounts according to the provided options.
@@ -260,7 +273,7 @@ export class SnapKeyring {
260
273
  throw new Error(`Unable to resolve account address: unknown Snap ID: ${snapId}`);
261
274
  }
262
275
  const keyring = await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getOrCreateKeyring).call(this, snapId);
263
- return keyring.resolveAccountAddress(scope, request);
276
+ return getKeyringV1For(keyring, 'address resolution').resolveAccountAddress(scope, request);
264
277
  }
265
278
  /**
266
279
  * Submit a request to a Snap from an account ID.
@@ -280,7 +293,7 @@ export class SnapKeyring {
280
293
  /* istanbul ignore next */
281
294
  const keyring = __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").get(snapId) ??
282
295
  throwError(`No keyring found for snap '${snapId}'`);
283
- return await keyring.submitSnapRequest({
296
+ return await getKeyringV1For(keyring, 'requests').submitSnapRequest({
284
297
  origin,
285
298
  account,
286
299
  method: method,
@@ -301,7 +314,7 @@ export class SnapKeyring {
301
314
  */
302
315
  async signTransaction(address, transaction, _opts = {}) {
303
316
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
304
- return keyring.signTransaction(account, transaction, _opts);
317
+ return getKeyringV1For(keyring, 'signing').signTransaction(account, transaction, _opts);
305
318
  }
306
319
  /**
307
320
  * Sign a typed data message.
@@ -313,7 +326,7 @@ export class SnapKeyring {
313
326
  */
314
327
  async signTypedData(address, data, opts = { version: SignTypedDataVersion.V1 }) {
315
328
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
316
- return keyring.signTypedData(account, data, opts);
329
+ return getKeyringV1For(keyring, 'signing').signTypedData(account, data, opts);
317
330
  }
318
331
  /**
319
332
  * Sign a message.
@@ -324,7 +337,7 @@ export class SnapKeyring {
324
337
  */
325
338
  async signMessage(address, hash) {
326
339
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
327
- return keyring.signMessage(account, hash);
340
+ return getKeyringV1For(keyring, 'signing').signMessage(account, hash);
328
341
  }
329
342
  /**
330
343
  * Sign a personal message.
@@ -338,7 +351,7 @@ export class SnapKeyring {
338
351
  */
339
352
  async signPersonalMessage(address, data) {
340
353
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
341
- return keyring.signPersonalMessage(account, data);
354
+ return getKeyringV1For(keyring, 'signing').signPersonalMessage(account, data);
342
355
  }
343
356
  /**
344
357
  * Convert a base transaction to a base UserOperation.
@@ -350,7 +363,7 @@ export class SnapKeyring {
350
363
  */
351
364
  async prepareUserOperation(address, transactions, context) {
352
365
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
353
- return keyring.prepareUserOperation(account, transactions, context);
366
+ return getKeyringV1For(keyring, 'prepareUserOperation').prepareUserOperation(account, transactions, context);
354
367
  }
355
368
  /**
356
369
  * Patches properties of a UserOperation. Currently, only the
@@ -363,7 +376,7 @@ export class SnapKeyring {
363
376
  */
364
377
  async patchUserOperation(address, userOp, context) {
365
378
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
366
- return keyring.patchUserOperation(account, userOp, context);
379
+ return getKeyringV1For(keyring, 'patchUserOperation').patchUserOperation(account, userOp, context);
367
380
  }
368
381
  /**
369
382
  * Signs a UserOperation.
@@ -375,7 +388,7 @@ export class SnapKeyring {
375
388
  */
376
389
  async signUserOperation(address, userOp, context) {
377
390
  const { account, keyring } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_resolveAddress).call(this, address);
378
- return keyring.signUserOperation(account, userOp, context);
391
+ return getKeyringV1For(keyring, 'signUserOperation').signUserOperation(account, userOp, context);
379
392
  }
380
393
  /**
381
394
  * Gets the private data associated with the given address so
@@ -423,7 +436,9 @@ export class SnapKeyring {
423
436
  snapAccounts.push(accountId);
424
437
  bySnap.set(snapId, snapAccounts);
425
438
  }
426
- await Promise.all([...__classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").entries()].map(async ([snapId, keyring]) => keyring.setSelectedAccounts(
439
+ // v1 snaps receive a keyring_setSelectedAccounts notification; v2 snaps
440
+ // have no equivalent concept in the protocol so they are intentionally skipped.
441
+ await Promise.all([...__classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").entries()].map(async ([snapId, keyring]) => keyring.v1?.setSelectedAccounts(
427
442
  /* istanbul ignore next */
428
443
  bySnap.get(snapId) ?? [])));
429
444
  }