@metamask/snaps-cli 0.10.2 → 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,10 @@ 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
|
+
|
|
9
13
|
## [0.10.2]
|
|
10
14
|
### Fixed
|
|
11
15
|
- Installation failure ([#279](https://github.com/MetaMask/snaps-skunkworks/pull/279))
|
|
@@ -132,7 +136,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
132
136
|
- Example snaps ([#72](https://github.com/MetaMask/snaps-skunkworks/pull/72))
|
|
133
137
|
- The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
|
|
134
138
|
|
|
135
|
-
[Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.
|
|
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
|
|
136
141
|
[0.10.2]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.1...v0.10.2
|
|
137
142
|
[0.10.1]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.0...v0.10.1
|
|
138
143
|
[0.10.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.9.0...v0.10.0
|
|
@@ -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
|
|
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":"
|
|
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,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,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ACvC,IAAI,UAAU,IAAI,aAAa,CAAC,cAAc,CAAC,EAAE;QAC/C,OAAO,iBAAiB,CAAC,cAAc,CAAC,CAAC;KAC1C;SAAM,IAAI,UAAU,IAAI,CAAC,cAAc,EAAE;QACxC,qCAAqC;QACrC,OAAO,YAAY,CAAC;KACrB;IACD,OAAO,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.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -45,7 +45,7 @@
|
|
|
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.
|
|
48
|
+
"@metamask/snap-controllers": "^0.10.3",
|
|
49
49
|
"@nodefactory/strip-comments": "^1.0.4",
|
|
50
50
|
"babelify": "^10.0.0",
|
|
51
51
|
"browserify": "^17.0.0",
|