@metamask/snaps-utils 0.34.0-flask.1 → 0.35.0-flask.1
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 +26 -1
- package/dist/cjs/array.js +23 -0
- package/dist/cjs/array.js.map +1 -0
- package/dist/cjs/caveats.js +33 -0
- package/dist/cjs/caveats.js.map +1 -0
- package/dist/cjs/checksum.js +38 -0
- package/dist/cjs/checksum.js.map +1 -0
- package/dist/cjs/cronjob.js +84 -0
- package/dist/cjs/cronjob.js.map +1 -0
- package/dist/cjs/deep-clone.js +22 -0
- package/dist/cjs/deep-clone.js.map +1 -0
- package/dist/cjs/default-endowments.js +49 -0
- package/dist/cjs/default-endowments.js.map +1 -0
- package/dist/cjs/entropy.js +23 -0
- package/dist/cjs/entropy.js.map +1 -0
- package/dist/cjs/enum.js +16 -0
- package/dist/cjs/enum.js.map +1 -0
- package/dist/{eval-worker.js → cjs/eval-worker.js} +22 -21
- package/dist/cjs/eval-worker.js.map +1 -0
- package/dist/cjs/eval.js +29 -0
- package/dist/cjs/eval.js.map +1 -0
- package/dist/cjs/fs.js +126 -0
- package/dist/cjs/fs.js.map +1 -0
- package/dist/cjs/handlers.js +6 -0
- package/dist/cjs/handlers.js.map +1 -0
- package/dist/cjs/icon.js +37 -0
- package/dist/cjs/icon.js.map +1 -0
- package/dist/{iframe.js → cjs/iframe.js} +14 -9
- package/dist/cjs/iframe.js.map +1 -0
- package/dist/cjs/index.browser.js +40 -0
- package/dist/cjs/index.browser.js.map +1 -0
- package/dist/cjs/index.executionenv.js +24 -0
- package/dist/cjs/index.executionenv.js.map +1 -0
- package/dist/cjs/index.js +45 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/json-rpc.js +46 -0
- package/dist/cjs/json-rpc.js.map +1 -0
- package/dist/cjs/json.js +16 -0
- package/dist/cjs/json.js.map +1 -0
- package/dist/cjs/logging.js +40 -0
- package/dist/cjs/logging.js.map +1 -0
- package/dist/cjs/manifest/index.browser.js +20 -0
- package/dist/cjs/manifest/index.browser.js.map +1 -0
- package/dist/cjs/manifest/index.js +21 -0
- package/dist/cjs/manifest/index.js.map +1 -0
- package/dist/cjs/manifest/manifest.js +239 -0
- package/dist/cjs/manifest/manifest.js.map +1 -0
- package/dist/cjs/manifest/validation.js +183 -0
- package/dist/cjs/manifest/validation.js.map +1 -0
- package/dist/cjs/mock.js +128 -0
- package/dist/cjs/mock.js.map +1 -0
- package/dist/cjs/namespace.js +124 -0
- package/dist/cjs/namespace.js.map +1 -0
- package/dist/cjs/npm.js +81 -0
- package/dist/cjs/npm.js.map +1 -0
- package/dist/cjs/path.js +21 -0
- package/dist/cjs/path.js.map +1 -0
- package/dist/cjs/post-process.js +328 -0
- package/dist/cjs/post-process.js.map +1 -0
- package/dist/cjs/snaps.js +230 -0
- package/dist/cjs/snaps.js.map +1 -0
- package/dist/cjs/types.js +117 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/validation.js +22 -0
- package/dist/cjs/validation.js.map +1 -0
- package/dist/cjs/versions.js +47 -0
- package/dist/cjs/versions.js.map +1 -0
- package/dist/cjs/virtual-file/VirtualFile.js +85 -0
- package/dist/cjs/virtual-file/VirtualFile.js.map +1 -0
- package/dist/cjs/virtual-file/index.browser.js +20 -0
- package/dist/cjs/virtual-file/index.browser.js.map +1 -0
- package/dist/cjs/virtual-file/index.js +21 -0
- package/dist/cjs/virtual-file/index.js.map +1 -0
- package/dist/cjs/virtual-file/toVirtualFile.js +33 -0
- package/dist/cjs/virtual-file/toVirtualFile.js.map +1 -0
- package/dist/esm/array.js +13 -0
- package/dist/esm/array.js.map +1 -0
- package/dist/esm/caveats.js +23 -0
- package/dist/esm/caveats.js.map +1 -0
- package/dist/esm/checksum.js +36 -0
- package/dist/esm/checksum.js.map +1 -0
- package/dist/esm/cronjob.js +66 -0
- package/dist/esm/cronjob.js.map +1 -0
- package/dist/esm/deep-clone.js +7 -0
- package/dist/esm/deep-clone.js.map +1 -0
- package/dist/{default-endowments.js → esm/default-endowments.js} +3 -6
- package/dist/esm/default-endowments.js.map +1 -0
- package/dist/esm/entropy.js +6 -0
- package/dist/esm/entropy.js.map +1 -0
- package/dist/esm/enum.js +12 -0
- package/dist/esm/enum.js.map +1 -0
- package/dist/esm/eval-worker.js +47 -0
- package/dist/esm/eval-worker.js.map +1 -0
- package/dist/esm/eval.js +25 -0
- package/dist/esm/eval.js.map +1 -0
- package/dist/{fs.js → esm/fs.js} +33 -55
- package/dist/esm/fs.js.map +1 -0
- package/dist/esm/handlers.js +3 -0
- package/dist/esm/handlers.js.map +1 -0
- package/dist/esm/icon.js +11 -0
- package/dist/esm/icon.js.map +1 -0
- package/dist/esm/iframe.js +49 -0
- package/dist/esm/iframe.js.map +1 -0
- package/dist/esm/index.browser.js +23 -0
- package/dist/esm/index.browser.js.map +1 -0
- package/dist/esm/index.executionenv.js +7 -0
- package/dist/esm/index.executionenv.js.map +1 -0
- package/dist/esm/index.js +28 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-rpc.js +39 -0
- package/dist/esm/json-rpc.js.map +1 -0
- package/dist/esm/json.js +17 -0
- package/dist/esm/json.js.map +1 -0
- package/dist/{logging.js → esm/logging.js} +6 -14
- package/dist/esm/logging.js.map +1 -0
- package/dist/esm/manifest/index.browser.js +3 -0
- package/dist/esm/manifest/index.browser.js.map +1 -0
- package/dist/esm/manifest/index.js +4 -0
- package/dist/esm/manifest/index.js.map +1 -0
- package/dist/{manifest → esm/manifest}/manifest.js +91 -107
- package/dist/esm/manifest/manifest.js.map +1 -0
- package/dist/esm/manifest/validation.js +152 -0
- package/dist/esm/manifest/validation.js.map +1 -0
- package/dist/{mock.js → esm/mock.js} +40 -42
- package/dist/esm/mock.js.map +1 -0
- package/dist/esm/namespace.js +110 -0
- package/dist/esm/namespace.js.map +1 -0
- package/dist/{npm.js → esm/npm.js} +23 -30
- package/dist/esm/npm.js.map +1 -0
- package/dist/esm/path.js +17 -0
- package/dist/esm/path.js.map +1 -0
- package/dist/{post-process.js → esm/post-process.js} +110 -99
- package/dist/esm/post-process.js.map +1 -0
- package/dist/esm/snaps.js +215 -0
- package/dist/esm/snaps.js.map +1 -0
- package/dist/esm/types.js +85 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/validation.js +17 -0
- package/dist/esm/validation.js.map +1 -0
- package/dist/{versions.js → esm/versions.js} +15 -18
- package/dist/esm/versions.js.map +1 -0
- package/dist/{virtual-file → esm/virtual-file}/VirtualFile.js +47 -33
- package/dist/esm/virtual-file/VirtualFile.js.map +1 -0
- package/dist/esm/virtual-file/index.browser.js +3 -0
- package/dist/esm/virtual-file/index.browser.js.map +1 -0
- package/dist/esm/virtual-file/index.js +4 -0
- package/dist/esm/virtual-file/index.js.map +1 -0
- package/dist/esm/virtual-file/toVirtualFile.js +26 -0
- package/dist/esm/virtual-file/toVirtualFile.js.map +1 -0
- package/dist/types/array.d.ts +10 -0
- package/dist/{caveats.d.ts → types/caveats.d.ts} +0 -4
- package/dist/types/enum.d.ts +30 -0
- package/dist/{handlers.d.ts → types/handlers.d.ts} +1 -38
- package/dist/{index.browser.d.ts → types/index.browser.d.ts} +3 -1
- package/dist/{index.d.ts → types/index.d.ts} +3 -1
- package/dist/types/index.executionenv.d.ts +4 -0
- package/dist/types/json.d.ts +13 -0
- package/dist/{manifest → types/manifest}/validation.d.ts +6 -69
- package/dist/types/namespace.d.ts +124 -0
- package/dist/{types.d.ts → types/types.d.ts} +2 -5
- package/package.json +52 -25
- package/dist/caveats.js +0 -35
- package/dist/caveats.js.map +0 -1
- package/dist/checksum.js +0 -42
- package/dist/checksum.js.map +0 -1
- package/dist/cronjob.js +0 -71
- package/dist/cronjob.js.map +0 -1
- package/dist/deep-clone.js +0 -9
- package/dist/deep-clone.js.map +0 -1
- package/dist/default-endowments.js.map +0 -1
- package/dist/entropy.js +0 -8
- package/dist/entropy.js.map +0 -1
- package/dist/eval-worker.js.map +0 -1
- package/dist/eval.js +0 -27
- package/dist/eval.js.map +0 -1
- package/dist/fs.js.map +0 -1
- package/dist/handlers.js +0 -3
- package/dist/handlers.js.map +0 -1
- package/dist/icon.js +0 -17
- package/dist/icon.js.map +0 -1
- package/dist/iframe.js.map +0 -1
- package/dist/iframe.test.browser.js +0 -15
- package/dist/iframe.test.browser.js.map +0 -1
- package/dist/index.browser.js +0 -36
- package/dist/index.browser.js.map +0 -1
- package/dist/index.js +0 -41
- package/dist/index.js.map +0 -1
- package/dist/json-rpc.js +0 -46
- package/dist/json-rpc.js.map +0 -1
- package/dist/logging.js.map +0 -1
- package/dist/manifest/index.browser.js +0 -18
- package/dist/manifest/index.browser.js.map +0 -1
- package/dist/manifest/index.js +0 -19
- package/dist/manifest/index.js.map +0 -1
- package/dist/manifest/manifest.js.map +0 -1
- package/dist/manifest/validation.js +0 -146
- package/dist/manifest/validation.js.map +0 -1
- package/dist/mock.js.map +0 -1
- package/dist/namespace.d.ts +0 -275
- package/dist/namespace.js +0 -225
- package/dist/namespace.js.map +0 -1
- package/dist/notification.d.ts +0 -66
- package/dist/notification.js +0 -58
- package/dist/notification.js.map +0 -1
- package/dist/npm.js.map +0 -1
- package/dist/path.js +0 -21
- package/dist/path.js.map +0 -1
- package/dist/post-process.js.map +0 -1
- package/dist/snaps.js +0 -212
- package/dist/snaps.js.map +0 -1
- package/dist/types.js +0 -103
- package/dist/types.js.map +0 -1
- package/dist/validation.js +0 -21
- package/dist/validation.js.map +0 -1
- package/dist/versions.js.map +0 -1
- package/dist/virtual-file/VirtualFile.js.map +0 -1
- package/dist/virtual-file/index.browser.js +0 -18
- package/dist/virtual-file/index.browser.js.map +0 -1
- package/dist/virtual-file/index.js +0 -19
- package/dist/virtual-file/index.js.map +0 -1
- package/dist/virtual-file/toVirtualFile.js +0 -30
- package/dist/virtual-file/toVirtualFile.js.map +0 -1
- /package/dist/{checksum.d.ts → types/checksum.d.ts} +0 -0
- /package/dist/{cronjob.d.ts → types/cronjob.d.ts} +0 -0
- /package/dist/{deep-clone.d.ts → types/deep-clone.d.ts} +0 -0
- /package/dist/{default-endowments.d.ts → types/default-endowments.d.ts} +0 -0
- /package/dist/{entropy.d.ts → types/entropy.d.ts} +0 -0
- /package/dist/{eval-worker.d.ts → types/eval-worker.d.ts} +0 -0
- /package/dist/{eval.d.ts → types/eval.d.ts} +0 -0
- /package/dist/{fs.d.ts → types/fs.d.ts} +0 -0
- /package/dist/{icon.d.ts → types/icon.d.ts} +0 -0
- /package/dist/{iframe.d.ts → types/iframe.d.ts} +0 -0
- /package/dist/{iframe.test.browser.d.ts → types/iframe.test.browser.d.ts} +0 -0
- /package/dist/{json-rpc.d.ts → types/json-rpc.d.ts} +0 -0
- /package/dist/{logging.d.ts → types/logging.d.ts} +0 -0
- /package/dist/{manifest → types/manifest}/index.browser.d.ts +0 -0
- /package/dist/{manifest → types/manifest}/index.d.ts +0 -0
- /package/dist/{manifest → types/manifest}/manifest.d.ts +0 -0
- /package/dist/{mock.d.ts → types/mock.d.ts} +0 -0
- /package/dist/{npm.d.ts → types/npm.d.ts} +0 -0
- /package/dist/{path.d.ts → types/path.d.ts} +0 -0
- /package/dist/{post-process.d.ts → types/post-process.d.ts} +0 -0
- /package/dist/{snaps.d.ts → types/snaps.d.ts} +0 -0
- /package/dist/{validation.d.ts → types/validation.d.ts} +0 -0
- /package/dist/{versions.d.ts → types/versions.d.ts} +0 -0
- /package/dist/{virtual-file → types/virtual-file}/VirtualFile.d.ts +0 -0
- /package/dist/{virtual-file → types/virtual-file}/index.browser.d.ts +0 -0
- /package/dist/{virtual-file → types/virtual-file}/index.d.ts +0 -0
- /package/dist/{virtual-file → types/virtual-file}/toVirtualFile.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/handlers.ts"],"names":[],"mappings":""}
|
package/dist/cjs/icon.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
SVG_MAX_BYTE_SIZE: function() {
|
|
13
|
+
return SVG_MAX_BYTE_SIZE;
|
|
14
|
+
},
|
|
15
|
+
SVG_MAX_BYTE_SIZE_TEXT: function() {
|
|
16
|
+
return SVG_MAX_BYTE_SIZE_TEXT;
|
|
17
|
+
},
|
|
18
|
+
assertIsSnapIcon: function() {
|
|
19
|
+
return assertIsSnapIcon;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _utils = require("@metamask/utils");
|
|
23
|
+
const _issvg = /*#__PURE__*/ _interop_require_default(require("is-svg"));
|
|
24
|
+
function _interop_require_default(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const SVG_MAX_BYTE_SIZE = 100000;
|
|
30
|
+
const SVG_MAX_BYTE_SIZE_TEXT = `${Math.floor(SVG_MAX_BYTE_SIZE / 1000)}kb`;
|
|
31
|
+
const assertIsSnapIcon = (icon)=>{
|
|
32
|
+
(0, _utils.assert)(icon.path.endsWith('.svg'), 'Expected snap icon to end in ".svg".');
|
|
33
|
+
(0, _utils.assert)(Buffer.byteLength(icon.value, 'utf8') <= SVG_MAX_BYTE_SIZE, `The specified SVG icon exceeds the maximum size of ${SVG_MAX_BYTE_SIZE_TEXT}.`);
|
|
34
|
+
(0, _utils.assert)((0, _issvg.default)(icon.toString()), 'Snap icon must be a valid SVG.');
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=icon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/icon.ts"],"sourcesContent":["import { assert } from '@metamask/utils';\nimport isSvg from 'is-svg';\n\nimport { VirtualFile } from './virtual-file';\n\nexport const SVG_MAX_BYTE_SIZE = 100_000;\nexport const SVG_MAX_BYTE_SIZE_TEXT = `${Math.floor(\n SVG_MAX_BYTE_SIZE / 1000,\n)}kb`;\n\nexport const assertIsSnapIcon = (icon: VirtualFile) => {\n assert(icon.path.endsWith('.svg'), 'Expected snap icon to end in \".svg\".');\n\n assert(\n Buffer.byteLength(icon.value, 'utf8') <= SVG_MAX_BYTE_SIZE,\n `The specified SVG icon exceeds the maximum size of ${SVG_MAX_BYTE_SIZE_TEXT}.`,\n );\n\n assert(isSvg(icon.toString()), 'Snap icon must be a valid SVG.');\n};\n"],"names":["SVG_MAX_BYTE_SIZE","SVG_MAX_BYTE_SIZE_TEXT","assertIsSnapIcon","Math","floor","icon","assert","path","endsWith","Buffer","byteLength","value","isSvg","toString"],"mappings":";;;;;;;;;;;IAKaA,iBAAiB;eAAjBA;;IACAC,sBAAsB;eAAtBA;;IAIAC,gBAAgB;eAAhBA;;;uBAVU;8DACL;;;;;;AAIX,MAAMF,oBAAoB;AAC1B,MAAMC,yBAAyB,CAAC,EAAEE,KAAKC,KAAK,CACjDJ,oBAAoB,MACpB,EAAE,CAAC;AAEE,MAAME,mBAAmB,CAACG;IAC/BC,IAAAA,aAAM,EAACD,KAAKE,IAAI,CAACC,QAAQ,CAAC,SAAS;IAEnCF,IAAAA,aAAM,EACJG,OAAOC,UAAU,CAACL,KAAKM,KAAK,EAAE,WAAWX,mBACzC,CAAC,mDAAmD,EAAEC,uBAAuB,CAAC,CAAC;IAGjFK,IAAAA,aAAM,EAACM,IAAAA,cAAK,EAACP,KAAKQ,QAAQ,KAAK;AACjC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createWindow = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Creates the iframe to be used as the execution environment. This may run
|
|
6
3
|
* forever if the iframe never loads, but the promise should be wrapped in
|
|
@@ -10,9 +7,18 @@ exports.createWindow = void 0;
|
|
|
10
7
|
* @param id - The ID to assign to the iframe.
|
|
11
8
|
* @param sandbox - Whether to enable the sandbox attribute.
|
|
12
9
|
* @returns A promise that resolves to the contentWindow of the iframe.
|
|
13
|
-
*/
|
|
10
|
+
*/ "use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", {
|
|
12
|
+
value: true
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "createWindow", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function() {
|
|
17
|
+
return createWindow;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
14
20
|
async function createWindow(uri, id, sandbox = true) {
|
|
15
|
-
return await new Promise((resolve, reject)
|
|
21
|
+
return await new Promise((resolve, reject)=>{
|
|
16
22
|
const iframe = document.createElement('iframe');
|
|
17
23
|
// The order of operations appears to matter for everything except this
|
|
18
24
|
// attribute. We may as well set it here.
|
|
@@ -38,11 +44,10 @@ async function createWindow(uri, id, sandbox = true) {
|
|
|
38
44
|
// Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489
|
|
39
45
|
iframe.setAttribute('src', uri);
|
|
40
46
|
document.body.appendChild(iframe);
|
|
41
|
-
iframe.addEventListener('load', ()
|
|
47
|
+
iframe.addEventListener('load', ()=>{
|
|
42
48
|
if (iframe.contentWindow) {
|
|
43
49
|
resolve(iframe.contentWindow);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
50
|
+
} else {
|
|
46
51
|
// We don't know of a case when this would happen, but better to fail
|
|
47
52
|
// fast if it does.
|
|
48
53
|
reject(new Error(`iframe.contentWindow not present on load for job "${id}".`));
|
|
@@ -50,5 +55,5 @@ async function createWindow(uri, id, sandbox = true) {
|
|
|
50
55
|
});
|
|
51
56
|
});
|
|
52
57
|
}
|
|
53
|
-
|
|
58
|
+
|
|
54
59
|
//# sourceMappingURL=iframe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/iframe.ts"],"sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n * @param uri - The iframe URI.\n * @param id - The ID to assign to the iframe.\n * @param sandbox - Whether to enable the sandbox attribute.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow(\n uri: string,\n id: string,\n sandbox = true,\n): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', 'snaps-iframe');\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener('load', () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n });\n });\n}\n"],"names":["createWindow","uri","id","sandbox","Promise","resolve","reject","iframe","document","createElement","setAttribute","body","appendChild","addEventListener","contentWindow","Error"],"mappings":"AAAA;;;;;;;;;CASC;;;;+BACqBA;;;eAAAA;;;AAAf,eAAeA,aACpBC,GAAW,EACXC,EAAU,EACVC,UAAU,IAAI;IAEd,OAAO,MAAM,IAAIC,QAAQ,CAACC,SAASC;QACjC,MAAMC,SAASC,SAASC,aAAa,CAAC;QACtC,uEAAuE;QACvE,yCAAyC;QACzCF,OAAOG,YAAY,CAAC,MAAMR;QAC1BK,OAAOG,YAAY,CAAC,eAAe;QAEnC,IAAIP,SAAS;YACX,gGAAgG;YAChG,kEAAkE;YAClE,WAAW;YACX,qFAAqF;YACrFI,OAAOG,YAAY,CAAC,WAAW;QACjC;QAEA,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJH,OAAOG,YAAY,CAAC,OAAOT;QAC3BO,SAASG,IAAI,CAACC,WAAW,CAACL;QAE1BA,OAAOM,gBAAgB,CAAC,QAAQ;YAC9B,IAAIN,OAAOO,aAAa,EAAE;gBACxBT,QAAQE,OAAOO,aAAa;YAC9B,OAAO;gBACL,qEAAqE;gBACrE,mBAAmB;gBACnBR,OACE,IAAIS,MACF,CAAC,kDAAkD,EAAEb,GAAG,EAAE,CAAC;YAGjE;QACF;IACF;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./array"), exports);
|
|
6
|
+
_export_star(require("./caveats"), exports);
|
|
7
|
+
_export_star(require("./checksum"), exports);
|
|
8
|
+
_export_star(require("./cronjob"), exports);
|
|
9
|
+
_export_star(require("./deep-clone"), exports);
|
|
10
|
+
_export_star(require("./default-endowments"), exports);
|
|
11
|
+
_export_star(require("./entropy"), exports);
|
|
12
|
+
_export_star(require("./enum"), exports);
|
|
13
|
+
_export_star(require("./handlers"), exports);
|
|
14
|
+
_export_star(require("./iframe"), exports);
|
|
15
|
+
_export_star(require("./json"), exports);
|
|
16
|
+
_export_star(require("./json-rpc"), exports);
|
|
17
|
+
_export_star(require("./logging"), exports);
|
|
18
|
+
_export_star(require("./manifest/index.browser"), exports);
|
|
19
|
+
_export_star(require("./namespace"), exports);
|
|
20
|
+
_export_star(require("./path"), exports);
|
|
21
|
+
_export_star(require("./snaps"), exports);
|
|
22
|
+
_export_star(require("./types"), exports);
|
|
23
|
+
_export_star(require("./validation"), exports);
|
|
24
|
+
_export_star(require("./versions"), exports);
|
|
25
|
+
_export_star(require("./virtual-file/index.browser"), exports);
|
|
26
|
+
function _export_star(from, to) {
|
|
27
|
+
Object.keys(from).forEach(function(k) {
|
|
28
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
29
|
+
Object.defineProperty(to, k, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function() {
|
|
32
|
+
return from[k];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return from;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["export * from './array';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './enum';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Special entrypoint for execution environments for bundle sizing reasons
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
_export_star(require("./handlers"), exports);
|
|
7
|
+
_export_star(require("./logging"), exports);
|
|
8
|
+
_export_star(require("./namespace"), exports);
|
|
9
|
+
_export_star(require("./types"), exports);
|
|
10
|
+
function _export_star(from, to) {
|
|
11
|
+
Object.keys(from).forEach(function(k) {
|
|
12
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
13
|
+
Object.defineProperty(to, k, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function() {
|
|
16
|
+
return from[k];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return from;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=index.executionenv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.executionenv.ts"],"sourcesContent":["// Special entrypoint for execution environments for bundle sizing reasons\nexport * from './handlers';\nexport * from './logging';\nexport * from './namespace';\nexport * from './types';\n"],"names":[],"mappings":"AAAA,0EAA0E;;;;;qBAC5D;qBACA;qBACA;qBACA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./array"), exports);
|
|
6
|
+
_export_star(require("./caveats"), exports);
|
|
7
|
+
_export_star(require("./cronjob"), exports);
|
|
8
|
+
_export_star(require("./checksum"), exports);
|
|
9
|
+
_export_star(require("./deep-clone"), exports);
|
|
10
|
+
_export_star(require("./default-endowments"), exports);
|
|
11
|
+
_export_star(require("./entropy"), exports);
|
|
12
|
+
_export_star(require("./enum"), exports);
|
|
13
|
+
_export_star(require("./eval"), exports);
|
|
14
|
+
_export_star(require("./fs"), exports);
|
|
15
|
+
_export_star(require("./handlers"), exports);
|
|
16
|
+
_export_star(require("./iframe"), exports);
|
|
17
|
+
_export_star(require("./json"), exports);
|
|
18
|
+
_export_star(require("./json-rpc"), exports);
|
|
19
|
+
_export_star(require("./logging"), exports);
|
|
20
|
+
_export_star(require("./manifest"), exports);
|
|
21
|
+
_export_star(require("./mock"), exports);
|
|
22
|
+
_export_star(require("./namespace"), exports);
|
|
23
|
+
_export_star(require("./npm"), exports);
|
|
24
|
+
_export_star(require("./path"), exports);
|
|
25
|
+
_export_star(require("./post-process"), exports);
|
|
26
|
+
_export_star(require("./snaps"), exports);
|
|
27
|
+
_export_star(require("./types"), exports);
|
|
28
|
+
_export_star(require("./validation"), exports);
|
|
29
|
+
_export_star(require("./versions"), exports);
|
|
30
|
+
_export_star(require("./virtual-file"), exports);
|
|
31
|
+
function _export_star(from, to) {
|
|
32
|
+
Object.keys(from).forEach(function(k) {
|
|
33
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
34
|
+
Object.defineProperty(to, k, {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function() {
|
|
37
|
+
return from[k];
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return from;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './array';\nexport * from './caveats';\nexport * from './cronjob';\nexport * from './checksum';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './enum';\nexport * from './eval';\nexport * from './fs';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './npm';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
RpcOriginsStruct: function() {
|
|
13
|
+
return RpcOriginsStruct;
|
|
14
|
+
},
|
|
15
|
+
assertIsRpcOrigins: function() {
|
|
16
|
+
return assertIsRpcOrigins;
|
|
17
|
+
},
|
|
18
|
+
assertIsJsonRpcSuccess: function() {
|
|
19
|
+
return assertIsJsonRpcSuccess;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _utils = require("@metamask/utils");
|
|
23
|
+
const _superstruct = require("superstruct");
|
|
24
|
+
const RpcOriginsStruct = (0, _superstruct.refine)((0, _superstruct.object)({
|
|
25
|
+
dapps: (0, _superstruct.optional)((0, _superstruct.boolean)()),
|
|
26
|
+
snaps: (0, _superstruct.optional)((0, _superstruct.boolean)())
|
|
27
|
+
}), 'RPC origins', (value)=>{
|
|
28
|
+
if (!Object.values(value).some(Boolean)) {
|
|
29
|
+
throw new Error('Must specify at least one JSON-RPC origin');
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
});
|
|
33
|
+
function assertIsRpcOrigins(value, // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
34
|
+
ErrorWrapper) {
|
|
35
|
+
(0, _utils.assertStruct)(value, RpcOriginsStruct, 'Invalid JSON-RPC origins', ErrorWrapper);
|
|
36
|
+
}
|
|
37
|
+
function assertIsJsonRpcSuccess(value) {
|
|
38
|
+
if (!(0, _utils.isJsonRpcSuccess)(value)) {
|
|
39
|
+
if ((0, _utils.isJsonRpcFailure)(value)) {
|
|
40
|
+
throw new Error(`JSON-RPC request failed: ${value.error.message}`);
|
|
41
|
+
}
|
|
42
|
+
throw new Error('Invalid JSON-RPC response.');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=json-rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/json-rpc.ts"],"sourcesContent":["import {\n isJsonRpcFailure,\n isJsonRpcSuccess,\n Json,\n JsonRpcSuccess,\n AssertionErrorConstructor,\n assertStruct,\n} from '@metamask/utils';\nimport { boolean, Infer, object, optional, refine } from 'superstruct';\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n }),\n 'RPC origins',\n (value) => {\n if (!Object.values(value).some(Boolean)) {\n throw new Error('Must specify at least one JSON-RPC origin');\n }\n\n return true;\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess<Json> {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"],"names":["RpcOriginsStruct","assertIsRpcOrigins","assertIsJsonRpcSuccess","refine","object","dapps","optional","boolean","snaps","value","Object","values","some","Boolean","Error","ErrorWrapper","assertStruct","isJsonRpcSuccess","isJsonRpcFailure","error","message"],"mappings":";;;;;;;;;;;IAUaA,gBAAgB;eAAhBA;;IAyBGC,kBAAkB;eAAlBA;;IAqBAC,sBAAsB;eAAtBA;;;uBAjDT;6BACkD;AAElD,MAAMF,mBAAmBG,IAAAA,mBAAM,EACpCC,IAAAA,mBAAM,EAAC;IACLC,OAAOC,IAAAA,qBAAQ,EAACC,IAAAA,oBAAO;IACvBC,OAAOF,IAAAA,qBAAQ,EAACC,IAAAA,oBAAO;AACzB,IACA,eACA,CAACE;IACC,IAAI,CAACC,OAAOC,MAAM,CAACF,OAAOG,IAAI,CAACC,UAAU;QACvC,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAO;AACT;AAaK,SAASb,mBACdQ,KAAc,EACd,gEAAgE;AAChEM,YAAwC;IAExCC,IAAAA,mBAAY,EACVP,OACAT,kBACA,4BACAe;AAEJ;AAUO,SAASb,uBACdO,KAAc;IAEd,IAAI,CAACQ,IAAAA,uBAAgB,EAACR,QAAQ;QAC5B,IAAIS,IAAAA,uBAAgB,EAACT,QAAQ;YAC3B,MAAM,IAAIK,MAAM,CAAC,yBAAyB,EAAEL,MAAMU,KAAK,CAACC,OAAO,CAAC,CAAC;QACnE;QAEA,MAAM,IAAIN,MAAM;IAClB;AACF"}
|
package/dist/cjs/json.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "parseJson", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return parseJson;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _utils = require("@metamask/utils");
|
|
12
|
+
function parseJson(json) {
|
|
13
|
+
return (0, _utils.getSafeJson)(JSON.parse(json));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import { getSafeJson, Json } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n return getSafeJson<Type>(JSON.parse(json));\n}\n"],"names":["parseJson","json","getSafeJson","JSON","parse"],"mappings":";;;;+BAegBA;;;eAAAA;;;uBAfkB;AAe3B,SAASA,UAAoCC,IAAY;IAC9D,OAAOC,IAAAA,kBAAW,EAAOC,KAAKC,KAAK,CAACH;AACtC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
snapsLogger: function() {
|
|
13
|
+
return snapsLogger;
|
|
14
|
+
},
|
|
15
|
+
logInfo: function() {
|
|
16
|
+
return logInfo;
|
|
17
|
+
},
|
|
18
|
+
logError: function() {
|
|
19
|
+
return logError;
|
|
20
|
+
},
|
|
21
|
+
logWarning: function() {
|
|
22
|
+
return logWarning;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _utils = require("@metamask/utils");
|
|
26
|
+
const snapsLogger = (0, _utils.createProjectLogger)('snaps');
|
|
27
|
+
function logInfo(message, ...optionalParams) {
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.log(message, ...optionalParams);
|
|
30
|
+
}
|
|
31
|
+
function logError(error, ...optionalParams) {
|
|
32
|
+
// eslint-disable-next-line no-console
|
|
33
|
+
console.error(error, ...optionalParams);
|
|
34
|
+
}
|
|
35
|
+
function logWarning(message, ...optionalParams) {
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
37
|
+
console.warn(message, ...optionalParams);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/logging.ts"],"sourcesContent":["import { createProjectLogger } from '@metamask/utils';\n\n// The global logger used across the monorepo. Other projects should use this\n// to create a module logger.\nexport const snapsLogger = createProjectLogger('snaps');\n\n/**\n * Log a message. Currently, this is just a wrapper around `console.log`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param message - The message to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logInfo(message: string, ...optionalParams: unknown[]): void {\n // eslint-disable-next-line no-console\n console.log(message, ...optionalParams);\n}\n\n/**\n * Log an error. Currently, this is just a wrapper around `console.error`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * These logs should always be visible, without requiring the user to enable\n * verbose logging (like setting a `DEBUG` environment variable), as they are\n * important for debugging snaps.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param error - The error to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logError(error: unknown, ...optionalParams: unknown[]): void {\n // eslint-disable-next-line no-console\n console.error(error, ...optionalParams);\n}\n\n/**\n * Log a warning. Currently, this is just a wrapper around `console.warn`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * These logs should always be visible, without requiring the user to enable\n * verbose logging (like setting a `DEBUG` environment variable), as they are\n * important for debugging snaps.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param message - The message to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logWarning(\n message: string,\n ...optionalParams: unknown[]\n): void {\n // eslint-disable-next-line no-console\n console.warn(message, ...optionalParams);\n}\n"],"names":["snapsLogger","logInfo","logError","logWarning","createProjectLogger","message","optionalParams","console","log","error","warn"],"mappings":";;;;;;;;;;;IAIaA,WAAW;eAAXA;;IAcGC,OAAO;eAAPA;;IAqBAC,QAAQ;eAARA;;IAqBAC,UAAU;eAAVA;;;uBA5DoB;AAI7B,MAAMH,cAAcI,IAAAA,0BAAmB,EAAC;AAcxC,SAASH,QAAQI,OAAe,EAAE,GAAGC,cAAyB;IACnE,sCAAsC;IACtCC,QAAQC,GAAG,CAACH,YAAYC;AAC1B;AAkBO,SAASJ,SAASO,KAAc,EAAE,GAAGH,cAAyB;IACnE,sCAAsC;IACtCC,QAAQE,KAAK,CAACA,UAAUH;AAC1B;AAkBO,SAASH,WACdE,OAAe,EACf,GAAGC,cAAyB;IAE5B,sCAAsC;IACtCC,QAAQG,IAAI,CAACL,YAAYC;AAC3B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./validation"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/manifest/index.browser.ts"],"sourcesContent":["export * from './validation';\n"],"names":[],"mappings":";;;;qBAAc"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./manifest"), exports);
|
|
6
|
+
_export_star(require("./validation"), 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/manifest/index.ts"],"sourcesContent":["export * from './manifest';\nexport * from './validation';\n"],"names":[],"mappings":";;;;qBAAc;qBACA"}
|
|
@@ -0,0 +1,239 @@
|
|
|
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
|
+
checkManifest: function() {
|
|
13
|
+
return checkManifest;
|
|
14
|
+
},
|
|
15
|
+
fixManifest: function() {
|
|
16
|
+
return fixManifest;
|
|
17
|
+
},
|
|
18
|
+
getSnapSourceCode: function() {
|
|
19
|
+
return getSnapSourceCode;
|
|
20
|
+
},
|
|
21
|
+
getSnapIcon: function() {
|
|
22
|
+
return getSnapIcon;
|
|
23
|
+
},
|
|
24
|
+
getWritableManifest: function() {
|
|
25
|
+
return getWritableManifest;
|
|
26
|
+
},
|
|
27
|
+
validateNpmSnapManifest: function() {
|
|
28
|
+
return validateNpmSnapManifest;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const _utils = require("@metamask/utils");
|
|
32
|
+
const _fastdeepequal = /*#__PURE__*/ _interop_require_default(require("fast-deep-equal"));
|
|
33
|
+
const _fs = require("fs");
|
|
34
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
35
|
+
const _deepclone = require("../deep-clone");
|
|
36
|
+
const _fs1 = require("../fs");
|
|
37
|
+
const _npm = require("../npm");
|
|
38
|
+
const _snaps = require("../snaps");
|
|
39
|
+
const _types = require("../types");
|
|
40
|
+
const _virtualfile = require("../virtual-file");
|
|
41
|
+
function _interop_require_default(obj) {
|
|
42
|
+
return obj && obj.__esModule ? obj : {
|
|
43
|
+
default: obj
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const MANIFEST_SORT_ORDER = {
|
|
47
|
+
$schema: 1,
|
|
48
|
+
version: 2,
|
|
49
|
+
description: 3,
|
|
50
|
+
proposedName: 4,
|
|
51
|
+
repository: 5,
|
|
52
|
+
source: 6,
|
|
53
|
+
initialPermissions: 7,
|
|
54
|
+
manifestVersion: 8
|
|
55
|
+
};
|
|
56
|
+
async function checkManifest(basePath, writeManifest = true, sourceCode) {
|
|
57
|
+
const warnings = [];
|
|
58
|
+
const errors = [];
|
|
59
|
+
let updated = false;
|
|
60
|
+
const manifestPath = _path.default.join(basePath, _types.NpmSnapFileNames.Manifest);
|
|
61
|
+
const manifestFile = await (0, _fs1.readJsonFile)(manifestPath);
|
|
62
|
+
const unvalidatedManifest = manifestFile.result;
|
|
63
|
+
const packageFile = await (0, _fs1.readJsonFile)(_path.default.join(basePath, _types.NpmSnapFileNames.PackageJson));
|
|
64
|
+
const snapFiles = {
|
|
65
|
+
manifest: manifestFile,
|
|
66
|
+
packageJson: packageFile,
|
|
67
|
+
sourceCode: await getSnapSourceCode(basePath, unvalidatedManifest, sourceCode),
|
|
68
|
+
svgIcon: await getSnapIcon(basePath, unvalidatedManifest)
|
|
69
|
+
};
|
|
70
|
+
let manifest;
|
|
71
|
+
try {
|
|
72
|
+
({ manifest } = (0, _npm.validateNpmSnap)(snapFiles));
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (error instanceof _snaps.ProgrammaticallyFixableSnapError) {
|
|
75
|
+
errors.push(error.message);
|
|
76
|
+
// If we get here, the files at least have the correct shape.
|
|
77
|
+
const partiallyValidatedFiles = snapFiles;
|
|
78
|
+
let isInvalid = true;
|
|
79
|
+
let currentError = error;
|
|
80
|
+
const maxAttempts = Object.keys(_types.SnapValidationFailureReason).length;
|
|
81
|
+
// Attempt to fix all fixable validation failure reasons. All such reasons
|
|
82
|
+
// are enumerated by the `SnapValidationFailureReason` enum, so we only
|
|
83
|
+
// attempt to fix the manifest the same amount of times as there are
|
|
84
|
+
// reasons in the enum.
|
|
85
|
+
for(let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++){
|
|
86
|
+
manifest = fixManifest(manifest ? {
|
|
87
|
+
...partiallyValidatedFiles,
|
|
88
|
+
manifest
|
|
89
|
+
} : partiallyValidatedFiles, currentError);
|
|
90
|
+
try {
|
|
91
|
+
validateNpmSnapManifest({
|
|
92
|
+
...partiallyValidatedFiles,
|
|
93
|
+
manifest
|
|
94
|
+
});
|
|
95
|
+
isInvalid = false;
|
|
96
|
+
} catch (nextValidationError) {
|
|
97
|
+
currentError = nextValidationError;
|
|
98
|
+
/* istanbul ignore next: this should be impossible */ if (!(nextValidationError instanceof _snaps.ProgrammaticallyFixableSnapError) || attempts === maxAttempts && !isInvalid) {
|
|
99
|
+
throw new Error(`Internal error: Failed to fix manifest. This is a bug, please report it. Reason:\n${error.message}`);
|
|
100
|
+
}
|
|
101
|
+
errors.push(currentError.message);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
updated = true;
|
|
105
|
+
} else {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// TypeScript assumes `manifest` can still be undefined, that is not the case.
|
|
110
|
+
// But we assert to keep TypeScript happy.
|
|
111
|
+
(0, _utils.assert)(manifest);
|
|
112
|
+
const validatedManifest = manifest.result;
|
|
113
|
+
// Check presence of recommended keys
|
|
114
|
+
const recommendedFields = [
|
|
115
|
+
'repository'
|
|
116
|
+
];
|
|
117
|
+
const missingRecommendedFields = recommendedFields.filter((key)=>!validatedManifest[key]);
|
|
118
|
+
if (missingRecommendedFields.length > 0) {
|
|
119
|
+
warnings.push(`Missing recommended package.json properties:\n${missingRecommendedFields.reduce((allMissing, currentField)=>{
|
|
120
|
+
return `${allMissing}\t${currentField}\n`;
|
|
121
|
+
}, '')}`);
|
|
122
|
+
}
|
|
123
|
+
if (writeManifest) {
|
|
124
|
+
try {
|
|
125
|
+
const newManifest = `${JSON.stringify(getWritableManifest(validatedManifest), null, 2)}\n`;
|
|
126
|
+
if (updated || newManifest !== manifestFile.value) {
|
|
127
|
+
await _fs.promises.writeFile(_path.default.join(basePath, _types.NpmSnapFileNames.Manifest), newManifest);
|
|
128
|
+
}
|
|
129
|
+
} catch (error) {
|
|
130
|
+
// Note: This error isn't pushed to the errors array, because it's not an
|
|
131
|
+
// error in the manifest itself.
|
|
132
|
+
throw new Error(`Failed to update snap.manifest.json: ${error.message}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
manifest: validatedManifest,
|
|
137
|
+
updated,
|
|
138
|
+
warnings,
|
|
139
|
+
errors
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function fixManifest(snapFiles, error) {
|
|
143
|
+
const { manifest, packageJson } = snapFiles;
|
|
144
|
+
const clonedFile = manifest.clone();
|
|
145
|
+
const manifestCopy = clonedFile.result;
|
|
146
|
+
switch(error.reason){
|
|
147
|
+
case _types.SnapValidationFailureReason.NameMismatch:
|
|
148
|
+
manifestCopy.source.location.npm.packageName = packageJson.result.name;
|
|
149
|
+
break;
|
|
150
|
+
case _types.SnapValidationFailureReason.VersionMismatch:
|
|
151
|
+
manifestCopy.version = packageJson.result.version;
|
|
152
|
+
break;
|
|
153
|
+
case _types.SnapValidationFailureReason.RepositoryMismatch:
|
|
154
|
+
manifestCopy.repository = packageJson.result.repository ? (0, _deepclone.deepClone)(packageJson.result.repository) : undefined;
|
|
155
|
+
break;
|
|
156
|
+
case _types.SnapValidationFailureReason.ShasumMismatch:
|
|
157
|
+
manifestCopy.source.shasum = (0, _snaps.getSnapChecksum)(snapFiles);
|
|
158
|
+
break;
|
|
159
|
+
/* istanbul ignore next */ default:
|
|
160
|
+
(0, _utils.assertExhaustive)(error.reason);
|
|
161
|
+
}
|
|
162
|
+
clonedFile.result = manifestCopy;
|
|
163
|
+
clonedFile.value = JSON.stringify(manifestCopy);
|
|
164
|
+
return clonedFile;
|
|
165
|
+
}
|
|
166
|
+
async function getSnapSourceCode(basePath, manifest, sourceCode) {
|
|
167
|
+
if (!(0, _utils.isPlainObject)(manifest)) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
const sourceFilePath = manifest.source?.location?.npm?.filePath;
|
|
171
|
+
if (!sourceFilePath) {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
if (sourceCode) {
|
|
175
|
+
return new _virtualfile.VirtualFile({
|
|
176
|
+
path: _path.default.join(basePath, sourceFilePath),
|
|
177
|
+
value: sourceCode
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
const virtualFile = await (0, _virtualfile.readVirtualFile)(_path.default.join(basePath, sourceFilePath), 'utf8');
|
|
182
|
+
return virtualFile;
|
|
183
|
+
} catch (error) {
|
|
184
|
+
throw new Error(`Failed to read Snap bundle file: ${error.message}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async function getSnapIcon(basePath, manifest) {
|
|
188
|
+
if (!(0, _utils.isPlainObject)(manifest)) {
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
const iconPath = manifest.source?.location?.npm?.iconPath;
|
|
192
|
+
if (!iconPath) {
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
const virtualFile = await (0, _virtualfile.readVirtualFile)(_path.default.join(basePath, iconPath), 'utf8');
|
|
197
|
+
return virtualFile;
|
|
198
|
+
} catch (error) {
|
|
199
|
+
throw new Error(`Failed to read Snap icon file: ${error.message}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function getWritableManifest(manifest) {
|
|
203
|
+
const { repository, ...remaining } = manifest;
|
|
204
|
+
const keys = Object.keys(repository ? {
|
|
205
|
+
...remaining,
|
|
206
|
+
repository
|
|
207
|
+
} : remaining);
|
|
208
|
+
const writableManifest = keys.sort((a, b)=>MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b]).reduce((result, key)=>({
|
|
209
|
+
...result,
|
|
210
|
+
[key]: manifest[key]
|
|
211
|
+
}), {});
|
|
212
|
+
return writableManifest;
|
|
213
|
+
}
|
|
214
|
+
function validateNpmSnapManifest({ manifest, packageJson, sourceCode, svgIcon }) {
|
|
215
|
+
const packageJsonName = packageJson.result.name;
|
|
216
|
+
const packageJsonVersion = packageJson.result.version;
|
|
217
|
+
const packageJsonRepository = packageJson.result.repository;
|
|
218
|
+
const manifestPackageName = manifest.result.source.location.npm.packageName;
|
|
219
|
+
const manifestPackageVersion = manifest.result.version;
|
|
220
|
+
const manifestRepository = manifest.result.repository;
|
|
221
|
+
if (packageJsonName !== manifestPackageName) {
|
|
222
|
+
throw new _snaps.ProgrammaticallyFixableSnapError(`"${_types.NpmSnapFileNames.Manifest}" npm package name ("${manifestPackageName}") does not match the "${_types.NpmSnapFileNames.PackageJson}" "name" field ("${packageJsonName}").`, _types.SnapValidationFailureReason.NameMismatch);
|
|
223
|
+
}
|
|
224
|
+
if (packageJsonVersion !== manifestPackageVersion) {
|
|
225
|
+
throw new _snaps.ProgrammaticallyFixableSnapError(`"${_types.NpmSnapFileNames.Manifest}" npm package version ("${manifestPackageVersion}") does not match the "${_types.NpmSnapFileNames.PackageJson}" "version" field ("${packageJsonVersion}").`, _types.SnapValidationFailureReason.VersionMismatch);
|
|
226
|
+
}
|
|
227
|
+
if (// The repository may be `undefined` in package.json but can only be defined
|
|
228
|
+
// or `null` in the Snap manifest due to TS@<4.4 issues.
|
|
229
|
+
(packageJsonRepository || manifestRepository) && !(0, _fastdeepequal.default)(packageJsonRepository, manifestRepository)) {
|
|
230
|
+
throw new _snaps.ProgrammaticallyFixableSnapError(`"${_types.NpmSnapFileNames.Manifest}" "repository" field does not match the "${_types.NpmSnapFileNames.PackageJson}" "repository" field.`, _types.SnapValidationFailureReason.RepositoryMismatch);
|
|
231
|
+
}
|
|
232
|
+
(0, _snaps.validateSnapShasum)({
|
|
233
|
+
manifest,
|
|
234
|
+
sourceCode,
|
|
235
|
+
svgIcon
|
|
236
|
+
}, `"${_types.NpmSnapFileNames.Manifest}" "shasum" field does not match computed shasum.`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
//# sourceMappingURL=manifest.js.map
|