@metamask/snaps-execution-environments 7.2.2 → 8.0.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 +20 -1
- package/dist/common/BaseSnapExecutor.cjs +12 -10
- package/dist/common/BaseSnapExecutor.cjs.map +1 -1
- package/dist/common/BaseSnapExecutor.d.cts.map +1 -1
- package/dist/common/BaseSnapExecutor.d.mts.map +1 -1
- package/dist/common/BaseSnapExecutor.mjs +12 -10
- package/dist/common/BaseSnapExecutor.mjs.map +1 -1
- package/dist/common/endowments/network.cjs +4 -4
- package/dist/common/endowments/network.cjs.map +1 -1
- package/dist/common/endowments/network.d.cts.map +1 -1
- package/dist/common/endowments/network.d.mts.map +1 -1
- package/dist/common/endowments/network.mjs +4 -4
- package/dist/common/endowments/network.mjs.map +1 -1
- package/dist/node-process/ChildProcessSnapExecutor.cjs +2 -2
- package/dist/node-process/ChildProcessSnapExecutor.cjs.map +1 -1
- package/dist/node-process/ChildProcessSnapExecutor.mjs +1 -1
- package/dist/node-process/ChildProcessSnapExecutor.mjs.map +1 -1
- package/dist/node-thread/ThreadSnapExecutor.cjs +2 -2
- package/dist/node-thread/ThreadSnapExecutor.cjs.map +1 -1
- package/dist/node-thread/ThreadSnapExecutor.mjs +1 -1
- package/dist/node-thread/ThreadSnapExecutor.mjs.map +1 -1
- package/dist/webpack/iframe/bundle.js +2 -0
- package/dist/webpack/iframe/bundle.js.LICENSE.txt +10 -0
- package/dist/webpack/iframe/index.html +13146 -0
- package/dist/webpack/node-process/bundle.js +12834 -0
- package/dist/{browserify/worker-pool/index.html → webpack/node-process/bundle.js.LICENSE.txt} +11668 -12229
- package/dist/webpack/node-thread/bundle.js +12834 -0
- package/dist/{browserify/iframe/index.html → webpack/node-thread/bundle.js.LICENSE.txt} +11668 -12229
- package/dist/webpack/webview/bundle.js.LICENSE.txt +10 -0
- package/dist/webpack/webview/index.html +13147 -0
- package/dist/webview/WebViewExecutorStream.cjs +1 -2
- package/dist/webview/WebViewExecutorStream.cjs.map +1 -1
- package/dist/webview/WebViewExecutorStream.d.cts.map +1 -1
- package/dist/webview/WebViewExecutorStream.d.mts.map +1 -1
- package/dist/webview/WebViewExecutorStream.mjs +1 -2
- package/dist/webview/WebViewExecutorStream.mjs.map +1 -1
- package/package.json +22 -23
- package/dist/browserify/iframe/bundle.js +0 -9
- package/dist/browserify/node-process/bundle.js +0 -13390
- package/dist/browserify/node-thread/bundle.js +0 -13390
- package/dist/browserify/webview/index.html +0 -13402
- package/dist/browserify/worker-executor/bundle.js +0 -13392
- package/dist/browserify/worker-pool/bundle.js +0 -9
- package/dist/webworker/executor/WebWorkerSnapExecutor.cjs +0 -37
- package/dist/webworker/executor/WebWorkerSnapExecutor.cjs.map +0 -1
- package/dist/webworker/executor/WebWorkerSnapExecutor.d.cts +0 -14
- package/dist/webworker/executor/WebWorkerSnapExecutor.d.cts.map +0 -1
- package/dist/webworker/executor/WebWorkerSnapExecutor.d.mts +0 -14
- package/dist/webworker/executor/WebWorkerSnapExecutor.d.mts.map +0 -1
- package/dist/webworker/executor/WebWorkerSnapExecutor.mjs +0 -37
- package/dist/webworker/executor/WebWorkerSnapExecutor.mjs.map +0 -1
- package/dist/webworker/executor/index.cjs +0 -10
- package/dist/webworker/executor/index.cjs.map +0 -1
- package/dist/webworker/executor/index.d.cts +0 -2
- package/dist/webworker/executor/index.d.cts.map +0 -1
- package/dist/webworker/executor/index.d.mts +0 -2
- package/dist/webworker/executor/index.d.mts.map +0 -1
- package/dist/webworker/executor/index.mjs +0 -8
- package/dist/webworker/executor/index.mjs.map +0 -1
- package/dist/webworker/pool/WebWorkerPool.cjs +0 -168
- package/dist/webworker/pool/WebWorkerPool.cjs.map +0 -1
- package/dist/webworker/pool/WebWorkerPool.d.cts +0 -24
- package/dist/webworker/pool/WebWorkerPool.d.cts.map +0 -1
- package/dist/webworker/pool/WebWorkerPool.d.mts +0 -24
- package/dist/webworker/pool/WebWorkerPool.d.mts.map +0 -1
- package/dist/webworker/pool/WebWorkerPool.mjs +0 -164
- package/dist/webworker/pool/WebWorkerPool.mjs.map +0 -1
- package/dist/webworker/pool/index.cjs +0 -10
- package/dist/webworker/pool/index.cjs.map +0 -1
- package/dist/webworker/pool/index.d.cts +0 -2
- package/dist/webworker/pool/index.d.cts.map +0 -1
- package/dist/webworker/pool/index.d.mts +0 -2
- package/dist/webworker/pool/index.d.mts.map +0 -1
- package/dist/webworker/pool/index.mjs +0 -8
- package/dist/webworker/pool/index.mjs.map +0 -1
|
@@ -181,14 +181,14 @@ const createNetwork = ({ notify } = {}) => {
|
|
|
181
181
|
let openFetchConnection;
|
|
182
182
|
return await withTeardown((async () => {
|
|
183
183
|
try {
|
|
184
|
-
await notify({
|
|
185
|
-
method: 'OutboundRequest',
|
|
186
|
-
params: { source: 'fetch' },
|
|
187
|
-
});
|
|
188
184
|
const fetchPromise = fetch(input, {
|
|
189
185
|
...init,
|
|
190
186
|
signal: abortController.signal,
|
|
191
187
|
});
|
|
188
|
+
await notify({
|
|
189
|
+
method: 'OutboundRequest',
|
|
190
|
+
params: { source: 'fetch' },
|
|
191
|
+
});
|
|
192
192
|
openFetchConnection = {
|
|
193
193
|
cancel: async () => {
|
|
194
194
|
abortController.abort();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.mjs","sourceRoot":"","sources":["../../../src/common/endowments/network.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAGzC,OAAO,EAAE,YAAY,EAAE,qBAAiB;AAExC;;;GAGG;AACH,MAAM,OAAO,eAAe;IAS1B,YACE,UAAoB,EACpB,WAAqC,EACrC,OAA4B,EAC5B,QAA6B;QAZtB,+CAAuC;QAEvC,8CAAsB;QAEtB,2CAA8B;QAE9B,4CAA+B;QAQtC,uBAAA,IAAI,+BAAe,UAAU,MAAA,CAAC;QAC9B,uBAAA,IAAI,gCAAgB,WAAW,MAAA,CAAC;QAChC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M,CAAC,kBAAkB,CAAC,CACjD,CAAC;YACJ,CAAC;YACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC,CAAC,EAAE,EACJ,WAAW,CACZ,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;QAClC,WAAW,CAAC,YAAY,IAAI,CAAC,CAAC;QAC9B,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,eAAe,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACjE,eAAe,CAAC,KAAK,EAAE,CAAC;QACxB,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,4EAA4E;QAC5E,gEAAgE;QAChE,yFAAyF;QACzF,uEAAuE;QACvE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;QACxB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC;QACjC,gBAAgB;KACjB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAU;IAC3D,OAAO,EAAE,aAAa;CACvB,CAAC;AACF,eAAe,eAAe,CAAC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type { EndowmentFactoryOptions } from './commonEndowmentFactory';\nimport { withTeardown } from '../utils';\n\n/**\n * This class wraps a Response object.\n * That way, a teardown process can stop any processes left.\n */\nexport class ResponseWrapper implements Response {\n readonly #teardownRef: { lastTeardown: number };\n\n readonly #ogResponse: Response;\n\n readonly #onStart: () => Promise<void>;\n\n readonly #onFinish: () => Promise<void>;\n\n constructor(\n ogResponse: Response,\n teardownRef: { lastTeardown: number },\n onStart: () => Promise<void>,\n onFinish: () => Promise<void>,\n ) {\n this.#ogResponse = ogResponse;\n this.#teardownRef = teardownRef;\n this.#onStart = onStart;\n this.#onFinish = onFinish;\n }\n\n get body(): ReadableStream<Uint8Array> | null {\n return this.#ogResponse.body;\n }\n\n get bodyUsed() {\n return this.#ogResponse.bodyUsed;\n }\n\n get headers() {\n return this.#ogResponse.headers;\n }\n\n get ok() {\n return this.#ogResponse.ok;\n }\n\n get redirected() {\n return this.#ogResponse.redirected;\n }\n\n get status() {\n return this.#ogResponse.status;\n }\n\n get statusText() {\n return this.#ogResponse.statusText;\n }\n\n get type() {\n return this.#ogResponse.type;\n }\n\n get url() {\n return this.#ogResponse.url;\n }\n\n async text() {\n return await withTeardown<string>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.text();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async arrayBuffer(): Promise<ArrayBuffer> {\n return await withTeardown<ArrayBuffer>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.arrayBuffer();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async blob(): Promise<Blob> {\n return await withTeardown<Blob>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.blob();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n clone(): Response {\n const newResponse = this.#ogResponse.clone();\n return new ResponseWrapper(\n newResponse,\n this.#teardownRef,\n this.#onStart,\n this.#onFinish,\n );\n }\n\n async formData(): Promise<FormData> {\n return await withTeardown<FormData>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.formData();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async json(): Promise<any> {\n return await withTeardown(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.json();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n}\n\n// We redefine the global Response class to overwrite [Symbol.hasInstance].\n// This fixes problems where the response from `fetch` would not pass\n// instance of checks, leading to failures in WASM bindgen.\nclass AlteredResponse extends Response {\n static [Symbol.hasInstance](instance: unknown) {\n return instance instanceof Response || instance instanceof ResponseWrapper;\n }\n}\n\n/**\n * Create a network endowment, consisting of a `fetch` function.\n * This allows us to provide a teardown function, so that we can cancel\n * any pending requests, connections, streams, etc. that may be open when a snap\n * is terminated.\n *\n * This wraps the original implementation of `fetch`,\n * to ensure that a bad actor cannot get access to the original function, thus\n * potentially preventing the network requests from being torn down.\n *\n * @param options - An options bag.\n * @param options.notify - A reference to the notify function of the snap executor.\n * @returns An object containing a wrapped `fetch`\n * function, as well as a teardown function.\n */\nconst createNetwork = ({ notify }: EndowmentFactoryOptions = {}) => {\n assert(notify, 'Notify must be passed to network endowment factory');\n // Open fetch calls or open body streams\n const openConnections = new Set<{ cancel: () => Promise<void> }>();\n // Track last teardown count\n const teardownRef = { lastTeardown: 0 };\n\n // Remove items from openConnections after they were garbage collected\n const cleanup = new FinalizationRegistry<() => void>(\n /* istanbul ignore next: can't test garbage collection without modifying node parameters */\n (callback) => callback(),\n );\n\n const _fetch: typeof fetch = async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const abortController = new AbortController();\n if (init?.signal !== null && init?.signal !== undefined) {\n const originalSignal = init.signal;\n // Merge abort controllers\n originalSignal.addEventListener(\n 'abort',\n () => {\n abortController.abort((originalSignal as any).reason);\n },\n { once: true },\n );\n }\n\n let started = false;\n const onStart = async () => {\n if (!started) {\n started = true;\n await notify({\n method: 'OutboundRequest',\n params: { source: 'fetch' },\n });\n }\n };\n\n let finished = false;\n const onFinish = async () => {\n if (!finished) {\n finished = true;\n await notify({\n method: 'OutboundResponse',\n params: { source: 'fetch' },\n });\n }\n };\n\n let res: Response;\n let openFetchConnection: { cancel: () => Promise<void> } | undefined;\n return await withTeardown(\n (async () => {\n try {\n await notify({\n method: 'OutboundRequest',\n params: { source: 'fetch' },\n });\n const fetchPromise = fetch(input, {\n ...init,\n signal: abortController.signal,\n });\n\n openFetchConnection = {\n cancel: async () => {\n abortController.abort();\n try {\n await fetchPromise;\n } catch {\n /* do nothing */\n }\n },\n };\n openConnections.add(openFetchConnection);\n\n res = new ResponseWrapper(\n await fetchPromise,\n teardownRef,\n onStart,\n onFinish,\n );\n } finally {\n if (openFetchConnection !== undefined) {\n openConnections.delete(openFetchConnection);\n }\n await notify({\n method: 'OutboundResponse',\n params: { source: 'fetch' },\n });\n }\n\n if (res.body !== null) {\n const body = new WeakRef<ReadableStream>(res.body);\n\n const openBodyConnection = {\n cancel:\n /* istanbul ignore next: see it.todo('can be torn down during body read') test */\n async () => {\n try {\n await body.deref()?.cancel();\n } catch {\n /* do nothing */\n }\n },\n };\n openConnections.add(openBodyConnection);\n cleanup.register(\n res.body,\n /* istanbul ignore next: can't test garbage collection without modifying node parameters */\n () => openConnections.delete(openBodyConnection),\n );\n }\n return harden(res);\n })(),\n teardownRef,\n );\n };\n\n const teardownFunction = async () => {\n teardownRef.lastTeardown += 1;\n const promises: Promise<void>[] = [];\n openConnections.forEach(({ cancel }) => promises.push(cancel()));\n openConnections.clear();\n await Promise.all(promises);\n };\n\n return {\n fetch: harden(_fetch),\n // Request, Headers and Response are the endowments injected alongside fetch\n // only when 'endowment:network-access' permission is requested,\n // therefore these are hardened as part of fetch dependency injection within its factory.\n // These endowments are not (and should never be) available by default.\n Request: harden(Request),\n Headers: harden(Headers),\n Response: harden(AlteredResponse),\n teardownFunction,\n };\n};\n\nconst endowmentModule = {\n names: ['fetch', 'Request', 'Headers', 'Response'] as const,\n factory: createNetwork,\n};\nexport default endowmentModule;\n"]}
|
|
1
|
+
{"version":3,"file":"network.mjs","sourceRoot":"","sources":["../../../src/common/endowments/network.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAGzC,OAAO,EAAE,YAAY,EAAE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Content":["import { assert } from '@metamask/utils';\n\nimport type { EndowmentFactoryOptions } from './commonEndowmentFactory';\nimport { withTeardown } from '../utils';\n\n/**\n * This class wraps a Response object.\n * That way, a teardown process can stop any processes left.\n */\nexport class ResponseWrapper implements Response {\n readonly #teardownRef: { lastTeardown: number };\n\n readonly #ogResponse: Response;\n\n readonly #onStart: () => Promise<void>;\n\n readonly #onFinish: () => Promise<void>;\n\n constructor(\n ogResponse: Response,\n teardownRef: { lastTeardown: number },\n onStart: () => Promise<void>,\n onFinish: () => Promise<void>,\n ) {\n this.#ogResponse = ogResponse;\n this.#teardownRef = teardownRef;\n this.#onStart = onStart;\n this.#onFinish = onFinish;\n }\n\n get body(): ReadableStream<Uint8Array> | null {\n return this.#ogResponse.body;\n }\n\n get bodyUsed() {\n return this.#ogResponse.bodyUsed;\n }\n\n get headers() {\n return this.#ogResponse.headers;\n }\n\n get ok() {\n return this.#ogResponse.ok;\n }\n\n get redirected() {\n return this.#ogResponse.redirected;\n }\n\n get status() {\n return this.#ogResponse.status;\n }\n\n get statusText() {\n return this.#ogResponse.statusText;\n }\n\n get type() {\n return this.#ogResponse.type;\n }\n\n get url() {\n return this.#ogResponse.url;\n }\n\n async text() {\n return await withTeardown<string>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.text();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async arrayBuffer(): Promise<ArrayBuffer> {\n return await withTeardown<ArrayBuffer>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.arrayBuffer();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async blob(): Promise<Blob> {\n return await withTeardown<Blob>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.blob();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n clone(): Response {\n const newResponse = this.#ogResponse.clone();\n return new ResponseWrapper(\n newResponse,\n this.#teardownRef,\n this.#onStart,\n this.#onFinish,\n );\n }\n\n async formData(): Promise<FormData> {\n return await withTeardown<FormData>(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.formData();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n\n async json(): Promise<any> {\n return await withTeardown(\n (async () => {\n await this.#onStart();\n try {\n return await this.#ogResponse.json();\n } finally {\n await this.#onFinish();\n }\n })(),\n this.#teardownRef,\n );\n }\n}\n\n// We redefine the global Response class to overwrite [Symbol.hasInstance].\n// This fixes problems where the response from `fetch` would not pass\n// instance of checks, leading to failures in WASM bindgen.\nclass AlteredResponse extends Response {\n static [Symbol.hasInstance](instance: unknown) {\n return instance instanceof Response || instance instanceof ResponseWrapper;\n }\n}\n\n/**\n * Create a network endowment, consisting of a `fetch` function.\n * This allows us to provide a teardown function, so that we can cancel\n * any pending requests, connections, streams, etc. that may be open when a snap\n * is terminated.\n *\n * This wraps the original implementation of `fetch`,\n * to ensure that a bad actor cannot get access to the original function, thus\n * potentially preventing the network requests from being torn down.\n *\n * @param options - An options bag.\n * @param options.notify - A reference to the notify function of the snap executor.\n * @returns An object containing a wrapped `fetch`\n * function, as well as a teardown function.\n */\nconst createNetwork = ({ notify }: EndowmentFactoryOptions = {}) => {\n assert(notify, 'Notify must be passed to network endowment factory');\n // Open fetch calls or open body streams\n const openConnections = new Set<{ cancel: () => Promise<void> }>();\n // Track last teardown count\n const teardownRef = { lastTeardown: 0 };\n\n // Remove items from openConnections after they were garbage collected\n const cleanup = new FinalizationRegistry<() => void>(\n /* istanbul ignore next: can't test garbage collection without modifying node parameters */\n (callback) => callback(),\n );\n\n const _fetch: typeof fetch = async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const abortController = new AbortController();\n if (init?.signal !== null && init?.signal !== undefined) {\n const originalSignal = init.signal;\n // Merge abort controllers\n originalSignal.addEventListener(\n 'abort',\n () => {\n abortController.abort((originalSignal as any).reason);\n },\n { once: true },\n );\n }\n\n let started = false;\n const onStart = async () => {\n if (!started) {\n started = true;\n await notify({\n method: 'OutboundRequest',\n params: { source: 'fetch' },\n });\n }\n };\n\n let finished = false;\n const onFinish = async () => {\n if (!finished) {\n finished = true;\n await notify({\n method: 'OutboundResponse',\n params: { source: 'fetch' },\n });\n }\n };\n\n let res: Response;\n let openFetchConnection: { cancel: () => Promise<void> } | undefined;\n return await withTeardown(\n (async () => {\n try {\n const fetchPromise = fetch(input, {\n ...init,\n signal: abortController.signal,\n });\n\n await notify({\n method: 'OutboundRequest',\n params: { source: 'fetch' },\n });\n\n openFetchConnection = {\n cancel: async () => {\n abortController.abort();\n try {\n await fetchPromise;\n } catch {\n /* do nothing */\n }\n },\n };\n openConnections.add(openFetchConnection);\n\n res = new ResponseWrapper(\n await fetchPromise,\n teardownRef,\n onStart,\n onFinish,\n );\n } finally {\n if (openFetchConnection !== undefined) {\n openConnections.delete(openFetchConnection);\n }\n await notify({\n method: 'OutboundResponse',\n params: { source: 'fetch' },\n });\n }\n\n if (res.body !== null) {\n const body = new WeakRef<ReadableStream>(res.body);\n\n const openBodyConnection = {\n cancel:\n /* istanbul ignore next: see it.todo('can be torn down during body read') test */\n async () => {\n try {\n await body.deref()?.cancel();\n } catch {\n /* do nothing */\n }\n },\n };\n openConnections.add(openBodyConnection);\n cleanup.register(\n res.body,\n /* istanbul ignore next: can't test garbage collection without modifying node parameters */\n () => openConnections.delete(openBodyConnection),\n );\n }\n return harden(res);\n })(),\n teardownRef,\n );\n };\n\n const teardownFunction = async () => {\n teardownRef.lastTeardown += 1;\n const promises: Promise<void>[] = [];\n openConnections.forEach(({ cancel }) => promises.push(cancel()));\n openConnections.clear();\n await Promise.all(promises);\n };\n\n return {\n fetch: harden(_fetch),\n // Request, Headers and Response are the endowments injected alongside fetch\n // only when 'endowment:network-access' permission is requested,\n // therefore these are hardened as part of fetch dependency injection within its factory.\n // These endowments are not (and should never be) available by default.\n Request: harden(Request),\n Headers: harden(Headers),\n Response: harden(AlteredResponse),\n teardownFunction,\n };\n};\n\nconst endowmentModule = {\n names: ['fetch', 'Request', 'Headers', 'Response'] as const,\n factory: createNetwork,\n};\nexport default endowmentModule;\n"]}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ChildProcessSnapExecutor = void 0;
|
|
7
7
|
const object_multiplex_1 = __importDefault(require("@metamask/object-multiplex"));
|
|
8
|
-
const
|
|
8
|
+
const node_1 = require("@metamask/post-message-stream/node");
|
|
9
9
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
10
10
|
const readable_stream_1 = require("readable-stream");
|
|
11
11
|
const BaseSnapExecutor_1 = require("../common/BaseSnapExecutor.cjs");
|
|
@@ -13,7 +13,7 @@ const logging_1 = require("../logging.cjs");
|
|
|
13
13
|
class ChildProcessSnapExecutor extends BaseSnapExecutor_1.BaseSnapExecutor {
|
|
14
14
|
static initialize() {
|
|
15
15
|
(0, logging_1.log)('Worker: Connecting to parent.');
|
|
16
|
-
const parentStream = new
|
|
16
|
+
const parentStream = new node_1.ProcessMessageStream();
|
|
17
17
|
const mux = new object_multiplex_1.default();
|
|
18
18
|
(0, readable_stream_1.pipeline)(parentStream, mux, parentStream, (error) => {
|
|
19
19
|
if (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChildProcessSnapExecutor.cjs","sourceRoot":"","sources":["../../src/node-process/ChildProcessSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,
|
|
1
|
+
{"version":3,"file":"ChildProcessSnapExecutor.cjs","sourceRoot":"","sources":["../../src/node-process/ChildProcessSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,6DAA0E;AAC1E,uDAAoE;AACpE,qDAA2C;AAE3C,qEAA8D;AAC9D,4CAAiC;AAEjC,MAAa,wBAAyB,SAAQ,mCAAgB;IAC5D,MAAM,CAAC,UAAU;QACf,IAAA,aAAG,EAAC,+BAA+B,CAAC,CAAC;QAErC,MAAM,YAAY,GAAG,IAAI,2BAAoB,EAAE,CAAC;QAChD,MAAM,GAAG,GAAG,IAAI,0BAAe,EAAE,CAAC;QAClC,IAAA,0BAAQ,EAAC,YAAY,EAAE,GAAU,EAAE,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;YACzD,IAAI,KAAK,EAAE,CAAC;gBACV,IAAA,sBAAQ,EAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,GAAG,CAAC,YAAY,CAAC,+BAAiB,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,+BAAiB,CAAC,QAAQ,CAAQ,CAAC;QACtE,OAAO,IAAI,wBAAwB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAChE,CAAC;CACF;AAjBD,4DAiBC","sourcesContent":["import ObjectMultiplex from '@metamask/object-multiplex';\nimport { ProcessMessageStream } from '@metamask/post-message-stream/node';\nimport { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils';\nimport { pipeline } from 'readable-stream';\n\nimport { BaseSnapExecutor } from '../common/BaseSnapExecutor';\nimport { log } from '../logging';\n\nexport class ChildProcessSnapExecutor extends BaseSnapExecutor {\n static initialize() {\n log('Worker: Connecting to parent.');\n\n const parentStream = new ProcessMessageStream();\n const mux = new ObjectMultiplex();\n pipeline(parentStream, mux as any, parentStream, (error) => {\n if (error) {\n logError(`Parent stream failure, closing worker.`, error);\n }\n self.close();\n });\n\n const commandStream = mux.createStream(SNAP_STREAM_NAMES.COMMAND);\n const rpcStream = mux.createStream(SNAP_STREAM_NAMES.JSON_RPC) as any;\n return new ChildProcessSnapExecutor(commandStream, rpcStream);\n }\n}\n"]}
|
|
@@ -6,7 +6,7 @@ function $importDefault(module) {
|
|
|
6
6
|
}
|
|
7
7
|
import $ObjectMultiplex from "@metamask/object-multiplex";
|
|
8
8
|
const ObjectMultiplex = $importDefault($ObjectMultiplex);
|
|
9
|
-
import { ProcessMessageStream } from "@metamask/post-message-stream";
|
|
9
|
+
import { ProcessMessageStream } from "@metamask/post-message-stream/node";
|
|
10
10
|
import { logError, SNAP_STREAM_NAMES } from "@metamask/snaps-utils";
|
|
11
11
|
import { pipeline } from "readable-stream";
|
|
12
12
|
import { BaseSnapExecutor } from "../common/BaseSnapExecutor.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChildProcessSnapExecutor.mjs","sourceRoot":"","sources":["../../src/node-process/ChildProcessSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,gBAAe,mCAAmC;;AACzD,OAAO,EAAE,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"ChildProcessSnapExecutor.mjs","sourceRoot":"","sources":["../../src/node-process/ChildProcessSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,gBAAe,mCAAmC;;AACzD,OAAO,EAAE,oBAAoB,EAAE,2CAA2C;AAC1E,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,8BAA8B;AACpE,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAE3C,OAAO,EAAE,gBAAgB,EAAE,uCAAmC;AAC9D,OAAO,EAAE,GAAG,EAAE,uBAAmB;AAEjC,MAAM,OAAO,wBAAyB,SAAQ,gBAAgB;IAC5D,MAAM,CAAC,UAAU;QACf,GAAG,CAAC,+BAA+B,CAAC,CAAC;QAErC,MAAM,YAAY,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAChD,MAAM,GAAG,GAAG,IAAI,eAAe,EAAE,CAAC;QAClC,QAAQ,CAAC,YAAY,EAAE,GAAU,EAAE,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;YACzD,IAAI,KAAK,EAAE,CAAC;gBACV,QAAQ,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,GAAG,CAAC,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,iBAAiB,CAAC,QAAQ,CAAQ,CAAC;QACtE,OAAO,IAAI,wBAAwB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["import ObjectMultiplex from '@metamask/object-multiplex';\nimport { ProcessMessageStream } from '@metamask/post-message-stream/node';\nimport { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils';\nimport { pipeline } from 'readable-stream';\n\nimport { BaseSnapExecutor } from '../common/BaseSnapExecutor';\nimport { log } from '../logging';\n\nexport class ChildProcessSnapExecutor extends BaseSnapExecutor {\n static initialize() {\n log('Worker: Connecting to parent.');\n\n const parentStream = new ProcessMessageStream();\n const mux = new ObjectMultiplex();\n pipeline(parentStream, mux as any, parentStream, (error) => {\n if (error) {\n logError(`Parent stream failure, closing worker.`, error);\n }\n self.close();\n });\n\n const commandStream = mux.createStream(SNAP_STREAM_NAMES.COMMAND);\n const rpcStream = mux.createStream(SNAP_STREAM_NAMES.JSON_RPC) as any;\n return new ChildProcessSnapExecutor(commandStream, rpcStream);\n }\n}\n"]}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ThreadSnapExecutor = void 0;
|
|
7
7
|
const object_multiplex_1 = __importDefault(require("@metamask/object-multiplex"));
|
|
8
|
-
const
|
|
8
|
+
const node_1 = require("@metamask/post-message-stream/node");
|
|
9
9
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
10
10
|
const readable_stream_1 = require("readable-stream");
|
|
11
11
|
const BaseSnapExecutor_1 = require("../common/BaseSnapExecutor.cjs");
|
|
@@ -13,7 +13,7 @@ const logging_1 = require("../logging.cjs");
|
|
|
13
13
|
class ThreadSnapExecutor extends BaseSnapExecutor_1.BaseSnapExecutor {
|
|
14
14
|
static initialize() {
|
|
15
15
|
(0, logging_1.log)('Worker: Connecting to parent.');
|
|
16
|
-
const parentStream = new
|
|
16
|
+
const parentStream = new node_1.ThreadMessageStream();
|
|
17
17
|
const mux = new object_multiplex_1.default();
|
|
18
18
|
(0, readable_stream_1.pipeline)(parentStream, mux, parentStream, (error) => {
|
|
19
19
|
if (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThreadSnapExecutor.cjs","sourceRoot":"","sources":["../../src/node-thread/ThreadSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,
|
|
1
|
+
{"version":3,"file":"ThreadSnapExecutor.cjs","sourceRoot":"","sources":["../../src/node-thread/ThreadSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,6DAAyE;AACzE,uDAAoE;AACpE,qDAA2C;AAE3C,qEAA8D;AAC9D,4CAAiC;AAEjC,MAAa,kBAAmB,SAAQ,mCAAgB;IACtD,MAAM,CAAC,UAAU;QACf,IAAA,aAAG,EAAC,+BAA+B,CAAC,CAAC;QAErC,MAAM,YAAY,GAAG,IAAI,0BAAmB,EAAE,CAAC;QAC/C,MAAM,GAAG,GAAG,IAAI,0BAAe,EAAE,CAAC;QAClC,IAAA,0BAAQ,EAAC,YAAY,EAAE,GAAU,EAAE,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;YACzD,IAAI,KAAK,EAAE,CAAC;gBACV,IAAA,sBAAQ,EAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,GAAG,CAAC,YAAY,CAAC,+BAAiB,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,+BAAiB,CAAC,QAAQ,CAAQ,CAAC;QACtE,OAAO,IAAI,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAjBD,gDAiBC","sourcesContent":["import ObjectMultiplex from '@metamask/object-multiplex';\nimport { ThreadMessageStream } from '@metamask/post-message-stream/node';\nimport { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils';\nimport { pipeline } from 'readable-stream';\n\nimport { BaseSnapExecutor } from '../common/BaseSnapExecutor';\nimport { log } from '../logging';\n\nexport class ThreadSnapExecutor extends BaseSnapExecutor {\n static initialize() {\n log('Worker: Connecting to parent.');\n\n const parentStream = new ThreadMessageStream();\n const mux = new ObjectMultiplex();\n pipeline(parentStream, mux as any, parentStream, (error) => {\n if (error) {\n logError(`Parent stream failure, closing worker.`, error);\n }\n self.close();\n });\n\n const commandStream = mux.createStream(SNAP_STREAM_NAMES.COMMAND);\n const rpcStream = mux.createStream(SNAP_STREAM_NAMES.JSON_RPC) as any;\n return new ThreadSnapExecutor(commandStream, rpcStream);\n }\n}\n"]}
|
|
@@ -6,7 +6,7 @@ function $importDefault(module) {
|
|
|
6
6
|
}
|
|
7
7
|
import $ObjectMultiplex from "@metamask/object-multiplex";
|
|
8
8
|
const ObjectMultiplex = $importDefault($ObjectMultiplex);
|
|
9
|
-
import { ThreadMessageStream } from "@metamask/post-message-stream";
|
|
9
|
+
import { ThreadMessageStream } from "@metamask/post-message-stream/node";
|
|
10
10
|
import { logError, SNAP_STREAM_NAMES } from "@metamask/snaps-utils";
|
|
11
11
|
import { pipeline } from "readable-stream";
|
|
12
12
|
import { BaseSnapExecutor } from "../common/BaseSnapExecutor.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThreadSnapExecutor.mjs","sourceRoot":"","sources":["../../src/node-thread/ThreadSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,gBAAe,mCAAmC;;AACzD,OAAO,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"ThreadSnapExecutor.mjs","sourceRoot":"","sources":["../../src/node-thread/ThreadSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,gBAAe,mCAAmC;;AACzD,OAAO,EAAE,mBAAmB,EAAE,2CAA2C;AACzE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,8BAA8B;AACpE,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAE3C,OAAO,EAAE,gBAAgB,EAAE,uCAAmC;AAC9D,OAAO,EAAE,GAAG,EAAE,uBAAmB;AAEjC,MAAM,OAAO,kBAAmB,SAAQ,gBAAgB;IACtD,MAAM,CAAC,UAAU;QACf,GAAG,CAAC,+BAA+B,CAAC,CAAC;QAErC,MAAM,YAAY,GAAG,IAAI,mBAAmB,EAAE,CAAC;QAC/C,MAAM,GAAG,GAAG,IAAI,eAAe,EAAE,CAAC;QAClC,QAAQ,CAAC,YAAY,EAAE,GAAU,EAAE,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;YACzD,IAAI,KAAK,EAAE,CAAC;gBACV,QAAQ,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,GAAG,CAAC,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,iBAAiB,CAAC,QAAQ,CAAQ,CAAC;QACtE,OAAO,IAAI,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF","sourcesContent":["import ObjectMultiplex from '@metamask/object-multiplex';\nimport { ThreadMessageStream } from '@metamask/post-message-stream/node';\nimport { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils';\nimport { pipeline } from 'readable-stream';\n\nimport { BaseSnapExecutor } from '../common/BaseSnapExecutor';\nimport { log } from '../logging';\n\nexport class ThreadSnapExecutor extends BaseSnapExecutor {\n static initialize() {\n log('Worker: Connecting to parent.');\n\n const parentStream = new ThreadMessageStream();\n const mux = new ObjectMultiplex();\n pipeline(parentStream, mux as any, parentStream, (error) => {\n if (error) {\n logError(`Parent stream failure, closing worker.`, error);\n }\n self.close();\n });\n\n const commandStream = mux.createStream(SNAP_STREAM_NAMES.COMMAND);\n const rpcStream = mux.createStream(SNAP_STREAM_NAMES.JSON_RPC) as any;\n return new ThreadSnapExecutor(commandStream, rpcStream);\n }\n}\n"]}
|