@metamask/snaps-simulation 1.5.0 → 2.1.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 +23 -1
- package/dist/controllers.cjs.map +1 -1
- package/dist/controllers.d.cts +2 -2
- package/dist/controllers.d.cts.map +1 -1
- package/dist/controllers.d.mts +2 -2
- package/dist/controllers.d.mts.map +1 -1
- package/dist/controllers.mjs.map +1 -1
- package/dist/helpers.cjs +1 -0
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +9 -0
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +9 -0
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +1 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/interface.cjs +6 -0
- package/dist/interface.cjs.map +1 -1
- package/dist/interface.d.cts +1 -1
- package/dist/interface.d.cts.map +1 -1
- package/dist/interface.d.mts +1 -1
- package/dist/interface.d.mts.map +1 -1
- package/dist/interface.mjs +6 -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/middleware/internal-methods/chain-id.cjs +23 -0
- package/dist/middleware/internal-methods/chain-id.cjs.map +1 -0
- package/dist/middleware/internal-methods/chain-id.d.cts +16 -0
- package/dist/middleware/internal-methods/chain-id.d.cts.map +1 -0
- package/dist/middleware/internal-methods/chain-id.d.mts +16 -0
- package/dist/middleware/internal-methods/chain-id.d.mts.map +1 -0
- package/dist/middleware/internal-methods/chain-id.mjs +19 -0
- package/dist/middleware/internal-methods/chain-id.mjs.map +1 -0
- package/dist/middleware/internal-methods/middleware.cjs +4 -0
- package/dist/middleware/internal-methods/middleware.cjs.map +1 -1
- package/dist/middleware/internal-methods/middleware.d.cts.map +1 -1
- package/dist/middleware/internal-methods/middleware.d.mts.map +1 -1
- package/dist/middleware/internal-methods/middleware.mjs +4 -0
- package/dist/middleware/internal-methods/middleware.mjs.map +1 -1
- package/dist/middleware/internal-methods/net-version.cjs +23 -0
- package/dist/middleware/internal-methods/net-version.cjs.map +1 -0
- package/dist/middleware/internal-methods/net-version.d.cts +16 -0
- package/dist/middleware/internal-methods/net-version.d.cts.map +1 -0
- package/dist/middleware/internal-methods/net-version.d.mts +16 -0
- package/dist/middleware/internal-methods/net-version.d.mts.map +1 -0
- package/dist/middleware/internal-methods/net-version.mjs +19 -0
- package/dist/middleware/internal-methods/net-version.mjs.map +1 -0
- 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 +15 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +15 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specifications.mjs","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":"AACA,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,uCAAuC,EACxC,oCAAoC;AAErC,OAAO,EAAE,kBAAkB,EAAE,8BAA8B;AAK3D,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EAC1B,wBAAoB;AACrB,OAAO,EACL,qCAAqC,EACrC,qCAAqC,EACrC,mCAAmC,EACnC,sCAAsC,EACtC,sCAAsC,EACtC,uCAAuC,EACvC,gCAAgC,EAChC,6BAA6B,EAC7B,oCAAoC,EACrC,0BAAgB;AAkBjB;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,MAAe;IACrC,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;AACtB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,
|
|
1
|
+
{"version":3,"file":"specifications.mjs","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":"AACA,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,uCAAuC,EACxC,oCAAoC;AAErC,OAAO,EAAE,kBAAkB,EAAE,8BAA8B;AAK3D,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EAC1B,wBAAoB;AACrB,OAAO,EACL,qCAAqC,EACrC,qCAAqC,EACrC,mCAAmC,EACnC,sCAAsC,EACtC,sCAAsC,EACtC,uCAAuC,EACvC,gCAAgC,EAChC,6BAA6B,EAC7B,oCAAoC,EACrC,0BAAgB;AAkBjB;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,MAAe;IACrC,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;AACtB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAO,MAAa;IAC9C,OAAO,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAC1C,mBAAmB,EACnB,KAAK,EACL,OAAO,EACP,OAAO,GAC4B;IACnC,OAAO;QACL,GAAG,gCAAgC,CAAC,wBAAwB,CAAC;QAC7D,GAAG,uCAAuC,CAAC,yBAAyB,EAAE;YACpE,gBAAgB;YAChB,GAAG,KAAK;YAER,wBAAwB;YACxB,cAAc,EAAE,qCAAqC,CAAC,OAAO,CAAC;YAC9D,cAAc,EAAE,qCAAqC,CAAC,OAAO,CAAC;YAC9D,YAAY,EAAE,mCAAmC,CAAC,OAAO,CAAC;YAC1D,gBAAgB,EAAE,YAAY,CAAC,IAAI,CAAC;YAEpC,+DAA+D;YAC/D,gBAAgB,EAAE,OAAO,CAAC,KAAK,CAAC;YAEhC,uBAAuB,EAAE,YAAY,EAAE;YACvC,mBAAmB,EAAE,oCAAoC,CAAC,OAAO,CAAC;YAClE,qBAAqB,EAAE,sCAAsC,CAAC,OAAO,CAAC;YACtE,sBAAsB,EAAE,uCAAuC,CAAC,OAAO,CAAC;YACxE,eAAe,EAAE,sCAAsC,CAAC,OAAO,CAAC;YAChE,eAAe,EAAE,gCAAgC,CAAC,mBAAmB,CAAC;YACtE,YAAY,EAAE,6BAA6B,CAAC,mBAAmB,CAAC;SACjE,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,oBAAiD,EACjD,MAAc;IAEd,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,MAAM,CAEzE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE;QAClC,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC;QAClC,IAAI,oBAAoB,CAAC,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC;YAC/D,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAAC,aAAa,CACzD,MAAM,EACN,cAAc,CACf,CAAC;YAEF,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,WAAW,CAAC,MAAM,CAAC,UAAsB,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAExB,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,kBAAkB,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC","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<Type>(result?: Type) {\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"]}
|
|
@@ -15,16 +15,19 @@ const mock_1 = require("./mock.cjs");
|
|
|
15
15
|
*
|
|
16
16
|
* @param options - The options to use when creating the engine.
|
|
17
17
|
* @param options.store - The Redux store to use.
|
|
18
|
-
* @param options.
|
|
18
|
+
* @param options.restrictedHooks - Any hooks used by the middleware handlers.
|
|
19
|
+
* @param options.permittedHooks - Any hooks used by the middleware handlers.
|
|
19
20
|
* @param options.permissionMiddleware - The permission middleware to use.
|
|
20
21
|
* @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.
|
|
21
22
|
* @returns A JSON-RPC engine.
|
|
22
23
|
*/
|
|
23
|
-
function createJsonRpcEngine({ store,
|
|
24
|
+
function createJsonRpcEngine({ store, restrictedHooks, permittedHooks, permissionMiddleware, endpoint = constants_1.DEFAULT_JSON_RPC_ENDPOINT, }) {
|
|
24
25
|
const engine = new json_rpc_engine_1.JsonRpcEngine();
|
|
25
26
|
engine.push((0, mock_1.createMockMiddleware)(store));
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
// The hooks here do not match the hooks used by the clients, so this
|
|
28
|
+
// middleware should not be used outside of the simulation environment.
|
|
29
|
+
engine.push((0, internal_methods_1.createInternalMethodsMiddleware)(restrictedHooks));
|
|
30
|
+
engine.push((0, snaps_rpc_methods_1.createSnapsMethodMiddleware)(true, permittedHooks));
|
|
28
31
|
engine.push(permissionMiddleware);
|
|
29
32
|
engine.push((0, eth_json_rpc_middleware_1.createFetchMiddleware)({
|
|
30
33
|
btoa: globalThis.btoa,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.cjs","sourceRoot":"","sources":["../../src/middleware/engine.ts"],"names":[],"mappings":";;;AAAA,+EAA0E;AAE1E,+DAA0D;AAE1D,mEAA0E;AAG1E,gDAAyD;
|
|
1
|
+
{"version":3,"file":"engine.cjs","sourceRoot":"","sources":["../../src/middleware/engine.ts"],"names":[],"mappings":";;;AAAA,+EAA0E;AAE1E,+DAA0D;AAE1D,mEAA0E;AAG1E,gDAAyD;AAMzD,mEAAqE;AACrE,qCAA8C;AAU9C;;;;;;;;;;;;;GAaG;AACH,SAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,QAAQ,GAAG,qCAAyB,GACT;IAC3B,MAAM,MAAM,GAAG,IAAI,+BAAa,EAAE,CAAC;IACnC,MAAM,CAAC,IAAI,CAAC,IAAA,2BAAoB,EAAC,KAAK,CAAC,CAAC,CAAC;IAEzC,qEAAqE;IACrE,uEAAuE;IACvE,MAAM,CAAC,IAAI,CAAC,IAAA,kDAA+B,EAAC,eAAe,CAAC,CAAC,CAAC;IAC9D,MAAM,CAAC,IAAI,CAAC,IAAA,+CAA2B,EAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC;IAE/D,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAClC,MAAM,CAAC,IAAI,CACT,IAAA,+CAAqB,EAAC;QACpB,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,MAAM,EAAE,QAAQ;KACjB,CAAC,CACH,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AAzBD,kDAyBC","sourcesContent":["import { createFetchMiddleware } from '@metamask/eth-json-rpc-middleware';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type { RestrictedMethodParameters } from '@metamask/permission-controller';\nimport { createSnapsMethodMiddleware } from '@metamask/snaps-rpc-methods';\nimport type { Json } from '@metamask/utils';\n\nimport { DEFAULT_JSON_RPC_ENDPOINT } from '../constants';\nimport type {\n PermittedMiddlewareHooks,\n RestrictedMiddlewareHooks,\n} from '../simulation';\nimport type { Store } from '../store';\nimport { createInternalMethodsMiddleware } from './internal-methods';\nimport { createMockMiddleware } from './mock';\n\nexport type CreateJsonRpcEngineOptions = {\n store: Store;\n restrictedHooks: RestrictedMiddlewareHooks;\n permittedHooks: PermittedMiddlewareHooks;\n permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;\n endpoint?: string;\n};\n\n/**\n * Create a JSON-RPC engine for use in a simulated environment. This engine\n * should be used to handle all JSON-RPC requests. It is set up to handle\n * requests that would normally be handled internally by the MetaMask client, as\n * well as Snap-specific requests.\n *\n * @param options - The options to use when creating the engine.\n * @param options.store - The Redux store to use.\n * @param options.restrictedHooks - Any hooks used by the middleware handlers.\n * @param options.permittedHooks - Any hooks used by the middleware handlers.\n * @param options.permissionMiddleware - The permission middleware to use.\n * @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.\n * @returns A JSON-RPC engine.\n */\nexport function createJsonRpcEngine({\n store,\n restrictedHooks,\n permittedHooks,\n permissionMiddleware,\n endpoint = DEFAULT_JSON_RPC_ENDPOINT,\n}: CreateJsonRpcEngineOptions) {\n const engine = new JsonRpcEngine();\n engine.push(createMockMiddleware(store));\n\n // The hooks here do not match the hooks used by the clients, so this\n // middleware should not be used outside of the simulation environment.\n engine.push(createInternalMethodsMiddleware(restrictedHooks));\n engine.push(createSnapsMethodMiddleware(true, permittedHooks));\n\n engine.push(permissionMiddleware);\n engine.push(\n createFetchMiddleware({\n btoa: globalThis.btoa,\n fetch: globalThis.fetch,\n rpcUrl: endpoint,\n }),\n );\n\n return engine;\n}\n"]}
|
|
@@ -2,11 +2,12 @@ import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
|
2
2
|
import { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
3
3
|
import type { RestrictedMethodParameters } from "@metamask/permission-controller";
|
|
4
4
|
import type { Json } from "@metamask/utils";
|
|
5
|
-
import type {
|
|
5
|
+
import type { PermittedMiddlewareHooks, RestrictedMiddlewareHooks } from "../simulation.cjs";
|
|
6
6
|
import type { Store } from "../store/index.cjs";
|
|
7
7
|
export type CreateJsonRpcEngineOptions = {
|
|
8
8
|
store: Store;
|
|
9
|
-
|
|
9
|
+
restrictedHooks: RestrictedMiddlewareHooks;
|
|
10
|
+
permittedHooks: PermittedMiddlewareHooks;
|
|
10
11
|
permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;
|
|
11
12
|
endpoint?: string;
|
|
12
13
|
};
|
|
@@ -18,10 +19,11 @@ export type CreateJsonRpcEngineOptions = {
|
|
|
18
19
|
*
|
|
19
20
|
* @param options - The options to use when creating the engine.
|
|
20
21
|
* @param options.store - The Redux store to use.
|
|
21
|
-
* @param options.
|
|
22
|
+
* @param options.restrictedHooks - Any hooks used by the middleware handlers.
|
|
23
|
+
* @param options.permittedHooks - Any hooks used by the middleware handlers.
|
|
22
24
|
* @param options.permissionMiddleware - The permission middleware to use.
|
|
23
25
|
* @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.
|
|
24
26
|
* @returns A JSON-RPC engine.
|
|
25
27
|
*/
|
|
26
|
-
export declare function createJsonRpcEngine({ store,
|
|
28
|
+
export declare function createJsonRpcEngine({ store, restrictedHooks, permittedHooks, permissionMiddleware, endpoint, }: CreateJsonRpcEngineOptions): JsonRpcEngine;
|
|
27
29
|
//# sourceMappingURL=engine.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.cts","sourceRoot":"","sources":["../../src/middleware/engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AACnE,OAAO,EAAE,aAAa,EAAE,kCAAkC;AAC1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,wCAAwC;AAElF,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"engine.d.cts","sourceRoot":"","sources":["../../src/middleware/engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AACnE,OAAO,EAAE,aAAa,EAAE,kCAAkC;AAC1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,wCAAwC;AAElF,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,0BAAsB;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,2BAAiB;AAItC,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,KAAK,CAAC;IACb,eAAe,EAAE,yBAAyB,CAAC;IAC3C,cAAc,EAAE,wBAAwB,CAAC;IACzC,oBAAoB,EAAE,iBAAiB,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAC;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,QAAoC,GACrC,EAAE,0BAA0B,iBAmB5B"}
|
|
@@ -2,11 +2,12 @@ import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
|
2
2
|
import { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
3
3
|
import type { RestrictedMethodParameters } from "@metamask/permission-controller";
|
|
4
4
|
import type { Json } from "@metamask/utils";
|
|
5
|
-
import type {
|
|
5
|
+
import type { PermittedMiddlewareHooks, RestrictedMiddlewareHooks } from "../simulation.mjs";
|
|
6
6
|
import type { Store } from "../store/index.mjs";
|
|
7
7
|
export type CreateJsonRpcEngineOptions = {
|
|
8
8
|
store: Store;
|
|
9
|
-
|
|
9
|
+
restrictedHooks: RestrictedMiddlewareHooks;
|
|
10
|
+
permittedHooks: PermittedMiddlewareHooks;
|
|
10
11
|
permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;
|
|
11
12
|
endpoint?: string;
|
|
12
13
|
};
|
|
@@ -18,10 +19,11 @@ export type CreateJsonRpcEngineOptions = {
|
|
|
18
19
|
*
|
|
19
20
|
* @param options - The options to use when creating the engine.
|
|
20
21
|
* @param options.store - The Redux store to use.
|
|
21
|
-
* @param options.
|
|
22
|
+
* @param options.restrictedHooks - Any hooks used by the middleware handlers.
|
|
23
|
+
* @param options.permittedHooks - Any hooks used by the middleware handlers.
|
|
22
24
|
* @param options.permissionMiddleware - The permission middleware to use.
|
|
23
25
|
* @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.
|
|
24
26
|
* @returns A JSON-RPC engine.
|
|
25
27
|
*/
|
|
26
|
-
export declare function createJsonRpcEngine({ store,
|
|
28
|
+
export declare function createJsonRpcEngine({ store, restrictedHooks, permittedHooks, permissionMiddleware, endpoint, }: CreateJsonRpcEngineOptions): JsonRpcEngine;
|
|
27
29
|
//# sourceMappingURL=engine.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.mts","sourceRoot":"","sources":["../../src/middleware/engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AACnE,OAAO,EAAE,aAAa,EAAE,kCAAkC;AAC1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,wCAAwC;AAElF,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"engine.d.mts","sourceRoot":"","sources":["../../src/middleware/engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AACnE,OAAO,EAAE,aAAa,EAAE,kCAAkC;AAC1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,wCAAwC;AAElF,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,0BAAsB;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,2BAAiB;AAItC,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,KAAK,CAAC;IACb,eAAe,EAAE,yBAAyB,CAAC;IAC3C,cAAc,EAAE,wBAAwB,CAAC;IACzC,oBAAoB,EAAE,iBAAiB,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAC;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,QAAoC,GACrC,EAAE,0BAA0B,iBAmB5B"}
|
|
@@ -12,16 +12,19 @@ import { createMockMiddleware } from "./mock.mjs";
|
|
|
12
12
|
*
|
|
13
13
|
* @param options - The options to use when creating the engine.
|
|
14
14
|
* @param options.store - The Redux store to use.
|
|
15
|
-
* @param options.
|
|
15
|
+
* @param options.restrictedHooks - Any hooks used by the middleware handlers.
|
|
16
|
+
* @param options.permittedHooks - Any hooks used by the middleware handlers.
|
|
16
17
|
* @param options.permissionMiddleware - The permission middleware to use.
|
|
17
18
|
* @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.
|
|
18
19
|
* @returns A JSON-RPC engine.
|
|
19
20
|
*/
|
|
20
|
-
export function createJsonRpcEngine({ store,
|
|
21
|
+
export function createJsonRpcEngine({ store, restrictedHooks, permittedHooks, permissionMiddleware, endpoint = DEFAULT_JSON_RPC_ENDPOINT, }) {
|
|
21
22
|
const engine = new JsonRpcEngine();
|
|
22
23
|
engine.push(createMockMiddleware(store));
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
// The hooks here do not match the hooks used by the clients, so this
|
|
25
|
+
// middleware should not be used outside of the simulation environment.
|
|
26
|
+
engine.push(createInternalMethodsMiddleware(restrictedHooks));
|
|
27
|
+
engine.push(createSnapsMethodMiddleware(true, permittedHooks));
|
|
25
28
|
engine.push(permissionMiddleware);
|
|
26
29
|
engine.push(createFetchMiddleware({
|
|
27
30
|
btoa: globalThis.btoa,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.mjs","sourceRoot":"","sources":["../../src/middleware/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,0CAA0C;AAE1E,OAAO,EAAE,aAAa,EAAE,kCAAkC;AAE1D,OAAO,EAAE,2BAA2B,EAAE,oCAAoC;AAG1E,OAAO,EAAE,yBAAyB,EAAE,yBAAqB;
|
|
1
|
+
{"version":3,"file":"engine.mjs","sourceRoot":"","sources":["../../src/middleware/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,0CAA0C;AAE1E,OAAO,EAAE,aAAa,EAAE,kCAAkC;AAE1D,OAAO,EAAE,2BAA2B,EAAE,oCAAoC;AAG1E,OAAO,EAAE,yBAAyB,EAAE,yBAAqB;AAMzD,OAAO,EAAE,+BAA+B,EAAE,qCAA2B;AACrE,OAAO,EAAE,oBAAoB,EAAE,mBAAe;AAU9C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,KAAK,EACL,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,QAAQ,GAAG,yBAAyB,GACT;IAC3B,MAAM,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;IACnC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;IAEzC,qEAAqE;IACrE,uEAAuE;IACvE,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,eAAe,CAAC,CAAC,CAAC;IAC9D,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC;IAE/D,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAClC,MAAM,CAAC,IAAI,CACT,qBAAqB,CAAC;QACpB,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,MAAM,EAAE,QAAQ;KACjB,CAAC,CACH,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { createFetchMiddleware } from '@metamask/eth-json-rpc-middleware';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type { RestrictedMethodParameters } from '@metamask/permission-controller';\nimport { createSnapsMethodMiddleware } from '@metamask/snaps-rpc-methods';\nimport type { Json } from '@metamask/utils';\n\nimport { DEFAULT_JSON_RPC_ENDPOINT } from '../constants';\nimport type {\n PermittedMiddlewareHooks,\n RestrictedMiddlewareHooks,\n} from '../simulation';\nimport type { Store } from '../store';\nimport { createInternalMethodsMiddleware } from './internal-methods';\nimport { createMockMiddleware } from './mock';\n\nexport type CreateJsonRpcEngineOptions = {\n store: Store;\n restrictedHooks: RestrictedMiddlewareHooks;\n permittedHooks: PermittedMiddlewareHooks;\n permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;\n endpoint?: string;\n};\n\n/**\n * Create a JSON-RPC engine for use in a simulated environment. This engine\n * should be used to handle all JSON-RPC requests. It is set up to handle\n * requests that would normally be handled internally by the MetaMask client, as\n * well as Snap-specific requests.\n *\n * @param options - The options to use when creating the engine.\n * @param options.store - The Redux store to use.\n * @param options.restrictedHooks - Any hooks used by the middleware handlers.\n * @param options.permittedHooks - Any hooks used by the middleware handlers.\n * @param options.permissionMiddleware - The permission middleware to use.\n * @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.\n * @returns A JSON-RPC engine.\n */\nexport function createJsonRpcEngine({\n store,\n restrictedHooks,\n permittedHooks,\n permissionMiddleware,\n endpoint = DEFAULT_JSON_RPC_ENDPOINT,\n}: CreateJsonRpcEngineOptions) {\n const engine = new JsonRpcEngine();\n engine.push(createMockMiddleware(store));\n\n // The hooks here do not match the hooks used by the clients, so this\n // middleware should not be used outside of the simulation environment.\n engine.push(createInternalMethodsMiddleware(restrictedHooks));\n engine.push(createSnapsMethodMiddleware(true, permittedHooks));\n\n engine.push(permissionMiddleware);\n engine.push(\n createFetchMiddleware({\n btoa: globalThis.btoa,\n fetch: globalThis.fetch,\n rpcUrl: endpoint,\n }),\n );\n\n return engine;\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getChainIdHandler = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A mock handler for eth_chainId that always returns a specific
|
|
6
|
+
* hardcoded result.
|
|
7
|
+
*
|
|
8
|
+
* @param _request - Incoming JSON-RPC request. Ignored for this specific
|
|
9
|
+
* handler.
|
|
10
|
+
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
11
|
+
* result.
|
|
12
|
+
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
13
|
+
* @param end - The `json-rpc-engine` middleware end handler.
|
|
14
|
+
* @returns The JSON-RPC response.
|
|
15
|
+
*/
|
|
16
|
+
async function getChainIdHandler(_request, response, _next, end) {
|
|
17
|
+
// For now this will return a mocked result, this should probably match
|
|
18
|
+
// whatever network the simulation is using.
|
|
19
|
+
response.result = '0x01';
|
|
20
|
+
return end();
|
|
21
|
+
}
|
|
22
|
+
exports.getChainIdHandler = getChainIdHandler;
|
|
23
|
+
//# sourceMappingURL=chain-id.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-id.cjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/chain-id.ts"],"names":[],"mappings":";;;AAUA;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,iBAAiB,CACrC,QAAwB,EACxB,QAAsC,EACtC,KAAgC,EAChC,GAA6B;IAE7B,uEAAuE;IACvE,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IAEzB,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAXD,8CAWC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\n/**\n * A mock handler for eth_chainId that always returns a specific\n * hardcoded result.\n *\n * @param _request - Incoming JSON-RPC request. Ignored for this specific\n * handler.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n * @returns The JSON-RPC response.\n */\nexport async function getChainIdHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n) {\n // For now this will return a mocked result, this should probably match\n // whatever network the simulation is using.\n response.result = '0x01';\n\n return end();\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* A mock handler for eth_chainId that always returns a specific
|
|
5
|
+
* hardcoded result.
|
|
6
|
+
*
|
|
7
|
+
* @param _request - Incoming JSON-RPC request. Ignored for this specific
|
|
8
|
+
* handler.
|
|
9
|
+
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
10
|
+
* result.
|
|
11
|
+
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
12
|
+
* @param end - The `json-rpc-engine` middleware end handler.
|
|
13
|
+
* @returns The JSON-RPC response.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getChainIdHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=chain-id.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-id.d.cts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/chain-id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,iBAO9B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* A mock handler for eth_chainId that always returns a specific
|
|
5
|
+
* hardcoded result.
|
|
6
|
+
*
|
|
7
|
+
* @param _request - Incoming JSON-RPC request. Ignored for this specific
|
|
8
|
+
* handler.
|
|
9
|
+
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
10
|
+
* result.
|
|
11
|
+
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
12
|
+
* @param end - The `json-rpc-engine` middleware end handler.
|
|
13
|
+
* @returns The JSON-RPC response.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getChainIdHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=chain-id.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-id.d.mts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/chain-id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,iBAO9B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mock handler for eth_chainId that always returns a specific
|
|
3
|
+
* hardcoded result.
|
|
4
|
+
*
|
|
5
|
+
* @param _request - Incoming JSON-RPC request. Ignored for this specific
|
|
6
|
+
* handler.
|
|
7
|
+
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
8
|
+
* result.
|
|
9
|
+
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
10
|
+
* @param end - The `json-rpc-engine` middleware end handler.
|
|
11
|
+
* @returns The JSON-RPC response.
|
|
12
|
+
*/
|
|
13
|
+
export async function getChainIdHandler(_request, response, _next, end) {
|
|
14
|
+
// For now this will return a mocked result, this should probably match
|
|
15
|
+
// whatever network the simulation is using.
|
|
16
|
+
response.result = '0x01';
|
|
17
|
+
return end();
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=chain-id.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-id.mjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/chain-id.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,QAAwB,EACxB,QAAsC,EACtC,KAAgC,EAChC,GAA6B;IAE7B,uEAAuE;IACvE,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IAEzB,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\n/**\n * A mock handler for eth_chainId that always returns a specific\n * hardcoded result.\n *\n * @param _request - Incoming JSON-RPC request. Ignored for this specific\n * handler.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n * @returns The JSON-RPC response.\n */\nexport async function getChainIdHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n) {\n // For now this will return a mocked result, this should probably match\n // whatever network the simulation is using.\n response.result = '0x01';\n\n return end();\n}\n"]}
|
|
@@ -3,12 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createInternalMethodsMiddleware = void 0;
|
|
4
4
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
5
5
|
const accounts_1 = require("./accounts.cjs");
|
|
6
|
+
const chain_id_1 = require("./chain-id.cjs");
|
|
7
|
+
const net_version_1 = require("./net-version.cjs");
|
|
6
8
|
const provider_state_1 = require("./provider-state.cjs");
|
|
7
9
|
const methodHandlers = {
|
|
8
10
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
9
11
|
metamask_getProviderState: provider_state_1.getProviderStateHandler,
|
|
10
12
|
eth_requestAccounts: accounts_1.getAccountsHandler,
|
|
11
13
|
eth_accounts: accounts_1.getAccountsHandler,
|
|
14
|
+
eth_chainId: chain_id_1.getChainIdHandler,
|
|
15
|
+
net_version: net_version_1.getNetworkVersionHandler,
|
|
12
16
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
13
17
|
};
|
|
14
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.cjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/middleware.ts"],"names":[],"mappings":";;;AACA,uDAAiD;AAGjD,6CAAgD;AAChD,yDAA2D;AAW3D,MAAM,cAAc,GAAG;IACrB,yDAAyD;IACzD,yBAAyB,EAAE,wCAAuB;IAClD,mBAAmB,EAAE,6BAAkB;IACvC,YAAY,EAAE,6BAAkB;IAChC,wDAAwD;CACzD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,SAAgB,+BAA+B,CAC7C,KAAqC;IAErC,kDAAkD;IAClD,kEAAkE;IAClE,OAAO,KAAK,UAAU,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG;QACjE,MAAM,OAAO,GACX,cAAc,CAAC,OAAO,CAAC,MAAqC,CAAC,CAAC;QAChE,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,kEAAkE;gBAClE,OAAO,MAAM,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAC5D,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAA,sBAAQ,EAAC,KAAK,CAAC,CAAC;gBAChB,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AApBD,0EAoBC","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { getAccountsHandler } from './accounts';\nimport { getProviderStateHandler } from './provider-state';\n\nexport type InternalMethodsMiddlewareHooks = {\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\nconst methodHandlers = {\n /* eslint-disable @typescript-eslint/naming-convention */\n metamask_getProviderState: getProviderStateHandler,\n eth_requestAccounts: getAccountsHandler,\n eth_accounts: getAccountsHandler,\n /* eslint-enable @typescript-eslint/naming-convention */\n};\n\n/**\n * Create a middleware for handling JSON-RPC methods normally handled internally\n * by the MetaMask client.\n *\n * NOTE: This middleware provides all `hooks` to all handlers and should\n * therefore NOT be used outside of the simulation environment. It is intended\n * for testing purposes only.\n *\n * @param hooks - Any hooks used by the middleware handlers.\n * @returns A middleware function.\n */\nexport function createInternalMethodsMiddleware(\n hooks: InternalMethodsMiddlewareHooks,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This should probably use createAsyncMiddleware.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n try {\n // Implementations may or may not be async, so we must await them.\n return await handler(request, response, next, end, hooks);\n } catch (error: any) {\n logError(error);\n return end(error);\n }\n }\n\n return next();\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"middleware.cjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/middleware.ts"],"names":[],"mappings":";;;AACA,uDAAiD;AAGjD,6CAAgD;AAChD,6CAA+C;AAC/C,mDAAyD;AACzD,yDAA2D;AAW3D,MAAM,cAAc,GAAG;IACrB,yDAAyD;IACzD,yBAAyB,EAAE,wCAAuB;IAClD,mBAAmB,EAAE,6BAAkB;IACvC,YAAY,EAAE,6BAAkB;IAChC,WAAW,EAAE,4BAAiB;IAC9B,WAAW,EAAE,sCAAwB;IACrC,wDAAwD;CACzD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,SAAgB,+BAA+B,CAC7C,KAAqC;IAErC,kDAAkD;IAClD,kEAAkE;IAClE,OAAO,KAAK,UAAU,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG;QACjE,MAAM,OAAO,GACX,cAAc,CAAC,OAAO,CAAC,MAAqC,CAAC,CAAC;QAChE,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,kEAAkE;gBAClE,OAAO,MAAM,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAC5D,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAA,sBAAQ,EAAC,KAAK,CAAC,CAAC;gBAChB,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AApBD,0EAoBC","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { getAccountsHandler } from './accounts';\nimport { getChainIdHandler } from './chain-id';\nimport { getNetworkVersionHandler } from './net-version';\nimport { getProviderStateHandler } from './provider-state';\n\nexport type InternalMethodsMiddlewareHooks = {\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\nconst methodHandlers = {\n /* eslint-disable @typescript-eslint/naming-convention */\n metamask_getProviderState: getProviderStateHandler,\n eth_requestAccounts: getAccountsHandler,\n eth_accounts: getAccountsHandler,\n eth_chainId: getChainIdHandler,\n net_version: getNetworkVersionHandler,\n /* eslint-enable @typescript-eslint/naming-convention */\n};\n\n/**\n * Create a middleware for handling JSON-RPC methods normally handled internally\n * by the MetaMask client.\n *\n * NOTE: This middleware provides all `hooks` to all handlers and should\n * therefore NOT be used outside of the simulation environment. It is intended\n * for testing purposes only.\n *\n * @param hooks - Any hooks used by the middleware handlers.\n * @returns A middleware function.\n */\nexport function createInternalMethodsMiddleware(\n hooks: InternalMethodsMiddlewareHooks,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This should probably use createAsyncMiddleware.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n try {\n // Implementations may or may not be async, so we must await them.\n return await handler(request, response, next, end, hooks);\n } catch (error: any) {\n logError(error);\n return end(error);\n }\n }\n\n return next();\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.cts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"middleware.d.cts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAO3D,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAYF;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,8BAA8B,GACpC,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAkBxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.mts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"middleware.d.mts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAO3D,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAYF;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,8BAA8B,GACpC,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAkBxC"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { logError } from "@metamask/snaps-utils";
|
|
2
2
|
import { getAccountsHandler } from "./accounts.mjs";
|
|
3
|
+
import { getChainIdHandler } from "./chain-id.mjs";
|
|
4
|
+
import { getNetworkVersionHandler } from "./net-version.mjs";
|
|
3
5
|
import { getProviderStateHandler } from "./provider-state.mjs";
|
|
4
6
|
const methodHandlers = {
|
|
5
7
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
6
8
|
metamask_getProviderState: getProviderStateHandler,
|
|
7
9
|
eth_requestAccounts: getAccountsHandler,
|
|
8
10
|
eth_accounts: getAccountsHandler,
|
|
11
|
+
eth_chainId: getChainIdHandler,
|
|
12
|
+
net_version: getNetworkVersionHandler,
|
|
9
13
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
10
14
|
};
|
|
11
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.mjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,OAAO,EAAE,kBAAkB,EAAE,uBAAmB;AAChD,OAAO,EAAE,uBAAuB,EAAE,6BAAyB;AAW3D,MAAM,cAAc,GAAG;IACrB,yDAAyD;IACzD,yBAAyB,EAAE,uBAAuB;IAClD,mBAAmB,EAAE,kBAAkB;IACvC,YAAY,EAAE,kBAAkB;IAChC,wDAAwD;CACzD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,+BAA+B,CAC7C,KAAqC;IAErC,kDAAkD;IAClD,kEAAkE;IAClE,OAAO,KAAK,UAAU,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG;QACjE,MAAM,OAAO,GACX,cAAc,CAAC,OAAO,CAAC,MAAqC,CAAC,CAAC;QAChE,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,kEAAkE;gBAClE,OAAO,MAAM,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAC5D,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAChB,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { getAccountsHandler } from './accounts';\nimport { getProviderStateHandler } from './provider-state';\n\nexport type InternalMethodsMiddlewareHooks = {\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\nconst methodHandlers = {\n /* eslint-disable @typescript-eslint/naming-convention */\n metamask_getProviderState: getProviderStateHandler,\n eth_requestAccounts: getAccountsHandler,\n eth_accounts: getAccountsHandler,\n /* eslint-enable @typescript-eslint/naming-convention */\n};\n\n/**\n * Create a middleware for handling JSON-RPC methods normally handled internally\n * by the MetaMask client.\n *\n * NOTE: This middleware provides all `hooks` to all handlers and should\n * therefore NOT be used outside of the simulation environment. It is intended\n * for testing purposes only.\n *\n * @param hooks - Any hooks used by the middleware handlers.\n * @returns A middleware function.\n */\nexport function createInternalMethodsMiddleware(\n hooks: InternalMethodsMiddlewareHooks,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This should probably use createAsyncMiddleware.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n try {\n // Implementations may or may not be async, so we must await them.\n return await handler(request, response, next, end, hooks);\n } catch (error: any) {\n logError(error);\n return end(error);\n }\n }\n\n return next();\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"middleware.mjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,OAAO,EAAE,kBAAkB,EAAE,uBAAmB;AAChD,OAAO,EAAE,iBAAiB,EAAE,uBAAmB;AAC/C,OAAO,EAAE,wBAAwB,EAAE,0BAAsB;AACzD,OAAO,EAAE,uBAAuB,EAAE,6BAAyB;AAW3D,MAAM,cAAc,GAAG;IACrB,yDAAyD;IACzD,yBAAyB,EAAE,uBAAuB;IAClD,mBAAmB,EAAE,kBAAkB;IACvC,YAAY,EAAE,kBAAkB;IAChC,WAAW,EAAE,iBAAiB;IAC9B,WAAW,EAAE,wBAAwB;IACrC,wDAAwD;CACzD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,+BAA+B,CAC7C,KAAqC;IAErC,kDAAkD;IAClD,kEAAkE;IAClE,OAAO,KAAK,UAAU,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG;QACjE,MAAM,OAAO,GACX,cAAc,CAAC,OAAO,CAAC,MAAqC,CAAC,CAAC;QAChE,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,kEAAkE;gBAClE,OAAO,MAAM,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAC5D,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAChB,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { getAccountsHandler } from './accounts';\nimport { getChainIdHandler } from './chain-id';\nimport { getNetworkVersionHandler } from './net-version';\nimport { getProviderStateHandler } from './provider-state';\n\nexport type InternalMethodsMiddlewareHooks = {\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\nconst methodHandlers = {\n /* eslint-disable @typescript-eslint/naming-convention */\n metamask_getProviderState: getProviderStateHandler,\n eth_requestAccounts: getAccountsHandler,\n eth_accounts: getAccountsHandler,\n eth_chainId: getChainIdHandler,\n net_version: getNetworkVersionHandler,\n /* eslint-enable @typescript-eslint/naming-convention */\n};\n\n/**\n * Create a middleware for handling JSON-RPC methods normally handled internally\n * by the MetaMask client.\n *\n * NOTE: This middleware provides all `hooks` to all handlers and should\n * therefore NOT be used outside of the simulation environment. It is intended\n * for testing purposes only.\n *\n * @param hooks - Any hooks used by the middleware handlers.\n * @returns A middleware function.\n */\nexport function createInternalMethodsMiddleware(\n hooks: InternalMethodsMiddlewareHooks,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This should probably use createAsyncMiddleware.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n try {\n // Implementations may or may not be async, so we must await them.\n return await handler(request, response, next, end, hooks);\n } catch (error: any) {\n logError(error);\n return end(error);\n }\n }\n\n return next();\n };\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNetworkVersionHandler = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A mock handler for net_version that always returns a specific
|
|
6
|
+
* hardcoded result.
|
|
7
|
+
*
|
|
8
|
+
* @param _request - Incoming JSON-RPC request. Ignored for this specific
|
|
9
|
+
* handler.
|
|
10
|
+
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
11
|
+
* result.
|
|
12
|
+
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
13
|
+
* @param end - The `json-rpc-engine` middleware end handler.
|
|
14
|
+
* @returns The JSON-RPC response.
|
|
15
|
+
*/
|
|
16
|
+
async function getNetworkVersionHandler(_request, response, _next, end) {
|
|
17
|
+
// For now this will return a mocked result, this should probably match
|
|
18
|
+
// whatever network the simulation is using.
|
|
19
|
+
response.result = '1';
|
|
20
|
+
return end();
|
|
21
|
+
}
|
|
22
|
+
exports.getNetworkVersionHandler = getNetworkVersionHandler;
|
|
23
|
+
//# sourceMappingURL=net-version.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"net-version.cjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/net-version.ts"],"names":[],"mappings":";;;AAUA;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,wBAAwB,CAC5C,QAAwB,EACxB,QAAsC,EACtC,KAAgC,EAChC,GAA6B;IAE7B,uEAAuE;IACvE,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC;IAEtB,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAXD,4DAWC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\n/**\n * A mock handler for net_version that always returns a specific\n * hardcoded result.\n *\n * @param _request - Incoming JSON-RPC request. Ignored for this specific\n * handler.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n * @returns The JSON-RPC response.\n */\nexport async function getNetworkVersionHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n) {\n // For now this will return a mocked result, this should probably match\n // whatever network the simulation is using.\n response.result = '1';\n\n return end();\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* A mock handler for net_version that always returns a specific
|
|
5
|
+
* hardcoded result.
|
|
6
|
+
*
|
|
7
|
+
* @param _request - Incoming JSON-RPC request. Ignored for this specific
|
|
8
|
+
* handler.
|
|
9
|
+
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
10
|
+
* result.
|
|
11
|
+
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
12
|
+
* @param end - The `json-rpc-engine` middleware end handler.
|
|
13
|
+
* @returns The JSON-RPC response.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getNetworkVersionHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=net-version.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"net-version.d.cts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/net-version.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB;;;;;;;;;;;GAWG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,iBAO9B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* A mock handler for net_version that always returns a specific
|
|
5
|
+
* hardcoded result.
|
|
6
|
+
*
|
|
7
|
+
* @param _request - Incoming JSON-RPC request. Ignored for this specific
|
|
8
|
+
* handler.
|
|
9
|
+
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
10
|
+
* result.
|
|
11
|
+
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
12
|
+
* @param end - The `json-rpc-engine` middleware end handler.
|
|
13
|
+
* @returns The JSON-RPC response.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getNetworkVersionHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=net-version.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"net-version.d.mts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/net-version.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB;;;;;;;;;;;GAWG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,iBAO9B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mock handler for net_version that always returns a specific
|
|
3
|
+
* hardcoded result.
|
|
4
|
+
*
|
|
5
|
+
* @param _request - Incoming JSON-RPC request. Ignored for this specific
|
|
6
|
+
* handler.
|
|
7
|
+
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
8
|
+
* result.
|
|
9
|
+
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
10
|
+
* @param end - The `json-rpc-engine` middleware end handler.
|
|
11
|
+
* @returns The JSON-RPC response.
|
|
12
|
+
*/
|
|
13
|
+
export async function getNetworkVersionHandler(_request, response, _next, end) {
|
|
14
|
+
// For now this will return a mocked result, this should probably match
|
|
15
|
+
// whatever network the simulation is using.
|
|
16
|
+
response.result = '1';
|
|
17
|
+
return end();
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=net-version.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"net-version.mjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/net-version.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,QAAwB,EACxB,QAAsC,EACtC,KAAgC,EAChC,GAA6B;IAE7B,uEAAuE;IACvE,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC;IAEtB,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\n/**\n * A mock handler for net_version that always returns a specific\n * hardcoded result.\n *\n * @param _request - Incoming JSON-RPC request. Ignored for this specific\n * handler.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n * @returns The JSON-RPC response.\n */\nexport async function getNetworkVersionHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n) {\n // For now this will return a mocked result, this should probably match\n // whatever network the simulation is using.\n response.result = '1';\n\n return end();\n}\n"]}
|
package/dist/options.cjs
CHANGED
|
@@ -10,6 +10,7 @@ const SimulationOptionsStruct = (0, superstruct_1.object)({
|
|
|
10
10
|
locale: (0, superstruct_1.defaulted)((0, superstruct_1.optional)((0, superstruct_1.string)()), constants_1.DEFAULT_LOCALE),
|
|
11
11
|
state: (0, superstruct_1.defaulted)((0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct))), null),
|
|
12
12
|
unencryptedState: (0, superstruct_1.defaulted)((0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct))), null),
|
|
13
|
+
hideBalances: (0, superstruct_1.defaulted)((0, superstruct_1.optional)((0, superstruct_1.boolean)()), false),
|
|
13
14
|
});
|
|
14
15
|
/**
|
|
15
16
|
* Get the options for the simulation.
|
package/dist/options.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AACA,uDAS+B;AAC/B,2CAA6C;AAE7C,+CAA4E;AAE5E,MAAM,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IACrC,QAAQ,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC,EAAE,4BAAgB,CAAC;IACzD,oBAAoB,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC,EAAE,uBAAW,CAAC;IAChE,MAAM,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC,EAAE,0BAAc,CAAC;IACrD,KAAK,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,sBAAQ,EAAC,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;IACxE,gBAAgB,EAAE,IAAA,uBAAS,EACzB,IAAA,sBAAQ,EAAC,IAAA,sBAAQ,EAAC,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC,EAChD,IAAI,CACL;IACD,YAAY,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC,EAAE,KAAK,CAAC;CACpD,CAAC,CAAC;AAoBH;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,OAA8B;IACvD,OAAO,IAAA,oBAAM,EACX,OAAO,EACP,uBAAuB,CACW,CAAC;AACvC,CAAC;AALD,gCAKC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n boolean,\n create,\n defaulted,\n nullable,\n object,\n optional,\n record,\n string,\n} from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { DEFAULT_CURRENCY, DEFAULT_LOCALE, DEFAULT_SRP } from './constants';\n\nconst SimulationOptionsStruct = object({\n currency: defaulted(optional(string()), DEFAULT_CURRENCY),\n secretRecoveryPhrase: defaulted(optional(string()), DEFAULT_SRP),\n locale: defaulted(optional(string()), DEFAULT_LOCALE),\n state: defaulted(optional(nullable(record(string(), JsonStruct))), null),\n unencryptedState: defaulted(\n optional(nullable(record(string(), JsonStruct))),\n null,\n ),\n hideBalances: defaulted(optional(boolean()), false),\n});\n\n/**\n * Options for the simulation.\n *\n * @property secretRecoveryPhrase - The secret recovery phrase to use. This is\n * used to derive addresses and private keys. Defaults to a test recovery\n * phrase.\n * @property locale - The locale to use. Defaults to `en`.\n * @property state - The initial state of the Snap, if any. Defaults to `null`.\n */\nexport type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;\n\n/**\n * Options for the simulation, with defaults filled in.\n *\n * See {@link SimulationUserOptions} for documentation.\n */\nexport type SimulationOptions = Required<SimulationUserOptions>;\n\n/**\n * Get the options for the simulation.\n *\n * @param options - The user options. Any options not specified will be filled\n * in with default values.\n * @returns The simulation options.\n */\nexport function getOptions(options: SimulationUserOptions): SimulationOptions {\n return create(\n options,\n SimulationOptionsStruct,\n ) as Required<SimulationUserOptions>;\n}\n"]}
|
package/dist/options.d.cts
CHANGED
|
@@ -4,6 +4,7 @@ declare const SimulationOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
|
4
4
|
currency?: string | undefined;
|
|
5
5
|
locale?: string | undefined;
|
|
6
6
|
secretRecoveryPhrase?: string | undefined;
|
|
7
|
+
hideBalances?: boolean | undefined;
|
|
7
8
|
unencryptedState?: Record<string, import("@metamask/utils").Json> | null | undefined;
|
|
8
9
|
}, {
|
|
9
10
|
currency: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
@@ -11,6 +12,7 @@ declare const SimulationOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
|
11
12
|
locale: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
12
13
|
state: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | null | undefined, null>;
|
|
13
14
|
unencryptedState: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | null | undefined, null>;
|
|
15
|
+
hideBalances: import("@metamask/superstruct").Struct<boolean | undefined, null>;
|
|
14
16
|
}>;
|
|
15
17
|
/**
|
|
16
18
|
* Options for the simulation.
|
package/dist/options.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.cts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"options.d.cts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAenD,QAAA,MAAM,uBAAuB;;;;;;;;;;;;;;EAU3B,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE1E;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAAC;AAEhE;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,qBAAqB,GAAG,iBAAiB,CAK5E"}
|
package/dist/options.d.mts
CHANGED
|
@@ -4,6 +4,7 @@ declare const SimulationOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
|
4
4
|
currency?: string | undefined;
|
|
5
5
|
locale?: string | undefined;
|
|
6
6
|
secretRecoveryPhrase?: string | undefined;
|
|
7
|
+
hideBalances?: boolean | undefined;
|
|
7
8
|
unencryptedState?: Record<string, import("@metamask/utils").Json> | null | undefined;
|
|
8
9
|
}, {
|
|
9
10
|
currency: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
@@ -11,6 +12,7 @@ declare const SimulationOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
|
11
12
|
locale: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
12
13
|
state: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | null | undefined, null>;
|
|
13
14
|
unencryptedState: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | null | undefined, null>;
|
|
15
|
+
hideBalances: import("@metamask/superstruct").Struct<boolean | undefined, null>;
|
|
14
16
|
}>;
|
|
15
17
|
/**
|
|
16
18
|
* Options for the simulation.
|
package/dist/options.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.mts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"options.d.mts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAenD,QAAA,MAAM,uBAAuB;;;;;;;;;;;;;;EAU3B,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE1E;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAAC;AAEhE;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,qBAAqB,GAAG,iBAAiB,CAK5E"}
|
package/dist/options.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { create, defaulted, nullable, object, optional, record, string } from "@metamask/superstruct";
|
|
1
|
+
import { boolean, create, defaulted, nullable, object, optional, record, string } from "@metamask/superstruct";
|
|
2
2
|
import { JsonStruct } from "@metamask/utils";
|
|
3
3
|
import { DEFAULT_CURRENCY, DEFAULT_LOCALE, DEFAULT_SRP } from "./constants.mjs";
|
|
4
4
|
const SimulationOptionsStruct = object({
|
|
@@ -7,6 +7,7 @@ const SimulationOptionsStruct = object({
|
|
|
7
7
|
locale: defaulted(optional(string()), DEFAULT_LOCALE),
|
|
8
8
|
state: defaulted(optional(nullable(record(string(), JsonStruct))), null),
|
|
9
9
|
unencryptedState: defaulted(optional(nullable(record(string(), JsonStruct))), null),
|
|
10
|
+
hideBalances: defaulted(optional(boolean()), false),
|
|
10
11
|
});
|
|
11
12
|
/**
|
|
12
13
|
* Get the options for the simulation.
|
package/dist/options.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.mjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,SAAS,EACT,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACP,8BAA8B;AAC/B,OAAO,EAAE,UAAU,EAAE,wBAAwB;AAE7C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,wBAAoB;AAE5E,MAAM,uBAAuB,GAAG,MAAM,CAAC;IACrC,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,gBAAgB,CAAC;IACzD,oBAAoB,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC;IAChE,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,cAAc,CAAC;IACrD,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;IACxE,gBAAgB,EAAE,SAAS,CACzB,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,EAChD,IAAI,CACL;
|
|
1
|
+
{"version":3,"file":"options.mjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,SAAS,EACT,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACP,8BAA8B;AAC/B,OAAO,EAAE,UAAU,EAAE,wBAAwB;AAE7C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,wBAAoB;AAE5E,MAAM,uBAAuB,GAAG,MAAM,CAAC;IACrC,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,gBAAgB,CAAC;IACzD,oBAAoB,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC;IAChE,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,cAAc,CAAC;IACrD,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;IACxE,gBAAgB,EAAE,SAAS,CACzB,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,EAChD,IAAI,CACL;IACD,YAAY,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC;CACpD,CAAC,CAAC;AAoBH;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,OAA8B;IACvD,OAAO,MAAM,CACX,OAAO,EACP,uBAAuB,CACW,CAAC;AACvC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n boolean,\n create,\n defaulted,\n nullable,\n object,\n optional,\n record,\n string,\n} from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { DEFAULT_CURRENCY, DEFAULT_LOCALE, DEFAULT_SRP } from './constants';\n\nconst SimulationOptionsStruct = object({\n currency: defaulted(optional(string()), DEFAULT_CURRENCY),\n secretRecoveryPhrase: defaulted(optional(string()), DEFAULT_SRP),\n locale: defaulted(optional(string()), DEFAULT_LOCALE),\n state: defaulted(optional(nullable(record(string(), JsonStruct))), null),\n unencryptedState: defaulted(\n optional(nullable(record(string(), JsonStruct))),\n null,\n ),\n hideBalances: defaulted(optional(boolean()), false),\n});\n\n/**\n * Options for the simulation.\n *\n * @property secretRecoveryPhrase - The secret recovery phrase to use. This is\n * used to derive addresses and private keys. Defaults to a test recovery\n * phrase.\n * @property locale - The locale to use. Defaults to `en`.\n * @property state - The initial state of the Snap, if any. Defaults to `null`.\n */\nexport type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;\n\n/**\n * Options for the simulation, with defaults filled in.\n *\n * See {@link SimulationUserOptions} for documentation.\n */\nexport type SimulationOptions = Required<SimulationUserOptions>;\n\n/**\n * Get the options for the simulation.\n *\n * @param options - The user options. Any options not specified will be filled\n * in with default values.\n * @returns The simulation options.\n */\nexport function getOptions(options: SimulationUserOptions): SimulationOptions {\n return create(\n options,\n SimulationOptionsStruct,\n ) as Required<SimulationUserOptions>;\n}\n"]}
|