@metamask/snaps-execution-environments 6.7.2 → 6.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +112 -1
- package/dist/browserify/iframe/bundle.js +1 -1
- package/dist/browserify/node-process/bundle.js +1 -1
- package/dist/browserify/node-thread/bundle.js +1 -1
- package/dist/browserify/webview/index.html +4 -4
- package/dist/browserify/worker-executor/bundle.js +3 -3
- package/dist/browserify/worker-pool/bundle.js +3 -3
- package/dist/proxy/ProxySnapExecutor.cjs +1 -1
- package/dist/proxy/ProxySnapExecutor.cjs.map +1 -1
- package/dist/proxy/ProxySnapExecutor.mjs +1 -1
- package/dist/proxy/ProxySnapExecutor.mjs.map +1 -1
- package/package.json +37 -26
|
@@ -88,7 +88,7 @@ _ProxySnapExecutor_stream = new WeakMap(), _ProxySnapExecutor_frameUrl = new Wea
|
|
|
88
88
|
* @returns The executor job object.
|
|
89
89
|
*/
|
|
90
90
|
async function _ProxySnapExecutor_initializeJob(jobId) {
|
|
91
|
-
const window = await (0, snaps_utils_1.createWindow)(__classPrivateFieldGet(this, _ProxySnapExecutor_frameUrl, "f"), jobId);
|
|
91
|
+
const window = await (0, snaps_utils_1.createWindow)({ uri: __classPrivateFieldGet(this, _ProxySnapExecutor_frameUrl, "f"), id: jobId });
|
|
92
92
|
const jobStream = new post_message_stream_1.WindowPostMessageStream({
|
|
93
93
|
name: 'parent',
|
|
94
94
|
target: 'child',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxySnapExecutor.cjs","sourceRoot":"","sources":["../../src/proxy/ProxySnapExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,uEAAwE;AACxE,6DAA6D;AAC7D,uGAA8E;AAC9E,uDAA+D;AAE/D,2CAAyC;AAQzC,MAAM,UAAU,GAAG,wCAAwC,sBAAW,CAAC,OAAO,aAAa,CAAC;AAE5F;;;;;;;;;;;;GAYG;AACH,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AAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC,6EAQa,KAAa;IACzB,IAAA,cAAM,EAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,KAAK,cAAc,CAAC,CAAC;IAEtD,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAA,cAAM,EAAC,MAAM,EAAE,mBAAmB,KAAK,cAAc,CAAC,CAAC;IAEvD,MAAM,CAAC,MAAM,EAAE,CAAC;IAChB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAClC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport packageJson from '@metamask/snaps-execution-environments/package.json';\nimport { createWindow, logError } from '@metamask/snaps-utils';\nimport type { JsonRpcRequest } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\ntype ExecutorJob = {\n id: string;\n window: Window;\n stream: WindowPostMessageStream;\n};\n\nconst IFRAME_URL = `https://execution.metamask.io/iframe/${packageJson.version}/index.html`;\n\n/**\n * A \"proxy\" snap executor that uses a level of indirection to execute snaps.\n *\n * Useful for multiple execution environments.\n *\n * This is not a traditional snap executor, as it does not execute snaps itself.\n * Instead, it creates an iframe window for each snap execution, and sends the\n * snap execution request to the iframe window. The iframe window is responsible\n * for executing the snap.\n *\n * This executor is persisted between snap executions. The executor essentially\n * acts as a proxy between the client and the iframe execution environment.\n */\nexport class ProxySnapExecutor {\n readonly #stream: BasePostMessageStream;\n\n readonly #frameUrl: string;\n\n readonly jobs: Record<string, ExecutorJob> = {};\n\n /**\n * Initialize the executor with the given stream. This is a wrapper around the\n * constructor.\n *\n * @param stream - The stream to use for communication.\n * @param frameUrl - An optional URL for the iframe to use.\n * @returns The initialized executor.\n */\n static initialize(stream: BasePostMessageStream, frameUrl = IFRAME_URL) {\n return new ProxySnapExecutor(stream, frameUrl);\n }\n\n constructor(stream: BasePostMessageStream, frameUrl: string) {\n this.#stream = stream;\n this.#stream.on('data', this.#onData.bind(this));\n this.#frameUrl = frameUrl;\n }\n\n /**\n * Handle an incoming message from a `ProxyExecutionService`. This\n * assumes that the message contains a `jobId` property, and a JSON-RPC\n * request in the `data` property.\n *\n * @param data - The message data.\n * @param data.data - The JSON-RPC request.\n * @param data.jobId - The job ID.\n */\n #onData(data: { data: JsonRpcRequest; jobId: string }) {\n const { jobId, data: request } = data;\n\n if (!this.jobs[jobId]) {\n // This ensures that a job is initialized before it is used. To avoid\n // code duplication, we call the `#onData` method again, which will\n // run the rest of the logic after initialization.\n this.#initializeJob(jobId)\n .then(() => {\n this.#onData(data);\n })\n .catch((error) => {\n logError('[Worker] Error initializing job:', error);\n });\n\n return;\n }\n\n // This is a method specific to the `OffscreenSnapExecutor`, as the service\n // itself does not have access to the iframes directly.\n if (request.method === 'terminateJob') {\n this.#terminateJob(jobId);\n return;\n }\n\n this.jobs[jobId].stream.write(request);\n }\n\n /**\n * Create a new iframe and set up a stream to communicate with it.\n *\n * @param jobId - The job ID.\n * @returns The executor job object.\n */\n async #initializeJob(jobId: string): Promise<ExecutorJob> {\n const window = await createWindow({ uri: this.#frameUrl, id: jobId });\n const jobStream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: window, // iframe's internal window\n targetOrigin: '*',\n });\n\n // Write messages from the iframe to the parent, wrapped with the job ID.\n jobStream.on('data', (data) => {\n this.#stream.write({ data, jobId });\n });\n\n this.jobs[jobId] = { id: jobId, window, stream: jobStream };\n return this.jobs[jobId];\n }\n\n /**\n * Terminate the job with the given ID. This will close the iframe and delete\n * the job from the internal job map.\n *\n * @param jobId - The job ID.\n */\n #terminateJob(jobId: string) {\n assert(this.jobs[jobId], `Job \"${jobId}\" not found.`);\n\n const iframe = document.getElementById(jobId);\n assert(iframe, `Iframe with ID \"${jobId}\" not found.`);\n\n iframe.remove();\n this.jobs[jobId].stream.destroy();\n delete this.jobs[jobId];\n }\n}\n"]}
|
|
@@ -82,7 +82,7 @@ _ProxySnapExecutor_stream = new WeakMap(), _ProxySnapExecutor_frameUrl = new Wea
|
|
|
82
82
|
* @returns The executor job object.
|
|
83
83
|
*/
|
|
84
84
|
async function _ProxySnapExecutor_initializeJob(jobId) {
|
|
85
|
-
const window = await createWindow(__classPrivateFieldGet(this, _ProxySnapExecutor_frameUrl, "f"), jobId);
|
|
85
|
+
const window = await createWindow({ uri: __classPrivateFieldGet(this, _ProxySnapExecutor_frameUrl, "f"), id: jobId });
|
|
86
86
|
const jobStream = new WindowPostMessageStream({
|
|
87
87
|
name: 'parent',
|
|
88
88
|
target: 'child',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxySnapExecutor.mjs","sourceRoot":"","sources":["../../src/proxy/ProxySnapExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,6DAA6D;AAC7D,OAAO,WAAW,kFAA4D;AAC9E,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,8BAA8B;AAE/D,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAQzC,MAAM,UAAU,GAAG,wCAAwC,WAAW,CAAC,OAAO,aAAa,CAAC;AAE5F;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,iBAAiB;IAO5B;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,MAA6B,EAAE,QAAQ,GAAG,UAAU;QACpE,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;IAED,YAAY,MAA6B,EAAE,QAAgB;;QAlBlD,4CAA+B;QAE/B,8CAAkB;QAElB,SAAI,GAAgC,EAAE,CAAC;QAe9C,uBAAA,IAAI,6BAAW,MAAM,MAAA,CAAC;QACtB,uB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EAAE,CAAC;IAChB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAClC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport packageJson from '@metamask/snaps-execution-environments/package.json';\nimport { createWindow, logError } from '@metamask/snaps-utils';\nimport type { JsonRpcRequest } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\ntype ExecutorJob = {\n id: string;\n window: Window;\n stream: WindowPostMessageStream;\n};\n\nconst IFRAME_URL = `https://execution.metamask.io/iframe/${packageJson.version}/index.html`;\n\n/**\n * A \"proxy\" snap executor that uses a level of indirection to execute snaps.\n *\n * Useful for multiple execution environments.\n *\n * This is not a traditional snap executor, as it does not execute snaps itself.\n * Instead, it creates an iframe window for each snap execution, and sends the\n * snap execution request to the iframe window. The iframe window is responsible\n * for executing the snap.\n *\n * This executor is persisted between snap executions. The executor essentially\n * acts as a proxy between the client and the iframe execution environment.\n */\nexport class ProxySnapExecutor {\n readonly #stream: BasePostMessageStream;\n\n readonly #frameUrl: string;\n\n readonly jobs: Record<string, ExecutorJob> = {};\n\n /**\n * Initialize the executor with the given stream. This is a wrapper around the\n * constructor.\n *\n * @param stream - The stream to use for communication.\n * @param frameUrl - An optional URL for the iframe to use.\n * @returns The initialized executor.\n */\n static initialize(stream: BasePostMessageStream, frameUrl = IFRAME_URL) {\n return new ProxySnapExecutor(stream, frameUrl);\n }\n\n constructor(stream: BasePostMessageStream, frameUrl: string) {\n this.#stream = stream;\n this.#stream.on('data', this.#onData.bind(this));\n this.#frameUrl = frameUrl;\n }\n\n /**\n * Handle an incoming message from a `ProxyExecutionService`. This\n * assumes that the message contains a `jobId` property, and a JSON-RPC\n * request in the `data` property.\n *\n * @param data - The message data.\n * @param data.data - The JSON-RPC request.\n * @param data.jobId - The job ID.\n */\n #onData(data: { data: JsonRpcRequest; jobId: string }) {\n const { jobId, data: request } = data;\n\n if (!this.jobs[jobId]) {\n // This ensures that a job is initialized before it is used. To avoid\n // code duplication, we call the `#onData` method again, which will\n // run the rest of the logic after initialization.\n this.#initializeJob(jobId)\n .then(() => {\n this.#onData(data);\n })\n .catch((error) => {\n logError('[Worker] Error initializing job:', error);\n });\n\n return;\n }\n\n // This is a method specific to the `OffscreenSnapExecutor`, as the service\n // itself does not have access to the iframes directly.\n if (request.method === 'terminateJob') {\n this.#terminateJob(jobId);\n return;\n }\n\n this.jobs[jobId].stream.write(request);\n }\n\n /**\n * Create a new iframe and set up a stream to communicate with it.\n *\n * @param jobId - The job ID.\n * @returns The executor job object.\n */\n async #initializeJob(jobId: string): Promise<ExecutorJob> {\n const window = await createWindow({ uri: this.#frameUrl, id: jobId });\n const jobStream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: window, // iframe's internal window\n targetOrigin: '*',\n });\n\n // Write messages from the iframe to the parent, wrapped with the job ID.\n jobStream.on('data', (data) => {\n this.#stream.write({ data, jobId });\n });\n\n this.jobs[jobId] = { id: jobId, window, stream: jobStream };\n return this.jobs[jobId];\n }\n\n /**\n * Terminate the job with the given ID. This will close the iframe and delete\n * the job from the internal job map.\n *\n * @param jobId - The job ID.\n */\n #terminateJob(jobId: string) {\n assert(this.jobs[jobId], `Job \"${jobId}\" not found.`);\n\n const iframe = document.getElementById(jobId);\n assert(iframe, `Iframe with ID \"${jobId}\" not found.`);\n\n iframe.remove();\n this.jobs[jobId].stream.destroy();\n delete this.jobs[jobId];\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-execution-environments",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.9.0",
|
|
4
4
|
"description": "Snap sandbox environments for executing SES javascript",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"MetaMask",
|
|
7
|
+
"Snaps",
|
|
8
|
+
"Ethereum"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/MetaMask/snaps/tree/main/packages/snaps-execution-environments#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/MetaMask/snaps/issues"
|
|
13
|
+
},
|
|
5
14
|
"repository": {
|
|
6
15
|
"type": "git",
|
|
7
16
|
"url": "https://github.com/MetaMask/snaps.git"
|
|
8
17
|
},
|
|
18
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
9
19
|
"sideEffects": false,
|
|
10
20
|
"exports": {
|
|
11
21
|
".": {
|
|
@@ -18,12 +28,8 @@
|
|
|
18
28
|
"default": "./dist/index.cjs"
|
|
19
29
|
}
|
|
20
30
|
},
|
|
21
|
-
"./dist/browserify/node-process/bundle.js":
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
"./dist/browserify/node-thread/bundle.js": {
|
|
25
|
-
"default": "./dist/browserify/node-thread/bundle.js"
|
|
26
|
-
},
|
|
31
|
+
"./dist/browserify/node-process/bundle.js": "./dist/browserify/node-process/bundle.js",
|
|
32
|
+
"./dist/browserify/node-thread/bundle.js": "./dist/browserify/node-thread/bundle.js",
|
|
27
33
|
"./package.json": "./package.json"
|
|
28
34
|
},
|
|
29
35
|
"main": "./dist/index.cjs",
|
|
@@ -33,25 +39,29 @@
|
|
|
33
39
|
"dist"
|
|
34
40
|
],
|
|
35
41
|
"scripts": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"test:browser": "wdio run wdio.config.js",
|
|
39
|
-
"test:ci": "yarn test",
|
|
40
|
-
"test:watch": "jest --watch",
|
|
41
|
-
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
|
|
42
|
-
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ./.prettierignore",
|
|
43
|
-
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
|
|
44
|
-
"lint:changelog": "../../scripts/validate-changelog.sh @metamask/snaps-execution-environments",
|
|
45
|
-
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog && yarn lint:dependencies",
|
|
46
|
-
"clean": "rimraf '*.tsbuildinfo' 'dist' 'src/__GENERATED__/' 'coverage/*' '__test__/*'",
|
|
47
|
-
"build": "ts-bridge --project tsconfig.build.json --verbose --no-references && yarn build:lavamoat",
|
|
42
|
+
"auto-changelog-init": "auto-changelog init",
|
|
43
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
48
44
|
"build:lavamoat": "lavamoat scripts/build.js --policy lavamoat/build-system/policy.json --policyOverride lavamoat/build-system/policy-override.json",
|
|
49
45
|
"build:lavamoat:policy": "yarn build:lavamoat --writeAutoPolicy && node scripts/build.js --writeAutoPolicy",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
46
|
+
"build:post": "yarn build:lavamoat",
|
|
47
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/snaps-execution-environments",
|
|
48
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/snaps-execution-environments",
|
|
49
|
+
"clean": "rimraf '*.tsbuildinfo' 'dist' 'src/__GENERATED__/' 'coverage/*' '__test__/*'",
|
|
50
|
+
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn changelog:validate && yarn lint:dependencies",
|
|
52
51
|
"lint:ci": "yarn lint",
|
|
52
|
+
"lint:dependencies": "depcheck",
|
|
53
|
+
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
|
|
54
|
+
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
|
|
55
|
+
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ./.prettierignore",
|
|
56
|
+
"publish:preview": "yarn npm publish --tag preview",
|
|
57
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
53
58
|
"start": "node scripts/start.js",
|
|
54
|
-
"
|
|
59
|
+
"test": "jest --reporters=jest-silent-reporter && yarn test:browser",
|
|
60
|
+
"test:browser": "wdio run wdio.config.js",
|
|
61
|
+
"test:clean": "jest --clearCache",
|
|
62
|
+
"test:post": "ts-node scripts/coverage.ts && rimraf coverage/jest coverage/wdio",
|
|
63
|
+
"test:verbose": "jest --verbose",
|
|
64
|
+
"test:watch": "jest --watch"
|
|
55
65
|
},
|
|
56
66
|
"dependencies": {
|
|
57
67
|
"@metamask/json-rpc-engine": "^9.0.2",
|
|
@@ -59,8 +69,8 @@
|
|
|
59
69
|
"@metamask/post-message-stream": "^8.1.1",
|
|
60
70
|
"@metamask/providers": "^17.1.2",
|
|
61
71
|
"@metamask/rpc-errors": "^6.3.1",
|
|
62
|
-
"@metamask/snaps-sdk": "^6.
|
|
63
|
-
"@metamask/snaps-utils": "^8.
|
|
72
|
+
"@metamask/snaps-sdk": "^6.7.0",
|
|
73
|
+
"@metamask/snaps-utils": "^8.3.0",
|
|
64
74
|
"@metamask/superstruct": "^3.1.0",
|
|
65
75
|
"@metamask/utils": "^9.2.1",
|
|
66
76
|
"nanoid": "^3.1.31",
|
|
@@ -115,10 +125,11 @@
|
|
|
115
125
|
"jest": "^29.0.2",
|
|
116
126
|
"jest-environment-node": "^29.5.0",
|
|
117
127
|
"jest-fetch-mock": "^3.0.3",
|
|
128
|
+
"jest-silent-reporter": "^0.6.0",
|
|
118
129
|
"lavamoat": "^8.0.4",
|
|
119
130
|
"lavamoat-browserify": "^17.0.5",
|
|
120
|
-
"prettier": "^2.
|
|
121
|
-
"prettier-plugin-packagejson": "^2.2
|
|
131
|
+
"prettier": "^2.8.8",
|
|
132
|
+
"prettier-plugin-packagejson": "^2.5.2",
|
|
122
133
|
"rimraf": "^4.1.2",
|
|
123
134
|
"serve-handler": "^6.1.5",
|
|
124
135
|
"ses": "^1.1.0",
|