@metamask/snaps-simulation 4.1.4 → 4.2.0
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 +10 -2
- package/dist/simulation.cjs +2 -2
- package/dist/simulation.cjs.map +1 -1
- package/dist/simulation.mjs +2 -2
- package/dist/simulation.mjs.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -7,13 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [4.2.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Use `withKeyringV2Unsafe` for accessing entropy ([#4009](https://github.com/MetaMask/snaps/pull/4009))
|
|
15
|
+
- Bump `@metamask/snaps-rpc-methods` from `16.0.0` to `17.0.0` ([#4020](https://github.com/MetaMask/snaps/pull/4020))
|
|
16
|
+
|
|
10
17
|
## [4.1.4]
|
|
11
18
|
|
|
12
19
|
### Changed
|
|
13
20
|
|
|
14
21
|
- Bump `@metamask/snaps-rpc-methods` from `^15.1.1` to `16.0.0` and handle breaking changes ([#3968](https://github.com/MetaMask/snaps/pull/3968), [#3987](https://github.com/MetaMask/snaps/pull/3987), [#3993](https://github.com/MetaMask/snaps/pull/3993))
|
|
15
22
|
- Bump `@metamask/permission-controller` `12.3.0` to `^13.1.0` ([#3984](https://github.com/MetaMask/snaps/pull/3984), [#3989](https://github.com/MetaMask/snaps/pull/3989))
|
|
16
|
-
- Bump `@metamask/json-rpc-engine` from `^10.2.4` to `^10.5.0` ([#3982](https://github.com/MetaMask/snaps/pull/3982),[#3992](https://github.com/MetaMask/snaps/pull/3992), [#3998](https://github.com/MetaMask/snaps/pull/3998))
|
|
23
|
+
- Bump `@metamask/json-rpc-engine` from `^10.2.4` to `^10.5.0` ([#3982](https://github.com/MetaMask/snaps/pull/3982), [#3992](https://github.com/MetaMask/snaps/pull/3992), [#3998](https://github.com/MetaMask/snaps/pull/3998))
|
|
17
24
|
- Bump `@metamask/messenger` from `^1.1.1` to `^1.2.0` ([#3981](https://github.com/MetaMask/snaps/pull/3981))
|
|
18
25
|
- Bump `@metamask/chain-agnostic-permission` from `^1.5.0` to `^1.6.0` ([#3997](https://github.com/MetaMask/snaps/pull/3997))
|
|
19
26
|
|
|
@@ -310,7 +317,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
310
317
|
|
|
311
318
|
- Initial release of `@metamask/snaps-simulation` package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
|
|
312
319
|
|
|
313
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.
|
|
320
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.2.0...HEAD
|
|
321
|
+
[4.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.4...@metamask/snaps-simulation@4.2.0
|
|
314
322
|
[4.1.4]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.3...@metamask/snaps-simulation@4.1.4
|
|
315
323
|
[4.1.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.2...@metamask/snaps-simulation@4.1.3
|
|
316
324
|
[4.1.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.1...@metamask/snaps-simulation@4.1.2
|
package/dist/simulation.cjs
CHANGED
|
@@ -341,7 +341,7 @@ function registerActions(controllerMessenger, runSaga, options, snapId, auxiliar
|
|
|
341
341
|
}));
|
|
342
342
|
controllerMessenger.registerActionHandler(
|
|
343
343
|
// @ts-expect-error - `KeyringController` is not part of the simulation messenger types.
|
|
344
|
-
'KeyringController:
|
|
344
|
+
'KeyringController:withKeyringV2Unsafe', async (selector, operation) => {
|
|
345
345
|
const source = (0, utils_1.hasProperty)(selector, 'id')
|
|
346
346
|
? selector.id
|
|
347
347
|
: undefined;
|
|
@@ -349,7 +349,7 @@ function registerActions(controllerMessenger, runSaga, options, snapId, auxiliar
|
|
|
349
349
|
const seed = await (0, key_tree_1.mnemonicToSeed)(mnemonic);
|
|
350
350
|
return await operation({
|
|
351
351
|
keyring: {
|
|
352
|
-
type: '
|
|
352
|
+
type: 'hd',
|
|
353
353
|
mnemonic,
|
|
354
354
|
seed,
|
|
355
355
|
},
|
package/dist/simulation.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation.cjs","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":";;;AAAA,qFAA0E;AAE1E,iDAAoD;AAOpD,mDAAoE;AACpE,2EAIyC;AAEzC,2DAK0C;AAC1C,mEAAoE;AASpE,uDAAiD;AACjD,2CAAgE;AAGhE,qDAA2C;AAE3C,gDAA4C;AAG5C,mDAA6D;AAC7D,uCAAsC;AAEtC,2CAAuC;AACvC,+CAA8C;AAC9C,iDAAwD;AACxD,qDAcyB;AACzB,uDAAmD;AAMnD,2CAAuC;AAOvC,6CAA2D;AAC3D,iDAA2D;AAkM3D;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,WAAW,CAG/B,MAAc,EACd,EACE,gBAAgB,EAChB,uBAAuB,EACvB,OAAO,EAAE,UAAU,GAAG,EAAE,MACgB,EAAE;IAE5C,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAC;IAEvC,oBAAoB;IACpB,MAAM,QAAQ,GAAG,IAAA,yBAAkB,EAAC,MAAM,EAAE;QAC1C,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,MAAM,IAAA,gBAAS,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEpD,sBAAsB;IACtB,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAA,mBAAW,EAAC,OAAO,CAAC,CAAC;IAEhD,MAAM,mBAAmB,GAAG,IAAI,qB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,CAC7B,CAAC;IAEF,mBAAmB,CAAC,qBAAqB;IACvC,wFAAwF;IACxF,4BAA4B,EAC5B,GAAG,EAAE,CAAC,CAAC;QACL,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,aAAa;gBACnB,QAAQ,EAAE;oBACR,EAAE,EAAE,SAAS;oBACb,IAAI,EAAE,gCAAgC;iBACvC;aACF;YACD;gBACE,IAAI,EAAE,aAAa;gBACnB,QAAQ,EAAE;oBACR,EAAE,EAAE,aAAa;oBACjB,IAAI,EAAE,oCAAoC;iBAC3C;aACF;SACF;KACF,CAAC,CACH,CAAC;IAEF,mBAAmB,CAAC,qBAAqB;IACvC,wFAAwF;IACxF,+BAA+B,EAC/B,KAAK,EACH,QAA2D,EAC3D,SAEsB,EACtB,EAAE;QACF,MAAM,MAAM,GAAG,IAAA,mBAAW,EAAC,QAAQ,EAAE,IAAI,CAAC;YACxC,CAAC,CAAE,QAAQ,CAAC,EAAa;YACzB,CAAC,CAAC,SAAS,CAAC;QAEd,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,IAAA,yBAAc,EAAC,QAAQ,CAAC,CAAC;QAE5C,OAAO,MAAM,SAAS,CAAC;YACrB,OAAO,EAAE;gBACP,IAAI,EAAE,aAAa;gBACnB,QAAQ;gBACR,IAAI;aACL;SACF,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC;AA7ND,0CA6NC","sourcesContent":["import { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { mnemonicToSeed } from '@metamask/key-tree';\nimport type {\n ActionConstraint,\n EventConstraint,\n MockAnyNamespace,\n NamespacedName,\n} from '@metamask/messenger';\nimport { MOCK_ANY_NAMESPACE, Messenger } from '@metamask/messenger';\nimport {\n PermissionDoesNotExistError,\n type Caveat,\n type RequestedPermissions,\n} from '@metamask/permission-controller';\nimport type { ExecutionService } from '@metamask/snaps-controllers';\nimport {\n detectSnapLocation,\n fetchSnap,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n TrackEventParams,\n SnapId,\n TraceRequest,\n EndTraceRequest,\n TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { Snap, VirtualFile } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport { assertExhaustive, hasProperty } from '@metamask/utils';\nimport type { CaipAssetType, Hex, Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport type { SnapHelpers } from './helpers';\nimport { getHelpers } from './helpers';\nimport { resolveWithSaga } from './interface';\nimport { asyncResolve, getEndowments } from './methods';\nimport {\n getGetMnemonicImplementation,\n getGetSnapImplementation,\n getTrackEventImplementation,\n getTrackErrorImplementation,\n getEndTraceImplementation,\n getStartTraceImplementation,\n getSetCurrentChainImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getRequestUserApprovalImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n} from './methods/hooks';\nimport { createJsonRpcEngine } from './middleware';\nimport type {\n SimulationAccount,\n SimulationOptions,\n SimulationUserOptions,\n} from './options';\nimport { getOptions } from './options';\nimport type {\n ApplicationState,\n Interface,\n RunSagaFunction,\n Store,\n} from './store';\nimport { createStore, getCurrentInterface } from './store';\nimport { addSnapMetadataToAccount } from './utils/account';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof ExecutionService>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>,\n> =\n ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof ExecutionService>;\n controllerMessenger: Messenger<\n NamespacedName,\n ActionConstraint,\n EventConstraint\n >;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n\n /**\n * A hook that returns metadata about a given Snap.\n *\n * @param snapId - The ID of a Snap.\n * @returns The metadata for the given Snap.\n */\n getSnap: (snapId: string) => Snap;\n\n /**\n * A hook that sets the current chain ID.\n *\n * @param chainId - The chain ID.\n */\n setCurrentChain: (chainId: Hex) => null;\n\n /**\n * A hook that gets the current simulation state.\n *\n * @returns The simulation state.\n */\n getSimulationState: () => ApplicationState;\n};\n\nexport type PermittedMiddlewareHooks = {\n /**\n * A hook that returns a promise that resolves once the extension is unlocked.\n *\n * @param shouldShowUnlockRequest - Whether to show the unlock request.\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A hook that returns whether the client is active or not.\n *\n * @returns A boolean flag signaling whether the client is opened.\n */\n getIsActive: () => boolean;\n\n /**\n * A hook that returns the client version.\n *\n * @returns A string that corresponds to the client version.\n */\n getVersion: () => string;\n\n /**\n * A hook that tracks an error.\n *\n * @param error - The error object containing error details and properties.\n */\n trackError(error: Error): void;\n\n /**\n * A hook that tracks an event.\n *\n * @param event - The event object containing event details and properties.\n */\n trackEvent(event: TrackEventParams['event']): void;\n\n /**\n * A hook that starts a performance trace.\n *\n * @param request - The trace request object containing trace details.\n */\n startTrace(request: TraceRequest): TraceContext;\n\n /**\n * A hook that ends a performance trace.\n *\n * @param request - The trace request object containing trace details.\n * @returns The trace data.\n */\n endTrace(request: EndTraceRequest): void;\n\n /**\n * A hook that returns the allowed keyring methods.\n *\n * @returns The keyring methods.\n */\n getAllowedKeyringMethods(): string[];\n};\n\nexport type MultichainMiddlewareHooks = {\n /**\n * A hook that returns the simulated accounts.\n *\n * @returns The simulated accounts.\n */\n getAccounts: () => SimulationAccount[];\n\n /**\n * A hook that retrieves a caveat for a given permission.\n *\n * @param permission - The permission name.\n * @param caveatType - The caveat type.\n * @returns The caveat, if it exists.\n */\n getCaveat: (\n permission: string,\n caveatType: string,\n ) => Caveat<string, Json> | undefined;\n\n /**\n * A hook that grants permissions to the origin.\n *\n * @param permissions - The permissions.\n */\n grantPermissions: (permissions: RequestedPermissions) => void;\n\n /**\n * A hook that revokes a permission for the origin.\n *\n * @param permission - The permission name.\n */\n revokePermission: (permission: string) => void;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The installed Snap object.\n * @template Service - The type of the execution service.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap & SnapHelpers> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const { store, runSaga } = createStore(options);\n\n const controllerMessenger = new Messenger<MockAnyNamespace, any, any>({\n namespace: MOCK_ANY_NAMESPACE,\n });\n\n registerActions(\n controllerMessenger,\n runSaga,\n options,\n snapId,\n snapFiles.auxiliaryFiles,\n );\n\n // Set up controllers and JSON-RPC stack.\n const restrictedHooks = getRestrictedHooks(options, store, runSaga);\n\n const permittedHooks = getPermittedHooks(runSaga);\n\n const multichainHooks = getMultichainHooks(\n snapId,\n options,\n controllerMessenger,\n );\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks: restrictedHooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n snapId,\n messenger: controllerMessenger,\n store,\n restrictedHooks,\n permittedHooks,\n multichainHooks,\n isMultichain: false,\n });\n\n const multichainEngine = createJsonRpcEngine({\n snapId,\n messenger: controllerMessenger,\n store,\n restrictedHooks,\n permittedHooks,\n multichainHooks,\n isMultichain: true,\n });\n\n // Create execution service.\n const ActualService = executionService ?? NodeThreadExecutionService;\n const service = new ActualService({\n ...executionServiceOptions,\n messenger: new Messenger({\n namespace: 'ExecutionService',\n parent: controllerMessenger,\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n });\n\n const multichainStream = mux.createStream('metamask-multichain-provider');\n const multichainProviderStream = createEngineStream({\n engine: multichainEngine,\n });\n\n /* istanbul ignore next 2 */\n pipeline(\n multichainStream,\n multichainProviderStream,\n multichainStream,\n (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n },\n );\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n const helpers = getHelpers({\n snapId,\n store,\n controllerMessenger,\n runSaga,\n executionService: service,\n options,\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n ...helpers,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @param store - The Redux store.\n * @param runSaga - The run saga function.\n * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n options: SimulationOptions,\n store: Store,\n runSaga: RunSagaFunction,\n): RestrictedMiddlewareHooks {\n return {\n getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\n getSnap: getGetSnapImplementation(true),\n setCurrentChain: getSetCurrentChainImplementation(runSaga),\n getSimulationState: store.getState.bind(store),\n };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n return {\n getUnlockPromise: asyncResolve(),\n getIsActive: () => true,\n getVersion: () => '13.6.0-flask.0',\n\n getAllowedKeyringMethods: () => [],\n\n trackError: getTrackErrorImplementation(runSaga),\n trackEvent: getTrackEventImplementation(runSaga),\n startTrace: getStartTraceImplementation(runSaga),\n endTrace: getEndTraceImplementation(runSaga),\n };\n}\n\n/**\n * Get the hooks for the multichain middleware simulation.\n *\n * @param snapId - The Snap ID.\n * @param options - The simulation options.\n * @param controllerMessenger - The controller messenger.\n * @returns The hooks for the middleware.\n */\nexport function getMultichainHooks(\n snapId: SnapId,\n options: SimulationOptions,\n controllerMessenger: RootControllerMessenger,\n): MultichainMiddlewareHooks {\n return {\n getAccounts: () => options.accounts,\n getCaveat: (permission: string, caveatType: string) => {\n try {\n return controllerMessenger.call(\n 'PermissionController:getCaveat',\n snapId,\n permission,\n caveatType,\n );\n } catch (error) {\n if (error instanceof PermissionDoesNotExistError) {\n return undefined;\n }\n /* istanbul ignore next */\n throw error;\n }\n },\n grantPermissions: (approvedPermissions: RequestedPermissions) => {\n controllerMessenger.call('PermissionController:grantPermissions', {\n subject: { origin: snapId },\n approvedPermissions,\n });\n },\n revokePermission: (permission: string) => {\n try {\n controllerMessenger.call('PermissionController:revokePermissions', {\n [snapId]: [permission],\n });\n } catch (error) {\n if (error instanceof PermissionDoesNotExistError) {\n return;\n }\n /* istanbul ignore next */\n throw error;\n }\n },\n };\n}\n\n/**\n * Get the mock mnemonic for a given source ID.\n *\n * @param options - The simulation options.\n * @returns The mnemonic.\n */\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @param options - The simulation options.\n * @param snapId - The ID of the Snap.\n * @param auxiliaryFiles - Auxiliary files from the fetched Snap.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n snapId: SnapId,\n auxiliaryFiles: VirtualFile[],\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: 'all' }),\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getAccountByAddress',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n (address) => {\n const matchingAccount = options.accounts.find(\n (account) => address === account.address,\n );\n\n if (!matchingAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(matchingAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getSelectedMultichainAccount',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n () => {\n const selectedAccount = options.accounts.find(\n (account) => account.selected,\n );\n\n if (!selectedAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(selectedAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:listMultichainAccounts',\n\n () =>\n // @ts-expect-error - These are partial accounts with only the necessary\n // data used by the interface controller.\n options.accounts.map((account) =>\n addSnapMetadataToAccount(account, snapId),\n ),\n );\n\n controllerMessenger.registerActionHandler(\n 'MultichainAssetsController:getState',\n () => ({\n // @ts-expect-error - These are partial assets with only the\n // necessary data used by the interface controller.\n assetsMetadata: options.assets,\n accountsAssets: options.accounts.reduce<Record<string, CaipAssetType[]>>(\n (acc, account) => {\n acc[account.id] = account.assets ?? [];\n return acc;\n },\n {},\n ),\n }),\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:hasRequest',\n (opts) => {\n /**\n * Get the current interface from the store.\n *\n * @yields Selects the current interface from the store.\n * @returns The current interface.\n */\n function* getCurrentInterfaceSaga(): SagaIterator {\n const currentInterface: Interface = yield select(getCurrentInterface);\n return currentInterface;\n }\n\n const currentInterface: Interface | undefined = runSaga(\n getCurrentInterfaceSaga,\n ).result();\n return (\n currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n currentInterface?.id === opts?.id\n );\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:acceptRequest',\n async (_id: string, value: unknown) => {\n await runSaga(resolveWithSaga, value).toPromise();\n\n return { value };\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:addRequest',\n // @ts-expect-error Types of property 'requestData' are incompatible.\n getRequestUserApprovalImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnap',\n getGetSnapImplementation(true),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnapState',\n getGetSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:updateSnapState',\n getUpdateSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:clearSnapState',\n getClearSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnapFile',\n async (_snapId, path, encoding) =>\n getSnapFile(auxiliaryFiles, path, encoding),\n );\n\n const showNativeNotification =\n getShowNativeNotificationImplementation(runSaga);\n const showInAppNotification = getShowInAppNotificationImplementation(runSaga);\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `RateLimitController` is not part of the simulation messenger types.\n 'RateLimitController:call',\n async (\n _origin: string,\n type: 'showNativeNotification' | 'showInAppNotification',\n ...args: unknown[]\n ) => {\n switch (type) {\n case 'showNativeNotification':\n return await showNativeNotification(args[0] as string, {\n type: 'native',\n message: args[1] as string,\n });\n case 'showInAppNotification':\n return await showInAppNotification(\n args[0] as string,\n args[1] as Parameters<typeof showInAppNotification>[1],\n );\n /* istanbul ignore next */\n default:\n return assertExhaustive(type);\n }\n },\n );\n\n const getMnemonic = getGetMnemonicImplementation(\n options.secretRecoveryPhrase,\n );\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `KeyringController` is not part of the simulation messenger types.\n 'KeyringController:getState',\n () => ({\n isUnlocked: true,\n keyrings: [\n {\n type: 'HD Key Tree',\n metadata: {\n id: 'default',\n name: 'Default Secret Recovery Phrase',\n },\n },\n {\n type: 'HD Key Tree',\n metadata: {\n id: 'alternative',\n name: 'Alternative Secret Recovery Phrase',\n },\n },\n ],\n }),\n );\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `KeyringController` is not part of the simulation messenger types.\n 'KeyringController:withKeyring',\n async (\n selector: { type: string; index?: number } | { id: string },\n operation: (args: {\n keyring: { type: string; mnemonic: Uint8Array; seed: Uint8Array };\n }) => Promise<unknown>,\n ) => {\n const source = hasProperty(selector, 'id')\n ? (selector.id as string)\n : undefined;\n\n const mnemonic = await getMnemonic(source);\n const seed = await mnemonicToSeed(mnemonic);\n\n return await operation({\n keyring: {\n type: 'HD Key Tree',\n mnemonic,\n seed,\n },\n });\n },\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"simulation.cjs","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":";;;AAAA,qFAA0E;AAE1E,iDAAoD;AAOpD,mDAAoE;AACpE,2EAIyC;AAEzC,2DAK0C;AAC1C,mEAAoE;AASpE,uDAAiD;AACjD,2CAAgE;AAGhE,qDAA2C;AAE3C,gDAA4C;AAG5C,mDAA6D;AAC7D,uCAAsC;AAEtC,2CAAuC;AACvC,+CAA8C;AAC9C,iDAAwD;AACxD,qDAcyB;AACzB,uDAAmD;AAMnD,2CAAuC;AAOvC,6CAA2D;AAC3D,iDAA2D;AAkM3D;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,WAAW,CAG/B,MAAc,EACd,EACE,gBAAgB,EAChB,uBAAuB,EACvB,OAAO,EAAE,UAAU,GAAG,EAAE,MACgB,EAAE;IAE5C,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAC;IAEvC,oBAAoB;IACpB,MAAM,QAAQ,GAAG,IAAA,yBAAkB,EAAC,MAAM,EAAE;QAC1C,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,MAAM,IAAA,gBAAS,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEpD,sBAAsB;IACtB,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG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ACF,CAAC;IAEF,MAAM,WAAW,GAAG,IAAA,oCAA4B,EAC9C,OAAO,CAAC,oBAAoB,CAC7B,CAAC;IAEF,mBAAmB,CAAC,qBAAqB;IACvC,wFAAwF;IACxF,4BAA4B,EAC5B,GAAG,EAAE,CAAC,CAAC;QACL,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,aAAa;gBACnB,QAAQ,EAAE;oBACR,EAAE,EAAE,SAAS;oBACb,IAAI,EAAE,gCAAgC;iBACvC;aACF;YACD;gBACE,IAAI,EAAE,aAAa;gBACnB,QAAQ,EAAE;oBACR,EAAE,EAAE,aAAa;oBACjB,IAAI,EAAE,oCAAoC;iBAC3C;aACF;SACF;KACF,CAAC,CACH,CAAC;IAEF,mBAAmB,CAAC,qBAAqB;IACvC,wFAAwF;IACxF,uCAAuC,EACvC,KAAK,EACH,QAA2D,EAC3D,SAEsB,EACtB,EAAE;QACF,MAAM,MAAM,GAAG,IAAA,mBAAW,EAAC,QAAQ,EAAE,IAAI,CAAC;YACxC,CAAC,CAAE,QAAQ,CAAC,EAAa;YACzB,CAAC,CAAC,SAAS,CAAC;QAEd,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,IAAA,yBAAc,EAAC,QAAQ,CAAC,CAAC;QAE5C,OAAO,MAAM,SAAS,CAAC;YACrB,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI;gBACV,QAAQ;gBACR,IAAI;aACL;SACF,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC;AA7ND,0CA6NC","sourcesContent":["import { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { mnemonicToSeed } from '@metamask/key-tree';\nimport type {\n ActionConstraint,\n EventConstraint,\n MockAnyNamespace,\n NamespacedName,\n} from '@metamask/messenger';\nimport { MOCK_ANY_NAMESPACE, Messenger } from '@metamask/messenger';\nimport {\n PermissionDoesNotExistError,\n type Caveat,\n type RequestedPermissions,\n} from '@metamask/permission-controller';\nimport type { ExecutionService } from '@metamask/snaps-controllers';\nimport {\n detectSnapLocation,\n fetchSnap,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n TrackEventParams,\n SnapId,\n TraceRequest,\n EndTraceRequest,\n TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { Snap, VirtualFile } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport { assertExhaustive, hasProperty } from '@metamask/utils';\nimport type { CaipAssetType, Hex, Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport type { SnapHelpers } from './helpers';\nimport { getHelpers } from './helpers';\nimport { resolveWithSaga } from './interface';\nimport { asyncResolve, getEndowments } from './methods';\nimport {\n getGetMnemonicImplementation,\n getGetSnapImplementation,\n getTrackEventImplementation,\n getTrackErrorImplementation,\n getEndTraceImplementation,\n getStartTraceImplementation,\n getSetCurrentChainImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getRequestUserApprovalImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n} from './methods/hooks';\nimport { createJsonRpcEngine } from './middleware';\nimport type {\n SimulationAccount,\n SimulationOptions,\n SimulationUserOptions,\n} from './options';\nimport { getOptions } from './options';\nimport type {\n ApplicationState,\n Interface,\n RunSagaFunction,\n Store,\n} from './store';\nimport { createStore, getCurrentInterface } from './store';\nimport { addSnapMetadataToAccount } from './utils/account';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof ExecutionService>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>,\n> =\n ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof ExecutionService>;\n controllerMessenger: Messenger<\n NamespacedName,\n ActionConstraint,\n EventConstraint\n >;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n\n /**\n * A hook that returns metadata about a given Snap.\n *\n * @param snapId - The ID of a Snap.\n * @returns The metadata for the given Snap.\n */\n getSnap: (snapId: string) => Snap;\n\n /**\n * A hook that sets the current chain ID.\n *\n * @param chainId - The chain ID.\n */\n setCurrentChain: (chainId: Hex) => null;\n\n /**\n * A hook that gets the current simulation state.\n *\n * @returns The simulation state.\n */\n getSimulationState: () => ApplicationState;\n};\n\nexport type PermittedMiddlewareHooks = {\n /**\n * A hook that returns a promise that resolves once the extension is unlocked.\n *\n * @param shouldShowUnlockRequest - Whether to show the unlock request.\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A hook that returns whether the client is active or not.\n *\n * @returns A boolean flag signaling whether the client is opened.\n */\n getIsActive: () => boolean;\n\n /**\n * A hook that returns the client version.\n *\n * @returns A string that corresponds to the client version.\n */\n getVersion: () => string;\n\n /**\n * A hook that tracks an error.\n *\n * @param error - The error object containing error details and properties.\n */\n trackError(error: Error): void;\n\n /**\n * A hook that tracks an event.\n *\n * @param event - The event object containing event details and properties.\n */\n trackEvent(event: TrackEventParams['event']): void;\n\n /**\n * A hook that starts a performance trace.\n *\n * @param request - The trace request object containing trace details.\n */\n startTrace(request: TraceRequest): TraceContext;\n\n /**\n * A hook that ends a performance trace.\n *\n * @param request - The trace request object containing trace details.\n * @returns The trace data.\n */\n endTrace(request: EndTraceRequest): void;\n\n /**\n * A hook that returns the allowed keyring methods.\n *\n * @returns The keyring methods.\n */\n getAllowedKeyringMethods(): string[];\n};\n\nexport type MultichainMiddlewareHooks = {\n /**\n * A hook that returns the simulated accounts.\n *\n * @returns The simulated accounts.\n */\n getAccounts: () => SimulationAccount[];\n\n /**\n * A hook that retrieves a caveat for a given permission.\n *\n * @param permission - The permission name.\n * @param caveatType - The caveat type.\n * @returns The caveat, if it exists.\n */\n getCaveat: (\n permission: string,\n caveatType: string,\n ) => Caveat<string, Json> | undefined;\n\n /**\n * A hook that grants permissions to the origin.\n *\n * @param permissions - The permissions.\n */\n grantPermissions: (permissions: RequestedPermissions) => void;\n\n /**\n * A hook that revokes a permission for the origin.\n *\n * @param permission - The permission name.\n */\n revokePermission: (permission: string) => void;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The installed Snap object.\n * @template Service - The type of the execution service.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap & SnapHelpers> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const { store, runSaga } = createStore(options);\n\n const controllerMessenger = new Messenger<MockAnyNamespace, any, any>({\n namespace: MOCK_ANY_NAMESPACE,\n });\n\n registerActions(\n controllerMessenger,\n runSaga,\n options,\n snapId,\n snapFiles.auxiliaryFiles,\n );\n\n // Set up controllers and JSON-RPC stack.\n const restrictedHooks = getRestrictedHooks(options, store, runSaga);\n\n const permittedHooks = getPermittedHooks(runSaga);\n\n const multichainHooks = getMultichainHooks(\n snapId,\n options,\n controllerMessenger,\n );\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks: restrictedHooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n snapId,\n messenger: controllerMessenger,\n store,\n restrictedHooks,\n permittedHooks,\n multichainHooks,\n isMultichain: false,\n });\n\n const multichainEngine = createJsonRpcEngine({\n snapId,\n messenger: controllerMessenger,\n store,\n restrictedHooks,\n permittedHooks,\n multichainHooks,\n isMultichain: true,\n });\n\n // Create execution service.\n const ActualService = executionService ?? NodeThreadExecutionService;\n const service = new ActualService({\n ...executionServiceOptions,\n messenger: new Messenger({\n namespace: 'ExecutionService',\n parent: controllerMessenger,\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n });\n\n const multichainStream = mux.createStream('metamask-multichain-provider');\n const multichainProviderStream = createEngineStream({\n engine: multichainEngine,\n });\n\n /* istanbul ignore next 2 */\n pipeline(\n multichainStream,\n multichainProviderStream,\n multichainStream,\n (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n },\n );\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n const helpers = getHelpers({\n snapId,\n store,\n controllerMessenger,\n runSaga,\n executionService: service,\n options,\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n ...helpers,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @param store - The Redux store.\n * @param runSaga - The run saga function.\n * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n options: SimulationOptions,\n store: Store,\n runSaga: RunSagaFunction,\n): RestrictedMiddlewareHooks {\n return {\n getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\n getSnap: getGetSnapImplementation(true),\n setCurrentChain: getSetCurrentChainImplementation(runSaga),\n getSimulationState: store.getState.bind(store),\n };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n return {\n getUnlockPromise: asyncResolve(),\n getIsActive: () => true,\n getVersion: () => '13.6.0-flask.0',\n\n getAllowedKeyringMethods: () => [],\n\n trackError: getTrackErrorImplementation(runSaga),\n trackEvent: getTrackEventImplementation(runSaga),\n startTrace: getStartTraceImplementation(runSaga),\n endTrace: getEndTraceImplementation(runSaga),\n };\n}\n\n/**\n * Get the hooks for the multichain middleware simulation.\n *\n * @param snapId - The Snap ID.\n * @param options - The simulation options.\n * @param controllerMessenger - The controller messenger.\n * @returns The hooks for the middleware.\n */\nexport function getMultichainHooks(\n snapId: SnapId,\n options: SimulationOptions,\n controllerMessenger: RootControllerMessenger,\n): MultichainMiddlewareHooks {\n return {\n getAccounts: () => options.accounts,\n getCaveat: (permission: string, caveatType: string) => {\n try {\n return controllerMessenger.call(\n 'PermissionController:getCaveat',\n snapId,\n permission,\n caveatType,\n );\n } catch (error) {\n if (error instanceof PermissionDoesNotExistError) {\n return undefined;\n }\n /* istanbul ignore next */\n throw error;\n }\n },\n grantPermissions: (approvedPermissions: RequestedPermissions) => {\n controllerMessenger.call('PermissionController:grantPermissions', {\n subject: { origin: snapId },\n approvedPermissions,\n });\n },\n revokePermission: (permission: string) => {\n try {\n controllerMessenger.call('PermissionController:revokePermissions', {\n [snapId]: [permission],\n });\n } catch (error) {\n if (error instanceof PermissionDoesNotExistError) {\n return;\n }\n /* istanbul ignore next */\n throw error;\n }\n },\n };\n}\n\n/**\n * Get the mock mnemonic for a given source ID.\n *\n * @param options - The simulation options.\n * @returns The mnemonic.\n */\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @param options - The simulation options.\n * @param snapId - The ID of the Snap.\n * @param auxiliaryFiles - Auxiliary files from the fetched Snap.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n snapId: SnapId,\n auxiliaryFiles: VirtualFile[],\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: 'all' }),\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getAccountByAddress',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n (address) => {\n const matchingAccount = options.accounts.find(\n (account) => address === account.address,\n );\n\n if (!matchingAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(matchingAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getSelectedMultichainAccount',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n () => {\n const selectedAccount = options.accounts.find(\n (account) => account.selected,\n );\n\n if (!selectedAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(selectedAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:listMultichainAccounts',\n\n () =>\n // @ts-expect-error - These are partial accounts with only the necessary\n // data used by the interface controller.\n options.accounts.map((account) =>\n addSnapMetadataToAccount(account, snapId),\n ),\n );\n\n controllerMessenger.registerActionHandler(\n 'MultichainAssetsController:getState',\n () => ({\n // @ts-expect-error - These are partial assets with only the\n // necessary data used by the interface controller.\n assetsMetadata: options.assets,\n accountsAssets: options.accounts.reduce<Record<string, CaipAssetType[]>>(\n (acc, account) => {\n acc[account.id] = account.assets ?? [];\n return acc;\n },\n {},\n ),\n }),\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:hasRequest',\n (opts) => {\n /**\n * Get the current interface from the store.\n *\n * @yields Selects the current interface from the store.\n * @returns The current interface.\n */\n function* getCurrentInterfaceSaga(): SagaIterator {\n const currentInterface: Interface = yield select(getCurrentInterface);\n return currentInterface;\n }\n\n const currentInterface: Interface | undefined = runSaga(\n getCurrentInterfaceSaga,\n ).result();\n return (\n currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n currentInterface?.id === opts?.id\n );\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:acceptRequest',\n async (_id: string, value: unknown) => {\n await runSaga(resolveWithSaga, value).toPromise();\n\n return { value };\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:addRequest',\n // @ts-expect-error Types of property 'requestData' are incompatible.\n getRequestUserApprovalImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnap',\n getGetSnapImplementation(true),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnapState',\n getGetSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:updateSnapState',\n getUpdateSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:clearSnapState',\n getClearSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnapFile',\n async (_snapId, path, encoding) =>\n getSnapFile(auxiliaryFiles, path, encoding),\n );\n\n const showNativeNotification =\n getShowNativeNotificationImplementation(runSaga);\n const showInAppNotification = getShowInAppNotificationImplementation(runSaga);\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `RateLimitController` is not part of the simulation messenger types.\n 'RateLimitController:call',\n async (\n _origin: string,\n type: 'showNativeNotification' | 'showInAppNotification',\n ...args: unknown[]\n ) => {\n switch (type) {\n case 'showNativeNotification':\n return await showNativeNotification(args[0] as string, {\n type: 'native',\n message: args[1] as string,\n });\n case 'showInAppNotification':\n return await showInAppNotification(\n args[0] as string,\n args[1] as Parameters<typeof showInAppNotification>[1],\n );\n /* istanbul ignore next */\n default:\n return assertExhaustive(type);\n }\n },\n );\n\n const getMnemonic = getGetMnemonicImplementation(\n options.secretRecoveryPhrase,\n );\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `KeyringController` is not part of the simulation messenger types.\n 'KeyringController:getState',\n () => ({\n isUnlocked: true,\n keyrings: [\n {\n type: 'HD Key Tree',\n metadata: {\n id: 'default',\n name: 'Default Secret Recovery Phrase',\n },\n },\n {\n type: 'HD Key Tree',\n metadata: {\n id: 'alternative',\n name: 'Alternative Secret Recovery Phrase',\n },\n },\n ],\n }),\n );\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `KeyringController` is not part of the simulation messenger types.\n 'KeyringController:withKeyringV2Unsafe',\n async (\n selector: { type: string; index?: number } | { id: string },\n operation: (args: {\n keyring: { type: string; mnemonic: Uint8Array; seed: Uint8Array };\n }) => Promise<unknown>,\n ) => {\n const source = hasProperty(selector, 'id')\n ? (selector.id as string)\n : undefined;\n\n const mnemonic = await getMnemonic(source);\n const seed = await mnemonicToSeed(mnemonic);\n\n return await operation({\n keyring: {\n type: 'hd',\n mnemonic,\n seed,\n },\n });\n },\n );\n}\n"]}
|
package/dist/simulation.mjs
CHANGED
|
@@ -334,7 +334,7 @@ export function registerActions(controllerMessenger, runSaga, options, snapId, a
|
|
|
334
334
|
}));
|
|
335
335
|
controllerMessenger.registerActionHandler(
|
|
336
336
|
// @ts-expect-error - `KeyringController` is not part of the simulation messenger types.
|
|
337
|
-
'KeyringController:
|
|
337
|
+
'KeyringController:withKeyringV2Unsafe', async (selector, operation) => {
|
|
338
338
|
const source = hasProperty(selector, 'id')
|
|
339
339
|
? selector.id
|
|
340
340
|
: undefined;
|
|
@@ -342,7 +342,7 @@ export function registerActions(controllerMessenger, runSaga, options, snapId, a
|
|
|
342
342
|
const seed = await mnemonicToSeed(mnemonic);
|
|
343
343
|
return await operation({
|
|
344
344
|
keyring: {
|
|
345
|
-
type: '
|
|
345
|
+
type: 'hd',
|
|
346
346
|
mnemonic,
|
|
347
347
|
seed,
|
|
348
348
|
},
|
package/dist/simulation.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation.mjs","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,6CAA6C;AAE1E,OAAO,EAAE,cAAc,EAAE,2BAA2B;AAOpD,OAAO,EAAE,kBAA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C,oBAAoB,CAC7B,CAAC;IAEF,mBAAmB,CAAC,qBAAqB;IACvC,wFAAwF;IACxF,4BAA4B,EAC5B,GAAG,EAAE,CAAC,CAAC;QACL,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,aAAa;gBACnB,QAAQ,EAAE;oBACR,EAAE,EAAE,SAAS;oBACb,IAAI,EAAE,gCAAgC;iBACvC;aACF;YACD;gBACE,IAAI,EAAE,aAAa;gBACnB,QAAQ,EAAE;oBACR,EAAE,EAAE,aAAa;oBACjB,IAAI,EAAE,oCAAoC;iBAC3C;aACF;SACF;KACF,CAAC,CACH,CAAC;IAEF,mBAAmB,CAAC,qBAAqB;IACvC,wFAAwF;IACxF,+BAA+B,EAC/B,KAAK,EACH,QAA2D,EAC3D,SAEsB,EACtB,EAAE;QACF,MAAM,MAAM,GAAG,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC;YACxC,CAAC,CAAE,QAAQ,CAAC,EAAa;YACzB,CAAC,CAAC,SAAS,CAAC;QAEd,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAC;QAE5C,OAAO,MAAM,SAAS,CAAC;YACrB,OAAO,EAAE;gBACP,IAAI,EAAE,aAAa;gBACnB,QAAQ;gBACR,IAAI;aACL;SACF,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { mnemonicToSeed } from '@metamask/key-tree';\nimport type {\n ActionConstraint,\n EventConstraint,\n MockAnyNamespace,\n NamespacedName,\n} from '@metamask/messenger';\nimport { MOCK_ANY_NAMESPACE, Messenger } from '@metamask/messenger';\nimport {\n PermissionDoesNotExistError,\n type Caveat,\n type RequestedPermissions,\n} from '@metamask/permission-controller';\nimport type { ExecutionService } from '@metamask/snaps-controllers';\nimport {\n detectSnapLocation,\n fetchSnap,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n TrackEventParams,\n SnapId,\n TraceRequest,\n EndTraceRequest,\n TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { Snap, VirtualFile } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport { assertExhaustive, hasProperty } from '@metamask/utils';\nimport type { CaipAssetType, Hex, Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport type { SnapHelpers } from './helpers';\nimport { getHelpers } from './helpers';\nimport { resolveWithSaga } from './interface';\nimport { asyncResolve, getEndowments } from './methods';\nimport {\n getGetMnemonicImplementation,\n getGetSnapImplementation,\n getTrackEventImplementation,\n getTrackErrorImplementation,\n getEndTraceImplementation,\n getStartTraceImplementation,\n getSetCurrentChainImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getRequestUserApprovalImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n} from './methods/hooks';\nimport { createJsonRpcEngine } from './middleware';\nimport type {\n SimulationAccount,\n SimulationOptions,\n SimulationUserOptions,\n} from './options';\nimport { getOptions } from './options';\nimport type {\n ApplicationState,\n Interface,\n RunSagaFunction,\n Store,\n} from './store';\nimport { createStore, getCurrentInterface } from './store';\nimport { addSnapMetadataToAccount } from './utils/account';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof ExecutionService>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>,\n> =\n ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof ExecutionService>;\n controllerMessenger: Messenger<\n NamespacedName,\n ActionConstraint,\n EventConstraint\n >;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n\n /**\n * A hook that returns metadata about a given Snap.\n *\n * @param snapId - The ID of a Snap.\n * @returns The metadata for the given Snap.\n */\n getSnap: (snapId: string) => Snap;\n\n /**\n * A hook that sets the current chain ID.\n *\n * @param chainId - The chain ID.\n */\n setCurrentChain: (chainId: Hex) => null;\n\n /**\n * A hook that gets the current simulation state.\n *\n * @returns The simulation state.\n */\n getSimulationState: () => ApplicationState;\n};\n\nexport type PermittedMiddlewareHooks = {\n /**\n * A hook that returns a promise that resolves once the extension is unlocked.\n *\n * @param shouldShowUnlockRequest - Whether to show the unlock request.\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A hook that returns whether the client is active or not.\n *\n * @returns A boolean flag signaling whether the client is opened.\n */\n getIsActive: () => boolean;\n\n /**\n * A hook that returns the client version.\n *\n * @returns A string that corresponds to the client version.\n */\n getVersion: () => string;\n\n /**\n * A hook that tracks an error.\n *\n * @param error - The error object containing error details and properties.\n */\n trackError(error: Error): void;\n\n /**\n * A hook that tracks an event.\n *\n * @param event - The event object containing event details and properties.\n */\n trackEvent(event: TrackEventParams['event']): void;\n\n /**\n * A hook that starts a performance trace.\n *\n * @param request - The trace request object containing trace details.\n */\n startTrace(request: TraceRequest): TraceContext;\n\n /**\n * A hook that ends a performance trace.\n *\n * @param request - The trace request object containing trace details.\n * @returns The trace data.\n */\n endTrace(request: EndTraceRequest): void;\n\n /**\n * A hook that returns the allowed keyring methods.\n *\n * @returns The keyring methods.\n */\n getAllowedKeyringMethods(): string[];\n};\n\nexport type MultichainMiddlewareHooks = {\n /**\n * A hook that returns the simulated accounts.\n *\n * @returns The simulated accounts.\n */\n getAccounts: () => SimulationAccount[];\n\n /**\n * A hook that retrieves a caveat for a given permission.\n *\n * @param permission - The permission name.\n * @param caveatType - The caveat type.\n * @returns The caveat, if it exists.\n */\n getCaveat: (\n permission: string,\n caveatType: string,\n ) => Caveat<string, Json> | undefined;\n\n /**\n * A hook that grants permissions to the origin.\n *\n * @param permissions - The permissions.\n */\n grantPermissions: (permissions: RequestedPermissions) => void;\n\n /**\n * A hook that revokes a permission for the origin.\n *\n * @param permission - The permission name.\n */\n revokePermission: (permission: string) => void;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The installed Snap object.\n * @template Service - The type of the execution service.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap & SnapHelpers> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const { store, runSaga } = createStore(options);\n\n const controllerMessenger = new Messenger<MockAnyNamespace, any, any>({\n namespace: MOCK_ANY_NAMESPACE,\n });\n\n registerActions(\n controllerMessenger,\n runSaga,\n options,\n snapId,\n snapFiles.auxiliaryFiles,\n );\n\n // Set up controllers and JSON-RPC stack.\n const restrictedHooks = getRestrictedHooks(options, store, runSaga);\n\n const permittedHooks = getPermittedHooks(runSaga);\n\n const multichainHooks = getMultichainHooks(\n snapId,\n options,\n controllerMessenger,\n );\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks: restrictedHooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n snapId,\n messenger: controllerMessenger,\n store,\n restrictedHooks,\n permittedHooks,\n multichainHooks,\n isMultichain: false,\n });\n\n const multichainEngine = createJsonRpcEngine({\n snapId,\n messenger: controllerMessenger,\n store,\n restrictedHooks,\n permittedHooks,\n multichainHooks,\n isMultichain: true,\n });\n\n // Create execution service.\n const ActualService = executionService ?? NodeThreadExecutionService;\n const service = new ActualService({\n ...executionServiceOptions,\n messenger: new Messenger({\n namespace: 'ExecutionService',\n parent: controllerMessenger,\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n });\n\n const multichainStream = mux.createStream('metamask-multichain-provider');\n const multichainProviderStream = createEngineStream({\n engine: multichainEngine,\n });\n\n /* istanbul ignore next 2 */\n pipeline(\n multichainStream,\n multichainProviderStream,\n multichainStream,\n (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n },\n );\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n const helpers = getHelpers({\n snapId,\n store,\n controllerMessenger,\n runSaga,\n executionService: service,\n options,\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n ...helpers,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @param store - The Redux store.\n * @param runSaga - The run saga function.\n * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n options: SimulationOptions,\n store: Store,\n runSaga: RunSagaFunction,\n): RestrictedMiddlewareHooks {\n return {\n getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\n getSnap: getGetSnapImplementation(true),\n setCurrentChain: getSetCurrentChainImplementation(runSaga),\n getSimulationState: store.getState.bind(store),\n };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n return {\n getUnlockPromise: asyncResolve(),\n getIsActive: () => true,\n getVersion: () => '13.6.0-flask.0',\n\n getAllowedKeyringMethods: () => [],\n\n trackError: getTrackErrorImplementation(runSaga),\n trackEvent: getTrackEventImplementation(runSaga),\n startTrace: getStartTraceImplementation(runSaga),\n endTrace: getEndTraceImplementation(runSaga),\n };\n}\n\n/**\n * Get the hooks for the multichain middleware simulation.\n *\n * @param snapId - The Snap ID.\n * @param options - The simulation options.\n * @param controllerMessenger - The controller messenger.\n * @returns The hooks for the middleware.\n */\nexport function getMultichainHooks(\n snapId: SnapId,\n options: SimulationOptions,\n controllerMessenger: RootControllerMessenger,\n): MultichainMiddlewareHooks {\n return {\n getAccounts: () => options.accounts,\n getCaveat: (permission: string, caveatType: string) => {\n try {\n return controllerMessenger.call(\n 'PermissionController:getCaveat',\n snapId,\n permission,\n caveatType,\n );\n } catch (error) {\n if (error instanceof PermissionDoesNotExistError) {\n return undefined;\n }\n /* istanbul ignore next */\n throw error;\n }\n },\n grantPermissions: (approvedPermissions: RequestedPermissions) => {\n controllerMessenger.call('PermissionController:grantPermissions', {\n subject: { origin: snapId },\n approvedPermissions,\n });\n },\n revokePermission: (permission: string) => {\n try {\n controllerMessenger.call('PermissionController:revokePermissions', {\n [snapId]: [permission],\n });\n } catch (error) {\n if (error instanceof PermissionDoesNotExistError) {\n return;\n }\n /* istanbul ignore next */\n throw error;\n }\n },\n };\n}\n\n/**\n * Get the mock mnemonic for a given source ID.\n *\n * @param options - The simulation options.\n * @returns The mnemonic.\n */\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @param options - The simulation options.\n * @param snapId - The ID of the Snap.\n * @param auxiliaryFiles - Auxiliary files from the fetched Snap.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n snapId: SnapId,\n auxiliaryFiles: VirtualFile[],\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: 'all' }),\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getAccountByAddress',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n (address) => {\n const matchingAccount = options.accounts.find(\n (account) => address === account.address,\n );\n\n if (!matchingAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(matchingAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getSelectedMultichainAccount',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n () => {\n const selectedAccount = options.accounts.find(\n (account) => account.selected,\n );\n\n if (!selectedAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(selectedAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:listMultichainAccounts',\n\n () =>\n // @ts-expect-error - These are partial accounts with only the necessary\n // data used by the interface controller.\n options.accounts.map((account) =>\n addSnapMetadataToAccount(account, snapId),\n ),\n );\n\n controllerMessenger.registerActionHandler(\n 'MultichainAssetsController:getState',\n () => ({\n // @ts-expect-error - These are partial assets with only the\n // necessary data used by the interface controller.\n assetsMetadata: options.assets,\n accountsAssets: options.accounts.reduce<Record<string, CaipAssetType[]>>(\n (acc, account) => {\n acc[account.id] = account.assets ?? [];\n return acc;\n },\n {},\n ),\n }),\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:hasRequest',\n (opts) => {\n /**\n * Get the current interface from the store.\n *\n * @yields Selects the current interface from the store.\n * @returns The current interface.\n */\n function* getCurrentInterfaceSaga(): SagaIterator {\n const currentInterface: Interface = yield select(getCurrentInterface);\n return currentInterface;\n }\n\n const currentInterface: Interface | undefined = runSaga(\n getCurrentInterfaceSaga,\n ).result();\n return (\n currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n currentInterface?.id === opts?.id\n );\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:acceptRequest',\n async (_id: string, value: unknown) => {\n await runSaga(resolveWithSaga, value).toPromise();\n\n return { value };\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:addRequest',\n // @ts-expect-error Types of property 'requestData' are incompatible.\n getRequestUserApprovalImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnap',\n getGetSnapImplementation(true),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnapState',\n getGetSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:updateSnapState',\n getUpdateSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:clearSnapState',\n getClearSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnapFile',\n async (_snapId, path, encoding) =>\n getSnapFile(auxiliaryFiles, path, encoding),\n );\n\n const showNativeNotification =\n getShowNativeNotificationImplementation(runSaga);\n const showInAppNotification = getShowInAppNotificationImplementation(runSaga);\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `RateLimitController` is not part of the simulation messenger types.\n 'RateLimitController:call',\n async (\n _origin: string,\n type: 'showNativeNotification' | 'showInAppNotification',\n ...args: unknown[]\n ) => {\n switch (type) {\n case 'showNativeNotification':\n return await showNativeNotification(args[0] as string, {\n type: 'native',\n message: args[1] as string,\n });\n case 'showInAppNotification':\n return await showInAppNotification(\n args[0] as string,\n args[1] as Parameters<typeof showInAppNotification>[1],\n );\n /* istanbul ignore next */\n default:\n return assertExhaustive(type);\n }\n },\n );\n\n const getMnemonic = getGetMnemonicImplementation(\n options.secretRecoveryPhrase,\n );\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `KeyringController` is not part of the simulation messenger types.\n 'KeyringController:getState',\n () => ({\n isUnlocked: true,\n keyrings: [\n {\n type: 'HD Key Tree',\n metadata: {\n id: 'default',\n name: 'Default Secret Recovery Phrase',\n },\n },\n {\n type: 'HD Key Tree',\n metadata: {\n id: 'alternative',\n name: 'Alternative Secret Recovery Phrase',\n },\n },\n ],\n }),\n );\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `KeyringController` is not part of the simulation messenger types.\n 'KeyringController:withKeyring',\n async (\n selector: { type: string; index?: number } | { id: string },\n operation: (args: {\n keyring: { type: string; mnemonic: Uint8Array; seed: Uint8Array };\n }) => Promise<unknown>,\n ) => {\n const source = hasProperty(selector, 'id')\n ? (selector.id as string)\n : undefined;\n\n const mnemonic = await getMnemonic(source);\n const seed = await mnemonicToSeed(mnemonic);\n\n return await operation({\n keyring: {\n type: 'HD Key Tree',\n mnemonic,\n seed,\n },\n });\n },\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"simulation.mjs","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,6CAA6C;AAE1E,OAAO,EAAE,cAAc,EAAE,2BAA2B;AAOpD,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,4BAA4B;AACpE,OAAO,EACL,2BAA2B,EAG5B,wCAAwC;AAEzC,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,0BAA0B,EAC1B,cAAc,EACf,yCAAyC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,oCAAoC;AASpE,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,wBAAwB;AAGhE,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAE3C,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAG5C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,0BAAsB;AAC7D,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,OAAO,EAAE,UAAU,EAAE,sBAAkB;AACvC,OAAO,EAAE,eAAe,EAAE,wBAAoB;AAC9C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,4BAAkB;AACxD,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,2BAA2B,EAC3B,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC3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,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAC;QAE5C,OAAO,MAAM,SAAS,CAAC;YACrB,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI;gBACV,QAAQ;gBACR,IAAI;aACL;SACF,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { mnemonicToSeed } from '@metamask/key-tree';\nimport type {\n ActionConstraint,\n EventConstraint,\n MockAnyNamespace,\n NamespacedName,\n} from '@metamask/messenger';\nimport { MOCK_ANY_NAMESPACE, Messenger } from '@metamask/messenger';\nimport {\n PermissionDoesNotExistError,\n type Caveat,\n type RequestedPermissions,\n} from '@metamask/permission-controller';\nimport type { ExecutionService } from '@metamask/snaps-controllers';\nimport {\n detectSnapLocation,\n fetchSnap,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n TrackEventParams,\n SnapId,\n TraceRequest,\n EndTraceRequest,\n TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { Snap, VirtualFile } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport { assertExhaustive, hasProperty } from '@metamask/utils';\nimport type { CaipAssetType, Hex, Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport type { SnapHelpers } from './helpers';\nimport { getHelpers } from './helpers';\nimport { resolveWithSaga } from './interface';\nimport { asyncResolve, getEndowments } from './methods';\nimport {\n getGetMnemonicImplementation,\n getGetSnapImplementation,\n getTrackEventImplementation,\n getTrackErrorImplementation,\n getEndTraceImplementation,\n getStartTraceImplementation,\n getSetCurrentChainImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getRequestUserApprovalImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n} from './methods/hooks';\nimport { createJsonRpcEngine } from './middleware';\nimport type {\n SimulationAccount,\n SimulationOptions,\n SimulationUserOptions,\n} from './options';\nimport { getOptions } from './options';\nimport type {\n ApplicationState,\n Interface,\n RunSagaFunction,\n Store,\n} from './store';\nimport { createStore, getCurrentInterface } from './store';\nimport { addSnapMetadataToAccount } from './utils/account';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof ExecutionService>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>,\n> =\n ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof ExecutionService>;\n controllerMessenger: Messenger<\n NamespacedName,\n ActionConstraint,\n EventConstraint\n >;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n\n /**\n * A hook that returns metadata about a given Snap.\n *\n * @param snapId - The ID of a Snap.\n * @returns The metadata for the given Snap.\n */\n getSnap: (snapId: string) => Snap;\n\n /**\n * A hook that sets the current chain ID.\n *\n * @param chainId - The chain ID.\n */\n setCurrentChain: (chainId: Hex) => null;\n\n /**\n * A hook that gets the current simulation state.\n *\n * @returns The simulation state.\n */\n getSimulationState: () => ApplicationState;\n};\n\nexport type PermittedMiddlewareHooks = {\n /**\n * A hook that returns a promise that resolves once the extension is unlocked.\n *\n * @param shouldShowUnlockRequest - Whether to show the unlock request.\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A hook that returns whether the client is active or not.\n *\n * @returns A boolean flag signaling whether the client is opened.\n */\n getIsActive: () => boolean;\n\n /**\n * A hook that returns the client version.\n *\n * @returns A string that corresponds to the client version.\n */\n getVersion: () => string;\n\n /**\n * A hook that tracks an error.\n *\n * @param error - The error object containing error details and properties.\n */\n trackError(error: Error): void;\n\n /**\n * A hook that tracks an event.\n *\n * @param event - The event object containing event details and properties.\n */\n trackEvent(event: TrackEventParams['event']): void;\n\n /**\n * A hook that starts a performance trace.\n *\n * @param request - The trace request object containing trace details.\n */\n startTrace(request: TraceRequest): TraceContext;\n\n /**\n * A hook that ends a performance trace.\n *\n * @param request - The trace request object containing trace details.\n * @returns The trace data.\n */\n endTrace(request: EndTraceRequest): void;\n\n /**\n * A hook that returns the allowed keyring methods.\n *\n * @returns The keyring methods.\n */\n getAllowedKeyringMethods(): string[];\n};\n\nexport type MultichainMiddlewareHooks = {\n /**\n * A hook that returns the simulated accounts.\n *\n * @returns The simulated accounts.\n */\n getAccounts: () => SimulationAccount[];\n\n /**\n * A hook that retrieves a caveat for a given permission.\n *\n * @param permission - The permission name.\n * @param caveatType - The caveat type.\n * @returns The caveat, if it exists.\n */\n getCaveat: (\n permission: string,\n caveatType: string,\n ) => Caveat<string, Json> | undefined;\n\n /**\n * A hook that grants permissions to the origin.\n *\n * @param permissions - The permissions.\n */\n grantPermissions: (permissions: RequestedPermissions) => void;\n\n /**\n * A hook that revokes a permission for the origin.\n *\n * @param permission - The permission name.\n */\n revokePermission: (permission: string) => void;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The installed Snap object.\n * @template Service - The type of the execution service.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap & SnapHelpers> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const { store, runSaga } = createStore(options);\n\n const controllerMessenger = new Messenger<MockAnyNamespace, any, any>({\n namespace: MOCK_ANY_NAMESPACE,\n });\n\n registerActions(\n controllerMessenger,\n runSaga,\n options,\n snapId,\n snapFiles.auxiliaryFiles,\n );\n\n // Set up controllers and JSON-RPC stack.\n const restrictedHooks = getRestrictedHooks(options, store, runSaga);\n\n const permittedHooks = getPermittedHooks(runSaga);\n\n const multichainHooks = getMultichainHooks(\n snapId,\n options,\n controllerMessenger,\n );\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks: restrictedHooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n snapId,\n messenger: controllerMessenger,\n store,\n restrictedHooks,\n permittedHooks,\n multichainHooks,\n isMultichain: false,\n });\n\n const multichainEngine = createJsonRpcEngine({\n snapId,\n messenger: controllerMessenger,\n store,\n restrictedHooks,\n permittedHooks,\n multichainHooks,\n isMultichain: true,\n });\n\n // Create execution service.\n const ActualService = executionService ?? NodeThreadExecutionService;\n const service = new ActualService({\n ...executionServiceOptions,\n messenger: new Messenger({\n namespace: 'ExecutionService',\n parent: controllerMessenger,\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n });\n\n const multichainStream = mux.createStream('metamask-multichain-provider');\n const multichainProviderStream = createEngineStream({\n engine: multichainEngine,\n });\n\n /* istanbul ignore next 2 */\n pipeline(\n multichainStream,\n multichainProviderStream,\n multichainStream,\n (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n },\n );\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n const helpers = getHelpers({\n snapId,\n store,\n controllerMessenger,\n runSaga,\n executionService: service,\n options,\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n ...helpers,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @param store - The Redux store.\n * @param runSaga - The run saga function.\n * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n options: SimulationOptions,\n store: Store,\n runSaga: RunSagaFunction,\n): RestrictedMiddlewareHooks {\n return {\n getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\n getSnap: getGetSnapImplementation(true),\n setCurrentChain: getSetCurrentChainImplementation(runSaga),\n getSimulationState: store.getState.bind(store),\n };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n return {\n getUnlockPromise: asyncResolve(),\n getIsActive: () => true,\n getVersion: () => '13.6.0-flask.0',\n\n getAllowedKeyringMethods: () => [],\n\n trackError: getTrackErrorImplementation(runSaga),\n trackEvent: getTrackEventImplementation(runSaga),\n startTrace: getStartTraceImplementation(runSaga),\n endTrace: getEndTraceImplementation(runSaga),\n };\n}\n\n/**\n * Get the hooks for the multichain middleware simulation.\n *\n * @param snapId - The Snap ID.\n * @param options - The simulation options.\n * @param controllerMessenger - The controller messenger.\n * @returns The hooks for the middleware.\n */\nexport function getMultichainHooks(\n snapId: SnapId,\n options: SimulationOptions,\n controllerMessenger: RootControllerMessenger,\n): MultichainMiddlewareHooks {\n return {\n getAccounts: () => options.accounts,\n getCaveat: (permission: string, caveatType: string) => {\n try {\n return controllerMessenger.call(\n 'PermissionController:getCaveat',\n snapId,\n permission,\n caveatType,\n );\n } catch (error) {\n if (error instanceof PermissionDoesNotExistError) {\n return undefined;\n }\n /* istanbul ignore next */\n throw error;\n }\n },\n grantPermissions: (approvedPermissions: RequestedPermissions) => {\n controllerMessenger.call('PermissionController:grantPermissions', {\n subject: { origin: snapId },\n approvedPermissions,\n });\n },\n revokePermission: (permission: string) => {\n try {\n controllerMessenger.call('PermissionController:revokePermissions', {\n [snapId]: [permission],\n });\n } catch (error) {\n if (error instanceof PermissionDoesNotExistError) {\n return;\n }\n /* istanbul ignore next */\n throw error;\n }\n },\n };\n}\n\n/**\n * Get the mock mnemonic for a given source ID.\n *\n * @param options - The simulation options.\n * @returns The mnemonic.\n */\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @param options - The simulation options.\n * @param snapId - The ID of the Snap.\n * @param auxiliaryFiles - Auxiliary files from the fetched Snap.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n snapId: SnapId,\n auxiliaryFiles: VirtualFile[],\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: 'all' }),\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getAccountByAddress',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n (address) => {\n const matchingAccount = options.accounts.find(\n (account) => address === account.address,\n );\n\n if (!matchingAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(matchingAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getSelectedMultichainAccount',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n () => {\n const selectedAccount = options.accounts.find(\n (account) => account.selected,\n );\n\n if (!selectedAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(selectedAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:listMultichainAccounts',\n\n () =>\n // @ts-expect-error - These are partial accounts with only the necessary\n // data used by the interface controller.\n options.accounts.map((account) =>\n addSnapMetadataToAccount(account, snapId),\n ),\n );\n\n controllerMessenger.registerActionHandler(\n 'MultichainAssetsController:getState',\n () => ({\n // @ts-expect-error - These are partial assets with only the\n // necessary data used by the interface controller.\n assetsMetadata: options.assets,\n accountsAssets: options.accounts.reduce<Record<string, CaipAssetType[]>>(\n (acc, account) => {\n acc[account.id] = account.assets ?? [];\n return acc;\n },\n {},\n ),\n }),\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:hasRequest',\n (opts) => {\n /**\n * Get the current interface from the store.\n *\n * @yields Selects the current interface from the store.\n * @returns The current interface.\n */\n function* getCurrentInterfaceSaga(): SagaIterator {\n const currentInterface: Interface = yield select(getCurrentInterface);\n return currentInterface;\n }\n\n const currentInterface: Interface | undefined = runSaga(\n getCurrentInterfaceSaga,\n ).result();\n return (\n currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n currentInterface?.id === opts?.id\n );\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:acceptRequest',\n async (_id: string, value: unknown) => {\n await runSaga(resolveWithSaga, value).toPromise();\n\n return { value };\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:addRequest',\n // @ts-expect-error Types of property 'requestData' are incompatible.\n getRequestUserApprovalImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnap',\n getGetSnapImplementation(true),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnapState',\n getGetSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:updateSnapState',\n getUpdateSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:clearSnapState',\n getClearSnapStateMethodImplementation(runSaga),\n );\n\n controllerMessenger.registerActionHandler(\n 'SnapController:getSnapFile',\n async (_snapId, path, encoding) =>\n getSnapFile(auxiliaryFiles, path, encoding),\n );\n\n const showNativeNotification =\n getShowNativeNotificationImplementation(runSaga);\n const showInAppNotification = getShowInAppNotificationImplementation(runSaga);\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `RateLimitController` is not part of the simulation messenger types.\n 'RateLimitController:call',\n async (\n _origin: string,\n type: 'showNativeNotification' | 'showInAppNotification',\n ...args: unknown[]\n ) => {\n switch (type) {\n case 'showNativeNotification':\n return await showNativeNotification(args[0] as string, {\n type: 'native',\n message: args[1] as string,\n });\n case 'showInAppNotification':\n return await showInAppNotification(\n args[0] as string,\n args[1] as Parameters<typeof showInAppNotification>[1],\n );\n /* istanbul ignore next */\n default:\n return assertExhaustive(type);\n }\n },\n );\n\n const getMnemonic = getGetMnemonicImplementation(\n options.secretRecoveryPhrase,\n );\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `KeyringController` is not part of the simulation messenger types.\n 'KeyringController:getState',\n () => ({\n isUnlocked: true,\n keyrings: [\n {\n type: 'HD Key Tree',\n metadata: {\n id: 'default',\n name: 'Default Secret Recovery Phrase',\n },\n },\n {\n type: 'HD Key Tree',\n metadata: {\n id: 'alternative',\n name: 'Alternative Secret Recovery Phrase',\n },\n },\n ],\n }),\n );\n\n controllerMessenger.registerActionHandler(\n // @ts-expect-error - `KeyringController` is not part of the simulation messenger types.\n 'KeyringController:withKeyringV2Unsafe',\n async (\n selector: { type: string; index?: number } | { id: string },\n operation: (args: {\n keyring: { type: string; mnemonic: Uint8Array; seed: Uint8Array };\n }) => Promise<unknown>,\n ) => {\n const source = hasProperty(selector, 'id')\n ? (selector.id as string)\n : undefined;\n\n const mnemonic = await getMnemonic(source);\n const seed = await mnemonicToSeed(mnemonic);\n\n return await operation({\n keyring: {\n type: 'hd',\n mnemonic,\n seed,\n },\n });\n },\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-simulation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -55,18 +55,18 @@
|
|
|
55
55
|
"test:watch": "jest --watch"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@metamask/chain-agnostic-permission": "^1.6.
|
|
58
|
+
"@metamask/chain-agnostic-permission": "^1.6.1",
|
|
59
59
|
"@metamask/json-rpc-engine": "^10.5.0",
|
|
60
60
|
"@metamask/json-rpc-middleware-stream": "^8.0.8",
|
|
61
61
|
"@metamask/key-tree": "^10.1.1",
|
|
62
62
|
"@metamask/messenger": "^1.2.0",
|
|
63
|
-
"@metamask/permission-controller": "^13.1.
|
|
63
|
+
"@metamask/permission-controller": "^13.1.1",
|
|
64
64
|
"@metamask/rpc-errors": "^7.0.3",
|
|
65
|
-
"@metamask/snaps-controllers": "^20.0.
|
|
66
|
-
"@metamask/snaps-execution-environments": "^11.1.
|
|
67
|
-
"@metamask/snaps-rpc-methods": "^
|
|
65
|
+
"@metamask/snaps-controllers": "^20.0.6",
|
|
66
|
+
"@metamask/snaps-execution-environments": "^11.1.1",
|
|
67
|
+
"@metamask/snaps-rpc-methods": "^17.0.0",
|
|
68
68
|
"@metamask/snaps-sdk": "^11.1.1",
|
|
69
|
-
"@metamask/snaps-utils": "^12.2.
|
|
69
|
+
"@metamask/snaps-utils": "^12.2.1",
|
|
70
70
|
"@metamask/superstruct": "^3.2.1",
|
|
71
71
|
"@metamask/utils": "^11.11.0",
|
|
72
72
|
"@reduxjs/toolkit": "^1.9.5",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@lavamoat/allow-scripts": "^4.0.0",
|
|
82
|
-
"@metamask/auto-changelog": "^6.1.
|
|
82
|
+
"@metamask/auto-changelog": "^6.1.1",
|
|
83
83
|
"@ts-bridge/cli": "^0.6.1",
|
|
84
84
|
"@types/express": "^5.0.1",
|
|
85
85
|
"@types/jest": "^27.5.1",
|