@metamask/snaps-jest 8.3.1 → 8.4.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 +16 -1
- package/dist/environment.cjs +2 -1
- package/dist/environment.cjs.map +1 -1
- package/dist/environment.d.cts +1 -1
- package/dist/environment.d.cts.map +1 -1
- package/dist/environment.d.mts +1 -1
- package/dist/environment.d.mts.map +1 -1
- package/dist/environment.mjs +3 -2
- package/dist/environment.mjs.map +1 -1
- package/dist/helpers.cjs +13 -80
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +2 -44
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +2 -44
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +4 -64
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/internals/environment.d.cts +1 -1
- package/dist/internals/environment.d.mts +1 -1
- package/dist/internals/index.cjs +0 -3
- package/dist/internals/index.cjs.map +1 -1
- package/dist/internals/index.d.cts +0 -3
- package/dist/internals/index.d.cts.map +1 -1
- package/dist/internals/index.d.mts +0 -3
- package/dist/internals/index.d.mts.map +1 -1
- package/dist/internals/index.mjs +0 -3
- package/dist/internals/index.mjs.map +1 -1
- package/dist/matchers.cjs +3 -3
- package/dist/matchers.cjs.map +1 -1
- package/dist/matchers.d.cts.map +1 -1
- package/dist/matchers.d.mts.map +1 -1
- package/dist/matchers.mjs +1 -1
- package/dist/matchers.mjs.map +1 -1
- package/dist/types/types.cjs.map +1 -1
- package/dist/types/types.d.cts +8 -1
- package/dist/types/types.d.cts.map +1 -1
- package/dist/types/types.d.mts +8 -1
- package/dist/types/types.d.mts.map +1 -1
- package/dist/types/types.mjs.map +1 -1
- package/package.json +7 -20
- package/dist/internals/request.cjs +0 -143
- package/dist/internals/request.cjs.map +0 -1
- package/dist/internals/request.d.cts +0 -56
- package/dist/internals/request.d.cts.map +0 -1
- package/dist/internals/request.d.mts +0 -56
- package/dist/internals/request.d.mts.map +0 -1
- package/dist/internals/request.mjs +0 -138
- package/dist/internals/request.mjs.map +0 -1
- package/dist/internals/simulation/constants.cjs +0 -21
- package/dist/internals/simulation/constants.cjs.map +0 -1
- package/dist/internals/simulation/constants.d.cts +0 -18
- package/dist/internals/simulation/constants.d.cts.map +0 -1
- package/dist/internals/simulation/constants.d.mts +0 -18
- package/dist/internals/simulation/constants.d.mts.map +0 -1
- package/dist/internals/simulation/constants.mjs +0 -18
- package/dist/internals/simulation/constants.mjs.map +0 -1
- package/dist/internals/simulation/controllers.cjs +0 -101
- package/dist/internals/simulation/controllers.cjs.map +0 -1
- package/dist/internals/simulation/controllers.d.cts +0 -41
- package/dist/internals/simulation/controllers.d.cts.map +0 -1
- package/dist/internals/simulation/controllers.d.mts +0 -41
- package/dist/internals/simulation/controllers.d.mts.map +0 -1
- package/dist/internals/simulation/controllers.mjs +0 -96
- package/dist/internals/simulation/controllers.mjs.map +0 -1
- package/dist/internals/simulation/files.cjs +0 -94
- package/dist/internals/simulation/files.cjs.map +0 -1
- package/dist/internals/simulation/files.d.cts +0 -49
- package/dist/internals/simulation/files.d.cts.map +0 -1
- package/dist/internals/simulation/files.d.mts +0 -49
- package/dist/internals/simulation/files.d.mts.map +0 -1
- package/dist/internals/simulation/files.mjs +0 -91
- package/dist/internals/simulation/files.mjs.map +0 -1
- package/dist/internals/simulation/index.cjs +0 -22
- package/dist/internals/simulation/index.cjs.map +0 -1
- package/dist/internals/simulation/index.d.cts +0 -6
- package/dist/internals/simulation/index.d.cts.map +0 -1
- package/dist/internals/simulation/index.d.mts +0 -6
- package/dist/internals/simulation/index.d.mts.map +0 -1
- package/dist/internals/simulation/index.mjs +0 -6
- package/dist/internals/simulation/index.mjs.map +0 -1
- package/dist/internals/simulation/interface.cjs +0 -527
- package/dist/internals/simulation/interface.cjs.map +0 -1
- package/dist/internals/simulation/interface.d.cts +0 -152
- package/dist/internals/simulation/interface.d.cts.map +0 -1
- package/dist/internals/simulation/interface.d.mts +0 -152
- package/dist/internals/simulation/interface.d.mts.map +0 -1
- package/dist/internals/simulation/interface.mjs +0 -513
- package/dist/internals/simulation/interface.mjs.map +0 -1
- package/dist/internals/simulation/methods/constants.cjs +0 -72
- package/dist/internals/simulation/methods/constants.cjs.map +0 -1
- package/dist/internals/simulation/methods/constants.d.cts +0 -11
- package/dist/internals/simulation/methods/constants.d.cts.map +0 -1
- package/dist/internals/simulation/methods/constants.d.mts +0 -11
- package/dist/internals/simulation/methods/constants.d.mts.map +0 -1
- package/dist/internals/simulation/methods/constants.mjs +0 -69
- package/dist/internals/simulation/methods/constants.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.cjs +0 -18
- package/dist/internals/simulation/methods/hooks/get-preferences.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.d.cts +0 -14
- package/dist/internals/simulation/methods/hooks/get-preferences.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.d.mts +0 -14
- package/dist/internals/simulation/methods/hooks/get-preferences.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs +0 -14
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.cjs +0 -22
- package/dist/internals/simulation/methods/hooks/index.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.d.cts +0 -6
- package/dist/internals/simulation/methods/hooks/index.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.d.mts +0 -6
- package/dist/internals/simulation/methods/hooks/index.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.mjs +0 -6
- package/dist/internals/simulation/methods/hooks/index.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.cjs +0 -24
- package/dist/internals/simulation/methods/hooks/interface.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.d.cts +0 -17
- package/dist/internals/simulation/methods/hooks/interface.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.d.mts +0 -17
- package/dist/internals/simulation/methods/hooks/interface.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.mjs +0 -19
- package/dist/internals/simulation/methods/hooks/interface.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.cjs +0 -58
- package/dist/internals/simulation/methods/hooks/notifications.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.d.cts +0 -17
- package/dist/internals/simulation/methods/hooks/notifications.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.d.mts +0 -17
- package/dist/internals/simulation/methods/hooks/notifications.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.mjs +0 -55
- package/dist/internals/simulation/methods/hooks/notifications.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.cjs +0 -38
- package/dist/internals/simulation/methods/hooks/request-user-approval.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts +0 -16
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts +0 -16
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +0 -35
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.cjs +0 -84
- package/dist/internals/simulation/methods/hooks/state.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.d.cts +0 -24
- package/dist/internals/simulation/methods/hooks/state.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.d.mts +0 -24
- package/dist/internals/simulation/methods/hooks/state.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.mjs +0 -79
- package/dist/internals/simulation/methods/hooks/state.mjs.map +0 -1
- package/dist/internals/simulation/methods/index.cjs +0 -18
- package/dist/internals/simulation/methods/index.cjs.map +0 -1
- package/dist/internals/simulation/methods/index.d.cts +0 -2
- package/dist/internals/simulation/methods/index.d.cts.map +0 -1
- package/dist/internals/simulation/methods/index.d.mts +0 -2
- package/dist/internals/simulation/methods/index.d.mts.map +0 -1
- package/dist/internals/simulation/methods/index.mjs +0 -2
- package/dist/internals/simulation/methods/index.mjs.map +0 -1
- package/dist/internals/simulation/methods/specifications.cjs +0 -85
- package/dist/internals/simulation/methods/specifications.cjs.map +0 -1
- package/dist/internals/simulation/methods/specifications.d.cts +0 -57
- package/dist/internals/simulation/methods/specifications.d.cts.map +0 -1
- package/dist/internals/simulation/methods/specifications.d.mts +0 -57
- package/dist/internals/simulation/methods/specifications.d.mts.map +0 -1
- package/dist/internals/simulation/methods/specifications.mjs +0 -78
- package/dist/internals/simulation/methods/specifications.mjs.map +0 -1
- package/dist/internals/simulation/middleware/engine.cjs +0 -37
- package/dist/internals/simulation/middleware/engine.cjs.map +0 -1
- package/dist/internals/simulation/middleware/engine.d.cts +0 -27
- package/dist/internals/simulation/middleware/engine.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/engine.d.mts +0 -27
- package/dist/internals/simulation/middleware/engine.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/engine.mjs +0 -34
- package/dist/internals/simulation/middleware/engine.mjs.map +0 -1
- package/dist/internals/simulation/middleware/index.cjs +0 -18
- package/dist/internals/simulation/middleware/index.cjs.map +0 -1
- package/dist/internals/simulation/middleware/index.d.cts +0 -2
- package/dist/internals/simulation/middleware/index.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/index.d.mts +0 -2
- package/dist/internals/simulation/middleware/index.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/index.mjs +0 -2
- package/dist/internals/simulation/middleware/index.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.cjs +0 -34
- package/dist/internals/simulation/middleware/internal-methods/accounts.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts +0 -20
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts +0 -20
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.mjs +0 -30
- package/dist/internals/simulation/middleware/internal-methods/accounts.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.cjs +0 -18
- package/dist/internals/simulation/middleware/internal-methods/index.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.d.cts +0 -2
- package/dist/internals/simulation/middleware/internal-methods/index.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.d.mts +0 -2
- package/dist/internals/simulation/middleware/internal-methods/index.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.mjs +0 -2
- package/dist/internals/simulation/middleware/internal-methods/index.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.cjs +0 -44
- package/dist/internals/simulation/middleware/internal-methods/middleware.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts +0 -23
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts +0 -23
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.mjs +0 -40
- package/dist/internals/simulation/middleware/internal-methods/middleware.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs +0 -28
- package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts +0 -16
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts +0 -16
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs +0 -24
- package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs.map +0 -1
- package/dist/internals/simulation/middleware/mock.cjs +0 -22
- package/dist/internals/simulation/middleware/mock.cjs.map +0 -1
- package/dist/internals/simulation/middleware/mock.d.cts +0 -11
- package/dist/internals/simulation/middleware/mock.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/mock.d.mts +0 -11
- package/dist/internals/simulation/middleware/mock.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/mock.mjs +0 -18
- package/dist/internals/simulation/middleware/mock.mjs.map +0 -1
- package/dist/internals/simulation/options.cjs +0 -25
- package/dist/internals/simulation/options.cjs.map +0 -1
- package/dist/internals/simulation/options.d.cts +0 -40
- package/dist/internals/simulation/options.d.cts.map +0 -1
- package/dist/internals/simulation/options.d.mts +0 -40
- package/dist/internals/simulation/options.d.mts.map +0 -1
- package/dist/internals/simulation/options.mjs +0 -21
- package/dist/internals/simulation/options.mjs.map +0 -1
- package/dist/internals/simulation/simulation.cjs +0 -155
- package/dist/internals/simulation/simulation.cjs.map +0 -1
- package/dist/internals/simulation/simulation.d.cts +0 -103
- package/dist/internals/simulation/simulation.d.cts.map +0 -1
- package/dist/internals/simulation/simulation.d.mts +0 -103
- package/dist/internals/simulation/simulation.d.mts.map +0 -1
- package/dist/internals/simulation/simulation.mjs +0 -150
- package/dist/internals/simulation/simulation.mjs.map +0 -1
- package/dist/internals/simulation/store/index.cjs +0 -21
- package/dist/internals/simulation/store/index.cjs.map +0 -1
- package/dist/internals/simulation/store/index.d.cts +0 -5
- package/dist/internals/simulation/store/index.d.cts.map +0 -1
- package/dist/internals/simulation/store/index.d.mts +0 -5
- package/dist/internals/simulation/store/index.d.mts.map +0 -1
- package/dist/internals/simulation/store/index.mjs +0 -5
- package/dist/internals/simulation/store/index.mjs.map +0 -1
- package/dist/internals/simulation/store/mocks.cjs +0 -39
- package/dist/internals/simulation/store/mocks.cjs.map +0 -1
- package/dist/internals/simulation/store/mocks.d.cts +0 -36
- package/dist/internals/simulation/store/mocks.d.cts.map +0 -1
- package/dist/internals/simulation/store/mocks.d.mts +0 -36
- package/dist/internals/simulation/store/mocks.d.mts.map +0 -1
- package/dist/internals/simulation/store/mocks.mjs +0 -35
- package/dist/internals/simulation/store/mocks.mjs.map +0 -1
- package/dist/internals/simulation/store/notifications.cjs +0 -35
- package/dist/internals/simulation/store/notifications.cjs.map +0 -1
- package/dist/internals/simulation/store/notifications.d.cts +0 -45
- package/dist/internals/simulation/store/notifications.d.cts.map +0 -1
- package/dist/internals/simulation/store/notifications.d.mts +0 -45
- package/dist/internals/simulation/store/notifications.d.mts.map +0 -1
- package/dist/internals/simulation/store/notifications.mjs +0 -32
- package/dist/internals/simulation/store/notifications.mjs.map +0 -1
- package/dist/internals/simulation/store/state.cjs +0 -54
- package/dist/internals/simulation/store/state.cjs.map +0 -1
- package/dist/internals/simulation/store/state.d.cts +0 -56
- package/dist/internals/simulation/store/state.d.cts.map +0 -1
- package/dist/internals/simulation/store/state.d.mts +0 -56
- package/dist/internals/simulation/store/state.d.mts.map +0 -1
- package/dist/internals/simulation/store/state.mjs +0 -50
- package/dist/internals/simulation/store/state.mjs.map +0 -1
- package/dist/internals/simulation/store/store.cjs +0 -51
- package/dist/internals/simulation/store/store.cjs.map +0 -1
- package/dist/internals/simulation/store/store.d.cts +0 -22
- package/dist/internals/simulation/store/store.d.cts.map +0 -1
- package/dist/internals/simulation/store/store.d.mts +0 -22
- package/dist/internals/simulation/store/store.d.mts.map +0 -1
- package/dist/internals/simulation/store/store.mjs +0 -45
- package/dist/internals/simulation/store/store.mjs.map +0 -1
- package/dist/internals/simulation/store/ui.cjs +0 -24
- package/dist/internals/simulation/store/ui.cjs.map +0 -1
- package/dist/internals/simulation/store/ui.d.cts +0 -27
- package/dist/internals/simulation/store/ui.d.cts.map +0 -1
- package/dist/internals/simulation/store/ui.d.mts +0 -27
- package/dist/internals/simulation/store/ui.d.mts.map +0 -1
- package/dist/internals/simulation/store/ui.mjs +0 -21
- package/dist/internals/simulation/store/ui.mjs.map +0 -1
- package/dist/internals/structs.cjs +0 -157
- package/dist/internals/structs.cjs.map +0 -1
- package/dist/internals/structs.d.cts +0 -205
- package/dist/internals/structs.d.cts.map +0 -1
- package/dist/internals/structs.d.mts +0 -205
- package/dist/internals/structs.d.mts.map +0 -1
- package/dist/internals/structs.mjs +0 -154
- package/dist/internals/structs.mjs.map +0 -1
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { endowmentPermissionBuilders, buildSnapEndowmentSpecifications, buildSnapRestrictedMethodSpecifications } from "@metamask/snaps-rpc-methods";
|
|
2
|
-
import { DEFAULT_ENDOWMENTS } from "@metamask/snaps-utils";
|
|
3
|
-
import { EXCLUDED_SNAP_ENDOWMENTS, EXCLUDED_SNAP_PERMISSIONS } from "./constants.mjs";
|
|
4
|
-
import { getGetPreferencesMethodImplementation, getClearSnapStateMethodImplementation, getGetSnapStateMethodImplementation, getUpdateSnapStateMethodImplementation, getShowInAppNotificationImplementation, getShowNativeNotificationImplementation, getCreateInterfaceImplementation, getGetInterfaceImplementation, getRequestUserApprovalImplementation } from "./hooks/index.mjs";
|
|
5
|
-
/**
|
|
6
|
-
* Get a function which resolves with the specified result.
|
|
7
|
-
*
|
|
8
|
-
* @param result - The result to return.
|
|
9
|
-
* @returns The function implementation.
|
|
10
|
-
*/
|
|
11
|
-
export function resolve(result) {
|
|
12
|
-
return () => result;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Get a function which resolves with the specified result.
|
|
16
|
-
*
|
|
17
|
-
* @param result - The result to return. If not specified, the function will
|
|
18
|
-
* resolve with `undefined`.
|
|
19
|
-
* @returns The function implementation.
|
|
20
|
-
*/
|
|
21
|
-
export function asyncResolve(result) {
|
|
22
|
-
return async () => result;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Get the permission specifications for the Snap.
|
|
26
|
-
*
|
|
27
|
-
* @param options - The options.
|
|
28
|
-
* @param options.controllerMessenger - The controller messenger.
|
|
29
|
-
* @param options.hooks - The hooks.
|
|
30
|
-
* @param options.runSaga - The function to run a saga outside the usual Redux
|
|
31
|
-
* flow.
|
|
32
|
-
* @param options.options - The simulation options.
|
|
33
|
-
* @returns The permission specifications for the Snap.
|
|
34
|
-
*/
|
|
35
|
-
export function getPermissionSpecifications({ controllerMessenger, hooks, runSaga, options, }) {
|
|
36
|
-
return {
|
|
37
|
-
...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),
|
|
38
|
-
...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {
|
|
39
|
-
// Shared hooks.
|
|
40
|
-
...hooks,
|
|
41
|
-
// Snaps-specific hooks.
|
|
42
|
-
clearSnapState: getClearSnapStateMethodImplementation(runSaga),
|
|
43
|
-
getPreferences: getGetPreferencesMethodImplementation(options),
|
|
44
|
-
getSnapState: getGetSnapStateMethodImplementation(runSaga),
|
|
45
|
-
getUnlockPromise: asyncResolve(true),
|
|
46
|
-
// TODO: Allow the user to specify the result of this function.
|
|
47
|
-
isOnPhishingList: resolve(false),
|
|
48
|
-
maybeUpdatePhishingList: asyncResolve(),
|
|
49
|
-
requestUserApproval: getRequestUserApprovalImplementation(runSaga),
|
|
50
|
-
showInAppNotification: getShowInAppNotificationImplementation(runSaga),
|
|
51
|
-
showNativeNotification: getShowNativeNotificationImplementation(runSaga),
|
|
52
|
-
updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),
|
|
53
|
-
createInterface: getCreateInterfaceImplementation(controllerMessenger),
|
|
54
|
-
getInterface: getGetInterfaceImplementation(controllerMessenger),
|
|
55
|
-
}),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Get the endowments for the Snap.
|
|
60
|
-
*
|
|
61
|
-
* @param permissionController - The permission controller.
|
|
62
|
-
* @param snapId - The ID of the Snap.
|
|
63
|
-
* @returns The endowments for the Snap.
|
|
64
|
-
*/
|
|
65
|
-
export async function getEndowments(permissionController, snapId) {
|
|
66
|
-
const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce(async (promise, permissionName) => {
|
|
67
|
-
const accumulator = await promise;
|
|
68
|
-
if (permissionController.hasPermission(snapId, permissionName)) {
|
|
69
|
-
const endowments = await permissionController.getEndowments(snapId, permissionName);
|
|
70
|
-
if (endowments) {
|
|
71
|
-
return accumulator.concat(endowments);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return accumulator;
|
|
75
|
-
}, Promise.resolve([]));
|
|
76
|
-
return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=specifications.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"specifications.mjs","sourceRoot":"","sources":["../../../../src/internals/simulation/methods/specifications.ts"],"names":[],"mappings":"AACA,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,uCAAuC,EACxC,oCAAoC;AAErC,OAAO,EAAE,kBAAkB,EAAE,8BAA8B;AAK3D,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EAC1B,wBAAoB;AACrB,OAAO,EACL,qCAAqC,EACrC,qCAAqC,EACrC,mCAAmC,EACnC,sCAAsC,EACtC,sCAAsC,EACtC,uCAAuC,EACvC,gCAAgC,EAChC,6BAA6B,EAC7B,oCAAoC,EACrC,0BAAgB;AAkBjB;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,MAAe;IACrC,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;AACtB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,MAAgB;IAC3C,OAAO,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAC1C,mBAAmB,EACnB,KAAK,EACL,OAAO,EACP,OAAO,GAC4B;IACnC,OAAO;QACL,GAAG,gCAAgC,CAAC,wBAAwB,CAAC;QAC7D,GAAG,uCAAuC,CAAC,yBAAyB,EAAE;YACpE,gBAAgB;YAChB,GAAG,KAAK;YAER,wBAAwB;YACxB,cAAc,EAAE,qCAAqC,CAAC,OAAO,CAAC;YAC9D,cAAc,EAAE,qCAAqC,CAAC,OAAO,CAAC;YAC9D,YAAY,EAAE,mCAAmC,CAAC,OAAO,CAAC;YAC1D,gBAAgB,EAAE,YAAY,CAAC,IAAI,CAAC;YAEpC,+DAA+D;YAC/D,gBAAgB,EAAE,OAAO,CAAC,KAAK,CAAC;YAEhC,uBAAuB,EAAE,YAAY,EAAE;YACvC,mBAAmB,EAAE,oCAAoC,CAAC,OAAO,CAAC;YAClE,qBAAqB,EAAE,sCAAsC,CAAC,OAAO,CAAC;YACtE,sBAAsB,EAAE,uCAAuC,CAAC,OAAO,CAAC;YACxE,eAAe,EAAE,sCAAsC,CAAC,OAAO,CAAC;YAChE,eAAe,EAAE,gCAAgC,CAAC,mBAAmB,CAAC;YACtE,YAAY,EAAE,6BAA6B,CAAC,mBAAmB,CAAC;SACjE,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,oBAAiD,EACjD,MAAc;IAEd,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,MAAM,CAEzE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE;QAClC,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC;QAClC,IAAI,oBAAoB,CAAC,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC;YAC/D,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAAC,aAAa,CACzD,MAAM,EACN,cAAc,CACf,CAAC;YAEF,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,WAAW,CAAC,MAAM,CAAC,UAAsB,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAExB,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,kBAAkB,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetPreferencesMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\n getRequestUserApprovalImplementation,\n} from './hooks';\n\nexport type PermissionSpecificationsHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n};\n\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve(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"]}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createJsonRpcEngine = void 0;
|
|
4
|
-
const eth_json_rpc_middleware_1 = require("@metamask/eth-json-rpc-middleware");
|
|
5
|
-
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
6
|
-
const snaps_rpc_methods_1 = require("@metamask/snaps-rpc-methods");
|
|
7
|
-
const constants_1 = require("../constants.cjs");
|
|
8
|
-
const internal_methods_1 = require("./internal-methods/index.cjs");
|
|
9
|
-
const mock_1 = require("./mock.cjs");
|
|
10
|
-
/**
|
|
11
|
-
* Create a JSON-RPC engine for use in a simulated environment. This engine
|
|
12
|
-
* should be used to handle all JSON-RPC requests. It is set up to handle
|
|
13
|
-
* requests that would normally be handled internally by the MetaMask client, as
|
|
14
|
-
* well as Snap-specific requests.
|
|
15
|
-
*
|
|
16
|
-
* @param options - The options to use when creating the engine.
|
|
17
|
-
* @param options.store - The Redux store to use.
|
|
18
|
-
* @param options.hooks - Any hooks used by the middleware handlers.
|
|
19
|
-
* @param options.permissionMiddleware - The permission middleware to use.
|
|
20
|
-
* @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.
|
|
21
|
-
* @returns A JSON-RPC engine.
|
|
22
|
-
*/
|
|
23
|
-
function createJsonRpcEngine({ store, hooks, permissionMiddleware, endpoint = constants_1.DEFAULT_JSON_RPC_ENDPOINT, }) {
|
|
24
|
-
const engine = new json_rpc_engine_1.JsonRpcEngine();
|
|
25
|
-
engine.push((0, mock_1.createMockMiddleware)(store));
|
|
26
|
-
engine.push((0, internal_methods_1.createInternalMethodsMiddleware)(hooks));
|
|
27
|
-
engine.push((0, snaps_rpc_methods_1.createSnapsMethodMiddleware)(true, hooks));
|
|
28
|
-
engine.push(permissionMiddleware);
|
|
29
|
-
engine.push((0, eth_json_rpc_middleware_1.createFetchMiddleware)({
|
|
30
|
-
btoa: globalThis.btoa,
|
|
31
|
-
fetch: globalThis.fetch,
|
|
32
|
-
rpcUrl: endpoint,
|
|
33
|
-
}));
|
|
34
|
-
return engine;
|
|
35
|
-
}
|
|
36
|
-
exports.createJsonRpcEngine = createJsonRpcEngine;
|
|
37
|
-
//# sourceMappingURL=engine.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engine.cjs","sourceRoot":"","sources":["../../../../src/internals/simulation/middleware/engine.ts"],"names":[],"mappings":";;;AAAA,+EAA0E;AAE1E,+DAA0D;AAE1D,mEAA0E;AAG1E,gDAAyD;AAGzD,mEAAqE;AACrE,qCAA8C;AAS9C;;;;;;;;;;;;GAYG;AACH,SAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,KAAK,EACL,oBAAoB,EACpB,QAAQ,GAAG,qCAAyB,GACT;IAC3B,MAAM,MAAM,GAAG,IAAI,+BAAa,EAAE,CAAC;IACnC,MAAM,CAAC,IAAI,CAAC,IAAA,2BAAoB,EAAC,KAAK,CAAC,CAAC,CAAC;IACzC,MAAM,CAAC,IAAI,CAAC,IAAA,kDAA+B,EAAC,KAAK,CAAC,CAAC,CAAC;IACpD,MAAM,CAAC,IAAI,CAAC,IAAA,+CAA2B,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACtD,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAClC,MAAM,CAAC,IAAI,CACT,IAAA,+CAAqB,EAAC;QACpB,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,MAAM,EAAE,QAAQ;KACjB,CAAC,CACH,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AApBD,kDAoBC","sourcesContent":["import { createFetchMiddleware } from '@metamask/eth-json-rpc-middleware';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type { RestrictedMethodParameters } from '@metamask/permission-controller';\nimport { createSnapsMethodMiddleware } from '@metamask/snaps-rpc-methods';\nimport type { Json } from '@metamask/utils';\n\nimport { DEFAULT_JSON_RPC_ENDPOINT } from '../constants';\nimport type { MiddlewareHooks } from '../simulation';\nimport type { Store } from '../store';\nimport { createInternalMethodsMiddleware } from './internal-methods';\nimport { createMockMiddleware } from './mock';\n\nexport type CreateJsonRpcEngineOptions = {\n store: Store;\n hooks: MiddlewareHooks;\n permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;\n endpoint?: string;\n};\n\n/**\n * Create a JSON-RPC engine for use in a simulated environment. This engine\n * should be used to handle all JSON-RPC requests. It is set up to handle\n * requests that would normally be handled internally by the MetaMask client, as\n * well as Snap-specific requests.\n *\n * @param options - The options to use when creating the engine.\n * @param options.store - The Redux store to use.\n * @param options.hooks - Any hooks used by the middleware handlers.\n * @param options.permissionMiddleware - The permission middleware to use.\n * @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.\n * @returns A JSON-RPC engine.\n */\nexport function createJsonRpcEngine({\n store,\n hooks,\n permissionMiddleware,\n endpoint = DEFAULT_JSON_RPC_ENDPOINT,\n}: CreateJsonRpcEngineOptions) {\n const engine = new JsonRpcEngine();\n engine.push(createMockMiddleware(store));\n engine.push(createInternalMethodsMiddleware(hooks));\n engine.push(createSnapsMethodMiddleware(true, hooks));\n engine.push(permissionMiddleware);\n engine.push(\n createFetchMiddleware({\n btoa: globalThis.btoa,\n fetch: globalThis.fetch,\n rpcUrl: endpoint,\n }),\n );\n\n return engine;\n}\n"]}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
-
import { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
3
|
-
import type { RestrictedMethodParameters } from "@metamask/permission-controller";
|
|
4
|
-
import type { Json } from "@metamask/utils";
|
|
5
|
-
import type { MiddlewareHooks } from "../simulation.cjs";
|
|
6
|
-
import type { Store } from "../store/index.cjs";
|
|
7
|
-
export type CreateJsonRpcEngineOptions = {
|
|
8
|
-
store: Store;
|
|
9
|
-
hooks: MiddlewareHooks;
|
|
10
|
-
permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;
|
|
11
|
-
endpoint?: string;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Create a JSON-RPC engine for use in a simulated environment. This engine
|
|
15
|
-
* should be used to handle all JSON-RPC requests. It is set up to handle
|
|
16
|
-
* requests that would normally be handled internally by the MetaMask client, as
|
|
17
|
-
* well as Snap-specific requests.
|
|
18
|
-
*
|
|
19
|
-
* @param options - The options to use when creating the engine.
|
|
20
|
-
* @param options.store - The Redux store to use.
|
|
21
|
-
* @param options.hooks - Any hooks used by the middleware handlers.
|
|
22
|
-
* @param options.permissionMiddleware - The permission middleware to use.
|
|
23
|
-
* @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.
|
|
24
|
-
* @returns A JSON-RPC engine.
|
|
25
|
-
*/
|
|
26
|
-
export declare function createJsonRpcEngine({ store, hooks, permissionMiddleware, endpoint, }: CreateJsonRpcEngineOptions): JsonRpcEngine;
|
|
27
|
-
//# sourceMappingURL=engine.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.cts","sourceRoot":"","sources":["../../../../src/internals/simulation/middleware/engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AACnE,OAAO,EAAE,aAAa,EAAE,kCAAkC;AAC1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,wCAAwC;AAElF,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,eAAe,EAAE,0BAAsB;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,2BAAiB;AAItC,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,eAAe,CAAC;IACvB,oBAAoB,EAAE,iBAAiB,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAC;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,KAAK,EACL,oBAAoB,EACpB,QAAoC,GACrC,EAAE,0BAA0B,iBAe5B"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
-
import { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
3
|
-
import type { RestrictedMethodParameters } from "@metamask/permission-controller";
|
|
4
|
-
import type { Json } from "@metamask/utils";
|
|
5
|
-
import type { MiddlewareHooks } from "../simulation.mjs";
|
|
6
|
-
import type { Store } from "../store/index.mjs";
|
|
7
|
-
export type CreateJsonRpcEngineOptions = {
|
|
8
|
-
store: Store;
|
|
9
|
-
hooks: MiddlewareHooks;
|
|
10
|
-
permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;
|
|
11
|
-
endpoint?: string;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Create a JSON-RPC engine for use in a simulated environment. This engine
|
|
15
|
-
* should be used to handle all JSON-RPC requests. It is set up to handle
|
|
16
|
-
* requests that would normally be handled internally by the MetaMask client, as
|
|
17
|
-
* well as Snap-specific requests.
|
|
18
|
-
*
|
|
19
|
-
* @param options - The options to use when creating the engine.
|
|
20
|
-
* @param options.store - The Redux store to use.
|
|
21
|
-
* @param options.hooks - Any hooks used by the middleware handlers.
|
|
22
|
-
* @param options.permissionMiddleware - The permission middleware to use.
|
|
23
|
-
* @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.
|
|
24
|
-
* @returns A JSON-RPC engine.
|
|
25
|
-
*/
|
|
26
|
-
export declare function createJsonRpcEngine({ store, hooks, permissionMiddleware, endpoint, }: CreateJsonRpcEngineOptions): JsonRpcEngine;
|
|
27
|
-
//# sourceMappingURL=engine.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.mts","sourceRoot":"","sources":["../../../../src/internals/simulation/middleware/engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AACnE,OAAO,EAAE,aAAa,EAAE,kCAAkC;AAC1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,wCAAwC;AAElF,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,eAAe,EAAE,0BAAsB;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,2BAAiB;AAItC,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,eAAe,CAAC;IACvB,oBAAoB,EAAE,iBAAiB,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAC;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,KAAK,EACL,oBAAoB,EACpB,QAAoC,GACrC,EAAE,0BAA0B,iBAe5B"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import $metamaskethjsonrpcmiddleware from "@metamask/eth-json-rpc-middleware";
|
|
2
|
-
const { createFetchMiddleware } = $metamaskethjsonrpcmiddleware;
|
|
3
|
-
import { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
4
|
-
import { createSnapsMethodMiddleware } from "@metamask/snaps-rpc-methods";
|
|
5
|
-
import { DEFAULT_JSON_RPC_ENDPOINT } from "../constants.mjs";
|
|
6
|
-
import { createInternalMethodsMiddleware } from "./internal-methods/index.mjs";
|
|
7
|
-
import { createMockMiddleware } from "./mock.mjs";
|
|
8
|
-
/**
|
|
9
|
-
* Create a JSON-RPC engine for use in a simulated environment. This engine
|
|
10
|
-
* should be used to handle all JSON-RPC requests. It is set up to handle
|
|
11
|
-
* requests that would normally be handled internally by the MetaMask client, as
|
|
12
|
-
* well as Snap-specific requests.
|
|
13
|
-
*
|
|
14
|
-
* @param options - The options to use when creating the engine.
|
|
15
|
-
* @param options.store - The Redux store to use.
|
|
16
|
-
* @param options.hooks - Any hooks used by the middleware handlers.
|
|
17
|
-
* @param options.permissionMiddleware - The permission middleware to use.
|
|
18
|
-
* @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.
|
|
19
|
-
* @returns A JSON-RPC engine.
|
|
20
|
-
*/
|
|
21
|
-
export function createJsonRpcEngine({ store, hooks, permissionMiddleware, endpoint = DEFAULT_JSON_RPC_ENDPOINT, }) {
|
|
22
|
-
const engine = new JsonRpcEngine();
|
|
23
|
-
engine.push(createMockMiddleware(store));
|
|
24
|
-
engine.push(createInternalMethodsMiddleware(hooks));
|
|
25
|
-
engine.push(createSnapsMethodMiddleware(true, hooks));
|
|
26
|
-
engine.push(permissionMiddleware);
|
|
27
|
-
engine.push(createFetchMiddleware({
|
|
28
|
-
btoa: globalThis.btoa,
|
|
29
|
-
fetch: globalThis.fetch,
|
|
30
|
-
rpcUrl: endpoint,
|
|
31
|
-
}));
|
|
32
|
-
return engine;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=engine.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engine.mjs","sourceRoot":"","sources":["../../../../src/internals/simulation/middleware/engine.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,aAAa,EAAE,kCAAkC;AAE1D,OAAO,EAAE,2BAA2B,EAAE,oCAAoC;AAG1E,OAAO,EAAE,yBAAyB,EAAE,yBAAqB;AAGzD,OAAO,EAAE,+BAA+B,EAAE,qCAA2B;AACrE,OAAO,EAAE,oBAAoB,EAAE,mBAAe;AAS9C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,KAAK,EACL,KAAK,EACL,oBAAoB,EACpB,QAAQ,GAAG,yBAAyB,GACT;IAC3B,MAAM,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;IACnC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;IACzC,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,KAAK,CAAC,CAAC,CAAC;IACpD,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACtD,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAClC,MAAM,CAAC,IAAI,CACT,qBAAqB,CAAC;QACpB,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,MAAM,EAAE,QAAQ;KACjB,CAAC,CACH,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { createFetchMiddleware } from '@metamask/eth-json-rpc-middleware';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type { RestrictedMethodParameters } from '@metamask/permission-controller';\nimport { createSnapsMethodMiddleware } from '@metamask/snaps-rpc-methods';\nimport type { Json } from '@metamask/utils';\n\nimport { DEFAULT_JSON_RPC_ENDPOINT } from '../constants';\nimport type { MiddlewareHooks } from '../simulation';\nimport type { Store } from '../store';\nimport { createInternalMethodsMiddleware } from './internal-methods';\nimport { createMockMiddleware } from './mock';\n\nexport type CreateJsonRpcEngineOptions = {\n store: Store;\n hooks: MiddlewareHooks;\n permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;\n endpoint?: string;\n};\n\n/**\n * Create a JSON-RPC engine for use in a simulated environment. This engine\n * should be used to handle all JSON-RPC requests. It is set up to handle\n * requests that would normally be handled internally by the MetaMask client, as\n * well as Snap-specific requests.\n *\n * @param options - The options to use when creating the engine.\n * @param options.store - The Redux store to use.\n * @param options.hooks - Any hooks used by the middleware handlers.\n * @param options.permissionMiddleware - The permission middleware to use.\n * @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.\n * @returns A JSON-RPC engine.\n */\nexport function createJsonRpcEngine({\n store,\n hooks,\n permissionMiddleware,\n endpoint = DEFAULT_JSON_RPC_ENDPOINT,\n}: CreateJsonRpcEngineOptions) {\n const engine = new JsonRpcEngine();\n engine.push(createMockMiddleware(store));\n engine.push(createInternalMethodsMiddleware(hooks));\n engine.push(createSnapsMethodMiddleware(true, hooks));\n engine.push(permissionMiddleware);\n engine.push(\n createFetchMiddleware({\n btoa: globalThis.btoa,\n fetch: globalThis.fetch,\n rpcUrl: endpoint,\n }),\n );\n\n return engine;\n}\n"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./engine.cjs"), exports);
|
|
18
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/internals/simulation/middleware/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAAyB","sourcesContent":["export * from './engine';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/internals/simulation/middleware/index.ts"],"names":[],"mappings":"AAAA,6BAAyB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/internals/simulation/middleware/index.ts"],"names":[],"mappings":"AAAA,6BAAyB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/internals/simulation/middleware/index.ts"],"names":[],"mappings":"AAAA,6BAAyB","sourcesContent":["export * from './engine';\n"]}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAccountsHandler = void 0;
|
|
4
|
-
const key_tree_1 = require("@metamask/key-tree");
|
|
5
|
-
/**
|
|
6
|
-
* A mock handler for account related methods that always returns the first
|
|
7
|
-
* address for the selected secret recovery phrase.
|
|
8
|
-
*
|
|
9
|
-
* @param _request - Incoming JSON-RPC request. This is ignored for this
|
|
10
|
-
* specific handler.
|
|
11
|
-
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
12
|
-
* result.
|
|
13
|
-
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
14
|
-
* @param end - The `json-rpc-engine` middleware end handler.
|
|
15
|
-
* @param hooks - Any hooks required by this handler.
|
|
16
|
-
* @returns The JSON-RPC response.
|
|
17
|
-
*/
|
|
18
|
-
async function getAccountsHandler(_request, response, _next, end, hooks) {
|
|
19
|
-
const { getMnemonic } = hooks;
|
|
20
|
-
const node = await key_tree_1.BIP44Node.fromDerivationPath({
|
|
21
|
-
derivationPath: [
|
|
22
|
-
await getMnemonic(),
|
|
23
|
-
`bip32:44'`,
|
|
24
|
-
`bip32:60'`,
|
|
25
|
-
`bip32:0'`,
|
|
26
|
-
`bip32:0`,
|
|
27
|
-
`bip32:0`,
|
|
28
|
-
],
|
|
29
|
-
});
|
|
30
|
-
response.result = [node.address];
|
|
31
|
-
return end();
|
|
32
|
-
}
|
|
33
|
-
exports.getAccountsHandler = getAccountsHandler;
|
|
34
|
-
//# sourceMappingURL=accounts.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/accounts.ts"],"names":[],"mappings":";;;AAIA,iDAA+C;AAW/C;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,kBAAkB,CACtC,QAAwB,EACxB,QAAsC,EACtC,KAAgC,EAChC,GAA6B,EAC7B,KAA8B;IAE9B,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAE9B,MAAM,IAAI,GAAG,MAAM,oBAAS,CAAC,kBAAkB,CAAC;QAC9C,cAAc,EAAE;YACd,MAAM,WAAW,EAAE;YACnB,WAAW;YACX,WAAW;YACX,UAAU;YACV,SAAS;YACT,SAAS;SACV;KACF,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAtBD,gDAsBC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport { BIP44Node } from '@metamask/key-tree';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nexport type GetAccountsHandlerHooks = {\n getMnemonic: () => Promise<Uint8Array>;\n};\n\n/**\n * A mock handler for account related methods that always returns the first\n * address for the selected secret recovery phrase.\n *\n * @param _request - Incoming JSON-RPC request. This is ignored for this\n * specific handler.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n * @param hooks - Any hooks required by this handler.\n * @returns The JSON-RPC response.\n */\nexport async function getAccountsHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: GetAccountsHandlerHooks,\n) {\n const { getMnemonic } = hooks;\n\n const node = await BIP44Node.fromDerivationPath({\n derivationPath: [\n await getMnemonic(),\n `bip32:44'`,\n `bip32:60'`,\n `bip32:0'`,\n `bip32:0`,\n `bip32:0`,\n ],\n });\n\n response.result = [node.address];\n return end();\n}\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
3
|
-
export type GetAccountsHandlerHooks = {
|
|
4
|
-
getMnemonic: () => Promise<Uint8Array>;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* A mock handler for account related methods that always returns the first
|
|
8
|
-
* address for the selected secret recovery phrase.
|
|
9
|
-
*
|
|
10
|
-
* @param _request - Incoming JSON-RPC request. This is ignored for this
|
|
11
|
-
* specific handler.
|
|
12
|
-
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
13
|
-
* result.
|
|
14
|
-
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
15
|
-
* @param end - The `json-rpc-engine` middleware end handler.
|
|
16
|
-
* @param hooks - Any hooks required by this handler.
|
|
17
|
-
* @returns The JSON-RPC response.
|
|
18
|
-
*/
|
|
19
|
-
export declare function getAccountsHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: GetAccountsHandlerHooks): Promise<void>;
|
|
20
|
-
//# sourceMappingURL=accounts.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.d.cts","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AAEnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,uBAAuB,iBAiB/B"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
3
|
-
export type GetAccountsHandlerHooks = {
|
|
4
|
-
getMnemonic: () => Promise<Uint8Array>;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* A mock handler for account related methods that always returns the first
|
|
8
|
-
* address for the selected secret recovery phrase.
|
|
9
|
-
*
|
|
10
|
-
* @param _request - Incoming JSON-RPC request. This is ignored for this
|
|
11
|
-
* specific handler.
|
|
12
|
-
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
13
|
-
* result.
|
|
14
|
-
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
15
|
-
* @param end - The `json-rpc-engine` middleware end handler.
|
|
16
|
-
* @param hooks - Any hooks required by this handler.
|
|
17
|
-
* @returns The JSON-RPC response.
|
|
18
|
-
*/
|
|
19
|
-
export declare function getAccountsHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: GetAccountsHandlerHooks): Promise<void>;
|
|
20
|
-
//# sourceMappingURL=accounts.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.d.mts","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AAEnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,uBAAuB,iBAiB/B"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { BIP44Node } from "@metamask/key-tree";
|
|
2
|
-
/**
|
|
3
|
-
* A mock handler for account related methods that always returns the first
|
|
4
|
-
* address for the selected secret recovery phrase.
|
|
5
|
-
*
|
|
6
|
-
* @param _request - Incoming JSON-RPC request. This is ignored for this
|
|
7
|
-
* specific handler.
|
|
8
|
-
* @param response - The outgoing JSON-RPC response, modified to return the
|
|
9
|
-
* result.
|
|
10
|
-
* @param _next - The `json-rpc-engine` middleware next handler.
|
|
11
|
-
* @param end - The `json-rpc-engine` middleware end handler.
|
|
12
|
-
* @param hooks - Any hooks required by this handler.
|
|
13
|
-
* @returns The JSON-RPC response.
|
|
14
|
-
*/
|
|
15
|
-
export async function getAccountsHandler(_request, response, _next, end, hooks) {
|
|
16
|
-
const { getMnemonic } = hooks;
|
|
17
|
-
const node = await BIP44Node.fromDerivationPath({
|
|
18
|
-
derivationPath: [
|
|
19
|
-
await getMnemonic(),
|
|
20
|
-
`bip32:44'`,
|
|
21
|
-
`bip32:60'`,
|
|
22
|
-
`bip32:0'`,
|
|
23
|
-
`bip32:0`,
|
|
24
|
-
`bip32:0`,
|
|
25
|
-
],
|
|
26
|
-
});
|
|
27
|
-
response.result = [node.address];
|
|
28
|
-
return end();
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=accounts.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.mjs","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/accounts.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAW/C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAwB,EACxB,QAAsC,EACtC,KAAgC,EAChC,GAA6B,EAC7B,KAA8B;IAE9B,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAE9B,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,kBAAkB,CAAC;QAC9C,cAAc,EAAE;YACd,MAAM,WAAW,EAAE;YACnB,WAAW;YACX,WAAW;YACX,UAAU;YACV,SAAS;YACT,SAAS;SACV;KACF,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport { BIP44Node } from '@metamask/key-tree';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nexport type GetAccountsHandlerHooks = {\n getMnemonic: () => Promise<Uint8Array>;\n};\n\n/**\n * A mock handler for account related methods that always returns the first\n * address for the selected secret recovery phrase.\n *\n * @param _request - Incoming JSON-RPC request. This is ignored for this\n * specific handler.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n * @param hooks - Any hooks required by this handler.\n * @returns The JSON-RPC response.\n */\nexport async function getAccountsHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: GetAccountsHandlerHooks,\n) {\n const { getMnemonic } = hooks;\n\n const node = await BIP44Node.fromDerivationPath({\n derivationPath: [\n await getMnemonic(),\n `bip32:44'`,\n `bip32:60'`,\n `bip32:0'`,\n `bip32:0`,\n `bip32:0`,\n ],\n });\n\n response.result = [node.address];\n return end();\n}\n"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./middleware.cjs"), exports);
|
|
18
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAA6B","sourcesContent":["export * from './middleware';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/index.ts"],"names":[],"mappings":"AAAA,iCAA6B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/index.ts"],"names":[],"mappings":"AAAA,iCAA6B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/index.ts"],"names":[],"mappings":"AAAA,iCAA6B","sourcesContent":["export * from './middleware';\n"]}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createInternalMethodsMiddleware = void 0;
|
|
4
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
5
|
-
const accounts_1 = require("./accounts.cjs");
|
|
6
|
-
const provider_state_1 = require("./provider-state.cjs");
|
|
7
|
-
const methodHandlers = {
|
|
8
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
9
|
-
metamask_getProviderState: provider_state_1.getProviderStateHandler,
|
|
10
|
-
eth_requestAccounts: accounts_1.getAccountsHandler,
|
|
11
|
-
eth_accounts: accounts_1.getAccountsHandler,
|
|
12
|
-
/* eslint-enable @typescript-eslint/naming-convention */
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Create a middleware for handling JSON-RPC methods normally handled internally
|
|
16
|
-
* by the MetaMask client.
|
|
17
|
-
*
|
|
18
|
-
* NOTE: This middleware provides all `hooks` to all handlers and should
|
|
19
|
-
* therefore NOT be used outside of the simulation environment. It is intended
|
|
20
|
-
* for testing purposes only.
|
|
21
|
-
*
|
|
22
|
-
* @param hooks - Any hooks used by the middleware handlers.
|
|
23
|
-
* @returns A middleware function.
|
|
24
|
-
*/
|
|
25
|
-
function createInternalMethodsMiddleware(hooks) {
|
|
26
|
-
// This should probably use createAsyncMiddleware.
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
28
|
-
return async function methodMiddleware(request, response, next, end) {
|
|
29
|
-
const handler = methodHandlers[request.method];
|
|
30
|
-
if (handler) {
|
|
31
|
-
try {
|
|
32
|
-
// Implementations may or may not be async, so we must await them.
|
|
33
|
-
return await handler(request, response, next, end, hooks);
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
(0, snaps_utils_1.logError)(error);
|
|
37
|
-
return end(error);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return next();
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
exports.createInternalMethodsMiddleware = createInternalMethodsMiddleware;
|
|
44
|
-
//# sourceMappingURL=middleware.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.cjs","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/middleware.ts"],"names":[],"mappings":";;;AACA,uDAAiD;AAGjD,6CAAgD;AAChD,yDAA2D;AAW3D,MAAM,cAAc,GAAG;IACrB,yDAAyD;IACzD,yBAAyB,EAAE,wCAAuB;IAClD,mBAAmB,EAAE,6BAAkB;IACvC,YAAY,EAAE,6BAAkB;IAChC,wDAAwD;CACzD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,SAAgB,+BAA+B,CAC7C,KAAqC;IAErC,kDAAkD;IAClD,kEAAkE;IAClE,OAAO,KAAK,UAAU,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG;QACjE,MAAM,OAAO,GACX,cAAc,CAAC,OAAO,CAAC,MAAqC,CAAC,CAAC;QAChE,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,kEAAkE;gBAClE,OAAO,MAAM,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAC5D,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAA,sBAAQ,EAAC,KAAK,CAAC,CAAC;gBAChB,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AApBD,0EAoBC","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { getAccountsHandler } from './accounts';\nimport { getProviderStateHandler } from './provider-state';\n\nexport type InternalMethodsMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n};\n\nconst methodHandlers = {\n /* eslint-disable @typescript-eslint/naming-convention */\n metamask_getProviderState: getProviderStateHandler,\n eth_requestAccounts: getAccountsHandler,\n eth_accounts: getAccountsHandler,\n /* eslint-enable @typescript-eslint/naming-convention */\n};\n\n/**\n * Create a middleware for handling JSON-RPC methods normally handled internally\n * by the MetaMask client.\n *\n * NOTE: This middleware provides all `hooks` to all handlers and should\n * therefore NOT be used outside of the simulation environment. It is intended\n * for testing purposes only.\n *\n * @param hooks - Any hooks used by the middleware handlers.\n * @returns A middleware function.\n */\nexport function createInternalMethodsMiddleware(\n hooks: InternalMethodsMiddlewareHooks,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This should probably use createAsyncMiddleware.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n try {\n // Implementations may or may not be async, so we must await them.\n return await handler(request, response, next, end, hooks);\n } catch (error: any) {\n logError(error);\n return end(error);\n }\n }\n\n return next();\n };\n}\n"]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
3
|
-
export type InternalMethodsMiddlewareHooks = {
|
|
4
|
-
/**
|
|
5
|
-
* A hook that returns the user's secret recovery phrase.
|
|
6
|
-
*
|
|
7
|
-
* @returns The user's secret recovery phrase.
|
|
8
|
-
*/
|
|
9
|
-
getMnemonic: () => Promise<Uint8Array>;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Create a middleware for handling JSON-RPC methods normally handled internally
|
|
13
|
-
* by the MetaMask client.
|
|
14
|
-
*
|
|
15
|
-
* NOTE: This middleware provides all `hooks` to all handlers and should
|
|
16
|
-
* therefore NOT be used outside of the simulation environment. It is intended
|
|
17
|
-
* for testing purposes only.
|
|
18
|
-
*
|
|
19
|
-
* @param hooks - Any hooks used by the middleware handlers.
|
|
20
|
-
* @returns A middleware function.
|
|
21
|
-
*/
|
|
22
|
-
export declare function createInternalMethodsMiddleware(hooks: InternalMethodsMiddlewareHooks): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
23
|
-
//# sourceMappingURL=middleware.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.cts","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAK3D,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAUF;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,8BAA8B,GACpC,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAkBxC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
3
|
-
export type InternalMethodsMiddlewareHooks = {
|
|
4
|
-
/**
|
|
5
|
-
* A hook that returns the user's secret recovery phrase.
|
|
6
|
-
*
|
|
7
|
-
* @returns The user's secret recovery phrase.
|
|
8
|
-
*/
|
|
9
|
-
getMnemonic: () => Promise<Uint8Array>;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Create a middleware for handling JSON-RPC methods normally handled internally
|
|
13
|
-
* by the MetaMask client.
|
|
14
|
-
*
|
|
15
|
-
* NOTE: This middleware provides all `hooks` to all handlers and should
|
|
16
|
-
* therefore NOT be used outside of the simulation environment. It is intended
|
|
17
|
-
* for testing purposes only.
|
|
18
|
-
*
|
|
19
|
-
* @param hooks - Any hooks used by the middleware handlers.
|
|
20
|
-
* @returns A middleware function.
|
|
21
|
-
*/
|
|
22
|
-
export declare function createInternalMethodsMiddleware(hooks: InternalMethodsMiddlewareHooks): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
23
|
-
//# sourceMappingURL=middleware.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.mts","sourceRoot":"","sources":["../../../../../src/internals/simulation/middleware/internal-methods/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAK3D,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAUF;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,8BAA8B,GACpC,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAkBxC"}
|