@metamask/snaps-cli 0.10.0 → 0.10.3

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 CHANGED
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.10.3]
10
+ ### Fixed
11
+ - Improve dynamic mocking ([#262](https://github.com/MetaMask/snaps-skunkworks/pull/262))
12
+
13
+ ## [0.10.2]
14
+ ### Fixed
15
+ - Installation failure ([#279](https://github.com/MetaMask/snaps-skunkworks/pull/279))
16
+ - A faulty installation script in a dependency caused the installation of this package to fail.
17
+
18
+ ## [0.10.1]
19
+ ### Fixed
20
+ - Comment stripping will no longer remove empty block comments in strings ([#276](https://github.com/MetaMask/snaps-skunkworks/pull/276))
21
+
9
22
  ## [0.10.0]
10
23
  ### Added
11
24
  - **BREAKING:** Transform HTML comments by default ([#237](https://github.com/MetaMask/snaps-skunkworks/pull/237))
@@ -123,7 +136,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
123
136
  - Example snaps ([#72](https://github.com/MetaMask/snaps-skunkworks/pull/72))
124
137
  - The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
125
138
 
126
- [Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.0...HEAD
139
+ [Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.3...HEAD
140
+ [0.10.3]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.2...v0.10.3
141
+ [0.10.2]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.1...v0.10.2
142
+ [0.10.1]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.0...v0.10.1
127
143
  [0.10.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.9.0...v0.10.0
128
144
  [0.9.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.8.0...v0.9.0
129
145
  [0.8.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.7.0...v0.8.0
@@ -61,10 +61,6 @@ function postProcess(bundleString, options = {}) {
61
61
  }
62
62
  let processedString = bundleString.trim();
63
63
  if (options.stripComments) {
64
- // TODO: Upstream a better fix to @nodefactory/strip-comments
65
- // The strip-comments package has issues with block comments of the
66
- // form "/**/", and so we remove them manually first:
67
- processedString = processedString.replace(/\/\*\*\//gu, '');
68
64
  processedString = strip_comments_1.default(processedString);
69
65
  }
70
66
  // Break up tokens that could be parsed as HTML comment terminators.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/cmds/build/utils.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAoC;AACpC,iFAAwD;AACxD,2CAA8C;AAE9C,6CAAoD;AAWpD;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,eAAe,CAAC,EACpC,WAAW,EACX,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,OAAO,EACP,IAAI,GACgB;IACpB,IAAI,WAAW,EAAE;QACf,MAAM,iBAAU,CAAC,cAAc,EAAE,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;KACpE;IAED,IAAI;QACF,MAAM,aAAE,CAAC,SAAS,CAChB,IAAI,EACJ,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;YACzD,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;SAClD,CAAW,CACb,CAAC;QAEF,IAAI,YAAY,EAAE;YAChB,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,iBAAiB,IAAI,IAAI,CAAC,CAAC;SAC9D;QACD,OAAO,CAAC,IAAI,CAAC,CAAC;KACf;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,iBAAU,CAAC,cAAc,EAAE,KAAK,CAAC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UC;AAED;;;;GAIG;AACH,SAAgB,uBAAuB,CAAC,YAAsB;IAC5D,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QACrC,OAAO,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,0DAIC;AAED,SAAgB,2BAA2B,CAAC,IAAe;IACzD,IACE,IAAI,CAAC,eAAe;QACpB,IAAI,CAAC,iBAAiB,KAAK,6BAAkB,CAAC,YAAY,EAC1D;QACA,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;KACH;AACH,CAAC;AATD,kEASC","sourcesContent":["import { promises as fs } from 'fs';\nimport stripComments from '@nodefactory/strip-comments';\nimport { writeError } from '../../utils/misc';\nimport { Option, YargsArgs } from '../../types/yargs';\nimport { TranspilationModes } from '../../builders';\n\ntype WriteBundleFileArgs = {\n bundleError: Error;\n bundleBuffer: Buffer;\n src: string;\n dest: string;\n resolve: (value: boolean) => void;\n argv: YargsArgs;\n};\n\n/**\n * Performs postprocessing on the bundle contents and writes them to disk.\n * Intended to be used in the callback passed to the Browserify `.bundle()`\n * call.\n *\n * @param options - Options bag.\n * @param options.bundleError - Any error received from Browserify.\n * @param options.bundleBuffer - The {@link Buffer} with the bundle contents\n * from Browserify.\n * @param options.src - The source file path.\n * @param options.dest - The destination file path.\n * @param options.resolve - A {@link Promise} resolution function, so that we\n * can use promises and `async`/`await` even though Browserify uses callbacks.\n * @param options.argv - The Yargs `argv` object.\n */\nexport async function writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n argv,\n}: WriteBundleFileArgs) {\n if (bundleError) {\n await writeError('Build error:', bundleError.message, bundleError);\n }\n\n try {\n await fs.writeFile(\n dest,\n postProcess(bundleBuffer ? bundleBuffer.toString() : null, {\n stripComments: argv.stripComments,\n transformHtmlComments: argv.transformHtmlComments,\n }) as string,\n );\n\n if (bundleBuffer) {\n console.log(`Build success: '${src}' bundled as '${dest}'!`);\n }\n resolve(true);\n } catch (error) {\n await writeError('Write error:', error.message, error, dest);\n }\n}\n\n/**\n * Postprocesses a JavaScript bundle string such that it can be evaluated in SES.\n * Currently:\n * - converts certain dot notation to string notation (for indexing)\n * - makes all direct calls to eval indirect\n * - wraps original bundle in anonymous function\n * - handles certain Babel-related edge cases\n *\n * @param bundleString - The bundle string\n * @param options - post process options\n * @param options.stripComments\n * @returns - The postprocessed bundle string\n */\nexport function postProcess(\n bundleString: string | null,\n options: Partial<Option> = {},\n): string | null {\n if (typeof bundleString !== 'string') {\n return null;\n }\n\n let processedString = bundleString.trim();\n\n if (options.stripComments) {\n // TODO: Upstream a better fix to @nodefactory/strip-comments\n // The strip-comments package has issues with block comments of the\n // form \"/**/\", and so we remove them manually first:\n processedString = processedString.replace(/\\/\\*\\*\\//gu, '');\n\n processedString = stripComments(processedString);\n }\n\n // Break up tokens that could be parsed as HTML comment terminators.\n // The regular expressions below are written strangely so as to avoid the\n // appearance of such tokens in our source code.\n // Ref: https://github.com/endojs/endo/blob/70cc86eb400655e922413b99c38818d7b2e79da0/packages/ses/error-codes/SES_HTML_COMMENT_REJECTED.md\n // This aggressive hack may change the behavior of programs that contain HTML\n // comment terminators in string literals.\n if (options.transformHtmlComments) {\n processedString = processedString.replace(\n new RegExp(`<!${'--'}`, 'gu'),\n '< !--',\n );\n\n processedString = processedString.replace(\n new RegExp(`${'--'}>`, 'gu'),\n '-- >',\n );\n }\n\n // stuff.eval(otherStuff) => (1, stuff.eval)(otherStuff)\n processedString = processedString.replace(\n /((?:\\b[\\w\\d]*[\\])]?\\.)+eval)(\\([^)]*\\))/gu,\n '(1, $1)$2',\n );\n\n // If we don't do the above, the below causes syntax errors if it encounters\n // things of the form: \"something.eval(stuff)\"\n // eval(stuff) => (1, eval)(stuff)\n processedString = processedString.replace(\n /(\\b)(eval)(\\([^)]*\\))/gu,\n '$1(1, $2)$3',\n );\n\n // Browserify provides the Buffer global as an argument to modules that use\n // it, but this does not work in SES. Since we pass in Buffer as an endowment,\n // we can simply remove the argument.\n processedString = processedString.replace(\n /^\\(function \\(Buffer\\)\\{$/gmu,\n '(function (){',\n );\n\n if (processedString.length === 0) {\n throw new Error(`Bundled code is empty after postprocessing.`);\n }\n\n // handle some cases by declaring missing globals\n // Babel regeneratorRuntime\n if (processedString.indexOf('regeneratorRuntime') !== -1) {\n processedString = `var regeneratorRuntime;\\n${processedString}`;\n }\n\n return processedString;\n}\n\n/**\n * Processes dependencies and updates argv with an options object\n * @param argv\n */\nexport function processDependencies(argv: YargsArgs) {\n const { depsToTranspile, transpilationMode } = argv;\n const babelifyOptions: Record<string, any> = {};\n if (transpilationMode === TranspilationModes.localAndDeps) {\n const regexpStr = getDependencyRegExp(depsToTranspile as string[]);\n if (regexpStr !== null) {\n babelifyOptions.ignore = [regexpStr];\n }\n }\n return babelifyOptions;\n}\n\n/**\n * Processes a string of space delimited dependencies into one regex string\n * @param dependencies\n * @returns a regexp string\n */\nexport function getDependencyRegExp(dependencies: string[]): RegExp | null {\n let regexp: string | null = null;\n if (!dependencies || dependencies.includes('.') || !dependencies.length) {\n return regexp;\n }\n const paths: string[] = sanitizeDependencyPaths(dependencies);\n regexp = `/node_modules/(?!${paths.shift()}`;\n paths.forEach((path) => (regexp += `|${path}`));\n regexp += '/)';\n return RegExp(regexp, 'u');\n}\n\n/**\n * Helper function remove any leading and trailing slashes from dependency list\n * @param dependencies\n * @returns an array of sanitized paths\n */\nexport function sanitizeDependencyPaths(dependencies: string[]): string[] {\n return dependencies.map((dependency) => {\n return dependency.replace(/^[/\\\\]+/u, '').replace(/[/\\\\]+$/u, '');\n });\n}\n\nexport function processInvalidTranspilation(argv: YargsArgs) {\n if (\n argv.depsToTranspile &&\n argv.transpilationMode !== TranspilationModes.localAndDeps\n ) {\n throw new Error(\n '\"depsToTranspile\" can only be specified if \"transpilationMode\" is set to \"localAndDeps\" .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s } from 'fs';\nimport stripComments from '@nodefactory/strip-comments';\nimport { writeError } from '../../utils/misc';\nimport { Option, YargsArgs } from '../../types/yargs';\nimport { TranspilationModes } from '../../builders';\n\ntype WriteBundleFileArgs = {\n bundleError: Error;\n bundleBuffer: Buffer;\n src: string;\n dest: string;\n resolve: (value: boolean) => void;\n argv: YargsArgs;\n};\n\n/**\n * Performs postprocessing on the bundle contents and writes them to disk.\n * Intended to be used in the callback passed to the Browserify `.bundle()`\n * call.\n *\n * @param options - Options bag.\n * @param options.bundleError - Any error received from Browserify.\n * @param options.bundleBuffer - The {@link Buffer} with the bundle contents\n * from Browserify.\n * @param options.src - The source file path.\n * @param options.dest - The destination file path.\n * @param options.resolve - A {@link Promise} resolution function, so that we\n * can use promises and `async`/`await` even though Browserify uses callbacks.\n * @param options.argv - The Yargs `argv` object.\n */\nexport async function writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n argv,\n}: WriteBundleFileArgs) {\n if (bundleError) {\n await writeError('Build error:', bundleError.message, bundleError);\n }\n\n try {\n await fs.writeFile(\n dest,\n postProcess(bundleBuffer ? bundleBuffer.toString() : null, {\n stripComments: argv.stripComments,\n transformHtmlComments: argv.transformHtmlComments,\n }) as string,\n );\n\n if (bundleBuffer) {\n console.log(`Build success: '${src}' bundled as '${dest}'!`);\n }\n resolve(true);\n } catch (error) {\n await writeError('Write error:', error.message, error, dest);\n }\n}\n\n/**\n * Postprocesses a JavaScript bundle string such that it can be evaluated in SES.\n * Currently:\n * - converts certain dot notation to string notation (for indexing)\n * - makes all direct calls to eval indirect\n * - wraps original bundle in anonymous function\n * - handles certain Babel-related edge cases\n *\n * @param bundleString - The bundle string\n * @param options - post process options\n * @param options.stripComments\n * @returns - The postprocessed bundle string\n */\nexport function postProcess(\n bundleString: string | null,\n options: Partial<Option> = {},\n): string | null {\n if (typeof bundleString !== 'string') {\n return null;\n }\n\n let processedString = bundleString.trim();\n\n if (options.stripComments) {\n processedString = stripComments(processedString);\n }\n\n // Break up tokens that could be parsed as HTML comment terminators.\n // The regular expressions below are written strangely so as to avoid the\n // appearance of such tokens in our source code.\n // Ref: https://github.com/endojs/endo/blob/70cc86eb400655e922413b99c38818d7b2e79da0/packages/ses/error-codes/SES_HTML_COMMENT_REJECTED.md\n // This aggressive hack may change the behavior of programs that contain HTML\n // comment terminators in string literals.\n if (options.transformHtmlComments) {\n processedString = processedString.replace(\n new RegExp(`<!${'--'}`, 'gu'),\n '< !--',\n );\n\n processedString = processedString.replace(\n new RegExp(`${'--'}>`, 'gu'),\n '-- >',\n );\n }\n\n // stuff.eval(otherStuff) => (1, stuff.eval)(otherStuff)\n processedString = processedString.replace(\n /((?:\\b[\\w\\d]*[\\])]?\\.)+eval)(\\([^)]*\\))/gu,\n '(1, $1)$2',\n );\n\n // If we don't do the above, the below causes syntax errors if it encounters\n // things of the form: \"something.eval(stuff)\"\n // eval(stuff) => (1, eval)(stuff)\n processedString = processedString.replace(\n /(\\b)(eval)(\\([^)]*\\))/gu,\n '$1(1, $2)$3',\n );\n\n // Browserify provides the Buffer global as an argument to modules that use\n // it, but this does not work in SES. Since we pass in Buffer as an endowment,\n // we can simply remove the argument.\n processedString = processedString.replace(\n /^\\(function \\(Buffer\\)\\{$/gmu,\n '(function (){',\n );\n\n if (processedString.length === 0) {\n throw new Error(`Bundled code is empty after postprocessing.`);\n }\n\n // handle some cases by declaring missing globals\n // Babel regeneratorRuntime\n if (processedString.indexOf('regeneratorRuntime') !== -1) {\n processedString = `var regeneratorRuntime;\\n${processedString}`;\n }\n\n return processedString;\n}\n\n/**\n * Processes dependencies and updates argv with an options object\n * @param argv\n */\nexport function processDependencies(argv: YargsArgs) {\n const { depsToTranspile, transpilationMode } = argv;\n const babelifyOptions: Record<string, any> = {};\n if (transpilationMode === TranspilationModes.localAndDeps) {\n const regexpStr = getDependencyRegExp(depsToTranspile as string[]);\n if (regexpStr !== null) {\n babelifyOptions.ignore = [regexpStr];\n }\n }\n return babelifyOptions;\n}\n\n/**\n * Processes a string of space delimited dependencies into one regex string\n * @param dependencies\n * @returns a regexp string\n */\nexport function getDependencyRegExp(dependencies: string[]): RegExp | null {\n let regexp: string | null = null;\n if (!dependencies || dependencies.includes('.') || !dependencies.length) {\n return regexp;\n }\n const paths: string[] = sanitizeDependencyPaths(dependencies);\n regexp = `/node_modules/(?!${paths.shift()}`;\n paths.forEach((path) => (regexp += `|${path}`));\n regexp += '/)';\n return RegExp(regexp, 'u');\n}\n\n/**\n * Helper function remove any leading and trailing slashes from dependency list\n * @param dependencies\n * @returns an array of sanitized paths\n */\nexport function sanitizeDependencyPaths(dependencies: string[]): string[] {\n return dependencies.map((dependency) => {\n return dependency.replace(/^[/\\\\]+/u, '').replace(/[/\\\\]+$/u, '');\n });\n}\n\nexport function processInvalidTranspilation(argv: YargsArgs) {\n if (\n argv.depsToTranspile &&\n argv.transpilationMode !== TranspilationModes.localAndDeps\n ) {\n throw new Error(\n '\"depsToTranspile\" can only be specified if \"transpilationMode\" is set to \"localAndDeps\" .',\n );\n }\n}\n"]}
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const events_1 = require("events");
7
3
  const worker_threads_1 = require("worker_threads");
8
4
  const fs_1 = require("fs");
9
- const crypto_1 = __importDefault(require("crypto"));
5
+ const mock_1 = require("./mock");
10
6
  // eslint-disable-next-line import/no-unassigned-import
11
7
  require("ses/lockdown");
12
8
  lockdown({
@@ -23,27 +19,8 @@ if (worker_threads_1.parentPort !== null) {
23
19
  setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
24
20
  });
25
21
  }
26
- function getMockSnapProvider() {
27
- const mockProvider = new events_1.EventEmitter();
28
- mockProvider.registerRpcMessageHandler = () => true;
29
- mockProvider.request = async () => true;
30
- return mockProvider;
31
- }
32
22
  function getMockEndowments() {
33
- const endowments = {
34
- BigInt,
35
- Buffer,
36
- console,
37
- crypto: crypto_1.default,
38
- Date,
39
- fetch: () => true,
40
- Math,
41
- wallet: getMockSnapProvider(),
42
- setTimeout,
43
- SubtleCrypto: () => undefined,
44
- WebSocket: () => true,
45
- XMLHttpRequest: () => true,
46
- };
23
+ const endowments = mock_1.generateMockEndowments();
47
24
  return Object.assign(Object.assign({}, endowments), { window: endowments });
48
25
  }
49
26
  //# sourceMappingURL=eval-worker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../../../src/cmds/eval/eval-worker.ts"],"names":[],"mappings":";;;;;AAAA,mCAAsC;AACtC,mDAA4C;AAC5C,2BAAkC;AAClC,oDAA4B;AAE5B,uDAAuD;AACvD,wBAAsB;AAStB,QAAQ,CAAC;IACP,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;CACzB,CAAC,CAAC;AAEH,IAAI,2BAAU,KAAK,IAAI,EAAE;IACvB,2BAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAiC,EAAE,EAAE;QAC7D,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAEjC,IAAI,WAAW,CAAC,iBAAiB,EAAE,CAAC,CAAC,QAAQ,CAC3C,iBAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CACnC,CAAC;QACF,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B;IACzE,CAAC,CAAC,CAAC;CACJ;AAED,SAAS,mBAAmB;IAC1B,MAAM,YAAY,GAAG,IAAI,qBAAY,EAA+B,CAAC;IACrE,YAAY,CAAC,yBAAyB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;IACpD,YAAY,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC;IACxC,OAAO,YAAgC,CAAC;AAC1C,CAAC;AAED,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG;QACjB,MAAM;QACN,MAAM;QACN,OAAO;QACP,MAAM,EAAN,gBAAM;QACN,IAAI;QACJ,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;QACjB,IAAI;QACJ,MAAM,EAAE,mBAAmB,EAAE;QAC7B,UAAU;QACV,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;QAC7B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;QACrB,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;KAC3B,CAAC;IAEF,uCACK,UAAU,KACb,MAAM,EAAE,UAAU,IAClB;AACJ,CAAC","sourcesContent":["import { EventEmitter } from 'events';\nimport { parentPort } from 'worker_threads';\nimport { readFileSync } from 'fs';\nimport crypto from 'crypto';\n\n// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\ndeclare let lockdown: any, Compartment: any;\n\ntype MockSnapProvider = EventEmitter & {\n registerRpcMessageHandler: () => any;\n request: () => Promise<any>;\n};\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n});\n\nif (parentPort !== null) {\n parentPort.on('message', (message: { snapFilePath: string }) => {\n const { snapFilePath } = message;\n\n new Compartment(getMockEndowments()).evaluate(\n readFileSync(snapFilePath, 'utf8'),\n );\n setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n });\n}\n\nfunction getMockSnapProvider(): MockSnapProvider {\n const mockProvider = new EventEmitter() as Partial<MockSnapProvider>;\n mockProvider.registerRpcMessageHandler = () => true;\n mockProvider.request = async () => true;\n return mockProvider as MockSnapProvider;\n}\n\nfunction getMockEndowments() {\n const endowments = {\n BigInt,\n Buffer,\n console,\n crypto,\n Date,\n fetch: () => true,\n Math,\n wallet: getMockSnapProvider(),\n setTimeout,\n SubtleCrypto: () => undefined,\n WebSocket: () => true,\n XMLHttpRequest: () => true,\n };\n\n return {\n ...endowments,\n window: endowments,\n };\n}\n"]}
1
+ {"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../../../src/cmds/eval/eval-worker.ts"],"names":[],"mappings":";;AAAA,mDAA4C;AAC5C,2BAAkC;AAClC,iCAAgD;AAEhD,uDAAuD;AACvD,wBAAsB;AAItB,QAAQ,CAAC;IACP,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;CACzB,CAAC,CAAC;AAEH,IAAI,2BAAU,KAAK,IAAI,EAAE;IACvB,2BAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAiC,EAAE,EAAE;QAC7D,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAEjC,IAAI,WAAW,CAAC,iBAAiB,EAAE,CAAC,CAAC,QAAQ,CAC3C,iBAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CACnC,CAAC;QACF,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B;IACzE,CAAC,CAAC,CAAC;CACJ;AAED,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG,6BAAsB,EAAE,CAAC;IAC5C,uCACK,UAAU,KACb,MAAM,EAAE,UAAU,IAClB;AACJ,CAAC","sourcesContent":["import { parentPort } from 'worker_threads';\nimport { readFileSync } from 'fs';\nimport { generateMockEndowments } from './mock';\n\n// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\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\nif (parentPort !== null) {\n parentPort.on('message', (message: { snapFilePath: string }) => {\n const { snapFilePath } = message;\n\n new Compartment(getMockEndowments()).evaluate(\n readFileSync(snapFilePath, 'utf8'),\n );\n setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n });\n}\n\nfunction getMockEndowments() {\n const endowments = generateMockEndowments();\n return {\n ...endowments,\n window: endowments,\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const ALL_APIS: string[];
2
+ export declare const generateMockEndowments: () => Record<string, any>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateMockEndowments = exports.ALL_APIS = void 0;
7
+ const events_1 = __importDefault(require("events"));
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const snap_controllers_1 = require("@metamask/snap-controllers");
10
+ const NETWORK_APIS = ['fetch', 'WebSocket'];
11
+ exports.ALL_APIS = [...snap_controllers_1.DEFAULT_EXPOSED_APIS, ...NETWORK_APIS];
12
+ function getMockSnapProvider() {
13
+ const mockProvider = new events_1.default();
14
+ mockProvider.registerRpcMessageHandler = () => true;
15
+ mockProvider.request = async () => true;
16
+ return mockProvider;
17
+ }
18
+ const isConstructor = (value) => Boolean(value.prototype) && Boolean(value.prototype.constructor.name);
19
+ const mockFunction = () => true;
20
+ class MockClass {
21
+ }
22
+ const handler = {
23
+ construct(Target, args) {
24
+ return new Proxy(new Target(...args), handler);
25
+ },
26
+ get(_target, _prop) {
27
+ return mockFunction;
28
+ },
29
+ };
30
+ const generateMockClass = (value) => {
31
+ return new Proxy(value, handler);
32
+ };
33
+ // Things not currently auto-mocked because of NodeJS, by adding them here we have types for them and can use that to generate mocks if needed
34
+ const mockWindow = {
35
+ WebSocket: MockClass,
36
+ crypto: crypto_1.default,
37
+ SubtleCrypto: MockClass,
38
+ };
39
+ const generateMockEndowment = (key) => {
40
+ const globalValue = global[key];
41
+ // Default exposed APIs don't need to be mocked
42
+ if (globalValue && snap_controllers_1.DEFAULT_EXPOSED_APIS.includes(key)) {
43
+ return globalValue;
44
+ }
45
+ // Fall back to mockWindow for certain APIs not exposed in global in Node.JS
46
+ const globalOrMocked = globalValue !== null && globalValue !== void 0 ? globalValue : mockWindow[key];
47
+ const type = typeof globalOrMocked;
48
+ const isFunction = type === 'function';
49
+ if (isFunction && isConstructor(globalOrMocked)) {
50
+ return generateMockClass(globalOrMocked);
51
+ }
52
+ else if (isFunction || !globalOrMocked) {
53
+ // Fall back to function mock for now
54
+ return mockFunction;
55
+ }
56
+ return globalOrMocked;
57
+ };
58
+ const generateMockEndowments = () => {
59
+ return exports.ALL_APIS.reduce((acc, cur) => (Object.assign(Object.assign({}, acc), { [cur]: generateMockEndowment(cur) })), { wallet: getMockSnapProvider() });
60
+ };
61
+ exports.generateMockEndowments = generateMockEndowments;
62
+ //# sourceMappingURL=mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.js","sourceRoot":"","sources":["../../../src/cmds/eval/mock.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAkC;AAClC,oDAA4B;AAC5B,iEAAkE;AAElE,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAE/B,QAAA,QAAQ,GAAa,CAAC,GAAG,uCAAoB,EAAE,GAAG,YAAY,CAAC,CAAC;AAO7E,SAAS,mBAAmB;IAC1B,MAAM,YAAY,GAAG,IAAI,gBAAY,EAA+B,CAAC;IACrE,YAAY,CAAC,yBAAyB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;IACpD,YAAY,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC;IACxC,OAAO,YAAgC,CAAC;AAC1C,CAAC;AAED,MAAM,aAAa,GAAG,CAAC,KAAU,EAAE,EAAE,CACnC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,SAAS,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AO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEK,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,OAAO,gBAAQ,CAAC,MAAM,CACpB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,iCAAM,GAAG,KAAE,CAAC,GAAG,CAAC,EAAE,qBAAqB,CAAC,GAAG,CAAC,IAAG,EAC7D,EAAE,MAAM,EAAE,mBAAmB,EAAE,EAAE,CAClC,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,sBAAsB,0BAKjC","sourcesContent":["import EventEmitter from 'events';\nimport crypto from 'crypto';\nimport { DEFAULT_EXPOSED_APIS } from '@metamask/snap-controllers';\n\nconst NETWORK_APIS = ['fetch', 'WebSocket'];\n\nexport const ALL_APIS: string[] = [...DEFAULT_EXPOSED_APIS, ...NETWORK_APIS];\n\ntype MockSnapProvider = EventEmitter & {\n registerRpcMessageHandler: () => any;\n request: () => Promise<any>;\n};\n\nfunction getMockSnapProvider(): MockSnapProvider {\n const mockProvider = new EventEmitter() as Partial<MockSnapProvider>;\n mockProvider.registerRpcMessageHandler = () => true;\n mockProvider.request = async () => true;\n return mockProvider as MockSnapProvider;\n}\n\nconst isConstructor = (value: any) =>\n Boolean(value.prototype) && Boolean(value.prototype.constructor.name);\n\nconst mockFunction = () => true;\nclass MockClass {}\n\nconst handler = {\n construct(Target: any, args: any[]): any {\n return new Proxy(new Target(...args), handler);\n },\n get(_target: any, _prop: any) {\n return mockFunction;\n },\n};\n\nconst generateMockClass = (value: any) => {\n return new Proxy(value, handler);\n};\n\n// Things not currently auto-mocked because of NodeJS, by adding them here we have types for them and can use that to generate mocks if needed\nconst mockWindow = {\n WebSocket: MockClass,\n crypto,\n SubtleCrypto: MockClass,\n};\n\nconst generateMockEndowment = (key: string) => {\n const globalValue = (global as any)[key];\n\n // Default exposed APIs don't need to be mocked\n if (globalValue && DEFAULT_EXPOSED_APIS.includes(key)) {\n return globalValue;\n }\n\n // Fall back to mockWindow for certain APIs not exposed in global in Node.JS\n const globalOrMocked = globalValue ?? (mockWindow as any)[key];\n\n const type = typeof globalOrMocked;\n const isFunction = type === 'function';\n if (isFunction && isConstructor(globalOrMocked)) {\n return generateMockClass(globalOrMocked);\n } else if (isFunction || !globalOrMocked) {\n // Fall back to function mock for now\n return mockFunction;\n }\n return globalOrMocked;\n};\n\nexport const generateMockEndowments = () => {\n return ALL_APIS.reduce<Record<string, any>>(\n (acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }),\n { wallet: getMockSnapProvider() },\n );\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-cli",
3
- "version": "0.10.0",
3
+ "version": "0.10.3",
4
4
  "description": "A CLI for developing MetaMask Snaps.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -45,8 +45,8 @@
45
45
  "@babel/plugin-proposal-optional-chaining": "^7.16.7",
46
46
  "@babel/plugin-transform-runtime": "^7.16.7",
47
47
  "@babel/preset-env": "^7.16.7",
48
- "@metamask/snap-controllers": "^0.10.0",
49
- "@nodefactory/strip-comments": "^1.0.2",
48
+ "@metamask/snap-controllers": "^0.10.3",
49
+ "@nodefactory/strip-comments": "^1.0.4",
50
50
  "babelify": "^10.0.0",
51
51
  "browserify": "^17.0.0",
52
52
  "chokidar": "^3.0.2",