@metamask/snaps-simulation 3.4.1 → 3.5.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/helpers.cjs +28 -9
  3. package/dist/helpers.cjs.map +1 -1
  4. package/dist/helpers.d.cts +61 -0
  5. package/dist/helpers.d.cts.map +1 -1
  6. package/dist/helpers.d.mts +61 -0
  7. package/dist/helpers.d.mts.map +1 -1
  8. package/dist/helpers.mjs +29 -9
  9. package/dist/helpers.mjs.map +1 -1
  10. package/dist/middleware/mock.cjs +16 -7
  11. package/dist/middleware/mock.cjs.map +1 -1
  12. package/dist/middleware/mock.d.cts +1 -1
  13. package/dist/middleware/mock.d.cts.map +1 -1
  14. package/dist/middleware/mock.d.mts +1 -1
  15. package/dist/middleware/mock.d.mts.map +1 -1
  16. package/dist/middleware/mock.mjs +17 -8
  17. package/dist/middleware/mock.mjs.map +1 -1
  18. package/dist/request.cjs +1 -1
  19. package/dist/request.cjs.map +1 -1
  20. package/dist/request.mjs +1 -1
  21. package/dist/request.mjs.map +1 -1
  22. package/dist/simulation.cjs +3 -2
  23. package/dist/simulation.cjs.map +1 -1
  24. package/dist/simulation.d.cts +9 -2
  25. package/dist/simulation.d.cts.map +1 -1
  26. package/dist/simulation.d.mts +9 -2
  27. package/dist/simulation.d.mts.map +1 -1
  28. package/dist/simulation.mjs +3 -2
  29. package/dist/simulation.mjs.map +1 -1
  30. package/dist/store/mocks.cjs +5 -8
  31. package/dist/store/mocks.cjs.map +1 -1
  32. package/dist/store/mocks.d.cts +6 -19
  33. package/dist/store/mocks.d.cts.map +1 -1
  34. package/dist/store/mocks.d.mts +6 -19
  35. package/dist/store/mocks.d.mts.map +1 -1
  36. package/dist/store/mocks.mjs +5 -8
  37. package/dist/store/mocks.mjs.map +1 -1
  38. package/dist/store/store.cjs +1 -1
  39. package/dist/store/store.cjs.map +1 -1
  40. package/dist/store/store.d.cts.map +1 -1
  41. package/dist/store/store.d.mts.map +1 -1
  42. package/dist/store/store.mjs +1 -1
  43. package/dist/store/store.mjs.map +1 -1
  44. package/dist/structs.d.cts +3 -3
  45. package/dist/structs.d.mts +3 -3
  46. package/dist/types.cjs.map +1 -1
  47. package/dist/types.d.cts +70 -2
  48. package/dist/types.d.cts.map +1 -1
  49. package/dist/types.d.mts +70 -2
  50. package/dist/types.d.mts.map +1 -1
  51. package/dist/types.mjs.map +1 -1
  52. package/package.json +11 -11
