@metamask-previews/eth-snap-keyring 24.0.0-914f87e → 24.1.0-00307a3

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 (42) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/dist/SnapKeyring.cjs +3 -1
  3. package/dist/SnapKeyring.cjs.map +1 -1
  4. package/dist/SnapKeyring.d.cts +4 -2
  5. package/dist/SnapKeyring.d.cts.map +1 -1
  6. package/dist/SnapKeyring.d.mts +4 -2
  7. package/dist/SnapKeyring.d.mts.map +1 -1
  8. package/dist/SnapKeyring.mjs +3 -1
  9. package/dist/SnapKeyring.mjs.map +1 -1
  10. package/dist/SnapKeyringV1.cjs +8 -2
  11. package/dist/SnapKeyringV1.cjs.map +1 -1
  12. package/dist/SnapKeyringV1.d.cts +4 -2
  13. package/dist/SnapKeyringV1.d.cts.map +1 -1
  14. package/dist/SnapKeyringV1.d.mts +4 -2
  15. package/dist/SnapKeyringV1.d.mts.map +1 -1
  16. package/dist/SnapKeyringV1.mjs +10 -4
  17. package/dist/SnapKeyringV1.mjs.map +1 -1
  18. package/dist/platform-versions.cjs +3 -1
  19. package/dist/platform-versions.cjs.map +1 -1
  20. package/dist/platform-versions.d.cts +2 -0
  21. package/dist/platform-versions.d.cts.map +1 -1
  22. package/dist/platform-versions.d.mts +2 -0
  23. package/dist/platform-versions.d.mts.map +1 -1
  24. package/dist/platform-versions.mjs +2 -0
  25. package/dist/platform-versions.mjs.map +1 -1
  26. package/dist/v2/SnapKeyring.cjs +10 -0
  27. package/dist/v2/SnapKeyring.cjs.map +1 -1
  28. package/dist/v2/SnapKeyring.d.cts +13 -11
  29. package/dist/v2/SnapKeyring.d.cts.map +1 -1
  30. package/dist/v2/SnapKeyring.d.mts +13 -11
  31. package/dist/v2/SnapKeyring.d.mts.map +1 -1
  32. package/dist/v2/SnapKeyring.mjs +10 -0
  33. package/dist/v2/SnapKeyring.mjs.map +1 -1
  34. package/dist/v2/SnapKeyringV1Adapter.cjs +22 -3
  35. package/dist/v2/SnapKeyringV1Adapter.cjs.map +1 -1
  36. package/dist/v2/SnapKeyringV1Adapter.d.cts +7 -0
  37. package/dist/v2/SnapKeyringV1Adapter.d.cts.map +1 -1
  38. package/dist/v2/SnapKeyringV1Adapter.d.mts +7 -0
  39. package/dist/v2/SnapKeyringV1Adapter.d.mts.map +1 -1
  40. package/dist/v2/SnapKeyringV1Adapter.mjs +18 -0
  41. package/dist/v2/SnapKeyringV1Adapter.mjs.map +1 -1
  42. package/package.json +6 -6
