@metamask/snaps-controllers 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -562
- package/dist/cjs/cronjob/CronjobController.js +294 -0
- package/dist/cjs/cronjob/CronjobController.js.map +1 -0
- package/dist/cjs/cronjob/index.js +20 -0
- package/dist/cjs/cronjob/index.js.map +1 -0
- package/dist/cjs/fsm.js +69 -0
- package/dist/cjs/fsm.js.map +1 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/logging.js +15 -0
- package/dist/cjs/logging.js.map +1 -0
- package/dist/cjs/services/AbstractExecutionService.js +390 -0
- package/dist/cjs/services/AbstractExecutionService.js.map +1 -0
- package/dist/cjs/services/ExecutionService.js +7 -0
- package/dist/cjs/services/ExecutionService.js.map +1 -0
- package/dist/cjs/services/ProxyPostMessageStream.js +116 -0
- package/dist/cjs/services/ProxyPostMessageStream.js.map +1 -0
- package/dist/cjs/services/browser.js +32 -0
- package/dist/cjs/services/browser.js.map +1 -0
- package/dist/cjs/services/iframe/IframeExecutionService.js +54 -0
- package/dist/cjs/services/iframe/IframeExecutionService.js.map +1 -0
- package/dist/cjs/services/iframe/index.js +20 -0
- package/dist/cjs/services/iframe/index.js.map +1 -0
- package/dist/cjs/services/index.js +32 -0
- package/dist/cjs/services/index.js.map +1 -0
- package/dist/cjs/services/node/NodeProcessExecutionService.js +30 -0
- package/dist/cjs/services/node/NodeProcessExecutionService.js.map +1 -0
- package/dist/cjs/services/node/NodeThreadExecutionService.js +30 -0
- package/dist/cjs/services/node/NodeThreadExecutionService.js.map +1 -0
- package/dist/cjs/services/node/index.js +21 -0
- package/dist/cjs/services/node/index.js.map +1 -0
- package/dist/cjs/services/offscreen/OffscreenExecutionService.js +159 -0
- package/dist/cjs/services/offscreen/OffscreenExecutionService.js.map +1 -0
- package/dist/cjs/services/offscreen/index.js +20 -0
- package/dist/cjs/services/offscreen/index.js.map +1 -0
- package/dist/cjs/services/webworker/WebWorkerExecutionService.js +148 -0
- package/dist/cjs/services/webworker/WebWorkerExecutionService.js.map +1 -0
- package/dist/cjs/services/webworker/index.js +20 -0
- package/dist/cjs/services/webworker/index.js.map +1 -0
- package/dist/cjs/snaps/RequestQueue.js +63 -0
- package/dist/cjs/snaps/RequestQueue.js.map +1 -0
- package/dist/cjs/snaps/SnapController.js +1736 -0
- package/dist/cjs/snaps/SnapController.js.map +1 -0
- package/dist/cjs/snaps/Timer.js +117 -0
- package/dist/cjs/snaps/Timer.js.map +1 -0
- package/dist/cjs/snaps/endowments/cronjob.js +100 -0
- package/dist/cjs/snaps/endowments/cronjob.js.map +1 -0
- package/dist/cjs/snaps/endowments/enum.js +24 -0
- package/dist/cjs/snaps/endowments/enum.js.map +1 -0
- package/dist/cjs/snaps/endowments/ethereum-provider.js +43 -0
- package/dist/cjs/snaps/endowments/ethereum-provider.js.map +1 -0
- package/dist/cjs/snaps/endowments/index.js +90 -0
- package/dist/cjs/snaps/endowments/index.js.map +1 -0
- package/dist/cjs/snaps/endowments/lifecycle-hooks.js +37 -0
- package/dist/cjs/snaps/endowments/lifecycle-hooks.js.map +1 -0
- package/dist/cjs/snaps/endowments/long-running.js +38 -0
- package/dist/cjs/snaps/endowments/long-running.js.map +1 -0
- package/dist/cjs/snaps/endowments/name-lookup.js +106 -0
- package/dist/cjs/snaps/endowments/name-lookup.js.map +1 -0
- package/dist/cjs/snaps/endowments/network-access.js +44 -0
- package/dist/cjs/snaps/endowments/network-access.js.map +1 -0
- package/dist/cjs/snaps/endowments/rpc.js +99 -0
- package/dist/cjs/snaps/endowments/rpc.js.map +1 -0
- package/dist/cjs/snaps/endowments/transaction-insight.js +106 -0
- package/dist/cjs/snaps/endowments/transaction-insight.js.map +1 -0
- package/dist/cjs/snaps/endowments/web-assembly.js +42 -0
- package/dist/cjs/snaps/endowments/web-assembly.js.map +1 -0
- package/dist/cjs/snaps/index.js +25 -0
- package/dist/cjs/snaps/index.js.map +1 -0
- package/dist/cjs/snaps/location/http.js +106 -0
- package/dist/cjs/snaps/location/http.js.map +1 -0
- package/dist/cjs/snaps/location/index.js +23 -0
- package/dist/cjs/snaps/location/index.js.map +1 -0
- package/dist/cjs/snaps/location/local.js +93 -0
- package/dist/cjs/snaps/location/local.js.map +1 -0
- package/dist/cjs/snaps/location/location.js +34 -0
- package/dist/cjs/snaps/location/location.js.map +1 -0
- package/dist/cjs/snaps/location/npm.js +293 -0
- package/dist/cjs/snaps/location/npm.js.map +1 -0
- package/dist/cjs/snaps/permissions.js +61 -0
- package/dist/cjs/snaps/permissions.js.map +1 -0
- package/dist/cjs/snaps/registry/index.js +21 -0
- package/dist/cjs/snaps/registry/index.js.map +1 -0
- package/dist/cjs/snaps/registry/json.js +277 -0
- package/dist/cjs/snaps/registry/json.js.map +1 -0
- package/dist/cjs/snaps/registry/registry.js +18 -0
- package/dist/cjs/snaps/registry/registry.js.map +1 -0
- package/dist/cjs/snaps/selectors.js +13 -0
- package/dist/cjs/snaps/selectors.js.map +1 -0
- package/dist/cjs/utils.js +70 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/cronjob/CronjobController.js +279 -0
- package/dist/esm/cronjob/CronjobController.js.map +1 -0
- package/dist/esm/cronjob/index.js +3 -0
- package/dist/esm/cronjob/index.js.map +1 -0
- package/dist/esm/fsm.js +70 -0
- package/dist/esm/fsm.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logging.js +10 -0
- package/dist/esm/logging.js.map +1 -0
- package/dist/esm/services/AbstractExecutionService.js +373 -0
- package/dist/esm/services/AbstractExecutionService.js.map +1 -0
- package/dist/esm/services/ExecutionService.js +4 -0
- package/dist/esm/services/ExecutionService.js.map +1 -0
- package/dist/esm/services/ProxyPostMessageStream.js +109 -0
- package/dist/esm/services/ProxyPostMessageStream.js.map +1 -0
- package/dist/esm/services/browser.js +9 -0
- package/dist/esm/services/browser.js.map +1 -0
- package/dist/esm/services/iframe/IframeExecutionService.js +44 -0
- package/dist/esm/services/iframe/IframeExecutionService.js.map +1 -0
- package/dist/esm/services/iframe/index.js +3 -0
- package/dist/esm/services/iframe/index.js.map +1 -0
- package/dist/esm/services/index.js +9 -0
- package/dist/esm/services/index.js.map +1 -0
- package/dist/esm/services/node/NodeProcessExecutionService.js +20 -0
- package/dist/esm/services/node/NodeProcessExecutionService.js.map +1 -0
- package/dist/esm/services/node/NodeThreadExecutionService.js +21 -0
- package/dist/esm/services/node/NodeThreadExecutionService.js.map +1 -0
- package/dist/esm/services/node/index.js +4 -0
- package/dist/esm/services/node/index.js.map +1 -0
- package/dist/esm/services/offscreen/OffscreenExecutionService.js +149 -0
- package/dist/esm/services/offscreen/OffscreenExecutionService.js.map +1 -0
- package/dist/esm/services/offscreen/index.js +3 -0
- package/dist/esm/services/offscreen/index.js.map +1 -0
- package/dist/esm/services/webworker/WebWorkerExecutionService.js +130 -0
- package/dist/esm/services/webworker/WebWorkerExecutionService.js.map +1 -0
- package/dist/esm/services/webworker/index.js +3 -0
- package/dist/esm/services/webworker/index.js.map +1 -0
- package/dist/esm/snaps/RequestQueue.js +53 -0
- package/dist/esm/snaps/RequestQueue.js.map +1 -0
- package/dist/esm/snaps/SnapController.js +1715 -0
- package/dist/esm/snaps/SnapController.js.map +1 -0
- package/dist/esm/snaps/Timer.js +107 -0
- package/dist/esm/snaps/Timer.js.map +1 -0
- package/dist/esm/snaps/endowments/cronjob.js +99 -0
- package/dist/esm/snaps/endowments/cronjob.js.map +1 -0
- package/dist/esm/snaps/endowments/enum.js +14 -0
- package/dist/esm/snaps/endowments/enum.js.map +1 -0
- package/dist/esm/snaps/endowments/ethereum-provider.js +33 -0
- package/dist/esm/snaps/endowments/ethereum-provider.js.map +1 -0
- package/dist/esm/snaps/endowments/index.js +47 -0
- package/dist/esm/snaps/endowments/index.js.map +1 -0
- package/dist/esm/snaps/endowments/lifecycle-hooks.js +27 -0
- package/dist/esm/snaps/endowments/lifecycle-hooks.js.map +1 -0
- package/dist/esm/snaps/endowments/long-running.js +28 -0
- package/dist/esm/snaps/endowments/long-running.js.map +1 -0
- package/dist/esm/snaps/endowments/name-lookup.js +98 -0
- package/dist/esm/snaps/endowments/name-lookup.js.map +1 -0
- package/dist/esm/snaps/endowments/network-access.js +34 -0
- package/dist/esm/snaps/endowments/network-access.js.map +1 -0
- package/dist/esm/snaps/endowments/rpc.js +88 -0
- package/dist/esm/snaps/endowments/rpc.js.map +1 -0
- package/dist/esm/snaps/endowments/transaction-insight.js +99 -0
- package/dist/esm/snaps/endowments/transaction-insight.js.map +1 -0
- package/dist/esm/snaps/endowments/web-assembly.js +32 -0
- package/dist/esm/snaps/endowments/web-assembly.js.map +1 -0
- package/dist/esm/snaps/index.js +8 -0
- package/dist/esm/snaps/index.js.map +1 -0
- package/dist/{snaps → esm/snaps}/location/http.js +52 -31
- package/dist/esm/snaps/location/http.js.map +1 -0
- package/dist/esm/snaps/location/index.js +6 -0
- package/dist/esm/snaps/location/index.js.map +1 -0
- package/dist/esm/snaps/location/local.js +83 -0
- package/dist/esm/snaps/location/local.js.map +1 -0
- package/dist/esm/snaps/location/location.js +30 -0
- package/dist/esm/snaps/location/location.js.map +1 -0
- package/dist/{snaps → esm/snaps}/location/npm.js +143 -117
- package/dist/esm/snaps/location/npm.js.map +1 -0
- package/dist/esm/snaps/permissions.js +50 -0
- package/dist/esm/snaps/permissions.js.map +1 -0
- package/dist/esm/snaps/registry/index.js +4 -0
- package/dist/esm/snaps/registry/index.js.map +1 -0
- package/dist/esm/snaps/registry/json.js +267 -0
- package/dist/esm/snaps/registry/json.js.map +1 -0
- package/dist/esm/snaps/registry/registry.js +8 -0
- package/dist/esm/snaps/registry/registry.js.map +1 -0
- package/dist/esm/snaps/selectors.js +3 -0
- package/dist/esm/snaps/selectors.js.map +1 -0
- package/dist/{utils.js → esm/utils.js} +21 -30
- package/dist/esm/utils.js.map +1 -0
- package/dist/{cronjob → types/cronjob}/CronjobController.d.ts +12 -11
- package/dist/{fsm.d.ts → types/fsm.d.ts} +1 -1
- package/dist/{index.d.ts → types/index.d.ts} +0 -1
- package/dist/{services → types/services}/AbstractExecutionService.d.ts +4 -4
- package/dist/{services → types/services}/ExecutionService.d.ts +3 -3
- package/dist/{services/offscreen/OffscreenPostMessageStream.d.ts → types/services/ProxyPostMessageStream.d.ts} +10 -10
- package/dist/{services → types/services}/browser.d.ts +2 -0
- package/dist/{services → types/services}/iframe/IframeExecutionService.d.ts +3 -2
- package/dist/{services → types/services}/index.d.ts +2 -0
- package/dist/{services → types/services}/node/NodeProcessExecutionService.d.ts +4 -3
- package/dist/{services → types/services}/node/NodeThreadExecutionService.d.ts +3 -2
- package/dist/{services → types/services}/offscreen/OffscreenExecutionService.d.ts +4 -3
- package/dist/types/services/offscreen/index.d.ts +1 -0
- package/dist/types/services/webworker/WebWorkerExecutionService.d.ts +45 -0
- package/dist/types/services/webworker/index.d.ts +1 -0
- package/dist/{snaps → types/snaps}/SnapController.d.ts +78 -39
- package/dist/{snaps → types/snaps}/endowments/cronjob.d.ts +5 -3
- package/dist/{snaps → types/snaps}/endowments/enum.d.ts +3 -2
- package/dist/{snaps → types/snaps}/endowments/ethereum-provider.d.ts +2 -1
- package/dist/{snaps → types/snaps}/endowments/index.d.ts +23 -14
- package/dist/types/snaps/endowments/lifecycle-hooks.d.ts +15 -0
- package/dist/{snaps → types/snaps}/endowments/long-running.d.ts +2 -1
- package/dist/types/snaps/endowments/name-lookup.d.ts +38 -0
- package/dist/{snaps → types/snaps}/endowments/network-access.d.ts +2 -1
- package/dist/{snaps → types/snaps}/endowments/rpc.d.ts +5 -3
- package/dist/{snaps → types/snaps}/endowments/transaction-insight.d.ts +3 -2
- package/dist/{snaps → types/snaps}/endowments/web-assembly.d.ts +2 -1
- package/dist/{snaps → types/snaps}/index.d.ts +2 -0
- package/dist/{snaps → types/snaps}/location/http.d.ts +3 -2
- package/dist/{snaps → types/snaps}/location/local.d.ts +3 -3
- package/dist/{snaps → types/snaps}/location/location.d.ts +2 -2
- package/dist/types/snaps/location/npm.d.ts +49 -0
- package/dist/types/snaps/permissions.d.ts +16 -0
- package/dist/{snaps → types/snaps}/registry/json.d.ts +5 -4
- package/dist/{snaps → types/snaps}/registry/registry.d.ts +5 -5
- package/dist/types/snaps/selectors.d.ts +2 -0
- package/dist/{utils.d.ts → types/utils.d.ts} +14 -14
- package/package.json +55 -45
- package/dist/cronjob/CronjobController.js +0 -248
- package/dist/cronjob/CronjobController.js.map +0 -1
- package/dist/cronjob/index.js +0 -18
- package/dist/cronjob/index.js.map +0 -1
- package/dist/fsm.js +0 -75
- package/dist/fsm.js.map +0 -1
- package/dist/index.js +0 -22
- package/dist/index.js.map +0 -1
- package/dist/logging.js +0 -13
- package/dist/logging.js.map +0 -1
- package/dist/multichain/MultiChainController.d.ts +0 -137
- package/dist/multichain/MultiChainController.js +0 -339
- package/dist/multichain/MultiChainController.js.map +0 -1
- package/dist/multichain/index.d.ts +0 -3
- package/dist/multichain/index.js +0 -20
- package/dist/multichain/index.js.map +0 -1
- package/dist/multichain/matching.d.ts +0 -9
- package/dist/multichain/matching.js +0 -57
- package/dist/multichain/matching.js.map +0 -1
- package/dist/multichain/middleware.d.ts +0 -14
- package/dist/multichain/middleware.js +0 -42
- package/dist/multichain/middleware.js.map +0 -1
- package/dist/services/AbstractExecutionService.js +0 -318
- package/dist/services/AbstractExecutionService.js.map +0 -1
- package/dist/services/ExecutionService.js +0 -4
- package/dist/services/ExecutionService.js.map +0 -1
- package/dist/services/browser.js +0 -22
- package/dist/services/browser.js.map +0 -1
- package/dist/services/iframe/IframeExecutionService.js +0 -30
- package/dist/services/iframe/IframeExecutionService.js.map +0 -1
- package/dist/services/iframe/index.js +0 -18
- package/dist/services/iframe/index.js.map +0 -1
- package/dist/services/index.js +0 -22
- package/dist/services/index.js.map +0 -1
- package/dist/services/node/NodeProcessExecutionService.js +0 -18
- package/dist/services/node/NodeProcessExecutionService.js.map +0 -1
- package/dist/services/node/NodeThreadExecutionService.js +0 -19
- package/dist/services/node/NodeThreadExecutionService.js.map +0 -1
- package/dist/services/node/index.js +0 -19
- package/dist/services/node/index.js.map +0 -1
- package/dist/services/offscreen/OffscreenExecutionService.js +0 -100
- package/dist/services/offscreen/OffscreenExecutionService.js.map +0 -1
- package/dist/services/offscreen/OffscreenPostMessageStream.js +0 -66
- package/dist/services/offscreen/OffscreenPostMessageStream.js.map +0 -1
- package/dist/services/offscreen/index.d.ts +0 -2
- package/dist/services/offscreen/index.js +0 -19
- package/dist/services/offscreen/index.js.map +0 -1
- package/dist/snaps/RequestQueue.js +0 -44
- package/dist/snaps/RequestQueue.js.map +0 -1
- package/dist/snaps/SnapController.js +0 -1478
- package/dist/snaps/SnapController.js.map +0 -1
- package/dist/snaps/Timer.js +0 -86
- package/dist/snaps/Timer.js.map +0 -1
- package/dist/snaps/endowments/cronjob.js +0 -105
- package/dist/snaps/endowments/cronjob.js.map +0 -1
- package/dist/snaps/endowments/enum.js +0 -15
- package/dist/snaps/endowments/enum.js.map +0 -1
- package/dist/snaps/endowments/ethereum-provider.js +0 -32
- package/dist/snaps/endowments/ethereum-provider.js.map +0 -1
- package/dist/snaps/endowments/index.js +0 -60
- package/dist/snaps/endowments/index.js.map +0 -1
- package/dist/snaps/endowments/keyring.d.ts +0 -40
- package/dist/snaps/endowments/keyring.js +0 -103
- package/dist/snaps/endowments/keyring.js.map +0 -1
- package/dist/snaps/endowments/long-running.js +0 -29
- package/dist/snaps/endowments/long-running.js.map +0 -1
- package/dist/snaps/endowments/network-access.js +0 -30
- package/dist/snaps/endowments/network-access.js.map +0 -1
- package/dist/snaps/endowments/rpc.js +0 -92
- package/dist/snaps/endowments/rpc.js.map +0 -1
- package/dist/snaps/endowments/transaction-insight.js +0 -106
- package/dist/snaps/endowments/transaction-insight.js.map +0 -1
- package/dist/snaps/endowments/web-assembly.js +0 -31
- package/dist/snaps/endowments/web-assembly.js.map +0 -1
- package/dist/snaps/index.js +0 -21
- package/dist/snaps/index.js.map +0 -1
- package/dist/snaps/location/http.js.map +0 -1
- package/dist/snaps/location/index.js +0 -21
- package/dist/snaps/location/index.js.map +0 -1
- package/dist/snaps/location/local.js +0 -51
- package/dist/snaps/location/local.js.map +0 -1
- package/dist/snaps/location/location.js +0 -34
- package/dist/snaps/location/location.js.map +0 -1
- package/dist/snaps/location/npm.d.ts +0 -28
- package/dist/snaps/location/npm.js.map +0 -1
- package/dist/snaps/registry/index.js +0 -19
- package/dist/snaps/registry/index.js.map +0 -1
- package/dist/snaps/registry/json.js +0 -197
- package/dist/snaps/registry/json.js.map +0 -1
- package/dist/snaps/registry/registry.js +0 -11
- package/dist/snaps/registry/registry.js.map +0 -1
- package/dist/snaps/selectors.d.ts +0 -2
- package/dist/snaps/selectors.js +0 -6
- package/dist/snaps/selectors.js.map +0 -1
- package/dist/utils.js.map +0 -1
- /package/dist/{cronjob → types/cronjob}/index.d.ts +0 -0
- /package/dist/{logging.d.ts → types/logging.d.ts} +0 -0
- /package/dist/{services → types/services}/iframe/index.d.ts +0 -0
- /package/dist/{services → types/services}/node/index.d.ts +0 -0
- /package/dist/{snaps → types/snaps}/RequestQueue.d.ts +0 -0
- /package/dist/{snaps → types/snaps}/Timer.d.ts +0 -0
- /package/dist/{snaps → types/snaps}/location/index.d.ts +0 -0
- /package/dist/{snaps → types/snaps}/registry/index.d.ts +0 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
2
|
+
if (privateCollection.has(obj)) {
|
|
3
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
7
|
+
if (descriptor.get) {
|
|
8
|
+
return descriptor.get.call(receiver);
|
|
9
|
+
}
|
|
10
|
+
return descriptor.value;
|
|
11
|
+
}
|
|
12
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
13
|
+
if (descriptor.set) {
|
|
14
|
+
descriptor.set.call(receiver, value);
|
|
15
|
+
} else {
|
|
16
|
+
if (!descriptor.writable) {
|
|
17
|
+
throw new TypeError("attempted to set read only private field");
|
|
18
|
+
}
|
|
19
|
+
descriptor.value = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
23
|
+
if (!privateMap.has(receiver)) {
|
|
24
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
25
|
+
}
|
|
26
|
+
return privateMap.get(receiver);
|
|
27
|
+
}
|
|
28
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
29
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
30
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
31
|
+
}
|
|
32
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
33
|
+
_check_private_redeclaration(obj, privateMap);
|
|
34
|
+
privateMap.set(obj, value);
|
|
35
|
+
}
|
|
36
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
37
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
38
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
function _class_private_method_get(receiver, privateSet, fn) {
|
|
42
|
+
if (!privateSet.has(receiver)) {
|
|
43
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
44
|
+
}
|
|
45
|
+
return fn;
|
|
46
|
+
}
|
|
47
|
+
function _class_private_method_init(obj, privateSet) {
|
|
48
|
+
_check_private_redeclaration(obj, privateSet);
|
|
49
|
+
privateSet.add(obj);
|
|
50
|
+
}
|
|
51
|
+
import { BaseControllerV2 as BaseController } from '@metamask/base-controller';
|
|
52
|
+
import { verify } from '@metamask/snaps-registry';
|
|
53
|
+
import { assert, Duration, inMilliseconds, satisfiesVersionRange } from '@metamask/utils';
|
|
54
|
+
import { SnapsRegistryStatus } from './registry';
|
|
55
|
+
// TODO: Replace with a Codefi URL
|
|
56
|
+
const SNAP_REGISTRY_URL = 'https://cdn.jsdelivr.net/gh/MetaMask/snaps-registry@gh-pages/latest/registry.json';
|
|
57
|
+
const SNAP_REGISTRY_SIGNATURE_URL = 'https://cdn.jsdelivr.net/gh/MetaMask/snaps-registry@gh-pages/latest/signature.json';
|
|
58
|
+
const controllerName = 'SnapsRegistry';
|
|
59
|
+
const defaultState = {
|
|
60
|
+
database: null,
|
|
61
|
+
lastUpdated: null
|
|
62
|
+
};
|
|
63
|
+
var _url = /*#__PURE__*/ new WeakMap(), _publicKey = /*#__PURE__*/ new WeakMap(), _fetchFunction = /*#__PURE__*/ new WeakMap(), _recentFetchThreshold = /*#__PURE__*/ new WeakMap(), _refetchOnAllowlistMiss = /*#__PURE__*/ new WeakMap(), _failOnUnavailableRegistry = /*#__PURE__*/ new WeakMap(), _currentUpdate = /*#__PURE__*/ new WeakMap(), _wasRecentlyFetched = /*#__PURE__*/ new WeakSet(), _triggerUpdate = /*#__PURE__*/ new WeakSet(), _update = /*#__PURE__*/ new WeakSet(), _getDatabase = /*#__PURE__*/ new WeakSet(), _getSingle = /*#__PURE__*/ new WeakSet(), _get = /*#__PURE__*/ new WeakSet(), _getMetadata = /*#__PURE__*/ new WeakSet(), _verifySignature = /*#__PURE__*/ new WeakSet(), _safeFetch = /*#__PURE__*/ new WeakSet();
|
|
64
|
+
export class JsonSnapsRegistry extends BaseController {
|
|
65
|
+
constructor({ messenger, state, url = {
|
|
66
|
+
registry: SNAP_REGISTRY_URL,
|
|
67
|
+
signature: SNAP_REGISTRY_SIGNATURE_URL
|
|
68
|
+
}, publicKey, fetchFunction = globalThis.fetch.bind(globalThis), recentFetchThreshold = inMilliseconds(5, Duration.Minute), failOnUnavailableRegistry = true, refetchOnAllowlistMiss = true }){
|
|
69
|
+
super({
|
|
70
|
+
messenger,
|
|
71
|
+
metadata: {
|
|
72
|
+
database: {
|
|
73
|
+
persist: true,
|
|
74
|
+
anonymous: false
|
|
75
|
+
},
|
|
76
|
+
lastUpdated: {
|
|
77
|
+
persist: true,
|
|
78
|
+
anonymous: false
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
name: controllerName,
|
|
82
|
+
state: {
|
|
83
|
+
...defaultState,
|
|
84
|
+
...state
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
_class_private_method_init(this, _wasRecentlyFetched);
|
|
88
|
+
/**
|
|
89
|
+
* Triggers an update of the registry database.
|
|
90
|
+
*
|
|
91
|
+
* If an existing update is in progress this function will await that update.
|
|
92
|
+
*/ _class_private_method_init(this, _triggerUpdate);
|
|
93
|
+
/**
|
|
94
|
+
* Updates the registry database if the registry hasn't been updated recently.
|
|
95
|
+
*
|
|
96
|
+
* NOTE: SHOULD NOT be called directly, instead `triggerUpdate` should be used.
|
|
97
|
+
*/ _class_private_method_init(this, _update);
|
|
98
|
+
_class_private_method_init(this, _getDatabase);
|
|
99
|
+
_class_private_method_init(this, _getSingle);
|
|
100
|
+
_class_private_method_init(this, _get);
|
|
101
|
+
/**
|
|
102
|
+
* Get metadata for the given snap ID.
|
|
103
|
+
*
|
|
104
|
+
* @param snapId - The ID of the snap to get metadata for.
|
|
105
|
+
* @returns The metadata for the given snap ID, or `null` if the snap is not
|
|
106
|
+
* verified.
|
|
107
|
+
*/ _class_private_method_init(this, _getMetadata);
|
|
108
|
+
/**
|
|
109
|
+
* Verify the signature of the registry.
|
|
110
|
+
*
|
|
111
|
+
* @param database - The registry database.
|
|
112
|
+
* @param signature - The signature of the registry.
|
|
113
|
+
* @throws If the signature is invalid.
|
|
114
|
+
* @private
|
|
115
|
+
*/ _class_private_method_init(this, _verifySignature);
|
|
116
|
+
/**
|
|
117
|
+
* Fetch the given URL, throwing if the response is not OK.
|
|
118
|
+
*
|
|
119
|
+
* @param url - The URL to fetch.
|
|
120
|
+
* @returns The response body.
|
|
121
|
+
* @private
|
|
122
|
+
*/ _class_private_method_init(this, _safeFetch);
|
|
123
|
+
_class_private_field_init(this, _url, {
|
|
124
|
+
writable: true,
|
|
125
|
+
value: void 0
|
|
126
|
+
});
|
|
127
|
+
_class_private_field_init(this, _publicKey, {
|
|
128
|
+
writable: true,
|
|
129
|
+
value: void 0
|
|
130
|
+
});
|
|
131
|
+
_class_private_field_init(this, _fetchFunction, {
|
|
132
|
+
writable: true,
|
|
133
|
+
value: void 0
|
|
134
|
+
});
|
|
135
|
+
_class_private_field_init(this, _recentFetchThreshold, {
|
|
136
|
+
writable: true,
|
|
137
|
+
value: void 0
|
|
138
|
+
});
|
|
139
|
+
_class_private_field_init(this, _refetchOnAllowlistMiss, {
|
|
140
|
+
writable: true,
|
|
141
|
+
value: void 0
|
|
142
|
+
});
|
|
143
|
+
_class_private_field_init(this, _failOnUnavailableRegistry, {
|
|
144
|
+
writable: true,
|
|
145
|
+
value: void 0
|
|
146
|
+
});
|
|
147
|
+
_class_private_field_init(this, _currentUpdate, {
|
|
148
|
+
writable: true,
|
|
149
|
+
value: void 0
|
|
150
|
+
});
|
|
151
|
+
_class_private_field_set(this, _url, url);
|
|
152
|
+
_class_private_field_set(this, _publicKey, publicKey);
|
|
153
|
+
_class_private_field_set(this, _fetchFunction, fetchFunction);
|
|
154
|
+
_class_private_field_set(this, _recentFetchThreshold, recentFetchThreshold);
|
|
155
|
+
_class_private_field_set(this, _refetchOnAllowlistMiss, refetchOnAllowlistMiss);
|
|
156
|
+
_class_private_field_set(this, _failOnUnavailableRegistry, failOnUnavailableRegistry);
|
|
157
|
+
_class_private_field_set(this, _currentUpdate, null);
|
|
158
|
+
this.messagingSystem.registerActionHandler('SnapsRegistry:get', async (...args)=>_class_private_method_get(this, _get, get).call(this, ...args));
|
|
159
|
+
this.messagingSystem.registerActionHandler('SnapsRegistry:getMetadata', async (...args)=>_class_private_method_get(this, _getMetadata, getMetadata).call(this, ...args));
|
|
160
|
+
this.messagingSystem.registerActionHandler('SnapsRegistry:update', async ()=>_class_private_method_get(this, _triggerUpdate, triggerUpdate).call(this));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function wasRecentlyFetched() {
|
|
164
|
+
return this.state.lastUpdated && Date.now() - this.state.lastUpdated < _class_private_field_get(this, _recentFetchThreshold);
|
|
165
|
+
}
|
|
166
|
+
async function triggerUpdate() {
|
|
167
|
+
// If an update is ongoing, wait for that.
|
|
168
|
+
if (_class_private_field_get(this, _currentUpdate)) {
|
|
169
|
+
await _class_private_field_get(this, _currentUpdate);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// If no update exists, create promise and store globally.
|
|
173
|
+
if (_class_private_field_get(this, _currentUpdate) === null) {
|
|
174
|
+
_class_private_field_set(this, _currentUpdate, _class_private_method_get(this, _update, update).call(this));
|
|
175
|
+
}
|
|
176
|
+
await _class_private_field_get(this, _currentUpdate);
|
|
177
|
+
_class_private_field_set(this, _currentUpdate, null);
|
|
178
|
+
}
|
|
179
|
+
async function update() {
|
|
180
|
+
// No-op if we recently fetched the registry.
|
|
181
|
+
if (_class_private_method_get(this, _wasRecentlyFetched, wasRecentlyFetched).call(this)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const database = await _class_private_method_get(this, _safeFetch, safeFetch).call(this, _class_private_field_get(this, _url).registry);
|
|
186
|
+
if (_class_private_field_get(this, _publicKey)) {
|
|
187
|
+
const signature = await _class_private_method_get(this, _safeFetch, safeFetch).call(this, _class_private_field_get(this, _url).signature);
|
|
188
|
+
await _class_private_method_get(this, _verifySignature, verifySignature).call(this, database, signature);
|
|
189
|
+
}
|
|
190
|
+
this.update((state)=>{
|
|
191
|
+
state.database = JSON.parse(database);
|
|
192
|
+
state.lastUpdated = Date.now();
|
|
193
|
+
});
|
|
194
|
+
} catch {
|
|
195
|
+
// Ignore
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async function getDatabase() {
|
|
199
|
+
if (this.state.database === null) {
|
|
200
|
+
await _class_private_method_get(this, _triggerUpdate, triggerUpdate).call(this);
|
|
201
|
+
}
|
|
202
|
+
// If the database is still null and we require it, throw.
|
|
203
|
+
if (_class_private_field_get(this, _failOnUnavailableRegistry) && this.state.database === null) {
|
|
204
|
+
throw new Error('Snaps registry is unavailable, installation blocked.');
|
|
205
|
+
}
|
|
206
|
+
return this.state.database;
|
|
207
|
+
}
|
|
208
|
+
async function getSingle(snapId, snapInfo, refetch = false) {
|
|
209
|
+
const database = await _class_private_method_get(this, _getDatabase, getDatabase).call(this);
|
|
210
|
+
const blockedEntry = database?.blockedSnaps.find((blocked)=>{
|
|
211
|
+
if ('id' in blocked) {
|
|
212
|
+
return blocked.id === snapId && satisfiesVersionRange(snapInfo.version, blocked.versionRange);
|
|
213
|
+
}
|
|
214
|
+
return blocked.checksum === snapInfo.checksum;
|
|
215
|
+
});
|
|
216
|
+
if (blockedEntry) {
|
|
217
|
+
return {
|
|
218
|
+
status: SnapsRegistryStatus.Blocked,
|
|
219
|
+
reason: blockedEntry.reason
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const verified = database?.verifiedSnaps[snapId];
|
|
223
|
+
const version = verified?.versions?.[snapInfo.version];
|
|
224
|
+
if (version && version.checksum === snapInfo.checksum) {
|
|
225
|
+
return {
|
|
226
|
+
status: SnapsRegistryStatus.Verified
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
// For now, if we have an allowlist miss, we can refetch once and try again.
|
|
230
|
+
if (_class_private_field_get(this, _refetchOnAllowlistMiss) && !refetch) {
|
|
231
|
+
await _class_private_method_get(this, _triggerUpdate, triggerUpdate).call(this);
|
|
232
|
+
return _class_private_method_get(this, _getSingle, getSingle).call(this, snapId, snapInfo, true);
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
status: SnapsRegistryStatus.Unverified
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
async function get(snaps) {
|
|
239
|
+
return Object.entries(snaps).reduce(async (previousPromise, [snapId, snapInfo])=>{
|
|
240
|
+
const result = await _class_private_method_get(this, _getSingle, getSingle).call(this, snapId, snapInfo);
|
|
241
|
+
const acc = await previousPromise;
|
|
242
|
+
acc[snapId] = result;
|
|
243
|
+
return acc;
|
|
244
|
+
}, Promise.resolve({}));
|
|
245
|
+
}
|
|
246
|
+
async function getMetadata(snapId) {
|
|
247
|
+
const database = await _class_private_method_get(this, _getDatabase, getDatabase).call(this);
|
|
248
|
+
return database?.verifiedSnaps[snapId]?.metadata ?? null;
|
|
249
|
+
}
|
|
250
|
+
async function verifySignature(database, signature) {
|
|
251
|
+
assert(_class_private_field_get(this, _publicKey), 'No public key provided.');
|
|
252
|
+
const valid = await verify({
|
|
253
|
+
registry: database,
|
|
254
|
+
signature: JSON.parse(signature),
|
|
255
|
+
publicKey: _class_private_field_get(this, _publicKey)
|
|
256
|
+
});
|
|
257
|
+
assert(valid, 'Invalid registry signature.');
|
|
258
|
+
}
|
|
259
|
+
async function safeFetch(url) {
|
|
260
|
+
const response = await _class_private_field_get(this, _fetchFunction).call(this, url);
|
|
261
|
+
if (!response.ok) {
|
|
262
|
+
throw new Error(`Failed to fetch ${url}.`);
|
|
263
|
+
}
|
|
264
|
+
return await response.text();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/snaps/registry/json.ts"],"sourcesContent":["import type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseControllerV2 as BaseController } from '@metamask/base-controller';\nimport type { SnapsRegistryDatabase } from '@metamask/snaps-registry';\nimport { verify } from '@metamask/snaps-registry';\nimport type { SnapId } from '@metamask/snaps-utils';\nimport type { Hex } from '@metamask/utils';\nimport {\n assert,\n Duration,\n inMilliseconds,\n satisfiesVersionRange,\n} from '@metamask/utils';\n\nimport type {\n SnapsRegistry,\n SnapsRegistryInfo,\n SnapsRegistryMetadata,\n SnapsRegistryRequest,\n SnapsRegistryResult,\n} from './registry';\nimport { SnapsRegistryStatus } from './registry';\n\n// TODO: Replace with a Codefi URL\nconst SNAP_REGISTRY_URL =\n 'https://cdn.jsdelivr.net/gh/MetaMask/snaps-registry@gh-pages/latest/registry.json';\n\nconst SNAP_REGISTRY_SIGNATURE_URL =\n 'https://cdn.jsdelivr.net/gh/MetaMask/snaps-registry@gh-pages/latest/signature.json';\n\ntype JsonSnapsRegistryUrl = {\n registry: string;\n signature: string;\n};\n\nexport type JsonSnapsRegistryArgs = {\n messenger: SnapsRegistryMessenger;\n state?: SnapsRegistryState;\n fetchFunction?: typeof fetch;\n url?: JsonSnapsRegistryUrl;\n recentFetchThreshold?: number;\n refetchOnAllowlistMiss?: boolean;\n failOnUnavailableRegistry?: boolean;\n publicKey?: Hex;\n};\n\nexport type GetResult = {\n type: `${typeof controllerName}:get`;\n handler: SnapsRegistry['get'];\n};\n\nexport type GetMetadata = {\n type: `${typeof controllerName}:getMetadata`;\n handler: SnapsRegistry['getMetadata'];\n};\n\nexport type Update = {\n type: `${typeof controllerName}:update`;\n handler: SnapsRegistry['update'];\n};\n\nexport type SnapsRegistryActions = GetResult | GetMetadata | Update;\n\nexport type SnapsRegistryEvents = never;\n\nexport type SnapsRegistryMessenger = RestrictedControllerMessenger<\n 'SnapsRegistry',\n SnapsRegistryActions,\n SnapsRegistryEvents,\n SnapsRegistryActions['type'],\n SnapsRegistryEvents['type']\n>;\n\nexport type SnapsRegistryState = {\n database: SnapsRegistryDatabase | null;\n lastUpdated: number | null;\n};\n\nconst controllerName = 'SnapsRegistry';\n\nconst defaultState = {\n database: null,\n lastUpdated: null,\n};\n\nexport class JsonSnapsRegistry extends BaseController<\n typeof controllerName,\n SnapsRegistryState,\n SnapsRegistryMessenger\n> {\n #url: JsonSnapsRegistryUrl;\n\n #publicKey?: Hex;\n\n #fetchFunction: typeof fetch;\n\n #recentFetchThreshold: number;\n\n #refetchOnAllowlistMiss: boolean;\n\n #failOnUnavailableRegistry: boolean;\n\n #currentUpdate: Promise<void> | null;\n\n constructor({\n messenger,\n state,\n url = {\n registry: SNAP_REGISTRY_URL,\n signature: SNAP_REGISTRY_SIGNATURE_URL,\n },\n publicKey,\n fetchFunction = globalThis.fetch.bind(globalThis),\n recentFetchThreshold = inMilliseconds(5, Duration.Minute),\n failOnUnavailableRegistry = true,\n refetchOnAllowlistMiss = true,\n }: JsonSnapsRegistryArgs) {\n super({\n messenger,\n metadata: {\n database: { persist: true, anonymous: false },\n lastUpdated: { persist: true, anonymous: false },\n },\n name: controllerName,\n state: {\n ...defaultState,\n ...state,\n },\n });\n this.#url = url;\n this.#publicKey = publicKey;\n this.#fetchFunction = fetchFunction;\n this.#recentFetchThreshold = recentFetchThreshold;\n this.#refetchOnAllowlistMiss = refetchOnAllowlistMiss;\n this.#failOnUnavailableRegistry = failOnUnavailableRegistry;\n this.#currentUpdate = null;\n\n this.messagingSystem.registerActionHandler(\n 'SnapsRegistry:get',\n async (...args) => this.#get(...args),\n );\n this.messagingSystem.registerActionHandler(\n 'SnapsRegistry:getMetadata',\n async (...args) => this.#getMetadata(...args),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SnapsRegistry:update',\n async () => this.#triggerUpdate(),\n );\n }\n\n #wasRecentlyFetched() {\n return (\n this.state.lastUpdated &&\n Date.now() - this.state.lastUpdated < this.#recentFetchThreshold\n );\n }\n\n /**\n * Triggers an update of the registry database.\n *\n * If an existing update is in progress this function will await that update.\n */\n async #triggerUpdate() {\n // If an update is ongoing, wait for that.\n if (this.#currentUpdate) {\n await this.#currentUpdate;\n return;\n }\n // If no update exists, create promise and store globally.\n if (this.#currentUpdate === null) {\n this.#currentUpdate = this.#update();\n }\n await this.#currentUpdate;\n this.#currentUpdate = null;\n }\n\n /**\n * Updates the registry database if the registry hasn't been updated recently.\n *\n * NOTE: SHOULD NOT be called directly, instead `triggerUpdate` should be used.\n */\n async #update() {\n // No-op if we recently fetched the registry.\n if (this.#wasRecentlyFetched()) {\n return;\n }\n\n try {\n const database = await this.#safeFetch(this.#url.registry);\n\n if (this.#publicKey) {\n const signature = await this.#safeFetch(this.#url.signature);\n await this.#verifySignature(database, signature);\n }\n\n this.update((state) => {\n state.database = JSON.parse(database);\n state.lastUpdated = Date.now();\n });\n } catch {\n // Ignore\n }\n }\n\n async #getDatabase(): Promise<SnapsRegistryDatabase | null> {\n if (this.state.database === null) {\n await this.#triggerUpdate();\n }\n\n // If the database is still null and we require it, throw.\n if (this.#failOnUnavailableRegistry && this.state.database === null) {\n throw new Error('Snaps registry is unavailable, installation blocked.');\n }\n return this.state.database;\n }\n\n async #getSingle(\n snapId: SnapId,\n snapInfo: SnapsRegistryInfo,\n refetch = false,\n ): Promise<SnapsRegistryResult> {\n const database = await this.#getDatabase();\n\n const blockedEntry = database?.blockedSnaps.find((blocked) => {\n if ('id' in blocked) {\n return (\n blocked.id === snapId &&\n satisfiesVersionRange(snapInfo.version, blocked.versionRange)\n );\n }\n\n return blocked.checksum === snapInfo.checksum;\n });\n\n if (blockedEntry) {\n return {\n status: SnapsRegistryStatus.Blocked,\n reason: blockedEntry.reason,\n };\n }\n\n const verified = database?.verifiedSnaps[snapId];\n const version = verified?.versions?.[snapInfo.version];\n if (version && version.checksum === snapInfo.checksum) {\n return { status: SnapsRegistryStatus.Verified };\n }\n // For now, if we have an allowlist miss, we can refetch once and try again.\n if (this.#refetchOnAllowlistMiss && !refetch) {\n await this.#triggerUpdate();\n return this.#getSingle(snapId, snapInfo, true);\n }\n return { status: SnapsRegistryStatus.Unverified };\n }\n\n async #get(\n snaps: SnapsRegistryRequest,\n ): Promise<Record<SnapId, SnapsRegistryResult>> {\n return Object.entries(snaps).reduce<\n Promise<Record<SnapId, SnapsRegistryResult>>\n >(async (previousPromise, [snapId, snapInfo]) => {\n const result = await this.#getSingle(snapId, snapInfo);\n const acc = await previousPromise;\n acc[snapId] = result;\n return acc;\n }, Promise.resolve({}));\n }\n\n /**\n * Get metadata for the given snap ID.\n *\n * @param snapId - The ID of the snap to get metadata for.\n * @returns The metadata for the given snap ID, or `null` if the snap is not\n * verified.\n */\n async #getMetadata(snapId: SnapId): Promise<SnapsRegistryMetadata | null> {\n const database = await this.#getDatabase();\n return database?.verifiedSnaps[snapId]?.metadata ?? null;\n }\n\n /**\n * Verify the signature of the registry.\n *\n * @param database - The registry database.\n * @param signature - The signature of the registry.\n * @throws If the signature is invalid.\n * @private\n */\n async #verifySignature(database: string, signature: string) {\n assert(this.#publicKey, 'No public key provided.');\n\n const valid = await verify({\n registry: database,\n signature: JSON.parse(signature),\n publicKey: this.#publicKey,\n });\n\n assert(valid, 'Invalid registry signature.');\n }\n\n /**\n * Fetch the given URL, throwing if the response is not OK.\n *\n * @param url - The URL to fetch.\n * @returns The response body.\n * @private\n */\n async #safeFetch(url: string) {\n const response = await this.#fetchFunction(url);\n if (!response.ok) {\n throw new Error(`Failed to fetch ${url}.`);\n }\n\n return await response.text();\n }\n}\n"],"names":["BaseControllerV2","BaseController","verify","assert","Duration","inMilliseconds","satisfiesVersionRange","SnapsRegistryStatus","SNAP_REGISTRY_URL","SNAP_REGISTRY_SIGNATURE_URL","controllerName","defaultState","database","lastUpdated","JsonSnapsRegistry","constructor","messenger","state","url","registry","signature","publicKey","fetchFunction","globalThis","fetch","bind","recentFetchThreshold","Minute","failOnUnavailableRegistry","refetchOnAllowlistMiss","metadata","persist","anonymous","name","currentUpdate","messagingSystem","registerActionHandler","args","get","getMetadata","triggerUpdate","Date","now","update","wasRecentlyFetched","safeFetch","verifySignature","JSON","parse","Error","snapId","snapInfo","refetch","getDatabase","blockedEntry","blockedSnaps","find","blocked","id","version","versionRange","checksum","status","Blocked","reason","verified","verifiedSnaps","versions","Verified","getSingle","Unverified","snaps","Object","entries","reduce","previousPromise","result","acc","Promise","resolve","valid","response","ok","text"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAASA,oBAAoBC,cAAc,QAAQ,4BAA4B;AAE/E,SAASC,MAAM,QAAQ,2BAA2B;AAGlD,SACEC,MAAM,EACNC,QAAQ,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AC;IAC3C;IAEA,OAAO,MAAM+D,SAASE,IAAI;AAC5B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export var SnapsRegistryStatus;
|
|
2
|
+
(function(SnapsRegistryStatus) {
|
|
3
|
+
SnapsRegistryStatus[SnapsRegistryStatus["Unverified"] = 0] = "Unverified";
|
|
4
|
+
SnapsRegistryStatus[SnapsRegistryStatus["Blocked"] = 1] = "Blocked";
|
|
5
|
+
SnapsRegistryStatus[SnapsRegistryStatus["Verified"] = 2] = "Verified";
|
|
6
|
+
})(SnapsRegistryStatus || (SnapsRegistryStatus = {}));
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/snaps/registry/registry.ts"],"sourcesContent":["import type {\n BlockReason,\n SnapsRegistryDatabase,\n} from '@metamask/snaps-registry';\nimport type { SnapId, ValidatedSnapId } from '@metamask/snaps-utils';\nimport type { SemVerVersion } from '@metamask/utils';\n\nexport type SnapsRegistryInfo = { version: SemVerVersion; checksum: string };\nexport type SnapsRegistryRequest = Record<SnapId, SnapsRegistryInfo>;\nexport type SnapsRegistryMetadata =\n SnapsRegistryDatabase['verifiedSnaps'][ValidatedSnapId]['metadata'];\n\n// TODO: Decide on names for these\nexport enum SnapsRegistryStatus {\n Unverified = 0,\n Blocked = 1,\n Verified = 2,\n}\n\nexport type SnapsRegistryResult = {\n status: SnapsRegistryStatus;\n reason?: BlockReason;\n};\n\nexport type SnapsRegistry = {\n get(\n snaps: SnapsRegistryRequest,\n ): Promise<Record<ValidatedSnapId, SnapsRegistryResult>>;\n\n update(): Promise<void>;\n\n /**\n * Get metadata for the given snap ID.\n *\n * @param snapId - The ID of the snap to get metadata for.\n * @returns The metadata for the given snap ID, or `null` if the snap is not\n * verified.\n */\n getMetadata(snapId: SnapId): Promise<SnapsRegistryMetadata | null>;\n};\n"],"names":["SnapsRegistryStatus","Unverified","Blocked","Verified"],"mappings":"WAaO;UAAKA,mBAAmB;IAAnBA,oBAAAA,oBACVC,gBAAa,KAAbA;IADUD,oBAAAA,oBAEVE,aAAU,KAAVA;IAFUF,oBAAAA,oBAGVG,cAAW,KAAXA;GAHUH,wBAAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/snaps/selectors.ts"],"sourcesContent":["import type { TruncatedSnap } from '@metamask/snaps-utils';\n\nexport const getRunnableSnaps = <Snap extends TruncatedSnap>(snaps: Snap[]) =>\n snaps.filter((snap) => snap.enabled && !snap.blocked);\n"],"names":["getRunnableSnaps","snaps","filter","snap","enabled","blocked"],"mappings":"AAEA,OAAO,MAAMA,mBAAmB,CAA6BC,QAC3DA,MAAMC,MAAM,CAAC,CAACC,OAASA,KAAKC,OAAO,IAAI,CAACD,KAAKE,OAAO,EAAE"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withTimeout = exports.hasTimedOut = exports.delayWithTimer = exports.delay = exports.setDiff = void 0;
|
|
4
|
-
const Timer_1 = require("./snaps/Timer");
|
|
1
|
+
import { Timer } from './snaps/Timer';
|
|
5
2
|
/**
|
|
6
3
|
* Takes two objects and does a Set Difference of them.
|
|
7
4
|
* Set Difference is generally defined as follows:
|
|
@@ -15,28 +12,24 @@ const Timer_1 = require("./snaps/Timer");
|
|
|
15
12
|
* @param objectA - The object on which the difference is being calculated.
|
|
16
13
|
* @param objectB - The object whose properties will be removed from objectA.
|
|
17
14
|
* @returns The objectA without properties from objectB.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
return Object.entries(objectA).reduce((acc, [key, value]) => {
|
|
15
|
+
*/ export function setDiff(objectA, objectB) {
|
|
16
|
+
return Object.entries(objectA).reduce((acc, [key, value])=>{
|
|
21
17
|
if (!(key in objectB)) {
|
|
22
18
|
acc[key] = value;
|
|
23
19
|
}
|
|
24
20
|
return acc;
|
|
25
21
|
}, {});
|
|
26
22
|
}
|
|
27
|
-
exports.setDiff = setDiff;
|
|
28
23
|
/**
|
|
29
|
-
* A Promise that delays
|
|
24
|
+
* A Promise that delays its return for a given amount of milliseconds.
|
|
30
25
|
*
|
|
31
26
|
* @param ms - Milliseconds to delay the execution for.
|
|
32
27
|
* @param result - The result to return from the Promise after delay.
|
|
33
28
|
* @returns A promise that is void if no result provided, result otherwise.
|
|
34
29
|
* @template Result - The `result`.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
return delayWithTimer(new Timer_1.Timer(ms), result);
|
|
30
|
+
*/ export function delay(ms, result) {
|
|
31
|
+
return delayWithTimer(new Timer(ms), result);
|
|
38
32
|
}
|
|
39
|
-
exports.delay = delay;
|
|
40
33
|
/**
|
|
41
34
|
* A Promise that delays it's return by using a pausable Timer.
|
|
42
35
|
*
|
|
@@ -44,16 +37,15 @@ exports.delay = delay;
|
|
|
44
37
|
* @param result - The result to return from the Promise after delay.
|
|
45
38
|
* @returns A promise that is void if no result provided, result otherwise.
|
|
46
39
|
* @template Result - The `result`.
|
|
47
|
-
*/
|
|
48
|
-
function delayWithTimer(timer, result) {
|
|
40
|
+
*/ export function delayWithTimer(timer, result) {
|
|
49
41
|
let rejectFunc;
|
|
50
|
-
const promise = new Promise((resolve, reject)
|
|
51
|
-
timer.start(()
|
|
42
|
+
const promise = new Promise((resolve, reject)=>{
|
|
43
|
+
timer.start(()=>{
|
|
52
44
|
result === undefined ? resolve() : resolve(result);
|
|
53
45
|
});
|
|
54
46
|
rejectFunc = reject;
|
|
55
47
|
});
|
|
56
|
-
promise.cancel = ()
|
|
48
|
+
promise.cancel = ()=>{
|
|
57
49
|
if (timer.status !== 'finished') {
|
|
58
50
|
timer.cancel();
|
|
59
51
|
rejectFunc(new Error('The delay has been canceled.'));
|
|
@@ -61,12 +53,10 @@ function delayWithTimer(timer, result) {
|
|
|
61
53
|
};
|
|
62
54
|
return promise;
|
|
63
55
|
}
|
|
64
|
-
exports.delayWithTimer = delayWithTimer;
|
|
65
56
|
/*
|
|
66
57
|
* We use a Symbol instead of rejecting the promise so that Errors thrown
|
|
67
58
|
* by the main promise will propagate.
|
|
68
|
-
*/
|
|
69
|
-
exports.hasTimedOut = Symbol('Used to check if the requested promise has timeout (see withTimeout)');
|
|
59
|
+
*/ export const hasTimedOut = Symbol('Used to check if the requested promise has timeout (see withTimeout)');
|
|
70
60
|
/**
|
|
71
61
|
* Executes the given Promise, if the Timer expires before the Promise settles, we return earlier.
|
|
72
62
|
*
|
|
@@ -76,17 +66,18 @@ exports.hasTimedOut = Symbol('Used to check if the requested promise has timeout
|
|
|
76
66
|
* @param timerOrMs - The timer controlling the timeout or a ms value.
|
|
77
67
|
* @returns The resolved `PromiseValue`, or the hasTimedOut symbol if
|
|
78
68
|
* returning early.
|
|
79
|
-
* @template PromiseValue
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const delayPromise = delayWithTimer(timer, exports.hasTimedOut);
|
|
69
|
+
* @template PromiseValue - The value of the Promise.
|
|
70
|
+
*/ export async function withTimeout(promise, timerOrMs) {
|
|
71
|
+
const timer = typeof timerOrMs === 'number' ? new Timer(timerOrMs) : timerOrMs;
|
|
72
|
+
const delayPromise = delayWithTimer(timer, hasTimedOut);
|
|
84
73
|
try {
|
|
85
|
-
return await Promise.race([
|
|
86
|
-
|
|
87
|
-
|
|
74
|
+
return await Promise.race([
|
|
75
|
+
promise,
|
|
76
|
+
delayPromise
|
|
77
|
+
]);
|
|
78
|
+
} finally{
|
|
88
79
|
delayPromise.cancel();
|
|
89
80
|
}
|
|
90
81
|
}
|
|
91
|
-
|
|
82
|
+
|
|
92
83
|
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { Timer } from './snaps/Timer';\n\n/**\n * Takes two objects and does a Set Difference of them.\n * Set Difference is generally defined as follows:\n * ```\n * 𝑥 ∈ A ∖ B ⟺ 𝑥 ∈ A ∧ 𝑥 ∉ B\n * ```\n * Meaning that the returned object contains all properties of A expect those that also\n * appear in B. Notice that properties that appear in B, but not in A, have no effect.\n *\n * @see [Set Difference]{@link https://proofwiki.org/wiki/Definition:Set_Difference}\n * @param objectA - The object on which the difference is being calculated.\n * @param objectB - The object whose properties will be removed from objectA.\n * @returns The objectA without properties from objectB.\n */\nexport function setDiff<\n ObjectA extends Record<any, unknown>,\n ObjectB extends Record<any, unknown>,\n>(objectA: ObjectA, objectB: ObjectB): Diff<ObjectA, ObjectB> {\n return Object.entries(objectA).reduce<Record<any, unknown>>(\n (acc, [key, value]) => {\n if (!(key in objectB)) {\n acc[key] = value;\n }\n return acc;\n },\n {},\n ) as Diff<ObjectA, ObjectB>;\n}\n\n/**\n * A Promise that delays its return for a given amount of milliseconds.\n *\n * @param ms - Milliseconds to delay the execution for.\n * @param result - The result to return from the Promise after delay.\n * @returns A promise that is void if no result provided, result otherwise.\n * @template Result - The `result`.\n */\nexport function delay<Result = void>(\n ms: number,\n result?: Result,\n): Promise<Result> & { cancel: () => void } {\n return delayWithTimer(new Timer(ms), result);\n}\n\n/**\n * A Promise that delays it's return by using a pausable Timer.\n *\n * @param timer - Timer used to control the delay.\n * @param result - The result to return from the Promise after delay.\n * @returns A promise that is void if no result provided, result otherwise.\n * @template Result - The `result`.\n */\nexport function delayWithTimer<Result = void>(\n timer: Timer,\n result?: Result,\n): Promise<Result> & { cancel: () => void } {\n let rejectFunc: (reason: Error) => void;\n const promise: any = new Promise<Result>((resolve: any, reject) => {\n timer.start(() => {\n result === undefined ? resolve() : resolve(result);\n });\n rejectFunc = reject;\n });\n\n promise.cancel = () => {\n if (timer.status !== 'finished') {\n timer.cancel();\n rejectFunc(new Error('The delay has been canceled.'));\n }\n };\n return promise;\n}\n\n/*\n * We use a Symbol instead of rejecting the promise so that Errors thrown\n * by the main promise will propagate.\n */\nexport const hasTimedOut = Symbol(\n 'Used to check if the requested promise has timeout (see withTimeout)',\n);\n\n/**\n * Executes the given Promise, if the Timer expires before the Promise settles, we return earlier.\n *\n * NOTE:** The given Promise is not cancelled or interrupted, and will continue to execute uninterrupted. We will just discard its result if it does not complete before the timeout.\n *\n * @param promise - The promise that you want to execute.\n * @param timerOrMs - The timer controlling the timeout or a ms value.\n * @returns The resolved `PromiseValue`, or the hasTimedOut symbol if\n * returning early.\n * @template PromiseValue - The value of the Promise.\n */\nexport async function withTimeout<PromiseValue = void>(\n promise: Promise<PromiseValue>,\n timerOrMs: Timer | number,\n): Promise<PromiseValue | typeof hasTimedOut> {\n const timer =\n typeof timerOrMs === 'number' ? new Timer(timerOrMs) : timerOrMs;\n const delayPromise = delayWithTimer(timer, hasTimedOut);\n try {\n return await Promise.race([promise, delayPromise]);\n } finally {\n delayPromise.cancel();\n }\n}\n\n/**\n * Checks whether the type is composed of literal types\n *\n * @returns @type {true} if whole type is composed of literals, @type {false} if whole type is not literals, @type {boolean} if mixed\n * @example\n * ```\n * type t1 = IsLiteral<1 | 2 | \"asd\" | true>;\n * // t1 = true\n *\n * type t2 = IsLiteral<number | string>;\n * // t2 = false\n *\n * type t3 = IsLiteral<1 | string>;\n * // t3 = boolean\n *\n * const s = Symbol();\n * type t4 = IsLiteral<typeof s>;\n * // t4 = true\n *\n * type t5 = IsLiteral<symbol>\n * // t5 = false;\n * ```\n */\ntype IsLiteral<Type> = Type extends string | number | boolean | symbol\n ? Extract<string | number | boolean | symbol, Type> extends never\n ? true\n : false\n : false;\n\n/**\n * Returns all keys of an object, that are literal, as an union\n *\n * @example\n * ```\n * type t1 = _LiteralKeys<{a: number, b: 0, c: 'foo', d: string}>\n * // t1 = 'b' | 'c'\n * ```\n * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}\n */\ntype LiteralKeys<Type> = NonNullable<\n {\n [Key in keyof Type]: IsLiteral<Key> extends true ? Key : never;\n }[keyof Type]\n>;\n\n/**\n * Returns all keys of an object, that are not literal, as an union\n *\n * @example\n * ```\n * type t1 = _NonLiteralKeys<{a: number, b: 0, c: 'foo', d: string}>\n * // t1 = 'a' | 'd'\n * ```\n * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}\n */\ntype NonLiteralKeys<Type> = NonNullable<\n {\n [Key in keyof Type]: IsLiteral<Key> extends false ? Key : never;\n }[keyof Type]\n>;\n\n/**\n * A set difference of two objects based on their keys\n *\n * @example\n * ```\n * type t1 = Diff<{a: string, b: string}, {a: number}>\n * // t1 = {b: string};\n * type t2 = Diff<{a: string, 0: string}, Record<string, unknown>>;\n * // t2 = { a?: string, 0: string};\n * type t3 = Diff<{a: string, 0: string, 1: string}, Record<1 | string, unknown>>;\n * // t3 = {a?: string, 0: string}\n * ```\n * @see {@link setDiff} for the main use-case\n */\nexport type Diff<First, Second> = Omit<First, LiteralKeys<Second>> &\n Partial<Pick<First, Extract<keyof First, NonLiteralKeys<Second>>>>;\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template Type - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n Type extends Record<string, unknown>,\n TargetKey extends string,\n> = {\n -readonly [Key in keyof Pick<Type, TargetKey>]: Type[Key];\n} & {\n [Key in keyof Omit<Type, TargetKey>]: Type[Key];\n};\n"],"names":["Timer","setDiff","objectA","objectB","Object","entries","reduce","acc","key","value","delay","ms","result","delayWithTimer","timer","rejectFunc","promise","Promise","resolve","reject","start","undefined","cancel","status","Error","hasTimedOut","Symbol","withTimeout","timerOrMs","delayPromise","race"],"mappings":"AAAA,SAASA,KAAK,QAAQ,gBAAgB;AAEtC;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,QAGdC,OAAgB,EAAEC,OAAgB;IAClC,OAAOC,OAAOC,OAAO,CAACH,SAASI,MAAM,CACnC,CAACC,KAAK,CAACC,KAAKC,MAAM;QAChB,IAAI,CAAED,CAAAA,OAAOL,OAAM,GAAI;YACrBI,GAAG,CAACC,IAAI,GAAGC;QACb;QACA,OAAOF;IACT,GACA,CAAC;AAEL;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,MACdC,EAAU,EACVC,MAAe;IAEf,OAAOC,eAAe,IAAIb,MAAMW,KAAKC;AACvC;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,eACdC,KAAY,EACZF,MAAe;IAEf,IAAIG;IACJ,MAAMC,UAAe,IAAIC,QAAgB,CAACC,SAAcC;QACtDL,MAAMM,KAAK,CAAC;YACVR,WAAWS,YAAYH,YAAYA,QAAQN;QAC7C;QACAG,aAAaI;IACf;IAEAH,QAAQM,MAAM,GAAG;QACf,IAAIR,MAAMS,MAAM,KAAK,YAAY;YAC/BT,MAAMQ,MAAM;YACZP,WAAW,IAAIS,MAAM;QACvB;IACF;IACA,OAAOR;AACT;AAEA;;;CAGC,GACD,OAAO,MAAMS,cAAcC,OACzB,wEACA;AAEF;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,YACpBX,OAA8B,EAC9BY,SAAyB;IAEzB,MAAMd,QACJ,OAAOc,cAAc,WAAW,IAAI5B,MAAM4B,aAAaA;IACzD,MAAMC,eAAehB,eAAeC,OAAOW;IAC3C,IAAI;QACF,OAAO,MAAMR,QAAQa,IAAI,CAAC;YAACd;YAASa;SAAa;IACnD,SAAU;QACRA,aAAaP,MAAM;IACrB;AACF"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
2
|
+
import { BaseControllerV2 as BaseController } from '@metamask/base-controller';
|
|
3
|
+
import type { GetPermissions } from '@metamask/permission-controller';
|
|
4
|
+
import type { SnapId, ValidatedSnapId, CronjobSpecification } from '@metamask/snaps-utils';
|
|
5
|
+
import type { GetAllSnaps, HandleSnapRequest, SnapDisabled, SnapEnabled, SnapInstalled, SnapRemoved, SnapUpdated } from '..';
|
|
5
6
|
import { Timer } from '../snaps/Timer';
|
|
6
7
|
export declare type CronjobControllerActions = GetAllSnaps | HandleSnapRequest | GetPermissions;
|
|
7
|
-
export declare type CronjobControllerEvents = SnapInstalled | SnapRemoved | SnapUpdated;
|
|
8
|
+
export declare type CronjobControllerEvents = SnapInstalled | SnapRemoved | SnapUpdated | SnapEnabled | SnapDisabled;
|
|
8
9
|
export declare type CronjobControllerMessenger = RestrictedControllerMessenger<'CronjobController', CronjobControllerActions, CronjobControllerEvents, CronjobControllerActions['type'], CronjobControllerEvents['type']>;
|
|
9
10
|
export declare const DAILY_TIMEOUT: number;
|
|
10
11
|
export declare type CronjobControllerArgs = {
|
|
@@ -17,7 +18,7 @@ export declare type CronjobControllerArgs = {
|
|
|
17
18
|
export declare type Cronjob = {
|
|
18
19
|
timer?: Timer;
|
|
19
20
|
id: string;
|
|
20
|
-
snapId:
|
|
21
|
+
snapId: ValidatedSnapId;
|
|
21
22
|
} & CronjobSpecification;
|
|
22
23
|
export declare type StoredJobInformation = {
|
|
23
24
|
lastRun: number;
|
|
@@ -52,7 +53,7 @@ export declare class CronjobController extends BaseController<typeof controllerN
|
|
|
52
53
|
*
|
|
53
54
|
* @param snapId - ID of a snap.
|
|
54
55
|
*/
|
|
55
|
-
register(snapId:
|
|
56
|
+
register(snapId: ValidatedSnapId): void;
|
|
56
57
|
/**
|
|
57
58
|
* Schedule a new job.
|
|
58
59
|
* This will interpret the cron expression and tell the timer to execute the job
|
|
@@ -95,17 +96,17 @@ export declare class CronjobController extends BaseController<typeof controllerN
|
|
|
95
96
|
*/
|
|
96
97
|
destroy(): void;
|
|
97
98
|
/**
|
|
98
|
-
* Handle
|
|
99
|
+
* Handle events that should cause cronjobs to be registered.
|
|
99
100
|
*
|
|
100
101
|
* @param snap - Basic Snap information.
|
|
101
102
|
*/
|
|
102
|
-
private
|
|
103
|
+
private _handleSnapRegisterEvent;
|
|
103
104
|
/**
|
|
104
|
-
* Handle
|
|
105
|
+
* Handle events that should cause cronjobs to be unregistered.
|
|
105
106
|
*
|
|
106
107
|
* @param snap - Basic Snap information.
|
|
107
108
|
*/
|
|
108
|
-
private
|
|
109
|
+
private _handleSnapUnregisterEvent;
|
|
109
110
|
/**
|
|
110
111
|
* Handle cron jobs on 'snapUpdated' event.
|
|
111
112
|
*
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import ObjectMultiplex from '@metamask/object-multiplex';
|
|
3
|
-
import { BasePostMessageStream } from '@metamask/post-message-stream';
|
|
4
|
-
import { SnapRpcHookArgs } from '@metamask/snaps-utils';
|
|
3
|
+
import type { BasePostMessageStream } from '@metamask/post-message-stream';
|
|
4
|
+
import type { SnapRpcHookArgs } from '@metamask/snaps-utils';
|
|
5
5
|
import { JsonRpcEngine } from 'json-rpc-engine';
|
|
6
|
-
import { Duplex } from 'stream';
|
|
7
|
-
import { ExecutionService, ExecutionServiceMessenger, SnapExecutionData } from './ExecutionService';
|
|
6
|
+
import type { Duplex } from 'stream';
|
|
7
|
+
import type { ExecutionService, ExecutionServiceMessenger, SnapExecutionData } from './ExecutionService';
|
|
8
8
|
export declare type SetupSnapProvider = (snapId: string, stream: Duplex) => void;
|
|
9
9
|
export declare type ExecutionServiceArgs = {
|
|
10
10
|
setupSnapProvider: SetupSnapProvider;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
2
|
-
import { SnapId, SnapRpcHookArgs } from '@metamask/snaps-utils';
|
|
3
|
-
import { Json } from '@metamask/
|
|
1
|
+
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
2
|
+
import type { SnapId, SnapRpcHookArgs } from '@metamask/snaps-utils';
|
|
3
|
+
import type { Json } from '@metamask/utils';
|
|
4
4
|
declare type TerminateSnap = (snapId: string) => Promise<void>;
|
|
5
5
|
declare type TerminateAll = () => Promise<void>;
|
|
6
6
|
declare type ExecuteSnap = (snapData: SnapExecutionData) => Promise<unknown>;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { BasePostMessageStream } from '@metamask/post-message-stream';
|
|
2
|
-
import { JsonRpcRequest } from '@metamask/utils';
|
|
3
|
-
export declare type
|
|
2
|
+
import type { JsonRpcRequest } from '@metamask/utils';
|
|
3
|
+
export declare type ProxyPostMessageStreamArgs = {
|
|
4
4
|
stream: BasePostMessageStream;
|
|
5
5
|
jobId: string;
|
|
6
|
-
|
|
6
|
+
extra?: Record<string, unknown>;
|
|
7
7
|
};
|
|
8
|
-
export declare type
|
|
8
|
+
export declare type ProxyPostMessage = {
|
|
9
9
|
jobId: string;
|
|
10
10
|
data: JsonRpcRequest;
|
|
11
|
+
extra?: Record<string, unknown>;
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
14
|
* A post message stream that wraps messages in a job ID, before sending them
|
|
14
15
|
* over the underlying stream.
|
|
15
16
|
*/
|
|
16
|
-
export declare class
|
|
17
|
+
export declare class ProxyPostMessageStream extends BasePostMessageStream {
|
|
17
18
|
#private;
|
|
18
19
|
/**
|
|
19
|
-
* Initializes a new `
|
|
20
|
+
* Initializes a new `ProxyPostMessageStream` instance.
|
|
20
21
|
*
|
|
21
22
|
* @param args - The constructor arguments.
|
|
22
23
|
* @param args.stream - The underlying stream to use for communication.
|
|
23
24
|
* @param args.jobId - The ID of the job this stream is associated with.
|
|
24
|
-
* @param args.
|
|
25
|
-
* document.
|
|
25
|
+
* @param args.extra - Extra data to include in the post message.
|
|
26
26
|
*/
|
|
27
|
-
constructor({ stream, jobId,
|
|
27
|
+
constructor({ stream, jobId, extra }: ProxyPostMessageStreamArgs);
|
|
28
28
|
/**
|
|
29
29
|
* Write data to the underlying stream. This wraps the data in an object with
|
|
30
30
|
* the job ID.
|
|
31
31
|
*
|
|
32
32
|
* @param data - The data to write.
|
|
33
33
|
*/
|
|
34
|
-
_postMessage(data:
|
|
34
|
+
_postMessage(data: ProxyPostMessage): void;
|
|
35
35
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BasePostMessageStream } from '@metamask/post-message-stream';
|
|
2
|
-
import { Job,
|
|
1
|
+
import type { BasePostMessageStream } from '@metamask/post-message-stream';
|
|
2
|
+
import type { Job, ExecutionServiceArgs } from '../AbstractExecutionService';
|
|
3
|
+
import { AbstractExecutionService } from '../AbstractExecutionService';
|
|
3
4
|
declare type IframeExecutionEnvironmentServiceArgs = {
|
|
4
5
|
iframeUrl: URL;
|
|
5
6
|
} & ExecutionServiceArgs;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './AbstractExecutionService';
|
|
2
2
|
export * from './ExecutionService';
|
|
3
|
+
export * from './ProxyPostMessageStream';
|
|
3
4
|
export * from './iframe';
|
|
4
5
|
export * from './node';
|
|
5
6
|
export * from './offscreen';
|
|
7
|
+
export { WebWorkerExecutionService } from './webworker';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { BasePostMessageStream } from '@metamask/post-message-stream';
|
|
3
|
-
import { ChildProcess } from 'child_process';
|
|
4
|
-
import {
|
|
2
|
+
import type { BasePostMessageStream } from '@metamask/post-message-stream';
|
|
3
|
+
import type { ChildProcess } from 'child_process';
|
|
4
|
+
import type { Job } from '..';
|
|
5
|
+
import { AbstractExecutionService } from '..';
|
|
5
6
|
export declare class NodeProcessExecutionService extends AbstractExecutionService<ChildProcess> {
|
|
6
7
|
protected initEnvStream(): Promise<{
|
|
7
8
|
worker: ChildProcess;
|