@metamask/snaps-jest 8.2.0 → 8.3.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 +11 -1
- package/README.md +2 -2
- package/dist/chunk-24CGIQLL.mjs +30 -0
- package/dist/chunk-24CGIQLL.mjs.map +1 -0
- package/dist/{chunk-T2PHS5FY.js → chunk-2RJYSYUB.js} +2 -2
- package/dist/chunk-2RJYSYUB.js.map +1 -0
- package/dist/{chunk-KNJNL723.mjs → chunk-3J2IBWXV.mjs} +2 -2
- package/dist/{chunk-DVDAOXO7.js → chunk-3NP6BDGK.js} +48 -15
- package/dist/chunk-3NP6BDGK.js.map +1 -0
- package/dist/{chunk-43HRTFLS.mjs → chunk-6JPBXAHM.mjs} +103 -15
- package/dist/chunk-6JPBXAHM.mjs.map +1 -0
- package/dist/{chunk-VXPCUDBI.js → chunk-6V6MFT67.js} +8 -6
- package/dist/chunk-6V6MFT67.js.map +1 -0
- package/dist/{chunk-MAT5SBM7.mjs → chunk-7PCHIR6O.mjs} +7 -37
- package/dist/chunk-7PCHIR6O.mjs.map +1 -0
- package/dist/{chunk-4MAA7WGJ.js → chunk-AMAL4SJH.js} +7 -7
- package/dist/chunk-AMAL4SJH.js.map +1 -0
- package/dist/{chunk-HOI6FPLR.mjs → chunk-C26TYXXD.mjs} +9 -9
- package/dist/chunk-C26TYXXD.mjs.map +1 -0
- package/dist/{chunk-NSMTFK33.mjs → chunk-CACRY3TX.mjs} +3 -3
- package/dist/{chunk-PZDTZGSI.js → chunk-D653LBAY.js} +1 -1
- package/dist/chunk-D653LBAY.js.map +1 -0
- package/dist/{chunk-GVTDUKXK.js → chunk-DUVKGPX5.js} +106 -18
- package/dist/chunk-DUVKGPX5.js.map +1 -0
- package/dist/{chunk-IH7UNS5A.mjs → chunk-G333FBBL.mjs} +6 -4
- package/dist/chunk-G333FBBL.mjs.map +1 -0
- package/dist/{chunk-YNUVT3HC.js → chunk-GLPGOEVE.js} +4 -4
- package/dist/chunk-GLPGOEVE.js.map +1 -0
- package/dist/{chunk-WMLSD6B5.js → chunk-K7MK6LQU.js} +3 -3
- package/dist/{chunk-B73P64TE.mjs → chunk-KOPPL55J.mjs} +2 -2
- package/dist/chunk-KOPPL55J.mjs.map +1 -0
- package/dist/{chunk-XKJHFUHE.js → chunk-KPRLFCKD.js} +4 -2
- package/dist/chunk-KPRLFCKD.js.map +1 -0
- package/dist/{chunk-IVFVB4VR.js → chunk-LPMHPAZK.js} +54 -14
- package/dist/chunk-LPMHPAZK.js.map +1 -0
- package/dist/{chunk-GG2BCPQH.mjs → chunk-LSKT2AUS.mjs} +5 -3
- package/dist/chunk-LSKT2AUS.mjs.map +1 -0
- package/dist/{chunk-6KXCBUNZ.mjs → chunk-LVNNGMJ2.mjs} +3 -1
- package/dist/{chunk-6KXCBUNZ.mjs.map → chunk-LVNNGMJ2.mjs.map} +1 -1
- package/dist/{chunk-TMAWGVZP.mjs → chunk-OHRFO2BL.mjs} +7 -7
- package/dist/chunk-OHRFO2BL.mjs.map +1 -0
- package/dist/{chunk-WRKY2DLV.js → chunk-OO6IVUCV.js} +5 -5
- package/dist/{chunk-3M4GRUMH.mjs → chunk-ORR7AE5X.mjs} +2 -2
- package/dist/{chunk-5SGLRSWR.mjs → chunk-PDOVVC74.mjs} +4 -4
- package/dist/chunk-PDOVVC74.mjs.map +1 -0
- package/dist/{chunk-O24GTINW.mjs → chunk-Q3I6P2ZF.mjs} +42 -9
- package/dist/chunk-Q3I6P2ZF.mjs.map +1 -0
- package/dist/chunk-QRVFWATH.mjs +14 -0
- package/dist/chunk-QRVFWATH.mjs.map +1 -0
- package/dist/{chunk-MBQHVBLA.js → chunk-QYHQ2WWX.js} +5 -5
- package/dist/chunk-QYHQ2WWX.js.map +1 -0
- package/dist/{chunk-XWGECIXI.js → chunk-RJNNNCZJ.js} +3 -3
- package/dist/{chunk-CYPP66I7.mjs → chunk-ROCGQYSK.mjs} +46 -6
- package/dist/chunk-ROCGQYSK.mjs.map +1 -0
- package/dist/chunk-SNXRXX2O.js +30 -0
- package/dist/chunk-SNXRXX2O.js.map +1 -0
- package/dist/{chunk-44ARQBXS.js → chunk-WZ57PU2K.js} +6 -4
- package/dist/chunk-WZ57PU2K.js.map +1 -0
- package/dist/chunk-XP4YGQJA.js +14 -0
- package/dist/chunk-XP4YGQJA.js.map +1 -0
- package/dist/{chunk-7Y27L2EV.js → chunk-Y2U3ZPCK.js} +15 -45
- package/dist/chunk-Y2U3ZPCK.js.map +1 -0
- package/dist/{chunk-74TIKA2T.mjs → chunk-ZJQSGRNK.mjs} +1 -1
- package/dist/chunk-ZJQSGRNK.mjs.map +1 -0
- package/dist/environment.js +16 -16
- package/dist/environment.mjs +15 -15
- package/dist/helpers.js +29 -15
- package/dist/helpers.mjs +28 -14
- package/dist/index.js +31 -17
- package/dist/index.mjs +30 -16
- package/dist/internals/index.js +28 -20
- package/dist/internals/index.mjs +31 -23
- package/dist/internals/request.js +14 -14
- package/dist/internals/request.mjs +13 -13
- package/dist/internals/simulation/constants.js +4 -2
- package/dist/internals/simulation/constants.mjs +3 -1
- package/dist/internals/simulation/controllers.js +7 -7
- package/dist/internals/simulation/controllers.mjs +6 -6
- package/dist/internals/simulation/index.js +26 -18
- package/dist/internals/simulation/index.mjs +29 -21
- package/dist/internals/simulation/interface.js +10 -4
- package/dist/internals/simulation/interface.mjs +9 -3
- package/dist/internals/simulation/methods/hooks/get-preferences.js +8 -0
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs +8 -0
- package/dist/internals/simulation/methods/hooks/index.js +5 -5
- package/dist/internals/simulation/methods/hooks/index.mjs +8 -8
- package/dist/internals/simulation/methods/hooks/notifications.js +2 -2
- package/dist/internals/simulation/methods/hooks/notifications.mjs +2 -2
- package/dist/internals/simulation/methods/hooks/request-user-approval.js +14 -0
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +14 -0
- package/dist/internals/simulation/methods/hooks/state.js +2 -2
- package/dist/internals/simulation/methods/hooks/state.mjs +2 -2
- package/dist/internals/simulation/methods/index.js +6 -6
- package/dist/internals/simulation/methods/index.mjs +5 -5
- package/dist/internals/simulation/methods/specifications.js +6 -6
- package/dist/internals/simulation/methods/specifications.mjs +5 -5
- package/dist/internals/simulation/middleware/engine.js +3 -3
- package/dist/internals/simulation/middleware/engine.mjs +2 -2
- package/dist/internals/simulation/middleware/index.js +3 -3
- package/dist/internals/simulation/middleware/index.mjs +2 -2
- package/dist/internals/simulation/options.js +3 -3
- package/dist/internals/simulation/options.mjs +2 -2
- package/dist/internals/simulation/simulation.js +12 -11
- package/dist/internals/simulation/simulation.mjs +11 -10
- package/dist/internals/simulation/store/index.js +3 -3
- package/dist/internals/simulation/store/index.mjs +2 -2
- package/dist/internals/simulation/store/store.js +3 -3
- package/dist/internals/simulation/store/store.mjs +2 -2
- package/dist/internals/simulation/store/ui.js +2 -2
- package/dist/internals/simulation/store/ui.mjs +1 -1
- package/dist/internals/structs.js +2 -2
- package/dist/internals/structs.mjs +1 -1
- package/dist/matchers.js +15 -17
- package/dist/matchers.mjs +14 -16
- package/dist/options.js +2 -2
- package/dist/options.mjs +1 -1
- package/dist/setup.js +14 -14
- package/dist/setup.mjs +14 -14
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/helpers.d.ts +43 -1
- package/dist/types/internals/request.d.ts +1 -1
- package/dist/types/internals/server.d.ts +1 -1
- package/dist/types/internals/simulation/constants.d.ts +4 -0
- package/dist/types/internals/simulation/controllers.d.ts +4 -4
- package/dist/types/internals/simulation/interface.d.ts +31 -4
- package/dist/types/internals/simulation/methods/hooks/get-preferences.d.ts +13 -0
- package/dist/types/internals/simulation/methods/hooks/index.d.ts +2 -2
- package/dist/types/internals/simulation/methods/hooks/request-user-approval.d.ts +15 -0
- package/dist/types/internals/simulation/methods/specifications.d.ts +2 -2
- package/dist/types/internals/simulation/middleware/engine.d.ts +1 -1
- package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +1 -1
- package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +1 -1
- package/dist/types/internals/simulation/options.d.ts +10 -8
- package/dist/types/internals/simulation/simulation.d.ts +8 -5
- package/dist/types/internals/simulation/store/mocks.d.ts +2 -2
- package/dist/types/internals/simulation/store/notifications.d.ts +2 -2
- package/dist/types/internals/simulation/store/state.d.ts +1 -1
- package/dist/types/internals/simulation/store/store.d.ts +4 -4
- package/dist/types/internals/simulation/store/ui.d.ts +4 -3
- package/dist/types/internals/structs.d.ts +41 -41
- package/dist/types/matchers.d.ts +0 -10
- package/dist/types/options.d.ts +7 -7
- package/dist/types/types.d.ts +60 -21
- package/package.json +16 -16
- package/dist/chunk-265BMFM5.js +0 -13
- package/dist/chunk-265BMFM5.js.map +0 -1
- package/dist/chunk-43HRTFLS.mjs.map +0 -1
- package/dist/chunk-44ARQBXS.js.map +0 -1
- package/dist/chunk-4MAA7WGJ.js.map +0 -1
- package/dist/chunk-5SGLRSWR.mjs.map +0 -1
- package/dist/chunk-74TIKA2T.mjs.map +0 -1
- package/dist/chunk-7Y27L2EV.js.map +0 -1
- package/dist/chunk-B73P64TE.mjs.map +0 -1
- package/dist/chunk-CYPP66I7.mjs.map +0 -1
- package/dist/chunk-DVDAOXO7.js.map +0 -1
- package/dist/chunk-GG2BCPQH.mjs.map +0 -1
- package/dist/chunk-GVTDUKXK.js.map +0 -1
- package/dist/chunk-HOI6FPLR.mjs.map +0 -1
- package/dist/chunk-IH7UNS5A.mjs.map +0 -1
- package/dist/chunk-IVFVB4VR.js.map +0 -1
- package/dist/chunk-KSIBNOB2.mjs +0 -13
- package/dist/chunk-KSIBNOB2.mjs.map +0 -1
- package/dist/chunk-MAT5SBM7.mjs.map +0 -1
- package/dist/chunk-MBQHVBLA.js.map +0 -1
- package/dist/chunk-O24GTINW.mjs.map +0 -1
- package/dist/chunk-ORO3T6BU.mjs +0 -24
- package/dist/chunk-ORO3T6BU.mjs.map +0 -1
- package/dist/chunk-PZDTZGSI.js.map +0 -1
- package/dist/chunk-RAMAN5RM.js +0 -24
- package/dist/chunk-RAMAN5RM.js.map +0 -1
- package/dist/chunk-T2PHS5FY.js.map +0 -1
- package/dist/chunk-TMAWGVZP.mjs.map +0 -1
- package/dist/chunk-VXPCUDBI.js.map +0 -1
- package/dist/chunk-XKJHFUHE.js.map +0 -1
- package/dist/chunk-YNUVT3HC.js.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-locale.js +0 -8
- package/dist/internals/simulation/methods/hooks/get-locale.mjs +0 -8
- package/dist/internals/simulation/methods/hooks/show-dialog.js +0 -14
- package/dist/internals/simulation/methods/hooks/show-dialog.mjs +0 -14
- package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +0 -9
- package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +0 -9
- /package/dist/{chunk-KNJNL723.mjs.map → chunk-3J2IBWXV.mjs.map} +0 -0
- /package/dist/{chunk-NSMTFK33.mjs.map → chunk-CACRY3TX.mjs.map} +0 -0
- /package/dist/{chunk-WMLSD6B5.js.map → chunk-K7MK6LQU.js.map} +0 -0
- /package/dist/{chunk-WRKY2DLV.js.map → chunk-OO6IVUCV.js.map} +0 -0
- /package/dist/{chunk-3M4GRUMH.mjs.map → chunk-ORR7AE5X.mjs.map} +0 -0
- /package/dist/{chunk-XWGECIXI.js.map → chunk-RJNNNCZJ.js.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{get-locale.js.map → get-preferences.js.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{get-locale.mjs.map → get-preferences.mjs.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{show-dialog.js.map → request-user-approval.js.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{show-dialog.mjs.map → request-user-approval.mjs.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/simulation.ts"],"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 { mnemonicPhraseToBytes } from '@metamask/key-tree';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n fetchSnap,\n detectSnapLocation,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n SnapId,\n AuxiliaryFileEncoding,\n Component,\n InterfaceState,\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 { 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 createInterface: (content: Component) => Promise<string>;\n updateInterface: (id: string, content: Component) => Promise<void>;\n getInterfaceState: (id: string) => InterfaceState;\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 * @template Service - The type of the execution service.\n */\nexport async function handleInstallSnap<\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> {\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 return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\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 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 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: '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}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A,IAClB;AAAA,IACA,OAAO,EAAE,QAAQ,OAAO,MAAM,MAAM;AAAA,EACtC;AAEA,sBAAoB;AAAA,IAClB;AAAA,IACA,CAAC,SAAS;AAOR,gBAAU,0BAAwC;AAChD,cAAMA,oBAA8B,MAAM,OAAO,mBAAmB;AACpE,eAAOA;AAAA,MACT;AAEA,YAAM,mBAA0C;AAAA,QAC9C;AAAA,MACF,EAAE,OAAO;AACT,aACE,kBAAkB,SAAS,sBAAsB,WACjD,kBAAkB,OAAO,MAAM;AAAA,IAEnC;AAAA,EACF;AAEA,sBAAoB;AAAA,IAClB;AAAA,IACA,OAAO,KAAa,UAAmB;AACrC,YAAM,QAAQ,iBAAiB,KAAK,EAAE,UAAU;AAEhD,aAAO,EAAE,MAAM;AAAA,IACjB;AAAA,EACF;AACF;","names":["currentInterface"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/internals/simulation/methods/hooks/get-preferences.ts
|
|
2
|
+
function getGetPreferencesMethodImplementation({
|
|
3
|
+
currency,
|
|
4
|
+
locale
|
|
5
|
+
}) {
|
|
6
|
+
return () => {
|
|
7
|
+
return { currency, locale };
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
getGetPreferencesMethodImplementation
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=chunk-QRVFWATH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/hooks/get-preferences.ts"],"sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getPreferences` hook.\n *\n * @param options - The simulation options.\n * @param options.currency - The currency to use.\n * @param options.locale - The locale to use.\n * @returns The implementation of the `getPreferences` hook.\n */\nexport function getGetPreferencesMethodImplementation({\n currency,\n locale,\n}: SimulationOptions) {\n return () => {\n return { currency, locale };\n };\n}\n"],"mappings":";AAUO,SAAS,sCAAsC;AAAA,EACpD;AAAA,EACA;AACF,GAAsB;AACpB,SAAO,MAAM;AACX,WAAO,EAAE,UAAU,OAAO;AAAA,EAC5B;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkXP4YGQJAjs = require('./chunk-XP4YGQJA.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@ var _chunkJ3I5KZIFjs = require('./chunk-J3I5KZIF.js');
|
|
|
11
11
|
var _chunkGMTKFAWOjs = require('./chunk-GMTKFAWO.js');
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkSNXRXX2Ojs = require('./chunk-SNXRXX2O.js');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -48,13 +48,13 @@ function getPermissionSpecifications({
|
|
|
48
48
|
...hooks,
|
|
49
49
|
// Snaps-specific hooks.
|
|
50
50
|
clearSnapState: _chunkSB5EPHE3js.getClearSnapStateMethodImplementation.call(void 0, runSaga),
|
|
51
|
-
|
|
51
|
+
getPreferences: _chunkXP4YGQJAjs.getGetPreferencesMethodImplementation.call(void 0, options),
|
|
52
52
|
getSnapState: _chunkSB5EPHE3js.getGetSnapStateMethodImplementation.call(void 0, runSaga),
|
|
53
53
|
getUnlockPromise: asyncResolve(true),
|
|
54
54
|
// TODO: Allow the user to specify the result of this function.
|
|
55
55
|
isOnPhishingList: resolve(false),
|
|
56
56
|
maybeUpdatePhishingList: asyncResolve(),
|
|
57
|
-
|
|
57
|
+
requestUserApproval: _chunkSNXRXX2Ojs.getRequestUserApprovalImplementation.call(void 0, runSaga),
|
|
58
58
|
showInAppNotification: _chunkGMTKFAWOjs.getShowInAppNotificationImplementation.call(void 0, runSaga),
|
|
59
59
|
showNativeNotification: _chunkGMTKFAWOjs.getShowNativeNotificationImplementation.call(void 0, runSaga),
|
|
60
60
|
updateSnapState: _chunkSB5EPHE3js.getUpdateSnapStateMethodImplementation.call(void 0, runSaga),
|
|
@@ -86,4 +86,4 @@ async function getEndowments(permissionController, snapId) {
|
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
exports.resolve = resolve; exports.asyncResolve = asyncResolve; exports.getPermissionSpecifications = getPermissionSpecifications; exports.getEndowments = getEndowments;
|
|
89
|
-
//# sourceMappingURL=chunk-
|
|
89
|
+
//# sourceMappingURL=chunk-QYHQ2WWX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/specifications.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,0BAA0B;AA2C5B,SAAS,QAAQ,QAAiB;AACvC,SAAO,MAAM;AACf;AASO,SAAS,aAAa,QAAkB;AAC7C,SAAO,YAAY;AACrB;AAaO,SAAS,4BAA4B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AACrC,SAAO;AAAA,IACL,GAAG,iCAAiC,wBAAwB;AAAA,IAC5D,GAAG,wCAAwC,2BAA2B;AAAA;AAAA,MAEpE,GAAG;AAAA;AAAA,MAGH,gBAAgB,sCAAsC,OAAO;AAAA,MAC7D,gBAAgB,sCAAsC,OAAO;AAAA,MAC7D,cAAc,oCAAoC,OAAO;AAAA,MACzD,kBAAkB,aAAa,IAAI;AAAA;AAAA,MAGnC,kBAAkB,QAAQ,KAAK;AAAA,MAE/B,yBAAyB,aAAa;AAAA,MACtC,qBAAqB,qCAAqC,OAAO;AAAA,MACjE,uBAAuB,uCAAuC,OAAO;AAAA,MACrE,wBAAwB,wCAAwC,OAAO;AAAA,MACvE,iBAAiB,uCAAuC,OAAO;AAAA,MAC/D,iBAAiB,iCAAiC,mBAAmB;AAAA,MACrE,cAAc,8BAA8B,mBAAmB;AAAA,IACjE,CAAC;AAAA,EACH;AACF;AASA,eAAsB,cACpB,sBACA,QACA;AACA,QAAM,gBAAgB,MAAM,OAAO,KAAK,2BAA2B,EAAE,OAEnE,OAAO,SAAS,mBAAmB;AACnC,UAAM,cAAc,MAAM;AAC1B,QAAI,qBAAqB,cAAc,QAAQ,cAAc,GAAG;AAC9D,YAAM,aAAa,MAAM,qBAAqB;AAAA,QAC5C;AAAA,QACA;AAAA,MACF;AAEA,UAAI,YAAY;AACd,eAAO,YAAY,OAAO,UAAsB;AAAA,MAClD;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG,QAAQ,QAAQ,CAAC,CAAC,CAAC;AAEtB,SAAO,CAAC,GAAG,oBAAI,IAAI,CAAC,GAAG,oBAAoB,GAAG,aAAa,CAAC,CAAC;AAC/D","sourcesContent":["import type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetPreferencesMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\n getRequestUserApprovalImplementation,\n} from './hooks';\n\nexport type PermissionSpecificationsHooks = {\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\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve(result?: unknown) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.runSaga - The function to run a saga outside the usual Redux\n * flow.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n}: GetPermissionSpecificationsOptions) {\n return {\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {\n // Shared hooks.\n ...hooks,\n\n // Snaps-specific hooks.\n clearSnapState: getClearSnapStateMethodImplementation(runSaga),\n getPreferences: getGetPreferencesMethodImplementation(options),\n getSnapState: getGetSnapStateMethodImplementation(runSaga),\n getUnlockPromise: asyncResolve(true),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n requestUserApproval: getRequestUserApprovalImplementation(runSaga),\n showInAppNotification: getShowInAppNotificationImplementation(runSaga),\n showNativeNotification: getShowNativeNotificationImplementation(runSaga),\n updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),\n createInterface: getCreateInterfaceImplementation(controllerMessenger),\n getInterface: getGetInterfaceImplementation(controllerMessenger),\n }),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"]}
|
|
@@ -6,7 +6,7 @@ var _chunkY3JC4WGWjs = require('./chunk-Y3JC4WGW.js');
|
|
|
6
6
|
var _chunkEMTW3H54js = require('./chunk-EMTW3H54.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkKPRLFCKDjs = require('./chunk-KPRLFCKD.js');
|
|
10
10
|
|
|
11
11
|
// src/internals/simulation/middleware/engine.ts
|
|
12
12
|
var _ethjsonrpcmiddleware = require('@metamask/eth-json-rpc-middleware');
|
|
@@ -16,7 +16,7 @@ function createJsonRpcEngine({
|
|
|
16
16
|
store,
|
|
17
17
|
hooks,
|
|
18
18
|
permissionMiddleware,
|
|
19
|
-
endpoint =
|
|
19
|
+
endpoint = _chunkKPRLFCKDjs.DEFAULT_JSON_RPC_ENDPOINT
|
|
20
20
|
}) {
|
|
21
21
|
const engine = new (0, _jsonrpcengine.JsonRpcEngine)();
|
|
22
22
|
engine.push(_chunkEMTW3H54js.createMockMiddleware.call(void 0, store));
|
|
@@ -36,4 +36,4 @@ function createJsonRpcEngine({
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
exports.createJsonRpcEngine = createJsonRpcEngine;
|
|
39
|
-
//# sourceMappingURL=chunk-
|
|
39
|
+
//# sourceMappingURL=chunk-RJNNNCZJ.js.map
|
|
@@ -3,7 +3,10 @@ import {
|
|
|
3
3
|
} from "./chunk-XK5HPZZC.mjs";
|
|
4
4
|
import {
|
|
5
5
|
handleRequest
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-PDOVVC74.mjs";
|
|
7
|
+
import {
|
|
8
|
+
getElementByType
|
|
9
|
+
} from "./chunk-6JPBXAHM.mjs";
|
|
7
10
|
import {
|
|
8
11
|
rootLogger
|
|
9
12
|
} from "./chunk-J4ZPUCLX.mjs";
|
|
@@ -12,16 +15,22 @@ import {
|
|
|
12
15
|
SignatureOptionsStruct,
|
|
13
16
|
SnapResponseWithInterfaceStruct,
|
|
14
17
|
TransactionOptionsStruct
|
|
15
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-C26TYXXD.mjs";
|
|
16
19
|
import {
|
|
17
20
|
addJsonRpcMock,
|
|
18
21
|
removeJsonRpcMock
|
|
19
22
|
} from "./chunk-H2464AXT.mjs";
|
|
20
23
|
|
|
21
24
|
// src/helpers.ts
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import { create } from "superstruct";
|
|
25
|
+
import { DialogType } from "@metamask/snaps-sdk";
|
|
26
|
+
import { HandlerType, getJsxChildren, logInfo } from "@metamask/snaps-utils";
|
|
27
|
+
import { create } from "@metamask/superstruct";
|
|
28
|
+
import {
|
|
29
|
+
assert,
|
|
30
|
+
assertStruct,
|
|
31
|
+
createModuleLogger,
|
|
32
|
+
hasProperty
|
|
33
|
+
} from "@metamask/utils";
|
|
25
34
|
var log = createModuleLogger(rootLogger, "helpers");
|
|
26
35
|
function getOptions(snapId, options) {
|
|
27
36
|
if (typeof snapId === "object") {
|
|
@@ -32,6 +41,30 @@ function getOptions(snapId, options) {
|
|
|
32
41
|
function assertIsResponseWithInterface(response) {
|
|
33
42
|
assertStruct(response, SnapResponseWithInterfaceStruct);
|
|
34
43
|
}
|
|
44
|
+
function assertIsAlertDialog(ui) {
|
|
45
|
+
assert(hasProperty(ui, "type") && ui.type === DialogType.Alert);
|
|
46
|
+
}
|
|
47
|
+
function assertIsConfirmationDialog(ui) {
|
|
48
|
+
assert(hasProperty(ui, "type") && ui.type === DialogType.Confirmation);
|
|
49
|
+
}
|
|
50
|
+
function assertIsPromptDialog(ui) {
|
|
51
|
+
assert(hasProperty(ui, "type") && ui.type === DialogType.Prompt);
|
|
52
|
+
}
|
|
53
|
+
function assertIsCustomDialog(ui) {
|
|
54
|
+
assert(!hasProperty(ui, "type"));
|
|
55
|
+
}
|
|
56
|
+
function assertCustomDialogHasFooter(ui) {
|
|
57
|
+
const footer = getElementByType(ui.content, "Footer");
|
|
58
|
+
assert(footer && getJsxChildren(footer).length === 2);
|
|
59
|
+
}
|
|
60
|
+
function assertCustomDialogHasPartialFooter(ui) {
|
|
61
|
+
const footer = getElementByType(ui.content, "Footer");
|
|
62
|
+
assert(footer && getJsxChildren(footer).length === 1);
|
|
63
|
+
}
|
|
64
|
+
function assertCustomDialogHasNoFooter(ui) {
|
|
65
|
+
const footer = getElementByType(ui.content, "Footer");
|
|
66
|
+
assert(!footer);
|
|
67
|
+
}
|
|
35
68
|
async function installSnap(snapId, options = {}) {
|
|
36
69
|
const resolvedOptions = getOptions(snapId, options);
|
|
37
70
|
const {
|
|
@@ -158,6 +191,13 @@ async function installSnap(snapId, options = {}) {
|
|
|
158
191
|
}
|
|
159
192
|
|
|
160
193
|
export {
|
|
194
|
+
assertIsAlertDialog,
|
|
195
|
+
assertIsConfirmationDialog,
|
|
196
|
+
assertIsPromptDialog,
|
|
197
|
+
assertIsCustomDialog,
|
|
198
|
+
assertCustomDialogHasFooter,
|
|
199
|
+
assertCustomDialogHasPartialFooter,
|
|
200
|
+
assertCustomDialogHasNoFooter,
|
|
161
201
|
installSnap
|
|
162
202
|
};
|
|
163
|
-
//# sourceMappingURL=chunk-
|
|
203
|
+
//# sourceMappingURL=chunk-ROCGQYSK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers.ts"],"sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DialogType } from '@metamask/snaps-sdk';\nimport type { FooterElement } from '@metamask/snaps-sdk/jsx';\nimport { HandlerType, getJsxChildren, logInfo } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport {\n assert,\n assertStruct,\n createModuleLogger,\n hasProperty,\n} from '@metamask/utils';\n\nimport {\n rootLogger,\n handleRequest,\n TransactionOptionsStruct,\n getEnvironment,\n JsonRpcMockOptionsStruct,\n SignatureOptionsStruct,\n SnapResponseWithInterfaceStruct,\n getElementByType,\n} from './internals';\nimport type { InstallSnapOptions } from './internals';\nimport {\n addJsonRpcMock,\n removeJsonRpcMock,\n} from './internals/simulation/store/mocks';\nimport type {\n SnapResponseWithInterface,\n CronjobOptions,\n JsonRpcMockOptions,\n Snap,\n SnapResponse,\n TransactionOptions,\n SnapInterface,\n SnapAlertInterface,\n SnapInterfaceActions,\n SnapConfirmationInterface,\n SnapPromptInterface,\n DefaultSnapInterface,\n DefaultSnapInterfaceWithFooter,\n DefaultSnapInterfaceWithPartialFooter,\n DefaultSnapInterfaceWithoutFooter,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Ensure that the actual response contains `getInterface`.\n *\n * @param response - The response of the handler.\n */\nfunction assertIsResponseWithInterface(\n response: SnapResponse,\n): asserts response is SnapResponseWithInterface {\n assertStruct(response, SnapResponseWithInterfaceStruct);\n}\n\n/**\n * Ensure that the actual interface is an alert dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsAlertDialog(\n ui: SnapInterface,\n): asserts ui is SnapAlertInterface & SnapInterfaceActions {\n assert(hasProperty(ui, 'type') && ui.type === DialogType.Alert);\n}\n\n/**\n * Ensure that the actual interface is a confirmation dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsConfirmationDialog(\n ui: SnapInterface,\n): asserts ui is SnapConfirmationInterface & SnapInterfaceActions {\n assert(hasProperty(ui, 'type') && ui.type === DialogType.Confirmation);\n}\n\n/**\n * Ensure that the actual interface is a Prompt dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsPromptDialog(\n ui: SnapInterface,\n): asserts ui is SnapPromptInterface & SnapInterfaceActions {\n assert(hasProperty(ui, 'type') && ui.type === DialogType.Prompt);\n}\n\n/**\n * Ensure that the actual interface is a custom dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsCustomDialog(\n ui: SnapInterface,\n): asserts ui is DefaultSnapInterface & SnapInterfaceActions {\n assert(!hasProperty(ui, 'type'));\n}\n\n/**\n * Ensure that the actual interface is a custom dialog with a complete footer.\n *\n * @param ui - The interface to verify.\n */\nexport function assertCustomDialogHasFooter(\n ui: DefaultSnapInterface & SnapInterfaceActions,\n): asserts ui is DefaultSnapInterfaceWithFooter & SnapInterfaceActions {\n const footer = getElementByType<FooterElement>(ui.content, 'Footer');\n\n assert(footer && getJsxChildren(footer).length === 2);\n}\n\n/**\n * Ensure that the actual interface is a custom dialog with a partial footer.\n *\n * @param ui - The interface to verify.\n */\nexport function assertCustomDialogHasPartialFooter(\n ui: DefaultSnapInterface & SnapInterfaceActions,\n): asserts ui is DefaultSnapInterfaceWithPartialFooter & SnapInterfaceActions {\n const footer = getElementByType<FooterElement>(ui.content, 'Footer');\n\n assert(footer && getJsxChildren(footer).length === 1);\n}\n\n/**\n * Ensure that the actual interface is a custom dialog without a footer.\n *\n * @param ui - The interface to verify.\n */\nexport function assertCustomDialogHasNoFooter(\n ui: DefaultSnapInterface & SnapInterfaceActions,\n): asserts ui is DefaultSnapInterfaceWithoutFooter & SnapInterfaceActions {\n const footer = getElementByType<FooterElement>(ui.content, 'Footer');\n\n assert(!footer);\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\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 snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\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 snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\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 snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n const {\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n } = await getEnvironment().installSnap(...resolvedOptions);\n\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n return {\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await executionService.terminateAllSnaps();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,kBAAkB;AAE3B,SAAS,aAAa,gBAAgB,eAAe;AACrD,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAmCP,IAAM,MAAM,mBAAmB,YAAY,SAAS;AASpD,SAAS,WAKP,QACA,SAC4D;AAC5D,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,CAAC,QAAW,MAAM;AAAA,EAC3B;AAEA,SAAO,CAAC,QAAQ,OAAO;AACzB;AAOA,SAAS,8BACP,UAC+C;AAC/C,eAAa,UAAU,+BAA+B;AACxD;AAOO,SAAS,oBACd,IACyD;AACzD,SAAO,YAAY,IAAI,MAAM,KAAK,GAAG,SAAS,WAAW,KAAK;AAChE;AAOO,SAAS,2BACd,IACgE;AAChE,SAAO,YAAY,IAAI,MAAM,KAAK,GAAG,SAAS,WAAW,YAAY;AACvE;AAOO,SAAS,qBACd,IAC0D;AAC1D,SAAO,YAAY,IAAI,MAAM,KAAK,GAAG,SAAS,WAAW,MAAM;AACjE;AAOO,SAAS,qBACd,IAC2D;AAC3D,SAAO,CAAC,YAAY,IAAI,MAAM,CAAC;AACjC;AAOO,SAAS,4BACd,IACqE;AACrE,QAAM,SAAS,iBAAgC,GAAG,SAAS,QAAQ;AAEnE,SAAO,UAAU,eAAe,MAAM,EAAE,WAAW,CAAC;AACtD;AAOO,SAAS,mCACd,IAC4E;AAC5E,QAAM,SAAS,iBAAgC,GAAG,SAAS,QAAQ;AAEnE,SAAO,UAAU,eAAe,MAAM,EAAE,WAAW,CAAC;AACtD;AAOO,SAA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+
var _chunkD653LBAYjs = require('./chunk-D653LBAY.js');
|
|
6
|
+
|
|
7
|
+
// src/internals/simulation/methods/hooks/request-user-approval.ts
|
|
8
|
+
var _effects = require('redux-saga/effects');
|
|
9
|
+
function* requestUserApprovalImplementation({
|
|
10
|
+
type,
|
|
11
|
+
requestData: { id }
|
|
12
|
+
}) {
|
|
13
|
+
yield _effects.put.call(void 0, _chunkD653LBAYjs.setInterface.call(void 0, { type, id }));
|
|
14
|
+
const { payload } = yield _effects.take.call(void 0, _chunkD653LBAYjs.resolveInterface.type);
|
|
15
|
+
yield _effects.put.call(void 0, _chunkD653LBAYjs.closeInterface.call(void 0, ));
|
|
16
|
+
return payload;
|
|
17
|
+
}
|
|
18
|
+
function getRequestUserApprovalImplementation(runSaga) {
|
|
19
|
+
return async (...args) => {
|
|
20
|
+
return await runSaga(
|
|
21
|
+
requestUserApprovalImplementation,
|
|
22
|
+
...args
|
|
23
|
+
).toPromise();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
exports.getRequestUserApprovalImplementation = getRequestUserApprovalImplementation;
|
|
30
|
+
//# sourceMappingURL=chunk-SNXRXX2O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/hooks/request-user-approval.ts"],"names":[],"mappings":";;;;;;;AACA,SAAS,KAAK,YAAY;AAwB1B,UAAU,kCAAkC;AAAA,EAC1C;AAAA,EACA,aAAa,EAAE,GAAG;AACpB,GAAqD;AACnD,QAAM,IAAI,aAAa,EAAE,MAAM,GAAG,CAAC,CAAC;AAIpC,QAAM,EAAE,QAAQ,IAAI,MAAM,KAAK,iBAAiB,IAAI;AACpD,QAAM,IAAI,eAAe,CAAC;AAE1B,SAAO;AACT;AAQO,SAAS,qCAAqC,SAA0B;AAC7E,SAAO,UACF,SACA;AACH,WAAO,MAAM;AAAA,MACX;AAAA,MACA,GAAG;AAAA,IACL,EAAE,UAAU;AAAA,EACd;AACF","sourcesContent":["import type { SagaIterator } from 'redux-saga';\nimport { put, take } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { resolveInterface, setInterface, closeInterface } from '../../store';\n\ntype RequestUserApprovalParams = {\n type: string;\n requestData: {\n id: string;\n };\n};\n\n/**\n * Show a dialog to the user. This will wait for `resolveUserInterface` to be\n * dispatched before returning.\n *\n * @param opts - The options for the request.\n * @param opts.type - The type of dialog to show.\n * @param opts.requestData - The data to display in the dialog.\n * @param opts.requestData.id - The ID of the interface.\n * @yields Sets the dialog in the store, waits for the user to resolve the\n * dialog, and closes the dialog.\n * @returns The result of the dialog.\n */\nfunction* requestUserApprovalImplementation({\n type,\n requestData: { id },\n}: RequestUserApprovalParams): SagaIterator<unknown> {\n yield put(setInterface({ type, id }));\n\n // We use `take` to wait for `resolveUserInterface` to be dispatched, which\n // indicates that the user has resolved the dialog.\n const { payload } = yield take(resolveInterface.type);\n yield put(closeInterface());\n\n return payload;\n}\n\n/**\n * Get the implementation of the `requestUserApproval` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `requestUserApproval` hook.\n */\nexport function getRequestUserApprovalImplementation(runSaga: RunSagaFunction) {\n return async (\n ...args: Parameters<typeof requestUserApprovalImplementation>\n ) => {\n return await runSaga(\n requestUserApprovalImplementation,\n ...args,\n ).toPromise();\n };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkQYHQ2WWXjs = require('./chunk-QYHQ2WWX.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkXAOCS6ZDjs = require('./chunk-XAOCS6ZD.js');
|
|
@@ -33,7 +33,9 @@ function getControllers(options) {
|
|
|
33
33
|
name: "SnapInterfaceController",
|
|
34
34
|
allowedActions: [
|
|
35
35
|
"PhishingController:maybeUpdateState",
|
|
36
|
-
"PhishingController:testOrigin"
|
|
36
|
+
"PhishingController:testOrigin",
|
|
37
|
+
"ApprovalController:hasRequest",
|
|
38
|
+
"ApprovalController:acceptRequest"
|
|
37
39
|
],
|
|
38
40
|
allowedEvents: []
|
|
39
41
|
})
|
|
@@ -47,7 +49,7 @@ function getControllers(options) {
|
|
|
47
49
|
}
|
|
48
50
|
function getPermissionController(options) {
|
|
49
51
|
const { controllerMessenger } = options;
|
|
50
|
-
const permissionSpecifications =
|
|
52
|
+
const permissionSpecifications = _chunkQYHQ2WWXjs.getPermissionSpecifications.call(void 0, options);
|
|
51
53
|
return new (0, _permissioncontroller.PermissionController)({
|
|
52
54
|
messenger: controllerMessenger.getRestricted({
|
|
53
55
|
name: "PermissionController",
|
|
@@ -92,4 +94,4 @@ async function registerSnap(snapId, manifest, {
|
|
|
92
94
|
|
|
93
95
|
|
|
94
96
|
exports.getControllers = getControllers; exports.registerSnap = registerSnap;
|
|
95
|
-
//# sourceMappingURL=chunk-
|
|
97
|
+
//# sourceMappingURL=chunk-WZ57PU2K.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/controllers.ts"],"names":[],"mappings":";;;;;;;;AAOA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,+BAA+B;AAMxC;AAAA,EACE,wBAAwB;AAAA,EACxB,iCAAiC;AAAA,EACjC;AAAA,OACK;AAGP,SAAS,mBAAmB;AA0CrB,SAAS,eAAe,SAA6C;AAC1E,QAAM,EAAE,oBAAoB,IAAI;AAChC,QAAM,4BAA4B,IAAI,0BAA0B;AAAA,IAC9D,WAAW,oBAAoB,cAAc;AAAA,MAC3C,MAAM;AAAA,MACN,gBAAgB,CAAC;AAAA,MACjB,eAAe,CAAC;AAAA,IAClB,CAAC;AAAA,IACD,mBAAmB;AAAA,EACrB,CAAC;AAED,QAAM,sBAAsB,IAAI,wBAAwB;AAAA,IACtD,WAAW,oBAAoB,cAAc;AAAA,MAC3C,MAAM;AAAA,MACN,gBAAgB;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,eAAe,CAAC;AAAA,IAClB,CAAC;AAAA,EACH,CAAC;AAED,QAAM,uBAAuB,wBAAwB,OAAO;AAE5D,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAUA,SAAS,wBAAwB,SAAgC;AAC/D,QAAM,EAAE,oBAAoB,IAAI;AAChC,QAAM,2BAA2B,4BAA4B,OAAO;AACpE,SAAO,IAAI,qBAAqB;AAAA,IAC9B,WAAW,oBAAoB,cAAc;AAAA,MAC3C,MAAM;AAAA,MACN,gBAAgB;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,eAAe,CAAC;AAAA,IAClB,CAAC;AAAA,IACD,sBAAsB;AAAA,MACpB,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,IACA;AAAA,IACA,qBAAqB;AAAA,EACvB,CAAC;AACH;AAWA,eAAsB,aACpB,QACA,UACA;AAAA,EACE;AAAA,EACA;AACF,GACA;AACA,4BAA0B,mBAAmB;AAAA,IAC3C,QAAQ;AAAA,IACR,aAAa,YAAY;AAAA,EAC3B,CAAC;AAED,QAAM,sBAAsB;AAAA,IAC1B,YAAY,SAAS,kBAAkB;AAAA,EACzC;AAEA,uBAAqB,iBAAiB;AAAA,IACpC;AAAA,IACA,SAAS,EAAE,QAAQ,OAAO;AAAA,IAC1B,6BAA6B;AAAA,EAC/B,CAAC;AACH","sourcesContent":["import type { ControllerMessenger } from '@metamask/base-controller';\nimport type {\n CaveatSpecificationConstraint,\n PermissionSpecificationConstraint,\n PermissionControllerActions,\n SubjectMetadataControllerActions,\n} from '@metamask/permission-controller';\nimport {\n PermissionController,\n SubjectMetadataController,\n SubjectType,\n} from '@metamask/permission-controller';\nimport { SnapInterfaceController } from '@metamask/snaps-controllers';\nimport type {\n ExecutionServiceActions,\n SnapInterfaceControllerActions,\n SnapInterfaceControllerAllowedActions,\n} from '@metamask/snaps-controllers';\nimport {\n caveatSpecifications as snapsCaveatsSpecifications,\n endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications,\n processSnapPermissions,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { SnapManifest } from '@metamask/snaps-utils';\nimport { getSafeJson } from '@metamask/utils';\n\nimport { getPermissionSpecifications } from './methods';\nimport { UNRESTRICTED_METHODS } from './methods/constants';\nimport type { SimulationOptions } from './options';\nimport type { MiddlewareHooks } from './simulation';\nimport type { RunSagaFunction } from './store';\n\nexport type RootControllerAllowedActions =\n | SnapInterfaceControllerActions\n | SnapInterfaceControllerAllowedActions\n | PermissionControllerActions\n | ExecutionServiceActions\n | SubjectMetadataControllerActions;\n\nexport type RootControllerMessenger = ControllerMessenger<\n RootControllerAllowedActions,\n any\n>;\n\nexport type GetControllersOptions = {\n controllerMessenger: ControllerMessenger<any, any>;\n hooks: MiddlewareHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\nexport type Controllers = {\n permissionController: PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n >;\n subjectMetadataController: SubjectMetadataController;\n interfaceController: SnapInterfaceController;\n};\n\n/**\n * Get the controllers for the Snap.\n *\n * @param options - The options.\n * @returns The controllers for the Snap.\n */\nexport function getControllers(options: GetControllersOptions): Controllers {\n const { controllerMessenger } = options;\n const subjectMetadataController = new SubjectMetadataController({\n messenger: controllerMessenger.getRestricted({\n name: 'SubjectMetadataController',\n allowedActions: [],\n allowedEvents: [],\n }),\n subjectCacheLimit: 100,\n });\n\n const interfaceController = new SnapInterfaceController({\n messenger: controllerMessenger.getRestricted({\n name: 'SnapInterfaceController',\n allowedActions: [\n 'PhishingController:maybeUpdateState',\n 'PhishingController:testOrigin',\n 'ApprovalController:hasRequest',\n 'ApprovalController:acceptRequest',\n ],\n allowedEvents: [],\n }),\n });\n\n const permissionController = getPermissionController(options);\n\n return {\n permissionController,\n subjectMetadataController,\n interfaceController,\n };\n}\n\n/**\n * Get the permission controller for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.options - Miscellaneous options.\n * @returns The permission controller for the Snap.\n */\nfunction getPermissionController(options: GetControllersOptions) {\n const { controllerMessenger } = options;\n const permissionSpecifications = getPermissionSpecifications(options);\n return new PermissionController({\n messenger: controllerMessenger.getRestricted({\n name: 'PermissionController',\n allowedActions: [\n `ApprovalController:addRequest`,\n `ApprovalController:hasRequest`,\n `ApprovalController:acceptRequest`,\n `ApprovalController:rejectRequest`,\n `SnapController:getPermitted`,\n `SnapController:install`,\n `SubjectMetadataController:getSubjectMetadata`,\n ],\n allowedEvents: [],\n }),\n caveatSpecifications: {\n ...snapsCaveatsSpecifications,\n ...snapsEndowmentCaveatSpecifications,\n },\n permissionSpecifications,\n unrestrictedMethods: UNRESTRICTED_METHODS,\n });\n}\n\n/**\n * Register the Snap. This sets up the Snap's permissions and subject metadata.\n *\n * @param snapId - The ID of the Snap to install.\n * @param manifest - The parsed manifest.\n * @param controllers - The controllers for the Snap.\n * @param controllers.permissionController - The permission controller.\n * @param controllers.subjectMetadataController - The subject metadata controller.\n */\nexport async function registerSnap(\n snapId: SnapId,\n manifest: SnapManifest,\n {\n permissionController,\n subjectMetadataController,\n }: Omit<Controllers, 'interfaceController'>,\n) {\n subjectMetadataController.addSubjectMetadata({\n origin: snapId,\n subjectType: SubjectType.Snap,\n });\n\n const approvedPermissions = processSnapPermissions(\n getSafeJson(manifest.initialPermissions),\n );\n\n permissionController.grantPermissions({\n approvedPermissions,\n subject: { origin: snapId },\n preserveExistingPermissions: false,\n });\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/internals/simulation/methods/hooks/get-preferences.ts
|
|
2
|
+
function getGetPreferencesMethodImplementation({
|
|
3
|
+
currency,
|
|
4
|
+
locale
|
|
5
|
+
}) {
|
|
6
|
+
return () => {
|
|
7
|
+
return { currency, locale };
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.getGetPreferencesMethodImplementation = getGetPreferencesMethodImplementation;
|
|
14
|
+
//# sourceMappingURL=chunk-XP4YGQJA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/hooks/get-preferences.ts"],"names":[],"mappings":";AAUO,SAAS,sCAAsC;AAAA,EACpD;AAAA,EACA;AACF,GAAsB;AACpB,SAAO,MAAM;AACX,WAAO,EAAE,UAAU,OAAO;AAAA,EAC5B;AACF","sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getPreferences` hook.\n *\n * @param options - The simulation options.\n * @param options.currency - The currency to use.\n * @param options.locale - The locale to use.\n * @returns The implementation of the `getPreferences` hook.\n */\nexport function getGetPreferencesMethodImplementation({\n currency,\n locale,\n}: SimulationOptions) {\n return () => {\n return { currency, locale };\n };\n}\n"]}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkGLPGOEVEjs = require('./chunk-GLPGOEVE.js');
|
|
5
5
|
|
|
6
6
|
// src/matchers.ts
|
|
7
7
|
var _globals = require('@jest/globals');
|
|
8
8
|
var _jsx = require('@metamask/snaps-sdk/jsx');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
9
12
|
var _snapsutils = require('@metamask/snaps-utils');
|
|
13
|
+
var _superstruct = require('@metamask/superstruct');
|
|
10
14
|
var _utils = require('@metamask/utils');
|
|
11
15
|
|
|
12
16
|
|
|
@@ -17,9 +21,8 @@ var _utils = require('@metamask/utils');
|
|
|
17
21
|
|
|
18
22
|
|
|
19
23
|
var _jestmatcherutils = require('jest-matcher-utils');
|
|
20
|
-
var _superstruct = require('superstruct');
|
|
21
24
|
function assertActualIsSnapResponse(actual, matcherName, options) {
|
|
22
|
-
if (!_superstruct.is.call(void 0, actual,
|
|
25
|
+
if (!_superstruct.is.call(void 0, actual, _chunkGLPGOEVEjs.SnapResponseStruct)) {
|
|
23
26
|
throw new Error(
|
|
24
27
|
_jestmatcherutils.matcherErrorMessage.call(void 0,
|
|
25
28
|
_jestmatcherutils.matcherHint.call(void 0, matcherName, void 0, void 0, options),
|
|
@@ -32,7 +35,7 @@ function assertActualIsSnapResponse(actual, matcherName, options) {
|
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
function assertHasInterface(actual, matcherName, options) {
|
|
35
|
-
if (!_superstruct.is.call(void 0, actual,
|
|
38
|
+
if (!_superstruct.is.call(void 0, actual, _chunkGLPGOEVEjs.InterfaceStruct) || !actual.content) {
|
|
36
39
|
throw new Error(
|
|
37
40
|
_jestmatcherutils.matcherErrorMessage.call(void 0,
|
|
38
41
|
_jestmatcherutils.matcherHint.call(void 0, matcherName, void 0, void 0, options),
|
|
@@ -99,38 +102,6 @@ Expected type: ${this.utils.printExpected(type)}
|
|
|
99
102
|
Received: ${this.utils.printReceived(notifications)}`;
|
|
100
103
|
return { message, pass };
|
|
101
104
|
};
|
|
102
|
-
function serialiseProp(prop) {
|
|
103
|
-
if (typeof prop === "string") {
|
|
104
|
-
return `"${prop}"`;
|
|
105
|
-
}
|
|
106
|
-
return `{${JSON.stringify(prop)}}`;
|
|
107
|
-
}
|
|
108
|
-
function serialiseProps(props) {
|
|
109
|
-
return Object.entries(props).filter(([key]) => key !== "children").sort(([a], [b]) => a.localeCompare(b)).map(([key, value]) => ` ${key}=${serialiseProp(value)}`).join("");
|
|
110
|
-
}
|
|
111
|
-
function serialiseJsx(node, indentation = 0) {
|
|
112
|
-
if (Array.isArray(node)) {
|
|
113
|
-
return node.map((child) => serialiseJsx(child, indentation)).join("");
|
|
114
|
-
}
|
|
115
|
-
const indent = " ".repeat(indentation);
|
|
116
|
-
if (typeof node === "string") {
|
|
117
|
-
return `${indent}${node}
|
|
118
|
-
`;
|
|
119
|
-
}
|
|
120
|
-
if (!node) {
|
|
121
|
-
return "";
|
|
122
|
-
}
|
|
123
|
-
const { type, props } = node;
|
|
124
|
-
const trailingNewline = indentation > 0 ? "\n" : "";
|
|
125
|
-
if (_utils.hasProperty.call(void 0, props, "children")) {
|
|
126
|
-
const children = serialiseJsx(props.children, indentation + 1);
|
|
127
|
-
return `${indent}<${type}${serialiseProps(
|
|
128
|
-
props
|
|
129
|
-
)}>
|
|
130
|
-
${children}${indent}</${type}>${trailingNewline}`;
|
|
131
|
-
}
|
|
132
|
-
return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;
|
|
133
|
-
}
|
|
134
105
|
var toRenderLegacy = function(actual, expected) {
|
|
135
106
|
assertHasInterface(actual, "toRender");
|
|
136
107
|
const { content } = actual;
|
|
@@ -168,26 +139,26 @@ var toRender = function(actual, expected) {
|
|
|
168
139
|
const { content } = actual;
|
|
169
140
|
const pass = this.equals(content, expected);
|
|
170
141
|
const difference = _jestmatcherutils.diff.call(void 0,
|
|
171
|
-
serialiseJsx(expected),
|
|
172
|
-
serialiseJsx(content)
|
|
142
|
+
_snapsutils.serialiseJsx.call(void 0, expected),
|
|
143
|
+
_snapsutils.serialiseJsx.call(void 0, content)
|
|
173
144
|
);
|
|
174
145
|
const message = pass ? () => `${this.utils.matcherHint(".not.toRender")}
|
|
175
146
|
|
|
176
147
|
Expected:
|
|
177
|
-
${_jestmatcherutils.EXPECTED_COLOR.call(void 0, serialiseJsx(expected))}
|
|
148
|
+
${_jestmatcherutils.EXPECTED_COLOR.call(void 0, _snapsutils.serialiseJsx.call(void 0, expected))}
|
|
178
149
|
|
|
179
150
|
Received:
|
|
180
|
-
${_jestmatcherutils.RECEIVED_COLOR.call(void 0, serialiseJsx(content))}
|
|
151
|
+
${_jestmatcherutils.RECEIVED_COLOR.call(void 0, _snapsutils.serialiseJsx.call(void 0, content))}
|
|
181
152
|
|
|
182
153
|
Difference:
|
|
183
154
|
|
|
184
155
|
${difference}` : () => `${this.utils.matcherHint(".toRender")}
|
|
185
156
|
|
|
186
157
|
Expected:
|
|
187
|
-
${_jestmatcherutils.EXPECTED_COLOR.call(void 0, serialiseJsx(expected))}
|
|
158
|
+
${_jestmatcherutils.EXPECTED_COLOR.call(void 0, _snapsutils.serialiseJsx.call(void 0, expected))}
|
|
188
159
|
|
|
189
160
|
Received:
|
|
190
|
-
${_jestmatcherutils.RECEIVED_COLOR.call(void 0, serialiseJsx(content))}
|
|
161
|
+
${_jestmatcherutils.RECEIVED_COLOR.call(void 0, _snapsutils.serialiseJsx.call(void 0, content))}
|
|
191
162
|
|
|
192
163
|
Difference:
|
|
193
164
|
|
|
@@ -206,6 +177,5 @@ _globals.expect.extend({
|
|
|
206
177
|
|
|
207
178
|
|
|
208
179
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
//# sourceMappingURL=chunk-7Y27L2EV.js.map
|
|
180
|
+
exports.toRespondWith = toRespondWith; exports.toRespondWithError = toRespondWithError; exports.toSendNotification = toSendNotification; exports.toRender = toRender;
|
|
181
|
+
//# sourceMappingURL=chunk-Y2U3ZPCK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/matchers.ts"],"names":["message"],"mappings":";;;;;;AAMA,SAAS,cAAc;AAQvB,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU;AAEnB,SAAS,mBAAmB;AAE5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAYP,SAAS,2BACP,QACA,aACA,SACgC;AAChC,MAAI,CAAC,GAAG,QAAQ,kBAAkB,GAAG;AACnC,UAAM,IAAI;AAAA,MACR;AAAA,QACE,YAAY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,eAAe,aAAa,OAAO,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,EAC7B,UAAU,KAClC,MACE,GAAG,KAAK,MAAM,YAAY,WAAW,CAAC;AAAA;AAAA;AAAA,EACxB,eAAe,aAAa,QAAQ,CAAC,CAAC;AAAA;AAAA;AAAA,EACtC,eAAe,aAAa,OAAO,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,EAC7B,UAAU;AAEtC,SAAO,EAAE,SAAS,KAAK;AACzB;AAEF,OAAO,OAAO;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC","sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n ComponentOrElement,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/store/ui.ts"],"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"],"mappings":";AAGA,SAAS,cAAc,gBAAgB,mBAAmB;AAa1D,IAAM,gBAAyB;AAAA,EAC7B,SAAS;AACX;AAEO,IAAM,UAAU,YAAY;AAAA,EACjC,MAAM;AAAA,EACN,cAAc;AAAA,EACd,UAAU;AAAA,IACR,aAAa,OAAO,QAAkC;AACpD,YAAM,UAAU,OAAO;AAAA,IACzB;AAAA,IACA,eAAe,OAAO;AACpB,YAAM,UAAU;AAAA,IAClB;AAAA,EACF;AACF,CAAC;AAEM,IAAM,mBAAmB;AAAA,EAC9B,GAAG,QAAQ,IAAI;AACjB;AAEO,IAAM,EAAE,cAAc,eAAe,IAAI,QAAQ;AAEjD,IAAM,sBAAsB;AAAA,EACjC,CAAC,UAA4B,MAAM;AAAA,EACnC,CAAC,OAAO,GAAG;AACb;","names":[]}
|
package/dist/environment.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('./chunk-
|
|
4
|
+
var _chunkOO6IVUCVjs = require('./chunk-OO6IVUCV.js');
|
|
5
|
+
require('./chunk-2RJYSYUB.js');
|
|
6
6
|
require('./chunk-HROOL3VI.js');
|
|
7
7
|
require('./chunk-2JTGBHPR.js');
|
|
8
|
-
require('./chunk-
|
|
8
|
+
require('./chunk-AMAL4SJH.js');
|
|
9
9
|
require('./chunk-GECE47HW.js');
|
|
10
|
-
require('./chunk-
|
|
11
|
-
require('./chunk-DVDAOXO7.js');
|
|
10
|
+
require('./chunk-3NP6BDGK.js');
|
|
12
11
|
require('./chunk-ZTX624YO.js');
|
|
13
|
-
require('./chunk-
|
|
12
|
+
require('./chunk-RJNNNCZJ.js');
|
|
14
13
|
require('./chunk-WHGYMK5B.js');
|
|
15
14
|
require('./chunk-Y3JC4WGW.js');
|
|
16
15
|
require('./chunk-WDYPMEZB.js');
|
|
17
16
|
require('./chunk-3FNLFVV2.js');
|
|
18
17
|
require('./chunk-EMTW3H54.js');
|
|
18
|
+
require('./chunk-DUVKGPX5.js');
|
|
19
19
|
require('./chunk-SW65QYFV.js');
|
|
20
|
-
require('./chunk-
|
|
20
|
+
require('./chunk-6V6MFT67.js');
|
|
21
21
|
require('./chunk-N6MAO223.js');
|
|
22
22
|
require('./chunk-TZB4LBT7.js');
|
|
23
|
-
require('./chunk-
|
|
24
|
-
require('./chunk-
|
|
25
|
-
require('./chunk-
|
|
23
|
+
require('./chunk-GLPGOEVE.js');
|
|
24
|
+
require('./chunk-KPRLFCKD.js');
|
|
25
|
+
require('./chunk-WZ57PU2K.js');
|
|
26
26
|
require('./chunk-DR6Y7IVX.js');
|
|
27
|
-
require('./chunk-
|
|
27
|
+
require('./chunk-QYHQ2WWX.js');
|
|
28
28
|
require('./chunk-CKRORVDW.js');
|
|
29
|
-
require('./chunk-
|
|
29
|
+
require('./chunk-XP4YGQJA.js');
|
|
30
30
|
require('./chunk-J3I5KZIF.js');
|
|
31
31
|
require('./chunk-GMTKFAWO.js');
|
|
32
|
-
require('./chunk-
|
|
32
|
+
require('./chunk-SNXRXX2O.js');
|
|
33
33
|
require('./chunk-SB5EPHE3.js');
|
|
34
34
|
require('./chunk-VHJZERIC.js');
|
|
35
|
-
require('./chunk-
|
|
36
|
-
require('./chunk-
|
|
35
|
+
require('./chunk-K7MK6LQU.js');
|
|
36
|
+
require('./chunk-D653LBAY.js');
|
|
37
37
|
require('./chunk-LACTK6EO.js');
|
|
38
38
|
require('./chunk-2YE2P5BZ.js');
|
|
39
39
|
require('./chunk-LBC2OGSN.js');
|
|
@@ -42,5 +42,5 @@ require('./chunk-PHUTP7NB.js');
|
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
|
|
45
|
-
exports.SnapsEnvironment =
|
|
45
|
+
exports.SnapsEnvironment = _chunkOO6IVUCVjs.SnapsEnvironment; exports.default = _chunkOO6IVUCVjs.environment_default;
|
|
46
46
|
//# sourceMappingURL=environment.js.map
|