@metamask/snaps-cli 6.5.2 → 6.5.4
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 +15 -1
- package/dist/webpack/loaders/wasm.cjs +13 -3
- package/dist/webpack/loaders/wasm.cjs.map +1 -1
- package/dist/webpack/loaders/wasm.d.cts.map +1 -1
- package/dist/webpack/loaders/wasm.d.mts.map +1 -1
- package/dist/webpack/loaders/wasm.mjs +14 -4
- package/dist/webpack/loaders/wasm.mjs.map +1 -1
- package/dist/webpack/server.cjs +4 -1
- package/dist/webpack/server.cjs.map +1 -1
- package/dist/webpack/server.d.cts.map +1 -1
- package/dist/webpack/server.d.mts.map +1 -1
- package/dist/webpack/server.mjs +4 -1
- package/dist/webpack/server.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.5.4]
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Bundle and initialize WASM modules using Base64 encoding ([#2913](https://github.com/MetaMask/snaps/pull/2913))
|
|
15
|
+
|
|
16
|
+
## [6.5.3]
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Ignore query strings when parsing URLs ([#2883](https://github.com/MetaMask/snaps/pull/2883))
|
|
21
|
+
|
|
10
22
|
## [6.5.2]
|
|
11
23
|
|
|
12
24
|
### Changed
|
|
@@ -282,7 +294,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
282
294
|
- The version of the package no longer needs to match the version of all other
|
|
283
295
|
MetaMask Snaps packages.
|
|
284
296
|
|
|
285
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.
|
|
297
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.4...HEAD
|
|
298
|
+
[6.5.4]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.3...@metamask/snaps-cli@6.5.4
|
|
299
|
+
[6.5.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.2...@metamask/snaps-cli@6.5.3
|
|
286
300
|
[6.5.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.1...@metamask/snaps-cli@6.5.2
|
|
287
301
|
[6.5.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.0...@metamask/snaps-cli@6.5.1
|
|
288
302
|
[6.5.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.4.0...@metamask/snaps-cli@6.5.0
|
|
@@ -66,8 +66,7 @@ exports.getExports = getExports;
|
|
|
66
66
|
// `this` to the loader context, and TypeScript can infer the type of `this`.
|
|
67
67
|
const loader = async function loader(source) {
|
|
68
68
|
(0, utils_1.assert)(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');
|
|
69
|
-
const
|
|
70
|
-
const wasmModule = await WebAssembly.compile(bytes);
|
|
69
|
+
const wasmModule = await WebAssembly.compile(source);
|
|
71
70
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
72
71
|
const exports = WebAssembly.Module.exports(wasmModule);
|
|
73
72
|
const imports = WebAssembly.Module.imports(wasmModule).reduce((target, descriptor) => {
|
|
@@ -85,7 +84,18 @@ const loader = async function loader(source) {
|
|
|
85
84
|
return `
|
|
86
85
|
${getImports(imports)}
|
|
87
86
|
|
|
88
|
-
const
|
|
87
|
+
const b64 = ${JSON.stringify((0, utils_1.bytesToBase64)(source))};
|
|
88
|
+
|
|
89
|
+
function decode(encoded) {
|
|
90
|
+
const str = atob(encoded);
|
|
91
|
+
const bytes = new Uint8Array(str.length);
|
|
92
|
+
for (let i = 0; i < str.length; i++) {
|
|
93
|
+
bytes[i] = str.charCodeAt(i);
|
|
94
|
+
}
|
|
95
|
+
return bytes;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const bytes = decode(b64);
|
|
89
99
|
const module = new WebAssembly.Module(bytes);
|
|
90
100
|
const instance = new WebAssembly.Instance(module, {
|
|
91
101
|
${getModuleImports(imports)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":";AAAA,0CAA0C;;;AAE1C,
|
|
1
|
+
{"version":3,"file":"wasm.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":";AAAA,0CAA0C;;;AAE1C,2CAAwD;AACxD,+BAAwC;AAGxC;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,CACzD,UAAU,CACX,GAAG,CACP;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AATD,gCASC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,SAAmC;IAClE,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAClE;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAPD,4CAOC;AAED;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,WAAiD;IAC1E,OAAO,WAAW;SACf,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QAClB,IAAI,UAAU,CAAC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E,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;MACH,UAAU,CAAC,OAAO,CAAC;;kBAEP,IAAI,CAAC,SAAS,CAAC,IAAA,qBAAa,EAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;;QAc/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACxD,QAAA,GAAG,GAAG,IAAI,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\n\nimport { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const module = new WebAssembly.Module(bytes);\n const instance = new WebAssembly.Instance(module, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"wasm.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,wBAgDb,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"wasm.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,wBAgDb,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-globals */
|
|
2
|
-
import { assert } from "@metamask/utils";
|
|
2
|
+
import { assert, bytesToBase64 } from "@metamask/utils";
|
|
3
3
|
import { dirname, resolve } from "path";
|
|
4
4
|
/**
|
|
5
5
|
* Get the imports code for the WASM module. This code imports each of the
|
|
@@ -60,8 +60,7 @@ export function getExports(descriptors) {
|
|
|
60
60
|
// `this` to the loader context, and TypeScript can infer the type of `this`.
|
|
61
61
|
const loader = async function loader(source) {
|
|
62
62
|
assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');
|
|
63
|
-
const
|
|
64
|
-
const wasmModule = await WebAssembly.compile(bytes);
|
|
63
|
+
const wasmModule = await WebAssembly.compile(source);
|
|
65
64
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
66
65
|
const exports = WebAssembly.Module.exports(wasmModule);
|
|
67
66
|
const imports = WebAssembly.Module.imports(wasmModule).reduce((target, descriptor) => {
|
|
@@ -79,7 +78,18 @@ const loader = async function loader(source) {
|
|
|
79
78
|
return `
|
|
80
79
|
${getImports(imports)}
|
|
81
80
|
|
|
82
|
-
const
|
|
81
|
+
const b64 = ${JSON.stringify(bytesToBase64(source))};
|
|
82
|
+
|
|
83
|
+
function decode(encoded) {
|
|
84
|
+
const str = atob(encoded);
|
|
85
|
+
const bytes = new Uint8Array(str.length);
|
|
86
|
+
for (let i = 0; i < str.length; i++) {
|
|
87
|
+
bytes[i] = str.charCodeAt(i);
|
|
88
|
+
}
|
|
89
|
+
return bytes;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const bytes = decode(b64);
|
|
83
93
|
const module = new WebAssembly.Module(bytes);
|
|
84
94
|
const instance = new WebAssembly.Instance(module, {
|
|
85
95
|
${getModuleImports(imports)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAE1C,OAAO,EAAE,MAAM,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"wasm.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAE1C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,wBAAwB;AACxD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa;AAGxC;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,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O,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CAE3D,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;;QACvB,MAAM,MAAC,UAAU,CAAC,MAAM,MAAxB,MAAM,OAAwB,EAAE,EAAC;QACjC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEhD,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,wEAAwE;IACxE,WAAW;IACX,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;MACH,UAAU,CAAC,OAAO,CAAC;;kBAEP,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;;QAc/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACrE,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\n\nimport { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const module = new WebAssembly.Module(bytes);\n const instance = new WebAssembly.Instance(module, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
|
package/dist/webpack/server.cjs
CHANGED
|
@@ -70,7 +70,10 @@ function getServer(config) {
|
|
|
70
70
|
const manifestPath = (0, path_1.join)(config.server.root, node_1.NpmSnapFileNames.Manifest);
|
|
71
71
|
const { result } = await (0, node_1.readJsonFile)(manifestPath);
|
|
72
72
|
const allowedPaths = getAllowedPaths(config, result);
|
|
73
|
-
const
|
|
73
|
+
const pathname = request.url &&
|
|
74
|
+
request.headers.host &&
|
|
75
|
+
new URL(request.url, `http://${request.headers.host}`).pathname;
|
|
76
|
+
const path = pathname?.slice(1);
|
|
74
77
|
const allowed = allowedPaths.some((allowedPath) => path === allowedPath);
|
|
75
78
|
if (!allowed) {
|
|
76
79
|
response.statusCode = 404;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.cjs","sourceRoot":"","sources":["../../src/webpack/server.ts"],"names":[],"mappings":";;;;;;AACA,qDAIoC;AAEpC,+BAAoC;AAEpC,+BAA0E;AAC1E,kEAA4C;AAI5C;;;;;;;;;GASG;AACH,SAAS,eAAe,CAAC,IAAY,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apManifest } from '@metamask/snaps-utils';\nimport {\n logError,\n NpmSnapFileNames,\n readJsonFile,\n} from '@metamask/snaps-utils/node';\nimport type { IncomingMessage, Server, ServerResponse } from 'http';\nimport { createServer } from 'http';\nimport type { AddressInfo } from 'net';\nimport { join, relative, resolve as resolvePath, sep, posix } from 'path';\nimport serveMiddleware from 'serve-handler';\n\nimport type { ProcessedConfig } from '../config';\n\n/**\n * Get the relative path from one path to another.\n *\n * Note: This is a modified version of `path.relative` that uses Posix\n * separators for URL-compatibility.\n *\n * @param from - The path to start from.\n * @param to - The path to end at.\n * @returns The relative path.\n */\nfunction getRelativePath(from: string, to: string) {\n return relative(from, to).split(sep).join(posix.sep);\n}\n\n/**\n * Get the allowed paths for the static server. This includes the output file,\n * the manifest file, and any auxiliary/localization files.\n *\n * @param config - The config object.\n * @param manifest - The Snap manifest object.\n * @returns An array of allowed paths.\n */\nexport function getAllowedPaths(\n config: ProcessedConfig,\n manifest: SnapManifest,\n) {\n const auxiliaryFiles =\n manifest.source.files?.map((file) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, file),\n ),\n ) ?? [];\n\n const localizationFiles =\n manifest.source.locales?.map((localization) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, localization),\n ),\n ) ?? [];\n\n const otherFiles = manifest.source.location.npm.iconPath\n ? [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n manifest.source.location.npm.iconPath,\n ),\n ),\n ]\n : [];\n\n return [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n config.output.path,\n config.output.filename,\n ),\n ),\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, NpmSnapFileNames.Manifest),\n ),\n ...auxiliaryFiles,\n ...localizationFiles,\n ...otherFiles,\n ];\n}\n\n/**\n * Get a static server for development purposes.\n *\n * Note: We're intentionally not using `webpack-dev-server` here because it\n * adds a lot of extra stuff to the output that we don't need, and it's\n * difficult to customize.\n *\n * @param config - The config object.\n * @returns An object with a `listen` method that returns a promise that\n * resolves when the server is listening.\n */\nexport function getServer(config: ProcessedConfig) {\n /**\n * Get the response for a request. This is extracted into a function so that\n * we can easily catch errors and send a 500 response.\n *\n * @param request - The request.\n * @param response - The response.\n * @returns A promise that resolves when the response is sent.\n */\n async function getResponse(\n request: IncomingMessage,\n response: ServerResponse,\n ) {\n const manifestPath = join(config.server.root, NpmSnapFileNames.Manifest);\n const { result } = await readJsonFile<SnapManifest>(manifestPath);\n const allowedPaths = getAllowedPaths(config, result);\n\n const pathname =\n request.url &&\n request.headers.host &&\n new URL(request.url, `http://${request.headers.host}`).pathname;\n const path = pathname?.slice(1);\n const allowed = allowedPaths.some((allowedPath) => path === allowedPath);\n\n if (!allowed) {\n response.statusCode = 404;\n response.end();\n return;\n }\n\n await serveMiddleware(request, response, {\n public: config.server.root,\n directoryListing: false,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n });\n }\n\n const server = createServer((request, response) => {\n getResponse(request, response).catch(\n /* istanbul ignore next */\n (error) => {\n logError(error);\n response.statusCode = 500;\n response.end();\n },\n );\n });\n\n /**\n * Start the server on the port specified in the config.\n *\n * @param port - The port to listen on.\n * @returns A promise that resolves when the server is listening. The promise\n * resolves to an object with the port and the server instance. Note that if\n * the `config.server.port` is `0`, the OS will choose a random port for us,\n * so we need to get the port from the server after it starts.\n */\n const listen = async (port = config.server.port) => {\n return new Promise<{\n port: number;\n server: Server;\n close: () => Promise<void>;\n }>((resolve, reject) => {\n try {\n server.listen(port, () => {\n const close = async () => {\n await new Promise<void>((resolveClose, rejectClose) => {\n server.close((closeError) => {\n if (closeError) {\n return rejectClose(closeError);\n }\n\n return resolveClose();\n });\n });\n };\n\n const address = server.address() as AddressInfo;\n resolve({ port: address.port, server, close });\n });\n } catch (listenError) {\n reject(listenError);\n }\n });\n };\n\n return { listen };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.cts","sourceRoot":"","sources":["../../src/webpack/server.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAM1D,OAAO,KAAK,EAAmB,MAAM,EAAkB,aAAa;AAMpE,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAgBjD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,YAAY,YA+CvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe;;
|
|
1
|
+
{"version":3,"file":"server.d.cts","sourceRoot":"","sources":["../../src/webpack/server.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAM1D,OAAO,KAAK,EAAmB,MAAM,EAAkB,aAAa;AAMpE,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAgBjD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,YAAY,YA+CvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe;;cAyErC,MAAM;gBACJ,MAAM;eACP,MAAM,QAAQ,IAAI,CAAC;;EA0B/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","sourceRoot":"","sources":["../../src/webpack/server.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAM1D,OAAO,KAAK,EAAmB,MAAM,EAAkB,aAAa;AAMpE,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAgBjD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,YAAY,YA+CvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe;;
|
|
1
|
+
{"version":3,"file":"server.d.mts","sourceRoot":"","sources":["../../src/webpack/server.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAM1D,OAAO,KAAK,EAAmB,MAAM,EAAkB,aAAa;AAMpE,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAgBjD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,YAAY,YA+CvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe;;cAyErC,MAAM;gBACJ,MAAM;eACP,MAAM,QAAQ,IAAI,CAAC;;EA0B/B"}
|
package/dist/webpack/server.mjs
CHANGED
|
@@ -70,7 +70,10 @@ export function getServer(config) {
|
|
|
70
70
|
const manifestPath = join(config.server.root, NpmSnapFileNames.Manifest);
|
|
71
71
|
const { result } = await readJsonFile(manifestPath);
|
|
72
72
|
const allowedPaths = getAllowedPaths(config, result);
|
|
73
|
-
const
|
|
73
|
+
const pathname = request.url &&
|
|
74
|
+
request.headers.host &&
|
|
75
|
+
new URL(request.url, `http://${request.headers.host}`).pathname;
|
|
76
|
+
const path = pathname?.slice(1);
|
|
74
77
|
const allowed = allowedPaths.some((allowedPath) => path === allowedPath);
|
|
75
78
|
if (!allowed) {
|
|
76
79
|
response.statusCode = 404;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","sourceRoot":"","sources":["../../src/webpack/server.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACb,mCAAmC;AAEpC,OAAO,EAAE,YAAY,EAAE,aAAa;AAEpC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,aAAa;AAC1E,OAAO,gBAAe,sBAAsB;;AAI5C;;;;;;;;;GASG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EAAE,MAAM,EAAE,CAAC;AACpB,CAAC","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n logError,\n NpmSnapFileNames,\n readJsonFile,\n} from '@metamask/snaps-utils/node';\nimport type { IncomingMessage, Server, ServerResponse } from 'http';\nimport { createServer } from 'http';\nimport type { AddressInfo } from 'net';\nimport { join, relative, resolve as resolvePath, sep, posix } from 'path';\nimport serveMiddleware from 'serve-handler';\n\nimport type { ProcessedConfig } from '../config';\n\n/**\n * Get the relative path from one path to another.\n *\n * Note: This is a modified version of `path.relative` that uses Posix\n * separators for URL-compatibility.\n *\n * @param from - The path to start from.\n * @param to - The path to end at.\n * @returns The relative path.\n */\nfunction getRelativePath(from: string, to: string) {\n return relative(from, to).split(sep).join(posix.sep);\n}\n\n/**\n * Get the allowed paths for the static server. This includes the output file,\n * the manifest file, and any auxiliary/localization files.\n *\n * @param config - The config object.\n * @param manifest - The Snap manifest object.\n * @returns An array of allowed paths.\n */\nexport function getAllowedPaths(\n config: ProcessedConfig,\n manifest: SnapManifest,\n) {\n const auxiliaryFiles =\n manifest.source.files?.map((file) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, file),\n ),\n ) ?? [];\n\n const localizationFiles =\n manifest.source.locales?.map((localization) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, localization),\n ),\n ) ?? [];\n\n const otherFiles = manifest.source.location.npm.iconPath\n ? [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n manifest.source.location.npm.iconPath,\n ),\n ),\n ]\n : [];\n\n return [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n config.output.path,\n config.output.filename,\n ),\n ),\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, NpmSnapFileNames.Manifest),\n ),\n ...auxiliaryFiles,\n ...localizationFiles,\n ...otherFiles,\n ];\n}\n\n/**\n * Get a static server for development purposes.\n *\n * Note: We're intentionally not using `webpack-dev-server` here because it\n * adds a lot of extra stuff to the output that we don't need, and it's\n * difficult to customize.\n *\n * @param config - The config object.\n * @returns An object with a `listen` method that returns a promise that\n * resolves when the server is listening.\n */\nexport function getServer(config: ProcessedConfig) {\n /**\n * Get the response for a request. This is extracted into a function so that\n * we can easily catch errors and send a 500 response.\n *\n * @param request - The request.\n * @param response - The response.\n * @returns A promise that resolves when the response is sent.\n */\n async function getResponse(\n request: IncomingMessage,\n response: ServerResponse,\n ) {\n const manifestPath = join(config.server.root, NpmSnapFileNames.Manifest);\n const { result } = await readJsonFile<SnapManifest>(manifestPath);\n const allowedPaths = getAllowedPaths(config, result);\n\n const pathname =\n request.url &&\n request.headers.host &&\n new URL(request.url, `http://${request.headers.host}`).pathname;\n const path = pathname?.slice(1);\n const allowed = allowedPaths.some((allowedPath) => path === allowedPath);\n\n if (!allowed) {\n response.statusCode = 404;\n response.end();\n return;\n }\n\n await serveMiddleware(request, response, {\n public: config.server.root,\n directoryListing: false,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n });\n }\n\n const server = createServer((request, response) => {\n getResponse(request, response).catch(\n /* istanbul ignore next */\n (error) => {\n logError(error);\n response.statusCode = 500;\n response.end();\n },\n );\n });\n\n /**\n * Start the server on the port specified in the config.\n *\n * @param port - The port to listen on.\n * @returns A promise that resolves when the server is listening. The promise\n * resolves to an object with the port and the server instance. Note that if\n * the `config.server.port` is `0`, the OS will choose a random port for us,\n * so we need to get the port from the server after it starts.\n */\n const listen = async (port = config.server.port) => {\n return new Promise<{\n port: number;\n server: Server;\n close: () => Promise<void>;\n }>((resolve, reject) => {\n try {\n server.listen(port, () => {\n const close = async () => {\n await new Promise<void>((resolveClose, rejectClose) => {\n server.close((closeError) => {\n if (closeError) {\n return rejectClose(closeError);\n }\n\n return resolveClose();\n });\n });\n };\n\n const address = server.address() as AddressInfo;\n resolve({ port: address.port, server, close });\n });\n } catch (listenError) {\n reject(listenError);\n }\n });\n };\n\n return { listen };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.4",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"@babel/plugin-transform-runtime": "^7.13.2",
|
|
73
73
|
"@babel/preset-env": "^7.23.2",
|
|
74
74
|
"@babel/preset-typescript": "^7.23.2",
|
|
75
|
-
"@metamask/snaps-sdk": "^6.
|
|
76
|
-
"@metamask/snaps-utils": "^8.
|
|
75
|
+
"@metamask/snaps-sdk": "^6.13.0",
|
|
76
|
+
"@metamask/snaps-utils": "^8.6.1",
|
|
77
77
|
"@metamask/snaps-webpack-plugin": "^4.1.2",
|
|
78
78
|
"@metamask/superstruct": "^3.1.0",
|
|
79
79
|
"@metamask/utils": "^10.0.0",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
124
124
|
"@metamask/eslint-config-typescript": "^12.1.0",
|
|
125
125
|
"@swc/jest": "^0.2.26",
|
|
126
|
-
"@ts-bridge/cli": "^0.
|
|
126
|
+
"@ts-bridge/cli": "^0.6.1",
|
|
127
127
|
"@types/browserify": "^12.0.37",
|
|
128
128
|
"@types/jest": "^27.5.1",
|
|
129
129
|
"@types/node": "18.14.2",
|