@metamask/snaps-simulation 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/constants.cjs +35 -1
  3. package/dist/constants.cjs.map +1 -1
  4. package/dist/constants.d.cts +12 -0
  5. package/dist/constants.d.cts.map +1 -1
  6. package/dist/constants.d.mts +12 -0
  7. package/dist/constants.d.mts.map +1 -1
  8. package/dist/constants.mjs +34 -0
  9. package/dist/constants.mjs.map +1 -1
  10. package/dist/controllers.cjs +4 -0
  11. package/dist/controllers.cjs.map +1 -1
  12. package/dist/controllers.d.cts.map +1 -1
  13. package/dist/controllers.d.mts.map +1 -1
  14. package/dist/controllers.mjs +4 -0
  15. package/dist/controllers.mjs.map +1 -1
  16. package/dist/helpers.cjs +13 -0
  17. package/dist/helpers.cjs.map +1 -1
  18. package/dist/helpers.d.cts.map +1 -1
  19. package/dist/helpers.d.mts.map +1 -1
  20. package/dist/helpers.mjs +13 -0
  21. package/dist/helpers.mjs.map +1 -1
  22. package/dist/interface.cjs +65 -16
  23. package/dist/interface.cjs.map +1 -1
  24. package/dist/interface.d.cts +34 -7
  25. package/dist/interface.d.cts.map +1 -1
  26. package/dist/interface.d.mts +34 -7
  27. package/dist/interface.d.mts.map +1 -1
  28. package/dist/interface.mjs +65 -17
  29. package/dist/interface.mjs.map +1 -1
  30. package/dist/options.cjs +13 -0
  31. package/dist/options.cjs.map +1 -1
  32. package/dist/options.d.cts +62 -0
  33. package/dist/options.d.cts.map +1 -1
  34. package/dist/options.d.mts +62 -0
  35. package/dist/options.d.mts.map +1 -1
  36. package/dist/options.mjs +16 -3
  37. package/dist/options.mjs.map +1 -1
  38. package/dist/request.cjs +7 -5
  39. package/dist/request.cjs.map +1 -1
  40. package/dist/request.d.cts +6 -2
  41. package/dist/request.d.cts.map +1 -1
  42. package/dist/request.d.mts +6 -2
  43. package/dist/request.d.mts.map +1 -1
  44. package/dist/request.mjs +7 -5
  45. package/dist/request.mjs.map +1 -1
  46. package/dist/simulation.cjs +24 -2
  47. package/dist/simulation.cjs.map +1 -1
  48. package/dist/simulation.d.cts +3 -2
  49. package/dist/simulation.d.cts.map +1 -1
  50. package/dist/simulation.d.mts +3 -2
  51. package/dist/simulation.d.mts.map +1 -1
  52. package/dist/simulation.mjs +24 -2
  53. package/dist/simulation.mjs.map +1 -1
  54. package/dist/structs.d.cts +14 -14
  55. package/dist/structs.d.mts +14 -14
  56. package/dist/types.cjs.map +1 -1
  57. package/dist/types.d.cts +2 -2
  58. package/dist/types.d.mts +2 -2
  59. package/dist/types.mjs.map +1 -1
  60. package/package.json +7 -7
@@ -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;AAUpE,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,EAC7B,kCAAwB;AACzB,OAAO,EAAE,gCAAg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AAkC,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 AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n InterfaceContext,\n SnapId,\n EntropySource,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { 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} 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';\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/**\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);\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: unknown) => {\n if (error) {\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}\n\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: PhishingDetectorResultType.All }),\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;AAUpE,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,4BA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AAO,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 {\n type AuxiliaryFileEncoding,\n type Component,\n type InterfaceState,\n type InterfaceContext,\n type SnapId,\n type EntropySource,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles } 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} 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';\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/**\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);\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: unknown) => {\n if (error) {\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}\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 */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: PhishingDetectorResultType.All }),\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getAccountByAddress',\n (address) =>\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n options.accounts.find((account) => address === account.address),\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 () => options.accounts.find((account) => account.selected),\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:listMultichainAccounts',\n // @ts-expect-error - These are partial accounts with only the necessary\n // data used by the interface controller.\n () => options.accounts,\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"]}
@@ -97,8 +97,8 @@ export declare const BaseNameLookupOptionsStruct: import("@metamask/superstruct"
97
97
  chainId: import("@metamask/superstruct").Struct<string, null>;
98
98
  }>;
