@metamask/snaps-controllers 1.0.1 → 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 -557
- 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
package/dist/cronjob/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./CronjobController"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cronjob/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC","sourcesContent":["export * from './CronjobController';\n"]}
|
package/dist/fsm.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.forceStrict = exports.validateMachine = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
const fsm_1 = require("@xstate/fsm");
|
|
6
|
-
/**
|
|
7
|
-
* Validates the set-up of a @xstate/fsm machine.
|
|
8
|
-
*
|
|
9
|
-
* 1. Ensures that all named actions in the config have a provided implementation.
|
|
10
|
-
*
|
|
11
|
-
* @param machine - The machine to validate.
|
|
12
|
-
* @throws {@link AssertionError}. If the validation fails.
|
|
13
|
-
*/
|
|
14
|
-
function validateMachine(machine) {
|
|
15
|
-
(0, utils_1.assert)('_options' in machine, 'The machine is not an @xstate/fsm machine');
|
|
16
|
-
const typed = machine;
|
|
17
|
-
// 1.
|
|
18
|
-
const toArray = (obj) => {
|
|
19
|
-
if (Array.isArray(obj)) {
|
|
20
|
-
return obj;
|
|
21
|
-
}
|
|
22
|
-
else if (obj === undefined || obj === null) {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
return [obj];
|
|
26
|
-
};
|
|
27
|
-
const allActions = new Set();
|
|
28
|
-
const addActions = (actions) => toArray(actions)
|
|
29
|
-
.flatMap((action) => {
|
|
30
|
-
if (typeof action === 'string') {
|
|
31
|
-
return [action];
|
|
32
|
-
}
|
|
33
|
-
(0, utils_1.assert)(typeof action === 'function');
|
|
34
|
-
return [];
|
|
35
|
-
})
|
|
36
|
-
.forEach(allActions.add.bind(allActions));
|
|
37
|
-
for (const state of Object.values(typed.config.states)) {
|
|
38
|
-
addActions(state.entry);
|
|
39
|
-
addActions(state.exit);
|
|
40
|
-
for (const transition of Object.values(state.on ?? {})) {
|
|
41
|
-
addActions(transition.actions);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
allActions.forEach((action) => (0, utils_1.assert)(typed._options.actions !== undefined && action in typed._options.actions, `Action "${action}" doesn't have an implementation`));
|
|
45
|
-
}
|
|
46
|
-
exports.validateMachine = validateMachine;
|
|
47
|
-
/**
|
|
48
|
-
* Ensure that the interpreter is strict.
|
|
49
|
-
* Strict means that the transition must occur.
|
|
50
|
-
* The event must exist in .on {} state config and it's guard must succeed.
|
|
51
|
-
*
|
|
52
|
-
* The error will be thrown when an invalid `interpreter.send()` is called
|
|
53
|
-
* and will be bubbled there.
|
|
54
|
-
*
|
|
55
|
-
* TODO(ritave): Doesn't support self transitions.
|
|
56
|
-
*
|
|
57
|
-
* @param interpreter - The interpreter that will be force into strict mode.
|
|
58
|
-
* @throws {@link Error} Thrown when the transition is invalid.
|
|
59
|
-
*/
|
|
60
|
-
function forceStrict(interpreter) {
|
|
61
|
-
// As soon as a listener subscribes, it is called. It might be called in
|
|
62
|
-
// an initial state which doesn't have the .changed property
|
|
63
|
-
let onInitialCalled = false;
|
|
64
|
-
interpreter.subscribe((state) => {
|
|
65
|
-
(0, utils_1.assert)(!onInitialCalled || state.changed, 'Invalid state transition');
|
|
66
|
-
onInitialCalled = true;
|
|
67
|
-
});
|
|
68
|
-
const ogSend = interpreter.send.bind(interpreter);
|
|
69
|
-
interpreter.send = (...args) => {
|
|
70
|
-
(0, utils_1.assert)(interpreter.status === fsm_1.InterpreterStatus.Running, 'Interpreter is stopped');
|
|
71
|
-
return ogSend(...args);
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
exports.forceStrict = forceStrict;
|
|
75
|
-
//# sourceMappingURL=fsm.js.map
|
package/dist/fsm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fsm.js","sourceRoot":"","sources":["../src/fsm.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AACzC,qCAKqB;AAErB;;;;;;;GAOG;AACH,SAAgB,eAAe,CAI7B,OAAuD;IACvD,IAAA,cAAM,EAAC,UAAU,IAAI,OAAO,EAAE,2CAA2C,CAAC,CAAC;IAC3E,MAAM,KAAK,GAAG,OAEb,CAAC;IAEF,KAAK;IACL,MAAM,OAAO,GAAG,CAAI,GAAY,EAAO,EAAE;QACvC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACtB,OAAO,GAAG,CAAC;SACZ;aAAM,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;YAC5C,OAAO,EAAE,CAAC;SACX;QACD,OAAO,CAAC,GAAG,CAAC,CAAC;IACf,CAAC,CAAC;IACF,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IACrC,MAAM,UAAU,GAAG,CAAC,OAAY,EAAE,EAAE,CAClC,OAAO,CAAC,OAAO,CAAC;SACb,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAClB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,OAAO,CAAC,MAAM,CAAC,CAAC;SACjB;QACD,IAAA,cAAM,EAAC,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC;QACrC,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;SACD,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAE9C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAC/B,KAAK,CAAC,MAAM,CAAC,MAAM,CACpB,EAAE;QACD,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACxB,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvB,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAM,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE;YAC3D,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;SAChC;KACF;IAED,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAC5B,IAAA,cAAM,EACJ,KAAK,CAAC,QAAQ,CAAC,OAAO,KAAK,SAAS,IAAI,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,EACxE,WAAW,MAAM,kCAAkC,CACpD,CACF,CAAC;AACJ,CAAC;AA/CD,0CA+CC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CAAC,WAAgD;IAC1E,wEAAwE;IACxE,4DAA4D;IAC5D,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,WAAW,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;QAC9B,IAAA,cAAM,EAAC,CAAC,eAAe,IAAI,KAAK,CAAC,OAAO,EAAE,0BAA0B,CAAC,CAAC;QACtE,eAAe,GAAG,IAAI,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,WAAW,CAAC,IAAI,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;QAC7B,IAAA,cAAM,EACJ,WAAW,CAAC,MAAM,KAAK,uBAAiB,CAAC,OAAO,EAChD,wBAAwB,CACzB,CAAC;QACF,OAAO,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IACzB,CAAC,CAAC;AACJ,CAAC;AAjBD,kCAiBC","sourcesContent":["import { assert } from '@metamask/utils';\nimport {\n EventObject,\n InterpreterStatus,\n StateMachine,\n Typestate,\n} from '@xstate/fsm';\n\n/**\n * Validates the set-up of a @xstate/fsm machine.\n *\n * 1. Ensures that all named actions in the config have a provided implementation.\n *\n * @param machine - The machine to validate.\n * @throws {@link AssertionError}. If the validation fails.\n */\nexport function validateMachine<\n TContext extends object,\n TEvent extends EventObject,\n TState extends Typestate<TContext>,\n>(machine: StateMachine.Machine<TContext, TEvent, TState>) {\n assert('_options' in machine, 'The machine is not an @xstate/fsm machine');\n const typed = machine as StateMachine.Machine<TContext, TEvent, TState> & {\n _options: { actions?: StateMachine.ActionMap<TContext, TEvent> };\n };\n\n // 1.\n const toArray = <T>(obj: T | T[]): T[] => {\n if (Array.isArray(obj)) {\n return obj;\n } else if (obj === undefined || obj === null) {\n return [];\n }\n return [obj];\n };\n const allActions = new Set<string>();\n const addActions = (actions: any) =>\n toArray(actions)\n .flatMap((action) => {\n if (typeof action === 'string') {\n return [action];\n }\n assert(typeof action === 'function');\n return [];\n })\n .forEach(allActions.add.bind(allActions));\n\n for (const state of Object.values<typeof typed.config.states[string]>(\n typed.config.states,\n )) {\n addActions(state.entry);\n addActions(state.exit);\n for (const transition of Object.values<any>(state.on ?? {})) {\n addActions(transition.actions);\n }\n }\n\n allActions.forEach((action) =>\n assert(\n typed._options.actions !== undefined && action in typed._options.actions,\n `Action \"${action}\" doesn't have an implementation`,\n ),\n );\n}\n\n/**\n * Ensure that the interpreter is strict.\n * Strict means that the transition must occur.\n * The event must exist in .on {} state config and it's guard must succeed.\n *\n * The error will be thrown when an invalid `interpreter.send()` is called\n * and will be bubbled there.\n *\n * TODO(ritave): Doesn't support self transitions.\n *\n * @param interpreter - The interpreter that will be force into strict mode.\n * @throws {@link Error} Thrown when the transition is invalid.\n */\nexport function forceStrict(interpreter: StateMachine.Service<any, any, any>) {\n // As soon as a listener subscribes, it is called. It might be called in\n // an initial state which doesn't have the .changed property\n let onInitialCalled = false;\n interpreter.subscribe((state) => {\n assert(!onInitialCalled || state.changed, 'Invalid state transition');\n onInitialCalled = true;\n });\n\n const ogSend = interpreter.send.bind(interpreter);\n interpreter.send = (...args) => {\n assert(\n interpreter.status === InterpreterStatus.Running,\n 'Interpreter is stopped',\n );\n return ogSend(...args);\n };\n}\n"]}
|
package/dist/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./services"), exports);
|
|
18
|
-
__exportStar(require("./snaps"), exports);
|
|
19
|
-
__exportStar(require("./utils"), exports);
|
|
20
|
-
__exportStar(require("./multichain"), exports);
|
|
21
|
-
__exportStar(require("./cronjob"), exports);
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,6CAA2B;AAC3B,0CAAwB;AACxB,0CAAwB;AACxB,+CAA6B;AAC7B,4CAA0B","sourcesContent":["export type { Json } from '@metamask/utils';\nexport * from './services';\nexport * from './snaps';\nexport * from './utils';\nexport * from './multichain';\nexport * from './cronjob';\n"]}
|
package/dist/logging.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.log = void 0;
|
|
4
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
5
|
-
const utils_1 = require("@metamask/utils");
|
|
6
|
-
/**
|
|
7
|
-
* A logging function specific to this package. The log messages don't show up
|
|
8
|
-
* by default, but they can be enabled by setting the environment variable:
|
|
9
|
-
* - `DEBUG=metamask:snaps:snaps-controllers`, or
|
|
10
|
-
* - `DEBUG=metamask:snaps:*` to enable all logs from `@metamask/snaps-*`.
|
|
11
|
-
*/
|
|
12
|
-
exports.log = (0, utils_1.createModuleLogger)(snaps_utils_1.snapsLogger, 'snaps-controllers');
|
|
13
|
-
//# sourceMappingURL=logging.js.map
|
package/dist/logging.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,2CAAqD;AAErD;;;;;GAKG;AACU,QAAA,GAAG,GAAG,IAAA,0BAAkB,EAAC,yBAAW,EAAE,mBAAmB,CAAC,CAAC","sourcesContent":["import { snapsLogger } from '@metamask/snaps-utils';\nimport { createModuleLogger } from '@metamask/utils';\n\n/**\n * A logging function specific to this package. The log messages don't show up\n * by default, but they can be enabled by setting the environment variable:\n * - `DEBUG=metamask:snaps:snaps-controllers`, or\n * - `DEBUG=metamask:snaps:*` to enable all logs from `@metamask/snaps-*`.\n */\nexport const log = createModuleLogger(snapsLogger, 'snaps-controllers');\n"]}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { AddApprovalRequest } from '@metamask/approval-controller';
|
|
2
|
-
import { BaseControllerV2 as BaseController, RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
3
|
-
import { GetPermissions, GrantPermissions, HasPermission } from '@metamask/permission-controller';
|
|
4
|
-
import { ChainId, ConnectArguments, NamespaceId, RequestArguments, RequestNamespace, Session, SnapId } from '@metamask/snaps-utils';
|
|
5
|
-
import { GetAllSnaps, HandleSnapRequest, IncrementActiveReferences, DecrementActiveReferences } from '../snaps';
|
|
6
|
-
declare const controllerName = "MultiChainController";
|
|
7
|
-
declare type AllowedActions = GetAllSnaps | IncrementActiveReferences | DecrementActiveReferences | HandleSnapRequest | GetPermissions | HasPermission | AddApprovalRequest | GrantPermissions;
|
|
8
|
-
declare type MultiChainControllerMessenger = RestrictedControllerMessenger<typeof controllerName, AllowedActions, never, AllowedActions['type'], never>;
|
|
9
|
-
declare type SessionData = {
|
|
10
|
-
origin: string;
|
|
11
|
-
requestedNamespaces: Record<NamespaceId, RequestNamespace>;
|
|
12
|
-
providedNamespaces: Record<NamespaceId, RequestNamespace>;
|
|
13
|
-
handlingSnaps: Record<NamespaceId, SnapId>;
|
|
14
|
-
};
|
|
15
|
-
declare type MultiChainControllerState = {
|
|
16
|
-
sessions: {
|
|
17
|
-
[origin: string]: SessionData;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
declare type Notify = (origin: string, data: {
|
|
21
|
-
method: string;
|
|
22
|
-
params?: Record<string, unknown>;
|
|
23
|
-
}) => Promise<void>;
|
|
24
|
-
declare type MultiChainControllerArgs = {
|
|
25
|
-
notify: Notify;
|
|
26
|
-
messenger: MultiChainControllerMessenger;
|
|
27
|
-
};
|
|
28
|
-
export declare class MultiChainController extends BaseController<typeof controllerName, MultiChainControllerState, MultiChainControllerMessenger> {
|
|
29
|
-
#private;
|
|
30
|
-
/**
|
|
31
|
-
* Construct a new {@link MultiChainController} instance.
|
|
32
|
-
*
|
|
33
|
-
* @param args - The arguments to construct the controller with.
|
|
34
|
-
* @param args.messenger - The controller messenger to use.
|
|
35
|
-
* @param args.notify - A function that should handle JSON-RPC notifications.
|
|
36
|
-
*/
|
|
37
|
-
constructor({ messenger, notify }: MultiChainControllerArgs);
|
|
38
|
-
/**
|
|
39
|
-
* Get an open session for the given origin.
|
|
40
|
-
*
|
|
41
|
-
* @param origin - The origin to get the session for.
|
|
42
|
-
* @returns The session, if it exists, or `undefined` otherwise.
|
|
43
|
-
*/
|
|
44
|
-
getSession(origin: string): SessionData | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* Close a session for the given origin.
|
|
47
|
-
*
|
|
48
|
-
* @param origin - The origin to close the session for.
|
|
49
|
-
* @throws If the session does not exist.
|
|
50
|
-
*/
|
|
51
|
-
closeSession(origin: string): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* Handles a new connection from the given origin. This will create a new
|
|
54
|
-
* session, and close any existing session for the origin.
|
|
55
|
-
*
|
|
56
|
-
* @param origin - The origin to create the session for.
|
|
57
|
-
* @param connection - The connection arguments.
|
|
58
|
-
* @param connection.requiredNamespaces - The namespaces that the origin
|
|
59
|
-
* requires.
|
|
60
|
-
* @returns The session that was created.
|
|
61
|
-
*/
|
|
62
|
-
onConnect(origin: string, connection: ConnectArguments): Promise<Session>;
|
|
63
|
-
/**
|
|
64
|
-
* Handle an incoming multichain request from the given origin. This will
|
|
65
|
-
* forward the request to the appropriate Snap, and return the response.
|
|
66
|
-
*
|
|
67
|
-
* @param origin - The origin to handle the request for.
|
|
68
|
-
* @param data - The request data.
|
|
69
|
-
* @param data.chainId - The chain ID for the request.
|
|
70
|
-
* @param data.request - The request arguments, i.e., the method and params.
|
|
71
|
-
* @returns The response from the Snap.
|
|
72
|
-
* @throws If the session does not exist, or the session does not provide the
|
|
73
|
-
* requested namespace.
|
|
74
|
-
*/
|
|
75
|
-
onRequest(origin: string, data: {
|
|
76
|
-
chainId: ChainId;
|
|
77
|
-
request: RequestArguments;
|
|
78
|
-
}): Promise<unknown>;
|
|
79
|
-
/**
|
|
80
|
-
* Send a request to the given Snap. This calls the given method with the
|
|
81
|
-
* given arguments on the keyring class in the given Snap.
|
|
82
|
-
*
|
|
83
|
-
* @param options - The request options.
|
|
84
|
-
* @param options.snapId - The ID of the Snap to send the request to.
|
|
85
|
-
* @param options.origin - The origin of the request.
|
|
86
|
-
* @param options.method - The request method.
|
|
87
|
-
* @param options.args - The request params.
|
|
88
|
-
* @returns The response from the Snap.
|
|
89
|
-
*/
|
|
90
|
-
private snapRequest;
|
|
91
|
-
/**
|
|
92
|
-
* Get the accounts exposed by the Snap's keyring.
|
|
93
|
-
*
|
|
94
|
-
* This also verifies that the accounts returned by the snap are valid CAIP-10
|
|
95
|
-
* account IDs.
|
|
96
|
-
*
|
|
97
|
-
* @param origin - The origin of the request.
|
|
98
|
-
* @param snapId - The ID of the Snap to get the accounts from.
|
|
99
|
-
* @returns The accounts, or `null` if the Snap does not have any accounts, or
|
|
100
|
-
* the accounts are invalid (i.e., not valid CAIP-10 account IDs).
|
|
101
|
-
*/
|
|
102
|
-
private getSnapAccounts;
|
|
103
|
-
/**
|
|
104
|
-
* Get the namespaces for the given Snap, as described in the Snap's manifest.
|
|
105
|
-
*
|
|
106
|
-
* @param snap - The Snap to get the namespaces for.
|
|
107
|
-
* @returns The namespaces, or `null` if the Snap does not have any
|
|
108
|
-
* namespaces.
|
|
109
|
-
*/
|
|
110
|
-
private snapToNamespaces;
|
|
111
|
-
/**
|
|
112
|
-
* Maps from an object of namespace IDs and Snap IDs, and an object of
|
|
113
|
-
* namespace IDs and requested namespaces, to an object of namespace IDs and
|
|
114
|
-
* resolved accounts, with the Snap ID providing the accounts.
|
|
115
|
-
*
|
|
116
|
-
* @param origin - The origin of the request.
|
|
117
|
-
* @param namespacesAndSnaps - An object of namespace IDs and Snap IDs
|
|
118
|
-
* providing the namespace.
|
|
119
|
-
* @param requestedNamespaces - An object of namespace IDs and requested
|
|
120
|
-
* namespaces.
|
|
121
|
-
* @returns An object of namespace IDs and resolved accounts, with the Snap ID
|
|
122
|
-
* providing the accounts.
|
|
123
|
-
*/
|
|
124
|
-
private namespacesToAccounts;
|
|
125
|
-
/**
|
|
126
|
-
* If multiple Snap IDs are provided for a namespace, this method will
|
|
127
|
-
* determine which Snap ID to use for the namespace, by showing the user a
|
|
128
|
-
* prompt.
|
|
129
|
-
*
|
|
130
|
-
* @param origin - The origin of the request.
|
|
131
|
-
* @param possibleAccounts - An object containing the accounts provided by
|
|
132
|
-
* each Snap ID for each namespace.
|
|
133
|
-
* @returns An object containing the Snap ID to use for each namespace.
|
|
134
|
-
*/
|
|
135
|
-
private resolveConflicts;
|
|
136
|
-
}
|
|
137
|
-
export {};
|
|
@@ -1,339 +0,0 @@
|
|
|
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 _MultiChainController_notify;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.MultiChainController = void 0;
|
|
16
|
-
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
-
const rpc_methods_1 = require("@metamask/rpc-methods");
|
|
18
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
19
|
-
const utils_1 = require("@metamask/utils");
|
|
20
|
-
const nanoid_1 = require("nanoid");
|
|
21
|
-
const snaps_1 = require("../snaps");
|
|
22
|
-
const keyring_1 = require("../snaps/endowments/keyring");
|
|
23
|
-
const matching_1 = require("./matching");
|
|
24
|
-
const controllerName = 'MultiChainController';
|
|
25
|
-
const defaultState = {
|
|
26
|
-
sessions: {},
|
|
27
|
-
};
|
|
28
|
-
// TODO(ritave): Support for legacy ethereum operations, not just snaps
|
|
29
|
-
class MultiChainController extends base_controller_1.BaseControllerV2 {
|
|
30
|
-
/**
|
|
31
|
-
* Construct a new {@link MultiChainController} instance.
|
|
32
|
-
*
|
|
33
|
-
* @param args - The arguments to construct the controller with.
|
|
34
|
-
* @param args.messenger - The controller messenger to use.
|
|
35
|
-
* @param args.notify - A function that should handle JSON-RPC notifications.
|
|
36
|
-
*/
|
|
37
|
-
constructor({ messenger, notify }) {
|
|
38
|
-
super({
|
|
39
|
-
messenger,
|
|
40
|
-
metadata: {
|
|
41
|
-
sessions: { persist: false, anonymous: false },
|
|
42
|
-
},
|
|
43
|
-
name: controllerName,
|
|
44
|
-
state: defaultState,
|
|
45
|
-
});
|
|
46
|
-
_MultiChainController_notify.set(this, void 0);
|
|
47
|
-
__classPrivateFieldSet(this, _MultiChainController_notify, notify, "f");
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Get an open session for the given origin.
|
|
51
|
-
*
|
|
52
|
-
* @param origin - The origin to get the session for.
|
|
53
|
-
* @returns The session, if it exists, or `undefined` otherwise.
|
|
54
|
-
*/
|
|
55
|
-
getSession(origin) {
|
|
56
|
-
return this.state.sessions[origin];
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Close a session for the given origin.
|
|
60
|
-
*
|
|
61
|
-
* @param origin - The origin to close the session for.
|
|
62
|
-
* @throws If the session does not exist.
|
|
63
|
-
*/
|
|
64
|
-
async closeSession(origin) {
|
|
65
|
-
const session = this.getSession(origin);
|
|
66
|
-
(0, utils_1.assert)(session, 'No session to close.');
|
|
67
|
-
await __classPrivateFieldGet(this, _MultiChainController_notify, "f").call(this, origin, {
|
|
68
|
-
method: 'multichainHack_metamask_disconnect',
|
|
69
|
-
});
|
|
70
|
-
this.update((state) => {
|
|
71
|
-
delete state.sessions[origin];
|
|
72
|
-
});
|
|
73
|
-
await Promise.all(Object.values(session.handlingSnaps).map((snapId) => this.messagingSystem.call('SnapController:decrementActiveReferences', snapId)));
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Handles a new connection from the given origin. This will create a new
|
|
77
|
-
* session, and close any existing session for the origin.
|
|
78
|
-
*
|
|
79
|
-
* @param origin - The origin to create the session for.
|
|
80
|
-
* @param connection - The connection arguments.
|
|
81
|
-
* @param connection.requiredNamespaces - The namespaces that the origin
|
|
82
|
-
* requires.
|
|
83
|
-
* @returns The session that was created.
|
|
84
|
-
*/
|
|
85
|
-
async onConnect(origin, connection) {
|
|
86
|
-
const existingSession = this.getSession(origin);
|
|
87
|
-
if (existingSession) {
|
|
88
|
-
await this.closeSession(origin);
|
|
89
|
-
}
|
|
90
|
-
const snaps = this.messagingSystem.call('SnapController:getAll');
|
|
91
|
-
const filteredSnaps = (0, snaps_1.getRunnableSnaps)(snaps);
|
|
92
|
-
// Get available namespaces supported by currently installed Snaps.
|
|
93
|
-
const availableNamespaces = Object.fromEntries(await Promise.all(filteredSnaps.map(async (snap) => [
|
|
94
|
-
snap.id,
|
|
95
|
-
await this.snapToNamespaces(snap),
|
|
96
|
-
])));
|
|
97
|
-
// The magical matching algorithm specified in SIP-2.
|
|
98
|
-
const namespaceToSnaps = (0, matching_1.findMatchingKeyringSnaps)(connection.requiredNamespaces, availableNamespaces);
|
|
99
|
-
const permissions = this.messagingSystem.call('PermissionController:getPermissions', origin);
|
|
100
|
-
(0, utils_1.assert)(permissions !== undefined, `${origin} does not have any permissions.`);
|
|
101
|
-
// Find namespaces that can be satisfied with existing approved Snaps.
|
|
102
|
-
const approvedNamespacesAndSnaps = Object.entries(namespaceToSnaps).reduce((acc, [namespace, snapIds]) => {
|
|
103
|
-
const approvedSnaps = snapIds.filter((snapId) => (0, snaps_utils_1.isSnapPermitted)(permissions, snapId));
|
|
104
|
-
if (approvedSnaps.length > 0) {
|
|
105
|
-
acc[namespace] = approvedSnaps;
|
|
106
|
-
}
|
|
107
|
-
return acc;
|
|
108
|
-
}, {});
|
|
109
|
-
// If we either don't have a snap to handle a namespace or we have multiple we have conflicts
|
|
110
|
-
const hasConflicts = Object.keys(namespaceToSnaps).some((namespace) => !(0, utils_1.hasProperty)(approvedNamespacesAndSnaps, namespace) ||
|
|
111
|
-
approvedNamespacesAndSnaps[namespace]?.length > 1);
|
|
112
|
-
// Use already approved snaps if they satisfy the requested namespaces.
|
|
113
|
-
const filteredNamespacesAndSnaps = hasConflicts
|
|
114
|
-
? namespaceToSnaps
|
|
115
|
-
: approvedNamespacesAndSnaps;
|
|
116
|
-
// Fetch possible accounts from snaps.
|
|
117
|
-
const possibleAccounts = await this.namespacesToAccounts(origin, filteredNamespacesAndSnaps, connection.requiredNamespaces);
|
|
118
|
-
// For now we fail here if no namespaces could be matched to a snap.
|
|
119
|
-
// We don't fail if at least one namespace is matched to a snap.
|
|
120
|
-
// TODO: Decide whether this is what we want
|
|
121
|
-
(0, utils_1.assert)(Object.values(possibleAccounts).some((possibleAccount) => possibleAccount.length > 0), 'No installed snaps found for any requested namespace.');
|
|
122
|
-
// If currently installed Snaps / configuration doesn't solve request, we
|
|
123
|
-
// need to show a prompt. This is handled by `resolveConflicts`.
|
|
124
|
-
const resolvedAccounts = hasConflicts
|
|
125
|
-
? await this.resolveConflicts(origin, possibleAccounts)
|
|
126
|
-
: Object.fromEntries(Object.entries(possibleAccounts).map(([namespace, snapAndAccounts]) => [
|
|
127
|
-
namespace,
|
|
128
|
-
snapAndAccounts[0] ?? null,
|
|
129
|
-
]));
|
|
130
|
-
// Aggregate information about session namespaces.
|
|
131
|
-
const providedNamespaces = Object.entries(connection.requiredNamespaces).reduce((acc, [namespaceId, namespace]) => {
|
|
132
|
-
const accounts = resolvedAccounts[namespaceId]?.accounts;
|
|
133
|
-
if (accounts) {
|
|
134
|
-
acc[namespaceId] = {
|
|
135
|
-
accounts,
|
|
136
|
-
chains: namespace.chains,
|
|
137
|
-
events: namespace.events,
|
|
138
|
-
methods: namespace.methods,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
return acc;
|
|
142
|
-
}, {});
|
|
143
|
-
// Collect information about handler Snaps for each namespace.
|
|
144
|
-
const handlingSnaps = Object.entries(resolvedAccounts).reduce((acc, [namespaceId, accountsAndSnap]) => {
|
|
145
|
-
if (accountsAndSnap) {
|
|
146
|
-
acc[namespaceId] = accountsAndSnap.snapId;
|
|
147
|
-
}
|
|
148
|
-
return acc;
|
|
149
|
-
}, {});
|
|
150
|
-
const session = {
|
|
151
|
-
origin,
|
|
152
|
-
requestedNamespaces: connection.requiredNamespaces,
|
|
153
|
-
providedNamespaces,
|
|
154
|
-
handlingSnaps,
|
|
155
|
-
};
|
|
156
|
-
// Makes sure used Snaps aren't killed while they are serving the session.
|
|
157
|
-
await Promise.all(Object.values(session.handlingSnaps).map((snapId) => this.messagingSystem.call('SnapController:incrementActiveReferences', snapId)));
|
|
158
|
-
this.update((state) => {
|
|
159
|
-
state.sessions[origin] = session;
|
|
160
|
-
});
|
|
161
|
-
return { namespaces: providedNamespaces };
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Handle an incoming multichain request from the given origin. This will
|
|
165
|
-
* forward the request to the appropriate Snap, and return the response.
|
|
166
|
-
*
|
|
167
|
-
* @param origin - The origin to handle the request for.
|
|
168
|
-
* @param data - The request data.
|
|
169
|
-
* @param data.chainId - The chain ID for the request.
|
|
170
|
-
* @param data.request - The request arguments, i.e., the method and params.
|
|
171
|
-
* @returns The response from the Snap.
|
|
172
|
-
* @throws If the session does not exist, or the session does not provide the
|
|
173
|
-
* requested namespace.
|
|
174
|
-
*/
|
|
175
|
-
async onRequest(origin, data) {
|
|
176
|
-
const session = this.getSession(origin);
|
|
177
|
-
(0, utils_1.assert)(session, `Session for "${origin}" doesn't exist.`);
|
|
178
|
-
const { namespace } = (0, snaps_utils_1.parseChainId)(data.chainId);
|
|
179
|
-
const sessionNamespace = session.providedNamespaces[namespace];
|
|
180
|
-
(0, utils_1.assert)(session.providedNamespaces[namespace]?.chains.includes(data.chainId), `Session for "${origin}" is not connected to "${data.chainId}" chain.`);
|
|
181
|
-
const { method } = data.request;
|
|
182
|
-
(0, utils_1.assert)(sessionNamespace?.methods?.includes(method), `Session for "${origin}" does not support ${method}`);
|
|
183
|
-
const snapId = session.handlingSnaps[namespace];
|
|
184
|
-
(0, utils_1.assert)(snapId !== undefined);
|
|
185
|
-
// TODO: Get permission for origin connecting to snap, or get user approval.
|
|
186
|
-
// In the future this is where we should prompt for this permission.
|
|
187
|
-
// In this iteration, we will grant this permission in `onConnect`.
|
|
188
|
-
const permissions = this.messagingSystem.call('PermissionController:getPermissions', origin);
|
|
189
|
-
(0, utils_1.assert)(permissions !== undefined, `${origin} does not have any permissions.`);
|
|
190
|
-
(0, utils_1.assert)((0, snaps_utils_1.isSnapPermitted)(permissions, snapId), `${origin} does not have permission to communicate with ${snapId}.`);
|
|
191
|
-
return this.snapRequest({
|
|
192
|
-
snapId,
|
|
193
|
-
origin,
|
|
194
|
-
method: 'handleRequest',
|
|
195
|
-
args: data,
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Send a request to the given Snap. This calls the given method with the
|
|
200
|
-
* given arguments on the keyring class in the given Snap.
|
|
201
|
-
*
|
|
202
|
-
* @param options - The request options.
|
|
203
|
-
* @param options.snapId - The ID of the Snap to send the request to.
|
|
204
|
-
* @param options.origin - The origin of the request.
|
|
205
|
-
* @param options.method - The request method.
|
|
206
|
-
* @param options.args - The request params.
|
|
207
|
-
* @returns The response from the Snap.
|
|
208
|
-
*/
|
|
209
|
-
async snapRequest({ snapId, origin, method, args, }) {
|
|
210
|
-
return this.messagingSystem.call('SnapController:handleRequest', {
|
|
211
|
-
snapId,
|
|
212
|
-
origin,
|
|
213
|
-
handler: snaps_utils_1.HandlerType.SnapKeyring,
|
|
214
|
-
request: { method, params: args ? [args] : [] },
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Get the accounts exposed by the Snap's keyring.
|
|
219
|
-
*
|
|
220
|
-
* This also verifies that the accounts returned by the snap are valid CAIP-10
|
|
221
|
-
* account IDs.
|
|
222
|
-
*
|
|
223
|
-
* @param origin - The origin of the request.
|
|
224
|
-
* @param snapId - The ID of the Snap to get the accounts from.
|
|
225
|
-
* @returns The accounts, or `null` if the Snap does not have any accounts, or
|
|
226
|
-
* the accounts are invalid (i.e., not valid CAIP-10 account IDs).
|
|
227
|
-
*/
|
|
228
|
-
async getSnapAccounts(origin, snapId) {
|
|
229
|
-
try {
|
|
230
|
-
const result = await this.snapRequest({
|
|
231
|
-
snapId,
|
|
232
|
-
origin,
|
|
233
|
-
method: 'getAccounts',
|
|
234
|
-
});
|
|
235
|
-
if ((0, snaps_utils_1.isAccountIdArray)(result)) {
|
|
236
|
-
return result;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
catch (error) {
|
|
240
|
-
// Ignore errors for now
|
|
241
|
-
(0, snaps_utils_1.logError)(error);
|
|
242
|
-
}
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Get the namespaces for the given Snap, as described in the Snap's manifest.
|
|
247
|
-
*
|
|
248
|
-
* @param snap - The Snap to get the namespaces for.
|
|
249
|
-
* @returns The namespaces, or `null` if the Snap does not have any
|
|
250
|
-
* namespaces.
|
|
251
|
-
*/
|
|
252
|
-
snapToNamespaces(snap) {
|
|
253
|
-
const permissions = this.messagingSystem.call('PermissionController:getPermissions', snap.id);
|
|
254
|
-
const keyringPermission = permissions?.[snaps_1.SnapEndowments.Keyring];
|
|
255
|
-
return (0, keyring_1.getKeyringCaveatNamespaces)(keyringPermission);
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Maps from an object of namespace IDs and Snap IDs, and an object of
|
|
259
|
-
* namespace IDs and requested namespaces, to an object of namespace IDs and
|
|
260
|
-
* resolved accounts, with the Snap ID providing the accounts.
|
|
261
|
-
*
|
|
262
|
-
* @param origin - The origin of the request.
|
|
263
|
-
* @param namespacesAndSnaps - An object of namespace IDs and Snap IDs
|
|
264
|
-
* providing the namespace.
|
|
265
|
-
* @param requestedNamespaces - An object of namespace IDs and requested
|
|
266
|
-
* namespaces.
|
|
267
|
-
* @returns An object of namespace IDs and resolved accounts, with the Snap ID
|
|
268
|
-
* providing the accounts.
|
|
269
|
-
*/
|
|
270
|
-
async namespacesToAccounts(origin, namespacesAndSnaps, requestedNamespaces) {
|
|
271
|
-
const dedupedSnaps = [
|
|
272
|
-
...new Set(Object.values(namespacesAndSnaps).flat()),
|
|
273
|
-
];
|
|
274
|
-
const allAccounts = await dedupedSnaps.reduce(async (previousPromise, snapId) => {
|
|
275
|
-
const result = await this.getSnapAccounts(origin, snapId);
|
|
276
|
-
const acc = await previousPromise;
|
|
277
|
-
if (result) {
|
|
278
|
-
acc[snapId] = result;
|
|
279
|
-
}
|
|
280
|
-
return acc;
|
|
281
|
-
}, Promise.resolve({}));
|
|
282
|
-
return Object.keys(namespacesAndSnaps).reduce((acc, namespaceId) => {
|
|
283
|
-
const { chains } = requestedNamespaces[namespaceId];
|
|
284
|
-
const accountInAnyRequestedChain = (account) => {
|
|
285
|
-
const { chainId: parsedChainId } = (0, snaps_utils_1.parseAccountId)(account);
|
|
286
|
-
return chains.some((chainId) => chainId === parsedChainId);
|
|
287
|
-
};
|
|
288
|
-
const result = Object.entries(allAccounts)
|
|
289
|
-
.map(([snapId, accounts]) => ({
|
|
290
|
-
snapId,
|
|
291
|
-
accounts: accounts.filter(accountInAnyRequestedChain),
|
|
292
|
-
}))
|
|
293
|
-
.filter(({ accounts }) => accounts.length > 0);
|
|
294
|
-
acc[namespaceId] = result;
|
|
295
|
-
return acc;
|
|
296
|
-
}, {});
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* If multiple Snap IDs are provided for a namespace, this method will
|
|
300
|
-
* determine which Snap ID to use for the namespace, by showing the user a
|
|
301
|
-
* prompt.
|
|
302
|
-
*
|
|
303
|
-
* @param origin - The origin of the request.
|
|
304
|
-
* @param possibleAccounts - An object containing the accounts provided by
|
|
305
|
-
* each Snap ID for each namespace.
|
|
306
|
-
* @returns An object containing the Snap ID to use for each namespace.
|
|
307
|
-
*/
|
|
308
|
-
async resolveConflicts(origin, possibleAccounts) {
|
|
309
|
-
// Get user approval for connection.
|
|
310
|
-
const id = (0, nanoid_1.nanoid)();
|
|
311
|
-
const resolvedAccounts = (await this.messagingSystem.call('ApprovalController:addRequest', {
|
|
312
|
-
origin,
|
|
313
|
-
id,
|
|
314
|
-
type: 'multichain_connect',
|
|
315
|
-
requestData: {
|
|
316
|
-
possibleAccounts,
|
|
317
|
-
},
|
|
318
|
-
}, true));
|
|
319
|
-
// TODO: In the future, use another permission here to not give full
|
|
320
|
-
// permission after handshake.
|
|
321
|
-
// Instead we should give origin only a read-only access to list of accounts
|
|
322
|
-
// without allowing provider.request() talking to a snap before additional
|
|
323
|
-
// user approval. The additional approval would be requested in `onRequest`.
|
|
324
|
-
const approvedPermissions = Object.values(resolvedAccounts).reduce((acc, curr) => {
|
|
325
|
-
if (curr !== null) {
|
|
326
|
-
acc[rpc_methods_1.WALLET_SNAP_PERMISSION_KEY][curr.snapId] = {};
|
|
327
|
-
}
|
|
328
|
-
return acc;
|
|
329
|
-
}, { [rpc_methods_1.WALLET_SNAP_PERMISSION_KEY]: {} });
|
|
330
|
-
this.messagingSystem.call('PermissionController:grantPermissions', {
|
|
331
|
-
approvedPermissions,
|
|
332
|
-
subject: { origin },
|
|
333
|
-
});
|
|
334
|
-
return resolvedAccounts;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
exports.MultiChainController = MultiChainController;
|
|
338
|
-
_MultiChainController_notify = new WeakMap();
|
|
339
|
-
//# sourceMappingURL=MultiChainController.js.map
|