@metamask/snaps-utils 8.1.1 → 8.3.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 +137 -1
- package/dist/currency.cjs +20 -0
- package/dist/currency.cjs.map +1 -0
- package/dist/currency.d.cts +11 -0
- package/dist/currency.d.cts.map +1 -0
- package/dist/currency.d.mts +11 -0
- package/dist/currency.d.mts.map +1 -0
- package/dist/currency.mjs +16 -0
- package/dist/currency.mjs.map +1 -0
- package/dist/handlers.d.cts +7 -0
- package/dist/handlers.d.cts.map +1 -1
- package/dist/handlers.d.mts +7 -0
- package/dist/handlers.d.mts.map +1 -1
- package/dist/iframe.cjs +8 -5
- package/dist/iframe.cjs.map +1 -1
- package/dist/iframe.d.cts +12 -4
- package/dist/iframe.d.cts.map +1 -1
- package/dist/iframe.d.mts +12 -4
- package/dist/iframe.d.mts.map +1 -1
- package/dist/iframe.mjs +8 -5
- package/dist/iframe.mjs.map +1 -1
- package/dist/iframe.test.browser.cjs +36 -1
- package/dist/iframe.test.browser.cjs.map +1 -1
- package/dist/iframe.test.browser.mjs +36 -1
- package/dist/iframe.test.browser.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/manifest/validation.cjs +1 -1
- package/dist/manifest/validation.cjs.map +1 -1
- package/dist/manifest/validation.mjs +1 -1
- package/dist/manifest/validation.mjs.map +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -2
- package/dist/types.mjs.map +1 -1
- package/dist/ui.cjs +26 -8
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.cts +8 -3
- package/dist/ui.d.cts.map +1 -1
- package/dist/ui.d.mts +8 -3
- package/dist/ui.d.mts.map +1 -1
- package/dist/ui.mjs +26 -8
- package/dist/ui.mjs.map +1 -1
- package/dist/url.cjs +76 -0
- package/dist/url.cjs.map +1 -0
- package/dist/url.d.cts +20 -0
- package/dist/url.d.cts.map +1 -0
- package/dist/url.d.mts +20 -0
- package/dist/url.d.mts.map +1 -0
- package/dist/url.mjs +72 -0
- package/dist/url.mjs.map +1 -0
- package/package.json +31 -15
package/dist/handlers.d.mts
CHANGED
|
@@ -152,6 +152,7 @@ export declare const OnTransactionResponseWithContentStruct: import("@metamask/s
|
|
|
152
152
|
}, "Radio">>;
|
|
153
153
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
154
154
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
155
|
+
size?: "md" | "lg" | undefined;
|
|
155
156
|
}, "Heading">;
|
|
156
157
|
severity?: SeverityLevel | undefined;
|
|
157
158
|
}, {
|
|
@@ -235,6 +236,7 @@ export declare const OnTransactionResponseWithContentStruct: import("@metamask/s
|
|
|
235
236
|
}, "Radio">>;
|
|
236
237
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
237
238
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
239
|
+
size?: "md" | "lg" | undefined;
|
|
238
240
|
}, "Heading">, null>;
|
|
239
241
|
severity: import("@metamask/superstruct").Struct<SeverityLevel | undefined, SeverityLevel>;
|
|
240
242
|
}>;
|
|
@@ -322,6 +324,7 @@ export declare const OnTransactionResponseStruct: import("@metamask/superstruct"
|
|
|
322
324
|
}, "Radio">>;
|
|
323
325
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
324
326
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
327
|
+
size?: "md" | "lg" | undefined;
|
|
325
328
|
}, "Heading">;
|
|
326
329
|
severity?: SeverityLevel | undefined;
|
|
327
330
|
} | null, null>;
|
|
@@ -409,6 +412,7 @@ export declare const OnSignatureResponseStruct: import("@metamask/superstruct").
|
|
|
409
412
|
}, "Radio">>;
|
|
410
413
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
411
414
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
415
|
+
size?: "md" | "lg" | undefined;
|
|
412
416
|
}, "Heading">;
|
|
413
417
|
severity?: SeverityLevel | undefined;
|
|
414
418
|
} | null, null>;
|
|
@@ -493,6 +497,7 @@ export declare const OnHomePageResponseWithContentStruct: import("@metamask/supe
|
|
|
493
497
|
}, "Radio">>;
|
|
494
498
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
495
499
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
500
|
+
size?: "md" | "lg" | undefined;
|
|
496
501
|
}, "Heading">;
|
|
497
502
|
}, {
|
|
498
503
|
content: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
@@ -575,6 +580,7 @@ export declare const OnHomePageResponseWithContentStruct: import("@metamask/supe
|
|
|
575
580
|
}, "Radio">>;
|
|
576
581
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
577
582
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
583
|
+
size?: "md" | "lg" | undefined;
|
|
578
584
|
}, "Heading">, null>;
|
|
579
585
|
}>;
|
|
580
586
|
export declare const OnHomePageResponseWithIdStruct: import("@metamask/superstruct").Struct<{
|
|
@@ -663,6 +669,7 @@ export declare const OnHomePageResponseStruct: import("@metamask/superstruct").S
|
|
|
663
669
|
}, "Radio">>;
|
|
664
670
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
665
671
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
672
|
+
size?: "md" | "lg" | undefined;
|
|
666
673
|
}, "Heading">;
|
|
667
674
|
} | {
|
|
668
675
|
id: string;
|
package/dist/handlers.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EAEpB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,EAA4B,aAAa,EAAE,4BAA4B;AAa9E,OAAO,KAAK,EAAE,WAAW,EAAE,4BAAwB;AACnD,OAAO,EAAE,WAAW,EAAE,4BAAwB;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,YAAY;;;;yCAIG,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;CAIzB,CAAC;AAEX,eAAO,MAAM,mCAAmC;;;;EAE9C,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;;;;EAK7C,CAAC;AAEF,eAAO,MAAM,sCAAsC
|
|
1
|
+
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings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ads, but the promise should be wrapped in
|
|
7
7
|
* an initialization timeout in the SnapController.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
9
|
+
*
|
|
10
|
+
* @param options - The options for createWindow.
|
|
11
|
+
* @param options.uri - The iframe URI.
|
|
12
|
+
* @param options.id - The ID to assign to the iframe.
|
|
13
|
+
* @param options.sandbox - Whether to enable the sandbox attribute.
|
|
14
|
+
* @param options.testId - The data-testid attribute to assign to the iframe.
|
|
12
15
|
* @returns A promise that resolves to the contentWindow of the iframe.
|
|
13
16
|
*/
|
|
14
|
-
async function createWindow(uri, id, sandbox = true) {
|
|
17
|
+
async function createWindow({ uri, id, sandbox = true, testId = 'snaps-iframe', }) {
|
|
15
18
|
return await new Promise((resolve, reject) => {
|
|
16
19
|
const iframe = document.createElement('iframe');
|
|
17
20
|
// The order of operations appears to matter for everything except this
|
|
18
21
|
// attribute. We may as well set it here.
|
|
19
22
|
iframe.setAttribute('id', id);
|
|
20
|
-
iframe.setAttribute('data-testid',
|
|
23
|
+
iframe.setAttribute('data-testid', testId);
|
|
21
24
|
if (sandbox) {
|
|
22
25
|
// For the sandbox property to have any effect it needs to be set before the iframe is appended.
|
|
23
26
|
// We apply this property as a principle of least authority (POLA)
|
package/dist/iframe.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.cjs","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"iframe.cjs","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAO,GAAG,IAAI,EACd,MAAM,GAAG,cAAc,GAMxB;IACC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAE3C,IAAI,OAAO,EAAE,CAAC;YACZ,gGAAgG;YAChG,kEAAkE;YAClE,WAAW;YACX,qFAAqF;YACrF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAClD,CAAC;QAED,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YACnC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACzB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,qEAAqE;gBACrE,mBAAmB;gBACnB,MAAM,CACJ,IAAI,KAAK,CACP,qDAAqD,EAAE,IAAI,CAC5D,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAtDD,oCAsDC","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n *\n * @param options - The options for createWindow.\n * @param options.uri - The iframe URI.\n * @param options.id - The ID to assign to the iframe.\n * @param options.sandbox - Whether to enable the sandbox attribute.\n * @param options.testId - The data-testid attribute to assign to the iframe.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow({\n uri,\n id,\n sandbox = true,\n testId = 'snaps-iframe',\n}: {\n uri: string;\n id: string;\n sandbox?: boolean;\n testId?: string;\n}): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', testId);\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener('load', () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n });\n });\n}\n"]}
|
package/dist/iframe.d.cts
CHANGED
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|
* forever if the iframe never loads, but the promise should be wrapped in
|
|
4
4
|
* an initialization timeout in the SnapController.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
6
|
+
*
|
|
7
|
+
* @param options - The options for createWindow.
|
|
8
|
+
* @param options.uri - The iframe URI.
|
|
9
|
+
* @param options.id - The ID to assign to the iframe.
|
|
10
|
+
* @param options.sandbox - Whether to enable the sandbox attribute.
|
|
11
|
+
* @param options.testId - The data-testid attribute to assign to the iframe.
|
|
9
12
|
* @returns A promise that resolves to the contentWindow of the iframe.
|
|
10
13
|
*/
|
|
11
|
-
export declare function createWindow(uri
|
|
14
|
+
export declare function createWindow({ uri, id, sandbox, testId, }: {
|
|
15
|
+
uri: string;
|
|
16
|
+
id: string;
|
|
17
|
+
sandbox?: boolean;
|
|
18
|
+
testId?: string;
|
|
19
|
+
}): Promise<Window>;
|
|
12
20
|
//# sourceMappingURL=iframe.d.cts.map
|
package/dist/iframe.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.d.cts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"iframe.d.cts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAc,EACd,MAAuB,GACxB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,CAAC,CA4ClB"}
|
package/dist/iframe.d.mts
CHANGED
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|
* forever if the iframe never loads, but the promise should be wrapped in
|
|
4
4
|
* an initialization timeout in the SnapController.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
6
|
+
*
|
|
7
|
+
* @param options - The options for createWindow.
|
|
8
|
+
* @param options.uri - The iframe URI.
|
|
9
|
+
* @param options.id - The ID to assign to the iframe.
|
|
10
|
+
* @param options.sandbox - Whether to enable the sandbox attribute.
|
|
11
|
+
* @param options.testId - The data-testid attribute to assign to the iframe.
|
|
9
12
|
* @returns A promise that resolves to the contentWindow of the iframe.
|
|
10
13
|
*/
|
|
11
|
-
export declare function createWindow(uri
|
|
14
|
+
export declare function createWindow({ uri, id, sandbox, testId, }: {
|
|
15
|
+
uri: string;
|
|
16
|
+
id: string;
|
|
17
|
+
sandbox?: boolean;
|
|
18
|
+
testId?: string;
|
|
19
|
+
}): Promise<Window>;
|
|
12
20
|
//# sourceMappingURL=iframe.d.mts.map
|
package/dist/iframe.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.d.mts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"iframe.d.mts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAc,EACd,MAAuB,GACxB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,CAAC,CA4ClB"}
|
package/dist/iframe.mjs
CHANGED
|
@@ -3,18 +3,21 @@
|
|
|
3
3
|
* forever if the iframe never loads, but the promise should be wrapped in
|
|
4
4
|
* an initialization timeout in the SnapController.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
6
|
+
*
|
|
7
|
+
* @param options - The options for createWindow.
|
|
8
|
+
* @param options.uri - The iframe URI.
|
|
9
|
+
* @param options.id - The ID to assign to the iframe.
|
|
10
|
+
* @param options.sandbox - Whether to enable the sandbox attribute.
|
|
11
|
+
* @param options.testId - The data-testid attribute to assign to the iframe.
|
|
9
12
|
* @returns A promise that resolves to the contentWindow of the iframe.
|
|
10
13
|
*/
|
|
11
|
-
export async function createWindow(uri, id, sandbox = true) {
|
|
14
|
+
export async function createWindow({ uri, id, sandbox = true, testId = 'snaps-iframe', }) {
|
|
12
15
|
return await new Promise((resolve, reject) => {
|
|
13
16
|
const iframe = document.createElement('iframe');
|
|
14
17
|
// The order of operations appears to matter for everything except this
|
|
15
18
|
// attribute. We may as well set it here.
|
|
16
19
|
iframe.setAttribute('id', id);
|
|
17
|
-
iframe.setAttribute('data-testid',
|
|
20
|
+
iframe.setAttribute('data-testid', testId);
|
|
18
21
|
if (sandbox) {
|
|
19
22
|
// For the sandbox property to have any effect it needs to be set before the iframe is appended.
|
|
20
23
|
// We apply this property as a principle of least authority (POLA)
|
package/dist/iframe.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.mjs","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"iframe.mjs","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAO,GAAG,IAAI,EACd,MAAM,GAAG,cAAc,GAMxB;IACC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAE3C,IAAI,OAAO,EAAE,CAAC;YACZ,gGAAgG;YAChG,kEAAkE;YAClE,WAAW;YACX,qFAAqF;YACrF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAClD,CAAC;QAED,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YACnC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACzB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,qEAAqE;gBACrE,mBAAmB;gBACnB,MAAM,CACJ,IAAI,KAAK,CACP,qDAAqD,EAAE,IAAI,CAC5D,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n *\n * @param options - The options for createWindow.\n * @param options.uri - The iframe URI.\n * @param options.id - The ID to assign to the iframe.\n * @param options.sandbox - Whether to enable the sandbox attribute.\n * @param options.testId - The data-testid attribute to assign to the iframe.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow({\n uri,\n id,\n sandbox = true,\n testId = 'snaps-iframe',\n}: {\n uri: string;\n id: string;\n sandbox?: boolean;\n testId?: string;\n}): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', testId);\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener('load', () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n });\n });\n}\n"]}
|
|
@@ -4,12 +4,47 @@ const iframe_1 = require("./iframe.cjs");
|
|
|
4
4
|
const IFRAME_URL = `http://localhost:4569`;
|
|
5
5
|
const MOCK_JOB_ID = 'job-id';
|
|
6
6
|
describe('createWindow', () => {
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
9
|
+
if (iframe) {
|
|
10
|
+
document.body.removeChild(iframe);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
7
13
|
it('creates an iframe window with the provided job ID as the iframe ID', async () => {
|
|
8
|
-
const window = await (0, iframe_1.createWindow)(IFRAME_URL, MOCK_JOB_ID);
|
|
14
|
+
const window = await (0, iframe_1.createWindow)({ uri: IFRAME_URL, id: MOCK_JOB_ID });
|
|
9
15
|
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
10
16
|
expect(iframe).toBeDefined();
|
|
11
17
|
expect(iframe.contentWindow).toBe(window);
|
|
12
18
|
expect(iframe.id).toBe(MOCK_JOB_ID);
|
|
13
19
|
});
|
|
20
|
+
it('sets the sandbox attribute when the sandbox option is true', async () => {
|
|
21
|
+
await (0, iframe_1.createWindow)({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: true });
|
|
22
|
+
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
23
|
+
expect(iframe).toBeDefined();
|
|
24
|
+
expect(iframe.getAttribute('sandbox')).toBe('allow-scripts');
|
|
25
|
+
});
|
|
26
|
+
it('does not set the sandbox attribute when the sandbox option is false', async () => {
|
|
27
|
+
await (0, iframe_1.createWindow)({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: false });
|
|
28
|
+
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
29
|
+
expect(iframe).toBeDefined();
|
|
30
|
+
expect(iframe.getAttribute('sandbox')).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
it('sets the data-testid attribute when provided', async () => {
|
|
33
|
+
const testId = 'test-id';
|
|
34
|
+
await (0, iframe_1.createWindow)({
|
|
35
|
+
uri: IFRAME_URL,
|
|
36
|
+
id: MOCK_JOB_ID,
|
|
37
|
+
testId,
|
|
38
|
+
});
|
|
39
|
+
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
40
|
+
expect(iframe).toBeDefined();
|
|
41
|
+
expect(iframe.getAttribute('data-testid')).toBe(testId);
|
|
42
|
+
});
|
|
43
|
+
it('uses the default data-testid attribute when not provided', async () => {
|
|
44
|
+
await (0, iframe_1.createWindow)({ uri: IFRAME_URL, id: MOCK_JOB_ID });
|
|
45
|
+
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
46
|
+
expect(iframe).toBeDefined();
|
|
47
|
+
expect(iframe.getAttribute('data-testid')).toBe('snaps-iframe');
|
|
48
|
+
});
|
|
14
49
|
});
|
|
15
50
|
//# sourceMappingURL=iframe.test.browser.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.test.browser.cjs","sourceRoot":"","sources":["../src/iframe.test.browser.ts"],"names":[],"mappings":";;AAAA,yCAAwC;AAExC,MAAM,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AK,IAAI,EAAE;QACxE,MAAM,IAAA,qBAAY,EAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;QACzD,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAsB,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { createWindow } from './iframe';\n\nconst IFRAME_URL = `http://localhost:4569`;\n\nconst MOCK_JOB_ID = 'job-id';\n\ndescribe('createWindow', () => {\n afterEach(() => {\n const iframe = document.getElementById(MOCK_JOB_ID);\n if (iframe) {\n document.body.removeChild(iframe);\n }\n });\n\n it('creates an iframe window with the provided job ID as the iframe ID', async () => {\n const window = await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.contentWindow).toBe(window);\n expect(iframe.id).toBe(MOCK_JOB_ID);\n });\n\n it('sets the sandbox attribute when the sandbox option is true', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: true });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('sandbox')).toBe('allow-scripts');\n });\n\n it('does not set the sandbox attribute when the sandbox option is false', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: false });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('sandbox')).toBeNull();\n });\n\n it('sets the data-testid attribute when provided', async () => {\n const testId = 'test-id';\n\n await createWindow({\n uri: IFRAME_URL,\n id: MOCK_JOB_ID,\n testId,\n });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('data-testid')).toBe(testId);\n });\n\n it('uses the default data-testid attribute when not provided', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('data-testid')).toBe('snaps-iframe');\n });\n});\n"]}
|
|
@@ -2,12 +2,47 @@ import { createWindow } from "./iframe.mjs";
|
|
|
2
2
|
const IFRAME_URL = `http://localhost:4569`;
|
|
3
3
|
const MOCK_JOB_ID = 'job-id';
|
|
4
4
|
describe('createWindow', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
7
|
+
if (iframe) {
|
|
8
|
+
document.body.removeChild(iframe);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
5
11
|
it('creates an iframe window with the provided job ID as the iframe ID', async () => {
|
|
6
|
-
const window = await createWindow(IFRAME_URL, MOCK_JOB_ID);
|
|
12
|
+
const window = await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });
|
|
7
13
|
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
8
14
|
expect(iframe).toBeDefined();
|
|
9
15
|
expect(iframe.contentWindow).toBe(window);
|
|
10
16
|
expect(iframe.id).toBe(MOCK_JOB_ID);
|
|
11
17
|
});
|
|
18
|
+
it('sets the sandbox attribute when the sandbox option is true', async () => {
|
|
19
|
+
await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: true });
|
|
20
|
+
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
21
|
+
expect(iframe).toBeDefined();
|
|
22
|
+
expect(iframe.getAttribute('sandbox')).toBe('allow-scripts');
|
|
23
|
+
});
|
|
24
|
+
it('does not set the sandbox attribute when the sandbox option is false', async () => {
|
|
25
|
+
await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: false });
|
|
26
|
+
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
27
|
+
expect(iframe).toBeDefined();
|
|
28
|
+
expect(iframe.getAttribute('sandbox')).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
it('sets the data-testid attribute when provided', async () => {
|
|
31
|
+
const testId = 'test-id';
|
|
32
|
+
await createWindow({
|
|
33
|
+
uri: IFRAME_URL,
|
|
34
|
+
id: MOCK_JOB_ID,
|
|
35
|
+
testId,
|
|
36
|
+
});
|
|
37
|
+
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
38
|
+
expect(iframe).toBeDefined();
|
|
39
|
+
expect(iframe.getAttribute('data-testid')).toBe(testId);
|
|
40
|
+
});
|
|
41
|
+
it('uses the default data-testid attribute when not provided', async () => {
|
|
42
|
+
await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });
|
|
43
|
+
const iframe = document.getElementById(MOCK_JOB_ID);
|
|
44
|
+
expect(iframe).toBeDefined();
|
|
45
|
+
expect(iframe.getAttribute('data-testid')).toBe('snaps-iframe');
|
|
46
|
+
});
|
|
12
47
|
});
|
|
13
48
|
//# sourceMappingURL=iframe.test.browser.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe.test.browser.mjs","sourceRoot":"","sources":["../src/iframe.test.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAiB;AAExC,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,oEAAoE,EAAE,KAAK,IAAI,EAAE;QAClF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"iframe.test.browser.mjs","sourceRoot":"","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AAI,CAAC,cAAc,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { createWindow } from './iframe';\n\nconst IFRAME_URL = `http://localhost:4569`;\n\nconst MOCK_JOB_ID = 'job-id';\n\ndescribe('createWindow', () => {\n afterEach(() => {\n const iframe = document.getElementById(MOCK_JOB_ID);\n if (iframe) {\n document.body.removeChild(iframe);\n }\n });\n\n it('creates an iframe window with the provided job ID as the iframe ID', async () => {\n const window = await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.contentWindow).toBe(window);\n expect(iframe.id).toBe(MOCK_JOB_ID);\n });\n\n it('sets the sandbox attribute when the sandbox option is true', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: true });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('sandbox')).toBe('allow-scripts');\n });\n\n it('does not set the sandbox attribute when the sandbox option is false', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: false });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('sandbox')).toBeNull();\n });\n\n it('sets the data-testid attribute when provided', async () => {\n const testId = 'test-id';\n\n await createWindow({\n uri: IFRAME_URL,\n id: MOCK_JOB_ID,\n testId,\n });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('data-testid')).toBe(testId);\n });\n\n it('uses the default data-testid attribute when not provided', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('data-testid')).toBe('snaps-iframe');\n });\n});\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ __exportStar(require("./caveats.cjs"), exports);
|
|
|
22
22
|
__exportStar(require("./checksum.cjs"), exports);
|
|
23
23
|
__exportStar(require("./constants.cjs"), exports);
|
|
24
24
|
__exportStar(require("./cronjob.cjs"), exports);
|
|
25
|
+
__exportStar(require("./currency.cjs"), exports);
|
|
25
26
|
__exportStar(require("./deep-clone.cjs"), exports);
|
|
26
27
|
__exportStar(require("./default-endowments.cjs"), exports);
|
|
27
28
|
__exportStar(require("./derivation-paths.cjs"), exports);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,wDAAkC;AAClC,+CAAyB;AACzB,8CAAwB;AACxB,gDAA0B;AAC1B,iDAA2B;AAC3B,kDAA4B;AAC5B,gDAA0B;AAC1B,mDAA6B;AAC7B,2DAAqC;AACrC,yDAAmC;AACnC,gDAA0B;AAC1B,+CAAyB;AACzB,iDAA2B;AAC3B,sDAAgC;AAChC,+CAAyB;AACzB,6CAAuB;AACvB,iDAA2B;AAC3B,qDAA+B;AAC/B,gDAA0B;AAC1B,uDAA2B;AAC3B,kDAA4B;AAC5B,6CAAuB;AACvB,8CAAwB;AACxB,gDAA0B;AAC1B,gDAA0B;AAC1B,8CAAwB;AACxB,2CAAqB;AACrB,mDAA6B;AAC7B,iDAA2B;AAC3B,2DAA+B;AAC/B,gDAA0B","sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './constants';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport * from './promise';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,wDAAkC;AAClC,+CAAyB;AACzB,8CAAwB;AACxB,gDAA0B;AAC1B,iDAA2B;AAC3B,kDAA4B;AAC5B,gDAA0B;AAC1B,iDAA2B;AAC3B,mDAA6B;AAC7B,2DAAqC;AACrC,yDAAmC;AACnC,gDAA0B;AAC1B,+CAAyB;AACzB,iDAA2B;AAC3B,sDAAgC;AAChC,+CAAyB;AACzB,6CAAuB;AACvB,iDAA2B;AAC3B,qDAA+B;AAC/B,gDAA0B;AAC1B,uDAA2B;AAC3B,kDAA4B;AAC5B,6CAAuB;AACvB,8CAAwB;AACxB,gDAA0B;AAC1B,gDAA0B;AAC1B,8CAAwB;AACxB,2CAAqB;AACrB,mDAA6B;AAC7B,iDAA2B;AAC3B,2DAA+B;AAC/B,gDAA0B","sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './constants';\nexport * from './cronjob';\nexport * from './currency';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport * from './promise';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./caveats.cjs";
|
|
|
6
6
|
export * from "./checksum.cjs";
|
|
7
7
|
export * from "./constants.cjs";
|
|
8
8
|
export * from "./cronjob.cjs";
|
|
9
|
+
export * from "./currency.cjs";
|
|
9
10
|
export * from "./deep-clone.cjs";
|
|
10
11
|
export * from "./default-endowments.cjs";
|
|
11
12
|
export * from "./derivation-paths.cjs";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B"}
|
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./caveats.mjs";
|
|
|
6
6
|
export * from "./checksum.mjs";
|
|
7
7
|
export * from "./constants.mjs";
|
|
8
8
|
export * from "./cronjob.mjs";
|
|
9
|
+
export * from "./currency.mjs";
|
|
9
10
|
export * from "./deep-clone.mjs";
|
|
10
11
|
export * from "./default-endowments.mjs";
|
|
11
12
|
export * from "./derivation-paths.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B"}
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./caveats.mjs";
|
|
|
6
6
|
export * from "./checksum.mjs";
|
|
7
7
|
export * from "./constants.mjs";
|
|
8
8
|
export * from "./cronjob.mjs";
|
|
9
|
+
export * from "./currency.mjs";
|
|
9
10
|
export * from "./deep-clone.mjs";
|
|
10
11
|
export * from "./default-endowments.mjs";
|
|
11
12
|
export * from "./derivation-paths.mjs";
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B","sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './constants';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport * from './promise';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B","sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './constants';\nexport * from './cronjob';\nexport * from './currency';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport * from './promise';\n"]}
|
|
@@ -134,7 +134,7 @@ exports.SnapManifestStruct = (0, superstruct_1.object)({
|
|
|
134
134
|
version: utils_1.VersionStruct,
|
|
135
135
|
description: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, 280),
|
|
136
136
|
proposedName: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, 214),
|
|
137
|
-
repository: (0, superstruct_1.optional)((0, superstruct_1.
|
|
137
|
+
repository: (0, superstruct_1.optional)((0, superstruct_1.type)({
|
|
138
138
|
type: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
|
|
139
139
|
url: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
|
|
140
140
|
})),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":";;;AACA,iDAA6D;AAG7D,uDAiB+B;AAC/B,2CAOyB;AAEzB,wCAAmC;AACnC,4CAA6D;AAC7D,4CAA6E;AAC7E,8CAAqE;AACrE,gDAA6C;AAC7C,wCAAwC;AACxC,4CAA8D;AAC9D,wCAA6D;AAE7D,+EAA+E;AAC/E,gCAAgC;AAChC,MAAM,kBAAkB,GAAa;IACnC,2BAAiB;IACjB,sCAA4B;CAC7B,CAAC;AAEW,QAAA,oBAAoB,GAAa,CAAC,EAAE,CAAC,CAAC;AACnD,MAAM,eAAe,GAAe,4BAAoB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;IACzE,GAAG;IAC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IH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAA,oBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,IAAI,wBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AARD,oDAQC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,IAAA,oBAAM,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AAC3C,CAAC;AAHD,gDAGC","sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport { isValidBIP32PathSegment } from '@metamask/key-tree';\nimport type { EmptyObject, InitialPermissions } from '@metamask/snaps-sdk';\nimport type { Describe, Infer, Struct } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n create,\n enums,\n integer,\n is,\n literal,\n object,\n optional,\n refine,\n record,\n size,\n string,\n type,\n union,\n intersection,\n} from '@metamask/superstruct';\nimport {\n assertStruct,\n ChecksumStruct,\n VersionStruct,\n isValidSemVerRange,\n inMilliseconds,\n Duration,\n} from '@metamask/utils';\n\nimport { isEqual } from '../array';\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { KeyringOriginsStruct, RpcOriginsStruct } from '../json-rpc';\nimport { ChainIdStruct } from '../namespace';\nimport { SnapIdStruct } from '../snaps';\nimport { mergeStructs, type InferMatching } from '../structs';\nimport { NameStruct, NpmSnapFileNames, uri } 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\nexport const CurveStruct: Describe<SupportedCurve> = enums([\n 'ed25519',\n 'secp256k1',\n 'ed25519Bip32',\n]);\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: CurveStruct,\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\nexport const ChainIdsStruct = size(array(ChainIdStruct), 1, Infinity);\n\nexport const LookupMatchersStruct = union([\n object({\n tlds: size(array(string()), 1, Infinity),\n }),\n object({\n schemes: size(array(string()), 1, Infinity),\n }),\n object({\n tlds: size(array(string()), 1, Infinity),\n schemes: size(array(string()), 1, Infinity),\n }),\n]);\n\nexport const MINIMUM_REQUEST_TIMEOUT = inMilliseconds(5, Duration.Second);\nexport const MAXIMUM_REQUEST_TIMEOUT = inMilliseconds(3, Duration.Minute);\n\nexport const MaxRequestTimeStruct = size(\n integer(),\n MINIMUM_REQUEST_TIMEOUT,\n MAXIMUM_REQUEST_TIMEOUT,\n);\n\n// Utility type to union with for all handler structs\nexport const HandlerCaveatsStruct = object({\n maxRequestTime: optional(MaxRequestTimeStruct),\n});\n\nexport type HandlerCaveats = Infer<typeof HandlerCaveatsStruct>;\n\nexport const EmptyObjectStruct = object<EmptyObject>({}) as unknown as Struct<\n EmptyObject,\n null\n>;\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct: Describe<InitialPermissions> = type({\n 'endowment:cronjob': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n ),\n 'endowment:ethereum-provider': optional(EmptyObjectStruct),\n 'endowment:keyring': optional(\n mergeStructs(HandlerCaveatsStruct, KeyringOriginsStruct),\n ),\n 'endowment:lifecycle-hooks': optional(HandlerCaveatsStruct),\n 'endowment:name-lookup': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n chains: optional(ChainIdsStruct),\n matchers: optional(LookupMatchersStruct),\n }),\n ),\n ),\n 'endowment:network-access': optional(EmptyObjectStruct),\n 'endowment:page-home': optional(HandlerCaveatsStruct),\n 'endowment:rpc': optional(\n mergeStructs(HandlerCaveatsStruct, RpcOriginsStruct),\n ),\n 'endowment:signature-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowSignatureOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:transaction-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:webassembly': optional(EmptyObjectStruct),\n snap_dialog: optional(EmptyObjectStruct),\n snap_manageState: optional(EmptyObjectStruct),\n snap_manageAccounts: optional(EmptyObjectStruct),\n snap_notify: optional(EmptyObjectStruct),\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(EmptyObjectStruct),\n snap_getLocale: optional(EmptyObjectStruct),\n wallet_snap: optional(SnapIdsStruct),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = InferMatching<\n typeof PermissionsStruct,\n InitialPermissions\n>;\n\nexport const SnapAuxilaryFilesStruct = array(string());\n\nexport const InitialConnectionsStruct = record(\n intersection([string(), uri()]),\n object({}),\n);\n\nexport type InitialConnections = Infer<typeof InitialConnectionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(string(), 1, 214),\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 files: optional(SnapAuxilaryFilesStruct),\n locales: optional(SnapAuxilaryFilesStruct),\n }),\n initialConnections: optional(InitialConnectionsStruct),\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"]}
|
|
1
|
+
{"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":";;;AACA,iDAA6D;AAG7D,uDAiB+B;AAC/B,2CAOyB;AAEzB,wCAAmC;AACnC,4CAA6D;AAC7D,4CAA6E;AAC7E,8CAAqE;AACrE,gDAA6C;AAC7C,wCAAwC;AACxC,4CAA8D;AAC9D,wCAA6D;AAE7D,+EAA+E;AAC/E,gCAAgC;AAChC,MAAM,kBAAkB,GAAa;IACnC,2BAAiB;IACjB,sCAA4B;CAC7B,CAAC;AAEW,QAAA,oBAAoB,GAAa,CAAC,EAAE,CAAC,CAAC;AACnD,MAAM,eAAe,GAAe,4BAAoB,CAAC,GAAG,CA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M,GAAE,CAAC,EAAE,oDAAoD;CAClF,CAAC,CAAC;AAIH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAA,oBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,IAAI,wBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AARD,oDAQC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,IAAA,oBAAM,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AAC3C,CAAC;AAHD,gDAGC","sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport { isValidBIP32PathSegment } from '@metamask/key-tree';\nimport type { EmptyObject, InitialPermissions } from '@metamask/snaps-sdk';\nimport type { Describe, Infer, Struct } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n create,\n enums,\n integer,\n is,\n literal,\n object,\n optional,\n refine,\n record,\n size,\n string,\n type,\n union,\n intersection,\n} from '@metamask/superstruct';\nimport {\n assertStruct,\n ChecksumStruct,\n VersionStruct,\n isValidSemVerRange,\n inMilliseconds,\n Duration,\n} from '@metamask/utils';\n\nimport { isEqual } from '../array';\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { KeyringOriginsStruct, RpcOriginsStruct } from '../json-rpc';\nimport { ChainIdStruct } from '../namespace';\nimport { SnapIdStruct } from '../snaps';\nimport { mergeStructs, type InferMatching } from '../structs';\nimport { NameStruct, NpmSnapFileNames, uri } 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\nexport const CurveStruct: Describe<SupportedCurve> = enums([\n 'ed25519',\n 'secp256k1',\n 'ed25519Bip32',\n]);\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: CurveStruct,\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\nexport const ChainIdsStruct = size(array(ChainIdStruct), 1, Infinity);\n\nexport const LookupMatchersStruct = union([\n object({\n tlds: size(array(string()), 1, Infinity),\n }),\n object({\n schemes: size(array(string()), 1, Infinity),\n }),\n object({\n tlds: size(array(string()), 1, Infinity),\n schemes: size(array(string()), 1, Infinity),\n }),\n]);\n\nexport const MINIMUM_REQUEST_TIMEOUT = inMilliseconds(5, Duration.Second);\nexport const MAXIMUM_REQUEST_TIMEOUT = inMilliseconds(3, Duration.Minute);\n\nexport const MaxRequestTimeStruct = size(\n integer(),\n MINIMUM_REQUEST_TIMEOUT,\n MAXIMUM_REQUEST_TIMEOUT,\n);\n\n// Utility type to union with for all handler structs\nexport const HandlerCaveatsStruct = object({\n maxRequestTime: optional(MaxRequestTimeStruct),\n});\n\nexport type HandlerCaveats = Infer<typeof HandlerCaveatsStruct>;\n\nexport const EmptyObjectStruct = object<EmptyObject>({}) as unknown as Struct<\n EmptyObject,\n null\n>;\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct: Describe<InitialPermissions> = type({\n 'endowment:cronjob': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n ),\n 'endowment:ethereum-provider': optional(EmptyObjectStruct),\n 'endowment:keyring': optional(\n mergeStructs(HandlerCaveatsStruct, KeyringOriginsStruct),\n ),\n 'endowment:lifecycle-hooks': optional(HandlerCaveatsStruct),\n 'endowment:name-lookup': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n chains: optional(ChainIdsStruct),\n matchers: optional(LookupMatchersStruct),\n }),\n ),\n ),\n 'endowment:network-access': optional(EmptyObjectStruct),\n 'endowment:page-home': optional(HandlerCaveatsStruct),\n 'endowment:rpc': optional(\n mergeStructs(HandlerCaveatsStruct, RpcOriginsStruct),\n ),\n 'endowment:signature-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowSignatureOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:transaction-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:webassembly': optional(EmptyObjectStruct),\n snap_dialog: optional(EmptyObjectStruct),\n snap_manageState: optional(EmptyObjectStruct),\n snap_manageAccounts: optional(EmptyObjectStruct),\n snap_notify: optional(EmptyObjectStruct),\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(EmptyObjectStruct),\n snap_getLocale: optional(EmptyObjectStruct),\n wallet_snap: optional(SnapIdsStruct),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = InferMatching<\n typeof PermissionsStruct,\n InitialPermissions\n>;\n\nexport const SnapAuxilaryFilesStruct = array(string());\n\nexport const InitialConnectionsStruct = record(\n intersection([string(), uri()]),\n object({}),\n);\n\nexport type InitialConnections = Infer<typeof InitialConnectionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(string(), 1, 214),\n repository: optional(\n type({\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 files: optional(SnapAuxilaryFilesStruct),\n locales: optional(SnapAuxilaryFilesStruct),\n }),\n initialConnections: optional(InitialConnectionsStruct),\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"]}
|
|
@@ -130,7 +130,7 @@ export const SnapManifestStruct = object({
|
|
|
130
130
|
version: VersionStruct,
|
|
131
131
|
description: size(string(), 1, 280),
|
|
132
132
|
proposedName: size(string(), 1, 214),
|
|
133
|
-
repository: optional(
|
|
133
|
+
repository: optional(type({
|
|
134
134
|
type: size(string(), 1, Infinity),
|
|
135
135
|
url: size(string(), 1, Infinity),
|
|
136
136
|
})),
|