@metamask/snaps-jest 8.1.3 → 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 +19 -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-EDFQDZNY.js → chunk-3NP6BDGK.js} +50 -17
- package/dist/chunk-3NP6BDGK.js.map +1 -0
- package/dist/{chunk-AFA4KKWW.mjs → chunk-6JPBXAHM.mjs} +250 -47
- 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-6V5GEUDO.mjs → chunk-7PCHIR6O.mjs} +7 -37
- package/dist/chunk-7PCHIR6O.mjs.map +1 -0
- package/dist/{chunk-2OHD2VKS.js → chunk-AMAL4SJH.js} +11 -37
- 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-K55LIE3W.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-DUVKGPX5.js +509 -0
- 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-IWJ4HKDR.mjs +50 -0
- package/dist/chunk-IWJ4HKDR.mjs.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-3FDEYMQU.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-JXAJWUVZ.js → chunk-OO6IVUCV.js} +5 -5
- package/dist/{chunk-3M4GRUMH.mjs → chunk-ORR7AE5X.mjs} +2 -2
- package/dist/{chunk-UPR3PTSA.mjs → chunk-PDOVVC74.mjs} +10 -36
- package/dist/chunk-PDOVVC74.mjs.map +1 -0
- package/dist/{chunk-E2BYTLOT.mjs → chunk-Q3I6P2ZF.mjs} +43 -10
- 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-U3DVRTS2.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-SW65QYFV.js +50 -0
- package/dist/chunk-SW65QYFV.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-KQBJQLZG.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 +17 -17
- package/dist/environment.mjs +16 -16
- package/dist/helpers.js +30 -16
- package/dist/helpers.mjs +29 -15
- package/dist/index.js +32 -18
- package/dist/index.mjs +31 -17
- package/dist/internals/index.js +33 -21
- package/dist/internals/index.mjs +35 -23
- package/dist/internals/request.js +15 -15
- package/dist/internals/request.mjs +14 -14
- 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/files.js +8 -2
- package/dist/internals/simulation/files.mjs +7 -1
- package/dist/internals/simulation/index.js +31 -19
- package/dist/internals/simulation/index.mjs +33 -21
- package/dist/internals/simulation/interface.js +15 -4
- package/dist/internals/simulation/interface.mjs +16 -5
- 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 +13 -12
- package/dist/internals/simulation/simulation.mjs +12 -11
- 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 +16 -18
- package/dist/matchers.mjs +15 -17
- package/dist/options.js +2 -2
- package/dist/options.mjs +1 -1
- package/dist/setup.js +15 -15
- package/dist/setup.mjs +15 -15
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/helpers.d.ts +43 -1
- package/dist/types/internals/request.d.ts +3 -2
- 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/files.d.ts +36 -0
- package/dist/types/internals/simulation/interface.d.ts +70 -8
- 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 +91 -20
- package/package.json +18 -16
- package/dist/chunk-265BMFM5.js +0 -13
- package/dist/chunk-265BMFM5.js.map +0 -1
- package/dist/chunk-2OHD2VKS.js.map +0 -1
- package/dist/chunk-3FDEYMQU.js.map +0 -1
- package/dist/chunk-44ARQBXS.js.map +0 -1
- package/dist/chunk-6V5GEUDO.mjs.map +0 -1
- package/dist/chunk-74TIKA2T.mjs.map +0 -1
- package/dist/chunk-AFA4KKWW.mjs.map +0 -1
- package/dist/chunk-B73P64TE.mjs.map +0 -1
- package/dist/chunk-E2BYTLOT.mjs.map +0 -1
- package/dist/chunk-EDFQDZNY.js.map +0 -1
- package/dist/chunk-GG2BCPQH.mjs.map +0 -1
- package/dist/chunk-HOI6FPLR.mjs.map +0 -1
- package/dist/chunk-IH7UNS5A.mjs.map +0 -1
- package/dist/chunk-KQBJQLZG.js.map +0 -1
- package/dist/chunk-KSIBNOB2.mjs +0 -13
- package/dist/chunk-KSIBNOB2.mjs.map +0 -1
- package/dist/chunk-MBQHVBLA.js.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-R55KAAM4.js +0 -306
- package/dist/chunk-R55KAAM4.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-TBDYQSRT.mjs +0 -16
- package/dist/chunk-TBDYQSRT.mjs.map +0 -1
- package/dist/chunk-TMAWGVZP.mjs.map +0 -1
- package/dist/chunk-TVD4SWH7.js +0 -16
- package/dist/chunk-TVD4SWH7.js.map +0 -1
- package/dist/chunk-U3DVRTS2.mjs.map +0 -1
- package/dist/chunk-UPR3PTSA.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-K55LIE3W.mjs.map → chunk-CACRY3TX.mjs.map} +0 -0
- /package/dist/{chunk-WMLSD6B5.js.map → chunk-K7MK6LQU.js.map} +0 -0
- /package/dist/{chunk-JXAJWUVZ.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
|
@@ -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
|
-
} from "./chunk-
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/simulation.ts"],"sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport { ControllerMessenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport { mnemonicPhraseToBytes } from '@metamask/key-tree';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n fetchSnap,\n detectSnapLocation,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n SnapId,\n AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport { resolveWithSaga } from './interface';\nimport { getEndowments } from './methods';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { Interface, RunSagaFunction, Store } from './store';\nimport { createStore, getCurrentInterface } from './store';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof AbstractExecutionService<unknown>>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService<unknown>\n >,\n> = ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof AbstractExecutionService>;\n controllerMessenger: ControllerMessenger<ActionConstraint, EventConstraint>;\n runSaga: RunSagaFunction;\n};\n\nexport type MiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * A hook that returns the Snap's auxiliary file for the given path.\n *\n * @param path - The path of the auxiliary file to get.\n * @param encoding - The encoding to use when returning the file.\n * @returns The Snap's auxiliary file for the given path.\n */\n getSnapFile: (\n path: string,\n encoding: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n createInterface: (content: Component) => Promise<string>;\n updateInterface: (id: string, content: Component) => Promise<void>;\n getInterfaceState: (id: string) => InterfaceState;\n resolveInterface: (id: string, value: Json) => Promise<void>;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport async function handleInstallSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const { store, runSaga } = createStore(options);\n\n const controllerMessenger = new ControllerMessenger<any, any>();\n\n registerActions(controllerMessenger, runSaga);\n\n // Set up controllers and JSON-RPC stack.\n const hooks = getHooks(options, snapFiles, snapId, controllerMessenger);\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n hooks,\n permissionMiddleware: permissionController.createPermissionMiddleware({\n origin: snapId,\n }),\n });\n\n // Create execution service.\n const ExecutionService = executionService ?? NodeThreadExecutionService;\n const service = new ExecutionService({\n ...executionServiceOptions,\n messenger: controllerMessenger.getRestricted({\n name: 'ExecutionService',\n allowedActions: [],\n allowedEvents: [],\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error: unknown) => {\n if (error) {\n logError(`Provider stream failure.`, error);\n }\n });\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @param snapFiles - The Snap files.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The hooks for the simulation.\n */\nexport function getHooks(\n options: SimulationOptions,\n snapFiles: FetchedSnapFiles,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): MiddlewareHooks {\n return {\n getMnemonic: async () =>\n Promise.resolve(mnemonicPhraseToBytes(options.secretRecoveryPhrase)),\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n getIsLocked: () => false,\n createInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n ...args,\n ),\n updateInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterface',\n snapId,\n ...args,\n ),\n getInterfaceState: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).state,\n resolveInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:resolveInterface',\n snapId,\n ...args,\n ),\n };\n}\n\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:maybeUpdateState',\n async () => Promise.resolve(),\n );\n\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: 'all' }),\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:hasRequest',\n (opts) => {\n /**\n * Get the current interface from the store.\n *\n * @yields Selects the current interface from the store.\n * @returns The current interface.\n */\n function* getCurrentInterfaceSaga(): SagaIterator {\n const currentInterface: Interface = yield select(getCurrentInterface);\n return currentInterface;\n }\n\n const currentInterface: Interface | undefined = runSaga(\n getCurrentInterfaceSaga,\n ).result();\n return (\n currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n currentInterface?.id === opts?.id\n );\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:acceptRequest',\n async (_id: string, value: unknown) => {\n await runSaga(resolveWithSaga, value).toPromise();\n\n return { value };\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AAEtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,6BAA6B;AAQtC,SAAS,gBAAgB;AAGzB,SAAS,gBAAgB;AAEzB,SAAS,cAAc;AA2GvB,eAAsB,kBAKpB,QACA;AAAA,EACE;AAAA,EACA;AAAA,EACA,SAAS,aAAa,CAAC;AACzB,IAA0C,CAAC,GACnB;AACxB,QAAM,UAAU,WAAW,UAAU;AAGrC,QAAM,WAAW,mBAAmB,QAAQ;AAAA,IAC1C,YAAY;AAAA,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AAU;AAEhD,aAAO,EAAE,MAAM;AAAA,IACjB;AAAA,EACF;AACF;","names":["currentInterface"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/internals/simulation/methods/hooks/get-preferences.ts
|
|
2
|
+
function getGetPreferencesMethodImplementation({
|
|
3
|
+
currency,
|
|
4
|
+
locale
|
|
5
|
+
}) {
|
|
6
|
+
return () => {
|
|
7
|
+
return { currency, locale };
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
getGetPreferencesMethodImplementation
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=chunk-QRVFWATH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/hooks/get-preferences.ts"],"sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getPreferences` hook.\n *\n * @param options - The simulation options.\n * @param options.currency - The currency to use.\n * @param options.locale - The locale to use.\n * @returns The implementation of the `getPreferences` hook.\n */\nexport function getGetPreferencesMethodImplementation({\n currency,\n locale,\n}: SimulationOptions) {\n return () => {\n return { currency, locale };\n };\n}\n"],"mappings":";AAUO,SAAS,sCAAsC;AAAA,EACpD;AAAA,EACA;AACF,GAAsB;AACpB,SAAO,MAAM;AACX,WAAO,EAAE,UAAU,OAAO;AAAA,EAC5B;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkXP4YGQJAjs = require('./chunk-XP4YGQJA.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@ var _chunkJ3I5KZIFjs = require('./chunk-J3I5KZIF.js');
|
|
|
11
11
|
var _chunkGMTKFAWOjs = require('./chunk-GMTKFAWO.js');
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkSNXRXX2Ojs = require('./chunk-SNXRXX2O.js');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -48,13 +48,13 @@ function getPermissionSpecifications({
|
|
|
48
48
|
...hooks,
|
|
49
49
|
// Snaps-specific hooks.
|
|
50
50
|
clearSnapState: _chunkSB5EPHE3js.getClearSnapStateMethodImplementation.call(void 0, runSaga),
|
|
51
|
-
|
|
51
|
+
getPreferences: _chunkXP4YGQJAjs.getGetPreferencesMethodImplementation.call(void 0, options),
|
|
52
52
|
getSnapState: _chunkSB5EPHE3js.getGetSnapStateMethodImplementation.call(void 0, runSaga),
|
|
53
53
|
getUnlockPromise: asyncResolve(true),
|
|
54
54
|
// TODO: Allow the user to specify the result of this function.
|
|
55
55
|
isOnPhishingList: resolve(false),
|
|
56
56
|
maybeUpdatePhishingList: asyncResolve(),
|
|
57
|
-
|
|
57
|
+
requestUserApproval: _chunkSNXRXX2Ojs.getRequestUserApprovalImplementation.call(void 0, runSaga),
|
|
58
58
|
showInAppNotification: _chunkGMTKFAWOjs.getShowInAppNotificationImplementation.call(void 0, runSaga),
|
|
59
59
|
showNativeNotification: _chunkGMTKFAWOjs.getShowNativeNotificationImplementation.call(void 0, runSaga),
|
|
60
60
|
updateSnapState: _chunkSB5EPHE3js.getUpdateSnapStateMethodImplementation.call(void 0, runSaga),
|
|
@@ -86,4 +86,4 @@ async function getEndowments(permissionController, snapId) {
|
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
exports.resolve = resolve; exports.asyncResolve = asyncResolve; exports.getPermissionSpecifications = getPermissionSpecifications; exports.getEndowments = getEndowments;
|
|
89
|
-
//# sourceMappingURL=chunk-
|
|
89
|
+
//# sourceMappingURL=chunk-QYHQ2WWX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/specifications.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,E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AAC,CAAC;AAC/D","sourcesContent":["import type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetPreferencesMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\n getRequestUserApprovalImplementation,\n} from './hooks';\n\nexport type PermissionSpecificationsHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n};\n\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve(result?: unknown) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.runSaga - The function to run a saga outside the usual Redux\n * flow.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n}: GetPermissionSpecificationsOptions) {\n return {\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {\n // Shared hooks.\n ...hooks,\n\n // Snaps-specific hooks.\n clearSnapState: getClearSnapStateMethodImplementation(runSaga),\n getPreferences: getGetPreferencesMethodImplementation(options),\n getSnapState: getGetSnapStateMethodImplementation(runSaga),\n getUnlockPromise: asyncResolve(true),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n requestUserApproval: getRequestUserApprovalImplementation(runSaga),\n showInAppNotification: getShowInAppNotificationImplementation(runSaga),\n showNativeNotification: getShowNativeNotificationImplementation(runSaga),\n updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),\n createInterface: getCreateInterfaceImplementation(controllerMessenger),\n getInterface: getGetInterfaceImplementation(controllerMessenger),\n }),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"]}
|
|
@@ -6,7 +6,7 @@ var _chunkY3JC4WGWjs = require('./chunk-Y3JC4WGW.js');
|
|
|
6
6
|
var _chunkEMTW3H54js = require('./chunk-EMTW3H54.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkKPRLFCKDjs = require('./chunk-KPRLFCKD.js');
|
|
10
10
|
|
|
11
11
|
// src/internals/simulation/middleware/engine.ts
|
|
12
12
|
var _ethjsonrpcmiddleware = require('@metamask/eth-json-rpc-middleware');
|
|
@@ -16,7 +16,7 @@ function createJsonRpcEngine({
|
|
|
16
16
|
store,
|
|
17
17
|
hooks,
|
|
18
18
|
permissionMiddleware,
|
|
19
|
-
endpoint =
|
|
19
|
+
endpoint = _chunkKPRLFCKDjs.DEFAULT_JSON_RPC_ENDPOINT
|
|
20
20
|
}) {
|
|
21
21
|
const engine = new (0, _jsonrpcengine.JsonRpcEngine)();
|
|
22
22
|
engine.push(_chunkEMTW3H54js.createMockMiddleware.call(void 0, store));
|
|
@@ -36,4 +36,4 @@ function createJsonRpcEngine({
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
exports.createJsonRpcEngine = createJsonRpcEngine;
|
|
39
|
-
//# sourceMappingURL=chunk-
|
|
39
|
+
//# sourceMappingURL=chunk-RJNNNCZJ.js.map
|
|
@@ -3,7 +3,10 @@ import {
|
|
|
3
3
|
} from "./chunk-XK5HPZZC.mjs";
|
|
4
4
|
import {
|
|
5
5
|
handleRequest
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-PDOVVC74.mjs";
|
|
7
|
+
import {
|
|
8
|
+
getElementByType
|
|
9
|
+
} from "./chunk-6JPBXAHM.mjs";
|
|
7
10
|
import {
|
|
8
11
|
rootLogger
|
|
9
12
|
} from "./chunk-J4ZPUCLX.mjs";
|
|
@@ -12,16 +15,22 @@ import {
|
|
|
12
15
|
SignatureOptionsStruct,
|
|
13
16
|
SnapResponseWithInterfaceStruct,
|
|
14
17
|
TransactionOptionsStruct
|
|
15
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-C26TYXXD.mjs";
|
|
16
19
|
import {
|
|
17
20
|
addJsonRpcMock,
|
|
18
21
|
removeJsonRpcMock
|
|
19
22
|
} from "./chunk-H2464AXT.mjs";
|
|
20
23
|
|
|
21
24
|
// src/helpers.ts
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import { create } from "superstruct";
|
|
25
|
+
import { DialogType } from "@metamask/snaps-sdk";
|
|
26
|
+
import { HandlerType, getJsxChildren, logInfo } from "@metamask/snaps-utils";
|
|
27
|
+
import { create } from "@metamask/superstruct";
|
|
28
|
+
import {
|
|
29
|
+
assert,
|
|
30
|
+
assertStruct,
|
|
31
|
+
createModuleLogger,
|
|
32
|
+
hasProperty
|
|
33
|
+
} from "@metamask/utils";
|
|
25
34
|
var log = createModuleLogger(rootLogger, "helpers");
|
|
26
35
|
function getOptions(snapId, options) {
|
|
27
36
|
if (typeof snapId === "object") {
|
|
@@ -32,6 +41,30 @@ function getOptions(snapId, options) {
|
|
|
32
41
|
function assertIsResponseWithInterface(response) {
|
|
33
42
|
assertStruct(response, SnapResponseWithInterfaceStruct);
|
|
34
43
|
}
|
|
44
|
+
function assertIsAlertDialog(ui) {
|
|
45
|
+
assert(hasProperty(ui, "type") && ui.type === DialogType.Alert);
|
|
46
|
+
}
|
|
47
|
+
function assertIsConfirmationDialog(ui) {
|
|
48
|
+
assert(hasProperty(ui, "type") && ui.type === DialogType.Confirmation);
|
|
49
|
+
}
|
|
50
|
+
function assertIsPromptDialog(ui) {
|
|
51
|
+
assert(hasProperty(ui, "type") && ui.type === DialogType.Prompt);
|
|
52
|
+
}
|
|
53
|
+
function assertIsCustomDialog(ui) {
|
|
54
|
+
assert(!hasProperty(ui, "type"));
|
|
55
|
+
}
|
|
56
|
+
function assertCustomDialogHasFooter(ui) {
|
|
57
|
+
const footer = getElementByType(ui.content, "Footer");
|
|
58
|
+
assert(footer && getJsxChildren(footer).length === 2);
|
|
59
|
+
}
|
|
60
|
+
function assertCustomDialogHasPartialFooter(ui) {
|
|
61
|
+
const footer = getElementByType(ui.content, "Footer");
|
|
62
|
+
assert(footer && getJsxChildren(footer).length === 1);
|
|
63
|
+
}
|
|
64
|
+
function assertCustomDialogHasNoFooter(ui) {
|
|
65
|
+
const footer = getElementByType(ui.content, "Footer");
|
|
66
|
+
assert(!footer);
|
|
67
|
+
}
|
|
35
68
|
async function installSnap(snapId, options = {}) {
|
|
36
69
|
const resolvedOptions = getOptions(snapId, options);
|
|
37
70
|
const {
|
|
@@ -158,6 +191,13 @@ async function installSnap(snapId, options = {}) {
|
|
|
158
191
|
}
|
|
159
192
|
|
|
160
193
|
export {
|
|
194
|
+
assertIsAlertDialog,
|
|
195
|
+
assertIsConfirmationDialog,
|
|
196
|
+
assertIsPromptDialog,
|
|
197
|
+
assertIsCustomDialog,
|
|
198
|
+
assertCustomDialogHasFooter,
|
|
199
|
+
assertCustomDialogHasPartialFooter,
|
|
200
|
+
assertCustomDialogHasNoFooter,
|
|
161
201
|
installSnap
|
|
162
202
|
};
|
|
163
|
-
//# sourceMappingURL=chunk-
|
|
203
|
+
//# sourceMappingURL=chunk-ROCGQYSK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers.ts"],"sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DialogType } from '@metamask/snaps-sdk';\nimport type { FooterElement } from '@metamask/snaps-sdk/jsx';\nimport { HandlerType, getJsxChildren, logInfo } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport {\n assert,\n assertStruct,\n createModuleLogger,\n hasProperty,\n} from '@metamask/utils';\n\nimport {\n rootLogger,\n handleRequest,\n TransactionOptionsStruct,\n getEnvironment,\n JsonRpcMockOptionsStruct,\n SignatureOptionsStruct,\n SnapResponseWithInterfaceStruct,\n getElementByType,\n} from './internals';\nimport type { InstallSnapOptions } from './internals';\nimport {\n addJsonRpcMock,\n removeJsonRpcMock,\n} from './internals/simulation/store/mocks';\nimport type {\n SnapResponseWithInterface,\n CronjobOptions,\n JsonRpcMockOptions,\n Snap,\n SnapResponse,\n TransactionOptions,\n SnapInterface,\n SnapAlertInterface,\n SnapInterfaceActions,\n SnapConfirmationInterface,\n SnapPromptInterface,\n DefaultSnapInterface,\n DefaultSnapInterfaceWithFooter,\n DefaultSnapInterfaceWithPartialFooter,\n DefaultSnapInterfaceWithoutFooter,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Ensure that the actual response contains `getInterface`.\n *\n * @param response - The response of the handler.\n */\nfunction assertIsResponseWithInterface(\n response: SnapResponse,\n): asserts response is SnapResponseWithInterface {\n assertStruct(response, SnapResponseWithInterfaceStruct);\n}\n\n/**\n * Ensure that the actual interface is an alert dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsAlertDialog(\n ui: SnapInterface,\n): asserts ui is SnapAlertInterface & SnapInterfaceActions {\n assert(hasProperty(ui, 'type') && ui.type === DialogType.Alert);\n}\n\n/**\n * Ensure that the actual interface is a confirmation dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsConfirmationDialog(\n ui: SnapInterface,\n): asserts ui is SnapConfirmationInterface & SnapInterfaceActions {\n assert(hasProperty(ui, 'type') && ui.type === DialogType.Confirmation);\n}\n\n/**\n * Ensure that the actual interface is a Prompt dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsPromptDialog(\n ui: SnapInterface,\n): asserts ui is SnapPromptInterface & SnapInterfaceActions {\n assert(hasProperty(ui, 'type') && ui.type === DialogType.Prompt);\n}\n\n/**\n * Ensure that the actual interface is a custom dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsCustomDialog(\n ui: SnapInterface,\n): asserts ui is DefaultSnapInterface & SnapInterfaceActions {\n assert(!hasProperty(ui, 'type'));\n}\n\n/**\n * Ensure that the actual interface is a custom dialog with a complete footer.\n *\n * @param ui - The interface to verify.\n */\nexport function assertCustomDialogHasFooter(\n ui: DefaultSnapInterface & SnapInterfaceActions,\n): asserts ui is DefaultSnapInterfaceWithFooter & SnapInterfaceActions {\n const footer = getElementByType<FooterElement>(ui.content, 'Footer');\n\n assert(footer && getJsxChildren(footer).length === 2);\n}\n\n/**\n * Ensure that the actual interface is a custom dialog with a partial footer.\n *\n * @param ui - The interface to verify.\n */\nexport function assertCustomDialogHasPartialFooter(\n ui: DefaultSnapInterface & SnapInterfaceActions,\n): asserts ui is DefaultSnapInterfaceWithPartialFooter & SnapInterfaceActions {\n const footer = getElementByType<FooterElement>(ui.content, 'Footer');\n\n assert(footer && getJsxChildren(footer).length === 1);\n}\n\n/**\n * Ensure that the actual interface is a custom dialog without a footer.\n *\n * @param ui - The interface to verify.\n */\nexport function assertCustomDialogHasNoFooter(\n ui: DefaultSnapInterface & SnapInterfaceActions,\n): asserts ui is DefaultSnapInterfaceWithoutFooter & SnapInterfaceActions {\n const footer = getElementByType<FooterElement>(ui.content, 'Footer');\n\n assert(!footer);\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n const {\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n } = await getEnvironment().installSnap(...resolvedOptions);\n\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n return {\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await executionService.terminateAllSnaps();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,kBAAkB;AAE3B,SAAS,aAAa,gBAAgB,eAAe;AACrD,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAmCP,IAAM,MAAM,mBAAmB,YAAY,SAAS;AASpD,SAAS,WAKP,QACA,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I,sBAAsB;AAE1B,YAAM,WAAW,MAAM,cAAc;AAAA,QACnC,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS,YAAY;AAAA,QACrB,SAAS;AAAA,UACP,QAAQ;AAAA,QACV;AAAA,MACF,CAAC;AAED,oCAA8B,QAAQ;AAEtC,aAAO;AAAA,IACT;AAAA,IAEA,YAAY,MAA0B;AACpC,UAAI,gCAAgC,IAAI;AAExC,YAAM,EAAE,QAAQ,OAAO,IAAI,OAAO,MAAM,wBAAwB;AAChE,YAAM,SAAS,eAAe,EAAE,QAAQ,OAAO,CAAC,CAAC;AAEjD,aAAO;AAAA,QACL,SAAS;AACP,cAAI,kCAAkC,IAAI;AAE1C,gBAAM,SAAS,kBAAkB,MAAM,CAAC;AAAA,QAC1C;AAAA,MACF;AAAA,IACF;AAAA,IAEA,OAAO,YAAY;AACjB,UAAI,4BAA4B;AAChC;AAAA,QACE;AAAA,MACF;AAEA,YAAM,iBAAiB,kBAAkB;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkD653LBAYjs = require('./chunk-D653LBAY.js');
|
|
6
|
+
|
|
7
|
+
// src/internals/simulation/methods/hooks/request-user-approval.ts
|
|
8
|
+
var _effects = require('redux-saga/effects');
|
|
9
|
+
function* requestUserApprovalImplementation({
|
|
10
|
+
type,
|
|
11
|
+
requestData: { id }
|
|
12
|
+
}) {
|
|
13
|
+
yield _effects.put.call(void 0, _chunkD653LBAYjs.setInterface.call(void 0, { type, id }));
|
|
14
|
+
const { payload } = yield _effects.take.call(void 0, _chunkD653LBAYjs.resolveInterface.type);
|
|
15
|
+
yield _effects.put.call(void 0, _chunkD653LBAYjs.closeInterface.call(void 0, ));
|
|
16
|
+
return payload;
|
|
17
|
+
}
|
|
18
|
+
function getRequestUserApprovalImplementation(runSaga) {
|
|
19
|
+
return async (...args) => {
|
|
20
|
+
return await runSaga(
|
|
21
|
+
requestUserApprovalImplementation,
|
|
22
|
+
...args
|
|
23
|
+
).toPromise();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
exports.getRequestUserApprovalImplementation = getRequestUserApprovalImplementation;
|
|
30
|
+
//# sourceMappingURL=chunk-SNXRXX2O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/hooks/request-user-approval.ts"],"names":[],"mappings":";;;;;;;AACA,SAAS,KAAK,YAAY;AAwB1B,UAAU,kCAAkC;AAAA,EAC1C;AAAA,EACA,aAAa,EAAE,GAAG;AACpB,GAAqD;AACnD,QAAM,IAAI,aAAa,EAAE,MAAM,GAAG,CAAC,CAAC;AAIpC,QAAM,EAAE,QAAQ,IAAI,MAAM,KAAK,iBAAiB,IAAI;AACpD,QAAM,IAAI,eAAe,CAAC;AAE1B,SAAO;AACT;AAQO,SAAS,qCAAqC,SAA0B;AAC7E,SAAO,UACF,SACA;AACH,WAAO,MAAM;AAAA,MACX;AAAA,MACA,GAAG;AAAA,IACL,EAAE,UAAU;AAAA,EACd;AACF","sourcesContent":["import type { SagaIterator } from 'redux-saga';\nimport { put, take } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { resolveInterface, setInterface, closeInterface } from '../../store';\n\ntype RequestUserApprovalParams = {\n type: string;\n requestData: {\n id: string;\n };\n};\n\n/**\n * Show a dialog to the user. This will wait for `resolveUserInterface` to be\n * dispatched before returning.\n *\n * @param opts - The options for the request.\n * @param opts.type - The type of dialog to show.\n * @param opts.requestData - The data to display in the dialog.\n * @param opts.requestData.id - The ID of the interface.\n * @yields Sets the dialog in the store, waits for the user to resolve the\n * dialog, and closes the dialog.\n * @returns The result of the dialog.\n */\nfunction* requestUserApprovalImplementation({\n type,\n requestData: { id },\n}: RequestUserApprovalParams): SagaIterator<unknown> {\n yield put(setInterface({ type, id }));\n\n // We use `take` to wait for `resolveUserInterface` to be dispatched, which\n // indicates that the user has resolved the dialog.\n const { payload } = yield take(resolveInterface.type);\n yield put(closeInterface());\n\n return payload;\n}\n\n/**\n * Get the implementation of the `requestUserApproval` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `requestUserApproval` hook.\n */\nexport function getRequestUserApprovalImplementation(runSaga: RunSagaFunction) {\n return async (\n ...args: Parameters<typeof requestUserApprovalImplementation>\n ) => {\n return await runSaga(\n requestUserApprovalImplementation,\n ...args,\n ).toPromise();\n };\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/internals/simulation/files.ts
|
|
2
|
+
var _snapssdk = require('@metamask/snaps-sdk');
|
|
3
|
+
var _snapsutils = require('@metamask/snaps-utils');
|
|
4
|
+
var _utils = require('@metamask/utils');
|
|
5
|
+
var _promises = require('fs/promises');
|
|
6
|
+
var _mime = require('mime'); var _mime2 = _interopRequireDefault(_mime);
|
|
7
|
+
var _path = require('path');
|
|
8
|
+
async function getSnapFile(files, path, encoding = _snapssdk.AuxiliaryFileEncoding.Base64) {
|
|
9
|
+
const normalizedPath = _snapsutils.normalizeRelative.call(void 0, path);
|
|
10
|
+
const base64 = files.find((file) => file.path === normalizedPath)?.toString("base64");
|
|
11
|
+
if (!base64) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return await _snapsutils.encodeAuxiliaryFile.call(void 0, base64, encoding);
|
|
15
|
+
}
|
|
16
|
+
function getContentType(extension) {
|
|
17
|
+
return _mime2.default.getType(extension) ?? "application/octet-stream";
|
|
18
|
+
}
|
|
19
|
+
async function getFileSize(file) {
|
|
20
|
+
if (typeof file === "string") {
|
|
21
|
+
const { size } = await _promises.stat.call(void 0, _path.resolve.call(void 0, process.cwd(), file));
|
|
22
|
+
return size;
|
|
23
|
+
}
|
|
24
|
+
return file.length;
|
|
25
|
+
}
|
|
26
|
+
async function getFileToUpload(file, { fileName, contentType } = {}) {
|
|
27
|
+
if (typeof file === "string") {
|
|
28
|
+
const buffer = await _promises.readFile.call(void 0, _path.resolve.call(void 0, process.cwd(), file));
|
|
29
|
+
return {
|
|
30
|
+
name: fileName ?? _path.basename.call(void 0, file),
|
|
31
|
+
size: buffer.byteLength,
|
|
32
|
+
contentType: contentType ?? getContentType(_path.extname.call(void 0, file)),
|
|
33
|
+
contents: _utils.bytesToBase64.call(void 0, buffer)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
name: fileName ?? "",
|
|
38
|
+
size: file.length,
|
|
39
|
+
contentType: contentType ?? "application/octet-stream",
|
|
40
|
+
contents: _utils.bytesToBase64.call(void 0, file)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
exports.getSnapFile = getSnapFile; exports.getContentType = getContentType; exports.getFileSize = getFileSize; exports.getFileToUpload = getFileToUpload;
|
|
50
|
+
//# sourceMappingURL=chunk-SW65QYFV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/files.ts"],"names":[],"mappings":";AACA,SAAS,6BAA6B;AAEtC,SAAS,qBAAqB,yBAAyB;AACvD,SAAS,qBAAqB;AAC9B,SAAS,UAAU,YAAY;AAC/B,OAAO,UAAU;AACjB,SAAS,UAAU,SAAS,eAAe;AAY3C,eAAsB,YACpB,OACA,MACA,WAAkC,sBAAsB,QACxD;AACA,QAAM,iBAAiB,kBAAkB,IAAI;AAC7C,QAAM,SAAS,MACZ,KAAK,CAAC,SAAS,KAAK,SAAS,cAAc,GAC1C,SAAS,QAAQ;AAErB,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,oBAAoB,QAAQ,QAAQ;AACnD;AASO,SAAS,eAAe,WAAmB;AAChD,SAAO,KAAK,QAAQ,SAAS,KAAK;AACpC;AAUA,eAAsB,YAAY,MAA2B;AAC3D,MAAI,OAAO,SAAS,UAAU;AAC5B,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,QAAQ,QAAQ,IAAI,GAAG,IAAI,CAAC;AACxD,WAAO;AAAA,EACT;AAEA,SAAO,KAAK;AACd;AAkBA,eAAsB,gBACpB,MACA,EAAE,UAAU,YAAY,IAAiB,CAAC,GAC3B;AACf,MAAI,OAAO,SAAS,UAAU;AAC5B,UAAM,SAAS,MAAM,SAAS,QAAQ,QAAQ,IAAI,GAAG,IAAI,CAAC;AAE1D,WAAO;AAAA,MACL,MAAM,YAAY,SAAS,IAAI;AAAA,MAC/B,MAAM,OAAO;AAAA,MACb,aAAa,eAAe,eAAe,QAAQ,IAAI,CAAC;AAAA,MACxD,UAAU,cAAc,MAAM;AAAA,IAChC;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM,YAAY;AAAA,IAClB,MAAM,KAAK;AAAA,IACX,aAAa,eAAe;AAAA,IAC5B,UAAU,cAAc,IAAI;AAAA,EAC9B;AACF","sourcesContent":["import type { File } from '@metamask/snaps-sdk';\nimport { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport type { VirtualFile } from '@metamask/snaps-utils';\nimport { encodeAuxiliaryFile, normalizeRelative } from '@metamask/snaps-utils';\nimport { bytesToBase64 } from '@metamask/utils';\nimport { readFile, stat } from 'fs/promises';\nimport mime from 'mime';\nimport { basename, extname, resolve } from 'path';\n\nimport type { FileOptions } from '../../types';\n\n/**\n * Get a statically defined Snap file from an array of files.\n *\n * @param files - The Snap files.\n * @param path - The file path.\n * @param encoding - The requested file encoding.\n * @returns The file in the requested encoding if found, otherwise null.\n */\nexport async function getSnapFile(\n files: VirtualFile[],\n path: string,\n encoding: AuxiliaryFileEncoding = AuxiliaryFileEncoding.Base64,\n) {\n const normalizedPath = normalizeRelative(path);\n const base64 = files\n .find((file) => file.path === normalizedPath)\n ?.toString('base64');\n\n if (!base64) {\n return null;\n }\n\n return await encodeAuxiliaryFile(base64, encoding);\n}\n\n/**\n * Get the content type of a file based on its extension.\n *\n * @param extension - The file extension.\n * @returns The content type of the file. If the content type cannot be inferred\n * from the extension, `application/octet-stream` is returned.\n */\nexport function getContentType(extension: string) {\n return mime.getType(extension) ?? 'application/octet-stream';\n}\n\n/**\n * Get the size of a file, from a file path or a `Uint8Array`.\n *\n * @param file - The file to get the size of. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @returns The size of the file in bytes.\n */\nexport async function getFileSize(file: string | Uint8Array) {\n if (typeof file === 'string') {\n const { size } = await stat(resolve(process.cwd(), file));\n return size;\n }\n\n return file.length;\n}\n\n/**\n * Get a file object to upload, from a file path or a `Uint8Array`, with an\n * optional file name and content type.\n *\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\nexport async function getFileToUpload(\n file: string | Uint8Array,\n { fileName, contentType }: FileOptions = {},\n): Promise<File> {\n if (typeof file === 'string') {\n const buffer = await readFile(resolve(process.cwd(), file));\n\n return {\n name: fileName ?? basename(file),\n size: buffer.byteLength,\n contentType: contentType ?? getContentType(extname(file)),\n contents: bytesToBase64(buffer),\n };\n }\n\n return {\n name: fileName ?? '',\n size: file.length,\n contentType: contentType ?? 'application/octet-stream',\n contents: bytesToBase64(file),\n };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkQYHQ2WWXjs = require('./chunk-QYHQ2WWX.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkXAOCS6ZDjs = require('./chunk-XAOCS6ZD.js');
|
|
@@ -33,7 +33,9 @@ function getControllers(options) {
|
|
|
33
33
|
name: "SnapInterfaceController",
|
|
34
34
|
allowedActions: [
|
|
35
35
|
"PhishingController:maybeUpdateState",
|
|
36
|
-
"PhishingController:testOrigin"
|
|
36
|
+
"PhishingController:testOrigin",
|
|
37
|
+
"ApprovalController:hasRequest",
|
|
38
|
+
"ApprovalController:acceptRequest"
|
|
37
39
|
],
|
|
38
40
|
allowedEvents: []
|
|
39
41
|
})
|
|
@@ -47,7 +49,7 @@ function getControllers(options) {
|
|
|
47
49
|
}
|
|
48
50
|
function getPermissionController(options) {
|
|
49
51
|
const { controllerMessenger } = options;
|
|
50
|
-
const permissionSpecifications =
|
|
52
|
+
const permissionSpecifications = _chunkQYHQ2WWXjs.getPermissionSpecifications.call(void 0, options);
|
|
51
53
|
return new (0, _permissioncontroller.PermissionController)({
|
|
52
54
|
messenger: controllerMessenger.getRestricted({
|
|
53
55
|
name: "PermissionController",
|
|
@@ -92,4 +94,4 @@ async function registerSnap(snapId, manifest, {
|
|
|
92
94
|
|
|
93
95
|
|
|
94
96
|
exports.getControllers = getControllers; exports.registerSnap = registerSnap;
|
|
95
|
-
//# sourceMappingURL=chunk-
|
|
97
|
+
//# sourceMappingURL=chunk-WZ57PU2K.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/controllers.ts"],"names":[],"mappings":";;;;;;;;AAOA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,+BAA+B;AAMxC;AAAA,EACE,wBAAwB;AAAA,EACxB,iCAAiC;AAAA,EACjC;AAAA,OACK;A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C;AAEA,uBAAqB,iBAAiB;AAAA,IACpC;AAAA,IACA,SAAS,EAAE,QAAQ,OAAO;AAAA,IAC1B,6BAA6B;AAAA,EAC/B,CAAC;AACH","sourcesContent":["import type { ControllerMessenger } from '@metamask/base-controller';\nimport type {\n CaveatSpecificationConstraint,\n PermissionSpecificationConstraint,\n PermissionControllerActions,\n SubjectMetadataControllerActions,\n} from '@metamask/permission-controller';\nimport {\n PermissionController,\n SubjectMetadataController,\n SubjectType,\n} from '@metamask/permission-controller';\nimport { SnapInterfaceController } from '@metamask/snaps-controllers';\nimport type {\n ExecutionServiceActions,\n SnapInterfaceControllerActions,\n SnapInterfaceControllerAllowedActions,\n} from '@metamask/snaps-controllers';\nimport {\n caveatSpecifications as snapsCaveatsSpecifications,\n endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications,\n processSnapPermissions,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { SnapManifest } from '@metamask/snaps-utils';\nimport { getSafeJson } from '@metamask/utils';\n\nimport { getPermissionSpecifications } from './methods';\nimport { UNRESTRICTED_METHODS } from './methods/constants';\nimport type { SimulationOptions } from './options';\nimport type { MiddlewareHooks } from './simulation';\nimport type { RunSagaFunction } from './store';\n\nexport type RootControllerAllowedActions =\n | SnapInterfaceControllerActions\n | SnapInterfaceControllerAllowedActions\n | PermissionControllerActions\n | ExecutionServiceActions\n | SubjectMetadataControllerActions;\n\nexport type RootControllerMessenger = ControllerMessenger<\n RootControllerAllowedActions,\n any\n>;\n\nexport type GetControllersOptions = {\n controllerMessenger: ControllerMessenger<any, any>;\n hooks: MiddlewareHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\nexport type Controllers = {\n permissionController: PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n >;\n subjectMetadataController: SubjectMetadataController;\n interfaceController: SnapInterfaceController;\n};\n\n/**\n * Get the controllers for the Snap.\n *\n * @param options - The options.\n * @returns The controllers for the Snap.\n */\nexport function getControllers(options: GetControllersOptions): Controllers {\n const { controllerMessenger } = options;\n const subjectMetadataController = new SubjectMetadataController({\n messenger: controllerMessenger.getRestricted({\n name: 'SubjectMetadataController',\n allowedActions: [],\n allowedEvents: [],\n }),\n subjectCacheLimit: 100,\n });\n\n const interfaceController = new SnapInterfaceController({\n messenger: controllerMessenger.getRestricted({\n name: 'SnapInterfaceController',\n allowedActions: [\n 'PhishingController:maybeUpdateState',\n 'PhishingController:testOrigin',\n 'ApprovalController:hasRequest',\n 'ApprovalController:acceptRequest',\n ],\n allowedEvents: [],\n }),\n });\n\n const permissionController = getPermissionController(options);\n\n return {\n permissionController,\n subjectMetadataController,\n interfaceController,\n };\n}\n\n/**\n * Get the permission controller for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.options - Miscellaneous options.\n * @returns The permission controller for the Snap.\n */\nfunction getPermissionController(options: GetControllersOptions) {\n const { controllerMessenger } = options;\n const permissionSpecifications = getPermissionSpecifications(options);\n return new PermissionController({\n messenger: controllerMessenger.getRestricted({\n name: 'PermissionController',\n allowedActions: [\n `ApprovalController:addRequest`,\n `ApprovalController:hasRequest`,\n `ApprovalController:acceptRequest`,\n `ApprovalController:rejectRequest`,\n `SnapController:getPermitted`,\n `SnapController:install`,\n `SubjectMetadataController:getSubjectMetadata`,\n ],\n allowedEvents: [],\n }),\n caveatSpecifications: {\n ...snapsCaveatsSpecifications,\n ...snapsEndowmentCaveatSpecifications,\n },\n permissionSpecifications,\n unrestrictedMethods: UNRESTRICTED_METHODS,\n });\n}\n\n/**\n * Register the Snap. This sets up the Snap's permissions and subject metadata.\n *\n * @param snapId - The ID of the Snap to install.\n * @param manifest - The parsed manifest.\n * @param controllers - The controllers for the Snap.\n * @param controllers.permissionController - The permission controller.\n * @param controllers.subjectMetadataController - The subject metadata controller.\n */\nexport async function registerSnap(\n snapId: SnapId,\n manifest: SnapManifest,\n {\n permissionController,\n subjectMetadataController,\n }: Omit<Controllers, 'interfaceController'>,\n) {\n subjectMetadataController.addSubjectMetadata({\n origin: snapId,\n subjectType: SubjectType.Snap,\n });\n\n const approvedPermissions = processSnapPermissions(\n getSafeJson(manifest.initialPermissions),\n );\n\n permissionController.grantPermissions({\n approvedPermissions,\n subject: { origin: snapId },\n preserveExistingPermissions: false,\n });\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/internals/simulation/methods/hooks/get-preferences.ts
|
|
2
|
+
function getGetPreferencesMethodImplementation({
|
|
3
|
+
currency,
|
|
4
|
+
locale
|
|
5
|
+
}) {
|
|
6
|
+
return () => {
|
|
7
|
+
return { currency, locale };
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.getGetPreferencesMethodImplementation = getGetPreferencesMethodImplementation;
|
|
14
|
+
//# sourceMappingURL=chunk-XP4YGQJA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/hooks/get-preferences.ts"],"names":[],"mappings":";AAUO,SAAS,sCAAsC;AAAA,EACpD;AAAA,EACA;AACF,GAAsB;AACpB,SAAO,MAAM;AACX,WAAO,EAAE,UAAU,OAAO;AAAA,EAC5B;AACF","sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getPreferences` hook.\n *\n * @param options - The simulation options.\n * @param options.currency - The currency to use.\n * @param options.locale - The locale to use.\n * @returns The implementation of the `getPreferences` hook.\n */\nexport function getGetPreferencesMethodImplementation({\n currency,\n locale,\n}: SimulationOptions) {\n return () => {\n return { currency, locale };\n };\n}\n"]}
|