@metamask-previews/eth-snap-keyring 8.1.1-7fd7a95 → 9.0.0-0aca2ee

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,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [9.0.0]
11
+
12
+ ### Added
13
+
14
+ - Add `account{AssetList,Balances,Transactions}Updated` keyring events and re-publish them through the new `Messenger` ([#154](https://github.com/MetaMask/accounts/pull/154))
15
+
16
+ ### Changed
17
+
18
+ - **BREAKING:** Use `Messenger` instead of `SnapsController` ([#152](https://github.com/MetaMask/accounts/pull/152))
19
+ - This allows to break the runtime dependency we had with some `snaps-*` pacakges.
20
+ - **BREAKING:** Make `scopes` more strict ([#159](https://github.com/MetaMask/accounts/pull/159))
21
+ - We now use specific `*AccountStucts` when checking created/updated accounts to make the `scopes` sent by the Snap are valid regarding their account type definition.
22
+
10
23
  ## [8.1.1]
11
24
 
12
25
  ### Changed
@@ -416,7 +429,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
416
429
 
417
430
  - Initial release.
418
431
 
419
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@8.1.1...HEAD
432
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@9.0.0...HEAD
433
+ [9.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@8.1.1...@metamask/eth-snap-keyring@9.0.0
420
434
  [8.1.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@8.1.0...@metamask/eth-snap-keyring@8.1.1
421
435
  [8.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@8.0.0...@metamask/eth-snap-keyring@8.1.0
422
436
  [8.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@7.1.0...@metamask/eth-snap-keyring@8.0.0
@@ -25,6 +25,7 @@ const superstruct_1 = require("@metamask/superstruct");
25
25
  const utils_1 = require("@metamask/utils");
26
26
  const events_1 = require("events");
27
27
  const uuid_1 = require("uuid");
28
+ const account_1 = require("./account.cjs");
28
29
  const DeferredPromise_1 = require("./DeferredPromise.cjs");
29
30
  const events_2 = require("./events.cjs");
30
31
  const logger_1 = require("./logger.cjs");
@@ -428,9 +429,8 @@ _SnapKeyring_messenger = new WeakMap(), _SnapKeyring_snapClient = new WeakMap(),
428
429
  async function _SnapKeyring_handleAccountCreated(snapId, message) {
429
430
  (0, superstruct_1.assert)(message, events_2.AccountCreatedEventStruct);
430
431
  const { account: newAccountFromEvent, accountNameSuggestion, displayConfirmation, } = message.params;
431
- // To keep the retro-compatibility with older keyring-api versions, we mark some fields
432
- // as optional and provide them here if they are missing.
433
- const account = (0, migrations_1.transformAccountV1)(newAccountFromEvent);
432
+ // Potentially migrate the account.
433
+ const account = (0, account_1.transformAccount)(newAccountFromEvent);
434
434
  // The UI still uses the account address to identify accounts, so we need
435
435
  // to block the creation of duplicate accounts for now to prevent accounts
436
436
  // from being overwritten.
@@ -463,9 +463,8 @@ async function _SnapKeyring_handleAccountUpdated(snapId, message) {
463
463
  const { account: newAccountFromEvent } = message.params;
464
464
  const { account: oldAccount } = __classPrivateFieldGet(this, _SnapKeyring_accounts, "f").get(snapId, newAccountFromEvent.id) ??
465
465
  (0, util_1.throwError)(`Account '${newAccountFromEvent.id}' not found`);
466
- // To keep the retro-compatibility with older keyring-api versions, we mark some fields
467
- // as optional and provide them here if they are missing.
468
- const newAccount = (0, migrations_1.transformAccountV1)(newAccountFromEvent);
466
+ // Potentially migrate the account.
467
+ const newAccount = (0, account_1.transformAccount)(newAccountFromEvent);
469
468
  // The address of the account cannot be changed. In the future, we will
470
469
  // support changing the address of an account since it will be required to
471
470
  // support UTXO-based chains.
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.cjs","sourceRoot":"","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CAC/E,CAAC;IACJ,CAAC;AACH,CAAC,qEA+Pe,OAAe;IAI7B,OAAO,CACL,CAAC,GAAG,uBAAA,IAAI,6BAAU,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAChD,IAAA,uBAAgB,EAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,IAAI,IAAA,iBAAU,EAAC,YAAY,OAAO,aAAa,CAAC,CAClD,CAAC;AACJ,CAAC,uDAQQ,MAAc;IACrB,OAAO,uBAAA,IAAI,8BAAW,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC,uEASC,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,oDAAS,MAAb,IAAI,EAAU,MAAM,CAAC,CAAC;IACnC,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACzE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,mFAQsB,IAAU;IAC/B,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,EAAE,cAAc;QACrE,EAAE,CACH,CAAC;AACJ,CAAC;AA55BM,gBAAI,GAAW,yBAAiB,AAA5B,CAA6B","sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n// This rule seems to be triggering a false positive. Possibly eslint is not\n// inferring the `EthMethod`, `BtcMethod`, and `InternalAccount` types correctly.\n\nimport type { TypedTransaction } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { ExtractEventPayload } from '@metamask/base-controller';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport {\n EthBytesStruct,\n EthMethod,\n EthBaseUserOperationStruct,\n EthUserOperationPatchStruct,\n isEvmAccountType,\n KeyringEvent,\n AccountAssetListUpdatedEventStruct,\n AccountBalancesUpdatedEventStruct,\n AccountTransactionsUpdatedEventStruct,\n} from '@metamask/keyring-api';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n KeyringResponse,\n BtcMethod,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringInternalSnapClient } from '@metamask/keyring-internal-snap-client';\nimport { strictMask } from '@metamask/keyring-utils';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { type Snap } from '@metamask/snaps-utils';\nimport { assert, mask, object, string } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport {\n bigIntToHex,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\nimport { EventEmitter } from 'events';\nimport { v4 as uuid } from 'uuid';\n\nimport { DeferredPromise } from './DeferredPromise';\nimport {\n AccountCreatedEventStruct,\n AccountUpdatedEventStruct,\n AccountDeletedEventStruct,\n RequestApprovedEventStruct,\n RequestRejectedEventStruct,\n} from './events';\nimport { projectLogger as log } from './logger';\nimport {\n isAccountV1,\n migrateAccountV1,\n transformAccountV1,\n} from './migrations';\nimport { SnapIdMap } from './SnapIdMap';\nimport type {\n SnapKeyringEvents,\n SnapKeyringMessenger,\n} from './SnapKeyringMessenger';\nimport type { SnapMessage } from './types';\nimport { SnapMessageStruct } from './types';\nimport {\n equalsIgnoreCase,\n sanitizeUrl,\n throwError,\n toJson,\n unique,\n} from './util';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n// TODO: to be removed when this is added to the keyring-api\n\ntype AccountMethod = EthMethod | BtcMethod;\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 accountNameSuggestion?: string,\n displayConfirmation?: boolean,\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 * Normalize account's address.\n *\n * @param account - The account.\n * @returns The normalized account address.\n */\nfunction normalizeAccountAddress(account: KeyringAccount): string {\n // FIXME: Is it required to lowercase the address here? For now we'll keep this behavior\n // only for Ethereum addresses and use the original address for other non-EVM accounts.\n // For example, Solana addresses are case-sensitives.\n return isEvmAccountType(account.type)\n ? account.address.toLowerCase()\n : account.address;\n}\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring extends EventEmitter {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n /**\n * Messenger to dispatch requests to the Snaps controller.\n */\n readonly #messenger: SnapKeyringMessenger;\n\n /**\n * Client used to call the Snap keyring.\n */\n readonly #snapClient: KeyringInternalSnapClient;\n\n /**\n * Mapping between account IDs and an object that contains the associated\n * account object and Snap ID.\n */\n #accounts: SnapIdMap<{\n account: KeyringAccount;\n snapId: SnapId;\n }>;\n\n /**\n * Mapping between request IDs and their deferred promises.\n */\n readonly #requests: SnapIdMap<{\n promise: DeferredPromise<any>;\n snapId: SnapId;\n }>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Create a new Snap keyring.\n *\n * @param messenger - Snap keyring messenger.\n * @param callbacks - Callbacks used to interact with other components.\n * @returns A new Snap keyring.\n */\n constructor(\n messenger: SnapKeyringMessenger,\n callbacks: SnapKeyringCallbacks,\n ) {\n super();\n this.type = SnapKeyring.type;\n this.#messenger = messenger;\n this.#snapClient = new KeyringInternalSnapClient({ messenger });\n this.#requests = new SnapIdMap();\n this.#accounts = new SnapIdMap();\n this.#callbacks = callbacks;\n }\n\n /**\n * Handle an Account Created event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountCreated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountCreatedEventStruct);\n const {\n account: newAccountFromEvent,\n accountNameSuggestion,\n displayConfirmation,\n } = message.params;\n\n // To keep the retro-compatibility with older keyring-api versions, we mark some fields\n // as optional and provide them here if they are missing.\n const account = transformAccountV1(newAccountFromEvent);\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 const address = normalizeAccountAddress(account);\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\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 if (this.#accounts.has(snapId, account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n await this.#callbacks.addAccount(\n address,\n snapId,\n async (accepted: boolean) => {\n if (accepted) {\n this.#accounts.set(account.id, { account, snapId });\n await this.#callbacks.saveState();\n }\n },\n accountNameSuggestion,\n displayConfirmation,\n );\n return null;\n }\n\n /**\n * Handle an Account Updated event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountUpdated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountUpdatedEventStruct);\n const { account: newAccountFromEvent } = message.params;\n const { account: oldAccount } =\n this.#accounts.get(snapId, newAccountFromEvent.id) ??\n throwError(`Account '${newAccountFromEvent.id}' not found`);\n\n // To keep the retro-compatibility with older keyring-api versions, we mark some fields\n // as optional and provide them here if they are missing.\n const newAccount = transformAccountV1(newAccountFromEvent);\n\n // The address of the account cannot be changed. In the future, we will\n // support changing the address of an account since it will be required to\n // support UTXO-based chains.\n if (!equalsIgnoreCase(oldAccount.address, newAccount.address)) {\n throw new Error(`Cannot change address of account '${newAccount.id}'`);\n }\n\n this.#accounts.set(newAccount.id, { account: newAccount, snapId });\n await this.#callbacks.saveState();\n return null;\n }\n\n /**\n * Handle an Account Deleted event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountDeleted(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountDeletedEventStruct);\n const { id } = message.params;\n const entry = this.#accounts.get(snapId, id);\n\n // We can ignore the case where the account was already removed from the\n // keyring, making the deletion idempotent.\n //\n // This happens when the keyring calls the Snap to delete an account, and\n // the Snap calls the keyring back with an `AccountDeleted` event.\n if (entry === undefined) {\n return null;\n }\n\n // At this point we know that the account exists, so we can safely\n // destructure it.\n const { account } = entry;\n\n await this.#callbacks.removeAccount(\n normalizeAccountAddress(account),\n snapId,\n async (accepted) => {\n if (accepted) {\n await this.#callbacks.saveState();\n }\n },\n );\n return null;\n }\n\n /**\n * Handle an Request Approved event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestApproved(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestApprovedEventStruct);\n const { id, result } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.resolve(result);\n return null;\n }\n\n /**\n * Handle an Request Rejected event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestRejected(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestRejectedEventStruct);\n const { id } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.reject(new Error(`Request rejected by user or snap.`));\n return null;\n }\n\n /**\n * Re-publish an account event.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @template EventType - A Snap keyring event type.\n * @returns `null`.\n */\n async #rePublishAccountEvent<EventType extends SnapKeyringEvents['type']>(\n event: EventType,\n ...payload: ExtractEventPayload<SnapKeyringEvents, EventType>\n ): Promise<null> {\n this.#messenger.publish(event, ...payload);\n return null;\n }\n\n /**\n * Handle a balances updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountBalancesUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountBalancesUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountBalancesUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a asset list updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountAssetListUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountAssetListUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountAssetListUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a transactions updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountTransactionsUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountTransactionsUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountTransactionsUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a message from a Snap.\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 assert(message, SnapMessageStruct);\n switch (message.method) {\n case `${KeyringEvent.AccountCreated}`: {\n return this.#handleAccountCreated(snapId, message);\n }\n\n case `${KeyringEvent.AccountUpdated}`: {\n return this.#handleAccountUpdated(snapId, message);\n }\n\n case `${KeyringEvent.AccountDeleted}`: {\n return this.#handleAccountDeleted(snapId, message);\n }\n\n case `${KeyringEvent.RequestApproved}`: {\n return this.#handleRequestApproved(snapId, message);\n }\n\n case `${KeyringEvent.RequestRejected}`: {\n return this.#handleRequestRejected(snapId, message);\n }\n\n // Assets related events:\n case `${KeyringEvent.AccountBalancesUpdated}`: {\n return this.#handleAccountBalancesUpdated(message);\n }\n\n case `${KeyringEvent.AccountAssetListUpdated}`: {\n return this.#handleAccountAssetListUpdated(message);\n }\n\n case `${KeyringEvent.AccountTransactionsUpdated}`: {\n return this.#handleAccountTransactionsUpdated(message);\n }\n\n default:\n throw new Error(`Method not supported: ${message.method}`);\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n return {\n accounts: this.#accounts.toObject(),\n };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\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 // Running Snap keyring migrations. We might have some accounts that have a\n // different \"version\" than the one we expect.\n // In this case, we \"transform\" then directly when deserializing to convert\n // them in the final account version.\n const accounts: KeyringState['accounts'] = {};\n for (const [snapId, entry] of Object.entries(state.accounts)) {\n // V1 accounts are missing the scopes.\n if (isAccountV1(entry.account)) {\n console.info(\n `SnapKeyring - Found a KeyringAccountV1, migrating to V2: ${entry.account.id}`,\n );\n accounts[snapId] = {\n ...entry,\n account: migrateAccountV1(entry.account),\n };\n } else {\n accounts[snapId] = entry;\n }\n }\n\n this.#accounts = SnapIdMap.fromObject(accounts);\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 return unique(\n [...this.#accounts.values()].map(({ account }) =>\n normalizeAccountAddress(account),\n ),\n );\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.#accounts.values()]\n .filter(({ snapId: accountSnapId }) => accountSnapId === snapId)\n .map(({ account }) => normalizeAccountAddress(account)),\n );\n }\n\n /**\n * Submit a request to a Snap.\n *\n * @param opts - Request options.\n * @param opts.address - Account address.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.chainId - Selected chain ID (CAIP-2).\n * @param opts.noPending - Whether the response is allowed to be pending.\n * @returns Promise that resolves to the result of the method call.\n */\n async #submitRequest<Response extends Json>({\n address,\n method,\n params,\n chainId = '',\n noPending = false,\n }: {\n address: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n chainId?: string;\n noPending?: boolean;\n }): Promise<Json> {\n const { account, snapId } = this.#resolveAddress(address);\n if (!this.#hasMethod(account, method as AccountMethod)) {\n throw new Error(\n `Method '${method}' not supported for account ${account.address}`,\n );\n }\n\n const requestId = uuid();\n\n // Create the promise before calling the Snap to prevent a race condition\n // where the Snap responds before we have a chance to create it.\n const promise = this.#createRequestPromise<Response>(requestId, snapId);\n\n const response = await this.#submitSnapRequest({\n snapId,\n requestId,\n account,\n method: method as AccountMethod,\n params,\n chainId,\n });\n\n // Some methods, like the ones used to prepare and patch user operations,\n // require the Snap to answer synchronously in order to work with the\n // confirmation flow. This check lets the caller enforce this behavior.\n if (noPending && response.pending) {\n throw new Error(\n `Request '${requestId}' to snap '${snapId}' is pending and noPending is true.`,\n );\n }\n\n // If the Snap answers synchronously, the promise must be removed from the\n // map to prevent a leak.\n if (!response.pending) {\n return this.#handleSyncResponse(response, requestId, snapId);\n }\n\n // If the Snap answers asynchronously, we will inform the user with a redirect\n if (response.redirect?.message || response.redirect?.url) {\n await this.#handleAsyncResponse(response.redirect, snapId);\n }\n\n return promise.promise;\n }\n\n /**\n * Check if an account supports the given method.\n *\n * @param account - The account object to check for method support.\n * @param method - The Ethereum method to validate.\n * @returns `true` if the method is supported, `false` otherwise.\n */\n #hasMethod(account: KeyringAccount, method: AccountMethod): boolean {\n return (account.methods as AccountMethod[]).includes(method);\n }\n\n /**\n * Creates a promise for a request and adds it to the map of requests.\n *\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns A DeferredPromise instance.\n */\n #createRequestPromise<Response>(\n requestId: string,\n snapId: SnapId,\n ): DeferredPromise<Response> {\n const promise = new DeferredPromise<Response>();\n this.#requests.set(requestId, { promise, snapId });\n return promise;\n }\n\n /**\n * Submits a request to a Snap.\n *\n * @param options - The options for the Snap request.\n * @param options.snapId - The Snap ID to submit the request to.\n * @param options.requestId - The unique identifier for the request.\n * @param options.account - The account to use for the request.\n * @param options.method - The Ethereum method to call.\n * @param options.params - The parameters to pass to the method, can be undefined.\n * @param options.chainId - The chain ID to use for the request, can be an empty string.\n * @returns A promise that resolves to the keyring response from the Snap.\n * @throws An error if the Snap fails to respond or if there's an issue with the request submission.\n */\n async #submitSnapRequest({\n snapId,\n requestId,\n account,\n method,\n params,\n chainId,\n }: {\n snapId: SnapId;\n requestId: string;\n account: KeyringAccount;\n method: AccountMethod;\n params?: Json[] | Record<string, Json> | undefined;\n chainId: string;\n }): Promise<KeyringResponse> {\n try {\n const request = {\n id: requestId,\n scope: chainId,\n account: account.id,\n request: {\n method,\n ...(params !== undefined && { params }),\n },\n };\n\n log('Submit Snap request: ', request);\n\n return await this.#snapClient.withSnapId(snapId).submitRequest(request);\n } catch (error) {\n log('Snap Request failed: ', { requestId });\n\n // If the Snap failed to respond, delete the promise to prevent a leak.\n this.#requests.delete(snapId, requestId);\n throw error;\n }\n }\n\n /**\n * Handles the synchronous response from a Snap. If the response indicates the request is not pending, it removes the request from the map.\n *\n * @param response - The response from the Snap.\n * @param response.pending - A boolean indicating if the request is pending should always be false in this context.\n * @param response.result - The result data from the Snap response.\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns The result from the Snap response.\n */\n #handleSyncResponse(\n response: { pending: false; result: Json },\n requestId: string,\n snapId: SnapId,\n ): Json {\n this.#requests.delete(snapId, requestId);\n return response.result;\n }\n\n /**\n * Handles the async redirect and response from a Snap. Validates the redirect URL and informs the user with a message and URL if provided.\n *\n * @param redirect - The redirect information including message and URL.\n * @param redirect.message - The message to show to the user if provided.\n * @param redirect.url - The URL to redirect the user to if provided.\n * @param snapId - The Snap ID associated with the request.\n * @throws An error if the redirect URL is not an allowed origin for the Snap.\n */\n async #handleAsyncResponse(\n redirect: { message?: string; url?: string },\n snapId: SnapId,\n ): Promise<void> {\n const { message = '', url: redirectUrl = '' } = redirect;\n const url = this.#sanitizeRedirectUrl(redirectUrl);\n if (url) {\n this.#validateRedirectUrl(url, snapId);\n }\n await this.#callbacks.redirectUser(snapId, url, message);\n }\n\n /**\n * Sanitize a redirect URL.\n *\n * @param url - The URL to sanitize.\n * @returns The new sanitized redirect URL.\n */\n #sanitizeRedirectUrl(url: string): string {\n // We do check if the URL is empty or not since the Snap might not returns any URL at all.\n return url ? sanitizeUrl(url) : url;\n }\n\n /**\n * Validates if the redirect URL is in the Snap's allowed origins.\n *\n * @param url - The URL to validate.\n * @param snapId - The Snap ID to check allowed origins for.\n * @throws An error if the URL's origin is not in the Snap's allowed origins.\n */\n #validateRedirectUrl(url: string, snapId: SnapId): void {\n const { origin } = new URL(url);\n const snap = this.#getSnap(snapId);\n if (!snap) {\n throw new Error(`Snap '${snapId}' not found.`);\n }\n const allowedOrigins = this.#getSnapAllowedOrigins(snap);\n if (!allowedOrigins.includes(origin)) {\n throw new Error(\n `Redirect URL domain '${origin}' is not an allowed origin by snap '${snapId}'`,\n );\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 chainId = transaction.common.chainId();\n const tx = toJson({\n ...transaction.toJSON(),\n from: address,\n type: `0x${transaction.type.toString(16)}`,\n chainId: bigIntToHex(chainId),\n });\n\n const signedTx = await this.#submitRequest({\n address,\n method: EthMethod.SignTransaction,\n params: [tx],\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n });\n\n // ! It's *** CRITICAL *** that we mask the signature here, otherwise the\n // ! Snap could overwrite the transaction.\n const signature = mask(\n signedTx,\n object({\n r: string(),\n s: string(),\n v: string(),\n }),\n );\n\n return TransactionFactory.fromTxData({\n ...(tx as Record<string, Json>),\n r: signature.r,\n s: signature.s,\n v: signature.v,\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 methods = {\n [SignTypedDataVersion.V1]: EthMethod.SignTypedDataV1,\n [SignTypedDataVersion.V3]: EthMethod.SignTypedDataV3,\n [SignTypedDataVersion.V4]: EthMethod.SignTypedDataV4,\n };\n\n // Use 'V1' by default to match other keyring implementations. V1 will be\n // used if the version is not specified or not supported.\n const method = methods[opts.version] || EthMethod.SignTypedDataV1;\n\n // Extract chain ID as if it was a typed message (as defined by EIP-712), if\n // input is not a typed message, then chain ID will be undefined!\n const chainId = (data as TypedMessage<any>).domain?.chainId;\n\n return strictMask(\n await this.#submitRequest({\n address,\n method,\n params: toJson<Json[]>([address, data]),\n ...(chainId === undefined\n ? {}\n : {\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n }),\n }),\n EthBytesStruct,\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.Sign,\n params: toJson<Json[]>([address, hash]),\n }),\n EthBytesStruct,\n );\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PersonalSign,\n params: toJson<Json[]>([data, address]),\n }),\n EthBytesStruct,\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PrepareUserOperation,\n params: toJson<Json[]>(transactions),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBaseUserOperationStruct,\n );\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PatchUserOperation,\n params: toJson<Json[]>([userOp]),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthUserOperationPatchStruct,\n );\n }\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Leyring 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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.SignUserOperation,\n params: toJson<Json[]>([userOp]),\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBytesStruct,\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 * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, snapId } = this.#resolveAddress(address);\n\n // Always remove the account from the maps, even if the Snap is going to\n // fail to delete it.\n this.#accounts.delete(snapId, account.id);\n\n try {\n await this.#snapClient.withSnapId(snapId).deleteAccount(account.id);\n } catch (error) {\n // If the Snap failed to delete the account, log the error and continue\n // with the account deletion, otherwise the account will be stuck in the\n // keyring.\n console.error(\n `Account '${address}' may not have been removed from snap '${snapId}':`,\n error,\n );\n }\n }\n\n /**\n * Resolve an address to an account and Snap ID.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and Snap ID. Throws if the account or Snap ID is not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n snapId: SnapId;\n } {\n return (\n [...this.#accounts.values()].find(({ account }) =>\n equalsIgnoreCase(account.address, address),\n ) ?? throwError(`Account '${address}' not found`)\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 | undefined {\n return this.#messenger.call('SnapController:get', snapId);\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#getSnap(snapId);\n return snap\n ? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }\n : undefined;\n }\n\n /**\n * Get the allowed origins of a Snap.\n *\n * @param snap - Snap.\n * @returns The allowed origins of the Snap.\n */\n #getSnapAllowedOrigins(snap: Snap): string[] {\n return (\n snap.manifest.initialPermissions['endowment:keyring']?.allowedOrigins ??\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 const accounts = this.listAccounts();\n return accounts.find(({ address: accountAddress }) =>\n equalsIgnoreCase(accountAddress, address),\n );\n }\n\n /**\n * List all Snap keyring accounts.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n return [...this.#accounts.values()].map(({ account, snapId }) => {\n const snap = this.#getSnapMetadata(snapId);\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"]}
1
+ {"version":3,"file":"SnapKeyring.cjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,iFAAiF;;;;;;;;;;;;;;;AAGjF,uCAAoD;AAGpD,yDAA8D;AAC9D,uDAU+B;AAY/B,yFAAmF;AACnF,2DAAqD;AAGrD,uDAAqE;AAErE,2CAIyB;AACzB,mCAAsC;AACtC,+BAAkC;AAElC,2CAA6C;AAC7C,2DAAoD;AACpD,yCAMkB;AAClB,yCAAgD;AAChD,uDAA6D;AAC7D,+CAAwC;AAMxC,uCAA4C;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AO,uBAAA,IAAI,8BAAW,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC,uEASC,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,oDAAS,MAAb,IAAI,EAAU,MAAM,CAAC,CAAC;IACnC,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACzE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,mFAQsB,IAAU;IAC/B,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,EAAE,cAAc;QACrE,EAAE,CACH,CAAC;AACJ,CAAC;AA15BM,gBAAI,GAAW,yBAAiB,AAA5B,CAA6B","sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n// This rule seems to be triggering a false positive. Possibly eslint is not\n// inferring the `EthMethod`, `BtcMethod`, and `InternalAccount` types correctly.\n\nimport type { TypedTransaction } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { ExtractEventPayload } from '@metamask/base-controller';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport {\n EthBytesStruct,\n EthMethod,\n EthBaseUserOperationStruct,\n EthUserOperationPatchStruct,\n isEvmAccountType,\n KeyringEvent,\n AccountAssetListUpdatedEventStruct,\n AccountBalancesUpdatedEventStruct,\n AccountTransactionsUpdatedEventStruct,\n} from '@metamask/keyring-api';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n KeyringResponse,\n BtcMethod,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringInternalSnapClient } from '@metamask/keyring-internal-snap-client';\nimport { strictMask } from '@metamask/keyring-utils';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { type Snap } from '@metamask/snaps-utils';\nimport { assert, mask, object, string } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport {\n bigIntToHex,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\nimport { EventEmitter } from 'events';\nimport { v4 as uuid } from 'uuid';\n\nimport { transformAccount } from './account';\nimport { DeferredPromise } from './DeferredPromise';\nimport {\n AccountCreatedEventStruct,\n AccountUpdatedEventStruct,\n AccountDeletedEventStruct,\n RequestApprovedEventStruct,\n RequestRejectedEventStruct,\n} from './events';\nimport { projectLogger as log } from './logger';\nimport { isAccountV1, migrateAccountV1 } from './migrations';\nimport { SnapIdMap } from './SnapIdMap';\nimport type {\n SnapKeyringEvents,\n SnapKeyringMessenger,\n} from './SnapKeyringMessenger';\nimport type { SnapMessage } from './types';\nimport { SnapMessageStruct } from './types';\nimport {\n equalsIgnoreCase,\n sanitizeUrl,\n throwError,\n toJson,\n unique,\n} from './util';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n// TODO: to be removed when this is added to the keyring-api\n\ntype AccountMethod = EthMethod | BtcMethod;\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 accountNameSuggestion?: string,\n displayConfirmation?: boolean,\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 * Normalize account's address.\n *\n * @param account - The account.\n * @returns The normalized account address.\n */\nfunction normalizeAccountAddress(account: KeyringAccount): string {\n // FIXME: Is it required to lowercase the address here? For now we'll keep this behavior\n // only for Ethereum addresses and use the original address for other non-EVM accounts.\n // For example, Solana addresses are case-sensitives.\n return isEvmAccountType(account.type)\n ? account.address.toLowerCase()\n : account.address;\n}\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring extends EventEmitter {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n /**\n * Messenger to dispatch requests to the Snaps controller.\n */\n readonly #messenger: SnapKeyringMessenger;\n\n /**\n * Client used to call the Snap keyring.\n */\n readonly #snapClient: KeyringInternalSnapClient;\n\n /**\n * Mapping between account IDs and an object that contains the associated\n * account object and Snap ID.\n */\n #accounts: SnapIdMap<{\n account: KeyringAccount;\n snapId: SnapId;\n }>;\n\n /**\n * Mapping between request IDs and their deferred promises.\n */\n readonly #requests: SnapIdMap<{\n promise: DeferredPromise<any>;\n snapId: SnapId;\n }>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Create a new Snap keyring.\n *\n * @param messenger - Snap keyring messenger.\n * @param callbacks - Callbacks used to interact with other components.\n * @returns A new Snap keyring.\n */\n constructor(\n messenger: SnapKeyringMessenger,\n callbacks: SnapKeyringCallbacks,\n ) {\n super();\n this.type = SnapKeyring.type;\n this.#messenger = messenger;\n this.#snapClient = new KeyringInternalSnapClient({ messenger });\n this.#requests = new SnapIdMap();\n this.#accounts = new SnapIdMap();\n this.#callbacks = callbacks;\n }\n\n /**\n * Handle an Account Created event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountCreated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountCreatedEventStruct);\n const {\n account: newAccountFromEvent,\n accountNameSuggestion,\n displayConfirmation,\n } = message.params;\n\n // Potentially migrate the account.\n const account = transformAccount(newAccountFromEvent);\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 const address = normalizeAccountAddress(account);\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\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 if (this.#accounts.has(snapId, account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n await this.#callbacks.addAccount(\n address,\n snapId,\n async (accepted: boolean) => {\n if (accepted) {\n this.#accounts.set(account.id, { account, snapId });\n await this.#callbacks.saveState();\n }\n },\n accountNameSuggestion,\n displayConfirmation,\n );\n return null;\n }\n\n /**\n * Handle an Account Updated event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountUpdated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountUpdatedEventStruct);\n const { account: newAccountFromEvent } = message.params;\n const { account: oldAccount } =\n this.#accounts.get(snapId, newAccountFromEvent.id) ??\n throwError(`Account '${newAccountFromEvent.id}' not found`);\n\n // Potentially migrate the account.\n const newAccount = transformAccount(newAccountFromEvent);\n\n // The address of the account cannot be changed. In the future, we will\n // support changing the address of an account since it will be required to\n // support UTXO-based chains.\n if (!equalsIgnoreCase(oldAccount.address, newAccount.address)) {\n throw new Error(`Cannot change address of account '${newAccount.id}'`);\n }\n\n this.#accounts.set(newAccount.id, { account: newAccount, snapId });\n await this.#callbacks.saveState();\n return null;\n }\n\n /**\n * Handle an Account Deleted event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountDeleted(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountDeletedEventStruct);\n const { id } = message.params;\n const entry = this.#accounts.get(snapId, id);\n\n // We can ignore the case where the account was already removed from the\n // keyring, making the deletion idempotent.\n //\n // This happens when the keyring calls the Snap to delete an account, and\n // the Snap calls the keyring back with an `AccountDeleted` event.\n if (entry === undefined) {\n return null;\n }\n\n // At this point we know that the account exists, so we can safely\n // destructure it.\n const { account } = entry;\n\n await this.#callbacks.removeAccount(\n normalizeAccountAddress(account),\n snapId,\n async (accepted) => {\n if (accepted) {\n await this.#callbacks.saveState();\n }\n },\n );\n return null;\n }\n\n /**\n * Handle an Request Approved event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestApproved(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestApprovedEventStruct);\n const { id, result } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.resolve(result);\n return null;\n }\n\n /**\n * Handle an Request Rejected event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestRejected(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestRejectedEventStruct);\n const { id } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.reject(new Error(`Request rejected by user or snap.`));\n return null;\n }\n\n /**\n * Re-publish an account event.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @template EventType - A Snap keyring event type.\n * @returns `null`.\n */\n async #rePublishAccountEvent<EventType extends SnapKeyringEvents['type']>(\n event: EventType,\n ...payload: ExtractEventPayload<SnapKeyringEvents, EventType>\n ): Promise<null> {\n this.#messenger.publish(event, ...payload);\n return null;\n }\n\n /**\n * Handle a balances updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountBalancesUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountBalancesUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountBalancesUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a asset list updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountAssetListUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountAssetListUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountAssetListUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a transactions updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountTransactionsUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountTransactionsUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountTransactionsUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a message from a Snap.\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 assert(message, SnapMessageStruct);\n switch (message.method) {\n case `${KeyringEvent.AccountCreated}`: {\n return this.#handleAccountCreated(snapId, message);\n }\n\n case `${KeyringEvent.AccountUpdated}`: {\n return this.#handleAccountUpdated(snapId, message);\n }\n\n case `${KeyringEvent.AccountDeleted}`: {\n return this.#handleAccountDeleted(snapId, message);\n }\n\n case `${KeyringEvent.RequestApproved}`: {\n return this.#handleRequestApproved(snapId, message);\n }\n\n case `${KeyringEvent.RequestRejected}`: {\n return this.#handleRequestRejected(snapId, message);\n }\n\n // Assets related events:\n case `${KeyringEvent.AccountBalancesUpdated}`: {\n return this.#handleAccountBalancesUpdated(message);\n }\n\n case `${KeyringEvent.AccountAssetListUpdated}`: {\n return this.#handleAccountAssetListUpdated(message);\n }\n\n case `${KeyringEvent.AccountTransactionsUpdated}`: {\n return this.#handleAccountTransactionsUpdated(message);\n }\n\n default:\n throw new Error(`Method not supported: ${message.method}`);\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n return {\n accounts: this.#accounts.toObject(),\n };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\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 // Running Snap keyring migrations. We might have some accounts that have a\n // different \"version\" than the one we expect.\n // In this case, we \"transform\" then directly when deserializing to convert\n // them in the final account version.\n const accounts: KeyringState['accounts'] = {};\n for (const [snapId, entry] of Object.entries(state.accounts)) {\n // V1 accounts are missing the scopes.\n if (isAccountV1(entry.account)) {\n console.info(\n `SnapKeyring - Found a KeyringAccountV1, migrating to V2: ${entry.account.id}`,\n );\n accounts[snapId] = {\n ...entry,\n account: migrateAccountV1(entry.account),\n };\n } else {\n accounts[snapId] = entry;\n }\n }\n\n this.#accounts = SnapIdMap.fromObject(accounts);\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 return unique(\n [...this.#accounts.values()].map(({ account }) =>\n normalizeAccountAddress(account),\n ),\n );\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.#accounts.values()]\n .filter(({ snapId: accountSnapId }) => accountSnapId === snapId)\n .map(({ account }) => normalizeAccountAddress(account)),\n );\n }\n\n /**\n * Submit a request to a Snap.\n *\n * @param opts - Request options.\n * @param opts.address - Account address.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.chainId - Selected chain ID (CAIP-2).\n * @param opts.noPending - Whether the response is allowed to be pending.\n * @returns Promise that resolves to the result of the method call.\n */\n async #submitRequest<Response extends Json>({\n address,\n method,\n params,\n chainId = '',\n noPending = false,\n }: {\n address: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n chainId?: string;\n noPending?: boolean;\n }): Promise<Json> {\n const { account, snapId } = this.#resolveAddress(address);\n if (!this.#hasMethod(account, method as AccountMethod)) {\n throw new Error(\n `Method '${method}' not supported for account ${account.address}`,\n );\n }\n\n const requestId = uuid();\n\n // Create the promise before calling the Snap to prevent a race condition\n // where the Snap responds before we have a chance to create it.\n const promise = this.#createRequestPromise<Response>(requestId, snapId);\n\n const response = await this.#submitSnapRequest({\n snapId,\n requestId,\n account,\n method: method as AccountMethod,\n params,\n chainId,\n });\n\n // Some methods, like the ones used to prepare and patch user operations,\n // require the Snap to answer synchronously in order to work with the\n // confirmation flow. This check lets the caller enforce this behavior.\n if (noPending && response.pending) {\n throw new Error(\n `Request '${requestId}' to snap '${snapId}' is pending and noPending is true.`,\n );\n }\n\n // If the Snap answers synchronously, the promise must be removed from the\n // map to prevent a leak.\n if (!response.pending) {\n return this.#handleSyncResponse(response, requestId, snapId);\n }\n\n // If the Snap answers asynchronously, we will inform the user with a redirect\n if (response.redirect?.message || response.redirect?.url) {\n await this.#handleAsyncResponse(response.redirect, snapId);\n }\n\n return promise.promise;\n }\n\n /**\n * Check if an account supports the given method.\n *\n * @param account - The account object to check for method support.\n * @param method - The Ethereum method to validate.\n * @returns `true` if the method is supported, `false` otherwise.\n */\n #hasMethod(account: KeyringAccount, method: AccountMethod): boolean {\n return (account.methods as AccountMethod[]).includes(method);\n }\n\n /**\n * Creates a promise for a request and adds it to the map of requests.\n *\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns A DeferredPromise instance.\n */\n #createRequestPromise<Response>(\n requestId: string,\n snapId: SnapId,\n ): DeferredPromise<Response> {\n const promise = new DeferredPromise<Response>();\n this.#requests.set(requestId, { promise, snapId });\n return promise;\n }\n\n /**\n * Submits a request to a Snap.\n *\n * @param options - The options for the Snap request.\n * @param options.snapId - The Snap ID to submit the request to.\n * @param options.requestId - The unique identifier for the request.\n * @param options.account - The account to use for the request.\n * @param options.method - The Ethereum method to call.\n * @param options.params - The parameters to pass to the method, can be undefined.\n * @param options.chainId - The chain ID to use for the request, can be an empty string.\n * @returns A promise that resolves to the keyring response from the Snap.\n * @throws An error if the Snap fails to respond or if there's an issue with the request submission.\n */\n async #submitSnapRequest({\n snapId,\n requestId,\n account,\n method,\n params,\n chainId,\n }: {\n snapId: SnapId;\n requestId: string;\n account: KeyringAccount;\n method: AccountMethod;\n params?: Json[] | Record<string, Json> | undefined;\n chainId: string;\n }): Promise<KeyringResponse> {\n try {\n const request = {\n id: requestId,\n scope: chainId,\n account: account.id,\n request: {\n method,\n ...(params !== undefined && { params }),\n },\n };\n\n log('Submit Snap request: ', request);\n\n return await this.#snapClient.withSnapId(snapId).submitRequest(request);\n } catch (error) {\n log('Snap Request failed: ', { requestId });\n\n // If the Snap failed to respond, delete the promise to prevent a leak.\n this.#requests.delete(snapId, requestId);\n throw error;\n }\n }\n\n /**\n * Handles the synchronous response from a Snap. If the response indicates the request is not pending, it removes the request from the map.\n *\n * @param response - The response from the Snap.\n * @param response.pending - A boolean indicating if the request is pending should always be false in this context.\n * @param response.result - The result data from the Snap response.\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns The result from the Snap response.\n */\n #handleSyncResponse(\n response: { pending: false; result: Json },\n requestId: string,\n snapId: SnapId,\n ): Json {\n this.#requests.delete(snapId, requestId);\n return response.result;\n }\n\n /**\n * Handles the async redirect and response from a Snap. Validates the redirect URL and informs the user with a message and URL if provided.\n *\n * @param redirect - The redirect information including message and URL.\n * @param redirect.message - The message to show to the user if provided.\n * @param redirect.url - The URL to redirect the user to if provided.\n * @param snapId - The Snap ID associated with the request.\n * @throws An error if the redirect URL is not an allowed origin for the Snap.\n */\n async #handleAsyncResponse(\n redirect: { message?: string; url?: string },\n snapId: SnapId,\n ): Promise<void> {\n const { message = '', url: redirectUrl = '' } = redirect;\n const url = this.#sanitizeRedirectUrl(redirectUrl);\n if (url) {\n this.#validateRedirectUrl(url, snapId);\n }\n await this.#callbacks.redirectUser(snapId, url, message);\n }\n\n /**\n * Sanitize a redirect URL.\n *\n * @param url - The URL to sanitize.\n * @returns The new sanitized redirect URL.\n */\n #sanitizeRedirectUrl(url: string): string {\n // We do check if the URL is empty or not since the Snap might not returns any URL at all.\n return url ? sanitizeUrl(url) : url;\n }\n\n /**\n * Validates if the redirect URL is in the Snap's allowed origins.\n *\n * @param url - The URL to validate.\n * @param snapId - The Snap ID to check allowed origins for.\n * @throws An error if the URL's origin is not in the Snap's allowed origins.\n */\n #validateRedirectUrl(url: string, snapId: SnapId): void {\n const { origin } = new URL(url);\n const snap = this.#getSnap(snapId);\n if (!snap) {\n throw new Error(`Snap '${snapId}' not found.`);\n }\n const allowedOrigins = this.#getSnapAllowedOrigins(snap);\n if (!allowedOrigins.includes(origin)) {\n throw new Error(\n `Redirect URL domain '${origin}' is not an allowed origin by snap '${snapId}'`,\n );\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 chainId = transaction.common.chainId();\n const tx = toJson({\n ...transaction.toJSON(),\n from: address,\n type: `0x${transaction.type.toString(16)}`,\n chainId: bigIntToHex(chainId),\n });\n\n const signedTx = await this.#submitRequest({\n address,\n method: EthMethod.SignTransaction,\n params: [tx],\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n });\n\n // ! It's *** CRITICAL *** that we mask the signature here, otherwise the\n // ! Snap could overwrite the transaction.\n const signature = mask(\n signedTx,\n object({\n r: string(),\n s: string(),\n v: string(),\n }),\n );\n\n return TransactionFactory.fromTxData({\n ...(tx as Record<string, Json>),\n r: signature.r,\n s: signature.s,\n v: signature.v,\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 methods = {\n [SignTypedDataVersion.V1]: EthMethod.SignTypedDataV1,\n [SignTypedDataVersion.V3]: EthMethod.SignTypedDataV3,\n [SignTypedDataVersion.V4]: EthMethod.SignTypedDataV4,\n };\n\n // Use 'V1' by default to match other keyring implementations. V1 will be\n // used if the version is not specified or not supported.\n const method = methods[opts.version] || EthMethod.SignTypedDataV1;\n\n // Extract chain ID as if it was a typed message (as defined by EIP-712), if\n // input is not a typed message, then chain ID will be undefined!\n const chainId = (data as TypedMessage<any>).domain?.chainId;\n\n return strictMask(\n await this.#submitRequest({\n address,\n method,\n params: toJson<Json[]>([address, data]),\n ...(chainId === undefined\n ? {}\n : {\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n }),\n }),\n EthBytesStruct,\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.Sign,\n params: toJson<Json[]>([address, hash]),\n }),\n EthBytesStruct,\n );\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PersonalSign,\n params: toJson<Json[]>([data, address]),\n }),\n EthBytesStruct,\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PrepareUserOperation,\n params: toJson<Json[]>(transactions),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBaseUserOperationStruct,\n );\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PatchUserOperation,\n params: toJson<Json[]>([userOp]),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthUserOperationPatchStruct,\n );\n }\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Leyring 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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.SignUserOperation,\n params: toJson<Json[]>([userOp]),\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBytesStruct,\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 * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, snapId } = this.#resolveAddress(address);\n\n // Always remove the account from the maps, even if the Snap is going to\n // fail to delete it.\n this.#accounts.delete(snapId, account.id);\n\n try {\n await this.#snapClient.withSnapId(snapId).deleteAccount(account.id);\n } catch (error) {\n // If the Snap failed to delete the account, log the error and continue\n // with the account deletion, otherwise the account will be stuck in the\n // keyring.\n console.error(\n `Account '${address}' may not have been removed from snap '${snapId}':`,\n error,\n );\n }\n }\n\n /**\n * Resolve an address to an account and Snap ID.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and Snap ID. Throws if the account or Snap ID is not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n snapId: SnapId;\n } {\n return (\n [...this.#accounts.values()].find(({ account }) =>\n equalsIgnoreCase(account.address, address),\n ) ?? throwError(`Account '${address}' not found`)\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 | undefined {\n return this.#messenger.call('SnapController:get', snapId);\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#getSnap(snapId);\n return snap\n ? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }\n : undefined;\n }\n\n /**\n * Get the allowed origins of a Snap.\n *\n * @param snap - Snap.\n * @returns The allowed origins of the Snap.\n */\n #getSnapAllowedOrigins(snap: Snap): string[] {\n return (\n snap.manifest.initialPermissions['endowment:keyring']?.allowedOrigins ??\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 const accounts = this.listAccounts();\n return accounts.find(({ address: accountAddress }) =>\n equalsIgnoreCase(accountAddress, address),\n );\n }\n\n /**\n * List all Snap keyring accounts.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n return [...this.#accounts.values()].map(({ account, snapId }) => {\n const snap = this.#getSnapMetadata(snapId);\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.d.cts","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AAGvD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,+BAA+B;AACxE,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAY9D,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EAGvB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACtB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAGlD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,EAAE,YAAY,EAAE,eAAe;AAkBtC,OAAO,KAAK,EAEV,oBAAoB,EACrB,mCAA+B;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAgB;AAU3C,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAMhD;;;;;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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;;;;;;OASG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAWtE;;;;;;;OAOG;IACG,oBAAoB,CACxB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,kBAAkB,EAAE,EAClC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,oBAAoB,CAAC;IAchC;;;;;;;;OAQG;IACG,kBAAkB,CACtB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IAcjC;;;;;;;OAOG;IACG,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC;IAalB;;;;;;;;;;OAUG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,SAAS;IAI/D;;;;OAIG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4EnD;;;;;OAKG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAOjE;;;;OAIG;IACH,YAAY,IAAI,eAAe,EAAE;CA0BlC"}
@@ -22,10 +22,11 @@ import { assert, mask, object, string } from "@metamask/superstruct";
22
22
  import { bigIntToHex, KnownCaipNamespace, toCaipChainId } from "@metamask/utils";
23
23
  import { EventEmitter } from "events";
24
24
  import { v4 as uuid } from "uuid";
25
+ import { transformAccount } from "./account.mjs";
25
26
  import { DeferredPromise } from "./DeferredPromise.mjs";
26
27
  import { AccountCreatedEventStruct, AccountUpdatedEventStruct, AccountDeletedEventStruct, RequestApprovedEventStruct, RequestRejectedEventStruct } from "./events.mjs";
27
28
  import { projectLogger as log } from "./logger.mjs";
28
- import { isAccountV1, migrateAccountV1, transformAccountV1 } from "./migrations/index.mjs";
29
+ import { isAccountV1, migrateAccountV1 } from "./migrations/index.mjs";
29
30
  import { SnapIdMap } from "./SnapIdMap.mjs";
30
31
  import { SnapMessageStruct } from "./types.mjs";
31
32
  import { equalsIgnoreCase, sanitizeUrl, throwError, toJson, unique } from "./util.mjs";
@@ -424,9 +425,8 @@ _SnapKeyring_messenger = new WeakMap(), _SnapKeyring_snapClient = new WeakMap(),
424
425
  async function _SnapKeyring_handleAccountCreated(snapId, message) {
425
426
  assert(message, AccountCreatedEventStruct);
426
427
  const { account: newAccountFromEvent, accountNameSuggestion, displayConfirmation, } = message.params;
427
- // To keep the retro-compatibility with older keyring-api versions, we mark some fields
428
- // as optional and provide them here if they are missing.
429
- const account = transformAccountV1(newAccountFromEvent);
428
+ // Potentially migrate the account.
429
+ const account = transformAccount(newAccountFromEvent);
430
430
  // The UI still uses the account address to identify accounts, so we need
431
431
  // to block the creation of duplicate accounts for now to prevent accounts
432
432
  // from being overwritten.
@@ -459,9 +459,8 @@ async function _SnapKeyring_handleAccountUpdated(snapId, message) {
459
459
  const { account: newAccountFromEvent } = message.params;
460
460
  const { account: oldAccount } = __classPrivateFieldGet(this, _SnapKeyring_accounts, "f").get(snapId, newAccountFromEvent.id) ??
461
461
  throwError(`Account '${newAccountFromEvent.id}' not found`);
462
- // To keep the retro-compatibility with older keyring-api versions, we mark some fields
463
- // as optional and provide them here if they are missing.
464
- const newAccount = transformAccountV1(newAccountFromEvent);
462
+ // Potentially migrate the account.
463
+ const newAccount = transformAccount(newAccountFromEvent);
465
464
  // The address of the account cannot be changed. In the future, we will
466
465
  // support changing the address of an account since it will be required to
467
466
  // support UTXO-based chains.
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.mjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,iFAAiF;;;;;;;;;;;;;AAGjF,OAAO,EAAE,kBAAkB,EAAE,uB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C;IACD,MAAM,cAAc,GAAG,uBAAA,IAAI,kEAAuB,MAA3B,IAAI,EAAwB,IAAI,CAAC,CAAC;IACzD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,uCAAuC,MAAM,GAAG,CAC/E,CAAC;IACJ,CAAC;AACH,CAAC,qEA+Pe,OAAe;IAI7B,OAAO,CACL,CAAC,GAAG,uBAAA,IAAI,6BAAU,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAChD,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,IAAI,UAAU,CAAC,YAAY,OAAO,aAAa,CAAC,CAClD,CAAC;AACJ,CAAC,uDAQQ,MAAc;IACrB,OAAO,uBAAA,IAAI,8BAAW,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC,uEASC,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,oDAAS,MAAb,IAAI,EAAU,MAAM,CAAC,CAAC;IACnC,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACzE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,mFAQsB,IAAU;IAC/B,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,EAAE,cAAc;QACrE,EAAE,CACH,CAAC;AACJ,CAAC;AA55BM,gBAAI,GAAW,iBAAiB,AAA5B,CAA6B","sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n// This rule seems to be triggering a false positive. Possibly eslint is not\n// inferring the `EthMethod`, `BtcMethod`, and `InternalAccount` types correctly.\n\nimport type { TypedTransaction } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { ExtractEventPayload } from '@metamask/base-controller';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport {\n EthBytesStruct,\n EthMethod,\n EthBaseUserOperationStruct,\n EthUserOperationPatchStruct,\n isEvmAccountType,\n KeyringEvent,\n AccountAssetListUpdatedEventStruct,\n AccountBalancesUpdatedEventStruct,\n AccountTransactionsUpdatedEventStruct,\n} from '@metamask/keyring-api';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n KeyringResponse,\n BtcMethod,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringInternalSnapClient } from '@metamask/keyring-internal-snap-client';\nimport { strictMask } from '@metamask/keyring-utils';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { type Snap } from '@metamask/snaps-utils';\nimport { assert, mask, object, string } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport {\n bigIntToHex,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\nimport { EventEmitter } from 'events';\nimport { v4 as uuid } from 'uuid';\n\nimport { DeferredPromise } from './DeferredPromise';\nimport {\n AccountCreatedEventStruct,\n AccountUpdatedEventStruct,\n AccountDeletedEventStruct,\n RequestApprovedEventStruct,\n RequestRejectedEventStruct,\n} from './events';\nimport { projectLogger as log } from './logger';\nimport {\n isAccountV1,\n migrateAccountV1,\n transformAccountV1,\n} from './migrations';\nimport { SnapIdMap } from './SnapIdMap';\nimport type {\n SnapKeyringEvents,\n SnapKeyringMessenger,\n} from './SnapKeyringMessenger';\nimport type { SnapMessage } from './types';\nimport { SnapMessageStruct } from './types';\nimport {\n equalsIgnoreCase,\n sanitizeUrl,\n throwError,\n toJson,\n unique,\n} from './util';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n// TODO: to be removed when this is added to the keyring-api\n\ntype AccountMethod = EthMethod | BtcMethod;\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 accountNameSuggestion?: string,\n displayConfirmation?: boolean,\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 * Normalize account's address.\n *\n * @param account - The account.\n * @returns The normalized account address.\n */\nfunction normalizeAccountAddress(account: KeyringAccount): string {\n // FIXME: Is it required to lowercase the address here? For now we'll keep this behavior\n // only for Ethereum addresses and use the original address for other non-EVM accounts.\n // For example, Solana addresses are case-sensitives.\n return isEvmAccountType(account.type)\n ? account.address.toLowerCase()\n : account.address;\n}\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring extends EventEmitter {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n /**\n * Messenger to dispatch requests to the Snaps controller.\n */\n readonly #messenger: SnapKeyringMessenger;\n\n /**\n * Client used to call the Snap keyring.\n */\n readonly #snapClient: KeyringInternalSnapClient;\n\n /**\n * Mapping between account IDs and an object that contains the associated\n * account object and Snap ID.\n */\n #accounts: SnapIdMap<{\n account: KeyringAccount;\n snapId: SnapId;\n }>;\n\n /**\n * Mapping between request IDs and their deferred promises.\n */\n readonly #requests: SnapIdMap<{\n promise: DeferredPromise<any>;\n snapId: SnapId;\n }>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Create a new Snap keyring.\n *\n * @param messenger - Snap keyring messenger.\n * @param callbacks - Callbacks used to interact with other components.\n * @returns A new Snap keyring.\n */\n constructor(\n messenger: SnapKeyringMessenger,\n callbacks: SnapKeyringCallbacks,\n ) {\n super();\n this.type = SnapKeyring.type;\n this.#messenger = messenger;\n this.#snapClient = new KeyringInternalSnapClient({ messenger });\n this.#requests = new SnapIdMap();\n this.#accounts = new SnapIdMap();\n this.#callbacks = callbacks;\n }\n\n /**\n * Handle an Account Created event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountCreated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountCreatedEventStruct);\n const {\n account: newAccountFromEvent,\n accountNameSuggestion,\n displayConfirmation,\n } = message.params;\n\n // To keep the retro-compatibility with older keyring-api versions, we mark some fields\n // as optional and provide them here if they are missing.\n const account = transformAccountV1(newAccountFromEvent);\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 const address = normalizeAccountAddress(account);\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\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 if (this.#accounts.has(snapId, account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n await this.#callbacks.addAccount(\n address,\n snapId,\n async (accepted: boolean) => {\n if (accepted) {\n this.#accounts.set(account.id, { account, snapId });\n await this.#callbacks.saveState();\n }\n },\n accountNameSuggestion,\n displayConfirmation,\n );\n return null;\n }\n\n /**\n * Handle an Account Updated event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountUpdated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountUpdatedEventStruct);\n const { account: newAccountFromEvent } = message.params;\n const { account: oldAccount } =\n this.#accounts.get(snapId, newAccountFromEvent.id) ??\n throwError(`Account '${newAccountFromEvent.id}' not found`);\n\n // To keep the retro-compatibility with older keyring-api versions, we mark some fields\n // as optional and provide them here if they are missing.\n const newAccount = transformAccountV1(newAccountFromEvent);\n\n // The address of the account cannot be changed. In the future, we will\n // support changing the address of an account since it will be required to\n // support UTXO-based chains.\n if (!equalsIgnoreCase(oldAccount.address, newAccount.address)) {\n throw new Error(`Cannot change address of account '${newAccount.id}'`);\n }\n\n this.#accounts.set(newAccount.id, { account: newAccount, snapId });\n await this.#callbacks.saveState();\n return null;\n }\n\n /**\n * Handle an Account Deleted event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountDeleted(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountDeletedEventStruct);\n const { id } = message.params;\n const entry = this.#accounts.get(snapId, id);\n\n // We can ignore the case where the account was already removed from the\n // keyring, making the deletion idempotent.\n //\n // This happens when the keyring calls the Snap to delete an account, and\n // the Snap calls the keyring back with an `AccountDeleted` event.\n if (entry === undefined) {\n return null;\n }\n\n // At this point we know that the account exists, so we can safely\n // destructure it.\n const { account } = entry;\n\n await this.#callbacks.removeAccount(\n normalizeAccountAddress(account),\n snapId,\n async (accepted) => {\n if (accepted) {\n await this.#callbacks.saveState();\n }\n },\n );\n return null;\n }\n\n /**\n * Handle an Request Approved event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestApproved(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestApprovedEventStruct);\n const { id, result } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.resolve(result);\n return null;\n }\n\n /**\n * Handle an Request Rejected event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestRejected(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestRejectedEventStruct);\n const { id } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.reject(new Error(`Request rejected by user or snap.`));\n return null;\n }\n\n /**\n * Re-publish an account event.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @template EventType - A Snap keyring event type.\n * @returns `null`.\n */\n async #rePublishAccountEvent<EventType extends SnapKeyringEvents['type']>(\n event: EventType,\n ...payload: ExtractEventPayload<SnapKeyringEvents, EventType>\n ): Promise<null> {\n this.#messenger.publish(event, ...payload);\n return null;\n }\n\n /**\n * Handle a balances updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountBalancesUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountBalancesUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountBalancesUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a asset list updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountAssetListUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountAssetListUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountAssetListUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a transactions updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountTransactionsUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountTransactionsUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountTransactionsUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a message from a Snap.\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 assert(message, SnapMessageStruct);\n switch (message.method) {\n case `${KeyringEvent.AccountCreated}`: {\n return this.#handleAccountCreated(snapId, message);\n }\n\n case `${KeyringEvent.AccountUpdated}`: {\n return this.#handleAccountUpdated(snapId, message);\n }\n\n case `${KeyringEvent.AccountDeleted}`: {\n return this.#handleAccountDeleted(snapId, message);\n }\n\n case `${KeyringEvent.RequestApproved}`: {\n return this.#handleRequestApproved(snapId, message);\n }\n\n case `${KeyringEvent.RequestRejected}`: {\n return this.#handleRequestRejected(snapId, message);\n }\n\n // Assets related events:\n case `${KeyringEvent.AccountBalancesUpdated}`: {\n return this.#handleAccountBalancesUpdated(message);\n }\n\n case `${KeyringEvent.AccountAssetListUpdated}`: {\n return this.#handleAccountAssetListUpdated(message);\n }\n\n case `${KeyringEvent.AccountTransactionsUpdated}`: {\n return this.#handleAccountTransactionsUpdated(message);\n }\n\n default:\n throw new Error(`Method not supported: ${message.method}`);\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n return {\n accounts: this.#accounts.toObject(),\n };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\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 // Running Snap keyring migrations. We might have some accounts that have a\n // different \"version\" than the one we expect.\n // In this case, we \"transform\" then directly when deserializing to convert\n // them in the final account version.\n const accounts: KeyringState['accounts'] = {};\n for (const [snapId, entry] of Object.entries(state.accounts)) {\n // V1 accounts are missing the scopes.\n if (isAccountV1(entry.account)) {\n console.info(\n `SnapKeyring - Found a KeyringAccountV1, migrating to V2: ${entry.account.id}`,\n );\n accounts[snapId] = {\n ...entry,\n account: migrateAccountV1(entry.account),\n };\n } else {\n accounts[snapId] = entry;\n }\n }\n\n this.#accounts = SnapIdMap.fromObject(accounts);\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 return unique(\n [...this.#accounts.values()].map(({ account }) =>\n normalizeAccountAddress(account),\n ),\n );\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.#accounts.values()]\n .filter(({ snapId: accountSnapId }) => accountSnapId === snapId)\n .map(({ account }) => normalizeAccountAddress(account)),\n );\n }\n\n /**\n * Submit a request to a Snap.\n *\n * @param opts - Request options.\n * @param opts.address - Account address.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.chainId - Selected chain ID (CAIP-2).\n * @param opts.noPending - Whether the response is allowed to be pending.\n * @returns Promise that resolves to the result of the method call.\n */\n async #submitRequest<Response extends Json>({\n address,\n method,\n params,\n chainId = '',\n noPending = false,\n }: {\n address: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n chainId?: string;\n noPending?: boolean;\n }): Promise<Json> {\n const { account, snapId } = this.#resolveAddress(address);\n if (!this.#hasMethod(account, method as AccountMethod)) {\n throw new Error(\n `Method '${method}' not supported for account ${account.address}`,\n );\n }\n\n const requestId = uuid();\n\n // Create the promise before calling the Snap to prevent a race condition\n // where the Snap responds before we have a chance to create it.\n const promise = this.#createRequestPromise<Response>(requestId, snapId);\n\n const response = await this.#submitSnapRequest({\n snapId,\n requestId,\n account,\n method: method as AccountMethod,\n params,\n chainId,\n });\n\n // Some methods, like the ones used to prepare and patch user operations,\n // require the Snap to answer synchronously in order to work with the\n // confirmation flow. This check lets the caller enforce this behavior.\n if (noPending && response.pending) {\n throw new Error(\n `Request '${requestId}' to snap '${snapId}' is pending and noPending is true.`,\n );\n }\n\n // If the Snap answers synchronously, the promise must be removed from the\n // map to prevent a leak.\n if (!response.pending) {\n return this.#handleSyncResponse(response, requestId, snapId);\n }\n\n // If the Snap answers asynchronously, we will inform the user with a redirect\n if (response.redirect?.message || response.redirect?.url) {\n await this.#handleAsyncResponse(response.redirect, snapId);\n }\n\n return promise.promise;\n }\n\n /**\n * Check if an account supports the given method.\n *\n * @param account - The account object to check for method support.\n * @param method - The Ethereum method to validate.\n * @returns `true` if the method is supported, `false` otherwise.\n */\n #hasMethod(account: KeyringAccount, method: AccountMethod): boolean {\n return (account.methods as AccountMethod[]).includes(method);\n }\n\n /**\n * Creates a promise for a request and adds it to the map of requests.\n *\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns A DeferredPromise instance.\n */\n #createRequestPromise<Response>(\n requestId: string,\n snapId: SnapId,\n ): DeferredPromise<Response> {\n const promise = new DeferredPromise<Response>();\n this.#requests.set(requestId, { promise, snapId });\n return promise;\n }\n\n /**\n * Submits a request to a Snap.\n *\n * @param options - The options for the Snap request.\n * @param options.snapId - The Snap ID to submit the request to.\n * @param options.requestId - The unique identifier for the request.\n * @param options.account - The account to use for the request.\n * @param options.method - The Ethereum method to call.\n * @param options.params - The parameters to pass to the method, can be undefined.\n * @param options.chainId - The chain ID to use for the request, can be an empty string.\n * @returns A promise that resolves to the keyring response from the Snap.\n * @throws An error if the Snap fails to respond or if there's an issue with the request submission.\n */\n async #submitSnapRequest({\n snapId,\n requestId,\n account,\n method,\n params,\n chainId,\n }: {\n snapId: SnapId;\n requestId: string;\n account: KeyringAccount;\n method: AccountMethod;\n params?: Json[] | Record<string, Json> | undefined;\n chainId: string;\n }): Promise<KeyringResponse> {\n try {\n const request = {\n id: requestId,\n scope: chainId,\n account: account.id,\n request: {\n method,\n ...(params !== undefined && { params }),\n },\n };\n\n log('Submit Snap request: ', request);\n\n return await this.#snapClient.withSnapId(snapId).submitRequest(request);\n } catch (error) {\n log('Snap Request failed: ', { requestId });\n\n // If the Snap failed to respond, delete the promise to prevent a leak.\n this.#requests.delete(snapId, requestId);\n throw error;\n }\n }\n\n /**\n * Handles the synchronous response from a Snap. If the response indicates the request is not pending, it removes the request from the map.\n *\n * @param response - The response from the Snap.\n * @param response.pending - A boolean indicating if the request is pending should always be false in this context.\n * @param response.result - The result data from the Snap response.\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns The result from the Snap response.\n */\n #handleSyncResponse(\n response: { pending: false; result: Json },\n requestId: string,\n snapId: SnapId,\n ): Json {\n this.#requests.delete(snapId, requestId);\n return response.result;\n }\n\n /**\n * Handles the async redirect and response from a Snap. Validates the redirect URL and informs the user with a message and URL if provided.\n *\n * @param redirect - The redirect information including message and URL.\n * @param redirect.message - The message to show to the user if provided.\n * @param redirect.url - The URL to redirect the user to if provided.\n * @param snapId - The Snap ID associated with the request.\n * @throws An error if the redirect URL is not an allowed origin for the Snap.\n */\n async #handleAsyncResponse(\n redirect: { message?: string; url?: string },\n snapId: SnapId,\n ): Promise<void> {\n const { message = '', url: redirectUrl = '' } = redirect;\n const url = this.#sanitizeRedirectUrl(redirectUrl);\n if (url) {\n this.#validateRedirectUrl(url, snapId);\n }\n await this.#callbacks.redirectUser(snapId, url, message);\n }\n\n /**\n * Sanitize a redirect URL.\n *\n * @param url - The URL to sanitize.\n * @returns The new sanitized redirect URL.\n */\n #sanitizeRedirectUrl(url: string): string {\n // We do check if the URL is empty or not since the Snap might not returns any URL at all.\n return url ? sanitizeUrl(url) : url;\n }\n\n /**\n * Validates if the redirect URL is in the Snap's allowed origins.\n *\n * @param url - The URL to validate.\n * @param snapId - The Snap ID to check allowed origins for.\n * @throws An error if the URL's origin is not in the Snap's allowed origins.\n */\n #validateRedirectUrl(url: string, snapId: SnapId): void {\n const { origin } = new URL(url);\n const snap = this.#getSnap(snapId);\n if (!snap) {\n throw new Error(`Snap '${snapId}' not found.`);\n }\n const allowedOrigins = this.#getSnapAllowedOrigins(snap);\n if (!allowedOrigins.includes(origin)) {\n throw new Error(\n `Redirect URL domain '${origin}' is not an allowed origin by snap '${snapId}'`,\n );\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 chainId = transaction.common.chainId();\n const tx = toJson({\n ...transaction.toJSON(),\n from: address,\n type: `0x${transaction.type.toString(16)}`,\n chainId: bigIntToHex(chainId),\n });\n\n const signedTx = await this.#submitRequest({\n address,\n method: EthMethod.SignTransaction,\n params: [tx],\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n });\n\n // ! It's *** CRITICAL *** that we mask the signature here, otherwise the\n // ! Snap could overwrite the transaction.\n const signature = mask(\n signedTx,\n object({\n r: string(),\n s: string(),\n v: string(),\n }),\n );\n\n return TransactionFactory.fromTxData({\n ...(tx as Record<string, Json>),\n r: signature.r,\n s: signature.s,\n v: signature.v,\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 methods = {\n [SignTypedDataVersion.V1]: EthMethod.SignTypedDataV1,\n [SignTypedDataVersion.V3]: EthMethod.SignTypedDataV3,\n [SignTypedDataVersion.V4]: EthMethod.SignTypedDataV4,\n };\n\n // Use 'V1' by default to match other keyring implementations. V1 will be\n // used if the version is not specified or not supported.\n const method = methods[opts.version] || EthMethod.SignTypedDataV1;\n\n // Extract chain ID as if it was a typed message (as defined by EIP-712), if\n // input is not a typed message, then chain ID will be undefined!\n const chainId = (data as TypedMessage<any>).domain?.chainId;\n\n return strictMask(\n await this.#submitRequest({\n address,\n method,\n params: toJson<Json[]>([address, data]),\n ...(chainId === undefined\n ? {}\n : {\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n }),\n }),\n EthBytesStruct,\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.Sign,\n params: toJson<Json[]>([address, hash]),\n }),\n EthBytesStruct,\n );\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PersonalSign,\n params: toJson<Json[]>([data, address]),\n }),\n EthBytesStruct,\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PrepareUserOperation,\n params: toJson<Json[]>(transactions),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBaseUserOperationStruct,\n );\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PatchUserOperation,\n params: toJson<Json[]>([userOp]),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthUserOperationPatchStruct,\n );\n }\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Leyring 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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.SignUserOperation,\n params: toJson<Json[]>([userOp]),\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBytesStruct,\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 * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, snapId } = this.#resolveAddress(address);\n\n // Always remove the account from the maps, even if the Snap is going to\n // fail to delete it.\n this.#accounts.delete(snapId, account.id);\n\n try {\n await this.#snapClient.withSnapId(snapId).deleteAccount(account.id);\n } catch (error) {\n // If the Snap failed to delete the account, log the error and continue\n // with the account deletion, otherwise the account will be stuck in the\n // keyring.\n console.error(\n `Account '${address}' may not have been removed from snap '${snapId}':`,\n error,\n );\n }\n }\n\n /**\n * Resolve an address to an account and Snap ID.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and Snap ID. Throws if the account or Snap ID is not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n snapId: SnapId;\n } {\n return (\n [...this.#accounts.values()].find(({ account }) =>\n equalsIgnoreCase(account.address, address),\n ) ?? throwError(`Account '${address}' not found`)\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 | undefined {\n return this.#messenger.call('SnapController:get', snapId);\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#getSnap(snapId);\n return snap\n ? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }\n : undefined;\n }\n\n /**\n * Get the allowed origins of a Snap.\n *\n * @param snap - Snap.\n * @returns The allowed origins of the Snap.\n */\n #getSnapAllowedOrigins(snap: Snap): string[] {\n return (\n snap.manifest.initialPermissions['endowment:keyring']?.allowedOrigins ??\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 const accounts = this.listAccounts();\n return accounts.find(({ address: accountAddress }) =>\n equalsIgnoreCase(accountAddress, address),\n );\n }\n\n /**\n * List all Snap keyring accounts.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n return [...this.#accounts.values()].map(({ account, snapId }) => {\n const snap = this.#getSnapMetadata(snapId);\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"]}
1
+ {"version":3,"file":"SnapKeyring.mjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,iFAAiF;;;;;;;;;;;;;AAGjF,OAAO,EAAE,kBAAkB,EAAE,uBAAu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C;IACD,MAAM,cAAc,GAAG,uBAAA,IAAI,kEAAuB,MAA3B,IAAI,EAAwB,IAAI,CAAC,CAAC;IACzD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,uCAAuC,MAAM,GAAG,CAC/E,CAAC;IACJ,CAAC;AACH,CAAC,qEA+Pe,OAAe;IAI7B,OAAO,CACL,CAAC,GAAG,uBAAA,IAAI,6BAAU,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAChD,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,IAAI,UAAU,CAAC,YAAY,OAAO,aAAa,CAAC,CAClD,CAAC;AACJ,CAAC,uDAQQ,MAAc;IACrB,OAAO,uBAAA,IAAI,8BAAW,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC,uEASC,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,oDAAS,MAAb,IAAI,EAAU,MAAM,CAAC,CAAC;IACnC,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACzE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,mFAQsB,IAAU;IAC/B,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,EAAE,cAAc;QACrE,EAAE,CACH,CAAC;AACJ,CAAC;AA15BM,gBAAI,GAAW,iBAAiB,AAA5B,CAA6B","sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n// This rule seems to be triggering a false positive. Possibly eslint is not\n// inferring the `EthMethod`, `BtcMethod`, and `InternalAccount` types correctly.\n\nimport type { TypedTransaction } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { ExtractEventPayload } from '@metamask/base-controller';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport {\n EthBytesStruct,\n EthMethod,\n EthBaseUserOperationStruct,\n EthUserOperationPatchStruct,\n isEvmAccountType,\n KeyringEvent,\n AccountAssetListUpdatedEventStruct,\n AccountBalancesUpdatedEventStruct,\n AccountTransactionsUpdatedEventStruct,\n} from '@metamask/keyring-api';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n KeyringResponse,\n BtcMethod,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringInternalSnapClient } from '@metamask/keyring-internal-snap-client';\nimport { strictMask } from '@metamask/keyring-utils';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { type Snap } from '@metamask/snaps-utils';\nimport { assert, mask, object, string } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport {\n bigIntToHex,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\nimport { EventEmitter } from 'events';\nimport { v4 as uuid } from 'uuid';\n\nimport { transformAccount } from './account';\nimport { DeferredPromise } from './DeferredPromise';\nimport {\n AccountCreatedEventStruct,\n AccountUpdatedEventStruct,\n AccountDeletedEventStruct,\n RequestApprovedEventStruct,\n RequestRejectedEventStruct,\n} from './events';\nimport { projectLogger as log } from './logger';\nimport { isAccountV1, migrateAccountV1 } from './migrations';\nimport { SnapIdMap } from './SnapIdMap';\nimport type {\n SnapKeyringEvents,\n SnapKeyringMessenger,\n} from './SnapKeyringMessenger';\nimport type { SnapMessage } from './types';\nimport { SnapMessageStruct } from './types';\nimport {\n equalsIgnoreCase,\n sanitizeUrl,\n throwError,\n toJson,\n unique,\n} from './util';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n// TODO: to be removed when this is added to the keyring-api\n\ntype AccountMethod = EthMethod | BtcMethod;\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 accountNameSuggestion?: string,\n displayConfirmation?: boolean,\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 * Normalize account's address.\n *\n * @param account - The account.\n * @returns The normalized account address.\n */\nfunction normalizeAccountAddress(account: KeyringAccount): string {\n // FIXME: Is it required to lowercase the address here? For now we'll keep this behavior\n // only for Ethereum addresses and use the original address for other non-EVM accounts.\n // For example, Solana addresses are case-sensitives.\n return isEvmAccountType(account.type)\n ? account.address.toLowerCase()\n : account.address;\n}\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring extends EventEmitter {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n /**\n * Messenger to dispatch requests to the Snaps controller.\n */\n readonly #messenger: SnapKeyringMessenger;\n\n /**\n * Client used to call the Snap keyring.\n */\n readonly #snapClient: KeyringInternalSnapClient;\n\n /**\n * Mapping between account IDs and an object that contains the associated\n * account object and Snap ID.\n */\n #accounts: SnapIdMap<{\n account: KeyringAccount;\n snapId: SnapId;\n }>;\n\n /**\n * Mapping between request IDs and their deferred promises.\n */\n readonly #requests: SnapIdMap<{\n promise: DeferredPromise<any>;\n snapId: SnapId;\n }>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Create a new Snap keyring.\n *\n * @param messenger - Snap keyring messenger.\n * @param callbacks - Callbacks used to interact with other components.\n * @returns A new Snap keyring.\n */\n constructor(\n messenger: SnapKeyringMessenger,\n callbacks: SnapKeyringCallbacks,\n ) {\n super();\n this.type = SnapKeyring.type;\n this.#messenger = messenger;\n this.#snapClient = new KeyringInternalSnapClient({ messenger });\n this.#requests = new SnapIdMap();\n this.#accounts = new SnapIdMap();\n this.#callbacks = callbacks;\n }\n\n /**\n * Handle an Account Created event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountCreated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountCreatedEventStruct);\n const {\n account: newAccountFromEvent,\n accountNameSuggestion,\n displayConfirmation,\n } = message.params;\n\n // Potentially migrate the account.\n const account = transformAccount(newAccountFromEvent);\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 const address = normalizeAccountAddress(account);\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\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 if (this.#accounts.has(snapId, account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n await this.#callbacks.addAccount(\n address,\n snapId,\n async (accepted: boolean) => {\n if (accepted) {\n this.#accounts.set(account.id, { account, snapId });\n await this.#callbacks.saveState();\n }\n },\n accountNameSuggestion,\n displayConfirmation,\n );\n return null;\n }\n\n /**\n * Handle an Account Updated event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountUpdated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountUpdatedEventStruct);\n const { account: newAccountFromEvent } = message.params;\n const { account: oldAccount } =\n this.#accounts.get(snapId, newAccountFromEvent.id) ??\n throwError(`Account '${newAccountFromEvent.id}' not found`);\n\n // Potentially migrate the account.\n const newAccount = transformAccount(newAccountFromEvent);\n\n // The address of the account cannot be changed. In the future, we will\n // support changing the address of an account since it will be required to\n // support UTXO-based chains.\n if (!equalsIgnoreCase(oldAccount.address, newAccount.address)) {\n throw new Error(`Cannot change address of account '${newAccount.id}'`);\n }\n\n this.#accounts.set(newAccount.id, { account: newAccount, snapId });\n await this.#callbacks.saveState();\n return null;\n }\n\n /**\n * Handle an Account Deleted event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountDeleted(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountDeletedEventStruct);\n const { id } = message.params;\n const entry = this.#accounts.get(snapId, id);\n\n // We can ignore the case where the account was already removed from the\n // keyring, making the deletion idempotent.\n //\n // This happens when the keyring calls the Snap to delete an account, and\n // the Snap calls the keyring back with an `AccountDeleted` event.\n if (entry === undefined) {\n return null;\n }\n\n // At this point we know that the account exists, so we can safely\n // destructure it.\n const { account } = entry;\n\n await this.#callbacks.removeAccount(\n normalizeAccountAddress(account),\n snapId,\n async (accepted) => {\n if (accepted) {\n await this.#callbacks.saveState();\n }\n },\n );\n return null;\n }\n\n /**\n * Handle an Request Approved event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestApproved(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestApprovedEventStruct);\n const { id, result } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.resolve(result);\n return null;\n }\n\n /**\n * Handle an Request Rejected event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestRejected(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestRejectedEventStruct);\n const { id } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.reject(new Error(`Request rejected by user or snap.`));\n return null;\n }\n\n /**\n * Re-publish an account event.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @template EventType - A Snap keyring event type.\n * @returns `null`.\n */\n async #rePublishAccountEvent<EventType extends SnapKeyringEvents['type']>(\n event: EventType,\n ...payload: ExtractEventPayload<SnapKeyringEvents, EventType>\n ): Promise<null> {\n this.#messenger.publish(event, ...payload);\n return null;\n }\n\n /**\n * Handle a balances updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountBalancesUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountBalancesUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountBalancesUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a asset list updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountAssetListUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountAssetListUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountAssetListUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a transactions updated event from a Snap.\n *\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountTransactionsUpdated(message: SnapMessage): Promise<null> {\n assert(message, AccountTransactionsUpdatedEventStruct);\n return this.#rePublishAccountEvent(\n 'SnapKeyring:accountTransactionsUpdated',\n message.params,\n );\n }\n\n /**\n * Handle a message from a Snap.\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 assert(message, SnapMessageStruct);\n switch (message.method) {\n case `${KeyringEvent.AccountCreated}`: {\n return this.#handleAccountCreated(snapId, message);\n }\n\n case `${KeyringEvent.AccountUpdated}`: {\n return this.#handleAccountUpdated(snapId, message);\n }\n\n case `${KeyringEvent.AccountDeleted}`: {\n return this.#handleAccountDeleted(snapId, message);\n }\n\n case `${KeyringEvent.RequestApproved}`: {\n return this.#handleRequestApproved(snapId, message);\n }\n\n case `${KeyringEvent.RequestRejected}`: {\n return this.#handleRequestRejected(snapId, message);\n }\n\n // Assets related events:\n case `${KeyringEvent.AccountBalancesUpdated}`: {\n return this.#handleAccountBalancesUpdated(message);\n }\n\n case `${KeyringEvent.AccountAssetListUpdated}`: {\n return this.#handleAccountAssetListUpdated(message);\n }\n\n case `${KeyringEvent.AccountTransactionsUpdated}`: {\n return this.#handleAccountTransactionsUpdated(message);\n }\n\n default:\n throw new Error(`Method not supported: ${message.method}`);\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n return {\n accounts: this.#accounts.toObject(),\n };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\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 // Running Snap keyring migrations. We might have some accounts that have a\n // different \"version\" than the one we expect.\n // In this case, we \"transform\" then directly when deserializing to convert\n // them in the final account version.\n const accounts: KeyringState['accounts'] = {};\n for (const [snapId, entry] of Object.entries(state.accounts)) {\n // V1 accounts are missing the scopes.\n if (isAccountV1(entry.account)) {\n console.info(\n `SnapKeyring - Found a KeyringAccountV1, migrating to V2: ${entry.account.id}`,\n );\n accounts[snapId] = {\n ...entry,\n account: migrateAccountV1(entry.account),\n };\n } else {\n accounts[snapId] = entry;\n }\n }\n\n this.#accounts = SnapIdMap.fromObject(accounts);\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 return unique(\n [...this.#accounts.values()].map(({ account }) =>\n normalizeAccountAddress(account),\n ),\n );\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.#accounts.values()]\n .filter(({ snapId: accountSnapId }) => accountSnapId === snapId)\n .map(({ account }) => normalizeAccountAddress(account)),\n );\n }\n\n /**\n * Submit a request to a Snap.\n *\n * @param opts - Request options.\n * @param opts.address - Account address.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.chainId - Selected chain ID (CAIP-2).\n * @param opts.noPending - Whether the response is allowed to be pending.\n * @returns Promise that resolves to the result of the method call.\n */\n async #submitRequest<Response extends Json>({\n address,\n method,\n params,\n chainId = '',\n noPending = false,\n }: {\n address: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n chainId?: string;\n noPending?: boolean;\n }): Promise<Json> {\n const { account, snapId } = this.#resolveAddress(address);\n if (!this.#hasMethod(account, method as AccountMethod)) {\n throw new Error(\n `Method '${method}' not supported for account ${account.address}`,\n );\n }\n\n const requestId = uuid();\n\n // Create the promise before calling the Snap to prevent a race condition\n // where the Snap responds before we have a chance to create it.\n const promise = this.#createRequestPromise<Response>(requestId, snapId);\n\n const response = await this.#submitSnapRequest({\n snapId,\n requestId,\n account,\n method: method as AccountMethod,\n params,\n chainId,\n });\n\n // Some methods, like the ones used to prepare and patch user operations,\n // require the Snap to answer synchronously in order to work with the\n // confirmation flow. This check lets the caller enforce this behavior.\n if (noPending && response.pending) {\n throw new Error(\n `Request '${requestId}' to snap '${snapId}' is pending and noPending is true.`,\n );\n }\n\n // If the Snap answers synchronously, the promise must be removed from the\n // map to prevent a leak.\n if (!response.pending) {\n return this.#handleSyncResponse(response, requestId, snapId);\n }\n\n // If the Snap answers asynchronously, we will inform the user with a redirect\n if (response.redirect?.message || response.redirect?.url) {\n await this.#handleAsyncResponse(response.redirect, snapId);\n }\n\n return promise.promise;\n }\n\n /**\n * Check if an account supports the given method.\n *\n * @param account - The account object to check for method support.\n * @param method - The Ethereum method to validate.\n * @returns `true` if the method is supported, `false` otherwise.\n */\n #hasMethod(account: KeyringAccount, method: AccountMethod): boolean {\n return (account.methods as AccountMethod[]).includes(method);\n }\n\n /**\n * Creates a promise for a request and adds it to the map of requests.\n *\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns A DeferredPromise instance.\n */\n #createRequestPromise<Response>(\n requestId: string,\n snapId: SnapId,\n ): DeferredPromise<Response> {\n const promise = new DeferredPromise<Response>();\n this.#requests.set(requestId, { promise, snapId });\n return promise;\n }\n\n /**\n * Submits a request to a Snap.\n *\n * @param options - The options for the Snap request.\n * @param options.snapId - The Snap ID to submit the request to.\n * @param options.requestId - The unique identifier for the request.\n * @param options.account - The account to use for the request.\n * @param options.method - The Ethereum method to call.\n * @param options.params - The parameters to pass to the method, can be undefined.\n * @param options.chainId - The chain ID to use for the request, can be an empty string.\n * @returns A promise that resolves to the keyring response from the Snap.\n * @throws An error if the Snap fails to respond or if there's an issue with the request submission.\n */\n async #submitSnapRequest({\n snapId,\n requestId,\n account,\n method,\n params,\n chainId,\n }: {\n snapId: SnapId;\n requestId: string;\n account: KeyringAccount;\n method: AccountMethod;\n params?: Json[] | Record<string, Json> | undefined;\n chainId: string;\n }): Promise<KeyringResponse> {\n try {\n const request = {\n id: requestId,\n scope: chainId,\n account: account.id,\n request: {\n method,\n ...(params !== undefined && { params }),\n },\n };\n\n log('Submit Snap request: ', request);\n\n return await this.#snapClient.withSnapId(snapId).submitRequest(request);\n } catch (error) {\n log('Snap Request failed: ', { requestId });\n\n // If the Snap failed to respond, delete the promise to prevent a leak.\n this.#requests.delete(snapId, requestId);\n throw error;\n }\n }\n\n /**\n * Handles the synchronous response from a Snap. If the response indicates the request is not pending, it removes the request from the map.\n *\n * @param response - The response from the Snap.\n * @param response.pending - A boolean indicating if the request is pending should always be false in this context.\n * @param response.result - The result data from the Snap response.\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns The result from the Snap response.\n */\n #handleSyncResponse(\n response: { pending: false; result: Json },\n requestId: string,\n snapId: SnapId,\n ): Json {\n this.#requests.delete(snapId, requestId);\n return response.result;\n }\n\n /**\n * Handles the async redirect and response from a Snap. Validates the redirect URL and informs the user with a message and URL if provided.\n *\n * @param redirect - The redirect information including message and URL.\n * @param redirect.message - The message to show to the user if provided.\n * @param redirect.url - The URL to redirect the user to if provided.\n * @param snapId - The Snap ID associated with the request.\n * @throws An error if the redirect URL is not an allowed origin for the Snap.\n */\n async #handleAsyncResponse(\n redirect: { message?: string; url?: string },\n snapId: SnapId,\n ): Promise<void> {\n const { message = '', url: redirectUrl = '' } = redirect;\n const url = this.#sanitizeRedirectUrl(redirectUrl);\n if (url) {\n this.#validateRedirectUrl(url, snapId);\n }\n await this.#callbacks.redirectUser(snapId, url, message);\n }\n\n /**\n * Sanitize a redirect URL.\n *\n * @param url - The URL to sanitize.\n * @returns The new sanitized redirect URL.\n */\n #sanitizeRedirectUrl(url: string): string {\n // We do check if the URL is empty or not since the Snap might not returns any URL at all.\n return url ? sanitizeUrl(url) : url;\n }\n\n /**\n * Validates if the redirect URL is in the Snap's allowed origins.\n *\n * @param url - The URL to validate.\n * @param snapId - The Snap ID to check allowed origins for.\n * @throws An error if the URL's origin is not in the Snap's allowed origins.\n */\n #validateRedirectUrl(url: string, snapId: SnapId): void {\n const { origin } = new URL(url);\n const snap = this.#getSnap(snapId);\n if (!snap) {\n throw new Error(`Snap '${snapId}' not found.`);\n }\n const allowedOrigins = this.#getSnapAllowedOrigins(snap);\n if (!allowedOrigins.includes(origin)) {\n throw new Error(\n `Redirect URL domain '${origin}' is not an allowed origin by snap '${snapId}'`,\n );\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 chainId = transaction.common.chainId();\n const tx = toJson({\n ...transaction.toJSON(),\n from: address,\n type: `0x${transaction.type.toString(16)}`,\n chainId: bigIntToHex(chainId),\n });\n\n const signedTx = await this.#submitRequest({\n address,\n method: EthMethod.SignTransaction,\n params: [tx],\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n });\n\n // ! It's *** CRITICAL *** that we mask the signature here, otherwise the\n // ! Snap could overwrite the transaction.\n const signature = mask(\n signedTx,\n object({\n r: string(),\n s: string(),\n v: string(),\n }),\n );\n\n return TransactionFactory.fromTxData({\n ...(tx as Record<string, Json>),\n r: signature.r,\n s: signature.s,\n v: signature.v,\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 methods = {\n [SignTypedDataVersion.V1]: EthMethod.SignTypedDataV1,\n [SignTypedDataVersion.V3]: EthMethod.SignTypedDataV3,\n [SignTypedDataVersion.V4]: EthMethod.SignTypedDataV4,\n };\n\n // Use 'V1' by default to match other keyring implementations. V1 will be\n // used if the version is not specified or not supported.\n const method = methods[opts.version] || EthMethod.SignTypedDataV1;\n\n // Extract chain ID as if it was a typed message (as defined by EIP-712), if\n // input is not a typed message, then chain ID will be undefined!\n const chainId = (data as TypedMessage<any>).domain?.chainId;\n\n return strictMask(\n await this.#submitRequest({\n address,\n method,\n params: toJson<Json[]>([address, data]),\n ...(chainId === undefined\n ? {}\n : {\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n }),\n }),\n EthBytesStruct,\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.Sign,\n params: toJson<Json[]>([address, hash]),\n }),\n EthBytesStruct,\n );\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PersonalSign,\n params: toJson<Json[]>([data, address]),\n }),\n EthBytesStruct,\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PrepareUserOperation,\n params: toJson<Json[]>(transactions),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBaseUserOperationStruct,\n );\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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PatchUserOperation,\n params: toJson<Json[]>([userOp]),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthUserOperationPatchStruct,\n );\n }\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Leyring 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 return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.SignUserOperation,\n params: toJson<Json[]>([userOp]),\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBytesStruct,\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 * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, snapId } = this.#resolveAddress(address);\n\n // Always remove the account from the maps, even if the Snap is going to\n // fail to delete it.\n this.#accounts.delete(snapId, account.id);\n\n try {\n await this.#snapClient.withSnapId(snapId).deleteAccount(account.id);\n } catch (error) {\n // If the Snap failed to delete the account, log the error and continue\n // with the account deletion, otherwise the account will be stuck in the\n // keyring.\n console.error(\n `Account '${address}' may not have been removed from snap '${snapId}':`,\n error,\n );\n }\n }\n\n /**\n * Resolve an address to an account and Snap ID.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and Snap ID. Throws if the account or Snap ID is not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n snapId: SnapId;\n } {\n return (\n [...this.#accounts.values()].find(({ account }) =>\n equalsIgnoreCase(account.address, address),\n ) ?? throwError(`Account '${address}' not found`)\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 | undefined {\n return this.#messenger.call('SnapController:get', snapId);\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#getSnap(snapId);\n return snap\n ? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }\n : undefined;\n }\n\n /**\n * Get the allowed origins of a Snap.\n *\n * @param snap - Snap.\n * @returns The allowed origins of the Snap.\n */\n #getSnapAllowedOrigins(snap: Snap): string[] {\n return (\n snap.manifest.initialPermissions['endowment:keyring']?.allowedOrigins ??\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 const accounts = this.listAccounts();\n return accounts.find(({ address: accountAddress }) =>\n equalsIgnoreCase(accountAddress, address),\n );\n }\n\n /**\n * List all Snap keyring accounts.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n return [...this.#accounts.values()].map(({ account, snapId }) => {\n const snap = this.#getSnapMetadata(snapId);\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"]}
package/dist/account.cjs CHANGED
@@ -1,11 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KeyringAccountV1Struct = void 0;
4
+ exports.assertKeyringAccount = assertKeyringAccount;
5
+ exports.transformAccount = transformAccount;
4
6
  const keyring_api_1 = require("@metamask/keyring-api");
5
7
  const superstruct_1 = require("@metamask/superstruct");
8
+ const migrations_1 = require("./migrations/index.cjs");
6
9
  /**
7
10
  * A `KeyringAccount` with some optional fields which can be used to keep
8
11
  * the retro-compatility with older version of keyring accounts/events.
9
12
  */
10
13
  exports.KeyringAccountV1Struct = (0, superstruct_1.omit)(keyring_api_1.KeyringAccountStruct, ['scopes']);
14
+ /**
15
+ * Assert that an account-like object matches its actual account type.
16
+ *
17
+ * @param account - The account-like object.
18
+ * @returns The account as normal `KeyringAccount`.
19
+ */
20
+ function assertKeyringAccount(account) {
21
+ // TODO: We should use a `selectiveUnion` for this and probably use it to define
22
+ // the `KeyringAccount`. This would also required to have a "generic `KeyringAccount`"
23
+ // definition.
24
+ switch (account.type) {
25
+ case keyring_api_1.BtcAccountType.P2wpkh: {
26
+ (0, superstruct_1.assert)(account, keyring_api_1.BtcP2wpkhAccountStruct);
27
+ return account;
28
+ }
29
+ case keyring_api_1.SolAccountType.DataAccount: {
30
+ (0, superstruct_1.assert)(account, keyring_api_1.SolDataAccountStruct);
31
+ return account;
32
+ }
33
+ case keyring_api_1.EthAccountType.Erc4337: {
34
+ (0, superstruct_1.assert)(account, keyring_api_1.EthErc4337AccountStruct);
35
+ return account;
36
+ }
37
+ case keyring_api_1.EthAccountType.Eoa: {
38
+ (0, superstruct_1.assert)(account, keyring_api_1.EthEoaAccountStruct);
39
+ return account;
40
+ }
41
+ default: {
42
+ // For now, we cannot much more than this (this should also, never happen)!
43
+ // NOTE: We could use a "generic `KeyringAccount` type" here though.
44
+ throw new Error(`Unknown account type: '${account.type}'`);
45
+ }
46
+ }
47
+ }
48
+ /**
49
+ * Transform any versionned account to a `KeyringAccount`.
50
+ *
51
+ * @param accountToTransform - The account to transform.
52
+ * @returns A valid transformed `KeyringAccount`.
53
+ */
54
+ function transformAccount(
55
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
56
+ accountToTransform) {
57
+ // To keep the retro-compatibility with older keyring-api versions, we identify the account's
58
+ // version and transform it to the latest `KeyringAccount` representation.
59
+ const account = (0, migrations_1.isAccountV1)(accountToTransform)
60
+ ? (0, migrations_1.transformAccountV1)(accountToTransform)
61
+ : accountToTransform;
62
+ // We still assert that the converted account is valid according to their account's type.
63
+ return assertKeyringAccount(account);
64
+ }
11
65
  //# sourceMappingURL=account.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.cjs","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;AAAA,uDAA6D;AAC7D,uDAAyD;AAEzD;;;GAGG;AACU,QAAA,sBAAsB,GAAG,IAAA,kBAAI,EAAC,kCAAoB,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import { KeyringAccountStruct } from '@metamask/keyring-api';\nimport { omit, type Infer } from '@metamask/superstruct';\n\n/**\n * A `KeyringAccount` with some optional fields which can be used to keep\n * the retro-compatility with older version of keyring accounts/events.\n */\nexport const KeyringAccountV1Struct = omit(KeyringAccountStruct, ['scopes']);\n\nexport type KeyringAccountV1 = Infer<typeof KeyringAccountV1Struct>;\n"]}
1
+ {"version":3,"file":"account.cjs","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;AA6BA,oDA6BC;AAQD,4CAYC;AA7ED,uDAS+B;AAC/B,uDAAiE;AAEjE,uDAA+D;AAE/D;;;GAGG;AACU,QAAA,sBAAsB,GAAG,IAAA,kBAAI,EAAC,kCAAoB,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AAI7E;;;;;GAKG;AACH,SAAgB,oBAAoB,CAElC,OAAgB;IAChB,gFAAgF;IAChF,sFAAsF;IACtF,cAAc;IACd,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,4BAAc,CAAC,MAAM,CAAC,CAAC,CAAC;YAC3B,IAAA,oBAAM,EAAC,OAAO,EAAE,oCAAsB,CAAC,CAAC;YACxC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,KAAK,4BAAc,CAAC,WAAW,CAAC,CAAC,CAAC;YAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,kCAAoB,CAAC,CAAC;YACtC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,KAAK,4BAAc,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5B,IAAA,oBAAM,EAAC,OAAO,EAAE,qCAAuB,CAAC,CAAC;YACzC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,KAAK,4BAAc,CAAC,GAAG,CAAC,CAAC,CAAC;YACxB,IAAA,oBAAM,EAAC,OAAO,EAAE,iCAAmB,CAAC,CAAC;YACrC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,2EAA2E;YAC3E,qEAAqE;YACrE,MAAM,IAAI,KAAK,CAAC,0BAA0B,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB;AAC9B,6EAA6E;AAC7E,kBAAqD;IAErD,6FAA6F;IAC7F,0EAA0E;IAC1E,MAAM,OAAO,GAAG,IAAA,wBAAW,EAAC,kBAAkB,CAAC;QAC7C,CAAC,CAAC,IAAA,+BAAkB,EAAC,kBAAkB,CAAC;QACxC,CAAC,CAAC,kBAAkB,CAAC;IAEvB,yFAAyF;IACzF,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import type { KeyringAccount, KeyringAccountType } from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcP2wpkhAccountStruct,\n EthAccountType,\n EthEoaAccountStruct,\n EthErc4337AccountStruct,\n KeyringAccountStruct,\n SolAccountType,\n SolDataAccountStruct,\n} from '@metamask/keyring-api';\nimport { assert, omit, type Infer } from '@metamask/superstruct';\n\nimport { isAccountV1, transformAccountV1 } from './migrations';\n\n/**\n * A `KeyringAccount` with some optional fields which can be used to keep\n * the retro-compatility with older version of keyring accounts/events.\n */\nexport const KeyringAccountV1Struct = omit(KeyringAccountStruct, ['scopes']);\n\nexport type KeyringAccountV1 = Infer<typeof KeyringAccountV1Struct>;\n\n/**\n * Assert that an account-like object matches its actual account type.\n *\n * @param account - The account-like object.\n * @returns The account as normal `KeyringAccount`.\n */\nexport function assertKeyringAccount<\n Account extends { type: KeyringAccountType },\n>(account: Account): KeyringAccount {\n // TODO: We should use a `selectiveUnion` for this and probably use it to define\n // the `KeyringAccount`. This would also required to have a \"generic `KeyringAccount`\"\n // definition.\n switch (account.type) {\n case BtcAccountType.P2wpkh: {\n assert(account, BtcP2wpkhAccountStruct);\n return account;\n }\n case SolAccountType.DataAccount: {\n assert(account, SolDataAccountStruct);\n return account;\n }\n case EthAccountType.Erc4337: {\n assert(account, EthErc4337AccountStruct);\n return account;\n }\n case EthAccountType.Eoa: {\n assert(account, EthEoaAccountStruct);\n return account;\n }\n default: {\n // For now, we cannot much more than this (this should also, never happen)!\n // NOTE: We could use a \"generic `KeyringAccount` type\" here though.\n throw new Error(`Unknown account type: '${account.type}'`);\n }\n }\n}\n\n/**\n * Transform any versionned account to a `KeyringAccount`.\n *\n * @param accountToTransform - The account to transform.\n * @returns A valid transformed `KeyringAccount`.\n */\nexport function transformAccount(\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n accountToTransform: KeyringAccountV1 | KeyringAccount,\n): KeyringAccount {\n // To keep the retro-compatibility with older keyring-api versions, we identify the account's\n // version and transform it to the latest `KeyringAccount` representation.\n const account = isAccountV1(accountToTransform)\n ? transformAccountV1(accountToTransform)\n : accountToTransform;\n\n // We still assert that the converted account is valid according to their account's type.\n return assertKeyringAccount(account);\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { KeyringAccount, KeyringAccountType } from "@metamask/keyring-api";
1
2
  import { type Infer } from "@metamask/superstruct";
2
3
  /**
3
4
  * A `KeyringAccount` with some optional fields which can be used to keep
@@ -23,4 +24,20 @@ export declare const KeyringAccountV1Struct: import("@metamask/superstruct").Str
23
24
  methods: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
24
25
  }, "scopes">>;
25
26
  export type KeyringAccountV1 = Infer<typeof KeyringAccountV1Struct>;
27
+ /**
28
+ * Assert that an account-like object matches its actual account type.
29
+ *
30
+ * @param account - The account-like object.
31
+ * @returns The account as normal `KeyringAccount`.
32
+ */
33
+ export declare function assertKeyringAccount<Account extends {
34
+ type: KeyringAccountType;
35
+ }>(account: Account): KeyringAccount;
36
+ /**
37
+ * Transform any versionned account to a `KeyringAccount`.
38
+ *
39
+ * @param accountToTransform - The account to transform.
40
+ * @returns A valid transformed `KeyringAccount`.
41
+ */
42
+ export declare function transformAccount(accountToTransform: KeyringAccountV1 | KeyringAccount): KeyringAccount;
26
43
  //# sourceMappingURL=account.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.cts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,KAAK,EAAE,8BAA8B;AAEzD;;;GAGG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;aAAyC,CAAC;AAE7E,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
1
+ {"version":3,"file":"account.d.cts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,8BAA8B;AAWhF,OAAO,EAAgB,KAAK,KAAK,EAAE,8BAA8B;AAIjE;;;GAGG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;aAAyC,CAAC;AAE7E,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEpE;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,SAAS;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,EAC5C,OAAO,EAAE,OAAO,GAAG,cAAc,CA2BlC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAE9B,kBAAkB,EAAE,gBAAgB,GAAG,cAAc,GACpD,cAAc,CAShB"}
@@ -1,3 +1,4 @@
1
+ import type { KeyringAccount, KeyringAccountType } from "@metamask/keyring-api";
1
2
  import { type Infer } from "@metamask/superstruct";
2
3
  /**
3
4
  * A `KeyringAccount` with some optional fields which can be used to keep
@@ -23,4 +24,20 @@ export declare const KeyringAccountV1Struct: import("@metamask/superstruct").Str
23
24
  methods: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
24
25
  }, "scopes">>;
25
26
  export type KeyringAccountV1 = Infer<typeof KeyringAccountV1Struct>;
27
+ /**
28
+ * Assert that an account-like object matches its actual account type.
29
+ *
30
+ * @param account - The account-like object.
31
+ * @returns The account as normal `KeyringAccount`.
32
+ */
33
+ export declare function assertKeyringAccount<Account extends {
34
+ type: KeyringAccountType;
35
+ }>(account: Account): KeyringAccount;
36
+ /**
37
+ * Transform any versionned account to a `KeyringAccount`.
38
+ *
39
+ * @param accountToTransform - The account to transform.
40
+ * @returns A valid transformed `KeyringAccount`.
41
+ */
42
+ export declare function transformAccount(accountToTransform: KeyringAccountV1 | KeyringAccount): KeyringAccount;
26
43
  //# sourceMappingURL=account.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.mts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,KAAK,EAAE,8BAA8B;AAEzD;;;GAGG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;aAAyC,CAAC;AAE7E,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
1
+ {"version":3,"file":"account.d.mts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,8BAA8B;AAWhF,OAAO,EAAgB,KAAK,KAAK,EAAE,8BAA8B;AAIjE;;;GAGG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;aAAyC,CAAC;AAE7E,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEpE;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,SAAS;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,EAC5C,OAAO,EAAE,OAAO,GAAG,cAAc,CA2BlC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAE9B,kBAAkB,EAAE,gBAAgB,GAAG,cAAc,GACpD,cAAc,CAShB"}
package/dist/account.mjs CHANGED
@@ -1,8 +1,60 @@
1
- import { KeyringAccountStruct } from "@metamask/keyring-api";
2
- import { omit } from "@metamask/superstruct";
1
+ import { BtcAccountType, BtcP2wpkhAccountStruct, EthAccountType, EthEoaAccountStruct, EthErc4337AccountStruct, KeyringAccountStruct, SolAccountType, SolDataAccountStruct } from "@metamask/keyring-api";
2
+ import { assert, omit } from "@metamask/superstruct";
3
+ import { isAccountV1, transformAccountV1 } from "./migrations/index.mjs";
3
4
  /**
4
5
  * A `KeyringAccount` with some optional fields which can be used to keep
5
6
  * the retro-compatility with older version of keyring accounts/events.
6
7
  */
7
8
  export const KeyringAccountV1Struct = omit(KeyringAccountStruct, ['scopes']);
9
+ /**
10
+ * Assert that an account-like object matches its actual account type.
11
+ *
12
+ * @param account - The account-like object.
13
+ * @returns The account as normal `KeyringAccount`.
14
+ */
15
+ export function assertKeyringAccount(account) {
16
+ // TODO: We should use a `selectiveUnion` for this and probably use it to define
17
+ // the `KeyringAccount`. This would also required to have a "generic `KeyringAccount`"
18
+ // definition.
19
+ switch (account.type) {
20
+ case BtcAccountType.P2wpkh: {
21
+ assert(account, BtcP2wpkhAccountStruct);
22
+ return account;
23
+ }
24
+ case SolAccountType.DataAccount: {
25
+ assert(account, SolDataAccountStruct);
26
+ return account;
27
+ }
28
+ case EthAccountType.Erc4337: {
29
+ assert(account, EthErc4337AccountStruct);
30
+ return account;
31
+ }
32
+ case EthAccountType.Eoa: {
33
+ assert(account, EthEoaAccountStruct);
34
+ return account;
35
+ }
36
+ default: {
37
+ // For now, we cannot much more than this (this should also, never happen)!
38
+ // NOTE: We could use a "generic `KeyringAccount` type" here though.
39
+ throw new Error(`Unknown account type: '${account.type}'`);
40
+ }
41
+ }
42
+ }
43
+ /**
44
+ * Transform any versionned account to a `KeyringAccount`.
45
+ *
46
+ * @param accountToTransform - The account to transform.
47
+ * @returns A valid transformed `KeyringAccount`.
48
+ */
49
+ export function transformAccount(
50
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
51
+ accountToTransform) {
52
+ // To keep the retro-compatibility with older keyring-api versions, we identify the account's
53
+ // version and transform it to the latest `KeyringAccount` representation.
54
+ const account = isAccountV1(accountToTransform)
55
+ ? transformAccountV1(accountToTransform)
56
+ : accountToTransform;
57
+ // We still assert that the converted account is valid according to their account's type.
58
+ return assertKeyringAccount(account);
59
+ }
8
60
  //# sourceMappingURL=account.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.mjs","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAC7D,OAAO,EAAE,IAAI,EAAc,8BAA8B;AAEzD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import { KeyringAccountStruct } from '@metamask/keyring-api';\nimport { omit, type Infer } from '@metamask/superstruct';\n\n/**\n * A `KeyringAccount` with some optional fields which can be used to keep\n * the retro-compatility with older version of keyring accounts/events.\n */\nexport const KeyringAccountV1Struct = omit(KeyringAccountStruct, ['scopes']);\n\nexport type KeyringAccountV1 = Infer<typeof KeyringAccountV1Struct>;\n"]}
1
+ {"version":3,"file":"account.mjs","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,EACpB,c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,kBAAkB,CAAC;QAC7C,CAAC,CAAC,kBAAkB,CAAC,kBAAkB,CAAC;QACxC,CAAC,CAAC,kBAAkB,CAAC;IAEvB,yFAAyF;IACzF,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import type { KeyringAccount, KeyringAccountType } from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcP2wpkhAccountStruct,\n EthAccountType,\n EthEoaAccountStruct,\n EthErc4337AccountStruct,\n KeyringAccountStruct,\n SolAccountType,\n SolDataAccountStruct,\n} from '@metamask/keyring-api';\nimport { assert, omit, type Infer } from '@metamask/superstruct';\n\nimport { isAccountV1, transformAccountV1 } from './migrations';\n\n/**\n * A `KeyringAccount` with some optional fields which can be used to keep\n * the retro-compatility with older version of keyring accounts/events.\n */\nexport const KeyringAccountV1Struct = omit(KeyringAccountStruct, ['scopes']);\n\nexport type KeyringAccountV1 = Infer<typeof KeyringAccountV1Struct>;\n\n/**\n * Assert that an account-like object matches its actual account type.\n *\n * @param account - The account-like object.\n * @returns The account as normal `KeyringAccount`.\n */\nexport function assertKeyringAccount<\n Account extends { type: KeyringAccountType },\n>(account: Account): KeyringAccount {\n // TODO: We should use a `selectiveUnion` for this and probably use it to define\n // the `KeyringAccount`. This would also required to have a \"generic `KeyringAccount`\"\n // definition.\n switch (account.type) {\n case BtcAccountType.P2wpkh: {\n assert(account, BtcP2wpkhAccountStruct);\n return account;\n }\n case SolAccountType.DataAccount: {\n assert(account, SolDataAccountStruct);\n return account;\n }\n case EthAccountType.Erc4337: {\n assert(account, EthErc4337AccountStruct);\n return account;\n }\n case EthAccountType.Eoa: {\n assert(account, EthEoaAccountStruct);\n return account;\n }\n default: {\n // For now, we cannot much more than this (this should also, never happen)!\n // NOTE: We could use a \"generic `KeyringAccount` type\" here though.\n throw new Error(`Unknown account type: '${account.type}'`);\n }\n }\n}\n\n/**\n * Transform any versionned account to a `KeyringAccount`.\n *\n * @param accountToTransform - The account to transform.\n * @returns A valid transformed `KeyringAccount`.\n */\nexport function transformAccount(\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n accountToTransform: KeyringAccountV1 | KeyringAccount,\n): KeyringAccount {\n // To keep the retro-compatibility with older keyring-api versions, we identify the account's\n // version and transform it to the latest `KeyringAccount` representation.\n const account = isAccountV1(accountToTransform)\n ? transformAccountV1(accountToTransform)\n : accountToTransform;\n\n // We still assert that the converted account is valid according to their account's type.\n return assertKeyringAccount(account);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,oDAA8B","sourcesContent":["export * from './types';\nexport * from './SnapKeyring';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,oDAA8B","sourcesContent":["export * from './types';\nexport * from './SnapKeyring';\nexport type * from './SnapKeyringMessenger';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./types.cjs";
2
2
  export * from "./SnapKeyring.cjs";
3
+ export type * from "./SnapKeyringMessenger.cjs";
3
4
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B;AAC9B,gDAA4C"}
package/dist/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./types.mjs";
2
2
  export * from "./SnapKeyring.mjs";
3
+ export type * from "./SnapKeyringMessenger.mjs";
3
4
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B;AAC9B,gDAA4C"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B","sourcesContent":["export * from './types';\nexport * from './SnapKeyring';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B","sourcesContent":["export * from './types';\nexport * from './SnapKeyring';\nexport type * from './SnapKeyringMessenger';\n"]}
@@ -30,30 +30,31 @@ function getScopesForAccountV1(accountV1) {
30
30
  case keyring_api_1.EthAccountType.Eoa: {
31
31
  // EVM EOA account are compatible with any EVM networks, and we use CAIP-2
32
32
  // namespaces when the scope relates to ALL chains (from that namespace).
33
- return [keyring_api_1.EthScopes.Namespace];
33
+ return [keyring_api_1.EthScope.Namespace];
34
34
  }
35
35
  case keyring_api_1.EthAccountType.Erc4337: {
36
36
  // EVM Erc4337 account
37
- // NOTE: A Smart Contract account might not be compatible with every chain, but we still use
38
- // "generic" scope for now. Also, there's no official Snap as of today that uses this account type. So
39
- // this case should never happen.
40
- return [keyring_api_1.EthScopes.Namespace];
37
+ // NOTE: A Smart Contract account might not be compatible with every chain, in this case we just default
38
+ // to testnet since we cannot really "guess" it from here.
39
+ // Also, there's no official Snap as of today that uses this account type. So this case should never happen
40
+ // in production.
41
+ return [keyring_api_1.EthScope.Testnet];
41
42
  }
42
43
  case keyring_api_1.BtcAccountType.P2wpkh: {
43
44
  // Bitcoin uses different accounts for testnet and mainnet
44
45
  return [
45
46
  (0, keyring_utils_1.isBtcMainnetAddress)(accountV1.address)
46
- ? keyring_api_1.BtcScopes.Mainnet
47
- : keyring_api_1.BtcScopes.Testnet,
47
+ ? keyring_api_1.BtcScope.Mainnet
48
+ : keyring_api_1.BtcScope.Testnet,
48
49
  ];
49
50
  }
50
51
  case keyring_api_1.SolAccountType.DataAccount: {
51
52
  // Solana account supports multiple chains.
52
- return [keyring_api_1.SolScopes.Mainnet, keyring_api_1.SolScopes.Testnet, keyring_api_1.SolScopes.Devnet];
53
+ return [keyring_api_1.SolScope.Mainnet, keyring_api_1.SolScope.Testnet, keyring_api_1.SolScope.Devnet];
53
54
  }
54
55
  default:
55
56
  // We re-use EOA scopes if we don't know what to do for now.
56
- return [keyring_api_1.EthScopes.Namespace];
57
+ return [keyring_api_1.EthScope.Namespace];
57
58
  }
58
59
  }
59
60
  /**
@@ -67,20 +68,19 @@ function getScopesForAccountV1(accountV1) {
67
68
  */
68
69
  function transformAccountV1(accountV1) {
69
70
  const { type } = accountV1;
70
- if (!isAccountV1(accountV1)) {
71
- // Nothing to do in this case.
72
- return accountV1;
73
- }
71
+ // EVM EOA account are compatible with any EVM networks, and we use CAIP-2
72
+ // namespaces when the scope relates to ALL chains (from that namespace).
73
+ // So we can automatically inject a valid `scopes` for this, but not for
74
+ // other kind of accounts.
74
75
  if (type === keyring_api_1.EthAccountType.Eoa) {
75
- // EVM EOA account are compatible with any EVM networks, and we use CAIP-2
76
- // namespaces when the scope relates to ALL chains (from that namespace).
77
76
  return {
78
77
  ...accountV1,
79
78
  scopes: getScopesForAccountV1(accountV1),
80
79
  };
81
80
  }
82
- // For all non-EVM Snaps and ERC4337 Snaps, the scopes is required.
83
- throw new Error(`Account scopes is required for non-EVM and ERC4337 accounts`);
81
+ // For all other non-EVM and ERC4337 Snap accounts, the `scopes` is required, and
82
+ // each `*AccountStruct` should assert that automatically.
83
+ return (0, account_1.assertKeyringAccount)(accountV1);
84
84
  }
85
85
  /**
86
86
  * Migrate an account v1. This account might have optional fields that are now required by
@@ -1 +1 @@
1
- {"version":3,"file":"v1.cjs","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":";;AAoBA,kCAKC;AAQ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AAG,SAAS,CAAC;IAE3B,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,8BAA8B;QAC9B,OAAO,SAA2B,CAAC;IACrC,CAAC;IAED,IAAI,IAAI,KAAK,4BAAc,CAAC,GAAG,EAAE,CAAC;QAChC,0EAA0E;QAC1E,yEAAyE;QACzE,OAAO;YACL,GAAG,SAAS;YACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;SACzC,CAAC;IACJ,CAAC;IAED,mEAAmE;IACnE,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAAC,SAA2B;IAC1D,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,8BAA8B;QAC9B,OAAO,SAA2B,CAAC;IACrC,CAAC;IAED,OAAO;QACL,GAAG,SAAS;QACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import {\n BtcAccountType,\n BtcScopes,\n EthAccountType,\n EthScopes,\n SolAccountType,\n SolScopes,\n type KeyringAccount,\n} from '@metamask/keyring-api';\nimport { isBtcMainnetAddress } from '@metamask/keyring-utils';\nimport { is } from '@metamask/superstruct';\n\nimport { KeyringAccountV1Struct, type KeyringAccountV1 } from '../account';\n\n/**\n * Checks if an account is an `KeyringAccount` v1.\n *\n * @param account - A v1 account to check.\n * @returns True if the account is v1, false otherwise.\n */\nexport function isAccountV1(\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n account: KeyringAccountV1 | KeyringAccount,\n): boolean {\n return is(account, KeyringAccountV1Struct);\n}\n\n/**\n * Gets default scopes for a v1 account.\n *\n * @param accountV1 - A v1 account.\n * @returns The list of scopes for that accounts.\n */\nexport function getScopesForAccountV1(accountV1: KeyringAccountV1): string[] {\n switch (accountV1.type) {\n case EthAccountType.Eoa: {\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n return [EthScopes.Namespace];\n }\n case EthAccountType.Erc4337: {\n // EVM Erc4337 account\n // NOTE: A Smart Contract account might not be compatible with every chain, but we still use\n // \"generic\" scope for now. Also, there's no official Snap as of today that uses this account type. So\n // this case should never happen.\n return [EthScopes.Namespace];\n }\n case BtcAccountType.P2wpkh: {\n // Bitcoin uses different accounts for testnet and mainnet\n return [\n isBtcMainnetAddress(accountV1.address)\n ? BtcScopes.Mainnet\n : BtcScopes.Testnet,\n ];\n }\n case SolAccountType.DataAccount: {\n // Solana account supports multiple chains.\n return [SolScopes.Mainnet, SolScopes.Testnet, SolScopes.Devnet];\n }\n default:\n // We re-use EOA scopes if we don't know what to do for now.\n return [EthScopes.Namespace];\n }\n}\n\n/**\n * Transform an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * default values.\n *\n * @param accountV1 - A v1 account to transform.\n * @throws An error if the v1 account cannot be transformed.\n * @returns A valid KeyringAccount.\n */\nexport function transformAccountV1(\n accountV1: KeyringAccountV1,\n): KeyringAccount {\n const { type } = accountV1;\n\n if (!isAccountV1(accountV1)) {\n // Nothing to do in this case.\n return accountV1 as KeyringAccount;\n }\n\n if (type === EthAccountType.Eoa) {\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n }\n\n // For all non-EVM Snaps and ERC4337 Snaps, the scopes is required.\n throw new Error(\n `Account scopes is required for non-EVM and ERC4337 accounts`,\n );\n}\n\n/**\n * Migrate an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * meaningful default values.\n *\n * @param accountV1 - The account to migrate.\n * @returns A valid KeyringAccount.\n */\nexport function migrateAccountV1(accountV1: KeyringAccountV1): KeyringAccount {\n if (!isAccountV1(accountV1)) {\n // Nothing to do in this case.\n return accountV1 as KeyringAccount;\n }\n\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n}\n"]}
1
+ {"version":3,"file":"v1.cjs","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":";;AAwBA,kCAKC;AAQD,sDA+BC;AAWD,gDAmBC;AAUD,4CAUC;AAtHD,uDAQ+B;AAC/B,2DAA8D;AAC9D,uDAA2C;AAE3C,4CAIoB;AAEpB;;;;;GAKG;AACH,SAAgB,WAAW;AACzB,6EAA6E;AAC7E,OAA0C;IAE1C,OAAO,IAAA,gBAAE,EAAC,OAAO,EAAE,gCAAsB,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,SAA2B;IAC/D,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,KAAK,4BAAc,CAAC,GAAG,CAAC,CAAC,CAAC;YACxB,0EAA0E;YAC1E,yEAAyE;YACzE,OAAO,CAAC,sBAAQ,CAAC,SAAS,CAAC,CAAC;QAC9B,CAAC;QACD,KAAK,4BAAc,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5B,sBAAsB;YACtB,wGAAwG;YACxG,0DAA0D;YAC1D,2GAA2G;YAC3G,iBAAiB;YACjB,OAAO,CAAC,sBAAQ,CAAC,OAAO,CAAC,CAAC;QAC5B,CAAC;QACD,KAAK,4BAAc,CAAC,MAAM,CAAC,CAAC,CAAC;YAC3B,0DAA0D;YAC1D,OAAO;gBACL,IAAA,mCAAmB,EAAC,SAAS,CAAC,OAAO,CAAC;oBACpC,CAAC,CAAC,sBAAQ,CAAC,OAAO;oBAClB,CAAC,CAAC,sBAAQ,CAAC,OAAO;aACrB,CAAC;QACJ,CAAC;QACD,KAAK,4BAAc,CAAC,WAAW,CAAC,CAAC,CAAC;YAChC,2CAA2C;YAC3C,OAAO,CAAC,sBAAQ,CAAC,OAAO,EAAE,sBAAQ,CAAC,OAAO,EAAE,sBAAQ,CAAC,MAAM,CAAC,CAAC;QAC/D,CAAC;QACD;YACE,4DAA4D;YAC5D,OAAO,CAAC,sBAAQ,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAChC,SAA2B;IAE3B,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC;IAE3B,0EAA0E;IAC1E,yEAAyE;IACzE,wEAAwE;IACxE,0BAA0B;IAC1B,IAAI,IAAI,KAAK,4BAAc,CAAC,GAAG,EAAE,CAAC;QAChC,OAAO;YACL,GAAG,SAAS;YACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;SACzC,CAAC;IACJ,CAAC;IAED,iFAAiF;IACjF,0DAA0D;IAC1D,OAAO,IAAA,8BAAoB,EAAC,SAAS,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAAC,SAA2B;IAC1D,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,8BAA8B;QAC9B,OAAO,SAA2B,CAAC;IACrC,CAAC;IAED,OAAO;QACL,GAAG,SAAS;QACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import {\n BtcAccountType,\n BtcScope,\n EthAccountType,\n EthScope,\n SolAccountType,\n SolScope,\n type KeyringAccount,\n} from '@metamask/keyring-api';\nimport { isBtcMainnetAddress } from '@metamask/keyring-utils';\nimport { is } from '@metamask/superstruct';\n\nimport {\n assertKeyringAccount,\n KeyringAccountV1Struct,\n type KeyringAccountV1,\n} from '../account';\n\n/**\n * Checks if an account is an `KeyringAccount` v1.\n *\n * @param account - A v1 account to check.\n * @returns True if the account is v1, false otherwise.\n */\nexport function isAccountV1(\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n account: KeyringAccountV1 | KeyringAccount,\n): boolean {\n return is(account, KeyringAccountV1Struct);\n}\n\n/**\n * Gets default scopes for a v1 account.\n *\n * @param accountV1 - A v1 account.\n * @returns The list of scopes for that accounts.\n */\nexport function getScopesForAccountV1(accountV1: KeyringAccountV1): string[] {\n switch (accountV1.type) {\n case EthAccountType.Eoa: {\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n return [EthScope.Namespace];\n }\n case EthAccountType.Erc4337: {\n // EVM Erc4337 account\n // NOTE: A Smart Contract account might not be compatible with every chain, in this case we just default\n // to testnet since we cannot really \"guess\" it from here.\n // Also, there's no official Snap as of today that uses this account type. So this case should never happen\n // in production.\n return [EthScope.Testnet];\n }\n case BtcAccountType.P2wpkh: {\n // Bitcoin uses different accounts for testnet and mainnet\n return [\n isBtcMainnetAddress(accountV1.address)\n ? BtcScope.Mainnet\n : BtcScope.Testnet,\n ];\n }\n case SolAccountType.DataAccount: {\n // Solana account supports multiple chains.\n return [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet];\n }\n default:\n // We re-use EOA scopes if we don't know what to do for now.\n return [EthScope.Namespace];\n }\n}\n\n/**\n * Transform an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * default values.\n *\n * @param accountV1 - A v1 account to transform.\n * @throws An error if the v1 account cannot be transformed.\n * @returns A valid KeyringAccount.\n */\nexport function transformAccountV1(\n accountV1: KeyringAccountV1,\n): KeyringAccount {\n const { type } = accountV1;\n\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n // So we can automatically inject a valid `scopes` for this, but not for\n // other kind of accounts.\n if (type === EthAccountType.Eoa) {\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n }\n\n // For all other non-EVM and ERC4337 Snap accounts, the `scopes` is required, and\n // each `*AccountStruct` should assert that automatically.\n return assertKeyringAccount(accountV1);\n}\n\n/**\n * Migrate an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * meaningful default values.\n *\n * @param accountV1 - The account to migrate.\n * @returns A valid KeyringAccount.\n */\nexport function migrateAccountV1(accountV1: KeyringAccountV1): KeyringAccount {\n if (!isAccountV1(accountV1)) {\n // Nothing to do in this case.\n return accountV1 as KeyringAccount;\n }\n\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"v1.d.cts","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,cAAc,EACpB,8BAA8B;AAI/B,OAAO,EAA0B,KAAK,gBAAgB,EAAE,uBAAmB;AAE3E;;;;;GAKG;AACH,wBAAgB,WAAW,CAEzB,OAAO,EAAE,gBAAgB,GAAG,cAAc,GACzC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,EAAE,CA8B3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,gBAAgB,GAC1B,cAAc,CAqBhB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,GAAG,cAAc,CAU5E"}
1
+ {"version":3,"file":"v1.d.cts","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,cAAc,EACpB,8BAA8B;AAI/B,OAAO,EAGL,KAAK,gBAAgB,EACtB,uBAAmB;AAEpB;;;;;GAKG;AACH,wBAAgB,WAAW,CAEzB,OAAO,EAAE,gBAAgB,GAAG,cAAc,GACzC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,EAAE,CA+B3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,gBAAgB,GAC1B,cAAc,CAiBhB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,GAAG,cAAc,CAU5E"}
@@ -1 +1 @@
1
- {"version":3,"file":"v1.d.mts","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,cAAc,EACpB,8BAA8B;AAI/B,OAAO,EAA0B,KAAK,gBAAgB,EAAE,uBAAmB;AAE3E;;;;;GAKG;AACH,wBAAgB,WAAW,CAEzB,OAAO,EAAE,gBAAgB,GAAG,cAAc,GACzC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,EAAE,CA8B3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,gBAAgB,GAC1B,cAAc,CAqBhB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,GAAG,cAAc,CAU5E"}
1
+ {"version":3,"file":"v1.d.mts","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,cAAc,EACpB,8BAA8B;AAI/B,OAAO,EAGL,KAAK,gBAAgB,EACtB,uBAAmB;AAEpB;;;;;GAKG;AACH,wBAAgB,WAAW,CAEzB,OAAO,EAAE,gBAAgB,GAAG,cAAc,GACzC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,EAAE,CA+B3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,gBAAgB,GAC1B,cAAc,CAiBhB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,GAAG,cAAc,CAU5E"}
@@ -1,7 +1,7 @@
1
- import { BtcAccountType, BtcScopes, EthAccountType, EthScopes, SolAccountType, SolScopes } from "@metamask/keyring-api";
1
+ import { BtcAccountType, BtcScope, EthAccountType, EthScope, SolAccountType, SolScope } from "@metamask/keyring-api";
2
2
  import { isBtcMainnetAddress } from "@metamask/keyring-utils";
3
3
  import { is } from "@metamask/superstruct";
4
- import { KeyringAccountV1Struct } from "../account.mjs";
4
+ import { assertKeyringAccount, KeyringAccountV1Struct } from "../account.mjs";
5
5
  /**
6
6
  * Checks if an account is an `KeyringAccount` v1.
7
7
  *
@@ -24,30 +24,31 @@ export function getScopesForAccountV1(accountV1) {
24
24
  case EthAccountType.Eoa: {
25
25
  // EVM EOA account are compatible with any EVM networks, and we use CAIP-2
26
26
  // namespaces when the scope relates to ALL chains (from that namespace).
27
- return [EthScopes.Namespace];
27
+ return [EthScope.Namespace];
28
28
  }
29
29
  case EthAccountType.Erc4337: {
30
30
  // EVM Erc4337 account
31
- // NOTE: A Smart Contract account might not be compatible with every chain, but we still use
32
- // "generic" scope for now. Also, there's no official Snap as of today that uses this account type. So
33
- // this case should never happen.
34
- return [EthScopes.Namespace];
31
+ // NOTE: A Smart Contract account might not be compatible with every chain, in this case we just default
32
+ // to testnet since we cannot really "guess" it from here.
33
+ // Also, there's no official Snap as of today that uses this account type. So this case should never happen
34
+ // in production.
35
+ return [EthScope.Testnet];
35
36
  }
36
37
  case BtcAccountType.P2wpkh: {
37
38
  // Bitcoin uses different accounts for testnet and mainnet
38
39
  return [
39
40
  isBtcMainnetAddress(accountV1.address)
40
- ? BtcScopes.Mainnet
41
- : BtcScopes.Testnet,
41
+ ? BtcScope.Mainnet
42
+ : BtcScope.Testnet,
42
43
  ];
43
44
  }
44
45
  case SolAccountType.DataAccount: {
45
46
  // Solana account supports multiple chains.
46
- return [SolScopes.Mainnet, SolScopes.Testnet, SolScopes.Devnet];
47
+ return [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet];
47
48
  }
48
49
  default:
49
50
  // We re-use EOA scopes if we don't know what to do for now.
50
- return [EthScopes.Namespace];
51
+ return [EthScope.Namespace];
51
52
  }
52
53
  }
53
54
  /**
@@ -61,20 +62,19 @@ export function getScopesForAccountV1(accountV1) {
61
62
  */
62
63
  export function transformAccountV1(accountV1) {
63
64
  const { type } = accountV1;
64
- if (!isAccountV1(accountV1)) {
65
- // Nothing to do in this case.
66
- return accountV1;
67
- }
65
+ // EVM EOA account are compatible with any EVM networks, and we use CAIP-2
66
+ // namespaces when the scope relates to ALL chains (from that namespace).
67
+ // So we can automatically inject a valid `scopes` for this, but not for
68
+ // other kind of accounts.
68
69
  if (type === EthAccountType.Eoa) {
69
- // EVM EOA account are compatible with any EVM networks, and we use CAIP-2
70
- // namespaces when the scope relates to ALL chains (from that namespace).
71
70
  return {
72
71
  ...accountV1,
73
72
  scopes: getScopesForAccountV1(accountV1),
74
73
  };
75
74
  }
76
- // For all non-EVM Snaps and ERC4337 Snaps, the scopes is required.
77
- throw new Error(`Account scopes is required for non-EVM and ERC4337 accounts`);
75
+ // For all other non-EVM and ERC4337 Snap accounts, the `scopes` is required, and
76
+ // each `*AccountStruct` should assert that automatically.
77
+ return assertKeyringAccount(accountV1);
78
78
  }
79
79
  /**
80
80
  * Migrate an account v1. This account might have optional fields that are now required by
@@ -1 +1 @@
1
- {"version":3,"file":"v1.mjs","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,cAAc,EACd,SAAS,EACT,cAAc,EACd,SAAS,EAEV,8BAA8B;AAC/B,OAAO,EAAE,mBAAmB,EAAE,gCAAgC;AAC9D,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EAAE,sBAAsB,EAAyB,uBAAmB;AAE3E;;;;;GAKG;AACH,MAAM,UAAU,WAAW;AACzB,6EAA6E;AAC7E,OAA0C;IAE1C,OAAO,EAAE,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAA2B;IAC/D,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,KAAK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CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAA2B;IAC1D,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,8BAA8B;QAC9B,OAAO,SAA2B,CAAC;IACrC,CAAC;IAED,OAAO;QACL,GAAG,SAAS;QACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import {\n BtcAccountType,\n BtcScopes,\n EthAccountType,\n EthScopes,\n SolAccountType,\n SolScopes,\n type KeyringAccount,\n} from '@metamask/keyring-api';\nimport { isBtcMainnetAddress } from '@metamask/keyring-utils';\nimport { is } from '@metamask/superstruct';\n\nimport { KeyringAccountV1Struct, type KeyringAccountV1 } from '../account';\n\n/**\n * Checks if an account is an `KeyringAccount` v1.\n *\n * @param account - A v1 account to check.\n * @returns True if the account is v1, false otherwise.\n */\nexport function isAccountV1(\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n account: KeyringAccountV1 | KeyringAccount,\n): boolean {\n return is(account, KeyringAccountV1Struct);\n}\n\n/**\n * Gets default scopes for a v1 account.\n *\n * @param accountV1 - A v1 account.\n * @returns The list of scopes for that accounts.\n */\nexport function getScopesForAccountV1(accountV1: KeyringAccountV1): string[] {\n switch (accountV1.type) {\n case EthAccountType.Eoa: {\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n return [EthScopes.Namespace];\n }\n case EthAccountType.Erc4337: {\n // EVM Erc4337 account\n // NOTE: A Smart Contract account might not be compatible with every chain, but we still use\n // \"generic\" scope for now. Also, there's no official Snap as of today that uses this account type. So\n // this case should never happen.\n return [EthScopes.Namespace];\n }\n case BtcAccountType.P2wpkh: {\n // Bitcoin uses different accounts for testnet and mainnet\n return [\n isBtcMainnetAddress(accountV1.address)\n ? BtcScopes.Mainnet\n : BtcScopes.Testnet,\n ];\n }\n case SolAccountType.DataAccount: {\n // Solana account supports multiple chains.\n return [SolScopes.Mainnet, SolScopes.Testnet, SolScopes.Devnet];\n }\n default:\n // We re-use EOA scopes if we don't know what to do for now.\n return [EthScopes.Namespace];\n }\n}\n\n/**\n * Transform an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * default values.\n *\n * @param accountV1 - A v1 account to transform.\n * @throws An error if the v1 account cannot be transformed.\n * @returns A valid KeyringAccount.\n */\nexport function transformAccountV1(\n accountV1: KeyringAccountV1,\n): KeyringAccount {\n const { type } = accountV1;\n\n if (!isAccountV1(accountV1)) {\n // Nothing to do in this case.\n return accountV1 as KeyringAccount;\n }\n\n if (type === EthAccountType.Eoa) {\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n }\n\n // For all non-EVM Snaps and ERC4337 Snaps, the scopes is required.\n throw new Error(\n `Account scopes is required for non-EVM and ERC4337 accounts`,\n );\n}\n\n/**\n * Migrate an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * meaningful default values.\n *\n * @param accountV1 - The account to migrate.\n * @returns A valid KeyringAccount.\n */\nexport function migrateAccountV1(accountV1: KeyringAccountV1): KeyringAccount {\n if (!isAccountV1(accountV1)) {\n // Nothing to do in this case.\n return accountV1 as KeyringAccount;\n }\n\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n}\n"]}
1
+ {"version":3,"file":"v1.mjs","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,QAAQ,EACR,cAAc,EACd,QAAQ,EACR,cAAc,EACd,QAAQ,EAET,8BAA8B;AAC/B,OAAO,EAAE,mBAAmB,EAAE,gCAAgC;AAC9D,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EACL,oBAAoB,EACpB,sBAAsB,E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0B;IAC1B,IAAI,IAAI,KAAK,cAAc,CAAC,GAAG,EAAE,CAAC;QAChC,OAAO;YACL,GAAG,SAAS;YACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;SACzC,CAAC;IACJ,CAAC;IAED,iFAAiF;IACjF,0DAA0D;IAC1D,OAAO,oBAAoB,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAA2B;IAC1D,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,8BAA8B;QAC9B,OAAO,SAA2B,CAAC;IACrC,CAAC;IAED,OAAO;QACL,GAAG,SAAS;QACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import {\n BtcAccountType,\n BtcScope,\n EthAccountType,\n EthScope,\n SolAccountType,\n SolScope,\n type KeyringAccount,\n} from '@metamask/keyring-api';\nimport { isBtcMainnetAddress } from '@metamask/keyring-utils';\nimport { is } from '@metamask/superstruct';\n\nimport {\n assertKeyringAccount,\n KeyringAccountV1Struct,\n type KeyringAccountV1,\n} from '../account';\n\n/**\n * Checks if an account is an `KeyringAccount` v1.\n *\n * @param account - A v1 account to check.\n * @returns True if the account is v1, false otherwise.\n */\nexport function isAccountV1(\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n account: KeyringAccountV1 | KeyringAccount,\n): boolean {\n return is(account, KeyringAccountV1Struct);\n}\n\n/**\n * Gets default scopes for a v1 account.\n *\n * @param accountV1 - A v1 account.\n * @returns The list of scopes for that accounts.\n */\nexport function getScopesForAccountV1(accountV1: KeyringAccountV1): string[] {\n switch (accountV1.type) {\n case EthAccountType.Eoa: {\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n return [EthScope.Namespace];\n }\n case EthAccountType.Erc4337: {\n // EVM Erc4337 account\n // NOTE: A Smart Contract account might not be compatible with every chain, in this case we just default\n // to testnet since we cannot really \"guess\" it from here.\n // Also, there's no official Snap as of today that uses this account type. So this case should never happen\n // in production.\n return [EthScope.Testnet];\n }\n case BtcAccountType.P2wpkh: {\n // Bitcoin uses different accounts for testnet and mainnet\n return [\n isBtcMainnetAddress(accountV1.address)\n ? BtcScope.Mainnet\n : BtcScope.Testnet,\n ];\n }\n case SolAccountType.DataAccount: {\n // Solana account supports multiple chains.\n return [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet];\n }\n default:\n // We re-use EOA scopes if we don't know what to do for now.\n return [EthScope.Namespace];\n }\n}\n\n/**\n * Transform an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * default values.\n *\n * @param accountV1 - A v1 account to transform.\n * @throws An error if the v1 account cannot be transformed.\n * @returns A valid KeyringAccount.\n */\nexport function transformAccountV1(\n accountV1: KeyringAccountV1,\n): KeyringAccount {\n const { type } = accountV1;\n\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n // So we can automatically inject a valid `scopes` for this, but not for\n // other kind of accounts.\n if (type === EthAccountType.Eoa) {\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n }\n\n // For all other non-EVM and ERC4337 Snap accounts, the `scopes` is required, and\n // each `*AccountStruct` should assert that automatically.\n return assertKeyringAccount(accountV1);\n}\n\n/**\n * Migrate an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * meaningful default values.\n *\n * @param accountV1 - The account to migrate.\n * @returns A valid KeyringAccount.\n */\nexport function migrateAccountV1(accountV1: KeyringAccountV1): KeyringAccount {\n if (!isAccountV1(accountV1)) {\n // Nothing to do in this case.\n return accountV1 as KeyringAccount;\n }\n\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/eth-snap-keyring",
3
- "version": "8.1.1-7fd7a95",
3
+ "version": "9.0.0-0aca2ee",
4
4
  "description": "Snaps keyring bridge.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,10 +40,10 @@
40
40
  "@ethereumjs/tx": "^4.2.0",
41
41
  "@metamask/base-controller": "^7.1.1",
42
42
  "@metamask/eth-sig-util": "^8.1.2",
43
- "@metamask/keyring-api": "14.0.0",
44
- "@metamask/keyring-internal-api": "2.0.1",
45
- "@metamask/keyring-internal-snap-client": "3.0.0",
46
- "@metamask/keyring-utils": "1.2.0",
43
+ "@metamask/keyring-api": "15.0.0",
44
+ "@metamask/keyring-internal-api": "3.0.0",
45
+ "@metamask/keyring-internal-snap-client": "3.0.1",
46
+ "@metamask/keyring-utils": "1.3.0",
47
47
  "@metamask/superstruct": "^3.1.0",
48
48
  "@metamask/utils": "^11.0.1",
49
49
  "@types/uuid": "^9.0.8",