@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,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
DEFAULT_NPM_REGISTRY: function() {
|
|
13
|
+
return DEFAULT_NPM_REGISTRY;
|
|
14
|
+
},
|
|
15
|
+
NpmLocation: function() {
|
|
16
|
+
return NpmLocation;
|
|
17
|
+
},
|
|
18
|
+
fetchNpmMetadata: function() {
|
|
19
|
+
return fetchNpmMetadata;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
23
|
+
const _utils = require("@metamask/utils");
|
|
24
|
+
const _concatstream = /*#__PURE__*/ _interop_require_default(require("concat-stream"));
|
|
25
|
+
const _gunzipmaybe = /*#__PURE__*/ _interop_require_default(require("gunzip-maybe"));
|
|
26
|
+
const _readablewebtonodestream = require("readable-web-to-node-stream");
|
|
27
|
+
const _stream = require("stream");
|
|
28
|
+
const _tarstream = require("tar-stream");
|
|
29
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
30
|
+
if (privateCollection.has(obj)) {
|
|
31
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function _class_private_method_get(receiver, privateSet, fn) {
|
|
35
|
+
if (!privateSet.has(receiver)) {
|
|
36
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
37
|
+
}
|
|
38
|
+
return fn;
|
|
39
|
+
}
|
|
40
|
+
function _class_private_method_init(obj, privateSet) {
|
|
41
|
+
_check_private_redeclaration(obj, privateSet);
|
|
42
|
+
privateSet.add(obj);
|
|
43
|
+
}
|
|
44
|
+
function _define_property(obj, key, value) {
|
|
45
|
+
if (key in obj) {
|
|
46
|
+
Object.defineProperty(obj, key, {
|
|
47
|
+
value: value,
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
obj[key] = value;
|
|
54
|
+
}
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
57
|
+
function _interop_require_default(obj) {
|
|
58
|
+
return obj && obj.__esModule ? obj : {
|
|
59
|
+
default: obj
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org';
|
|
63
|
+
var _lazyInit = /*#__PURE__*/ new WeakSet();
|
|
64
|
+
class NpmLocation {
|
|
65
|
+
async manifest() {
|
|
66
|
+
if (this.validatedManifest) {
|
|
67
|
+
return this.validatedManifest.clone();
|
|
68
|
+
}
|
|
69
|
+
const vfile = await this.fetch('snap.manifest.json');
|
|
70
|
+
const result = (0, _snapsutils.parseJson)(vfile.toString());
|
|
71
|
+
vfile.result = (0, _snapsutils.createSnapManifest)(result);
|
|
72
|
+
this.validatedManifest = vfile;
|
|
73
|
+
return this.manifest();
|
|
74
|
+
}
|
|
75
|
+
async fetch(path) {
|
|
76
|
+
const relativePath = (0, _snapsutils.normalizeRelative)(path);
|
|
77
|
+
if (!this.files) {
|
|
78
|
+
await _class_private_method_get(this, _lazyInit, lazyInit).call(this);
|
|
79
|
+
(0, _utils.assert)(this.files !== undefined);
|
|
80
|
+
}
|
|
81
|
+
const vfile = this.files.get(relativePath);
|
|
82
|
+
(0, _utils.assert)(vfile !== undefined, new TypeError(`File "${path}" not found in package.`));
|
|
83
|
+
return vfile.clone();
|
|
84
|
+
}
|
|
85
|
+
get packageName() {
|
|
86
|
+
return this.meta.packageName;
|
|
87
|
+
}
|
|
88
|
+
get version() {
|
|
89
|
+
(0, _utils.assert)(this.meta.version !== undefined, 'Tried to access version without first fetching NPM package.');
|
|
90
|
+
return this.meta.version;
|
|
91
|
+
}
|
|
92
|
+
get registry() {
|
|
93
|
+
return this.meta.registry;
|
|
94
|
+
}
|
|
95
|
+
get versionRange() {
|
|
96
|
+
return this.meta.requestedRange;
|
|
97
|
+
}
|
|
98
|
+
constructor(url, opts = {}){
|
|
99
|
+
_class_private_method_init(this, _lazyInit);
|
|
100
|
+
_define_property(this, "meta", void 0);
|
|
101
|
+
_define_property(this, "validatedManifest", void 0);
|
|
102
|
+
_define_property(this, "files", void 0);
|
|
103
|
+
const allowCustomRegistries = opts.allowCustomRegistries ?? false;
|
|
104
|
+
const fetchFunction = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
105
|
+
const requestedRange = opts.versionRange ?? _snapsutils.DEFAULT_REQUESTED_SNAP_VERSION;
|
|
106
|
+
(0, _utils.assertStruct)(url.toString(), _snapsutils.NpmSnapIdStruct, 'Invalid Snap Id: ');
|
|
107
|
+
let registry;
|
|
108
|
+
if (url.host === '' && url.port === '' && url.username === '' && url.password === '') {
|
|
109
|
+
registry = new URL(DEFAULT_NPM_REGISTRY);
|
|
110
|
+
} else {
|
|
111
|
+
registry = 'https://';
|
|
112
|
+
if (url.username) {
|
|
113
|
+
registry += url.username;
|
|
114
|
+
if (url.password) {
|
|
115
|
+
registry += `:${url.password}`;
|
|
116
|
+
}
|
|
117
|
+
registry += '@';
|
|
118
|
+
}
|
|
119
|
+
registry += url.host;
|
|
120
|
+
registry = new URL(registry);
|
|
121
|
+
(0, _utils.assert)(allowCustomRegistries, new TypeError(`Custom NPM registries are disabled, tried to use "${registry.toString()}".`));
|
|
122
|
+
}
|
|
123
|
+
(0, _utils.assert)(registry.pathname === '/' && registry.search === '' && registry.hash === '');
|
|
124
|
+
(0, _utils.assert)(url.pathname !== '' && url.pathname !== '/', new TypeError('The package name in NPM location is empty.'));
|
|
125
|
+
let packageName = url.pathname;
|
|
126
|
+
if (packageName.startsWith('/')) {
|
|
127
|
+
packageName = packageName.slice(1);
|
|
128
|
+
}
|
|
129
|
+
this.meta = {
|
|
130
|
+
requestedRange,
|
|
131
|
+
registry,
|
|
132
|
+
packageName,
|
|
133
|
+
fetch: fetchFunction
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async function lazyInit() {
|
|
138
|
+
(0, _utils.assert)(this.files === undefined);
|
|
139
|
+
const [tarballResponse, actualVersion] = await fetchNpmTarball(this.meta.packageName, this.meta.requestedRange, this.meta.registry, this.meta.fetch);
|
|
140
|
+
this.meta.version = actualVersion;
|
|
141
|
+
let canonicalBase = 'npm://';
|
|
142
|
+
if (this.meta.registry.username !== '') {
|
|
143
|
+
canonicalBase += this.meta.registry.username;
|
|
144
|
+
if (this.meta.registry.password !== '') {
|
|
145
|
+
canonicalBase += `:${this.meta.registry.password}`;
|
|
146
|
+
}
|
|
147
|
+
canonicalBase += '@';
|
|
148
|
+
}
|
|
149
|
+
canonicalBase += this.meta.registry.host;
|
|
150
|
+
// TODO(ritave): Lazily extract files instead of up-front extracting all of them
|
|
151
|
+
// We would need to replace tar-stream package because it requires immediate consumption of streams.
|
|
152
|
+
await new Promise((resolve, reject)=>{
|
|
153
|
+
this.files = new Map();
|
|
154
|
+
(0, _stream.pipeline)(getNodeStream(tarballResponse), // The "gz" in "tgz" stands for "gzip". The tarball needs to be decompressed
|
|
155
|
+
// before we can actually grab any files from it.
|
|
156
|
+
// To prevent recursion-based zip bombs, we set a maximum recursion depth of 1.
|
|
157
|
+
(0, _gunzipmaybe.default)(1), createTarballStream(`${canonicalBase}/${this.meta.packageName}/`, this.files), (error)=>{
|
|
158
|
+
error ? reject(error) : resolve();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
// Safety limit for tarballs, 250 MB in bytes
|
|
163
|
+
const TARBALL_SIZE_SAFETY_LIMIT = 262144000;
|
|
164
|
+
async function fetchNpmMetadata(packageName, registryUrl, fetchFunction) {
|
|
165
|
+
const packageResponse = await fetchFunction(new URL(packageName, registryUrl).toString());
|
|
166
|
+
if (!packageResponse.ok) {
|
|
167
|
+
throw new Error(`Failed to fetch NPM registry entry. Status code: ${packageResponse.status}.`);
|
|
168
|
+
}
|
|
169
|
+
const packageMetadata = await packageResponse.json();
|
|
170
|
+
if (!(0, _utils.isObject)(packageMetadata)) {
|
|
171
|
+
throw new Error(`Failed to fetch package "${packageName}" metadata from npm.`);
|
|
172
|
+
}
|
|
173
|
+
return packageMetadata;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Fetches the tarball (`.tgz` file) of the specified package and version from
|
|
177
|
+
* the public npm registry.
|
|
178
|
+
*
|
|
179
|
+
* @param packageName - The name of the package whose tarball to fetch.
|
|
180
|
+
* @param versionRange - The SemVer range of the package to fetch. The highest
|
|
181
|
+
* version satisfying the range will be fetched.
|
|
182
|
+
* @param registryUrl - The URL of the npm registry to fetch the tarball from.
|
|
183
|
+
* @param fetchFunction - The fetch function to use. Defaults to the global
|
|
184
|
+
* {@link fetch}. Useful for Node.js compatibility.
|
|
185
|
+
* @returns A tuple of the {@link Response} for the package tarball and the
|
|
186
|
+
* actual version of the package.
|
|
187
|
+
* @throws If fetching the tarball fails.
|
|
188
|
+
*/ async function fetchNpmTarball(packageName, versionRange, registryUrl, fetchFunction) {
|
|
189
|
+
const packageMetadata = await fetchNpmMetadata(packageName, registryUrl, fetchFunction);
|
|
190
|
+
const versions = Object.keys(packageMetadata?.versions ?? {}).map((version)=>{
|
|
191
|
+
(0, _utils.assertIsSemVerVersion)(version);
|
|
192
|
+
return version;
|
|
193
|
+
});
|
|
194
|
+
const targetVersion = (0, _snapsutils.getTargetVersion)(versions, versionRange);
|
|
195
|
+
if (targetVersion === null) {
|
|
196
|
+
throw new Error(`Failed to find a matching version in npm metadata for package "${packageName}" and requested semver range "${versionRange}".`);
|
|
197
|
+
}
|
|
198
|
+
const tarballUrlString = packageMetadata?.versions?.[targetVersion]?.dist?.tarball;
|
|
199
|
+
if (!(0, _snapsutils.isValidUrl)(tarballUrlString) || !tarballUrlString.toString().endsWith('.tgz')) {
|
|
200
|
+
throw new Error(`Failed to find valid tarball URL in NPM metadata for package "${packageName}".`);
|
|
201
|
+
}
|
|
202
|
+
// Override the tarball hostname/protocol with registryUrl hostname/protocol
|
|
203
|
+
const newRegistryUrl = new URL(registryUrl);
|
|
204
|
+
const newTarballUrl = new URL(tarballUrlString);
|
|
205
|
+
newTarballUrl.hostname = newRegistryUrl.hostname;
|
|
206
|
+
newTarballUrl.protocol = newRegistryUrl.protocol;
|
|
207
|
+
// Perform a raw fetch because we want the Response object itself.
|
|
208
|
+
const tarballResponse = await fetchFunction(newTarballUrl.toString());
|
|
209
|
+
if (!tarballResponse.ok || !tarballResponse.body) {
|
|
210
|
+
throw new Error(`Failed to fetch tarball for package "${packageName}".`);
|
|
211
|
+
}
|
|
212
|
+
// We assume that NPM is a good actor and provides us with a valid `content-length` header.
|
|
213
|
+
const tarballSizeString = tarballResponse.headers.get('content-length');
|
|
214
|
+
(0, _utils.assert)(tarballSizeString, 'Snap tarball has invalid content-length');
|
|
215
|
+
const tarballSize = parseInt(tarballSizeString, 10);
|
|
216
|
+
(0, _utils.assert)(tarballSize <= TARBALL_SIZE_SAFETY_LIMIT, 'Snap tarball exceeds size limit');
|
|
217
|
+
return [
|
|
218
|
+
tarballResponse.body,
|
|
219
|
+
targetVersion
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The paths of files within npm tarballs appear to always be prefixed with
|
|
224
|
+
* "package/".
|
|
225
|
+
*/ const NPM_TARBALL_PATH_PREFIX = /^package\//u;
|
|
226
|
+
/**
|
|
227
|
+
* Converts a {@link ReadableStream} to a Node.js {@link Readable}
|
|
228
|
+
* stream. Returns the stream directly if it is already a Node.js stream.
|
|
229
|
+
* We can't use the native Web {@link ReadableStream} directly because the
|
|
230
|
+
* other stream libraries we use expect Node.js streams.
|
|
231
|
+
*
|
|
232
|
+
* @param stream - The stream to convert.
|
|
233
|
+
* @returns The given stream as a Node.js Readable stream.
|
|
234
|
+
*/ function getNodeStream(stream) {
|
|
235
|
+
if (typeof stream.getReader !== 'function') {
|
|
236
|
+
return stream;
|
|
237
|
+
}
|
|
238
|
+
return new _readablewebtonodestream.ReadableWebToNodeStream(stream);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Creates a `tar-stream` that will get the necessary files from an npm Snap
|
|
242
|
+
* package tarball (`.tgz` file).
|
|
243
|
+
*
|
|
244
|
+
* @param canonicalBase - A base URI as specified in {@link https://github.com/MetaMask/SIPs/blob/main/SIPS/sip-8.md SIP-8}. Starting with 'npm:'. Will be used for canonicalPath vfile argument.
|
|
245
|
+
* @param files - An object to write target file contents to.
|
|
246
|
+
* @returns The {@link Writable} tarball extraction stream.
|
|
247
|
+
*/ function createTarballStream(canonicalBase, files) {
|
|
248
|
+
(0, _utils.assert)(canonicalBase.endsWith('/'), "Base needs to end with '/' for relative paths to be added as children instead of siblings.");
|
|
249
|
+
(0, _utils.assert)(canonicalBase.startsWith('npm:'), 'Protocol mismatch, expected "npm:".');
|
|
250
|
+
// `tar-stream` is pretty old-school, so we create it first and then
|
|
251
|
+
// instrument it by adding event listeners.
|
|
252
|
+
const extractStream = (0, _tarstream.extract)();
|
|
253
|
+
let totalSize = 0;
|
|
254
|
+
// "entry" is fired for every discreet entity in the tarball. This includes
|
|
255
|
+
// files and folders.
|
|
256
|
+
extractStream.on('entry', (header, entryStream, next)=>{
|
|
257
|
+
const { name: headerName, type: headerType } = header;
|
|
258
|
+
if (headerType === 'file') {
|
|
259
|
+
// The name is a path if the header type is "file".
|
|
260
|
+
const path = headerName.replace(NPM_TARBALL_PATH_PREFIX, '');
|
|
261
|
+
return entryStream.pipe((0, _concatstream.default)({
|
|
262
|
+
encoding: 'uint8array'
|
|
263
|
+
}, (data)=>{
|
|
264
|
+
try {
|
|
265
|
+
totalSize += data.byteLength;
|
|
266
|
+
// To prevent zip bombs, we set a safety limit for the total size of tarballs.
|
|
267
|
+
(0, _utils.assert)(totalSize < TARBALL_SIZE_SAFETY_LIMIT, `Snap tarball exceeds limit of ${TARBALL_SIZE_SAFETY_LIMIT} bytes.`);
|
|
268
|
+
const vfile = new _snapsutils.VirtualFile({
|
|
269
|
+
value: data,
|
|
270
|
+
path,
|
|
271
|
+
data: {
|
|
272
|
+
canonicalPath: new URL(path, canonicalBase).toString()
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
// We disallow files having identical paths as it may confuse our checksum calculations.
|
|
276
|
+
(0, _utils.assert)(!files.has(path), 'Malformed tarball, multiple files with the same path.');
|
|
277
|
+
files.set(path, vfile);
|
|
278
|
+
return next();
|
|
279
|
+
} catch (error) {
|
|
280
|
+
return extractStream.destroy(error);
|
|
281
|
+
}
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
// If we get here, the entry is not a file, and we want to ignore. The entry
|
|
285
|
+
// stream must be drained, or the extractStream will stop reading. This is
|
|
286
|
+
// effectively a no-op for the current entry.
|
|
287
|
+
entryStream.on('end', ()=>next());
|
|
288
|
+
return entryStream.resume();
|
|
289
|
+
});
|
|
290
|
+
return extractStream;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
//# sourceMappingURL=npm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/snaps/location/npm.ts"],"sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n createSnapManifest,\n DEFAULT_REQUESTED_SNAP_VERSION,\n getTargetVersion,\n isValidUrl,\n NpmSnapIdStruct,\n VirtualFile,\n normalizeRelative,\n parseJson,\n} from '@metamask/snaps-utils';\nimport type { SemVerRange, SemVerVersion } from '@metamask/utils';\nimport {\n assert,\n assertIsSemVerVersion,\n assertStruct,\n isObject,\n} from '@metamask/utils';\nimport concat from 'concat-stream';\nimport createGunzipStream from 'gunzip-maybe';\nimport { ReadableWebToNodeStream } from 'readable-web-to-node-stream';\nimport { pipeline } from 'stream';\nimport type { Readable, Writable } from 'stream';\nimport { extract as tarExtract } from 'tar-stream';\n\nimport type { DetectSnapLocationOptions, SnapLocation } from './location';\n\nexport const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org';\n\ninterface NpmMeta {\n registry: URL;\n packageName: string;\n requestedRange: SemVerRange;\n version?: string;\n fetch: typeof fetch;\n}\nexport interface NpmOptions {\n /**\n * @default DEFAULT_REQUESTED_SNAP_VERSION\n */\n versionRange?: SemVerRange;\n /**\n * Whether to allow custom NPM registries outside of {@link DEFAULT_NPM_REGISTRY}.\n *\n * @default false\n */\n allowCustomRegistries?: boolean;\n}\n\nexport class NpmLocation implements SnapLocation {\n private readonly meta: NpmMeta;\n\n private validatedManifest?: VirtualFile<SnapManifest>;\n\n private files?: Map<string, VirtualFile>;\n\n constructor(url: URL, opts: DetectSnapLocationOptions = {}) {\n const allowCustomRegistries = opts.allowCustomRegistries ?? false;\n const fetchFunction = opts.fetch ?? globalThis.fetch.bind(globalThis);\n const requestedRange = opts.versionRange ?? DEFAULT_REQUESTED_SNAP_VERSION;\n\n assertStruct(url.toString(), NpmSnapIdStruct, 'Invalid Snap Id: ');\n\n let registry: string | URL;\n if (\n url.host === '' &&\n url.port === '' &&\n url.username === '' &&\n url.password === ''\n ) {\n registry = new URL(DEFAULT_NPM_REGISTRY);\n } else {\n registry = 'https://';\n if (url.username) {\n registry += url.username;\n if (url.password) {\n registry += `:${url.password}`;\n }\n registry += '@';\n }\n registry += url.host;\n registry = new URL(registry);\n assert(\n allowCustomRegistries,\n new TypeError(\n `Custom NPM registries are disabled, tried to use \"${registry.toString()}\".`,\n ),\n );\n }\n\n assert(\n registry.pathname === '/' &&\n registry.search === '' &&\n registry.hash === '',\n );\n\n assert(\n url.pathname !== '' && url.pathname !== '/',\n new TypeError('The package name in NPM location is empty.'),\n );\n let packageName = url.pathname;\n if (packageName.startsWith('/')) {\n packageName = packageName.slice(1);\n }\n\n this.meta = {\n requestedRange,\n registry,\n packageName,\n fetch: fetchFunction,\n };\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n if (this.validatedManifest) {\n return this.validatedManifest.clone();\n }\n\n const vfile = await this.fetch('snap.manifest.json');\n const result = parseJson(vfile.toString());\n vfile.result = createSnapManifest(result);\n this.validatedManifest = vfile as VirtualFile<SnapManifest>;\n\n return this.manifest();\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n const relativePath = normalizeRelative(path);\n if (!this.files) {\n await this.#lazyInit();\n assert(this.files !== undefined);\n }\n const vfile = this.files.get(relativePath);\n assert(\n vfile !== undefined,\n new TypeError(`File \"${path}\" not found in package.`),\n );\n return vfile.clone();\n }\n\n get packageName(): string {\n return this.meta.packageName;\n }\n\n get version(): string {\n assert(\n this.meta.version !== undefined,\n 'Tried to access version without first fetching NPM package.',\n );\n return this.meta.version;\n }\n\n get registry(): URL {\n return this.meta.registry;\n }\n\n get versionRange(): SemVerRange {\n return this.meta.requestedRange;\n }\n\n async #lazyInit() {\n assert(this.files === undefined);\n const [tarballResponse, actualVersion] = await fetchNpmTarball(\n this.meta.packageName,\n this.meta.requestedRange,\n this.meta.registry,\n this.meta.fetch,\n );\n this.meta.version = actualVersion;\n\n let canonicalBase = 'npm://';\n if (this.meta.registry.username !== '') {\n canonicalBase += this.meta.registry.username;\n if (this.meta.registry.password !== '') {\n canonicalBase += `:${this.meta.registry.password}`;\n }\n canonicalBase += '@';\n }\n canonicalBase += this.meta.registry.host;\n\n // TODO(ritave): Lazily extract files instead of up-front extracting all of them\n // We would need to replace tar-stream package because it requires immediate consumption of streams.\n await new Promise<void>((resolve, reject) => {\n this.files = new Map();\n pipeline(\n getNodeStream(tarballResponse),\n // The \"gz\" in \"tgz\" stands for \"gzip\". The tarball needs to be decompressed\n // before we can actually grab any files from it.\n // To prevent recursion-based zip bombs, we set a maximum recursion depth of 1.\n createGunzipStream(1),\n createTarballStream(\n `${canonicalBase}/${this.meta.packageName}/`,\n this.files,\n ),\n (error) => {\n error ? reject(error) : resolve();\n },\n );\n });\n }\n}\n\n// Safety limit for tarballs, 250 MB in bytes\nconst TARBALL_SIZE_SAFETY_LIMIT = 262144000;\n\n// Incomplete type\nexport type PartialNpmMetadata = {\n versions: Record<string, { dist: { tarball: string } }>;\n};\n\n/**\n * Fetches the NPM metadata of the specified package from\n * the public npm registry.\n *\n * @param packageName - The name of the package whose metadata to fetch.\n * @param registryUrl - The URL of the npm registry to fetch the metadata from.\n * @param fetchFunction - The fetch function to use. Defaults to the global\n * {@link fetch}. Useful for Node.js compatibility.\n * @returns The NPM metadata object.\n * @throws If fetching the metadata fails.\n */\nexport async function fetchNpmMetadata(\n packageName: string,\n registryUrl: URL | string,\n fetchFunction: typeof fetch,\n): Promise<PartialNpmMetadata> {\n const packageResponse = await fetchFunction(\n new URL(packageName, registryUrl).toString(),\n );\n if (!packageResponse.ok) {\n throw new Error(\n `Failed to fetch NPM registry entry. Status code: ${packageResponse.status}.`,\n );\n }\n const packageMetadata = await packageResponse.json();\n\n if (!isObject(packageMetadata)) {\n throw new Error(\n `Failed to fetch package \"${packageName}\" metadata from npm.`,\n );\n }\n\n return packageMetadata as PartialNpmMetadata;\n}\n\n/**\n * Fetches the tarball (`.tgz` file) of the specified package and version from\n * the public npm registry.\n *\n * @param packageName - The name of the package whose tarball to fetch.\n * @param versionRange - The SemVer range of the package to fetch. The highest\n * version satisfying the range will be fetched.\n * @param registryUrl - The URL of the npm registry to fetch the tarball from.\n * @param fetchFunction - The fetch function to use. Defaults to the global\n * {@link fetch}. Useful for Node.js compatibility.\n * @returns A tuple of the {@link Response} for the package tarball and the\n * actual version of the package.\n * @throws If fetching the tarball fails.\n */\nasync function fetchNpmTarball(\n packageName: string,\n versionRange: SemVerRange,\n registryUrl: URL | string,\n fetchFunction: typeof fetch,\n): Promise<[ReadableStream, SemVerVersion]> {\n const packageMetadata = await fetchNpmMetadata(\n packageName,\n registryUrl,\n fetchFunction,\n );\n\n const versions = Object.keys(packageMetadata?.versions ?? {}).map(\n (version) => {\n assertIsSemVerVersion(version);\n return version;\n },\n );\n\n const targetVersion = getTargetVersion(versions, versionRange);\n\n if (targetVersion === null) {\n throw new Error(\n `Failed to find a matching version in npm metadata for package \"${packageName}\" and requested semver range \"${versionRange}\".`,\n );\n }\n\n const tarballUrlString =\n packageMetadata?.versions?.[targetVersion]?.dist?.tarball;\n\n if (\n !isValidUrl(tarballUrlString) ||\n !tarballUrlString.toString().endsWith('.tgz')\n ) {\n throw new Error(\n `Failed to find valid tarball URL in NPM metadata for package \"${packageName}\".`,\n );\n }\n\n // Override the tarball hostname/protocol with registryUrl hostname/protocol\n const newRegistryUrl = new URL(registryUrl);\n const newTarballUrl = new URL(tarballUrlString);\n newTarballUrl.hostname = newRegistryUrl.hostname;\n newTarballUrl.protocol = newRegistryUrl.protocol;\n\n // Perform a raw fetch because we want the Response object itself.\n const tarballResponse = await fetchFunction(newTarballUrl.toString());\n if (!tarballResponse.ok || !tarballResponse.body) {\n throw new Error(`Failed to fetch tarball for package \"${packageName}\".`);\n }\n // We assume that NPM is a good actor and provides us with a valid `content-length` header.\n const tarballSizeString = tarballResponse.headers.get('content-length');\n assert(tarballSizeString, 'Snap tarball has invalid content-length');\n const tarballSize = parseInt(tarballSizeString, 10);\n assert(\n tarballSize <= TARBALL_SIZE_SAFETY_LIMIT,\n 'Snap tarball exceeds size limit',\n );\n return [tarballResponse.body, targetVersion];\n}\n\n/**\n * The paths of files within npm tarballs appear to always be prefixed with\n * \"package/\".\n */\nconst NPM_TARBALL_PATH_PREFIX = /^package\\//u;\n\n/**\n * Converts a {@link ReadableStream} to a Node.js {@link Readable}\n * stream. Returns the stream directly if it is already a Node.js stream.\n * We can't use the native Web {@link ReadableStream} directly because the\n * other stream libraries we use expect Node.js streams.\n *\n * @param stream - The stream to convert.\n * @returns The given stream as a Node.js Readable stream.\n */\nfunction getNodeStream(stream: ReadableStream): Readable {\n if (typeof stream.getReader !== 'function') {\n return stream as unknown as Readable;\n }\n\n return new ReadableWebToNodeStream(stream);\n}\n\n/**\n * Creates a `tar-stream` that will get the necessary files from an npm Snap\n * package tarball (`.tgz` file).\n *\n * @param canonicalBase - A base URI as specified in {@link https://github.com/MetaMask/SIPs/blob/main/SIPS/sip-8.md SIP-8}. Starting with 'npm:'. Will be used for canonicalPath vfile argument.\n * @param files - An object to write target file contents to.\n * @returns The {@link Writable} tarball extraction stream.\n */\nfunction createTarballStream(\n canonicalBase: string,\n files: Map<string, VirtualFile>,\n): Writable {\n assert(\n canonicalBase.endsWith('/'),\n \"Base needs to end with '/' for relative paths to be added as children instead of siblings.\",\n );\n\n assert(\n canonicalBase.startsWith('npm:'),\n 'Protocol mismatch, expected \"npm:\".',\n );\n // `tar-stream` is pretty old-school, so we create it first and then\n // instrument it by adding event listeners.\n const extractStream = tarExtract();\n\n let totalSize = 0;\n\n // \"entry\" is fired for every discreet entity in the tarball. This includes\n // files and folders.\n extractStream.on('entry', (header, entryStream, next) => {\n const { name: headerName, type: headerType } = header;\n if (headerType === 'file') {\n // The name is a path if the header type is \"file\".\n const path = headerName.replace(NPM_TARBALL_PATH_PREFIX, '');\n return entryStream.pipe(\n concat({ encoding: 'uint8array' }, (data) => {\n try {\n totalSize += data.byteLength;\n // To prevent zip bombs, we set a safety limit for the total size of tarballs.\n assert(\n totalSize < TARBALL_SIZE_SAFETY_LIMIT,\n `Snap tarball exceeds limit of ${TARBALL_SIZE_SAFETY_LIMIT} bytes.`,\n );\n const vfile = new VirtualFile({\n value: data,\n path,\n data: {\n canonicalPath: new URL(path, canonicalBase).toString(),\n },\n });\n // We disallow files having identical paths as it may confuse our checksum calculations.\n assert(\n !files.has(path),\n 'Malformed tarball, multiple files with the same path.',\n );\n files.set(path, vfile);\n return next();\n } catch (error) {\n return extractStream.destroy(error);\n }\n }),\n );\n }\n\n // If we get here, the entry is not a file, and we want to ignore. The entry\n // stream must be drained, or the extractStream will stop reading. This is\n // effectively a no-op for the current entry.\n entryStream.on('end', () => next());\n return entryStream.resume();\n });\n return extractStream;\n}\n"],"names":["DEFAULT_NPM_REGISTRY","NpmLocation","fetchNpmMetadata","manifest","validatedManifest","clone","vfile","fetch","result","parseJson","toString","createSnapManifest","path","relativePath","normalizeRelative","files","lazyInit","assert","undefined","get","TypeError","packageName","meta","version","registry","versionRange","requestedRange","constructor","url","opts","allowCustomRegistries","fetchFunction","globalThis","bind","DEFAULT_REQUESTED_SNAP_VERSION","assertStruct","NpmSnapIdStruct","host","port","username","password","URL","pathname","search","hash","startsWith","slice","tarballResponse","actualVersion","fetchNpmTarball","canonicalBase","Promise","resolve","reject","Map","pipeline","getNodeStream","createGunzipStream","createTarballStream","error","TARBALL_SIZE_SAFETY_LIMIT","registryUrl","packageResponse","ok","Error","status","packageMetadata","json","isObject","versions","Object","keys","map","assertIsSemVerVersion","targetVersion","getTargetVersion","tarballUrlString","dist","tarball","isValidUrl","endsWith","newRegistryUrl","newTarballUrl","hostname","protocol","body","tarballSizeString","headers","tarballSize","parseInt","NPM_TARBALL_PATH_PREFIX","stream","getReader","ReadableWebToNodeStream","extractStream","tarExtract","totalSize","on","header","entryStream","next","name","headerName","type","headerType","replace","pipe","concat","encoding","data","byteLength","VirtualFile","value","canonicalPath","has","set","destroy","resume"],"mappings":";;;;;;;;;;;IA2BaA,oBAAoB;eAApBA;;IAsBAC,WAAW;eAAXA;;IA4KSC,gBAAgB;eAAhBA;;;4BAnNf;uBAOA;qEACY;oEACY;yCACS;wBACf;2BAEa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAI/B,MAAMF,uBAAuB;IAqI5B;AA/GD,MAAMC;IAgEX,MAAME,WAA+C;QACnD,IAAI,IAAI,CAACC,iBAAiB,EAAE;YAC1B,OAAO,IAAI,CAACA,iBAAiB,CAACC,KAAK;QACrC;QAEA,MAAMC,QAAQ,MAAM,IAAI,CAACC,KAAK,CAAC;QAC/B,MAAMC,SAASC,IAAAA,qBAAS,EAACH,MAAMI,QAAQ;QACvCJ,MAAME,MAAM,GAAGG,IAAAA,8BAAkB,EAACH;QAClC,IAAI,CAACJ,iBAAiB,GAAGE;QAEzB,OAAO,IAAI,CAACH,QAAQ;IACtB;IAEA,MAAMI,MAAMK,IAAY,EAAwB;QAC9C,MAAMC,eAAeC,IAAAA,6BAAiB,EAACF;QACvC,IAAI,CAAC,IAAI,CAACG,KAAK,EAAE;YACf,MAAM,0BAAA,IAAI,EAAEC,WAAAA,eAAN,IAAI;YACVC,IAAAA,aAAM,EAAC,IAAI,CAACF,KAAK,KAAKG;QACxB;QACA,MAAMZ,QAAQ,IAAI,CAACS,KAAK,CAACI,GAAG,CAACN;QAC7BI,IAAAA,aAAM,EACJX,UAAUY,WACV,IAAIE,UAAU,CAAC,MAAM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0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
processSnapPermissions: function() {
|
|
13
|
+
return processSnapPermissions;
|
|
14
|
+
},
|
|
15
|
+
buildSnapEndowmentSpecifications: function() {
|
|
16
|
+
return buildSnapEndowmentSpecifications;
|
|
17
|
+
},
|
|
18
|
+
buildSnapRestrictedMethodSpecifications: function() {
|
|
19
|
+
return buildSnapRestrictedMethodSpecifications;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _rpcmethods = require("@metamask/rpc-methods");
|
|
23
|
+
const _utils = require("@metamask/utils");
|
|
24
|
+
const _endowments = require("./endowments");
|
|
25
|
+
function processSnapPermissions(initialPermissions) {
|
|
26
|
+
return Object.fromEntries(Object.entries(initialPermissions).map(([initialPermission, value])=>{
|
|
27
|
+
if ((0, _utils.hasProperty)(_rpcmethods.caveatMappers, initialPermission)) {
|
|
28
|
+
return [
|
|
29
|
+
initialPermission,
|
|
30
|
+
_rpcmethods.caveatMappers[initialPermission](value)
|
|
31
|
+
];
|
|
32
|
+
} else if ((0, _utils.hasProperty)(_endowments.endowmentCaveatMappers, initialPermission)) {
|
|
33
|
+
return [
|
|
34
|
+
initialPermission,
|
|
35
|
+
_endowments.endowmentCaveatMappers[initialPermission](value)
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
// If we have no mapping, this may be a non-snap permission, return as-is
|
|
39
|
+
return [
|
|
40
|
+
initialPermission,
|
|
41
|
+
value
|
|
42
|
+
];
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
const buildSnapEndowmentSpecifications = (excludedEndowments)=>Object.values(_endowments.endowmentPermissionBuilders).reduce((allSpecifications, { targetName, specificationBuilder })=>{
|
|
46
|
+
if (!excludedEndowments.includes(targetName)) {
|
|
47
|
+
allSpecifications[targetName] = specificationBuilder({});
|
|
48
|
+
}
|
|
49
|
+
return allSpecifications;
|
|
50
|
+
}, {});
|
|
51
|
+
const buildSnapRestrictedMethodSpecifications = (excludedPermissions, hooks)=>Object.values(_rpcmethods.restrictedMethodPermissionBuilders).reduce((specifications, { targetName, specificationBuilder, methodHooks })=>{
|
|
52
|
+
if (!excludedPermissions.includes(targetName)) {
|
|
53
|
+
specifications[targetName] = specificationBuilder({
|
|
54
|
+
// @ts-expect-error The selectHooks type is wonky
|
|
55
|
+
methodHooks: (0, _rpcmethods.selectHooks)(hooks, methodHooks)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return specifications;
|
|
59
|
+
}, {});
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/snaps/permissions.ts"],"sourcesContent":["import type {\n PermissionConstraint,\n PermissionSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n caveatMappers,\n restrictedMethodPermissionBuilders,\n selectHooks,\n} from '@metamask/rpc-methods';\nimport type { SnapPermissions } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\n\nimport {\n endowmentCaveatMappers,\n endowmentPermissionBuilders,\n} from './endowments';\n\n/**\n * Map initial permissions as defined in a Snap manifest to something that can\n * be processed by the PermissionsController. Each caveat mapping function\n * should return a valid permission caveat value.\n *\n * This function does not validate the caveat values, since that is done by\n * the PermissionsController itself, upon requesting the permissions.\n *\n * @param initialPermissions - The initial permissions to process.\n * @returns The processed permissions.\n */\nexport function processSnapPermissions(\n initialPermissions: SnapPermissions,\n): Record<string, Pick<PermissionConstraint, 'caveats'>> {\n return Object.fromEntries(\n Object.entries(initialPermissions).map(([initialPermission, value]) => {\n if (hasProperty(caveatMappers, initialPermission)) {\n return [initialPermission, caveatMappers[initialPermission](value)];\n } else if (hasProperty(endowmentCaveatMappers, initialPermission)) {\n return [\n initialPermission,\n endowmentCaveatMappers[initialPermission](value),\n ];\n }\n\n // If we have no mapping, this may be a non-snap permission, return as-is\n return [\n initialPermission,\n value as Pick<PermissionConstraint, 'caveats'>,\n ];\n }),\n );\n}\n\nexport const buildSnapEndowmentSpecifications = (\n excludedEndowments: string[],\n) =>\n Object.values(endowmentPermissionBuilders).reduce<\n Record<string, PermissionSpecificationConstraint>\n >((allSpecifications, { targetName, specificationBuilder }) => {\n if (!excludedEndowments.includes(targetName)) {\n allSpecifications[targetName] = specificationBuilder({});\n }\n return allSpecifications;\n }, {});\n\nexport const buildSnapRestrictedMethodSpecifications = (\n excludedPermissions: string[],\n hooks: Record<string, unknown>,\n) =>\n Object.values(restrictedMethodPermissionBuilders).reduce<\n Record<string, PermissionSpecificationConstraint>\n >((specifications, { targetName, specificationBuilder, methodHooks }) => {\n if (!excludedPermissions.includes(targetName)) {\n specifications[targetName] = specificationBuilder({\n // @ts-expect-error The selectHooks type is wonky\n methodHooks: selectHooks<typeof hooks, keyof typeof methodHooks>(\n hooks,\n methodHooks,\n ) as Pick<typeof hooks, keyof typeof methodHooks>,\n });\n }\n return specifications;\n }, {});\n"],"names":["processSnapPermissions","buildSnapEndowmentSpecifications","buildSnapRestrictedMethodSpecifications","initialPermissions","Object","fromEntries","entries","map","initialPermission","value","hasProperty","caveatMappers","endowmentCaveatMappers","excludedEndowments","values","endowmentPermissionBuilders","reduce","allSpecifications","targetName","specificationBuilder","includes","excludedPermissions","hooks","restrictedMethodPermissionBuilders","specifications","methodHooks","selectHooks"],"mappings":";;;;;;;;;;;IA4BgBA,sBAAsB;eAAtBA;;IAuBHC,gCAAgC;eAAhCA;;IAYAC,uCAAuC;eAAvCA;;;4BAvDN;uBAEqB;4BAKrB;AAaA,SAASF,uBACdG,kBAAmC;IAEnC,OAAOC,OAAOC,WAAW,CACvBD,OAAOE,OAAO,CAACH,oBAAoBI,GAAG,CAAC,CAAC,CAACC,mBAAmBC,MAAM;QAChE,IAAIC,IAAAA,kBAAW,EAACC,yBAAa,EAAEH,oBAAoB;YACjD,OAAO;gBAACA;gBAAmBG,yBAAa,CAACH,kBAAkB,CAACC;aAAO;QACrE,OAAO,IAAIC,IAAAA,kBAAW,EAACE,kCAAsB,EAAEJ,oBAAoB;YACjE,OAAO;gBACLA;gBACAI,kCAAsB,CAACJ,kBAAkB,CAACC;aAC3C;QACH;QAEA,yEAAyE;QACzE,OAAO;YACLD;YACAC;SACD;IACH;AAEJ;AAEO,MAAMR,mCAAmC,CAC9CY,qBAEAT,OAAOU,MAAM,CAACC,uCAA2B,EAAEC,MAAM,CAE/C,CAACC,mBAAmB,EAAEC,UAAU,EAAEC,oBAAoB,EAAE;QACxD,IAAI,CAACN,mBAAmBO,QAAQ,CAACF,aAAa;YAC5CD,iBAAiB,CAACC,WAAW,GAAGC,qBAAqB,CAAC;QACxD;QACA,OAAOF;IACT,GAAG,CAAC;AAEC,MAAMf,0CAA0C,CACrDmB,qBACAC,QAEAlB,OAAOU,MAAM,CAACS,8CAAkC,EAAEP,MAAM,CAEtD,CAACQ,gBAAgB,EAAEN,UAAU,EAAEC,oBAAoB,EAAEM,WAAW,EAAE;QAClE,IAAI,CAACJ,oBAAoBD,QAAQ,CAACF,aAAa;YAC7CM,cAAc,CAACN,WAAW,GAAGC,qBAAqB;gBAChD,iDAAiD;gBACjDM,aAAaC,IAAAA,uBAAW,EACtBJ,OACAG;YAEJ;QACF;QACA,OAAOD;IACT,GAAG,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./registry"), exports);
|
|
6
|
+
_export_star(require("./json"), exports);
|
|
7
|
+
function _export_star(from, to) {
|
|
8
|
+
Object.keys(from).forEach(function(k) {
|
|
9
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
+
Object.defineProperty(to, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return from[k];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return from;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/snaps/registry/index.ts"],"sourcesContent":["export * from './registry';\nexport * from './json';\n"],"names":[],"mappings":";;;;qBAAc;qBACA"}
|