package/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [24.1.0]
11
+
12
+ ### Added
13
+
14
+ - Add `isSnapKeyringV1Adapter` ([#618](https://github.com/MetaMask/accounts/pull/618))
15
+ - This helper ensure we can safely identify the adapter if multiple versions/variants of that same class exists.
16
+ - Forward `originMetadata` from `submitRequest` to the Snap handler when the platform supports it ([#615](https://github.com/MetaMask/accounts/pull/615))
17
+ - Snaps running on platform `>=12.0.0` will receive `originMetadata` in `onKeyringRequest` requests.
18
+ - Older platform versions continue to receive requests without this field.
19
+
20
+ ### Changed
21
+
22
+ - Bump `@metamask/keyring-sdk` from `^3.0.0` to `^3.1.0` ([#614](https://github.com/MetaMask/accounts/pull/614))
23
+ - Bump `@metamask/keyring-internal-api` from `^12.0.0` to `^12.1.0` ([#620](https://github.com/MetaMask/accounts/pull/620))
24
+ - Bump `@metamask/keyring-internal-snap-client` from `^11.0.0` to `^11.1.0` ([#620](https://github.com/MetaMask/accounts/pull/620))
25
+
10
26
  ## [24.0.0]
11
27
 
12
28
  ### Changed
@@ -799,7 +815,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
799
815
 
800
816
  - Initial release.
801
817
 
802
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@24.0.0...HEAD
818
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@24.1.0...HEAD
819
+ [24.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@24.0.0...@metamask/eth-snap-keyring@24.1.0
803
820
  [24.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@23.0.2...@metamask/eth-snap-keyring@24.0.0
804
821
  [23.0.2]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@23.0.1...@metamask/eth-snap-keyring@23.0.2
805
822
  [23.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@23.0.0...@metamask/eth-snap-keyring@23.0.1
@@ -285,19 +285,21 @@ class SnapKeyring {
285
285
  *
286
286
  * @param opts - Request options.
287
287
  * @param opts.origin - Send origin.
288
+ * @param opts.originMetadata - Optional metadata about the origin.
288
289
  * @param opts.account - Account ID.
289
290
  * @param opts.method - Method to call.
290
291
  * @param opts.params - Method parameters.
291
292
  * @param opts.scope - Selected chain ID (CAIP-2).
292
293
  * @returns Promise that resolves to the result of the method call.
293
294
  */
294
- async submitRequest({ origin, account: accountId, method, params, scope, }) {
295
+ async submitRequest({ origin, originMetadata, account: accountId, method, params, scope, }) {
295
296
  const { account, snapId } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getAccount).call(this, accountId);
296
297
  /* istanbul ignore next */
297
298
  const keyring = __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").get(snapId) ??
298
299
  (0, util_1.throwError)(`No keyring found for snap '${snapId}'`);
299
300
  return await getKeyringV1For(keyring, 'requests').submitSnapRequest({
300
301
  origin,
302
+ ...(originMetadata !== undefined && { originMetadata }),
301
303
  account,
302
304
  method: method,
303
305
  params,
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.cjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yDAA8D;AAY9D,uDAAqE;AA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C1D,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"]}
1
+ {"version":3,"file":"SnapKeyring.cjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],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AC,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;AAvxBM,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 OriginMetadata,\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.originMetadata - Optional metadata about the 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 originMetadata,\n account: accountId,\n method,\n params,\n scope,\n }: {\n origin: string;\n originMetadata?: OriginMetadata | null;\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 ...(originMetadata !== undefined && { originMetadata }),\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"]}
@@ -1,7 +1,7 @@
1
1
  import type { TypedTransaction } from "@ethereumjs/tx";
2
2
  import type { TypedDataV1, TypedMessage } from "@metamask/eth-sig-util";
3
3
  import { SignTypedDataVersion } from "@metamask/eth-sig-util";
4
- import type { KeyringAccount, KeyringExecutionContext, EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, ResolvedAccountAddress, CaipChainId, CreateAccountOptions } from "@metamask/keyring-api";
4
+ import type { KeyringAccount, KeyringExecutionContext, EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, ResolvedAccountAddress, CaipChainId, CreateAccountOptions, OriginMetadata } from "@metamask/keyring-api";
5
5
  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";
@@ -150,14 +150,16 @@ export declare class SnapKeyring {
150
150
  *
151
151
  * @param opts - Request options.
152
152
  * @param opts.origin - Send origin.
153
+ * @param opts.originMetadata - Optional metadata about the origin.
153
154
  * @param opts.account - Account ID.
154
155
  * @param opts.method - Method to call.
155
156
  * @param opts.params - Method parameters.
156
157
  * @param opts.scope - Selected chain ID (CAIP-2).
157
158
  * @returns Promise that resolves to the result of the method call.
158
159
  */
159
- submitRequest({ origin, account: accountId, method, params, scope, }: {
160
+ submitRequest({ origin, originMetadata, account: accountId, method, params, scope, }: {
160
161
  origin: string;
162
+ originMetadata?: OriginMetadata | null;
161
163
  account: string;
162
164
  method: string;
163
165
  params?: Json[] | Record<string, Json>;
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.d.cts","sourceRoot":"","sources":["../src/SnapKeyring.ts"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AAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAK9D;;;;;;;;;OASG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAQtE;;;;;;;OAOG;IACG,oBAAoB,CACxB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,kBAAkB,EAAE,EAClC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,oBAAoB,CAAC;IAQhC;;;;;;;;OAQG;IACG,kBAAkB,CACtB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IASjC;;;;;;;OAOG;IACG,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC;IASlB;;;;;;;;;;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"}
@@ -1,7 +1,7 @@
1
1
  import type { TypedTransaction } from "@ethereumjs/tx";
2
2
  import type { TypedDataV1, TypedMessage } from "@metamask/eth-sig-util";
3
3
  import { SignTypedDataVersion } from "@metamask/eth-sig-util";
4
- import type { KeyringAccount, KeyringExecutionContext, EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, ResolvedAccountAddress, CaipChainId, CreateAccountOptions } from "@metamask/keyring-api";
4
+ import type { KeyringAccount, KeyringExecutionContext, EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, ResolvedAccountAddress, CaipChainId, CreateAccountOptions, OriginMetadata } from "@metamask/keyring-api";
5
5
  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";
@@ -150,14 +150,16 @@ export declare class SnapKeyring {
150
150
  *
151
151
  * @param opts - Request options.
152
152
  * @param opts.origin - Send origin.
153
+ * @param opts.originMetadata - Optional metadata about the origin.
153
154
  * @param opts.account - Account ID.
154
155
  * @param opts.method - Method to call.
155
156
  * @param opts.params - Method parameters.
156
157
  * @param opts.scope - Selected chain ID (CAIP-2).
157
158
  * @returns Promise that resolves to the result of the method call.
158
159
  */
159
- submitRequest({ origin, account: accountId, method, params, scope, }: {
160
+ submitRequest({ origin, originMetadata, account: accountId, method, params, scope, }: {
160
161
  origin: string;
162
+ originMetadata?: OriginMetadata | null;
161
163
  account: string;
162
164
  method: string;
163
165
  params?: Json[] | Record<string, Json>;
@@ -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,EA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,uBAAuB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IASjC;;;;;;;OAOG;IACG,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC;IASlB;;;;;;;;;;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"}
@@ -282,19 +282,21 @@ export class SnapKeyring {
282
282
  *
283
283
  * @param opts - Request options.
284
284
  * @param opts.origin - Send origin.
285
+ * @param opts.originMetadata - Optional metadata about the origin.
285
286
  * @param opts.account - Account ID.
286
287
  * @param opts.method - Method to call.
287
288
  * @param opts.params - Method parameters.
288
289
  * @param opts.scope - Selected chain ID (CAIP-2).
289
290
  * @returns Promise that resolves to the result of the method call.
290
291
  */
291
- async submitRequest({ origin, account: accountId, method, params, scope, }) {
292
+ async submitRequest({ origin, originMetadata, account: accountId, method, params, scope, }) {
292
293
  const { account, snapId } = __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_getAccount).call(this, accountId);
293
294
  /* istanbul ignore next */
294
295
  const keyring = __classPrivateFieldGet(this, _SnapKeyring_snapKeyrings, "f").get(snapId) ??
295
296
  throwError(`No keyring found for snap '${snapId}'`);
296
297
  return await getKeyringV1For(keyring, 'requests').submitSnapRequest({
297
298
  origin,
299
+ ...(originMetadata !== undefined && { originMetadata }),
298
300
  account,
299
301
  method: method,
300
302
  params,