99
99
  export declare const NameLookupOptionsStruct: import("@metamask/superstruct").Struct<{
100
- chainId: string;
101
100
  address: string;
101
+ chainId: string;
102
102
  } | {
103
103
  chainId: string;
104
104
  domain: string;
@@ -125,9 +125,10 @@ export declare const InterfaceStruct: import("@metamask/superstruct").Struct<{
125
125
  content: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk/jsx").JSXElement | undefined, null>;
126
126
  }>;
127
127
  export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/superstruct").Struct<{
128
+ id: string;
128
129
  notifications: {
129
- type: "inApp" | "native";
130
130
  id: string;
131
+ type: "inApp" | "native";
131
132
  message: string;
132
133
  title?: string | undefined;
133
134
  content?: string | undefined;
@@ -136,7 +137,6 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
136
137
  href: string;
137
138
  } | undefined;
138
139
  }[];
139
- id: string;
140
140
  response: {
141
141
  result: import("@metamask/snaps-sdk").Json;
142
142
  } | {
@@ -150,8 +150,8 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
150
150
  error: import("@metamask/snaps-sdk").Json;
151
151
  }, null>;
152
152
  notifications: import("@metamask/superstruct").Struct<{
153
- type: "inApp" | "native";
154
153
  id: string;
154
+ type: "inApp" | "native";
155
155
  message: string;
156
156
  title?: string | undefined;
157
157
  content?: string | undefined;
@@ -160,8 +160,8 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
160
160
  href: string;
161
161
  } | undefined;
162
162
  }[], import("@metamask/superstruct").Struct<{
163
- type: "inApp" | "native";
164
163
  id: string;
164
+ type: "inApp" | "native";
165
165
  message: string;
166
166
  title?: string | undefined;
167
167
  content?: string | undefined;
@@ -185,10 +185,11 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
185
185
  }>>;
186
186
  }>;
187
187
  export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstruct").Struct<{
188
+ id: string;
188
189
  getInterface: Function;
189
190
  notifications: {
190
- type: "inApp" | "native";
191
191
  id: string;
192
+ type: "inApp" | "native";
192
193
  message: string;
193
194
  title?: string | undefined;
194
195
  content?: string | undefined;
@@ -197,7 +198,6 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
197
198
  href: string;
198
199
  } | undefined;
199
200
  }[];
200
- id: string;
201
201
  response: {
202
202
  result: import("@metamask/snaps-sdk").Json;
203
203
  } | {
@@ -205,9 +205,10 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
205
205
  };
206
206
  }, {
207
207
  getInterface: import("@metamask/superstruct").Struct<Function, null>;
208
+ id: import("@metamask/superstruct").Struct<string, null>;
208
209
  notifications: import("@metamask/superstruct").Struct<{
209
- type: "inApp" | "native";
210
210
  id: string;
211
+ type: "inApp" | "native";
211
212
  message: string;
212
213
  title?: string | undefined;
213
214
  content?: string | undefined;
@@ -216,8 +217,8 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
216
217
  href: string;
217
218
  } | undefined;
218
219
  }[], import("@metamask/superstruct").Struct<{
219
- type: "inApp" | "native";
220
220
  id: string;
221
+ type: "inApp" | "native";
221
222
  message: string;
222
223
  title?: string | undefined;
223
224
  content?: string | undefined;
@@ -239,7 +240,6 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
239
240
  text: import("@metamask/superstruct").Struct<string, null>;
240
241
  }>;
241
242
  }>>;
242
- id: import("@metamask/superstruct").Struct<string, null>;
243
243
  response: import("@metamask/superstruct").Struct<{
244
244
  result: import("@metamask/snaps-sdk").Json;
245
245
  } | {
@@ -247,9 +247,10 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
247
247
  }, null>;
248
248
  }>;
249
249
  export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<{
250
+ id: string;
250
251
  notifications: {
251
- type: "inApp" | "native";
252
252
  id: string;
253
+ type: "inApp" | "native";
253
254
  message: string;
254
255
  title?: string | undefined;
255
256
  content?: string | undefined;
@@ -258,17 +259,17 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
258
259
  href: string;
259
260
  } | undefined;
260
261
  }[];
261
- id: string;
262
262
  response: {
263
263
  result: import("@metamask/snaps-sdk").Json;
264
264
  } | {
265
265
  error: import("@metamask/snaps-sdk").Json;
266
266
  };
