@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/structs.ts"],"names":[],"mappings":";AAAA,SAAS,kBAAkB,iBAAiB;AAC5C,SAAS,wBAAwB;AACjC;AAAA,EACE;AA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dk';\nimport { JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n union,\n record,\n any,\n func,\n type,\n} from '@metamask/superstruct';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SignatureOptionsStruct = object({\n /**\n * The origin making the signature request.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address signing the signature request. Defaults to a randomly generated\n * address.\n */\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `string`, an object, or an array of objects. This covers the data types\n * for the supported signature methods. Defaults to `0x`.\n */\n data: defaulted(\n union([\n StrictHexStruct,\n literal('0x'),\n record(string(), any()),\n array(record(string(), any())),\n ]),\n '0x',\n ),\n\n /**\n * The signature method being used.\n */\n signatureMethod: defaulted(\n union([\n literal('eth_sign'),\n literal('personal_sign'),\n literal('eth_signTypedData'),\n literal('eth_signTypedData_v3'),\n literal('eth_signTypedData_v4'),\n ]),\n 'personal_sign',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const JsonRpcMockOptionsStruct = object({\n method: string(),\n result: JsonStruct,\n});\n\nexport const InterfaceStruct = type({\n content: optional(JSXElementStruct),\n});\n\nexport const SnapResponseWithoutInterfaceStruct = object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n});\n\nexport const SnapResponseWithInterfaceStruct = assign(\n SnapResponseWithoutInterfaceStruct,\n object({\n getInterface: func(),\n }),\n);\n\nexport const SnapResponseStruct = union([\n SnapResponseWithoutInterfaceStruct,\n SnapResponseWithInterfaceStruct,\n]);\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkD653LBAYjs = require('./chunk-D653LBAY.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkLACTK6EOjs = require('./chunk-LACTK6EO.js');
|
|
@@ -22,7 +22,7 @@ function createStore({ state, unencryptedState }) {
|
|
|
22
22
|
mocks: _chunkLACTK6EOjs.mocksSlice.reducer,
|
|
23
23
|
notifications: _chunk2YE2P5BZjs.notificationsSlice.reducer,
|
|
24
24
|
state: _chunkLBC2OGSNjs.stateSlice.reducer,
|
|
25
|
-
ui:
|
|
25
|
+
ui: _chunkD653LBAYjs.uiSlice.reducer
|
|
26
26
|
},
|
|
27
27
|
middleware: (getDefaultMiddleware) => getDefaultMiddleware({ thunk: false }).concat(sagaMiddleware)
|
|
28
28
|
});
|
|
@@ -51,4 +51,4 @@ function createStore({ state, unencryptedState }) {
|
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
exports.createStore = createStore;
|
|
54
|
-
//# sourceMappingURL=chunk-
|
|
54
|
+
//# sourceMappingURL=chunk-K7MK6LQU.js.map
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
object,
|
|
8
8
|
string,
|
|
9
9
|
type
|
|
10
|
-
} from "superstruct";
|
|
10
|
+
} from "@metamask/superstruct";
|
|
11
11
|
var SnapsEnvironmentOptionsStruct = type({
|
|
12
12
|
server: defaulted(
|
|
13
13
|
object({
|
|
@@ -25,4 +25,4 @@ function getOptions(testEnvironmentOptions) {
|
|
|
25
25
|
export {
|
|
26
26
|
getOptions
|
|
27
27
|
};
|
|
28
|
-
//# sourceMappingURL=chunk-
|
|
28
|
+
//# sourceMappingURL=chunk-KOPPL55J.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/options.ts"],"sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from '@metamask/superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,gCAAgC,KAAK;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,MACL,SAAS,UAAU,QAAQ,GAAG,IAAI;AAAA,MAClC,MAAM,UAAU,OAAO,GAAG,CAAC;AAAA,MAC3B,MAAM,UAAU,OAAO,GAAG,QAAQ,IAAI,CAAC;AAAA,IACzC,CAAC;AAAA,IACD,CAAC;AAAA,EACH;AACF,CAAC;AAuCM,SAAS,WAAW,wBAAiD;AAC1E,SAAO,OAAO,wBAAwB,6BAA6B;AACrE;","names":[]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/internals/simulation/constants.ts
|
|
2
2
|
var DEFAULT_SRP = "test test test test test test test test test test test ball";
|
|
3
3
|
var DEFAULT_LOCALE = "en";
|
|
4
|
+
var DEFAULT_CURRENCY = "usd";
|
|
4
5
|
var DEFAULT_JSON_RPC_ENDPOINT = "https://cloudflare-eth.com/";
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
exports.DEFAULT_SRP = DEFAULT_SRP; exports.DEFAULT_LOCALE = DEFAULT_LOCALE; exports.DEFAULT_CURRENCY = DEFAULT_CURRENCY; exports.DEFAULT_JSON_RPC_ENDPOINT = DEFAULT_JSON_RPC_ENDPOINT;
|
|
13
|
+
//# sourceMappingURL=chunk-KPRLFCKD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/constants.ts"],"names":[],"mappings":";AAIO,IAAM,cACX;AAKK,IAAM,iBAAiB;AAKvB,IAAM,mBAAmB;AAKzB,IAAM,4BAA4B","sourcesContent":["/**\n * A secret recovery phrase that is used for testing purposes. Do not use this\n * to store any real funds!\n */\nexport const DEFAULT_SRP =\n 'test test test test test test test test test test test ball';\n\n/**\n * The default locale.\n */\nexport const DEFAULT_LOCALE = 'en';\n\n/**\n * The default currency.\n */\nexport const DEFAULT_CURRENCY = 'usd';\n\n/**\n * The default JSON-RPC endpoint for Ethereum requests.\n */\nexport const DEFAULT_JSON_RPC_ENDPOINT = 'https://cloudflare-eth.com/';\n"]}
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
var _chunk2JTGBHPRjs = require('./chunk-2JTGBHPR.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkAMAL4SJHjs = require('./chunk-AMAL4SJH.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkDUVKGPX5js = require('./chunk-DUVKGPX5.js');
|
|
7
10
|
|
|
8
11
|
|
|
9
12
|
var _chunkTZB4LBT7js = require('./chunk-TZB4LBT7.js');
|
|
@@ -12,16 +15,22 @@ var _chunkTZB4LBT7js = require('./chunk-TZB4LBT7.js');
|
|
|
12
15
|
|
|
13
16
|
|
|
14
17
|
|
|
15
|
-
var
|
|
18
|
+
var _chunkGLPGOEVEjs = require('./chunk-GLPGOEVE.js');
|
|
16
19
|
|
|
17
20
|
|
|
18
21
|
|
|
19
22
|
var _chunkLACTK6EOjs = require('./chunk-LACTK6EO.js');
|
|
20
23
|
|
|
21
24
|
// src/helpers.ts
|
|
25
|
+
var _snapssdk = require('@metamask/snaps-sdk');
|
|
22
26
|
var _snapsutils = require('@metamask/snaps-utils');
|
|
27
|
+
var _superstruct = require('@metamask/superstruct');
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
23
33
|
var _utils = require('@metamask/utils');
|
|
24
|
-
var _superstruct = require('superstruct');
|
|
25
34
|
var log = _utils.createModuleLogger.call(void 0, _chunkTZB4LBT7js.rootLogger, "helpers");
|
|
26
35
|
function getOptions(snapId, options) {
|
|
27
36
|
if (typeof snapId === "object") {
|
|
@@ -30,7 +39,31 @@ function getOptions(snapId, options) {
|
|
|
30
39
|
return [snapId, options];
|
|
31
40
|
}
|
|
32
41
|
function assertIsResponseWithInterface(response) {
|
|
33
|
-
_utils.assertStruct.call(void 0, response,
|
|
42
|
+
_utils.assertStruct.call(void 0, response, _chunkGLPGOEVEjs.SnapResponseWithInterfaceStruct);
|
|
43
|
+
}
|
|
44
|
+
function assertIsAlertDialog(ui) {
|
|
45
|
+
_utils.assert.call(void 0, _utils.hasProperty.call(void 0, ui, "type") && ui.type === _snapssdk.DialogType.Alert);
|
|
46
|
+
}
|
|
47
|
+
function assertIsConfirmationDialog(ui) {
|
|
48
|
+
_utils.assert.call(void 0, _utils.hasProperty.call(void 0, ui, "type") && ui.type === _snapssdk.DialogType.Confirmation);
|
|
49
|
+
}
|
|
50
|
+
function assertIsPromptDialog(ui) {
|
|
51
|
+
_utils.assert.call(void 0, _utils.hasProperty.call(void 0, ui, "type") && ui.type === _snapssdk.DialogType.Prompt);
|
|
52
|
+
}
|
|
53
|
+
function assertIsCustomDialog(ui) {
|
|
54
|
+
_utils.assert.call(void 0, !_utils.hasProperty.call(void 0, ui, "type"));
|
|
55
|
+
}
|
|
56
|
+
function assertCustomDialogHasFooter(ui) {
|
|
57
|
+
const footer = _chunkDUVKGPX5js.getElementByType.call(void 0, ui.content, "Footer");
|
|
58
|
+
_utils.assert.call(void 0, footer && _snapsutils.getJsxChildren.call(void 0, footer).length === 2);
|
|
59
|
+
}
|
|
60
|
+
function assertCustomDialogHasPartialFooter(ui) {
|
|
61
|
+
const footer = _chunkDUVKGPX5js.getElementByType.call(void 0, ui.content, "Footer");
|
|
62
|
+
_utils.assert.call(void 0, footer && _snapsutils.getJsxChildren.call(void 0, footer).length === 1);
|
|
63
|
+
}
|
|
64
|
+
function assertCustomDialogHasNoFooter(ui) {
|
|
65
|
+
const footer = _chunkDUVKGPX5js.getElementByType.call(void 0, ui.content, "Footer");
|
|
66
|
+
_utils.assert.call(void 0, !footer);
|
|
34
67
|
}
|
|
35
68
|
async function installSnap(snapId, options = {}) {
|
|
36
69
|
const resolvedOptions = getOptions(snapId, options);
|
|
@@ -47,8 +80,8 @@ async function installSnap(snapId, options = {}) {
|
|
|
47
80
|
origin: transactionOrigin,
|
|
48
81
|
chainId,
|
|
49
82
|
...transaction
|
|
50
|
-
} = _superstruct.create.call(void 0, request,
|
|
51
|
-
const response = await
|
|
83
|
+
} = _superstruct.create.call(void 0, request, _chunkGLPGOEVEjs.TransactionOptionsStruct);
|
|
84
|
+
const response = await _chunkAMAL4SJHjs.handleRequest.call(void 0, {
|
|
52
85
|
snapId: installedSnapId,
|
|
53
86
|
store,
|
|
54
87
|
executionService,
|
|
@@ -69,7 +102,7 @@ async function installSnap(snapId, options = {}) {
|
|
|
69
102
|
};
|
|
70
103
|
const onCronjob = (request) => {
|
|
71
104
|
log("Running cronjob %o.", options);
|
|
72
|
-
return
|
|
105
|
+
return _chunkAMAL4SJHjs.handleRequest.call(void 0, {
|
|
73
106
|
snapId: installedSnapId,
|
|
74
107
|
store,
|
|
75
108
|
executionService,
|
|
@@ -82,7 +115,7 @@ async function installSnap(snapId, options = {}) {
|
|
|
82
115
|
return {
|
|
83
116
|
request: (request) => {
|
|
84
117
|
log("Sending request %o.", request);
|
|
85
|
-
return
|
|
118
|
+
return _chunkAMAL4SJHjs.handleRequest.call(void 0, {
|
|
86
119
|
snapId: installedSnapId,
|
|
87
120
|
store,
|
|
88
121
|
executionService,
|
|
@@ -98,9 +131,9 @@ async function installSnap(snapId, options = {}) {
|
|
|
98
131
|
log("Requesting signature %o.", request);
|
|
99
132
|
const { origin: signatureOrigin, ...signature } = _superstruct.create.call(void 0,
|
|
100
133
|
request,
|
|
101
|
-
|
|
134
|
+
_chunkGLPGOEVEjs.SignatureOptionsStruct
|
|
102
135
|
);
|
|
103
|
-
const response = await
|
|
136
|
+
const response = await _chunkAMAL4SJHjs.handleRequest.call(void 0, {
|
|
104
137
|
snapId: installedSnapId,
|
|
105
138
|
store,
|
|
106
139
|
executionService,
|
|
@@ -122,7 +155,7 @@ async function installSnap(snapId, options = {}) {
|
|
|
122
155
|
runCronjob: onCronjob,
|
|
123
156
|
onHomePage: async () => {
|
|
124
157
|
log("Rendering home page.");
|
|
125
|
-
const response = await
|
|
158
|
+
const response = await _chunkAMAL4SJHjs.handleRequest.call(void 0, {
|
|
126
159
|
snapId: installedSnapId,
|
|
127
160
|
store,
|
|
128
161
|
executionService,
|
|
@@ -138,7 +171,7 @@ async function installSnap(snapId, options = {}) {
|
|
|
138
171
|
},
|
|
139
172
|
mockJsonRpc(mock) {
|
|
140
173
|
log("Mocking JSON-RPC request %o.", mock);
|
|
141
|
-
const { method, result } = _superstruct.create.call(void 0, mock,
|
|
174
|
+
const { method, result } = _superstruct.create.call(void 0, mock, _chunkGLPGOEVEjs.JsonRpcMockOptionsStruct);
|
|
142
175
|
store.dispatch(_chunkLACTK6EOjs.addJsonRpcMock.call(void 0, { method, result }));
|
|
143
176
|
return {
|
|
144
177
|
unmock() {
|
|
@@ -159,5 +192,12 @@ async function installSnap(snapId, options = {}) {
|
|
|
159
192
|
|
|
160
193
|
|
|
161
194
|
|
|
162
|
-
|
|
163
|
-
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
exports.assertIsAlertDialog = assertIsAlertDialog; exports.assertIsConfirmationDialog = assertIsConfirmationDialog; exports.assertIsPromptDialog = assertIsPromptDialog; exports.assertIsCustomDialog = assertIsCustomDialog; exports.assertCustomDialogHasFooter = assertCustomDialogHasFooter; exports.assertCustomDialogHasPartialFooter = assertCustomDialogHasPartialFooter; exports.assertCustomDialogHasNoFooter = assertCustomDialogHasNoFooter; exports.installSnap = installSnap;
|
|
203
|
+
//# sourceMappingURL=chunk-LPMHPAZK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers.ts"],"names":[],"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,EA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B;AAAA,IAC3C;AAAA,EACF;AACF","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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getPermissionSpecifications
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OHRFO2BL.mjs";
|
|
4
4
|
import {
|
|
5
5
|
UNRESTRICTED_METHODS
|
|
6
6
|
} from "./chunk-57SGDM5B.mjs";
|
|
@@ -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
|
})
|
|
@@ -92,4 +94,4 @@ export {
|
|
|
92
94
|
getControllers,
|
|
93
95
|
registerSnap
|
|
94
96
|
};
|
|
95
|
-
//# sourceMappingURL=chunk-
|
|
97
|
+
//# sourceMappingURL=chunk-LSKT2AUS.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/controllers.ts"],"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"],"mappings":";;;;;;;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BAA0B,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;","names":[]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// src/internals/simulation/constants.ts
|
|
2
2
|
var DEFAULT_SRP = "test test test test test test test test test test test ball";
|
|
3
3
|
var DEFAULT_LOCALE = "en";
|
|
4
|
+
var DEFAULT_CURRENCY = "usd";
|
|
4
5
|
var DEFAULT_JSON_RPC_ENDPOINT = "https://cloudflare-eth.com/";
|
|
5
6
|
|
|
6
7
|
export {
|
|
7
8
|
DEFAULT_SRP,
|
|
8
9
|
DEFAULT_LOCALE,
|
|
10
|
+
DEFAULT_CURRENCY,
|
|
9
11
|
DEFAULT_JSON_RPC_ENDPOINT
|
|
10
12
|
};
|
|
11
|
-
//# sourceMappingURL=chunk-
|
|
13
|
+
//# sourceMappingURL=chunk-LVNNGMJ2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internals/simulation/constants.ts"],"sourcesContent":["/**\n * A secret recovery phrase that is used for testing purposes. Do not use this\n * to store any real funds!\n */\nexport const DEFAULT_SRP =\n 'test test test test test test test test test test test ball';\n\n/**\n * The default locale.\n */\nexport const DEFAULT_LOCALE = 'en';\n\n/**\n * The default JSON-RPC endpoint for Ethereum requests.\n */\nexport const DEFAULT_JSON_RPC_ENDPOINT = 'https://cloudflare-eth.com/';\n"],"mappings":";AAIO,IAAM,cACX;AAKK,IAAM,iBAAiB;AAKvB,IAAM,4BAA4B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/constants.ts"],"sourcesContent":["/**\n * A secret recovery phrase that is used for testing purposes. Do not use this\n * to store any real funds!\n */\nexport const DEFAULT_SRP =\n 'test test test test test test test test test test test ball';\n\n/**\n * The default locale.\n */\nexport const DEFAULT_LOCALE = 'en';\n\n/**\n * The default currency.\n */\nexport const DEFAULT_CURRENCY = 'usd';\n\n/**\n * The default JSON-RPC endpoint for Ethereum requests.\n */\nexport const DEFAULT_JSON_RPC_ENDPOINT = 'https://cloudflare-eth.com/';\n"],"mappings":";AAIO,IAAM,cACX;AAKK,IAAM,iBAAiB;AAKvB,IAAM,mBAAmB;AAKzB,IAAM,4BAA4B;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
getGetPreferencesMethodImplementation
|
|
3
|
+
} from "./chunk-QRVFWATH.mjs";
|
|
4
4
|
import {
|
|
5
5
|
getCreateInterfaceImplementation,
|
|
6
6
|
getGetInterfaceImplementation
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
getShowNativeNotificationImplementation
|
|
11
11
|
} from "./chunk-ALRZENWP.mjs";
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
} from "./chunk-
|
|
13
|
+
getRequestUserApprovalImplementation
|
|
14
|
+
} from "./chunk-24CGIQLL.mjs";
|
|
15
15
|
import {
|
|
16
16
|
getClearSnapStateMethodImplementation,
|
|
17
17
|
getGetSnapStateMethodImplementation,
|
|
@@ -48,13 +48,13 @@ function getPermissionSpecifications({
|
|
|
48
48
|
...hooks,
|
|
49
49
|
// Snaps-specific hooks.
|
|
50
50
|
clearSnapState: getClearSnapStateMethodImplementation(runSaga),
|
|
51
|
-
|
|
51
|
+
getPreferences: getGetPreferencesMethodImplementation(options),
|
|
52
52
|
getSnapState: getGetSnapStateMethodImplementation(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: getRequestUserApprovalImplementation(runSaga),
|
|
58
58
|
showInAppNotification: getShowInAppNotificationImplementation(runSaga),
|
|
59
59
|
showNativeNotification: getShowNativeNotificationImplementation(runSaga),
|
|
60
60
|
updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),
|
|
@@ -86,4 +86,4 @@ export {
|
|
|
86
86
|
getPermissionSpecifications,
|
|
87
87
|
getEndowments
|
|
88
88
|
};
|
|
89
|
-
//# sourceMappingURL=chunk-
|
|
89
|
+
//# sourceMappingURL=chunk-OHRFO2BL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/specifications.ts"],"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"],"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;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk2RJYSYUBjs = require('./chunk-2RJYSYUB.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk3NP6BDGKjs = require('./chunk-3NP6BDGK.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkN6MAO223js = require('./chunk-N6MAO223.js');
|
|
@@ -33,7 +33,7 @@ var SnapsEnvironment = class extends _jestenvironmentnode2.default {
|
|
|
33
33
|
_chunkPHUTP7NBjs.__privateAdd.call(void 0, this, _options, void 0);
|
|
34
34
|
_chunkPHUTP7NBjs.__privateAdd.call(void 0, this, _server, void 0);
|
|
35
35
|
_chunkPHUTP7NBjs.__privateAdd.call(void 0, this, _instance, void 0);
|
|
36
|
-
_chunkPHUTP7NBjs.__privateSet.call(void 0, this, _options,
|
|
36
|
+
_chunkPHUTP7NBjs.__privateSet.call(void 0, this, _options, _chunk2RJYSYUBjs.getOptions.call(void 0, options.projectConfig.testEnvironmentOptions));
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Set up the environment. This starts the built-in HTTP server, and creates a
|
|
@@ -72,7 +72,7 @@ var SnapsEnvironment = class extends _jestenvironmentnode2.default {
|
|
|
72
72
|
*/
|
|
73
73
|
async installSnap(snapId = this.snapId, options = {}) {
|
|
74
74
|
await _chunkPHUTP7NBjs.__privateGet.call(void 0, this, _instance)?.executionService.terminateAllSnaps();
|
|
75
|
-
_chunkPHUTP7NBjs.__privateSet.call(void 0, this, _instance, await
|
|
75
|
+
_chunkPHUTP7NBjs.__privateSet.call(void 0, this, _instance, await _chunk3NP6BDGKjs.handleInstallSnap.call(void 0, snapId, options));
|
|
76
76
|
return _chunkPHUTP7NBjs.__privateGet.call(void 0, this, _instance);
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
@@ -101,4 +101,4 @@ var environment_default = SnapsEnvironment;
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
exports.SnapsEnvironment = SnapsEnvironment; exports.environment_default = environment_default;
|
|
104
|
-
//# sourceMappingURL=chunk-
|
|
104
|
+
//# sourceMappingURL=chunk-OO6IVUCV.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
uiSlice
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZJQSGRNK.mjs";
|
|
4
4
|
import {
|
|
5
5
|
mocksSlice
|
|
6
6
|
} from "./chunk-H2464AXT.mjs";
|
|
@@ -51,4 +51,4 @@ function createStore({ state, unencryptedState }) {
|
|
|
51
51
|
export {
|
|
52
52
|
createStore
|
|
53
53
|
};
|
|
54
|
-
//# sourceMappingURL=chunk-
|
|
54
|
+
//# sourceMappingURL=chunk-ORR7AE5X.mjs.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getInterface,
|
|
3
3
|
getInterfaceActions
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6JPBXAHM.mjs";
|
|
5
5
|
import {
|
|
6
6
|
SnapResponseStruct
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-C26TYXXD.mjs";
|
|
8
8
|
import {
|
|
9
9
|
clearNotifications,
|
|
10
10
|
getNotifications
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
ComponentOrElementStruct
|
|
16
16
|
} from "@metamask/snaps-sdk";
|
|
17
17
|
import { unwrapError } from "@metamask/snaps-utils";
|
|
18
|
+
import { is } from "@metamask/superstruct";
|
|
18
19
|
import {
|
|
19
20
|
assert,
|
|
20
21
|
getSafeJson,
|
|
@@ -22,7 +23,6 @@ import {
|
|
|
22
23
|
isPlainObject
|
|
23
24
|
} from "@metamask/utils";
|
|
24
25
|
import { nanoid } from "@reduxjs/toolkit";
|
|
25
|
-
import { is } from "superstruct";
|
|
26
26
|
function handleRequest({
|
|
27
27
|
snapId,
|
|
28
28
|
store,
|
|
@@ -150,4 +150,4 @@ export {
|
|
|
150
150
|
getInterfaceFromResult,
|
|
151
151
|
getInterfaceApi
|
|
152
152
|
};
|
|
153
|
-
//# sourceMappingURL=chunk-
|
|
153
|
+
//# sourceMappingURL=chunk-PDOVVC74.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/request.ts"],"sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n type ComponentOrElement,\n ComponentOrElementStruct,\n type JsonRpcError,\n type SnapId,\n} from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport { unwrapError } from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport {\n assert,\n getSafeJson,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { nanoid } from '@reduxjs/toolkit';\n\nimport type {\n RequestOptions,\n SnapHandlerInterface,\n SnapRequest,\n} from '../types';\nimport type { RunSagaFunction, Store } from './simulation';\nimport {\n clearNotifications,\n getInterface,\n getInterfaceActions,\n getNotifications,\n} from './simulation';\nimport type { RootControllerMessenger } from './simulation/controllers';\nimport { SnapResponseStruct } from './structs';\n\nexport type HandleRequestOptions = {\n snapId: SnapId;\n store: Store;\n executionService: AbstractExecutionService<unknown>;\n handler: HandlerType;\n controllerMessenger: RootControllerMessenger;\n runSaga: RunSagaFunction;\n request: RequestOptions;\n};\n\n/**\n * Send a JSON-RPC request to the Snap, and wrap the response in a\n * {@link SnapResponse} object.\n *\n * @param options - The request options.\n * @param options.snapId - The ID of the Snap to send the request to.\n * @param options.store - The Redux store.\n * @param options.executionService - The execution service to use to send the\n * request.\n * @param options.handler - The handler to use to send the request.\n * @param options.controllerMessenger - The controller messenger used to call actions.\n * @param options.runSaga - A function to run a saga outside the usual Redux\n * flow.\n * @param options.request - The request to send.\n * @param options.request.id - The ID of the request. If not provided, a random\n * ID will be generated.\n * @param options.request.origin - The origin of the request. Defaults to\n * `https://metamask.io`.\n * @returns The response, wrapped in a {@link SnapResponse} object.\n */\nexport function handleRequest({\n snapId,\n store,\n executionService,\n handler,\n controllerMessenger,\n runSaga,\n request: { id = nanoid(), origin = 'https://metamask.io', ...options },\n}: HandleRequestOptions): SnapRequest {\n const getInterfaceError = () => {\n throw new Error(\n 'Unable to get the interface from the Snap: The request to the Snap failed.',\n );\n };\n\n const promise = executionService\n .handleRpcRequest(snapId, {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n })\n .then(async (result) => {\n const notifications = getNotifications(store.getState());\n store.dispatch(clearNotifications());\n\n try {\n const getInterfaceFn = await getInterfaceApi(\n result,\n snapId,\n controllerMessenger,\n );\n\n return {\n id: String(id),\n response: {\n result: getSafeJson(result),\n },\n notifications,\n ...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),\n };\n } catch (error) {\n const [unwrappedError] = unwrapError(error);\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }\n })\n .catch((error) => {\n const [unwrappedError] = unwrapError(error);\n\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }) as unknown as SnapRequest;\n\n promise.getInterface = async () => {\n const sagaPromise = runSaga(\n getInterface,\n runSaga,\n snapId,\n controllerMessenger,\n ).toPromise();\n const result = await Promise.race([promise, sagaPromise]);\n\n // If the request promise has resolved to an error, we should throw\n // instead of waiting for an interface that likely will never be displayed\n if (\n is(result, SnapResponseStruct) &&\n hasProperty(result.response, 'error')\n ) {\n throw new Error(\n `Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${\n (result.response.error as JsonRpcError).message\n }`,\n );\n }\n\n return await sagaPromise;\n };\n\n return promise;\n}\n\n/**\n * Get the interface ID from the result if it's available or create a new interface if the result contains static components.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The interface ID or undefined if the result doesn't include content.\n */\nexport async function getInterfaceFromResult(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n) {\n if (isPlainObject(result) && hasProperty(result, 'id')) {\n return result.id as string;\n }\n\n if (isPlainObject(result) && hasProperty(result, 'content')) {\n assert(\n is(result.content, ComponentOrElementStruct),\n 'The Snap returned an invalid interface.',\n );\n const id = await controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n result.content as ComponentOrElement,\n );\n\n return id;\n }\n\n return undefined;\n}\n\n/**\n * Get the response content from the `SnapInterfaceController` and include the\n * interaction methods.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The content components if any.\n */\nexport async function getInterfaceApi(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): Promise<(() => SnapHandlerInterface) | undefined> {\n const interfaceId = await getInterfaceFromResult(\n result,\n snapId,\n controllerMessenger,\n );\n\n if (interfaceId) {\n return () => {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n interfaceId,\n );\n\n const actions = getInterfaceActions(snapId, controllerMessenger, {\n id: interfaceId,\n content,\n });\n\n return {\n content,\n ...actions,\n };\n };\n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AA,QACJ;AAAA,MACF,CAAC;AAED,aAAO;AAAA,QACL;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createJsonRpcEngine
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3J2IBWXV.mjs";
|
|
4
|
+
import {
|
|
5
|
+
resolveWithSaga
|
|
6
|
+
} from "./chunk-6JPBXAHM.mjs";
|
|
4
7
|
import {
|
|
5
8
|
getSnapFile
|
|
6
9
|
} from "./chunk-IWJ4HKDR.mjs";
|
|
7
10
|
import {
|
|
8
11
|
getOptions
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-G333FBBL.mjs";
|
|
10
13
|
import {
|
|
11
14
|
getControllers,
|
|
12
15
|
registerSnap
|
|
13
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-LSKT2AUS.mjs";
|
|
14
17
|
import {
|
|
15
18
|
getEndowments
|
|
16
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-OHRFO2BL.mjs";
|
|
17
20
|
import {
|
|
18
21
|
createStore
|
|
19
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-ORR7AE5X.mjs";
|
|
23
|
+
import {
|
|
24
|
+
getCurrentInterface
|
|
25
|
+
} from "./chunk-ZJQSGRNK.mjs";
|
|
20
26
|
|
|
21
27
|
// src/internals/simulation/simulation.ts
|
|
22
28
|
import { ControllerMessenger } from "@metamask/base-controller";
|
|
@@ -28,8 +34,10 @@ import {
|
|
|
28
34
|
NodeThreadExecutionService,
|
|
29
35
|
setupMultiplex
|
|
30
36
|
} from "@metamask/snaps-controllers/node";
|
|
37
|
+
import { DIALOG_APPROVAL_TYPES } from "@metamask/snaps-rpc-methods";
|
|
31
38
|
import { logError } from "@metamask/snaps-utils";
|
|
32
39
|
import { pipeline } from "readable-stream";
|
|
40
|
+
import { select } from "redux-saga/effects";
|
|
33
41
|
async function handleInstallSnap(snapId, {
|
|
34
42
|
executionService,
|
|
35
43
|
executionServiceOptions,
|
|
@@ -42,7 +50,7 @@ async function handleInstallSnap(snapId, {
|
|
|
42
50
|
const snapFiles = await fetchSnap(snapId, location);
|
|
43
51
|
const { store, runSaga } = createStore(options);
|
|
44
52
|
const controllerMessenger = new ControllerMessenger();
|
|
45
|
-
registerActions(controllerMessenger);
|
|
53
|
+
registerActions(controllerMessenger, runSaga);
|
|
46
54
|
const hooks = getHooks(options, snapFiles, snapId, controllerMessenger);
|
|
47
55
|
const { subjectMetadataController, permissionController } = getControllers({
|
|
48
56
|
controllerMessenger,
|
|
@@ -112,10 +120,15 @@ function getHooks(options, snapFiles, snapId, controllerMessenger) {
|
|
|
112
120
|
"SnapInterfaceController:getInterface",
|
|
113
121
|
snapId,
|
|
114
122
|
...args
|
|
115
|
-
).state
|
|
123
|
+
).state,
|
|
124
|
+
resolveInterface: async (...args) => controllerMessenger.call(
|
|
125
|
+
"SnapInterfaceController:resolveInterface",
|
|
126
|
+
snapId,
|
|
127
|
+
...args
|
|
128
|
+
)
|
|
116
129
|
};
|
|
117
130
|
}
|
|
118
|
-
function registerActions(controllerMessenger) {
|
|
131
|
+
function registerActions(controllerMessenger, runSaga) {
|
|
119
132
|
controllerMessenger.registerActionHandler(
|
|
120
133
|
"PhishingController:maybeUpdateState",
|
|
121
134
|
async () => Promise.resolve()
|
|
@@ -124,6 +137,26 @@ function registerActions(controllerMessenger) {
|
|
|
124
137
|
"PhishingController:testOrigin",
|
|
125
138
|
() => ({ result: false, type: "all" })
|
|
126
139
|
);
|
|
140
|
+
controllerMessenger.registerActionHandler(
|
|
141
|
+
"ApprovalController:hasRequest",
|
|
142
|
+
(opts) => {
|
|
143
|
+
function* getCurrentInterfaceSaga() {
|
|
144
|
+
const currentInterface2 = yield select(getCurrentInterface);
|
|
145
|
+
return currentInterface2;
|
|
146
|
+
}
|
|
147
|
+
const currentInterface = runSaga(
|
|
148
|
+
getCurrentInterfaceSaga
|
|
149
|
+
).result();
|
|
150
|
+
return currentInterface?.type === DIALOG_APPROVAL_TYPES.default && currentInterface?.id === opts?.id;
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
controllerMessenger.registerActionHandler(
|
|
154
|
+
"ApprovalController:acceptRequest",
|
|
155
|
+
async (_id, value) => {
|
|
156
|
+
await runSaga(resolveWithSaga, value).toPromise();
|
|
157
|
+
return { value };
|
|
158
|
+
}
|
|
159
|
+
);
|
|
127
160
|
}
|
|
128
161
|
|
|
129
162
|
export {
|
|
@@ -131,4 +164,4 @@ export {
|
|
|
131
164
|
getHooks,
|
|
132
165
|
registerActions
|
|
133
166
|
};
|
|
134
|
-
//# sourceMappingURL=chunk-
|
|
167
|
+
//# sourceMappingURL=chunk-Q3I6P2ZF.mjs.map
|