@metamask/snaps-jest 4.0.1 → 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 +16 -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 +43 -0
- 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 +38 -1
- 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 -74
- 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 +153 -0
- 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,80 @@
|
|
|
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
|
+
getGetSnapStateMethodImplementation: function() {
|
|
13
|
+
return getGetSnapStateMethodImplementation;
|
|
14
|
+
},
|
|
15
|
+
getUpdateSnapStateMethodImplementation: function() {
|
|
16
|
+
return getUpdateSnapStateMethodImplementation;
|
|
17
|
+
},
|
|
18
|
+
getClearSnapStateMethodImplementation: function() {
|
|
19
|
+
return getClearSnapStateMethodImplementation;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _effects = require("redux-saga/effects");
|
|
23
|
+
const _store = require("../../store");
|
|
24
|
+
/**
|
|
25
|
+
* Get the Snap state from the store.
|
|
26
|
+
*
|
|
27
|
+
* @param _snapId - The ID of the Snap to get the state for. This is ignored
|
|
28
|
+
* because the simulator only supports one Snap.
|
|
29
|
+
* @param encrypted - Whether to get the encrypted or unencrypted state.
|
|
30
|
+
* Defaults to encrypted state.
|
|
31
|
+
* @returns The state of the Snap.
|
|
32
|
+
* @yields Selects the state from the store.
|
|
33
|
+
*/ function* getSnapStateImplementation(_snapId, encrypted = true) {
|
|
34
|
+
return yield (0, _effects.select)((0, _store.getState)(encrypted));
|
|
35
|
+
}
|
|
36
|
+
function getGetSnapStateMethodImplementation(runSaga) {
|
|
37
|
+
return (...args)=>{
|
|
38
|
+
return runSaga(getSnapStateImplementation, ...args).result();
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Update the Snap state in the store.
|
|
43
|
+
*
|
|
44
|
+
* @param _snapId - The ID of the Snap to update the state for. This is ignored
|
|
45
|
+
* because the simulator only supports one Snap.
|
|
46
|
+
* @param newState - The new state.
|
|
47
|
+
* @param encrypted - Whether to update the encrypted or unencrypted state.
|
|
48
|
+
* Defaults to encrypted state.
|
|
49
|
+
* @yields Puts the new state in the store.
|
|
50
|
+
*/ function* updateSnapStateImplementation(_snapId, newState, encrypted = true) {
|
|
51
|
+
yield (0, _effects.put)((0, _store.setState)({
|
|
52
|
+
state: newState,
|
|
53
|
+
encrypted
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
function getUpdateSnapStateMethodImplementation(runSaga) {
|
|
57
|
+
return (...args)=>{
|
|
58
|
+
runSaga(updateSnapStateImplementation, ...args).result();
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Clear the Snap state in the store.
|
|
63
|
+
*
|
|
64
|
+
* @param _snapId - The ID of the Snap to clear the state for. This is ignored
|
|
65
|
+
* because the simulator only supports one Snap.
|
|
66
|
+
* @param encrypted - Whether to clear the encrypted or unencrypted state.
|
|
67
|
+
* Defaults to encrypted state.
|
|
68
|
+
* @yields Puts the new state in the store.
|
|
69
|
+
*/ function* clearSnapStateImplementation(_snapId, encrypted = true) {
|
|
70
|
+
yield (0, _effects.put)((0, _store.clearState)({
|
|
71
|
+
encrypted
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
function getClearSnapStateMethodImplementation(runSaga) {
|
|
75
|
+
return async (...args)=>{
|
|
76
|
+
runSaga(clearSnapStateImplementation, ...args).result();
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/state.ts"],"sourcesContent":["import type { SagaIterator } from 'redux-saga';\nimport { put, select } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { clearState, getState, setState } from '../../store';\n\n/**\n * Get the Snap state from the store.\n *\n * @param _snapId - The ID of the Snap to get the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @returns The state of the Snap.\n * @yields Selects the state from the store.\n */\nfunction* getSnapStateImplementation(\n _snapId: string,\n encrypted = true,\n): SagaIterator<string> {\n return yield select(getState(encrypted));\n}\n\n/**\n * Get the implementation of the `getSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `getSnapState` hook.\n */\nexport function getGetSnapStateMethodImplementation(runSaga: RunSagaFunction) {\n return (...args: Parameters<typeof getSnapStateImplementation>) => {\n return runSaga(getSnapStateImplementation, ...args).result();\n };\n}\n\n/**\n * Update the Snap state in the store.\n *\n * @param _snapId - The ID of the Snap to update the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @yields Puts the new state in the store.\n */\nfunction* updateSnapStateImplementation(\n _snapId: string,\n newState: string,\n encrypted = true,\n): SagaIterator<void> {\n yield put(setState({ state: newState, encrypted }));\n}\n\n/**\n * Get the implementation of the `updateSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `updateSnapState` hook.\n */\nexport function getUpdateSnapStateMethodImplementation(\n runSaga: RunSagaFunction,\n) {\n return (...args: Parameters<typeof updateSnapStateImplementation>) => {\n runSaga(updateSnapStateImplementation, ...args).result();\n };\n}\n\n/**\n * Clear the Snap state in the store.\n *\n * @param _snapId - The ID of the Snap to clear the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @yields Puts the new state in the store.\n */\nfunction* clearSnapStateImplementation(\n _snapId: string,\n encrypted = true,\n): SagaIterator<void> {\n yield put(clearState({ encrypted }));\n}\n\n/**\n * Get the implementation of the `clearSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `clearSnapState` hook.\n */\nexport function getClearSnapStateMethodImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (...args: Parameters<typeof clearSnapStateImplementation>) => {\n runSaga(clearSnapStateImplementation, ...args).result();\n };\n}\n"],"names":["getGetSnapStateMethodImplementation","getUpdateSnapStateMethodImplementation","getClearSnapStateMethodImplementation","getSnapStateImplementation","_snapId","encrypted","select","getState","runSaga","args","result","updateSnapStateImplementation","newState","put","setState","state","clearSnapStateImplementation","clearState"],"mappings":";;;;;;;;;;;IA6BgBA,mCAAmC;eAAnCA;;IA8BAC,sCAAsC;eAAtCA;;IA8BAC,qCAAqC;eAArCA;;;yBAxFY;uBAGmB;AAE/C;;;;;;;;;CASC,GACD,UAAUC,2BACRC,OAAe,EACfC,YAAY,IAAI;IAEhB,OAAO,MAAMC,IAAAA,eAAM,EAACC,IAAAA,eAAQ,EAACF;AAC/B;AAQO,SAASL,oCAAoCQ,OAAwB;IAC1E,OAAO,CAAC,GAAGC;QACT,OAAOD,QAAQL,+BAA+BM,MAAMC,MAAM;IAC5D;AACF;AAEA;;;;;;;;;CASC,GACD,UAAUC,8BACRP,OAAe,EACfQ,QAAgB,EAChBP,YAAY,IAAI;IAEhB,MAAMQ,IAAAA,YAAG,EAACC,IAAAA,eAAQ,EAAC;QAAEC,OAAOH;QAAUP;IAAU;AAClD;AAQO,SAASJ,uCACdO,OAAwB;IAExB,OAAO,CAAC,GAAGC;QACTD,QAAQG,kCAAkCF,MAAMC,MAAM;IACxD;AACF;AAEA;;;;;;;;CAQC,GACD,UAAUM,6BACRZ,OAAe,EACfC,YAAY,IAAI;IAEhB,MAAMQ,IAAAA,YAAG,EAACI,IAAAA,iBAAU,EAAC;QAAEZ;IAAU;AACnC;AAQO,SAASH,sCACdM,OAAwB;IAExB,OAAO,OAAO,GAAGC;QACfD,QAAQQ,iCAAiCP,MAAMC,MAAM;IACvD;AACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./specifications"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/internals/simulation/methods/index.ts"],"sourcesContent":["export * from './specifications';\n"],"names":[],"mappings":";;;;qBAAc"}
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
resolve: function() {
|
|
13
|
+
return resolve;
|
|
14
|
+
},
|
|
15
|
+
asyncResolve: function() {
|
|
16
|
+
return asyncResolve;
|
|
17
|
+
},
|
|
18
|
+
getPermissionSpecifications: function() {
|
|
19
|
+
return getPermissionSpecifications;
|
|
20
|
+
},
|
|
21
|
+
getEndowments: function() {
|
|
22
|
+
return getEndowments;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _snapsrpcmethods = require("@metamask/snaps-rpc-methods");
|
|
26
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
27
|
+
const _constants = require("./constants");
|
|
28
|
+
const _hooks = require("./hooks");
|
|
29
|
+
function resolve(result) {
|
|
30
|
+
return ()=>result;
|
|
31
|
+
}
|
|
32
|
+
function asyncResolve(result) {
|
|
33
|
+
return async ()=>result;
|
|
34
|
+
}
|
|
35
|
+
function getPermissionSpecifications({ controllerMessenger, hooks, runSaga, options }) {
|
|
36
|
+
return {
|
|
37
|
+
...(0, _snapsrpcmethods.buildSnapEndowmentSpecifications)(_constants.EXCLUDED_SNAP_ENDOWMENTS),
|
|
38
|
+
...(0, _snapsrpcmethods.buildSnapRestrictedMethodSpecifications)(_constants.EXCLUDED_SNAP_PERMISSIONS, {
|
|
39
|
+
// Shared hooks.
|
|
40
|
+
...hooks,
|
|
41
|
+
// Encryption and decryption hooks.
|
|
42
|
+
// TODO: Swap these out for the real implementations.
|
|
43
|
+
encrypt: _hooks.encryptImplementation,
|
|
44
|
+
decrypt: _hooks.decryptImplementation,
|
|
45
|
+
// Snaps-specific hooks.
|
|
46
|
+
clearSnapState: (0, _hooks.getClearSnapStateMethodImplementation)(runSaga),
|
|
47
|
+
getLocale: (0, _hooks.getGetLocaleMethodImplementation)(options),
|
|
48
|
+
getSnapState: (0, _hooks.getGetSnapStateMethodImplementation)(runSaga),
|
|
49
|
+
getUnlockPromise: asyncResolve(true),
|
|
50
|
+
// TODO: Allow the user to specify the result of this function.
|
|
51
|
+
isOnPhishingList: resolve(false),
|
|
52
|
+
maybeUpdatePhishingList: asyncResolve(),
|
|
53
|
+
showDialog: (0, _hooks.getShowDialogImplementation)(runSaga),
|
|
54
|
+
showInAppNotification: (0, _hooks.getShowInAppNotificationImplementation)(runSaga),
|
|
55
|
+
showNativeNotification: (0, _hooks.getShowNativeNotificationImplementation)(runSaga),
|
|
56
|
+
updateSnapState: (0, _hooks.getUpdateSnapStateMethodImplementation)(runSaga),
|
|
57
|
+
createInterface: (0, _hooks.getCreateInterfaceImplementation)(controllerMessenger),
|
|
58
|
+
getInterface: (0, _hooks.getGetInterfaceImplementation)(controllerMessenger)
|
|
59
|
+
})
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async function getEndowments(permissionController, snapId) {
|
|
63
|
+
const allEndowments = await Object.keys(_snapsrpcmethods.endowmentPermissionBuilders).reduce(async (promise, permissionName)=>{
|
|
64
|
+
const accumulator = await promise;
|
|
65
|
+
if (permissionController.hasPermission(snapId, permissionName)) {
|
|
66
|
+
const endowments = await permissionController.getEndowments(snapId, permissionName);
|
|
67
|
+
if (endowments) {
|
|
68
|
+
return accumulator.concat(endowments);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return accumulator;
|
|
72
|
+
}, Promise.resolve([]));
|
|
73
|
+
return [
|
|
74
|
+
...new Set([
|
|
75
|
+
..._snapsutils.DEFAULT_ENDOWMENTS,
|
|
76
|
+
...allEndowments
|
|
77
|
+
])
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=specifications.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/internals/simulation/methods/specifications.ts"],"sourcesContent":["import type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetLocaleMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowDialogImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n encryptImplementation,\n decryptImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\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 // Encryption and decryption hooks.\n // TODO: Swap these out for the real implementations.\n encrypt: encryptImplementation,\n decrypt: decryptImplementation,\n\n // Snaps-specific hooks.\n clearSnapState: getClearSnapStateMethodImplementation(runSaga),\n getLocale: getGetLocaleMethodImplementation(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 showDialog: getShowDialogImplementation(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"],"names":["resolve","asyncResolve","getPermissionSpecifications","getEndowments","result","controllerMessenger","hooks","runSaga","options","buildSnapEndowmentSpecifications","EXCLUDED_SNAP_ENDOWMENTS","buildSnapRestrictedMethodSpecifications","EXCLUDED_SNAP_PERMISSIONS","encrypt","encryptImplementation","decrypt","decryptImplementation","clearSnapState","getClearSnapStateMethodImplementation","getLocale","getGetLocaleMethodImplementation","getSnapState","getGetSnapStateMethodImplementation","getUnlockPromise","isOnPhishingList","maybeUpdatePhishingList","showDialog","getShowDialogImplementation","showInAppNotification","getShowInAppNotificationImplementation","showNativeNotification","getShowNativeNotificationImplementation","updateSnapState","getUpdateSnapStateMethodImplementation","createInterface","getCreateInterfaceImplementation","getInterface","getGetInterfaceImplementation","permissionController","snapId","allEndowments","Object","keys","endowmentPermissionBuilders","reduce","promise","permissionName","accumulator","hasPermission","endowments","concat","Promise","Set","DEFAULT_ENDOWMENTS"],"mappings":";;;;;;;;;;;IAoDgBA,OAAO;eAAPA;;IAWAC,YAAY;eAAZA;;IAeAC,2BAA2B;eAA3BA;;IA4CMC,aAAa;eAAbA;;;iCArHf;4BAE4B;2BAQ5B;uBAaA;AAwBA,SAASH,QAAQI,MAAe;IACrC,OAAO,IAAMA;AACf;AASO,SAASH,aAAaG,MAAgB;IAC3C,OAAO,UAAYA;AACrB;AAaO,SAASF,4BAA4B,EAC1CG,mBAAmB,EACnBC,KAAK,EACLC,OAAO,EACPC,OAAO,EAC4B;IACnC,OAAO;QACL,GAAGC,IAAAA,iDAAgC,EAACC,mCAAwB,CAAC;QAC7D,GAAGC,IAAAA,wDAAuC,EAACC,oCAAyB,EAAE;YACpE,gBAAgB;YAChB,GAAGN,KAAK;YAER,mCAAmC;YACnC,qDAAqD;YACrDO,SAASC,4BAAqB;YAC9BC,SAASC,4BAAqB;YAE9B,wBAAwB;YACxBC,gBAAgBC,IAAAA,4CAAqC,EAACX;YACtDY,WAAWC,IAAAA,uCAAgC,EAACZ;YAC5Ca,cAAcC,IAAAA,0CAAmC,EAACf;YAClDgB,kBAAkBtB,aAAa;YAE/B,+DAA+D;YAC/DuB,kBAAkBxB,QAAQ;YAE1ByB,yBAAyBxB;YACzByB,YAAYC,IAAAA,kCAA2B,EAACpB;YACxCqB,uBAAuBC,IAAAA,6CAAsC,EAACtB;YAC9DuB,wBAAwBC,IAAAA,8CAAuC,EAACxB;YAChEyB,iBAAiBC,IAAAA,6CAAsC,EAAC1B;YACxD2B,iBAAiBC,IAAAA,uCAAgC,EAAC9B;YAClD+B,cAAcC,IAAAA,oCAA6B,EAAChC;QAC9C,EAAE;IACJ;AACF;AASO,eAAeF,cACpBmC,oBAAiD,EACjDC,MAAc;IAEd,MAAMC,gBAAgB,MAAMC,OAAOC,IAAI,CAACC,4CAA2B,EAAEC,MAAM,CAEzE,OAAOC,SAASC;QAChB,MAAMC,cAAc,MAAMF;QAC1B,IAAIP,qBAAqBU,aAAa,CAACT,QAAQO,iBAAiB;YAC9D,MAAMG,aAAa,MAAMX,qBAAqBnC,aAAa,CACzDoC,QACAO;YAGF,IAAIG,YAAY;gBACd,OAAOF,YAAYG,MAAM,CAACD;YAC5B;QACF;QAEA,OAAOF;IACT,GAAGI,QAAQnD,OAAO,CAAC,EAAE;IAErB,OAAO;WAAI,IAAIoD,IAAI;eAAIC,8BAAkB;eAAKb;SAAc;KAAE;AAChE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createJsonRpcEngine", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createJsonRpcEngine;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _ethjsonrpcmiddleware = require("@metamask/eth-json-rpc-middleware");
|
|
12
|
+
const _jsonrpcengine = require("@metamask/json-rpc-engine");
|
|
13
|
+
const _snapsrpcmethods = require("@metamask/snaps-rpc-methods");
|
|
14
|
+
const _constants = require("../constants");
|
|
15
|
+
const _internalmethods = require("./internal-methods");
|
|
16
|
+
const _mock = require("./mock");
|
|
17
|
+
function createJsonRpcEngine({ store, hooks, permissionMiddleware, endpoint = _constants.DEFAULT_JSON_RPC_ENDPOINT }) {
|
|
18
|
+
const engine = new _jsonrpcengine.JsonRpcEngine();
|
|
19
|
+
engine.push((0, _mock.createMockMiddleware)(store));
|
|
20
|
+
engine.push((0, _internalmethods.createInternalMethodsMiddleware)(hooks));
|
|
21
|
+
engine.push((0, _snapsrpcmethods.createSnapsMethodMiddleware)(true, hooks));
|
|
22
|
+
engine.push(permissionMiddleware);
|
|
23
|
+
engine.push((0, _ethjsonrpcmiddleware.createFetchMiddleware)({
|
|
24
|
+
btoa: globalThis.btoa,
|
|
25
|
+
fetch: globalThis.fetch,
|
|
26
|
+
rpcUrl: endpoint
|
|
27
|
+
}));
|
|
28
|
+
return engine;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/internals/simulation/middleware/engine.ts"],"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"],"names":["createJsonRpcEngine","store","hooks","permissionMiddleware","endpoint","DEFAULT_JSON_RPC_ENDPOINT","engine","JsonRpcEngine","push","createMockMiddleware","createInternalMethodsMiddleware","createSnapsMethodMiddleware","createFetchMiddleware","btoa","globalThis","fetch","rpcUrl"],"mappings":";;;;+BAiCgBA;;;eAAAA;;;sCAjCsB;+BAER;iCAEc;2BAGF;iCAGM;sBACX;AAsB9B,SAASA,oBAAoB,EAClCC,KAAK,EACLC,KAAK,EACLC,oBAAoB,EACpBC,WAAWC,oCAAyB,EACT;IAC3B,MAAMC,SAAS,IAAIC,4BAAa;IAChCD,OAAOE,IAAI,CAACC,IAAAA,0BAAoB,EAACR;IACjCK,OAAOE,IAAI,CAACE,IAAAA,gDAA+B,EAACR;IAC5CI,OAAOE,IAAI,CAACG,IAAAA,4CAA2B,EAAC,MAAMT;IAC9CI,OAAOE,IAAI,CAACL;IACZG,OAAOE,IAAI,CACTI,IAAAA,2CAAqB,EAAC;QACpBC,MAAMC,WAAWD,IAAI;QACrBE,OAAOD,WAAWC,KAAK;QACvBC,QAAQZ;IACV;IAGF,OAAOE;AACT"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./engine"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/internals/simulation/middleware/index.ts"],"sourcesContent":["export * from './engine';\n"],"names":[],"mappings":";;;;qBAAc"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getAccountsHandler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getAccountsHandler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _keytree = require("@metamask/key-tree");
|
|
12
|
+
async function getAccountsHandler(_request, response, _next, end, hooks) {
|
|
13
|
+
const { getMnemonic } = hooks;
|
|
14
|
+
const node = await _keytree.BIP44Node.fromDerivationPath({
|
|
15
|
+
derivationPath: [
|
|
16
|
+
await getMnemonic(),
|
|
17
|
+
`bip32:44'`,
|
|
18
|
+
`bip32:60'`,
|
|
19
|
+
`bip32:0'`,
|
|
20
|
+
`bip32:0`,
|
|
21
|
+
`bip32:0`
|
|
22
|
+
]
|
|
23
|
+
});
|
|
24
|
+
response.result = [
|
|
25
|
+
node.address
|
|
26
|
+
];
|
|
27
|
+
return end();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/middleware/internal-methods/accounts.ts"],"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 */\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"],"names":["getAccountsHandler","_request","response","_next","end","hooks","getMnemonic","node","BIP44Node","fromDerivationPath","derivationPath","result","address"],"mappings":";;;;+BA2BsBA;;;eAAAA;;;yBAvBI;AAuBnB,eAAeA,mBACpBC,QAAwB,EACxBC,QAAsC,EACtCC,KAAgC,EAChCC,GAA6B,EAC7BC,KAA8B;IAE9B,MAAM,EAAEC,WAAW,EAAE,GAAGD;IAExB,MAAME,OAAO,MAAMC,kBAAS,CAACC,kBAAkB,CAAC;QAC9CC,gBAAgB;YACd,MAAMJ;YACN,CAAC,SAAS,CAAC;YACX,CAAC,SAAS,CAAC;YACX,CAAC,QAAQ,CAAC;YACV,CAAC,OAAO,CAAC;YACT,CAAC,OAAO,CAAC;SACV;IACH;IAEAJ,SAASS,MAAM,GAAG;QAACJ,KAAKK,OAAO;KAAC;IAChC,OAAOR;AACT"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./middleware"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/middleware/internal-methods/index.ts"],"sourcesContent":["export * from './middleware';\n"],"names":[],"mappings":";;;;qBAAc"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createInternalMethodsMiddleware", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createInternalMethodsMiddleware;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
12
|
+
const _accounts = require("./accounts");
|
|
13
|
+
const _providerstate = require("./provider-state");
|
|
14
|
+
const methodHandlers = {
|
|
15
|
+
/* eslint-disable @typescript-eslint/naming-convention */ metamask_getProviderState: _providerstate.getProviderStateHandler,
|
|
16
|
+
eth_requestAccounts: _accounts.getAccountsHandler,
|
|
17
|
+
eth_accounts: _accounts.getAccountsHandler
|
|
18
|
+
};
|
|
19
|
+
function createInternalMethodsMiddleware(hooks) {
|
|
20
|
+
// This should probably use createAsyncMiddleware.
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
22
|
+
return async function methodMiddleware(request, response, next, end) {
|
|
23
|
+
const handler = methodHandlers[request.method];
|
|
24
|
+
if (handler) {
|
|
25
|
+
try {
|
|
26
|
+
// Implementations may or may not be async, so we must await them.
|
|
27
|
+
return await handler(request, response, next, end, hooks);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
(0, _snapsutils.logError)(error);
|
|
30
|
+
return end(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return next();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/middleware/internal-methods/middleware.ts"],"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"],"names":["createInternalMethodsMiddleware","methodHandlers","metamask_getProviderState","getProviderStateHandler","eth_requestAccounts","getAccountsHandler","eth_accounts","hooks","methodMiddleware","request","response","next","end","handler","method","error","logError"],"mappings":";;;;+BAmCgBA;;;eAAAA;;;4BAlCS;0BAGU;+BACK;AAWxC,MAAMC,iBAAiB;IACrB,uDAAuD,GACvDC,2BAA2BC,sCAAuB;IAClDC,qBAAqBC,4BAAkB;IACvCC,cAAcD,4BAAkB;AAElC;AAaO,SAASL,gCACdO,KAAqC;IAErC,kDAAkD;IAClD,kEAAkE;IAClE,OAAO,eAAeC,iBAAiBC,OAAO,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,GAAG;QACjE,MAAMC,UACJZ,cAAc,CAACQ,QAAQK,MAAM,CAAgC;QAC/D,IAAID,SAAS;YACX,IAAI;gBACF,kEAAkE;gBAClE,OAAO,MAAMA,QAAQJ,SAASC,UAAUC,MAAMC,KAAKL;YACrD,EAAE,OAAOQ,OAAY;gBACnBC,IAAAA,oBAAQ,EAACD;gBACT,OAAOH,IAAIG;YACb;QACF;QAEA,OAAOJ;IACT;AACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getProviderStateHandler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getProviderStateHandler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
async function getProviderStateHandler(_request, response, _next, end) {
|
|
12
|
+
// For now this will return a mocked result, this should probably match
|
|
13
|
+
// whatever network the simulation is using.
|
|
14
|
+
response.result = {
|
|
15
|
+
isUnlocked: true,
|
|
16
|
+
chainId: '0x01',
|
|
17
|
+
networkVersion: '0x01',
|
|
18
|
+
accounts: []
|
|
19
|
+
};
|
|
20
|
+
return end();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=provider-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/internals/simulation/middleware/internal-methods/provider-state.ts"],"sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\n/**\n * A mock handler for metamask_getProviderState that always returns a specific\n * hardcoded result.\n *\n * @param _request - Incoming JSON-RPC request. Ignored for this specific\n * handler.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n */\nexport async function getProviderStateHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n) {\n // For now this will return a mocked result, this should probably match\n // whatever network the simulation is using.\n response.result = {\n isUnlocked: true,\n chainId: '0x01',\n networkVersion: '0x01',\n accounts: [],\n };\n\n return end();\n}\n"],"names":["getProviderStateHandler","_request","response","_next","end","result","isUnlocked","chainId","networkVersion","accounts"],"mappings":";;;;+BAqBsBA;;;eAAAA;;;AAAf,eAAeA,wBACpBC,QAAwB,EACxBC,QAAsC,EACtCC,KAAgC,EAChCC,GAA6B;IAE7B,uEAAuE;IACvE,4CAA4C;IAC5CF,SAASG,MAAM,GAAG;QAChBC,YAAY;QACZC,SAAS;QACTC,gBAAgB;QAChBC,UAAU,EAAE;IACd;IAEA,OAAOL;AACT"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createMockMiddleware", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createMockMiddleware;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _mocks = require("../store/mocks");
|
|
12
|
+
function createMockMiddleware(store) {
|
|
13
|
+
return function mockMiddleware(request, response, next, end) {
|
|
14
|
+
const result = (0, _mocks.getJsonRpcMock)(store.getState(), request.method);
|
|
15
|
+
if (result) {
|
|
16
|
+
response.result = result;
|
|
17
|
+
return end();
|
|
18
|
+
}
|
|
19
|
+
return next();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/internals/simulation/middleware/mock.ts"],"sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport type { Store } from '../store';\nimport { getJsonRpcMock } from '../store/mocks';\n\n/**\n * Create a middleware for handling JSON-RPC methods that have been mocked.\n *\n * @param store - The Redux store to use.\n * @returns A middleware function.\n */\nexport function createMockMiddleware(\n store: Store,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n return function mockMiddleware(request, response, next, end) {\n const result = getJsonRpcMock(store.getState(), request.method);\n if (result) {\n response.result = result;\n return end();\n }\n\n return next();\n };\n}\n"],"names":["createMockMiddleware","store","mockMiddleware","request","response","next","end","result","getJsonRpcMock","getState","method"],"mappings":";;;;+BAYgBA;;;eAAAA;;;uBARe;AAQxB,SAASA,qBACdC,KAAY;IAEZ,OAAO,SAASC,eAAeC,OAAO,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,GAAG;QACzD,MAAMC,SAASC,IAAAA,qBAAc,EAACP,MAAMQ,QAAQ,IAAIN,QAAQO,MAAM;QAC9D,IAAIH,QAAQ;YACVH,SAASG,MAAM,GAAGA;YAClB,OAAOD;QACT;QAEA,OAAOD;IACT;AACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getOptions", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getOptions;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _utils = require("@metamask/utils");
|
|
12
|
+
const _superstruct = require("superstruct");
|
|
13
|
+
const _constants = require("./constants");
|
|
14
|
+
const SimulationOptionsStruct = (0, _superstruct.object)({
|
|
15
|
+
secretRecoveryPhrase: (0, _superstruct.defaulted)((0, _superstruct.optional)((0, _superstruct.string)()), _constants.DEFAULT_SRP),
|
|
16
|
+
locale: (0, _superstruct.defaulted)((0, _superstruct.optional)((0, _superstruct.string)()), _constants.DEFAULT_LOCALE),
|
|
17
|
+
state: (0, _superstruct.defaulted)((0, _superstruct.optional)((0, _superstruct.nullable)((0, _superstruct.record)((0, _superstruct.string)(), _utils.JsonStruct))), null),
|
|
18
|
+
unencryptedState: (0, _superstruct.defaulted)((0, _superstruct.optional)((0, _superstruct.nullable)((0, _superstruct.record)((0, _superstruct.string)(), _utils.JsonStruct))), null)
|
|
19
|
+
});
|
|
20
|
+
function getOptions(options) {
|
|
21
|
+
return (0, _superstruct.create)(options, SimulationOptionsStruct);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/internals/simulation/options.ts"],"sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n create,\n defaulted,\n nullable,\n object,\n optional,\n record,\n string,\n} from 'superstruct';\n\nimport { DEFAULT_LOCALE, DEFAULT_SRP } from './constants';\n\nconst SimulationOptionsStruct = object({\n secretRecoveryPhrase: defaulted(optional(string()), DEFAULT_SRP),\n locale: defaulted(optional(string()), DEFAULT_LOCALE),\n state: defaulted(optional(nullable(record(string(), JsonStruct))), null),\n unencryptedState: defaulted(\n optional(nullable(record(string(), JsonStruct))),\n null,\n ),\n});\n\n/**\n * Options for the simulation.\n *\n * @property secretRecoveryPhrase - The secret recovery phrase to use. This is\n * used to derive addresses and private keys. Defaults to a test recovery\n * phrase.\n * @property locale - The locale to use. Defaults to `en`.\n * @property state - The initial state of the Snap, if any. Defaults to `null`.\n */\nexport type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;\n\n/**\n * Options for the simulation, with defaults filled in.\n *\n * See {@link SimulationUserOptions} for documentation.\n */\nexport type SimulationOptions = Required<SimulationUserOptions>;\n\n/**\n * Get the options for the simulation.\n *\n * @param options - The user options. Any options not specified will be filled\n * in with default values.\n * @returns The simulation options.\n */\nexport function getOptions(options: SimulationUserOptions): SimulationOptions {\n return create(\n options,\n SimulationOptionsStruct,\n ) as Required<SimulationUserOptions>;\n}\n"],"names":["getOptions","SimulationOptionsStruct","object","secretRecoveryPhrase","defaulted","optional","string","DEFAULT_SRP","locale","DEFAULT_LOCALE","state","nullable","record","JsonStruct","unencryptedState","options","create"],"mappings":";;;;+BAiDgBA;;;eAAAA;;;uBAjDW;6BAUpB;2BAEqC;AAE5C,MAAMC,0BAA0BC,IAAAA,mBAAM,EAAC;IACrCC,sBAAsBC,IAAAA,sBAAS,EAACC,IAAAA,qBAAQ,EAACC,IAAAA,mBAAM,MAAKC,sBAAW;IAC/DC,QAAQJ,IAAAA,sBAAS,EAACC,IAAAA,qBAAQ,EAACC,IAAAA,mBAAM,MAAKG,yBAAc;IACpDC,OAAON,IAAAA,sBAAS,EAACC,IAAAA,qBAAQ,EAACM,IAAAA,qBAAQ,EAACC,IAAAA,mBAAM,EAACN,IAAAA,mBAAM,KAAIO,iBAAU,KAAK;IACnEC,kBAAkBV,IAAAA,sBAAS,EACzBC,IAAAA,qBAAQ,EAACM,IAAAA,qBAAQ,EAACC,IAAAA,mBAAM,EAACN,IAAAA,mBAAM,KAAIO,iBAAU,KAC7C;AAEJ;AA2BO,SAASb,WAAWe,OAA8B;IACvD,OAAOC,IAAAA,mBAAM,EACXD,SACAd;AAEJ"}
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
handleInstallSnap: function() {
|
|
13
|
+
return handleInstallSnap;
|
|
14
|
+
},
|
|
15
|
+
getHooks: function() {
|
|
16
|
+
return getHooks;
|
|
17
|
+
},
|
|
18
|
+
registerActions: function() {
|
|
19
|
+
return registerActions;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _basecontroller = require("@metamask/base-controller");
|
|
23
|
+
const _jsonrpcmiddlewarestream = require("@metamask/json-rpc-middleware-stream");
|
|
24
|
+
const _keytree = require("@metamask/key-tree");
|
|
25
|
+
const _snapscontrollers = require("@metamask/snaps-controllers");
|
|
26
|
+
const _snapsrpcmethods = require("@metamask/snaps-rpc-methods");
|
|
27
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
28
|
+
const _readablestream = require("readable-stream");
|
|
29
|
+
const _controllers = require("./controllers");
|
|
30
|
+
const _files = require("./files");
|
|
31
|
+
const _methods = require("./methods");
|
|
32
|
+
const _middleware = require("./middleware");
|
|
33
|
+
const _options = require("./options");
|
|
34
|
+
const _store = require("./store");
|
|
35
|
+
async function handleInstallSnap(snapId, { executionService, executionServiceOptions, options: rawOptions = {} } = {}) {
|
|
36
|
+
const options = (0, _options.getOptions)(rawOptions);
|
|
37
|
+
// Fetch Snap files.
|
|
38
|
+
const location = (0, _snapscontrollers.detectSnapLocation)(snapId, {
|
|
39
|
+
allowLocal: true
|
|
40
|
+
});
|
|
41
|
+
const snapFiles = await (0, _snapscontrollers.fetchSnap)(snapId, location);
|
|
42
|
+
// Create Redux store.
|
|
43
|
+
const password = await (0, _snapsrpcmethods.getEncryptionKey)({
|
|
44
|
+
mnemonicPhrase: (0, _keytree.mnemonicPhraseToBytes)(options.secretRecoveryPhrase),
|
|
45
|
+
snapId
|
|
46
|
+
});
|
|
47
|
+
const { store, runSaga } = (0, _store.createStore)(password, options);
|
|
48
|
+
const controllerMessenger = new _basecontroller.ControllerMessenger();
|
|
49
|
+
registerActions(controllerMessenger);
|
|
50
|
+
// Set up controllers and JSON-RPC stack.
|
|
51
|
+
const hooks = getHooks(options, snapFiles, snapId, controllerMessenger);
|
|
52
|
+
const { subjectMetadataController, permissionController } = (0, _controllers.getControllers)({
|
|
53
|
+
controllerMessenger,
|
|
54
|
+
hooks,
|
|
55
|
+
runSaga,
|
|
56
|
+
options
|
|
57
|
+
});
|
|
58
|
+
const engine = (0, _middleware.createJsonRpcEngine)({
|
|
59
|
+
store,
|
|
60
|
+
hooks,
|
|
61
|
+
permissionMiddleware: permissionController.createPermissionMiddleware({
|
|
62
|
+
origin: snapId
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
// Create execution service.
|
|
66
|
+
const ExecutionService = executionService ?? _snapscontrollers.NodeThreadExecutionService;
|
|
67
|
+
const service = new ExecutionService({
|
|
68
|
+
...executionServiceOptions,
|
|
69
|
+
messenger: controllerMessenger.getRestricted({
|
|
70
|
+
name: 'ExecutionService'
|
|
71
|
+
}),
|
|
72
|
+
setupSnapProvider: (_snapId, rpcStream)=>{
|
|
73
|
+
const mux = (0, _snapscontrollers.setupMultiplex)(rpcStream, 'snapStream');
|
|
74
|
+
const stream = mux.createStream('metamask-provider');
|
|
75
|
+
const providerStream = (0, _jsonrpcmiddlewarestream.createEngineStream)({
|
|
76
|
+
engine
|
|
77
|
+
});
|
|
78
|
+
// Error function is difficult to test, so we ignore it.
|
|
79
|
+
/* istanbul ignore next 2 */ (0, _readablestream.pipeline)(stream, providerStream, stream, (error)=>{
|
|
80
|
+
if (error) {
|
|
81
|
+
(0, _snapsutils.logError)(`Provider stream failure.`, error);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// Register the Snap. This sets up the Snap's permissions and subject
|
|
87
|
+
// metadata.
|
|
88
|
+
await (0, _controllers.registerSnap)(snapId, snapFiles.manifest.result, {
|
|
89
|
+
permissionController,
|
|
90
|
+
subjectMetadataController
|
|
91
|
+
});
|
|
92
|
+
// Run the Snap code in the execution service.
|
|
93
|
+
await service.executeSnap({
|
|
94
|
+
snapId,
|
|
95
|
+
sourceCode: snapFiles.sourceCode.toString('utf8'),
|
|
96
|
+
endowments: await (0, _methods.getEndowments)(permissionController, snapId)
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
snapId,
|
|
100
|
+
store,
|
|
101
|
+
executionService: service,
|
|
102
|
+
controllerMessenger,
|
|
103
|
+
runSaga
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function getHooks(options, snapFiles, snapId, controllerMessenger) {
|
|
107
|
+
return {
|
|
108
|
+
getMnemonic: async ()=>Promise.resolve((0, _keytree.mnemonicPhraseToBytes)(options.secretRecoveryPhrase)),
|
|
109
|
+
getSnapFile: async (path, encoding)=>await (0, _files.getSnapFile)(snapFiles.auxiliaryFiles, path, encoding),
|
|
110
|
+
getIsLocked: ()=>false,
|
|
111
|
+
createInterface: async (...args)=>controllerMessenger.call('SnapInterfaceController:createInterface', snapId, ...args),
|
|
112
|
+
updateInterface: async (...args)=>controllerMessenger.call('SnapInterfaceController:updateInterface', snapId, ...args),
|
|
113
|
+
getInterfaceState: (...args)=>controllerMessenger.call('SnapInterfaceController:getInterface', snapId, ...args).state
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function registerActions(controllerMessenger) {
|
|
117
|
+
controllerMessenger.registerActionHandler('PhishingController:maybeUpdateState', async ()=>Promise.resolve());
|
|
118
|
+
controllerMessenger.registerActionHandler('PhishingController:testOrigin', ()=>({
|
|
119
|
+
result: false,
|
|
120
|
+
type: 'all'
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=simulation.js.map
|