@metamask/snaps-utils 0.34.1-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 +21 -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 +46 -21
- 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
package/dist/checksum.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checksumFiles = exports.checksum = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
const sha256_1 = require("@noble/hashes/sha256");
|
|
6
|
-
const VirtualFile_1 = require("./virtual-file/VirtualFile");
|
|
7
|
-
/**
|
|
8
|
-
* Calculates checksum for a single byte array.
|
|
9
|
-
*
|
|
10
|
-
* @param bytes - The byte array to calculate the checksum for.
|
|
11
|
-
* @returns A single sha-256 checksum.
|
|
12
|
-
*/
|
|
13
|
-
function checksum(bytes) {
|
|
14
|
-
const value = bytes instanceof VirtualFile_1.VirtualFile ? bytes.value : bytes;
|
|
15
|
-
return (0, sha256_1.sha256)(value);
|
|
16
|
-
}
|
|
17
|
-
exports.checksum = checksum;
|
|
18
|
-
/**
|
|
19
|
-
* Calculates checksum over multiple files in a reproducible way.
|
|
20
|
-
*
|
|
21
|
-
* 1. Sort all the files by their paths.
|
|
22
|
-
* 2. Calculate sha-256 checksum of each file separately.
|
|
23
|
-
* 3. Concatenate all the checksums into one buffer and sha-256 that buffer.
|
|
24
|
-
*
|
|
25
|
-
* The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.
|
|
26
|
-
*
|
|
27
|
-
* @param files - The files over which to calculate the checksum.
|
|
28
|
-
* @returns A single sha-256 checksum.
|
|
29
|
-
*/
|
|
30
|
-
function checksumFiles(files) {
|
|
31
|
-
return checksum((0, utils_1.concatBytes)([...files]
|
|
32
|
-
.sort((a, b) => {
|
|
33
|
-
(0, utils_1.assert)(a.path !== b.path, 'Tried to sort files with non-unique paths.');
|
|
34
|
-
if (a.path < b.path) {
|
|
35
|
-
return -1;
|
|
36
|
-
}
|
|
37
|
-
return 1;
|
|
38
|
-
})
|
|
39
|
-
.map((file) => checksum(file))));
|
|
40
|
-
}
|
|
41
|
-
exports.checksumFiles = checksumFiles;
|
|
42
|
-
//# sourceMappingURL=checksum.js.map
|
package/dist/checksum.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checksum.js","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AACtD,iDAA8C;AAE9C,4DAAyD;AAEzD;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,KAAwC;IAC/D,MAAM,KAAK,GAAG,KAAK,YAAY,yBAAW,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IACjE,OAAO,IAAA,eAAM,EAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAHD,4BAGC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,KAAoB;IAChD,OAAO,QAAQ,CACb,IAAA,mBAAW,EACT,CAAC,GAAG,KAAK,CAAC;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,IAAA,cAAM,EACJ,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EACjB,4CAA4C,CAC7C,CAAC;QACF,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE;YACnB,OAAO,CAAC,CAAC,CAAC;SACX;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CACjC,CACF,CAAC;AACJ,CAAC;AAjBD,sCAiBC","sourcesContent":["import { assert, concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { VirtualFile } from './virtual-file/VirtualFile';\n\n/**\n * Calculates checksum for a single byte array.\n *\n * @param bytes - The byte array to calculate the checksum for.\n * @returns A single sha-256 checksum.\n */\nexport function checksum(bytes: VirtualFile | Uint8Array | string): Uint8Array {\n const value = bytes instanceof VirtualFile ? bytes.value : bytes;\n return sha256(value);\n}\n\n/**\n * Calculates checksum over multiple files in a reproducible way.\n *\n * 1. Sort all the files by their paths.\n * 2. Calculate sha-256 checksum of each file separately.\n * 3. Concatenate all the checksums into one buffer and sha-256 that buffer.\n *\n * The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.\n *\n * @param files - The files over which to calculate the checksum.\n * @returns A single sha-256 checksum.\n */\nexport function checksumFiles(files: VirtualFile[]) {\n return checksum(\n concatBytes(\n [...files]\n .sort((a, b) => {\n assert(\n a.path !== b.path,\n 'Tried to sort files with non-unique paths.',\n );\n if (a.path < b.path) {\n return -1;\n }\n return 1;\n })\n .map((file) => checksum(file)),\n ),\n );\n}\n"]}
|
package/dist/cronjob.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCronjobSpecificationArray = exports.CronjobSpecificationArrayStruct = exports.isCronjobSpecification = exports.CronjobSpecificationStruct = exports.parseCronExpression = exports.CronExpressionStruct = exports.CronjobRpcRequestStruct = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
const cron_parser_1 = require("cron-parser");
|
|
6
|
-
const superstruct_1 = require("superstruct");
|
|
7
|
-
exports.CronjobRpcRequestStruct = (0, superstruct_1.assign)((0, superstruct_1.partial)((0, superstruct_1.pick)(utils_1.JsonRpcRequestStruct, ['id', 'jsonrpc'])), (0, superstruct_1.omit)(utils_1.JsonRpcRequestStruct, ['id', 'jsonrpc']));
|
|
8
|
-
exports.CronExpressionStruct = (0, superstruct_1.refine)((0, superstruct_1.coerce)((0, superstruct_1.string)(), (0, superstruct_1.object)({
|
|
9
|
-
minute: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
10
|
-
hour: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
11
|
-
dayOfMonth: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
12
|
-
month: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
13
|
-
dayOfWeek: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
14
|
-
}), (value) => `${value.minute ?? '*'} ${value.hour ?? '*'} ${value.dayOfMonth ?? '*'} ${value.month ?? '*'} ${value.dayOfWeek ?? '*'}`), 'CronExpression', (value) => {
|
|
15
|
-
try {
|
|
16
|
-
(0, cron_parser_1.parseExpression)(value);
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
/**
|
|
24
|
-
* Parses a cron expression.
|
|
25
|
-
*
|
|
26
|
-
* @param expression - Expression to parse.
|
|
27
|
-
* @returns A CronExpression class instance.
|
|
28
|
-
*/
|
|
29
|
-
function parseCronExpression(expression) {
|
|
30
|
-
const ensureStringExpression = (0, superstruct_1.create)(expression, exports.CronExpressionStruct);
|
|
31
|
-
return (0, cron_parser_1.parseExpression)(ensureStringExpression);
|
|
32
|
-
}
|
|
33
|
-
exports.parseCronExpression = parseCronExpression;
|
|
34
|
-
exports.CronjobSpecificationStruct = (0, superstruct_1.object)({
|
|
35
|
-
expression: exports.CronExpressionStruct,
|
|
36
|
-
request: exports.CronjobRpcRequestStruct,
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* Check if the given value is a {@link CronjobSpecification} object.
|
|
40
|
-
*
|
|
41
|
-
* @param value - The value to check.
|
|
42
|
-
* @returns Whether the value is a valid {@link CronjobSpecification} object.
|
|
43
|
-
*/
|
|
44
|
-
function isCronjobSpecification(value) {
|
|
45
|
-
try {
|
|
46
|
-
(0, superstruct_1.create)(value, exports.CronjobSpecificationStruct);
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.isCronjobSpecification = isCronjobSpecification;
|
|
54
|
-
exports.CronjobSpecificationArrayStruct = (0, superstruct_1.array)(exports.CronjobSpecificationStruct);
|
|
55
|
-
/**
|
|
56
|
-
* Check if the given value is an array of {@link CronjobSpecification} objects.
|
|
57
|
-
*
|
|
58
|
-
* @param value - The value to check.
|
|
59
|
-
* @returns Whether the value is a valid array of {@link CronjobSpecification} objects.
|
|
60
|
-
*/
|
|
61
|
-
function isCronjobSpecificationArray(value) {
|
|
62
|
-
try {
|
|
63
|
-
(0, superstruct_1.create)(value, exports.CronjobSpecificationArrayStruct);
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.isCronjobSpecificationArray = isCronjobSpecificationArray;
|
|
71
|
-
//# sourceMappingURL=cronjob.js.map
|
package/dist/cronjob.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cronjob.js","sourceRoot":"","sources":["../src/cronjob.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AACvD,6CAA8C;AAC9C,6CAaqB;AAER,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAC3C,IAAA,qBAAO,EAAC,IAAA,kBAAI,EAAC,4BAAoB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EACtD,IAAA,kBAAI,EAAC,4BAAoB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAC9C,CAAC;AAGW,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EACxC,IAAA,oBAAM,EACJ,IAAA,oBAAM,GAAE,EACR,IAAA,oBAAM,EAAC;IACL,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B,IAAI,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACxB,UAAU,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC9B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACzB,SAAS,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC9B,CAAC,EACF,CAAC,KAAK,EAAE,EAAE,CACR,GAAG,KAAK,CAAC,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,IAAI,IAAI,GAAG,IAAI,KAAK,CAAC,UAAU,IAAI,GAAG,IACpE,KAAK,CAAC,KAAK,IAAI,GACjB,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAC/B,EACD,gBAAgB,EAChB,CAAC,KAAK,EAAE,EAAE;IACR,IAAI;QACF,IAAA,6BAAe,EAAC,KAAK,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CACF,CAAC;AAIF;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,UAA2B;IAC7D,MAAM,sBAAsB,GAAG,IAAA,oBAAM,EAAC,UAAU,EAAE,4BAAoB,CAAC,CAAC;IACxE,OAAO,IAAA,6BAAe,EAAC,sBAAsB,CAAC,CAAC;AACjD,CAAC;AAHD,kDAGC;AAEY,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,UAAU,EAAE,4BAAoB;IAChC,OAAO,EAAE,+BAAuB;CACjC,CAAC,CAAC;AAGH;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,KAAc;IACnD,IAAI;QACF,IAAA,oBAAM,EAAC,KAAK,EAAE,kCAA0B,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,wDAOC;AAEY,QAAA,+BAA+B,GAAG,IAAA,mBAAK,EAClD,kCAA0B,CAC3B,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,2BAA2B,CAAC,KAAc;IACxD,IAAI;QACF,IAAA,oBAAM,EAAC,KAAK,EAAE,uCAA+B,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,kEAOC","sourcesContent":["import { JsonRpcRequestStruct } from '@metamask/utils';\nimport { parseExpression } from 'cron-parser';\nimport {\n array,\n assign,\n coerce,\n create,\n Infer,\n object,\n omit,\n optional,\n partial,\n pick,\n refine,\n string,\n} from 'superstruct';\n\nexport const CronjobRpcRequestStruct = assign(\n partial(pick(JsonRpcRequestStruct, ['id', 'jsonrpc'])),\n omit(JsonRpcRequestStruct, ['id', 'jsonrpc']),\n);\nexport type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;\n\nexport const CronExpressionStruct = refine(\n coerce(\n string(),\n object({\n minute: optional(string()),\n hour: optional(string()),\n dayOfMonth: optional(string()),\n month: optional(string()),\n dayOfWeek: optional(string()),\n }),\n (value) =>\n `${value.minute ?? '*'} ${value.hour ?? '*'} ${value.dayOfMonth ?? '*'} ${\n value.month ?? '*'\n } ${value.dayOfWeek ?? '*'}`,\n ),\n 'CronExpression',\n (value) => {\n try {\n parseExpression(value);\n return true;\n } catch {\n return false;\n }\n },\n);\n\nexport type CronExpression = Infer<typeof CronExpressionStruct>;\n\n/**\n * Parses a cron expression.\n *\n * @param expression - Expression to parse.\n * @returns A CronExpression class instance.\n */\nexport function parseCronExpression(expression: string | object) {\n const ensureStringExpression = create(expression, CronExpressionStruct);\n return parseExpression(ensureStringExpression);\n}\n\nexport const CronjobSpecificationStruct = object({\n expression: CronExpressionStruct,\n request: CronjobRpcRequestStruct,\n});\nexport type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;\n\n/**\n * Check if the given value is a {@link CronjobSpecification} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link CronjobSpecification} object.\n */\nexport function isCronjobSpecification(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationStruct);\n return true;\n } catch {\n return false;\n }\n}\n\nexport const CronjobSpecificationArrayStruct = array(\n CronjobSpecificationStruct,\n);\n\n/**\n * Check if the given value is an array of {@link CronjobSpecification} objects.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid array of {@link CronjobSpecification} objects.\n */\nexport function isCronjobSpecificationArray(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationArrayStruct);\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
package/dist/deep-clone.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.deepClone = void 0;
|
|
7
|
-
const rfdc_1 = __importDefault(require("rfdc"));
|
|
8
|
-
exports.deepClone = (0, rfdc_1.default)({ proto: false, circles: false });
|
|
9
|
-
//# sourceMappingURL=deep-clone.js.map
|
package/dist/deep-clone.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deep-clone.js","sourceRoot":"","sources":["../src/deep-clone.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAEX,QAAA,SAAS,GAAG,IAAA,cAAI,EAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC","sourcesContent":["import rfdc from 'rfdc';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default-endowments.js","sourceRoot":"","sources":["../src/default-endowments.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,kBAAkB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACjE,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,MAAM;IACN,MAAM;IACN,YAAY;IACZ,cAAc;IACd,cAAc;IACd,aAAa;IACb,aAAa;IACb,KAAK;IACL,aAAa;IACb,eAAe;IACf,WAAW;IACX,YAAY;IACZ,mBAAmB;IACnB,YAAY;IACZ,aAAa;IACb,YAAY;IACZ,aAAa;IACb,cAAc;IACd,cAAc;IACd,eAAe;IACf,gBAAgB;IAChB,UAAU;IACV,aAAa;IACb,qFAAqF;IACrF,wDAAwD;IACxD,6DAA6D;IAC7D,iBAAiB;IACjB,aAAa;CACd,CAAC,CAAC","sourcesContent":["/**\n * Global JavaScript APIs exposed by default to all snaps.\n */\nexport const DEFAULT_ENDOWMENTS: readonly string[] = Object.freeze([\n 'atob',\n 'btoa',\n 'BigInt',\n 'console',\n 'crypto',\n 'Date',\n 'Math',\n 'setTimeout',\n 'clearTimeout',\n 'SubtleCrypto',\n 'TextDecoder',\n 'TextEncoder',\n 'URL',\n 'setInterval',\n 'clearInterval',\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array',\n 'DataView',\n 'ArrayBuffer',\n // Used by fetch, but also as API for some packages that don't do network connections\n // https://github.com/MetaMask/snaps-monorepo/issues/662\n // https://github.com/MetaMask/snaps-monorepo/discussions/678\n 'AbortController',\n 'AbortSignal',\n]);\n"]}
|
package/dist/entropy.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STATE_ENCRYPTION_MAGIC_VALUE = exports.SIP_6_MAGIC_VALUE = void 0;
|
|
4
|
-
// 0xd36e6170 - 0x80000000
|
|
5
|
-
exports.SIP_6_MAGIC_VALUE = `1399742832'`;
|
|
6
|
-
// `${bytesToNumber(keccak256('Snaps state encryption').slice(0, 4))}'`
|
|
7
|
-
exports.STATE_ENCRYPTION_MAGIC_VALUE = `572232532'`;
|
|
8
|
-
//# sourceMappingURL=entropy.js.map
|
package/dist/entropy.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entropy.js","sourceRoot":"","sources":["../src/entropy.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AACb,QAAA,iBAAiB,GAAG,aAA6B,CAAC;AAE/D,uEAAuE;AAC1D,QAAA,4BAA4B,GAAG,YAA4B,CAAC","sourcesContent":["// 0xd36e6170 - 0x80000000\nexport const SIP_6_MAGIC_VALUE = `1399742832'` as `${number}'`;\n\n// `${bytesToNumber(keccak256('Snaps state encryption').slice(0, 4))}'`\nexport const STATE_ENCRYPTION_MAGIC_VALUE = `572232532'` as `${number}'`;\n\nexport type MagicValue =\n | typeof SIP_6_MAGIC_VALUE\n | typeof STATE_ENCRYPTION_MAGIC_VALUE;\n"]}
|
package/dist/eval-worker.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,wBAAsB;AAEtB,2BAAkC;AAElC,iCAAgD;AAChD,mCAAyD;AAIzD,QAAQ,CAAC;IACP,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;IAExB,uEAAuE;IACvE,oDAAoD;IACpD,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;QACjC,CAAC,CAAC;YACE,YAAY,EAAE,QAAQ;SACvB;QACH,CAAC,CAAC,EAAE,CAAC;CACR,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG,IAAA,6BAAsB,GAAE,CAAC;IAC5C,OAAO;QACL,GAAG,UAAU;QACb,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,UAAU;KACjB,CAAC;AACJ,CAAC;AAED,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,MAAM,UAAU,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEtD,IAAI,WAAW,CAAC;IACd,GAAG,iBAAiB,EAAE;IACtB,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,UAAU,CAAC,OAAO;CAC5B,CAAC,CAAC,QAAQ,CAAC,IAAA,iBAAY,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAC3D,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,yBAAiB,CAAC,QAAQ,CAAC,UAAyB,CAAC,CACvE,CAAC;AAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;IAC7B,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,mCAAmC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CAC9E;AAED,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B","sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\n\nimport { generateMockEndowments } from './mock';\nimport { HandlerType, SNAP_EXPORT_NAMES } from './types';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n\n // TODO: See if there's an easier way to do this. This file is ran in a\n // separate process, so we can't mock SES with Jest.\n ...(process.env.NODE_ENV === 'test'\n ? {\n domainTaming: 'unsafe',\n }\n : {}),\n});\n\n/**\n * Get mock endowments that don't do anything. This is useful for running the\n * eval, for snaps that try to communicate with the extension on initialisation,\n * for example.\n *\n * @returns The mock endowments.\n */\nfunction getMockEndowments() {\n const endowments = generateMockEndowments();\n return {\n ...endowments,\n window: endowments,\n self: endowments,\n };\n}\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nnew Compartment({\n ...getMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n}).evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n // eslint-disable-next-line no-console\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\nsetTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n"]}
|
package/dist/eval.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evalBundle = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const fs_1 = require("./fs");
|
|
7
|
-
/**
|
|
8
|
-
* Spawn a new process to run the provided bundle in.
|
|
9
|
-
*
|
|
10
|
-
* @param bundlePath - The path to the bundle to run.
|
|
11
|
-
* @returns `null` if the worker ran successfully.
|
|
12
|
-
* @throws If the worker failed to run successfully.
|
|
13
|
-
*/
|
|
14
|
-
async function evalBundle(bundlePath) {
|
|
15
|
-
await (0, fs_1.validateFilePath)(bundlePath);
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
const worker = (0, child_process_1.fork)((0, path_1.join)(__dirname, 'eval-worker.js'), [bundlePath]);
|
|
18
|
-
worker.on('exit', (exitCode) => {
|
|
19
|
-
if (exitCode === 0) {
|
|
20
|
-
return resolve(null);
|
|
21
|
-
}
|
|
22
|
-
return reject(new Error(`Process exited with non-zero exit code: ${exitCode}`));
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
exports.evalBundle = evalBundle;
|
|
27
|
-
//# sourceMappingURL=eval.js.map
|
package/dist/eval.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eval.js","sourceRoot":"","sources":["../src/eval.ts"],"names":[],"mappings":";;;AAAA,iDAAqC;AACrC,+BAA4B;AAE5B,6BAAwC;AAExC;;;;;;GAMG;AACI,KAAK,UAAU,UAAU,CAAC,UAAkB;IACjD,MAAM,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;IAEnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,IAAA,oBAAI,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,gBAAgB,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;QAErE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YACrC,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;aACtB;YAED,OAAO,MAAM,CACX,IAAI,KAAK,CAAC,2CAA2C,QAAQ,EAAE,CAAC,CACjE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,gCAgBC","sourcesContent":["import { fork } from 'child_process';\nimport { join } from 'path';\n\nimport { validateFilePath } from './fs';\n\n/**\n * Spawn a new process to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport async function evalBundle(bundlePath: string): Promise<null> {\n await validateFilePath(bundlePath);\n\n return new Promise((resolve, reject) => {\n const worker = fork(join(__dirname, 'eval-worker.js'), [bundlePath]);\n\n worker.on('exit', (exitCode: number) => {\n if (exitCode === 0) {\n return resolve(null);\n }\n\n return reject(\n new Error(`Process exited with non-zero exit code: ${exitCode}`),\n );\n });\n });\n}\n"]}
|
package/dist/fs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":";;;;;;AACA,2BAAoC;AACpC,4CAAoB;AACpB,gDAA6B;AAE7B,iDAA8D;AAE9D;;;;;;;GAOG;AACI,KAAK,UAAU,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CAAC,IAAI,CAAC,YAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;IACvD,MAAM,aAAE,CAAC,KAAK,CAAC,cAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,MAAM,aAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC3C,IAAI;QACF,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC;KACpB;YAAS;QACR,IAAI,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE;YAC1B,MAAM,aAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;SAC3B;KACF;AACH,CAAC;AAfD,4CAeC","sourcesContent":["import { Json } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport os from 'os';\nimport pathUtils from 'path';\n\nimport { readVirtualFile, VirtualFile } from './virtual-file';\n\n/**\n * Checks whether the given path string resolves to an existing directory, and\n * optionally creates the directory if it doesn't exist.\n *\n * @param pathString - The path string to check.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns Whether the given path is an existing directory.\n */\nexport async function isDirectory(\n pathString: string,\n createDir: boolean,\n): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isDirectory();\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (!createDir) {\n return false;\n }\n\n await fs.mkdir(pathString, { recursive: true });\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * Checks whether the given path string resolves to an existing file.\n *\n * @param pathString - The path string to check.\n * @returns Whether the given path is an existing file.\n */\nexport async function isFile(pathString: string): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Reads a `.json` file, parses its contents, and returns them.\n *\n * @param pathString - The path to the JSON file.\n * @returns The parsed contents of the JSON file.\n */\nexport async function readJsonFile<Type extends Json = Json>(\n pathString: string,\n): Promise<VirtualFile<Type>> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n let file;\n try {\n file = await readVirtualFile(pathString, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${pathString}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n file.result = JSON.parse(file.toString());\n return file as VirtualFile<Type>;\n}\n\n/**\n * Gets the complete out file path from an output file name and parent\n * directory path.\n *\n * @param outDir - The path to the out file's parent directory.\n * @param outFileName - The out file's name.\n * @returns The complete path to the out file.\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a `.js` file name.\n * Throws on validation failure.\n *\n * @param filename - The file name to validate.\n * @returns `true` if validation succeeded.\n * @throws If the file name is invalid.\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n pathUtils.basename(filename) !== filename\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path. Throws on validation failure.\n *\n * @param filePath - The file path to validate.\n * @returns `true` if validation succeeded.\n * @throws If the path does not resolve to a file.\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path. Throws on validation failure.\n *\n * @param dirPath - The directory path to validate.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns `true` if validation succeeded or the directory was created.\n * @throws If the directory does not exist or could not be created.\n */\nexport async function validateDirPath(\n dirPath: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirPath, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirPath}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n\n/**\n * Creates a temporary file with a given name and content, writes it to disk and calls the provided function.\n * This function handles deletion of the temporary file after usage.\n *\n * @param fileName - The name of the temporary file.\n * @param fileContents - The content of the temporary file.\n * @param fn - The callback function to call when the temporary file has been created.\n */\nexport async function useTemporaryFile(\n fileName: string,\n fileContents: string,\n fn: (path: string) => Promise<unknown>,\n): Promise<void> {\n const filePath = pathUtils.join(os.tmpdir(), fileName);\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, fileContents);\n try {\n await fn(filePath);\n } finally {\n if (await isFile(filePath)) {\n await fs.unlink(filePath);\n }\n }\n}\n"]}
|
package/dist/handlers.js
DELETED
package/dist/handlers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"","sourcesContent":["import { Component } from '@metamask/snaps-ui';\nimport { Json, JsonRpcRequest } from '@metamask/utils';\n\nimport { AccountId, ChainId, RequestArguments } from './namespace';\n\n/**\n * The `onRpcRequest` handler. This is called whenever a JSON-RPC request is\n * made to the snap.\n *\n * @param args - The request arguments.\n * @param args.origin - The origin of the request. This can be the ID of another\n * snap, or the URL of a dapp.\n * @param args.request - The JSON-RPC request sent to the snap.\n * @returns The JSON-RPC response. This must be a JSON-serializable value.\n */\nexport type OnRpcRequestHandler<\n Params extends Json[] | Record<string, Json> | undefined =\n | Json[]\n | Record<string, Json>\n | undefined,\n> = (args: {\n origin: string;\n request: JsonRpcRequest<Params>;\n}) => Promise<unknown>;\n\n/**\n * The response from a snap's `onTransaction` handler.\n *\n * @property content - A custom UI component, that will be shown in MetaMask. Can be created using `@metamask/snaps-ui`.\n *\n * If the snap has no insights about the transaction, this should be `null`.\n */\nexport type OnTransactionResponse = {\n content: Component | null;\n};\n\n/**\n * The `onTransaction` handler. This is called whenever a transaction is\n * submitted to the snap. It can return insights about the transaction, which\n * will be displayed to the user.\n *\n * @param args - The request arguments.\n * @param args.transaction - The transaction object.\n * @param args.chainId - The CAIP-2 chain ID of the network the transaction is\n * being submitted to.\n * @param args.transactionOrigin - The origin of the transaction. This is the\n * URL of the dapp that submitted the transaction.\n * @returns Insights about the transaction. See {@link OnTransactionResponse}.\n */\n// TODO: Improve type.\nexport type OnTransactionHandler = (args: {\n transaction: { [key: string]: Json };\n chainId: string;\n transactionOrigin?: string;\n}) => Promise<OnTransactionResponse>;\n\n/**\n * The `onCronjob` handler. This is called on a regular interval, as defined by\n * the snap's manifest.\n *\n * @param args - The request arguments.\n * @param args.request - The JSON-RPC request sent to the snap.\n */\nexport type OnCronjobHandler<\n Params extends Json[] | Record<string, Json> | undefined =\n | Json[]\n | Record<string, Json>\n | undefined,\n> = (args: { request: JsonRpcRequest<Params> }) => Promise<unknown>;\n\n/**\n * A request sent to the `handleRequest` handler of a snap keyring.\n *\n * @property chainId - The CAIP-2 chain ID of the network the request is being\n * made to.\n * @property origin - The origin of the request. This can be the ID of another\n * snap, or the URL of a dapp.\n */\nexport type KeyringRequest = {\n chainId: ChainId;\n origin: string;\n};\n\n/**\n * A keyring event, which consists of a {@link KeyringRequest}, combined with\n * the name of the event.\n */\nexport type KeyringEvent = KeyringRequest & { eventName: string };\n\n/**\n * A snap keyring object, which can be exported as `keyring` in a snap.\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface SnapKeyring {\n getAccounts(): Promise<AccountId[]>;\n handleRequest(\n data: KeyringRequest & {\n request: RequestArguments;\n },\n ): Promise<Json>;\n on(data: KeyringEvent, listener: (...args: Json[]) => void): void;\n off(data: KeyringEvent): void;\n\n addAccount?(chainId: ChainId): Promise<AccountId>;\n removeAccount?(accountId: AccountId): Promise<void>;\n\n importAccount?(chainId: ChainId, data: Json): Promise<AccountId>;\n exportAccount?(accountId: AccountId): Promise<Json>;\n}\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n onRpcRequest?: OnRpcRequestHandler;\n onTransaction?: OnTransactionHandler;\n onCronjob?: OnCronjobHandler;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports & {\n keyring?: SnapKeyring;\n};\n"]}
|
package/dist/icon.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assertIsSnapIcon = exports.SVG_MAX_BYTE_SIZE_TEXT = exports.SVG_MAX_BYTE_SIZE = void 0;
|
|
7
|
-
const utils_1 = require("@metamask/utils");
|
|
8
|
-
const is_svg_1 = __importDefault(require("is-svg"));
|
|
9
|
-
exports.SVG_MAX_BYTE_SIZE = 100000;
|
|
10
|
-
exports.SVG_MAX_BYTE_SIZE_TEXT = `${Math.floor(exports.SVG_MAX_BYTE_SIZE / 1000)}kb`;
|
|
11
|
-
const assertIsSnapIcon = (icon) => {
|
|
12
|
-
(0, utils_1.assert)(icon.path.endsWith('.svg'), 'Expected snap icon to end in ".svg".');
|
|
13
|
-
(0, utils_1.assert)(Buffer.byteLength(icon.value, 'utf8') <= exports.SVG_MAX_BYTE_SIZE, `The specified SVG icon exceeds the maximum size of ${exports.SVG_MAX_BYTE_SIZE_TEXT}.`);
|
|
14
|
-
(0, utils_1.assert)((0, is_svg_1.default)(icon.toString()), 'Snap icon must be a valid SVG.');
|
|
15
|
-
};
|
|
16
|
-
exports.assertIsSnapIcon = assertIsSnapIcon;
|
|
17
|
-
//# sourceMappingURL=icon.js.map
|
package/dist/icon.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"icon.js","sourceRoot":"","sources":["../src/icon.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAyC;AACzC,oDAA2B;AAId,QAAA,iBAAiB,GAAG,MAAO,CAAC;AAC5B,QAAA,sBAAsB,GAAG,GAAG,IAAI,CAAC,KAAK,CACjD,yBAAiB,GAAG,IAAI,CACzB,IAAI,CAAC;AAEC,MAAM,gBAAgB,GAAG,CAAC,IAAiB,EAAE,EAAE;IACpD,IAAA,cAAM,EAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,sCAAsC,CAAC,CAAC;IAE3E,IAAA,cAAM,EACJ,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,yBAAiB,EAC1D,sDAAsD,8BAAsB,GAAG,CAChF,CAAC;IAEF,IAAA,cAAM,EAAC,IAAA,gBAAK,EAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,gCAAgC,CAAC,CAAC;AACnE,CAAC,CAAC;AATW,QAAA,gBAAgB,oBAS3B","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"]}
|
package/dist/iframe.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.js","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,GAAW,EACX,EAAU,EACV,OAAO,GAAG,IAAI;IAEd,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;QAEnD,IAAI,OAAO,EAAE;YACX,gGAAgG;YAChG,kEAAkE;YAClE,WAAW;YACX,qFAAqF;YACrF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;SACjD;QAED,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YACnC,IAAI,MAAM,CAAC,aAAa,EAAE;gBACxB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;aAC/B;iBAAM;gBACL,qEAAqE;gBACrE,mBAAmB;gBACnB,MAAM,CACJ,IAAI,KAAK,CACP,qDAAqD,EAAE,IAAI,CAC5D,CACF,CAAC;aACH;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhDD,oCAgDC","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"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const iframe_1 = require("./iframe");
|
|
4
|
-
const IFRAME_URL = `http://localhost:4569`;
|
|
5
|
-
const MOCK_JOB_ID = 'job-id';
|
|
6
|
-
describe('createWindow', () => {
|
|
7
|
-
it('creates an iframe window with the provided job ID as the iframe ID', async () => {
|
|
8
|
-
const window = await (0, iframe_1.createWindow)(IFRAME_URL, MOCK_JOB_ID);
|
|
9
|
-
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
10
|
-
expect(iframe).toBeDefined();
|
|
11
|
-
expect(iframe.contentWindow).toBe(window);
|
|
12
|
-
expect(iframe.id).toBe(MOCK_JOB_ID);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
//# sourceMappingURL=iframe.test.browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.test.browser.js","sourceRoot":"","sources":["../src/iframe.test.browser.ts"],"names":[],"mappings":";;AAAA,qCAAwC;AAExC,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,oEAAoE,EAAE,KAAK,IAAI,EAAE;QAClF,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAY,EAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAC3D,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAsB,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { createWindow } from './iframe';\n\nconst IFRAME_URL = `http://localhost:4569`;\n\nconst MOCK_JOB_ID = 'job-id';\n\ndescribe('createWindow', () => {\n it('creates an iframe window with the provided job ID as the iframe ID', async () => {\n const window = await createWindow(IFRAME_URL, MOCK_JOB_ID);\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.contentWindow).toBe(window);\n expect(iframe.id).toBe(MOCK_JOB_ID);\n });\n});\n"]}
|
package/dist/index.browser.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./caveats"), exports);
|
|
18
|
-
__exportStar(require("./checksum"), exports);
|
|
19
|
-
__exportStar(require("./cronjob"), exports);
|
|
20
|
-
__exportStar(require("./deep-clone"), exports);
|
|
21
|
-
__exportStar(require("./default-endowments"), exports);
|
|
22
|
-
__exportStar(require("./entropy"), exports);
|
|
23
|
-
__exportStar(require("./handlers"), exports);
|
|
24
|
-
__exportStar(require("./iframe"), exports);
|
|
25
|
-
__exportStar(require("./json-rpc"), exports);
|
|
26
|
-
__exportStar(require("./logging"), exports);
|
|
27
|
-
__exportStar(require("./manifest/index.browser"), exports);
|
|
28
|
-
__exportStar(require("./namespace"), exports);
|
|
29
|
-
__exportStar(require("./notification"), exports);
|
|
30
|
-
__exportStar(require("./path"), exports);
|
|
31
|
-
__exportStar(require("./snaps"), exports);
|
|
32
|
-
__exportStar(require("./types"), exports);
|
|
33
|
-
__exportStar(require("./validation"), exports);
|
|
34
|
-
__exportStar(require("./versions"), exports);
|
|
35
|
-
__exportStar(require("./virtual-file/index.browser"), exports);
|
|
36
|
-
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B;AAC1B,+CAA6B;AAC7B,uDAAqC;AACrC,4CAA0B;AAC1B,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,4CAA0B;AAC1B,2DAAyC;AACzC,8CAA4B;AAC5B,iDAA+B;AAC/B,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB;AACxB,+CAA6B;AAC7B,6CAA2B;AAC3B,+DAA6C","sourcesContent":["export * from './caveats';\nexport * from './checksum';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './notification';\nexport * from './path';\nexport * from './snaps';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"]}
|
package/dist/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./caveats"), exports);
|
|
18
|
-
__exportStar(require("./cronjob"), exports);
|
|
19
|
-
__exportStar(require("./checksum"), exports);
|
|
20
|
-
__exportStar(require("./deep-clone"), exports);
|
|
21
|
-
__exportStar(require("./default-endowments"), exports);
|
|
22
|
-
__exportStar(require("./entropy"), exports);
|
|
23
|
-
__exportStar(require("./eval"), exports);
|
|
24
|
-
__exportStar(require("./fs"), exports);
|
|
25
|
-
__exportStar(require("./handlers"), exports);
|
|
26
|
-
__exportStar(require("./iframe"), exports);
|
|
27
|
-
__exportStar(require("./json-rpc"), exports);
|
|
28
|
-
__exportStar(require("./logging"), exports);
|
|
29
|
-
__exportStar(require("./manifest"), exports);
|
|
30
|
-
__exportStar(require("./mock"), exports);
|
|
31
|
-
__exportStar(require("./namespace"), exports);
|
|
32
|
-
__exportStar(require("./notification"), exports);
|
|
33
|
-
__exportStar(require("./npm"), exports);
|
|
34
|
-
__exportStar(require("./path"), exports);
|
|
35
|
-
__exportStar(require("./post-process"), exports);
|
|
36
|
-
__exportStar(require("./snaps"), exports);
|
|
37
|
-
__exportStar(require("./types"), exports);
|
|
38
|
-
__exportStar(require("./validation"), exports);
|
|
39
|
-
__exportStar(require("./versions"), exports);
|
|
40
|
-
__exportStar(require("./virtual-file"), exports);
|
|
41
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B;AAC3B,+CAA6B;AAC7B,uDAAqC;AACrC,4CAA0B;AAC1B,yCAAuB;AACvB,uCAAqB;AACrB,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,4CAA0B;AAC1B,6CAA2B;AAC3B,yCAAuB;AACvB,8CAA4B;AAC5B,iDAA+B;AAC/B,wCAAsB;AACtB,yCAAuB;AACvB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,+CAA6B;AAC7B,6CAA2B;AAC3B,iDAA+B","sourcesContent":["export * from './caveats';\nexport * from './cronjob';\nexport * from './checksum';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './eval';\nexport * from './fs';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './notification';\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"]}
|
package/dist/json-rpc.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertIsJsonRpcSuccess = exports.assertIsRpcOrigins = exports.RpcOriginsStruct = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
const superstruct_1 = require("superstruct");
|
|
6
|
-
exports.RpcOriginsStruct = (0, superstruct_1.refine)((0, superstruct_1.object)({
|
|
7
|
-
dapps: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
8
|
-
snaps: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
9
|
-
}), 'RPC origins', (value) => {
|
|
10
|
-
if (!Object.values(value).some(Boolean)) {
|
|
11
|
-
throw new Error('Must specify at least one JSON-RPC origin');
|
|
12
|
-
}
|
|
13
|
-
return true;
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Asserts that the given value is a valid {@link RpcOrigins} object.
|
|
17
|
-
*
|
|
18
|
-
* @param value - The value to assert.
|
|
19
|
-
* @param ErrorWrapper - An optional error wrapper to use. Defaults to
|
|
20
|
-
* {@link AssertionError}.
|
|
21
|
-
* @throws If the value is not a valid {@link RpcOrigins} object.
|
|
22
|
-
*/
|
|
23
|
-
function assertIsRpcOrigins(value,
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
25
|
-
ErrorWrapper) {
|
|
26
|
-
(0, utils_1.assertStruct)(value, exports.RpcOriginsStruct, 'Invalid JSON-RPC origins', ErrorWrapper);
|
|
27
|
-
}
|
|
28
|
-
exports.assertIsRpcOrigins = assertIsRpcOrigins;
|
|
29
|
-
/**
|
|
30
|
-
* Assert that the given value is a successful JSON-RPC response. If the value
|
|
31
|
-
* is not a success response, an error is thrown. If the value is an JSON-RPC
|
|
32
|
-
* error, the error message is included in the thrown error.
|
|
33
|
-
*
|
|
34
|
-
* @param value - The value to check.
|
|
35
|
-
* @throws If the value is not a JSON-RPC success response.
|
|
36
|
-
*/
|
|
37
|
-
function assertIsJsonRpcSuccess(value) {
|
|
38
|
-
if (!(0, utils_1.isJsonRpcSuccess)(value)) {
|
|
39
|
-
if ((0, utils_1.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
|
-
exports.assertIsJsonRpcSuccess = assertIsJsonRpcSuccess;
|
|
46
|
-
//# sourceMappingURL=json-rpc.js.map
|
package/dist/json-rpc.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.js","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":";;;AAAA,2CAOyB;AACzB,6CAAuE;AAE1D,QAAA,gBAAgB,GAAG,IAAA,oBAAM,EACpC,IAAA,oBAAM,EAAC;IACL,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC1B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;CAC3B,CAAC,EACF,aAAa,EACb,CAAC,KAAK,EAAE,EAAE;IACR,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAC9D;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAIF;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,KAAc;AACd,gEAAgE;AAChE,YAAwC;IAExC,IAAA,oBAAY,EACV,KAAK,EACL,wBAAgB,EAChB,0BAA0B,EAC1B,YAAY,CACb,CAAC;AACJ,CAAC;AAXD,gDAWC;AAED;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CACpC,KAAc;IAEd,IAAI,CAAC,IAAA,wBAAgB,EAAC,KAAK,CAAC,EAAE;QAC5B,IAAI,IAAA,wBAAgB,EAAC,KAAK,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;SACpE;QAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;KAC/C;AACH,CAAC;AAVD,wDAUC","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"]}
|
package/dist/logging.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAEtD,6EAA6E;AAC7E,6BAA6B;AAChB,QAAA,WAAW,GAAG,IAAA,2BAAmB,EAAC,OAAO,CAAC,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,SAAgB,OAAO,CAAC,OAAe,EAAE,GAAG,cAAyB;IACnE,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;AAC1C,CAAC;AAHD,0BAGC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,QAAQ,CAAC,KAAc,EAAE,GAAG,cAAyB;IACnE,sCAAsC;IACtC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,cAAc,CAAC,CAAC;AAC1C,CAAC;AAHD,4BAGC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,UAAU,CACxB,OAAe,EACf,GAAG,cAAyB;IAE5B,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;AAC3C,CAAC;AAND,gCAMC","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"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./validation"), exports);
|
|
18
|
-
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../src/manifest/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B","sourcesContent":["export * from './validation';\n"]}
|
package/dist/manifest/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./manifest"), exports);
|
|
18
|
-
__exportStar(require("./validation"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/manifest/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B","sourcesContent":["export * from './manifest';\nexport * from './validation';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAgF;AAChF,sEAAwC;AACxC,2BAAoC;AACpC,gDAA6B;AAE7B,8CAA0C;AAC1C,8BAAqC;AACrC,gCAAyC;AACzC,oCAIkB;AAClB,oCAKkB;AAClB,kDAA+D;AAG/D,MAAM,mBAAmB,GAAuC;IAC9D,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;IACf,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,CAAC;IACT,kBAAkB,EAAE,CAAC;IACrB,eAAe,EAAE,CAAC;CACnB,CAAC;AAuBF;;;;;;;;;;GAUG;AACI,KAAK,UAAU,aAAa,CACjC,QAAgB,EAChB,aAAa,GAAG,IAAI,EACpB,UAAmB;IAEnB,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,MAAM,YAAY,GA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AAC;KACH;IAED,IAAA,0BAAkB,EAChB,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,EACjC,IAAI,wBAAgB,CAAC,QAAQ,kDAAkD,CAChF,CAAC;AACJ,CAAC;AA5CD,0DA4CC","sourcesContent":["import { Json, assertExhaustive, assert, isPlainObject } from '@metamask/utils';\nimport deepEqual from 'fast-deep-equal';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { validateNpmSnap } from '../npm';\nimport {\n getSnapChecksum,\n ProgrammaticallyFixableSnapError,\n validateSnapShasum,\n} from '../snaps';\nimport {\n NpmSnapFileNames,\n SnapFiles,\n SnapValidationFailureReason,\n UnvalidatedSnapFiles,\n} from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file';\nimport { SnapManifest } from './validation';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialPermissions: 7,\n manifestVersion: 8,\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was updated.\n * @property warnings - An array of warnings that were encountered during\n * processing of the manifest files. These warnings are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n * @property errors - An array of errors that were encountered during\n * processing of the manifest files. These errors are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n */\nexport type CheckManifestResult = {\n manifest: SnapManifest;\n updated?: boolean;\n warnings: string[];\n errors: string[];\n};\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param writeManifest - Whether to write the fixed manifest to disk.\n * @param sourceCode - The source code of the Snap.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n writeManifest = true,\n sourceCode?: string,\n): Promise<CheckManifestResult> {\n const warnings: string[] = [];\n const errors: string[] = [];\n\n let updated = false;\n\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n };\n\n let manifest: VirtualFile<SnapManifest> | undefined;\n try {\n ({ manifest } = validateNpmSnap(snapFiles));\n } catch (error) {\n if (error instanceof ProgrammaticallyFixableSnapError) {\n errors.push(error.message);\n\n // If we get here, the files at least have the correct shape.\n const partiallyValidatedFiles = snapFiles as SnapFiles;\n\n let isInvalid = true;\n let currentError = error;\n const maxAttempts = Object.keys(SnapValidationFailureReason).length;\n\n // Attempt to fix all fixable validation failure reasons. All such reasons\n // are enumerated by the `SnapValidationFailureReason` enum, so we only\n // attempt to fix the manifest the same amount of times as there are\n // reasons in the enum.\n for (let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++) {\n manifest = fixManifest(\n manifest\n ? { ...partiallyValidatedFiles, manifest }\n : partiallyValidatedFiles,\n currentError,\n );\n\n try {\n validateNpmSnapManifest({ ...partiallyValidatedFiles, manifest });\n\n isInvalid = false;\n } catch (nextValidationError) {\n currentError = nextValidationError;\n /* istanbul ignore next: this should be impossible */\n if (\n !(\n nextValidationError instanceof ProgrammaticallyFixableSnapError\n ) ||\n (attempts === maxAttempts && !isInvalid)\n ) {\n throw new Error(\n `Internal error: Failed to fix manifest. This is a bug, please report it. Reason:\\n${error.message}`,\n );\n }\n\n errors.push(currentError.message);\n }\n }\n\n updated = true;\n } else {\n throw error;\n }\n }\n\n // TypeScript assumes `manifest` can still be undefined, that is not the case.\n // But we assert to keep TypeScript happy.\n assert(manifest);\n\n const validatedManifest = manifest.result;\n\n // Check presence of recommended keys\n const recommendedFields = ['repository'] as const;\n\n const missingRecommendedFields = recommendedFields.filter(\n (key) => !validatedManifest[key],\n );\n\n if (missingRecommendedFields.length > 0) {\n warnings.push(\n `Missing recommended package.json properties:\\n${missingRecommendedFields.reduce(\n (allMissing, currentField) => {\n return `${allMissing}\\t${currentField}\\n`;\n },\n '',\n )}`,\n );\n }\n\n if (writeManifest) {\n try {\n const newManifest = `${JSON.stringify(\n getWritableManifest(validatedManifest),\n null,\n 2,\n )}\\n`;\n\n if (updated || newManifest !== manifestFile.value) {\n await fs.writeFile(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n newManifest,\n );\n }\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(`Failed to update snap.manifest.json: ${error.message}`);\n }\n }\n\n return { manifest: validatedManifest, updated, warnings, errors };\n}\n\n/**\n * Given the relevant Snap files (manifest, `package.json`, and bundle) and a\n * Snap manifest validation error, fixes the fault in the manifest that caused\n * the error.\n *\n * @param snapFiles - The contents of all Snap files.\n * @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.\n * @returns A copy of the manifest file where the cause of the error is fixed.\n */\nexport function fixManifest(\n snapFiles: SnapFiles,\n error: ProgrammaticallyFixableSnapError,\n): VirtualFile<SnapManifest> {\n const { manifest, packageJson } = snapFiles;\n const clonedFile = manifest.clone();\n const manifestCopy = clonedFile.result;\n\n switch (error.reason) {\n case SnapValidationFailureReason.NameMismatch:\n manifestCopy.source.location.npm.packageName = packageJson.result.name;\n break;\n\n case SnapValidationFailureReason.VersionMismatch:\n manifestCopy.version = packageJson.result.version;\n break;\n\n case SnapValidationFailureReason.RepositoryMismatch:\n manifestCopy.repository = packageJson.result.repository\n ? deepClone(packageJson.result.repository)\n : undefined;\n break;\n\n case SnapValidationFailureReason.ShasumMismatch:\n manifestCopy.source.shasum = getSnapChecksum(snapFiles);\n break;\n\n /* istanbul ignore next */\n default:\n assertExhaustive(error.reason);\n }\n\n clonedFile.result = manifestCopy;\n clonedFile.value = JSON.stringify(manifestCopy);\n return clonedFile;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read Snap bundle file: ${error.message}`);\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read Snap icon file: ${error.message}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n\n/**\n * Validates the fields of an npm Snap manifest that has already passed JSON\n * Schema validation.\n *\n * @param snapFiles - The relevant snap files to validate.\n * @param snapFiles.manifest - The npm Snap manifest to validate.\n * @param snapFiles.packageJson - The npm Snap's `package.json`.\n * @param snapFiles.sourceCode - The Snap's source code.\n * @param snapFiles.svgIcon - The Snap's optional icon.\n */\nexport function validateNpmSnapManifest({\n manifest,\n packageJson,\n sourceCode,\n svgIcon,\n}: SnapFiles) {\n const packageJsonName = packageJson.result.name;\n const packageJsonVersion = packageJson.result.version;\n const packageJsonRepository = packageJson.result.repository;\n\n const manifestPackageName = manifest.result.source.location.npm.packageName;\n const manifestPackageVersion = manifest.result.version;\n const manifestRepository = manifest.result.repository;\n\n if (packageJsonName !== manifestPackageName) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package name (\"${manifestPackageName}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"name\" field (\"${packageJsonName}\").`,\n SnapValidationFailureReason.NameMismatch,\n );\n }\n\n if (packageJsonVersion !== manifestPackageVersion) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package version (\"${manifestPackageVersion}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"version\" field (\"${packageJsonVersion}\").`,\n SnapValidationFailureReason.VersionMismatch,\n );\n }\n\n if (\n // The repository may be `undefined` in package.json but can only be defined\n // or `null` in the Snap manifest due to TS@<4.4 issues.\n (packageJsonRepository || manifestRepository) &&\n !deepEqual(packageJsonRepository, manifestRepository)\n ) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" \"repository\" field does not match the \"${NpmSnapFileNames.PackageJson}\" \"repository\" field.`,\n SnapValidationFailureReason.RepositoryMismatch,\n );\n }\n\n validateSnapShasum(\n { manifest, sourceCode, svgIcon },\n `\"${NpmSnapFileNames.Manifest}\" \"shasum\" field does not match computed shasum.`,\n );\n}\n"]}
|