@metamask/snaps-controllers 9.5.0 → 9.6.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 +13 -1
- package/dist/cronjob/CronjobController.cjs +255 -0
- package/dist/cronjob/CronjobController.cjs.map +1 -0
- package/dist/{types/cronjob/CronjobController.d.ts → cronjob/CronjobController.d.cts} +8 -7
- package/dist/cronjob/CronjobController.d.cts.map +1 -0
- package/dist/cronjob/CronjobController.d.mts +121 -0
- package/dist/cronjob/CronjobController.d.mts.map +1 -0
- package/dist/cronjob/CronjobController.mjs +249 -41
- package/dist/cronjob/CronjobController.mjs.map +1 -1
- package/dist/cronjob/index.cjs +18 -0
- package/dist/cronjob/index.cjs.map +1 -0
- package/dist/cronjob/index.d.cts +2 -0
- package/dist/cronjob/index.d.cts.map +1 -0
- package/dist/cronjob/index.d.mts +2 -0
- package/dist/cronjob/index.d.mts.map +1 -0
- package/dist/cronjob/index.mjs +1 -42
- package/dist/cronjob/index.mjs.map +1 -1
- package/dist/fsm.cjs +75 -0
- package/dist/fsm.cjs.map +1 -0
- package/dist/{types/fsm.d.ts → fsm.d.cts} +2 -1
- package/dist/fsm.d.cts.map +1 -0
- package/dist/fsm.d.mts +25 -0
- package/dist/fsm.d.mts.map +1 -0
- package/dist/fsm.mjs +69 -9
- package/dist/fsm.mjs.map +1 -1
- package/dist/index.cjs +23 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -124
- package/dist/index.mjs.map +1 -1
- package/dist/insights/SnapInsightsController.cjs +182 -0
- package/dist/insights/SnapInsightsController.cjs.map +1 -0
- package/dist/{types/insights/SnapInsightsController.d.ts → insights/SnapInsightsController.d.cts} +8 -7
- package/dist/insights/SnapInsightsController.d.cts.map +1 -0
- package/dist/insights/SnapInsightsController.d.mts +38 -0
- package/dist/insights/SnapInsightsController.d.mts.map +1 -0
- package/dist/insights/SnapInsightsController.mjs +176 -23
- package/dist/insights/SnapInsightsController.mjs.map +1 -1
- package/dist/insights/index.cjs +18 -0
- package/dist/insights/index.cjs.map +1 -0
- package/dist/insights/index.d.cts +2 -0
- package/dist/insights/index.d.cts.map +1 -0
- package/dist/insights/index.d.mts +2 -0
- package/dist/insights/index.d.mts.map +1 -0
- package/dist/insights/index.mjs +1 -25
- package/dist/insights/index.mjs.map +1 -1
- package/dist/interface/SnapInterfaceController.cjs +176 -0
- package/dist/interface/SnapInterfaceController.cjs.map +1 -0
- package/dist/{types/interface/SnapInterfaceController.d.ts → interface/SnapInterfaceController.d.cts} +8 -7
- package/dist/interface/SnapInterfaceController.d.cts.map +1 -0
- package/dist/interface/SnapInterfaceController.d.mts +107 -0
- package/dist/interface/SnapInterfaceController.d.mts.map +1 -0
- package/dist/interface/SnapInterfaceController.mjs +170 -7
- package/dist/interface/SnapInterfaceController.mjs.map +1 -1
- package/dist/interface/index.cjs +18 -0
- package/dist/interface/index.cjs.map +1 -0
- package/dist/interface/index.d.cts +2 -0
- package/dist/interface/index.d.cts.map +1 -0
- package/dist/interface/index.d.mts +2 -0
- package/dist/interface/index.d.mts.map +1 -0
- package/dist/interface/index.mjs +1 -9
- package/dist/interface/index.mjs.map +1 -1
- package/dist/interface/utils.cjs +165 -0
- package/dist/interface/utils.cjs.map +1 -0
- package/dist/{types/interface/utils.d.ts → interface/utils.d.cts} +3 -2
- package/dist/interface/utils.d.cts.map +1 -0
- package/dist/interface/utils.d.mts +34 -0
- package/dist/interface/utils.d.mts.map +1 -0
- package/dist/interface/utils.mjs +157 -13
- package/dist/interface/utils.mjs.map +1 -1
- package/dist/logging.cjs +13 -0
- package/dist/logging.cjs.map +1 -0
- package/dist/{types/logging.d.ts → logging.d.cts} +1 -0
- package/dist/logging.d.cts.map +1 -0
- package/dist/logging.d.mts +9 -0
- package/dist/logging.d.mts.map +1 -0
- package/dist/logging.mjs +9 -7
- package/dist/logging.mjs.map +1 -1
- package/dist/node.cjs +20 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +3 -0
- package/dist/node.d.cts.map +1 -0
- package/dist/node.d.mts +3 -0
- package/dist/node.d.mts.map +1 -0
- package/dist/node.mjs +3 -134
- package/dist/node.mjs.map +1 -1
- package/dist/react-native.cjs +20 -0
- package/dist/react-native.cjs.map +1 -0
- package/dist/react-native.d.cts +3 -0
- package/dist/react-native.d.cts.map +1 -0
- package/dist/react-native.d.mts +3 -0
- package/dist/react-native.d.mts.map +1 -0
- package/dist/react-native.mjs +3 -131
- package/dist/react-native.mjs.map +1 -1
- package/dist/services/AbstractExecutionService.cjs +348 -0
- package/dist/services/AbstractExecutionService.cjs.map +1 -0
- package/dist/{types/services/AbstractExecutionService.d.ts → services/AbstractExecutionService.d.cts} +8 -8
- package/dist/services/AbstractExecutionService.d.cts.map +1 -0
- package/dist/services/AbstractExecutionService.d.mts +131 -0
- package/dist/services/AbstractExecutionService.d.mts.map +1 -0
- package/dist/services/AbstractExecutionService.mjs +345 -11
- package/dist/services/AbstractExecutionService.mjs.map +1 -1
- package/dist/services/ExecutionService.cjs +4 -0
- package/dist/services/ExecutionService.cjs.map +1 -0
- package/dist/{types/services/ExecutionService.d.ts → services/ExecutionService.d.cts} +4 -3
- package/dist/services/ExecutionService.d.cts.map +1 -0
- package/dist/services/ExecutionService.d.mts +69 -0
- package/dist/services/ExecutionService.d.mts.map +1 -0
- package/dist/services/ExecutionService.mjs +2 -1
- package/dist/services/ExecutionService.mjs.map +1 -1
- package/dist/services/ProxyPostMessageStream.cjs +58 -0
- package/dist/services/ProxyPostMessageStream.cjs.map +1 -0
- package/dist/{types/services/ProxyPostMessageStream.d.ts → services/ProxyPostMessageStream.d.cts} +3 -2
- package/dist/services/ProxyPostMessageStream.d.cts.map +1 -0
- package/dist/services/ProxyPostMessageStream.d.mts +35 -0
- package/dist/services/ProxyPostMessageStream.d.mts.map +1 -0
- package/dist/services/ProxyPostMessageStream.mjs +53 -6
- package/dist/services/ProxyPostMessageStream.mjs.map +1 -1
- package/dist/services/browser.cjs +27 -0
- package/dist/services/browser.cjs.map +1 -0
- package/dist/services/browser.d.cts +8 -0
- package/dist/services/browser.d.cts.map +1 -0
- package/dist/services/browser.d.mts +8 -0
- package/dist/services/browser.d.mts.map +1 -0
- package/dist/services/browser.mjs +8 -39
- package/dist/services/browser.mjs.map +1 -1
- package/dist/services/iframe/IframeExecutionService.cjs +30 -0
- package/dist/services/iframe/IframeExecutionService.cjs.map +1 -0
- package/dist/{types/services/iframe/IframeExecutionService.d.ts → services/iframe/IframeExecutionService.d.cts} +4 -3
- package/dist/services/iframe/IframeExecutionService.d.cts.map +1 -0
- package/dist/services/iframe/IframeExecutionService.d.mts +17 -0
- package/dist/services/iframe/IframeExecutionService.d.mts.map +1 -0
- package/dist/services/iframe/IframeExecutionService.mjs +26 -11
- package/dist/services/iframe/IframeExecutionService.mjs.map +1 -1
- package/dist/services/iframe/index.cjs +18 -0
- package/dist/services/iframe/index.cjs.map +1 -0
- package/dist/services/iframe/index.d.cts +2 -0
- package/dist/services/iframe/index.d.cts.map +1 -0
- package/dist/services/iframe/index.d.mts +2 -0
- package/dist/services/iframe/index.d.mts.map +1 -0
- package/dist/services/iframe/index.mjs +1 -12
- package/dist/services/iframe/index.mjs.map +1 -1
- package/dist/services/index.cjs +25 -0
- package/dist/services/index.cjs.map +1 -0
- package/dist/services/index.d.cts +7 -0
- package/dist/services/index.d.cts.map +1 -0
- package/dist/services/index.d.mts +7 -0
- package/dist/services/index.d.mts.map +1 -0
- package/dist/services/index.mjs +6 -34
- package/dist/services/index.mjs.map +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.cjs +30 -0
- package/dist/services/node-js/NodeProcessExecutionService.cjs.map +1 -0
- package/dist/{types/services/node-js/NodeProcessExecutionService.d.ts → services/node-js/NodeProcessExecutionService.d.cts} +5 -4
- package/dist/services/node-js/NodeProcessExecutionService.d.cts.map +1 -0
- package/dist/services/node-js/NodeProcessExecutionService.d.mts +13 -0
- package/dist/services/node-js/NodeProcessExecutionService.d.mts.map +1 -0
- package/dist/services/node-js/NodeProcessExecutionService.mjs +26 -21
- package/dist/services/node-js/NodeProcessExecutionService.mjs.map +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.cjs +32 -0
- package/dist/services/node-js/NodeThreadExecutionService.cjs.map +1 -0
- package/dist/{types/services/node-js/NodeThreadExecutionService.d.ts → services/node-js/NodeThreadExecutionService.d.cts} +5 -4
- package/dist/services/node-js/NodeThreadExecutionService.d.cts.map +1 -0
- package/dist/services/node-js/NodeThreadExecutionService.d.mts +13 -0
- package/dist/services/node-js/NodeThreadExecutionService.d.mts.map +1 -0
- package/dist/services/node-js/NodeThreadExecutionService.mjs +28 -21
- package/dist/services/node-js/NodeThreadExecutionService.mjs.map +1 -1
- package/dist/services/node-js/index.cjs +19 -0
- package/dist/services/node-js/index.cjs.map +1 -0
- package/dist/services/node-js/index.d.cts +3 -0
- package/dist/services/node-js/index.d.cts.map +1 -0
- package/dist/services/node-js/index.d.mts +3 -0
- package/dist/services/node-js/index.d.mts.map +1 -0
- package/dist/services/node-js/index.mjs +2 -26
- package/dist/services/node-js/index.mjs.map +1 -1
- package/dist/services/node.cjs +19 -0
- package/dist/services/node.cjs.map +1 -0
- package/dist/services/node.d.cts +3 -0
- package/dist/services/node.d.cts.map +1 -0
- package/dist/services/node.d.mts +3 -0
- package/dist/services/node.d.mts.map +1 -0
- package/dist/services/node.mjs +2 -44
- package/dist/services/node.mjs.map +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.cjs +56 -0
- package/dist/services/offscreen/OffscreenExecutionService.cjs.map +1 -0
- package/dist/{types/services/offscreen/OffscreenExecutionService.d.ts → services/offscreen/OffscreenExecutionService.d.cts} +3 -2
- package/dist/services/offscreen/OffscreenExecutionService.d.cts.map +1 -0
- package/dist/services/offscreen/OffscreenExecutionService.d.mts +33 -0
- package/dist/services/offscreen/OffscreenExecutionService.d.mts.map +1 -0
- package/dist/services/offscreen/OffscreenExecutionService.mjs +51 -12
- package/dist/services/offscreen/OffscreenExecutionService.mjs.map +1 -1
- package/dist/services/offscreen/index.cjs +18 -0
- package/dist/services/offscreen/index.cjs.map +1 -0
- package/dist/services/offscreen/index.d.cts +2 -0
- package/dist/services/offscreen/index.d.cts.map +1 -0
- package/dist/services/offscreen/index.d.mts +2 -0
- package/dist/services/offscreen/index.d.mts.map +1 -0
- package/dist/services/offscreen/index.mjs +1 -14
- package/dist/services/offscreen/index.mjs.map +1 -1
- package/dist/services/proxy/ProxyExecutionService.cjs +85 -0
- package/dist/services/proxy/ProxyExecutionService.cjs.map +1 -0
- package/dist/{types/services/proxy/ProxyExecutionService.d.ts → services/proxy/ProxyExecutionService.d.cts} +6 -4
- package/dist/services/proxy/ProxyExecutionService.d.cts.map +1 -0
- package/dist/services/proxy/ProxyExecutionService.d.mts +41 -0
- package/dist/services/proxy/ProxyExecutionService.d.mts.map +1 -0
- package/dist/services/proxy/ProxyExecutionService.mjs +79 -11
- package/dist/services/proxy/ProxyExecutionService.mjs.map +1 -1
- package/dist/services/react-native.cjs +19 -0
- package/dist/services/react-native.cjs.map +1 -0
- package/dist/services/react-native.d.cts +3 -0
- package/dist/services/react-native.d.cts.map +1 -0
- package/dist/services/react-native.d.mts +3 -0
- package/dist/services/react-native.d.mts.map +1 -0
- package/dist/services/react-native.mjs +2 -41
- package/dist/services/react-native.mjs.map +1 -1
- package/dist/services/webview/WebViewExecutionService.cjs +54 -0
- package/dist/services/webview/WebViewExecutionService.cjs.map +1 -0
- package/dist/{types/services/webview/WebViewExecutionService.d.ts → services/webview/WebViewExecutionService.d.cts} +5 -3
- package/dist/services/webview/WebViewExecutionService.d.cts.map +1 -0
- package/dist/services/webview/WebViewExecutionService.d.mts +22 -0
- package/dist/services/webview/WebViewExecutionService.d.mts.map +1 -0
- package/dist/services/webview/WebViewExecutionService.mjs +48 -13
- package/dist/services/webview/WebViewExecutionService.mjs.map +1 -1
- package/dist/services/webview/WebViewMessageStream.cjs +89 -0
- package/dist/services/webview/WebViewMessageStream.cjs.map +1 -0
- package/dist/{types/services/webview/WebViewMessageStream.d.ts → services/webview/WebViewMessageStream.d.cts} +3 -2
- package/dist/services/webview/WebViewMessageStream.d.cts.map +1 -0
- package/dist/services/webview/WebViewMessageStream.d.mts +33 -0
- package/dist/services/webview/WebViewMessageStream.d.mts.map +1 -0
- package/dist/services/webview/WebViewMessageStream.mjs +84 -6
- package/dist/services/webview/WebViewMessageStream.mjs.map +1 -1
- package/dist/services/webview/index.cjs +18 -0
- package/dist/services/webview/index.cjs.map +1 -0
- package/dist/services/webview/index.d.cts +2 -0
- package/dist/services/webview/index.d.cts.map +1 -0
- package/dist/services/webview/index.d.mts +2 -0
- package/dist/services/webview/index.d.mts.map +1 -0
- package/dist/services/webview/index.mjs +1 -15
- package/dist/services/webview/index.mjs.map +1 -1
- package/dist/services/webworker/WebWorkerExecutionService.cjs +101 -0
- package/dist/services/webworker/WebWorkerExecutionService.cjs.map +1 -0
- package/dist/{types/services/webworker/WebWorkerExecutionService.d.ts → services/webworker/WebWorkerExecutionService.d.cts} +5 -3
- package/dist/services/webworker/WebWorkerExecutionService.d.cts.map +1 -0
- package/dist/services/webworker/WebWorkerExecutionService.d.mts +47 -0
- package/dist/services/webworker/WebWorkerExecutionService.d.mts.map +1 -0
- package/dist/services/webworker/WebWorkerExecutionService.mjs +96 -13
- package/dist/services/webworker/WebWorkerExecutionService.mjs.map +1 -1
- package/dist/services/webworker/index.cjs +18 -0
- package/dist/services/webworker/index.cjs.map +1 -0
- package/dist/services/webworker/index.d.cts +2 -0
- package/dist/services/webworker/index.d.cts.map +1 -0
- package/dist/services/webworker/index.d.mts +2 -0
- package/dist/services/webworker/index.d.mts.map +1 -0
- package/dist/services/webworker/index.mjs +1 -15
- package/dist/services/webworker/index.mjs.map +1 -1
- package/dist/snaps/RequestQueue.cjs +44 -0
- package/dist/snaps/RequestQueue.cjs.map +1 -0
- package/dist/{types/snaps/RequestQueue.d.ts → snaps/RequestQueue.d.cts} +1 -0
- package/dist/snaps/RequestQueue.d.cts.map +1 -0
- package/dist/snaps/RequestQueue.d.mts +25 -0
- package/dist/snaps/RequestQueue.d.mts.map +1 -0
- package/dist/snaps/RequestQueue.mjs +39 -7
- package/dist/snaps/RequestQueue.mjs.map +1 -1
- package/dist/snaps/SnapController.cjs +1896 -0
- package/dist/snaps/SnapController.cjs.map +1 -0
- package/dist/{types/snaps/SnapController.d.ts → snaps/SnapController.d.cts} +33 -20
- package/dist/snaps/SnapController.d.cts.map +1 -0
- package/dist/snaps/SnapController.d.mts +667 -0
- package/dist/snaps/SnapController.d.mts.map +1 -0
- package/dist/snaps/SnapController.mjs +1890 -28
- package/dist/snaps/SnapController.mjs.map +1 -1
- package/dist/snaps/Timer.cjs +103 -0
- package/dist/snaps/Timer.cjs.map +1 -0
- package/dist/{types/snaps/Timer.d.ts → snaps/Timer.d.cts} +1 -0
- package/dist/snaps/Timer.d.cts.map +1 -0
- package/dist/snaps/Timer.d.mts +47 -0
- package/dist/snaps/Timer.d.mts.map +1 -0
- package/dist/snaps/Timer.mjs +98 -7
- package/dist/snaps/Timer.mjs.map +1 -1
- package/dist/snaps/constants.cjs +24 -0
- package/dist/snaps/constants.cjs.map +1 -0
- package/dist/{types/snaps/constants.d.ts → snaps/constants.d.cts} +1 -0
- package/dist/snaps/constants.d.cts.map +1 -0
- package/dist/snaps/constants.d.mts +8 -0
- package/dist/snaps/constants.d.mts.map +1 -0
- package/dist/snaps/constants.mjs +19 -8
- package/dist/snaps/constants.mjs.map +1 -1
- package/dist/snaps/index.cjs +21 -0
- package/dist/snaps/index.cjs.map +1 -0
- package/dist/snaps/index.d.cts +5 -0
- package/dist/snaps/index.d.cts.map +1 -0
- package/dist/snaps/index.d.mts +5 -0
- package/dist/snaps/index.d.mts.map +1 -0
- package/dist/snaps/index.mjs +4 -62
- package/dist/snaps/index.mjs.map +1 -1
- package/dist/snaps/location/http.cjs +75 -0
- package/dist/snaps/location/http.cjs.map +1 -0
- package/dist/{types/snaps/location/http.d.ts → snaps/location/http.d.cts} +4 -3
- package/dist/snaps/location/http.d.cts.map +1 -0
- package/dist/snaps/location/http.d.mts +23 -0
- package/dist/snaps/location/http.d.mts.map +1 -0
- package/dist/snaps/location/http.mjs +70 -7
- package/dist/snaps/location/http.mjs.map +1 -1
- package/dist/snaps/location/index.cjs +21 -0
- package/dist/snaps/location/index.cjs.map +1 -0
- package/dist/snaps/location/index.d.cts +5 -0
- package/dist/snaps/location/index.d.cts.map +1 -0
- package/dist/snaps/location/index.d.mts +5 -0
- package/dist/snaps/location/index.d.mts.map +1 -0
- package/dist/snaps/location/index.mjs +4 -30
- package/dist/snaps/location/index.mjs.map +1 -1
- package/dist/snaps/location/local.cjs +51 -0
- package/dist/snaps/location/local.cjs.map +1 -0
- package/dist/{types/snaps/location/local.d.ts → snaps/location/local.d.cts} +4 -3
- package/dist/snaps/location/local.d.cts.map +1 -0
- package/dist/snaps/location/local.d.mts +11 -0
- package/dist/snaps/location/local.d.mts.map +1 -0
- package/dist/snaps/location/local.mjs +45 -7
- package/dist/snaps/location/local.mjs.map +1 -1
- package/dist/snaps/location/location.cjs +34 -0
- package/dist/{chunk-ZKG6FRKN.mjs.map → snaps/location/location.cjs.map} +1 -1
- package/dist/{types/snaps/location/location.d.ts → snaps/location/location.d.cts} +4 -3
- package/dist/snaps/location/location.d.cts.map +1 -0
- package/dist/snaps/location/location.d.mts +45 -0
- package/dist/snaps/location/location.d.mts.map +1 -0
- package/dist/snaps/location/location.mjs +29 -10
- package/dist/snaps/location/location.mjs.map +1 -1
- package/dist/snaps/location/npm.cjs +335 -0
- package/dist/snaps/location/npm.cjs.map +1 -0
- package/dist/{types/snaps/location/npm.d.ts → snaps/location/npm.d.cts} +5 -4
- package/dist/snaps/location/npm.d.cts.map +1 -0
- package/dist/snaps/location/npm.d.mts +84 -0
- package/dist/snaps/location/npm.d.mts.map +1 -0
- package/dist/snaps/location/npm.mjs +331 -16
- package/dist/snaps/location/npm.mjs.map +1 -1
- package/dist/snaps/registry/index.cjs +19 -0
- package/dist/snaps/registry/index.cjs.map +1 -0
- package/dist/snaps/registry/index.d.cts +3 -0
- package/dist/snaps/registry/index.d.cts.map +1 -0
- package/dist/snaps/registry/index.d.mts +3 -0
- package/dist/snaps/registry/index.d.mts.map +1 -0
- package/dist/snaps/registry/index.mjs +2 -12
- package/dist/snaps/registry/index.mjs.map +1 -1
- package/dist/snaps/registry/json.cjs +224 -0
- package/dist/snaps/registry/json.cjs.map +1 -0
- package/dist/{types/snaps/registry/json.d.ts → snaps/registry/json.d.cts} +6 -5
- package/dist/snaps/registry/json.d.cts.map +1 -0
- package/dist/snaps/registry/json.d.mts +51 -0
- package/dist/snaps/registry/json.d.mts.map +1 -0
- package/dist/snaps/registry/json.mjs +219 -7
- package/dist/snaps/registry/json.mjs.map +1 -1
- package/dist/snaps/registry/registry.cjs +11 -0
- package/dist/snaps/registry/registry.cjs.map +1 -0
- package/dist/{types/snaps/registry/registry.d.ts → snaps/registry/registry.d.cts} +4 -3
- package/dist/snaps/registry/registry.d.cts.map +1 -0
- package/dist/snaps/registry/registry.d.mts +42 -0
- package/dist/snaps/registry/registry.d.mts.map +1 -0
- package/dist/snaps/registry/registry.mjs +7 -7
- package/dist/snaps/registry/registry.mjs.map +1 -1
- package/dist/snaps/selectors.cjs +6 -0
- package/dist/snaps/selectors.cjs.map +1 -0
- package/dist/snaps/selectors.d.cts +3 -0
- package/dist/snaps/selectors.d.cts.map +1 -0
- package/dist/snaps/selectors.d.mts +3 -0
- package/dist/snaps/selectors.d.mts.map +1 -0
- package/dist/snaps/selectors.mjs +1 -7
- package/dist/snaps/selectors.mjs.map +1 -1
- package/dist/types/controllers.cjs +4 -0
- package/dist/types/controllers.cjs.map +1 -0
- package/dist/types/{types/controllers.d.ts → controllers.d.cts} +3 -2
- package/dist/types/controllers.d.cts.map +1 -0
- package/dist/types/controllers.d.mts +132 -0
- package/dist/types/controllers.d.mts.map +1 -0
- package/dist/types/controllers.mjs +2 -1
- package/dist/types/controllers.mjs.map +1 -1
- package/dist/types/encryptor.cjs +3 -0
- package/dist/types/encryptor.cjs.map +1 -0
- package/dist/types/{types/encryptor.d.ts → encryptor.d.cts} +2 -1
- package/dist/types/encryptor.d.cts.map +1 -0
- package/dist/types/encryptor.d.mts +99 -0
- package/dist/types/encryptor.d.mts.map +1 -0
- package/dist/types/encryptor.mjs +1 -1
- package/dist/types/encryptor.mjs.map +1 -1
- package/dist/types/index.cjs +19 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +3 -0
- package/dist/types/index.d.cts.map +1 -0
- package/dist/types/index.d.mts +3 -0
- package/dist/types/index.d.mts.map +1 -0
- package/dist/types/index.mjs +2 -2
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils.cjs +174 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/{types/utils.d.ts → utils.d.cts} +8 -14
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +245 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +167 -22
- package/dist/utils.mjs.map +1 -1
- package/package.json +42 -30
- package/react-native.d.ts +3 -1
- package/react-native.js +1 -1
- package/dist/chunk-272IFIK7.mjs +0 -1
- package/dist/chunk-272IFIK7.mjs.map +0 -1
- package/dist/chunk-2D5PGL7S.js +0 -253
- package/dist/chunk-2D5PGL7S.js.map +0 -1
- package/dist/chunk-2SRKMEUV.mjs +0 -92
- package/dist/chunk-2SRKMEUV.mjs.map +0 -1
- package/dist/chunk-2XQD4P2S.mjs +0 -1
- package/dist/chunk-2XQD4P2S.mjs.map +0 -1
- package/dist/chunk-36QDTCDZ.js +0 -276
- package/dist/chunk-36QDTCDZ.js.map +0 -1
- package/dist/chunk-3RNW7OKG.mjs +0 -1
- package/dist/chunk-3RNW7OKG.mjs.map +0 -1
- package/dist/chunk-3WWZDKQL.js +0 -40
- package/dist/chunk-3WWZDKQL.js.map +0 -1
- package/dist/chunk-4CA3O64H.js +0 -13
- package/dist/chunk-4CA3O64H.js.map +0 -1
- package/dist/chunk-4HVWEABQ.mjs +0 -9
- package/dist/chunk-4HVWEABQ.mjs.map +0 -1
- package/dist/chunk-4M2FX2AT.mjs +0 -26
- package/dist/chunk-4M2FX2AT.mjs.map +0 -1
- package/dist/chunk-4URGXJP7.js +0 -1
- package/dist/chunk-4URGXJP7.js.map +0 -1
- package/dist/chunk-6EZSNS4O.mjs +0 -59
- package/dist/chunk-6EZSNS4O.mjs.map +0 -1
- package/dist/chunk-6K4MATNG.js +0 -2548
- package/dist/chunk-6K4MATNG.js.map +0 -1
- package/dist/chunk-6WGCLJGC.mjs +0 -58
- package/dist/chunk-6WGCLJGC.mjs.map +0 -1
- package/dist/chunk-6Z4WDAVC.js +0 -48
- package/dist/chunk-6Z4WDAVC.js.map +0 -1
- package/dist/chunk-7BUNUNUC.js +0 -58
- package/dist/chunk-7BUNUNUC.js.map +0 -1
- package/dist/chunk-7Y6P5FRN.js +0 -60
- package/dist/chunk-7Y6P5FRN.js.map +0 -1
- package/dist/chunk-A6WJEA3C.js +0 -1
- package/dist/chunk-A6WJEA3C.js.map +0 -1
- package/dist/chunk-AP7CJ6DA.js +0 -47
- package/dist/chunk-AP7CJ6DA.js.map +0 -1
- package/dist/chunk-B6KTRDBK.js +0 -127
- package/dist/chunk-B6KTRDBK.js.map +0 -1
- package/dist/chunk-B7R3EWM3.mjs +0 -1
- package/dist/chunk-B7R3EWM3.mjs.map +0 -1
- package/dist/chunk-BAEXVO3U.mjs +0 -1
- package/dist/chunk-BAEXVO3U.mjs.map +0 -1
- package/dist/chunk-BAUQWPSP.mjs +0 -331
- package/dist/chunk-BAUQWPSP.mjs.map +0 -1
- package/dist/chunk-BO2ZDPWV.js +0 -59
- package/dist/chunk-BO2ZDPWV.js.map +0 -1
- package/dist/chunk-BOFPNIRX.js +0 -119
- package/dist/chunk-BOFPNIRX.js.map +0 -1
- package/dist/chunk-C4D6GBMY.js +0 -71
- package/dist/chunk-C4D6GBMY.js.map +0 -1
- package/dist/chunk-D66YLO7T.js +0 -38
- package/dist/chunk-D66YLO7T.js.map +0 -1
- package/dist/chunk-D74XJG2L.js +0 -1
- package/dist/chunk-D74XJG2L.js.map +0 -1
- package/dist/chunk-DSOZPX7I.js +0 -283
- package/dist/chunk-DSOZPX7I.js.map +0 -1
- package/dist/chunk-ESQPQNEF.mjs +0 -1
- package/dist/chunk-ESQPQNEF.mjs.map +0 -1
- package/dist/chunk-EXN2TFDJ.js +0 -38
- package/dist/chunk-EXN2TFDJ.js.map +0 -1
- package/dist/chunk-F3ZMDQ52.mjs +0 -276
- package/dist/chunk-F3ZMDQ52.mjs.map +0 -1
- package/dist/chunk-FX5AADOV.mjs +0 -1
- package/dist/chunk-FX5AADOV.mjs.map +0 -1
- package/dist/chunk-FZOI4WPB.js +0 -82
- package/dist/chunk-FZOI4WPB.js.map +0 -1
- package/dist/chunk-G66GQJS6.js +0 -1
- package/dist/chunk-G66GQJS6.js.map +0 -1
- package/dist/chunk-G7U6WKWS.mjs +0 -1
- package/dist/chunk-G7U6WKWS.mjs.map +0 -1
- package/dist/chunk-HLQQTAMM.mjs +0 -105
- package/dist/chunk-HLQQTAMM.mjs.map +0 -1
- package/dist/chunk-HOY6NKQR.js +0 -1
- package/dist/chunk-HOY6NKQR.js.map +0 -1
- package/dist/chunk-HP6S5IOB.js +0 -1
- package/dist/chunk-HP6S5IOB.js.map +0 -1
- package/dist/chunk-HULNFJMA.mjs +0 -108
- package/dist/chunk-HULNFJMA.mjs.map +0 -1
- package/dist/chunk-HWJE3SDW.mjs +0 -1
- package/dist/chunk-HWJE3SDW.mjs.map +0 -1
- package/dist/chunk-I25KLPIS.js +0 -273
- package/dist/chunk-I25KLPIS.js.map +0 -1
- package/dist/chunk-I5V56NYO.mjs +0 -273
- package/dist/chunk-I5V56NYO.mjs.map +0 -1
- package/dist/chunk-IABOI7TW.mjs +0 -1
- package/dist/chunk-IABOI7TW.mjs.map +0 -1
- package/dist/chunk-IDCWJJCQ.js +0 -1
- package/dist/chunk-IDCWJJCQ.js.map +0 -1
- package/dist/chunk-IGC4E7PI.mjs +0 -71
- package/dist/chunk-IGC4E7PI.mjs.map +0 -1
- package/dist/chunk-JAUAKTUL.js +0 -1
- package/dist/chunk-JAUAKTUL.js.map +0 -1
- package/dist/chunk-JQ54YYLU.js +0 -26
- package/dist/chunk-JQ54YYLU.js.map +0 -1
- package/dist/chunk-JW7WBUL7.js +0 -1
- package/dist/chunk-JW7WBUL7.js.map +0 -1
- package/dist/chunk-K3TNQEM5.js +0 -331
- package/dist/chunk-K3TNQEM5.js.map +0 -1
- package/dist/chunk-KCMULJ2M.mjs +0 -1
- package/dist/chunk-KCMULJ2M.mjs.map +0 -1
- package/dist/chunk-KELDSV7H.js +0 -39
- package/dist/chunk-KELDSV7H.js.map +0 -1
- package/dist/chunk-KRI4OKC3.mjs +0 -127
- package/dist/chunk-KRI4OKC3.mjs.map +0 -1
- package/dist/chunk-KYRKZ3RH.mjs +0 -38
- package/dist/chunk-KYRKZ3RH.mjs.map +0 -1
- package/dist/chunk-LDL6LJ3P.mjs +0 -38
- package/dist/chunk-LDL6LJ3P.mjs.map +0 -1
- package/dist/chunk-M7DWHPVM.js +0 -1
- package/dist/chunk-M7DWHPVM.js.map +0 -1
- package/dist/chunk-NC5PBDKD.mjs +0 -47
- package/dist/chunk-NC5PBDKD.mjs.map +0 -1
- package/dist/chunk-NXZVKBSV.js +0 -9
- package/dist/chunk-NXZVKBSV.js.map +0 -1
- package/dist/chunk-NZOUFWUN.mjs +0 -1
- package/dist/chunk-NZOUFWUN.mjs.map +0 -1
- package/dist/chunk-OHMCPTOI.js +0 -1
- package/dist/chunk-OHMCPTOI.js.map +0 -1
- package/dist/chunk-OIEUL55W.js +0 -1
- package/dist/chunk-OIEUL55W.js.map +0 -1
- package/dist/chunk-OVATPF5I.js +0 -58
- package/dist/chunk-OVATPF5I.js.map +0 -1
- package/dist/chunk-P66VIDFG.js +0 -105
- package/dist/chunk-P66VIDFG.js.map +0 -1
- package/dist/chunk-P7Y6MIZW.mjs +0 -7
- package/dist/chunk-P7Y6MIZW.mjs.map +0 -1
- package/dist/chunk-PYSDWIVK.js +0 -38
- package/dist/chunk-PYSDWIVK.js.map +0 -1
- package/dist/chunk-QL3QGUTM.mjs +0 -1
- package/dist/chunk-QL3QGUTM.mjs.map +0 -1
- package/dist/chunk-QRISQRFI.js +0 -399
- package/dist/chunk-QRISQRFI.js.map +0 -1
- package/dist/chunk-QWN3UOMA.mjs +0 -2548
- package/dist/chunk-QWN3UOMA.mjs.map +0 -1
- package/dist/chunk-RZ2NHZXH.js +0 -108
- package/dist/chunk-RZ2NHZXH.js.map +0 -1
- package/dist/chunk-TG6OXBLR.js +0 -1
- package/dist/chunk-TG6OXBLR.js.map +0 -1
- package/dist/chunk-TIURYSSR.js +0 -92
- package/dist/chunk-TIURYSSR.js.map +0 -1
- package/dist/chunk-TMWMIQV4.js +0 -1
- package/dist/chunk-TMWMIQV4.js.map +0 -1
- package/dist/chunk-TSDUJNOP.mjs +0 -399
- package/dist/chunk-TSDUJNOP.mjs.map +0 -1
- package/dist/chunk-U74FML7Z.mjs +0 -1
- package/dist/chunk-U74FML7Z.mjs.map +0 -1
- package/dist/chunk-UM4NFNEI.mjs +0 -48
- package/dist/chunk-UM4NFNEI.mjs.map +0 -1
- package/dist/chunk-V6NFZ47P.mjs +0 -1
- package/dist/chunk-V6NFZ47P.mjs.map +0 -1
- package/dist/chunk-VKMY6CKT.mjs +0 -39
- package/dist/chunk-VKMY6CKT.mjs.map +0 -1
- package/dist/chunk-VNOCJWOK.js +0 -1
- package/dist/chunk-VNOCJWOK.js.map +0 -1
- package/dist/chunk-WEY7ICES.js +0 -1
- package/dist/chunk-WEY7ICES.js.map +0 -1
- package/dist/chunk-WR7CVDEY.mjs +0 -58
- package/dist/chunk-WR7CVDEY.mjs.map +0 -1
- package/dist/chunk-XO7KDFBY.mjs +0 -119
- package/dist/chunk-XO7KDFBY.mjs.map +0 -1
- package/dist/chunk-XOSHP4J3.mjs +0 -82
- package/dist/chunk-XOSHP4J3.mjs.map +0 -1
- package/dist/chunk-YRZVIDCF.mjs +0 -38
- package/dist/chunk-YRZVIDCF.mjs.map +0 -1
- package/dist/chunk-YYPUPKQY.js +0 -7
- package/dist/chunk-YYPUPKQY.js.map +0 -1
- package/dist/chunk-Z4BUMSH3.mjs +0 -283
- package/dist/chunk-Z4BUMSH3.mjs.map +0 -1
- package/dist/chunk-Z5QWRDUN.mjs +0 -253
- package/dist/chunk-Z5QWRDUN.mjs.map +0 -1
- package/dist/chunk-ZKG6FRKN.mjs +0 -40
- package/dist/chunk-ZQAGLOXD.mjs +0 -1
- package/dist/chunk-ZQAGLOXD.mjs.map +0 -1
- package/dist/chunk-ZVOYOZFT.mjs +0 -60
- package/dist/chunk-ZVOYOZFT.mjs.map +0 -1
- package/dist/chunk-ZZD3HUNE.mjs +0 -13
- package/dist/chunk-ZZD3HUNE.mjs.map +0 -1
- package/dist/cronjob/CronjobController.js +0 -43
- package/dist/cronjob/CronjobController.js.map +0 -1
- package/dist/cronjob/index.js +0 -43
- package/dist/cronjob/index.js.map +0 -1
- package/dist/fsm.js +0 -10
- package/dist/fsm.js.map +0 -1
- package/dist/index.js +0 -125
- package/dist/index.js.map +0 -1
- package/dist/insights/SnapInsightsController.js +0 -25
- package/dist/insights/SnapInsightsController.js.map +0 -1
- package/dist/insights/index.js +0 -26
- package/dist/insights/index.js.map +0 -1
- package/dist/interface/SnapInterfaceController.js +0 -9
- package/dist/interface/SnapInterfaceController.js.map +0 -1
- package/dist/interface/index.js +0 -10
- package/dist/interface/index.js.map +0 -1
- package/dist/interface/utils.js +0 -14
- package/dist/interface/utils.js.map +0 -1
- package/dist/logging.js +0 -8
- package/dist/logging.js.map +0 -1
- package/dist/node.js +0 -135
- package/dist/node.js.map +0 -1
- package/dist/react-native.js +0 -132
- package/dist/react-native.js.map +0 -1
- package/dist/services/AbstractExecutionService.js +0 -13
- package/dist/services/AbstractExecutionService.js.map +0 -1
- package/dist/services/ExecutionService.js +0 -2
- package/dist/services/ExecutionService.js.map +0 -1
- package/dist/services/ProxyPostMessageStream.js +0 -8
- package/dist/services/ProxyPostMessageStream.js.map +0 -1
- package/dist/services/browser.js +0 -40
- package/dist/services/browser.js.map +0 -1
- package/dist/services/iframe/IframeExecutionService.js +0 -12
- package/dist/services/iframe/IframeExecutionService.js.map +0 -1
- package/dist/services/iframe/index.js +0 -13
- package/dist/services/iframe/index.js.map +0 -1
- package/dist/services/index.js +0 -35
- package/dist/services/index.js.map +0 -1
- package/dist/services/node-js/NodeProcessExecutionService.js +0 -22
- package/dist/services/node-js/NodeProcessExecutionService.js.map +0 -1
- package/dist/services/node-js/NodeThreadExecutionService.js +0 -22
- package/dist/services/node-js/NodeThreadExecutionService.js.map +0 -1
- package/dist/services/node-js/index.js +0 -27
- package/dist/services/node-js/index.js.map +0 -1
- package/dist/services/node.js +0 -45
- package/dist/services/node.js.map +0 -1
- package/dist/services/offscreen/OffscreenExecutionService.js +0 -14
- package/dist/services/offscreen/OffscreenExecutionService.js.map +0 -1
- package/dist/services/offscreen/index.js +0 -15
- package/dist/services/offscreen/index.js.map +0 -1
- package/dist/services/proxy/ProxyExecutionService.js +0 -13
- package/dist/services/proxy/ProxyExecutionService.js.map +0 -1
- package/dist/services/react-native.js +0 -42
- package/dist/services/react-native.js.map +0 -1
- package/dist/services/webview/WebViewExecutionService.js +0 -15
- package/dist/services/webview/WebViewExecutionService.js.map +0 -1
- package/dist/services/webview/WebViewMessageStream.js +0 -8
- package/dist/services/webview/WebViewMessageStream.js.map +0 -1
- package/dist/services/webview/index.js +0 -16
- package/dist/services/webview/index.js.map +0 -1
- package/dist/services/webworker/WebWorkerExecutionService.js +0 -15
- package/dist/services/webworker/WebWorkerExecutionService.js.map +0 -1
- package/dist/services/webworker/index.js +0 -16
- package/dist/services/webworker/index.js.map +0 -1
- package/dist/snaps/RequestQueue.js +0 -8
- package/dist/snaps/RequestQueue.js.map +0 -1
- package/dist/snaps/SnapController.js +0 -30
- package/dist/snaps/SnapController.js.map +0 -1
- package/dist/snaps/Timer.js +0 -8
- package/dist/snaps/Timer.js.map +0 -1
- package/dist/snaps/constants.js +0 -10
- package/dist/snaps/constants.js.map +0 -1
- package/dist/snaps/index.js +0 -63
- package/dist/snaps/index.js.map +0 -1
- package/dist/snaps/location/http.js +0 -8
- package/dist/snaps/location/http.js.map +0 -1
- package/dist/snaps/location/index.js +0 -31
- package/dist/snaps/location/index.js.map +0 -1
- package/dist/snaps/location/local.js +0 -9
- package/dist/snaps/location/local.js.map +0 -1
- package/dist/snaps/location/location.js +0 -11
- package/dist/snaps/location/location.js.map +0 -1
- package/dist/snaps/location/npm.js +0 -18
- package/dist/snaps/location/npm.js.map +0 -1
- package/dist/snaps/registry/index.js +0 -13
- package/dist/snaps/registry/index.js.map +0 -1
- package/dist/snaps/registry/json.js +0 -9
- package/dist/snaps/registry/json.js.map +0 -1
- package/dist/snaps/registry/registry.js +0 -8
- package/dist/snaps/registry/registry.js.map +0 -1
- package/dist/snaps/selectors.js +0 -8
- package/dist/snaps/selectors.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/controllers.js +0 -2
- package/dist/types/controllers.js.map +0 -1
- package/dist/types/cronjob/index.d.ts +0 -1
- package/dist/types/encryptor.js +0 -2
- package/dist/types/encryptor.js.map +0 -1
- package/dist/types/index.d.ts +0 -7
- package/dist/types/index.js +0 -3
- package/dist/types/index.js.map +0 -1
- package/dist/types/insights/index.d.ts +0 -1
- package/dist/types/interface/index.d.ts +0 -1
- package/dist/types/node.d.ts +0 -2
- package/dist/types/react-native.d.ts +0 -2
- package/dist/types/services/browser.d.ts +0 -7
- package/dist/types/services/iframe/index.d.ts +0 -1
- package/dist/types/services/index.d.ts +0 -6
- package/dist/types/services/node-js/index.d.ts +0 -2
- package/dist/types/services/node.d.ts +0 -2
- package/dist/types/services/offscreen/index.d.ts +0 -1
- package/dist/types/services/react-native.d.ts +0 -2
- package/dist/types/services/webview/index.d.ts +0 -1
- package/dist/types/services/webworker/index.d.ts +0 -1
- package/dist/types/snaps/index.d.ts +0 -4
- package/dist/types/snaps/location/index.d.ts +0 -4
- package/dist/types/snaps/registry/index.d.ts +0 -2
- package/dist/types/snaps/selectors.d.ts +0 -2
- package/dist/types/types/index.d.ts +0 -2
- package/dist/types/vendor/global.d.js +0 -1
- package/dist/types/vendor/global.d.js.map +0 -1
- package/dist/types/vendor/global.d.mjs +0 -1
- package/dist/types/vendor/global.d.mjs.map +0 -1
- package/dist/types/vendor/readable-stream.d.js +0 -1
- package/dist/types/vendor/readable-stream.d.js.map +0 -1
- package/dist/types/vendor/readable-stream.d.mjs +0 -1
- package/dist/types/vendor/readable-stream.d.mjs.map +0 -1
- package/dist/types/vendor/zlib.d.js +0 -1
- package/dist/types/vendor/zlib.d.js.map +0 -1
- package/dist/types/vendor/zlib.d.mjs +0 -1
- package/dist/types/vendor/zlib.d.mjs.map +0 -1
- package/dist/utils.js +0 -23
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1,1896 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _SnapController_instances, _SnapController_closeAllConnections, _SnapController_dynamicPermissions, _SnapController_environmentEndowmentPermissions, _SnapController_excludedPermissions, _SnapController_featureFlags, _SnapController_fetchFunction, _SnapController_idleTimeCheckInterval, _SnapController_maxIdleTime, _SnapController_encryptor, _SnapController_getMnemonic, _SnapController_getFeatureFlags, _SnapController_detectSnapLocation, _SnapController_snapsRuntimeData, _SnapController_rollbackSnapshots, _SnapController_timeoutForLastRequestStatus, _SnapController_statusMachine, _SnapController_preinstalledSnaps, _SnapController_initializeStateMachine, _SnapController_registerMessageHandlers, _SnapController_handlePreinstalledSnaps, _SnapController_pollForLastRequestStatus, _SnapController_blockSnap, _SnapController_unblockSnap, _SnapController_assertIsInstallAllowed, _SnapController_assertCanInstallSnaps, _SnapController_assertCanUsePlatform, _SnapController_stopSnapsLastRequestPastMax, _SnapController_transition, _SnapController_terminateSnap, _SnapController_getSnapEncryptionKey, _SnapController_decryptSnapState, _SnapController_encryptSnapState, _SnapController_handleInitialConnections, _SnapController_addSnapToSubject, _SnapController_removeSnapFromSubjects, _SnapController_revokeAllSnapPermissions, _SnapController_createApproval, _SnapController_updateApproval, _SnapController_resolveAllowlistVersion, _SnapController_add, _SnapController_startSnap, _SnapController_getEndowments, _SnapController_set, _SnapController_validateSnapPermissions, _SnapController_getExecutionTimeout, _SnapController_getRpcRequestHandler, _SnapController_createInterface, _SnapController_assertInterfaceExists, _SnapController_transformSnapRpcRequestResult, _SnapController_assertSnapRpcRequestResult, _SnapController_recordSnapRpcRequestStart, _SnapController_recordSnapRpcRequestFinish, _SnapController_getRollbackSnapshot, _SnapController_createRollbackSnapshot, _SnapController_rollbackSnap, _SnapController_rollbackSnaps, _SnapController_getRuntime, _SnapController_getRuntimeExpect, _SnapController_setupRuntime, _SnapController_calculatePermissionsChange, _SnapController_isSubjectConnectedToSnap, _SnapController_calculateConnectionsChange, _SnapController_updatePermissions, _SnapController_isValidUpdate, _SnapController_callLifecycleHook;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SnapController = exports.SNAP_APPROVAL_RESULT = exports.SNAP_APPROVAL_UPDATE = exports.SNAP_APPROVAL_INSTALL = exports.controllerName = void 0;
|
|
16
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
+
const permission_controller_1 = require("@metamask/permission-controller");
|
|
18
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
19
|
+
const snaps_rpc_methods_1 = require("@metamask/snaps-rpc-methods");
|
|
20
|
+
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
21
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
22
|
+
const utils_1 = require("@metamask/utils");
|
|
23
|
+
const fsm_1 = require("@xstate/fsm");
|
|
24
|
+
const nanoid_1 = require("nanoid");
|
|
25
|
+
const fsm_2 = require("../fsm.cjs");
|
|
26
|
+
const logging_1 = require("../logging.cjs");
|
|
27
|
+
const utils_2 = require("../utils.cjs");
|
|
28
|
+
const constants_1 = require("./constants.cjs");
|
|
29
|
+
const location_1 = require("./location/index.cjs");
|
|
30
|
+
const registry_1 = require("./registry/index.cjs");
|
|
31
|
+
const RequestQueue_1 = require("./RequestQueue.cjs");
|
|
32
|
+
const Timer_1 = require("./Timer.cjs");
|
|
33
|
+
exports.controllerName = 'SnapController';
|
|
34
|
+
// TODO: Figure out how to name these
|
|
35
|
+
exports.SNAP_APPROVAL_INSTALL = 'wallet_installSnap';
|
|
36
|
+
exports.SNAP_APPROVAL_UPDATE = 'wallet_updateSnap';
|
|
37
|
+
exports.SNAP_APPROVAL_RESULT = 'wallet_installSnapResult';
|
|
38
|
+
const TRUNCATED_SNAP_PROPERTIES = new Set([
|
|
39
|
+
'initialPermissions',
|
|
40
|
+
'id',
|
|
41
|
+
'version',
|
|
42
|
+
'enabled',
|
|
43
|
+
'blocked',
|
|
44
|
+
]);
|
|
45
|
+
const defaultState = {
|
|
46
|
+
snaps: {},
|
|
47
|
+
snapStates: {},
|
|
48
|
+
unencryptedSnapStates: {},
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Truncates the properties of a snap to only ones that are easily serializable.
|
|
52
|
+
*
|
|
53
|
+
* @param snap - The snap to truncate.
|
|
54
|
+
* @returns Object with serializable snap properties.
|
|
55
|
+
*/
|
|
56
|
+
function truncateSnap(snap) {
|
|
57
|
+
const truncatedSnap = Object.keys(snap).reduce((serialized, key) => {
|
|
58
|
+
if (TRUNCATED_SNAP_PROPERTIES.has(key)) {
|
|
59
|
+
serialized[key] = snap[key];
|
|
60
|
+
}
|
|
61
|
+
return serialized;
|
|
62
|
+
}, {});
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
64
|
+
return truncatedSnap;
|
|
65
|
+
}
|
|
66
|
+
const name = 'SnapController';
|
|
67
|
+
/*
|
|
68
|
+
* A snap is initialized in three phases:
|
|
69
|
+
* - Add: Loads the snap from a remote source and parses it.
|
|
70
|
+
* - Authorize: Requests the snap's required permissions from the user.
|
|
71
|
+
* - Start: Initializes the snap in its SES realm with the authorized permissions.
|
|
72
|
+
*/
|
|
73
|
+
class SnapController extends base_controller_1.BaseController {
|
|
74
|
+
constructor({ closeAllConnections, messenger, state, dynamicPermissions = ['eth_accounts'], environmentEndowmentPermissions = [], excludedPermissions = {}, idleTimeCheckInterval = (0, utils_1.inMilliseconds)(5, utils_1.Duration.Second), maxIdleTime = (0, utils_1.inMilliseconds)(30, utils_1.Duration.Second), maxRequestTime = (0, utils_1.inMilliseconds)(60, utils_1.Duration.Second), fetchFunction = globalThis.fetch.bind(undefined), featureFlags = {}, detectSnapLocation: detectSnapLocationFunction = location_1.detectSnapLocation, preinstalledSnaps = null, encryptor, getMnemonic, getFeatureFlags = () => ({}), }) {
|
|
75
|
+
super({
|
|
76
|
+
messenger,
|
|
77
|
+
metadata: {
|
|
78
|
+
snapStates: {
|
|
79
|
+
persist: true,
|
|
80
|
+
anonymous: false,
|
|
81
|
+
},
|
|
82
|
+
unencryptedSnapStates: {
|
|
83
|
+
persist: true,
|
|
84
|
+
anonymous: false,
|
|
85
|
+
},
|
|
86
|
+
snaps: {
|
|
87
|
+
persist: (snaps) => {
|
|
88
|
+
return (Object.values(snaps)
|
|
89
|
+
// We should not persist snaps that are in the installing state,
|
|
90
|
+
// since they haven't completed installation and would be unusable
|
|
91
|
+
.filter((snap) => snap.status !== snaps_utils_1.SnapStatus.Installing)
|
|
92
|
+
.map((snap) => {
|
|
93
|
+
return {
|
|
94
|
+
...snap,
|
|
95
|
+
// At the time state is rehydrated, no snap will be running.
|
|
96
|
+
status: snaps_utils_1.SnapStatus.Stopped,
|
|
97
|
+
};
|
|
98
|
+
})
|
|
99
|
+
.reduce((memo, snap) => {
|
|
100
|
+
memo[snap.id] = snap;
|
|
101
|
+
return memo;
|
|
102
|
+
}, {}));
|
|
103
|
+
},
|
|
104
|
+
anonymous: false,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
name,
|
|
108
|
+
state: {
|
|
109
|
+
...defaultState,
|
|
110
|
+
...state,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
_SnapController_instances.add(this);
|
|
114
|
+
_SnapController_closeAllConnections.set(this, void 0);
|
|
115
|
+
_SnapController_dynamicPermissions.set(this, void 0);
|
|
116
|
+
_SnapController_environmentEndowmentPermissions.set(this, void 0);
|
|
117
|
+
_SnapController_excludedPermissions.set(this, void 0);
|
|
118
|
+
_SnapController_featureFlags.set(this, void 0);
|
|
119
|
+
_SnapController_fetchFunction.set(this, void 0);
|
|
120
|
+
_SnapController_idleTimeCheckInterval.set(this, void 0);
|
|
121
|
+
_SnapController_maxIdleTime.set(this, void 0);
|
|
122
|
+
_SnapController_encryptor.set(this, void 0);
|
|
123
|
+
_SnapController_getMnemonic.set(this, void 0);
|
|
124
|
+
_SnapController_getFeatureFlags.set(this, void 0);
|
|
125
|
+
_SnapController_detectSnapLocation.set(this, void 0);
|
|
126
|
+
_SnapController_snapsRuntimeData.set(this, void 0);
|
|
127
|
+
_SnapController_rollbackSnapshots.set(this, void 0);
|
|
128
|
+
_SnapController_timeoutForLastRequestStatus.set(this, void 0);
|
|
129
|
+
_SnapController_statusMachine.set(this, void 0);
|
|
130
|
+
_SnapController_preinstalledSnaps.set(this, void 0);
|
|
131
|
+
__classPrivateFieldSet(this, _SnapController_closeAllConnections, closeAllConnections, "f");
|
|
132
|
+
__classPrivateFieldSet(this, _SnapController_dynamicPermissions, dynamicPermissions, "f");
|
|
133
|
+
__classPrivateFieldSet(this, _SnapController_environmentEndowmentPermissions, environmentEndowmentPermissions, "f");
|
|
134
|
+
__classPrivateFieldSet(this, _SnapController_excludedPermissions, excludedPermissions, "f");
|
|
135
|
+
__classPrivateFieldSet(this, _SnapController_featureFlags, featureFlags, "f");
|
|
136
|
+
__classPrivateFieldSet(this, _SnapController_fetchFunction, fetchFunction, "f");
|
|
137
|
+
__classPrivateFieldSet(this, _SnapController_idleTimeCheckInterval, idleTimeCheckInterval, "f");
|
|
138
|
+
__classPrivateFieldSet(this, _SnapController_maxIdleTime, maxIdleTime, "f");
|
|
139
|
+
this.maxRequestTime = maxRequestTime;
|
|
140
|
+
__classPrivateFieldSet(this, _SnapController_detectSnapLocation, detectSnapLocationFunction, "f");
|
|
141
|
+
__classPrivateFieldSet(this, _SnapController_encryptor, encryptor, "f");
|
|
142
|
+
__classPrivateFieldSet(this, _SnapController_getMnemonic, getMnemonic, "f");
|
|
143
|
+
__classPrivateFieldSet(this, _SnapController_getFeatureFlags, getFeatureFlags, "f");
|
|
144
|
+
__classPrivateFieldSet(this, _SnapController_preinstalledSnaps, preinstalledSnaps, "f");
|
|
145
|
+
this._onUnhandledSnapError = this._onUnhandledSnapError.bind(this);
|
|
146
|
+
this._onOutboundRequest = this._onOutboundRequest.bind(this);
|
|
147
|
+
this._onOutboundResponse = this._onOutboundResponse.bind(this);
|
|
148
|
+
__classPrivateFieldSet(this, _SnapController_rollbackSnapshots, new Map(), "f");
|
|
149
|
+
__classPrivateFieldSet(this, _SnapController_snapsRuntimeData, new Map(), "f");
|
|
150
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_pollForLastRequestStatus).call(this);
|
|
151
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
152
|
+
this.messagingSystem.subscribe('ExecutionService:unhandledError', this._onUnhandledSnapError);
|
|
153
|
+
this.messagingSystem.subscribe('ExecutionService:outboundRequest', this._onOutboundRequest);
|
|
154
|
+
this.messagingSystem.subscribe('ExecutionService:outboundResponse', this._onOutboundResponse);
|
|
155
|
+
/* eslint-enable @typescript-eslint/unbound-method */
|
|
156
|
+
this.messagingSystem.subscribe('SnapController:snapInstalled', ({ id }, origin) => {
|
|
157
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_callLifecycleHook).call(this, origin, id, snaps_utils_1.HandlerType.OnInstall).catch((error) => {
|
|
158
|
+
(0, snaps_utils_1.logError)(`Error when calling \`onInstall\` lifecycle hook for snap "${id}": ${(0, snaps_sdk_1.getErrorMessage)(error)}`);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
this.messagingSystem.subscribe('SnapController:snapUpdated', ({ id }, _oldVersion, origin) => {
|
|
162
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_callLifecycleHook).call(this, origin, id, snaps_utils_1.HandlerType.OnUpdate).catch((error) => {
|
|
163
|
+
(0, snaps_utils_1.logError)(`Error when calling \`onUpdate\` lifecycle hook for snap "${id}": ${(0, snaps_sdk_1.getErrorMessage)(error)}`);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_initializeStateMachine).call(this);
|
|
167
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_registerMessageHandlers).call(this);
|
|
168
|
+
if (__classPrivateFieldGet(this, _SnapController_preinstalledSnaps, "f")) {
|
|
169
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_handlePreinstalledSnaps).call(this, __classPrivateFieldGet(this, _SnapController_preinstalledSnaps, "f"));
|
|
170
|
+
}
|
|
171
|
+
Object.values(this.state?.snaps ?? {}).forEach((snap) => __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_setupRuntime).call(this, snap.id));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Checks all installed snaps against the block list and
|
|
175
|
+
* blocks/unblocks snaps as appropriate. See {@link SnapController.blockSnap}
|
|
176
|
+
* for more information.
|
|
177
|
+
*/
|
|
178
|
+
async updateBlockedSnaps() {
|
|
179
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertCanUsePlatform).call(this);
|
|
180
|
+
await this.messagingSystem.call('SnapsRegistry:update');
|
|
181
|
+
const blockedSnaps = await this.messagingSystem.call('SnapsRegistry:get', Object.values(this.state.snaps).reduce((blockListArg, snap) => {
|
|
182
|
+
blockListArg[snap.id] = {
|
|
183
|
+
version: snap.version,
|
|
184
|
+
checksum: snap.manifest.source.shasum,
|
|
185
|
+
};
|
|
186
|
+
return blockListArg;
|
|
187
|
+
}, {}));
|
|
188
|
+
await Promise.all(Object.entries(blockedSnaps).map(async ([snapId, { status, reason }]) => {
|
|
189
|
+
if (status === registry_1.SnapsRegistryStatus.Blocked) {
|
|
190
|
+
return __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_blockSnap).call(this, snapId, reason);
|
|
191
|
+
}
|
|
192
|
+
return __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_unblockSnap).call(this, snapId);
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
_onUnhandledSnapError(snapId, _error) {
|
|
196
|
+
this.stopSnap(snapId, snaps_utils_1.SnapStatusEvents.Crash).catch((stopSnapError) => {
|
|
197
|
+
// TODO: Decide how to handle errors.
|
|
198
|
+
(0, snaps_utils_1.logError)(stopSnapError);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
_onOutboundRequest(snapId) {
|
|
202
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
203
|
+
// Ideally we would only pause the pending request that is making the outbound request
|
|
204
|
+
// but right now we don't have a way to know which request initiated the outbound request
|
|
205
|
+
runtime.pendingInboundRequests
|
|
206
|
+
.filter((pendingRequest) => pendingRequest.timer.status === 'running')
|
|
207
|
+
.forEach((pendingRequest) => pendingRequest.timer.pause());
|
|
208
|
+
runtime.pendingOutboundRequests += 1;
|
|
209
|
+
}
|
|
210
|
+
_onOutboundResponse(snapId) {
|
|
211
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
212
|
+
runtime.pendingOutboundRequests -= 1;
|
|
213
|
+
if (runtime.pendingOutboundRequests === 0) {
|
|
214
|
+
runtime.pendingInboundRequests
|
|
215
|
+
.filter((pendingRequest) => pendingRequest.timer.status === 'paused')
|
|
216
|
+
.forEach((pendingRequest) => pendingRequest.timer.resume());
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Starts the given snap. Throws an error if no such snap exists
|
|
221
|
+
* or if it is already running.
|
|
222
|
+
*
|
|
223
|
+
* @param snapId - The id of the Snap to start.
|
|
224
|
+
*/
|
|
225
|
+
async startSnap(snapId) {
|
|
226
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertCanUsePlatform).call(this);
|
|
227
|
+
const snap = this.state.snaps[snapId];
|
|
228
|
+
if (snap.enabled === false) {
|
|
229
|
+
throw new Error(`Snap "${snapId}" is disabled.`);
|
|
230
|
+
}
|
|
231
|
+
await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_startSnap).call(this, {
|
|
232
|
+
snapId,
|
|
233
|
+
sourceCode: snap.sourceCode,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Enables the given snap. A snap can only be started if it is enabled. A snap
|
|
238
|
+
* can only be enabled if it isn't blocked.
|
|
239
|
+
*
|
|
240
|
+
* @param snapId - The id of the Snap to enable.
|
|
241
|
+
*/
|
|
242
|
+
enableSnap(snapId) {
|
|
243
|
+
this.getExpect(snapId);
|
|
244
|
+
if (this.state.snaps[snapId].blocked) {
|
|
245
|
+
throw new Error(`Snap "${snapId}" is blocked and cannot be enabled.`);
|
|
246
|
+
}
|
|
247
|
+
this.update((state) => {
|
|
248
|
+
state.snaps[snapId].enabled = true;
|
|
249
|
+
});
|
|
250
|
+
this.messagingSystem.publish('SnapController:snapEnabled', this.getTruncatedExpect(snapId));
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Disables the given snap. A snap can only be started if it is enabled.
|
|
254
|
+
*
|
|
255
|
+
* @param snapId - The id of the Snap to disable.
|
|
256
|
+
* @returns A promise that resolves once the snap has been disabled.
|
|
257
|
+
*/
|
|
258
|
+
async disableSnap(snapId) {
|
|
259
|
+
if (!this.has(snapId)) {
|
|
260
|
+
throw new Error(`Snap "${snapId}" not found.`);
|
|
261
|
+
}
|
|
262
|
+
this.update((state) => {
|
|
263
|
+
state.snaps[snapId].enabled = false;
|
|
264
|
+
});
|
|
265
|
+
if (this.isRunning(snapId)) {
|
|
266
|
+
await this.stopSnap(snapId, snaps_utils_1.SnapStatusEvents.Stop);
|
|
267
|
+
}
|
|
268
|
+
this.messagingSystem.publish('SnapController:snapDisabled', this.getTruncatedExpect(snapId));
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Stops the given snap, removes all hooks, closes all connections, and
|
|
272
|
+
* terminates its worker.
|
|
273
|
+
*
|
|
274
|
+
* @param snapId - The id of the Snap to stop.
|
|
275
|
+
* @param statusEvent - The Snap status event that caused the snap to be
|
|
276
|
+
* stopped.
|
|
277
|
+
*/
|
|
278
|
+
async stopSnap(snapId, statusEvent = snaps_utils_1.SnapStatusEvents.Stop) {
|
|
279
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntime).call(this, snapId);
|
|
280
|
+
if (!runtime) {
|
|
281
|
+
throw new Error(`The snap "${snapId}" is not running.`);
|
|
282
|
+
}
|
|
283
|
+
// No-op if the Snap is already stopping.
|
|
284
|
+
if (runtime.stopping) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
// Flag that the Snap is actively stopping, this prevents other calls to stopSnap
|
|
288
|
+
// while we are handling termination of the Snap
|
|
289
|
+
runtime.stopping = true;
|
|
290
|
+
try {
|
|
291
|
+
if (this.isRunning(snapId)) {
|
|
292
|
+
__classPrivateFieldGet(this, _SnapController_closeAllConnections, "f")?.call(this, snapId);
|
|
293
|
+
await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_terminateSnap).call(this, snapId);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
// Reset request tracking
|
|
298
|
+
runtime.lastRequest = null;
|
|
299
|
+
runtime.pendingInboundRequests = [];
|
|
300
|
+
runtime.pendingOutboundRequests = 0;
|
|
301
|
+
runtime.stopping = false;
|
|
302
|
+
if (this.isRunning(snapId)) {
|
|
303
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_transition).call(this, snapId, statusEvent);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Stops all running snaps, removes all hooks, closes all connections, and
|
|
309
|
+
* terminates their workers.
|
|
310
|
+
*
|
|
311
|
+
* @param statusEvent - The Snap status event that caused the snap to be
|
|
312
|
+
* stopped.
|
|
313
|
+
*/
|
|
314
|
+
async stopAllSnaps(statusEvent = snaps_utils_1.SnapStatusEvents.Stop) {
|
|
315
|
+
const snaps = Object.values(this.state.snaps).filter((snap) => this.isRunning(snap.id));
|
|
316
|
+
const promises = snaps.map(async (snap) => this.stopSnap(snap.id, statusEvent));
|
|
317
|
+
await Promise.allSettled(promises);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Returns whether the given snap is running.
|
|
321
|
+
* Throws an error if the snap doesn't exist.
|
|
322
|
+
*
|
|
323
|
+
* @param snapId - The id of the Snap to check.
|
|
324
|
+
* @returns `true` if the snap is running, otherwise `false`.
|
|
325
|
+
*/
|
|
326
|
+
isRunning(snapId) {
|
|
327
|
+
return this.getExpect(snapId).status === 'running';
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Returns whether the given snap has been added to state.
|
|
331
|
+
*
|
|
332
|
+
* @param snapId - The id of the Snap to check for.
|
|
333
|
+
* @returns `true` if the snap exists in the controller state, otherwise `false`.
|
|
334
|
+
*/
|
|
335
|
+
has(snapId) {
|
|
336
|
+
return Boolean(this.get(snapId));
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Gets the snap with the given id if it exists, including all data.
|
|
340
|
+
* This should not be used if the snap is to be serializable, as e.g.
|
|
341
|
+
* the snap sourceCode may be quite large.
|
|
342
|
+
*
|
|
343
|
+
* @param snapId - The id of the Snap to get.
|
|
344
|
+
* @returns The entire snap object from the controller state.
|
|
345
|
+
*/
|
|
346
|
+
get(snapId) {
|
|
347
|
+
return this.state.snaps[snapId];
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Gets the snap with the given id, throws if doesn't.
|
|
351
|
+
* This should not be used if the snap is to be serializable, as e.g.
|
|
352
|
+
* the snap sourceCode may be quite large.
|
|
353
|
+
*
|
|
354
|
+
* @see {@link SnapController.get}
|
|
355
|
+
* @throws {@link Error}. If the snap doesn't exist
|
|
356
|
+
* @param snapId - The id of the snap to get.
|
|
357
|
+
* @returns The entire snap object.
|
|
358
|
+
*/
|
|
359
|
+
getExpect(snapId) {
|
|
360
|
+
const snap = this.get(snapId);
|
|
361
|
+
(0, utils_1.assert)(snap !== undefined, new Error(`Snap "${snapId}" not found.`));
|
|
362
|
+
return snap;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Gets the snap with the given id if it exists, excluding any
|
|
366
|
+
* non-serializable or expensive-to-serialize data.
|
|
367
|
+
*
|
|
368
|
+
* @param snapId - The id of the Snap to get.
|
|
369
|
+
* @returns A truncated version of the snap state, that is less expensive to serialize.
|
|
370
|
+
*/
|
|
371
|
+
// TODO(ritave): this.get returns undefined, this.getTruncated returns null
|
|
372
|
+
getTruncated(snapId) {
|
|
373
|
+
const snap = this.get(snapId);
|
|
374
|
+
return snap ? truncateSnap(snap) : null;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Gets the snap with the given id, throw if it doesn't exist.
|
|
378
|
+
*
|
|
379
|
+
* @throws {@link Error}. If snap doesn't exist
|
|
380
|
+
* @param snapId - The id of the snap to get.
|
|
381
|
+
* @returns A truncated version of the snap state, that is less expensive to serialize.
|
|
382
|
+
*/
|
|
383
|
+
getTruncatedExpect(snapId) {
|
|
384
|
+
return truncateSnap(this.getExpect(snapId));
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Updates the own state of the snap with the given id.
|
|
388
|
+
* This is distinct from the state MetaMask uses to manage snaps.
|
|
389
|
+
*
|
|
390
|
+
* @param snapId - The id of the Snap whose state should be updated.
|
|
391
|
+
* @param newSnapState - The new state of the snap.
|
|
392
|
+
* @param encrypted - A flag to indicate whether to use encrypted storage or not.
|
|
393
|
+
*/
|
|
394
|
+
async updateSnapState(snapId, newSnapState, encrypted) {
|
|
395
|
+
if (encrypted) {
|
|
396
|
+
const encryptedState = await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_encryptSnapState).call(this, snapId, newSnapState);
|
|
397
|
+
this.update((state) => {
|
|
398
|
+
state.snapStates[snapId] = encryptedState;
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
this.update((state) => {
|
|
403
|
+
state.unencryptedSnapStates[snapId] = JSON.stringify(newSnapState);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Clears the state of the snap with the given id.
|
|
409
|
+
* This is distinct from the state MetaMask uses to manage snaps.
|
|
410
|
+
*
|
|
411
|
+
* @param snapId - The id of the Snap whose state should be cleared.
|
|
412
|
+
* @param encrypted - A flag to indicate whether to use encrypted storage or not.
|
|
413
|
+
*/
|
|
414
|
+
clearSnapState(snapId, encrypted) {
|
|
415
|
+
this.update((state) => {
|
|
416
|
+
if (encrypted) {
|
|
417
|
+
state.snapStates[snapId] = null;
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
state.unencryptedSnapStates[snapId] = null;
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Gets the own state of the snap with the given id.
|
|
426
|
+
* This is distinct from the state MetaMask uses to manage snaps.
|
|
427
|
+
*
|
|
428
|
+
* @param snapId - The id of the Snap whose state to get.
|
|
429
|
+
* @param encrypted - A flag to indicate whether to use encrypted storage or not.
|
|
430
|
+
* @returns The requested snap state or null if no state exists.
|
|
431
|
+
*/
|
|
432
|
+
async getSnapState(snapId, encrypted) {
|
|
433
|
+
const state = encrypted
|
|
434
|
+
? this.state.snapStates[snapId]
|
|
435
|
+
: this.state.unencryptedSnapStates[snapId];
|
|
436
|
+
if (state === null || state === undefined) {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
if (!encrypted) {
|
|
440
|
+
return (0, snaps_utils_1.parseJson)(state);
|
|
441
|
+
}
|
|
442
|
+
const decrypted = await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_decryptSnapState).call(this, snapId, state);
|
|
443
|
+
return decrypted;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Gets a static auxiliary snap file in a chosen file encoding.
|
|
447
|
+
*
|
|
448
|
+
* @param snapId - The id of the Snap whose state to get.
|
|
449
|
+
* @param path - The path to the requested file.
|
|
450
|
+
* @param encoding - An optional requested file encoding.
|
|
451
|
+
* @returns The file requested in the chosen file encoding or null if the file is not found.
|
|
452
|
+
*/
|
|
453
|
+
async getSnapFile(snapId, path, encoding = snaps_sdk_1.AuxiliaryFileEncoding.Base64) {
|
|
454
|
+
const snap = this.getExpect(snapId);
|
|
455
|
+
const normalizedPath = (0, snaps_utils_1.normalizeRelative)(path);
|
|
456
|
+
const value = snap.auxiliaryFiles?.find((file) => file.path === normalizedPath)?.value;
|
|
457
|
+
if (!value) {
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
const encoded = await (0, snaps_utils_1.encodeAuxiliaryFile)(value, encoding);
|
|
461
|
+
(0, utils_1.assert)(encoded.length < snaps_utils_1.MAX_FILE_SIZE, `Failed to encode static file to "${encoding}": Static files must be less than 64 MB when encoded.`);
|
|
462
|
+
return encoded;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Completely clear the controller's state: delete all associated data,
|
|
466
|
+
* handlers, event listeners, and permissions; tear down all snap providers.
|
|
467
|
+
*/
|
|
468
|
+
async clearState() {
|
|
469
|
+
const snapIds = Object.keys(this.state.snaps);
|
|
470
|
+
if (__classPrivateFieldGet(this, _SnapController_closeAllConnections, "f")) {
|
|
471
|
+
snapIds.forEach((snapId) => {
|
|
472
|
+
__classPrivateFieldGet(this, _SnapController_closeAllConnections, "f")?.call(this, snapId);
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
await this.messagingSystem.call('ExecutionService:terminateAllSnaps');
|
|
476
|
+
snapIds.forEach((snapId) => __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_revokeAllSnapPermissions).call(this, snapId));
|
|
477
|
+
this.update((state) => {
|
|
478
|
+
state.snaps = {};
|
|
479
|
+
state.snapStates = {};
|
|
480
|
+
});
|
|
481
|
+
__classPrivateFieldGet(this, _SnapController_snapsRuntimeData, "f").clear();
|
|
482
|
+
// We want to remove all snaps & permissions, except for preinstalled snaps
|
|
483
|
+
if (__classPrivateFieldGet(this, _SnapController_preinstalledSnaps, "f")) {
|
|
484
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_handlePreinstalledSnaps).call(this, __classPrivateFieldGet(this, _SnapController_preinstalledSnaps, "f"));
|
|
485
|
+
Object.values(this.state?.snaps).forEach((snap) => __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_setupRuntime).call(this, snap.id));
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Removes the given snap from state, and clears all associated handlers
|
|
490
|
+
* and listeners.
|
|
491
|
+
*
|
|
492
|
+
* @param snapId - The id of the Snap.
|
|
493
|
+
* @returns A promise that resolves once the snap has been removed.
|
|
494
|
+
*/
|
|
495
|
+
async removeSnap(snapId) {
|
|
496
|
+
return this.removeSnaps([snapId]);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Stops the given snaps, removes them from state, and clears all associated
|
|
500
|
+
* permissions, handlers, and listeners.
|
|
501
|
+
*
|
|
502
|
+
* @param snapIds - The ids of the Snaps.
|
|
503
|
+
*/
|
|
504
|
+
async removeSnaps(snapIds) {
|
|
505
|
+
if (!Array.isArray(snapIds)) {
|
|
506
|
+
throw new Error('Expected array of snap ids.');
|
|
507
|
+
}
|
|
508
|
+
snapIds.forEach((snapId) => {
|
|
509
|
+
const snap = this.getExpect(snapId);
|
|
510
|
+
(0, utils_1.assert)(snap.removable !== false, `${snapId} is not removable.`);
|
|
511
|
+
});
|
|
512
|
+
await Promise.all(snapIds.map(async (snapId) => {
|
|
513
|
+
const snap = this.getExpect(snapId);
|
|
514
|
+
const truncated = this.getTruncatedExpect(snapId);
|
|
515
|
+
// Disable the snap and revoke all of its permissions before deleting
|
|
516
|
+
// it. This ensures that the snap will not be restarted or otherwise
|
|
517
|
+
// affect the host environment while we are deleting it.
|
|
518
|
+
await this.disableSnap(snapId);
|
|
519
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_revokeAllSnapPermissions).call(this, snapId);
|
|
520
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_removeSnapFromSubjects).call(this, snapId);
|
|
521
|
+
__classPrivateFieldGet(this, _SnapController_snapsRuntimeData, "f").delete(snapId);
|
|
522
|
+
this.update((state) => {
|
|
523
|
+
delete state.snaps[snapId];
|
|
524
|
+
delete state.snapStates[snapId];
|
|
525
|
+
delete state.unencryptedSnapStates[snapId];
|
|
526
|
+
});
|
|
527
|
+
// If the snap has been fully installed before, also emit snapUninstalled.
|
|
528
|
+
if (snap.status !== snaps_utils_1.SnapStatus.Installing) {
|
|
529
|
+
this.messagingSystem.publish(`SnapController:snapUninstalled`, truncated);
|
|
530
|
+
}
|
|
531
|
+
}));
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Removes a snap's permission (caveat) from the specified subject.
|
|
535
|
+
*
|
|
536
|
+
* @param origin - The origin from which to remove the snap.
|
|
537
|
+
* @param snapId - The id of the snap to remove.
|
|
538
|
+
*/
|
|
539
|
+
removeSnapFromSubject(origin, snapId) {
|
|
540
|
+
const subjectPermissions = this.messagingSystem.call('PermissionController:getPermissions', origin);
|
|
541
|
+
const snapIdsCaveat = subjectPermissions?.[snaps_rpc_methods_1.WALLET_SNAP_PERMISSION_KEY]?.caveats?.find((caveat) => caveat.type === snaps_utils_1.SnapCaveatType.SnapIds);
|
|
542
|
+
if (!snapIdsCaveat) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
const caveatHasSnap = Boolean(snapIdsCaveat.value?.[snapId]);
|
|
546
|
+
if (caveatHasSnap) {
|
|
547
|
+
const newCaveatValue = {
|
|
548
|
+
...snapIdsCaveat.value,
|
|
549
|
+
};
|
|
550
|
+
delete newCaveatValue[snapId];
|
|
551
|
+
if (Object.keys(newCaveatValue).length > 0) {
|
|
552
|
+
this.messagingSystem.call('PermissionController:updateCaveat', origin, snaps_rpc_methods_1.WALLET_SNAP_PERMISSION_KEY, snaps_utils_1.SnapCaveatType.SnapIds, newCaveatValue);
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
this.messagingSystem.call('PermissionController:revokePermissions', {
|
|
556
|
+
[origin]: [snaps_rpc_methods_1.WALLET_SNAP_PERMISSION_KEY],
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Checks if a list of permissions are dynamic and allowed to be revoked, if they are they will all be revoked.
|
|
563
|
+
*
|
|
564
|
+
* @param snapId - The snap ID.
|
|
565
|
+
* @param permissionNames - The names of the permissions.
|
|
566
|
+
* @throws If non-dynamic permissions are passed.
|
|
567
|
+
*/
|
|
568
|
+
revokeDynamicSnapPermissions(snapId, permissionNames) {
|
|
569
|
+
(0, utils_1.assert)(permissionNames.every((permissionName) => __classPrivateFieldGet(this, _SnapController_dynamicPermissions, "f").includes(permissionName)), 'Non-dynamic permissions cannot be revoked');
|
|
570
|
+
this.messagingSystem.call('PermissionController:revokePermissions', {
|
|
571
|
+
[snapId]: permissionNames,
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Handles incrementing the activeReferences counter.
|
|
576
|
+
*
|
|
577
|
+
* @param snapId - The snap id of the snap that was referenced.
|
|
578
|
+
*/
|
|
579
|
+
incrementActiveReferences(snapId) {
|
|
580
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
581
|
+
runtime.activeReferences += 1;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Handles decrement the activeReferences counter.
|
|
585
|
+
*
|
|
586
|
+
* @param snapId - The snap id of the snap that was referenced..
|
|
587
|
+
*/
|
|
588
|
+
decrementActiveReferences(snapId) {
|
|
589
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
590
|
+
(0, utils_1.assert)(runtime.activeReferences > 0, 'SnapController reference management is in an invalid state.');
|
|
591
|
+
runtime.activeReferences -= 1;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Gets all snaps in their truncated format.
|
|
595
|
+
*
|
|
596
|
+
* @returns All installed snaps in their truncated format.
|
|
597
|
+
*/
|
|
598
|
+
getAllSnaps() {
|
|
599
|
+
return Object.values(this.state.snaps).map(truncateSnap);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Gets the serialized permitted snaps of the given origin, if any.
|
|
603
|
+
*
|
|
604
|
+
* @param origin - The origin whose permitted snaps to retrieve.
|
|
605
|
+
* @returns The serialized permitted snaps for the origin.
|
|
606
|
+
*/
|
|
607
|
+
getPermittedSnaps(origin) {
|
|
608
|
+
const permissions = this.messagingSystem.call('PermissionController:getPermissions', origin) ?? {};
|
|
609
|
+
const snaps = permissions[snaps_rpc_methods_1.WALLET_SNAP_PERMISSION_KEY]?.caveats?.find((caveat) => caveat.type === snaps_utils_1.SnapCaveatType.SnapIds)?.value ?? {};
|
|
610
|
+
return Object.keys(snaps).reduce((permittedSnaps, snapId) => {
|
|
611
|
+
const snap = this.get(snapId);
|
|
612
|
+
const truncatedSnap = this.getTruncated(snapId);
|
|
613
|
+
if (truncatedSnap && snap?.status !== snaps_utils_1.SnapStatus.Installing) {
|
|
614
|
+
permittedSnaps[snapId] = truncatedSnap;
|
|
615
|
+
}
|
|
616
|
+
return permittedSnaps;
|
|
617
|
+
}, {});
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Installs the snaps requested by the given origin, returning the snap
|
|
621
|
+
* object if the origin is permitted to install it, and an authorization error
|
|
622
|
+
* otherwise.
|
|
623
|
+
*
|
|
624
|
+
* @param origin - The origin that requested to install the snaps.
|
|
625
|
+
* @param requestedSnaps - The snaps to install.
|
|
626
|
+
* @returns An object of snap ids and snap objects, or errors if a
|
|
627
|
+
* snap couldn't be installed.
|
|
628
|
+
*/
|
|
629
|
+
async installSnaps(origin, requestedSnaps) {
|
|
630
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertCanUsePlatform).call(this);
|
|
631
|
+
const result = {};
|
|
632
|
+
const snapIds = Object.keys(requestedSnaps);
|
|
633
|
+
const pendingUpdates = [];
|
|
634
|
+
const pendingInstalls = [];
|
|
635
|
+
try {
|
|
636
|
+
for (const [snapId, { version: rawVersion }] of Object.entries(requestedSnaps)) {
|
|
637
|
+
(0, snaps_utils_1.assertIsValidSnapId)(snapId);
|
|
638
|
+
const [error, version] = (0, snaps_utils_1.resolveVersionRange)(rawVersion);
|
|
639
|
+
if (error) {
|
|
640
|
+
throw rpc_errors_1.rpcErrors.invalidParams(`The "version" field must be a valid SemVer version range if specified. Received: "${rawVersion}".`);
|
|
641
|
+
}
|
|
642
|
+
const location = __classPrivateFieldGet(this, _SnapController_detectSnapLocation, "f").call(this, snapId, {
|
|
643
|
+
versionRange: version,
|
|
644
|
+
fetch: __classPrivateFieldGet(this, _SnapController_fetchFunction, "f"),
|
|
645
|
+
allowLocal: __classPrivateFieldGet(this, _SnapController_featureFlags, "f").allowLocalSnaps,
|
|
646
|
+
resolveVersion: async (range) => __classPrivateFieldGet(this, _SnapController_featureFlags, "f").requireAllowlist
|
|
647
|
+
? await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_resolveAllowlistVersion).call(this, snapId, range)
|
|
648
|
+
: range,
|
|
649
|
+
});
|
|
650
|
+
// Existing snaps may need to be updated, unless they should be re-installed (e.g. local snaps)
|
|
651
|
+
// Everything else is treated as an install
|
|
652
|
+
const isUpdate = this.has(snapId) && !location.shouldAlwaysReload;
|
|
653
|
+
if (isUpdate && __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_isValidUpdate).call(this, snapId, version)) {
|
|
654
|
+
const existingSnap = this.getExpect(snapId);
|
|
655
|
+
pendingUpdates.push({ snapId, oldVersion: existingSnap.version });
|
|
656
|
+
let rollbackSnapshot = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRollbackSnapshot).call(this, snapId);
|
|
657
|
+
if (rollbackSnapshot === undefined) {
|
|
658
|
+
rollbackSnapshot = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_createRollbackSnapshot).call(this, snapId);
|
|
659
|
+
rollbackSnapshot.newVersion = version;
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
throw new Error('This snap is already being updated.');
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
else if (!isUpdate) {
|
|
666
|
+
pendingInstalls.push(snapId);
|
|
667
|
+
}
|
|
668
|
+
result[snapId] = await this.processRequestedSnap(origin, snapId, location, version);
|
|
669
|
+
}
|
|
670
|
+
// Once we finish all installs / updates, emit events.
|
|
671
|
+
pendingInstalls.forEach((snapId) => this.messagingSystem.publish(`SnapController:snapInstalled`, this.getTruncatedExpect(snapId), origin));
|
|
672
|
+
pendingUpdates.forEach(({ snapId, oldVersion }) => this.messagingSystem.publish(`SnapController:snapUpdated`, this.getTruncatedExpect(snapId), oldVersion, origin));
|
|
673
|
+
snapIds.forEach((snapId) => __classPrivateFieldGet(this, _SnapController_rollbackSnapshots, "f").delete(snapId));
|
|
674
|
+
}
|
|
675
|
+
catch (error) {
|
|
676
|
+
const installed = pendingInstalls.filter((snapId) => this.has(snapId));
|
|
677
|
+
await this.removeSnaps(installed);
|
|
678
|
+
const snapshottedSnaps = [...__classPrivateFieldGet(this, _SnapController_rollbackSnapshots, "f").keys()];
|
|
679
|
+
const snapsToRollback = pendingUpdates
|
|
680
|
+
.map(({ snapId }) => snapId)
|
|
681
|
+
.filter((snapId) => snapshottedSnaps.includes(snapId));
|
|
682
|
+
await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_rollbackSnaps).call(this, snapsToRollback);
|
|
683
|
+
throw error;
|
|
684
|
+
}
|
|
685
|
+
return result;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Adds, authorizes, and runs the given snap with a snap provider.
|
|
689
|
+
* Results from this method should be efficiently serializable.
|
|
690
|
+
*
|
|
691
|
+
* @param origin - The origin requesting the snap.
|
|
692
|
+
* @param snapId - The id of the snap.
|
|
693
|
+
* @param location - The location implementation of the snap.
|
|
694
|
+
* @param versionRange - The semver range of the snap to install.
|
|
695
|
+
* @returns The resulting snap object, or an error if something went wrong.
|
|
696
|
+
*/
|
|
697
|
+
async processRequestedSnap(origin, snapId, location, versionRange) {
|
|
698
|
+
const existingSnap = this.getTruncated(snapId);
|
|
699
|
+
// For devX we always re-install local snaps.
|
|
700
|
+
if (existingSnap && !location.shouldAlwaysReload) {
|
|
701
|
+
if ((0, utils_1.satisfiesVersionRange)(existingSnap.version, versionRange)) {
|
|
702
|
+
return existingSnap;
|
|
703
|
+
}
|
|
704
|
+
return await this.updateSnap(origin, snapId, location, versionRange,
|
|
705
|
+
// Since we are requesting an update from within processRequestedSnap,
|
|
706
|
+
// we disable the emitting of the snapUpdated event and rely on the caller
|
|
707
|
+
// to publish this event after the update is complete.
|
|
708
|
+
// This is necessary as installSnaps may be installing multiple snaps
|
|
709
|
+
// and we don't want to emit events prematurely.
|
|
710
|
+
false);
|
|
711
|
+
}
|
|
712
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertCanInstallSnaps).call(this);
|
|
713
|
+
let pendingApproval = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_createApproval).call(this, {
|
|
714
|
+
origin,
|
|
715
|
+
snapId,
|
|
716
|
+
type: exports.SNAP_APPROVAL_INSTALL,
|
|
717
|
+
});
|
|
718
|
+
this.messagingSystem.publish('SnapController:snapInstallStarted', snapId, origin, false);
|
|
719
|
+
// Existing snaps must be stopped before overwriting
|
|
720
|
+
if (existingSnap && this.isRunning(snapId)) {
|
|
721
|
+
await this.stopSnap(snapId, snaps_utils_1.SnapStatusEvents.Stop);
|
|
722
|
+
}
|
|
723
|
+
// Existing snaps that should be re-installed should not maintain their existing permissions
|
|
724
|
+
if (existingSnap && location.shouldAlwaysReload) {
|
|
725
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_revokeAllSnapPermissions).call(this, snapId);
|
|
726
|
+
}
|
|
727
|
+
try {
|
|
728
|
+
const { sourceCode } = await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_add).call(this, {
|
|
729
|
+
origin,
|
|
730
|
+
id: snapId,
|
|
731
|
+
location,
|
|
732
|
+
versionRange,
|
|
733
|
+
});
|
|
734
|
+
await this.authorize(snapId, pendingApproval);
|
|
735
|
+
pendingApproval = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_createApproval).call(this, {
|
|
736
|
+
origin,
|
|
737
|
+
snapId,
|
|
738
|
+
type: exports.SNAP_APPROVAL_RESULT,
|
|
739
|
+
});
|
|
740
|
+
await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_startSnap).call(this, {
|
|
741
|
+
snapId,
|
|
742
|
+
sourceCode,
|
|
743
|
+
});
|
|
744
|
+
const truncated = this.getTruncatedExpect(snapId);
|
|
745
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_updateApproval).call(this, pendingApproval.id, {
|
|
746
|
+
loading: false,
|
|
747
|
+
type: exports.SNAP_APPROVAL_INSTALL,
|
|
748
|
+
});
|
|
749
|
+
return truncated;
|
|
750
|
+
}
|
|
751
|
+
catch (error) {
|
|
752
|
+
(0, snaps_utils_1.logError)(`Error when adding ${snapId}.`, error);
|
|
753
|
+
const errorString = error instanceof Error ? error.message : error.toString();
|
|
754
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_updateApproval).call(this, pendingApproval.id, {
|
|
755
|
+
loading: false,
|
|
756
|
+
type: exports.SNAP_APPROVAL_INSTALL,
|
|
757
|
+
error: errorString,
|
|
758
|
+
});
|
|
759
|
+
this.messagingSystem.publish('SnapController:snapInstallFailed', snapId, origin, false, errorString);
|
|
760
|
+
throw error;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Updates an installed snap. The flow is similar to
|
|
765
|
+
* {@link SnapController.installSnaps}. The user will be asked if they want
|
|
766
|
+
* to update, then approve any permission changes, and finally the snap will
|
|
767
|
+
* be restarted.
|
|
768
|
+
*
|
|
769
|
+
* The update will fail if the user rejects any prompt or if the new version
|
|
770
|
+
* of the snap is blocked.
|
|
771
|
+
*
|
|
772
|
+
* If the original version of the snap was blocked and the update succeeded,
|
|
773
|
+
* the snap will be unblocked and enabled before it is restarted.
|
|
774
|
+
*
|
|
775
|
+
* @param origin - The origin requesting the snap update.
|
|
776
|
+
* @param snapId - The id of the Snap to be updated.
|
|
777
|
+
* @param location - The location implementation of the snap.
|
|
778
|
+
* @param newVersionRange - A semver version range in which the maximum version will be chosen.
|
|
779
|
+
* @param emitEvent - An optional boolean flag to indicate whether this update should emit an event.
|
|
780
|
+
* @returns The snap metadata if updated, `null` otherwise.
|
|
781
|
+
*/
|
|
782
|
+
async updateSnap(origin, snapId, location, newVersionRange = snaps_utils_1.DEFAULT_REQUESTED_SNAP_VERSION, emitEvent = true) {
|
|
783
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertCanInstallSnaps).call(this);
|
|
784
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertCanUsePlatform).call(this);
|
|
785
|
+
if (!(0, utils_1.isValidSemVerRange)(newVersionRange)) {
|
|
786
|
+
throw new Error(`Received invalid snap version range: "${newVersionRange}".`);
|
|
787
|
+
}
|
|
788
|
+
let pendingApproval = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_createApproval).call(this, {
|
|
789
|
+
origin,
|
|
790
|
+
snapId,
|
|
791
|
+
type: exports.SNAP_APPROVAL_UPDATE,
|
|
792
|
+
});
|
|
793
|
+
try {
|
|
794
|
+
this.messagingSystem.publish('SnapController:snapInstallStarted', snapId, origin, true);
|
|
795
|
+
const snap = this.getExpect(snapId);
|
|
796
|
+
const oldManifest = snap.manifest;
|
|
797
|
+
const newSnap = await (0, utils_2.fetchSnap)(snapId, location);
|
|
798
|
+
const { sourceCode: sourceCodeFile, manifest: manifestFile } = newSnap;
|
|
799
|
+
const manifest = manifestFile.result;
|
|
800
|
+
const newVersion = manifest.version;
|
|
801
|
+
if (!(0, utils_1.gtVersion)(newVersion, snap.version)) {
|
|
802
|
+
throw rpc_errors_1.rpcErrors.invalidParams(`Snap "${snapId}@${snap.version}" is already installed. Couldn't update to a version inside requested "${newVersionRange}" range.`);
|
|
803
|
+
}
|
|
804
|
+
if (!(0, utils_1.satisfiesVersionRange)(newVersion, newVersionRange)) {
|
|
805
|
+
throw new Error(`Version mismatch. Manifest for "${snapId}" specifies version "${newVersion}" which doesn't satisfy requested version range "${newVersionRange}".`);
|
|
806
|
+
}
|
|
807
|
+
await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertIsInstallAllowed).call(this, snapId, {
|
|
808
|
+
version: newVersion,
|
|
809
|
+
checksum: manifest.source.shasum,
|
|
810
|
+
permissions: manifest.initialPermissions,
|
|
811
|
+
});
|
|
812
|
+
const processedPermissions = (0, snaps_rpc_methods_1.processSnapPermissions)(manifest.initialPermissions);
|
|
813
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_validateSnapPermissions).call(this, processedPermissions);
|
|
814
|
+
const { newPermissions, unusedPermissions, approvedPermissions } = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_calculatePermissionsChange).call(this, snapId, processedPermissions);
|
|
815
|
+
const { newConnections, unusedConnections, approvedConnections } = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_calculateConnectionsChange).call(this, snapId, oldManifest.initialConnections ?? {}, manifest.initialConnections ?? {});
|
|
816
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_updateApproval).call(this, pendingApproval.id, {
|
|
817
|
+
permissions: newPermissions,
|
|
818
|
+
newVersion: manifest.version,
|
|
819
|
+
newPermissions,
|
|
820
|
+
approvedPermissions,
|
|
821
|
+
unusedPermissions,
|
|
822
|
+
newConnections,
|
|
823
|
+
unusedConnections,
|
|
824
|
+
approvedConnections,
|
|
825
|
+
loading: false,
|
|
826
|
+
});
|
|
827
|
+
const { permissions: approvedNewPermissions, ...requestData } = (await pendingApproval.promise);
|
|
828
|
+
pendingApproval = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_createApproval).call(this, {
|
|
829
|
+
origin,
|
|
830
|
+
snapId,
|
|
831
|
+
type: exports.SNAP_APPROVAL_RESULT,
|
|
832
|
+
});
|
|
833
|
+
if (this.isRunning(snapId)) {
|
|
834
|
+
await this.stopSnap(snapId, snaps_utils_1.SnapStatusEvents.Stop);
|
|
835
|
+
}
|
|
836
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_transition).call(this, snapId, snaps_utils_1.SnapStatusEvents.Update);
|
|
837
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_set).call(this, {
|
|
838
|
+
origin,
|
|
839
|
+
id: snapId,
|
|
840
|
+
files: newSnap,
|
|
841
|
+
isUpdate: true,
|
|
842
|
+
});
|
|
843
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_updatePermissions).call(this, {
|
|
844
|
+
snapId,
|
|
845
|
+
unusedPermissions,
|
|
846
|
+
newPermissions: approvedNewPermissions,
|
|
847
|
+
requestData,
|
|
848
|
+
});
|
|
849
|
+
if (manifest.initialConnections) {
|
|
850
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_handleInitialConnections).call(this, snapId, oldManifest.initialConnections ?? null, manifest.initialConnections);
|
|
851
|
+
}
|
|
852
|
+
const rollbackSnapshot = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRollbackSnapshot).call(this, snapId);
|
|
853
|
+
if (rollbackSnapshot !== undefined) {
|
|
854
|
+
rollbackSnapshot.permissions.revoked = unusedPermissions;
|
|
855
|
+
rollbackSnapshot.permissions.granted = approvedNewPermissions;
|
|
856
|
+
rollbackSnapshot.permissions.requestData = requestData;
|
|
857
|
+
}
|
|
858
|
+
const sourceCode = sourceCodeFile.toString();
|
|
859
|
+
(0, utils_1.assert)(typeof sourceCode === 'string' && sourceCode.length > 0, `Invalid source code for snap "${snapId}".`);
|
|
860
|
+
try {
|
|
861
|
+
await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_startSnap).call(this, { snapId, sourceCode });
|
|
862
|
+
}
|
|
863
|
+
catch {
|
|
864
|
+
throw new Error(`Snap ${snapId} crashed with updated source code.`);
|
|
865
|
+
}
|
|
866
|
+
const truncatedSnap = this.getTruncatedExpect(snapId);
|
|
867
|
+
if (emitEvent) {
|
|
868
|
+
this.messagingSystem.publish('SnapController:snapUpdated', truncatedSnap, snap.version, origin);
|
|
869
|
+
}
|
|
870
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_updateApproval).call(this, pendingApproval.id, {
|
|
871
|
+
loading: false,
|
|
872
|
+
type: exports.SNAP_APPROVAL_UPDATE,
|
|
873
|
+
});
|
|
874
|
+
return truncatedSnap;
|
|
875
|
+
}
|
|
876
|
+
catch (error) {
|
|
877
|
+
(0, snaps_utils_1.logError)(`Error when updating ${snapId},`, error);
|
|
878
|
+
const errorString = error instanceof Error ? error.message : error.toString();
|
|
879
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_updateApproval).call(this, pendingApproval.id, {
|
|
880
|
+
loading: false,
|
|
881
|
+
error: errorString,
|
|
882
|
+
type: exports.SNAP_APPROVAL_UPDATE,
|
|
883
|
+
});
|
|
884
|
+
this.messagingSystem.publish('SnapController:snapInstallFailed', snapId, origin, true, errorString);
|
|
885
|
+
throw error;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Get metadata for the given snap ID.
|
|
890
|
+
*
|
|
891
|
+
* @param snapId - The ID of the snap to get metadata for.
|
|
892
|
+
* @returns The metadata for the given snap ID, or `null` if the snap is not
|
|
893
|
+
* verified.
|
|
894
|
+
*/
|
|
895
|
+
async getRegistryMetadata(snapId) {
|
|
896
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertCanUsePlatform).call(this);
|
|
897
|
+
return await this.messagingSystem.call('SnapsRegistry:getMetadata', snapId);
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Initiates a request for the given snap's initial permissions.
|
|
901
|
+
* Must be called in order. See processRequestedSnap.
|
|
902
|
+
*
|
|
903
|
+
* This function is not hash private yet because of tests.
|
|
904
|
+
*
|
|
905
|
+
* @param snapId - The id of the Snap.
|
|
906
|
+
* @param pendingApproval - Pending approval to update.
|
|
907
|
+
* @returns The snap's approvedPermissions.
|
|
908
|
+
*/
|
|
909
|
+
async authorize(snapId, pendingApproval) {
|
|
910
|
+
(0, logging_1.log)(`Authorizing snap: ${snapId}`);
|
|
911
|
+
const snapsState = this.state.snaps;
|
|
912
|
+
const snap = snapsState[snapId];
|
|
913
|
+
const { initialPermissions, initialConnections } = snap;
|
|
914
|
+
try {
|
|
915
|
+
const processedPermissions = (0, snaps_rpc_methods_1.processSnapPermissions)(initialPermissions);
|
|
916
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_validateSnapPermissions).call(this, processedPermissions);
|
|
917
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_updateApproval).call(this, pendingApproval.id, {
|
|
918
|
+
loading: false,
|
|
919
|
+
connections: initialConnections ?? {},
|
|
920
|
+
permissions: processedPermissions,
|
|
921
|
+
});
|
|
922
|
+
const { permissions: approvedPermissions, ...requestData } = (await pendingApproval.promise);
|
|
923
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_updatePermissions).call(this, {
|
|
924
|
+
snapId,
|
|
925
|
+
newPermissions: approvedPermissions,
|
|
926
|
+
requestData,
|
|
927
|
+
});
|
|
928
|
+
if (snap.manifest.initialConnections) {
|
|
929
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_handleInitialConnections).call(this, snapId, null, snap.manifest.initialConnections);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
finally {
|
|
933
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
934
|
+
runtime.installPromise = null;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
destroy() {
|
|
938
|
+
super.destroy();
|
|
939
|
+
if (__classPrivateFieldGet(this, _SnapController_timeoutForLastRequestStatus, "f")) {
|
|
940
|
+
clearTimeout(__classPrivateFieldGet(this, _SnapController_timeoutForLastRequestStatus, "f"));
|
|
941
|
+
}
|
|
942
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
943
|
+
this.messagingSystem.unsubscribe('ExecutionService:unhandledError', this._onUnhandledSnapError);
|
|
944
|
+
this.messagingSystem.unsubscribe('ExecutionService:outboundRequest', this._onOutboundRequest);
|
|
945
|
+
this.messagingSystem.unsubscribe('ExecutionService:outboundResponse', this._onOutboundResponse);
|
|
946
|
+
this.messagingSystem.clearEventSubscriptions('SnapController:snapInstalled');
|
|
947
|
+
this.messagingSystem.clearEventSubscriptions('SnapController:snapUpdated');
|
|
948
|
+
/* eslint-enable @typescript-eslint/unbound-method */
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Passes a JSON-RPC request object to the RPC handler function of a snap.
|
|
952
|
+
*
|
|
953
|
+
* @param options - A bag of options.
|
|
954
|
+
* @param options.snapId - The ID of the recipient snap.
|
|
955
|
+
* @param options.origin - The origin of the RPC request.
|
|
956
|
+
* @param options.handler - The handler to trigger on the snap for the request.
|
|
957
|
+
* @param options.request - The JSON-RPC request object.
|
|
958
|
+
* @returns The result of the JSON-RPC request.
|
|
959
|
+
*/
|
|
960
|
+
async handleRequest({ snapId, origin, handler: handlerType, request: rawRequest, }) {
|
|
961
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertCanUsePlatform).call(this);
|
|
962
|
+
const request = {
|
|
963
|
+
jsonrpc: '2.0',
|
|
964
|
+
id: (0, nanoid_1.nanoid)(),
|
|
965
|
+
...rawRequest,
|
|
966
|
+
};
|
|
967
|
+
(0, utils_1.assertIsJsonRpcRequest)(request);
|
|
968
|
+
const permissionName = snaps_rpc_methods_1.handlerEndowments[handlerType];
|
|
969
|
+
(0, utils_1.assert)(typeof permissionName === 'string' || permissionName === null, "'permissionName' must be either a string or null.");
|
|
970
|
+
const permissions = this.messagingSystem.call('PermissionController:getPermissions', snapId);
|
|
971
|
+
// If permissionName is null, the handler does not require a permission.
|
|
972
|
+
if (permissionName !== null &&
|
|
973
|
+
(!permissions || !(0, utils_1.hasProperty)(permissions, permissionName))) {
|
|
974
|
+
throw new Error(`Snap "${snapId}" is not permitted to use "${permissionName}".`);
|
|
975
|
+
}
|
|
976
|
+
const handlerPermissions = permissionName
|
|
977
|
+
? permissions[permissionName]
|
|
978
|
+
: undefined;
|
|
979
|
+
if (permissionName === snaps_rpc_methods_1.SnapEndowments.Rpc ||
|
|
980
|
+
permissionName === snaps_rpc_methods_1.SnapEndowments.Keyring) {
|
|
981
|
+
(0, utils_1.assert)(handlerPermissions);
|
|
982
|
+
const subject = this.messagingSystem.call('SubjectMetadataController:getSubjectMetadata', origin);
|
|
983
|
+
const origins = permissionName === snaps_rpc_methods_1.SnapEndowments.Rpc
|
|
984
|
+
? (0, snaps_rpc_methods_1.getRpcCaveatOrigins)(handlerPermissions)
|
|
985
|
+
: (0, snaps_rpc_methods_1.getKeyringCaveatOrigins)(handlerPermissions);
|
|
986
|
+
(0, utils_1.assert)(origins);
|
|
987
|
+
if (!(0, snaps_utils_1.isOriginAllowed)(origins, subject?.subjectType ?? permission_controller_1.SubjectType.Website, origin)) {
|
|
988
|
+
throw new Error(`Snap "${snapId}" is not permitted to handle requests from "${origin}".`);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
const handler = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRpcRequestHandler).call(this, snapId);
|
|
992
|
+
if (!handler) {
|
|
993
|
+
throw new Error(`Snap RPC message handler not found for snap "${snapId}".`);
|
|
994
|
+
}
|
|
995
|
+
const timeout = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getExecutionTimeout).call(this, handlerPermissions);
|
|
996
|
+
return handler({ origin, handler: handlerType, request, timeout });
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
exports.SnapController = SnapController;
|
|
1000
|
+
_SnapController_closeAllConnections = new WeakMap(), _SnapController_dynamicPermissions = new WeakMap(), _SnapController_environmentEndowmentPermissions = new WeakMap(), _SnapController_excludedPermissions = new WeakMap(), _SnapController_featureFlags = new WeakMap(), _SnapController_fetchFunction = new WeakMap(), _SnapController_idleTimeCheckInterval = new WeakMap(), _SnapController_maxIdleTime = new WeakMap(), _SnapController_encryptor = new WeakMap(), _SnapController_getMnemonic = new WeakMap(), _SnapController_getFeatureFlags = new WeakMap(), _SnapController_detectSnapLocation = new WeakMap(), _SnapController_snapsRuntimeData = new WeakMap(), _SnapController_rollbackSnapshots = new WeakMap(), _SnapController_timeoutForLastRequestStatus = new WeakMap(), _SnapController_statusMachine = new WeakMap(), _SnapController_preinstalledSnaps = new WeakMap(), _SnapController_instances = new WeakSet(), _SnapController_initializeStateMachine = function _SnapController_initializeStateMachine() {
|
|
1001
|
+
const disableGuard = ({ snapId }) => {
|
|
1002
|
+
return this.getExpect(snapId).enabled;
|
|
1003
|
+
};
|
|
1004
|
+
const statusConfig = {
|
|
1005
|
+
initial: snaps_utils_1.SnapStatus.Installing,
|
|
1006
|
+
states: {
|
|
1007
|
+
[snaps_utils_1.SnapStatus.Installing]: {
|
|
1008
|
+
on: {
|
|
1009
|
+
[snaps_utils_1.SnapStatusEvents.Start]: {
|
|
1010
|
+
target: snaps_utils_1.SnapStatus.Running,
|
|
1011
|
+
cond: disableGuard,
|
|
1012
|
+
},
|
|
1013
|
+
},
|
|
1014
|
+
},
|
|
1015
|
+
[snaps_utils_1.SnapStatus.Updating]: {
|
|
1016
|
+
on: {
|
|
1017
|
+
[snaps_utils_1.SnapStatusEvents.Start]: {
|
|
1018
|
+
target: snaps_utils_1.SnapStatus.Running,
|
|
1019
|
+
cond: disableGuard,
|
|
1020
|
+
},
|
|
1021
|
+
[snaps_utils_1.SnapStatusEvents.Stop]: snaps_utils_1.SnapStatus.Stopped,
|
|
1022
|
+
},
|
|
1023
|
+
},
|
|
1024
|
+
[snaps_utils_1.SnapStatus.Running]: {
|
|
1025
|
+
on: {
|
|
1026
|
+
[snaps_utils_1.SnapStatusEvents.Stop]: snaps_utils_1.SnapStatus.Stopped,
|
|
1027
|
+
[snaps_utils_1.SnapStatusEvents.Crash]: snaps_utils_1.SnapStatus.Crashed,
|
|
1028
|
+
},
|
|
1029
|
+
},
|
|
1030
|
+
[snaps_utils_1.SnapStatus.Stopped]: {
|
|
1031
|
+
on: {
|
|
1032
|
+
[snaps_utils_1.SnapStatusEvents.Start]: {
|
|
1033
|
+
target: snaps_utils_1.SnapStatus.Running,
|
|
1034
|
+
cond: disableGuard,
|
|
1035
|
+
},
|
|
1036
|
+
[snaps_utils_1.SnapStatusEvents.Update]: snaps_utils_1.SnapStatus.Updating,
|
|
1037
|
+
},
|
|
1038
|
+
},
|
|
1039
|
+
[snaps_utils_1.SnapStatus.Crashed]: {
|
|
1040
|
+
on: {
|
|
1041
|
+
[snaps_utils_1.SnapStatusEvents.Start]: {
|
|
1042
|
+
target: snaps_utils_1.SnapStatus.Running,
|
|
1043
|
+
cond: disableGuard,
|
|
1044
|
+
},
|
|
1045
|
+
[snaps_utils_1.SnapStatusEvents.Update]: snaps_utils_1.SnapStatus.Updating,
|
|
1046
|
+
},
|
|
1047
|
+
},
|
|
1048
|
+
},
|
|
1049
|
+
};
|
|
1050
|
+
__classPrivateFieldSet(this, _SnapController_statusMachine, (0, fsm_1.createMachine)(statusConfig), "f");
|
|
1051
|
+
(0, fsm_2.validateMachine)(__classPrivateFieldGet(this, _SnapController_statusMachine, "f"));
|
|
1052
|
+
}, _SnapController_registerMessageHandlers = function _SnapController_registerMessageHandlers() {
|
|
1053
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:clearSnapState`, (...args) => this.clearSnapState(...args));
|
|
1054
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:get`, (...args) => this.get(...args));
|
|
1055
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:getSnapState`, async (...args) => this.getSnapState(...args));
|
|
1056
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:handleRequest`, async (...args) => this.handleRequest(...args));
|
|
1057
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:has`, (...args) => this.has(...args));
|
|
1058
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:updateBlockedSnaps`, async () => this.updateBlockedSnaps());
|
|
1059
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:updateSnapState`, async (...args) => this.updateSnapState(...args));
|
|
1060
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:enable`, (...args) => this.enableSnap(...args));
|
|
1061
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:disable`, async (...args) => this.disableSnap(...args));
|
|
1062
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:remove`, async (...args) => this.removeSnap(...args));
|
|
1063
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:getPermitted`, (...args) => this.getPermittedSnaps(...args));
|
|
1064
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:install`, async (...args) => this.installSnaps(...args));
|
|
1065
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:getAll`, (...args) => this.getAllSnaps(...args));
|
|
1066
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:incrementActiveReferences`, (...args) => this.incrementActiveReferences(...args));
|
|
1067
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:decrementActiveReferences`, (...args) => this.decrementActiveReferences(...args));
|
|
1068
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:getRegistryMetadata`, async (...args) => this.getRegistryMetadata(...args));
|
|
1069
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:disconnectOrigin`, (...args) => this.removeSnapFromSubject(...args));
|
|
1070
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:revokeDynamicPermissions`, (...args) => this.revokeDynamicSnapPermissions(...args));
|
|
1071
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:getFile`, async (...args) => this.getSnapFile(...args));
|
|
1072
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:stopAllSnaps`, async (...args) => this.stopAllSnaps(...args));
|
|
1073
|
+
}, _SnapController_handlePreinstalledSnaps = function _SnapController_handlePreinstalledSnaps(preinstalledSnaps) {
|
|
1074
|
+
for (const { snapId, manifest, files, removable, hidden, } of preinstalledSnaps) {
|
|
1075
|
+
const existingSnap = this.get(snapId);
|
|
1076
|
+
const isAlreadyInstalled = existingSnap !== undefined;
|
|
1077
|
+
const isUpdate = isAlreadyInstalled && (0, utils_1.gtVersion)(manifest.version, existingSnap.version);
|
|
1078
|
+
// Disallow downgrades and overwriting non preinstalled snaps
|
|
1079
|
+
if (isAlreadyInstalled &&
|
|
1080
|
+
(!isUpdate || existingSnap.preinstalled !== true)) {
|
|
1081
|
+
continue;
|
|
1082
|
+
}
|
|
1083
|
+
const manifestFile = new snaps_utils_1.VirtualFile({
|
|
1084
|
+
path: snaps_utils_1.NpmSnapFileNames.Manifest,
|
|
1085
|
+
value: JSON.stringify(manifest),
|
|
1086
|
+
result: manifest,
|
|
1087
|
+
});
|
|
1088
|
+
const virtualFiles = files.map(({ path, value }) => new snaps_utils_1.VirtualFile({ value, path }));
|
|
1089
|
+
const { filePath, iconPath } = manifest.source.location.npm;
|
|
1090
|
+
const sourceCode = virtualFiles.find((file) => file.path === filePath);
|
|
1091
|
+
const svgIcon = iconPath
|
|
1092
|
+
? virtualFiles.find((file) => file.path === iconPath)
|
|
1093
|
+
: undefined;
|
|
1094
|
+
(0, utils_1.assert)(sourceCode, 'Source code not provided for preinstalled snap.');
|
|
1095
|
+
(0, utils_1.assert)(!iconPath || (iconPath && svgIcon), 'Icon not provided for preinstalled snap.');
|
|
1096
|
+
(0, utils_1.assert)(manifest.source.files === undefined, 'Auxiliary files are not currently supported for preinstalled snaps.');
|
|
1097
|
+
const localizationFiles = manifest.source.locales?.map((path) => virtualFiles.find((file) => file.path === path)) ?? [];
|
|
1098
|
+
const validatedLocalizationFiles = (0, snaps_utils_1.getValidatedLocalizationFiles)(localizationFiles.filter(Boolean));
|
|
1099
|
+
(0, utils_1.assert)(localizationFiles.length === validatedLocalizationFiles.length, 'Missing localization files for preinstalled snap.');
|
|
1100
|
+
const filesObject = {
|
|
1101
|
+
manifest: manifestFile,
|
|
1102
|
+
sourceCode,
|
|
1103
|
+
svgIcon,
|
|
1104
|
+
auxiliaryFiles: [],
|
|
1105
|
+
localizationFiles: validatedLocalizationFiles,
|
|
1106
|
+
};
|
|
1107
|
+
// Add snap to the SnapController state
|
|
1108
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_set).call(this, {
|
|
1109
|
+
id: snapId,
|
|
1110
|
+
origin: 'metamask',
|
|
1111
|
+
files: filesObject,
|
|
1112
|
+
removable,
|
|
1113
|
+
hidden,
|
|
1114
|
+
preinstalled: true,
|
|
1115
|
+
});
|
|
1116
|
+
// Setup permissions
|
|
1117
|
+
const processedPermissions = (0, snaps_rpc_methods_1.processSnapPermissions)(manifest.initialPermissions);
|
|
1118
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_validateSnapPermissions).call(this, processedPermissions);
|
|
1119
|
+
const { newPermissions, unusedPermissions } = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_calculatePermissionsChange).call(this, snapId, processedPermissions);
|
|
1120
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_updatePermissions).call(this, { snapId, newPermissions, unusedPermissions });
|
|
1121
|
+
if (manifest.initialConnections) {
|
|
1122
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_handleInitialConnections).call(this, snapId, existingSnap?.initialConnections ?? null, manifest.initialConnections);
|
|
1123
|
+
}
|
|
1124
|
+
// Set status
|
|
1125
|
+
this.update((state) => {
|
|
1126
|
+
state.snaps[snapId].status = snaps_utils_1.SnapStatus.Stopped;
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
}, _SnapController_pollForLastRequestStatus = function _SnapController_pollForLastRequestStatus() {
|
|
1130
|
+
__classPrivateFieldSet(this, _SnapController_timeoutForLastRequestStatus, setTimeout(() => {
|
|
1131
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_stopSnapsLastRequestPastMax).call(this).catch((error) => {
|
|
1132
|
+
// TODO: Decide how to handle errors.
|
|
1133
|
+
(0, snaps_utils_1.logError)(error);
|
|
1134
|
+
});
|
|
1135
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_pollForLastRequestStatus).call(this);
|
|
1136
|
+
}, __classPrivateFieldGet(this, _SnapController_idleTimeCheckInterval, "f")), "f");
|
|
1137
|
+
}, _SnapController_blockSnap =
|
|
1138
|
+
/**
|
|
1139
|
+
* Blocks an installed snap and prevents it from being started again. Emits
|
|
1140
|
+
* {@link SnapBlocked}. Does nothing if the snap is not installed.
|
|
1141
|
+
*
|
|
1142
|
+
* @param snapId - The snap to block.
|
|
1143
|
+
* @param blockedSnapInfo - Information detailing why the snap is blocked.
|
|
1144
|
+
*/
|
|
1145
|
+
async function _SnapController_blockSnap(snapId, blockedSnapInfo) {
|
|
1146
|
+
if (!this.has(snapId)) {
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
try {
|
|
1150
|
+
this.update((state) => {
|
|
1151
|
+
state.snaps[snapId].blocked = true;
|
|
1152
|
+
state.snaps[snapId].blockInformation = blockedSnapInfo;
|
|
1153
|
+
});
|
|
1154
|
+
await this.disableSnap(snapId);
|
|
1155
|
+
}
|
|
1156
|
+
catch (error) {
|
|
1157
|
+
(0, snaps_utils_1.logError)(`Encountered error when stopping blocked snap "${snapId}".`, error);
|
|
1158
|
+
}
|
|
1159
|
+
this.messagingSystem.publish(`${exports.controllerName}:snapBlocked`, snapId, blockedSnapInfo);
|
|
1160
|
+
}, _SnapController_unblockSnap = function _SnapController_unblockSnap(snapId) {
|
|
1161
|
+
if (!this.has(snapId) || !this.state.snaps[snapId].blocked) {
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
this.update((state) => {
|
|
1165
|
+
state.snaps[snapId].blocked = false;
|
|
1166
|
+
delete state.snaps[snapId].blockInformation;
|
|
1167
|
+
});
|
|
1168
|
+
this.messagingSystem.publish(`${exports.controllerName}:snapUnblocked`, snapId);
|
|
1169
|
+
}, _SnapController_assertIsInstallAllowed = async function _SnapController_assertIsInstallAllowed(snapId, snapInfo) {
|
|
1170
|
+
const results = await this.messagingSystem.call('SnapsRegistry:get', {
|
|
1171
|
+
[snapId]: snapInfo,
|
|
1172
|
+
});
|
|
1173
|
+
const result = results[snapId];
|
|
1174
|
+
if (result.status === registry_1.SnapsRegistryStatus.Blocked) {
|
|
1175
|
+
throw new Error(`Cannot install version "${snapInfo.version}" of snap "${snapId}": The version is blocked. ${result.reason?.explanation ?? ''}`);
|
|
1176
|
+
}
|
|
1177
|
+
const isAllowlistingRequired = Object.keys(snapInfo.permissions).some((permission) => !constants_1.ALLOWED_PERMISSIONS.includes(permission));
|
|
1178
|
+
if (__classPrivateFieldGet(this, _SnapController_featureFlags, "f").requireAllowlist &&
|
|
1179
|
+
isAllowlistingRequired &&
|
|
1180
|
+
result.status !== registry_1.SnapsRegistryStatus.Verified) {
|
|
1181
|
+
throw new Error(`Cannot install version "${snapInfo.version}" of snap "${snapId}": ${result.status === registry_1.SnapsRegistryStatus.Unavailable
|
|
1182
|
+
? 'The registry is temporarily unavailable.'
|
|
1183
|
+
: 'The snap is not on the allowlist.'}`);
|
|
1184
|
+
}
|
|
1185
|
+
}, _SnapController_assertCanInstallSnaps = function _SnapController_assertCanInstallSnaps() {
|
|
1186
|
+
(0, utils_1.assert)(__classPrivateFieldGet(this, _SnapController_featureFlags, "f").disableSnapInstallation !== true, 'Installing Snaps is currently disabled in this version of MetaMask.');
|
|
1187
|
+
}, _SnapController_assertCanUsePlatform = function _SnapController_assertCanUsePlatform() {
|
|
1188
|
+
const flags = __classPrivateFieldGet(this, _SnapController_getFeatureFlags, "f").call(this);
|
|
1189
|
+
(0, utils_1.assert)(flags.disableSnaps !== true, 'The Snaps platform requires basic functionality to be used. Enable basic functionality in the settings to use the Snaps platform.');
|
|
1190
|
+
}, _SnapController_stopSnapsLastRequestPastMax = async function _SnapController_stopSnapsLastRequestPastMax() {
|
|
1191
|
+
const entries = [...__classPrivateFieldGet(this, _SnapController_snapsRuntimeData, "f").entries()];
|
|
1192
|
+
return Promise.all(entries
|
|
1193
|
+
.filter(([_snapId, runtime]) => runtime.activeReferences === 0 &&
|
|
1194
|
+
runtime.pendingInboundRequests.length === 0 &&
|
|
1195
|
+
runtime.lastRequest &&
|
|
1196
|
+
__classPrivateFieldGet(this, _SnapController_maxIdleTime, "f") &&
|
|
1197
|
+
(0, utils_1.timeSince)(runtime.lastRequest) > __classPrivateFieldGet(this, _SnapController_maxIdleTime, "f"))
|
|
1198
|
+
.map(async ([snapId]) => this.stopSnap(snapId, snaps_utils_1.SnapStatusEvents.Stop)));
|
|
1199
|
+
}, _SnapController_transition = function _SnapController_transition(snapId, event) {
|
|
1200
|
+
const { interpreter } = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
1201
|
+
interpreter.send(event);
|
|
1202
|
+
this.update((state) => {
|
|
1203
|
+
state.snaps[snapId].status = interpreter.state.value;
|
|
1204
|
+
});
|
|
1205
|
+
}, _SnapController_terminateSnap =
|
|
1206
|
+
/**
|
|
1207
|
+
* Terminates the specified snap and emits the `snapTerminated` event.
|
|
1208
|
+
*
|
|
1209
|
+
* @param snapId - The snap to terminate.
|
|
1210
|
+
*/
|
|
1211
|
+
async function _SnapController_terminateSnap(snapId) {
|
|
1212
|
+
await this.messagingSystem.call('ExecutionService:terminateSnap', snapId);
|
|
1213
|
+
// Hack to give up execution for a bit to let gracefully terminating Snaps return.
|
|
1214
|
+
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
1215
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
1216
|
+
// Unresponsive requests may still be timed, time them out.
|
|
1217
|
+
runtime.pendingInboundRequests
|
|
1218
|
+
.filter((pendingRequest) => pendingRequest.timer.status !== 'finished')
|
|
1219
|
+
.forEach((pendingRequest) => pendingRequest.timer.finish());
|
|
1220
|
+
// Hack to give up execution for a bit to let timed out requests return.
|
|
1221
|
+
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
1222
|
+
this.messagingSystem.publish('SnapController:snapTerminated', this.getTruncatedExpect(snapId));
|
|
1223
|
+
}, _SnapController_getSnapEncryptionKey =
|
|
1224
|
+
/**
|
|
1225
|
+
* Generate an encryption key to be used for state encryption for a given Snap.
|
|
1226
|
+
*
|
|
1227
|
+
* @param options - An options bag.
|
|
1228
|
+
* @param options.snapId - The Snap ID.
|
|
1229
|
+
* @param options.salt - A salt to be used for the encryption key.
|
|
1230
|
+
* @param options.useCache - Whether to use caching or not.
|
|
1231
|
+
* @param options.keyMetadata - Optional metadata about how to derive the encryption key.
|
|
1232
|
+
* @returns An encryption key.
|
|
1233
|
+
*/
|
|
1234
|
+
async function _SnapController_getSnapEncryptionKey({ snapId, salt: passedSalt, useCache, keyMetadata, }) {
|
|
1235
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
1236
|
+
if (runtime.encryptionKey && runtime.encryptionSalt && useCache) {
|
|
1237
|
+
return {
|
|
1238
|
+
key: await __classPrivateFieldGet(this, _SnapController_encryptor, "f").importKey(runtime.encryptionKey),
|
|
1239
|
+
salt: runtime.encryptionSalt,
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
const salt = passedSalt ?? __classPrivateFieldGet(this, _SnapController_encryptor, "f").generateSalt();
|
|
1243
|
+
const mnemonicPhrase = await __classPrivateFieldGet(this, _SnapController_getMnemonic, "f").call(this);
|
|
1244
|
+
const entropy = await (0, snaps_rpc_methods_1.getEncryptionEntropy)({ snapId, mnemonicPhrase });
|
|
1245
|
+
const encryptionKey = await __classPrivateFieldGet(this, _SnapController_encryptor, "f").keyFromPassword(entropy, salt, true, keyMetadata);
|
|
1246
|
+
const exportedKey = await __classPrivateFieldGet(this, _SnapController_encryptor, "f").exportKey(encryptionKey);
|
|
1247
|
+
// Cache exported encryption key in runtime
|
|
1248
|
+
if (useCache) {
|
|
1249
|
+
runtime.encryptionKey = exportedKey;
|
|
1250
|
+
runtime.encryptionSalt = salt;
|
|
1251
|
+
}
|
|
1252
|
+
return { key: encryptionKey, salt };
|
|
1253
|
+
}, _SnapController_decryptSnapState =
|
|
1254
|
+
/**
|
|
1255
|
+
* Decrypt the encrypted state for a given Snap.
|
|
1256
|
+
*
|
|
1257
|
+
* @param snapId - The Snap ID.
|
|
1258
|
+
* @param state - The encrypted state as a string.
|
|
1259
|
+
* @returns A valid JSON object derived from the encrypted state.
|
|
1260
|
+
* @throws If the decryption fails or the decrypted state is not valid JSON.
|
|
1261
|
+
*/
|
|
1262
|
+
async function _SnapController_decryptSnapState(snapId, state) {
|
|
1263
|
+
try {
|
|
1264
|
+
const parsed = (0, snaps_utils_1.parseJson)(state);
|
|
1265
|
+
const { salt, keyMetadata } = parsed;
|
|
1266
|
+
const useCache = __classPrivateFieldGet(this, _SnapController_encryptor, "f").isVaultUpdated(state);
|
|
1267
|
+
const { key } = await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getSnapEncryptionKey).call(this, {
|
|
1268
|
+
snapId,
|
|
1269
|
+
salt,
|
|
1270
|
+
useCache,
|
|
1271
|
+
// When decrypting state we expect key metadata to be present.
|
|
1272
|
+
// If it isn't present, we assume that the Snap state we are decrypting is old enough to use the legacy encryption params.
|
|
1273
|
+
keyMetadata: keyMetadata ?? constants_1.LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS,
|
|
1274
|
+
});
|
|
1275
|
+
const decryptedState = await __classPrivateFieldGet(this, _SnapController_encryptor, "f").decryptWithKey(key, parsed);
|
|
1276
|
+
(0, utils_1.assert)((0, utils_1.isValidJson)(decryptedState));
|
|
1277
|
+
return decryptedState;
|
|
1278
|
+
}
|
|
1279
|
+
catch {
|
|
1280
|
+
throw rpc_errors_1.rpcErrors.internal({
|
|
1281
|
+
message: 'Failed to decrypt snap state, the state must be corrupted.',
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
}, _SnapController_encryptSnapState =
|
|
1285
|
+
/**
|
|
1286
|
+
* Encrypt a JSON state object for a given Snap.
|
|
1287
|
+
*
|
|
1288
|
+
* Note: This function does not assert the validity of the object,
|
|
1289
|
+
* please ensure only valid JSON is passed to it.
|
|
1290
|
+
*
|
|
1291
|
+
* @param snapId - The Snap ID.
|
|
1292
|
+
* @param state - The state object.
|
|
1293
|
+
* @returns A string containing the encrypted JSON object.
|
|
1294
|
+
*/
|
|
1295
|
+
async function _SnapController_encryptSnapState(snapId, state) {
|
|
1296
|
+
const { key, salt } = await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getSnapEncryptionKey).call(this, {
|
|
1297
|
+
snapId,
|
|
1298
|
+
useCache: true,
|
|
1299
|
+
});
|
|
1300
|
+
const encryptedState = await __classPrivateFieldGet(this, _SnapController_encryptor, "f").encryptWithKey(key, state);
|
|
1301
|
+
encryptedState.salt = salt;
|
|
1302
|
+
return JSON.stringify(encryptedState);
|
|
1303
|
+
}, _SnapController_handleInitialConnections = function _SnapController_handleInitialConnections(snapId, previousInitialConnections, initialConnections) {
|
|
1304
|
+
if (previousInitialConnections) {
|
|
1305
|
+
const revokedInitialConnections = (0, utils_2.setDiff)(previousInitialConnections, initialConnections);
|
|
1306
|
+
for (const origin of Object.keys(revokedInitialConnections)) {
|
|
1307
|
+
this.removeSnapFromSubject(origin, snapId);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
for (const origin of Object.keys(initialConnections)) {
|
|
1311
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_addSnapToSubject).call(this, origin, snapId);
|
|
1312
|
+
}
|
|
1313
|
+
}, _SnapController_addSnapToSubject = function _SnapController_addSnapToSubject(origin, snapId) {
|
|
1314
|
+
const subjectPermissions = this.messagingSystem.call('PermissionController:getPermissions', origin);
|
|
1315
|
+
const existingCaveat = subjectPermissions?.[snaps_rpc_methods_1.WALLET_SNAP_PERMISSION_KEY]?.caveats?.find((caveat) => caveat.type === snaps_utils_1.SnapCaveatType.SnapIds);
|
|
1316
|
+
const subjectHasSnap = Boolean(existingCaveat?.value?.[snapId]);
|
|
1317
|
+
// If the subject is already connected to the snap, this is a no-op.
|
|
1318
|
+
if (subjectHasSnap) {
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
// If an existing caveat exists, we add the snap to that.
|
|
1322
|
+
if (existingCaveat) {
|
|
1323
|
+
this.messagingSystem.call('PermissionController:updateCaveat', origin, snaps_rpc_methods_1.WALLET_SNAP_PERMISSION_KEY, snaps_utils_1.SnapCaveatType.SnapIds, { ...existingCaveat.value, [snapId]: {} });
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
const approvedPermissions = {
|
|
1327
|
+
[snaps_rpc_methods_1.WALLET_SNAP_PERMISSION_KEY]: {
|
|
1328
|
+
caveats: [
|
|
1329
|
+
{
|
|
1330
|
+
type: snaps_utils_1.SnapCaveatType.SnapIds,
|
|
1331
|
+
value: {
|
|
1332
|
+
[snapId]: {},
|
|
1333
|
+
},
|
|
1334
|
+
},
|
|
1335
|
+
],
|
|
1336
|
+
},
|
|
1337
|
+
};
|
|
1338
|
+
this.messagingSystem.call('PermissionController:grantPermissions', {
|
|
1339
|
+
approvedPermissions,
|
|
1340
|
+
subject: { origin },
|
|
1341
|
+
});
|
|
1342
|
+
}, _SnapController_removeSnapFromSubjects = function _SnapController_removeSnapFromSubjects(snapId) {
|
|
1343
|
+
const subjects = this.messagingSystem.call('PermissionController:getSubjectNames');
|
|
1344
|
+
for (const subject of subjects) {
|
|
1345
|
+
this.removeSnapFromSubject(subject, snapId);
|
|
1346
|
+
}
|
|
1347
|
+
}, _SnapController_revokeAllSnapPermissions = function _SnapController_revokeAllSnapPermissions(snapId) {
|
|
1348
|
+
if (this.messagingSystem.call('PermissionController:hasPermissions', snapId)) {
|
|
1349
|
+
this.messagingSystem.call('PermissionController:revokeAllPermissions', snapId);
|
|
1350
|
+
}
|
|
1351
|
+
}, _SnapController_createApproval = function _SnapController_createApproval({ origin, snapId, type, }) {
|
|
1352
|
+
const id = (0, nanoid_1.nanoid)();
|
|
1353
|
+
const promise = this.messagingSystem.call('ApprovalController:addRequest', {
|
|
1354
|
+
origin,
|
|
1355
|
+
id,
|
|
1356
|
+
type,
|
|
1357
|
+
requestData: {
|
|
1358
|
+
// Mirror previous installation metadata
|
|
1359
|
+
metadata: { id, origin: snapId, dappOrigin: origin },
|
|
1360
|
+
snapId,
|
|
1361
|
+
},
|
|
1362
|
+
requestState: {
|
|
1363
|
+
loading: true,
|
|
1364
|
+
},
|
|
1365
|
+
}, true);
|
|
1366
|
+
return { id, promise };
|
|
1367
|
+
}, _SnapController_updateApproval = function _SnapController_updateApproval(id, requestState) {
|
|
1368
|
+
try {
|
|
1369
|
+
this.messagingSystem.call('ApprovalController:updateRequestState', {
|
|
1370
|
+
id,
|
|
1371
|
+
requestState,
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
catch {
|
|
1375
|
+
// Do nothing
|
|
1376
|
+
}
|
|
1377
|
+
}, _SnapController_resolveAllowlistVersion = async function _SnapController_resolveAllowlistVersion(snapId, versionRange) {
|
|
1378
|
+
return await this.messagingSystem.call('SnapsRegistry:resolveVersion', snapId, versionRange);
|
|
1379
|
+
}, _SnapController_add =
|
|
1380
|
+
/**
|
|
1381
|
+
* Returns a promise representing the complete installation of the requested snap.
|
|
1382
|
+
* If the snap is already being installed, the previously pending promise will be returned.
|
|
1383
|
+
*
|
|
1384
|
+
* @param args - Object containing the snap id and either the URL of the snap's manifest,
|
|
1385
|
+
* or the snap's manifest and source code. The object may also optionally contain a target
|
|
1386
|
+
* version.
|
|
1387
|
+
* @returns The resulting snap object.
|
|
1388
|
+
*/
|
|
1389
|
+
async function _SnapController_add(args) {
|
|
1390
|
+
const { id: snapId, location, versionRange } = args;
|
|
1391
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_setupRuntime).call(this, snapId);
|
|
1392
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
1393
|
+
if (!runtime.installPromise) {
|
|
1394
|
+
(0, logging_1.log)(`Adding snap: ${snapId}`);
|
|
1395
|
+
// If fetching and setting the snap succeeds, this property will be set
|
|
1396
|
+
// to null in the authorize() method.
|
|
1397
|
+
runtime.installPromise = (async () => {
|
|
1398
|
+
const fetchedSnap = await (0, utils_2.fetchSnap)(snapId, location);
|
|
1399
|
+
const manifest = fetchedSnap.manifest.result;
|
|
1400
|
+
if (!(0, utils_1.satisfiesVersionRange)(manifest.version, versionRange)) {
|
|
1401
|
+
throw new Error(`Version mismatch. Manifest for "${snapId}" specifies version "${manifest.version}" which doesn't satisfy requested version range "${versionRange}".`);
|
|
1402
|
+
}
|
|
1403
|
+
await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertIsInstallAllowed).call(this, snapId, {
|
|
1404
|
+
version: manifest.version,
|
|
1405
|
+
checksum: manifest.source.shasum,
|
|
1406
|
+
permissions: manifest.initialPermissions,
|
|
1407
|
+
});
|
|
1408
|
+
return __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_set).call(this, {
|
|
1409
|
+
...args,
|
|
1410
|
+
files: fetchedSnap,
|
|
1411
|
+
id: snapId,
|
|
1412
|
+
});
|
|
1413
|
+
})();
|
|
1414
|
+
}
|
|
1415
|
+
try {
|
|
1416
|
+
return await runtime.installPromise;
|
|
1417
|
+
}
|
|
1418
|
+
catch (error) {
|
|
1419
|
+
// Reset promise so users can retry installation in case the problem is
|
|
1420
|
+
// temporary.
|
|
1421
|
+
runtime.installPromise = null;
|
|
1422
|
+
throw error;
|
|
1423
|
+
}
|
|
1424
|
+
}, _SnapController_startSnap = async function _SnapController_startSnap(snapData) {
|
|
1425
|
+
const { snapId } = snapData;
|
|
1426
|
+
if (this.isRunning(snapId)) {
|
|
1427
|
+
throw new Error(`Snap "${snapId}" is already started.`);
|
|
1428
|
+
}
|
|
1429
|
+
try {
|
|
1430
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
1431
|
+
const result = await this.messagingSystem.call('ExecutionService:executeSnap', {
|
|
1432
|
+
...snapData,
|
|
1433
|
+
endowments: await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getEndowments).call(this, snapId),
|
|
1434
|
+
});
|
|
1435
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_transition).call(this, snapId, snaps_utils_1.SnapStatusEvents.Start);
|
|
1436
|
+
// We treat the initialization of the snap as the first request, for idle timing purposes.
|
|
1437
|
+
runtime.lastRequest = Date.now();
|
|
1438
|
+
return result;
|
|
1439
|
+
}
|
|
1440
|
+
catch (error) {
|
|
1441
|
+
await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_terminateSnap).call(this, snapId);
|
|
1442
|
+
throw error;
|
|
1443
|
+
}
|
|
1444
|
+
}, _SnapController_getEndowments =
|
|
1445
|
+
/**
|
|
1446
|
+
* Gets the names of all endowments that will be added to the Snap's
|
|
1447
|
+
* Compartment when it executes. These should be the names of global
|
|
1448
|
+
* JavaScript APIs accessible in the root realm of the execution environment.
|
|
1449
|
+
*
|
|
1450
|
+
* Throws an error if the endowment getter for a permission returns a truthy
|
|
1451
|
+
* value that is not an array of strings.
|
|
1452
|
+
*
|
|
1453
|
+
* @param snapId - The id of the snap whose SES endowments to get.
|
|
1454
|
+
* @returns An array of the names of the endowments.
|
|
1455
|
+
*/
|
|
1456
|
+
async function _SnapController_getEndowments(snapId) {
|
|
1457
|
+
let allEndowments = [];
|
|
1458
|
+
for (const permissionName of __classPrivateFieldGet(this, _SnapController_environmentEndowmentPermissions, "f")) {
|
|
1459
|
+
if (this.messagingSystem.call('PermissionController:hasPermission', snapId, permissionName)) {
|
|
1460
|
+
const endowments = await this.messagingSystem.call('PermissionController:getEndowments', snapId, permissionName);
|
|
1461
|
+
if (endowments) {
|
|
1462
|
+
// We don't have any guarantees about the type of the endowments
|
|
1463
|
+
// value, so we have to guard at runtime.
|
|
1464
|
+
if (!Array.isArray(endowments) ||
|
|
1465
|
+
endowments.some((value) => typeof value !== 'string')) {
|
|
1466
|
+
throw new Error('Expected an array of string endowment names.');
|
|
1467
|
+
}
|
|
1468
|
+
allEndowments = allEndowments.concat(endowments);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
const dedupedEndowments = [
|
|
1473
|
+
...new Set([...snaps_utils_1.DEFAULT_ENDOWMENTS, ...allEndowments]),
|
|
1474
|
+
];
|
|
1475
|
+
if (dedupedEndowments.length <
|
|
1476
|
+
// This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313
|
|
1477
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
1478
|
+
snaps_utils_1.DEFAULT_ENDOWMENTS.length + allEndowments.length) {
|
|
1479
|
+
(0, snaps_utils_1.logError)(`Duplicate endowments found for ${snapId}. Default endowments should not be requested.`, allEndowments);
|
|
1480
|
+
}
|
|
1481
|
+
return dedupedEndowments;
|
|
1482
|
+
}, _SnapController_set = function _SnapController_set(args) {
|
|
1483
|
+
const { id: snapId, origin, files, isUpdate = false, removable, preinstalled, hidden, } = args;
|
|
1484
|
+
const { manifest, sourceCode: sourceCodeFile, svgIcon, auxiliaryFiles: rawAuxiliaryFiles, localizationFiles, } = files;
|
|
1485
|
+
(0, snaps_utils_1.assertIsSnapManifest)(manifest.result);
|
|
1486
|
+
const { version } = manifest.result;
|
|
1487
|
+
const sourceCode = sourceCodeFile.toString();
|
|
1488
|
+
(0, utils_1.assert)(typeof sourceCode === 'string' && sourceCode.length > 0, `Invalid source code for snap "${snapId}".`);
|
|
1489
|
+
const auxiliaryFiles = rawAuxiliaryFiles.map((file) => {
|
|
1490
|
+
(0, utils_1.assert)(typeof file.data.base64 === 'string');
|
|
1491
|
+
return {
|
|
1492
|
+
path: file.path,
|
|
1493
|
+
value: file.data.base64,
|
|
1494
|
+
};
|
|
1495
|
+
});
|
|
1496
|
+
const snapsState = this.state.snaps;
|
|
1497
|
+
const existingSnap = snapsState[snapId];
|
|
1498
|
+
const previousVersionHistory = existingSnap?.versionHistory ?? [];
|
|
1499
|
+
const versionHistory = [
|
|
1500
|
+
...previousVersionHistory,
|
|
1501
|
+
{
|
|
1502
|
+
version,
|
|
1503
|
+
date: Date.now(),
|
|
1504
|
+
origin,
|
|
1505
|
+
},
|
|
1506
|
+
];
|
|
1507
|
+
const localizedFiles = localizationFiles.map((file) => file.result);
|
|
1508
|
+
const snap = {
|
|
1509
|
+
// Restore relevant snap state if it exists
|
|
1510
|
+
...existingSnap,
|
|
1511
|
+
// Note that the snap will be unblocked and enabled, regardless of its
|
|
1512
|
+
// previous state.
|
|
1513
|
+
blocked: false,
|
|
1514
|
+
enabled: true,
|
|
1515
|
+
removable,
|
|
1516
|
+
preinstalled,
|
|
1517
|
+
hidden,
|
|
1518
|
+
id: snapId,
|
|
1519
|
+
initialConnections: manifest.result.initialConnections,
|
|
1520
|
+
initialPermissions: manifest.result.initialPermissions,
|
|
1521
|
+
manifest: manifest.result,
|
|
1522
|
+
status: __classPrivateFieldGet(this, _SnapController_statusMachine, "f").config.initial,
|
|
1523
|
+
sourceCode,
|
|
1524
|
+
version,
|
|
1525
|
+
versionHistory,
|
|
1526
|
+
auxiliaryFiles,
|
|
1527
|
+
localizationFiles: localizedFiles,
|
|
1528
|
+
};
|
|
1529
|
+
// If the snap was blocked, it isn't any longer
|
|
1530
|
+
delete snap.blockInformation;
|
|
1531
|
+
// store the snap back in state
|
|
1532
|
+
const { inversePatches } = this.update((state) => {
|
|
1533
|
+
state.snaps[snapId] = snap;
|
|
1534
|
+
});
|
|
1535
|
+
// checking for isUpdate here as this function is also used in
|
|
1536
|
+
// the install flow, we do not care to create snapshots for installs
|
|
1537
|
+
if (isUpdate) {
|
|
1538
|
+
const rollbackSnapshot = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRollbackSnapshot).call(this, snapId);
|
|
1539
|
+
if (rollbackSnapshot !== undefined) {
|
|
1540
|
+
rollbackSnapshot.statePatches = inversePatches;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
// In case the Snap uses a localized manifest, we need to get the
|
|
1544
|
+
// proposed name from the localized manifest.
|
|
1545
|
+
const { proposedName } = (0, snaps_utils_1.getLocalizedSnapManifest)(manifest.result, 'en', localizedFiles);
|
|
1546
|
+
this.messagingSystem.call('SubjectMetadataController:addSubjectMetadata', {
|
|
1547
|
+
subjectType: permission_controller_1.SubjectType.Snap,
|
|
1548
|
+
name: proposedName,
|
|
1549
|
+
origin: snap.id,
|
|
1550
|
+
version,
|
|
1551
|
+
svgIcon: svgIcon?.toString() ?? null,
|
|
1552
|
+
});
|
|
1553
|
+
return { ...snap, sourceCode };
|
|
1554
|
+
}, _SnapController_validateSnapPermissions = function _SnapController_validateSnapPermissions(processedPermissions) {
|
|
1555
|
+
const permissionKeys = Object.keys(processedPermissions);
|
|
1556
|
+
const handlerPermissions = Array.from(new Set(Object.values(snaps_rpc_methods_1.handlerEndowments)));
|
|
1557
|
+
(0, utils_1.assert)(permissionKeys.some((key) => handlerPermissions.includes(key)), `A snap must request at least one of the following permissions: ${handlerPermissions
|
|
1558
|
+
.filter((handler) => handler !== null)
|
|
1559
|
+
.join(', ')}.`);
|
|
1560
|
+
const excludedPermissionErrors = permissionKeys.reduce((errors, permission) => {
|
|
1561
|
+
if ((0, utils_1.hasProperty)(__classPrivateFieldGet(this, _SnapController_excludedPermissions, "f"), permission)) {
|
|
1562
|
+
errors.push(__classPrivateFieldGet(this, _SnapController_excludedPermissions, "f")[permission]);
|
|
1563
|
+
}
|
|
1564
|
+
return errors;
|
|
1565
|
+
}, []);
|
|
1566
|
+
(0, utils_1.assert)(excludedPermissionErrors.length === 0, `One or more permissions are not allowed:\n${excludedPermissionErrors.join('\n')}`);
|
|
1567
|
+
}, _SnapController_getExecutionTimeout = function _SnapController_getExecutionTimeout(permission) {
|
|
1568
|
+
return (0, snaps_rpc_methods_1.getMaxRequestTimeCaveat)(permission) ?? this.maxRequestTime;
|
|
1569
|
+
}, _SnapController_getRpcRequestHandler = function _SnapController_getRpcRequestHandler(snapId) {
|
|
1570
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
1571
|
+
const existingHandler = runtime.rpcHandler;
|
|
1572
|
+
if (existingHandler) {
|
|
1573
|
+
return existingHandler;
|
|
1574
|
+
}
|
|
1575
|
+
const requestQueue = new RequestQueue_1.RequestQueue(5);
|
|
1576
|
+
// We need to set up this promise map to map snapIds to their respective startPromises,
|
|
1577
|
+
// because otherwise we would lose context on the correct startPromise.
|
|
1578
|
+
const startPromises = new Map();
|
|
1579
|
+
const rpcHandler = async ({ origin, handler: handlerType, request, timeout, }) => {
|
|
1580
|
+
if (this.state.snaps[snapId].enabled === false) {
|
|
1581
|
+
throw new Error(`Snap "${snapId}" is disabled.`);
|
|
1582
|
+
}
|
|
1583
|
+
if (this.state.snaps[snapId].status === snaps_utils_1.SnapStatus.Installing) {
|
|
1584
|
+
throw new Error(`Snap "${snapId}" is currently being installed. Please try again later.`);
|
|
1585
|
+
}
|
|
1586
|
+
if (!this.isRunning(snapId)) {
|
|
1587
|
+
let localStartPromise = startPromises.get(snapId);
|
|
1588
|
+
if (!localStartPromise) {
|
|
1589
|
+
localStartPromise = this.startSnap(snapId);
|
|
1590
|
+
startPromises.set(snapId, localStartPromise);
|
|
1591
|
+
}
|
|
1592
|
+
else if (requestQueue.get(origin) >= requestQueue.maxQueueSize) {
|
|
1593
|
+
throw new Error('Exceeds maximum number of requests waiting to be resolved, please try again.');
|
|
1594
|
+
}
|
|
1595
|
+
requestQueue.increment(origin);
|
|
1596
|
+
try {
|
|
1597
|
+
await localStartPromise;
|
|
1598
|
+
}
|
|
1599
|
+
finally {
|
|
1600
|
+
requestQueue.decrement(origin);
|
|
1601
|
+
// Only delete startPromise for a snap if its value hasn't changed
|
|
1602
|
+
if (startPromises.get(snapId) === localStartPromise) {
|
|
1603
|
+
startPromises.delete(snapId);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
const timer = new Timer_1.Timer(timeout);
|
|
1608
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_recordSnapRpcRequestStart).call(this, snapId, request.id, timer);
|
|
1609
|
+
const handleRpcRequestPromise = this.messagingSystem.call('ExecutionService:handleRpcRequest', snapId, { origin, handler: handlerType, request });
|
|
1610
|
+
// This will either get the result or reject due to the timeout.
|
|
1611
|
+
try {
|
|
1612
|
+
const result = await (0, utils_2.withTimeout)(handleRpcRequestPromise, timer);
|
|
1613
|
+
if (result === utils_2.hasTimedOut) {
|
|
1614
|
+
throw new Error(`${snapId} failed to respond to the request in time.`);
|
|
1615
|
+
}
|
|
1616
|
+
await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertSnapRpcRequestResult).call(this, snapId, handlerType, result);
|
|
1617
|
+
const transformedResult = await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_transformSnapRpcRequestResult).call(this, snapId, handlerType, result);
|
|
1618
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_recordSnapRpcRequestFinish).call(this, snapId, request.id);
|
|
1619
|
+
return transformedResult;
|
|
1620
|
+
}
|
|
1621
|
+
catch (error) {
|
|
1622
|
+
// We flag the RPC request as finished early since termination may affect pending requests
|
|
1623
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_recordSnapRpcRequestFinish).call(this, snapId, request.id);
|
|
1624
|
+
const [jsonRpcError, handled] = (0, snaps_utils_1.unwrapError)(error);
|
|
1625
|
+
if (!handled) {
|
|
1626
|
+
await this.stopSnap(snapId, snaps_utils_1.SnapStatusEvents.Crash);
|
|
1627
|
+
}
|
|
1628
|
+
throw jsonRpcError;
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
runtime.rpcHandler = rpcHandler;
|
|
1632
|
+
return rpcHandler;
|
|
1633
|
+
}, _SnapController_createInterface =
|
|
1634
|
+
/**
|
|
1635
|
+
* Create a dynamic interface in the SnapInterfaceController.
|
|
1636
|
+
*
|
|
1637
|
+
* @param snapId - The snap ID.
|
|
1638
|
+
* @param content - The initial interface content.
|
|
1639
|
+
* @returns An identifier that can be used to identify the interface.
|
|
1640
|
+
*/
|
|
1641
|
+
async function _SnapController_createInterface(snapId, content) {
|
|
1642
|
+
return this.messagingSystem.call('SnapInterfaceController:createInterface', snapId, content);
|
|
1643
|
+
}, _SnapController_assertInterfaceExists = function _SnapController_assertInterfaceExists(snapId, id) {
|
|
1644
|
+
// This will throw if the interface isn't accessible, but we assert nevertheless.
|
|
1645
|
+
(0, utils_1.assert)(this.messagingSystem.call('SnapInterfaceController:getInterface', snapId, id));
|
|
1646
|
+
}, _SnapController_transformSnapRpcRequestResult =
|
|
1647
|
+
/**
|
|
1648
|
+
* Transform a RPC request result if necessary.
|
|
1649
|
+
*
|
|
1650
|
+
* @param snapId - The snap ID of the snap that produced the result.
|
|
1651
|
+
* @param handlerType - The handler type that produced the result.
|
|
1652
|
+
* @param result - The result.
|
|
1653
|
+
* @returns The transformed result if applicable, otherwise the original result.
|
|
1654
|
+
*/
|
|
1655
|
+
async function _SnapController_transformSnapRpcRequestResult(snapId, handlerType, result) {
|
|
1656
|
+
switch (handlerType) {
|
|
1657
|
+
case snaps_utils_1.HandlerType.OnTransaction:
|
|
1658
|
+
case snaps_utils_1.HandlerType.OnSignature:
|
|
1659
|
+
case snaps_utils_1.HandlerType.OnHomePage: {
|
|
1660
|
+
// Since this type has been asserted earlier we can cast
|
|
1661
|
+
const castResult = result;
|
|
1662
|
+
// If a handler returns static content, we turn it into a dynamic UI
|
|
1663
|
+
if (castResult && (0, utils_1.hasProperty)(castResult, 'content')) {
|
|
1664
|
+
const { content, ...rest } = castResult;
|
|
1665
|
+
const id = await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_createInterface).call(this, snapId, content);
|
|
1666
|
+
return { ...rest, id };
|
|
1667
|
+
}
|
|
1668
|
+
return result;
|
|
1669
|
+
}
|
|
1670
|
+
default:
|
|
1671
|
+
return result;
|
|
1672
|
+
}
|
|
1673
|
+
}, _SnapController_assertSnapRpcRequestResult =
|
|
1674
|
+
/**
|
|
1675
|
+
* Assert that the returned result of a Snap RPC call is the expected shape.
|
|
1676
|
+
*
|
|
1677
|
+
* @param snapId - The snap ID.
|
|
1678
|
+
* @param handlerType - The handler type of the RPC Request.
|
|
1679
|
+
* @param result - The result of the RPC request.
|
|
1680
|
+
*/
|
|
1681
|
+
async function _SnapController_assertSnapRpcRequestResult(snapId, handlerType, result) {
|
|
1682
|
+
switch (handlerType) {
|
|
1683
|
+
case snaps_utils_1.HandlerType.OnTransaction: {
|
|
1684
|
+
(0, utils_1.assertStruct)(result, snaps_utils_1.OnTransactionResponseStruct);
|
|
1685
|
+
if (result && (0, utils_1.hasProperty)(result, 'id')) {
|
|
1686
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertInterfaceExists).call(this, snapId, result.id);
|
|
1687
|
+
}
|
|
1688
|
+
break;
|
|
1689
|
+
}
|
|
1690
|
+
case snaps_utils_1.HandlerType.OnSignature: {
|
|
1691
|
+
(0, utils_1.assertStruct)(result, snaps_utils_1.OnSignatureResponseStruct);
|
|
1692
|
+
if (result && (0, utils_1.hasProperty)(result, 'id')) {
|
|
1693
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertInterfaceExists).call(this, snapId, result.id);
|
|
1694
|
+
}
|
|
1695
|
+
break;
|
|
1696
|
+
}
|
|
1697
|
+
case snaps_utils_1.HandlerType.OnHomePage: {
|
|
1698
|
+
(0, utils_1.assertStruct)(result, snaps_utils_1.OnHomePageResponseStruct);
|
|
1699
|
+
if (result && (0, utils_1.hasProperty)(result, 'id')) {
|
|
1700
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertInterfaceExists).call(this, snapId, result.id);
|
|
1701
|
+
}
|
|
1702
|
+
break;
|
|
1703
|
+
}
|
|
1704
|
+
case snaps_utils_1.HandlerType.OnNameLookup:
|
|
1705
|
+
(0, utils_1.assertStruct)(result, snaps_utils_1.OnNameLookupResponseStruct);
|
|
1706
|
+
break;
|
|
1707
|
+
default:
|
|
1708
|
+
break;
|
|
1709
|
+
}
|
|
1710
|
+
}, _SnapController_recordSnapRpcRequestStart = function _SnapController_recordSnapRpcRequestStart(snapId, requestId, timer) {
|
|
1711
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
1712
|
+
runtime.pendingInboundRequests.push({ requestId, timer });
|
|
1713
|
+
runtime.lastRequest = null;
|
|
1714
|
+
}, _SnapController_recordSnapRpcRequestFinish = function _SnapController_recordSnapRpcRequestFinish(snapId, requestId) {
|
|
1715
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntimeExpect).call(this, snapId);
|
|
1716
|
+
runtime.pendingInboundRequests = runtime.pendingInboundRequests.filter((request) => request.requestId !== requestId);
|
|
1717
|
+
if (runtime.pendingInboundRequests.length === 0) {
|
|
1718
|
+
runtime.lastRequest = Date.now();
|
|
1719
|
+
}
|
|
1720
|
+
}, _SnapController_getRollbackSnapshot = function _SnapController_getRollbackSnapshot(snapId) {
|
|
1721
|
+
return __classPrivateFieldGet(this, _SnapController_rollbackSnapshots, "f").get(snapId);
|
|
1722
|
+
}, _SnapController_createRollbackSnapshot = function _SnapController_createRollbackSnapshot(snapId) {
|
|
1723
|
+
(0, utils_1.assert)(__classPrivateFieldGet(this, _SnapController_rollbackSnapshots, "f").get(snapId) === undefined, new Error(`Snap "${snapId}" rollback snapshot already exists.`));
|
|
1724
|
+
__classPrivateFieldGet(this, _SnapController_rollbackSnapshots, "f").set(snapId, {
|
|
1725
|
+
statePatches: [],
|
|
1726
|
+
permissions: {},
|
|
1727
|
+
newVersion: '',
|
|
1728
|
+
});
|
|
1729
|
+
const newRollbackSnapshot = __classPrivateFieldGet(this, _SnapController_rollbackSnapshots, "f").get(snapId);
|
|
1730
|
+
(0, utils_1.assert)(newRollbackSnapshot !== undefined, new Error(`Snapshot creation failed for ${snapId}.`));
|
|
1731
|
+
return newRollbackSnapshot;
|
|
1732
|
+
}, _SnapController_rollbackSnap =
|
|
1733
|
+
/**
|
|
1734
|
+
* Rolls back a snap to its previous state, permissions
|
|
1735
|
+
* and source code based on the `RollbackSnapshot` that
|
|
1736
|
+
* is captured during the update process. After rolling back,
|
|
1737
|
+
* the function also emits an event indicating that the
|
|
1738
|
+
* snap has been rolled back and it clears the snapshot
|
|
1739
|
+
* for that snap.
|
|
1740
|
+
*
|
|
1741
|
+
* @param snapId - The snap id.
|
|
1742
|
+
* @throws {@link Error}. If a snapshot does not exist.
|
|
1743
|
+
*/
|
|
1744
|
+
async function _SnapController_rollbackSnap(snapId) {
|
|
1745
|
+
const rollbackSnapshot = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRollbackSnapshot).call(this, snapId);
|
|
1746
|
+
if (!rollbackSnapshot) {
|
|
1747
|
+
throw new Error('A snapshot does not exist for this snap.');
|
|
1748
|
+
}
|
|
1749
|
+
await this.stopSnap(snapId, snaps_utils_1.SnapStatusEvents.Stop);
|
|
1750
|
+
// Always set to stopped even if it wasn't running initially
|
|
1751
|
+
if (this.get(snapId)?.status !== snaps_utils_1.SnapStatus.Stopped) {
|
|
1752
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_transition).call(this, snapId, snaps_utils_1.SnapStatusEvents.Stop);
|
|
1753
|
+
}
|
|
1754
|
+
const { statePatches, permissions } = rollbackSnapshot;
|
|
1755
|
+
if (statePatches?.length) {
|
|
1756
|
+
this.applyPatches(statePatches);
|
|
1757
|
+
}
|
|
1758
|
+
// Reset snap status, as we may have been in another state when we stored state patches
|
|
1759
|
+
// But now we are 100% in a stopped state
|
|
1760
|
+
if (this.get(snapId)?.status !== snaps_utils_1.SnapStatus.Stopped) {
|
|
1761
|
+
this.update((state) => {
|
|
1762
|
+
state.snaps[snapId].status = snaps_utils_1.SnapStatus.Stopped;
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
__classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_updatePermissions).call(this, {
|
|
1766
|
+
snapId,
|
|
1767
|
+
unusedPermissions: permissions.granted,
|
|
1768
|
+
newPermissions: permissions.revoked,
|
|
1769
|
+
requestData: permissions.requestData,
|
|
1770
|
+
});
|
|
1771
|
+
const truncatedSnap = this.getTruncatedExpect(snapId);
|
|
1772
|
+
this.messagingSystem.publish('SnapController:snapRolledback', truncatedSnap, rollbackSnapshot.newVersion);
|
|
1773
|
+
__classPrivateFieldGet(this, _SnapController_rollbackSnapshots, "f").delete(snapId);
|
|
1774
|
+
}, _SnapController_rollbackSnaps =
|
|
1775
|
+
/**
|
|
1776
|
+
* Iterates through an array of snap ids
|
|
1777
|
+
* and calls `rollbackSnap` on them.
|
|
1778
|
+
*
|
|
1779
|
+
* @param snapIds - An array of snap ids.
|
|
1780
|
+
*/
|
|
1781
|
+
async function _SnapController_rollbackSnaps(snapIds) {
|
|
1782
|
+
for (const snapId of snapIds) {
|
|
1783
|
+
await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_rollbackSnap).call(this, snapId);
|
|
1784
|
+
}
|
|
1785
|
+
}, _SnapController_getRuntime = function _SnapController_getRuntime(snapId) {
|
|
1786
|
+
return __classPrivateFieldGet(this, _SnapController_snapsRuntimeData, "f").get(snapId);
|
|
1787
|
+
}, _SnapController_getRuntimeExpect = function _SnapController_getRuntimeExpect(snapId) {
|
|
1788
|
+
const runtime = __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_getRuntime).call(this, snapId);
|
|
1789
|
+
(0, utils_1.assert)(runtime !== undefined, new Error(`Snap "${snapId}" runtime data not found`));
|
|
1790
|
+
return runtime;
|
|
1791
|
+
}, _SnapController_setupRuntime = function _SnapController_setupRuntime(snapId) {
|
|
1792
|
+
if (__classPrivateFieldGet(this, _SnapController_snapsRuntimeData, "f").has(snapId)) {
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1795
|
+
const snap = this.get(snapId);
|
|
1796
|
+
const interpreter = (0, fsm_1.interpret)(__classPrivateFieldGet(this, _SnapController_statusMachine, "f"));
|
|
1797
|
+
interpreter.start({
|
|
1798
|
+
context: { snapId },
|
|
1799
|
+
value: snap?.status ??
|
|
1800
|
+
__classPrivateFieldGet(this, _SnapController_statusMachine, "f").config.initial,
|
|
1801
|
+
});
|
|
1802
|
+
(0, fsm_2.forceStrict)(interpreter);
|
|
1803
|
+
__classPrivateFieldGet(this, _SnapController_snapsRuntimeData, "f").set(snapId, {
|
|
1804
|
+
lastRequest: null,
|
|
1805
|
+
rpcHandler: null,
|
|
1806
|
+
installPromise: null,
|
|
1807
|
+
encryptionKey: null,
|
|
1808
|
+
encryptionSalt: null,
|
|
1809
|
+
activeReferences: 0,
|
|
1810
|
+
pendingInboundRequests: [],
|
|
1811
|
+
pendingOutboundRequests: 0,
|
|
1812
|
+
interpreter,
|
|
1813
|
+
stopping: false,
|
|
1814
|
+
});
|
|
1815
|
+
}, _SnapController_calculatePermissionsChange = function _SnapController_calculatePermissionsChange(snapId, desiredPermissionsSet) {
|
|
1816
|
+
const oldPermissions = this.messagingSystem.call('PermissionController:getPermissions', snapId) ?? {};
|
|
1817
|
+
const newPermissions = (0, utils_2.permissionsDiff)(desiredPermissionsSet, oldPermissions);
|
|
1818
|
+
// TODO(ritave): The assumption that these are unused only holds so long as we do not
|
|
1819
|
+
// permit dynamic permission requests.
|
|
1820
|
+
const unusedPermissions = (0, utils_2.permissionsDiff)(oldPermissions, desiredPermissionsSet);
|
|
1821
|
+
// It's a Set Intersection of oldPermissions and desiredPermissionsSet
|
|
1822
|
+
// oldPermissions ∖ (oldPermissions ∖ desiredPermissionsSet) ⟺ oldPermissions ∩ desiredPermissionsSet
|
|
1823
|
+
const approvedPermissions = (0, utils_2.permissionsDiff)(oldPermissions, unusedPermissions);
|
|
1824
|
+
return { newPermissions, unusedPermissions, approvedPermissions };
|
|
1825
|
+
}, _SnapController_isSubjectConnectedToSnap = function _SnapController_isSubjectConnectedToSnap(snapId, origin) {
|
|
1826
|
+
const subjectPermissions = this.messagingSystem.call('PermissionController:getPermissions', origin);
|
|
1827
|
+
const existingCaveat = subjectPermissions?.[snaps_rpc_methods_1.WALLET_SNAP_PERMISSION_KEY]?.caveats?.find((caveat) => caveat.type === snaps_utils_1.SnapCaveatType.SnapIds);
|
|
1828
|
+
return Boolean(existingCaveat?.value?.[snapId]);
|
|
1829
|
+
}, _SnapController_calculateConnectionsChange = function _SnapController_calculateConnectionsChange(snapId, oldConnectionsSet, desiredConnectionsSet) {
|
|
1830
|
+
// Filter out any origins that have been revoked since last install/update.
|
|
1831
|
+
// That way they will be represented as new.
|
|
1832
|
+
const filteredOldConnections = Object.keys(oldConnectionsSet)
|
|
1833
|
+
.filter((origin) => __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_isSubjectConnectedToSnap).call(this, snapId, origin))
|
|
1834
|
+
.reduce((accumulator, origin) => {
|
|
1835
|
+
accumulator[origin] = oldConnectionsSet[origin];
|
|
1836
|
+
return accumulator;
|
|
1837
|
+
}, {});
|
|
1838
|
+
const newConnections = (0, utils_2.setDiff)(desiredConnectionsSet, filteredOldConnections);
|
|
1839
|
+
const unusedConnections = (0, utils_2.setDiff)(filteredOldConnections, desiredConnectionsSet);
|
|
1840
|
+
// It's a Set Intersection of oldConnections and desiredConnectionsSet
|
|
1841
|
+
// oldConnections ∖ (oldConnections ∖ desiredConnectionsSet) ⟺ oldConnections ∩ desiredConnectionsSet
|
|
1842
|
+
const approvedConnections = (0, utils_2.setDiff)(filteredOldConnections, unusedConnections);
|
|
1843
|
+
return { newConnections, unusedConnections, approvedConnections };
|
|
1844
|
+
}, _SnapController_updatePermissions = function _SnapController_updatePermissions({ snapId, unusedPermissions = {}, newPermissions = {}, requestData, }) {
|
|
1845
|
+
const unusedPermissionsKeys = Object.keys(unusedPermissions);
|
|
1846
|
+
if ((0, utils_1.isNonEmptyArray)(unusedPermissionsKeys)) {
|
|
1847
|
+
this.messagingSystem.call('PermissionController:revokePermissions', {
|
|
1848
|
+
[snapId]: unusedPermissionsKeys,
|
|
1849
|
+
});
|
|
1850
|
+
}
|
|
1851
|
+
if ((0, utils_1.isNonEmptyArray)(Object.keys(newPermissions))) {
|
|
1852
|
+
this.messagingSystem.call('PermissionController:grantPermissions', {
|
|
1853
|
+
approvedPermissions: newPermissions,
|
|
1854
|
+
subject: { origin: snapId },
|
|
1855
|
+
requestData,
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
}, _SnapController_isValidUpdate = function _SnapController_isValidUpdate(snapId, newVersionRange) {
|
|
1859
|
+
const existingSnap = this.getExpect(snapId);
|
|
1860
|
+
if ((0, utils_1.satisfiesVersionRange)(existingSnap.version, newVersionRange)) {
|
|
1861
|
+
return false;
|
|
1862
|
+
}
|
|
1863
|
+
if ((0, utils_1.gtRange)(existingSnap.version, newVersionRange)) {
|
|
1864
|
+
return false;
|
|
1865
|
+
}
|
|
1866
|
+
return true;
|
|
1867
|
+
}, _SnapController_callLifecycleHook =
|
|
1868
|
+
/**
|
|
1869
|
+
* Call a lifecycle hook on a snap, if the snap has the
|
|
1870
|
+
* `endowment:lifecycle-hooks` permission. If the snap does not have the
|
|
1871
|
+
* permission, nothing happens.
|
|
1872
|
+
*
|
|
1873
|
+
* @param origin - The origin.
|
|
1874
|
+
* @param snapId - The snap ID.
|
|
1875
|
+
* @param handler - The lifecycle hook to call. This should be one of the
|
|
1876
|
+
* supported lifecycle hooks.
|
|
1877
|
+
* @private
|
|
1878
|
+
*/
|
|
1879
|
+
async function _SnapController_callLifecycleHook(origin, snapId, handler) {
|
|
1880
|
+
const permissionName = snaps_rpc_methods_1.handlerEndowments[handler];
|
|
1881
|
+
(0, utils_1.assert)(permissionName, 'Lifecycle hook must have an endowment.');
|
|
1882
|
+
const hasPermission = this.messagingSystem.call('PermissionController:hasPermission', snapId, permissionName);
|
|
1883
|
+
if (!hasPermission) {
|
|
1884
|
+
return;
|
|
1885
|
+
}
|
|
1886
|
+
await this.handleRequest({
|
|
1887
|
+
snapId,
|
|
1888
|
+
handler,
|
|
1889
|
+
origin,
|
|
1890
|
+
request: {
|
|
1891
|
+
jsonrpc: '2.0',
|
|
1892
|
+
method: handler,
|
|
1893
|
+
},
|
|
1894
|
+
});
|
|
1895
|
+
};
|
|
1896
|
+
//# sourceMappingURL=SnapController.cjs.map
|