267
267
  } | {
268
+ id: string;
268
269
  getInterface: Function;
269
270
  notifications: {
270
- type: "inApp" | "native";
271
271
  id: string;
272
+ type: "inApp" | "native";
272
273
  message: string;
273
274
  title?: string | undefined;
274
275
  content?: string | undefined;
@@ -277,7 +278,6 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
277
278
  href: string;
278
279
  } | undefined;
279
280
  }[];
280
- id: string;
281
281
  response: {
282
282
  result: import("@metamask/snaps-sdk").Json;
283
283
  } | {
@@ -97,8 +97,8 @@ export declare const BaseNameLookupOptionsStruct: import("@metamask/superstruct"
97
97
  chainId: import("@metamask/superstruct").Struct<string, null>;
98
98
  }>;
99
99
  export declare const NameLookupOptionsStruct: import("@metamask/superstruct").Struct<{
100
- chainId: string;
101
100
  address: string;
101
+ chainId: string;
102
102
  } | {
103
103
  chainId: string;
104
104
  domain: string;
@@ -125,9 +125,10 @@ export declare const InterfaceStruct: import("@metamask/superstruct").Struct<{
125
125
  content: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk/jsx").JSXElement | undefined, null>;
126
126
  }>;
127
127
  export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/superstruct").Struct<{
128
+ id: string;
128
129
  notifications: {
129
- type: "inApp" | "native";
130
130
  id: string;
131
+ type: "inApp" | "native";
131
132
  message: string;
132
133
  title?: string | undefined;
133
134
  content?: string | undefined;
@@ -136,7 +137,6 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
136
137
  href: string;
137
138
  } | undefined;
138
139
  }[];
139
- id: string;
140
140
  response: {
141
141
  result: import("@metamask/snaps-sdk").Json;
142
142
  } | {
@@ -150,8 +150,8 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
150
150
  error: import("@metamask/snaps-sdk").Json;
151
151
  }, null>;
152
152
  notifications: import("@metamask/superstruct").Struct<{
153
- type: "inApp" | "native";
154
153
  id: string;
154
+ type: "inApp" | "native";
155
155
  message: string;
156
156
  title?: string | undefined;
157
157
  content?: string | undefined;
@@ -160,8 +160,8 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
160
160
  href: string;
161
161
  } | undefined;
162
162
  }[], import("@metamask/superstruct").Struct<{
163
- type: "inApp" | "native";
164
163
  id: string;
164
+ type: "inApp" | "native";
165
165
  message: string;
166
166
  title?: string | undefined;
167
167
  content?: string | undefined;
@@ -185,10 +185,11 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
185
185
  }>>;
186
186
  }>;
187
187
  export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstruct").Struct<{
188
+ id: string;
188
189
  getInterface: Function;
189
190
  notifications: {
190
- type: "inApp" | "native";
191
191
  id: string;
192
+ type: "inApp" | "native";
192
193
  message: string;
193
194
  title?: string | undefined;
194
195
  content?: string | undefined;
@@ -197,7 +198,6 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
197
198
  href: string;
198
199
  } | undefined;
199
200
  }[];
200
- id: string;
201
201
  response: {
202
202
  result: import("@metamask/snaps-sdk").Json;
203
203
  } | {
@@ -205,9 +205,10 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
205
205
  };
206
206
  }, {
207
207
  getInterface: import("@metamask/superstruct").Struct<Function, null>;
208
+ id: import("@metamask/superstruct").Struct<string, null>;
208
209
  notifications: import("@metamask/superstruct").Struct<{
209
- type: "inApp" | "native";
210
210
  id: string;
211
+ type: "inApp" | "native";
211
212
  message: string;
212
213
  title?: string | undefined;
213
214
  content?: string | undefined;
@@ -216,8 +217,8 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
216
217
  href: string;
217
218
  } | undefined;
218
219
  }[], import("@metamask/superstruct").Struct<{
219
- type: "inApp" | "native";
220
220
  id: string;
221
+ type: "inApp" | "native";
221
222
  message: string;
222
223
  title?: string | undefined;
223
224
  content?: string | undefined;
@@ -239,7 +240,6 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
239
240
  text: import("@metamask/superstruct").Struct<string, null>;
240
241
  }>;
241
242
  }>>;
242
- id: import("@metamask/superstruct").Struct<string, null>;
243
243
  response: import("@metamask/superstruct").Struct<{
244
244
  result: import("@metamask/snaps-sdk").Json;
245
245
  } | {
@@ -247,9 +247,10 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
247
247
  }, null>;
