@metamask/snaps-utils 0.38.0-flask.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +222 -11
- package/dist/{esm/array.js → array.js} +7 -3
- package/dist/array.js.map +1 -0
- package/dist/{types/caveats.d.ts → caveats.d.ts} +4 -0
- package/dist/caveats.js +35 -0
- package/dist/caveats.js.map +1 -0
- package/dist/checksum.js +42 -0
- package/dist/checksum.js.map +1 -0
- package/dist/{types/cronjob.d.ts → cronjob.d.ts} +1 -1
- package/dist/cronjob.js +71 -0
- package/dist/cronjob.js.map +1 -0
- package/dist/deep-clone.js +9 -0
- package/dist/deep-clone.js.map +1 -0
- package/dist/{esm/default-endowments.js → default-endowments.js} +6 -3
- package/dist/default-endowments.js.map +1 -0
- package/dist/entropy.js +8 -0
- package/dist/entropy.js.map +1 -0
- package/dist/{cjs/eval-worker.js → eval-worker.js} +21 -22
- package/dist/eval-worker.js.map +1 -0
- package/dist/{types/eval.d.ts → eval.d.ts} +1 -9
- package/dist/eval.js +27 -0
- package/dist/eval.js.map +1 -0
- package/dist/{types/fs.d.ts → fs.d.ts} +2 -2
- package/dist/{esm/fs.js → fs.js} +56 -33
- package/dist/fs.js.map +1 -0
- package/dist/handlers.d.ts +105 -0
- package/dist/handlers.js +3 -0
- package/dist/handlers.js.map +1 -0
- package/dist/{types/iframe.d.ts → iframe.d.ts} +2 -3
- package/dist/{esm/iframe.js → iframe.js} +18 -16
- package/dist/iframe.js.map +1 -0
- package/dist/iframe.test.browser.js +15 -0
- package/dist/iframe.test.browser.js.map +1 -0
- package/dist/{types/index.browser.d.ts → index.browser.d.ts} +1 -5
- package/dist/index.browser.js +37 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/{types/index.d.ts → index.d.ts} +1 -5
- package/dist/index.executionenv.js +22 -0
- package/dist/index.executionenv.js.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/{types/json-rpc.d.ts → json-rpc.d.ts} +2 -2
- package/dist/json-rpc.js +46 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/json.d.ts +9 -0
- package/dist/json.js +18 -0
- package/dist/json.js.map +1 -0
- package/dist/{esm/logging.js → logging.js} +14 -6
- package/dist/logging.js.map +1 -0
- package/dist/manifest/index.browser.js +18 -0
- package/dist/manifest/index.browser.js.map +1 -0
- package/dist/manifest/index.js +19 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/{types/manifest → manifest}/manifest.d.ts +4 -6
- package/dist/{esm/manifest → manifest}/manifest.js +115 -101
- package/dist/manifest/manifest.js.map +1 -0
- package/dist/{types/manifest → manifest}/validation.d.ts +76 -34
- package/dist/manifest/validation.js +141 -0
- package/dist/manifest/validation.js.map +1 -0
- package/dist/{esm/mock.js → mock.js} +40 -42
- package/dist/mock.js.map +1 -0
- package/dist/namespace.d.ts +275 -0
- package/dist/namespace.js +225 -0
- package/dist/namespace.js.map +1 -0
- package/dist/notification.d.ts +66 -0
- package/dist/notification.js +58 -0
- package/dist/notification.js.map +1 -0
- package/dist/{types/npm.d.ts → npm.d.ts} +3 -2
- package/dist/npm.js +74 -0
- package/dist/npm.js.map +1 -0
- package/dist/path.js +21 -0
- package/dist/path.js.map +1 -0
- package/dist/{esm/post-process.js → post-process.js} +99 -110
- package/dist/post-process.js.map +1 -0
- package/dist/{types/snaps.d.ts → snaps.d.ts} +9 -17
- package/dist/snaps.js +202 -0
- package/dist/snaps.js.map +1 -0
- package/dist/{types/types.d.ts → types.d.ts} +22 -15
- package/dist/types.js +103 -0
- package/dist/types.js.map +1 -0
- package/dist/{types/versions.d.ts → versions.d.ts} +1 -1
- package/dist/{esm/versions.js → versions.js} +18 -15
- package/dist/versions.js.map +1 -0
- package/dist/{esm/virtual-file → virtual-file}/VirtualFile.js +33 -47
- package/dist/virtual-file/VirtualFile.js.map +1 -0
- package/dist/virtual-file/index.browser.js +18 -0
- package/dist/virtual-file/index.browser.js.map +1 -0
- package/dist/virtual-file/index.js +19 -0
- package/dist/virtual-file/index.js.map +1 -0
- package/dist/virtual-file/toVirtualFile.js +30 -0
- package/dist/virtual-file/toVirtualFile.js.map +1 -0
- package/package.json +40 -59
- package/dist/cjs/array.js +0 -23
- package/dist/cjs/array.js.map +0 -1
- package/dist/cjs/caveats.js +0 -33
- package/dist/cjs/caveats.js.map +0 -1
- package/dist/cjs/checksum.js +0 -38
- package/dist/cjs/checksum.js.map +0 -1
- package/dist/cjs/cronjob.js +0 -84
- package/dist/cjs/cronjob.js.map +0 -1
- package/dist/cjs/deep-clone.js +0 -22
- package/dist/cjs/deep-clone.js.map +0 -1
- package/dist/cjs/default-endowments.js +0 -49
- package/dist/cjs/default-endowments.js.map +0 -1
- package/dist/cjs/entropy.js +0 -23
- package/dist/cjs/entropy.js.map +0 -1
- package/dist/cjs/enum.js +0 -16
- package/dist/cjs/enum.js.map +0 -1
- package/dist/cjs/errors.js +0 -19
- package/dist/cjs/errors.js.map +0 -1
- package/dist/cjs/eval-worker.js.map +0 -1
- package/dist/cjs/eval.js +0 -77
- package/dist/cjs/eval.js.map +0 -1
- package/dist/cjs/fs.js +0 -126
- package/dist/cjs/fs.js.map +0 -1
- package/dist/cjs/handlers.js +0 -65
- package/dist/cjs/handlers.js.map +0 -1
- package/dist/cjs/icon.js +0 -37
- package/dist/cjs/icon.js.map +0 -1
- package/dist/cjs/iframe.js +0 -59
- package/dist/cjs/iframe.js.map +0 -1
- package/dist/cjs/index.browser.js +0 -43
- package/dist/cjs/index.browser.js.map +0 -1
- package/dist/cjs/index.executionenv.js +0 -24
- package/dist/cjs/index.executionenv.js.map +0 -1
- package/dist/cjs/index.js +0 -48
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json-rpc.js +0 -46
- package/dist/cjs/json-rpc.js.map +0 -1
- package/dist/cjs/json.js +0 -16
- package/dist/cjs/json.js.map +0 -1
- package/dist/cjs/logging.js +0 -40
- package/dist/cjs/logging.js.map +0 -1
- package/dist/cjs/manifest/index.browser.js +0 -20
- package/dist/cjs/manifest/index.browser.js.map +0 -1
- package/dist/cjs/manifest/index.js +0 -21
- package/dist/cjs/manifest/index.js.map +0 -1
- package/dist/cjs/manifest/manifest.js +0 -239
- package/dist/cjs/manifest/manifest.js.map +0 -1
- package/dist/cjs/manifest/validation.js +0 -183
- package/dist/cjs/manifest/validation.js.map +0 -1
- package/dist/cjs/mock.js +0 -128
- package/dist/cjs/mock.js.map +0 -1
- package/dist/cjs/namespace.js +0 -124
- package/dist/cjs/namespace.js.map +0 -1
- package/dist/cjs/npm.js +0 -81
- package/dist/cjs/npm.js.map +0 -1
- package/dist/cjs/path.js +0 -21
- package/dist/cjs/path.js.map +0 -1
- package/dist/cjs/post-process.js +0 -328
- package/dist/cjs/post-process.js.map +0 -1
- package/dist/cjs/snaps.js +0 -230
- package/dist/cjs/snaps.js.map +0 -1
- package/dist/cjs/strings.js +0 -21
- package/dist/cjs/strings.js.map +0 -1
- package/dist/cjs/structs.js +0 -163
- package/dist/cjs/structs.js.map +0 -1
- package/dist/cjs/types.js +0 -109
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/validation.js +0 -22
- package/dist/cjs/validation.js.map +0 -1
- package/dist/cjs/versions.js +0 -47
- package/dist/cjs/versions.js.map +0 -1
- package/dist/cjs/virtual-file/VirtualFile.js +0 -85
- package/dist/cjs/virtual-file/VirtualFile.js.map +0 -1
- package/dist/cjs/virtual-file/index.browser.js +0 -20
- package/dist/cjs/virtual-file/index.browser.js.map +0 -1
- package/dist/cjs/virtual-file/index.js +0 -21
- package/dist/cjs/virtual-file/index.js.map +0 -1
- package/dist/cjs/virtual-file/toVirtualFile.js +0 -33
- package/dist/cjs/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/esm/array.js.map +0 -1
- package/dist/esm/caveats.js +0 -23
- package/dist/esm/caveats.js.map +0 -1
- package/dist/esm/checksum.js +0 -36
- package/dist/esm/checksum.js.map +0 -1
- package/dist/esm/cronjob.js +0 -66
- package/dist/esm/cronjob.js.map +0 -1
- package/dist/esm/deep-clone.js +0 -7
- package/dist/esm/deep-clone.js.map +0 -1
- package/dist/esm/default-endowments.js.map +0 -1
- package/dist/esm/entropy.js +0 -6
- package/dist/esm/entropy.js.map +0 -1
- package/dist/esm/enum.js +0 -12
- package/dist/esm/enum.js.map +0 -1
- package/dist/esm/errors.js +0 -17
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/eval-worker.js +0 -47
- package/dist/esm/eval-worker.js.map +0 -1
- package/dist/esm/eval.js +0 -65
- package/dist/esm/eval.js.map +0 -1
- package/dist/esm/fs.js.map +0 -1
- package/dist/esm/handlers.js +0 -47
- package/dist/esm/handlers.js.map +0 -1
- package/dist/esm/icon.js +0 -11
- package/dist/esm/icon.js.map +0 -1
- package/dist/esm/iframe.js.map +0 -1
- package/dist/esm/index.browser.js +0 -26
- package/dist/esm/index.browser.js.map +0 -1
- package/dist/esm/index.executionenv.js +0 -7
- package/dist/esm/index.executionenv.js.map +0 -1
- package/dist/esm/index.js +0 -31
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json-rpc.js +0 -39
- package/dist/esm/json-rpc.js.map +0 -1
- package/dist/esm/json.js +0 -17
- package/dist/esm/json.js.map +0 -1
- package/dist/esm/logging.js.map +0 -1
- package/dist/esm/manifest/index.browser.js +0 -3
- package/dist/esm/manifest/index.browser.js.map +0 -1
- package/dist/esm/manifest/index.js +0 -4
- package/dist/esm/manifest/index.js.map +0 -1
- package/dist/esm/manifest/manifest.js.map +0 -1
- package/dist/esm/manifest/validation.js +0 -152
- package/dist/esm/manifest/validation.js.map +0 -1
- package/dist/esm/mock.js.map +0 -1
- package/dist/esm/namespace.js +0 -110
- package/dist/esm/namespace.js.map +0 -1
- package/dist/esm/npm.js +0 -70
- package/dist/esm/npm.js.map +0 -1
- package/dist/esm/path.js +0 -17
- package/dist/esm/path.js.map +0 -1
- package/dist/esm/post-process.js.map +0 -1
- package/dist/esm/snaps.js +0 -215
- package/dist/esm/snaps.js.map +0 -1
- package/dist/esm/strings.js +0 -11
- package/dist/esm/strings.js.map +0 -1
- package/dist/esm/structs.js +0 -230
- package/dist/esm/structs.js.map +0 -1
- package/dist/esm/types.js +0 -80
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/validation.js +0 -17
- package/dist/esm/validation.js.map +0 -1
- package/dist/esm/versions.js.map +0 -1
- package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
- package/dist/esm/virtual-file/index.browser.js +0 -3
- package/dist/esm/virtual-file/index.browser.js.map +0 -1
- package/dist/esm/virtual-file/index.js +0 -4
- package/dist/esm/virtual-file/index.js.map +0 -1
- package/dist/esm/virtual-file/toVirtualFile.js +0 -26
- package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/types/enum.d.ts +0 -30
- package/dist/types/errors.d.ts +0 -10
- package/dist/types/handlers.d.ts +0 -144
- package/dist/types/icon.d.ts +0 -4
- package/dist/types/json.d.ts +0 -13
- package/dist/types/namespace.d.ts +0 -124
- package/dist/types/strings.d.ts +0 -8
- package/dist/types/structs.d.ts +0 -158
- package/dist/types/validation.d.ts +0 -8
- /package/dist/{types/array.d.ts → array.d.ts} +0 -0
- /package/dist/{types/checksum.d.ts → checksum.d.ts} +0 -0
- /package/dist/{types/deep-clone.d.ts → deep-clone.d.ts} +0 -0
- /package/dist/{types/default-endowments.d.ts → default-endowments.d.ts} +0 -0
- /package/dist/{types/entropy.d.ts → entropy.d.ts} +0 -0
- /package/dist/{types/eval-worker.d.ts → eval-worker.d.ts} +0 -0
- /package/dist/{types/iframe.test.browser.d.ts → iframe.test.browser.d.ts} +0 -0
- /package/dist/{types/index.executionenv.d.ts → index.executionenv.d.ts} +0 -0
- /package/dist/{types/logging.d.ts → logging.d.ts} +0 -0
- /package/dist/{types/manifest → manifest}/index.browser.d.ts +0 -0
- /package/dist/{types/manifest → manifest}/index.d.ts +0 -0
- /package/dist/{types/mock.d.ts → mock.d.ts} +0 -0
- /package/dist/{types/path.d.ts → path.d.ts} +0 -0
- /package/dist/{types/post-process.d.ts → post-process.d.ts} +0 -0
- /package/dist/{types/virtual-file → virtual-file}/VirtualFile.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/index.browser.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/index.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/toVirtualFile.d.ts +0 -0
package/dist/cjs/logging.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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
|
package/dist/cjs/logging.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/manifest/index.browser.ts"],"sourcesContent":["export * from './validation';\n"],"names":[],"mappings":";;;;qBAAc"}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/manifest/index.ts"],"sourcesContent":["export * from './manifest';\nexport * from './validation';\n"],"names":[],"mappings":";;;;qBAAc;qBACA"}
|
|
@@ -1,239 +0,0 @@
|
|
|
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, writeFileFn = _fs.promises.writeFile) {
|
|
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 writeFileFn(_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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/manifest/manifest.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport { 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 type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames, SnapValidationFailureReason } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file';\nimport type { 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\nexport type WriteFileFunction = (path: string, data: string) => Promise<void>;\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 * @param writeFileFn - The function to use to write the manifest to disk.\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 writeFileFn: WriteFileFunction = fs.writeFile,\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 writeFileFn(\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"],"names":["checkManifest","fixManifest","getSnapSourceCode","getSnapIcon","getWritableManifest","validateNpmSnapManifest","MANIFEST_SORT_ORDER","$schema","version","description","proposedName","repository","source","initialPermissions","manifestVersion","basePath","writeManifest","sourceCode","writeFileFn","fs","writeFile","warnings","errors","updated","manifestPath","pathUtils","join","NpmSnapFileNames","Manifest","manifestFile","readJsonFile","unvalidatedManifest","result","packageFile","PackageJson","snapFiles","manifest","packageJson","svgIcon","validateNpmSnap","error","ProgrammaticallyFixableSnapError","push","message","partiallyValidatedFiles","isInvalid","currentError","maxAttempts","Object","keys","SnapValidationFailureReason","length","attempts","nextValidationError","Error","assert","validatedManifest","recommendedFields","missingRecommendedFields","filter","key","reduce","allMissing","currentField","newManifest","JSON","stringify","value","clonedFile","clone","manifestCopy","reason","NameMismatch","location","npm","packageName","name","VersionMismatch","RepositoryMismatch","deepClone","undefined","ShasumMismatch","shasum","getSnapChecksum","assertExhaustive","isPlainObject","sourceFilePath","filePath","VirtualFile","path","virtualFile","readVirtualFile","iconPath","remaining","writableManifest","sort","a","b","packageJsonName","packageJsonVersion","packageJsonRepository","manifestPackageName","manifestPackageVersion","manifestRepository","deepEqual","validateSnapShasum"],"mappings":";;;;;;;;;;;IAiEsBA,aAAa;eAAbA;;IA6INC,WAAW;eAAXA;;IA8CMC,iBAAiB;eAAjBA;;IA0CAC,WAAW;eAAXA;;IAiCNC,mBAAmB;eAAnBA;;IA8BAC,uBAAuB;eAAvBA;;;uBApWwC;sEAClC;oBACS;6DACT;2BAEI;qBACG;qBACG;uBAKzB;uBAEuD;6BACjB;;;;;;AAG7C,MAAMC,sBAA0D;IAC9DC,SAAS;IACTC,SAAS;IACTC,aAAa;IACbC,cAAc;IACdC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpBC,iBAAiB;AACnB;AAqCO,eAAed,cACpBe,QAAgB,EAChBC,gBAAgB,IAAI,EACpBC,UAAmB,EACnBC,cAAiCC,YAAE,CAACC,SAAS;IAE7C,MAAMC,WAAqB,EAAE;IAC7B,MAAMC,SAAmB,EAAE;IAE3B,IAAIC,UAAU;IAEd,MAAMC,eAAeC,aAAS,CAACC,IAAI,CAACX,UAAUY,uBAAgB,CAACC,QAAQ;IACvE,MAAMC,eAAe,MAAMC,IAAAA,iBAAY,EAACN;IACxC,MAAMO,sBAAsBF,aAAaG,MAAM;IAE/C,MAAMC,cAAc,MAAMH,IAAAA,iBAAY,EACpCL,aAAS,CAACC,IAAI,CAACX,UAAUY,uBAAgB,CAACO,WAAW;IAGvD,MAAMC,YAAk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B,uBAAuB,EAAE1E,uBAAgB,CAACO,WAAW,CAAC,iBAAiB,EAAEgE,gBAAgB,GAAG,CAAC,EACtKhD,kCAA2B,CAACsB,YAAY;IAE5C;IAEA,IAAI2B,uBAAuBG,wBAAwB;QACjD,MAAM,IAAI7D,uCAAgC,CACxC,CAAC,CAAC,EAAEd,uBAAgB,CAACC,QAAQ,CAAC,wBAAwB,EAAE0E,uBAAuB,uBAAuB,EAAE3E,uBAAgB,CAACO,WAAW,CAAC,oBAAoB,EAAEiE,mBAAmB,GAAG,CAAC,EAClLjD,kCAA2B,CAAC2B,eAAe;IAE/C;IAEA,IAGE,AAFA,4EAA4E;IAC5E,wDAAwD;IACvDuB,CAAAA,yBAAyBG,kBAAiB,KAC3C,CAACC,IAAAA,sBAAS,EAACJ,uBAAuBG,qBAClC;QACA,MAAM,IAAI9D,uCAAgC,CACxC,CAAC,CAAC,EAAEd,uBAAgB,CAACC,QAAQ,CAAC,yCAAyC,EAAED,uBAAgB,CAACO,WAAW,CAAC,qBAAqB,CAAC,EAC5HgB,kCAA2B,CAAC4B,kBAAkB;IAElD;IAEA2B,IAAAA,yBAAkB,EAChB;QAAErE;QAAUnB;QAAYqB;IAAQ,GAChC,CAAC,CAAC,EAAEX,uBAAgB,CAACC,QAAQ,CAAC,gDAAgD,CAAC;AAEnF"}
|
|
@@ -1,183 +0,0 @@
|
|
|
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
|
-
FORBIDDEN_COIN_TYPES: function() {
|
|
13
|
-
return FORBIDDEN_COIN_TYPES;
|
|
14
|
-
},
|
|
15
|
-
Bip32PathStruct: function() {
|
|
16
|
-
return Bip32PathStruct;
|
|
17
|
-
},
|
|
18
|
-
bip32entropy: function() {
|
|
19
|
-
return bip32entropy;
|
|
20
|
-
},
|
|
21
|
-
Bip32EntropyStruct: function() {
|
|
22
|
-
return Bip32EntropyStruct;
|
|
23
|
-
},
|
|
24
|
-
SnapGetBip32EntropyPermissionsStruct: function() {
|
|
25
|
-
return SnapGetBip32EntropyPermissionsStruct;
|
|
26
|
-
},
|
|
27
|
-
SemVerRangeStruct: function() {
|
|
28
|
-
return SemVerRangeStruct;
|
|
29
|
-
},
|
|
30
|
-
SnapIdsStruct: function() {
|
|
31
|
-
return SnapIdsStruct;
|
|
32
|
-
},
|
|
33
|
-
PermissionsStruct: function() {
|
|
34
|
-
return PermissionsStruct;
|
|
35
|
-
},
|
|
36
|
-
SnapManifestStruct: function() {
|
|
37
|
-
return SnapManifestStruct;
|
|
38
|
-
},
|
|
39
|
-
isSnapManifest: function() {
|
|
40
|
-
return isSnapManifest;
|
|
41
|
-
},
|
|
42
|
-
assertIsSnapManifest: function() {
|
|
43
|
-
return assertIsSnapManifest;
|
|
44
|
-
},
|
|
45
|
-
createSnapManifest: function() {
|
|
46
|
-
return createSnapManifest;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
const _keytree = require("@metamask/key-tree");
|
|
50
|
-
const _utils = require("@metamask/utils");
|
|
51
|
-
const _superstruct = require("superstruct");
|
|
52
|
-
const _array = require("../array");
|
|
53
|
-
const _cronjob = require("../cronjob");
|
|
54
|
-
const _entropy = require("../entropy");
|
|
55
|
-
const _jsonrpc = require("../json-rpc");
|
|
56
|
-
const _snaps = require("../snaps");
|
|
57
|
-
const _types = require("../types");
|
|
58
|
-
// BIP-43 purposes that cannot be used for entropy derivation. These are in the
|
|
59
|
-
// string form, ending with `'`.
|
|
60
|
-
const FORBIDDEN_PURPOSES = [
|
|
61
|
-
_entropy.SIP_6_MAGIC_VALUE,
|
|
62
|
-
_entropy.STATE_ENCRYPTION_MAGIC_VALUE
|
|
63
|
-
];
|
|
64
|
-
const FORBIDDEN_COIN_TYPES = [
|
|
65
|
-
60
|
|
66
|
-
];
|
|
67
|
-
const FORBIDDEN_PATHS = FORBIDDEN_COIN_TYPES.map((coinType)=>[
|
|
68
|
-
'm',
|
|
69
|
-
"44'",
|
|
70
|
-
`${coinType}'`
|
|
71
|
-
]);
|
|
72
|
-
const Bip32PathStruct = (0, _superstruct.refine)((0, _superstruct.array)((0, _superstruct.string)()), 'BIP-32 path', (path)=>{
|
|
73
|
-
if (path.length === 0) {
|
|
74
|
-
return 'Path must be a non-empty BIP-32 derivation path array';
|
|
75
|
-
}
|
|
76
|
-
if (path[0] !== 'm') {
|
|
77
|
-
return 'Path must start with "m".';
|
|
78
|
-
}
|
|
79
|
-
if (path.length < 3) {
|
|
80
|
-
return 'Paths must have a length of at least three.';
|
|
81
|
-
}
|
|
82
|
-
if (path.slice(1).some((part)=>!(0, _keytree.isValidBIP32PathSegment)(part))) {
|
|
83
|
-
return 'Path must be a valid BIP-32 derivation path array.';
|
|
84
|
-
}
|
|
85
|
-
if (FORBIDDEN_PURPOSES.includes(path[1])) {
|
|
86
|
-
return `The purpose "${path[1]}" is not allowed for entropy derivation.`;
|
|
87
|
-
}
|
|
88
|
-
if (FORBIDDEN_PATHS.some((forbiddenPath)=>(0, _array.isEqual)(path.slice(0, forbiddenPath.length), forbiddenPath))) {
|
|
89
|
-
return `The path "${path.join('/')}" is not allowed for entropy derivation.`;
|
|
90
|
-
}
|
|
91
|
-
return true;
|
|
92
|
-
});
|
|
93
|
-
const bip32entropy = (struct)=>(0, _superstruct.refine)(struct, 'BIP-32 entropy', (value)=>{
|
|
94
|
-
if (value.curve === 'ed25519' && value.path.slice(1).some((part)=>!part.endsWith("'"))) {
|
|
95
|
-
return 'Ed25519 does not support unhardened paths.';
|
|
96
|
-
}
|
|
97
|
-
return true;
|
|
98
|
-
});
|
|
99
|
-
const Bip32EntropyStruct = bip32entropy((0, _superstruct.type)({
|
|
100
|
-
path: Bip32PathStruct,
|
|
101
|
-
curve: (0, _superstruct.enums)([
|
|
102
|
-
'ed25519',
|
|
103
|
-
'secp256k1'
|
|
104
|
-
])
|
|
105
|
-
}));
|
|
106
|
-
const SnapGetBip32EntropyPermissionsStruct = (0, _superstruct.size)((0, _superstruct.array)(Bip32EntropyStruct), 1, Infinity);
|
|
107
|
-
const SemVerRangeStruct = (0, _superstruct.refine)((0, _superstruct.string)(), 'SemVer range', (value)=>{
|
|
108
|
-
if ((0, _utils.isValidSemVerRange)(value)) {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
return 'Expected a valid SemVer range.';
|
|
112
|
-
});
|
|
113
|
-
const SnapIdsStruct = (0, _superstruct.refine)((0, _superstruct.record)(_snaps.SnapIdStruct, (0, _superstruct.object)({
|
|
114
|
-
version: (0, _superstruct.optional)(SemVerRangeStruct)
|
|
115
|
-
})), 'SnapIds', (value)=>{
|
|
116
|
-
if (Object.keys(value).length === 0) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
return true;
|
|
120
|
-
});
|
|
121
|
-
const PermissionsStruct = (0, _superstruct.type)({
|
|
122
|
-
'endowment:long-running': (0, _superstruct.optional)((0, _superstruct.object)({})),
|
|
123
|
-
'endowment:network-access': (0, _superstruct.optional)((0, _superstruct.object)({})),
|
|
124
|
-
'endowment:webassembly': (0, _superstruct.optional)((0, _superstruct.object)({})),
|
|
125
|
-
'endowment:transaction-insight': (0, _superstruct.optional)((0, _superstruct.object)({
|
|
126
|
-
allowTransactionOrigin: (0, _superstruct.optional)((0, _superstruct.boolean)())
|
|
127
|
-
})),
|
|
128
|
-
'endowment:cronjob': (0, _superstruct.optional)((0, _superstruct.object)({
|
|
129
|
-
jobs: _cronjob.CronjobSpecificationArrayStruct
|
|
130
|
-
})),
|
|
131
|
-
'endowment:rpc': (0, _superstruct.optional)(_jsonrpc.RpcOriginsStruct),
|
|
132
|
-
snap_dialog: (0, _superstruct.optional)((0, _superstruct.object)({})),
|
|
133
|
-
// TODO: Remove
|
|
134
|
-
snap_confirm: (0, _superstruct.optional)((0, _superstruct.object)({})),
|
|
135
|
-
snap_manageState: (0, _superstruct.optional)((0, _superstruct.object)({})),
|
|
136
|
-
snap_manageAccounts: (0, _superstruct.optional)((0, _superstruct.object)({})),
|
|
137
|
-
snap_notify: (0, _superstruct.optional)((0, _superstruct.object)({})),
|
|
138
|
-
snap_getBip32Entropy: (0, _superstruct.optional)(SnapGetBip32EntropyPermissionsStruct),
|
|
139
|
-
snap_getBip32PublicKey: (0, _superstruct.optional)(SnapGetBip32EntropyPermissionsStruct),
|
|
140
|
-
snap_getBip44Entropy: (0, _superstruct.optional)((0, _superstruct.size)((0, _superstruct.array)((0, _superstruct.object)({
|
|
141
|
-
coinType: (0, _superstruct.size)((0, _superstruct.integer)(), 0, 2 ** 32 - 1)
|
|
142
|
-
})), 1, Infinity)),
|
|
143
|
-
snap_getEntropy: (0, _superstruct.optional)((0, _superstruct.object)({})),
|
|
144
|
-
wallet_snap: (0, _superstruct.optional)(SnapIdsStruct)
|
|
145
|
-
});
|
|
146
|
-
const SnapManifestStruct = (0, _superstruct.object)({
|
|
147
|
-
version: _utils.VersionStruct,
|
|
148
|
-
description: (0, _superstruct.size)((0, _superstruct.string)(), 1, 280),
|
|
149
|
-
proposedName: (0, _superstruct.size)((0, _superstruct.pattern)((0, _superstruct.string)(), /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u), 1, 214),
|
|
150
|
-
repository: (0, _superstruct.optional)((0, _superstruct.object)({
|
|
151
|
-
type: (0, _superstruct.size)((0, _superstruct.string)(), 1, Infinity),
|
|
152
|
-
url: (0, _superstruct.size)((0, _superstruct.string)(), 1, Infinity)
|
|
153
|
-
})),
|
|
154
|
-
source: (0, _superstruct.object)({
|
|
155
|
-
shasum: _utils.ChecksumStruct,
|
|
156
|
-
location: (0, _superstruct.object)({
|
|
157
|
-
npm: (0, _superstruct.object)({
|
|
158
|
-
filePath: (0, _superstruct.size)((0, _superstruct.string)(), 1, Infinity),
|
|
159
|
-
iconPath: (0, _superstruct.optional)((0, _superstruct.size)((0, _superstruct.string)(), 1, Infinity)),
|
|
160
|
-
packageName: _types.NameStruct,
|
|
161
|
-
registry: (0, _superstruct.union)([
|
|
162
|
-
(0, _superstruct.literal)('https://registry.npmjs.org'),
|
|
163
|
-
(0, _superstruct.literal)('https://registry.npmjs.org/')
|
|
164
|
-
])
|
|
165
|
-
})
|
|
166
|
-
})
|
|
167
|
-
}),
|
|
168
|
-
initialPermissions: PermissionsStruct,
|
|
169
|
-
manifestVersion: (0, _superstruct.literal)('0.1'),
|
|
170
|
-
$schema: (0, _superstruct.optional)((0, _superstruct.string)())
|
|
171
|
-
});
|
|
172
|
-
function isSnapManifest(value) {
|
|
173
|
-
return (0, _superstruct.is)(value, SnapManifestStruct);
|
|
174
|
-
}
|
|
175
|
-
function assertIsSnapManifest(value) {
|
|
176
|
-
(0, _utils.assertStruct)(value, SnapManifestStruct, `"${_types.NpmSnapFileNames.Manifest}" is invalid`);
|
|
177
|
-
}
|
|
178
|
-
function createSnapManifest(value) {
|
|
179
|
-
// TODO: Add a utility to prefix these errors similar to assertStruct
|
|
180
|
-
return (0, _superstruct.create)(value, SnapManifestStruct);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/manifest/validation.ts"],"sourcesContent":["import { isValidBIP32PathSegment } from '@metamask/key-tree';\nimport {\n assertStruct,\n ChecksumStruct,\n VersionStruct,\n isValidSemVerRange,\n} from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n array,\n boolean,\n create,\n enums,\n integer,\n is,\n literal,\n object,\n optional,\n pattern,\n refine,\n record,\n size,\n string,\n type,\n union,\n} from 'superstruct';\n\nimport { isEqual } from '../array';\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { RpcOriginsStruct } from '../json-rpc';\nimport { SnapIdStruct } from '../snaps';\nimport { NameStruct, NpmSnapFileNames } from '../types';\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [\n SIP_6_MAGIC_VALUE,\n STATE_ENCRYPTION_MAGIC_VALUE,\n];\n\nexport const FORBIDDEN_COIN_TYPES: number[] = [60];\nconst FORBIDDEN_PATHS: string[][] = FORBIDDEN_COIN_TYPES.map((coinType) => [\n 'm',\n \"44'\",\n `${coinType}'`,\n]);\n\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path: string[]) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !isValidBIP32PathSegment(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n if (\n FORBIDDEN_PATHS.some((forbiddenPath) =>\n isEqual(path.slice(0, forbiddenPath.length), forbiddenPath),\n )\n ) {\n return `The path \"${path.join(\n '/',\n )}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <\n Type extends { path: string[]; curve: string },\n Schema,\n>(\n struct: Struct<Type, Schema>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: enums(['ed25519', 'secp256k1']),\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\nexport const SemVerRangeStruct = refine(string(), 'SemVer range', (value) => {\n if (isValidSemVerRange(value)) {\n return true;\n }\n return 'Expected a valid SemVer range.';\n});\n\nexport const SnapIdsStruct = refine(\n record(SnapIdStruct, object({ version: optional(SemVerRangeStruct) })),\n 'SnapIds',\n (value) => {\n if (Object.keys(value).length === 0) {\n return false;\n }\n\n return true;\n },\n);\n\nexport type SnapIds = Infer<typeof SnapIdsStruct>;\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct = type({\n 'endowment:long-running': optional(object({})),\n 'endowment:network-access': optional(object({})),\n 'endowment:webassembly': optional(object({})),\n 'endowment:transaction-insight': optional(\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n 'endowment:cronjob': optional(\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n 'endowment:rpc': optional(RpcOriginsStruct),\n snap_dialog: optional(object({})),\n // TODO: Remove\n snap_confirm: optional(object({})),\n snap_manageState: optional(object({})),\n snap_manageAccounts: optional(object({})),\n snap_notify: optional(object({})),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(object({})),\n wallet_snap: optional(SnapIdsStruct),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = Infer<typeof PermissionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(\n pattern(\n string(),\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u,\n ),\n 1,\n 214,\n ),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: ChecksumStruct,\n location: object({\n npm: object({\n filePath: size(string(), 1, Infinity),\n iconPath: optional(size(string(), 1, Infinity)),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n }),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n $schema: optional(string()), // enables JSON-Schema linting in VSC and other IDEs\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"],"names":["FORBIDDEN_COIN_TYPES","Bip32PathStruct","bip32entropy","Bip32EntropyStruct","SnapGetBip32EntropyPermissionsStruct","SemVerRangeStruct","SnapIdsStruct","PermissionsStruct","SnapManifestStruct","isSnapManifest","assertIsSnapManifest","createSnapManifest","FORBIDDEN_PURPOSES","SIP_6_MAGIC_VALUE","STATE_ENCRYPTION_MAGIC_VALUE","FORBIDDEN_PATHS","map","coinType","refine","array","string","path","length","slice","some","part","isValidBIP32PathSegment","includes","forbiddenPath","isEqual","join","struct","value","curve","endsWith","type","enums","size","Infinity","isValidSemVerRange","record","SnapIdStruct","object","version","optional","Object","keys","allowTransactionOrigin","boolean","jobs","CronjobSpecificationArrayStruct","RpcOriginsStruct","snap_dialog","snap_confirm","snap_manageState","snap_manageAccounts","snap_notify","snap_getBip32Entropy","snap_getBip32PublicKey","snap_getBip44Entropy","integer","snap_getEntropy","wallet_snap","VersionStruct","description","proposedName","pattern","repository","url","source","shasum","ChecksumStruct","location","npm","filePath","iconPath","packageName","NameStruct","registry","union","literal","initialPermissions","manifestVersion","$schema","is","assertStruct","NpmSnapFileNames","Manifest","create"],"mappings":";;;;;;;;;;;IAyCaA,oBAAoB;eAApBA;;IAOAC,eAAe;eAAfA;;IAsCAC,YAAY;eAAZA;;IAkBAC,kBAAkB;eAAlBA;;IASAC,oCAAoC;eAApCA;;IAMAC,iBAAiB;eAAjBA;;IAOAC,aAAa;eAAbA;;IAeAC,iBAAiB;eAAjBA;;IAmCAC,kBAAkB;eAAlBA;;IA4CGC,cAAc;eAAdA;;IAUAC,oBAAoB;eAApBA;;IAiBAC,kBAAkB;eAAlBA;;;yBAvPwB;uBAMjC;6BAmBA;uBAEiB;yBACwB;yBACgB;yBAC/B;uBACJ;uBACgB;AAE7C,+EAA+E;AAC/E,gCAAgC;AAChC,MAAMC,qBAA+B;IACnCC,0BAAiB;IACjBC,qCAA4B;CAC7B;AAEM,MAAMd,uBAAiC;IAAC;CAAG;AAClD,MAAMe,kBAA8Bf,qBAAqBgB,GAAG,CAAC,CAACC,WAAa;QACzE;QACA;QACA,CAAC,EAAEA,SAAS,CAAC,CAAC;KACf;AAEM,MAAMhB,kBAAkBiB,IAAAA,mBAAM,EACnCC,IAAAA,kBAAK,EAACC,IAAAA,mBA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