@metamask/snaps-utils 9.2.2 → 9.4.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 +22 -1
- package/dist/account.cjs +53 -0
- package/dist/account.cjs.map +1 -1
- package/dist/account.d.cts +26 -1
- package/dist/account.d.cts.map +1 -1
- package/dist/account.d.mts +26 -1
- package/dist/account.d.mts.map +1 -1
- package/dist/account.mjs +49 -1
- package/dist/account.mjs.map +1 -1
- package/dist/eval-worker.cjs +38 -11
- package/dist/eval-worker.cjs.map +1 -1
- package/dist/eval-worker.d.cts.map +1 -1
- package/dist/eval-worker.d.mts.map +1 -1
- package/dist/eval-worker.mjs +38 -11
- package/dist/eval-worker.mjs.map +1 -1
- package/dist/eval.cjs +6 -0
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.d.cts +7 -0
- package/dist/eval.d.cts.map +1 -1
- package/dist/eval.d.mts +7 -0
- package/dist/eval.d.mts.map +1 -1
- package/dist/eval.mjs +6 -0
- package/dist/eval.mjs.map +1 -1
- package/dist/fs.cjs +51 -6
- package/dist/fs.cjs.map +1 -1
- package/dist/fs.d.cts +16 -4
- package/dist/fs.d.cts.map +1 -1
- package/dist/fs.d.mts +16 -4
- package/dist/fs.d.mts.map +1 -1
- package/dist/fs.mjs +49 -5
- package/dist/fs.mjs.map +1 -1
- package/dist/handlers/exports.cjs +7 -0
- package/dist/handlers/exports.cjs.map +1 -1
- package/dist/handlers/exports.d.cts +6 -1
- package/dist/handlers/exports.d.cts.map +1 -1
- package/dist/handlers/exports.d.mts +6 -1
- package/dist/handlers/exports.d.mts.map +1 -1
- package/dist/handlers/exports.mjs +7 -0
- package/dist/handlers/exports.mjs.map +1 -1
- package/dist/handlers/home-page.d.cts +3 -3
- package/dist/handlers/home-page.d.mts +3 -3
- package/dist/handlers/settings-page.d.cts +1 -1
- package/dist/handlers/settings-page.d.mts +1 -1
- package/dist/handlers/signature.d.cts +1 -1
- package/dist/handlers/signature.d.mts +1 -1
- package/dist/handlers/transaction.d.cts +3 -3
- package/dist/handlers/transaction.d.mts +3 -3
- package/dist/handlers/types.cjs +1 -0
- package/dist/handlers/types.cjs.map +1 -1
- package/dist/handlers/types.d.cts +2 -1
- package/dist/handlers/types.d.cts.map +1 -1
- package/dist/handlers/types.d.mts +2 -1
- package/dist/handlers/types.d.mts.map +1 -1
- package/dist/handlers/types.mjs +1 -0
- package/dist/handlers/types.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/manifest/manifest.cjs +36 -4
- package/dist/manifest/manifest.cjs.map +1 -1
- package/dist/manifest/manifest.d.cts +40 -7
- package/dist/manifest/manifest.d.cts.map +1 -1
- package/dist/manifest/manifest.d.mts +40 -7
- package/dist/manifest/manifest.d.mts.map +1 -1
- package/dist/manifest/manifest.mjs +13 -4
- package/dist/manifest/manifest.mjs.map +1 -1
- package/dist/manifest/validator-types.cjs.map +1 -1
- package/dist/manifest/validator-types.d.cts +18 -1
- package/dist/manifest/validator-types.d.cts.map +1 -1
- package/dist/manifest/validator-types.d.mts +18 -1
- package/dist/manifest/validator-types.d.mts.map +1 -1
- package/dist/manifest/validator-types.mjs.map +1 -1
- package/dist/manifest/validator.cjs +23 -10
- package/dist/manifest/validator.cjs.map +1 -1
- package/dist/manifest/validator.d.cts +4 -2
- package/dist/manifest/validator.d.cts.map +1 -1
- package/dist/manifest/validator.d.mts +4 -2
- package/dist/manifest/validator.d.mts.map +1 -1
- package/dist/manifest/validator.mjs +23 -10
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/index.cjs +2 -0
- package/dist/manifest/validators/index.cjs.map +1 -1
- package/dist/manifest/validators/index.d.cts +2 -0
- package/dist/manifest/validators/index.d.cts.map +1 -1
- package/dist/manifest/validators/index.d.mts +2 -0
- package/dist/manifest/validators/index.d.mts.map +1 -1
- package/dist/manifest/validators/index.mjs +2 -0
- package/dist/manifest/validators/index.mjs.map +1 -1
- package/dist/manifest/validators/production-platform-version.cjs +47 -0
- package/dist/manifest/validators/production-platform-version.cjs.map +1 -0
- package/dist/manifest/validators/production-platform-version.d.cts +7 -0
- package/dist/manifest/validators/production-platform-version.d.cts.map +1 -0
- package/dist/manifest/validators/production-platform-version.d.mts +7 -0
- package/dist/manifest/validators/production-platform-version.d.mts.map +1 -0
- package/dist/manifest/validators/production-platform-version.mjs +44 -0
- package/dist/manifest/validators/production-platform-version.mjs.map +1 -0
- package/dist/manifest/validators/unused-exports.cjs +53 -0
- package/dist/manifest/validators/unused-exports.cjs.map +1 -0
- package/dist/manifest/validators/unused-exports.d.cts +7 -0
- package/dist/manifest/validators/unused-exports.d.cts.map +1 -0
- package/dist/manifest/validators/unused-exports.d.mts +7 -0
- package/dist/manifest/validators/unused-exports.d.mts.map +1 -0
- package/dist/manifest/validators/unused-exports.mjs +50 -0
- package/dist/manifest/validators/unused-exports.mjs.map +1 -0
- package/dist/time.cjs +15 -1
- package/dist/time.cjs.map +1 -1
- package/dist/time.d.cts +7 -0
- package/dist/time.d.cts.map +1 -1
- package/dist/time.d.mts +7 -0
- package/dist/time.d.mts.map +1 -1
- package/dist/time.mjs +13 -0
- package/dist/time.mjs.map +1 -1
- package/package.json +4 -3
|
@@ -70,7 +70,7 @@ export declare const OnSignatureResponseStruct: import("@metamask/superstruct").
|
|
|
70
70
|
variant?: "primary" | "secondary" | undefined;
|
|
71
71
|
buttonType?: "button" | "submit" | undefined;
|
|
72
72
|
})[];
|
|
73
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
73
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
74
74
|
src: string;
|
|
75
75
|
alt?: string | undefined;
|
|
76
76
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -80,7 +80,7 @@ export declare const OnTransactionResponseWithContentStruct: import("@metamask/s
|
|
|
80
80
|
variant?: "primary" | "secondary" | undefined;
|
|
81
81
|
buttonType?: "button" | "submit" | undefined;
|
|
82
82
|
})[];
|
|
83
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
83
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
84
84
|
src: string;
|
|
85
85
|
alt?: string | undefined;
|
|
86
86
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -167,7 +167,7 @@ export declare const OnTransactionResponseWithContentStruct: import("@metamask/s
|
|
|
167
167
|
variant?: "primary" | "secondary" | undefined;
|
|
168
168
|
buttonType?: "button" | "submit" | undefined;
|
|
169
169
|
})[];
|
|
170
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
170
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
171
171
|
src: string;
|
|
172
172
|
alt?: string | undefined;
|
|
173
173
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -258,7 +258,7 @@ export declare const OnTransactionResponseStruct: import("@metamask/superstruct"
|
|
|
258
258
|
variant?: "primary" | "secondary" | undefined;
|
|
259
259
|
buttonType?: "button" | "submit" | undefined;
|
|
260
260
|
})[];
|
|
261
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
261
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
262
262
|
src: string;
|
|
263
263
|
alt?: string | undefined;
|
|
264
264
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -80,7 +80,7 @@ export declare const OnTransactionResponseWithContentStruct: import("@metamask/s
|
|
|
80
80
|
variant?: "primary" | "secondary" | undefined;
|
|
81
81
|
buttonType?: "button" | "submit" | undefined;
|
|
82
82
|
})[];
|
|
83
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
83
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
84
84
|
src: string;
|
|
85
85
|
alt?: string | undefined;
|
|
86
86
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -167,7 +167,7 @@ export declare const OnTransactionResponseWithContentStruct: import("@metamask/s
|
|
|
167
167
|
variant?: "primary" | "secondary" | undefined;
|
|
168
168
|
buttonType?: "button" | "submit" | undefined;
|
|
169
169
|
})[];
|
|
170
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
170
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
171
171
|
src: string;
|
|
172
172
|
alt?: string | undefined;
|
|
173
173
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -258,7 +258,7 @@ export declare const OnTransactionResponseStruct: import("@metamask/superstruct"
|
|
|
258
258
|
variant?: "primary" | "secondary" | undefined;
|
|
259
259
|
buttonType?: "button" | "submit" | undefined;
|
|
260
260
|
})[];
|
|
261
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
261
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
262
262
|
src: string;
|
|
263
263
|
alt?: string | undefined;
|
|
264
264
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
package/dist/handlers/types.cjs
CHANGED
|
@@ -18,5 +18,6 @@ var HandlerType;
|
|
|
18
18
|
HandlerType["OnAssetsConversion"] = "onAssetsConversion";
|
|
19
19
|
HandlerType["OnAssetHistoricalPrice"] = "onAssetHistoricalPrice";
|
|
20
20
|
HandlerType["OnProtocolRequest"] = "onProtocolRequest";
|
|
21
|
+
HandlerType["OnClientRequest"] = "onClientRequest";
|
|
21
22
|
})(HandlerType || (exports.HandlerType = HandlerType = {}));
|
|
22
23
|
//# sourceMappingURL=types.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;AA8BA,IAAY,
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;AA8BA,IAAY,WAiBX;AAjBD,WAAY,WAAW;IACrB,4CAA6B,CAAA;IAC7B,0CAA2B,CAAA;IAC3B,8CAA+B,CAAA;IAC/B,sCAAuB,CAAA;IACvB,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;IACrB,4CAA6B,CAAA;IAC7B,oDAAqC,CAAA;IACrC,wCAAyB,CAAA;IACzB,gDAAiC,CAAA;IACjC,0CAA2B,CAAA;IAC3B,gDAAiC,CAAA;IACjC,wDAAyC,CAAA;IACzC,gEAAiD,CAAA;IACjD,sDAAuC,CAAA;IACvC,kDAAmC,CAAA;AACrC,CAAC,EAjBW,WAAW,2BAAX,WAAW,QAiBtB","sourcesContent":["import type { SNAP_EXPORTS } from './exports';\n\nexport type SnapRpcHookArgs = {\n origin: string;\n handler: HandlerType;\n request: Record<string, unknown>;\n};\n\n/**\n * Utility type for getting the handler function type from a handler type.\n */\nexport type HandlerFunction<Type extends SnapHandler> =\n Type['validator'] extends (snapExport: unknown) => snapExport is infer Handler\n ? Handler\n : never;\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<\n (typeof SNAP_EXPORTS)[Key]\n >;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports;\n\nexport enum HandlerType {\n OnRpcRequest = 'onRpcRequest',\n OnSignature = 'onSignature',\n OnTransaction = 'onTransaction',\n OnCronjob = 'onCronjob',\n OnInstall = 'onInstall',\n OnUpdate = 'onUpdate',\n OnNameLookup = 'onNameLookup',\n OnKeyringRequest = 'onKeyringRequest',\n OnHomePage = 'onHomePage',\n OnSettingsPage = 'onSettingsPage',\n OnUserInput = 'onUserInput',\n OnAssetsLookup = 'onAssetsLookup',\n OnAssetsConversion = 'onAssetsConversion',\n OnAssetHistoricalPrice = 'onAssetHistoricalPrice',\n OnProtocolRequest = 'onProtocolRequest',\n OnClientRequest = 'onClientRequest',\n}\n\nexport type SnapHandler = {\n /**\n * The type of handler.\n */\n type: HandlerType;\n\n /**\n * Whether the handler is required, i.e., whether the request will fail if the\n * handler is called, but the snap does not export it.\n *\n * This is primarily used for the lifecycle handlers, which are optional.\n */\n required: boolean;\n\n /**\n * Validate the given snap export. This should return a type guard for the\n * handler type.\n *\n * @param snapExport - The export to validate.\n * @returns Whether the export is valid.\n */\n validator: (snapExport: unknown) => boolean;\n};\n"]}
|
|
@@ -33,7 +33,8 @@ export declare enum HandlerType {
|
|
|
33
33
|
OnAssetsLookup = "onAssetsLookup",
|
|
34
34
|
OnAssetsConversion = "onAssetsConversion",
|
|
35
35
|
OnAssetHistoricalPrice = "onAssetHistoricalPrice",
|
|
36
|
-
OnProtocolRequest = "onProtocolRequest"
|
|
36
|
+
OnProtocolRequest = "onProtocolRequest",
|
|
37
|
+
OnClientRequest = "onClientRequest"
|
|
37
38
|
}
|
|
38
39
|
export type SnapHandler = {
|
|
39
40
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAkB;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;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,WAAW,IAClD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,KAAK,UAAU,IAAI,MAAM,OAAO,GAC1E,OAAO,GACP,KAAK,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;KAC/B,GAAG,IAAI,MAAM,OAAO,YAAY,CAAC,CAAC,EAAE,eAAe,CAClD,CAAC,OAAO,YAAY,CAAC,CAAC,GAAG,CAAC,CAC3B;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAE9C,oBAAY,WAAW;IACrB,YAAY,iBAAiB;I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B;IAC3B,cAAc,mBAAmB;IACjC,kBAAkB,uBAAuB;IACzC,sBAAsB,2BAA2B;IACjD,iBAAiB,sBAAsB;IACvC,eAAe,oBAAoB;CACpC;AAED,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;;;;OAKG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,OAAO,CAAC;CAC7C,CAAC"}
|
|
@@ -33,7 +33,8 @@ export declare enum HandlerType {
|
|
|
33
33
|
OnAssetsLookup = "onAssetsLookup",
|
|
34
34
|
OnAssetsConversion = "onAssetsConversion",
|
|
35
35
|
OnAssetHistoricalPrice = "onAssetHistoricalPrice",
|
|
36
|
-
OnProtocolRequest = "onProtocolRequest"
|
|
36
|
+
OnProtocolRequest = "onProtocolRequest",
|
|
37
|
+
OnClientRequest = "onClientRequest"
|
|
37
38
|
}
|
|
38
39
|
export type SnapHandler = {
|
|
39
40
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAkB;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;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,WAAW,IAClD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,KAAK,UAAU,IAAI,MAAM,OAAO,GAC1E,OAAO,GACP,KAAK,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;KAC/B,GAAG,IAAI,MAAM,OAAO,YAAY,CAAC,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gB;IAC3B,aAAa,kBAAkB;IAC/B,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,gBAAgB,qBAAqB;IACrC,UAAU,eAAe;IACzB,cAAc,mBAAmB;IACjC,WAAW,gBAAgB;IAC3B,cAAc,mBAAmB;IACjC,kBAAkB,uBAAuB;IACzC,sBAAsB,2BAA2B;IACjD,iBAAiB,sBAAsB;IACvC,eAAe,oBAAoB;CACpC;AAED,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;;;;OAKG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,OAAO,CAAC;CAC7C,CAAC"}
|
package/dist/handlers/types.mjs
CHANGED
|
@@ -15,5 +15,6 @@ export var HandlerType;
|
|
|
15
15
|
HandlerType["OnAssetsConversion"] = "onAssetsConversion";
|
|
16
16
|
HandlerType["OnAssetHistoricalPrice"] = "onAssetHistoricalPrice";
|
|
17
17
|
HandlerType["OnProtocolRequest"] = "onProtocolRequest";
|
|
18
|
+
HandlerType["OnClientRequest"] = "onClientRequest";
|
|
18
19
|
})(HandlerType || (HandlerType = {}));
|
|
19
20
|
//# sourceMappingURL=types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AA8BA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AA8BA,MAAM,CAAN,IAAY,WAiBX;AAjBD,WAAY,WAAW;IACrB,4CAA6B,CAAA;IAC7B,0CAA2B,CAAA;IAC3B,8CAA+B,CAAA;IAC/B,sCAAuB,CAAA;IACvB,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;IACrB,4CAA6B,CAAA;IAC7B,oDAAqC,CAAA;IACrC,wCAAyB,CAAA;IACzB,gDAAiC,CAAA;IACjC,0CAA2B,CAAA;IAC3B,gDAAiC,CAAA;IACjC,wDAAyC,CAAA;IACzC,gEAAiD,CAAA;IACjD,sDAAuC,CAAA;IACvC,kDAAmC,CAAA;AACrC,CAAC,EAjBW,WAAW,KAAX,WAAW,QAiBtB","sourcesContent":["import type { SNAP_EXPORTS } from './exports';\n\nexport type SnapRpcHookArgs = {\n origin: string;\n handler: HandlerType;\n request: Record<string, unknown>;\n};\n\n/**\n * Utility type for getting the handler function type from a handler type.\n */\nexport type HandlerFunction<Type extends SnapHandler> =\n Type['validator'] extends (snapExport: unknown) => snapExport is infer Handler\n ? Handler\n : never;\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<\n (typeof SNAP_EXPORTS)[Key]\n >;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports;\n\nexport enum HandlerType {\n OnRpcRequest = 'onRpcRequest',\n OnSignature = 'onSignature',\n OnTransaction = 'onTransaction',\n OnCronjob = 'onCronjob',\n OnInstall = 'onInstall',\n OnUpdate = 'onUpdate',\n OnNameLookup = 'onNameLookup',\n OnKeyringRequest = 'onKeyringRequest',\n OnHomePage = 'onHomePage',\n OnSettingsPage = 'onSettingsPage',\n OnUserInput = 'onUserInput',\n OnAssetsLookup = 'onAssetsLookup',\n OnAssetsConversion = 'onAssetsConversion',\n OnAssetHistoricalPrice = 'onAssetHistoricalPrice',\n OnProtocolRequest = 'onProtocolRequest',\n OnClientRequest = 'onClientRequest',\n}\n\nexport type SnapHandler = {\n /**\n * The type of handler.\n */\n type: HandlerType;\n\n /**\n * Whether the handler is required, i.e., whether the request will fail if the\n * handler is called, but the snap does not export it.\n *\n * This is primarily used for the lifecycle handlers, which are optional.\n */\n required: boolean;\n\n /**\n * Validate the given snap export. This should return a type guard for the\n * handler type.\n *\n * @param snapExport - The export to validate.\n * @returns Whether the export is valid.\n */\n validator: (snapExport: unknown) => boolean;\n};\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./account.cjs"), exports);
|
|
17
18
|
__exportStar(require("./array.cjs"), exports);
|
|
18
19
|
__exportStar(require("./auxiliary-files.cjs"), exports);
|
|
19
20
|
__exportStar(require("./base64.cjs"), exports);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,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,uDAA2B;AAC3B,+CAAyB;AACzB,6CAAuB;AACvB,iDAA2B;AAC3B,qDAA+B;AAC/B,gDAA0B;AAC1B,uDAA2B;AAC3B,6CAAuB;AACvB,yDAAmC;AACnC,8CAAwB;AACxB,gDAA0B;AAC1B,gDAA0B;AAC1B,6CAAuB;AACvB,8CAAwB;AACxB,2CAAqB;AACrB,4CAAsB;AACtB,mDAA6B;AAC7B,iDAA2B;AAC3B,2DAA+B","sourcesContent":["export * from './account';\nexport * 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 './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './path';\nexport * from './platform-version';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './time';\nexport * from './types';\nexport * from './ui';\nexport * from './url';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport type * from './promise';\n"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA0B;AAC1B,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,qCAA2B;AAC3B,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,mCAA+B"}
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA0B;AAC1B,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,qCAA2B;AAC3B,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,mCAA+B"}
|
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA0B;AAC1B,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,qCAA2B;AAC3B,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B","sourcesContent":["export * from './account';\nexport * 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 './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './path';\nexport * from './platform-version';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './time';\nexport * from './types';\nexport * from './ui';\nexport * from './url';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport type * from './promise';\n"]}
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -9,6 +32,7 @@ const utils_1 = require("@metamask/utils");
|
|
|
9
32
|
const fs_1 = require("fs");
|
|
10
33
|
const path_1 = __importDefault(require("path"));
|
|
11
34
|
const validator_1 = require("./validator.cjs");
|
|
35
|
+
const defaultValidators = __importStar(require("./validators/index.cjs"));
|
|
12
36
|
const deep_clone_1 = require("../deep-clone.cjs");
|
|
13
37
|
const fs_2 = require("../fs.cjs");
|
|
14
38
|
const json_1 = require("../json.cjs");
|
|
@@ -34,12 +58,20 @@ const MANIFEST_SORT_ORDER = {
|
|
|
34
58
|
* @param basePath - The path to the folder with the manifest files.
|
|
35
59
|
* @param options - Additional options for the function.
|
|
36
60
|
* @param options.sourceCode - The source code of the Snap.
|
|
37
|
-
* @param options.writeFileFn - The function to use to write the manifest to
|
|
38
|
-
*
|
|
61
|
+
* @param options.writeFileFn - The function to use to write the manifest to
|
|
62
|
+
* disk.
|
|
63
|
+
* @param options.updateAndWriteManifest - Whether to auto-magically try to fix
|
|
64
|
+
* errors and then write the manifest to disk.
|
|
65
|
+
* @param options.exports - The exports detected by evaluating the bundle. This
|
|
66
|
+
* may be used by one or more validators to determine whether the Snap is valid.
|
|
67
|
+
* @param options.handlerEndowments - An object containing the names of the
|
|
68
|
+
* handlers and their respective permission name. This must be provided to avoid
|
|
69
|
+
* circular dependencies between `@metamask/snaps-utils` and
|
|
70
|
+
* `@metamask/snaps-rpc-methods`.
|
|
39
71
|
* @returns Whether the manifest was updated, and an array of warnings that
|
|
40
72
|
* were encountered during processing of the manifest files.
|
|
41
73
|
*/
|
|
42
|
-
async function checkManifest(basePath, { updateAndWriteManifest = true, sourceCode, writeFileFn = fs_1.promises.writeFile, } = {}) {
|
|
74
|
+
async function checkManifest(basePath, { updateAndWriteManifest = true, sourceCode, writeFileFn = fs_1.promises.writeFile, exports, handlerEndowments, } = {}) {
|
|
43
75
|
const manifestPath = path_1.default.join(basePath, types_1.NpmSnapFileNames.Manifest);
|
|
44
76
|
const manifestFile = await (0, fs_2.readJsonFile)(manifestPath);
|
|
45
77
|
const unvalidatedManifest = manifestFile.result;
|
|
@@ -65,7 +97,7 @@ async function checkManifest(basePath, { updateAndWriteManifest = true, sourceCo
|
|
|
65
97
|
auxiliaryFiles: (await getSnapFiles(basePath, auxiliaryFilePaths, null)) ?? [],
|
|
66
98
|
localizationFiles,
|
|
67
99
|
};
|
|
68
|
-
const validatorResults = await (0, validator_1.runValidators)(snapFiles);
|
|
100
|
+
const validatorResults = await (0, validator_1.runValidators)(snapFiles, Object.values(defaultValidators), { exports, handlerEndowments });
|
|
69
101
|
let manifestResults = {
|
|
70
102
|
updated: false,
|
|
71
103
|
files: validatorResults.files,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.cjs","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAsD;AAEtD,2CAAwD;AACxD,2BAAoC;AACpC,gDAA6B;AAI7B,+CAAsD;AAEtD,kDAA0C;AAC1C,kCAAqC;AACrC,sCAAoC;AAEpC,wCAA4C;AAC5C,mDAAoE;AAEpE,MAAM,mBAAmB,GAAuC;IAC9D,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;IACf,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,CAAC;IACT,kBAAkB,EAAE,CAAC;IACrB,k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C,mBAAmB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;SAC/D,MAAM,CACL,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAChB,GAAG,MAAM;QACT,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC;KACrB,CAAC,EACF,EAAE,CACH,CAAC;IAEJ,OAAO,gBAAgC,CAAC;AAC1C,CAAC;AAlBD,kDAkBC","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assert, isPlainObject } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport type { SnapManifest } from './validation';\nimport type { ValidatorResults } from './validator';\nimport { hasFixes, runValidators } from './validator';\nimport type { ValidatorMeta, ValidatorReport } from './validator-types';\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { parseJson } from '../json';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file/node';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialConnections: 7,\n initialPermissions: 8,\n platformVersion: 9,\n manifestVersion: 10,\n};\n\nexport type CheckManifestReport = Omit<ValidatorReport, 'fix'> & {\n wasFixed?: boolean;\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was written and updated.\n */\nexport type CheckManifestResult = {\n files?: SnapFiles;\n updated: boolean;\n reports: CheckManifestReport[];\n};\n\nexport type WriteFileFunction = (path: string, data: string) => Promise<void>;\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param options - Additional options for the function.\n * @param options.sourceCode - The source code of the Snap.\n * @param options.writeFileFn - The function to use to write the manifest to disk.\n * @param options.updateAndWriteManifest - Whether to auto-magically try to fix errors and then write the manifest to disk.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n {\n updateAndWriteManifest = true,\n sourceCode,\n writeFileFn = fs.writeFile,\n }: {\n updateAndWriteManifest?: boolean;\n sourceCode?: string;\n writeFileFn?: WriteFileFunction;\n } = {},\n): Promise<CheckManifestResult> {\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const auxiliaryFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.files,\n );\n\n const localizationFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.locales,\n );\n const localizationFiles =\n (await getSnapFiles(basePath, localizationFilePaths)) ?? [];\n for (const localization of localizationFiles) {\n try {\n localization.result = parseJson(localization.toString());\n } catch (error) {\n assert(error instanceof SyntaxError, error);\n throw new Error(\n `Failed to parse localization file \"${localization.path}\" as JSON.`,\n );\n }\n }\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n // Intentionally pass null as the encoding here since the files may be binary\n auxiliaryFiles:\n (await getSnapFiles(basePath, auxiliaryFilePaths, null)) ?? [],\n localizationFiles,\n };\n\n const validatorResults = await runValidators(snapFiles);\n let manifestResults: CheckManifestResult = {\n updated: false,\n files: validatorResults.files,\n reports: validatorResults.reports,\n };\n\n if (updateAndWriteManifest && hasFixes(manifestResults)) {\n const fixedResults = await runFixes(validatorResults);\n\n if (fixedResults.updated) {\n manifestResults = fixedResults;\n\n assert(manifestResults.files);\n\n try {\n await writeFileFn(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n manifestResults.files.manifest.toString(),\n );\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(\n `Failed to update \"snap.manifest.json\": ${getErrorMessage(error)}`,\n );\n }\n }\n }\n\n return manifestResults;\n}\n\n/**\n * Run the algorithm for automatically fixing errors in manifest.\n *\n * The algorithm updates the manifest by fixing all fixable problems,\n * and then run validation again to check if the new manifest is now correct.\n * If not correct, the algorithm will use the manifest from previous iteration\n * and try again `MAX_ATTEMPTS` times to update it before bailing and\n * resulting in failure.\n *\n * @param results - Results of the initial run of validation.\n * @param rules - Optional list of rules to run the fixes with.\n * @returns The updated manifest and whether it was updated.\n */\nexport async function runFixes(\n results: ValidatorResults,\n rules?: ValidatorMeta[],\n): Promise<CheckManifestResult> {\n let shouldRunFixes = true;\n const MAX_ATTEMPTS = 10;\n\n assert(results.files);\n\n let fixResults: ValidatorResults = results;\n assert(fixResults.files);\n fixResults.files.manifest = fixResults.files.manifest.clone();\n\n for (\n let attempts = 1;\n shouldRunFixes && attempts <= MAX_ATTEMPTS;\n attempts++\n ) {\n assert(fixResults.files);\n\n let manifest = fixResults.files.manifest.result;\n\n const fixable = fixResults.reports.filter((report) => report.fix);\n for (const report of fixable) {\n assert(report.fix);\n ({ manifest } = await report.fix({ manifest }));\n }\n\n fixResults.files.manifest.value = `${JSON.stringify(\n getWritableManifest(manifest),\n null,\n 2,\n )}\\n`;\n fixResults.files.manifest.result = manifest;\n\n fixResults = await runValidators(fixResults.files, rules);\n shouldRunFixes = hasFixes(fixResults);\n }\n\n const initialReports: (CheckManifestReport & ValidatorReport)[] = deepClone(\n results.reports,\n );\n\n // Was fixed\n if (!shouldRunFixes) {\n for (const report of initialReports) {\n if (report.fix) {\n report.wasFixed = true;\n delete report.fix;\n }\n }\n\n return {\n files: fixResults.files,\n updated: true,\n reports: initialReports,\n };\n }\n\n for (const report of initialReports) {\n delete report.fix;\n }\n\n return {\n files: results.files,\n updated: false,\n reports: initialReports,\n };\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(\n `Failed to read snap bundle file: ${getErrorMessage(error)}`,\n );\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read snap icon file: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Get an array of paths from an unvalidated Snap manifest.\n *\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param selector - A function that returns the paths to the files.\n * @returns The paths to the files, if any.\n */\nexport function getSnapFilePaths(\n manifest: Json,\n selector: (manifest: Partial<SnapManifest>) => string[] | undefined,\n) {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const snapManifest = manifest as Partial<SnapManifest>;\n const paths = selector(snapManifest);\n\n if (!Array.isArray(paths)) {\n return undefined;\n }\n\n return paths;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the files with the\n * given paths and read them.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param paths - The paths to the files.\n * @param encoding - An optional encoding to pass down to readVirtualFile.\n * @returns A list of auxiliary files and their contents, if any.\n */\nexport async function getSnapFiles(\n basePath: string,\n paths: string[] | undefined,\n encoding: BufferEncoding | null = 'utf8',\n): Promise<VirtualFile[] | undefined> {\n if (!paths) {\n return undefined;\n }\n\n try {\n return await Promise.all(\n paths.map(async (filePath) =>\n readVirtualFile(pathUtils.join(basePath, filePath), encoding),\n ),\n );\n } catch (error) {\n throw new Error(`Failed to read snap files: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"manifest.cjs","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAsD;AAEtD,2CAAwD;AACx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BAA8B,IAAA,2BAAe,EAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC;AAlBD,oCAkBC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,QAAsB;IACxD,MAAM,EAAE,UAAU,EAAE,GAAG,SAAS,EAAE,GAAG,QAAQ,CAAC;IAE9C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CACtB,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAC5B,CAAC;IAE5B,MAAM,gBAAgB,GAAG,IAAI;SAC1B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;SAC/D,MAAM,CACL,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAChB,GAAG,MAAM;QACT,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC;KACrB,CAAC,EACF,EAAE,CACH,CAAC;IAEJ,OAAO,gBAAgC,CAAC;AAC1C,CAAC;AAlBD,kDAkBC","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assert, isPlainObject } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport type { SnapManifest } from './validation';\nimport type { ValidatorResults } from './validator';\nimport { hasFixes, runValidators } from './validator';\nimport type { ValidatorMeta, ValidatorReport } from './validator-types';\nimport * as defaultValidators from './validators';\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { parseJson } from '../json';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file/node';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialConnections: 7,\n initialPermissions: 8,\n platformVersion: 9,\n manifestVersion: 10,\n};\n\nexport type CheckManifestReport = Omit<ValidatorReport, 'fix'> & {\n wasFixed?: boolean;\n};\n\n/**\n * The options for the `checkManifest` function.\n */\nexport type CheckManifestOptions = {\n /**\n * Whether to auto-magically try to fix errors and then write the manifest to\n * disk.\n */\n updateAndWriteManifest?: boolean;\n\n /**\n * The source code of the Snap.\n */\n sourceCode?: string;\n\n /**\n * The function to use to write the manifest to disk.\n */\n writeFileFn?: WriteFileFunction;\n\n /**\n * The exports detected by evaluating the bundle. This may be used by one or\n * more validators to determine whether the Snap is valid.\n */\n exports?: string[];\n\n /**\n * An object containing the names of the handlers and their respective\n * permission name. This must be provided to avoid circular dependencies\n * between `@metamask/snaps-utils` and `@metamask/snaps-rpc-methods`.\n */\n handlerEndowments?: Record<string, string | null>;\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was written and updated.\n */\nexport type CheckManifestResult = {\n files?: SnapFiles;\n updated: boolean;\n reports: CheckManifestReport[];\n};\n\nexport type WriteFileFunction = (path: string, data: string) => Promise<void>;\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param options - Additional options for the function.\n * @param options.sourceCode - The source code of the Snap.\n * @param options.writeFileFn - The function to use to write the manifest to\n * disk.\n * @param options.updateAndWriteManifest - Whether to auto-magically try to fix\n * errors and then write the manifest to disk.\n * @param options.exports - The exports detected by evaluating the bundle. This\n * may be used by one or more validators to determine whether the Snap is valid.\n * @param options.handlerEndowments - An object containing the names of the\n * handlers and their respective permission name. This must be provided to avoid\n * circular dependencies between `@metamask/snaps-utils` and\n * `@metamask/snaps-rpc-methods`.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n {\n updateAndWriteManifest = true,\n sourceCode,\n writeFileFn = fs.writeFile,\n exports,\n handlerEndowments,\n }: CheckManifestOptions = {},\n): Promise<CheckManifestResult> {\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const auxiliaryFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.files,\n );\n\n const localizationFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.locales,\n );\n const localizationFiles =\n (await getSnapFiles(basePath, localizationFilePaths)) ?? [];\n for (const localization of localizationFiles) {\n try {\n localization.result = parseJson(localization.toString());\n } catch (error) {\n assert(error instanceof SyntaxError, error);\n throw new Error(\n `Failed to parse localization file \"${localization.path}\" as JSON.`,\n );\n }\n }\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n // Intentionally pass null as the encoding here since the files may be binary\n auxiliaryFiles:\n (await getSnapFiles(basePath, auxiliaryFilePaths, null)) ?? [],\n localizationFiles,\n };\n\n const validatorResults = await runValidators(\n snapFiles,\n Object.values(defaultValidators),\n { exports, handlerEndowments },\n );\n\n let manifestResults: CheckManifestResult = {\n updated: false,\n files: validatorResults.files,\n reports: validatorResults.reports,\n };\n\n if (updateAndWriteManifest && hasFixes(manifestResults)) {\n const fixedResults = await runFixes(validatorResults);\n\n if (fixedResults.updated) {\n manifestResults = fixedResults;\n\n assert(manifestResults.files);\n\n try {\n await writeFileFn(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n manifestResults.files.manifest.toString(),\n );\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(\n `Failed to update \"snap.manifest.json\": ${getErrorMessage(error)}`,\n );\n }\n }\n }\n\n return manifestResults;\n}\n\n/**\n * Run the algorithm for automatically fixing errors in manifest.\n *\n * The algorithm updates the manifest by fixing all fixable problems,\n * and then run validation again to check if the new manifest is now correct.\n * If not correct, the algorithm will use the manifest from previous iteration\n * and try again `MAX_ATTEMPTS` times to update it before bailing and\n * resulting in failure.\n *\n * @param results - Results of the initial run of validation.\n * @param rules - Optional list of rules to run the fixes with.\n * @returns The updated manifest and whether it was updated.\n */\nexport async function runFixes(\n results: ValidatorResults,\n rules?: ValidatorMeta[],\n): Promise<CheckManifestResult> {\n let shouldRunFixes = true;\n const MAX_ATTEMPTS = 10;\n\n assert(results.files);\n\n let fixResults: ValidatorResults = results;\n assert(fixResults.files);\n fixResults.files.manifest = fixResults.files.manifest.clone();\n\n for (\n let attempts = 1;\n shouldRunFixes && attempts <= MAX_ATTEMPTS;\n attempts++\n ) {\n assert(fixResults.files);\n\n let manifest = fixResults.files.manifest.result;\n\n const fixable = fixResults.reports.filter((report) => report.fix);\n for (const report of fixable) {\n assert(report.fix);\n ({ manifest } = await report.fix({ manifest }));\n }\n\n fixResults.files.manifest.value = `${JSON.stringify(\n getWritableManifest(manifest),\n null,\n 2,\n )}\\n`;\n fixResults.files.manifest.result = manifest;\n\n fixResults = await runValidators(fixResults.files, rules);\n shouldRunFixes = hasFixes(fixResults);\n }\n\n const initialReports: (CheckManifestReport & ValidatorReport)[] = deepClone(\n results.reports,\n );\n\n // Was fixed\n if (!shouldRunFixes) {\n for (const report of initialReports) {\n if (report.fix) {\n report.wasFixed = true;\n delete report.fix;\n }\n }\n\n return {\n files: fixResults.files,\n updated: true,\n reports: initialReports,\n };\n }\n\n for (const report of initialReports) {\n delete report.fix;\n }\n\n return {\n files: results.files,\n updated: false,\n reports: initialReports,\n };\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(\n `Failed to read snap bundle file: ${getErrorMessage(error)}`,\n );\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read snap icon file: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Get an array of paths from an unvalidated Snap manifest.\n *\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param selector - A function that returns the paths to the files.\n * @returns The paths to the files, if any.\n */\nexport function getSnapFilePaths(\n manifest: Json,\n selector: (manifest: Partial<SnapManifest>) => string[] | undefined,\n) {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const snapManifest = manifest as Partial<SnapManifest>;\n const paths = selector(snapManifest);\n\n if (!Array.isArray(paths)) {\n return undefined;\n }\n\n return paths;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the files with the\n * given paths and read them.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param paths - The paths to the files.\n * @param encoding - An optional encoding to pass down to readVirtualFile.\n * @returns A list of auxiliary files and their contents, if any.\n */\nexport async function getSnapFiles(\n basePath: string,\n paths: string[] | undefined,\n encoding: BufferEncoding | null = 'utf8',\n): Promise<VirtualFile[] | undefined> {\n if (!paths) {\n return undefined;\n }\n\n try {\n return await Promise.all(\n paths.map(async (filePath) =>\n readVirtualFile(pathUtils.join(basePath, filePath), encoding),\n ),\n );\n } catch (error) {\n throw new Error(`Failed to read snap files: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n"]}
|
|
@@ -8,6 +8,35 @@ import { VirtualFile } from "../virtual-file/node.cjs";
|
|
|
8
8
|
export type CheckManifestReport = Omit<ValidatorReport, 'fix'> & {
|
|
9
9
|
wasFixed?: boolean;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* The options for the `checkManifest` function.
|
|
13
|
+
*/
|
|
14
|
+
export type CheckManifestOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* Whether to auto-magically try to fix errors and then write the manifest to
|
|
17
|
+
* disk.
|
|
18
|
+
*/
|
|
19
|
+
updateAndWriteManifest?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The source code of the Snap.
|
|
22
|
+
*/
|
|
23
|
+
sourceCode?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The function to use to write the manifest to disk.
|
|
26
|
+
*/
|
|
27
|
+
writeFileFn?: WriteFileFunction;
|
|
28
|
+
/**
|
|
29
|
+
* The exports detected by evaluating the bundle. This may be used by one or
|
|
30
|
+
* more validators to determine whether the Snap is valid.
|
|
31
|
+
*/
|
|
32
|
+
exports?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* An object containing the names of the handlers and their respective
|
|
35
|
+
* permission name. This must be provided to avoid circular dependencies
|
|
36
|
+
* between `@metamask/snaps-utils` and `@metamask/snaps-rpc-methods`.
|
|
37
|
+
*/
|
|
38
|
+
handlerEndowments?: Record<string, string | null>;
|
|
39
|
+
};
|
|
11
40
|
/**
|
|
12
41
|
* The result from the `checkManifest` function.
|
|
13
42
|
*
|
|
@@ -28,16 +57,20 @@ export type WriteFileFunction = (path: string, data: string) => Promise<void>;
|
|
|
28
57
|
* @param basePath - The path to the folder with the manifest files.
|
|
29
58
|
* @param options - Additional options for the function.
|
|
30
59
|
* @param options.sourceCode - The source code of the Snap.
|
|
31
|
-
* @param options.writeFileFn - The function to use to write the manifest to
|
|
32
|
-
*
|
|
60
|
+
* @param options.writeFileFn - The function to use to write the manifest to
|
|
61
|
+
* disk.
|
|
62
|
+
* @param options.updateAndWriteManifest - Whether to auto-magically try to fix
|
|
63
|
+
* errors and then write the manifest to disk.
|
|
64
|
+
* @param options.exports - The exports detected by evaluating the bundle. This
|
|
65
|
+
* may be used by one or more validators to determine whether the Snap is valid.
|
|
66
|
+
* @param options.handlerEndowments - An object containing the names of the
|
|
67
|
+
* handlers and their respective permission name. This must be provided to avoid
|
|
68
|
+
* circular dependencies between `@metamask/snaps-utils` and
|
|
69
|
+
* `@metamask/snaps-rpc-methods`.
|
|
33
70
|
* @returns Whether the manifest was updated, and an array of warnings that
|
|
34
71
|
* were encountered during processing of the manifest files.
|
|
35
72
|
*/
|
|
36
|
-
export declare function checkManifest(basePath: string, { updateAndWriteManifest, sourceCode, writeFileFn, }?:
|
|
37
|
-
updateAndWriteManifest?: boolean;
|
|
38
|
-
sourceCode?: string;
|
|
39
|
-
writeFileFn?: WriteFileFunction;
|
|
40
|
-
}): Promise<CheckManifestResult>;
|
|
73
|
+
export declare function checkManifest(basePath: string, { updateAndWriteManifest, sourceCode, writeFileFn, exports, handlerEndowments, }?: CheckManifestOptions): Promise<CheckManifestResult>;
|
|
41
74
|
/**
|
|
42
75
|
* Run the algorithm for automatically fixing errors in manifest.
|
|
43
76
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.cts","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAoB;AAEpD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,8BAA0B;
|
|
1
|
+
{"version":3,"file":"manifest.d.cts","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAoB;AAEpD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,8BAA0B;AAKxE,OAAO,KAAK,EAAE,SAAS,EAAwB,qBAAiB;AAEhE,OAAO,EAAmB,WAAW,EAAE,iCAA6B;AAepE,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,GAAG;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC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EAAE,MAAM,EAChB,QAAQ,EAAE,IAAI,GACb,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAqBlC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,IAAI,EACd,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,MAAM,EAAE,GAAG,SAAS,wBAcpE;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,EAC3B,QAAQ,GAAE,cAAc,GAAG,IAAa,GACvC,OAAO,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,CAcpC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,CAkBxE"}
|
|
@@ -8,6 +8,35 @@ import { VirtualFile } from "../virtual-file/node.mjs";
|
|
|
8
8
|
export type CheckManifestReport = Omit<ValidatorReport, 'fix'> & {
|
|
9
9
|
wasFixed?: boolean;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* The options for the `checkManifest` function.
|
|
13
|
+
*/
|
|
14
|
+
export type CheckManifestOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* Whether to auto-magically try to fix errors and then write the manifest to
|
|
17
|
+
* disk.
|
|
18
|
+
*/
|
|
19
|
+
updateAndWriteManifest?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The source code of the Snap.
|
|
22
|
+
*/
|
|
23
|
+
sourceCode?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The function to use to write the manifest to disk.
|
|
26
|
+
*/
|
|
27
|
+
writeFileFn?: WriteFileFunction;
|
|
28
|
+
/**
|
|
29
|
+
* The exports detected by evaluating the bundle. This may be used by one or
|
|
30
|
+
* more validators to determine whether the Snap is valid.
|
|
31
|
+
*/
|
|
32
|
+
exports?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* An object containing the names of the handlers and their respective
|
|
35
|
+
* permission name. This must be provided to avoid circular dependencies
|
|
36
|
+
* between `@metamask/snaps-utils` and `@metamask/snaps-rpc-methods`.
|
|
37
|
+
*/
|
|
38
|
+
handlerEndowments?: Record<string, string | null>;
|
|
39
|
+
};
|
|
11
40
|
/**
|
|
12
41
|
* The result from the `checkManifest` function.
|
|
13
42
|
*
|
|
@@ -28,16 +57,20 @@ export type WriteFileFunction = (path: string, data: string) => Promise<void>;
|
|
|
28
57
|
* @param basePath - The path to the folder with the manifest files.
|
|
29
58
|
* @param options - Additional options for the function.
|
|
30
59
|
* @param options.sourceCode - The source code of the Snap.
|
|
31
|
-
* @param options.writeFileFn - The function to use to write the manifest to
|
|
32
|
-
*
|
|
60
|
+
* @param options.writeFileFn - The function to use to write the manifest to
|
|
61
|
+
* disk.
|
|
62
|
+
* @param options.updateAndWriteManifest - Whether to auto-magically try to fix
|
|
63
|
+
* errors and then write the manifest to disk.
|
|
64
|
+
* @param options.exports - The exports detected by evaluating the bundle. This
|
|
65
|
+
* may be used by one or more validators to determine whether the Snap is valid.
|
|
66
|
+
* @param options.handlerEndowments - An object containing the names of the
|
|
67
|
+
* handlers and their respective permission name. This must be provided to avoid
|
|
68
|
+
* circular dependencies between `@metamask/snaps-utils` and
|
|
69
|
+
* `@metamask/snaps-rpc-methods`.
|
|
33
70
|
* @returns Whether the manifest was updated, and an array of warnings that
|
|
34
71
|
* were encountered during processing of the manifest files.
|
|
35
72
|
*/
|
|
36
|
-
export declare function checkManifest(basePath: string, { updateAndWriteManifest, sourceCode, writeFileFn, }?:
|
|
37
|
-
updateAndWriteManifest?: boolean;
|
|
38
|
-
sourceCode?: string;
|
|
39
|
-
writeFileFn?: WriteFileFunction;
|
|
40
|
-
}): Promise<CheckManifestResult>;
|
|
73
|
+
export declare function checkManifest(basePath: string, { updateAndWriteManifest, sourceCode, writeFileFn, exports, handlerEndowments, }?: CheckManifestOptions): Promise<CheckManifestResult>;
|
|
41
74
|
/**
|
|
42
75
|
* Run the algorithm for automatically fixing errors in manifest.
|
|
43
76
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.mts","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAoB;AAEpD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,8BAA0B;
|
|
1
|
+
{"version":3,"file":"manifest.d.mts","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAoB;AAEpD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,8BAA0B;AAKxE,OAAO,KAAK,EAAE,SAAS,EAAwB,qBAAiB;AAEhE,OAAO,EAAmB,WAAW,EAAE,iCAA6B;AAepE,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,GAAG;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAEhC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;CACnD,CAAC;AAEF;;;;;GAKG;AACH,MAAM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IAAa,GACvC,OAAO,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,CAcpC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,CAkBxE"}
|
|
@@ -3,6 +3,7 @@ import { assert, isPlainObject } from "@metamask/utils";
|
|
|
3
3
|
import { promises as fs } from "fs";
|
|
4
4
|
import pathUtils from "path";
|
|
5
5
|
import { hasFixes, runValidators } from "./validator.mjs";
|
|
6
|
+
import * as defaultValidators from "./validators/index.mjs";
|
|
6
7
|
import { deepClone } from "../deep-clone.mjs";
|
|
7
8
|
import { readJsonFile } from "../fs.mjs";
|
|
8
9
|
import { parseJson } from "../json.mjs";
|
|
@@ -28,12 +29,20 @@ const MANIFEST_SORT_ORDER = {
|
|
|
28
29
|
* @param basePath - The path to the folder with the manifest files.
|
|
29
30
|
* @param options - Additional options for the function.
|
|
30
31
|
* @param options.sourceCode - The source code of the Snap.
|
|
31
|
-
* @param options.writeFileFn - The function to use to write the manifest to
|
|
32
|
-
*
|
|
32
|
+
* @param options.writeFileFn - The function to use to write the manifest to
|
|
33
|
+
* disk.
|
|
34
|
+
* @param options.updateAndWriteManifest - Whether to auto-magically try to fix
|
|
35
|
+
* errors and then write the manifest to disk.
|
|
36
|
+
* @param options.exports - The exports detected by evaluating the bundle. This
|
|
37
|
+
* may be used by one or more validators to determine whether the Snap is valid.
|
|
38
|
+
* @param options.handlerEndowments - An object containing the names of the
|
|
39
|
+
* handlers and their respective permission name. This must be provided to avoid
|
|
40
|
+
* circular dependencies between `@metamask/snaps-utils` and
|
|
41
|
+
* `@metamask/snaps-rpc-methods`.
|
|
33
42
|
* @returns Whether the manifest was updated, and an array of warnings that
|
|
34
43
|
* were encountered during processing of the manifest files.
|
|
35
44
|
*/
|
|
36
|
-
export async function checkManifest(basePath, { updateAndWriteManifest = true, sourceCode, writeFileFn = fs.writeFile, } = {}) {
|
|
45
|
+
export async function checkManifest(basePath, { updateAndWriteManifest = true, sourceCode, writeFileFn = fs.writeFile, exports, handlerEndowments, } = {}) {
|
|
37
46
|
const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);
|
|
38
47
|
const manifestFile = await readJsonFile(manifestPath);
|
|
39
48
|
const unvalidatedManifest = manifestFile.result;
|
|
@@ -59,7 +68,7 @@ export async function checkManifest(basePath, { updateAndWriteManifest = true, s
|
|
|
59
68
|
auxiliaryFiles: (await getSnapFiles(basePath, auxiliaryFilePaths, null)) ?? [],
|
|
60
69
|
localizationFiles,
|
|
61
70
|
};
|
|
62
|
-
const validatorResults = await runValidators(snapFiles);
|
|
71
|
+
const validatorResults = await runValidators(snapFiles, Object.values(defaultValidators), { exports, handlerEndowments });
|
|
63
72
|
let manifestResults = {
|
|
64
73
|
updated: false,
|
|
65
74
|
files: validatorResults.files,
|