248
248
  }>;
249
249
  export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<{
250
+ id: string;
250
251
  notifications: {
251
- type: "inApp" | "native";
252
252
  id: string;
253
+ type: "inApp" | "native";
253
254
  message: string;
254
255
  title?: string | undefined;
255
256
  content?: string | undefined;
@@ -258,17 +259,17 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
258
259
  href: string;
259
260
  } | undefined;
260
261
  }[];
261
- id: string;
262
262
  response: {
263
263
  result: import("@metamask/snaps-sdk").Json;
264
264
  } | {
265
265
  error: import("@metamask/snaps-sdk").Json;
266
266
  };
267
267
  } | {
268
+ id: string;
268
269
  getInterface: Function;
269
270
  notifications: {
270
- type: "inApp" | "native";
271
271
  id: string;
272
+ type: "inApp" | "native";
272
273
  message: string;
273
274
  title?: string | undefined;
274
275
  content?: string | undefined;
@@ -277,7 +278,6 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
277
278
  href: string;
278
279
  } | undefined;
279
280
  }[];
280
- id: string;
281
281
  response: {
282
282
  result: import("@metamask/snaps-sdk").Json;
283
283
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { NotificationType, EnumToUnion } 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 Selector component.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\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 SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\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 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 { NotificationType, EnumToUnion } 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 SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\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 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"]}
package/dist/types.d.cts CHANGED
@@ -122,10 +122,10 @@ export type SnapInterfaceActions = {
122
122
  */
123
123
  selectFromRadioGroup(name: string, value: string): Promise<void>;
124
124
  /**
125
- * Choose an option with a value from Selector component.
125
+ * Choose an option with a value from a Selector, AccountSelector or AssetSelector component.
126
126
  *
127
127
  * @param name - The element name to type in.
128
- * @param value - The value to type.
128
+ * @param value - The value to select.
129
129
  */
130
130
  selectFromSelector(name: string, value: string): Promise<void>;
131
131
  /**
package/dist/types.d.mts CHANGED
@@ -122,10 +122,10 @@ export type SnapInterfaceActions = {
122
122
  */
123
123
  selectFromRadioGroup(name: string, value: string): Promise<void>;
124
124
  /**
125
- * Choose an option with a value from Selector component.
125
+ * Choose an option with a value from a Selector, AccountSelector or AssetSelector component.
126
126
  *
127
127
  * @param name - The element name to type in.
128
- * @param value - The value to type.
128
+ * @param value - The value to select.
129
129
  */
130
130
  selectFromSelector(name: string, value: string): Promise<void>;
131
131
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { NotificationType, EnumToUnion } 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 Selector component.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\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 SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\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 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.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { NotificationType, EnumToUnion } 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 SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\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 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-simulation",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -62,11 +62,11 @@
62
62
  "@metamask/key-tree": "^10.1.1",
63
63
  "@metamask/permission-controller": "^11.0.6",
64
64
  "@metamask/phishing-controller": "^12.6.0",
65
- "@metamask/snaps-controllers": "^13.1.0",
66
- "@metamask/snaps-execution-environments": "^9.1.0",
67
- "@metamask/snaps-rpc-methods": "^13.1.0",
68
- "@metamask/snaps-sdk": "^8.1.0",
69
- "@metamask/snaps-utils": "^10.1.0",
65
+ "@metamask/snaps-controllers": "^14.0.0",
66
+ "@metamask/snaps-execution-environments": "^10.0.0",
67
+ "@metamask/snaps-rpc-methods": "^13.2.0",
68
+ "@metamask/snaps-sdk": "^9.0.0",
69
+ "@metamask/snaps-utils": "^11.0.0",
70
70
  "@metamask/superstruct": "^3.2.1",
71
71
  "@metamask/utils": "^11.4.0",
72
72
  "@reduxjs/toolkit": "^1.9.5",
@@ -76,7 +76,7 @@
76
76
  "redux-saga": "^1.2.3"
77
77
  },
78
78
  "devDependencies": {
79
- "@lavamoat/allow-scripts": "^3.3.3",
79
+ "@lavamoat/allow-scripts": "^3.3.4",
80
80
  "@metamask/auto-changelog": "^5.0.2",
81
81
  "@ts-bridge/cli": "^0.6.1",
82
82
  "@types/express": "^5.0.1",