@metamask/snaps-execution-environments 0.34.1-flask.1 → 0.35.1-flask.1
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 +17 -1
- package/dist/cjs/common/BaseSnapExecutor.js +415 -0
- package/dist/cjs/common/BaseSnapExecutor.js.map +1 -0
- package/dist/cjs/common/commands.js +65 -0
- package/dist/cjs/common/commands.js.map +1 -0
- package/dist/cjs/common/endowments/commonEndowmentFactory.js +147 -0
- package/dist/cjs/common/endowments/commonEndowmentFactory.js.map +1 -0
- package/dist/cjs/common/endowments/console.js +134 -0
- package/dist/cjs/common/endowments/console.js.map +1 -0
- package/dist/cjs/common/endowments/crypto.js +44 -0
- package/dist/cjs/common/endowments/crypto.js.map +1 -0
- package/dist/cjs/common/endowments/date.js +53 -0
- package/dist/cjs/common/endowments/date.js.map +1 -0
- package/dist/cjs/common/endowments/index.js +91 -0
- package/dist/cjs/common/endowments/index.js.map +1 -0
- package/dist/cjs/common/endowments/interval.js +61 -0
- package/dist/cjs/common/endowments/interval.js.map +1 -0
- package/dist/cjs/common/endowments/math.js +67 -0
- package/dist/cjs/common/endowments/math.js.map +1 -0
- package/dist/cjs/common/endowments/network.js +206 -0
- package/dist/cjs/common/endowments/network.js.map +1 -0
- package/dist/cjs/common/endowments/textDecoder.js +28 -0
- package/dist/cjs/common/endowments/textDecoder.js.map +1 -0
- package/dist/cjs/common/endowments/textEncoder.js +28 -0
- package/dist/cjs/common/endowments/textEncoder.js.map +1 -0
- package/dist/cjs/common/endowments/timeout.js +63 -0
- package/dist/cjs/common/endowments/timeout.js.map +1 -0
- package/dist/cjs/common/globalEvents.js +39 -0
- package/dist/cjs/common/globalEvents.js.map +1 -0
- package/dist/cjs/common/globalObject.js +53 -0
- package/dist/{common → cjs/common}/globalObject.js.map +1 -1
- package/dist/cjs/common/lockdown/lockdown-events.js +74 -0
- package/dist/cjs/common/lockdown/lockdown-events.js.map +1 -0
- package/dist/cjs/common/lockdown/lockdown-more.js +73 -0
- package/dist/cjs/common/lockdown/lockdown-more.js.map +1 -0
- package/dist/cjs/common/lockdown/lockdown.js +30 -0
- package/dist/cjs/common/lockdown/lockdown.js.map +1 -0
- package/dist/cjs/common/sortParams.js +26 -0
- package/dist/cjs/common/sortParams.js.map +1 -0
- package/dist/cjs/common/utils.js +116 -0
- package/dist/cjs/common/utils.js.map +1 -0
- package/dist/cjs/common/validation.js +114 -0
- package/dist/cjs/common/validation.js.map +1 -0
- package/dist/cjs/iframe/IFrameSnapExecutor.js +50 -0
- package/dist/cjs/iframe/IFrameSnapExecutor.js.map +1 -0
- package/dist/cjs/iframe/index.js +13 -0
- package/dist/cjs/iframe/index.js.map +1 -0
- package/dist/cjs/logging.js +15 -0
- package/dist/cjs/logging.js.map +1 -0
- package/dist/cjs/node-process/ChildProcessSnapExecutor.js +39 -0
- package/dist/cjs/node-process/ChildProcessSnapExecutor.js.map +1 -0
- package/dist/cjs/node-process/index.js +11 -0
- package/dist/cjs/node-process/index.js.map +1 -0
- package/dist/cjs/node-thread/ThreadSnapExecutor.js +39 -0
- package/dist/cjs/node-thread/ThreadSnapExecutor.js.map +1 -0
- package/dist/cjs/node-thread/index.js +11 -0
- package/dist/cjs/node-thread/index.js.map +1 -0
- package/dist/cjs/offscreen/OffscreenSnapExecutor.js +173 -0
- package/dist/cjs/offscreen/OffscreenSnapExecutor.js.map +1 -0
- package/dist/cjs/offscreen/index.js +19 -0
- package/dist/cjs/offscreen/index.js.map +1 -0
- package/dist/cjs/webworker/executor/WebWorkerSnapExecutor.js +45 -0
- package/dist/cjs/webworker/executor/WebWorkerSnapExecutor.js.map +1 -0
- package/dist/cjs/webworker/executor/index.js +13 -0
- package/dist/cjs/webworker/executor/index.js.map +1 -0
- package/dist/cjs/webworker/pool/WebWorkerPool.js +248 -0
- package/dist/cjs/webworker/pool/WebWorkerPool.js.map +1 -0
- package/dist/cjs/webworker/pool/index.js +13 -0
- package/dist/cjs/webworker/pool/index.js.map +1 -0
- package/dist/esm/common/BaseSnapExecutor.js +400 -0
- package/dist/esm/common/BaseSnapExecutor.js.map +1 -0
- package/dist/esm/common/commands.js +64 -0
- package/dist/esm/common/commands.js.map +1 -0
- package/dist/esm/common/endowments/commonEndowmentFactory.js +132 -0
- package/dist/esm/common/endowments/commonEndowmentFactory.js.map +1 -0
- package/dist/{common → esm/common}/endowments/console.js +46 -33
- package/dist/esm/common/endowments/console.js.map +1 -0
- package/dist/esm/common/endowments/crypto.js +26 -0
- package/dist/esm/common/endowments/crypto.js.map +1 -0
- package/dist/{common → esm/common}/endowments/date.js +20 -16
- package/dist/esm/common/endowments/date.js.map +1 -0
- package/dist/{common → esm/common}/endowments/index.js +33 -35
- package/dist/esm/common/endowments/index.js.map +1 -0
- package/dist/{common → esm/common}/endowments/interval.js +13 -12
- package/dist/esm/common/endowments/interval.js.map +1 -0
- package/dist/{common → esm/common}/endowments/math.js +19 -16
- package/dist/esm/common/endowments/math.js.map +1 -0
- package/dist/esm/common/endowments/network.js +196 -0
- package/dist/esm/common/endowments/network.js.map +1 -0
- package/dist/esm/common/endowments/textDecoder.js +18 -0
- package/dist/esm/common/endowments/textDecoder.js.map +1 -0
- package/dist/esm/common/endowments/textEncoder.js +18 -0
- package/dist/esm/common/endowments/textEncoder.js.map +1 -0
- package/dist/{common → esm/common}/endowments/timeout.js +14 -13
- package/dist/esm/common/endowments/timeout.js.map +1 -0
- package/dist/esm/common/globalEvents.js +35 -0
- package/dist/esm/common/globalEvents.js.map +1 -0
- package/dist/esm/common/globalObject.js +36 -0
- package/dist/esm/common/globalObject.js.map +1 -0
- package/dist/esm/common/lockdown/lockdown-events.js +66 -0
- package/dist/esm/common/lockdown/lockdown-events.js.map +1 -0
- package/dist/{common → esm/common}/lockdown/lockdown-more.js +15 -22
- package/dist/esm/common/lockdown/lockdown-more.js.map +1 -0
- package/dist/{common → esm/common}/lockdown/lockdown.js +6 -11
- package/dist/esm/common/lockdown/lockdown.js.map +1 -0
- package/dist/{common → esm/common}/sortParams.js +7 -13
- package/dist/esm/common/sortParams.js.map +1 -0
- package/dist/esm/common/utils.js +120 -0
- package/dist/esm/common/utils.js.map +1 -0
- package/dist/esm/common/validation.js +92 -0
- package/dist/esm/common/validation.js.map +1 -0
- package/dist/esm/iframe/IFrameSnapExecutor.js +35 -0
- package/dist/esm/iframe/IFrameSnapExecutor.js.map +1 -0
- package/dist/esm/iframe/index.js +9 -0
- package/dist/esm/iframe/index.js.map +1 -0
- package/dist/esm/logging.js +10 -0
- package/dist/esm/logging.js.map +1 -0
- package/dist/esm/node-process/ChildProcessSnapExecutor.js +24 -0
- package/dist/esm/node-process/ChildProcessSnapExecutor.js.map +1 -0
- package/dist/esm/node-process/index.js +7 -0
- package/dist/esm/node-process/index.js.map +1 -0
- package/dist/esm/node-thread/ThreadSnapExecutor.js +24 -0
- package/dist/esm/node-thread/ThreadSnapExecutor.js.map +1 -0
- package/dist/esm/node-thread/index.js +7 -0
- package/dist/esm/node-thread/index.js.map +1 -0
- package/dist/esm/offscreen/OffscreenSnapExecutor.js +176 -0
- package/dist/esm/offscreen/OffscreenSnapExecutor.js.map +1 -0
- package/dist/esm/offscreen/index.js +15 -0
- package/dist/esm/offscreen/index.js.map +1 -0
- package/dist/esm/webworker/executor/WebWorkerSnapExecutor.js +30 -0
- package/dist/esm/webworker/executor/WebWorkerSnapExecutor.js.map +1 -0
- package/dist/esm/webworker/executor/index.js +9 -0
- package/dist/esm/webworker/executor/index.js.map +1 -0
- package/dist/esm/webworker/pool/WebWorkerPool.js +245 -0
- package/dist/esm/webworker/pool/WebWorkerPool.js.map +1 -0
- package/dist/esm/webworker/pool/index.js +9 -0
- package/dist/esm/webworker/pool/index.js.map +1 -0
- package/package.json +58 -20
- package/dist/browserify/iframe/bundle.js +0 -6421
- package/dist/browserify/iframe/index.html +0 -11660
- package/dist/browserify/node-process/bundle.js +0 -15545
- package/dist/browserify/node-thread/bundle.js +0 -15545
- package/dist/browserify/offscreen/bundle.js +0 -2478
- package/dist/browserify/offscreen/index.html +0 -11660
- package/dist/browserify/worker-executor/bundle.js +0 -18072
- package/dist/browserify/worker-pool/bundle.js +0 -2492
- package/dist/browserify/worker-pool/index.html +0 -11660
- package/dist/common/BaseSnapExecutor.js +0 -370
- package/dist/common/BaseSnapExecutor.js.map +0 -1
- package/dist/common/commands.js +0 -65
- package/dist/common/commands.js.map +0 -1
- package/dist/common/endowments/commonEndowmentFactory.js +0 -76
- package/dist/common/endowments/commonEndowmentFactory.js.map +0 -1
- package/dist/common/endowments/console.js.map +0 -1
- package/dist/common/endowments/crypto.js +0 -30
- package/dist/common/endowments/crypto.js.map +0 -1
- package/dist/common/endowments/date.js.map +0 -1
- package/dist/common/endowments/index.js.map +0 -1
- package/dist/common/endowments/interval.js.map +0 -1
- package/dist/common/endowments/math.js.map +0 -1
- package/dist/common/endowments/network.js +0 -170
- package/dist/common/endowments/network.js.map +0 -1
- package/dist/common/endowments/textDecoder.js +0 -18
- package/dist/common/endowments/textDecoder.js.map +0 -1
- package/dist/common/endowments/textEncoder.js +0 -18
- package/dist/common/endowments/textEncoder.js.map +0 -1
- package/dist/common/endowments/timeout.js.map +0 -1
- package/dist/common/globalEvents.js +0 -47
- package/dist/common/globalEvents.js.map +0 -1
- package/dist/common/globalObject.js +0 -50
- package/dist/common/keyring.d.ts +0 -12
- package/dist/common/keyring.js +0 -42
- package/dist/common/keyring.js.map +0 -1
- package/dist/common/lockdown/lockdown-events.js +0 -60
- package/dist/common/lockdown/lockdown-events.js.map +0 -1
- package/dist/common/lockdown/lockdown-more.js.map +0 -1
- package/dist/common/lockdown/lockdown.js.map +0 -1
- package/dist/common/sortParams.js.map +0 -1
- package/dist/common/utils.js +0 -133
- package/dist/common/utils.js.map +0 -1
- package/dist/common/validation.js +0 -109
- package/dist/common/validation.js.map +0 -1
- package/dist/iframe/IFrameSnapExecutor.js +0 -42
- package/dist/iframe/IFrameSnapExecutor.js.map +0 -1
- package/dist/iframe/index.js +0 -10
- package/dist/iframe/index.js.map +0 -1
- package/dist/logging.js +0 -13
- package/dist/logging.js.map +0 -1
- package/dist/node-process/ChildProcessSnapExecutor.js +0 -30
- package/dist/node-process/ChildProcessSnapExecutor.js.map +0 -1
- package/dist/node-process/index.js +0 -8
- package/dist/node-process/index.js.map +0 -1
- package/dist/node-thread/ThreadSnapExecutor.js +0 -30
- package/dist/node-thread/ThreadSnapExecutor.js.map +0 -1
- package/dist/node-thread/index.js +0 -8
- package/dist/node-thread/index.js.map +0 -1
- package/dist/offscreen/OffscreenSnapExecutor.js +0 -104
- package/dist/offscreen/OffscreenSnapExecutor.js.map +0 -1
- package/dist/offscreen/index.js +0 -16
- package/dist/offscreen/index.js.map +0 -1
- package/dist/openrpc.json +0 -210
- package/dist/webworker/executor/WebWorkerSnapExecutor.js +0 -37
- package/dist/webworker/executor/WebWorkerSnapExecutor.js.map +0 -1
- package/dist/webworker/executor/index.js +0 -10
- package/dist/webworker/executor/index.js.map +0 -1
- package/dist/webworker/pool/WebWorkerPool.js +0 -168
- package/dist/webworker/pool/WebWorkerPool.js.map +0 -1
- package/dist/webworker/pool/index.js +0 -10
- package/dist/webworker/pool/index.js.map +0 -1
- /package/dist/{common → types/common}/BaseSnapExecutor.d.ts +0 -0
- /package/dist/{common → types/common}/commands.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/commonEndowmentFactory.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/console.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/crypto.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/date.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/index.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/interval.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/math.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/network.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/textDecoder.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/textEncoder.d.ts +0 -0
- /package/dist/{common → types/common}/endowments/timeout.d.ts +0 -0
- /package/dist/{common → types/common}/globalEvents.d.ts +0 -0
- /package/dist/{common → types/common}/globalObject.d.ts +0 -0
- /package/dist/{common → types/common}/lockdown/lockdown-events.d.ts +0 -0
- /package/dist/{common → types/common}/lockdown/lockdown-more.d.ts +0 -0
- /package/dist/{common → types/common}/lockdown/lockdown.d.ts +0 -0
- /package/dist/{common → types/common}/sortParams.d.ts +0 -0
- /package/dist/{common → types/common}/utils.d.ts +0 -0
- /package/dist/{common → types/common}/validation.d.ts +0 -0
- /package/dist/{iframe → types/iframe}/IFrameSnapExecutor.d.ts +0 -0
- /package/dist/{iframe → types/iframe}/index.d.ts +0 -0
- /package/dist/{logging.d.ts → types/logging.d.ts} +0 -0
- /package/dist/{node-process → types/node-process}/ChildProcessSnapExecutor.d.ts +0 -0
- /package/dist/{node-process → types/node-process}/index.d.ts +0 -0
- /package/dist/{node-thread → types/node-thread}/ThreadSnapExecutor.d.ts +0 -0
- /package/dist/{node-thread → types/node-thread}/index.d.ts +0 -0
- /package/dist/{offscreen → types/offscreen}/OffscreenSnapExecutor.d.ts +0 -0
- /package/dist/{offscreen → types/offscreen}/index.d.ts +0 -0
- /package/dist/{webworker → types/webworker}/executor/WebWorkerSnapExecutor.d.ts +0 -0
- /package/dist/{webworker → types/webworker}/executor/index.d.ts +0 -0
- /package/dist/{webworker → types/webworker}/pool/WebWorkerPool.d.ts +0 -0
- /package/dist/{webworker → types/webworker}/pool/index.d.ts +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _globalObject = require("../globalObject");
|
|
12
|
+
const _crypto = require("./crypto");
|
|
13
|
+
/**
|
|
14
|
+
* Create a {@link Math} object, with the same properties as the global
|
|
15
|
+
* {@link Math} object, but with the {@link Math.random} method replaced.
|
|
16
|
+
*
|
|
17
|
+
* @returns The {@link Math} object with the {@link Math.random} method
|
|
18
|
+
* replaced.
|
|
19
|
+
*/ function createMath() {
|
|
20
|
+
// `Math` does not work with `Object.keys`, `Object.entries`, etc., so we
|
|
21
|
+
// need to create a new object with the same properties.
|
|
22
|
+
const keys = Object.getOwnPropertyNames(_globalObject.rootRealmGlobal.Math);
|
|
23
|
+
const math = keys.reduce((target, key)=>{
|
|
24
|
+
if (key === 'random') {
|
|
25
|
+
return target;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
...target,
|
|
29
|
+
[key]: _globalObject.rootRealmGlobal.Math[key]
|
|
30
|
+
};
|
|
31
|
+
}, {});
|
|
32
|
+
// Since the math endowment requires crypto, we can leverage the crypto endowment factory to get a hardened and platform agnostic instance of webcrypto
|
|
33
|
+
const { crypto: hardenedCrypto } = (0, _crypto.createCrypto)();
|
|
34
|
+
return harden({
|
|
35
|
+
Math: {
|
|
36
|
+
...math,
|
|
37
|
+
random: ()=>{
|
|
38
|
+
// NOTE: This is not intended to be a secure replacement for the weak
|
|
39
|
+
// random number generator used by `Math.random`. It is only intended to
|
|
40
|
+
// prevent side channel attacks of `Math.random` by replacing it with an
|
|
41
|
+
// alternative implementation that is not vulnerable to the same
|
|
42
|
+
// attacks.
|
|
43
|
+
//
|
|
44
|
+
// This does not mean that this implementation is secure. It is not
|
|
45
|
+
// intended to be used in a security context, and this implementation
|
|
46
|
+
// may change at any time.
|
|
47
|
+
//
|
|
48
|
+
// To securely generate random numbers, use a cryptographically secure
|
|
49
|
+
// random number generator, such as the one provided by the Web Crypto
|
|
50
|
+
// API:
|
|
51
|
+
//
|
|
52
|
+
// - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey
|
|
53
|
+
// - https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
|
|
54
|
+
return hardenedCrypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const endowmentModule = {
|
|
60
|
+
names: [
|
|
61
|
+
'Math'
|
|
62
|
+
],
|
|
63
|
+
factory: createMath
|
|
64
|
+
};
|
|
65
|
+
const _default = endowmentModule;
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/common/endowments/math.ts"],"sourcesContent":["import { rootRealmGlobal } from '../globalObject';\nimport { createCrypto } from './crypto';\n\n/**\n * Create a {@link Math} object, with the same properties as the global\n * {@link Math} object, but with the {@link Math.random} method replaced.\n *\n * @returns The {@link Math} object with the {@link Math.random} method\n * replaced.\n */\nfunction createMath() {\n // `Math` does not work with `Object.keys`, `Object.entries`, etc., so we\n // need to create a new object with the same properties.\n const keys = Object.getOwnPropertyNames(\n rootRealmGlobal.Math,\n ) as (keyof typeof Math)[];\n\n const math = keys.reduce<Partial<Math>>((target, key) => {\n if (key === 'random') {\n return target;\n }\n\n return { ...target, [key]: rootRealmGlobal.Math[key] };\n }, {});\n\n // Since the math endowment requires crypto, we can leverage the crypto endowment factory to get a hardened and platform agnostic instance of webcrypto\n const { crypto: hardenedCrypto } = createCrypto();\n\n return harden({\n Math: {\n ...math,\n random: () => {\n // NOTE: This is not intended to be a secure replacement for the weak\n // random number generator used by `Math.random`. It is only intended to\n // prevent side channel attacks of `Math.random` by replacing it with an\n // alternative implementation that is not vulnerable to the same\n // attacks.\n //\n // This does not mean that this implementation is secure. It is not\n // intended to be used in a security context, and this implementation\n // may change at any time.\n //\n // To securely generate random numbers, use a cryptographically secure\n // random number generator, such as the one provided by the Web Crypto\n // API:\n //\n // - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey\n // - https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues\n return hardenedCrypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32;\n },\n },\n });\n}\n\nconst endowmentModule = {\n names: ['Math'] as const,\n factory: createMath,\n};\n\nexport default endowmentModule;\n"],"names":["createMath","keys","Object","getOwnPropertyNames","rootRealmGlobal","Math","math","reduce","target","key","crypto","hardenedCrypto","createCrypto","harden","random","getRandomValues","Uint32Array","endowmentModule","names","factory"],"mappings":";;;;+BA2DA;;;eAAA;;;8BA3DgC;wBACH;AAE7B;;;;;;CAMC,GACD,SAASA;IACP,yEAAyE;IACzE,wDAAwD;IACxD,MAAMC,OAAOC,OAAOC,mBAAmB,CACrCC,6BAAe,CAACC,IAAI;IAGtB,MAAMC,OAAOL,KAAKM,MAAM,CAAgB,CAACC,QAAQC;QAC/C,IAAIA,QAAQ,UAAU;YACpB,OAAOD;QACT;QAEA,OAAO;YAAE,GAAGA,MAAM;YAAE,CAACC,IAAI,EAAEL,6BAAe,CAACC,IAAI,CAACI,IAAI;QAAC;IACvD,GAAG,CAAC;IAEJ,uJAAuJ;IACvJ,MAAM,EAAEC,QAAQC,cAAc,EAAE,GAAGC,IAAAA,oBAAY;IAE/C,OAAOC,OAAO;QACZR,MAAM;YACJ,GAAGC,IAAI;YACPQ,QAAQ;gBACN,qEAAqE;gBACrE,wEAAwE;gBACxE,wEAAwE;gBACxE,gEAAgE;gBAChE,WAAW;gBACX,EAAE;gBACF,mEAAmE;gBACnE,qEAAqE;gBACrE,0BAA0B;gBAC1B,EAAE;gBACF,sEAAsE;gBACtE,sEAAsE;gBACtE,OAAO;gBACP,EAAE;gBACF,8EAA8E;gBAC9E,4EAA4E;gBAC5E,OAAOH,eAAeI,eAAe,CAAC,IAAIC,YAAY,GAAG,CAAC,EAAE,GAAG,KAAK;YACtE;QACF;IACF;AACF;AAEA,MAAMC,kBAAkB;IACtBC,OAAO;QAAC;KAAO;IACfC,SAASnB;AACX;MAEA,WAAeiB"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _utils = require("../utils");
|
|
12
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
13
|
+
if (privateCollection.has(obj)) {
|
|
14
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
18
|
+
if (descriptor.get) {
|
|
19
|
+
return descriptor.get.call(receiver);
|
|
20
|
+
}
|
|
21
|
+
return descriptor.value;
|
|
22
|
+
}
|
|
23
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
24
|
+
if (descriptor.set) {
|
|
25
|
+
descriptor.set.call(receiver, value);
|
|
26
|
+
} else {
|
|
27
|
+
if (!descriptor.writable) {
|
|
28
|
+
throw new TypeError("attempted to set read only private field");
|
|
29
|
+
}
|
|
30
|
+
descriptor.value = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
34
|
+
if (!privateMap.has(receiver)) {
|
|
35
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
36
|
+
}
|
|
37
|
+
return privateMap.get(receiver);
|
|
38
|
+
}
|
|
39
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
40
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
41
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
42
|
+
}
|
|
43
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
44
|
+
_check_private_redeclaration(obj, privateMap);
|
|
45
|
+
privateMap.set(obj, value);
|
|
46
|
+
}
|
|
47
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
48
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
49
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
var _teardownRef = /*#__PURE__*/ new WeakMap(), _ogResponse = /*#__PURE__*/ new WeakMap();
|
|
53
|
+
/**
|
|
54
|
+
* This class wraps a Response object.
|
|
55
|
+
* That way, a teardown process can stop any processes left.
|
|
56
|
+
*/ class ResponseWrapper {
|
|
57
|
+
get body() {
|
|
58
|
+
return _class_private_field_get(this, _ogResponse).body;
|
|
59
|
+
}
|
|
60
|
+
get bodyUsed() {
|
|
61
|
+
return _class_private_field_get(this, _ogResponse).bodyUsed;
|
|
62
|
+
}
|
|
63
|
+
get headers() {
|
|
64
|
+
return _class_private_field_get(this, _ogResponse).headers;
|
|
65
|
+
}
|
|
66
|
+
get ok() {
|
|
67
|
+
return _class_private_field_get(this, _ogResponse).ok;
|
|
68
|
+
}
|
|
69
|
+
get redirected() {
|
|
70
|
+
return _class_private_field_get(this, _ogResponse).redirected;
|
|
71
|
+
}
|
|
72
|
+
get status() {
|
|
73
|
+
return _class_private_field_get(this, _ogResponse).status;
|
|
74
|
+
}
|
|
75
|
+
get statusText() {
|
|
76
|
+
return _class_private_field_get(this, _ogResponse).statusText;
|
|
77
|
+
}
|
|
78
|
+
get type() {
|
|
79
|
+
return _class_private_field_get(this, _ogResponse).type;
|
|
80
|
+
}
|
|
81
|
+
get url() {
|
|
82
|
+
return _class_private_field_get(this, _ogResponse).url;
|
|
83
|
+
}
|
|
84
|
+
async text() {
|
|
85
|
+
return (0, _utils.withTeardown)(_class_private_field_get(this, _ogResponse).text(), this);
|
|
86
|
+
}
|
|
87
|
+
async arrayBuffer() {
|
|
88
|
+
return (0, _utils.withTeardown)(_class_private_field_get(this, _ogResponse).arrayBuffer(), this);
|
|
89
|
+
}
|
|
90
|
+
async blob() {
|
|
91
|
+
return (0, _utils.withTeardown)(_class_private_field_get(this, _ogResponse).blob(), this);
|
|
92
|
+
}
|
|
93
|
+
clone() {
|
|
94
|
+
const newResponse = _class_private_field_get(this, _ogResponse).clone();
|
|
95
|
+
return new ResponseWrapper(newResponse, _class_private_field_get(this, _teardownRef));
|
|
96
|
+
}
|
|
97
|
+
async formData() {
|
|
98
|
+
return (0, _utils.withTeardown)(_class_private_field_get(this, _ogResponse).formData(), this);
|
|
99
|
+
}
|
|
100
|
+
async json() {
|
|
101
|
+
return (0, _utils.withTeardown)(_class_private_field_get(this, _ogResponse).json(), this);
|
|
102
|
+
}
|
|
103
|
+
constructor(ogResponse, teardownRef){
|
|
104
|
+
_class_private_field_init(this, _teardownRef, {
|
|
105
|
+
writable: true,
|
|
106
|
+
value: void 0
|
|
107
|
+
});
|
|
108
|
+
_class_private_field_init(this, _ogResponse, {
|
|
109
|
+
writable: true,
|
|
110
|
+
value: void 0
|
|
111
|
+
});
|
|
112
|
+
_class_private_field_set(this, _ogResponse, ogResponse);
|
|
113
|
+
_class_private_field_set(this, _teardownRef, teardownRef);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create a network endowment, consisting of a `fetch` function.
|
|
118
|
+
* This allows us to provide a teardown function, so that we can cancel
|
|
119
|
+
* any pending requests, connections, streams, etc. that may be open when a snap
|
|
120
|
+
* is terminated.
|
|
121
|
+
*
|
|
122
|
+
* This wraps the original implementation of `fetch`,
|
|
123
|
+
* to ensure that a bad actor cannot get access to the original function, thus
|
|
124
|
+
* potentially preventing the network requests from being torn down.
|
|
125
|
+
*
|
|
126
|
+
* @returns An object containing a wrapped `fetch`
|
|
127
|
+
* function, as well as a teardown function.
|
|
128
|
+
*/ const createNetwork = ()=>{
|
|
129
|
+
// Open fetch calls or open body streams
|
|
130
|
+
const openConnections = new Set();
|
|
131
|
+
// Track last teardown count
|
|
132
|
+
const teardownRef = {
|
|
133
|
+
lastTeardown: 0
|
|
134
|
+
};
|
|
135
|
+
// Remove items from openConnections after they were garbage collected
|
|
136
|
+
const cleanup = new FinalizationRegistry(/* istanbul ignore next: can't test garbage collection without modifying node parameters */ (callback)=>callback());
|
|
137
|
+
const _fetch = async (input, init)=>{
|
|
138
|
+
const abortController = new AbortController();
|
|
139
|
+
if (init?.signal !== null && init?.signal !== undefined) {
|
|
140
|
+
const originalSignal = init.signal;
|
|
141
|
+
// Merge abort controllers
|
|
142
|
+
originalSignal.addEventListener('abort', ()=>{
|
|
143
|
+
abortController.abort(originalSignal.reason);
|
|
144
|
+
}, {
|
|
145
|
+
once: true
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
let res;
|
|
149
|
+
let openFetchConnection;
|
|
150
|
+
try {
|
|
151
|
+
const fetchPromise = fetch(input, {
|
|
152
|
+
...init,
|
|
153
|
+
signal: abortController.signal
|
|
154
|
+
});
|
|
155
|
+
openFetchConnection = {
|
|
156
|
+
cancel: async ()=>{
|
|
157
|
+
abortController.abort();
|
|
158
|
+
try {
|
|
159
|
+
await fetchPromise;
|
|
160
|
+
} catch {
|
|
161
|
+
/* do nothing */ }
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
openConnections.add(openFetchConnection);
|
|
165
|
+
res = new ResponseWrapper(await (0, _utils.withTeardown)(fetchPromise, teardownRef), teardownRef);
|
|
166
|
+
} finally{
|
|
167
|
+
if (openFetchConnection !== undefined) {
|
|
168
|
+
openConnections.delete(openFetchConnection);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (res.body !== null) {
|
|
172
|
+
const body = new WeakRef(res.body);
|
|
173
|
+
const openBodyConnection = {
|
|
174
|
+
cancel: /* istanbul ignore next: see it.todo('can be torn down during body read') test */ async ()=>{
|
|
175
|
+
try {
|
|
176
|
+
await body.deref()?.cancel();
|
|
177
|
+
} catch {
|
|
178
|
+
/* do nothing */ }
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
openConnections.add(openBodyConnection);
|
|
182
|
+
cleanup.register(res.body, /* istanbul ignore next: can't test garbage collection without modifying node parameters */ ()=>openConnections.delete(openBodyConnection));
|
|
183
|
+
}
|
|
184
|
+
return harden(res);
|
|
185
|
+
};
|
|
186
|
+
const teardownFunction = async ()=>{
|
|
187
|
+
teardownRef.lastTeardown += 1;
|
|
188
|
+
const promises = [];
|
|
189
|
+
openConnections.forEach(({ cancel })=>promises.push(cancel()));
|
|
190
|
+
openConnections.clear();
|
|
191
|
+
await Promise.all(promises);
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
fetch: harden(_fetch),
|
|
195
|
+
teardownFunction
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
const endowmentModule = {
|
|
199
|
+
names: [
|
|
200
|
+
'fetch'
|
|
201
|
+
],
|
|
202
|
+
factory: createNetwork
|
|
203
|
+
};
|
|
204
|
+
const _default = endowmentModule;
|
|
205
|
+
|
|
206
|
+
//# sourceMappingURL=network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/common/endowments/network.ts"],"sourcesContent":["import { withTeardown } from '../utils';\n\n/**\n * This class wraps a Response object.\n * That way, a teardown process can stop any processes left.\n */\nclass ResponseWrapper implements Response {\n readonly #teardownRef: { lastTeardown: number };\n\n #ogResponse: Response;\n\n constructor(ogResponse: Response, teardownRef: { lastTeardown: number }) {\n this.#ogResponse = ogResponse;\n this.#teardownRef = teardownRef;\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 withTeardown<string>(this.#ogResponse.text(), this as any);\n }\n\n async arrayBuffer(): Promise<ArrayBuffer> {\n return withTeardown<ArrayBuffer>(\n this.#ogResponse.arrayBuffer(),\n this as any,\n );\n }\n\n async blob(): Promise<Blob> {\n return withTeardown<Blob>(this.#ogResponse.blob(), this as any);\n }\n\n clone(): Response {\n const newResponse = this.#ogResponse.clone();\n return new ResponseWrapper(newResponse, this.#teardownRef);\n }\n\n async formData(): Promise<FormData> {\n return withTeardown<FormData>(this.#ogResponse.formData(), this as any);\n }\n\n async json(): Promise<any> {\n return withTeardown(this.#ogResponse.json(), this as any);\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 * @returns An object containing a wrapped `fetch`\n * function, as well as a teardown function.\n */\nconst createNetwork = () => {\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 res: Response;\n let openFetchConnection: { cancel: () => Promise<void> } | undefined;\n try {\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 withTeardown(fetchPromise, teardownRef),\n teardownRef,\n );\n } finally {\n if (openFetchConnection !== undefined) {\n openConnections.delete(openFetchConnection);\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\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 teardownFunction,\n };\n};\n\nconst endowmentModule = {\n names: ['fetch'] as const,\n factory: createNetwork,\n};\nexport default endowmentModule;\n"],"names":["ResponseWrapper","body","ogResponse","bodyUsed","headers","ok","redirected","status","statusText","type","url","text","withTeardown","arrayBuffer","blob","clone","newResponse","teardownRef","formData","json","constructor","createNetwork","openConnections","Set","lastTeardown","cleanup","FinalizationRegistry","callback","_fetch","input","init","abortController","AbortController","signal","undefined","originalSignal","addEventListener","abort","reason","once","res","openFetchConnection","fetchPromise","fetch","cancel","add","delete","WeakRef","openBodyConnection","deref","register","harden","teardownFunction","promises","forEach","push","clear","Promise","all","endowmentModule","names","factory"],"mappings":"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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates TextDecoder function hardened by SES.
|
|
3
|
+
*
|
|
4
|
+
* @returns An object with the attenuated `TextDecoder` function.
|
|
5
|
+
*/ "use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(exports, "default", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return _default;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const createTextDecoder = ()=>{
|
|
16
|
+
return {
|
|
17
|
+
TextDecoder: harden(TextDecoder)
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const endowmentModule = {
|
|
21
|
+
names: [
|
|
22
|
+
'TextDecoder'
|
|
23
|
+
],
|
|
24
|
+
factory: createTextDecoder
|
|
25
|
+
};
|
|
26
|
+
const _default = endowmentModule;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=textDecoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/common/endowments/textDecoder.ts"],"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"],"names":["createTextDecoder","TextDecoder","harden","endowmentModule","names","factory"],"mappings":"AAAA;;;;CAIC;;;;+BAWD;;;eAAA;;;AAVA,MAAMA,oBAAoB;IACxB,OAAO;QACLC,aAAaC,OAAOD;IACtB;AACF;AAEA,MAAME,kBAAkB;IACtBC,OAAO;QAAC;KAAc;IACtBC,SAASL;AACX;MACA,WAAeG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates TextEncoder function hardened by SES.
|
|
3
|
+
*
|
|
4
|
+
* @returns An object with the attenuated `TextEncoder` function.
|
|
5
|
+
*/ "use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(exports, "default", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return _default;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const createTextEncoder = ()=>{
|
|
16
|
+
return {
|
|
17
|
+
TextEncoder: harden(TextEncoder)
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const endowmentModule = {
|
|
21
|
+
names: [
|
|
22
|
+
'TextEncoder'
|
|
23
|
+
],
|
|
24
|
+
factory: createTextEncoder
|
|
25
|
+
};
|
|
26
|
+
const _default = endowmentModule;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=textEncoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/common/endowments/textEncoder.ts"],"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"],"names":["createTextEncoder","TextEncoder","harden","endowmentModule","names","factory"],"mappings":"AAAA;;;;CAIC;;;;+BAWD;;;eAAA;;;AAVA,MAAMA,oBAAoB;IACxB,OAAO;QACLC,aAAaC,OAAOD;IACtB;AACF;AAEA,MAAME,kBAAkB;IACtBC,OAAO;QAAC;KAAc;IACtBC,SAASL;AACX;MACA,WAAeG"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const MINIMUM_TIMEOUT = 10;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a pair of `setTimeout` and `clearTimeout` functions attenuated such
|
|
14
|
+
* that:
|
|
15
|
+
* - `setTimeout` throws if its "handler" parameter is not a function.
|
|
16
|
+
* - `clearTimeout` only clears timeouts created by its sibling `setTimeout`,
|
|
17
|
+
* or else no-ops.
|
|
18
|
+
*
|
|
19
|
+
* @returns An object with the attenuated `setTimeout` and `clearTimeout`
|
|
20
|
+
* functions.
|
|
21
|
+
*/ const createTimeout = ()=>{
|
|
22
|
+
const registeredHandles = new Map();
|
|
23
|
+
const _setTimeout = (handler, timeout)=>{
|
|
24
|
+
if (typeof handler !== 'function') {
|
|
25
|
+
throw new Error(`The timeout handler must be a function. Received: ${typeof handler}`);
|
|
26
|
+
}
|
|
27
|
+
harden(handler);
|
|
28
|
+
const handle = Object.freeze(Object.create(null));
|
|
29
|
+
const platformHandle = setTimeout(()=>{
|
|
30
|
+
registeredHandles.delete(handle);
|
|
31
|
+
handler();
|
|
32
|
+
}, Math.max(MINIMUM_TIMEOUT, timeout ?? 0));
|
|
33
|
+
registeredHandles.set(handle, platformHandle);
|
|
34
|
+
return handle;
|
|
35
|
+
};
|
|
36
|
+
const _clearTimeout = (handle)=>{
|
|
37
|
+
const platformHandle = registeredHandles.get(handle);
|
|
38
|
+
if (platformHandle !== undefined) {
|
|
39
|
+
clearTimeout(platformHandle);
|
|
40
|
+
registeredHandles.delete(handle);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const teardownFunction = ()=>{
|
|
44
|
+
for (const handle of registeredHandles.keys()){
|
|
45
|
+
_clearTimeout(handle);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
setTimeout: harden(_setTimeout),
|
|
50
|
+
clearTimeout: harden(_clearTimeout),
|
|
51
|
+
teardownFunction
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const endowmentModule = {
|
|
55
|
+
names: [
|
|
56
|
+
'setTimeout',
|
|
57
|
+
'clearTimeout'
|
|
58
|
+
],
|
|
59
|
+
factory: createTimeout
|
|
60
|
+
};
|
|
61
|
+
const _default = endowmentModule;
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/common/endowments/timeout.ts"],"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 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"],"names":["MINIMUM_TIMEOUT","createTimeout","registeredHandles","Map","_setTimeout","handler","timeout","Error","harden","handle","Object","freeze","create","platformHandle","setTimeout","delete","Math","max","set","_clearTimeout","get","undefined","clearTimeout","teardownFunction","keys","endowmentModule","names","factory"],"mappings":";;;;+BAwDA;;;eAAA;;;AAxDA,MAAMA,kBAAkB;AAExB;;;;;;;;;CASC,GACD,MAAMC,gBAAgB;IACpB,MAAMC,oBAAoB,IAAIC;IAC9B,MAAMC,cAAc,CAACC,SAAuBC;QAC1C,IAAI,OAAOD,YAAY,YAAY;YACjC,MAAM,IAAIE,MACR,CAAC,kDAAkD,EAAE,OAAOF,QAAQ,CAAC;QAEzE;QACAG,OAAOH;QACP,MAAMI,SAASC,OAAOC,MAAM,CAACD,OAAOE,MAAM,CAAC;QAC3C,MAAMC,iBAAiBC,WAAW;YAChCZ,kBAAkBa,MAAM,CAACN;YACzBJ;QACF,GAAGW,KAAKC,GAAG,CAACjB,iBAAiBM,WAAW;QAExCJ,kBAAkBgB,GAAG,CAACT,QAAQI;QAC9B,OAAOJ;IACT;IAEA,MAAMU,gBAAgB,CAACV;QACrB,MAAMI,iBAAiBX,kBAAkBkB,GAAG,CAACX;QAC7C,IAAII,mBAAmBQ,WAAW;YAChCC,aAAaT;YACbX,kBAAkBa,MAAM,CAACN;QAC3B;IACF;IAEA,MAAMc,mBAAmB;QACvB,KAAK,MAAMd,UAAUP,kBAAkBsB,IAAI,GAAI;YAC7CL,cAAcV;QAChB;IACF;IAEA,OAAO;QACLK,YAAYN,OAAOJ;QACnBkB,cAAcd,OAAOW;QACrBI;IACF;AACF;AAEA,MAAME,kBAAkB;IACtBC,OAAO;QAAC;QAAc;KAAe;IACrCC,SAAS1B;AACX;MACA,WAAewB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
addEventListener: function() {
|
|
13
|
+
return addEventListener;
|
|
14
|
+
},
|
|
15
|
+
removeEventListener: function() {
|
|
16
|
+
return removeEventListener;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _globalObject = require("./globalObject");
|
|
20
|
+
function addEventListener(event, listener) {
|
|
21
|
+
if ('addEventListener' in _globalObject.rootRealmGlobal && typeof _globalObject.rootRealmGlobal.addEventListener === 'function') {
|
|
22
|
+
return _globalObject.rootRealmGlobal.addEventListener(event.toLowerCase(), listener);
|
|
23
|
+
}
|
|
24
|
+
if (_globalObject.rootRealmGlobal.process && 'on' in _globalObject.rootRealmGlobal.process && typeof _globalObject.rootRealmGlobal.process.on === 'function') {
|
|
25
|
+
return _globalObject.rootRealmGlobal.process.on(event, listener);
|
|
26
|
+
}
|
|
27
|
+
throw new Error('Platform agnostic addEventListener failed');
|
|
28
|
+
}
|
|
29
|
+
function removeEventListener(event, listener) {
|
|
30
|
+
if ('removeEventListener' in _globalObject.rootRealmGlobal && typeof _globalObject.rootRealmGlobal.removeEventListener === 'function') {
|
|
31
|
+
return _globalObject.rootRealmGlobal.removeEventListener(event.toLowerCase(), listener);
|
|
32
|
+
}
|
|
33
|
+
if (_globalObject.rootRealmGlobal.process && 'removeListener' in _globalObject.rootRealmGlobal.process && typeof _globalObject.rootRealmGlobal.process.removeListener === 'function') {
|
|
34
|
+
return _globalObject.rootRealmGlobal.process.removeListener(event, listener);
|
|
35
|
+
}
|
|
36
|
+
throw new Error('Platform agnostic removeEventListener failed');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=globalEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/common/globalEvents.ts"],"sourcesContent":["import { rootRealmGlobal } from './globalObject';\n\n/**\n * Adds an event listener platform agnostically, trying both `globalThis.addEventListener` and `globalThis.process.on`\n *\n * @param event - The event to listen for.\n * @param listener - The listener to be triggered when the event occurs.\n * @returns The result of the platform agnostic operation if any.\n * @throws If none of the platform options are present.\n */\nexport function addEventListener(\n event: string,\n listener: (...args: any[]) => void,\n) {\n if (\n 'addEventListener' in rootRealmGlobal &&\n typeof rootRealmGlobal.addEventListener === 'function'\n ) {\n return rootRealmGlobal.addEventListener(event.toLowerCase(), listener);\n }\n\n if (\n rootRealmGlobal.process &&\n 'on' in rootRealmGlobal.process &&\n typeof rootRealmGlobal.process.on === 'function'\n ) {\n return rootRealmGlobal.process.on(event, listener);\n }\n\n throw new Error('Platform agnostic addEventListener failed');\n}\n\n/**\n * Removes an event listener platform agnostically, trying both `globalThis.removeEventListener` and `globalThis.process.removeListener`\n *\n * @param event - The event to remove the listener for.\n * @param listener - The currently attached listener.\n * @returns The result of the platform agnostic operation if any.\n * @throws If none of the platform options are present.\n */\nexport function removeEventListener(\n event: string,\n listener: (...args: any[]) => void,\n) {\n if (\n 'removeEventListener' in rootRealmGlobal &&\n typeof rootRealmGlobal.removeEventListener === 'function'\n ) {\n return rootRealmGlobal.removeEventListener(event.toLowerCase(), listener);\n }\n\n if (\n rootRealmGlobal.process &&\n 'removeListener' in rootRealmGlobal.process &&\n typeof rootRealmGlobal.process.removeListener === 'function'\n ) {\n return rootRealmGlobal.process.removeListener(event, listener);\n }\n\n throw new Error('Platform agnostic removeEventListener failed');\n}\n"],"names":["addEventListener","removeEventListener","event","listener","rootRealmGlobal","toLowerCase","process","on","Error","removeListener"],"mappings":";;;;;;;;;;;IAUgBA,gBAAgB;eAAhBA;;IA8BAC,mBAAmB;eAAnBA;;;8BAxCgB;AAUzB,SAASD,iBACdE,KAAa,EACbC,QAAkC;IAElC,IACE,sBAAsBC,6BAAe,IACrC,OAAOA,6BAAe,CAACJ,gBAAgB,KAAK,YAC5C;QACA,OAAOI,6BAAe,CAACJ,gBAAgB,CAACE,MAAMG,WAAW,IAAIF;IAC/D;IAEA,IACEC,6BAAe,CAACE,OAAO,IACvB,QAAQF,6BAAe,CAACE,OAAO,IAC/B,OAAOF,6BAAe,CAACE,OAAO,CAACC,EAAE,KAAK,YACtC;QACA,OAAOH,6BAAe,CAACE,OAAO,CAACC,EAAE,CAACL,OAAOC;IAC3C;IAEA,MAAM,IAAIK,MAAM;AAClB;AAUO,SAASP,oBACdC,KAAa,EACbC,QAAkC;IAElC,IACE,yBAAyBC,6BAAe,IACxC,OAAOA,6BAAe,CAACH,mBAAmB,KAAK,YAC/C;QACA,OAAOG,6BAAe,CAACH,mBAAmB,CAACC,MAAMG,WAAW,IAAIF;IAClE;IAEA,IACEC,6BAAe,CAACE,OAAO,IACvB,oBAAoBF,6BAAe,CAACE,OAAO,IAC3C,OAAOF,6BAAe,CAACE,OAAO,CAACG,cAAc,KAAK,YAClD;QACA,OAAOL,6BAAe,CAACE,OAAO,CAACG,cAAc,CAACP,OAAOC;IACvD;IAEA,MAAM,IAAIK,MAAM;AAClB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
rootRealmGlobal: function() {
|
|
13
|
+
return rootRealmGlobal;
|
|
14
|
+
},
|
|
15
|
+
rootRealmGlobalName: function() {
|
|
16
|
+
return rootRealmGlobalName;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var GlobalObjectNames;
|
|
20
|
+
(function(GlobalObjectNames) {
|
|
21
|
+
GlobalObjectNames[// The globalThis entry is incorrectly identified as shadowing the global
|
|
22
|
+
// globalThis.
|
|
23
|
+
/* eslint-disable @typescript-eslint/naming-convention */ // eslint-disable-next-line @typescript-eslint/no-shadow
|
|
24
|
+
"globalThis"] = "globalThis";
|
|
25
|
+
GlobalObjectNames["global"] = "global";
|
|
26
|
+
GlobalObjectNames["self"] = "self";
|
|
27
|
+
GlobalObjectNames["window"] = "window";
|
|
28
|
+
})(GlobalObjectNames || (GlobalObjectNames = {}));
|
|
29
|
+
let _rootRealmGlobal;
|
|
30
|
+
let _rootRealmGlobalName;
|
|
31
|
+
/* istanbul ignore next */ /* eslint-disable no-negated-condition */ if (typeof globalThis !== 'undefined') {
|
|
32
|
+
_rootRealmGlobal = globalThis;
|
|
33
|
+
_rootRealmGlobalName = GlobalObjectNames.globalThis;
|
|
34
|
+
} else if (typeof self !== 'undefined') {
|
|
35
|
+
_rootRealmGlobal = self;
|
|
36
|
+
_rootRealmGlobalName = GlobalObjectNames.self;
|
|
37
|
+
} else if (typeof window !== 'undefined') {
|
|
38
|
+
_rootRealmGlobal = window;
|
|
39
|
+
_rootRealmGlobalName = GlobalObjectNames.window;
|
|
40
|
+
} else if (typeof global !== 'undefined') {
|
|
41
|
+
_rootRealmGlobal = global;
|
|
42
|
+
_rootRealmGlobalName = GlobalObjectNames.global;
|
|
43
|
+
} else {
|
|
44
|
+
throw new Error('Unknown realm type; failed to identify global object.');
|
|
45
|
+
}
|
|
46
|
+
/* eslint-enable no-negated-condition */ /**
|
|
47
|
+
* A platform-agnostic alias for the root realm global object.
|
|
48
|
+
*/ const rootRealmGlobal = _rootRealmGlobal;
|
|
49
|
+
/**
|
|
50
|
+
* The string literal corresponding to the name of the root realm global object.
|
|
51
|
+
*/ const rootRealmGlobalName = _rootRealmGlobalName;
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=globalObject.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../src/common/globalObject.ts"],"sourcesContent":["enum GlobalObjectNames {\n // The globalThis entry is incorrectly identified as shadowing the global\n // globalThis.\n /* eslint-disable @typescript-eslint/naming-convention */\n // eslint-disable-next-line @typescript-eslint/no-shadow\n globalThis = 'globalThis',\n global = 'global',\n self = 'self',\n window = 'window',\n /* eslint-enavle @typescript-eslint/naming-convention */\n}\n\nlet _rootRealmGlobal: typeof globalThis;\nlet _rootRealmGlobalName: string;\n\n/* istanbul ignore next */\n/* eslint-disable no-negated-condition */\nif (typeof globalThis !== 'undefined') {\n _rootRealmGlobal = globalThis;\n _rootRealmGlobalName = GlobalObjectNames.globalThis;\n} else if (typeof self !== 'undefined') {\n _rootRealmGlobal = self;\n _rootRealmGlobalName = GlobalObjectNames.self;\n} else if (typeof window !== 'undefined') {\n _rootRealmGlobal = window;\n _rootRealmGlobalName = GlobalObjectNames.window;\n} else if (typeof global !== 'undefined') {\n _rootRealmGlobal = global;\n _rootRealmGlobalName = GlobalObjectNames.global;\n} else {\n throw new Error('Unknown realm type; failed to identify global object.');\n}\n/* eslint-enable no-negated-condition */\n\n/**\n * A platform-agnostic alias for the root realm global object.\n */\nconst rootRealmGlobal = _rootRealmGlobal;\n\n/**\n * The string literal corresponding to the name of the root realm global object.\n */\nconst rootRealmGlobalName = _rootRealmGlobalName;\n\nexport { rootRealmGlobal, rootRealmGlobalName };\n"],"names":["rootRealmGlobal","rootRealmGlobalName","GlobalObjectNames","globalThis","global","self","window","_rootRealmGlobal","_rootRealmGlobalName","Error"],"mappings":";;;;;;;;;;;IA4CSA,eAAe;eAAfA;;IAAiBC,mBAAmB;eAAnBA;;;IA5C1B;UAAKC,iBAAiB;IAAjBA,kBACH,yEAAyE;IACzE,cAAc;IACd,uDAAuD,GACvD,wDAAwD;IACxDC,gBAAAA;IALGD,kBAMHE,YAAAA;IANGF,kBAOHG,UAAAA;IAPGH,kBAQHI,YAAAA;GARGJ,sBAAAA;AAYL,IAAIK;AACJ,IAAIC;AAEJ,wBAAwB,GACxB,uCAAuC,GACvC,IAAI,OAAOL,eAAe,aAAa;IACrCI,mBAAmBJ;IACnBK,uBAAuBN,kBAAkBC,UAAU;AACrD,OAAO,IAAI,OAAOE,SAAS,aAAa;IACtCE,mBAAmBF;IACnBG,uBAAuBN,kBAAkBG,IAAI;AAC/C,OAAO,IAAI,OAAOC,WAAW,aAAa;IACxCC,mBAAmBD;IACnBE,uBAAuBN,kBAAkBI,MAAM;AACjD,OAAO,IAAI,OAAOF,WAAW,aAAa;IACxCG,mBAAmBH;IACnBI,uBAAuBN,kBAAkBE,MAAM;AACjD,OAAO;IACL,MAAM,IAAIK,MAAM;AAClB;AACA,sCAAsC,GAEtC;;CAEC,GACD,MAAMT,kBAAkBO;AAExB;;CAEC,GACD,MAAMN,sBAAsBO"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// When creating a sandbox, limitation of the events from leaking
|
|
2
|
+
// sensitive objects is required. This is done by overriding own properties
|
|
3
|
+
// of prototypes of all existing events.
|
|
4
|
+
"use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "executeLockdownEvents", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
11
|
+
return executeLockdownEvents;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const _utils = require("@metamask/utils");
|
|
15
|
+
/**
|
|
16
|
+
* Targeted Event objects and properties.
|
|
17
|
+
* Note: This is a map of the prototypes that inherit from Events with
|
|
18
|
+
* properties that are identified to leak sensitive objects.
|
|
19
|
+
* Not all browsers support all event types, so checking its existence is required.
|
|
20
|
+
*/ const targetEvents = new Map();
|
|
21
|
+
if ((0, _utils.hasProperty)(globalThis, 'UIEvent')) {
|
|
22
|
+
targetEvents.set(UIEvent.prototype, [
|
|
23
|
+
'view'
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
if ((0, _utils.hasProperty)(globalThis, 'MutationEvent')) {
|
|
27
|
+
targetEvents.set(MutationEvent.prototype, [
|
|
28
|
+
'relatedNode'
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
if ((0, _utils.hasProperty)(globalThis, 'MessageEvent')) {
|
|
32
|
+
targetEvents.set(MessageEvent.prototype, [
|
|
33
|
+
'source'
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
if ((0, _utils.hasProperty)(globalThis, 'FocusEvent')) {
|
|
37
|
+
targetEvents.set(FocusEvent.prototype, [
|
|
38
|
+
'relatedTarget'
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
if ((0, _utils.hasProperty)(globalThis, 'MouseEvent')) {
|
|
42
|
+
targetEvents.set(MouseEvent.prototype, [
|
|
43
|
+
'relatedTarget',
|
|
44
|
+
'fromElement',
|
|
45
|
+
'toElement'
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
if ((0, _utils.hasProperty)(globalThis, 'TouchEvent')) {
|
|
49
|
+
targetEvents.set(TouchEvent.prototype, [
|
|
50
|
+
'targetTouches',
|
|
51
|
+
'touches'
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
if ((0, _utils.hasProperty)(globalThis, 'Event')) {
|
|
55
|
+
targetEvents.set(Event.prototype, [
|
|
56
|
+
'target',
|
|
57
|
+
'currentTarget',
|
|
58
|
+
'srcElement',
|
|
59
|
+
'composedPath'
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
function executeLockdownEvents() {
|
|
63
|
+
targetEvents.forEach((properties, prototype)=>{
|
|
64
|
+
for (const property of properties){
|
|
65
|
+
Object.defineProperty(prototype, property, {
|
|
66
|
+
value: undefined,
|
|
67
|
+
configurable: false,
|
|
68
|
+
writable: false
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=lockdown-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/common/lockdown/lockdown-events.ts"],"sourcesContent":["// When creating a sandbox, limitation of the events from leaking\n// sensitive objects is required. This is done by overriding own properties\n// of prototypes of all existing events.\nimport { hasProperty } from '@metamask/utils';\n\n/**\n * Targeted Event objects and properties.\n * Note: This is a map of the prototypes that inherit from Events with\n * properties that are identified to leak sensitive objects.\n * Not all browsers support all event types, so checking its existence is required.\n */\nconst targetEvents = new Map();\nif (hasProperty(globalThis, 'UIEvent')) {\n targetEvents.set(UIEvent.prototype, ['view']);\n}\nif (hasProperty(globalThis, 'MutationEvent')) {\n targetEvents.set(MutationEvent.prototype, ['relatedNode']);\n}\nif (hasProperty(globalThis, 'MessageEvent')) {\n targetEvents.set(MessageEvent.prototype, ['source']);\n}\nif (hasProperty(globalThis, 'FocusEvent')) {\n targetEvents.set(FocusEvent.prototype, ['relatedTarget']);\n}\nif (hasProperty(globalThis, 'MouseEvent')) {\n targetEvents.set(MouseEvent.prototype, [\n 'relatedTarget',\n 'fromElement',\n 'toElement',\n ]);\n}\nif (hasProperty(globalThis, 'TouchEvent')) {\n targetEvents.set(TouchEvent.prototype, ['targetTouches', 'touches']);\n}\nif (hasProperty(globalThis, 'Event')) {\n targetEvents.set(Event.prototype, [\n 'target',\n 'currentTarget',\n 'srcElement',\n 'composedPath',\n ]);\n}\n\n/**\n * Attenuate Event objects by replacing its own properties.\n */\nexport function executeLockdownEvents() {\n targetEvents.forEach((properties, prototype) => {\n for (const property of properties) {\n Object.defineProperty(prototype, property, {\n value: undefined,\n configurable: false,\n writable: false,\n });\n }\n });\n}\n"],"names":["executeLockdownEvents","targetEvents","Map","hasProperty","globalThis","set","UIEvent","prototype","MutationEvent","MessageEvent","FocusEvent","MouseEvent","TouchEvent","Event","forEach","properties","property","Object","defineProperty","value","undefined","configurable","writable"],"mappings":"AAAA,iEAAiE;AACjE,2EAA2E;AAC3E,wCAAwC;;;;;+BA4CxBA;;;eAAAA;;;uBA3CY;AAE5B;;;;;CAKC,GACD,MAAMC,eAAe,IAAIC;AACzB,IAAIC,IAAAA,kBAAW,EAACC,YAAY,YAAY;IACtCH,aAAaI,GAAG,CAACC,QAAQC,SAAS,EAAE;QAAC;KAAO;AAC9C;AACA,IAAIJ,IAAAA,kBAAW,EAACC,YAAY,kBAAkB;IAC5CH,aAAaI,GAAG,CAACG,cAAcD,SAAS,EAAE;QAAC;KAAc;AAC3D;AACA,IAAIJ,IAAAA,kBAAW,EAACC,YAAY,iBAAiB;IAC3CH,aAAaI,GAAG,CAACI,aAAaF,SAAS,EAAE;QAAC;KAAS;AACrD;AACA,IAAIJ,IAAAA,kBAAW,EAACC,YAAY,eAAe;IACzCH,aAAaI,GAAG,CAACK,WAAWH,SAAS,EAAE;QAAC;KAAgB;AAC1D;AACA,IAAIJ,IAAAA,kBAAW,EAACC,YAAY,eAAe;IACzCH,aAAaI,GAAG,CAACM,WAAWJ,SAAS,EAAE;QACrC;QACA;QACA;KACD;AACH;AACA,IAAIJ,IAAAA,kBAAW,EAACC,YAAY,eAAe;IACzCH,aAAaI,GAAG,CAACO,WAAWL,SAAS,EAAE;QAAC;QAAiB;KAAU;AACrE;AACA,IAAIJ,IAAAA,kBAAW,EAACC,YAAY,UAAU;IACpCH,aAAaI,GAAG,CAACQ,MAAMN,SAAS,EAAE;QAChC;QACA;QACA;QACA;KACD;AACH;AAKO,SAASP;IACdC,aAAaa,OAAO,CAAC,CAACC,YAAYR;QAChC,KAAK,MAAMS,YAAYD,WAAY;YACjCE,OAAOC,cAAc,CAACX,WAAWS,UAAU;gBACzCG,OAAOC;gBACPC,cAAc;gBACdC,UAAU;YACZ;QACF;IACF;AACF"}
|