@metamask/snaps-simulation 2.3.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -1
- package/dist/controllers.cjs +0 -1
- package/dist/controllers.cjs.map +1 -1
- package/dist/controllers.d.cts.map +1 -1
- package/dist/controllers.d.mts.map +1 -1
- package/dist/controllers.mjs +0 -1
- package/dist/controllers.mjs.map +1 -1
- package/dist/interface.cjs +6 -6
- package/dist/interface.cjs.map +1 -1
- package/dist/interface.mjs +6 -6
- package/dist/interface.mjs.map +1 -1
- package/dist/methods/hooks/get-mnemonic-seed.cjs +29 -0
- package/dist/methods/hooks/get-mnemonic-seed.cjs.map +1 -0
- package/dist/methods/hooks/get-mnemonic-seed.d.cts +9 -0
- package/dist/methods/hooks/get-mnemonic-seed.d.cts.map +1 -0
- package/dist/methods/hooks/get-mnemonic-seed.d.mts +9 -0
- package/dist/methods/hooks/get-mnemonic-seed.d.mts.map +1 -0
- package/dist/methods/hooks/get-mnemonic-seed.mjs +25 -0
- package/dist/methods/hooks/get-mnemonic-seed.mjs.map +1 -0
- package/dist/options.d.cts +3 -3
- package/dist/options.d.mts +3 -3
- package/dist/simulation.cjs +2 -1
- package/dist/simulation.cjs.map +1 -1
- package/dist/simulation.d.cts +7 -0
- package/dist/simulation.d.cts.map +1 -1
- package/dist/simulation.d.mts +7 -0
- package/dist/simulation.d.mts.map +1 -1
- package/dist/simulation.mjs +2 -1
- package/dist/simulation.mjs.map +1 -1
- package/dist/structs.d.cts +41 -41
- package/dist/structs.d.mts +41 -41
- package/package.json +12 -12
package/dist/simulation.mjs.map
CHANGED
|
@@ -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,0B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AAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,0BAA0B,CAAC,GAAG,EAAE,CAAC,CAChE,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,+BAA+B,EAC/B,CAAC,IAAI,EAAE,EAAE;QACP;;;;;WAKG;QACH,QAAQ,CAAC,CAAC,uBAAuB;YAC/B,MAAM,gBAAgB,GAAc,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;YACtE,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAED,MAAM,gBAAgB,GAA0B,OAAO,CACrD,uBAAuB,CACxB,CAAC,MAAM,EAAE,CAAC;QACX,OAAO,CACL,gBAAgB,EAAE,IAAI,KAAK,qBAAqB,CAAC,OAAO;YACxD,gBAAgB,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,CAClC,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,kCAAkC,EAClC,KAAK,EAAE,GAAW,EAAE,KAAc,EAAE,EAAE;QACpC,MAAM,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;QAElD,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport { Messenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { PhishingDetectorResultType } from '@metamask/phishing-controller';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n detectSnapLocation,\n fetchSnap,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n 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 { 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 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 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 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\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:maybeUpdateState',\n async () => Promise.resolve(),\n );\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,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;;;;;WAKG;QACH,QAAQ,CAAC,CAAC,uBAAuB;YAC/B,MAAM,gBAAgB,GAAc,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;YACtE,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAED,MAAM,gBAAgB,GAA0B,OAAO,CACrD,uBAAuB,CACxB,CAAC,MAAM,EAAE,CAAC;QACX,OAAO,CACL,gBAAgB,EAAE,IAAI,KAAK,qBAAqB,CAAC,OAAO;YACxD,gBAAgB,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,CAClC,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,kCAAkC,EAClC,KAAK,EAAE,GAAW,EAAE,KAAc,EAAE,EAAE;QACpC,MAAM,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;QAElD,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport { Messenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { PhishingDetectorResultType } from '@metamask/phishing-controller';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n detectSnapLocation,\n fetchSnap,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n 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 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\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"]}
|
package/dist/structs.d.cts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { SnapResponse, SnapResponseWithInterface } from "./types.cjs";
|
|
2
2
|
export declare const TransactionOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
3
|
-
data: `0x${string}`;
|
|
4
|
-
origin: string;
|
|
5
3
|
value: `0x${string}`;
|
|
6
|
-
nonce: `0x${string}`;
|
|
7
|
-
from: `0x${string}`;
|
|
8
4
|
chainId: string;
|
|
5
|
+
origin: string;
|
|
6
|
+
from: `0x${string}`;
|
|
9
7
|
to: `0x${string}`;
|
|
10
8
|
gasLimit: `0x${string}`;
|
|
11
9
|
maxFeePerGas: `0x${string}`;
|
|
12
10
|
maxPriorityFeePerGas: `0x${string}`;
|
|
11
|
+
nonce: `0x${string}`;
|
|
12
|
+
data: `0x${string}`;
|
|
13
13
|
}, {
|
|
14
14
|
/**
|
|
15
15
|
* The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.
|
|
@@ -63,10 +63,10 @@ export declare const TransactionOptionsStruct: import("@metamask/superstruct").S
|
|
|
63
63
|
data: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
64
64
|
}>;
|
|
65
65
|
export declare const SignatureOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
66
|
-
data: `0x${string}` | Record<string, any> | Record<string, any>[];
|
|
67
66
|
origin: string;
|
|
68
67
|
from: `0x${string}`;
|
|
69
|
-
|
|
68
|
+
data: `0x${string}` | Record<string, any> | Record<string, any>[];
|
|
69
|
+
signatureMethod: "eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "personal_sign";
|
|
70
70
|
}, {
|
|
71
71
|
/**
|
|
72
72
|
* The origin making the signature request.
|
|
@@ -86,7 +86,7 @@ export declare const SignatureOptionsStruct: import("@metamask/superstruct").Str
|
|
|
86
86
|
/**
|
|
87
87
|
* The signature method being used.
|
|
88
88
|
*/
|
|
89
|
-
signatureMethod: import("@metamask/superstruct").Struct<"eth_signTypedData" | "
|
|
89
|
+
signatureMethod: import("@metamask/superstruct").Struct<"eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "personal_sign", null>;
|
|
90
90
|
}>;
|
|
91
91
|
export declare const BaseNameLookupOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
92
92
|
chainId: string;
|
|
@@ -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
|
-
address: string;
|
|
101
100
|
chainId: string;
|
|
101
|
+
address: string;
|
|
102
102
|
} | {
|
|
103
103
|
chainId: string;
|
|
104
104
|
domain: string;
|
|
@@ -125,18 +125,18 @@ 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;
|
|
129
128
|
notifications: {
|
|
130
|
-
type: "
|
|
131
|
-
message: string;
|
|
129
|
+
type: "inApp" | "native";
|
|
132
130
|
id: string;
|
|
133
|
-
|
|
131
|
+
message: string;
|
|
134
132
|
title?: string | undefined;
|
|
133
|
+
content?: string | undefined;
|
|
135
134
|
footerLink?: {
|
|
136
135
|
text: string;
|
|
137
136
|
href: string;
|
|
138
137
|
} | undefined;
|
|
139
138
|
}[];
|
|
139
|
+
id: string;
|
|
140
140
|
response: {
|
|
141
141
|
result: import("@metamask/snaps-sdk").Json;
|
|
142
142
|
} | {
|
|
@@ -150,21 +150,21 @@ 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: "
|
|
154
|
-
message: string;
|
|
153
|
+
type: "inApp" | "native";
|
|
155
154
|
id: string;
|
|
156
|
-
|
|
155
|
+
message: string;
|
|
157
156
|
title?: string | undefined;
|
|
157
|
+
content?: string | undefined;
|
|
158
158
|
footerLink?: {
|
|
159
159
|
text: string;
|
|
160
160
|
href: string;
|
|
161
161
|
} | undefined;
|
|
162
162
|
}[], import("@metamask/superstruct").Struct<{
|
|
163
|
-
type: "
|
|
164
|
-
message: string;
|
|
163
|
+
type: "inApp" | "native";
|
|
165
164
|
id: string;
|
|
166
|
-
|
|
165
|
+
message: string;
|
|
167
166
|
title?: string | undefined;
|
|
167
|
+
content?: string | undefined;
|
|
168
168
|
footerLink?: {
|
|
169
169
|
text: string;
|
|
170
170
|
href: string;
|
|
@@ -172,7 +172,7 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
|
|
|
172
172
|
}, {
|
|
173
173
|
id: import("@metamask/superstruct").Struct<string, null>;
|
|
174
174
|
message: import("@metamask/superstruct").Struct<string, null>;
|
|
175
|
-
type: import("@metamask/superstruct").Struct<"
|
|
175
|
+
type: import("@metamask/superstruct").Struct<"inApp" | "native", null>;
|
|
176
176
|
title: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
177
177
|
content: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
178
178
|
footerLink: import("@metamask/superstruct").Struct<{
|
|
@@ -185,43 +185,42 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
|
|
|
185
185
|
}>>;
|
|
186
186
|
}>;
|
|
187
187
|
export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstruct").Struct<{
|
|
188
|
-
|
|
188
|
+
getInterface: Function;
|
|
189
189
|
notifications: {
|
|
190
|
-
type: "
|
|
191
|
-
message: string;
|
|
190
|
+
type: "inApp" | "native";
|
|
192
191
|
id: string;
|
|
193
|
-
|
|
192
|
+
message: string;
|
|
194
193
|
title?: string | undefined;
|
|
194
|
+
content?: string | undefined;
|
|
195
195
|
footerLink?: {
|
|
196
196
|
text: string;
|
|
197
197
|
href: string;
|
|
198
198
|
} | undefined;
|
|
199
199
|
}[];
|
|
200
|
+
id: string;
|
|
200
201
|
response: {
|
|
201
202
|
result: import("@metamask/snaps-sdk").Json;
|
|
202
203
|
} | {
|
|
203
204
|
error: import("@metamask/snaps-sdk").Json;
|
|
204
205
|
};
|
|
205
|
-
getInterface: Function;
|
|
206
206
|
}, {
|
|
207
207
|
getInterface: import("@metamask/superstruct").Struct<Function, null>;
|
|
208
|
-
id: import("@metamask/superstruct").Struct<string, null>;
|
|
209
208
|
notifications: import("@metamask/superstruct").Struct<{
|
|
210
|
-
type: "
|
|
211
|
-
message: string;
|
|
209
|
+
type: "inApp" | "native";
|
|
212
210
|
id: string;
|
|
213
|
-
|
|
211
|
+
message: string;
|
|
214
212
|
title?: string | undefined;
|
|
213
|
+
content?: string | undefined;
|
|
215
214
|
footerLink?: {
|
|
216
215
|
text: string;
|
|
217
216
|
href: string;
|
|
218
217
|
} | undefined;
|
|
219
218
|
}[], import("@metamask/superstruct").Struct<{
|
|
220
|
-
type: "
|
|
221
|
-
message: string;
|
|
219
|
+
type: "inApp" | "native";
|
|
222
220
|
id: string;
|
|
223
|
-
|
|
221
|
+
message: string;
|
|
224
222
|
title?: string | undefined;
|
|
223
|
+
content?: string | undefined;
|
|
225
224
|
footerLink?: {
|
|
226
225
|
text: string;
|
|
227
226
|
href: string;
|
|
@@ -229,7 +228,7 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
|
|
|
229
228
|
}, {
|
|
230
229
|
id: import("@metamask/superstruct").Struct<string, null>;
|
|
231
230
|
message: import("@metamask/superstruct").Struct<string, null>;
|
|
232
|
-
type: import("@metamask/superstruct").Struct<"
|
|
231
|
+
type: import("@metamask/superstruct").Struct<"inApp" | "native", null>;
|
|
233
232
|
title: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
234
233
|
content: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
235
234
|
footerLink: import("@metamask/superstruct").Struct<{
|
|
@@ -240,6 +239,7 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
|
|
|
240
239
|
text: import("@metamask/superstruct").Struct<string, null>;
|
|
241
240
|
}>;
|
|
242
241
|
}>>;
|
|
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,42 +247,42 @@ 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;
|
|
251
250
|
notifications: {
|
|
252
|
-
type: "
|
|
253
|
-
message: string;
|
|
251
|
+
type: "inApp" | "native";
|
|
254
252
|
id: string;
|
|
255
|
-
|
|
253
|
+
message: string;
|
|
256
254
|
title?: string | undefined;
|
|
255
|
+
content?: string | undefined;
|
|
257
256
|
footerLink?: {
|
|
258
257
|
text: string;
|
|
259
258
|
href: string;
|
|
260
259
|
} | undefined;
|
|
261
260
|
}[];
|
|
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
|
-
|
|
268
|
+
getInterface: Function;
|
|
269
269
|
notifications: {
|
|
270
|
-
type: "
|
|
271
|
-
message: string;
|
|
270
|
+
type: "inApp" | "native";
|
|
272
271
|
id: string;
|
|
273
|
-
|
|
272
|
+
message: string;
|
|
274
273
|
title?: string | undefined;
|
|
274
|
+
content?: string | undefined;
|
|
275
275
|
footerLink?: {
|
|
276
276
|
text: string;
|
|
277
277
|
href: string;
|
|
278
278
|
} | undefined;
|
|
279
279
|
}[];
|
|
280
|
+
id: string;
|
|
280
281
|
response: {
|
|
281
282
|
result: import("@metamask/snaps-sdk").Json;
|
|
282
283
|
} | {
|
|
283
284
|
error: import("@metamask/snaps-sdk").Json;
|
|
284
285
|
};
|
|
285
|
-
getInterface: Function;
|
|
286
286
|
}, null>;
|
|
287
287
|
/**
|
|
288
288
|
* Ensure that the actual response contains `getInterface`.
|
package/dist/structs.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { SnapResponse, SnapResponseWithInterface } from "./types.mjs";
|
|
2
2
|
export declare const TransactionOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
3
|
-
data: `0x${string}`;
|
|
4
|
-
origin: string;
|
|
5
3
|
value: `0x${string}`;
|
|
6
|
-
nonce: `0x${string}`;
|
|
7
|
-
from: `0x${string}`;
|
|
8
4
|
chainId: string;
|
|
5
|
+
origin: string;
|
|
6
|
+
from: `0x${string}`;
|
|
9
7
|
to: `0x${string}`;
|
|
10
8
|
gasLimit: `0x${string}`;
|
|
11
9
|
maxFeePerGas: `0x${string}`;
|
|
12
10
|
maxPriorityFeePerGas: `0x${string}`;
|
|
11
|
+
nonce: `0x${string}`;
|
|
12
|
+
data: `0x${string}`;
|
|
13
13
|
}, {
|
|
14
14
|
/**
|
|
15
15
|
* The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.
|
|
@@ -63,10 +63,10 @@ export declare const TransactionOptionsStruct: import("@metamask/superstruct").S
|
|
|
63
63
|
data: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
64
64
|
}>;
|
|
65
65
|
export declare const SignatureOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
66
|
-
data: `0x${string}` | Record<string, any> | Record<string, any>[];
|
|
67
66
|
origin: string;
|
|
68
67
|
from: `0x${string}`;
|
|
69
|
-
|
|
68
|
+
data: `0x${string}` | Record<string, any> | Record<string, any>[];
|
|
69
|
+
signatureMethod: "eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "personal_sign";
|
|
70
70
|
}, {
|
|
71
71
|
/**
|
|
72
72
|
* The origin making the signature request.
|
|
@@ -86,7 +86,7 @@ export declare const SignatureOptionsStruct: import("@metamask/superstruct").Str
|
|
|
86
86
|
/**
|
|
87
87
|
* The signature method being used.
|
|
88
88
|
*/
|
|
89
|
-
signatureMethod: import("@metamask/superstruct").Struct<"eth_signTypedData" | "
|
|
89
|
+
signatureMethod: import("@metamask/superstruct").Struct<"eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "personal_sign", null>;
|
|
90
90
|
}>;
|
|
91
91
|
export declare const BaseNameLookupOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
92
92
|
chainId: string;
|
|
@@ -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
|
-
address: string;
|
|
101
100
|
chainId: string;
|
|
101
|
+
address: string;
|
|
102
102
|
} | {
|
|
103
103
|
chainId: string;
|
|
104
104
|
domain: string;
|
|
@@ -125,18 +125,18 @@ 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;
|
|
129
128
|
notifications: {
|
|
130
|
-
type: "
|
|
131
|
-
message: string;
|
|
129
|
+
type: "inApp" | "native";
|
|
132
130
|
id: string;
|
|
133
|
-
|
|
131
|
+
message: string;
|
|
134
132
|
title?: string | undefined;
|
|
133
|
+
content?: string | undefined;
|
|
135
134
|
footerLink?: {
|
|
136
135
|
text: string;
|
|
137
136
|
href: string;
|
|
138
137
|
} | undefined;
|
|
139
138
|
}[];
|
|
139
|
+
id: string;
|
|
140
140
|
response: {
|
|
141
141
|
result: import("@metamask/snaps-sdk").Json;
|
|
142
142
|
} | {
|
|
@@ -150,21 +150,21 @@ 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: "
|
|
154
|
-
message: string;
|
|
153
|
+
type: "inApp" | "native";
|
|
155
154
|
id: string;
|
|
156
|
-
|
|
155
|
+
message: string;
|
|
157
156
|
title?: string | undefined;
|
|
157
|
+
content?: string | undefined;
|
|
158
158
|
footerLink?: {
|
|
159
159
|
text: string;
|
|
160
160
|
href: string;
|
|
161
161
|
} | undefined;
|
|
162
162
|
}[], import("@metamask/superstruct").Struct<{
|
|
163
|
-
type: "
|
|
164
|
-
message: string;
|
|
163
|
+
type: "inApp" | "native";
|
|
165
164
|
id: string;
|
|
166
|
-
|
|
165
|
+
message: string;
|
|
167
166
|
title?: string | undefined;
|
|
167
|
+
content?: string | undefined;
|
|
168
168
|
footerLink?: {
|
|
169
169
|
text: string;
|
|
170
170
|
href: string;
|
|
@@ -172,7 +172,7 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
|
|
|
172
172
|
}, {
|
|
173
173
|
id: import("@metamask/superstruct").Struct<string, null>;
|
|
174
174
|
message: import("@metamask/superstruct").Struct<string, null>;
|
|
175
|
-
type: import("@metamask/superstruct").Struct<"
|
|
175
|
+
type: import("@metamask/superstruct").Struct<"inApp" | "native", null>;
|
|
176
176
|
title: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
177
177
|
content: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
178
178
|
footerLink: import("@metamask/superstruct").Struct<{
|
|
@@ -185,43 +185,42 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
|
|
|
185
185
|
}>>;
|
|
186
186
|
}>;
|
|
187
187
|
export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstruct").Struct<{
|
|
188
|
-
|
|
188
|
+
getInterface: Function;
|
|
189
189
|
notifications: {
|
|
190
|
-
type: "
|
|
191
|
-
message: string;
|
|
190
|
+
type: "inApp" | "native";
|
|
192
191
|
id: string;
|
|
193
|
-
|
|
192
|
+
message: string;
|
|
194
193
|
title?: string | undefined;
|
|
194
|
+
content?: string | undefined;
|
|
195
195
|
footerLink?: {
|
|
196
196
|
text: string;
|
|
197
197
|
href: string;
|
|
198
198
|
} | undefined;
|
|
199
199
|
}[];
|
|
200
|
+
id: string;
|
|
200
201
|
response: {
|
|
201
202
|
result: import("@metamask/snaps-sdk").Json;
|
|
202
203
|
} | {
|
|
203
204
|
error: import("@metamask/snaps-sdk").Json;
|
|
204
205
|
};
|
|
205
|
-
getInterface: Function;
|
|
206
206
|
}, {
|
|
207
207
|
getInterface: import("@metamask/superstruct").Struct<Function, null>;
|
|
208
|
-
id: import("@metamask/superstruct").Struct<string, null>;
|
|
209
208
|
notifications: import("@metamask/superstruct").Struct<{
|
|
210
|
-
type: "
|
|
211
|
-
message: string;
|
|
209
|
+
type: "inApp" | "native";
|
|
212
210
|
id: string;
|
|
213
|
-
|
|
211
|
+
message: string;
|
|
214
212
|
title?: string | undefined;
|
|
213
|
+
content?: string | undefined;
|
|
215
214
|
footerLink?: {
|
|
216
215
|
text: string;
|
|
217
216
|
href: string;
|
|
218
217
|
} | undefined;
|
|
219
218
|
}[], import("@metamask/superstruct").Struct<{
|
|
220
|
-
type: "
|
|
221
|
-
message: string;
|
|
219
|
+
type: "inApp" | "native";
|
|
222
220
|
id: string;
|
|
223
|
-
|
|
221
|
+
message: string;
|
|
224
222
|
title?: string | undefined;
|
|
223
|
+
content?: string | undefined;
|
|
225
224
|
footerLink?: {
|
|
226
225
|
text: string;
|
|
227
226
|
href: string;
|
|
@@ -229,7 +228,7 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
|
|
|
229
228
|
}, {
|
|
230
229
|
id: import("@metamask/superstruct").Struct<string, null>;
|
|
231
230
|
message: import("@metamask/superstruct").Struct<string, null>;
|
|
232
|
-
type: import("@metamask/superstruct").Struct<"
|
|
231
|
+
type: import("@metamask/superstruct").Struct<"inApp" | "native", null>;
|
|
233
232
|
title: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
234
233
|
content: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
235
234
|
footerLink: import("@metamask/superstruct").Struct<{
|
|
@@ -240,6 +239,7 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
|
|
|
240
239
|
text: import("@metamask/superstruct").Struct<string, null>;
|
|
241
240
|
}>;
|
|
242
241
|
}>>;
|
|
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,42 +247,42 @@ 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;
|
|
251
250
|
notifications: {
|
|
252
|
-
type: "
|
|
253
|
-
message: string;
|
|
251
|
+
type: "inApp" | "native";
|
|
254
252
|
id: string;
|
|
255
|
-
|
|
253
|
+
message: string;
|
|
256
254
|
title?: string | undefined;
|
|
255
|
+
content?: string | undefined;
|
|
257
256
|
footerLink?: {
|
|
258
257
|
text: string;
|
|
259
258
|
href: string;
|
|
260
259
|
} | undefined;
|
|
261
260
|
}[];
|
|
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
|
-
|
|
268
|
+
getInterface: Function;
|
|
269
269
|
notifications: {
|
|
270
|
-
type: "
|
|
271
|
-
message: string;
|
|
270
|
+
type: "inApp" | "native";
|
|
272
271
|
id: string;
|
|
273
|
-
|
|
272
|
+
message: string;
|
|
274
273
|
title?: string | undefined;
|
|
274
|
+
content?: string | undefined;
|
|
275
275
|
footerLink?: {
|
|
276
276
|
text: string;
|
|
277
277
|
href: string;
|
|
278
278
|
} | undefined;
|
|
279
279
|
}[];
|
|
280
|
+
id: string;
|
|
280
281
|
response: {
|
|
281
282
|
result: import("@metamask/snaps-sdk").Json;
|
|
282
283
|
} | {
|
|
283
284
|
error: import("@metamask/snaps-sdk").Json;
|
|
284
285
|
};
|
|
285
|
-
getInterface: Function;
|
|
286
286
|
}, null>;
|
|
287
287
|
/**
|
|
288
288
|
* Ensure that the actual response contains `getInterface`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-simulation",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -56,18 +56,18 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@metamask/base-controller": "^8.0.0",
|
|
59
|
-
"@metamask/eth-json-rpc-middleware": "^
|
|
59
|
+
"@metamask/eth-json-rpc-middleware": "^16.0.1",
|
|
60
60
|
"@metamask/json-rpc-engine": "^10.0.2",
|
|
61
61
|
"@metamask/json-rpc-middleware-stream": "^8.0.7",
|
|
62
|
-
"@metamask/key-tree": "^10.
|
|
62
|
+
"@metamask/key-tree": "^10.1.1",
|
|
63
63
|
"@metamask/permission-controller": "^11.0.6",
|
|
64
|
-
"@metamask/phishing-controller": "^12.4.
|
|
65
|
-
"@metamask/snaps-controllers": "^
|
|
66
|
-
"@metamask/snaps-execution-environments": "^7.
|
|
67
|
-
"@metamask/snaps-rpc-methods": "^
|
|
68
|
-
"@metamask/snaps-sdk": "^6.
|
|
69
|
-
"@metamask/snaps-utils": "^9.0
|
|
70
|
-
"@metamask/superstruct": "^3.1
|
|
64
|
+
"@metamask/phishing-controller": "^12.4.1",
|
|
65
|
+
"@metamask/snaps-controllers": "^11.2.0",
|
|
66
|
+
"@metamask/snaps-execution-environments": "^7.2.0",
|
|
67
|
+
"@metamask/snaps-rpc-methods": "^12.1.0",
|
|
68
|
+
"@metamask/snaps-sdk": "^6.22.0",
|
|
69
|
+
"@metamask/snaps-utils": "^9.2.0",
|
|
70
|
+
"@metamask/superstruct": "^3.2.1",
|
|
71
71
|
"@metamask/utils": "^11.2.0",
|
|
72
72
|
"@reduxjs/toolkit": "^1.9.5",
|
|
73
73
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@lavamoat/allow-scripts": "^3.0.4",
|
|
80
|
-
"@metamask/auto-changelog": "^
|
|
80
|
+
"@metamask/auto-changelog": "^5.0.1",
|
|
81
81
|
"@ts-bridge/cli": "^0.6.1",
|
|
82
82
|
"@types/express": "^4.17.17",
|
|
83
83
|
"@types/jest": "^27.5.1",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"deepmerge": "^4.2.2",
|
|
87
87
|
"depcheck": "^1.4.7",
|
|
88
88
|
"eslint": "^9.11.0",
|
|
89
|
-
"express": "^4.
|
|
89
|
+
"express": "^4.21.2",
|
|
90
90
|
"jest": "^29.0.2",
|
|
91
91
|
"jest-it-up": "^2.0.0",
|
|
92
92
|
"jest-silent-reporter": "^0.6.0",
|