@metamask/snaps-utils 9.4.0 → 10.1.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 +28 -1
- package/dist/cronjob.cjs +16 -15
- package/dist/cronjob.cjs.map +1 -1
- package/dist/cronjob.d.cts +27 -36
- package/dist/cronjob.d.cts.map +1 -1
- package/dist/cronjob.d.mts +27 -36
- package/dist/cronjob.d.mts.map +1 -1
- package/dist/cronjob.mjs +16 -14
- package/dist/cronjob.mjs.map +1 -1
- package/dist/errors.cjs +22 -24
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +22 -24
- package/dist/errors.mjs.map +1 -1
- package/dist/eval.cjs +1 -0
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.mjs +1 -0
- package/dist/eval.mjs.map +1 -1
- package/dist/handlers/exports.cjs +14 -0
- package/dist/handlers/exports.cjs.map +1 -1
- package/dist/handlers/exports.d.cts +11 -1
- package/dist/handlers/exports.d.cts.map +1 -1
- package/dist/handlers/exports.d.mts +11 -1
- package/dist/handlers/exports.d.mts.map +1 -1
- package/dist/handlers/exports.mjs +14 -0
- package/dist/handlers/exports.mjs.map +1 -1
- package/dist/handlers/types.cjs +2 -0
- package/dist/handlers/types.cjs.map +1 -1
- package/dist/handlers/types.d.cts +3 -1
- package/dist/handlers/types.d.cts.map +1 -1
- package/dist/handlers/types.d.mts +3 -1
- package/dist/handlers/types.d.mts.map +1 -1
- package/dist/handlers/types.mjs +2 -0
- package/dist/handlers/types.mjs.map +1 -1
- package/dist/localization.d.cts +1 -1
- package/dist/localization.d.mts +1 -1
- package/dist/manifest/validation.d.cts +3 -3
- package/dist/manifest/validation.d.cts.map +1 -1
- package/dist/manifest/validation.d.mts +3 -3
- package/dist/manifest/validation.d.mts.map +1 -1
- package/dist/manifest/validator.cjs +8 -21
- package/dist/manifest/validator.cjs.map +1 -1
- package/dist/manifest/validator.mjs +8 -21
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/unused-exports.cjs +12 -2
- package/dist/manifest/validators/unused-exports.cjs.map +1 -1
- package/dist/manifest/validators/unused-exports.d.cts.map +1 -1
- package/dist/manifest/validators/unused-exports.d.mts.map +1 -1
- package/dist/manifest/validators/unused-exports.mjs +12 -2
- package/dist/manifest/validators/unused-exports.mjs.map +1 -1
- package/dist/time.cjs.map +1 -1
- package/dist/time.d.cts.map +1 -1
- package/dist/time.d.mts.map +1 -1
- package/dist/time.mjs.map +1 -1
- package/dist/types.cjs +7 -3
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +8 -4
- package/dist/types.mjs.map +1 -1
- package/dist/virtual-file/VirtualFile.cjs +4 -0
- package/dist/virtual-file/VirtualFile.cjs.map +1 -1
- package/dist/virtual-file/VirtualFile.mjs +4 -0
- package/dist/virtual-file/VirtualFile.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -57,7 +57,7 @@ export declare const EmptyObjectStruct: Struct<EmptyObject, null>;
|
|
|
57
57
|
export declare const PermissionsStruct: Describe<InitialPermissions>;
|
|
58
58
|
export type SnapPermissions = InferMatching<typeof PermissionsStruct, InitialPermissions>;
|
|
59
59
|
export declare const SnapAuxilaryFilesStruct: Struct<string[], Struct<string, null>>;
|
|
60
|
-
export declare const InitialConnectionsStruct: Struct<Record<string
|
|
60
|
+
export declare const InitialConnectionsStruct: Struct<Record<string, {}>, null>;
|
|
61
61
|
export type InitialConnections = Infer<typeof InitialConnectionsStruct>;
|
|
62
62
|
export declare const SnapManifestStruct: Struct<{
|
|
63
63
|
description: string;
|
|
@@ -132,7 +132,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
132
132
|
type: string;
|
|
133
133
|
url: string;
|
|
134
134
|
} | undefined;
|
|
135
|
-
initialConnections?: Record<string
|
|
135
|
+
initialConnections?: Record<string, {}> | undefined;
|
|
136
136
|
platformVersion?: import("@metamask/utils").SemVerVersion | undefined;
|
|
137
137
|
$schema?: string | undefined;
|
|
138
138
|
}, {
|
|
@@ -183,7 +183,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
183
183
|
files: Struct<string[] | undefined, Struct<string, null>>;
|
|
184
184
|
locales: Struct<string[] | undefined, Struct<string, null>>;
|
|
185
185
|
}>;
|
|
186
|
-
initialConnections: Struct<Record<string
|
|
186
|
+
initialConnections: Struct<Record<string, {}> | undefined, null>;
|
|
187
187
|
initialPermissions: Describe<Partial<{
|
|
188
188
|
'endowment:cronjob': {
|
|
189
189
|
jobs?: import("@metamask/snaps-sdk").Cronjob[] | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B;AAEzD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,4BAA4B;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAkCrE,OAAO,EAAgB,KAAK,aAAa,EAAE,uBAAmB;AAU9D,eAAO,MAAM,oBAAoB,EAAE,MAAM,EAAS,CAAC;AAOnD,eAAO,MAAM,eAAe,wCAoC3B,CAAC;AAEF,eAAO,MAAM,YAAY;UACF,MAAM,EAAE;WAAS,MAAM;gEAc1C,CAAC;AAEL,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,cAAc,CAI/C,CAAC;AAGH,eAAO,MAAM,kBAAkB;;;;;;EAK9B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5D,eAAO,MAAM,oCAAoC;;;;;;;;;GAIhD,CAAC;AAEF,eAAO,MAAM,iBAAiB,sBAK5B,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+B7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,YAAY,CAM/B;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAG/D"}
|
|
@@ -22,23 +22,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
26
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
28
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
29
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
30
|
-
};
|
|
31
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
32
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
33
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
34
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
35
|
-
};
|
|
36
|
-
var _Context_options, _Context_nextSeverity;
|
|
37
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
26
|
exports.hasFixes = exports.runValidators = void 0;
|
|
39
27
|
const utils_1 = require("@metamask/utils");
|
|
40
28
|
const defaultValidators = __importStar(require("./validators/index.cjs"));
|
|
41
29
|
class Context {
|
|
30
|
+
reports = [];
|
|
31
|
+
#options = {};
|
|
32
|
+
#nextSeverity = undefined;
|
|
42
33
|
/**
|
|
43
34
|
* Construct a new validator context.
|
|
44
35
|
*
|
|
@@ -46,30 +37,26 @@ class Context {
|
|
|
46
37
|
* @param options.exports - Exports detected by evaluating the bundle.
|
|
47
38
|
*/
|
|
48
39
|
constructor(options) {
|
|
49
|
-
this
|
|
50
|
-
_Context_options.set(this, {});
|
|
51
|
-
_Context_nextSeverity.set(this, undefined);
|
|
52
|
-
__classPrivateFieldSet(this, _Context_options, options, "f");
|
|
40
|
+
this.#options = options;
|
|
53
41
|
}
|
|
54
42
|
report(message, fix) {
|
|
55
|
-
(0, utils_1.assert)(
|
|
43
|
+
(0, utils_1.assert)(this.#nextSeverity !== undefined);
|
|
56
44
|
this.reports.push({
|
|
57
|
-
severity:
|
|
45
|
+
severity: this.#nextSeverity,
|
|
58
46
|
message,
|
|
59
47
|
fix,
|
|
60
48
|
});
|
|
61
49
|
}
|
|
62
50
|
prepareForValidator(settings) {
|
|
63
|
-
|
|
51
|
+
this.#nextSeverity = settings.severity;
|
|
64
52
|
}
|
|
65
53
|
get hasErrors() {
|
|
66
54
|
return this.reports.some((report) => report.severity === 'error');
|
|
67
55
|
}
|
|
68
56
|
get options() {
|
|
69
|
-
return
|
|
57
|
+
return this.#options;
|
|
70
58
|
}
|
|
71
59
|
}
|
|
72
|
-
_Context_options = new WeakMap(), _Context_nextSeverity = new WeakMap();
|
|
73
60
|
/**
|
|
74
61
|
* Verify that snap files are completely valid.
|
|
75
62
|
* First it runs validators on unparsed files to check structure.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.cjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"
|
|
1
|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CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,KAAkB,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO;QACL,KAAK,EAAE,KAAkB;QACzB,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC;AA/BD,sCA+BC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,OAAyB;IAChD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC;AAFD,4BAEC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type {\n ValidatorContext,\n ValidatorContextOptions,\n ValidatorFix,\n ValidatorMeta,\n ValidatorReport,\n ValidatorSeverity,\n} from './validator-types';\nimport * as defaultValidators from './validators';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\nexport type ValidatorResults = {\n files?: SnapFiles;\n reports: ValidatorReport[];\n};\n\nclass Context implements ValidatorContext {\n reports: ValidatorReport[] = [];\n\n readonly #options: ValidatorContextOptions = {};\n\n #nextSeverity?: ValidatorSeverity = undefined;\n\n /**\n * Construct a new validator context.\n *\n * @param options - The options for the validator context.\n * @param options.exports - Exports detected by evaluating the bundle.\n */\n constructor(options: ValidatorContextOptions) {\n this.#options = options;\n }\n\n report(message: string, fix?: ValidatorFix): void {\n assert(this.#nextSeverity !== undefined);\n this.reports.push({\n severity: this.#nextSeverity,\n message,\n fix,\n });\n }\n\n prepareForValidator(settings: { severity: ValidatorSeverity }) {\n this.#nextSeverity = settings.severity;\n }\n\n get hasErrors() {\n return this.reports.some((report) => report.severity === 'error');\n }\n\n get options() {\n return this.#options;\n }\n}\n\n/**\n * Verify that snap files are completely valid.\n * First it runs validators on unparsed files to check structure.\n * Secondly it runs validators on parsed files to check semantics.\n *\n * @param files - All files required to run a snap.\n * @param rules - Validators to run.\n * @param options - Options for the validation.\n * @param options.exports - Exports detected by evaluating the bundle.\n * @returns The validation results.\n */\n// TODO(ritave): snap.manifest.json and package.json should check\n// json parsing as well instead of assuming it's\n// already parsed\nexport async function runValidators(\n files: UnvalidatedSnapFiles,\n rules: ValidatorMeta[] = Object.values(defaultValidators),\n options: ValidatorContextOptions = {},\n): Promise<ValidatorResults> {\n const context = new Context(options);\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.structureCheck?.(files, context);\n }\n\n if (context.hasErrors) {\n return {\n reports: context.reports,\n };\n }\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.semanticCheck?.(files as SnapFiles, context);\n }\n\n return {\n files: files as SnapFiles,\n reports: context.reports,\n };\n}\n\n/**\n * Get whether any reports has pending fixes.\n *\n * @param results - Results of the validation run.\n * @returns Whether there are fixes pending.\n */\nexport function hasFixes(results: ValidatorResults): boolean {\n return results.reports.some((report) => report.fix);\n}\n"]}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _Context_options, _Context_nextSeverity;
|
|
13
1
|
import { assert } from "@metamask/utils";
|
|
14
2
|
import * as defaultValidators from "./validators/index.mjs";
|
|
15
3
|
class Context {
|
|
4
|
+
reports = [];
|
|
5
|
+
#options = {};
|
|
6
|
+
#nextSeverity = undefined;
|
|
16
7
|
/**
|
|
17
8
|
* Construct a new validator context.
|
|
18
9
|
*
|
|
@@ -20,30 +11,26 @@ class Context {
|
|
|
20
11
|
* @param options.exports - Exports detected by evaluating the bundle.
|
|
21
12
|
*/
|
|
22
13
|
constructor(options) {
|
|
23
|
-
this
|
|
24
|
-
_Context_options.set(this, {});
|
|
25
|
-
_Context_nextSeverity.set(this, undefined);
|
|
26
|
-
__classPrivateFieldSet(this, _Context_options, options, "f");
|
|
14
|
+
this.#options = options;
|
|
27
15
|
}
|
|
28
16
|
report(message, fix) {
|
|
29
|
-
assert(
|
|
17
|
+
assert(this.#nextSeverity !== undefined);
|
|
30
18
|
this.reports.push({
|
|
31
|
-
severity:
|
|
19
|
+
severity: this.#nextSeverity,
|
|
32
20
|
message,
|
|
33
21
|
fix,
|
|
34
22
|
});
|
|
35
23
|
}
|
|
36
24
|
prepareForValidator(settings) {
|
|
37
|
-
|
|
25
|
+
this.#nextSeverity = settings.severity;
|
|
38
26
|
}
|
|
39
27
|
get hasErrors() {
|
|
40
28
|
return this.reports.some((report) => report.severity === 'error');
|
|
41
29
|
}
|
|
42
30
|
get options() {
|
|
43
|
-
return
|
|
31
|
+
return this.#options;
|
|
44
32
|
}
|
|
45
33
|
}
|
|
46
|
-
_Context_options = new WeakMap(), _Context_nextSeverity = new WeakMap();
|
|
47
34
|
/**
|
|
48
35
|
* Verify that snap files are completely valid.
|
|
49
36
|
* First it runs validators on unparsed files to check structure.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.mjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validator.mjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAUzC,OAAO,KAAK,iBAAiB,+BAAqB;AAQlD,MAAM,OAAO;IACX,OAAO,GAAsB,EAAE,CAAC;IAEvB,QAAQ,GAA4B,EAAE,CAAC;IAEhD,aAAa,GAAuB,SAAS,CAAC;IAE9C;;;;;OAKG;IACH,YAAY,OAAgC;QAC1C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,OAAe,EAAE,GAAkB;QACxC,MAAM,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,QAAQ,EAAE,IAAI,CAAC,aAAa;YAC5B,OAAO;YACP,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB,CAAC,QAAyC;QAC3D,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,QAAQ,CAAC;IACzC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,iEAAiE;AACjE,8DAA8D;AAC9D,+BAA+B;AAC/B,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAA2B,EAC3B,QAAyB,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,EACzD,UAAmC,EAAE;IAErC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAErC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,KAAkB,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO;QACL,KAAK,EAAE,KAAkB;QACzB,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAyB;IAChD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type {\n ValidatorContext,\n ValidatorContextOptions,\n ValidatorFix,\n ValidatorMeta,\n ValidatorReport,\n ValidatorSeverity,\n} from './validator-types';\nimport * as defaultValidators from './validators';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\nexport type ValidatorResults = {\n files?: SnapFiles;\n reports: ValidatorReport[];\n};\n\nclass Context implements ValidatorContext {\n reports: ValidatorReport[] = [];\n\n readonly #options: ValidatorContextOptions = {};\n\n #nextSeverity?: ValidatorSeverity = undefined;\n\n /**\n * Construct a new validator context.\n *\n * @param options - The options for the validator context.\n * @param options.exports - Exports detected by evaluating the bundle.\n */\n constructor(options: ValidatorContextOptions) {\n this.#options = options;\n }\n\n report(message: string, fix?: ValidatorFix): void {\n assert(this.#nextSeverity !== undefined);\n this.reports.push({\n severity: this.#nextSeverity,\n message,\n fix,\n });\n }\n\n prepareForValidator(settings: { severity: ValidatorSeverity }) {\n this.#nextSeverity = settings.severity;\n }\n\n get hasErrors() {\n return this.reports.some((report) => report.severity === 'error');\n }\n\n get options() {\n return this.#options;\n }\n}\n\n/**\n * Verify that snap files are completely valid.\n * First it runs validators on unparsed files to check structure.\n * Secondly it runs validators on parsed files to check semantics.\n *\n * @param files - All files required to run a snap.\n * @param rules - Validators to run.\n * @param options - Options for the validation.\n * @param options.exports - Exports detected by evaluating the bundle.\n * @returns The validation results.\n */\n// TODO(ritave): snap.manifest.json and package.json should check\n// json parsing as well instead of assuming it's\n// already parsed\nexport async function runValidators(\n files: UnvalidatedSnapFiles,\n rules: ValidatorMeta[] = Object.values(defaultValidators),\n options: ValidatorContextOptions = {},\n): Promise<ValidatorResults> {\n const context = new Context(options);\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.structureCheck?.(files, context);\n }\n\n if (context.hasErrors) {\n return {\n reports: context.reports,\n };\n }\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.semanticCheck?.(files as SnapFiles, context);\n }\n\n return {\n files: files as SnapFiles,\n reports: context.reports,\n };\n}\n\n/**\n * Get whether any reports has pending fixes.\n *\n * @param results - Results of the validation run.\n * @returns Whether there are fixes pending.\n */\nexport function hasFixes(results: ValidatorResults): boolean {\n return results.reports.some((report) => report.fix);\n}\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.unusedExports = void 0;
|
|
4
|
+
// Special case endowments that should be ignored.
|
|
5
|
+
const IGNORED_ENDOWMENTS = ['endowment:network-access'];
|
|
4
6
|
/**
|
|
5
7
|
* Check if the Snap exports handlers that are not requested in the manifest, or
|
|
6
8
|
* if the Snap requests permissions for handlers that are not exported.
|
|
@@ -14,6 +16,12 @@ exports.unusedExports = {
|
|
|
14
16
|
if (!handlerEndowments || !exports) {
|
|
15
17
|
return;
|
|
16
18
|
}
|
|
19
|
+
// Endowments used based on the exports from the Snap. This is used to
|
|
20
|
+
// filter endowments that are used by multiple handlers, e.g., the lifecycle
|
|
21
|
+
// handlers.
|
|
22
|
+
const usedEndowments = Object.entries(handlerEndowments)
|
|
23
|
+
.filter(([handler, endowment]) => endowment === null || exports.includes(handler))
|
|
24
|
+
.map(([, endowment]) => endowment);
|
|
17
25
|
const unusedHandlers = Object.entries(handlerEndowments)
|
|
18
26
|
.filter(([handler, endowment]) => {
|
|
19
27
|
if (endowment === null) {
|
|
@@ -24,10 +32,12 @@ exports.unusedExports = {
|
|
|
24
32
|
})
|
|
25
33
|
.map(([handler, endowment]) => `${handler} (${endowment})`);
|
|
26
34
|
const unusedEndowments = Object.entries(handlerEndowments).filter(([handler, endowment]) => {
|
|
27
|
-
if (endowment === null) {
|
|
35
|
+
if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {
|
|
28
36
|
return false;
|
|
29
37
|
}
|
|
30
|
-
return (
|
|
38
|
+
return (!usedEndowments.includes(endowment) &&
|
|
39
|
+
files.manifest.result.initialPermissions[endowment] &&
|
|
40
|
+
!exports.includes(handler));
|
|
31
41
|
});
|
|
32
42
|
if (unusedHandlers.length > 0) {
|
|
33
43
|
// We don't specify a fix function here, because:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACU,QAAA,aAAa,GAAkB;IAC1C,QAAQ,EAAE,SAAS;IACnB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QAE7D,0EAA0E;QAC1E,aAAa;QACb,IAAI,CAAC,iBAAiB,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;aACrD,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE;YAC/B,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,CACL,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBACzB,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CACvC,SAAqC,CACtC,CACF,CAAC;QACJ,CAAC,CAAC;aACD,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC,CAAC;QAE9D,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAC/D,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE;YACvB,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"unused-exports.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":";;;AAIA,kDAAkD;AAClD,MAAM,kBAAkB,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAExD;;;GAGG;AACU,QAAA,aAAa,GAAkB;I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kBAAkB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBACjE,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,CACL,CAAC,cAAc,CAAC,QAAQ,CAAC,SAAS,CAAC;gBACnC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CACtC,SAAqC,CACtC;gBACD,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAC3B,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,iDAAiD;YACjD,oEAAoE;YACpE,gCAAgC;YAChC,yEAAyE;YACzE,2DAA2D;YAC3D,OAAO,CAAC,MAAM,CACZ,sFAAsF,cAAc,CAAC,IAAI,CACvG,IAAI,CACL,GAAG,CACL,CAAC;QACJ,CAAC;QAED,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,mBAAmB,GAAG,gBAAgB;iBACzC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC;iBAC1D,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,OAAO,CAAC,MAAM,CACZ,sFAAsF,mBAAmB,GAAG,EAC5G,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE;oBACzC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,SAAqC,CACtC,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import type { InitialPermissions } from '@metamask/snaps-sdk';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n// Special case endowments that should be ignored.\nconst IGNORED_ENDOWMENTS = ['endowment:network-access'];\n\n/**\n * Check if the Snap exports handlers that are not requested in the manifest, or\n * if the Snap requests permissions for handlers that are not exported.\n */\nexport const unusedExports: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n const { handlerEndowments, exports } = context.options ?? {};\n\n // The handler endowments or exports must be provided for this check to be\n // performed.\n if (!handlerEndowments || !exports) {\n return;\n }\n\n // Endowments used based on the exports from the Snap. This is used to\n // filter endowments that are used by multiple handlers, e.g., the lifecycle\n // handlers.\n const usedEndowments = Object.entries(handlerEndowments)\n .filter(\n ([handler, endowment]) =>\n endowment === null || exports.includes(handler),\n )\n .map(([, endowment]) => endowment);\n\n const unusedHandlers = Object.entries(handlerEndowments)\n .filter(([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n exports.includes(handler) &&\n !files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ]\n );\n })\n .map(([handler, endowment]) => `${handler} (${endowment})`);\n\n const unusedEndowments = Object.entries(handlerEndowments).filter(\n ([handler, endowment]) => {\n if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {\n return false;\n }\n\n return (\n !usedEndowments.includes(endowment) &&\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ] &&\n !exports.includes(handler)\n );\n },\n );\n\n if (unusedHandlers.length > 0) {\n // We don't specify a fix function here, because:\n // 1. Removing the export from the Snap bundle is complicated, as it\n // requires AST manipulation.\n // 2. Adding the permission to the manifest is not always possible, as it\n // may require additional configuration in the manifest.\n context.report(\n `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(\n ', ',\n )}.`,\n );\n }\n\n if (unusedEndowments.length > 0) {\n const formattedEndowments = unusedEndowments\n .map(([handler, endowment]) => `${handler} (${endowment})`)\n .join(', ');\n\n context.report(\n `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`,\n ({ manifest }) => {\n unusedEndowments.forEach(([, endowment]) => {\n delete manifest.initialPermissions[\n endowment as keyof InitialPermissions\n ];\n });\n\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;
|
|
1
|
+
{"version":3,"file":"unused-exports.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAKxD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,aAoF3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;
|
|
1
|
+
{"version":3,"file":"unused-exports.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAKxD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,aAoF3B,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Special case endowments that should be ignored.
|
|
2
|
+
const IGNORED_ENDOWMENTS = ['endowment:network-access'];
|
|
1
3
|
/**
|
|
2
4
|
* Check if the Snap exports handlers that are not requested in the manifest, or
|
|
3
5
|
* if the Snap requests permissions for handlers that are not exported.
|
|
@@ -11,6 +13,12 @@ export const unusedExports = {
|
|
|
11
13
|
if (!handlerEndowments || !exports) {
|
|
12
14
|
return;
|
|
13
15
|
}
|
|
16
|
+
// Endowments used based on the exports from the Snap. This is used to
|
|
17
|
+
// filter endowments that are used by multiple handlers, e.g., the lifecycle
|
|
18
|
+
// handlers.
|
|
19
|
+
const usedEndowments = Object.entries(handlerEndowments)
|
|
20
|
+
.filter(([handler, endowment]) => endowment === null || exports.includes(handler))
|
|
21
|
+
.map(([, endowment]) => endowment);
|
|
14
22
|
const unusedHandlers = Object.entries(handlerEndowments)
|
|
15
23
|
.filter(([handler, endowment]) => {
|
|
16
24
|
if (endowment === null) {
|
|
@@ -21,10 +29,12 @@ export const unusedExports = {
|
|
|
21
29
|
})
|
|
22
30
|
.map(([handler, endowment]) => `${handler} (${endowment})`);
|
|
23
31
|
const unusedEndowments = Object.entries(handlerEndowments).filter(([handler, endowment]) => {
|
|
24
|
-
if (endowment === null) {
|
|
32
|
+
if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {
|
|
25
33
|
return false;
|
|
26
34
|
}
|
|
27
|
-
return (
|
|
35
|
+
return (!usedEndowments.includes(endowment) &&
|
|
36
|
+
files.manifest.result.initialPermissions[endowment] &&
|
|
37
|
+
!exports.includes(handler));
|
|
28
38
|
});
|
|
29
39
|
if (unusedHandlers.length > 0) {
|
|
30
40
|
// We don't specify a fix function here, because:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,QAAQ,EAAE,SAAS;IACnB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QAE7D,0EAA0E;QAC1E,aAAa;QACb,IAAI,CAAC,iBAAiB,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;aACrD,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE;YAC/B,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC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,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,mBAAmB,GAAG,gBAAgB;iBACzC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC;iBAC1D,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,OAAO,CAAC,MAAM,CACZ,sFAAsF,mBAAmB,GAAG,EAC5G,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE;oBACzC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,SAAqC,CACtC,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import type { InitialPermissions } from '@metamask/snaps-sdk';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n// Special case endowments that should be ignored.\nconst IGNORED_ENDOWMENTS = ['endowment:network-access'];\n\n/**\n * Check if the Snap exports handlers that are not requested in the manifest, or\n * if the Snap requests permissions for handlers that are not exported.\n */\nexport const unusedExports: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n const { handlerEndowments, exports } = context.options ?? {};\n\n // The handler endowments or exports must be provided for this check to be\n // performed.\n if (!handlerEndowments || !exports) {\n return;\n }\n\n // Endowments used based on the exports from the Snap. This is used to\n // filter endowments that are used by multiple handlers, e.g., the lifecycle\n // handlers.\n const usedEndowments = Object.entries(handlerEndowments)\n .filter(\n ([handler, endowment]) =>\n endowment === null || exports.includes(handler),\n )\n .map(([, endowment]) => endowment);\n\n const unusedHandlers = Object.entries(handlerEndowments)\n .filter(([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n exports.includes(handler) &&\n !files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ]\n );\n })\n .map(([handler, endowment]) => `${handler} (${endowment})`);\n\n const unusedEndowments = Object.entries(handlerEndowments).filter(\n ([handler, endowment]) => {\n if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {\n return false;\n }\n\n return (\n !usedEndowments.includes(endowment) &&\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ] &&\n !exports.includes(handler)\n );\n },\n );\n\n if (unusedHandlers.length > 0) {\n // We don't specify a fix function here, because:\n // 1. Removing the export from the Snap bundle is complicated, as it\n // requires AST manipulation.\n // 2. Adding the permission to the manifest is not always possible, as it\n // may require additional configuration in the manifest.\n context.report(\n `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(\n ', ',\n )}.`,\n );\n }\n\n if (unusedEndowments.length > 0) {\n const formattedEndowments = unusedEndowments\n .map(([handler, endowment]) => `${handler} (${endowment})`)\n .join(', ');\n\n context.report(\n `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`,\n ({ manifest }) => {\n unusedEndowments.forEach(([, endowment]) => {\n delete manifest.initialPermissions[\n endowment as keyof InitialPermissions\n ];\n });\n\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
package/dist/time.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.cjs","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,iCAA2C;AAE3C;;GAEG;AACU,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EACzC,IAAA,oBAAM,GAAE,EACR,mBAAmB,EACnB,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,cAAc,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CAAC;IACzC,CAAC;
|
|
1
|
+
{"version":3,"file":"time.cjs","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,iCAA2C;AAE3C;;GAEG;AACU,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EACzC,IAAA,oBAAM,GAAE,EACR,mBAAmB,EACnB,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,cAAc,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CAAC;IACzC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3E,MAAM,UAAU,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE3C,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,2BAA2B,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,+EAA+E;QAC/E,OAAO,8CAA8C,CAAC;IACxD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,KAAa;IACnD,MAAM,IAAI,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAExD,kDAAkD;IAClD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;QAClC,oBAAoB,EAAE,IAAI;KAC3B,CAAW,CAAC;AACf,CAAC;AAPD,0DAOC","sourcesContent":["import { refine, string } from '@metamask/superstruct';\nimport { DateTime, Duration } from 'luxon';\n\n/**\n * Refines a string as an ISO 8601 duration.\n */\nexport const ISO8601DurationStruct = refine(\n string(),\n 'ISO 8601 duration',\n (value) => {\n const parsedDuration = Duration.fromISO(value);\n if (!parsedDuration.isValid) {\n return 'Not a valid ISO 8601 duration';\n }\n\n return true;\n },\n);\n\n/**\n * Regex to match the offset part of an ISO 8601 date.\n */\nconst offsetRegex = /Z|([+-]\\d{2}:?\\d{2})$/u;\n\n/**\n * Refines a string as an ISO 8601 date.\n */\nexport const ISO8601DateStruct = refine(string(), 'ISO 8601 date', (value) => {\n const parsedDate = DateTime.fromISO(value);\n\n if (!parsedDate.isValid) {\n return 'Not a valid ISO 8601 date';\n }\n\n if (!offsetRegex.test(value)) {\n // Luxon doesn't have a reliable way to check if timezone info was not provided\n return 'ISO 8601 date must have timezone information';\n }\n\n return true;\n});\n\n/**\n * Remove millisecond precision from an ISO 8601 string.\n *\n * @param value - A valid ISO 8601 date.\n * @returns A valid ISO 8601 date with millisecond precision removed.\n */\nexport function toCensoredISO8601String(value: string) {\n const date = DateTime.fromISO(value, { setZone: true });\n\n // Make sure any millisecond precision is removed.\n return date.startOf('second').toISO({\n suppressMilliseconds: true,\n }) as string;\n}\n"]}
|
package/dist/time.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.cts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"time.d.cts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,qBAAqB,sDAWjC,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,iBAAiB,sDAa5B,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,UAOpD"}
|
package/dist/time.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.mts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"time.d.mts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,qBAAqB,sDAWjC,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,iBAAiB,sDAa5B,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,UAOpD"}
|
package/dist/time.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.mjs","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AACvD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CACzC,MAAM,EAAE,EACR,mBAAmB,EACnB,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CAAC;IACzC,CAAC;
|
|
1
|
+
{"version":3,"file":"time.mjs","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AACvD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CACzC,MAAM,EAAE,EACR,mBAAmB,EACnB,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CAAC;IACzC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3E,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE3C,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,2BAA2B,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,+EAA+E;QAC/E,OAAO,8CAA8C,CAAC;IACxD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAExD,kDAAkD;IAClD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;QAClC,oBAAoB,EAAE,IAAI;KAC3B,CAAW,CAAC;AACf,CAAC","sourcesContent":["import { refine, string } from '@metamask/superstruct';\nimport { DateTime, Duration } from 'luxon';\n\n/**\n * Refines a string as an ISO 8601 duration.\n */\nexport const ISO8601DurationStruct = refine(\n string(),\n 'ISO 8601 duration',\n (value) => {\n const parsedDuration = Duration.fromISO(value);\n if (!parsedDuration.isValid) {\n return 'Not a valid ISO 8601 duration';\n }\n\n return true;\n },\n);\n\n/**\n * Regex to match the offset part of an ISO 8601 date.\n */\nconst offsetRegex = /Z|([+-]\\d{2}:?\\d{2})$/u;\n\n/**\n * Refines a string as an ISO 8601 date.\n */\nexport const ISO8601DateStruct = refine(string(), 'ISO 8601 date', (value) => {\n const parsedDate = DateTime.fromISO(value);\n\n if (!parsedDate.isValid) {\n return 'Not a valid ISO 8601 date';\n }\n\n if (!offsetRegex.test(value)) {\n // Luxon doesn't have a reliable way to check if timezone info was not provided\n return 'ISO 8601 date must have timezone information';\n }\n\n return true;\n});\n\n/**\n * Remove millisecond precision from an ISO 8601 string.\n *\n * @param value - A valid ISO 8601 date.\n * @returns A valid ISO 8601 date with millisecond precision removed.\n */\nexport function toCensoredISO8601String(value: string) {\n const date = DateTime.fromISO(value, { setZone: true });\n\n // Make sure any millisecond precision is removed.\n return date.startOf('second').toISO({\n suppressMilliseconds: true,\n }) as string;\n}\n"]}
|
package/dist/types.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WALLET_SNAP_PERMISSION_KEY = exports.isValidUrl = exports.uri = exports.SNAP_STREAM_NAMES = exports.SnapIdPrefixes = exports.NpmSnapPackageJsonStruct = exports.NameStruct = exports.NpmSnapFileNames = void 0;
|
|
4
|
+
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
4
5
|
const superstruct_1 = require("@metamask/superstruct");
|
|
5
6
|
const utils_1 = require("@metamask/utils");
|
|
6
7
|
var NpmSnapFileNames;
|
|
@@ -36,15 +37,18 @@ var SNAP_STREAM_NAMES;
|
|
|
36
37
|
SNAP_STREAM_NAMES["JSON_RPC"] = "jsonRpc";
|
|
37
38
|
SNAP_STREAM_NAMES["COMMAND"] = "command";
|
|
38
39
|
})(SNAP_STREAM_NAMES || (exports.SNAP_STREAM_NAMES = SNAP_STREAM_NAMES = {}));
|
|
39
|
-
const uri = (opts = {}) => (0, superstruct_1.refine)((0, superstruct_1.
|
|
40
|
+
const uri = (opts = {}) => (0, superstruct_1.refine)((0, superstruct_1.string)(), 'uri', (value) => {
|
|
40
41
|
try {
|
|
41
42
|
const url = new URL(value);
|
|
42
43
|
const UrlStruct = (0, superstruct_1.type)(opts);
|
|
43
44
|
(0, superstruct_1.assert)(url, UrlStruct);
|
|
44
45
|
return true;
|
|
45
46
|
}
|
|
46
|
-
catch {
|
|
47
|
-
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof superstruct_1.StructError) {
|
|
49
|
+
return (0, snaps_sdk_1.getErrorMessage)(error);
|
|
50
|
+
}
|
|
51
|
+
return `Expected URL, got "${value.toString()}"`;
|
|
48
52
|
}
|
|
49
53
|
});
|
|
50
54
|
exports.uri = uri;
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,mDAAsD;AACtD,uDAS+B;AAG/B,2CAA+D;AAQ/D,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,gDAA4B,CAAA;IAC5B,mDAA+B,CAAA;AACjC,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B;AAEY,QAAA,UAAU,GAAG,IAAA,kBAAI,EAC5B,IAAA,qBAAa,EACX,WAAW,EACX,6DAA6D,CAC9D,EACD,CAAC,EACD,GAAG,CACJ,CAAC;AAEF,2EAA2E;AAC3E,sBAAsB;AACT,QAAA,wBAAwB,GAAG,IAAA,kBAAI,EAAC;IAC3C,OAAO,EAAE,qBAAa;IACtB,IAAI,EAAE,kBAAU;IAChB,IAAI,EAAE,IAAA,sBAAQ,EAAC,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC3C,UAAU,EAAE,IAAA,sBAAQ,EAClB,IAAA,kBAAI,EAAC;QACH,IAAI,EAAE,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,QAAQ,CAAC;QACjC,GAAG,EAAE,IAAA,kBA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0BAA0B,GAAG,aAAa,CAAC","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport {\n is,\n optional,\n refine,\n size,\n string,\n type,\n assert as assertSuperstruct,\n StructError,\n} from '@metamask/superstruct';\nimport type { Infer, Struct } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { definePattern, VersionStruct } from '@metamask/utils';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n definePattern(\n 'Snap Name',\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n type({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile<LocalizationFile>[];\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n SnapFiles,\n 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(string(), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch (error) {\n if (error instanceof StructError) {\n return getErrorMessage(error);\n }\n return `Expected URL, got \"${value.toString()}\"`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -80,7 +80,7 @@ type UriOptions<Type extends string> = {
|
|
|
80
80
|
pathname?: Struct<Type>;
|
|
81
81
|
search?: Struct<Type>;
|
|
82
82
|
};
|
|
83
|
-
export declare const uri: (opts?: UriOptions<any>) => Struct<string
|
|
83
|
+
export declare const uri: (opts?: UriOptions<any>) => Struct<string, null>;
|
|
84
84
|
/**
|
|
85
85
|
* Returns whether a given value is a valid URL.
|
|
86
86
|
*
|
|
@@ -88,7 +88,7 @@ export declare const uri: (opts?: UriOptions<any>) => Struct<string | URL, null>
|
|
|
88
88
|
* @param opts - Optional constraints for url checking.
|
|
89
89
|
* @returns Whether `url` is valid URL or not.
|
|
90
90
|
*/
|
|
91
|
-
export declare function isValidUrl(url: unknown, opts?: UriOptions<any>): url is string
|
|
91
|
+
export declare function isValidUrl(url: unknown, opts?: UriOptions<any>): url is string;
|
|
92
92
|
export declare const WALLET_SNAP_PERMISSION_KEY = "wallet_snap";
|
|
93
93
|
export type SnapsPermissionRequest = {
|
|
94
94
|
[WALLET_SNAP_PERMISSION_KEY]: {
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAkB;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,6BAAmB;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAAuB;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,6BAAmB;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD,oBAAY,gBAAgB;IAC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CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IACtD,UAAU,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;AAEjC,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;AAE1E,KAAK,UAAU,CAAC,IAAI,SAAS,MAAM,IAAI;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,GAAG,UAAU,WAAW,GAAG,CAAC,yBAcrC,CAAC;AAEL;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,OAAO,EACZ,IAAI,GAAE,UAAU,CAAC,GAAG,CAAM,GACzB,GAAG,IAAI,MAAM,CAEf;AAGD,eAAO,MAAM,0BAA0B,gBAAgB,CAAC;AAExD,MAAM,MAAM,sBAAsB,GAAG;IACnC,CAAC,0BAA0B,CAAC,EAAE;QAC5B,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC;gBAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;aAC7B;SACF,CAAC;KACH,CAAC;CACH,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -80,7 +80,7 @@ type UriOptions<Type extends string> = {
|
|
|
80
80
|
pathname?: Struct<Type>;
|
|
81
81
|
search?: Struct<Type>;
|
|
82
82
|
};
|
|
83
|
-
export declare const uri: (opts?: UriOptions<any>) => Struct<string
|
|
83
|
+
export declare const uri: (opts?: UriOptions<any>) => Struct<string, null>;
|
|
84
84
|
/**
|
|
85
85
|
* Returns whether a given value is a valid URL.
|
|
86
86
|
*
|
|
@@ -88,7 +88,7 @@ export declare const uri: (opts?: UriOptions<any>) => Struct<string | URL, null>
|
|
|
88
88
|
* @param opts - Optional constraints for url checking.
|
|
89
89
|
* @returns Whether `url` is valid URL or not.
|
|
90
90
|
*/
|
|
91
|
-
export declare function isValidUrl(url: unknown, opts?: UriOptions<any>): url is string
|
|
91
|
+
export declare function isValidUrl(url: unknown, opts?: UriOptions<any>): url is string;
|
|
92
92
|
export declare const WALLET_SNAP_PERMISSION_KEY = "wallet_snap";
|
|
93
93
|
export type SnapsPermissionRequest = {
|
|
94
94
|
[WALLET_SNAP_PERMISSION_KEY]: {
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAkB;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,6BAAmB;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAAuB;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,6BAAmB;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD,oBAAY,gBAAgB;IAC1B,WAAW,iBAAiB;IAC5B,QAAQ,uBAAuB;CAChC;AAED,eAAO,MAAM,UAAU,sBAOtB,CAAC;AAIF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;EAUnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,GACrE,MAAM,CAAC,MAA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SAAS,MAAM,IAAI;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,GAAG,UAAU,WAAW,GAAG,CAAC,yBAcrC,CAAC;AAEL;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,OAAO,EACZ,IAAI,GAAE,UAAU,CAAC,GAAG,CAAM,GACzB,GAAG,IAAI,MAAM,CAEf;AAGD,eAAO,MAAM,0BAA0B,gBAAgB,CAAC;AAExD,MAAM,MAAM,sBAAsB,GAAG;IACnC,CAAC,0BAA0B,CAAC,EAAE;QAC5B,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC;gBAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;aAC7B;SACF,CAAC;KACH,CAAC;CACH,CAAC"}
|
package/dist/types.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getErrorMessage } from "@metamask/snaps-sdk";
|
|
2
|
+
import { is, optional, refine, size, string, type, assert as assertSuperstruct, StructError } from "@metamask/superstruct";
|
|
2
3
|
import { definePattern, VersionStruct } from "@metamask/utils";
|
|
3
4
|
export var NpmSnapFileNames;
|
|
4
5
|
(function (NpmSnapFileNames) {
|
|
@@ -33,15 +34,18 @@ export var SNAP_STREAM_NAMES;
|
|
|
33
34
|
SNAP_STREAM_NAMES["JSON_RPC"] = "jsonRpc";
|
|
34
35
|
SNAP_STREAM_NAMES["COMMAND"] = "command";
|
|
35
36
|
})(SNAP_STREAM_NAMES || (SNAP_STREAM_NAMES = {}));
|
|
36
|
-
export const uri = (opts = {}) => refine(
|
|
37
|
+
export const uri = (opts = {}) => refine(string(), 'uri', (value) => {
|
|
37
38
|
try {
|
|
38
39
|
const url = new URL(value);
|
|
39
40
|
const UrlStruct = type(opts);
|
|
40
41
|
assertSuperstruct(url, UrlStruct);
|
|
41
42
|
return true;
|
|
42
43
|
}
|
|
43
|
-
catch {
|
|
44
|
-
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof StructError) {
|
|
46
|
+
return getErrorMessage(error);
|
|
47
|
+
}
|
|
48
|
+
return `Expected URL, got "${value.toString()}"`;
|
|
45
49
|
}
|
|
46
50
|
});
|
|
47
51
|
/**
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,4BAA4B;AACtD,OAAO,EACL,EAAE,EACF,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,MAAM,IAAI,iBAAiB,EAC3B,WAAW,EACZ,8BAA8B;AAG/B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,wBAAwB;AAQ/D,MAAM,CAAN,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,gDAA4B,CAAA;IAC5B,mDAA+B,CAAA;AACjC,CAAC,EAHW,gBAAgB,KAAhB,gBAAgB,QAG3B;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAC5B,aAAa,CACX,WAAW,EACX,6DAA6D,CAC9D,EACD,CAAC,EACD,GAAG,CACJ,CAAC;AAEF,2EAA2E;AAC3E,sBAAsB;AACtB,MAAM,CAAC,MAA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K,CAAC,QAAQ,EAAE,GAAG,CAAC;IACnD,CAAC;AACH,CAAC,CAAC,CAAC;AAEL;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,GAAY,EACZ,OAAwB,EAAE;IAE1B,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED,+CAA+C;AAC/C,MAAM,CAAC,MAAM,0BAA0B,GAAG,aAAa,CAAC","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport {\n is,\n optional,\n refine,\n size,\n string,\n type,\n assert as assertSuperstruct,\n StructError,\n} from '@metamask/superstruct';\nimport type { Infer, Struct } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { definePattern, VersionStruct } from '@metamask/utils';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n definePattern(\n 'Snap Name',\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n type({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile<LocalizationFile>[];\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n SnapFiles,\n 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(string(), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch (error) {\n if (error instanceof StructError) {\n return getErrorMessage(error);\n }\n return `Expected URL, got \"${value.toString()}\"`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"]}
|