@metamask/snaps-utils 9.0.0 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/dist/eval-worker.cjs +1 -1
- package/dist/eval-worker.cjs.map +1 -1
- package/dist/eval-worker.mjs +1 -1
- package/dist/eval-worker.mjs.map +1 -1
- package/dist/fs.cjs +1 -1
- package/dist/fs.cjs.map +1 -1
- package/dist/fs.mjs +1 -1
- package/dist/fs.mjs.map +1 -1
- package/dist/iframe.cjs +0 -1
- package/dist/iframe.cjs.map +1 -1
- package/dist/iframe.d.cts +0 -1
- package/dist/iframe.d.cts.map +1 -1
- package/dist/iframe.d.mts +0 -1
- package/dist/iframe.d.mts.map +1 -1
- package/dist/iframe.mjs +0 -1
- package/dist/iframe.mjs.map +1 -1
- package/dist/index.cjs +0 -1
- 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 +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/json-rpc.cjs +2 -6
- package/dist/json-rpc.cjs.map +1 -1
- package/dist/json-rpc.d.cts.map +1 -1
- package/dist/json-rpc.d.mts.map +1 -1
- package/dist/json-rpc.mjs +2 -6
- package/dist/json-rpc.mjs.map +1 -1
- package/dist/manifest/manifest.cjs +1 -1
- package/dist/manifest/manifest.cjs.map +1 -1
- package/dist/manifest/manifest.d.cts +2 -2
- package/dist/manifest/manifest.d.cts.map +1 -1
- package/dist/manifest/manifest.d.mts +2 -2
- package/dist/manifest/manifest.d.mts.map +1 -1
- package/dist/manifest/manifest.mjs +1 -1
- package/dist/manifest/manifest.mjs.map +1 -1
- package/dist/manifest/validator-types.cjs.map +1 -1
- package/dist/manifest/validator-types.d.cts +1 -1
- package/dist/manifest/validator-types.d.cts.map +1 -1
- package/dist/manifest/validator-types.d.mts +1 -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.map +1 -1
- package/dist/manifest/validator.d.cts +1 -1
- package/dist/manifest/validator.d.cts.map +1 -1
- package/dist/manifest/validator.d.mts +1 -1
- package/dist/manifest/validator.d.mts.map +1 -1
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/platform-version.cjs +1 -1
- package/dist/manifest/validators/platform-version.cjs.map +1 -1
- package/dist/manifest/validators/platform-version.mjs +1 -1
- package/dist/manifest/validators/platform-version.mjs.map +1 -1
- package/dist/mock.cjs +0 -3
- package/dist/mock.cjs.map +1 -1
- package/dist/mock.d.cts.map +1 -1
- package/dist/mock.d.mts.map +1 -1
- package/dist/mock.mjs +0 -3
- package/dist/mock.mjs.map +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.mjs +1 -1
- package/dist/node.mjs.map +1 -1
- package/dist/post-process.cjs.map +1 -1
- package/dist/post-process.d.cts.map +1 -1
- package/dist/post-process.d.mts.map +1 -1
- package/dist/post-process.mjs.map +1 -1
- package/dist/snaps.cjs +21 -3
- package/dist/snaps.cjs.map +1 -1
- package/dist/snaps.d.cts +2 -1
- package/dist/snaps.d.cts.map +1 -1
- package/dist/snaps.d.mts +2 -1
- package/dist/snaps.d.mts.map +1 -1
- package/dist/snaps.mjs +22 -4
- package/dist/snaps.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 +3 -3
- package/dist/types.mjs.map +1 -1
- package/dist/ui.cjs +7 -5
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.cts.map +1 -1
- package/dist/ui.d.mts.map +1 -1
- package/dist/ui.mjs +7 -5
- package/dist/ui.mjs.map +1 -1
- package/dist/virtual-file/VirtualFile.cjs.map +1 -1
- package/dist/virtual-file/VirtualFile.mjs.map +1 -1
- package/package.json +8 -22
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [9.0.1]
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Improve error messaging ([#3142](https://github.com/MetaMask/snaps/pull/3142))
|
|
15
|
+
|
|
10
16
|
## [9.0.0]
|
|
11
17
|
|
|
12
18
|
### Changed
|
|
@@ -566,7 +572,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
566
572
|
- The version of the package no longer needs to match the version of all other
|
|
567
573
|
MetaMask Snaps packages.
|
|
568
574
|
|
|
569
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.0.
|
|
575
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.0.1...HEAD
|
|
576
|
+
[9.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.0.0...@metamask/snaps-utils@9.0.1
|
|
570
577
|
[9.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.10.0...@metamask/snaps-utils@9.0.0
|
|
571
578
|
[8.10.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.9.1...@metamask/snaps-utils@8.10.0
|
|
572
579
|
[8.9.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.9.0...@metamask/snaps-utils@8.9.1
|
package/dist/eval-worker.cjs
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
4
|
// @ts-ignore - TypeScript complains about this being ESM in a CJS file, but
|
|
5
5
|
// `ses/lockdown` has a CommonJS entry point.
|
|
6
|
-
// eslint-disable-next-line import/no-unassigned-import
|
|
6
|
+
// eslint-disable-next-line import-x/no-unassigned-import
|
|
7
7
|
require("ses/lockdown");
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
9
|
const handler_types_1 = require("./handler-types.cjs");
|
package/dist/eval-worker.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.cjs","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":";;AAAA,6DAA6D;AAC7D,4EAA4E;AAC5E,6CAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"eval-worker.cjs","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":";;AAAA,6DAA6D;AAC7D,4EAA4E;AAC5E,6CAA6C;AAC7C,yDAAyD;AACzD,wBAAsB;AAEtB,2BAAkC;AAGlC,uDAAoD;AACpD,qCAAgD;AAIhD,QAAQ,CAAC;IACP,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;IAExB,2EAA2E;IAC3E,yEAAyE;IACzE,kCAAkC;IAClC,YAAY,EAAE,QAAQ;CACvB,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,MAAM,UAAU,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEtD,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC;IAClC,GAAG,IAAA,6BAAsB,GAAE;IAC3B,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,UAAU,CAAC,OAAO;CAC5B,CAAC,CAAC;AAEH,0BAA0B;AAC1B,WAAW,CAAC,UAAU,CAAC,IAAI,GAAG,WAAW,CAAC,UAAU,CAAC;AACrD,WAAW,CAAC,UAAU,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC;AACvD,WAAW,CAAC,UAAU,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC;AAEvD,WAAW,CAAC,QAAQ,CAAC,IAAA,iBAAY,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAEzD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAC3D,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,iCAAiB,CAAC,QAAQ,CAAC,UAAyB,CAAC,CACvE,CAAC;AAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;IAC9B,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,mCAAmC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/E,CAAC;AAED,0DAA0D;AAC1D,0EAA0E;AAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC","sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore - TypeScript complains about this being ESM in a CJS file, but\n// `ses/lockdown` has a CommonJS entry point.\n// eslint-disable-next-line import-x/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\n\nimport type { HandlerType } from './handler-types';\nimport { SNAP_EXPORT_NAMES } from './handler-types';\nimport { generateMockEndowments } from './mock';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n\n // We disable domain taming, because it does not work in certain cases when\n // running tests. This is unlikely to be a problem in production, because\n // Node.js domains are deprecated.\n domainTaming: 'unsafe',\n});\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nconst compartment = new Compartment({\n ...generateMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n});\n\n// Mirror BaseSnapExecutor\ncompartment.globalThis.self = compartment.globalThis;\ncompartment.globalThis.global = compartment.globalThis;\ncompartment.globalThis.window = compartment.globalThis;\n\ncompartment.evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n // eslint-disable-next-line no-console\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\n// To ensure the worker exits we explicitly call exit here\n// If we didn't the eval would wait for timers set during Compartment eval\nprocess.exit(0);\n"]}
|
package/dist/eval-worker.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
2
|
// @ts-ignore - TypeScript complains about this being ESM in a CJS file, but
|
|
3
3
|
// `ses/lockdown` has a CommonJS entry point.
|
|
4
|
-
// eslint-disable-next-line import/no-unassigned-import
|
|
4
|
+
// eslint-disable-next-line import-x/no-unassigned-import
|
|
5
5
|
import "ses/lockdown";
|
|
6
6
|
import { readFileSync } from "fs";
|
|
7
7
|
import { SNAP_EXPORT_NAMES } from "./handler-types.mjs";
|
package/dist/eval-worker.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.mjs","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,4EAA4E;AAC5E,6CAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"eval-worker.mjs","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,4EAA4E;AAC5E,6CAA6C;AAC7C,yDAAyD;AACzD,sBAAsB;AAEtB,OAAO,EAAE,YAAY,EAAE,WAAW;AAGlC,OAAO,EAAE,iBAAiB,EAAE,4BAAwB;AACpD,OAAO,EAAE,sBAAsB,EAAE,mBAAe;AAIhD,QAAQ,CAAC;IACP,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,U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being ESM in a CJS file, but\n// `ses/lockdown` has a CommonJS entry point.\n// eslint-disable-next-line import-x/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\n\nimport type { HandlerType } from './handler-types';\nimport { SNAP_EXPORT_NAMES } from './handler-types';\nimport { generateMockEndowments } from './mock';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n\n // We disable domain taming, because it does not work in certain cases when\n // running tests. This is unlikely to be a problem in production, because\n // Node.js domains are deprecated.\n domainTaming: 'unsafe',\n});\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nconst compartment = new Compartment({\n ...generateMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n});\n\n// Mirror BaseSnapExecutor\ncompartment.globalThis.self = compartment.globalThis;\ncompartment.globalThis.global = compartment.globalThis;\ncompartment.globalThis.window = compartment.globalThis;\n\ncompartment.evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n // eslint-disable-next-line no-console\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\n// To ensure the worker exits we explicitly call exit here\n// If we didn't the eval would wait for timers set during Compartment eval\nprocess.exit(0);\n"]}
|
package/dist/fs.cjs
CHANGED
package/dist/fs.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.cjs","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":";;;;;;AACA,2BAAoC;AACpC,4CAAoB;AACpB,gDAA6B;AAE7B,qCAAmC;AAEnC,kDAAsD;AAEtD;;;;;;;GAOG;AACI,KAAK,UAAU,WAAW,CAC/B,UAAkB,EAClB,SAAkB;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C,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC3C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;YAAS,CAAC;QACT,IAAI,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,MAAM,aAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;AACH,CAAC;AAfD,4CAeC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport os from 'os';\nimport pathUtils from 'path';\n\nimport { parseJson } from './json';\nimport type { VirtualFile } from './virtual-file';\nimport { readVirtualFile } from './virtual-file/node';\n\n/**\n * Checks whether the given path string resolves to an existing directory, and\n * optionally creates the directory if it doesn't exist.\n *\n * @param pathString - The path string to check.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns Whether the given path is an existing directory.\n */\nexport async function isDirectory(\n pathString: string,\n createDir: boolean,\n): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isDirectory();\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (!createDir) {\n return false;\n }\n\n await fs.mkdir(pathString, { recursive: true });\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * Checks whether the given path string resolves to an existing file.\n *\n * @param pathString - The path string to check.\n * @returns Whether the given path is an existing file.\n */\nexport async function isFile(pathString: string): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * Reads a `.json` file, parses its contents, and returns them.\n *\n * @param pathString - The path to the JSON file.\n * @returns The parsed contents of the JSON file.\n */\nexport async function readJsonFile<Type extends Json = Json>(\n pathString: string,\n): Promise<VirtualFile<Type>> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n let file;\n try {\n file = await readVirtualFile(pathString, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${pathString}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n file.result = parseJson(file.toString());\n return file as VirtualFile<Type>;\n}\n\n/**\n * Gets the complete out file path from an output file name and parent\n * directory path.\n *\n * @param outDir - The path to the out file's parent directory.\n * @param outFileName - The out file's name.\n * @returns The complete path to the out file.\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a `.js` file name.\n * Throws on validation failure.\n *\n * @param filename - The file name to validate.\n * @returns `true` if validation succeeded.\n * @throws If the file name is invalid.\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n pathUtils.basename(filename) !== filename\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path. Throws on validation failure.\n *\n * @param filePath - The file path to validate.\n * @returns `true` if validation succeeded.\n * @throws If the path does not resolve to a file.\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path. Throws on validation failure.\n *\n * @param dirPath - The directory path to validate.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns `true` if validation succeeded or the directory was created.\n * @throws If the directory does not exist or could not be created.\n */\nexport async function validateDirPath(\n dirPath: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirPath, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirPath}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n\n/**\n * Creates a temporary file with a given name and content, writes it to disk and calls the provided function.\n * This function handles deletion of the temporary file after usage.\n *\n * @param fileName - The name of the temporary file.\n * @param fileContents - The content of the temporary file.\n * @param fn - The callback function to call when the temporary file has been created.\n */\nexport async function useTemporaryFile(\n fileName: string,\n fileContents: string,\n fn: (path: string) => Promise<unknown>,\n): Promise<void> {\n const filePath = pathUtils.join(os.tmpdir(), fileName);\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, fileContents);\n try {\n await fn(filePath);\n } finally {\n if (await isFile(filePath)) {\n await fs.unlink(filePath);\n }\n }\n}\n"]}
|
package/dist/fs.mjs
CHANGED
package/dist/fs.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.mjs","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,WAAW;AACpC,OAAO,EAAE,WAAW;AACpB,OAAO,SAAS,aAAa;AAE7B,OAAO,EAAE,SAAS,EAAE,mBAAe;AAEnC,OAAO,EAAE,eAAe,EAAE,gCAA4B;AAEtD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,UAAkB,EAClB,SAAkB;IAElB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5B,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;YACf,CAAC;YAED,MAAM,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,UAAkB;IAC7C,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CA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ACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,SAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,oBAAoB,OAAO,+CAA+C,CAC3E,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAAgB,EAChB,YAAoB,EACpB,EAAsC;IAEtC,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;IACvD,MAAM,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC3C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;YAAS,CAAC;QACT,IAAI,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport os from 'os';\nimport pathUtils from 'path';\n\nimport { parseJson } from './json';\nimport type { VirtualFile } from './virtual-file';\nimport { readVirtualFile } from './virtual-file/node';\n\n/**\n * Checks whether the given path string resolves to an existing directory, and\n * optionally creates the directory if it doesn't exist.\n *\n * @param pathString - The path string to check.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns Whether the given path is an existing directory.\n */\nexport async function isDirectory(\n pathString: string,\n createDir: boolean,\n): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isDirectory();\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (!createDir) {\n return false;\n }\n\n await fs.mkdir(pathString, { recursive: true });\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * Checks whether the given path string resolves to an existing file.\n *\n * @param pathString - The path string to check.\n * @returns Whether the given path is an existing file.\n */\nexport async function isFile(pathString: string): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * Reads a `.json` file, parses its contents, and returns them.\n *\n * @param pathString - The path to the JSON file.\n * @returns The parsed contents of the JSON file.\n */\nexport async function readJsonFile<Type extends Json = Json>(\n pathString: string,\n): Promise<VirtualFile<Type>> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n let file;\n try {\n file = await readVirtualFile(pathString, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${pathString}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n file.result = parseJson(file.toString());\n return file as VirtualFile<Type>;\n}\n\n/**\n * Gets the complete out file path from an output file name and parent\n * directory path.\n *\n * @param outDir - The path to the out file's parent directory.\n * @param outFileName - The out file's name.\n * @returns The complete path to the out file.\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a `.js` file name.\n * Throws on validation failure.\n *\n * @param filename - The file name to validate.\n * @returns `true` if validation succeeded.\n * @throws If the file name is invalid.\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n pathUtils.basename(filename) !== filename\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path. Throws on validation failure.\n *\n * @param filePath - The file path to validate.\n * @returns `true` if validation succeeded.\n * @throws If the path does not resolve to a file.\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path. Throws on validation failure.\n *\n * @param dirPath - The directory path to validate.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns `true` if validation succeeded or the directory was created.\n * @throws If the directory does not exist or could not be created.\n */\nexport async function validateDirPath(\n dirPath: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirPath, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirPath}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n\n/**\n * Creates a temporary file with a given name and content, writes it to disk and calls the provided function.\n * This function handles deletion of the temporary file after usage.\n *\n * @param fileName - The name of the temporary file.\n * @param fileContents - The content of the temporary file.\n * @param fn - The callback function to call when the temporary file has been created.\n */\nexport async function useTemporaryFile(\n fileName: string,\n fileContents: string,\n fn: (path: string) => Promise<unknown>,\n): Promise<void> {\n const filePath = pathUtils.join(os.tmpdir(), fileName);\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, fileContents);\n try {\n await fn(filePath);\n } finally {\n if (await isFile(filePath)) {\n await fs.unlink(filePath);\n }\n }\n}\n"]}
|
package/dist/iframe.cjs
CHANGED
|
@@ -6,7 +6,6 @@ exports.createWindow = void 0;
|
|
|
6
6
|
* forever if the iframe never loads, but the promise should be wrapped in
|
|
7
7
|
* an initialization timeout in the SnapController.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
9
|
* @param options - The options for createWindow.
|
|
11
10
|
* @param options.uri - The iframe URI.
|
|
12
11
|
* @param options.id - The ID to assign to the iframe.
|
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;;;;;;;;;;;GAWG;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 * @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,7 +3,6 @@
|
|
|
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
6
|
* @param options - The options for createWindow.
|
|
8
7
|
* @param options.uri - The iframe URI.
|
|
9
8
|
* @param options.id - The ID to assign to the iframe.
|
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;;;;;;;;;;;GAWG;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,7 +3,6 @@
|
|
|
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
6
|
* @param options - The options for createWindow.
|
|
8
7
|
* @param options.uri - The iframe URI.
|
|
9
8
|
* @param options.id - The ID to assign to the iframe.
|
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;;;;;;;;;;;GAWG;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,7 +3,6 @@
|
|
|
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
6
|
* @param options - The options for createWindow.
|
|
8
7
|
* @param options.uri - The iframe URI.
|
|
9
8
|
* @param options.id - The ID to assign to the iframe.
|
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;;;;;;;;;;;GAWG;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 * @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/index.cjs
CHANGED
|
@@ -47,5 +47,4 @@ __exportStar(require("./url.cjs"), exports);
|
|
|
47
47
|
__exportStar(require("./validation.cjs"), exports);
|
|
48
48
|
__exportStar(require("./versions.cjs"), exports);
|
|
49
49
|
__exportStar(require("./virtual-file/index.cjs"), exports);
|
|
50
|
-
__exportStar(require("./promise.cjs"), exports);
|
|
51
50
|
//# sourceMappingURL=index.cjs.map
|
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,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,6CAAuB;AACvB,yDAAmC;AACnC,8CAAwB;AACxB,gDAA0B;AAC1B,gDAA0B;AAC1B,8CAAwB;AACxB,2CAAqB;AACrB,4CAAsB;AACtB,mDAA6B;AAC7B,iDAA2B;AAC3B,2DAA+B
|
|
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,6CAAuB;AACvB,yDAAmC;AACnC,8CAAwB;AACxB,gDAA0B;AAC1B,gDAA0B;AAC1B,8CAAwB;AACxB,2CAAqB;AACrB,4CAAsB;AACtB,mDAA6B;AAC7B,iDAA2B;AAC3B,2DAA+B","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 './path';\nexport * from './platform-version';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\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,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,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,
|
|
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,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,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,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,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,
|
|
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,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,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":"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,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B
|
|
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,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B","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 './path';\nexport * from './platform-version';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\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/json-rpc.cjs
CHANGED
|
@@ -32,9 +32,7 @@ exports.RpcOriginsStruct = (0, superstruct_1.refine)((0, superstruct_1.object)({
|
|
|
32
32
|
* {@link AssertionError}.
|
|
33
33
|
* @throws If the value is not a valid {@link RpcOrigins} object.
|
|
34
34
|
*/
|
|
35
|
-
function assertIsRpcOrigins(value,
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
37
|
-
ErrorWrapper) {
|
|
35
|
+
function assertIsRpcOrigins(value, ErrorWrapper) {
|
|
38
36
|
(0, utils_1.assertStruct)(value, exports.RpcOriginsStruct, 'Invalid JSON-RPC origins', ErrorWrapper);
|
|
39
37
|
}
|
|
40
38
|
exports.assertIsRpcOrigins = assertIsRpcOrigins;
|
|
@@ -49,9 +47,7 @@ exports.KeyringOriginsStruct = (0, superstruct_1.object)({
|
|
|
49
47
|
* {@link AssertionError}.
|
|
50
48
|
* @throws If the value is not a valid {@link KeyringOrigins} object.
|
|
51
49
|
*/
|
|
52
|
-
function assertIsKeyringOrigins(value,
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
54
|
-
ErrorWrapper) {
|
|
50
|
+
function assertIsKeyringOrigins(value, ErrorWrapper) {
|
|
55
51
|
(0, utils_1.assertStruct)(value, exports.KeyringOriginsStruct, 'Invalid keyring origins', ErrorWrapper);
|
|
56
52
|
}
|
|
57
53
|
exports.assertIsKeyringOrigins = assertIsKeyringOrigins;
|
package/dist/json-rpc.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.cjs","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":";;;AAAA,2EAA8D;AAE9D,uDAO+B;AAM/B,2CAIyB;AAEzB,MAAM,oBAAoB,GAAG,IAAA,mBAAK,EAChC,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9C,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO,sEAAsE,CAAC;IAChF,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CACH,CAAC;AAEW,QAAA,gBAAgB,GAAG,IAAA,oBAAM,EACpC,IAAA,oBAAM,EAAC;IACL,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC1B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC1B,cAAc,EAAE,IAAA,sBAAQ,EAAC,oBAAoB,CAAC;CAC/C,CAAC,EACF,aAAa,EACb,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,UAAU,GAAG,OAAO,CACxB,KAAK,CAAC,KAAK,KAAK,IAAI;QAClB,KAAK,CAAC,KAAK,KAAK,IAAI;QACpB,CAAC,KAAK,CAAC,cAA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,WAAwB,EACxB,MAAc;IAEd,yCAAyC;IACzC,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gEAAgE;IAChE,IACE,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CACvC,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,CACpC,EACD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iEAAiE;IACjE,IAAI,WAAW,KAAK,mCAAW,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8DAA8D;IAC9D,OAAO,OAAO,CAAC,WAAW,KAAK,mCAAW,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AA1BD,0CA0BC;AAED;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CACpC,KAAc;IAEd,IAAI,CAAC,IAAA,wBAAgB,EAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,IAAI,IAAA,wBAAgB,EAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAVD,wDAUC","sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport type {\n AssertionErrorConstructor,\n Json,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\n\nconst AllowedOriginsStruct = array(\n refine(string(), 'Allowed origin', (value) => {\n const wildcards = value.split('*').length - 1;\n if (wildcards > 2) {\n return 'No more than two wildcards (\"*\") are allowed in an origin specifier.';\n }\n\n return true;\n }),\n);\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(AllowedOriginsStruct),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(AllowedOriginsStruct),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Create regular expression for matching against an origin while allowing wildcards.\n *\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n *\n * @param matcher - The string to create the regular expression with.\n * @returns The regular expression.\n */\nfunction createOriginRegExp(matcher: string) {\n // Escape potential Regex characters\n const escaped = matcher.replace(/[.*+?^${}()|[\\]\\\\]/gu, '\\\\$&');\n // Support wildcards\n const regex = escaped.replace(/\\\\\\*/gu, '.*');\n return RegExp(`^${regex}$`, 'u');\n}\n\n/**\n * Check whether an origin is allowed or not using a matcher string.\n *\n * The matcher string may be a specific origin to match or include wildcards.\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n * Note: this means that https://*metamask.io matches both https://metamask.io\n * and https://snaps.metamask.io.\n *\n * @param matcher - The matcher string.\n * @param origin - The origin.\n * @returns Whether the origin is allowed.\n */\nfunction checkAllowedOrigin(matcher: string, origin: string) {\n // If the matcher is a single wildcard or identical to the origin we can return true immediately.\n if (matcher === '*' || matcher === origin) {\n return true;\n }\n\n const regex = createOriginRegExp(matcher);\n return regex.test(origin);\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (\n origins.allowedOrigins?.some((matcher) =>\n checkAllowedOrigin(matcher, origin),\n )\n ) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess<Json> {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"]}
|
package/dist/json-rpc.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.d.cts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AASnD,OAAO,KAAK,EACV,yBAAyB,EACzB,IAAI,EACJ,cAAc,EACf,wBAAwB;AAkBzB,eAAO,MAAM,gBAAgB;;;;;;;;EAoB5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"json-rpc.d.cts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AASnD,OAAO,KAAK,EACV,yBAAyB,EACzB,IAAI,EACJ,cAAc,EACf,wBAAwB;AAkBzB,eAAO,MAAM,gBAAgB;;;;;;;;EAoB5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,UAAU,CAO7B;AAED,eAAO,MAAM,oBAAoB;;;;EAE/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,cAAc,CAOjC;AAwCD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,WAuBf;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC,CAQvC"}
|
package/dist/json-rpc.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.d.mts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AASnD,OAAO,KAAK,EACV,yBAAyB,EACzB,IAAI,EACJ,cAAc,EACf,wBAAwB;AAkBzB,eAAO,MAAM,gBAAgB;;;;;;;;EAoB5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"json-rpc.d.mts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AASnD,OAAO,KAAK,EACV,yBAAyB,EACzB,IAAI,EACJ,cAAc,EACf,wBAAwB;AAkBzB,eAAO,MAAM,gBAAgB;;;;;;;;EAoB5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,UAAU,CAO7B;AAED,eAAO,MAAM,oBAAoB;;;;EAE/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,cAAc,CAOjC;AAwCD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,WAuBf;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC,CAQvC"}
|
package/dist/json-rpc.mjs
CHANGED
|
@@ -29,9 +29,7 @@ export const RpcOriginsStruct = refine(object({
|
|
|
29
29
|
* {@link AssertionError}.
|
|
30
30
|
* @throws If the value is not a valid {@link RpcOrigins} object.
|
|
31
31
|
*/
|
|
32
|
-
export function assertIsRpcOrigins(value,
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
34
|
-
ErrorWrapper) {
|
|
32
|
+
export function assertIsRpcOrigins(value, ErrorWrapper) {
|
|
35
33
|
assertStruct(value, RpcOriginsStruct, 'Invalid JSON-RPC origins', ErrorWrapper);
|
|
36
34
|
}
|
|
37
35
|
export const KeyringOriginsStruct = object({
|
|
@@ -45,9 +43,7 @@ export const KeyringOriginsStruct = object({
|
|
|
45
43
|
* {@link AssertionError}.
|
|
46
44
|
* @throws If the value is not a valid {@link KeyringOrigins} object.
|
|
47
45
|
*/
|
|
48
|
-
export function assertIsKeyringOrigins(value,
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
50
|
-
ErrorWrapper) {
|
|
46
|
+
export function assertIsKeyringOrigins(value, ErrorWrapper) {
|
|
51
47
|
assertStruct(value, KeyringOriginsStruct, 'Invalid keyring origins', ErrorWrapper);
|
|
52
48
|
}
|
|
53
49
|
/**
|
package/dist/json-rpc.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.mjs","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAE9D,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACP,8BAA8B;AAM/B,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EACjB,wBAAwB;AAEzB,MAAM,oBAAoB,GAAG,KAAK,CAChC,MAAM,CAAC,MAAM,EAAE,EAAE,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9C,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO,sEAAsE,CAAC;IAChF,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CACpC,MAAM,CAAC;IACL,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC1B,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC1B,cAAc,EAAE,QAAQ,CAAC,oBAAoB,CAAC;CAC/C,CAAC,EACF,aAAa,EACb,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,UAAU,GAAG,OAAO,CACxB,KAAK,CAAC,KAAK,KAAK,IAAI;QAClB,KAAK,CAAC,KAAK,KAAK,IAAI;QACpB,CAAC,KAAK,CAAC,cAAc,IAAI,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAC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EACnB,WAAwB,EACxB,MAAc;IAEd,yCAAyC;IACzC,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gEAAgE;IAChE,IACE,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CACvC,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,CACpC,EACD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iEAAiE;IACjE,IAAI,WAAW,KAAK,WAAW,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8DAA8D;IAC9D,OAAO,OAAO,CAAC,WAAW,KAAK,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAc;IAEd,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;AACH,CAAC","sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport type {\n AssertionErrorConstructor,\n Json,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\n\nconst AllowedOriginsStruct = array(\n refine(string(), 'Allowed origin', (value) => {\n const wildcards = value.split('*').length - 1;\n if (wildcards > 2) {\n return 'No more than two wildcards (\"*\") are allowed in an origin specifier.';\n }\n\n return true;\n }),\n);\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(AllowedOriginsStruct),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(AllowedOriginsStruct),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Create regular expression for matching against an origin while allowing wildcards.\n *\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n *\n * @param matcher - The string to create the regular expression with.\n * @returns The regular expression.\n */\nfunction createOriginRegExp(matcher: string) {\n // Escape potential Regex characters\n const escaped = matcher.replace(/[.*+?^${}()|[\\]\\\\]/gu, '\\\\$&');\n // Support wildcards\n const regex = escaped.replace(/\\\\\\*/gu, '.*');\n return RegExp(`^${regex}$`, 'u');\n}\n\n/**\n * Check whether an origin is allowed or not using a matcher string.\n *\n * The matcher string may be a specific origin to match or include wildcards.\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n * Note: this means that https://*metamask.io matches both https://metamask.io\n * and https://snaps.metamask.io.\n *\n * @param matcher - The matcher string.\n * @param origin - The origin.\n * @returns Whether the origin is allowed.\n */\nfunction checkAllowedOrigin(matcher: string, origin: string) {\n // If the matcher is a single wildcard or identical to the origin we can return true immediately.\n if (matcher === '*' || matcher === origin) {\n return true;\n }\n\n const regex = createOriginRegExp(matcher);\n return regex.test(origin);\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (\n origins.allowedOrigins?.some((matcher) =>\n checkAllowedOrigin(matcher, origin),\n )\n ) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess<Json> {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"]}
|
|
@@ -8,12 +8,12 @@ const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
|
8
8
|
const utils_1 = require("@metamask/utils");
|
|
9
9
|
const fs_1 = require("fs");
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const validator_1 = require("./validator.cjs");
|
|
11
12
|
const deep_clone_1 = require("../deep-clone.cjs");
|
|
12
13
|
const fs_2 = require("../fs.cjs");
|
|
13
14
|
const json_1 = require("../json.cjs");
|
|
14
15
|
const types_1 = require("../types.cjs");
|
|
15
16
|
const node_1 = require("../virtual-file/node.cjs");
|
|
16
|
-
const validator_1 = require("./validator.cjs");
|
|
17
17
|
const MANIFEST_SORT_ORDER = {
|
|
18
18
|
$schema: 1,
|
|
19
19
|
version: 2,
|