@metamask/snaps-controllers 11.2.3 → 12.0.1
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 +30 -1
- package/dist/cronjob/CronjobController.cjs +6 -9
- package/dist/cronjob/CronjobController.cjs.map +1 -1
- package/dist/cronjob/CronjobController.d.cts +1 -1
- package/dist/cronjob/CronjobController.d.cts.map +1 -1
- package/dist/cronjob/CronjobController.d.mts +1 -1
- package/dist/cronjob/CronjobController.d.mts.map +1 -1
- package/dist/cronjob/CronjobController.mjs +6 -9
- package/dist/cronjob/CronjobController.mjs.map +1 -1
- package/dist/multichain/MultichainRouter.cjs +1 -1
- package/dist/multichain/MultichainRouter.cjs.map +1 -1
- package/dist/multichain/MultichainRouter.mjs +1 -1
- package/dist/multichain/MultichainRouter.mjs.map +1 -1
- package/dist/services/browser.cjs +0 -3
- package/dist/services/browser.cjs.map +1 -1
- package/dist/services/browser.d.cts +0 -1
- package/dist/services/browser.d.cts.map +1 -1
- package/dist/services/browser.d.mts +0 -1
- package/dist/services/browser.d.mts.map +1 -1
- package/dist/services/browser.mjs +0 -1
- package/dist/services/browser.mjs.map +1 -1
- package/dist/services/index.cjs +0 -3
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +0 -1
- package/dist/services/index.d.cts.map +1 -1
- package/dist/services/index.d.mts +0 -1
- package/dist/services/index.d.mts.map +1 -1
- package/dist/services/index.mjs +0 -1
- package/dist/services/index.mjs.map +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.cjs +3 -3
- package/dist/services/node-js/NodeProcessExecutionService.cjs.map +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.d.cts.map +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.d.mts.map +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.mjs +2 -2
- package/dist/services/node-js/NodeProcessExecutionService.mjs.map +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.cjs +3 -3
- package/dist/services/node-js/NodeThreadExecutionService.cjs.map +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.d.cts.map +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.d.mts.map +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.mjs +2 -2
- package/dist/services/node-js/NodeThreadExecutionService.mjs.map +1 -1
- package/dist/services/webview/WebViewMessageStream.cjs +4 -5
- package/dist/services/webview/WebViewMessageStream.cjs.map +1 -1
- package/dist/services/webview/WebViewMessageStream.d.cts.map +1 -1
- package/dist/services/webview/WebViewMessageStream.d.mts.map +1 -1
- package/dist/services/webview/WebViewMessageStream.mjs +1 -2
- package/dist/services/webview/WebViewMessageStream.mjs.map +1 -1
- package/dist/snaps/SnapController.cjs +36 -18
- package/dist/snaps/SnapController.cjs.map +1 -1
- package/dist/snaps/SnapController.d.cts +13 -15
- package/dist/snaps/SnapController.d.cts.map +1 -1
- package/dist/snaps/SnapController.d.mts +13 -15
- package/dist/snaps/SnapController.d.mts.map +1 -1
- package/dist/snaps/SnapController.mjs +37 -19
- package/dist/snaps/SnapController.mjs.map +1 -1
- package/dist/snaps/registry/json.cjs +3 -12
- package/dist/snaps/registry/json.cjs.map +1 -1
- package/dist/snaps/registry/json.d.cts.map +1 -1
- package/dist/snaps/registry/json.d.mts.map +1 -1
- package/dist/snaps/registry/json.mjs +3 -12
- package/dist/snaps/registry/json.mjs.map +1 -1
- package/dist/snaps/registry/registry.cjs.map +1 -1
- package/dist/snaps/registry/registry.d.cts +1 -1
- package/dist/snaps/registry/registry.d.cts.map +1 -1
- package/dist/snaps/registry/registry.d.mts +1 -1
- package/dist/snaps/registry/registry.d.mts.map +1 -1
- package/dist/snaps/registry/registry.mjs.map +1 -1
- package/dist/utils.cjs +63 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +24 -0
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +24 -0
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +61 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +10 -10
- package/dist/services/webworker/WebWorkerExecutionService.cjs +0 -112
- package/dist/services/webworker/WebWorkerExecutionService.cjs.map +0 -1
- package/dist/services/webworker/WebWorkerExecutionService.d.cts +0 -47
- package/dist/services/webworker/WebWorkerExecutionService.d.cts.map +0 -1
- package/dist/services/webworker/WebWorkerExecutionService.d.mts +0 -47
- package/dist/services/webworker/WebWorkerExecutionService.d.mts.map +0 -1
- package/dist/services/webworker/WebWorkerExecutionService.mjs +0 -108
- package/dist/services/webworker/WebWorkerExecutionService.mjs.map +0 -1
- package/dist/services/webworker/index.cjs +0 -18
- package/dist/services/webworker/index.cjs.map +0 -1
- package/dist/services/webworker/index.d.cts +0 -2
- package/dist/services/webworker/index.d.cts.map +0 -1
- package/dist/services/webworker/index.d.mts +0 -2
- package/dist/services/webworker/index.d.mts.map +0 -1
- package/dist/services/webworker/index.mjs +0 -2
- package/dist/services/webworker/index.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainRouter.mjs","sourceRoot":"","sources":["../../src/multichain/MultichainRouter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EACL,uBAAuB,EACvB,cAAc,EACf,oCAAoC;AAGrC,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAMpD,OAAO,EACL,MAAM,EACN,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AACzB,OAAO,EAAE,MAAM,EAAE,eAAe;AAEhC,OAAO,EAAE,gBAAgB,EAAE,2BAAiB;AA+E5C,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAEhC,MAAM,OAAO,gBAAgB;IAS3B,YAAY,EAAE,SAAS,EAAE,eAAe,EAAwB;;QARhE,SAAI,GAAgB,IAAI,CAAC;QAEzB,UAAK,GAAG,IAAI,CAAC;QAEJ,8CAAsC;QAEtC,oDAA0C;QAGjD,uBAAA,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;SACxD,MAAM,CAAC,CAAC,OAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["import type { RestrictedMessenger } from '@metamask/base-controller';\nimport type { GetPermissions } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n getProtocolCaveatScopes,\n SnapEndowments,\n} from '@metamask/snaps-rpc-methods';\nimport type { Json, JsonRpcRequest, SnapId } from '@metamask/snaps-sdk';\nimport type { InternalAccount } from '@metamask/snaps-utils';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type {\n CaipAccountId,\n CaipChainId,\n JsonRpcParams,\n} from '@metamask/utils';\nimport {\n assert,\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport { getRunnableSnaps } from '../snaps';\nimport type { GetAllSnaps, HandleSnapRequest } from '../snaps';\n\nexport type MultichainRouterHandleRequestAction = {\n type: `${typeof name}:handleRequest`;\n handler: MultichainRouter['handleRequest'];\n};\n\nexport type MultichainRouterGetSupportedMethodsAction = {\n type: `${typeof name}:getSupportedMethods`;\n handler: MultichainRouter['getSupportedMethods'];\n};\n\nexport type MultichainRouterGetSupportedAccountsAction = {\n type: `${typeof name}:getSupportedAccounts`;\n handler: MultichainRouter['getSupportedAccounts'];\n};\n\nexport type MultichainRouterIsSupportedScopeAction = {\n type: `${typeof name}:isSupportedScope`;\n handler: MultichainRouter['isSupportedScope'];\n};\n\ntype SnapKeyring = {\n submitRequest: (request: {\n account: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n scope: CaipChainId;\n }) => Promise<Json>;\n resolveAccountAddress: (\n snapId: SnapId,\n scope: CaipChainId,\n request: Json,\n ) => Promise<{ address: CaipAccountId } | null>;\n};\n\n// Expecting a bound function that calls KeyringController.withKeyring selecting the Snap keyring\ntype WithSnapKeyringFunction = <ReturnType>(\n operation: ({ keyring }: { keyring: SnapKeyring }) => Promise<ReturnType>,\n) => Promise<ReturnType>;\n\nexport type AccountsControllerListMultichainAccountsAction = {\n type: `AccountsController:listMultichainAccounts`;\n handler: (chainId?: CaipChainId) => InternalAccount[];\n};\n\nexport type MultichainRouterActions =\n | MultichainRouterHandleRequestAction\n | MultichainRouterGetSupportedMethodsAction\n | MultichainRouterGetSupportedAccountsAction\n | MultichainRouterIsSupportedScopeAction;\n\nexport type MultichainRouterAllowedActions =\n | GetAllSnaps\n | HandleSnapRequest\n | GetPermissions\n | AccountsControllerListMultichainAccountsAction;\n\nexport type MultichainRouterEvents = never;\n\nexport type MultichainRouterMessenger = RestrictedMessenger<\n typeof name,\n MultichainRouterActions | MultichainRouterAllowedActions,\n never,\n MultichainRouterAllowedActions['type'],\n MultichainRouterEvents['type']\n>;\n\nexport type MultichainRouterArgs = {\n messenger: MultichainRouterMessenger;\n withSnapKeyring: WithSnapKeyringFunction;\n};\n\ntype ProtocolSnap = {\n snapId: SnapId;\n methods: string[];\n};\n\nconst name = 'MultichainRouter';\n\nexport class MultichainRouter {\n name: typeof name = name;\n\n state = null;\n\n readonly #messenger: MultichainRouterMessenger;\n\n readonly #withSnapKeyring: WithSnapKeyringFunction;\n\n constructor({ messenger, withSnapKeyring }: MultichainRouterArgs) {\n this.#messenger = messenger;\n this.#withSnapKeyring = withSnapKeyring;\n\n this.#messenger.registerActionHandler(\n `${name}:handleRequest`,\n async (...args) => this.handleRequest(...args),\n );\n\n this.#messenger.registerActionHandler(\n `${name}:getSupportedMethods`,\n (...args) => this.getSupportedMethods(...args),\n );\n\n this.#messenger.registerActionHandler(\n `${name}:getSupportedAccounts`,\n (...args) => this.getSupportedAccounts(...args),\n );\n\n this.#messenger.registerActionHandler(\n `${name}:isSupportedScope`,\n (...args) => this.isSupportedScope(...args),\n );\n }\n\n /**\n * Attempts to resolve the account address to use for a given request by inspecting the request itself.\n *\n * The request is sent to to an account Snap via the SnapKeyring that will attempt this resolution.\n *\n * @param snapId - The ID of the Snap to send the request to.\n * @param scope - The CAIP-2 scope for the request.\n * @param request - The JSON-RPC request.\n * @returns The resolved address if found, otherwise null.\n * @throws If the invocation of the SnapKeyring fails.\n */\n async #resolveRequestAddress(\n snapId: SnapId,\n scope: CaipChainId,\n request: JsonRpcRequest,\n ) {\n try {\n const result = await this.#withSnapKeyring(async ({ keyring }) =>\n keyring.resolveAccountAddress(snapId, scope, request),\n );\n const address = result?.address;\n return address ? parseCaipAccountId(address).address : null;\n } catch {\n throw rpcErrors.internal();\n }\n }\n\n /**\n * Get the account ID of the account that should service the RPC request via an account Snap.\n *\n * This function checks whether any accounts exist that can service a given request by\n * using a combination of the resolveAccountAddress functionality and the connected accounts.\n *\n * If an account is expected to service this request but none is found, the function will throw.\n *\n * @param connectedAddresses - The CAIP-10 addresses connected to the requesting origin.\n * @param scope - The CAIP-2 scope for the request.\n * @param request - The JSON-RPC request.\n * @returns An account ID if found, otherwise null.\n * @throws If no account is found, but the accounts exist that could service the request.\n */\n async #getSnapAccountId(\n connectedAddresses: CaipAccountId[],\n scope: CaipChainId,\n request: JsonRpcRequest,\n ) {\n const accounts = this.#messenger\n .call('AccountsController:listMultichainAccounts', scope)\n .filter(\n (\n account: InternalAccount,\n ): account is InternalAccount & {\n metadata: Required<InternalAccount['metadata']>;\n } =>\n Boolean(account.metadata.snap?.enabled) &&\n account.methods.includes(request.method),\n );\n\n // If no accounts can service the request, return null.\n if (accounts.length === 0) {\n return null;\n }\n\n const resolutionSnapId = accounts[0].metadata.snap.id;\n\n // Attempt to resolve the address that should be used for signing.\n const address = await this.#resolveRequestAddress(\n resolutionSnapId,\n scope,\n request,\n );\n\n const parsedConnectedAddresses = connectedAddresses.map(\n (connectedAddress) => parseCaipAccountId(connectedAddress).address,\n );\n\n // If we have a resolved address, try to find the selected account based on that\n // otherwise, default to one of the connected accounts.\n // TODO: Eventually let the user choose if we have more than one option for the account.\n const selectedAccount = accounts.find(\n (account) =>\n parsedConnectedAddresses.includes(account.address) &&\n (!address || account.address === address),\n );\n\n if (!selectedAccount) {\n throw rpcErrors.invalidParams({\n message: 'No available account found for request.',\n });\n }\n\n return selectedAccount.id;\n }\n\n /**\n * Get all protocol Snaps that can service a given CAIP-2 scope.\n *\n * Protocol Snaps are deemed fit to service a scope if they are runnable\n * and have the proper permissions set for the scope.\n *\n * @param scope - A CAIP-2 scope.\n * @returns A list of all the protocol Snaps available and their RPC methods.\n */\n #getProtocolSnaps(scope: CaipChainId) {\n const allSnaps = this.#messenger.call('SnapController:getAll');\n const filteredSnaps = getRunnableSnaps(allSnaps);\n\n return filteredSnaps.reduce<ProtocolSnap[]>((accumulator, snap) => {\n const permissions = this.#messenger.call(\n 'PermissionController:getPermissions',\n snap.id,\n );\n\n if (permissions && hasProperty(permissions, SnapEndowments.Protocol)) {\n const permission = permissions[SnapEndowments.Protocol];\n const scopes = getProtocolCaveatScopes(permission);\n if (scopes && hasProperty(scopes, scope)) {\n accumulator.push({\n snapId: snap.id,\n methods: scopes[scope].methods,\n });\n }\n }\n\n return accumulator;\n }, []);\n }\n\n /**\n * Handle an incoming JSON-RPC request tied to a specific scope by routing\n * to either a procotol Snap or an account Snap.\n *\n * Note: Addresses are considered case sensitive by the MultichainRouter as\n * not all non-EVM chains are case insensitive.\n *\n * @param options - An options bag.\n * @param options.connectedAddresses - Addresses currently connected to the origin.\n * @param options.origin - The origin of the RPC request.\n * @param options.request - The JSON-RPC request.\n * @param options.scope - The CAIP-2 scope for the request.\n * @returns The response from the chosen Snap.\n * @throws If no handler was found.\n */\n async handleRequest({\n connectedAddresses,\n origin,\n scope,\n request: rawRequest,\n }: {\n connectedAddresses: CaipAccountId[];\n origin: string;\n scope: CaipChainId;\n request: JsonRpcRequest;\n }): Promise<Json> {\n // Explicitly block EVM scopes, just in case.\n assert(\n !scope.startsWith(KnownCaipNamespace.Eip155) &&\n !scope.startsWith('wallet:eip155'),\n );\n\n // Re-create the request to simplify and remove additional properties that may be present in MM middleware.\n const request = {\n jsonrpc: '2.0' as const,\n id: rawRequest.id ?? nanoid(),\n method: rawRequest.method,\n params: rawRequest.params,\n };\n\n const { method, params } = request;\n\n // If the RPC request can be serviced by an account Snap, route it there.\n const accountId = await this.#getSnapAccountId(\n connectedAddresses,\n scope,\n request,\n );\n\n if (accountId) {\n return this.#withSnapKeyring(async ({ keyring }) =>\n keyring.submitRequest({\n account: accountId,\n scope,\n method,\n params: params as JsonRpcParams,\n }),\n );\n }\n\n // If the RPC request cannot be serviced by an account Snap,\n // but has a protocol Snap available, route it there.\n const protocolSnaps = this.#getProtocolSnaps(scope);\n const protocolSnap = protocolSnaps.find((snap) =>\n snap.methods.includes(method),\n );\n\n if (protocolSnap) {\n return this.#messenger.call('SnapController:handleRequest', {\n snapId: protocolSnap.snapId,\n origin,\n request: {\n method: '',\n params: {\n request,\n scope,\n },\n },\n handler: HandlerType.OnProtocolRequest,\n }) as Promise<Json>;\n }\n\n // If no compatible account or protocol Snaps were found, throw.\n throw rpcErrors.methodNotFound();\n }\n\n /**\n * Get a list of metadata for supported accounts for a given scope from the client.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of metadata for the supported accounts.\n */\n #getSupportedAccountsMetadata(scope: CaipChainId): InternalAccount[] {\n return this.#messenger\n .call('AccountsController:listMultichainAccounts', scope)\n .filter((account: InternalAccount) => account.metadata.snap?.enabled);\n }\n\n /**\n * Get a list of supported methods for a given scope.\n * This combines both protocol and account Snaps supported methods.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of supported methods.\n */\n getSupportedMethods(scope: CaipChainId): string[] {\n const accountMethods = this.#getSupportedAccountsMetadata(scope).flatMap(\n (account) => account.methods,\n );\n\n const protocolMethods = this.#getProtocolSnaps(scope).flatMap(\n (snap) => snap.methods,\n );\n\n return Array.from(new Set([...accountMethods, ...protocolMethods]));\n }\n\n /**\n * Get a list of supported accounts for a given scope.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of CAIP-10 addresses.\n */\n getSupportedAccounts(scope: CaipChainId): string[] {\n return this.#getSupportedAccountsMetadata(scope).map(\n (account) => `${scope}:${account.address}`,\n );\n }\n\n /**\n * Determine whether a given CAIP-2 scope is supported by the router.\n *\n * @param scope - The CAIP-2 scope.\n * @returns True if the router can service the scope, otherwise false.\n */\n isSupportedScope(scope: CaipChainId): boolean {\n const hasAccountSnap = this.#messenger\n .call('AccountsController:listMultichainAccounts', scope)\n .some((account: InternalAccount) => account.metadata.snap?.enabled);\n // We currently assume here that if one Snap exists that service the scope, we can service the scope generally.\n return hasAccountSnap || this.#getProtocolSnaps(scope).length > 0;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MultichainRouter.mjs","sourceRoot":"","sources":["../../src/multichain/MultichainRouter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EACL,uBAAuB,EACvB,cAAc,EACf,oCAAoC;AAGrC,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAMpD,OAAO,EACL,MAAM,EACN,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AACzB,OAAO,EAAE,MAAM,EAAE,eAAe;AAEhC,OAAO,EAAE,gBAAgB,EAAE,2BAAiB;AA+E5C,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAEhC,MAAM,OAAO,gBAAgB;IAS3B,YAAY,EAAE,SAAS,EAAE,eAAe,EAAwB;;QARhE,SAAI,GAAgB,IAAI,CAAC;QAEzB,UAAK,GAAG,IAAI,CAAC;QAEJ,8CAAsC;QAEtC,oDAA0C;QAGjD,uBAAA,IAAI,+BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,qCAAoB,eAAe,MAAA,CAAC;QAExC,uBAAA,IAAI,mCAAW,CAAC,qBAAqB,CACnC,GAAG,IAAI,gBAAgB,EACvB,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,CAC/C,CAAC;QAEF,uBAA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ermissions } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n getProtocolCaveatScopes,\n SnapEndowments,\n} from '@metamask/snaps-rpc-methods';\nimport type { Json, JsonRpcRequest, SnapId } from '@metamask/snaps-sdk';\nimport type { InternalAccount } from '@metamask/snaps-utils';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type {\n CaipAccountId,\n CaipChainId,\n JsonRpcParams,\n} from '@metamask/utils';\nimport {\n assert,\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport { getRunnableSnaps } from '../snaps';\nimport type { GetAllSnaps, HandleSnapRequest } from '../snaps';\n\nexport type MultichainRouterHandleRequestAction = {\n type: `${typeof name}:handleRequest`;\n handler: MultichainRouter['handleRequest'];\n};\n\nexport type MultichainRouterGetSupportedMethodsAction = {\n type: `${typeof name}:getSupportedMethods`;\n handler: MultichainRouter['getSupportedMethods'];\n};\n\nexport type MultichainRouterGetSupportedAccountsAction = {\n type: `${typeof name}:getSupportedAccounts`;\n handler: MultichainRouter['getSupportedAccounts'];\n};\n\nexport type MultichainRouterIsSupportedScopeAction = {\n type: `${typeof name}:isSupportedScope`;\n handler: MultichainRouter['isSupportedScope'];\n};\n\ntype SnapKeyring = {\n submitRequest: (request: {\n account: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n scope: CaipChainId;\n }) => Promise<Json>;\n resolveAccountAddress: (\n snapId: SnapId,\n scope: CaipChainId,\n request: Json,\n ) => Promise<{ address: CaipAccountId } | null>;\n};\n\n// Expecting a bound function that calls KeyringController.withKeyring selecting the Snap keyring\ntype WithSnapKeyringFunction = <ReturnType>(\n operation: ({ keyring }: { keyring: SnapKeyring }) => Promise<ReturnType>,\n) => Promise<ReturnType>;\n\nexport type AccountsControllerListMultichainAccountsAction = {\n type: `AccountsController:listMultichainAccounts`;\n handler: (chainId?: CaipChainId) => InternalAccount[];\n};\n\nexport type MultichainRouterActions =\n | MultichainRouterHandleRequestAction\n | MultichainRouterGetSupportedMethodsAction\n | MultichainRouterGetSupportedAccountsAction\n | MultichainRouterIsSupportedScopeAction;\n\nexport type MultichainRouterAllowedActions =\n | GetAllSnaps\n | HandleSnapRequest\n | GetPermissions\n | AccountsControllerListMultichainAccountsAction;\n\nexport type MultichainRouterEvents = never;\n\nexport type MultichainRouterMessenger = RestrictedMessenger<\n typeof name,\n MultichainRouterActions | MultichainRouterAllowedActions,\n never,\n MultichainRouterAllowedActions['type'],\n MultichainRouterEvents['type']\n>;\n\nexport type MultichainRouterArgs = {\n messenger: MultichainRouterMessenger;\n withSnapKeyring: WithSnapKeyringFunction;\n};\n\ntype ProtocolSnap = {\n snapId: SnapId;\n methods: string[];\n};\n\nconst name = 'MultichainRouter';\n\nexport class MultichainRouter {\n name: typeof name = name;\n\n state = null;\n\n readonly #messenger: MultichainRouterMessenger;\n\n readonly #withSnapKeyring: WithSnapKeyringFunction;\n\n constructor({ messenger, withSnapKeyring }: MultichainRouterArgs) {\n this.#messenger = messenger;\n this.#withSnapKeyring = withSnapKeyring;\n\n this.#messenger.registerActionHandler(\n `${name}:handleRequest`,\n async (...args) => this.handleRequest(...args),\n );\n\n this.#messenger.registerActionHandler(\n `${name}:getSupportedMethods`,\n (...args) => this.getSupportedMethods(...args),\n );\n\n this.#messenger.registerActionHandler(\n `${name}:getSupportedAccounts`,\n (...args) => this.getSupportedAccounts(...args),\n );\n\n this.#messenger.registerActionHandler(\n `${name}:isSupportedScope`,\n (...args) => this.isSupportedScope(...args),\n );\n }\n\n /**\n * Attempts to resolve the account address to use for a given request by inspecting the request itself.\n *\n * The request is sent to to an account Snap via the SnapKeyring that will attempt this resolution.\n *\n * @param snapId - The ID of the Snap to send the request to.\n * @param scope - The CAIP-2 scope for the request.\n * @param request - The JSON-RPC request.\n * @returns The resolved address if found, otherwise null.\n * @throws If the invocation of the SnapKeyring fails.\n */\n async #resolveRequestAddress(\n snapId: SnapId,\n scope: CaipChainId,\n request: JsonRpcRequest,\n ) {\n try {\n const result = await this.#withSnapKeyring(async ({ keyring }) =>\n keyring.resolveAccountAddress(snapId, scope, request),\n );\n const address = result?.address;\n return address ? parseCaipAccountId(address).address : null;\n } catch {\n throw rpcErrors.internal();\n }\n }\n\n /**\n * Get the account ID of the account that should service the RPC request via an account Snap.\n *\n * This function checks whether any accounts exist that can service a given request by\n * using a combination of the resolveAccountAddress functionality and the connected accounts.\n *\n * If an account is expected to service this request but none is found, the function will throw.\n *\n * @param connectedAddresses - The CAIP-10 addresses connected to the requesting origin.\n * @param scope - The CAIP-2 scope for the request.\n * @param request - The JSON-RPC request.\n * @returns An account ID if found, otherwise null.\n * @throws If no account is found, but the accounts exist that could service the request.\n */\n async #getSnapAccountId(\n connectedAddresses: CaipAccountId[],\n scope: CaipChainId,\n request: JsonRpcRequest,\n ) {\n const accounts = this.#messenger\n .call('AccountsController:listMultichainAccounts', scope)\n .filter(\n (\n account: InternalAccount,\n ): account is InternalAccount & {\n metadata: Required<InternalAccount['metadata']>;\n } =>\n Boolean(account.metadata.snap?.enabled) &&\n account.methods.includes(request.method),\n );\n\n // If no accounts can service the request, return null.\n if (accounts.length === 0) {\n return null;\n }\n\n const resolutionSnapId = accounts[0].metadata.snap.id;\n\n // Attempt to resolve the address that should be used for signing.\n const address = await this.#resolveRequestAddress(\n resolutionSnapId,\n scope,\n request,\n );\n\n const parsedConnectedAddresses = connectedAddresses.map(\n (connectedAddress) => parseCaipAccountId(connectedAddress).address,\n );\n\n // If we have a resolved address, try to find the selected account based on that\n // otherwise, default to one of the connected accounts.\n // TODO: Eventually let the user choose if we have more than one option for the account.\n const selectedAccount = accounts.find(\n (account) =>\n parsedConnectedAddresses.includes(account.address) &&\n (!address || account.address === address),\n );\n\n if (!selectedAccount) {\n throw rpcErrors.invalidParams({\n message: 'No available account found for request.',\n });\n }\n\n return selectedAccount.id;\n }\n\n /**\n * Get all protocol Snaps that can service a given CAIP-2 scope.\n *\n * Protocol Snaps are deemed fit to service a scope if they are runnable\n * and have the proper permissions set for the scope.\n *\n * @param scope - A CAIP-2 scope.\n * @returns A list of all the protocol Snaps available and their RPC methods.\n */\n #getProtocolSnaps(scope: CaipChainId) {\n const allSnaps = this.#messenger.call('SnapController:getAll');\n const filteredSnaps = getRunnableSnaps(allSnaps);\n\n return filteredSnaps.reduce<ProtocolSnap[]>((accumulator, snap) => {\n const permissions = this.#messenger.call(\n 'PermissionController:getPermissions',\n snap.id,\n );\n\n if (permissions && hasProperty(permissions, SnapEndowments.Protocol)) {\n const permission = permissions[SnapEndowments.Protocol];\n const scopes = getProtocolCaveatScopes(permission);\n if (scopes && hasProperty(scopes, scope)) {\n accumulator.push({\n snapId: snap.id,\n methods: scopes[scope].methods,\n });\n }\n }\n\n return accumulator;\n }, []);\n }\n\n /**\n * Handle an incoming JSON-RPC request tied to a specific scope by routing\n * to either a procotol Snap or an account Snap.\n *\n * Note: Addresses are considered case sensitive by the MultichainRouter as\n * not all non-EVM chains are case insensitive.\n *\n * @param options - An options bag.\n * @param options.connectedAddresses - Addresses currently connected to the origin.\n * @param options.origin - The origin of the RPC request.\n * @param options.request - The JSON-RPC request.\n * @param options.scope - The CAIP-2 scope for the request.\n * @returns The response from the chosen Snap.\n * @throws If no handler was found.\n */\n async handleRequest({\n connectedAddresses,\n origin,\n scope,\n request: rawRequest,\n }: {\n connectedAddresses: CaipAccountId[];\n origin: string;\n scope: CaipChainId;\n request: JsonRpcRequest;\n }): Promise<Json> {\n // Explicitly block EVM scopes, just in case.\n assert(\n !scope.startsWith(KnownCaipNamespace.Eip155) &&\n !scope.startsWith('wallet:eip155'),\n );\n\n // Re-create the request to simplify and remove additional properties that may be present in MM middleware.\n const request = {\n jsonrpc: '2.0' as const,\n id: rawRequest.id ?? nanoid(),\n method: rawRequest.method,\n ...(rawRequest.params ? { params: rawRequest.params } : {}),\n };\n\n const { method, params } = request;\n\n // If the RPC request can be serviced by an account Snap, route it there.\n const accountId = await this.#getSnapAccountId(\n connectedAddresses,\n scope,\n request,\n );\n\n if (accountId) {\n return this.#withSnapKeyring(async ({ keyring }) =>\n keyring.submitRequest({\n account: accountId,\n scope,\n method,\n params: params as JsonRpcParams,\n }),\n );\n }\n\n // If the RPC request cannot be serviced by an account Snap,\n // but has a protocol Snap available, route it there.\n const protocolSnaps = this.#getProtocolSnaps(scope);\n const protocolSnap = protocolSnaps.find((snap) =>\n snap.methods.includes(method),\n );\n\n if (protocolSnap) {\n return this.#messenger.call('SnapController:handleRequest', {\n snapId: protocolSnap.snapId,\n origin,\n request: {\n method: '',\n params: {\n request,\n scope,\n },\n },\n handler: HandlerType.OnProtocolRequest,\n }) as Promise<Json>;\n }\n\n // If no compatible account or protocol Snaps were found, throw.\n throw rpcErrors.methodNotFound();\n }\n\n /**\n * Get a list of metadata for supported accounts for a given scope from the client.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of metadata for the supported accounts.\n */\n #getSupportedAccountsMetadata(scope: CaipChainId): InternalAccount[] {\n return this.#messenger\n .call('AccountsController:listMultichainAccounts', scope)\n .filter((account: InternalAccount) => account.metadata.snap?.enabled);\n }\n\n /**\n * Get a list of supported methods for a given scope.\n * This combines both protocol and account Snaps supported methods.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of supported methods.\n */\n getSupportedMethods(scope: CaipChainId): string[] {\n const accountMethods = this.#getSupportedAccountsMetadata(scope).flatMap(\n (account) => account.methods,\n );\n\n const protocolMethods = this.#getProtocolSnaps(scope).flatMap(\n (snap) => snap.methods,\n );\n\n return Array.from(new Set([...accountMethods, ...protocolMethods]));\n }\n\n /**\n * Get a list of supported accounts for a given scope.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of CAIP-10 addresses.\n */\n getSupportedAccounts(scope: CaipChainId): string[] {\n return this.#getSupportedAccountsMetadata(scope).map(\n (account) => `${scope}:${account.address}`,\n );\n }\n\n /**\n * Determine whether a given CAIP-2 scope is supported by the router.\n *\n * @param scope - The CAIP-2 scope.\n * @returns True if the router can service the scope, otherwise false.\n */\n isSupportedScope(scope: CaipChainId): boolean {\n const hasAccountSnap = this.#messenger\n .call('AccountsController:listMultichainAccounts', scope)\n .some((account: InternalAccount) => account.metadata.snap?.enabled);\n // We currently assume here that if one Snap exists that service the scope, we can service the scope generally.\n return hasAccountSnap || this.#getProtocolSnaps(scope).length > 0;\n }\n}\n"]}
|
|
@@ -14,13 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.WebWorkerExecutionService = void 0;
|
|
18
17
|
// Subset of exports meant for browser environments, omits Node.js services
|
|
19
18
|
__exportStar(require("./AbstractExecutionService.cjs"), exports);
|
|
20
19
|
__exportStar(require("./ProxyPostMessageStream.cjs"), exports);
|
|
21
20
|
__exportStar(require("./iframe/index.cjs"), exports);
|
|
22
21
|
__exportStar(require("./offscreen/index.cjs"), exports);
|
|
23
22
|
__exportStar(require("./webview/index.cjs"), exports);
|
|
24
|
-
var webworker_1 = require("./webworker/index.cjs");
|
|
25
|
-
Object.defineProperty(exports, "WebWorkerExecutionService", { enumerable: true, get: function () { return webworker_1.WebWorkerExecutionService; } });
|
|
26
23
|
//# sourceMappingURL=browser.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.cjs","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browser.cjs","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2EAA2E;AAC3E,iEAA2C;AAE3C,+DAAyC;AACzC,qDAAyB;AACzB,wDAA4B;AAC5B,sDAA0B","sourcesContent":["// Subset of exports meant for browser environments, omits Node.js services\nexport * from './AbstractExecutionService';\nexport type * from './ExecutionService';\nexport * from './ProxyPostMessageStream';\nexport * from './iframe';\nexport * from './offscreen';\nexport * from './webview';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.cts","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AACA,+CAA2C;AAC3C,4CAAwC;AACxC,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B
|
|
1
|
+
{"version":3,"file":"browser.d.cts","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AACA,+CAA2C;AAC3C,4CAAwC;AACxC,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.mts","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AACA,+CAA2C;AAC3C,4CAAwC;AACxC,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B
|
|
1
|
+
{"version":3,"file":"browser.d.mts","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AACA,+CAA2C;AAC3C,4CAAwC;AACxC,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.mjs","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,+CAA2C;AAE3C,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B
|
|
1
|
+
{"version":3,"file":"browser.mjs","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,+CAA2C;AAE3C,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B","sourcesContent":["// Subset of exports meant for browser environments, omits Node.js services\nexport * from './AbstractExecutionService';\nexport type * from './ExecutionService';\nexport * from './ProxyPostMessageStream';\nexport * from './iframe';\nexport * from './offscreen';\nexport * from './webview';\n"]}
|
package/dist/services/index.cjs
CHANGED
|
@@ -14,11 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.WebWorkerExecutionService = void 0;
|
|
18
17
|
__exportStar(require("./AbstractExecutionService.cjs"), exports);
|
|
19
18
|
__exportStar(require("./ProxyPostMessageStream.cjs"), exports);
|
|
20
19
|
__exportStar(require("./iframe/index.cjs"), exports);
|
|
21
20
|
__exportStar(require("./offscreen/index.cjs"), exports);
|
|
22
|
-
var webworker_1 = require("./webworker/index.cjs");
|
|
23
|
-
Object.defineProperty(exports, "WebWorkerExecutionService", { enumerable: true, get: function () { return webworker_1.WebWorkerExecutionService; } });
|
|
24
21
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA2C;AAE3C,+DAAyC;AACzC,qDAAyB;AACzB,wDAA4B","sourcesContent":["export * from './AbstractExecutionService';\nexport type * from './ExecutionService';\nexport * from './ProxyPostMessageStream';\nexport * from './iframe';\nexport * from './offscreen';\n"]}
|
|
@@ -3,5 +3,4 @@ export type * from "./ExecutionService.cjs";
|
|
|
3
3
|
export * from "./ProxyPostMessageStream.cjs";
|
|
4
4
|
export * from "./iframe/index.cjs";
|
|
5
5
|
export * from "./offscreen/index.cjs";
|
|
6
|
-
export { WebWorkerExecutionService } from "./webworker/index.cjs";
|
|
7
6
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,4CAAwC;AACxC,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,4CAAwC;AACxC,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B"}
|
|
@@ -3,5 +3,4 @@ export type * from "./ExecutionService.mjs";
|
|
|
3
3
|
export * from "./ProxyPostMessageStream.mjs";
|
|
4
4
|
export * from "./iframe/index.mjs";
|
|
5
5
|
export * from "./offscreen/index.mjs";
|
|
6
|
-
export { WebWorkerExecutionService } from "./webworker/index.mjs";
|
|
7
6
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,4CAAwC;AACxC,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,4CAAwC;AACxC,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B"}
|
package/dist/services/index.mjs
CHANGED
|
@@ -2,5 +2,4 @@ export * from "./AbstractExecutionService.mjs";
|
|
|
2
2
|
export * from "./ProxyPostMessageStream.mjs";
|
|
3
3
|
export * from "./iframe/index.mjs";
|
|
4
4
|
export * from "./offscreen/index.mjs";
|
|
5
|
-
export { WebWorkerExecutionService } from "./webworker/index.mjs";
|
|
6
5
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAE3C,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAE3C,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B","sourcesContent":["export * from './AbstractExecutionService';\nexport type * from './ExecutionService';\nexport * from './ProxyPostMessageStream';\nexport * from './iframe';\nexport * from './offscreen';\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NodeProcessExecutionService = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_1 = require("@metamask/post-message-stream/node");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
6
|
const __1 = require("../index.cjs");
|
|
7
7
|
class NodeProcessExecutionService extends __1.AbstractExecutionService {
|
|
8
8
|
async initEnvStream() {
|
|
9
|
-
const worker = (0, child_process_1.fork)(require.resolve('@metamask/snaps-execution-environments/
|
|
9
|
+
const worker = (0, child_process_1.fork)(require.resolve('@metamask/snaps-execution-environments/node-process'), {
|
|
10
10
|
stdio: 'pipe',
|
|
11
11
|
});
|
|
12
12
|
// Capturing `stdout` and `stderr` from the worker prevents the worker from
|
|
@@ -19,7 +19,7 @@ class NodeProcessExecutionService extends __1.AbstractExecutionService {
|
|
|
19
19
|
// eslint-disable-next-line no-console
|
|
20
20
|
console.error(data.toString());
|
|
21
21
|
});
|
|
22
|
-
const stream = new
|
|
22
|
+
const stream = new node_1.ProcessParentMessageStream({ process: worker });
|
|
23
23
|
return Promise.resolve({ worker, stream });
|
|
24
24
|
}
|
|
25
25
|
terminateJob(jobWrapper) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeProcessExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeProcessExecutionService.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"NodeProcessExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeProcessExecutionService.ts"],"names":[],"mappings":";;;AACA,6DAAgF;AAEhF,iDAAqC;AAGrC,oCAA8C;AAE9C,MAAa,2BAA4B,SAAQ,4BAAsC;IAC3E,KAAK,CAAC,aAAa;QAI3B,MAAM,MAAM,GAAG,IAAA,oBAAI,EACjB,OAAO,CAAC,OAAO,CAAC,qDAAqD,CAAC,EACtE;YACE,KAAK,EAAE,MAAM;SACd,CACF,CAAC;QAEF,2EAA2E;QAC3E,mEAAmE;QACnE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACjC,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACjC,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,iCAA0B,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QACnE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,CAAC;IAES,YAAY,CAAC,UAA0C;QAC/D,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;CACF;AA/BD,kEA+BC","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { ProcessParentMessageStream } from '@metamask/post-message-stream/node';\nimport type { ChildProcess } from 'child_process';\nimport { fork } from 'child_process';\n\nimport type { TerminateJobArgs } from '..';\nimport { AbstractExecutionService } from '..';\n\nexport class NodeProcessExecutionService extends AbstractExecutionService<ChildProcess> {\n protected async initEnvStream(): Promise<{\n worker: ChildProcess;\n stream: BasePostMessageStream;\n }> {\n const worker = fork(\n require.resolve('@metamask/snaps-execution-environments/node-process'),\n {\n stdio: 'pipe',\n },\n );\n\n // Capturing `stdout` and `stderr` from the worker prevents the worker from\n // writing to them directly, making it easier to capture them Jest.\n worker.stdout?.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n });\n\n worker.stderr?.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.error(data.toString());\n });\n\n const stream = new ProcessParentMessageStream({ process: worker });\n return Promise.resolve({ worker, stream });\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<ChildProcess>): void {\n jobWrapper.worker?.kill();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeProcessExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/node-js/NodeProcessExecutionService.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB;AAGlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAW;AAC3C,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,qBAAa,2BAA4B,SAAQ,wBAAwB,CAAC,YAAY,CAAC;cACrE,aAAa,IAAI,OAAO,CAAC;QACvC,MAAM,EAAE,YAAY,CAAC;QACrB,MAAM,EAAE,qBAAqB,CAAC;KAC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"NodeProcessExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/node-js/NodeProcessExecutionService.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB;AAGlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAW;AAC3C,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,qBAAa,2BAA4B,SAAQ,wBAAwB,CAAC,YAAY,CAAC;cACrE,aAAa,IAAI,OAAO,CAAC;QACvC,MAAM,EAAE,YAAY,CAAC;QACrB,MAAM,EAAE,qBAAqB,CAAC;KAC/B,CAAC;IAwBF,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,gBAAgB,CAAC,YAAY,CAAC,GAAG,IAAI;CAGzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeProcessExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/node-js/NodeProcessExecutionService.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB;AAGlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAW;AAC3C,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,qBAAa,2BAA4B,SAAQ,wBAAwB,CAAC,YAAY,CAAC;cACrE,aAAa,IAAI,OAAO,CAAC;QACvC,MAAM,EAAE,YAAY,CAAC;QACrB,MAAM,EAAE,qBAAqB,CAAC;KAC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"NodeProcessExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/node-js/NodeProcessExecutionService.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB;AAGlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAW;AAC3C,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,qBAAa,2BAA4B,SAAQ,wBAAwB,CAAC,YAAY,CAAC;cACrE,aAAa,IAAI,OAAO,CAAC;QACvC,MAAM,EAAE,YAAY,CAAC;QACrB,MAAM,EAAE,qBAAqB,CAAC;KAC/B,CAAC;IAwBF,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,gBAAgB,CAAC,YAAY,CAAC,GAAG,IAAI;CAGzE"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRequire as $createRequire } from "module";
|
|
2
2
|
const $require = $createRequire(import.meta.url);
|
|
3
|
-
import { ProcessParentMessageStream } from "@metamask/post-message-stream";
|
|
3
|
+
import { ProcessParentMessageStream } from "@metamask/post-message-stream/node";
|
|
4
4
|
import { fork } from "child_process";
|
|
5
5
|
import { AbstractExecutionService } from "../index.mjs";
|
|
6
6
|
export class NodeProcessExecutionService extends AbstractExecutionService {
|
|
7
7
|
async initEnvStream() {
|
|
8
|
-
const worker = fork($require.resolve('@metamask/snaps-execution-environments/
|
|
8
|
+
const worker = fork($require.resolve('@metamask/snaps-execution-environments/node-process'), {
|
|
9
9
|
stdio: 'pipe',
|
|
10
10
|
});
|
|
11
11
|
// Capturing `stdout` and `stderr` from the worker prevents the worker from
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeProcessExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeProcessExecutionService.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,0BAA0B,EAAE,
|
|
1
|
+
{"version":3,"file":"NodeProcessExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeProcessExecutionService.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,0BAA0B,EAAE,2CAA2C;AAEhF,OAAO,EAAE,IAAI,EAAE,sBAAsB;AAGrC,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,MAAM,OAAO,2BAA4B,SAAQ,wBAAsC;IAC3E,KAAK,CAAC,aAAa;QAI3B,MAAM,MAAM,GAAG,IAAI,kBACD,qDAAqD,GACrE;YACE,KAAK,EAAE,MAAM;SACd,CACF,CAAC;QAEF,2EAA2E;QAC3E,mEAAmE;QACnE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACjC,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACjC,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,0BAA0B,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QACnE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,CAAC;IAES,YAAY,CAAC,UAA0C;QAC/D,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { ProcessParentMessageStream } from '@metamask/post-message-stream/node';\nimport type { ChildProcess } from 'child_process';\nimport { fork } from 'child_process';\n\nimport type { TerminateJobArgs } from '..';\nimport { AbstractExecutionService } from '..';\n\nexport class NodeProcessExecutionService extends AbstractExecutionService<ChildProcess> {\n protected async initEnvStream(): Promise<{\n worker: ChildProcess;\n stream: BasePostMessageStream;\n }> {\n const worker = fork(\n require.resolve('@metamask/snaps-execution-environments/node-process'),\n {\n stdio: 'pipe',\n },\n );\n\n // Capturing `stdout` and `stderr` from the worker prevents the worker from\n // writing to them directly, making it easier to capture them Jest.\n worker.stdout?.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n });\n\n worker.stderr?.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.error(data.toString());\n });\n\n const stream = new ProcessParentMessageStream({ process: worker });\n return Promise.resolve({ worker, stream });\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<ChildProcess>): void {\n jobWrapper.worker?.kill();\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NodeThreadExecutionService = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_1 = require("@metamask/post-message-stream/node");
|
|
5
5
|
const worker_threads_1 = require("worker_threads");
|
|
6
6
|
const __1 = require("../index.cjs");
|
|
7
7
|
class NodeThreadExecutionService extends __1.AbstractExecutionService {
|
|
8
8
|
async initEnvStream() {
|
|
9
|
-
const worker = new worker_threads_1.Worker(require.resolve('@metamask/snaps-execution-environments/
|
|
9
|
+
const worker = new worker_threads_1.Worker(require.resolve('@metamask/snaps-execution-environments/node-thread'), {
|
|
10
10
|
stdout: true,
|
|
11
11
|
stderr: true,
|
|
12
12
|
});
|
|
@@ -20,7 +20,7 @@ class NodeThreadExecutionService extends __1.AbstractExecutionService {
|
|
|
20
20
|
// eslint-disable-next-line no-console
|
|
21
21
|
console.error(data.toString());
|
|
22
22
|
});
|
|
23
|
-
const stream = new
|
|
23
|
+
const stream = new node_1.ThreadParentMessageStream({ thread: worker });
|
|
24
24
|
return Promise.resolve({ worker, stream });
|
|
25
25
|
}
|
|
26
26
|
// TODO: Either fix this lint violation or explain why it's necessary to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeThreadExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeThreadExecutionService.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"NodeThreadExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeThreadExecutionService.ts"],"names":[],"mappings":";;;AACA,6DAA+E;AAC/E,mDAAwC;AAGxC,oCAA8C;AAE9C,MAAa,0BAA2B,SAAQ,4BAAgC;IACpE,KAAK,CAAC,aAAa;QAI3B,MAAM,MAAM,GAAG,IAAI,uBAAM,CACvB,OAAO,CAAC,OAAO,CAAC,oDAAoD,CAAC,EACrE;YACE,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,IAAI;SACb,CACF,CAAC;QAEF,2EAA2E;QAC3E,mEAAmE;QACnE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAChC,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAChC,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,gCAAyB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,wEAAwE;IACxE,WAAW;IACX,kEAAkE;IACxD,KAAK,CAAC,YAAY,CAC1B,UAAoC;QAEpC,MAAM,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC;IACvC,CAAC;CACF;AArCD,gEAqCC","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { ThreadParentMessageStream } from '@metamask/post-message-stream/node';\nimport { Worker } from 'worker_threads';\n\nimport type { TerminateJobArgs } from '..';\nimport { AbstractExecutionService } from '..';\n\nexport class NodeThreadExecutionService extends AbstractExecutionService<Worker> {\n protected async initEnvStream(): Promise<{\n worker: Worker;\n stream: BasePostMessageStream;\n }> {\n const worker = new Worker(\n require.resolve('@metamask/snaps-execution-environments/node-thread'),\n {\n stdout: true,\n stderr: true,\n },\n );\n\n // Capturing `stdout` and `stderr` from the worker prevents the worker from\n // writing to them directly, making it easier to capture them Jest.\n worker.stdout.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n });\n\n worker.stderr.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.error(data.toString());\n });\n\n const stream = new ThreadParentMessageStream({ thread: worker });\n return Promise.resolve({ worker, stream });\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n protected async terminateJob(\n jobWrapper: TerminateJobArgs<Worker>,\n ): Promise<void> {\n await jobWrapper.worker?.terminate();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeThreadExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/node-js/NodeThreadExecutionService.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAE3E,OAAO,EAAE,MAAM,EAAE,uBAAuB;AAExC,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAW;AAC3C,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,qBAAa,0BAA2B,SAAQ,wBAAwB,CAAC,MAAM,CAAC;cAC9D,aAAa,IAAI,OAAO,CAAC;QACvC,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,qBAAqB,CAAC;KAC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"NodeThreadExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/node-js/NodeThreadExecutionService.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAE3E,OAAO,EAAE,MAAM,EAAE,uBAAuB;AAExC,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAW;AAC3C,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,qBAAa,0BAA2B,SAAQ,wBAAwB,CAAC,MAAM,CAAC;cAC9D,aAAa,IAAI,OAAO,CAAC;QACvC,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,qBAAqB,CAAC;KAC/B,CAAC;cA4Bc,YAAY,CAC1B,UAAU,EAAE,gBAAgB,CAAC,MAAM,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC;CAGjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeThreadExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/node-js/NodeThreadExecutionService.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAE3E,OAAO,EAAE,MAAM,EAAE,uBAAuB;AAExC,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAW;AAC3C,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,qBAAa,0BAA2B,SAAQ,wBAAwB,CAAC,MAAM,CAAC;cAC9D,aAAa,IAAI,OAAO,CAAC;QACvC,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,qBAAqB,CAAC;KAC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"NodeThreadExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/node-js/NodeThreadExecutionService.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAE3E,OAAO,EAAE,MAAM,EAAE,uBAAuB;AAExC,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAW;AAC3C,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,qBAAa,0BAA2B,SAAQ,wBAAwB,CAAC,MAAM,CAAC;cAC9D,aAAa,IAAI,OAAO,CAAC;QACvC,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,qBAAqB,CAAC;KAC/B,CAAC;cA4Bc,YAAY,CAC1B,UAAU,EAAE,gBAAgB,CAAC,MAAM,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC;CAGjB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRequire as $createRequire } from "module";
|
|
2
2
|
const $require = $createRequire(import.meta.url);
|
|
3
|
-
import { ThreadParentMessageStream } from "@metamask/post-message-stream";
|
|
3
|
+
import { ThreadParentMessageStream } from "@metamask/post-message-stream/node";
|
|
4
4
|
import { Worker } from "worker_threads";
|
|
5
5
|
import { AbstractExecutionService } from "../index.mjs";
|
|
6
6
|
export class NodeThreadExecutionService extends AbstractExecutionService {
|
|
7
7
|
async initEnvStream() {
|
|
8
|
-
const worker = new Worker($require.resolve('@metamask/snaps-execution-environments/
|
|
8
|
+
const worker = new Worker($require.resolve('@metamask/snaps-execution-environments/node-thread'), {
|
|
9
9
|
stdout: true,
|
|
10
10
|
stderr: true,
|
|
11
11
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeThreadExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeThreadExecutionService.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,yBAAyB,EAAE,
|
|
1
|
+
{"version":3,"file":"NodeThreadExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeThreadExecutionService.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,yBAAyB,EAAE,2CAA2C;AAC/E,OAAO,EAAE,MAAM,EAAE,uBAAuB;AAGxC,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,MAAM,OAAO,0BAA2B,SAAQ,wBAAgC;IACpE,KAAK,CAAC,aAAa;QAI3B,MAAM,MAAM,GAAG,IAAI,MAAM,kBACP,oDAAoD,GACpE;YACE,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,IAAI;SACb,CACF,CAAC;QAEF,2EAA2E;QAC3E,mEAAmE;QACnE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAChC,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAChC,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,yBAAyB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,wEAAwE;IACxE,WAAW;IACX,kEAAkE;IACxD,KAAK,CAAC,YAAY,CAC1B,UAAoC;QAEpC,MAAM,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC;IACvC,CAAC;CACF","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { ThreadParentMessageStream } from '@metamask/post-message-stream/node';\nimport { Worker } from 'worker_threads';\n\nimport type { TerminateJobArgs } from '..';\nimport { AbstractExecutionService } from '..';\n\nexport class NodeThreadExecutionService extends AbstractExecutionService<Worker> {\n protected async initEnvStream(): Promise<{\n worker: Worker;\n stream: BasePostMessageStream;\n }> {\n const worker = new Worker(\n require.resolve('@metamask/snaps-execution-environments/node-thread'),\n {\n stdout: true,\n stderr: true,\n },\n );\n\n // Capturing `stdout` and `stderr` from the worker prevents the worker from\n // writing to them directly, making it easier to capture them Jest.\n worker.stdout.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n });\n\n worker.stderr.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.error(data.toString());\n });\n\n const stream = new ThreadParentMessageStream({ thread: worker });\n return Promise.resolve({ worker, stream });\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n protected async terminateJob(\n jobWrapper: TerminateJobArgs<Worker>,\n ): Promise<void> {\n await jobWrapper.worker?.terminate();\n }\n}\n"]}
|
|
@@ -14,8 +14,7 @@ var _WebViewMessageStream_name, _WebViewMessageStream_target, _WebViewMessageStr
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.WebViewMessageStream = void 0;
|
|
16
16
|
const post_message_stream_1 = require("@metamask/post-message-stream");
|
|
17
|
-
const utils_1 = require("@metamask/
|
|
18
|
-
const utils_2 = require("@metamask/utils");
|
|
17
|
+
const utils_1 = require("@metamask/utils");
|
|
19
18
|
/**
|
|
20
19
|
* A special postMessage stream used to interface with a WebView.
|
|
21
20
|
*/
|
|
@@ -44,7 +43,7 @@ class WebViewMessageStream extends post_message_stream_1.BasePostMessageStream {
|
|
|
44
43
|
this._handshake();
|
|
45
44
|
}
|
|
46
45
|
_postMessage(data) {
|
|
47
|
-
(0,
|
|
46
|
+
(0, utils_1.assert)(__classPrivateFieldGet(this, _WebViewMessageStream_webView, "f"));
|
|
48
47
|
const json = JSON.stringify({
|
|
49
48
|
target: __classPrivateFieldGet(this, _WebViewMessageStream_target, "f"),
|
|
50
49
|
data,
|
|
@@ -62,13 +61,13 @@ class WebViewMessageStream extends post_message_stream_1.BasePostMessageStream {
|
|
|
62
61
|
const message = JSON.parse(event.data);
|
|
63
62
|
// Notice that we don't check targetWindow or targetOrigin here.
|
|
64
63
|
// This doesn't seem possible to do in RN.
|
|
65
|
-
if (!(0,
|
|
64
|
+
if (!(0, post_message_stream_1.isValidStreamMessage)(message) || message.target !== __classPrivateFieldGet(this, _WebViewMessageStream_name, "f")) {
|
|
66
65
|
return;
|
|
67
66
|
}
|
|
68
67
|
this._onData(message.data);
|
|
69
68
|
}
|
|
70
69
|
_destroy() {
|
|
71
|
-
(0,
|
|
70
|
+
(0, utils_1.assert)(__classPrivateFieldGet(this, _WebViewMessageStream_webView, "f"));
|
|
72
71
|
// This method is already bound.
|
|
73
72
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
74
73
|
__classPrivateFieldGet(this, _WebViewMessageStream_webView, "f").unregisterMessageListener(this._onMessage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebViewMessageStream.cjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"W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C,KAAK,CAAC,IAAI,CAAC,CAAC;QAEvC,gEAAgE;QAChE,0CAA0C;QAC1C,IAAI,CAAC,IAAA,0CAAoB,EAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,uBAAA,IAAI,kCAAM,EAAE,CAAC;YACpE,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,QAAQ;QACN,IAAA,cAAM,EAAC,uBAAA,IAAI,qCAAS,CAAC,CAAC;QACtB,gCAAgC;QAChC,6DAA6D;QAC7D,uBAAA,IAAI,qCAAS,CAAC,yBAAyB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC3D,CAAC;CACF;AApED,oDAoEC","sourcesContent":["import type { PostMessageEvent } from '@metamask/post-message-stream';\nimport {\n BasePostMessageStream,\n isValidStreamMessage,\n} from '@metamask/post-message-stream';\nimport { assert } from '@metamask/utils';\n\nexport type WebViewInterface = {\n injectJavaScript(js: string): void;\n registerMessageListener(listener: (event: PostMessageEvent) => void): void;\n unregisterMessageListener(listener: (event: PostMessageEvent) => void): void;\n};\n\nexport type WebViewStreamArgs = {\n name: string;\n target: string;\n webView: WebViewInterface;\n};\n\n/**\n * A special postMessage stream used to interface with a WebView.\n */\nexport class WebViewMessageStream extends BasePostMessageStream {\n readonly #name;\n\n readonly #target;\n\n readonly #webView: WebViewInterface | undefined;\n\n /**\n * Creates a stream for communicating with other streams inside a WebView.\n *\n * @param args - Options bag.\n * @param args.name - The name of the stream. Used to differentiate between\n * multiple streams sharing the same window object.\n * @param args.target - The name of the stream to exchange messages with.\n * @param args.webView - A reference to the WebView.\n */\n constructor({ name, target, webView }: WebViewStreamArgs) {\n super();\n\n this.#name = name;\n this.#target = target;\n\n this._onMessage = this._onMessage.bind(this);\n\n this.#webView = webView;\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.registerMessageListener(this._onMessage);\n this._handshake();\n }\n\n protected _postMessage(data: unknown): void {\n assert(this.#webView);\n const json = JSON.stringify({\n target: this.#target,\n data,\n });\n\n const encoded = JSON.stringify(json);\n\n this.#webView.injectJavaScript(`window.postMessage(${encoded})`);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private _onMessage(event: PostMessageEvent): void {\n if (typeof event.data !== 'string') {\n return;\n }\n\n const message = JSON.parse(event.data);\n\n // Notice that we don't check targetWindow or targetOrigin here.\n // This doesn't seem possible to do in RN.\n if (!isValidStreamMessage(message) || message.target !== this.#name) {\n return;\n }\n\n this._onData(message.data);\n }\n\n _destroy() {\n assert(this.#webView);\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.unregisterMessageListener(this._onMessage);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebViewMessageStream.d.cts","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,sCAAsC;AACtE,OAAO,
|
|
1
|
+
{"version":3,"file":"WebViewMessageStream.d.cts","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,sCAAsC;AACtE,OAAO,EACL,qBAAqB,EAEtB,sCAAsC;AAGvC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,uBAAuB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAAC;IAC3E,yBAAyB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAAC;CAC9E,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,qBAAqB;;IAO7D;;;;;;;;OAQG;gBACS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,iBAAiB;IAexD,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAe3C,OAAO,CAAC,UAAU;IAgBlB,QAAQ;CAMT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebViewMessageStream.d.mts","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,sCAAsC;AACtE,OAAO,
|
|
1
|
+
{"version":3,"file":"WebViewMessageStream.d.mts","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,sCAAsC;AACtE,OAAO,EACL,qBAAqB,EAEtB,sCAAsC;AAGvC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,uBAAuB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAAC;IAC3E,yBAAyB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAAC;CAC9E,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,qBAAqB;;IAO7D;;;;;;;;OAQG;gBACS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,iBAAiB;IAexD,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAe3C,OAAO,CAAC,UAAU;IAgBlB,QAAQ;CAMT"}
|
|
@@ -10,8 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _WebViewMessageStream_name, _WebViewMessageStream_target, _WebViewMessageStream_webView;
|
|
13
|
-
import { BasePostMessageStream } from "@metamask/post-message-stream";
|
|
14
|
-
import { isValidStreamMessage } from "@metamask/post-message-stream/dist/utils.js";
|
|
13
|
+
import { BasePostMessageStream, isValidStreamMessage } from "@metamask/post-message-stream";
|
|
15
14
|
import { assert } from "@metamask/utils";
|
|
16
15
|
/**
|
|
17
16
|
* A special postMessage stream used to interface with a WebView.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebViewMessageStream.mjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"WebViewMessageStream.mjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACrB,sCAAsC;AACvC,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAczC;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,qBAAqB;IAO7D;;;;;;;;OAQG;IACH,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAqB;QACtD,KAAK,EAAE,CAAC;QAhBD,6CAAM;QAEN,+CAAQ;QAER,gDAAuC;QAc9C,uBAAA,IAAI,8BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QAEtB,IAAI,CAAC,UAAU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CAAC;IAC3D,CAAC;CACF","sourcesContent":["import type { PostMessageEvent } from '@metamask/post-message-stream';\nimport {\n BasePostMessageStream,\n isValidStreamMessage,\n} from '@metamask/post-message-stream';\nimport { assert } from '@metamask/utils';\n\nexport type WebViewInterface = {\n injectJavaScript(js: string): void;\n registerMessageListener(listener: (event: PostMessageEvent) => void): void;\n unregisterMessageListener(listener: (event: PostMessageEvent) => void): void;\n};\n\nexport type WebViewStreamArgs = {\n name: string;\n target: string;\n webView: WebViewInterface;\n};\n\n/**\n * A special postMessage stream used to interface with a WebView.\n */\nexport class WebViewMessageStream extends BasePostMessageStream {\n readonly #name;\n\n readonly #target;\n\n readonly #webView: WebViewInterface | undefined;\n\n /**\n * Creates a stream for communicating with other streams inside a WebView.\n *\n * @param args - Options bag.\n * @param args.name - The name of the stream. Used to differentiate between\n * multiple streams sharing the same window object.\n * @param args.target - The name of the stream to exchange messages with.\n * @param args.webView - A reference to the WebView.\n */\n constructor({ name, target, webView }: WebViewStreamArgs) {\n super();\n\n this.#name = name;\n this.#target = target;\n\n this._onMessage = this._onMessage.bind(this);\n\n this.#webView = webView;\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.registerMessageListener(this._onMessage);\n this._handshake();\n }\n\n protected _postMessage(data: unknown): void {\n assert(this.#webView);\n const json = JSON.stringify({\n target: this.#target,\n data,\n });\n\n const encoded = JSON.stringify(json);\n\n this.#webView.injectJavaScript(`window.postMessage(${encoded})`);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private _onMessage(event: PostMessageEvent): void {\n if (typeof event.data !== 'string') {\n return;\n }\n\n const message = JSON.parse(event.data);\n\n // Notice that we don't check targetWindow or targetOrigin here.\n // This doesn't seem possible to do in RN.\n if (!isValidStreamMessage(message) || message.target !== this.#name) {\n return;\n }\n\n this._onData(message.data);\n }\n\n _destroy() {\n assert(this.#webView);\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.unregisterMessageListener(this._onMessage);\n }\n}\n"]}
|