@metamask/snaps-jest 4.0.0 → 5.0.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 +21 -1
- package/README.md +66 -179
- package/dist/cjs/environment.js +21 -82
- package/dist/cjs/environment.js.map +1 -1
- package/dist/cjs/helpers.js +118 -43
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/internals/environment.js +1 -1
- package/dist/cjs/internals/environment.js.map +1 -1
- package/dist/cjs/internals/index.js +1 -4
- package/dist/cjs/internals/index.js.map +1 -1
- package/dist/cjs/internals/request.js +42 -94
- package/dist/cjs/internals/request.js.map +1 -1
- package/dist/cjs/internals/server.js +0 -4
- package/dist/cjs/internals/server.js.map +1 -1
- package/dist/cjs/internals/simulation/constants.js +29 -0
- package/dist/cjs/internals/simulation/constants.js.map +1 -0
- package/dist/cjs/internals/simulation/controllers.js +95 -0
- package/dist/cjs/internals/simulation/controllers.js.map +1 -0
- package/dist/cjs/internals/simulation/files.js +22 -0
- package/dist/cjs/internals/simulation/files.js.map +1 -0
- package/dist/cjs/internals/simulation/index.js +24 -0
- package/dist/cjs/internals/simulation/index.js.map +1 -0
- package/dist/cjs/internals/simulation/interface.js +98 -0
- package/dist/cjs/internals/simulation/interface.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/constants.js +84 -0
- package/dist/cjs/internals/simulation/methods/constants.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/encryption.js +33 -0
- package/dist/cjs/internals/simulation/methods/hooks/encryption.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/get-locale.js +17 -0
- package/dist/cjs/internals/simulation/methods/hooks/get-locale.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/index.js +25 -0
- package/dist/cjs/internals/simulation/methods/hooks/index.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/interface.js +26 -0
- package/dist/cjs/internals/simulation/methods/hooks/interface.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/notifications.js +66 -0
- package/dist/cjs/internals/simulation/methods/hooks/notifications.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js +43 -0
- package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/state.js +80 -0
- package/dist/cjs/internals/simulation/methods/hooks/state.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/index.js +20 -0
- package/dist/cjs/internals/simulation/methods/index.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/specifications.js +81 -0
- package/dist/cjs/internals/simulation/methods/specifications.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/engine.js +31 -0
- package/dist/cjs/internals/simulation/middleware/engine.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/index.js +20 -0
- package/dist/cjs/internals/simulation/middleware/index.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js +30 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/index.js +20 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/index.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js +37 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/mock.js +23 -0
- package/dist/cjs/internals/simulation/middleware/mock.js.map +1 -0
- package/dist/cjs/internals/simulation/options.js +24 -0
- package/dist/cjs/internals/simulation/options.js.map +1 -0
- package/dist/cjs/internals/simulation/simulation.js +124 -0
- package/dist/cjs/internals/simulation/simulation.js.map +1 -0
- package/dist/cjs/internals/simulation/store/index.js +23 -0
- package/dist/cjs/internals/simulation/store/index.js.map +1 -0
- package/dist/cjs/internals/simulation/store/mocks.js +52 -0
- package/dist/cjs/internals/simulation/store/mocks.js.map +1 -0
- package/dist/cjs/internals/simulation/store/notifications.js +52 -0
- package/dist/cjs/internals/simulation/store/notifications.js.map +1 -0
- package/dist/cjs/internals/simulation/store/state.js +64 -0
- package/dist/cjs/internals/simulation/store/state.js.map +1 -0
- package/dist/cjs/internals/simulation/store/store.js +57 -0
- package/dist/cjs/internals/simulation/store/store.js.map +1 -0
- package/dist/cjs/internals/simulation/store/ui.js +48 -0
- package/dist/cjs/internals/simulation/store/ui.js.map +1 -0
- package/dist/cjs/internals/structs.js +47 -5
- package/dist/cjs/internals/structs.js.map +1 -1
- package/dist/cjs/matchers.js +5 -2
- package/dist/cjs/matchers.js.map +1 -1
- package/dist/cjs/options.js +0 -6
- package/dist/cjs/options.js.map +1 -1
- package/dist/esm/environment.js +22 -83
- package/dist/esm/environment.js.map +1 -1
- package/dist/esm/helpers.js +127 -46
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/internals/environment.js +1 -1
- package/dist/esm/internals/environment.js.map +1 -1
- package/dist/esm/internals/index.js +1 -5
- package/dist/esm/internals/index.js.map +1 -1
- package/dist/esm/internals/request.js +61 -104
- package/dist/esm/internals/request.js.map +1 -1
- package/dist/esm/internals/server.js +1 -5
- package/dist/esm/internals/server.js.map +1 -1
- package/dist/esm/internals/simulation/constants.js +12 -0
- package/dist/esm/internals/simulation/constants.js.map +1 -0
- package/dist/esm/internals/simulation/controllers.js +90 -0
- package/dist/esm/internals/simulation/controllers.js.map +1 -0
- package/dist/esm/internals/simulation/files.js +19 -0
- package/dist/esm/internals/simulation/files.js.map +1 -0
- package/dist/esm/internals/simulation/index.js +7 -0
- package/dist/esm/internals/simulation/index.js.map +1 -0
- package/dist/esm/internals/simulation/interface.js +95 -0
- package/dist/esm/internals/simulation/interface.js.map +1 -0
- package/dist/esm/internals/simulation/methods/constants.js +69 -0
- package/dist/esm/internals/simulation/methods/constants.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/encryption.js +39 -0
- package/dist/esm/internals/simulation/methods/hooks/encryption.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/get-locale.js +13 -0
- package/dist/esm/internals/simulation/methods/hooks/get-locale.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/index.js +8 -0
- package/dist/esm/internals/simulation/methods/hooks/index.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/interface.js +18 -0
- package/dist/esm/internals/simulation/methods/hooks/interface.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/notifications.js +58 -0
- package/dist/esm/internals/simulation/methods/hooks/notifications.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/show-dialog.js +38 -0
- package/dist/esm/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/state.js +74 -0
- package/dist/esm/internals/simulation/methods/hooks/state.js.map +1 -0
- package/dist/esm/internals/simulation/methods/index.js +3 -0
- package/dist/esm/internals/simulation/methods/index.js.map +1 -0
- package/dist/esm/internals/simulation/methods/specifications.js +84 -0
- package/dist/esm/internals/simulation/methods/specifications.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/engine.js +33 -0
- package/dist/esm/internals/simulation/middleware/engine.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/index.js +3 -0
- package/dist/esm/internals/simulation/middleware/index.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js +31 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/index.js +3 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/index.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js +37 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/mock.js +18 -0
- package/dist/esm/internals/simulation/middleware/mock.js.map +1 -0
- package/dist/esm/internals/simulation/options.js +20 -0
- package/dist/esm/internals/simulation/options.js.map +1 -0
- package/dist/esm/internals/simulation/simulation.js +128 -0
- package/dist/esm/internals/simulation/simulation.js.map +1 -0
- package/dist/esm/internals/simulation/store/index.js +6 -0
- package/dist/esm/internals/simulation/store/index.js.map +1 -0
- package/dist/esm/internals/simulation/store/mocks.js +32 -0
- package/dist/esm/internals/simulation/store/mocks.js.map +1 -0
- package/dist/esm/internals/simulation/store/notifications.js +30 -0
- package/dist/esm/internals/simulation/store/notifications.js.map +1 -0
- package/dist/esm/internals/simulation/store/state.js +47 -0
- package/dist/esm/internals/simulation/store/state.js.map +1 -0
- package/dist/esm/internals/simulation/store/store.js +50 -0
- package/dist/esm/internals/simulation/store/store.js.map +1 -0
- package/dist/esm/internals/simulation/store/ui.js +21 -0
- package/dist/esm/internals/simulation/store/ui.js.map +1 -0
- package/dist/esm/internals/structs.js +41 -5
- package/dist/esm/internals/structs.js.map +1 -1
- package/dist/esm/matchers.js +5 -2
- package/dist/esm/matchers.js.map +1 -1
- package/dist/esm/options.js +1 -7
- package/dist/esm/options.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/types/environment.d.ts +14 -15
- package/dist/types/helpers.d.ts +64 -3
- package/dist/types/internals/index.d.ts +1 -4
- package/dist/types/internals/request.d.ts +38 -56
- package/dist/types/internals/simulation/constants.d.ts +13 -0
- package/dist/types/internals/simulation/controllers.d.ts +40 -0
- package/dist/types/internals/simulation/files.d.ts +11 -0
- package/dist/types/internals/simulation/index.d.ts +5 -0
- package/dist/types/internals/simulation/interface.d.ts +25 -0
- package/dist/types/internals/simulation/methods/constants.d.ts +10 -0
- package/dist/types/internals/simulation/methods/hooks/encryption.d.ts +29 -0
- package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +9 -0
- package/dist/types/internals/simulation/methods/hooks/index.d.ts +6 -0
- package/dist/types/internals/simulation/methods/hooks/interface.d.ts +16 -0
- package/dist/types/internals/simulation/methods/hooks/notifications.d.ts +16 -0
- package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +9 -0
- package/dist/types/internals/simulation/methods/hooks/state.d.ts +22 -0
- package/dist/types/internals/simulation/methods/index.d.ts +1 -0
- package/dist/types/internals/simulation/methods/specifications.d.ts +56 -0
- package/dist/types/internals/simulation/middleware/engine.d.ts +26 -0
- package/dist/types/internals/simulation/middleware/index.d.ts +1 -0
- package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +18 -0
- package/dist/types/internals/simulation/middleware/internal-methods/index.d.ts +1 -0
- package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +22 -0
- package/dist/types/internals/simulation/middleware/internal-methods/provider-state.d.ts +14 -0
- package/dist/types/internals/simulation/middleware/mock.d.ts +10 -0
- package/dist/types/internals/simulation/options.d.ts +37 -0
- package/dist/types/internals/simulation/simulation.d.ts +98 -0
- package/dist/types/internals/simulation/store/index.d.ts +4 -0
- package/dist/types/internals/simulation/store/mocks.d.ts +35 -0
- package/dist/types/internals/simulation/store/notifications.d.ts +44 -0
- package/dist/types/internals/simulation/store/state.d.ts +55 -0
- package/dist/types/internals/simulation/store/store.d.ts +22 -0
- package/dist/types/internals/simulation/store/ui.d.ts +25 -0
- package/dist/types/internals/structs.d.ts +229 -16
- package/dist/types/options.d.ts +3 -35
- package/dist/types/types.d.ts +88 -41
- package/package.json +21 -12
- package/dist/cjs/internals/interface.js +0 -103
- package/dist/cjs/internals/interface.js.map +0 -1
- package/dist/cjs/internals/network.js +0 -148
- package/dist/cjs/internals/network.js.map +0 -1
- package/dist/cjs/internals/types.js +0 -6
- package/dist/cjs/internals/types.js.map +0 -1
- package/dist/cjs/internals/wait-for.js +0 -63
- package/dist/cjs/internals/wait-for.js.map +0 -1
- package/dist/esm/internals/interface.js +0 -100
- package/dist/esm/internals/interface.js.map +0 -1
- package/dist/esm/internals/network.js +0 -143
- package/dist/esm/internals/network.js.map +0 -1
- package/dist/esm/internals/types.js +0 -3
- package/dist/esm/internals/types.js.map +0 -1
- package/dist/esm/internals/wait-for.js +0 -63
- package/dist/esm/internals/wait-for.js.map +0 -1
- package/dist/types/internals/interface.d.ts +0 -25
- package/dist/types/internals/network.d.ts +0 -87
- package/dist/types/internals/types.d.ts +0 -18
- package/dist/types/internals/wait-for.d.ts +0 -38
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getControllers: function() {
|
|
13
|
+
return getControllers;
|
|
14
|
+
},
|
|
15
|
+
registerSnap: function() {
|
|
16
|
+
return registerSnap;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _permissioncontroller = require("@metamask/permission-controller");
|
|
20
|
+
const _snapscontrollers = require("@metamask/snaps-controllers");
|
|
21
|
+
const _snapsrpcmethods = require("@metamask/snaps-rpc-methods");
|
|
22
|
+
const _utils = require("@metamask/utils");
|
|
23
|
+
const _methods = require("./methods");
|
|
24
|
+
const _constants = require("./methods/constants");
|
|
25
|
+
function getControllers(options) {
|
|
26
|
+
const { controllerMessenger } = options;
|
|
27
|
+
const subjectMetadataController = new _permissioncontroller.SubjectMetadataController({
|
|
28
|
+
messenger: controllerMessenger.getRestricted({
|
|
29
|
+
name: 'SubjectMetadataController'
|
|
30
|
+
}),
|
|
31
|
+
subjectCacheLimit: 100
|
|
32
|
+
});
|
|
33
|
+
const interfaceController = new _snapscontrollers.SnapInterfaceController({
|
|
34
|
+
messenger: controllerMessenger.getRestricted({
|
|
35
|
+
name: 'SnapInterfaceController',
|
|
36
|
+
allowedActions: [
|
|
37
|
+
'PhishingController:maybeUpdateState',
|
|
38
|
+
'PhishingController:testOrigin'
|
|
39
|
+
]
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
const permissionController = getPermissionController(options);
|
|
43
|
+
return {
|
|
44
|
+
permissionController,
|
|
45
|
+
subjectMetadataController,
|
|
46
|
+
interfaceController
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the permission controller for the Snap.
|
|
51
|
+
*
|
|
52
|
+
* @param options - The options.
|
|
53
|
+
* @param options.controllerMessenger - The controller messenger.
|
|
54
|
+
* @param options.options - Miscellaneous options.
|
|
55
|
+
* @returns The permission controller for the Snap.
|
|
56
|
+
*/ function getPermissionController(options) {
|
|
57
|
+
const { controllerMessenger } = options;
|
|
58
|
+
const permissionSpecifications = (0, _methods.getPermissionSpecifications)(options);
|
|
59
|
+
return new _permissioncontroller.PermissionController({
|
|
60
|
+
messenger: controllerMessenger.getRestricted({
|
|
61
|
+
name: 'PermissionController',
|
|
62
|
+
allowedActions: [
|
|
63
|
+
`ApprovalController:addRequest`,
|
|
64
|
+
`ApprovalController:hasRequest`,
|
|
65
|
+
`ApprovalController:acceptRequest`,
|
|
66
|
+
`ApprovalController:rejectRequest`,
|
|
67
|
+
`SnapController:getPermitted`,
|
|
68
|
+
`SnapController:install`,
|
|
69
|
+
`SubjectMetadataController:getSubjectMetadata`
|
|
70
|
+
]
|
|
71
|
+
}),
|
|
72
|
+
caveatSpecifications: {
|
|
73
|
+
..._snapsrpcmethods.caveatSpecifications,
|
|
74
|
+
..._snapsrpcmethods.endowmentCaveatSpecifications
|
|
75
|
+
},
|
|
76
|
+
permissionSpecifications,
|
|
77
|
+
unrestrictedMethods: _constants.UNRESTRICTED_METHODS
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async function registerSnap(snapId, manifest, { permissionController, subjectMetadataController }) {
|
|
81
|
+
subjectMetadataController.addSubjectMetadata({
|
|
82
|
+
origin: snapId,
|
|
83
|
+
subjectType: _permissioncontroller.SubjectType.Snap
|
|
84
|
+
});
|
|
85
|
+
const approvedPermissions = (0, _snapsrpcmethods.processSnapPermissions)((0, _utils.getSafeJson)(manifest.initialPermissions));
|
|
86
|
+
permissionController.grantPermissions({
|
|
87
|
+
approvedPermissions,
|
|
88
|
+
subject: {
|
|
89
|
+
origin: snapId
|
|
90
|
+
},
|
|
91
|
+
preserveExistingPermissions: false
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=controllers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/internals/simulation/controllers.ts"],"sourcesContent":["import type { ControllerMessenger } from '@metamask/base-controller';\nimport type {\n CaveatSpecificationConstraint,\n PermissionSpecificationConstraint,\n PermissionControllerActions,\n SubjectMetadataControllerActions,\n} from '@metamask/permission-controller';\nimport {\n PermissionController,\n SubjectMetadataController,\n SubjectType,\n} from '@metamask/permission-controller';\nimport { SnapInterfaceController } from '@metamask/snaps-controllers';\nimport type {\n ExecutionServiceActions,\n SnapInterfaceControllerActions,\n SnapInterfaceControllerAllowedActions,\n} from '@metamask/snaps-controllers';\nimport {\n caveatSpecifications as snapsCaveatsSpecifications,\n endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications,\n processSnapPermissions,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { SnapManifest } from '@metamask/snaps-utils';\nimport { getSafeJson } from '@metamask/utils';\n\nimport { getPermissionSpecifications } from './methods';\nimport { UNRESTRICTED_METHODS } from './methods/constants';\nimport type { SimulationOptions } from './options';\nimport type { MiddlewareHooks } from './simulation';\nimport type { RunSagaFunction } from './store';\n\nexport type RootControllerAllowedActions =\n | SnapInterfaceControllerActions\n | SnapInterfaceControllerAllowedActions\n | PermissionControllerActions\n | ExecutionServiceActions\n | SubjectMetadataControllerActions;\n\nexport type RootControllerMessenger = ControllerMessenger<\n RootControllerAllowedActions,\n any\n>;\n\nexport type GetControllersOptions = {\n controllerMessenger: ControllerMessenger<any, any>;\n hooks: MiddlewareHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\nexport type Controllers = {\n permissionController: PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n >;\n subjectMetadataController: SubjectMetadataController;\n interfaceController: SnapInterfaceController;\n};\n\n/**\n * Get the controllers for the Snap.\n *\n * @param options - The options.\n * @returns The controllers for the Snap.\n */\nexport function getControllers(options: GetControllersOptions): Controllers {\n const { controllerMessenger } = options;\n const subjectMetadataController = new SubjectMetadataController({\n messenger: controllerMessenger.getRestricted({\n name: 'SubjectMetadataController',\n }),\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 ],\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 }),\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"],"names":["getControllers","registerSnap","options","controllerMessenger","subjectMetadataController","SubjectMetadataController","messenger","getRestricted","name","subjectCacheLimit","interfaceController","SnapInterfaceController","allowedActions","permissionController","getPermissionController","permissionSpecifications","getPermissionSpecifications","PermissionController","caveatSpecifications","snapsCaveatsSpecifications","snapsEndowmentCaveatSpecifications","unrestrictedMethods","UNRESTRICTED_METHODS","snapId","manifest","addSubjectMetadata","origin","subjectType","SubjectType","Snap","approvedPermissions","processSnapPermissions","getSafeJson","initialPermissions","grantPermissions","subject","preserveExistingPermissions"],"mappings":";;;;;;;;;;;IAmEgBA,cAAc;eAAdA;;IAsEMC,YAAY;eAAZA;;;sCA9Hf;kCACiC;iCAUjC;uBAGqB;yBAEgB;2BACP;AAuC9B,SAASD,eAAeE,OAA8B;IAC3D,MAAM,EAAEC,mBAAmB,EAAE,GAAGD;IAChC,MAAME,4BAA4B,IAAIC,+CAAyB,CAAC;QAC9DC,WAAWH,oBAAoBI,aAAa,CAAC;YAC3CC,MAAM;QACR;QACAC,mBAAmB;IACrB;IAEA,MAAMC,sBAAsB,IAAIC,yCAAuB,CAAC;QACtDL,WAAWH,oBAAoBI,aAAa,CAAC;YAC3CC,MAAM;YACNI,gBAAgB;gBACd;gBACA;aACD;QACH;IACF;IAEA,MAAMC,uBAAuBC,wBAAwBZ;IAErD,OAAO;QACLW;QACAT;QACAM;IACF;AACF;AAEA;;;;;;;CAOC,GACD,SAASI,wBAAwBZ,OAA8B;IAC7D,MAAM,EAAEC,mBAAmB,EAAE,GAAGD;IAChC,MAAMa,2BAA2BC,IAAAA,oCAA2B,EAACd;IAC7D,OAAO,IAAIe,0CAAoB,CAAC;QAC9BX,WAAWH,oBAAoBI,aAAa,CAAC;YAC3CC,MAAM;YACNI,gBAAgB;gBACd,CAAC,6BAA6B,CAAC;gBAC/B,CAAC,6BAA6B,CAAC;gBAC/B,CAAC,gCAAgC,CAAC;gBAClC,CAAC,gCAAgC,CAAC;gBAClC,CAAC,2BAA2B,CAAC;gBAC7B,CAAC,sBAAsB,CAAC;gBACxB,CAAC,4CAA4C,CAAC;aAC/C;QACH;QACAM,sBAAsB;YACpB,GAAGC,qCAA0B;YAC7B,GAAGC,8CAAkC;QACvC;QACAL;QACAM,qBAAqBC,+BAAoB;IAC3C;AACF;AAWO,eAAerB,aACpBsB,MAAc,EACdC,QAAsB,EACtB,EACEX,oBAAoB,EACpBT,yBAAyB,EACgB;IAE3CA,0BAA0BqB,kBAAkB,CAAC;QAC3CC,QAAQH;QACRI,aAAaC,iCAAW,CAACC,IAAI;IAC/B;IAEA,MAAMC,sBAAsBC,IAAAA,uCAAsB,EAChDC,IAAAA,kBAAW,EAACR,SAASS,kBAAkB;IAGzCpB,qBAAqBqB,gBAAgB,CAAC;QACpCJ;QACAK,SAAS;YAAET,QAAQH;QAAO;QAC1Ba,6BAA6B;IAC/B;AACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getSnapFile", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getSnapFile;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _snapssdk = require("@metamask/snaps-sdk");
|
|
12
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
13
|
+
async function getSnapFile(files, path, encoding = _snapssdk.AuxiliaryFileEncoding.Base64) {
|
|
14
|
+
const normalizedPath = (0, _snapsutils.normalizeRelative)(path);
|
|
15
|
+
const base64 = files.find((file)=>file.path === normalizedPath)?.toString('base64');
|
|
16
|
+
if (!base64) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return await (0, _snapsutils.encodeAuxiliaryFile)(base64, encoding);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/internals/simulation/files.ts"],"sourcesContent":["import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport type { VirtualFile } from '@metamask/snaps-utils';\nimport { encodeAuxiliaryFile, normalizeRelative } from '@metamask/snaps-utils';\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"],"names":["getSnapFile","files","path","encoding","AuxiliaryFileEncoding","Base64","normalizedPath","normalizeRelative","base64","find","file","toString","encodeAuxiliaryFile"],"mappings":";;;;+BAYsBA;;;eAAAA;;;0BAZgB;4BAEiB;AAUhD,eAAeA,YACpBC,KAAoB,EACpBC,IAAY,EACZC,WAAkCC,+BAAqB,CAACC,MAAM;IAE9D,MAAMC,iBAAiBC,IAAAA,6BAAiB,EAACL;IACzC,MAAMM,SAASP,MACZQ,IAAI,CAAC,CAACC,OAASA,KAAKR,IAAI,KAAKI,iBAC5BK,SAAS;IAEb,IAAI,CAACH,QAAQ;QACX,OAAO;IACT;IAEA,OAAO,MAAMI,IAAAA,+BAAmB,EAACJ,QAAQL;AAC3C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./constants"), exports);
|
|
6
|
+
_export_star(require("./interface"), exports);
|
|
7
|
+
_export_star(require("./simulation"), exports);
|
|
8
|
+
_export_star(require("./options"), exports);
|
|
9
|
+
_export_star(require("./store"), exports);
|
|
10
|
+
function _export_star(from, to) {
|
|
11
|
+
Object.keys(from).forEach(function(k) {
|
|
12
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
13
|
+
Object.defineProperty(to, k, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function() {
|
|
16
|
+
return from[k];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return from;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/internals/simulation/index.ts"],"sourcesContent":["export * from './constants';\nexport * from './interface';\nexport * from './simulation';\nexport * from './options';\nexport * from './store';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getInterfaceResponse: function() {
|
|
13
|
+
return getInterfaceResponse;
|
|
14
|
+
},
|
|
15
|
+
getInterface: function() {
|
|
16
|
+
return getInterface;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _snapssdk = require("@metamask/snaps-sdk");
|
|
20
|
+
const _effects = require("redux-saga/effects");
|
|
21
|
+
const _store = require("./store");
|
|
22
|
+
function getInterfaceResponse(runSaga, type, content) {
|
|
23
|
+
switch(type){
|
|
24
|
+
case _snapssdk.DialogType.Alert:
|
|
25
|
+
return {
|
|
26
|
+
type,
|
|
27
|
+
content,
|
|
28
|
+
ok: resolveWith(runSaga, null)
|
|
29
|
+
};
|
|
30
|
+
case _snapssdk.DialogType.Confirmation:
|
|
31
|
+
return {
|
|
32
|
+
type,
|
|
33
|
+
content,
|
|
34
|
+
ok: resolveWith(runSaga, true),
|
|
35
|
+
cancel: resolveWith(runSaga, false)
|
|
36
|
+
};
|
|
37
|
+
case _snapssdk.DialogType.Prompt:
|
|
38
|
+
return {
|
|
39
|
+
type,
|
|
40
|
+
content,
|
|
41
|
+
ok: resolveWithInput(runSaga),
|
|
42
|
+
cancel: resolveWith(runSaga, null)
|
|
43
|
+
};
|
|
44
|
+
default:
|
|
45
|
+
throw new Error(`Unknown or unsupported dialog type: "${String(type)}".`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the current user interface with the given value. This returns a
|
|
50
|
+
* function that can be used to resolve the user interface.
|
|
51
|
+
*
|
|
52
|
+
* @param runSaga - A function to run a saga outside the usual Redux flow.
|
|
53
|
+
* @param value - The value to resolve the user interface with.
|
|
54
|
+
* @returns A function that can be used to resolve the user interface.
|
|
55
|
+
*/ function resolveWith(runSaga, value) {
|
|
56
|
+
/**
|
|
57
|
+
* Resolve the current user interface with the given value.
|
|
58
|
+
*
|
|
59
|
+
* @yields Puts the resolve user interface action.
|
|
60
|
+
*/ function* resolveWithSaga() {
|
|
61
|
+
yield (0, _effects.put)((0, _store.resolveInterface)(value));
|
|
62
|
+
}
|
|
63
|
+
return async ()=>{
|
|
64
|
+
await runSaga(resolveWithSaga).toPromise();
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Resolve the current user interface with the provided input. This returns a
|
|
69
|
+
* function that can be used to resolve the user interface.
|
|
70
|
+
*
|
|
71
|
+
* @param runSaga - A function to run a saga outside the usual Redux flow.
|
|
72
|
+
* @returns A function that can be used to resolve the user interface.
|
|
73
|
+
*/ function resolveWithInput(runSaga) {
|
|
74
|
+
/**
|
|
75
|
+
* Resolve the current user interface with the given value.
|
|
76
|
+
*
|
|
77
|
+
* @param value - The value to resolve the user interface with.
|
|
78
|
+
* @yields Puts the resolve user interface action.
|
|
79
|
+
*/ function* resolveWithSaga(value) {
|
|
80
|
+
yield (0, _effects.put)((0, _store.resolveInterface)(value));
|
|
81
|
+
}
|
|
82
|
+
return async (value = '')=>{
|
|
83
|
+
await runSaga(resolveWithSaga, value).toPromise();
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function* getInterface(runSaga, snapId, controllerMessenger) {
|
|
87
|
+
const currentInterface = yield (0, _effects.select)(_store.getCurrentInterface);
|
|
88
|
+
if (currentInterface) {
|
|
89
|
+
const { content } = controllerMessenger.call('SnapInterfaceController:getInterface', snapId, currentInterface.id);
|
|
90
|
+
return getInterfaceResponse(runSaga, currentInterface.type, content);
|
|
91
|
+
}
|
|
92
|
+
const { payload } = yield (0, _effects.take)(_store.setInterface.type);
|
|
93
|
+
const { type, id } = payload;
|
|
94
|
+
const { content } = controllerMessenger.call('SnapInterfaceController:getInterface', snapId, id);
|
|
95
|
+
return getInterfaceResponse(runSaga, type, content);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/internals/simulation/interface.ts"],"sourcesContent":["import type { Component, SnapId } from '@metamask/snaps-sdk';\nimport { DialogType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport type { SagaIterator } from 'redux-saga';\nimport { put, select, take } from 'redux-saga/effects';\n\nimport type { SnapInterface } from '../../types';\nimport type { RootControllerMessenger } from './controllers';\nimport type { Interface, RunSagaFunction } from './store';\nimport { getCurrentInterface, resolveInterface, setInterface } from './store';\n\n/**\n * Get a user interface object from a type and content object.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param type - The type of the interface.\n * @param content - The content to show in the interface.\n * @returns The user interface object.\n */\nexport function getInterfaceResponse(\n runSaga: RunSagaFunction,\n type: DialogType,\n content: Component,\n): SnapInterface {\n switch (type) {\n case DialogType.Alert:\n return {\n type,\n content,\n ok: resolveWith(runSaga, null),\n };\n\n case DialogType.Confirmation:\n return {\n type,\n content,\n\n ok: resolveWith(runSaga, true),\n cancel: resolveWith(runSaga, false),\n };\n\n case DialogType.Prompt:\n return {\n type,\n content,\n\n ok: resolveWithInput(runSaga),\n cancel: resolveWith(runSaga, null),\n };\n\n default:\n throw new Error(`Unknown or unsupported dialog type: \"${String(type)}\".`);\n }\n}\n\n/**\n * Resolve the current user interface with the given value. This returns a\n * function that can be used to resolve the user interface.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param value - The value to resolve the user interface with.\n * @returns A function that can be used to resolve the user interface.\n */\nfunction resolveWith(runSaga: RunSagaFunction, value: unknown) {\n /**\n * Resolve the current user interface with the given value.\n *\n * @yields Puts the resolve user interface action.\n */\n function* resolveWithSaga(): SagaIterator {\n yield put(resolveInterface(value));\n }\n\n return async () => {\n await runSaga(resolveWithSaga).toPromise();\n };\n}\n\n/**\n * Resolve the current user interface with the provided input. This returns a\n * function that can be used to resolve the user interface.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A function that can be used to resolve the user interface.\n */\nfunction resolveWithInput(runSaga: RunSagaFunction) {\n /**\n * Resolve the current user interface with the given value.\n *\n * @param value - The value to resolve the user interface with.\n * @yields Puts the resolve user interface action.\n */\n function* resolveWithSaga(value: string): SagaIterator {\n yield put(resolveInterface(value));\n }\n\n return async (value = '') => {\n await runSaga(resolveWithSaga, value).toPromise();\n };\n}\n\n/**\n * Get a user interface object from a Snap.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger used to call actions.\n * @yields Takes the set interface action.\n * @returns The user interface object.\n */\nexport function* getInterface(\n runSaga: RunSagaFunction,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): SagaIterator<SnapInterface> {\n const currentInterface: Interface | null = yield select(getCurrentInterface);\n if (currentInterface) {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n currentInterface.id,\n );\n return getInterfaceResponse(runSaga, currentInterface.type, content);\n }\n\n const { payload }: PayloadAction<Interface> = yield take(setInterface.type);\n const { type, id } = payload;\n\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n return getInterfaceResponse(runSaga, type, content);\n}\n"],"names":["getInterfaceResponse","getInterface","runSaga","type","content","DialogType","Alert","ok","resolveWith","Confirmation","cancel","Prompt","resolveWithInput","Error","String","value","resolveWithSaga","put","resolveInterface","toPromise","snapId","controllerMessenger","currentInterface","select","getCurrentInterface","call","id","payload","take","setInterface"],"mappings":";;;;;;;;;;;IAmBgBA,oBAAoB;eAApBA;;IA2FCC,YAAY;eAAZA;;;0BA7GU;yBAGO;uBAKkC;AAU7D,SAASD,qBACdE,OAAwB,EACxBC,IAAgB,EAChBC,OAAkB;IAElB,OAAQD;QACN,KAAKE,oBAAU,CAACC,KAAK;YACnB,OAAO;gBACLH;gBACAC;gBACAG,IAAIC,YAAYN,SAAS;YAC3B;QAEF,KAAKG,oBAAU,CAACI,YAAY;YAC1B,OAAO;gBACLN;gBACAC;gBAEAG,IAAIC,YAAYN,SAAS;gBACzBQ,QAAQF,YAAYN,SAAS;YAC/B;QAEF,KAAKG,oBAAU,CAACM,MAAM;YACpB,OAAO;gBACLR;gBACAC;gBAEAG,IAAIK,iBAAiBV;gBACrBQ,QAAQF,YAAYN,SAAS;YAC/B;QAEF;YACE,MAAM,IAAIW,MAAM,CAAC,qCAAqC,EAAEC,OAAOX,MAAM,EAAE,CAAC;IAC5E;AACF;AAEA;;;;;;;CAOC,GACD,SAASK,YAAYN,OAAwB,EAAEa,KAAc;IAC3D;;;;GAIC,GACD,UAAUC;QACR,MAAMC,IAAAA,YAAG,EAACC,IAAAA,uBAAgB,EAACH;IAC7B;IAEA,OAAO;QACL,MAAMb,QAAQc,iBAAiBG,SAAS;IAC1C;AACF;AAEA;;;;;;CAMC,GACD,SAASP,iBAAiBV,OAAwB;IAChD;;;;;GAKC,GACD,UAAUc,gBAAgBD,KAAa;QACrC,MAAME,IAAAA,YAAG,EAACC,IAAAA,uBAAgB,EAACH;IAC7B;IAEA,OAAO,OAAOA,QAAQ,EAAE;QACtB,MAAMb,QAAQc,iBAAiBD,OAAOI,SAAS;IACjD;AACF;AAWO,UAAUlB,aACfC,OAAwB,EACxBkB,MAAc,EACdC,mBAA4C;IAE5C,MAAMC,mBAAqC,MAAMC,IAAAA,eAAM,EAACC,0BAAmB;IAC3E,IAAIF,kBAAkB;QACpB,MAAM,EAAElB,OAAO,EAAE,GAAGiB,oBAAoBI,IAAI,CAC1C,wCACAL,QACAE,iBAAiBI,EAAE;QAErB,OAAO1B,qBAAqBE,SAASoB,iBAAiBnB,IAAI,EAAEC;IAC9D;IAEA,MAAM,EAAEuB,OAAO,EAAE,GAA6B,MAAMC,IAAAA,aAAI,EAACC,mBAAY,CAAC1B,IAAI;IAC1E,MAAM,EAAEA,IAAI,EAAEuB,EAAE,EAAE,GAAGC;IAErB,MAAM,EAAEvB,OAAO,EAAE,GAAGiB,oBAAoBI,IAAI,CAC1C,wCACAL,QACAM;IAGF,OAAO1B,qBAAqBE,SAASC,MAAMC;AAC7C"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
EXCLUDED_SNAP_ENDOWMENTS: function() {
|
|
13
|
+
return EXCLUDED_SNAP_ENDOWMENTS;
|
|
14
|
+
},
|
|
15
|
+
EXCLUDED_SNAP_PERMISSIONS: function() {
|
|
16
|
+
return EXCLUDED_SNAP_PERMISSIONS;
|
|
17
|
+
},
|
|
18
|
+
UNRESTRICTED_METHODS: function() {
|
|
19
|
+
return UNRESTRICTED_METHODS;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const EXCLUDED_SNAP_ENDOWMENTS = [];
|
|
23
|
+
const EXCLUDED_SNAP_PERMISSIONS = [];
|
|
24
|
+
const UNRESTRICTED_METHODS = Object.freeze([
|
|
25
|
+
'eth_blockNumber',
|
|
26
|
+
'eth_call',
|
|
27
|
+
'eth_chainId',
|
|
28
|
+
'eth_coinbase',
|
|
29
|
+
'eth_decrypt',
|
|
30
|
+
'eth_estimateGas',
|
|
31
|
+
'eth_feeHistory',
|
|
32
|
+
'eth_gasPrice',
|
|
33
|
+
'eth_getBalance',
|
|
34
|
+
'eth_getBlockByHash',
|
|
35
|
+
'eth_getBlockByNumber',
|
|
36
|
+
'eth_getBlockTransactionCountByHash',
|
|
37
|
+
'eth_getBlockTransactionCountByNumber',
|
|
38
|
+
'eth_getCode',
|
|
39
|
+
'eth_getEncryptionPublicKey',
|
|
40
|
+
'eth_getFilterChanges',
|
|
41
|
+
'eth_getFilterLogs',
|
|
42
|
+
'eth_getLogs',
|
|
43
|
+
'eth_getProof',
|
|
44
|
+
'eth_getStorageAt',
|
|
45
|
+
'eth_getTransactionByBlockHashAndIndex',
|
|
46
|
+
'eth_getTransactionByBlockNumberAndIndex',
|
|
47
|
+
'eth_getTransactionByHash',
|
|
48
|
+
'eth_getTransactionCount',
|
|
49
|
+
'eth_getTransactionReceipt',
|
|
50
|
+
'eth_getUncleByBlockHashAndIndex',
|
|
51
|
+
'eth_getUncleByBlockNumberAndIndex',
|
|
52
|
+
'eth_getUncleCountByBlockHash',
|
|
53
|
+
'eth_getUncleCountByBlockNumber',
|
|
54
|
+
'eth_getWork',
|
|
55
|
+
'eth_hashrate',
|
|
56
|
+
'eth_mining',
|
|
57
|
+
'eth_newBlockFilter',
|
|
58
|
+
'eth_newFilter',
|
|
59
|
+
'eth_newPendingTransactionFilter',
|
|
60
|
+
'eth_protocolVersion',
|
|
61
|
+
'eth_sendRawTransaction',
|
|
62
|
+
'eth_sendTransaction',
|
|
63
|
+
'eth_sign',
|
|
64
|
+
'eth_signTypedData',
|
|
65
|
+
'eth_signTypedData_v1',
|
|
66
|
+
'eth_signTypedData_v3',
|
|
67
|
+
'eth_signTypedData_v4',
|
|
68
|
+
'eth_submitHashrate',
|
|
69
|
+
'eth_submitWork',
|
|
70
|
+
'eth_syncing',
|
|
71
|
+
'eth_uninstallFilter',
|
|
72
|
+
'metamask_getProviderState',
|
|
73
|
+
'metamask_watchAsset',
|
|
74
|
+
'net_listening',
|
|
75
|
+
'net_peerCount',
|
|
76
|
+
'net_version',
|
|
77
|
+
'personal_ecRecover',
|
|
78
|
+
'personal_sign',
|
|
79
|
+
'wallet_watchAsset',
|
|
80
|
+
'web3_clientVersion',
|
|
81
|
+
'web3_sha3'
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/internals/simulation/methods/constants.ts"],"sourcesContent":["export const EXCLUDED_SNAP_ENDOWMENTS = [];\n\nexport const EXCLUDED_SNAP_PERMISSIONS = [];\n\n/**\n * All unrestricted methods recognized by the `PermissionController`.\n * Unrestricted methods are ignored by the permission system, but every\n * JSON-RPC request seen by the permission system must correspond to a\n * restricted or unrestricted method, or the request will be rejected with a\n * \"method not found\" error.\n */\nexport const UNRESTRICTED_METHODS = Object.freeze([\n 'eth_blockNumber',\n 'eth_call',\n 'eth_chainId',\n 'eth_coinbase',\n 'eth_decrypt',\n 'eth_estimateGas',\n 'eth_feeHistory',\n 'eth_gasPrice',\n 'eth_getBalance',\n 'eth_getBlockByHash',\n 'eth_getBlockByNumber',\n 'eth_getBlockTransactionCountByHash',\n 'eth_getBlockTransactionCountByNumber',\n 'eth_getCode',\n 'eth_getEncryptionPublicKey',\n 'eth_getFilterChanges',\n 'eth_getFilterLogs',\n 'eth_getLogs',\n 'eth_getProof',\n 'eth_getStorageAt',\n 'eth_getTransactionByBlockHashAndIndex',\n 'eth_getTransactionByBlockNumberAndIndex',\n 'eth_getTransactionByHash',\n 'eth_getTransactionCount',\n 'eth_getTransactionReceipt',\n 'eth_getUncleByBlockHashAndIndex',\n 'eth_getUncleByBlockNumberAndIndex',\n 'eth_getUncleCountByBlockHash',\n 'eth_getUncleCountByBlockNumber',\n 'eth_getWork',\n 'eth_hashrate',\n 'eth_mining',\n 'eth_newBlockFilter',\n 'eth_newFilter',\n 'eth_newPendingTransactionFilter',\n 'eth_protocolVersion',\n 'eth_sendRawTransaction',\n 'eth_sendTransaction',\n 'eth_sign',\n 'eth_signTypedData',\n 'eth_signTypedData_v1',\n 'eth_signTypedData_v3',\n 'eth_signTypedData_v4',\n 'eth_submitHashrate',\n 'eth_submitWork',\n 'eth_syncing',\n 'eth_uninstallFilter',\n 'metamask_getProviderState',\n 'metamask_watchAsset',\n 'net_listening',\n 'net_peerCount',\n 'net_version',\n 'personal_ecRecover',\n 'personal_sign',\n 'wallet_watchAsset',\n 'web3_clientVersion',\n 'web3_sha3',\n]);\n"],"names":["EXCLUDED_SNAP_ENDOWMENTS","EXCLUDED_SNAP_PERMISSIONS","UNRESTRICTED_METHODS","Object","freeze"],"mappings":";;;;;;;;;;;IAAaA,wBAAwB;eAAxBA;;IAEAC,yBAAyB;eAAzBA;;IASAC,oBAAoB;eAApBA;;;AAXN,MAAMF,2BAA2B,EAAE;AAEnC,MAAMC,4BAA4B,EAAE;AASpC,MAAMC,uBAAuBC,OAAOC,MAAM,CAAC;IAChD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
encryptImplementation: function() {
|
|
13
|
+
return encryptImplementation;
|
|
14
|
+
},
|
|
15
|
+
decryptImplementation: function() {
|
|
16
|
+
return decryptImplementation;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function encryptImplementation(password, value) {
|
|
20
|
+
return JSON.stringify({
|
|
21
|
+
password,
|
|
22
|
+
value
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function decryptImplementation(password, value) {
|
|
26
|
+
const decryptedValue = JSON.parse(value);
|
|
27
|
+
if (decryptedValue.password !== password) {
|
|
28
|
+
throw new Error('Incorrect password. This is a bug in `@metamask/snaps-jest`, please report it.');
|
|
29
|
+
}
|
|
30
|
+
return decryptedValue.value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=encryption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/encryption.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\n\n/**\n * Mocks encrypting a value using a password. This is not a real encryption\n * method, but rather is used to simulate encryption in the tests.\n *\n * Ideally we would use a real encryption method, such as\n * `@metamask/browser-passworder`, but it doesn't seem to work with Node.js 18\n * without some mocking. We can switch to a real encryption method once we\n * drop support for Node.js 18.\n *\n * @param password - The password to use.\n * @param value - The value to encrypt.\n * @returns The \"encrypted\" value.\n */\nexport function encryptImplementation(password: string, value: Json) {\n return JSON.stringify({\n password,\n value,\n });\n}\n\n/**\n * Mocks decrypting a value using a password. This is not a real encryption\n * method, but rather is used to simulate encryption in the tests.\n *\n * Ideally we would use a real decryption method, such as\n * `@metamask/browser-passworder`, but it doesn't seem to work with Node.js 18\n * without some mocking. We can switch to a real encryption method once we\n * drop support for Node.js 18.\n *\n * @param password - The password to use.\n * @param value - The value to decrypt.\n * @returns The \"decrypted\" value.\n */\nexport function decryptImplementation(password: string, value: string) {\n const decryptedValue = JSON.parse(value);\n if (decryptedValue.password !== password) {\n throw new Error(\n 'Incorrect password. This is a bug in `@metamask/snaps-jest`, please report it.',\n );\n }\n\n return decryptedValue.value;\n}\n"],"names":["encryptImplementation","decryptImplementation","password","value","JSON","stringify","decryptedValue","parse","Error"],"mappings":";;;;;;;;;;;IAegBA,qBAAqB;eAArBA;;IAoBAC,qBAAqB;eAArBA;;;AApBT,SAASD,sBAAsBE,QAAgB,EAAEC,KAAW;IACjE,OAAOC,KAAKC,SAAS,CAAC;QACpBH;QACAC;IACF;AACF;AAeO,SAASF,sBAAsBC,QAAgB,EAAEC,KAAa;IACnE,MAAMG,iBAAiBF,KAAKG,KAAK,CAACJ;IAClC,IAAIG,eAAeJ,QAAQ,KAAKA,UAAU;QACxC,MAAM,IAAIM,MACR;IAEJ;IAEA,OAAOF,eAAeH,KAAK;AAC7B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getGetLocaleMethodImplementation", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getGetLocaleMethodImplementation;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function getGetLocaleMethodImplementation({ locale }) {
|
|
12
|
+
return async ()=>{
|
|
13
|
+
return locale;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=get-locale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/get-locale.ts"],"sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getLocale` hook.\n *\n * @param options - The simulation options.\n * @param options.locale - The locale to use.\n * @returns The implementation of the `getLocale` hook.\n */\nexport function getGetLocaleMethodImplementation({\n locale,\n}: SimulationOptions) {\n return async () => {\n return locale;\n };\n}\n"],"names":["getGetLocaleMethodImplementation","locale"],"mappings":";;;;+BASgBA;;;eAAAA;;;AAAT,SAASA,iCAAiC,EAC/CC,MAAM,EACY;IAClB,OAAO;QACL,OAAOA;IACT;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./encryption"), exports);
|
|
6
|
+
_export_star(require("./get-locale"), exports);
|
|
7
|
+
_export_star(require("./notifications"), exports);
|
|
8
|
+
_export_star(require("./show-dialog"), exports);
|
|
9
|
+
_export_star(require("./state"), exports);
|
|
10
|
+
_export_star(require("./interface"), exports);
|
|
11
|
+
function _export_star(from, to) {
|
|
12
|
+
Object.keys(from).forEach(function(k) {
|
|
13
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
14
|
+
Object.defineProperty(to, k, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function() {
|
|
17
|
+
return from[k];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return from;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/index.ts"],"sourcesContent":["export * from './encryption';\nexport * from './get-locale';\nexport * from './notifications';\nexport * from './show-dialog';\nexport * from './state';\nexport * from './interface';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getCreateInterfaceImplementation: function() {
|
|
13
|
+
return getCreateInterfaceImplementation;
|
|
14
|
+
},
|
|
15
|
+
getGetInterfaceImplementation: function() {
|
|
16
|
+
return getGetInterfaceImplementation;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function getCreateInterfaceImplementation(controllerMessenger) {
|
|
20
|
+
return async (snapId, content)=>controllerMessenger.call('SnapInterfaceController:createInterface', snapId, content);
|
|
21
|
+
}
|
|
22
|
+
function getGetInterfaceImplementation(controllerMessenger) {
|
|
23
|
+
return (snapId, id)=>controllerMessenger.call('SnapInterfaceController:getInterface', snapId, id);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/interface.ts"],"sourcesContent":["import type { Component, SnapId } from '@metamask/snaps-sdk';\n\nimport type { RootControllerMessenger } from '../../controllers';\n\n/**\n * Get the implementation of the `createInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `createInterface` hook.\n */\nexport function getCreateInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return async (snapId: SnapId, content: Component) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n content,\n );\n}\n\n/**\n * Get the implementation of the `getInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `getInterface` hook.\n */\nexport function getGetInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return (snapId: SnapId, id: string) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n}\n"],"names":["getCreateInterfaceImplementation","getGetInterfaceImplementation","controllerMessenger","snapId","content","call","id"],"mappings":";;;;;;;;;;;IAUgBA,gCAAgC;eAAhCA;;IAiBAC,6BAA6B;eAA7BA;;;AAjBT,SAASD,iCACdE,mBAA4C;IAE5C,OAAO,OAAOC,QAAgBC,UAC5BF,oBAAoBG,IAAI,CACtB,2CACAF,QACAC;AAEN;AAQO,SAASH,8BACdC,mBAA4C;IAE5C,OAAO,CAACC,QAAgBG,KACtBJ,oBAAoBG,IAAI,CACtB,wCACAF,QACAG;AAEN"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getShowNativeNotificationImplementation: function() {
|
|
13
|
+
return getShowNativeNotificationImplementation;
|
|
14
|
+
},
|
|
15
|
+
getShowInAppNotificationImplementation: function() {
|
|
16
|
+
return getShowInAppNotificationImplementation;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _snapssdk = require("@metamask/snaps-sdk");
|
|
20
|
+
const _toolkit = require("@reduxjs/toolkit");
|
|
21
|
+
const _effects = require("redux-saga/effects");
|
|
22
|
+
const _store = require("../../store");
|
|
23
|
+
/**
|
|
24
|
+
* Show a native notification to the user.
|
|
25
|
+
*
|
|
26
|
+
* @param _snapId - The ID of the Snap that created the notification.
|
|
27
|
+
* @param options - The notification options.
|
|
28
|
+
* @param options.message - The message to show in the notification.
|
|
29
|
+
* @yields Adds the notification to the store.
|
|
30
|
+
* @returns `null`.
|
|
31
|
+
*/ function* showNativeNotificationImplementation(_snapId, { message }) {
|
|
32
|
+
yield (0, _effects.put)((0, _store.addNotification)({
|
|
33
|
+
id: (0, _toolkit.nanoid)(),
|
|
34
|
+
type: _snapssdk.NotificationType.Native,
|
|
35
|
+
message
|
|
36
|
+
}));
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
function getShowNativeNotificationImplementation(runSaga) {
|
|
40
|
+
return async (...args)=>{
|
|
41
|
+
return await runSaga(showNativeNotificationImplementation, ...args).toPromise();
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Show an in-app notification to the user.
|
|
46
|
+
*
|
|
47
|
+
* @param _snapId - The ID of the Snap that created the notification.
|
|
48
|
+
* @param options - The notification options.
|
|
49
|
+
* @param options.message - The message to show in the notification.
|
|
50
|
+
* @yields Adds the notification to the store.
|
|
51
|
+
* @returns `null`.
|
|
52
|
+
*/ function* showInAppNotificationImplementation(_snapId, { message }) {
|
|
53
|
+
yield (0, _effects.put)((0, _store.addNotification)({
|
|
54
|
+
id: (0, _toolkit.nanoid)(),
|
|
55
|
+
type: _snapssdk.NotificationType.InApp,
|
|
56
|
+
message
|
|
57
|
+
}));
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
function getShowInAppNotificationImplementation(runSaga) {
|
|
61
|
+
return async (...args)=>{
|
|
62
|
+
return await runSaga(showInAppNotificationImplementation, ...args).toPromise();
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=notifications.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/notifications.ts"],"sourcesContent":["import type { NotifyParams } from '@metamask/snaps-sdk';\nimport { NotificationType } from '@metamask/snaps-sdk';\nimport { nanoid } from '@reduxjs/toolkit';\nimport type { SagaIterator } from 'redux-saga';\nimport { put } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { addNotification } from '../../store';\n\n/**\n * Show a native notification to the user.\n *\n * @param _snapId - The ID of the Snap that created the notification.\n * @param options - The notification options.\n * @param options.message - The message to show in the notification.\n * @yields Adds the notification to the store.\n * @returns `null`.\n */\nfunction* showNativeNotificationImplementation(\n _snapId: string,\n { message }: NotifyParams,\n): SagaIterator {\n yield put(\n addNotification({ id: nanoid(), type: NotificationType.Native, message }),\n );\n\n return null;\n}\n\n/**\n * Get a method that can be used to show a native notification.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A method that can be used to show a native notification.\n */\nexport function getShowNativeNotificationImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (\n ...args: Parameters<typeof showNativeNotificationImplementation>\n ) => {\n return await runSaga(\n showNativeNotificationImplementation,\n ...args,\n ).toPromise();\n };\n}\n\n/**\n * Show an in-app notification to the user.\n *\n * @param _snapId - The ID of the Snap that created the notification.\n * @param options - The notification options.\n * @param options.message - The message to show in the notification.\n * @yields Adds the notification to the store.\n * @returns `null`.\n */\nfunction* showInAppNotificationImplementation(\n _snapId: string,\n { message }: NotifyParams,\n): SagaIterator<null> {\n yield put(\n addNotification({ id: nanoid(), type: NotificationType.InApp, message }),\n );\n\n return null;\n}\n\n/**\n * Get a method that can be used to show an in-app notification.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A method that can be used to show an in-app notification.\n */\nexport function getShowInAppNotificationImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (\n ...args: Parameters<typeof showInAppNotificationImplementation>\n ) => {\n return await runSaga(\n showInAppNotificationImplementation,\n ...args,\n ).toPromise();\n };\n}\n"],"names":["getShowNativeNotificationImplementation","getShowInAppNotificationImplementation","showNativeNotificationImplementation","_snapId","message","put","addNotification","id","nanoid","type","NotificationType","Native","runSaga","args","toPromise","showInAppNotificationImplementation","InApp"],"mappings":";;;;;;;;;;;IAmCgBA,uCAAuC;eAAvCA;;IAuCAC,sCAAsC;eAAtCA;;;0BAzEiB;yBACV;yBAEH;uBAGY;AAEhC;;;;;;;;CAQC,GACD,UAAUC,qCACRC,OAAe,EACf,EAAEC,OAAO,EAAgB;IAEzB,MAAMC,IAAAA,YAAG,EACPC,IAAAA,sBAAe,EAAC;QAAEC,IAAIC,IAAAA,eAAM;QAAIC,MAAMC,0BAAgB,CAACC,MAAM;QAAEP;IAAQ;IAGzE,OAAO;AACT;AAQO,SAASJ,wCACdY,OAAwB;IAExB,OAAO,OACL,GAAGC;QAEH,OAAO,MAAMD,QACXV,yCACGW,MACHC,SAAS;IACb;AACF;AAEA;;;;;;;;CAQC,GACD,UAAUC,oCACRZ,OAAe,EACf,EAAEC,OAAO,EAAgB;IAEzB,MAAMC,IAAAA,YAAG,EACPC,IAAAA,sBAAe,EAAC;QAAEC,IAAIC,IAAAA,eAAM;QAAIC,MAAMC,0BAAgB,CAACM,KAAK;QAAEZ;IAAQ;IAGxE,OAAO;AACT;AAQO,SAASH,uCACdW,OAAwB;IAExB,OAAO,OACL,GAAGC;QAEH,OAAO,MAAMD,QACXG,wCACGF,MACHC,SAAS;IACb;AACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getShowDialogImplementation", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getShowDialogImplementation;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _effects = require("redux-saga/effects");
|
|
12
|
+
const _store = require("../../store");
|
|
13
|
+
/**
|
|
14
|
+
* Show a dialog to the user. This will wait for `resolveUserInterface` to be
|
|
15
|
+
* dispatched before returning.
|
|
16
|
+
*
|
|
17
|
+
* @param _snapId - The ID of the Snap that created the dialog. This is ignored
|
|
18
|
+
* because the simulator only supports one Snap.
|
|
19
|
+
* @param type - The type of dialog to show.
|
|
20
|
+
* @param id - The interface ID.
|
|
21
|
+
* @param _placeholder - The placeholder text to show in the dialog. This is
|
|
22
|
+
* not implemented yet.
|
|
23
|
+
* @yields Sets the dialog in the store, waits for the user to resolve the
|
|
24
|
+
* dialog, and closes the dialog.
|
|
25
|
+
* @returns The result of the dialog.
|
|
26
|
+
*/ function* showDialogImplementation(_snapId, type, id, _placeholder) {
|
|
27
|
+
yield (0, _effects.put)((0, _store.setInterface)({
|
|
28
|
+
type,
|
|
29
|
+
id
|
|
30
|
+
}));
|
|
31
|
+
// We use `take` to wait for `resolveUserInterface` to be dispatched, which
|
|
32
|
+
// indicates that the user has resolved the dialog.
|
|
33
|
+
const { payload } = yield (0, _effects.take)(_store.resolveInterface.type);
|
|
34
|
+
yield (0, _effects.put)((0, _store.closeInterface)());
|
|
35
|
+
return payload;
|
|
36
|
+
}
|
|
37
|
+
function getShowDialogImplementation(runSaga) {
|
|
38
|
+
return async (...args)=>{
|
|
39
|
+
return await runSaga(showDialogImplementation, ...args).toPromise();
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=show-dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/show-dialog.ts"],"sourcesContent":["import type { DialogType } from '@metamask/snaps-sdk';\nimport 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\n/**\n * Show a dialog to the user. This will wait for `resolveUserInterface` to be\n * dispatched before returning.\n *\n * @param _snapId - The ID of the Snap that created the dialog. This is ignored\n * because the simulator only supports one Snap.\n * @param type - The type of dialog to show.\n * @param id - The interface ID.\n * @param _placeholder - The placeholder text to show in the dialog. This is\n * not implemented yet.\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* showDialogImplementation(\n _snapId: string,\n type: DialogType,\n id: string,\n _placeholder?: string,\n): 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 `showDialog` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `showDialog` hook.\n */\nexport function getShowDialogImplementation(runSaga: RunSagaFunction) {\n return async (...args: Parameters<typeof showDialogImplementation>) => {\n return await runSaga(showDialogImplementation, ...args).toPromise();\n };\n}\n"],"names":["getShowDialogImplementation","showDialogImplementation","_snapId","type","id","_placeholder","put","setInterface","payload","take","resolveInterface","closeInterface","runSaga","args","toPromise"],"mappings":";;;;+BA2CgBA;;;eAAAA;;;yBAzCU;uBAGqC;AAE/D;;;;;;;;;;;;;CAaC,GACD,UAAUC,yBACRC,OAAe,EACfC,IAAgB,EAChBC,EAAU,EACVC,YAAqB;IAErB,MAAMC,IAAAA,YAAG,EAACC,IAAAA,mBAAY,EAAC;QAAEJ;QAAMC;IAAG;IAElC,2EAA2E;IAC3E,mDAAmD;IACnD,MAAM,EAAEI,OAAO,EAAE,GAAG,MAAMC,IAAAA,aAAI,EAACC,uBAAgB,CAACP,IAAI;IACpD,MAAMG,IAAAA,YAAG,EAACK,IAAAA,qBAAc;IAExB,OAAOH;AACT;AAQO,SAASR,4BAA4BY,OAAwB;IAClE,OAAO,OAAO,GAAGC;QACf,OAAO,MAAMD,QAAQX,6BAA6BY,MAAMC,SAAS;IACnE;AACF"}
|