@@ -1 +1 @@
1
- {"version":3,"file":"simulation.mjs","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,kCAAkC;AACtD,OAAO,EAAE,kBAAkB,EAAE,6CAA6C;AAE1E,OAAO,EAAE,0BAA0B,EAAE,sCAAsC;AAE3E,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,0BAA0B,EAC1B,cAAc,EACf,yCAAyC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,oCAAoC;AAcpE,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,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,8CAA8C,EAC9C,4CAA4C,EAC5C,+CAA+C,EAC/C,kCAAkC,EAClC,4BAA4B,EAC5B,wBAAwB,EACxB,2BAA2B,EAC3B,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC5B,kCAAwB;AACzB,OAAO,EAAE,gCAAgC,EAAE,8CAA0C;AACrF,OAAO,EAAE,mBAAmB,EAAE,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B,CACvC,+BAA+B,EAC/B,CAAC,IAAI,EAAE,EAAE;QACP;;;;;WAKG;QACH,QAAQ,CAAC,CAAC,uBAAuB;YAC/B,MAAM,gBAAgB,GAAc,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;YACtE,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAED,MAAM,gBAAgB,GAA0B,OAAO,CACrD,uBAAuB,CACxB,CAAC,MAAM,EAAE,CAAC;QACX,OAAO,CACL,gBAAgB,EAAE,IAAI,KAAK,qBAAqB,CAAC,OAAO;YACxD,gBAAgB,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,CAClC,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,kCAAkC,EAClC,KAAK,EAAE,GAAW,EAAE,KAAc,EAAE,EAAE;QACpC,MAAM,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;QAElD,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport { Messenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { PhishingDetectorResultType } from '@metamask/phishing-controller';\nimport type { AbstractExecutionService } 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 AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n InterfaceContext,\n SnapId,\n EntropySource,\n TraceRequest,\n EndTraceRequest,\n TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles, Snap } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { CaipAssetType, 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 getPermittedClearSnapStateMethodImplementation,\n getPermittedGetSnapStateMethodImplementation,\n getPermittedUpdateSnapStateMethodImplementation,\n getGetEntropySourcesImplementation,\n getGetMnemonicImplementation,\n getGetSnapImplementation,\n getTrackEventImplementation,\n getTrackErrorImplementation,\n getEndTraceImplementation,\n getStartTraceImplementation,\n} from './methods/hooks';\nimport { getGetMnemonicSeedImplementation } from './methods/hooks/get-mnemonic-seed';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { Interface, RunSagaFunction, Store } 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 AbstractExecutionService<unknown>>[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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService<unknown>>,\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 AbstractExecutionService>;\n controllerMessenger: Messenger<ActionConstraint, EventConstraint>;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the mnemonic from.\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * A hook that returns the seed derived from the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the seed from.\n * @returns The seed.\n */\n getMnemonicSeed: (source?: string | undefined) => 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\nexport type PermittedMiddlewareHooks = {\n /**\n * A hook that gets whether the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * A hook that returns the entropy sources available to the Snap.\n *\n * @returns The entropy sources available to the Snap.\n */\n getEntropySources: () => EntropySource[];\n\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 locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\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 Snap's auxiliary file for the given path. This hook\n * is bound to the Snap ID.\n *\n * @param path - The path of the auxiliary file to get.\n * @param encoding - The encoding to use when returning the file.\n * @returns The Snap's auxiliary file for the given path.\n */\n getSnapFile: (\n path: string,\n encoding: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n\n /**\n * A hook that gets the state of the Snap. This hook is bound to the Snap ID.\n *\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * A hook that updates the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n */\n updateSnapState: (\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n\n /**\n * A hook that clears the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n */\n clearSnapState: (encrypted: boolean) => Promise<void>;\n\n /**\n * A hook that creates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param content - The content of the interface.\n * @param context - The context of the interface.\n * @returns The ID of the created interface.\n */\n createInterface: (\n content: Component,\n context?: InterfaceContext,\n ) => Promise<string>;\n\n /**\n * A hook that updates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to update.\n * @param content - The content of the interface.\n */\n updateInterface: (id: string, content: Component) => Promise<void>;\n\n /**\n * A hook that gets the state of an interface for the Snap. This hook is bound\n * to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The state of the interface.\n */\n getInterfaceState: (id: string) => InterfaceState;\n\n /**\n * A hook that gets the context of an interface for the Snap. This hook is\n * bound to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The context of the interface.\n */\n getInterfaceContext: (id: string) => InterfaceContext | null;\n\n /**\n * A hook that resolves an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to resolve.\n * @param value - The value to resolve the interface with.\n */\n resolveInterface: (id: string, value: Json) => Promise<void>;\n\n /**\n * A hook that gets the Snap's metadata.\n *\n * @param snapId - The ID of the Snap to get.\n * @returns The Snap's metadata.\n */\n getSnap(snapId: string): Snap;\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/**\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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<any, any>();\n\n registerActions(controllerMessenger, runSaga, options, snapId);\n\n // Set up controllers and JSON-RPC stack.\n const restrictedHooks = getRestrictedHooks(options);\n const permittedHooks = getPermittedHooks(\n snapId,\n snapFiles,\n controllerMessenger,\n runSaga,\n );\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks: restrictedHooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n restrictedHooks,\n permittedHooks,\n permissionMiddleware: permissionController.createPermissionMiddleware({\n origin: snapId,\n }),\n });\n\n // Create execution service.\n const ExecutionService = executionService ?? NodeThreadExecutionService;\n const service = new ExecutionService({\n ...executionServiceOptions,\n messenger: controllerMessenger.getRestricted({\n name: 'ExecutionService',\n allowedActions: [],\n allowedEvents: [],\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 });\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 * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n options: SimulationOptions,\n): RestrictedMiddlewareHooks {\n return {\n getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n getMnemonicSeed: getGetMnemonicSeedImplementation(\n options.secretRecoveryPhrase,\n ),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\n };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param snapId - The ID of the Snap.\n * @param snapFiles - The fetched Snap files.\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n snapId: SnapId,\n snapFiles: FetchedSnapFiles,\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n return {\n hasPermission: () => true,\n getUnlockPromise: asyncResolve(),\n getIsLocked: () => false,\n getIsActive: () => true,\n\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n\n createInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n ...args,\n ),\n updateInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterface',\n snapId,\n ...args,\n ),\n getInterfaceState: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).state,\n getInterfaceContext: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).context,\n resolveInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:resolveInterface',\n snapId,\n ...args,\n ),\n\n getEntropySources: getGetEntropySourcesImplementation(),\n getSnapState: getPermittedGetSnapStateMethodImplementation(runSaga),\n updateSnapState: getPermittedUpdateSnapStateMethodImplementation(runSaga),\n clearSnapState: getPermittedClearSnapStateMethodImplementation(runSaga),\n\n getSnap: getGetSnapImplementation(true),\n trackError: getTrackErrorImplementation(runSaga),\n trackEvent: getTrackEventImplementation(runSaga),\n startTrace: getStartTraceImplementation(runSaga),\n endTrace: getEndTraceImplementation(runSaga),\n };\n}\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 */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n snapId: SnapId,\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: PhishingDetectorResultType.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"]}
1
+ {"version":3,"file":"simulation.mjs","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,kCAAkC;AACtD,OAAO,EAAE,kBAAkB,EAAE,6CAA6C;AAE1E,OAAO,EAAE,0BAA0B,EAAE,sCAAsC;AAE3E,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,0BAA0B,EAC1B,cAAc,EACf,yCAAyC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,oCAAoC;AAcpE,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,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,8CAA8C,EAC9C,4CAA4C,EAC5C,+CAA+C,EAC/C,kCAAkC,EAClC,4BAA4B,EAC5B,wBAAwB,EACxB,2BAA2B,EAC3B,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC5B,kCAAwB;AACzB,OAAO,EAAE,gCAAgC,EAAE,8CAA0C;AACrF,OAAO,EAAE,mBAAmB,EAAE,+BAAqB;AAEnD,OAAO,EAAE,UAAU,EAAE,sBAAkB;AAEvC,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,0BAAgB;AAC3D,OAAO,EAAE,wBAAwB,EAAE,4BA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AAM,gBAAgB,GAAc,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;YACtE,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAED,MAAM,gBAAgB,GAA0B,OAAO,CACrD,uBAAuB,CACxB,CAAC,MAAM,EAAE,CAAC;QACX,OAAO,CACL,gBAAgB,EAAE,IAAI,KAAK,qBAAqB,CAAC,OAAO;YACxD,gBAAgB,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,CAClC,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,kCAAkC,EAClC,KAAK,EAAE,GAAW,EAAE,KAAc,EAAE,EAAE;QACpC,MAAM,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;QAElD,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport { Messenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { PhishingDetectorResultType } from '@metamask/phishing-controller';\nimport type { AbstractExecutionService } 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 AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n InterfaceContext,\n SnapId,\n EntropySource,\n TraceRequest,\n EndTraceRequest,\n TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles, Snap } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { CaipAssetType, 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 getPermittedClearSnapStateMethodImplementation,\n getPermittedGetSnapStateMethodImplementation,\n getPermittedUpdateSnapStateMethodImplementation,\n getGetEntropySourcesImplementation,\n getGetMnemonicImplementation,\n getGetSnapImplementation,\n getTrackEventImplementation,\n getTrackErrorImplementation,\n getEndTraceImplementation,\n getStartTraceImplementation,\n} from './methods/hooks';\nimport { getGetMnemonicSeedImplementation } from './methods/hooks/get-mnemonic-seed';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { Interface, RunSagaFunction, Store } 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 AbstractExecutionService<unknown>>[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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService<unknown>>,\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 AbstractExecutionService>;\n controllerMessenger: Messenger<ActionConstraint, EventConstraint>;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the mnemonic from.\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * A hook that returns the seed derived from the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the seed from.\n * @returns The seed.\n */\n getMnemonicSeed: (source?: string | undefined) => 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\nexport type PermittedMiddlewareHooks = {\n /**\n * A hook that gets whether the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * A hook that returns the entropy sources available to the Snap.\n *\n * @returns The entropy sources available to the Snap.\n */\n getEntropySources: () => EntropySource[];\n\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 locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\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 Snap's auxiliary file for the given path. This hook\n * is bound to the Snap ID.\n *\n * @param path - The path of the auxiliary file to get.\n * @param encoding - The encoding to use when returning the file.\n * @returns The Snap's auxiliary file for the given path.\n */\n getSnapFile: (\n path: string,\n encoding: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n\n /**\n * A hook that gets the state of the Snap. This hook is bound to the Snap ID.\n *\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * A hook that updates the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n */\n updateSnapState: (\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n\n /**\n * A hook that clears the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n */\n clearSnapState: (encrypted: boolean) => Promise<void>;\n\n /**\n * A hook that creates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param content - The content of the interface.\n * @param context - The context of the interface.\n * @returns The ID of the created interface.\n */\n createInterface: (content: Component, context?: InterfaceContext) => string;\n\n /**\n * A hook that updates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to update.\n * @param content - The content of the interface.\n */\n updateInterface: (id: string, content: Component) => void;\n\n /**\n * A hook that gets the state of an interface for the Snap. This hook is bound\n * to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The state of the interface.\n */\n getInterfaceState: (id: string) => InterfaceState;\n\n /**\n * A hook that gets the context of an interface for the Snap. This hook is\n * bound to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The context of the interface.\n */\n getInterfaceContext: (id: string) => InterfaceContext | null;\n\n /**\n * A hook that resolves an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to resolve.\n * @param value - The value to resolve the interface with.\n */\n resolveInterface: (id: string, value: Json) => Promise<void>;\n\n /**\n * A hook that gets the Snap's metadata.\n *\n * @param snapId - The ID of the Snap to get.\n * @returns The Snap's metadata.\n */\n getSnap(snapId: string): Snap;\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/**\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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<any, any>();\n\n registerActions(controllerMessenger, runSaga, options, snapId);\n\n // Set up controllers and JSON-RPC stack.\n const restrictedHooks = getRestrictedHooks(options);\n const permittedHooks = getPermittedHooks(\n snapId,\n snapFiles,\n controllerMessenger,\n runSaga,\n );\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks: restrictedHooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n restrictedHooks,\n permittedHooks,\n permissionMiddleware: permissionController.createPermissionMiddleware({\n origin: snapId,\n }),\n });\n\n // Create execution service.\n const ExecutionService = executionService ?? NodeThreadExecutionService;\n const service = new ExecutionService({\n ...executionServiceOptions,\n messenger: controllerMessenger.getRestricted({\n name: 'ExecutionService',\n allowedActions: [],\n allowedEvents: [],\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 });\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 * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n options: SimulationOptions,\n): RestrictedMiddlewareHooks {\n return {\n getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n getMnemonicSeed: getGetMnemonicSeedImplementation(\n options.secretRecoveryPhrase,\n ),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\n getSnap: getGetSnapImplementation(true),\n };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param snapId - The ID of the Snap.\n * @param snapFiles - The fetched Snap files.\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n snapId: SnapId,\n snapFiles: FetchedSnapFiles,\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n return {\n hasPermission: () => true,\n getUnlockPromise: asyncResolve(),\n getIsLocked: () => false,\n getIsActive: () => true,\n\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n\n createInterface: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n ...args,\n ),\n updateInterface: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterface',\n snapId,\n ...args,\n ),\n getInterfaceState: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).state,\n getInterfaceContext: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).context,\n resolveInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:resolveInterface',\n snapId,\n ...args,\n ),\n\n getEntropySources: getGetEntropySourcesImplementation(),\n getSnapState: getPermittedGetSnapStateMethodImplementation(runSaga),\n updateSnapState: getPermittedUpdateSnapStateMethodImplementation(runSaga),\n clearSnapState: getPermittedClearSnapStateMethodImplementation(runSaga),\n\n getSnap: getGetSnapImplementation(true),\n trackError: getTrackErrorImplementation(runSaga),\n trackEvent: getTrackEventImplementation(runSaga),\n startTrace: getStartTraceImplementation(runSaga),\n endTrace: getEndTraceImplementation(runSaga),\n };\n}\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 */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n snapId: SnapId,\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: PhishingDetectorResultType.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"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getJsonRpcMock = exports.getJsonRpcMocks = exports.removeJsonRpcMock = exports.addJsonRpcMock = exports.mocksSlice = void 0;
4
+ exports.getJsonRpcMocks = exports.removeJsonRpcMock = exports.addJsonRpcMock = exports.mocksSlice = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  /**
7
7
  * The initial notifications state.
@@ -14,9 +14,10 @@ exports.mocksSlice = (0, toolkit_1.createSlice)({
14
14
  initialState: INITIAL_STATE,
15
15
  reducers: {
16
16
  addJsonRpcMock: (state, action) => {
17
- // @ts-expect-error - TS2589: Type instantiation is excessively deep and
18
- // possibly infinite.
19
- state.jsonRpc[action.payload.method] = action.payload.result;
17
+ state.jsonRpc[action.payload.id] = {
18
+ implementation: action.payload.implementation,
19
+ once: action.payload.once,
20
+ };
20
21
  },
21
22
  removeJsonRpcMock: (state, action) => {
22
23
  delete state.jsonRpc[action.payload];
@@ -32,8 +33,4 @@ _a = exports.mocksSlice.actions, exports.addJsonRpcMock = _a.addJsonRpcMock, exp
32
33
  */
33
34
  const getJsonRpcMocks = (state) => state.mocks.jsonRpc;
34
35
  exports.getJsonRpcMocks = getJsonRpcMocks;
35
- /**
36
- * Get the JSON-RPC mock for a given method from the state.
37
- */
38
- exports.getJsonRpcMock = (0, toolkit_1.createSelector)(exports.getJsonRpcMocks, (_, method) => method, (jsonRpcMocks, method) => jsonRpcMocks[method]);
39
36
  //# sourceMappingURL=mocks.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"mocks.cjs","sourceRoot":"","sources":["../../src/store/mocks.ts"],"names":[],"mappings":";;;;AAEA,8CAA+D;AAa/D;;GAEG;AACH,MAAM,aAAa,GAAe;IAChC,OAAO,EAAE,EAAE;CACZ,CAAC;AAEW,QAAA,UAAU,GAAG,IAAA,qBAAW,EAAC;IACpC,IAAI,EAAE,OAAO;IACb,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,cAAc,EAAE,CAAC,KAAK,EAAE,MAAkC,EAAE,EAAE;YAC5D,wEAAwE;YACxE,qBAAqB;YACrB,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAC/D,CAAC;QACD,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAA6B,EAAE,EAAE;YAC1D,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC;KACF;CACF,CAAC,CAAC;AAEU,KAAwC,kBAAU,CAAC,OAAO,EAAxD,sBAAc,sBAAE,yBAAiB,wBAAwB;AAExE;;;;;GAKG;AACI,MAAM,eAAe,GAAG,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;AAAnE,QAAA,eAAe,mBAAoD;AAEhF;;GAEG;AACU,QAAA,cAAc,GAAG,IAAA,wBAAc,EAC1C,uBAAe,EACf,CAAC,CAAU,EAAE,MAAc,EAAE,EAAE,CAAC,MAAM,EACtC,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAC/C,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\nexport type JsonRpcMock = {\n method: string;\n result: Json;\n};\n\nexport type MocksState = {\n jsonRpc: Record<string, Json>;\n};\n\n/**\n * The initial notifications state.\n */\nconst INITIAL_STATE: MocksState = {\n jsonRpc: {},\n};\n\nexport const mocksSlice = createSlice({\n name: 'mocks',\n initialState: INITIAL_STATE,\n reducers: {\n addJsonRpcMock: (state, action: PayloadAction<JsonRpcMock>) => {\n // @ts-expect-error - TS2589: Type instantiation is excessively deep and\n // possibly infinite.\n state.jsonRpc[action.payload.method] = action.payload.result;\n },\n removeJsonRpcMock: (state, action: PayloadAction<string>) => {\n delete state.jsonRpc[action.payload];\n },\n },\n});\n\nexport const { addJsonRpcMock, removeJsonRpcMock } = mocksSlice.actions;\n\n/**\n * Get the JSON-RPC mocks from the state.\n *\n * @param state - The application state.\n * @returns The JSON-RPC mocks.\n */\nexport const getJsonRpcMocks = (state: ApplicationState) => state.mocks.jsonRpc;\n\n/**\n * Get the JSON-RPC mock for a given method from the state.\n */\nexport const getJsonRpcMock = createSelector(\n getJsonRpcMocks,\n (_: unknown, method: string) => method,\n (jsonRpcMocks, method) => jsonRpcMocks[method],\n);\n"]}
1
+ {"version":3,"file":"mocks.cjs","sourceRoot":"","sources":["../../src/store/mocks.ts"],"names":[],"mappings":";;;;AACA,8CAA+C;AAe/C;;GAEG;AACH,MAAM,aAAa,GAAe;IAChC,OAAO,EAAE,EAAE;CACZ,CAAC;AAEW,QAAA,UAAU,GAAG,IAAA,qBAAW,EAAC;IACpC,IAAI,EAAE,OAAO;IACb,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,cAAc,EAAE,CAAC,KAAK,EAAE,MAAkC,EAAE,EAAE;YAC5D,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG;gBACjC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,cAAc;gBAC7C,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI;aAC1B,CAAC;QACJ,CAAC;QACD,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAA6B,EAAE,EAAE;YAC1D,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC;KACF;CACF,CAAC,CAAC;AAEU,KAAwC,kBAAU,CAAC,OAAO,EAAxD,sBAAc,sBAAE,yBAAiB,wBAAwB;AAExE;;;;;GAKG;AACI,MAAM,eAAe,GAAG,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;AAAnE,QAAA,eAAe,mBAAoD","sourcesContent":["import type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\nimport type { JsonRpcMockImplementation } from '../types';\n\nexport type JsonRpcMock = {\n id: string;\n implementation: JsonRpcMockImplementation;\n once?: boolean;\n};\n\nexport type MocksState = {\n jsonRpc: Record<string, Omit<JsonRpcMock, 'id'>>;\n};\n\n/**\n * The initial notifications state.\n */\nconst INITIAL_STATE: MocksState = {\n jsonRpc: {},\n};\n\nexport const mocksSlice = createSlice({\n name: 'mocks',\n initialState: INITIAL_STATE,\n reducers: {\n addJsonRpcMock: (state, action: PayloadAction<JsonRpcMock>) => {\n state.jsonRpc[action.payload.id] = {\n implementation: action.payload.implementation,\n once: action.payload.once,\n };\n },\n removeJsonRpcMock: (state, action: PayloadAction<string>) => {\n delete state.jsonRpc[action.payload];\n },\n },\n});\n\nexport const { addJsonRpcMock, removeJsonRpcMock } = mocksSlice.actions;\n\n/**\n * Get the JSON-RPC mocks from the state.\n *\n * @param state - The application state.\n * @returns The JSON-RPC mocks.\n */\nexport const getJsonRpcMocks = (state: ApplicationState) => state.mocks.jsonRpc;\n"]}
@@ -1,12 +1,13 @@
1
- import type { Json } from "@metamask/utils";
2
1
  import type { PayloadAction } from "@reduxjs/toolkit";
3
2
  import type { ApplicationState } from "./store.cjs";
3
+ import type { JsonRpcMockImplementation } from "../types.cjs";
4
4
  export type JsonRpcMock = {
5
- method: string;
6
- result: Json;
5
+ id: string;
6
+ implementation: JsonRpcMockImplementation;
7
+ once?: boolean;
7
8
  };
8
9
  export type MocksState = {
9
- jsonRpc: Record<string, Json>;
10
+ jsonRpc: Record<string, Omit<JsonRpcMock, 'id'>>;
10
11
  };
11
12
  export declare const mocksSlice: import("@reduxjs/toolkit").Slice<MocksState, {
12
13
  addJsonRpcMock: (state: import("immer/dist/internal.js").WritableDraft<MocksState>, action: PayloadAction<JsonRpcMock>) => void;
@@ -19,19 +20,5 @@ export declare const addJsonRpcMock: import("@reduxjs/toolkit").ActionCreatorWit
19
20
  * @param state - The application state.
20
21
  * @returns The JSON-RPC mocks.
21
22
  */
22
- export declare const getJsonRpcMocks: (state: ApplicationState) => Record<string, Json>;
23
- /**
24
- * Get the JSON-RPC mock for a given method from the state.
25
- */
26
- export declare const getJsonRpcMock: ((state: {
27
- mocks: MocksState;
28
- notifications: import("./notifications.cjs").NotificationsState;
29
- state: import("./state.cjs").State;
30
- trackables: import("./trackables.cjs").TrackablesState;
31
- ui: import("./ui.cjs").UiState;
32
- }, method: string) => Json) & import("reselect").OutputSelectorFields<(args_0: Record<string, Json>, args_1: string) => Json, {
33
- clearCache: () => void;
34
- }> & {
35
- clearCache: () => void;
36
- };
23
+ export declare const getJsonRpcMocks: (state: ApplicationState) => Record<string, Omit<JsonRpcMock, "id">>;
37
24
  //# sourceMappingURL=mocks.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mocks.d.cts","sourceRoot":"","sources":["../../src/store/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAgB;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,IAAI,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC/B,CAAC;AASF,eAAO,MAAM,UAAU;gGAIa,cAAc,WAAW,CAAC;mGAKvB,cAAc,MAAM,CAAC;WAI1D,CAAC;AAEH,eAAO,MAAQ,cAAc,4FAAE,iBAAiB,wFAAuB,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,gBAAgB,yBAAwB,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;CAI1B,CAAC"}
1
+ {"version":3,"file":"mocks.d.cts","sourceRoot":"","sources":["../../src/store/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAgB;AAChD,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAiB;AAE1D,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,yBAAyB,CAAC;IAC1C,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;CAClD,CAAC;AASF,eAAO,MAAM,UAAU;gGAIa,cAAc,WAAW,CAAC;mGAMvB,cAAc,MAAM,CAAC;WAI1D,CAAC;AAEH,eAAO,MAAQ,cAAc,4FAAE,iBAAiB,wFAAuB,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,gBAAgB,4CAAwB,CAAC"}
@@ -1,12 +1,13 @@
1
- import type { Json } from "@metamask/utils";
2
1
  import type { PayloadAction } from "@reduxjs/toolkit";
3
2
  import type { ApplicationState } from "./store.mjs";
3
+ import type { JsonRpcMockImplementation } from "../types.mjs";
4
4
  export type JsonRpcMock = {
5
- method: string;
6
- result: Json;
5
+ id: string;
6
+ implementation: JsonRpcMockImplementation;
7
+ once?: boolean;
7
8
  };
8
9
  export type MocksState = {
9
- jsonRpc: Record<string, Json>;
10
+ jsonRpc: Record<string, Omit<JsonRpcMock, 'id'>>;
10
11
  };
11
12
  export declare const mocksSlice: import("@reduxjs/toolkit").Slice<MocksState, {
12
13
  addJsonRpcMock: (state: import("immer/dist/internal.js").WritableDraft<MocksState>, action: PayloadAction<JsonRpcMock>) => void;
@@ -19,19 +20,5 @@ export declare const addJsonRpcMock: import("@reduxjs/toolkit").ActionCreatorWit
19
20
  * @param state - The application state.
20
21
  * @returns The JSON-RPC mocks.
21
22
  */
22
- export declare const getJsonRpcMocks: (state: ApplicationState) => Record<string, Json>;
23
- /**
24
- * Get the JSON-RPC mock for a given method from the state.
25
- */
26
- export declare const getJsonRpcMock: ((state: {
27
- mocks: MocksState;
28
- notifications: import("./notifications.mjs").NotificationsState;
29
- state: import("./state.mjs").State;
30
- trackables: import("./trackables.mjs").TrackablesState;
31
- ui: import("./ui.mjs").UiState;
32
- }, method: string) => Json) & import("reselect").OutputSelectorFields<(args_0: Record<string, Json>, args_1: string) => Json, {
33
- clearCache: () => void;
34
- }> & {
35
- clearCache: () => void;
36
- };
23
+ export declare const getJsonRpcMocks: (state: ApplicationState) => Record<string, Omit<JsonRpcMock, "id">>;
37
24
  //# sourceMappingURL=mocks.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mocks.d.mts","sourceRoot":"","sources":["../../src/store/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAgB;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,IAAI,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC/B,CAAC;AASF,eAAO,MAAM,UAAU;gGAIa,cAAc,WAAW,CAAC;mGAKvB,cAAc,MAAM,CAAC;WAI1D,CAAC;AAEH,eAAO,MAAQ,cAAc,4FAAE,iBAAiB,wFAAuB,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,gBAAgB,yBAAwB,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;CAI1B,CAAC"}
1
+ {"version":3,"file":"mocks.d.mts","sourceRoot":"","sources":["../../src/store/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAgB;AAChD,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAiB;AAE1D,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,yBAAyB,CAAC;IAC1C,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;CAClD,CAAC;AASF,eAAO,MAAM,UAAU;gGAIa,cAAc,WAAW,CAAC;mGAMvB,cAAc,MAAM,CAAC;WAI1D,CAAC;AAEH,eAAO,MAAQ,cAAc,4FAAE,iBAAiB,wFAAuB,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,gBAAgB,4CAAwB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import $reduxjstoolkit from "@reduxjs/toolkit";
2
- const { createSelector, createSlice } = $reduxjstoolkit;
2
+ const { createSlice } = $reduxjstoolkit;
3
3
  /**
4
4
  * The initial notifications state.
5
5
  */
@@ -11,9 +11,10 @@ export const mocksSlice = createSlice({
11
11
  initialState: INITIAL_STATE,
12
12
  reducers: {
13
13
  addJsonRpcMock: (state, action) => {
14
- // @ts-expect-error - TS2589: Type instantiation is excessively deep and
15
- // possibly infinite.
16
- state.jsonRpc[action.payload.method] = action.payload.result;
14
+ state.jsonRpc[action.payload.id] = {
15
+ implementation: action.payload.implementation,
16
+ once: action.payload.once,
17
+ };
17
18
  },
18
19
  removeJsonRpcMock: (state, action) => {
19
20
  delete state.jsonRpc[action.payload];
@@ -28,8 +29,4 @@ export const { addJsonRpcMock, removeJsonRpcMock } = mocksSlice.actions;
28
29
  * @returns The JSON-RPC mocks.
29
30
  */
30
31
  export const getJsonRpcMocks = (state) => state.mocks.jsonRpc;
31
- /**
32
- * Get the JSON-RPC mock for a given method from the state.
33
- */
34
- export const getJsonRpcMock = createSelector(getJsonRpcMocks, (_, method) => method, (jsonRpcMocks, method) => jsonRpcMocks[method]);
35
32
  //# sourceMappingURL=mocks.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"mocks.mjs","sourceRoot":"","sources":["../../src/store/mocks.ts"],"names":[],"mappings":";;AAeA;;GAEG;AACH,MAAM,aAAa,GAAe;IAChC,OAAO,EAAE,EAAE;CACZ,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC;IACpC,IAAI,EAAE,OAAO;IACb,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,cAAc,EAAE,CAAC,KAAK,EAAE,MAAkC,EAAE,EAAE;YAC5D,wEAAwE;YACxE,qBAAqB;YACrB,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAC/D,CAAC;QACD,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAA6B,EAAE,EAAE;YAC1D,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC;AAExE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;AAEhF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAC1C,eAAe,EACf,CAAC,CAAU,EAAE,MAAc,EAAE,EAAE,CAAC,MAAM,EACtC,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAC/C,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\nexport type JsonRpcMock = {\n method: string;\n result: Json;\n};\n\nexport type MocksState = {\n jsonRpc: Record<string, Json>;\n};\n\n/**\n * The initial notifications state.\n */\nconst INITIAL_STATE: MocksState = {\n jsonRpc: {},\n};\n\nexport const mocksSlice = createSlice({\n name: 'mocks',\n initialState: INITIAL_STATE,\n reducers: {\n addJsonRpcMock: (state, action: PayloadAction<JsonRpcMock>) => {\n // @ts-expect-error - TS2589: Type instantiation is excessively deep and\n // possibly infinite.\n state.jsonRpc[action.payload.method] = action.payload.result;\n },\n removeJsonRpcMock: (state, action: PayloadAction<string>) => {\n delete state.jsonRpc[action.payload];\n },\n },\n});\n\nexport const { addJsonRpcMock, removeJsonRpcMock } = mocksSlice.actions;\n\n/**\n * Get the JSON-RPC mocks from the state.\n *\n * @param state - The application state.\n * @returns The JSON-RPC mocks.\n */\nexport const getJsonRpcMocks = (state: ApplicationState) => state.mocks.jsonRpc;\n\n/**\n * Get the JSON-RPC mock for a given method from the state.\n */\nexport const getJsonRpcMock = createSelector(\n getJsonRpcMocks,\n (_: unknown, method: string) => method,\n (jsonRpcMocks, method) => jsonRpcMocks[method],\n);\n"]}
1
+ {"version":3,"file":"mocks.mjs","sourceRoot":"","sources":["../../src/store/mocks.ts"],"names":[],"mappings":";;AAgBA;;GAEG;AACH,MAAM,aAAa,GAAe;IAChC,OAAO,EAAE,EAAE;CACZ,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC;IACpC,IAAI,EAAE,OAAO;IACb,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,cAAc,EAAE,CAAC,KAAK,EAAE,MAAkC,EAAE,EAAE;YAC5D,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG;gBACjC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,cAAc;gBAC7C,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI;aAC1B,CAAC;QACJ,CAAC;QACD,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAA6B,EAAE,EAAE;YAC1D,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC;AAExE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC","sourcesContent":["import type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\nimport type { JsonRpcMockImplementation } from '../types';\n\nexport type JsonRpcMock = {\n id: string;\n implementation: JsonRpcMockImplementation;\n once?: boolean;\n};\n\nexport type MocksState = {\n jsonRpc: Record<string, Omit<JsonRpcMock, 'id'>>;\n};\n\n/**\n * The initial notifications state.\n */\nconst INITIAL_STATE: MocksState = {\n jsonRpc: {},\n};\n\nexport const mocksSlice = createSlice({\n name: 'mocks',\n initialState: INITIAL_STATE,\n reducers: {\n addJsonRpcMock: (state, action: PayloadAction<JsonRpcMock>) => {\n state.jsonRpc[action.payload.id] = {\n implementation: action.payload.implementation,\n once: action.payload.once,\n };\n },\n removeJsonRpcMock: (state, action: PayloadAction<string>) => {\n delete state.jsonRpc[action.payload];\n },\n },\n});\n\nexport const { addJsonRpcMock, removeJsonRpcMock } = mocksSlice.actions;\n\n/**\n * Get the JSON-RPC mocks from the state.\n *\n * @param state - The application state.\n * @returns The JSON-RPC mocks.\n */\nexport const getJsonRpcMocks = (state: ApplicationState) => state.mocks.jsonRpc;\n"]}
@@ -29,7 +29,7 @@ function createStore({ state, unencryptedState }) {
29
29
  trackables: trackables_1.trackablesSlice.reducer,
30
30
  ui: ui_1.uiSlice.reducer,
31
31
  },
32
- middleware: (getDefaultMiddleware) => getDefaultMiddleware({ thunk: false }).concat(sagaMiddleware),
32
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware({ thunk: false, serializableCheck: false }).concat(sagaMiddleware),
33
33
  });
34
34
  // Set initial state for the Snap.
35
35
  if (state) {
@@ -1 +1 @@
1
- {"version":3,"file":"store.cjs","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAkD;AAClD,4DAA8C;AAE9C,uCAAqC;AACrC,uDAAqD;AACrD,uCAA+C;AAC/C,iDAA+C;AAC/C,iCAA+B;AAG/B;;;;;;;GAOG;AACH,SAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAqB;IACxE,MAAM,cAAc,GAAG,IAAA,oBAAoB,GAAE,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAA,wBAAc,EAAC;QAC3B,OAAO,EAAE;YACP,KAAK,EAAE,kBAAU,CAAC,OAAO;YACzB,aAAa,EAAE,kCAAkB,CAAC,OAAO;YACzC,KAAK,EAAE,kBAAU,CAAC,OAAO;YACzB,UAAU,EAAE,4BAAe,CAAC,OAAO;YACnC,EAAE,EAAE,YAAO,CAAC,OAAO;SACpB;QACD,UAAU,EAAE,CAAC,oBAAoB,EAAE,EAAE,CACnC,oBAAoB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;KAChE,CAAC,CAAC;IAEH,kCAAkC;IAClC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,QAAQ,CACZ,IAAA,gBAAQ,EAAC;YACP,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC5B,SAAS,EAAE,IAAI;SAChB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,KAAK,CAAC,QAAQ,CACZ,IAAA,gBAAQ,EAAC;YACP,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;YACvC,SAAS,EAAE,KAAK;SACjB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK;QACL,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC;KACjD,CAAC;AACJ,CAAC;AArCD,kCAqCC","sourcesContent":["import { configureStore } from '@reduxjs/toolkit';\nimport createSagaMiddleware from 'redux-saga';\n\nimport { mocksSlice } from './mocks';\nimport { notificationsSlice } from './notifications';\nimport { setState, stateSlice } from './state';\nimport { trackablesSlice } from './trackables';\nimport { uiSlice } from './ui';\nimport type { SimulationOptions } from '../options';\n\n/**\n * Create a Redux store.\n *\n * @param options - The simulation options.\n * @param options.state - The initial state for the Snap.\n * @param options.unencryptedState - The initial unencrypted state for the Snap.\n * @returns A Redux store with the default state.\n */\nexport function createStore({ state, unencryptedState }: SimulationOptions) {\n const sagaMiddleware = createSagaMiddleware();\n const store = configureStore({\n reducer: {\n mocks: mocksSlice.reducer,\n notifications: notificationsSlice.reducer,\n state: stateSlice.reducer,\n trackables: trackablesSlice.reducer,\n ui: uiSlice.reducer,\n },\n middleware: (getDefaultMiddleware) =>\n getDefaultMiddleware({ thunk: false }).concat(sagaMiddleware),\n });\n\n // Set initial state for the Snap.\n if (state) {\n store.dispatch(\n setState({\n state: JSON.stringify(state),\n encrypted: true,\n }),\n );\n }\n\n if (unencryptedState) {\n store.dispatch(\n setState({\n state: JSON.stringify(unencryptedState),\n encrypted: false,\n }),\n );\n }\n\n return {\n store,\n runSaga: sagaMiddleware.run.bind(sagaMiddleware),\n };\n}\n\nexport type Store = ReturnType<typeof createStore>['store'];\nexport type ApplicationState = ReturnType<Store['getState']>;\nexport type RunSagaFunction = ReturnType<typeof createStore>['runSaga'];\n"]}
1
+ {"version":3,"file":"store.cjs","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAkD;AAClD,4DAA8C;AAE9C,uCAAqC;AACrC,uDAAqD;AACrD,uCAA+C;AAC/C,iDAA+C;AAC/C,iCAA+B;AAG/B;;;;;;;GAOG;AACH,SAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAqB;IACxE,MAAM,cAAc,GAAG,IAAA,oBAAoB,GAAE,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAA,wBAAc,EAAC;QAC3B,OAAO,EAAE;YACP,KAAK,EAAE,kBAAU,CAAC,OAAO;YACzB,aAAa,EAAE,kCAAkB,CAAC,OAAO;YACzC,KAAK,EAAE,kBAAU,CAAC,OAAO;YACzB,UAAU,EAAE,4BAAe,CAAC,OAAO;YACnC,EAAE,EAAE,YAAO,CAAC,OAAO;SACpB;QACD,UAAU,EAAE,CAAC,oBAAoB,EAAE,EAAE,CACnC,oBAAoB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CACrE,cAAc,CACf;KACJ,CAAC,CAAC;IAEH,kCAAkC;IAClC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,QAAQ,CACZ,IAAA,gBAAQ,EAAC;YACP,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC5B,SAAS,EAAE,IAAI;SAChB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,KAAK,CAAC,QAAQ,CACZ,IAAA,gBAAQ,EAAC;YACP,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;YACvC,SAAS,EAAE,KAAK;SACjB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK;QACL,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC;KACjD,CAAC;AACJ,CAAC;AAvCD,kCAuCC","sourcesContent":["import { configureStore } from '@reduxjs/toolkit';\nimport createSagaMiddleware from 'redux-saga';\n\nimport { mocksSlice } from './mocks';\nimport { notificationsSlice } from './notifications';\nimport { setState, stateSlice } from './state';\nimport { trackablesSlice } from './trackables';\nimport { uiSlice } from './ui';\nimport type { SimulationOptions } from '../options';\n\n/**\n * Create a Redux store.\n *\n * @param options - The simulation options.\n * @param options.state - The initial state for the Snap.\n * @param options.unencryptedState - The initial unencrypted state for the Snap.\n * @returns A Redux store with the default state.\n */\nexport function createStore({ state, unencryptedState }: SimulationOptions) {\n const sagaMiddleware = createSagaMiddleware();\n const store = configureStore({\n reducer: {\n mocks: mocksSlice.reducer,\n notifications: notificationsSlice.reducer,\n state: stateSlice.reducer,\n trackables: trackablesSlice.reducer,\n ui: uiSlice.reducer,\n },\n middleware: (getDefaultMiddleware) =>\n getDefaultMiddleware({ thunk: false, serializableCheck: false }).concat(\n sagaMiddleware,\n ),\n });\n\n // Set initial state for the Snap.\n if (state) {\n store.dispatch(\n setState({\n state: JSON.stringify(state),\n encrypted: true,\n }),\n );\n }\n\n if (unencryptedState) {\n store.dispatch(\n setState({\n state: JSON.stringify(unencryptedState),\n encrypted: false,\n }),\n );\n }\n\n return {\n store,\n runSaga: sagaMiddleware.run.bind(sagaMiddleware),\n };\n}\n\nexport type Store = ReturnType<typeof createStore>['store'];\nexport type ApplicationState = ReturnType<Store['getState']>;\nexport type RunSagaFunction = ReturnType<typeof createStore>['runSaga'];\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.cts","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAmB;AAEpD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,iBAAiB;;;;;;;;;EAqCzE;AAED,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC;AAC5D,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC"}
1
+ {"version":3,"file":"store.d.cts","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAmB;AAEpD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,iBAAiB;;;;;;;;;EAuCzE;AAED,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC;AAC5D,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.mts","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAmB;AAEpD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,iBAAiB;;;;;;;;;EAqCzE;AAED,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC;AAC5D,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC"}
1
+ {"version":3,"file":"store.d.mts","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAmB;AAEpD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,iBAAiB;;;;;;;;;EAuCzE;AAED,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC;AAC5D,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC"}
@@ -24,7 +24,7 @@ export function createStore({ state, unencryptedState }) {
24
24
  trackables: trackablesSlice.reducer,
25
25
  ui: uiSlice.reducer,
26
26
  },
27
- middleware: (getDefaultMiddleware) => getDefaultMiddleware({ thunk: false }).concat(sagaMiddleware),
27
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware({ thunk: false, serializableCheck: false }).concat(sagaMiddleware),
28
28
  });
29
29
  // Set initial state for the Snap.
30
30
  if (state) {
@@ -1 +1 @@
1
- {"version":3,"file":"store.mjs","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":";;AACA,OAAO,oBAAoB,mBAAmB;AAE9C,OAAO,EAAE,UAAU,EAAE,oBAAgB;AACrC,OAAO,EAAE,kBAAkB,EAAE,4BAAwB;AACrD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,oBAAgB;AAC/C,OAAO,EAAE,eAAe,EAAE,yBAAqB;AAC/C,OAAO,EAAE,OAAO,EAAE,iBAAa;AAG/B;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAqB;IACxE,MAAM,cAAc,GAAG,oBAAoB,EAAE,CAAC;IAC9C,MAAM,KAAK,GAAG,cAAc,CAAC;QAC3B,OAAO,EAAE;YACP,KAAK,EAAE,UAAU,CAAC,OAAO;YACzB,aAAa,EAAE,kBAAkB,CAAC,OAAO;YACzC,KAAK,EAAE,UAAU,CAAC,OAAO;YACzB,UAAU,EAAE,eAAe,CAAC,OAAO;YACnC,EAAE,EAAE,OAAO,CAAC,OAAO;SACpB;QACD,UAAU,EAAE,CAAC,oBAAoB,EAAE,EAAE,CACnC,oBAAoB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;KAChE,CAAC,CAAC;IAEH,kCAAkC;IAClC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,QAAQ,CACZ,QAAQ,CAAC;YACP,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC5B,SAAS,EAAE,IAAI;SAChB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,KAAK,CAAC,QAAQ,CACZ,QAAQ,CAAC;YACP,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;YACvC,SAAS,EAAE,KAAK;SACjB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK;QACL,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC;KACjD,CAAC;AACJ,CAAC","sourcesContent":["import { configureStore } from '@reduxjs/toolkit';\nimport createSagaMiddleware from 'redux-saga';\n\nimport { mocksSlice } from './mocks';\nimport { notificationsSlice } from './notifications';\nimport { setState, stateSlice } from './state';\nimport { trackablesSlice } from './trackables';\nimport { uiSlice } from './ui';\nimport type { SimulationOptions } from '../options';\n\n/**\n * Create a Redux store.\n *\n * @param options - The simulation options.\n * @param options.state - The initial state for the Snap.\n * @param options.unencryptedState - The initial unencrypted state for the Snap.\n * @returns A Redux store with the default state.\n */\nexport function createStore({ state, unencryptedState }: SimulationOptions) {\n const sagaMiddleware = createSagaMiddleware();\n const store = configureStore({\n reducer: {\n mocks: mocksSlice.reducer,\n notifications: notificationsSlice.reducer,\n state: stateSlice.reducer,\n trackables: trackablesSlice.reducer,\n ui: uiSlice.reducer,\n },\n middleware: (getDefaultMiddleware) =>\n getDefaultMiddleware({ thunk: false }).concat(sagaMiddleware),\n });\n\n // Set initial state for the Snap.\n if (state) {\n store.dispatch(\n setState({\n state: JSON.stringify(state),\n encrypted: true,\n }),\n );\n }\n\n if (unencryptedState) {\n store.dispatch(\n setState({\n state: JSON.stringify(unencryptedState),\n encrypted: false,\n }),\n );\n }\n\n return {\n store,\n runSaga: sagaMiddleware.run.bind(sagaMiddleware),\n };\n}\n\nexport type Store = ReturnType<typeof createStore>['store'];\nexport type ApplicationState = ReturnType<Store['getState']>;\nexport type RunSagaFunction = ReturnType<typeof createStore>['runSaga'];\n"]}
1
+ {"version":3,"file":"store.mjs","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":";;AACA,OAAO,oBAAoB,mBAAmB;AAE9C,OAAO,EAAE,UAAU,EAAE,oBAAgB;AACrC,OAAO,EAAE,kBAAkB,EAAE,4BAAwB;AACrD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,oBAAgB;AAC/C,OAAO,EAAE,eAAe,EAAE,yBAAqB;AAC/C,OAAO,EAAE,OAAO,EAAE,iBAAa;AAG/B;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAqB;IACxE,MAAM,cAAc,GAAG,oBAAoB,EAAE,CAAC;IAC9C,MAAM,KAAK,GAAG,cAAc,CAAC;QAC3B,OAAO,EAAE;YACP,KAAK,EAAE,UAAU,CAAC,OAAO;YACzB,aAAa,EAAE,kBAAkB,CAAC,OAAO;YACzC,KAAK,EAAE,UAAU,CAAC,OAAO;YACzB,UAAU,EAAE,eAAe,CAAC,OAAO;YACnC,EAAE,EAAE,OAAO,CAAC,OAAO;SACpB;QACD,UAAU,EAAE,CAAC,oBAAoB,EAAE,EAAE,CACnC,oBAAoB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CACrE,cAAc,CACf;KACJ,CAAC,CAAC;IAEH,kCAAkC;IAClC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,QAAQ,CACZ,QAAQ,CAAC;YACP,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC5B,SAAS,EAAE,IAAI;SAChB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,KAAK,CAAC,QAAQ,CACZ,QAAQ,CAAC;YACP,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;YACvC,SAAS,EAAE,KAAK;SACjB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK;QACL,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC;KACjD,CAAC;AACJ,CAAC","sourcesContent":["import { configureStore } from '@reduxjs/toolkit';\nimport createSagaMiddleware from 'redux-saga';\n\nimport { mocksSlice } from './mocks';\nimport { notificationsSlice } from './notifications';\nimport { setState, stateSlice } from './state';\nimport { trackablesSlice } from './trackables';\nimport { uiSlice } from './ui';\nimport type { SimulationOptions } from '../options';\n\n/**\n * Create a Redux store.\n *\n * @param options - The simulation options.\n * @param options.state - The initial state for the Snap.\n * @param options.unencryptedState - The initial unencrypted state for the Snap.\n * @returns A Redux store with the default state.\n */\nexport function createStore({ state, unencryptedState }: SimulationOptions) {\n const sagaMiddleware = createSagaMiddleware();\n const store = configureStore({\n reducer: {\n mocks: mocksSlice.reducer,\n notifications: notificationsSlice.reducer,\n state: stateSlice.reducer,\n trackables: trackablesSlice.reducer,\n ui: uiSlice.reducer,\n },\n middleware: (getDefaultMiddleware) =>\n getDefaultMiddleware({ thunk: false, serializableCheck: false }).concat(\n sagaMiddleware,\n ),\n });\n\n // Set initial state for the Snap.\n if (state) {\n store.dispatch(\n setState({\n state: JSON.stringify(state),\n encrypted: true,\n }),\n );\n }\n\n if (unencryptedState) {\n store.dispatch(\n setState({\n state: JSON.stringify(unencryptedState),\n encrypted: false,\n }),\n );\n }\n\n return {\n store,\n runSaga: sagaMiddleware.run.bind(sagaMiddleware),\n };\n}\n\nexport type Store = ReturnType<typeof createStore>['store'];\nexport type ApplicationState = ReturnType<Store['getState']>;\nexport type RunSagaFunction = ReturnType<typeof createStore>['runSaga'];\n"]}
@@ -1,11 +1,11 @@
1
1
  import type { SnapResponse, SnapResponseWithInterface } from "./types.cjs";
2
2
  export declare const TransactionOptionsStruct: import("@metamask/superstruct").Struct<{
3
3
  data: `0x${string}`;
4
- value: `0x${string}`;
5
4
  chainId: string;
6
5
  origin: string;
7
6
  from: `0x${string}`;
8
7
  to: `0x${string}`;
8
+ value: `0x${string}`;
9
9
  gasLimit: `0x${string}`;
10
10
  maxFeePerGas: `0x${string}`;
11
11
  maxPriorityFeePerGas: `0x${string}`;
@@ -266,7 +266,6 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
266
266
  href: string;
267
267
  } | undefined;
268
268
  }[];
269
- getInterface: Function;
270
269
  response: {
271
270
  result: import("@metamask/snaps-sdk").Json;
272
271
  } | {
@@ -288,6 +287,7 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
288
287
  tags?: Record<string, string | number | boolean> | undefined;
289
288
  }[];
290
289
  };
290
+ getInterface: Function;
291
291
  }, {
292
292
  getInterface: import("@metamask/superstruct").Struct<Function, null>;
293
293
  id: import("@metamask/superstruct").Struct<string, null>;
@@ -431,7 +431,6 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
431
431
  href: string;
432
432
  } | undefined;
433
433
  }[];
434
- getInterface: Function;
435
434
  response: {
436
435
  result: import("@metamask/snaps-sdk").Json;
437
436
  } | {
@@ -453,6 +452,7 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
453
452
  tags?: Record<string, string | number | boolean> | undefined;
454
453
  }[];
455
454
  };
455
+ getInterface: Function;
456
456
  }, null>;
457
457
  /**
458
458
  * Ensure that the actual response contains `getInterface`.
@@ -1,11 +1,11 @@
1
1
  import type { SnapResponse, SnapResponseWithInterface } from "./types.mjs";
2
2
  export declare const TransactionOptionsStruct: import("@metamask/superstruct").Struct<{
3
3
  data: `0x${string}`;
4
- value: `0x${string}`;
5
4
  chainId: string;
6
5
  origin: string;
7
6
  from: `0x${string}`;
8
7
  to: `0x${string}`;
8
+ value: `0x${string}`;
9
9
  gasLimit: `0x${string}`;
10
10
  maxFeePerGas: `0x${string}`;
11
11
  maxPriorityFeePerGas: `0x${string}`;
@@ -266,7 +266,6 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
266
266
  href: string;
267
267
  } | undefined;
268
268
  }[];
269
- getInterface: Function;
270
269
  response: {
271
270
  result: import("@metamask/snaps-sdk").Json;
272
271
  } | {
@@ -288,6 +287,7 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
288
287
  tags?: Record<string, string | number | boolean> | undefined;
289
288
  }[];
290
289
  };
290
+ getInterface: Function;
291
291
  }, {
292
292
  getInterface: import("@metamask/superstruct").Struct<Function, null>;
293
293
  id: import("@metamask/superstruct").Struct<string, null>;
@@ -431,7 +431,6 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
431
431
  href: string;
432
432
  } | undefined;
433
433
  }[];
434
- getInterface: Function;
435
434
  response: {
436
435
  result: import("@metamask/snaps-sdk").Json;
437
436
  } | {
@@ -453,6 +452,7 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
453
452
  tags?: Record<string, string | number | boolean> | undefined;
454
453
  }[];
455
454
  };
455
+ getInterface: Function;
456
456
  }, null>;
457
457
  /**
458
458
  * Ensure that the actual response contains `getInterface`.
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n NotificationType,\n EnumToUnion,\n TrackableError,\n TraceRequest,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n CaipChainId,\n Json,\n JsonRpcId,\n JsonRpcParams,\n} from '@metamask/utils';\n\nimport type {\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from './structs';\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for keyring requests.\n */\nexport type KeyringOptions = RequestOptions;\n\n/**\n * The options to use for name lookup requests.\n *\n * @property chainId - Chain ID.\n * @property domain - Domain name to lookup and resolve.\n * @property address - Address to lookup and resolve.\n */\nexport type NameLookupOptions = Infer<typeof NameLookupOptionsStruct>;\n\n/**\n * The options to use for signature requests.\n *\n * @property origin - The origin to send the signature request from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the signature from. Defaults to a\n * randomly generated address.\n * @property data - The data to sign. Defaults to `0x`.\n * @property signatureMethod - The signature method.\n */\nexport type SignatureOptions = Infer<typeof SignatureOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * Options for uploading a file.\n *\n * @property fileName - The name of the file. By default, this is inferred from\n * the file path if it's a path, and defaults to an empty string if it's a\n * `Uint8Array`.\n * @property contentType - The content type of the file. By default, this is\n * inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type cannot\n * be inferred from the file name.\n */\nexport type FileOptions = {\n fileName?: string;\n contentType?: string;\n};\n\nexport type SnapInterfaceActions = {\n /**\n * Click on an interface element.\n *\n * @param name - The element name to click.\n */\n clickElement(name: string): Promise<void>;\n\n /**\n * Type a value in a interface field.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n typeInField(name: string, value: string): Promise<void>;\n\n /**\n * Select an option with a value in a dropdown.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectInDropdown(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from radio group.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromRadioGroup(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from a Selector, AccountSelector or AssetSelector component.\n *\n * @param name - The element name to type in.\n * @param value - The value to select.\n */\n selectFromSelector(name: string, value: string): Promise<void>;\n\n /**\n * Upload a file.\n *\n * @param name - The element name to upload the file to.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\n uploadFile(\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ): Promise<void>;\n\n /**\n * Wait for the interface to be updated.\n */\n waitForUpdate: () => Promise<SnapHandlerInterface>;\n};\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with two buttons defined.\n * The approval of this confirmation is handled by the snap.\n */\nexport type DefaultSnapInterfaceWithFooter = {\n /**\n * The content to show in the interface.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with one button defined.\n * A cancel button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithPartialFooter =\n DefaultSnapInterfaceWithFooter & {\n /**\n * Cancel the dialog.\n */\n cancel(): Promise<void>;\n };\n\n/**\n * A `snap_dialog` default interface that has no Footer defined.\n * A cancel and ok button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithoutFooter =\n DefaultSnapInterfaceWithPartialFooter & {\n /**\n * Close the dialog.\n *\n */\n ok(): Promise<void>;\n };\n\nexport type DefaultSnapInterface = (\n | DefaultSnapInterfaceWithFooter\n | DefaultSnapInterfaceWithPartialFooter\n | DefaultSnapInterfaceWithoutFooter\n) & {\n type?: never;\n};\n\nexport type SnapInterface = (\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface\n | DefaultSnapInterface\n) &\n SnapInterfaceActions;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * The options to use for mocking a JSON-RPC request.\n */\nexport type JsonRpcMockOptions = {\n /**\n * The JSON-RPC request method.\n */\n method: string;\n\n /**\n * The JSON-RPC response, which will be returned when a request with the\n * specified method is sent.\n */\n result: Json;\n};\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type Snap = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Run a background event in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param backgroundEvent - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified as the `request` param in the `snap_scheduleBackgroundEvent` method.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onBackgroundEvent(backgroundEvent: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Get the response from the snap's `onSettingsPage` method.\n *\n * @returns The response.\n */\n onSettingsPage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a keyring to the Snap.\n *\n * @param keyringRequest - Keyring request options.\n * @returns The response.\n */\n onKeyringRequest(keyringRequest: KeyringOptions): SnapRequest;\n\n /**\n * Get the response from the Snap's `onInstall` handler.\n *\n * @returns The response.\n */\n onInstall(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onUpdate` handler.\n *\n * @returns The response.\n */\n onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onStart` handler.\n *\n * @returns The response.\n */\n onStart(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onNameLookup` handler.\n *\n * @returns The response.\n */\n onNameLookup(\n nameLookupRequest: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Send a JSON-RPC protocol request to the Snap.\n *\n * @param scope - A CAIP-2 scope.\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onProtocolRequest(\n scope: CaipChainId,\n request: RequestOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n * @deprecated Snaps are now automatically closed when the test ends. This\n * method will be removed in a future release.\n */\n close(): Promise<void>;\n};\n\nexport type SnapHandlerInterface = {\n content: JSXElement;\n} & SnapInterfaceActions;\n\nexport type TrackedSnapResponseData = {\n errors: TrackableError[];\n events: {\n event: string;\n properties?: Record<string, Json>;\n sensitiveProperties?: Record<string, Json>;\n }[];\n traces: TraceRequest[];\n};\n\nexport type SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\n\n notifications: {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n title?: string | undefined;\n content?: string | undefined;\n footerLink?: { text: string; href: string } | undefined;\n }[];\n\n tracked: TrackedSnapResponseData;\n\n getInterface(): SnapHandlerInterface;\n};\n\nexport type SnapResponseWithoutInterface = Omit<\n SnapResponseWithInterface,\n 'getInterface'\n>;\n\nexport type SnapResponseType =\n | SnapResponseWithoutInterface\n | SnapResponseWithInterface;\n\nexport type SnapResponse = InferMatching<\n typeof SnapResponseStruct,\n SnapResponseType\n>;\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n NotificationType,\n EnumToUnion,\n TrackableError,\n TraceRequest,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n CaipChainId,\n Json,\n JsonRpcId,\n JsonRpcParams,\n JsonRpcRequest,\n} from '@metamask/utils';\n\nimport type {\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from './structs';\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for keyring requests.\n */\nexport type KeyringOptions = RequestOptions;\n\n/**\n * The options to use for name lookup requests.\n *\n * @property chainId - Chain ID.\n * @property domain - Domain name to lookup and resolve.\n * @property address - Address to lookup and resolve.\n */\nexport type NameLookupOptions = Infer<typeof NameLookupOptionsStruct>;\n\n/**\n * The options to use for signature requests.\n *\n * @property origin - The origin to send the signature request from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the signature from. Defaults to a\n * randomly generated address.\n * @property data - The data to sign. Defaults to `0x`.\n * @property signatureMethod - The signature method.\n */\nexport type SignatureOptions = Infer<typeof SignatureOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * Options for uploading a file.\n *\n * @property fileName - The name of the file. By default, this is inferred from\n * the file path if it's a path, and defaults to an empty string if it's a\n * `Uint8Array`.\n * @property contentType - The content type of the file. By default, this is\n * inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type cannot\n * be inferred from the file name.\n */\nexport type FileOptions = {\n fileName?: string;\n contentType?: string;\n};\n\nexport type SnapInterfaceActions = {\n /**\n * Click on an interface element.\n *\n * @param name - The element name to click.\n */\n clickElement(name: string): Promise<void>;\n\n /**\n * Type a value in a interface field.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n typeInField(name: string, value: string): Promise<void>;\n\n /**\n * Select an option with a value in a dropdown.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectInDropdown(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from radio group.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromRadioGroup(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from a Selector, AccountSelector or AssetSelector component.\n *\n * @param name - The element name to type in.\n * @param value - The value to select.\n */\n selectFromSelector(name: string, value: string): Promise<void>;\n\n /**\n * Upload a file.\n *\n * @param name - The element name to upload the file to.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\n uploadFile(\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ): Promise<void>;\n\n /**\n * Wait for the interface to be updated.\n */\n waitForUpdate: () => Promise<SnapHandlerInterface>;\n};\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with two buttons defined.\n * The approval of this confirmation is handled by the snap.\n */\nexport type DefaultSnapInterfaceWithFooter = {\n /**\n * The content to show in the interface.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with one button defined.\n * A cancel button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithPartialFooter =\n DefaultSnapInterfaceWithFooter & {\n /**\n * Cancel the dialog.\n */\n cancel(): Promise<void>;\n };\n\n/**\n * A `snap_dialog` default interface that has no Footer defined.\n * A cancel and ok button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithoutFooter =\n DefaultSnapInterfaceWithPartialFooter & {\n /**\n * Close the dialog.\n *\n */\n ok(): Promise<void>;\n };\n\nexport type DefaultSnapInterface = (\n | DefaultSnapInterfaceWithFooter\n | DefaultSnapInterfaceWithPartialFooter\n | DefaultSnapInterfaceWithoutFooter\n) & {\n type?: never;\n};\n\nexport type SnapInterface = (\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface\n | DefaultSnapInterface\n) &\n SnapInterfaceActions;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * The options to use for mocking a JSON-RPC request.\n */\nexport type JsonRpcMockOptions =\n | {\n /**\n * The JSON-RPC request method.\n */\n method: string;\n\n /**\n * The JSON-RPC response, which will be returned when a request with the\n * specified method is sent.\n */\n result: Json;\n }\n | JsonRpcMockImplementation;\n\n/**\n * A function that can be used to mock a JSON-RPC implementation.\n *\n * @param request - The JSON-RPC request.\n * @returns A valid JSON value, optionally as a promise or undefined.\n */\nexport type JsonRpcMockImplementation = (\n request: JsonRpcRequest,\n) => Promise<Json> | Json | undefined;\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type Snap = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Run a background event in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param backgroundEvent - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified as the `request` param in the `snap_scheduleBackgroundEvent` method.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onBackgroundEvent(backgroundEvent: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Get the response from the snap's `onSettingsPage` method.\n *\n * @returns The response.\n */\n onSettingsPage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a keyring to the Snap.\n *\n * @param keyringRequest - Keyring request options.\n * @returns The response.\n */\n onKeyringRequest(keyringRequest: KeyringOptions): SnapRequest;\n\n /**\n * Get the response from the Snap's `onInstall` handler.\n *\n * @returns The response.\n */\n onInstall(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onUpdate` handler.\n *\n * @returns The response.\n */\n onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onStart` handler.\n *\n * @returns The response.\n */\n onStart(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onNameLookup` handler.\n *\n * @returns The response.\n */\n onNameLookup(\n nameLookupRequest: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Send a JSON-RPC protocol request to the Snap.\n *\n * @param scope - A CAIP-2 scope.\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onProtocolRequest(\n scope: CaipChainId,\n request: RequestOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc((request) => {\n * if (request.method === 'eth_accounts') {\n * return ['0x1234'];\n * }\n * });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Mock a JSON-RPC request once. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpcOnce({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n *\n * const response2 =\n * await ethereum.request({ method: 'eth_accounts' }); // Default behavior\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpcOnce((request) => {\n * if (request.method === 'eth_accounts') {\n * return ['0x1234'];\n * }\n * });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n *\n * const response2 =\n * await ethereum.request({ method: 'eth_accounts' }); // Default behavior\n */\n mockJsonRpcOnce(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n * @deprecated Snaps are now automatically closed when the test ends. This\n * method will be removed in a future release.\n */\n close(): Promise<void>;\n};\n\nexport type SnapHandlerInterface = {\n content: JSXElement;\n} & SnapInterfaceActions;\n\nexport type TrackedSnapResponseData = {\n errors: TrackableError[];\n events: {\n event: string;\n properties?: Record<string, Json>;\n sensitiveProperties?: Record<string, Json>;\n }[];\n traces: TraceRequest[];\n};\n\nexport type SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\n\n notifications: {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n title?: string | undefined;\n content?: string | undefined;\n footerLink?: { text: string; href: string } | undefined;\n }[];\n\n tracked: TrackedSnapResponseData;\n\n getInterface(): SnapHandlerInterface;\n};\n\nexport type SnapResponseWithoutInterface = Omit<\n SnapResponseWithInterface,\n 'getInterface'\n>;\n\nexport type SnapResponseType =\n | SnapResponseWithoutInterface\n | SnapResponseWithInterface;\n\nexport type SnapResponse = InferMatching<\n typeof SnapResponseStruct,\n SnapResponseType\n>;\n"]}