@metamask/snaps-execution-environments 0.28.0 → 0.29.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/dist/common/BaseSnapExecutor.js +4 -3
- package/dist/common/BaseSnapExecutor.js.map +1 -1
- package/dist/common/endowments/commonEndowmentFactory.d.ts +19 -0
- package/dist/common/endowments/commonEndowmentFactory.js +69 -0
- package/dist/common/endowments/commonEndowmentFactory.js.map +1 -0
- package/dist/common/endowments/crypto.js +4 -1
- package/dist/common/endowments/crypto.js.map +1 -1
- package/dist/common/endowments/date.d.ts +15 -0
- package/dist/common/endowments/date.js +39 -0
- package/dist/common/endowments/date.js.map +1 -0
- package/dist/common/endowments/index.d.ts +1 -1
- package/dist/common/endowments/index.js +6 -6
- package/dist/common/endowments/index.js.map +1 -1
- package/dist/common/endowments/interval.js +7 -4
- package/dist/common/endowments/interval.js.map +1 -1
- package/dist/common/endowments/math.js +2 -2
- package/dist/common/endowments/math.js.map +1 -1
- package/dist/common/endowments/network.js +2 -2
- package/dist/common/endowments/network.js.map +1 -1
- package/dist/common/endowments/textDecoder.d.ts +10 -0
- package/dist/common/endowments/textDecoder.js +18 -0
- package/dist/common/endowments/textDecoder.js.map +1 -0
- package/dist/common/endowments/textEncoder.d.ts +10 -0
- package/dist/common/endowments/textEncoder.js +18 -0
- package/dist/common/endowments/textEncoder.js.map +1 -0
- package/dist/common/endowments/timeout.js +6 -4
- package/dist/common/endowments/timeout.js.map +1 -1
- package/dist/common/lockdown/lockdown-more.js +2 -1
- package/dist/common/lockdown/lockdown-more.js.map +1 -1
- package/dist/common/lockdown/lockdown.js +2 -1
- package/dist/common/lockdown/lockdown.js.map +1 -1
- package/dist/common/utils.js +3 -2
- package/dist/common/utils.js.map +1 -1
- package/dist/iframe/IFrameSnapExecutor.js +3 -2
- package/dist/iframe/IFrameSnapExecutor.js.map +1 -1
- package/dist/logging.d.ts +8 -0
- package/dist/logging.js +13 -0
- package/dist/logging.js.map +1 -0
- package/dist/node-process/ChildProcessSnapExecutor.js +3 -2
- package/dist/node-process/ChildProcessSnapExecutor.js.map +1 -1
- package/dist/node-thread/ThreadSnapExecutor.js +3 -2
- package/dist/node-thread/ThreadSnapExecutor.js.map +1 -1
- package/dist/offscreen/OffscreenSnapExecutor.js +1 -1
- package/dist/offscreen/OffscreenSnapExecutor.js.map +1 -1
- package/dist/webpack/iframe/bundle.js +2 -2
- package/dist/webpack/node-process/bundle.js +2 -2
- package/dist/webpack/node-thread/bundle.js +2 -2
- package/dist/webpack/offscreen/bundle.js +2 -2
- package/package.json +8 -6
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Creates TextDecoder function hardened by SES.
|
|
5
|
+
*
|
|
6
|
+
* @returns An object with the attenuated `TextDecoder` function.
|
|
7
|
+
*/
|
|
8
|
+
const createTextDecoder = () => {
|
|
9
|
+
return {
|
|
10
|
+
TextDecoder: harden(TextDecoder),
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const endowmentModule = {
|
|
14
|
+
names: ['TextDecoder'],
|
|
15
|
+
factory: createTextDecoder,
|
|
16
|
+
};
|
|
17
|
+
exports.default = endowmentModule;
|
|
18
|
+
//# sourceMappingURL=textDecoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textDecoder.js","sourceRoot":"","sources":["../../../src/common/endowments/textDecoder.ts"],"names":[],"mappings":";;AAAA;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC7B,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC;KACxB,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,aAAa,CAAU;IAC/B,OAAO,EAAE,iBAAiB;CAC3B,CAAC;AACF,kBAAe,eAAe,CAAC","sourcesContent":["/**\n * Creates TextDecoder function hardened by SES.\n *\n * @returns An object with the attenuated `TextDecoder` function.\n */\nconst createTextDecoder = () => {\n return {\n TextDecoder: harden(TextDecoder),\n } as const;\n};\n\nconst endowmentModule = {\n names: ['TextDecoder'] as const,\n factory: createTextDecoder,\n};\nexport default endowmentModule;\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Creates TextEncoder function hardened by SES.
|
|
5
|
+
*
|
|
6
|
+
* @returns An object with the attenuated `TextEncoder` function.
|
|
7
|
+
*/
|
|
8
|
+
const createTextEncoder = () => {
|
|
9
|
+
return {
|
|
10
|
+
TextEncoder: harden(TextEncoder),
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const endowmentModule = {
|
|
14
|
+
names: ['TextEncoder'],
|
|
15
|
+
factory: createTextEncoder,
|
|
16
|
+
};
|
|
17
|
+
exports.default = endowmentModule;
|
|
18
|
+
//# sourceMappingURL=textEncoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textEncoder.js","sourceRoot":"","sources":["../../../src/common/endowments/textEncoder.ts"],"names":[],"mappings":";;AAAA;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC7B,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC;KACxB,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,aAAa,CAAU;IAC/B,OAAO,EAAE,iBAAiB;CAC3B,CAAC;AACF,kBAAe,eAAe,CAAC","sourcesContent":["/**\n * Creates TextEncoder function hardened by SES.\n *\n * @returns An object with the attenuated `TextEncoder` function.\n */\nconst createTextEncoder = () => {\n return {\n TextEncoder: harden(TextEncoder),\n } as const;\n};\n\nconst endowmentModule = {\n names: ['TextEncoder'] as const,\n factory: createTextEncoder,\n};\nexport default endowmentModule;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MINIMUM_TIMEOUT = 10;
|
|
3
4
|
/**
|
|
4
5
|
* Creates a pair of `setTimeout` and `clearTimeout` functions attenuated such
|
|
5
6
|
* that:
|
|
@@ -16,11 +17,12 @@ const createTimeout = () => {
|
|
|
16
17
|
if (typeof handler !== 'function') {
|
|
17
18
|
throw new Error(`The timeout handler must be a function. Received: ${typeof handler}`);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
harden(handler);
|
|
21
|
+
const handle = Object.freeze(Object.create(null));
|
|
20
22
|
const platformHandle = setTimeout(() => {
|
|
21
23
|
registeredHandles.delete(handle);
|
|
22
24
|
handler();
|
|
23
|
-
}, timeout);
|
|
25
|
+
}, Math.max(MINIMUM_TIMEOUT, timeout !== null && timeout !== void 0 ? timeout : 0));
|
|
24
26
|
registeredHandles.set(handle, platformHandle);
|
|
25
27
|
return handle;
|
|
26
28
|
};
|
|
@@ -37,8 +39,8 @@ const createTimeout = () => {
|
|
|
37
39
|
}
|
|
38
40
|
};
|
|
39
41
|
return {
|
|
40
|
-
setTimeout: _setTimeout,
|
|
41
|
-
clearTimeout: _clearTimeout,
|
|
42
|
+
setTimeout: harden(_setTimeout),
|
|
43
|
+
clearTimeout: harden(_clearTimeout),
|
|
42
44
|
teardownFunction,
|
|
43
45
|
};
|
|
44
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../../src/common/endowments/timeout.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;GASG;AACH,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEtD,MAAM,WAAW,GAAG,CAAC,OAAqB,EAAE,OAAgB,EAAW,EAAE;QACvE,IAAI,OAAO,OAAO,KAAK,UAAU,E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MAAM,gBAAgB,GAAG,GAAS,EAAE;QAClC,KAAK,MAAM,MAAM,IAAI,iBAAiB,CAAC,IAAI,EAAE,EAAE;YAC7C,aAAa,CAAC,MAAM,CAAC,CAAC;SACvB;IACH,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC;QAC/B,YAAY,EAAE,MAAM,CAAC,aAAa,CAAC;QACnC,gBAAgB;KACR,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,YAAY,EAAE,cAAc,CAAU;IAC9C,OAAO,EAAE,aAAa;CACvB,CAAC;AACF,kBAAe,eAAe,CAAC","sourcesContent":["const MINIMUM_TIMEOUT = 10;\n\n/**\n * Creates a pair of `setTimeout` and `clearTimeout` functions attenuated such\n * that:\n * - `setTimeout` throws if its \"handler\" parameter is not a function.\n * - `clearTimeout` only clears timeouts created by its sibling `setTimeout`,\n * or else no-ops.\n *\n * @returns An object with the attenuated `setTimeout` and `clearTimeout`\n * functions.\n */\nconst createTimeout = () => {\n const registeredHandles = new Map<unknown, unknown>();\n\n const _setTimeout = (handler: TimerHandler, timeout?: number): unknown => {\n if (typeof handler !== 'function') {\n throw new Error(\n `The timeout handler must be a function. Received: ${typeof handler}`,\n );\n }\n harden(handler);\n const handle = Object.freeze(Object.create(null));\n const platformHandle = setTimeout(() => {\n registeredHandles.delete(handle);\n handler();\n }, Math.max(MINIMUM_TIMEOUT, timeout ?? 0));\n\n registeredHandles.set(handle, platformHandle);\n return handle;\n };\n\n const _clearTimeout = (handle: unknown): void => {\n const platformHandle = registeredHandles.get(handle);\n if (platformHandle !== undefined) {\n clearTimeout(platformHandle as any);\n registeredHandles.delete(handle);\n }\n };\n\n const teardownFunction = (): void => {\n for (const handle of registeredHandles.keys()) {\n _clearTimeout(handle);\n }\n };\n\n return {\n setTimeout: harden(_setTimeout),\n clearTimeout: harden(_clearTimeout),\n teardownFunction,\n } as const;\n};\n\nconst endowmentModule = {\n names: ['setTimeout', 'clearTimeout'] as const,\n factory: createTimeout,\n};\nexport default endowmentModule;\n"]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/// <reference path="../../../../../node_modules/ses/index.d.ts" />
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.executeLockdownMore = void 0;
|
|
6
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
6
7
|
/**
|
|
7
8
|
* The SES `lockdown` function only hardens the properties enumerated by the
|
|
8
9
|
* universalPropertyNames constant specified in 'ses/src/whitelist'. This
|
|
@@ -67,7 +68,7 @@ function executeLockdownMore() {
|
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
catch (error) {
|
|
70
|
-
|
|
71
|
+
(0, snaps_utils_1.logError)('Protecting intrinsics failed:', error);
|
|
71
72
|
throw error;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lockdown-more.js","sourceRoot":"","sources":["../../../src/common/lockdown/lockdown-more.ts"],"names":[],"mappings":";AAAA,qFAAqF;AACrF,mEAAmE;;;AAEnE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,mBAAmB;IACjC,gEAAgE;IAChE,oDAAoD;IACpD,gEAAgE;IAChE,oBAAoB;IACpB,IAAI;QACF,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC,UAAU,CAAC,CAAC;QAEtE,sEAAsE;QACtE,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAkB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;QAE5E,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;YAC/B,yEAAyE;YACzE,oEAAoE;YACpE,8CAA8C;YAC9C,GAAG,eAAe;YAElB,gDAAgD;YAChD,sDAAsD;YACtD,8BAA8B;SAC/B,CAAC,CAAC;QAEH,gBAAgB,CAAC,OAAO,C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E;YACpE,8CAA8C;YAC9C,GAAG,eAAe;YAElB,gDAAgD;YAChD,sDAAsD;YACtD,8BAA8B;SAC/B,CAAC,CAAC;QAEH,gBAAgB,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;YACxC,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CACjD,UAAU,EACV,YAAY,CACb,CAAC;YAEF,IAAI,UAAU,EAAE;gBACd,IAAI,UAAU,CAAC,YAAY,EAAE;oBAC3B,yDAAyD;oBACzD,mEAAmE;oBACnE,gBAAgB;oBAChB,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE;wBAC3B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,YAAY,EAAE;4BAC9C,YAAY,EAAE,KAAK;yBACpB,CAAC,CAAC;qBACJ;yBAAM;wBACL,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,YAAY,EAAE;4BAC9C,YAAY,EAAE,KAAK;4BACnB,QAAQ,EAAE,KAAK;yBAChB,CAAC,CAAC;qBACJ;iBACF;gBAED,IAAI,oBAAoB,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;oBAC1C,MAAM,CAAE,UAAkB,CAAC,YAAY,CAAC,CAAC,CAAC;iBAC3C;aACF;QACH,CAAC,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,sBAAQ,EAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAtDD,kDAsDC;AAED;;;;;;;;;GASG;AACH,SAAS,WAAW,CAAC,UAAe;IAClC,OAAO,KAAK,IAAI,UAAU,IAAI,KAAK,IAAI,UAAU,CAAC;AACpD,CAAC","sourcesContent":["// eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment\n/// <reference path=\"../../../../../node_modules/ses/index.d.ts\" />\n\nimport { logError } from '@metamask/snaps-utils';\n\n/**\n * The SES `lockdown` function only hardens the properties enumerated by the\n * universalPropertyNames constant specified in 'ses/src/whitelist'. This\n * function makes all function and object properties on the start compartment\n * global non-configurable and non-writable, unless they are already\n * non-configurable.\n *\n * It is critical that this function runs at the right time during\n * initialization, which should always be immediately after `lockdown` has been\n * called. At the time of writing, the modifications this function makes to the\n * runtime environment appear to be non-breaking, but that could change with\n * the addition of dependencies, or the order of our scripts in our HTML files.\n * Exercise caution.\n *\n * See inline comments for implementation details.\n *\n * We write this function in IIFE format to avoid polluting global scope.\n *\n * @throws If the lockdown failed.\n */\nexport function executeLockdownMore() {\n // Make all \"object\" and \"function\" own properties of globalThis\n // non-configurable and non-writable, when possible.\n // We call a property that is non-configurable and non-writable,\n // \"non-modifiable\".\n try {\n const namedIntrinsics = Reflect.ownKeys(new Compartment().globalThis);\n\n // These named intrinsics are not automatically hardened by `lockdown`\n const shouldHardenManually = new Set<symbol | string>(['eval', 'Function']);\n\n const globalProperties = new Set([\n // universalPropertyNames is a constant added by lockdown to global scope\n // at the time of writing, it is initialized in 'ses/src/whitelist'.\n // These properties tend to be non-enumerable.\n ...namedIntrinsics,\n\n // TODO: Also include the named platform globals\n // This grabs every enumerable property on globalThis.\n // ...Object.keys(globalThis),\n ]);\n\n globalProperties.forEach((propertyName) => {\n const descriptor = Reflect.getOwnPropertyDescriptor(\n globalThis,\n propertyName,\n );\n\n if (descriptor) {\n if (descriptor.configurable) {\n // If the property on globalThis is configurable, make it\n // non-configurable. If it has no accessor properties, also make it\n // non-writable.\n if (hasAccessor(descriptor)) {\n Object.defineProperty(globalThis, propertyName, {\n configurable: false,\n });\n } else {\n Object.defineProperty(globalThis, propertyName, {\n configurable: false,\n writable: false,\n });\n }\n }\n\n if (shouldHardenManually.has(propertyName)) {\n harden((globalThis as any)[propertyName]);\n }\n }\n });\n } catch (error) {\n logError('Protecting intrinsics failed:', error);\n throw error;\n }\n}\n\n/**\n * Checks whether the given propertyName descriptor has any accessors, i.e. the\n * properties `get` or `set`.\n *\n * We want to make globals non-writable, and we can't set the `writable`\n * property and accessor properties at the same time.\n *\n * @param descriptor - The propertyName descriptor to check.\n * @returns Whether the propertyName descriptor has any accessors.\n */\nfunction hasAccessor(descriptor: any): boolean {\n return 'set' in descriptor || 'get' in descriptor;\n}\n"]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/// <reference path="../../../../../node_modules/ses/index.d.ts" />
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.executeLockdown = void 0;
|
|
6
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
6
7
|
/**
|
|
7
8
|
* Execute SES lockdown in the current context, i.e., the current iframe.
|
|
8
9
|
*
|
|
@@ -20,7 +21,7 @@ function executeLockdown() {
|
|
|
20
21
|
}
|
|
21
22
|
catch (error) {
|
|
22
23
|
// If the `lockdown` call throws an exception, it should not be able to continue
|
|
23
|
-
|
|
24
|
+
(0, snaps_utils_1.logError)('Lockdown failed:', error);
|
|
24
25
|
throw error;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lockdown.js","sourceRoot":"","sources":["../../../src/common/lockdown/lockdown.ts"],"names":[],"mappings":";AAAA,qFAAqF;AACrF,mEAAmE;;;AAEnE;;;;GAIG;AACH,SAAgB,eAAe;IAC7B,IAAI;QACF,QAAQ,CAAC;YACP,aAAa,EAAE,QAAQ;YACvB,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,QAAQ;YACpB,UAAU,EAAE,QAAQ;YACpB,cAAc,EAAE,QAAQ;SACzB,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,gFAAgF;QAChF,
|
|
1
|
+
{"version":3,"file":"lockdown.js","sourceRoot":"","sources":["../../../src/common/lockdown/lockdown.ts"],"names":[],"mappings":";AAAA,qFAAqF;AACrF,mEAAmE;;;AAEnE,uDAAiD;AAEjD;;;;GAIG;AACH,SAAgB,eAAe;IAC7B,IAAI;QACF,QAAQ,CAAC;YACP,aAAa,EAAE,QAAQ;YACvB,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,QAAQ;YACpB,UAAU,EAAE,QAAQ;YACpB,cAAc,EAAE,QAAQ;SACzB,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,gFAAgF;QAChF,IAAA,sBAAQ,EAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACpC,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAdD,0CAcC","sourcesContent":["// eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment\n/// <reference path=\"../../../../../node_modules/ses/index.d.ts\" />\n\nimport { logError } from '@metamask/snaps-utils';\n\n/**\n * Execute SES lockdown in the current context, i.e., the current iframe.\n *\n * @throws If the SES lockdown failed.\n */\nexport function executeLockdown() {\n try {\n lockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n });\n } catch (error) {\n // If the `lockdown` call throws an exception, it should not be able to continue\n logError('Lockdown failed:', error);\n throw error;\n }\n}\n"]}
|
package/dist/common/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withTeardown = exports.constructError = void 0;
|
|
4
|
+
const logging_1 = require("../logging");
|
|
4
5
|
/**
|
|
5
6
|
* Takes an error that was thrown, determines if it is
|
|
6
7
|
* an error object. If it is then it will return that. Otherwise,
|
|
@@ -41,7 +42,7 @@ async function withTeardown(originalPromise, teardownRef) {
|
|
|
41
42
|
resolve(value);
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
44
|
-
|
|
45
|
+
(0, logging_1.log)('Late promise received after Snap finished execution. Promise will be dropped.');
|
|
45
46
|
}
|
|
46
47
|
})
|
|
47
48
|
.catch((reason) => {
|
|
@@ -49,7 +50,7 @@ async function withTeardown(originalPromise, teardownRef) {
|
|
|
49
50
|
reject(reason);
|
|
50
51
|
}
|
|
51
52
|
else {
|
|
52
|
-
|
|
53
|
+
(0, logging_1.log)('Late promise received after Snap finished execution. Promise will be dropped.');
|
|
53
54
|
}
|
|
54
55
|
});
|
|
55
56
|
});
|
package/dist/common/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,aAAsB;IACnD,IAAI,cAAiC,CAAC;IACtC,IAAI,aAAa,YAAY,KAAK,EAAE;QAClC,cAAc,GAAG,aAAa,CAAC;KAChC;SAAM,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;QAC5C,cAAc,GAAG,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QAC1C,qCAAqC;QACrC,OAAO,cAAc,CAAC,KAAK,CAAC;KAC7B;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAVD,wCAUC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,eAA2B,EAC3B,WAAqC;IAErC,MAAM,UAAU,GAAG,WAAW,CAAC,YAAY,CAAC;IAC5C,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,eAAe;aACZ,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;YACd,IAAI,WAAW,CAAC,YAAY,KAAK,UAAU,EAAE;gBAC3C,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;iBAAM;gBACL,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":";;;AAAA,wCAAiC;AAEjC;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,aAAsB;IACnD,IAAI,cAAiC,CAAC;IACtC,IAAI,aAAa,YAAY,KAAK,EAAE;QAClC,cAAc,GAAG,aAAa,CAAC;KAChC;SAAM,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;QAC5C,cAAc,GAAG,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QAC1C,qCAAqC;QACrC,OAAO,cAAc,CAAC,KAAK,CAAC;KAC7B;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAVD,wCAUC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,eAA2B,EAC3B,WAAqC;IAErC,MAAM,UAAU,GAAG,WAAW,CAAC,YAAY,CAAC;IAC5C,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,eAAe;aACZ,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;YACd,IAAI,WAAW,CAAC,YAAY,KAAK,UAAU,EAAE;gBAC3C,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;iBAAM;gBACL,IAAA,aAAG,EACD,+EAA+E,CAChF,CAAC;aACH;QACH,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YAChB,IAAI,WAAW,CAAC,YAAY,KAAK,UAAU,EAAE;gBAC3C,MAAM,CAAC,MAAM,CAAC,CAAC;aAChB;iBAAM;gBACL,IAAA,aAAG,EACD,+EAA+E,CAChF,CAAC;aACH;QACH,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC;AA1BD,oCA0BC","sourcesContent":["import { log } from '../logging';\n\n/**\n * Takes an error that was thrown, determines if it is\n * an error object. If it is then it will return that. Otherwise,\n * an error object is created with the original error message.\n *\n * @param originalError - The error that was originally thrown.\n * @returns An error object.\n */\nexport function constructError(originalError: unknown) {\n let _originalError: Error | undefined;\n if (originalError instanceof Error) {\n _originalError = originalError;\n } else if (typeof originalError === 'string') {\n _originalError = new Error(originalError);\n // The stack is useless in this case.\n delete _originalError.stack;\n }\n return _originalError;\n}\n\n/**\n * Make proxy for Promise and handle the teardown process properly.\n * If the teardown is called in the meanwhile, Promise result will not be\n * exposed to the snap anymore and warning will be logged to the console.\n *\n * @param originalPromise - Original promise.\n * @param teardownRef - Reference containing teardown count.\n * @param teardownRef.lastTeardown - Number of the last teardown.\n * @returns New proxy promise.\n */\nexport async function withTeardown<T>(\n originalPromise: Promise<T>,\n teardownRef: { lastTeardown: number },\n): Promise<T> {\n const myTeardown = teardownRef.lastTeardown;\n return new Promise<T>((resolve, reject) => {\n originalPromise\n .then((value) => {\n if (teardownRef.lastTeardown === myTeardown) {\n resolve(value);\n } else {\n log(\n 'Late promise received after Snap finished execution. Promise will be dropped.',\n );\n }\n })\n .catch((reason) => {\n if (teardownRef.lastTeardown === myTeardown) {\n reject(reason);\n } else {\n log(\n 'Late promise received after Snap finished execution. Promise will be dropped.',\n );\n }\n });\n });\n}\n"]}
|
|
@@ -9,6 +9,7 @@ const post_message_stream_1 = require("@metamask/post-message-stream");
|
|
|
9
9
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
10
10
|
const pump_1 = __importDefault(require("pump"));
|
|
11
11
|
const BaseSnapExecutor_1 = require("../common/BaseSnapExecutor");
|
|
12
|
+
const logging_1 = require("../logging");
|
|
12
13
|
class IFrameSnapExecutor extends BaseSnapExecutor_1.BaseSnapExecutor {
|
|
13
14
|
/**
|
|
14
15
|
* Initialize the IFrameSnapExecutor. This creates a post message stream from
|
|
@@ -18,7 +19,7 @@ class IFrameSnapExecutor extends BaseSnapExecutor_1.BaseSnapExecutor {
|
|
|
18
19
|
* message streams.
|
|
19
20
|
*/
|
|
20
21
|
static initialize() {
|
|
21
|
-
|
|
22
|
+
(0, logging_1.log)('Worker: Connecting to parent.');
|
|
22
23
|
const parentStream = new post_message_stream_1.WindowPostMessageStream({
|
|
23
24
|
name: 'child',
|
|
24
25
|
target: 'parent',
|
|
@@ -28,7 +29,7 @@ class IFrameSnapExecutor extends BaseSnapExecutor_1.BaseSnapExecutor {
|
|
|
28
29
|
const mux = new object_multiplex_1.default();
|
|
29
30
|
(0, pump_1.default)(parentStream, mux, parentStream, (error) => {
|
|
30
31
|
if (error) {
|
|
31
|
-
|
|
32
|
+
(0, snaps_utils_1.logError)(`Parent stream failure, closing worker.`, error);
|
|
32
33
|
}
|
|
33
34
|
self.close();
|
|
34
35
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IFrameSnapExecutor.js","sourceRoot":"","sources":["../../src/iframe/IFrameSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,uEAAwE;AACxE,
|
|
1
|
+
{"version":3,"file":"IFrameSnapExecutor.js","sourceRoot":"","sources":["../../src/iframe/IFrameSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,uEAAwE;AACxE,uDAAoE;AACpE,gDAAwB;AAExB,iEAA8D;AAC9D,wCAAiC;AAEjC,MAAa,kBAAmB,SAAQ,mCAAgB;IACtD;;;;;;OAMG;IACH,MAAM,CAAC,UAAU;QACf,IAAA,aAAG,EAAC,+BAA+B,CAAC,CAAC;QAErC,MAAM,YAAY,GAAG,IAAI,6CAAuB,CAAC;YAC/C,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,QAAQ;YAChB,YAAY,EAAE,IAAI,CAAC,MAAM;YACzB,YAAY,EAAE,GAAG;SAClB,CAAC,CAAC;QAEH,MAAM,GAAG,GAAG,IAAI,0BAAe,EAAE,CAAC;QAClC,IAAA,cAAI,EAAC,YAAY,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;YAC9C,IAAI,KAAK,EAAE;gBACT,IAAA,sBAAQ,EAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;aAC3D;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,CAAC,CAAC;QAE/D,OAAO,IAAI,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AA/BD,gDA+BC","sourcesContent":["import ObjectMultiplex from '@metamask/object-multiplex';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\nimport { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils';\nimport pump from 'pump';\n\nimport { BaseSnapExecutor } from '../common/BaseSnapExecutor';\nimport { log } from '../logging';\n\nexport class IFrameSnapExecutor extends BaseSnapExecutor {\n /**\n * Initialize the IFrameSnapExecutor. This creates a post message stream from\n * and to the parent window, for two-way communication with the iframe.\n *\n * @returns An instance of `IFrameSnapExecutor`, with the initialized post\n * message streams.\n */\n static initialize() {\n log('Worker: Connecting to parent.');\n\n const parentStream = new WindowPostMessageStream({\n name: 'child',\n target: 'parent',\n targetWindow: self.parent,\n targetOrigin: '*',\n });\n\n const mux = new ObjectMultiplex();\n pump(parentStream, mux, 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);\n\n return new IFrameSnapExecutor(commandStream, rpcStream);\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="debug" />
|
|
2
|
+
/**
|
|
3
|
+
* A logging function specific to this package. The log messages don't show up
|
|
4
|
+
* by default, but they can be enabled by setting the environment variable:
|
|
5
|
+
* - `DEBUG=metamask:snaps:snaps-execution-environments`, or
|
|
6
|
+
* - `DEBUG=metamask:snaps:*` to enable all logs from `@metamask/snaps-*`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const log: import("debug").Debugger;
|
package/dist/logging.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.log = void 0;
|
|
4
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
/**
|
|
7
|
+
* A logging function specific to this package. The log messages don't show up
|
|
8
|
+
* by default, but they can be enabled by setting the environment variable:
|
|
9
|
+
* - `DEBUG=metamask:snaps:snaps-execution-environments`, or
|
|
10
|
+
* - `DEBUG=metamask:snaps:*` to enable all logs from `@metamask/snaps-*`.
|
|
11
|
+
*/
|
|
12
|
+
exports.log = (0, utils_1.createModuleLogger)(snaps_utils_1.snapsLogger, 'snaps-execution-environments');
|
|
13
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,2CAAqD;AAErD;;;;;GAKG;AACU,QAAA,GAAG,GAAG,IAAA,0BAAkB,EACnC,yBAAW,EACX,8BAA8B,CAC/B,CAAC","sourcesContent":["import { snapsLogger } from '@metamask/snaps-utils';\nimport { createModuleLogger } from '@metamask/utils';\n\n/**\n * A logging function specific to this package. The log messages don't show up\n * by default, but they can be enabled by setting the environment variable:\n * - `DEBUG=metamask:snaps:snaps-execution-environments`, or\n * - `DEBUG=metamask:snaps:*` to enable all logs from `@metamask/snaps-*`.\n */\nexport const log = createModuleLogger(\n snapsLogger,\n 'snaps-execution-environments',\n);\n"]}
|
|
@@ -9,14 +9,15 @@ const post_message_stream_1 = require("@metamask/post-message-stream");
|
|
|
9
9
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
10
10
|
const pump_1 = __importDefault(require("pump"));
|
|
11
11
|
const BaseSnapExecutor_1 = require("../common/BaseSnapExecutor");
|
|
12
|
+
const logging_1 = require("../logging");
|
|
12
13
|
class ChildProcessSnapExecutor extends BaseSnapExecutor_1.BaseSnapExecutor {
|
|
13
14
|
static initialize() {
|
|
14
|
-
|
|
15
|
+
(0, logging_1.log)('Worker: Connecting to parent.');
|
|
15
16
|
const parentStream = new post_message_stream_1.ProcessMessageStream();
|
|
16
17
|
const mux = new object_multiplex_1.default();
|
|
17
18
|
(0, pump_1.default)(parentStream, mux, parentStream, (error) => {
|
|
18
19
|
if (error) {
|
|
19
|
-
|
|
20
|
+
(0, snaps_utils_1.logError)(`Parent stream failure, closing worker.`, error);
|
|
20
21
|
}
|
|
21
22
|
self.close();
|
|
22
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChildProcessSnapExecutor.js","sourceRoot":"","sources":["../../src/node-process/ChildProcessSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,uEAAqE;AACrE,
|
|
1
|
+
{"version":3,"file":"ChildProcessSnapExecutor.js","sourceRoot":"","sources":["../../src/node-process/ChildProcessSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,uEAAqE;AACrE,uDAAoE;AACpE,gDAAwB;AAExB,iEAA8D;AAC9D,wCAAiC;AAEjC,MAAa,wBAAyB,SAAQ,mCAAgB;IAC5D,MAAM,CAAC,UAAU;QACf,IAAA,aAAG,EAAC,+BAA+B,CAAC,CAAC;QAErC,MAAM,YAAY,GAAG,IAAI,0CAAoB,EAAE,CAAC;QAChD,MAAM,GAAG,GAAG,IAAI,0BAAe,EAAE,CAAC;QAClC,IAAA,cAAI,EAAC,YAAY,EAAE,GAAU,EAAE,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;YACrD,IAAI,KAAK,EAAE;gBACT,IAAA,sBAAQ,EAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;aAC3D;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';\nimport { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils';\nimport pump from 'pump';\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 pump(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"]}
|
|
@@ -9,14 +9,15 @@ const post_message_stream_1 = require("@metamask/post-message-stream");
|
|
|
9
9
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
10
10
|
const pump_1 = __importDefault(require("pump"));
|
|
11
11
|
const BaseSnapExecutor_1 = require("../common/BaseSnapExecutor");
|
|
12
|
+
const logging_1 = require("../logging");
|
|
12
13
|
class ThreadSnapExecutor extends BaseSnapExecutor_1.BaseSnapExecutor {
|
|
13
14
|
static initialize() {
|
|
14
|
-
|
|
15
|
+
(0, logging_1.log)('Worker: Connecting to parent.');
|
|
15
16
|
const parentStream = new post_message_stream_1.ThreadMessageStream();
|
|
16
17
|
const mux = new object_multiplex_1.default();
|
|
17
18
|
(0, pump_1.default)(parentStream, mux, parentStream, (error) => {
|
|
18
19
|
if (error) {
|
|
19
|
-
|
|
20
|
+
(0, snaps_utils_1.logError)(`Parent stream failure, closing worker.`, error);
|
|
20
21
|
}
|
|
21
22
|
self.close();
|
|
22
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThreadSnapExecutor.js","sourceRoot":"","sources":["../../src/node-thread/ThreadSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,uEAAoE;AACpE,
|
|
1
|
+
{"version":3,"file":"ThreadSnapExecutor.js","sourceRoot":"","sources":["../../src/node-thread/ThreadSnapExecutor.ts"],"names":[],"mappings":";;;;;;AAAA,kFAAyD;AACzD,uEAAoE;AACpE,uDAAoE;AACpE,gDAAwB;AAExB,iEAA8D;AAC9D,wCAAiC;AAEjC,MAAa,kBAAmB,SAAQ,mCAAgB;IACtD,MAAM,CAAC,UAAU;QACf,IAAA,aAAG,EAAC,+BAA+B,CAAC,CAAC;QAErC,MAAM,YAAY,GAAG,IAAI,yCAAmB,EAAE,CAAC;QAC/C,MAAM,GAAG,GAAG,IAAI,0BAAe,EAAE,CAAC;QAClC,IAAA,cAAI,EAAC,YAAY,EAAE,GAAU,EAAE,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;YACrD,IAAI,KAAK,EAAE;gBACT,IAAA,sBAAQ,EAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;aAC3D;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';\nimport { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils';\nimport pump from 'pump';\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 pump(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"]}
|
|
@@ -61,7 +61,7 @@ _OffscreenSnapExecutor_stream = new WeakMap(), _OffscreenSnapExecutor_instances
|
|
|
61
61
|
__classPrivateFieldGet(this, _OffscreenSnapExecutor_instances, "m", _OffscreenSnapExecutor_onData).call(this, data);
|
|
62
62
|
})
|
|
63
63
|
.catch((error) => {
|
|
64
|
-
|
|
64
|
+
(0, snaps_utils_1.logError)('[Worker] Error initializing job:', error);
|
|
65
65
|
});
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OffscreenSnapExecutor.js","sourceRoot":"","sources":["../../src/offscreen/OffscreenSnapExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAGuC;AACvC,
|
|
1
|
+
{"version":3,"file":"OffscreenSnapExecutor.js","sourceRoot":"","sources":["../../src/offscreen/OffscreenSnapExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAGuC;AACvC,uDAA+D;AAC/D,2CAAyD;AAQzD;;;;;;;;;;;;;GAaG;AACH,MAAa,qBAAqB;IAgBhC,YAAY,MAA6B;;QAfzC,gDAAwC;QAE/B,SAAI,GAAgC,EAAE,CAAC;QAc9C,uBAAA,IAAI,iCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,qCAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,uBAAA,IAAI,uEAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,C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,yEAAyE;IACzE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QAC5B,uBAAA,IAAI,qCAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC5D,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC,qFAQa,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 {\n BasePostMessageStream,\n WindowPostMessageStream,\n} from '@metamask/post-message-stream';\nimport { createWindow, logError } from '@metamask/snaps-utils';\nimport { JsonRpcRequest, assert } from '@metamask/utils';\n\ntype ExecutorJob = {\n id: string;\n window: Window;\n stream: WindowPostMessageStream;\n};\n\n/**\n * A snap executor using the Offscreen Documents API.\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 * Extensions can only have a single offscreen document, so this executor is\n * persisted between snap executions. The offscreen snap executor essentially\n * acts as a proxy between the extension and the iframe execution environment.\n *\n * @see https://developer.chrome.com/docs/extensions/reference/offscreen/\n */\nexport class OffscreenSnapExecutor {\n readonly #stream: BasePostMessageStream;\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 * @returns The initialized executor.\n */\n static initialize(stream: BasePostMessageStream) {\n return new OffscreenSnapExecutor(stream);\n }\n\n constructor(stream: BasePostMessageStream) {\n this.#stream = stream;\n this.#stream.on('data', this.#onData.bind(this));\n }\n\n /**\n * Handle an incoming message from the `OffscreenExecutionService`. 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 * @param data.frameUrl - The URL to load in the iframe.\n */\n #onData(data: { data: JsonRpcRequest; jobId: string; frameUrl: string }) {\n const { jobId, frameUrl, 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, frameUrl)\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 * @param frameUrl - The URL to load in the iframe.\n */\n async #initializeJob(jobId: string, frameUrl: string): Promise<ExecutorJob> {\n const window = await createWindow(frameUrl, jobId);\n const jobStream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: 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"]}
|