@metamask/snaps-simulation 1.4.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -1
- package/dist/controllers.cjs.map +1 -1
- package/dist/controllers.d.cts +5 -4
- package/dist/controllers.d.cts.map +1 -1
- package/dist/controllers.d.mts +5 -4
- package/dist/controllers.d.mts.map +1 -1
- package/dist/controllers.mjs.map +1 -1
- package/dist/helpers.cjs +17 -0
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +15 -0
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +15 -0
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +17 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/interface.cjs +39 -1
- package/dist/interface.cjs.map +1 -1
- package/dist/interface.d.cts +12 -2
- package/dist/interface.d.cts.map +1 -1
- package/dist/interface.d.mts +12 -2
- package/dist/interface.d.mts.map +1 -1
- package/dist/interface.mjs +41 -0
- package/dist/interface.mjs.map +1 -1
- package/dist/methods/hooks/get-preferences.cjs +3 -2
- package/dist/methods/hooks/get-preferences.cjs.map +1 -1
- package/dist/methods/hooks/get-preferences.d.cts +3 -1
- package/dist/methods/hooks/get-preferences.d.cts.map +1 -1
- package/dist/methods/hooks/get-preferences.d.mts +3 -1
- package/dist/methods/hooks/get-preferences.d.mts.map +1 -1
- package/dist/methods/hooks/get-preferences.mjs +3 -2
- package/dist/methods/hooks/get-preferences.mjs.map +1 -1
- package/dist/methods/hooks/index.cjs +2 -1
- package/dist/methods/hooks/index.cjs.map +1 -1
- package/dist/methods/hooks/index.d.cts +2 -1
- package/dist/methods/hooks/index.d.cts.map +1 -1
- package/dist/methods/hooks/index.d.mts +2 -1
- package/dist/methods/hooks/index.d.mts.map +1 -1
- package/dist/methods/hooks/index.mjs +2 -1
- package/dist/methods/hooks/index.mjs.map +1 -1
- package/dist/methods/hooks/notifications.cjs +15 -2
- package/dist/methods/hooks/notifications.cjs.map +1 -1
- package/dist/methods/hooks/notifications.d.cts +13 -1
- package/dist/methods/hooks/notifications.d.cts.map +1 -1
- package/dist/methods/hooks/notifications.d.mts +13 -1
- package/dist/methods/hooks/notifications.d.mts.map +1 -1
- package/dist/methods/hooks/notifications.mjs +16 -3
- package/dist/methods/hooks/notifications.mjs.map +1 -1
- package/dist/methods/hooks/permitted/index.cjs +18 -0
- package/dist/methods/hooks/permitted/index.cjs.map +1 -0
- package/dist/methods/hooks/permitted/index.d.cts +2 -0
- package/dist/methods/hooks/permitted/index.d.cts.map +1 -0
- package/dist/methods/hooks/permitted/index.d.mts +2 -0
- package/dist/methods/hooks/permitted/index.d.mts.map +1 -0
- package/dist/methods/hooks/permitted/index.mjs +2 -0
- package/dist/methods/hooks/permitted/index.mjs.map +1 -0
- package/dist/methods/hooks/permitted/state.cjs +78 -0
- package/dist/methods/hooks/permitted/state.cjs.map +1 -0
- package/dist/methods/hooks/permitted/state.d.cts +24 -0
- package/dist/methods/hooks/permitted/state.d.cts.map +1 -0
- package/dist/methods/hooks/permitted/state.d.mts +24 -0
- package/dist/methods/hooks/permitted/state.d.mts.map +1 -0
- package/dist/methods/hooks/permitted/state.mjs +72 -0
- package/dist/methods/hooks/permitted/state.mjs.map +1 -0
- package/dist/methods/specifications.cjs.map +1 -1
- package/dist/methods/specifications.d.cts +1 -1
- package/dist/methods/specifications.d.cts.map +1 -1
- package/dist/methods/specifications.d.mts +1 -1
- package/dist/methods/specifications.d.mts.map +1 -1
- package/dist/methods/specifications.mjs.map +1 -1
- package/dist/middleware/engine.cjs +7 -4
- package/dist/middleware/engine.cjs.map +1 -1
- package/dist/middleware/engine.d.cts +6 -4
- package/dist/middleware/engine.d.cts.map +1 -1
- package/dist/middleware/engine.d.mts +6 -4
- package/dist/middleware/engine.d.mts.map +1 -1
- package/dist/middleware/engine.mjs +7 -4
- package/dist/middleware/engine.mjs.map +1 -1
- package/dist/options.cjs +1 -0
- package/dist/options.cjs.map +1 -1
- package/dist/options.d.cts +2 -0
- package/dist/options.d.cts.map +1 -1
- package/dist/options.d.mts +2 -0
- package/dist/options.d.mts.map +1 -1
- package/dist/options.mjs +2 -1
- package/dist/options.mjs.map +1 -1
- package/dist/request.cjs +8 -5
- package/dist/request.cjs.map +1 -1
- package/dist/request.d.cts +2 -1
- package/dist/request.d.cts.map +1 -1
- package/dist/request.d.mts +2 -1
- package/dist/request.d.mts.map +1 -1
- package/dist/request.mjs +8 -5
- package/dist/request.mjs.map +1 -1
- package/dist/simulation.cjs +30 -10
- package/dist/simulation.cjs.map +1 -1
- package/dist/simulation.d.cts +101 -13
- package/dist/simulation.d.cts.map +1 -1
- package/dist/simulation.d.mts +101 -13
- package/dist/simulation.d.mts.map +1 -1
- package/dist/simulation.mjs +28 -9
- package/dist/simulation.mjs.map +1 -1
- package/dist/store/notifications.cjs.map +1 -1
- package/dist/store/notifications.d.cts +9 -0
- package/dist/store/notifications.d.cts.map +1 -1
- package/dist/store/notifications.d.mts +9 -0
- package/dist/store/notifications.d.mts.map +1 -1
- package/dist/store/notifications.mjs.map +1 -1
- package/dist/store/ui.cjs.map +1 -1
- package/dist/store/ui.d.cts +1 -1
- package/dist/store/ui.d.cts.map +1 -1
- package/dist/store/ui.d.mts +1 -1
- package/dist/store/ui.d.mts.map +1 -1
- package/dist/store/ui.mjs.map +1 -1
- package/dist/structs.cjs +6 -0
- package/dist/structs.cjs.map +1 -1
- package/dist/structs.d.cts +66 -0
- package/dist/structs.d.cts.map +1 -1
- package/dist/structs.d.mts +66 -0
- package/dist/structs.d.mts.map +1 -1
- package/dist/structs.mjs +6 -0
- package/dist/structs.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +25 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +25 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +15 -14
package/dist/simulation.mjs.map
CHANGED
|
@@ -1 +1 @@
|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AgB,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 { ControllerMessenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport {\n type CryptographicFunctions,\n mnemonicPhraseToBytes,\n} 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} 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 { getEndowments } from './methods';\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 (...args: any[]) => InstanceType<\n 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: ControllerMessenger<ActionConstraint, EventConstraint>;\n runSaga: RunSagaFunction;\n};\n\nexport type MiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * A hook that returns the Snap's auxiliary file for the given path.\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 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 createInterface: (\n content: Component,\n context?: InterfaceContext,\n ) => Promise<string>;\n updateInterface: (id: string, content: Component) => Promise<void>;\n getInterfaceState: (id: string) => InterfaceState;\n getInterfaceContext: (id: string) => InterfaceContext | null;\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 (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\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 ControllerMessenger<any, any>();\n\n registerActions(controllerMessenger, runSaga);\n\n // Set up controllers and JSON-RPC stack.\n const hooks = getHooks(options, snapFiles, snapId, controllerMessenger);\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n hooks,\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 * @param snapFiles - The Snap files.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The hooks for the simulation.\n */\nexport function getHooks(\n options: SimulationOptions,\n snapFiles: FetchedSnapFiles,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): MiddlewareHooks {\n return {\n getMnemonic: async () =>\n Promise.resolve(mnemonicPhraseToBytes(options.secretRecoveryPhrase)),\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\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}\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,mBAAmB,EAAE,kCAAkC;AAChE,OAAO,EAAE,kBAAkB,EAAE,6CAA6C;AAC1E,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ACvC,+BAA+B,EAC/B,GAAG,EAAE,CAAC,CAAC,EAAE,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 { ControllerMessenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport {\n type CryptographicFunctions,\n mnemonicPhraseToBytes,\n} 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} 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} 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 (...args: any[]) => InstanceType<\n 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: ControllerMessenger<ActionConstraint, EventConstraint>;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n};\n\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 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 (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\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 ControllerMessenger<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: async () =>\n Promise.resolve(mnemonicPhraseToBytes(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 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.cjs","sourceRoot":"","sources":["../../src/store/notifications.ts"],"names":[],"mappings":";;;;AAEA,8CAA+D;
|
|
1
|
+
{"version":3,"file":"notifications.cjs","sourceRoot":"","sources":["../../src/store/notifications.ts"],"names":[],"mappings":";;;;AAEA,8CAA+D;AAgC/D;;GAEG;AACH,MAAM,aAAa,GAAuB;IACxC,aAAa,EAAE,EAAE;CAClB,CAAC;AAEW,QAAA,kBAAkB,GAAG,IAAA,qBAAW,EAAC;IAC5C,IAAI,EAAE,eAAe;IACrB,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,eAAe,EAAE,CAAC,KAAK,EAAE,MAAmC,EAAE,EAAE;YAC9D,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3C,CAAC;QACD,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAA6B,EAAE,EAAE;YAC3D,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,MAAM,CAC9C,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CACrD,CAAC;QACJ,CAAC;QACD,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE;YAC5B,KAAK,CAAC,aAAa,GAAG,EAAE,CAAC;QAC3B,CAAC;KACF;CACF,CAAC,CAAC;AAEU,KACX,0BAAkB,CAAC,OAAO,EADb,uBAAe,uBAAE,0BAAkB,0BAAE,0BAAkB,yBACzC;AAE7B;;;;;GAKG;AACU,QAAA,gBAAgB,GAAG,IAAA,wBAAc,EAC5C,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,EAChD,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC,aAAa,CACrC,CAAC","sourcesContent":["import type { NotificationType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\n/**\n * A notification object.\n *\n * @property id - A unique ID for the notification.\n * @property message - The notification message.\n * @property type - The notification type.\n * @property title - The notification title (expanded view).\n * @property content - The notification JSX content (expanded view).\n * @property footerLink - The notification footer (expanded view).\n */\nexport type Notification = {\n id: string;\n message: string;\n type: NotificationType;\n title?: string;\n content?: string;\n footerLink?: { text: string; href: string };\n};\n\n/**\n * The notifications state.\n *\n * @property notifications - An array of notifications.\n */\nexport type NotificationsState = {\n notifications: Notification[];\n};\n\n/**\n * The initial notifications state.\n */\nconst INITIAL_STATE: NotificationsState = {\n notifications: [],\n};\n\nexport const notificationsSlice = createSlice({\n name: 'notifications',\n initialState: INITIAL_STATE,\n reducers: {\n addNotification: (state, action: PayloadAction<Notification>) => {\n state.notifications.push(action.payload);\n },\n removeNotification: (state, action: PayloadAction<string>) => {\n state.notifications = state.notifications.filter(\n (notification) => notification.id !== action.payload,\n );\n },\n clearNotifications: (state) => {\n state.notifications = [];\n },\n },\n});\n\nexport const { addNotification, removeNotification, clearNotifications } =\n notificationsSlice.actions;\n\n/**\n * Get the notifications from the state.\n *\n * @param state - The application state.\n * @returns An array of notifications.\n */\nexport const getNotifications = createSelector(\n (state: ApplicationState) => state.notifications,\n ({ notifications }) => notifications,\n);\n"]}
|
|
@@ -6,11 +6,20 @@ import type { PayloadAction } from "@reduxjs/toolkit";
|
|
|
6
6
|
* @property id - A unique ID for the notification.
|
|
7
7
|
* @property message - The notification message.
|
|
8
8
|
* @property type - The notification type.
|
|
9
|
+
* @property title - The notification title (expanded view).
|
|
10
|
+
* @property content - The notification JSX content (expanded view).
|
|
11
|
+
* @property footerLink - The notification footer (expanded view).
|
|
9
12
|
*/
|
|
10
13
|
export type Notification = {
|
|
11
14
|
id: string;
|
|
12
15
|
message: string;
|
|
13
16
|
type: NotificationType;
|
|
17
|
+
title?: string;
|
|
18
|
+
content?: string;
|
|
19
|
+
footerLink?: {
|
|
20
|
+
text: string;
|
|
21
|
+
href: string;
|
|
22
|
+
};
|
|
14
23
|
};
|
|
15
24
|
/**
|
|
16
25
|
* The notifications state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.d.cts","sourceRoot":"","sources":["../../src/store/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,4BAA4B;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAKtD
|
|
1
|
+
{"version":3,"file":"notifications.d.cts","sourceRoot":"","sources":["../../src/store/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,4BAA4B;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAKtD;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B,CAAC;AASF,eAAO,MAAM,kBAAkB;yGAIM,cAAc,YAAY,CAAC;4GAGxB,cAAc,MAAM,CAAC;;mBAS3D,CAAC;AAEH,eAAO,MAAQ,eAAe,sGAAE,kBAAkB,mGAAE,kBAAkB,4FAC1C,CAAC;AAE7B;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;CAG5B,CAAC"}
|
|
@@ -6,11 +6,20 @@ import type { PayloadAction } from "@reduxjs/toolkit";
|
|
|
6
6
|
* @property id - A unique ID for the notification.
|
|
7
7
|
* @property message - The notification message.
|
|
8
8
|
* @property type - The notification type.
|
|
9
|
+
* @property title - The notification title (expanded view).
|
|
10
|
+
* @property content - The notification JSX content (expanded view).
|
|
11
|
+
* @property footerLink - The notification footer (expanded view).
|
|
9
12
|
*/
|
|
10
13
|
export type Notification = {
|
|
11
14
|
id: string;
|
|
12
15
|
message: string;
|
|
13
16
|
type: NotificationType;
|
|
17
|
+
title?: string;
|
|
18
|
+
content?: string;
|
|
19
|
+
footerLink?: {
|
|
20
|
+
text: string;
|
|
21
|
+
href: string;
|
|
22
|
+
};
|
|
14
23
|
};
|
|
15
24
|
/**
|
|
16
25
|
* The notifications state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.d.mts","sourceRoot":"","sources":["../../src/store/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,4BAA4B;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAKtD
|
|
1
|
+
{"version":3,"file":"notifications.d.mts","sourceRoot":"","sources":["../../src/store/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,4BAA4B;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAKtD;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B,CAAC;AASF,eAAO,MAAM,kBAAkB;yGAIM,cAAc,YAAY,CAAC;4GAGxB,cAAc,MAAM,CAAC;;mBAS3D,CAAC;AAEH,eAAO,MAAQ,eAAe,sGAAE,kBAAkB,mGAAE,kBAAkB,4FAC1C,CAAC;AAE7B;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;CAG5B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.mjs","sourceRoot":"","sources":["../../src/store/notifications.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"notifications.mjs","sourceRoot":"","sources":["../../src/store/notifications.ts"],"names":[],"mappings":";;AAkCA;;GAEG;AACH,MAAM,aAAa,GAAuB;IACxC,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;IAC5C,IAAI,EAAE,eAAe;IACrB,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,eAAe,EAAE,CAAC,KAAK,EAAE,MAAmC,EAAE,EAAE;YAC9D,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3C,CAAC;QACD,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAA6B,EAAE,EAAE;YAC3D,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,MAAM,CAC9C,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CACrD,CAAC;QACJ,CAAC;QACD,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE;YAC5B,KAAK,CAAC,aAAa,GAAG,EAAE,CAAC;QAC3B,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,GACtE,kBAAkB,CAAC,OAAO,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAC5C,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,EAChD,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC,aAAa,CACrC,CAAC","sourcesContent":["import type { NotificationType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\n/**\n * A notification object.\n *\n * @property id - A unique ID for the notification.\n * @property message - The notification message.\n * @property type - The notification type.\n * @property title - The notification title (expanded view).\n * @property content - The notification JSX content (expanded view).\n * @property footerLink - The notification footer (expanded view).\n */\nexport type Notification = {\n id: string;\n message: string;\n type: NotificationType;\n title?: string;\n content?: string;\n footerLink?: { text: string; href: string };\n};\n\n/**\n * The notifications state.\n *\n * @property notifications - An array of notifications.\n */\nexport type NotificationsState = {\n notifications: Notification[];\n};\n\n/**\n * The initial notifications state.\n */\nconst INITIAL_STATE: NotificationsState = {\n notifications: [],\n};\n\nexport const notificationsSlice = createSlice({\n name: 'notifications',\n initialState: INITIAL_STATE,\n reducers: {\n addNotification: (state, action: PayloadAction<Notification>) => {\n state.notifications.push(action.payload);\n },\n removeNotification: (state, action: PayloadAction<string>) => {\n state.notifications = state.notifications.filter(\n (notification) => notification.id !== action.payload,\n );\n },\n clearNotifications: (state) => {\n state.notifications = [];\n },\n },\n});\n\nexport const { addNotification, removeNotification, clearNotifications } =\n notificationsSlice.actions;\n\n/**\n * Get the notifications from the state.\n *\n * @param state - The application state.\n * @returns An array of notifications.\n */\nexport const getNotifications = createSelector(\n (state: ApplicationState) => state.notifications,\n ({ notifications }) => notifications,\n);\n"]}
|
package/dist/store/ui.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.cjs","sourceRoot":"","sources":["../../src/store/ui.ts"],"names":[],"mappings":";;;;AAGA,8CAA6E;AAa7E,MAAM,aAAa,GAAY;IAC7B,OAAO,EAAE,IAAI;CACd,CAAC;AAEW,QAAA,OAAO,GAAG,IAAA,qBAAW,EAAC;IACjC,IAAI,EAAE,IAAI;IACV,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,YAAY,CAAC,KAAK,EAAE,MAAgC;YAClD,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,cAAc,CAAC,KAAK;YAClB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;QACvB,CAAC;KACF;CACF,CAAC,CAAC;AAEU,QAAA,gBAAgB,GAAG,IAAA,sBAAY,EAC1C,GAAG,eAAO,CAAC,IAAI,mBAAmB,CACnC,CAAC;AAEW,KAAmC,eAAO,CAAC,OAAO,EAAhD,oBAAY,oBAAE,sBAAc,qBAAqB;AAEnD,QAAA,mBAAmB,GAAG,IAAA,wBAAc,EAC/C,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,EACrC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CACnB,CAAC","sourcesContent":["import type { DialogApprovalTypes } from '@metamask/snaps-rpc-methods';\nimport type { DialogType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createAction, createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\nexport type Interface = {\n type: DialogApprovalTypes[DialogType | 'default'];\n id: string;\n};\n\nexport type UiState = {\n current?: Interface | null;\n};\n\nconst INITIAL_STATE: UiState = {\n current: null,\n};\n\nexport const uiSlice = createSlice({\n name: 'ui',\n initialState: INITIAL_STATE,\n reducers: {\n setInterface(state, action: PayloadAction<Interface>) {\n state.current = action.payload;\n },\n closeInterface(state) {\n state.current = null;\n },\n },\n});\n\nexport const resolveInterface = createAction<unknown>(\n `${uiSlice.name}/resolveInterface`,\n);\n\nexport const { setInterface, closeInterface } = uiSlice.actions;\n\nexport const getCurrentInterface = createSelector(\n (state: ApplicationState) => state.ui,\n (ui) => ui.current,\n);\n"]}
|
|
1
|
+
{"version":3,"file":"ui.cjs","sourceRoot":"","sources":["../../src/store/ui.ts"],"names":[],"mappings":";;;;AAGA,8CAA6E;AAa7E,MAAM,aAAa,GAAY;IAC7B,OAAO,EAAE,IAAI;CACd,CAAC;AAEW,QAAA,OAAO,GAAG,IAAA,qBAAW,EAAC;IACjC,IAAI,EAAE,IAAI;IACV,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,YAAY,CAAC,KAAK,EAAE,MAAgC;YAClD,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,cAAc,CAAC,KAAK;YAClB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;QACvB,CAAC;KACF;CACF,CAAC,CAAC;AAEU,QAAA,gBAAgB,GAAG,IAAA,sBAAY,EAC1C,GAAG,eAAO,CAAC,IAAI,mBAAmB,CACnC,CAAC;AAEW,KAAmC,eAAO,CAAC,OAAO,EAAhD,oBAAY,oBAAE,sBAAc,qBAAqB;AAEnD,QAAA,mBAAmB,GAAG,IAAA,wBAAc,EAC/C,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,EACrC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CACnB,CAAC","sourcesContent":["import type { DialogApprovalTypes } from '@metamask/snaps-rpc-methods';\nimport type { DialogType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createAction, createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\nexport type Interface = {\n type: DialogApprovalTypes[DialogType | 'default'] | 'Notification';\n id: string;\n};\n\nexport type UiState = {\n current?: Interface | null;\n};\n\nconst INITIAL_STATE: UiState = {\n current: null,\n};\n\nexport const uiSlice = createSlice({\n name: 'ui',\n initialState: INITIAL_STATE,\n reducers: {\n setInterface(state, action: PayloadAction<Interface>) {\n state.current = action.payload;\n },\n closeInterface(state) {\n state.current = null;\n },\n },\n});\n\nexport const resolveInterface = createAction<unknown>(\n `${uiSlice.name}/resolveInterface`,\n);\n\nexport const { setInterface, closeInterface } = uiSlice.actions;\n\nexport const getCurrentInterface = createSelector(\n (state: ApplicationState) => state.ui,\n (ui) => ui.current,\n);\n"]}
|
package/dist/store/ui.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import type { DialogApprovalTypes } from "@metamask/snaps-rpc-methods";
|
|
|
2
2
|
import type { DialogType } from "@metamask/snaps-sdk";
|
|
3
3
|
import type { PayloadAction } from "@reduxjs/toolkit";
|
|
4
4
|
export type Interface = {
|
|
5
|
-
type: DialogApprovalTypes[DialogType | 'default'];
|
|
5
|
+
type: DialogApprovalTypes[DialogType | 'default'] | 'Notification';
|
|
6
6
|
id: string;
|
|
7
7
|
};
|
|
8
8
|
export type UiState = {
|
package/dist/store/ui.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.d.cts","sourceRoot":"","sources":["../../src/store/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,4BAA4B;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAKtD,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,mBAAmB,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ui.d.cts","sourceRoot":"","sources":["../../src/store/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,4BAA4B;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAKtD,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,mBAAmB,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,cAAc,CAAC;IACnE,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CAC5B,CAAC;AAMF,eAAO,MAAM,OAAO;yFAIY,cAAc,SAAS,CAAC;;QAOtD,CAAC;AAEH,eAAO,MAAM,gBAAgB,0EAE5B,CAAC;AAEF,eAAO,MAAQ,YAAY,qFAAE,cAAc,6EAAoB,CAAC;AAEhE,eAAO,MAAM,mBAAmB;;;;;;;;;CAG/B,CAAC"}
|
package/dist/store/ui.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import type { DialogApprovalTypes } from "@metamask/snaps-rpc-methods";
|
|
|
2
2
|
import type { DialogType } from "@metamask/snaps-sdk";
|
|
3
3
|
import type { PayloadAction } from "@reduxjs/toolkit";
|
|
4
4
|
export type Interface = {
|
|
5
|
-
type: DialogApprovalTypes[DialogType | 'default'];
|
|
5
|
+
type: DialogApprovalTypes[DialogType | 'default'] | 'Notification';
|
|
6
6
|
id: string;
|
|
7
7
|
};
|
|
8
8
|
export type UiState = {
|
package/dist/store/ui.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.d.mts","sourceRoot":"","sources":["../../src/store/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,4BAA4B;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAKtD,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,mBAAmB,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ui.d.mts","sourceRoot":"","sources":["../../src/store/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,4BAA4B;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB;AAKtD,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,mBAAmB,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,cAAc,CAAC;IACnE,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CAC5B,CAAC;AAMF,eAAO,MAAM,OAAO;yFAIY,cAAc,SAAS,CAAC;;QAOtD,CAAC;AAEH,eAAO,MAAM,gBAAgB,0EAE5B,CAAC;AAEF,eAAO,MAAQ,YAAY,qFAAE,cAAc,6EAAoB,CAAC;AAEhE,eAAO,MAAM,mBAAmB;;;;;;;;;CAG/B,CAAC"}
|
package/dist/store/ui.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.mjs","sourceRoot":"","sources":["../../src/store/ui.ts"],"names":[],"mappings":";;AAgBA,MAAM,aAAa,GAAY;IAC7B,OAAO,EAAE,IAAI;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,WAAW,CAAC;IACjC,IAAI,EAAE,IAAI;IACV,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,YAAY,CAAC,KAAK,EAAE,MAAgC;YAClD,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,cAAc,CAAC,KAAK;YAClB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;QACvB,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAC1C,GAAG,OAAO,CAAC,IAAI,mBAAmB,CACnC,CAAC;AAEF,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;AAEhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,cAAc,CAC/C,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,EACrC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CACnB,CAAC","sourcesContent":["import type { DialogApprovalTypes } from '@metamask/snaps-rpc-methods';\nimport type { DialogType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createAction, createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\nexport type Interface = {\n type: DialogApprovalTypes[DialogType | 'default'];\n id: string;\n};\n\nexport type UiState = {\n current?: Interface | null;\n};\n\nconst INITIAL_STATE: UiState = {\n current: null,\n};\n\nexport const uiSlice = createSlice({\n name: 'ui',\n initialState: INITIAL_STATE,\n reducers: {\n setInterface(state, action: PayloadAction<Interface>) {\n state.current = action.payload;\n },\n closeInterface(state) {\n state.current = null;\n },\n },\n});\n\nexport const resolveInterface = createAction<unknown>(\n `${uiSlice.name}/resolveInterface`,\n);\n\nexport const { setInterface, closeInterface } = uiSlice.actions;\n\nexport const getCurrentInterface = createSelector(\n (state: ApplicationState) => state.ui,\n (ui) => ui.current,\n);\n"]}
|
|
1
|
+
{"version":3,"file":"ui.mjs","sourceRoot":"","sources":["../../src/store/ui.ts"],"names":[],"mappings":";;AAgBA,MAAM,aAAa,GAAY;IAC7B,OAAO,EAAE,IAAI;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,WAAW,CAAC;IACjC,IAAI,EAAE,IAAI;IACV,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,YAAY,CAAC,KAAK,EAAE,MAAgC;YAClD,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,cAAc,CAAC,KAAK;YAClB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;QACvB,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAC1C,GAAG,OAAO,CAAC,IAAI,mBAAmB,CACnC,CAAC;AAEF,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;AAEhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,cAAc,CAC/C,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,EACrC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CACnB,CAAC","sourcesContent":["import type { DialogApprovalTypes } from '@metamask/snaps-rpc-methods';\nimport type { DialogType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createAction, createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\nexport type Interface = {\n type: DialogApprovalTypes[DialogType | 'default'] | 'Notification';\n id: string;\n};\n\nexport type UiState = {\n current?: Interface | null;\n};\n\nconst INITIAL_STATE: UiState = {\n current: null,\n};\n\nexport const uiSlice = createSlice({\n name: 'ui',\n initialState: INITIAL_STATE,\n reducers: {\n setInterface(state, action: PayloadAction<Interface>) {\n state.current = action.payload;\n },\n closeInterface(state) {\n state.current = null;\n },\n },\n});\n\nexport const resolveInterface = createAction<unknown>(\n `${uiSlice.name}/resolveInterface`,\n);\n\nexport const { setInterface, closeInterface } = uiSlice.actions;\n\nexport const getCurrentInterface = createSelector(\n (state: ApplicationState) => state.ui,\n (ui) => ui.current,\n);\n"]}
|
package/dist/structs.cjs
CHANGED
|
@@ -164,6 +164,12 @@ exports.SnapResponseWithoutInterfaceStruct = (0, superstruct_1.object)({
|
|
|
164
164
|
(0, snaps_sdk_1.enumValue)(snaps_sdk_1.NotificationType.InApp),
|
|
165
165
|
(0, snaps_sdk_1.enumValue)(snaps_sdk_1.NotificationType.Native),
|
|
166
166
|
]),
|
|
167
|
+
title: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
168
|
+
content: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
169
|
+
footerLink: (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
170
|
+
href: (0, superstruct_1.string)(),
|
|
171
|
+
text: (0, superstruct_1.string)(),
|
|
172
|
+
})),
|
|
167
173
|
})),
|
|
168
174
|
});
|
|
169
175
|
exports.SnapResponseWithInterfaceStruct = (0, superstruct_1.assign)(exports.SnapResponseWithoutInterfaceStruct, (0, superstruct_1.object)({
|
package/dist/structs.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structs.cjs","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAClE,iDAA2D;AAC3D,uDAiB+B;AAC/B,2CAMyB;AACzB,mCAAqC;AAIrC,oDAAoD;AACpD,MAAM,eAAe,GAAG,IAAA,mBAAK,EAAC;IAC5B,IAA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,CAAC;KACH,CAAC,CACH;CACF,CAAC,CAAC;AAEU,QAAA,+BAA+B,GAAG,IAAA,oBAAM,EACnD,0CAAkC,EAClC,IAAA,oBAAM,EAAC;IACL,YAAY,EAAE,IAAA,kBAAI,GAAE;CACrB,CAAC,CACH,CAAC;AAEW,QAAA,kBAAkB,GAAG,IAAA,mBAAK,EAAC;IACtC,0CAAkC;IAClC,uCAA+B;CAChC,CAAC,CAAC;AAEH;;;;GAIG;AACH,SAAgB,6BAA6B,CAC3C,QAAsB;IAEtB,IAAA,oBAAY,EAAC,QAAQ,EAAE,uCAA+B,CAAC,CAAC;AAC1D,CAAC;AAJD,sEAIC","sourcesContent":["import { NotificationType, enumValue } from '@metamask/snaps-sdk';\nimport { JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n union,\n record,\n any,\n func,\n type,\n} from '@metamask/superstruct';\nimport {\n assertStruct,\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\n\nimport type { SnapResponse, SnapResponseWithInterface } from './types';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SignatureOptionsStruct = object({\n /**\n * The origin making the signature request.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address signing the signature request. Defaults to a randomly generated\n * address.\n */\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `string`, an object, or an array of objects. This covers the data types\n * for the supported signature methods. Defaults to `0x`.\n */\n data: defaulted(\n union([\n StrictHexStruct,\n literal('0x'),\n record(string(), any()),\n array(record(string(), any())),\n ]),\n '0x',\n ),\n\n /**\n * The signature method being used.\n */\n signatureMethod: defaulted(\n union([\n literal('personal_sign'),\n literal('eth_signTypedData'),\n literal('eth_signTypedData_v3'),\n literal('eth_signTypedData_v4'),\n ]),\n 'personal_sign',\n ),\n});\n\nexport const BaseNameLookupOptionsStruct = object({\n /**\n * The CAIP-2 chain ID. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n});\n\nexport const NameLookupOptionsStruct = union([\n assign(\n BaseNameLookupOptionsStruct,\n object({\n /**\n * Address to lookup.\n */\n address: string(),\n }),\n ),\n assign(\n BaseNameLookupOptionsStruct,\n object({\n /**\n * Domain name to lookup.\n */\n domain: string(),\n }),\n ),\n]);\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const JsonRpcMockOptionsStruct = object({\n method: string(),\n result: JsonStruct,\n});\n\nexport const InterfaceStruct = type({\n content: optional(JSXElementStruct),\n});\n\nexport const SnapResponseWithoutInterfaceStruct = object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n});\n\nexport const SnapResponseWithInterfaceStruct = assign(\n SnapResponseWithoutInterfaceStruct,\n object({\n getInterface: func(),\n }),\n);\n\nexport const SnapResponseStruct = union([\n SnapResponseWithoutInterfaceStruct,\n SnapResponseWithInterfaceStruct,\n]);\n\n/**\n * Ensure that the actual response contains `getInterface`.\n *\n * @param response - The response of the handler.\n */\nexport function assertIsResponseWithInterface(\n response: SnapResponse,\n): asserts response is SnapResponseWithInterface {\n assertStruct(response, SnapResponseWithInterfaceStruct);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"structs.cjs","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAClE,iDAA2D;AAC3D,uDAiB+B;AAC/B,2CAMyB;AACzB,mCAAqC;AAIrC,oDAAoD;AACpD,MAAM,eAAe,GAAG,IAAA,mBAAK,EAAC;IAC5B,IAAA,oBAAM,GAAE;IACR,IAAA,oBAAM,GAAE;IACR,IAAA,oBAAM,GAAE;IACR,IAAA,sBAAQ,EAAC,UAAU,CAAC;CACrB,CAAC,CAAC;AAEU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC;IAC7C;;OAEG;IACH,OAAO,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,UAAU,CAAC;IAExC;;OAEG;IACH,MAAM,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,aAAa,CAAC;IAE1C;;;OAGG;IACH,gDAAgD;IAChD,IAAI,EAAE,IAAA,oBAAM,EAAC,uBAAe,EAAE,IAAA,sBAAQ,EAAC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;QACjE,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,IAAA,kBAAU,EAAC,IAAA,oBAAY,EAAC,KAAK,CAAC,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,IAAA,kBAAU,EAAC,IAAA,oBAAW,EAAC,EAAE,C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;AAC1D,CAAC;AAJD,sEAIC","sourcesContent":["import { NotificationType, enumValue } from '@metamask/snaps-sdk';\nimport { JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n union,\n record,\n any,\n func,\n type,\n} from '@metamask/superstruct';\nimport {\n assertStruct,\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\n\nimport type { SnapResponse, SnapResponseWithInterface } from './types';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SignatureOptionsStruct = object({\n /**\n * The origin making the signature request.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address signing the signature request. Defaults to a randomly generated\n * address.\n */\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `string`, an object, or an array of objects. This covers the data types\n * for the supported signature methods. Defaults to `0x`.\n */\n data: defaulted(\n union([\n StrictHexStruct,\n literal('0x'),\n record(string(), any()),\n array(record(string(), any())),\n ]),\n '0x',\n ),\n\n /**\n * The signature method being used.\n */\n signatureMethod: defaulted(\n union([\n literal('personal_sign'),\n literal('eth_signTypedData'),\n literal('eth_signTypedData_v3'),\n literal('eth_signTypedData_v4'),\n ]),\n 'personal_sign',\n ),\n});\n\nexport const BaseNameLookupOptionsStruct = object({\n /**\n * The CAIP-2 chain ID. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n});\n\nexport const NameLookupOptionsStruct = union([\n assign(\n BaseNameLookupOptionsStruct,\n object({\n /**\n * Address to lookup.\n */\n address: string(),\n }),\n ),\n assign(\n BaseNameLookupOptionsStruct,\n object({\n /**\n * Domain name to lookup.\n */\n domain: string(),\n }),\n ),\n]);\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const JsonRpcMockOptionsStruct = object({\n method: string(),\n result: JsonStruct,\n});\n\nexport const InterfaceStruct = type({\n content: optional(JSXElementStruct),\n});\n\nexport const SnapResponseWithoutInterfaceStruct = object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n title: optional(string()),\n content: optional(string()),\n footerLink: optional(\n object({\n href: string(),\n text: string(),\n }),\n ),\n }),\n ),\n});\n\nexport const SnapResponseWithInterfaceStruct = assign(\n SnapResponseWithoutInterfaceStruct,\n object({\n getInterface: func(),\n }),\n);\n\nexport const SnapResponseStruct = union([\n SnapResponseWithoutInterfaceStruct,\n SnapResponseWithInterfaceStruct,\n]);\n\n/**\n * Ensure that the actual response contains `getInterface`.\n *\n * @param response - The response of the handler.\n */\nexport function assertIsResponseWithInterface(\n response: SnapResponse,\n): asserts response is SnapResponseWithInterface {\n assertStruct(response, SnapResponseWithInterfaceStruct);\n}\n"]}
|
package/dist/structs.d.cts
CHANGED
|
@@ -130,6 +130,12 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
|
|
|
130
130
|
type: "native" | "inApp";
|
|
131
131
|
message: string;
|
|
132
132
|
id: string;
|
|
133
|
+
content?: string | undefined;
|
|
134
|
+
title?: string | undefined;
|
|
135
|
+
footerLink?: {
|
|
136
|
+
text: string;
|
|
137
|
+
href: string;
|
|
138
|
+
} | undefined;
|
|
133
139
|
}[];
|
|
134
140
|
response: {
|
|
135
141
|
result: import("@metamask/snaps-sdk").Json;
|
|
@@ -147,14 +153,35 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
|
|
|
147
153
|
type: "native" | "inApp";
|
|
148
154
|
message: string;
|
|
149
155
|
id: string;
|
|
156
|
+
content?: string | undefined;
|
|
157
|
+
title?: string | undefined;
|
|
158
|
+
footerLink?: {
|
|
159
|
+
text: string;
|
|
160
|
+
href: string;
|
|
161
|
+
} | undefined;
|
|
150
162
|
}[], import("@metamask/superstruct").Struct<{
|
|
151
163
|
type: "native" | "inApp";
|
|
152
164
|
message: string;
|
|
153
165
|
id: string;
|
|
166
|
+
content?: string | undefined;
|
|
167
|
+
title?: string | undefined;
|
|
168
|
+
footerLink?: {
|
|
169
|
+
text: string;
|
|
170
|
+
href: string;
|
|
171
|
+
} | undefined;
|
|
154
172
|
}, {
|
|
155
173
|
id: import("@metamask/superstruct").Struct<string, null>;
|
|
156
174
|
message: import("@metamask/superstruct").Struct<string, null>;
|
|
157
175
|
type: import("@metamask/superstruct").Struct<"native" | "inApp", null>;
|
|
176
|
+
title: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
177
|
+
content: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
178
|
+
footerLink: import("@metamask/superstruct").Struct<{
|
|
179
|
+
text: string;
|
|
180
|
+
href: string;
|
|
181
|
+
} | undefined, {
|
|
182
|
+
href: import("@metamask/superstruct").Struct<string, null>;
|
|
183
|
+
text: import("@metamask/superstruct").Struct<string, null>;
|
|
184
|
+
}>;
|
|
158
185
|
}>>;
|
|
159
186
|
}>;
|
|
160
187
|
export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstruct").Struct<{
|
|
@@ -163,6 +190,12 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
|
|
|
163
190
|
type: "native" | "inApp";
|
|
164
191
|
message: string;
|
|
165
192
|
id: string;
|
|
193
|
+
content?: string | undefined;
|
|
194
|
+
title?: string | undefined;
|
|
195
|
+
footerLink?: {
|
|
196
|
+
text: string;
|
|
197
|
+
href: string;
|
|
198
|
+
} | undefined;
|
|
166
199
|
}[];
|
|
167
200
|
response: {
|
|
168
201
|
result: import("@metamask/snaps-sdk").Json;
|
|
@@ -177,14 +210,35 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
|
|
|
177
210
|
type: "native" | "inApp";
|
|
178
211
|
message: string;
|
|
179
212
|
id: string;
|
|
213
|
+
content?: string | undefined;
|
|
214
|
+
title?: string | undefined;
|
|
215
|
+
footerLink?: {
|
|
216
|
+
text: string;
|
|
217
|
+
href: string;
|
|
218
|
+
} | undefined;
|
|
180
219
|
}[], import("@metamask/superstruct").Struct<{
|
|
181
220
|
type: "native" | "inApp";
|
|
182
221
|
message: string;
|
|
183
222
|
id: string;
|
|
223
|
+
content?: string | undefined;
|
|
224
|
+
title?: string | undefined;
|
|
225
|
+
footerLink?: {
|
|
226
|
+
text: string;
|
|
227
|
+
href: string;
|
|
228
|
+
} | undefined;
|
|
184
229
|
}, {
|
|
185
230
|
id: import("@metamask/superstruct").Struct<string, null>;
|
|
186
231
|
message: import("@metamask/superstruct").Struct<string, null>;
|
|
187
232
|
type: import("@metamask/superstruct").Struct<"native" | "inApp", null>;
|
|
233
|
+
title: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
234
|
+
content: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
235
|
+
footerLink: import("@metamask/superstruct").Struct<{
|
|
236
|
+
text: string;
|
|
237
|
+
href: string;
|
|
238
|
+
} | undefined, {
|
|
239
|
+
href: import("@metamask/superstruct").Struct<string, null>;
|
|
240
|
+
text: import("@metamask/superstruct").Struct<string, null>;
|
|
241
|
+
}>;
|
|
188
242
|
}>>;
|
|
189
243
|
response: import("@metamask/superstruct").Struct<{
|
|
190
244
|
result: import("@metamask/snaps-sdk").Json;
|
|
@@ -198,6 +252,12 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
|
|
|
198
252
|
type: "native" | "inApp";
|
|
199
253
|
message: string;
|
|
200
254
|
id: string;
|
|
255
|
+
content?: string | undefined;
|
|
256
|
+
title?: string | undefined;
|
|
257
|
+
footerLink?: {
|
|
258
|
+
text: string;
|
|
259
|
+
href: string;
|
|
260
|
+
} | undefined;
|
|
201
261
|
}[];
|
|
202
262
|
response: {
|
|
203
263
|
result: import("@metamask/snaps-sdk").Json;
|
|
@@ -210,6 +270,12 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
|
|
|
210
270
|
type: "native" | "inApp";
|
|
211
271
|
message: string;
|
|
212
272
|
id: string;
|
|
273
|
+
content?: string | undefined;
|
|
274
|
+
title?: string | undefined;
|
|
275
|
+
footerLink?: {
|
|
276
|
+
text: string;
|
|
277
|
+
href: string;
|
|
278
|
+
} | undefined;
|
|
213
279
|
}[];
|
|
214
280
|
response: {
|
|
215
281
|
result: import("@metamask/snaps-sdk").Json;
|
package/dist/structs.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structs.d.cts","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAyB,EAAE,oBAAgB;AAUvE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;IACnC;;OAEG;;IAGH;;OAEG;;IAGH;;;OAGG;;IAUH;;;OAGG;;IAUH;;;OAGG;;IAQH;;;OAGG;;I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;;;;;;;;;;;EA8B7C,CAAC;AAEH,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAK3C,CAAC;AAEF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAG7B,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,QAAQ,IAAI,yBAAyB,CAE/C"}
|
package/dist/structs.d.mts
CHANGED
|
@@ -130,6 +130,12 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
|
|
|
130
130
|
type: "native" | "inApp";
|
|
131
131
|
message: string;
|
|
132
132
|
id: string;
|
|
133
|
+
content?: string | undefined;
|
|
134
|
+
title?: string | undefined;
|
|
135
|
+
footerLink?: {
|
|
136
|
+
text: string;
|
|
137
|
+
href: string;
|
|
138
|
+
} | undefined;
|
|
133
139
|
}[];
|
|
134
140
|
response: {
|
|
135
141
|
result: import("@metamask/snaps-sdk").Json;
|
|
@@ -147,14 +153,35 @@ export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/super
|
|
|
147
153
|
type: "native" | "inApp";
|
|
148
154
|
message: string;
|
|
149
155
|
id: string;
|
|
156
|
+
content?: string | undefined;
|
|
157
|
+
title?: string | undefined;
|
|
158
|
+
footerLink?: {
|
|
159
|
+
text: string;
|
|
160
|
+
href: string;
|
|
161
|
+
} | undefined;
|
|
150
162
|
}[], import("@metamask/superstruct").Struct<{
|
|
151
163
|
type: "native" | "inApp";
|
|
152
164
|
message: string;
|
|
153
165
|
id: string;
|
|
166
|
+
content?: string | undefined;
|
|
167
|
+
title?: string | undefined;
|
|
168
|
+
footerLink?: {
|
|
169
|
+
text: string;
|
|
170
|
+
href: string;
|
|
171
|
+
} | undefined;
|
|
154
172
|
}, {
|
|
155
173
|
id: import("@metamask/superstruct").Struct<string, null>;
|
|
156
174
|
message: import("@metamask/superstruct").Struct<string, null>;
|
|
157
175
|
type: import("@metamask/superstruct").Struct<"native" | "inApp", null>;
|
|
176
|
+
title: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
177
|
+
content: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
178
|
+
footerLink: import("@metamask/superstruct").Struct<{
|
|
179
|
+
text: string;
|
|
180
|
+
href: string;
|
|
181
|
+
} | undefined, {
|
|
182
|
+
href: import("@metamask/superstruct").Struct<string, null>;
|
|
183
|
+
text: import("@metamask/superstruct").Struct<string, null>;
|
|
184
|
+
}>;
|
|
158
185
|
}>>;
|
|
159
186
|
}>;
|
|
160
187
|
export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstruct").Struct<{
|
|
@@ -163,6 +190,12 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
|
|
|
163
190
|
type: "native" | "inApp";
|
|
164
191
|
message: string;
|
|
165
192
|
id: string;
|
|
193
|
+
content?: string | undefined;
|
|
194
|
+
title?: string | undefined;
|
|
195
|
+
footerLink?: {
|
|
196
|
+
text: string;
|
|
197
|
+
href: string;
|
|
198
|
+
} | undefined;
|
|
166
199
|
}[];
|
|
167
200
|
response: {
|
|
168
201
|
result: import("@metamask/snaps-sdk").Json;
|
|
@@ -177,14 +210,35 @@ export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstr
|
|
|
177
210
|
type: "native" | "inApp";
|
|
178
211
|
message: string;
|
|
179
212
|
id: string;
|
|
213
|
+
content?: string | undefined;
|
|
214
|
+
title?: string | undefined;
|
|
215
|
+
footerLink?: {
|
|
216
|
+
text: string;
|
|
217
|
+
href: string;
|
|
218
|
+
} | undefined;
|
|
180
219
|
}[], import("@metamask/superstruct").Struct<{
|
|
181
220
|
type: "native" | "inApp";
|
|
182
221
|
message: string;
|
|
183
222
|
id: string;
|
|
223
|
+
content?: string | undefined;
|
|
224
|
+
title?: string | undefined;
|
|
225
|
+
footerLink?: {
|
|
226
|
+
text: string;
|
|
227
|
+
href: string;
|
|
228
|
+
} | undefined;
|
|
184
229
|
}, {
|
|
185
230
|
id: import("@metamask/superstruct").Struct<string, null>;
|
|
186
231
|
message: import("@metamask/superstruct").Struct<string, null>;
|
|
187
232
|
type: import("@metamask/superstruct").Struct<"native" | "inApp", null>;
|
|
233
|
+
title: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
234
|
+
content: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
235
|
+
footerLink: import("@metamask/superstruct").Struct<{
|
|
236
|
+
text: string;
|
|
237
|
+
href: string;
|
|
238
|
+
} | undefined, {
|
|
239
|
+
href: import("@metamask/superstruct").Struct<string, null>;
|
|
240
|
+
text: import("@metamask/superstruct").Struct<string, null>;
|
|
241
|
+
}>;
|
|
188
242
|
}>>;
|
|
189
243
|
response: import("@metamask/superstruct").Struct<{
|
|
190
244
|
result: import("@metamask/snaps-sdk").Json;
|
|
@@ -198,6 +252,12 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
|
|
|
198
252
|
type: "native" | "inApp";
|
|
199
253
|
message: string;
|
|
200
254
|
id: string;
|
|
255
|
+
content?: string | undefined;
|
|
256
|
+
title?: string | undefined;
|
|
257
|
+
footerLink?: {
|
|
258
|
+
text: string;
|
|
259
|
+
href: string;
|
|
260
|
+
} | undefined;
|
|
201
261
|
}[];
|
|
202
262
|
response: {
|
|
203
263
|
result: import("@metamask/snaps-sdk").Json;
|
|
@@ -210,6 +270,12 @@ export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<
|
|
|
210
270
|
type: "native" | "inApp";
|
|
211
271
|
message: string;
|
|
212
272
|
id: string;
|
|
273
|
+
content?: string | undefined;
|
|
274
|
+
title?: string | undefined;
|
|
275
|
+
footerLink?: {
|
|
276
|
+
text: string;
|
|
277
|
+
href: string;
|
|
278
|
+
} | undefined;
|
|
213
279
|
}[];
|
|
214
280
|
response: {
|
|
215
281
|
result: import("@metamask/snaps-sdk").Json;
|
package/dist/structs.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structs.d.mts","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAyB,EAAE,oBAAgB;AAUvE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;IACnC;;OAEG;;IAGH;;OAEG;;IAGH;;;OAGG;;IAUH;;;OAGG;;IAUH;;;OAGG;;IAQH;;;OAGG;;IAQH;;;;OAIG;;IAQH;;;;OAIG;;IAQH;;;OAGG;;IAQH;;;OAGG;;EAOH,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;IACjC;;OAEG;;IAGH;;;OAGG;;IASH;;;;OAIG;;IAWH;;OAEG;;EAUH,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;IACtC;;OAEG;;EAEH,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;QAmBlC,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;IAC5B;;;OAGG;;EAEH,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;EAGnC,CAAC;AAEH,eAAO,MAAM,eAAe;;;;EAE1B,CAAC;AAEH,eAAO,MAAM,kCAAkC
|
|
1
|
+
{"version":3,"file":"structs.d.mts","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAyB,EAAE,oBAAgB;AAUvE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;IACnC;;OAEG;;IAGH;;OAEG;;IAGH;;;OAGG;;IAUH;;;OAGG;;IAUH;;;OAGG;;IAQH;;;OAGG;;IAQH;;;;OAIG;;IAQH;;;;OAIG;;IAQH;;;OAGG;;IAQH;;;OAGG;;EAOH,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;IACjC;;OAEG;;IAGH;;;OAGG;;IASH;;;;OAIG;;IAWH;;OAEG;;EAUH,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;IACtC;;OAEG;;EAEH,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;QAmBlC,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;IAC5B;;;OAGG;;EAEH,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;EAGnC,CAAC;AAEH,eAAO,MAAM,eAAe;;;;EAE1B,CAAC;AAEH,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8B7C,CAAC;AAEH,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAK3C,CAAC;AAEF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAG7B,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,QAAQ,IAAI,yBAAyB,CAE/C"}
|
package/dist/structs.mjs
CHANGED
|
@@ -161,6 +161,12 @@ export const SnapResponseWithoutInterfaceStruct = object({
|
|
|
161
161
|
enumValue(NotificationType.InApp),
|
|
162
162
|
enumValue(NotificationType.Native),
|
|
163
163
|
]),
|
|
164
|
+
title: optional(string()),
|
|
165
|
+
content: optional(string()),
|
|
166
|
+
footerLink: optional(object({
|
|
167
|
+
href: string(),
|
|
168
|
+
text: string(),
|
|
169
|
+
})),
|
|
164
170
|
})),
|
|
165
171
|
});
|
|
166
172
|
export const SnapResponseWithInterfaceStruct = assign(SnapResponseWithoutInterfaceStruct, object({
|