@metamask/snaps-execution-environments 0.31.0 → 0.32.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.
Files changed (32) hide show
  1. package/dist/browserify/iframe/bundle.js +6435 -0
  2. package/dist/{webpack → browserify}/iframe/index.html +1411 -178
  3. package/dist/browserify/node-process/bundle.js +15135 -0
  4. package/dist/browserify/node-thread/bundle.js +15135 -0
  5. package/dist/browserify/offscreen/bundle.js +2266 -0
  6. package/dist/{webpack → browserify}/offscreen/index.html +1411 -178
  7. package/dist/common/endowments/commonEndowmentFactory.d.ts +1 -0
  8. package/dist/common/endowments/commonEndowmentFactory.js +9 -3
  9. package/dist/common/endowments/commonEndowmentFactory.js.map +1 -1
  10. package/dist/common/endowments/index.d.ts +0 -7
  11. package/dist/common/endowments/index.js +4 -24
  12. package/dist/common/endowments/index.js.map +1 -1
  13. package/dist/common/lockdown/lockdown-events.d.ts +4 -0
  14. package/dist/common/lockdown/lockdown-events.js +60 -0
  15. package/dist/common/lockdown/lockdown-events.js.map +1 -0
  16. package/dist/iframe/index.js +3 -2
  17. package/dist/iframe/index.js.map +1 -1
  18. package/dist/node-process/index.js +1 -2
  19. package/dist/node-process/index.js.map +1 -1
  20. package/dist/node-thread/index.js +1 -2
  21. package/dist/node-thread/index.js.map +1 -1
  22. package/dist/offscreen/index.js +3 -2
  23. package/dist/offscreen/index.js.map +1 -1
  24. package/package.json +18 -18
  25. package/dist/webpack/iframe/bundle.js +0 -2
  26. package/dist/webpack/iframe/bundle.js.LICENSE.txt +0 -14
  27. package/dist/webpack/node-process/bundle.js +0 -111579
  28. package/dist/webpack/node-process/lockdown.umd.min.js +0 -1
  29. package/dist/webpack/node-thread/bundle.js +0 -111579
  30. package/dist/webpack/node-thread/lockdown.umd.min.js +0 -1
  31. package/dist/webpack/offscreen/bundle.js +0 -2
  32. package/dist/webpack/offscreen/bundle.js.LICENSE.txt +0 -12
@@ -7,6 +7,7 @@ export declare type EndowmentFactory = {
7
7
  export declare type CommonEndowmentSpecification = {
8
8
  endowment: unknown;
9
9
  name: string;
10
+ bind?: boolean;
10
11
  };
11
12
  /**
12
13
  * Creates a consolidated collection of common endowments.
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const globalObject_1 = require("../globalObject");
6
7
  const crypto_1 = __importDefault(require("./crypto"));
7
8
  const date_1 = __importDefault(require("./date"));
8
9
  const interval_1 = __importDefault(require("./interval"));
@@ -16,11 +17,12 @@ const commonEndowments = [
16
17
  { endowment: AbortController, name: 'AbortController' },
17
18
  { endowment: AbortSignal, name: 'AbortSignal' },
18
19
  { endowment: ArrayBuffer, name: 'ArrayBuffer' },
19
- { endowment: atob, name: 'atob' },
20
+ { endowment: atob, name: 'atob', bind: true },
20
21
  { endowment: BigInt, name: 'BigInt' },
21
22
  { endowment: BigInt64Array, name: 'BigInt64Array' },
22
23
  { endowment: BigUint64Array, name: 'BigUint64Array' },
23
- { endowment: btoa, name: 'btoa' },
24
+ { endowment: btoa, name: 'btoa', bind: true },
25
+ { endowment: console, name: 'console' },
24
26
  { endowment: DataView, name: 'DataView' },
25
27
  { endowment: Float32Array, name: 'Float32Array' },
26
28
  { endowment: Float64Array, name: 'Float64Array' },
@@ -56,8 +58,12 @@ const buildCommonEndowments = () => {
56
58
  const endowment = {
57
59
  names: [endowmentSpecification.name],
58
60
  factory: () => {
61
+ const boundEndowment = typeof endowmentSpecification.endowment === 'function' &&
62
+ endowmentSpecification.bind
63
+ ? endowmentSpecification.endowment.bind(globalObject_1.rootRealmGlobal)
64
+ : endowmentSpecification.endowment;
59
65
  return {
60
- [endowmentSpecification.name]: harden(endowmentSpecification.endowment),
66
+ [endowmentSpecification.name]: harden(boundEndowment),
61
67
  };
62
68
  },
63
69
  };
@@ -1 +1 @@
1
- {"version":3,"file":"commonEndowmentFact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S,EAAE,WAAW,EAAE,IAAI,EAAE,aAAa,EAAE;IAC/C,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,aAAa,EAAE;IAC/C,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE;IAC/B,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,aAAa,EAAE;CAChD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,qBAAqB,GAAG,GAAuB,EAAE;IACrD,MAAM,kBAAkB,GAAuB;QAC7C,gBAAM;QACN,kBAAQ;QACR,cAAI;QACJ,iBAAO;QACP,iBAAO;QACP,qBAAW;QACX,qBAAW;QACX,cAAI;KACL,CAAC;IAEF,gBAAgB,CAAC,OAAO,CAAC,CAAC,sBAAsB,EAAE,EAAE;QAClD,MAAM,SAAS,GAAG;YAChB,KAAK,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAU;YAC7C,OAAO,EAAE,GAAG,EAAE;gBACZ,OAAO;oBACL,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,CACnC,sBAAsB,CAAC,SAAS,CACjC;iBACO,CAAC;YACb,CAAC;SACF,CAAC;QACF,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC;AAEF,kBAAe,qBAAqB,CAAC","sourcesContent":["import crypto from './crypto';\nimport date from './date';\nimport interval from './interval';\nimport math from './math';\nimport network from './network';\nimport textDecoder from './textDecoder';\nimport textEncoder from './textEncoder';\nimport timeout from './timeout';\n\nexport type EndowmentFactory = {\n names: readonly string[];\n factory: () => { [key: string]: unknown };\n};\n\nexport type CommonEndowmentSpecification = {\n endowment: unknown;\n name: string;\n};\n\n// Array of common endowments\nconst commonEndowments: CommonEndowmentSpecification[] = [\n { endowment: AbortController, name: 'AbortController' },\n { endowment: AbortSignal, name: 'AbortSignal' },\n { endowment: ArrayBuffer, name: 'ArrayBuffer' },\n { endowment: atob, name: 'atob' },\n { endowment: BigInt, name: 'BigInt' },\n { endowment: BigInt64Array, name: 'BigInt64Array' },\n { endowment: BigUint64Array, name: 'BigUint64Array' },\n { endowment: btoa, name: 'btoa' },\n { endowment: DataView, name: 'DataView' },\n { endowment: Float32Array, name: 'Float32Array' },\n { endowment: Float64Array, name: 'Float64Array' },\n { endowment: Int8Array, name: 'Int8Array' },\n { endowment: Int16Array, name: 'Int16Array' },\n { endowment: Int32Array, name: 'Int32Array' },\n { endowment: Uint8Array, name: 'Uint8Array' },\n { endowment: Uint8ClampedArray, name: 'Uint8ClampedArray' },\n { endowment: Uint16Array, name: 'Uint16Array' },\n { endowment: Uint32Array, name: 'Uint32Array' },\n { endowment: URL, name: 'URL' },\n { endowment: WebAssembly, name: 'WebAssembly' },\n];\n\n/**\n * Creates a consolidated collection of common endowments.\n * This function will return factories for all common endowments including\n * the additionally attenuated. All hardened with SES.\n *\n * @returns An object with common endowments.\n */\nconst buildCommonEndowments = (): EndowmentFactory[] => {\n const endowmentFactories: EndowmentFactory[] = [\n crypto,\n interval,\n math,\n network,\n timeout,\n textDecoder,\n textEncoder,\n date,\n ];\n\n commonEndowments.forEach((endowmentSpecification) => {\n const endowment = {\n names: [endowmentSpecification.name] as const,\n factory: () => {\n return {\n [endowmentSpecification.name]: harden(\n endowmentSpecification.endowment,\n ),\n } as const;\n },\n };\n endowmentFactories.push(endowment);\n });\n\n return endowmentFactories;\n};\n\nexport default buildCommonEndowments;\n"]}
1
+ {"version":3,"file":"commonEndowmentFactory.js","sourceRoot":"","sources":["../../../src/common/endowments/commonEndowmentFactory.ts"],"names":[],"mappings":";;;;;AAAA,kDAAkD;AAClD,sDAA8B;AAC9B,kDAA0B;AAC1B,0DAAkC;AAClC,kDAA0B;AAC1B,wDAAgC;AAChC,gEAAwC;AACxC,gEAAwC;AACxC,wDAAgC;AAahC,6BAA6B;AAC7B,MAAM,gBAAgB,GAAmC;IACvD,EAAE,SAAS,E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,IAAI,EAAE,KAAK,EAAE;IAC/B,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,aAAa,EAAE;CAChD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,qBAAqB,GAAG,GAAuB,EAAE;IACrD,MAAM,kBAAkB,GAAuB;QAC7C,gBAAM;QACN,kBAAQ;QACR,cAAI;QACJ,iBAAO;QACP,iBAAO;QACP,qBAAW;QACX,qBAAW;QACX,cAAI;KACL,CAAC;IAEF,gBAAgB,CAAC,OAAO,CAAC,CAAC,sBAAsB,EAAE,EAAE;QAClD,MAAM,SAAS,GAAG;YAChB,KAAK,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAU;YAC7C,OAAO,EAAE,GAAG,EAAE;gBACZ,MAAM,cAAc,GAClB,OAAO,sBAAsB,CAAC,SAAS,KAAK,UAAU;oBACtD,sBAAsB,CAAC,IAAI;oBACzB,CAAC,CAAC,sBAAsB,CAAC,SAAS,CAAC,IAAI,CAAC,8BAAe,CAAC;oBACxD,CAAC,CAAC,sBAAsB,CAAC,SAAS,CAAC;gBACvC,OAAO;oBACL,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;iBAC7C,CAAC;YACb,CAAC;SACF,CAAC;QACF,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC;AAEF,kBAAe,qBAAqB,CAAC","sourcesContent":["import { rootRealmGlobal } from '../globalObject';\nimport crypto from './crypto';\nimport date from './date';\nimport interval from './interval';\nimport math from './math';\nimport network from './network';\nimport textDecoder from './textDecoder';\nimport textEncoder from './textEncoder';\nimport timeout from './timeout';\n\nexport type EndowmentFactory = {\n names: readonly string[];\n factory: () => { [key: string]: unknown };\n};\n\nexport type CommonEndowmentSpecification = {\n endowment: unknown;\n name: string;\n bind?: boolean;\n};\n\n// Array of common endowments\nconst commonEndowments: CommonEndowmentSpecification[] = [\n { endowment: AbortController, name: 'AbortController' },\n { endowment: AbortSignal, name: 'AbortSignal' },\n { endowment: ArrayBuffer, name: 'ArrayBuffer' },\n { endowment: atob, name: 'atob', bind: true },\n { endowment: BigInt, name: 'BigInt' },\n { endowment: BigInt64Array, name: 'BigInt64Array' },\n { endowment: BigUint64Array, name: 'BigUint64Array' },\n { endowment: btoa, name: 'btoa', bind: true },\n { endowment: console, name: 'console' },\n { endowment: DataView, name: 'DataView' },\n { endowment: Float32Array, name: 'Float32Array' },\n { endowment: Float64Array, name: 'Float64Array' },\n { endowment: Int8Array, name: 'Int8Array' },\n { endowment: Int16Array, name: 'Int16Array' },\n { endowment: Int32Array, name: 'Int32Array' },\n { endowment: Uint8Array, name: 'Uint8Array' },\n { endowment: Uint8ClampedArray, name: 'Uint8ClampedArray' },\n { endowment: Uint16Array, name: 'Uint16Array' },\n { endowment: Uint32Array, name: 'Uint32Array' },\n { endowment: URL, name: 'URL' },\n { endowment: WebAssembly, name: 'WebAssembly' },\n];\n\n/**\n * Creates a consolidated collection of common endowments.\n * This function will return factories for all common endowments including\n * the additionally attenuated. All hardened with SES.\n *\n * @returns An object with common endowments.\n */\nconst buildCommonEndowments = (): EndowmentFactory[] => {\n const endowmentFactories: EndowmentFactory[] = [\n crypto,\n interval,\n math,\n network,\n timeout,\n textDecoder,\n textEncoder,\n date,\n ];\n\n commonEndowments.forEach((endowmentSpecification) => {\n const endowment = {\n names: [endowmentSpecification.name] as const,\n factory: () => {\n const boundEndowment =\n typeof endowmentSpecification.endowment === 'function' &&\n endowmentSpecification.bind\n ? endowmentSpecification.endowment.bind(rootRealmGlobal)\n : endowmentSpecification.endowment;\n return {\n [endowmentSpecification.name]: harden(boundEndowment),\n } as const;\n },\n };\n endowmentFactories.push(endowment);\n });\n\n return endowmentFactories;\n};\n\nexport default buildCommonEndowments;\n"]}
@@ -16,10 +16,3 @@ export declare function createEndowments(snap: SnapsGlobalObject, ethereum: Stre
16
16
  endowments: Record<string, unknown>;
17
17
  teardown: () => Promise<void>;
18
18
  };
19
- /**
20
- * Checks whether the specified function is a constructor.
21
- *
22
- * @param value - Any function value.
23
- * @returns Whether the specified function is a constructor.
24
- */
25
- export declare function isConstructor<T extends Function>(value: T): boolean;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isConstructor = exports.createEndowments = void 0;
6
+ exports.createEndowments = void 0;
7
+ const snaps_utils_1 = require("@metamask/snaps-utils");
7
8
  const utils_1 = require("@metamask/utils");
8
9
  const globalObject_1 = require("../globalObject");
9
10
  const commonEndowmentFactory_1 = __importDefault(require("./commonEndowmentFactory"));
@@ -64,13 +65,11 @@ function createEndowments(snap, ethereum, endowments = []) {
64
65
  allEndowments[endowmentName] = ethereum;
65
66
  }
66
67
  else if (endowmentName in globalObject_1.rootRealmGlobal) {
68
+ (0, snaps_utils_1.logWarning)(`Access to unhardened global ${endowmentName}.`);
67
69
  // If the endowment doesn't have a factory, just use whatever is on the
68
70
  // global object.
69
71
  const globalValue = globalObject_1.rootRealmGlobal[endowmentName];
70
- allEndowments[endowmentName] =
71
- typeof globalValue === 'function' && !isConstructor(globalValue)
72
- ? globalValue.bind(globalObject_1.rootRealmGlobal)
73
- : globalValue;
72
+ allEndowments[endowmentName] = globalValue;
74
73
  }
75
74
  else {
76
75
  // If we get to this point, we've been passed an endowment that doesn't
@@ -88,23 +87,4 @@ function createEndowments(snap, ethereum, endowments = []) {
88
87
  return { endowments: result.allEndowments, teardown };
89
88
  }
90
89
  exports.createEndowments = createEndowments;
91
- /**
92
- * Checks whether the specified function is a constructor.
93
- *
94
- * @param value - Any function value.
95
- * @returns Whether the specified function is a constructor.
96
- */
97
- // `Function` is exactly what we want here.
98
- // eslint-disable-next-line @typescript-eslint/ban-types
99
- function isConstructor(value) {
100
- // In our current usage, the string `prototype.constructor.name` should never
101
- // be empty, because you can't create a class with no name, and the
102
- // `prototype.constructor.name` property is configurable but not writable.
103
- // Nevertheless, that property was the empty string for `Date` in the iframe
104
- // execution environment during local testing. We have no idea why, but we
105
- // have to handle that case.
106
- // TODO: Does the `prototype` object always have a `constructor` property?
107
- return Boolean(typeof value.prototype?.constructor?.name === 'string');
108
- }
109
- exports.isConstructor = isConstructor;
110
90
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/endowments/index.ts"],"names":[],"mappings":";;;;;;AAEA,2CAA8C;AAE9C,kDAAkD;AAClD,sFAA6D;AAe7D;;GAEG;AACH,MAAM,oBAAoB,GAAG,IAAA,gCAAqB,GAAE,CAAC;AAErD;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;IAC5E,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC7B,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC,EAAE,IAAI,GAAG,EAAwC,CAAC,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB,CAC9B,IAAuB,EACvB,QAAwB,EACxB,aAAuB,EAAE;IAEzB,MAAM,oBAAoB,GAA4B,EAAE,CAAC;IAEzD,0EAA0E;IAC1E,yEAAyE;IACzE,2CAA2C;IAC3C,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAI9B,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,aAAa,EAAE,EAAE;QAC9C,oEAAoE;QACpE,IAAI,kBAAkB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;YACzC,IAAI,CAAC,IAAA,mBAAW,EAAC,oBAAoB,EAAE,aAAa,CAAC,E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AAC,CAAC,gBAAgB,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC,CAC/D,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,QAAQ,EAAE,CAAC;AACxD,CAAC;AAnED,4CAmEC;AAED;;;;;GAKG;AACH,2CAA2C;AAC3C,wDAAwD;AACxD,SAAgB,aAAa,CAAqB,KAAQ;IACxD,6EAA6E;IAC7E,mEAAmE;IACnE,0EAA0E;IAC1E,4EAA4E;IAC5E,0EAA0E;IAC1E,4BAA4B;IAC5B,0EAA0E;IAC1E,OAAO,OAAO,CAAC,OAAO,KAAK,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC;AACzE,CAAC;AATD,sCASC","sourcesContent":["import { StreamProvider } from '@metamask/providers';\nimport { SnapsGlobalObject } from '@metamask/rpc-methods';\nimport { hasProperty } from '@metamask/utils';\n\nimport { rootRealmGlobal } from '../globalObject';\nimport buildCommonEndowments from './commonEndowmentFactory';\n\ntype EndowmentFactoryResult = {\n /**\n * A function that performs any necessary teardown when the snap becomes idle.\n *\n * NOTE:** The endowments are not reconstructed if the snap is re-invoked\n * before being terminated, so the teardown operation must not render the\n * endowments unusable; it should simply restore the endowments to their\n * original state.\n */\n teardownFunction?: () => Promise<void> | void;\n [key: string]: unknown;\n};\n\n/**\n * Retrieve consolidated endowment factories for common endowments.\n */\nconst registeredEndowments = buildCommonEndowments();\n\n/**\n * A map of endowment names to their factory functions. Some endowments share\n * the same factory function, but we only call each factory once for each snap.\n * See {@link createEndowments} for details.\n */\nconst endowmentFactories = registeredEndowments.reduce((factories, builder) => {\n builder.names.forEach((name) => {\n factories.set(name, builder.factory);\n });\n return factories;\n}, new Map<string, () => EndowmentFactoryResult>());\n\n/**\n * Gets the endowments for a particular Snap. Some endowments, like `setTimeout`\n * and `clearTimeout`, must be attenuated so that they can only affect behavior\n * within the Snap's own realm. Therefore, we use factory functions to create\n * such attenuated / modified endowments. Otherwise, the value that's on the\n * root realm global will be used.\n *\n * @param snap - The Snaps global API object.\n * @param ethereum - The Snap's EIP-1193 provider object.\n * @param endowments - The list of endowments to provide to the snap.\n * @returns An object containing the Snap's endowments.\n */\nexport function createEndowments(\n snap: SnapsGlobalObject,\n ethereum: StreamProvider,\n endowments: string[] = [],\n): { endowments: Record<string, unknown>; teardown: () => Promise<void> } {\n const attenuatedEndowments: Record<string, unknown> = {};\n\n // TODO: All endowments should be hardened to prevent covert communication\n // channels. Hardening the returned objects breaks tests elsewhere in the\n // monorepo, so further research is needed.\n const result = endowments.reduce<{\n allEndowments: Record<string, unknown>;\n teardowns: (() => Promise<void> | void)[];\n }>(\n ({ allEndowments, teardowns }, endowmentName) => {\n // First, check if the endowment has a factory, and default to that.\n if (endowmentFactories.has(endowmentName)) {\n if (!hasProperty(attenuatedEndowments, endowmentName)) {\n // Call the endowment factory for the current endowment. If the factory\n // creates multiple endowments, they will all be assigned to the\n // `attenuatedEndowments` object, but will only be passed on to the snap\n // if explicitly listed among its endowment.\n // This may not have an actual use case, but, safety first.\n\n // We just confirmed that endowmentFactories has the specified key.\n const { teardownFunction, ...endowment } =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n endowmentFactories.get(endowmentName)!();\n Object.assign(attenuatedEndowments, endowment);\n if (teardownFunction) {\n teardowns.push(teardownFunction);\n }\n }\n\n allEndowments[endowmentName] = attenuatedEndowments[endowmentName];\n } else if (endowmentName === 'ethereum') {\n // Special case for adding the EIP-1193 provider.\n allEndowments[endowmentName] = ethereum;\n } else if (endowmentName in rootRealmGlobal) {\n // If the endowment doesn't have a factory, just use whatever is on the\n // global object.\n const globalValue = (rootRealmGlobal as Record<string, unknown>)[\n endowmentName\n ];\n allEndowments[endowmentName] =\n typeof globalValue === 'function' && !isConstructor(globalValue)\n ? globalValue.bind(rootRealmGlobal)\n : globalValue;\n } else {\n // If we get to this point, we've been passed an endowment that doesn't\n // exist in our current environment.\n throw new Error(`Unknown endowment: \"${endowmentName}\".`);\n }\n return { allEndowments, teardowns };\n },\n {\n allEndowments: { snap },\n teardowns: [],\n },\n );\n\n const teardown = async () => {\n await Promise.all(\n result.teardowns.map((teardownFunction) => teardownFunction()),\n );\n };\n return { endowments: result.allEndowments, teardown };\n}\n\n/**\n * Checks whether the specified function is a constructor.\n *\n * @param value - Any function value.\n * @returns Whether the specified function is a constructor.\n */\n// `Function` is exactly what we want here.\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function isConstructor<T extends Function>(value: T): boolean {\n // In our current usage, the string `prototype.constructor.name` should never\n // be empty, because you can't create a class with no name, and the\n // `prototype.constructor.name` property is configurable but not writable.\n // Nevertheless, that property was the empty string for `Date` in the iframe\n // execution environment during local testing. We have no idea why, but we\n // have to handle that case.\n // TODO: Does the `prototype` object always have a `constructor` property?\n return Boolean(typeof value.prototype?.constructor?.name === 'string');\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/endowments/index.ts"],"names":[],"mappings":";;;;;;AAEA,uDAAmD;AACnD,2CAA8C;AAE9C,kDAAkD;AAClD,sFAA6D;AAe7D;;GAEG;AACH,MAAM,oBAAoB,GAAG,IAAA,gCAAqB,GAAE,CAAC;AAErD;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;IAC5E,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC7B,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC,EAAE,IAAI,GAAG,EAAwC,CAAC,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB,CAC9B,IAAuB,EACvB,QAAwB,EACxB,aAAuB,EAAE;IAEzB,MAAM,oBAAoB,GAA4B,EAAE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,SAAS,EAAE,CAAC;IACtC,CAAC,EACD;QACE,aAAa,EAAE,EAAE,IAAI,EAAE;QACvB,SAAS,EAAE,EAAE;KACd,CACF,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC,CAC/D,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,QAAQ,EAAE,CAAC;AACxD,CAAC;AAjED,4CAiEC","sourcesContent":["import { StreamProvider } from '@metamask/providers';\nimport { SnapsGlobalObject } from '@metamask/rpc-methods';\nimport { logWarning } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\n\nimport { rootRealmGlobal } from '../globalObject';\nimport buildCommonEndowments from './commonEndowmentFactory';\n\ntype EndowmentFactoryResult = {\n /**\n * A function that performs any necessary teardown when the snap becomes idle.\n *\n * NOTE:** The endowments are not reconstructed if the snap is re-invoked\n * before being terminated, so the teardown operation must not render the\n * endowments unusable; it should simply restore the endowments to their\n * original state.\n */\n teardownFunction?: () => Promise<void> | void;\n [key: string]: unknown;\n};\n\n/**\n * Retrieve consolidated endowment factories for common endowments.\n */\nconst registeredEndowments = buildCommonEndowments();\n\n/**\n * A map of endowment names to their factory functions. Some endowments share\n * the same factory function, but we only call each factory once for each snap.\n * See {@link createEndowments} for details.\n */\nconst endowmentFactories = registeredEndowments.reduce((factories, builder) => {\n builder.names.forEach((name) => {\n factories.set(name, builder.factory);\n });\n return factories;\n}, new Map<string, () => EndowmentFactoryResult>());\n\n/**\n * Gets the endowments for a particular Snap. Some endowments, like `setTimeout`\n * and `clearTimeout`, must be attenuated so that they can only affect behavior\n * within the Snap's own realm. Therefore, we use factory functions to create\n * such attenuated / modified endowments. Otherwise, the value that's on the\n * root realm global will be used.\n *\n * @param snap - The Snaps global API object.\n * @param ethereum - The Snap's EIP-1193 provider object.\n * @param endowments - The list of endowments to provide to the snap.\n * @returns An object containing the Snap's endowments.\n */\nexport function createEndowments(\n snap: SnapsGlobalObject,\n ethereum: StreamProvider,\n endowments: string[] = [],\n): { endowments: Record<string, unknown>; teardown: () => Promise<void> } {\n const attenuatedEndowments: Record<string, unknown> = {};\n\n // TODO: All endowments should be hardened to prevent covert communication\n // channels. Hardening the returned objects breaks tests elsewhere in the\n // monorepo, so further research is needed.\n const result = endowments.reduce<{\n allEndowments: Record<string, unknown>;\n teardowns: (() => Promise<void> | void)[];\n }>(\n ({ allEndowments, teardowns }, endowmentName) => {\n // First, check if the endowment has a factory, and default to that.\n if (endowmentFactories.has(endowmentName)) {\n if (!hasProperty(attenuatedEndowments, endowmentName)) {\n // Call the endowment factory for the current endowment. If the factory\n // creates multiple endowments, they will all be assigned to the\n // `attenuatedEndowments` object, but will only be passed on to the snap\n // if explicitly listed among its endowment.\n // This may not have an actual use case, but, safety first.\n\n // We just confirmed that endowmentFactories has the specified key.\n const { teardownFunction, ...endowment } =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n endowmentFactories.get(endowmentName)!();\n Object.assign(attenuatedEndowments, endowment);\n if (teardownFunction) {\n teardowns.push(teardownFunction);\n }\n }\n\n allEndowments[endowmentName] = attenuatedEndowments[endowmentName];\n } else if (endowmentName === 'ethereum') {\n // Special case for adding the EIP-1193 provider.\n allEndowments[endowmentName] = ethereum;\n } else if (endowmentName in rootRealmGlobal) {\n logWarning(`Access to unhardened global ${endowmentName}.`);\n // If the endowment doesn't have a factory, just use whatever is on the\n // global object.\n const globalValue = (rootRealmGlobal as Record<string, unknown>)[\n endowmentName\n ];\n allEndowments[endowmentName] = globalValue;\n } else {\n // If we get to this point, we've been passed an endowment that doesn't\n // exist in our current environment.\n throw new Error(`Unknown endowment: \"${endowmentName}\".`);\n }\n return { allEndowments, teardowns };\n },\n {\n allEndowments: { snap },\n teardowns: [],\n },\n );\n\n const teardown = async () => {\n await Promise.all(\n result.teardowns.map((teardownFunction) => teardownFunction()),\n );\n };\n return { endowments: result.allEndowments, teardown };\n}\n"]}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Attenuate Event objects by replacing its own properties.
3
+ */
4
+ export declare function executeLockdownEvents(): void;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeLockdownEvents = void 0;
4
+ // When creating a sandbox, limitation of the events from leaking
5
+ // sensitive objects is required. This is done by overriding own properties
6
+ // of prototypes of all existing events.
7
+ const utils_1 = require("@metamask/utils");
8
+ /**
9
+ * Targeted Event objects and properties.
10
+ * Note: This is a map of the prototypes that inherit from Events with
11
+ * properties that are identified to leak sensitive objects.
12
+ * Not all browsers support all event types, so checking its existence is required.
13
+ */
14
+ const targetEvents = new Map();
15
+ if ((0, utils_1.hasProperty)(globalThis, 'UIEvent')) {
16
+ targetEvents.set(UIEvent.prototype, ['view']);
17
+ }
18
+ if ((0, utils_1.hasProperty)(globalThis, 'MutationEvent')) {
19
+ targetEvents.set(MutationEvent.prototype, ['relatedNode']);
20
+ }
21
+ if ((0, utils_1.hasProperty)(globalThis, 'MessageEvent')) {
22
+ targetEvents.set(MessageEvent.prototype, ['source']);
23
+ }
24
+ if ((0, utils_1.hasProperty)(globalThis, 'FocusEvent')) {
25
+ targetEvents.set(FocusEvent.prototype, ['relatedTarget']);
26
+ }
27
+ if ((0, utils_1.hasProperty)(globalThis, 'MouseEvent')) {
28
+ targetEvents.set(MouseEvent.prototype, [
29
+ 'relatedTarget',
30
+ 'fromElement',
31
+ 'toElement',
32
+ ]);
33
+ }
34
+ if ((0, utils_1.hasProperty)(globalThis, 'TouchEvent')) {
35
+ targetEvents.set(TouchEvent.prototype, ['targetTouches', 'touches']);
36
+ }
37
+ if ((0, utils_1.hasProperty)(globalThis, 'Event')) {
38
+ targetEvents.set(Event.prototype, [
39
+ 'target',
40
+ 'currentTarget',
41
+ 'srcElement',
42
+ 'composedPath',
43
+ ]);
44
+ }
45
+ /**
46
+ * Attenuate Event objects by replacing its own properties.
47
+ */
48
+ function executeLockdownEvents() {
49
+ targetEvents.forEach((properties, prototype) => {
50
+ for (const property of properties) {
51
+ Object.defineProperty(prototype, property, {
52
+ value: undefined,
53
+ configurable: false,
54
+ writable: false,
55
+ });
56
+ }
57
+ });
58
+ }
59
+ exports.executeLockdownEvents = executeLockdownEvents;
60
+ //# sourceMappingURL=lockdown-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockdown-events.js","sourceRoot":"","sources":["../../../src/common/lockdown/lockdown-events.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AACjE,2EAA2E;AAC3E,wCAAwC;AACxC,2CAA8C;AAE9C;;;;;GAKG;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;AAC/B,IAAI,IAAA,mBAAW,EAAC,UAAU,EAAE,SAAS,CAAC,EAAE;IACtC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;CAC/C;AACD,IAAI,IAAA,mBAAW,EAAC,UAAU,EAAE,eAAe,CAAC,EAAE;IAC5C,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;CAC5D;AACD,IAAI,IAAA,mBAAW,EAAC,UAAU,EAAE,cAAc,CAAC,EAAE;IAC3C,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;CACtD;AACD,IAAI,IAAA,mBAAW,EAAC,UAAU,EAAE,YAAY,CAAC,EAAE;IACzC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;CAC3D;AACD,IAAI,IAAA,mBAAW,EAAC,UAAU,EAAE,YAAY,CAAC,EAAE;IACzC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE;QACrC,eAAe;QACf,aAAa;QACb,WAAW;KACZ,CAAC,CAAC;CACJ;AACD,IAAI,IAAA,mBAAW,EAAC,UAAU,EAAE,YAAY,CAAC,EAAE;IACzC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC;CACtE;AACD,IAAI,IAAA,mBAAW,EAAC,UAAU,EAAE,OAAO,CAAC,EAAE;IACpC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE;QAChC,QAAQ;QACR,eAAe;QACf,YAAY;QACZ,cAAc;KACf,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,SAAgB,qBAAqB;IACnC,YAAY,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE;QAC7C,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;YACjC,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,QAAQ,EAAE;gBACzC,KAAK,EAAE,SAAS;gBAChB,YAAY,EAAE,KAAK;gBACnB,QAAQ,EAAE,KAAK;aAChB,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAVD,sDAUC","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"]}
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const lockdown_1 = require("../common/lockdown/lockdown");
3
+ const lockdown_events_1 = require("../common/lockdown/lockdown-events");
4
4
  const lockdown_more_1 = require("../common/lockdown/lockdown-more");
5
5
  const IFrameSnapExecutor_1 = require("./IFrameSnapExecutor");
6
- (0, lockdown_1.executeLockdown)();
6
+ // Lockdown is already applied in LavaMoat
7
7
  (0, lockdown_more_1.executeLockdownMore)();
8
+ (0, lockdown_events_1.executeLockdownEvents)();
8
9
  IFrameSnapExecutor_1.IFrameSnapExecutor.initialize();
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/iframe/index.ts"],"names":[],"mappings":";;AAAA,0DAA8D;AAC9D,oEAAuE;AACvE,6DAA0D;AAE1D,IAAA,0BAAe,GAAE,CAAC;AAClB,IAAA,mCAAmB,GAAE,CAAC;AAEtB,uCAAkB,CAAC,UAAU,EAAE,CAAC","sourcesContent":["import { executeLockdown } from '../common/lockdown/lockdown';\nimport { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { IFrameSnapExecutor } from './IFrameSnapExecutor';\n\nexecuteLockdown();\nexecuteLockdownMore();\n\nIFrameSnapExecutor.initialize();\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/iframe/index.ts"],"names":[],"mappings":";;AAAA,wEAA2E;AAC3E,oEAAuE;AACvE,6DAA0D;AAE1D,0CAA0C;AAC1C,IAAA,mCAAmB,GAAE,CAAC;AACtB,IAAA,uCAAqB,GAAE,CAAC;AAExB,uCAAkB,CAAC,UAAU,EAAE,CAAC","sourcesContent":["import { executeLockdownEvents } from '../common/lockdown/lockdown-events';\nimport { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { IFrameSnapExecutor } from './IFrameSnapExecutor';\n\n// Lockdown is already applied in LavaMoat\nexecuteLockdownMore();\nexecuteLockdownEvents();\n\nIFrameSnapExecutor.initialize();\n"]}
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const lockdown_1 = require("../common/lockdown/lockdown");
4
3
  const lockdown_more_1 = require("../common/lockdown/lockdown-more");
5
4
  const ChildProcessSnapExecutor_1 = require("./ChildProcessSnapExecutor");
6
- (0, lockdown_1.executeLockdown)();
5
+ // Lockdown is already applied in LavaMoat
7
6
  (0, lockdown_more_1.executeLockdownMore)();
8
7
  ChildProcessSnapExecutor_1.ChildProcessSnapExecutor.initialize();
9
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node-process/index.ts"],"names":[],"mappings":";;AAAA,0DAA8D;AAC9D,oEAAuE;AACvE,yEAAsE;AAEtE,IAAA,0BAAe,GAAE,CAAC;AAClB,IAAA,mCAAmB,GAAE,CAAC;AAEtB,mDAAwB,CAAC,UAAU,EAAE,CAAC","sourcesContent":["import { executeLockdown } from '../common/lockdown/lockdown';\nimport { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { ChildProcessSnapExecutor } from './ChildProcessSnapExecutor';\n\nexecuteLockdown();\nexecuteLockdownMore();\n\nChildProcessSnapExecutor.initialize();\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node-process/index.ts"],"names":[],"mappings":";;AAAA,oEAAuE;AACvE,yEAAsE;AAEtE,0CAA0C;AAC1C,IAAA,mCAAmB,GAAE,CAAC;AAEtB,mDAAwB,CAAC,UAAU,EAAE,CAAC","sourcesContent":["import { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { ChildProcessSnapExecutor } from './ChildProcessSnapExecutor';\n\n// Lockdown is already applied in LavaMoat\nexecuteLockdownMore();\n\nChildProcessSnapExecutor.initialize();\n"]}
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const lockdown_1 = require("../common/lockdown/lockdown");
4
3
  const lockdown_more_1 = require("../common/lockdown/lockdown-more");
5
4
  const ThreadSnapExecutor_1 = require("./ThreadSnapExecutor");
6
- (0, lockdown_1.executeLockdown)();
5
+ // Lockdown is already applied in LavaMoat
7
6
  (0, lockdown_more_1.executeLockdownMore)();
8
7
  ThreadSnapExecutor_1.ThreadSnapExecutor.initialize();
9
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node-thread/index.ts"],"names":[],"mappings":";;AAAA,0DAA8D;AAC9D,oEAAuE;AACvE,6DAA0D;AAE1D,IAAA,0BAAe,GAAE,CAAC;AAClB,IAAA,mCAAmB,GAAE,CAAC;AAEtB,uCAAkB,CAAC,UAAU,EAAE,CAAC","sourcesContent":["import { executeLockdown } from '../common/lockdown/lockdown';\nimport { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { ThreadSnapExecutor } from './ThreadSnapExecutor';\n\nexecuteLockdown();\nexecuteLockdownMore();\n\nThreadSnapExecutor.initialize();\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node-thread/index.ts"],"names":[],"mappings":";;AAAA,oEAAuE;AACvE,6DAA0D;AAE1D,0CAA0C;AAC1C,IAAA,mCAAmB,GAAE,CAAC;AAEtB,uCAAkB,CAAC,UAAU,EAAE,CAAC","sourcesContent":["import { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { ThreadSnapExecutor } from './ThreadSnapExecutor';\n\n// Lockdown is already applied in LavaMoat\nexecuteLockdownMore();\n\nThreadSnapExecutor.initialize();\n"]}
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const post_message_stream_1 = require("@metamask/post-message-stream");
4
- const lockdown_1 = require("../common/lockdown/lockdown");
4
+ const lockdown_events_1 = require("../common/lockdown/lockdown-events");
5
5
  const lockdown_more_1 = require("../common/lockdown/lockdown-more");
6
6
  const OffscreenSnapExecutor_1 = require("./OffscreenSnapExecutor");
7
- (0, lockdown_1.executeLockdown)();
7
+ // Lockdown is already applied in LavaMoat
8
8
  (0, lockdown_more_1.executeLockdownMore)();
9
+ (0, lockdown_events_1.executeLockdownEvents)();
9
10
  // The stream from the offscreen document to the execution service.
10
11
  const parentStream = new post_message_stream_1.BrowserRuntimePostMessageStream({
11
12
  name: 'child',
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/offscreen/index.ts"],"names":[],"mappings":";;AAAA,uEAAgF;AAEhF,0DAA8D;AAC9D,oEAAuE;AACvE,mEAAgE;AAEhE,IAAA,0BAAe,GAAE,CAAC;AAClB,IAAA,mCAAmB,GAAE,CAAC;AAEtB,mEAAmE;AACnE,MAAM,YAAY,GAAG,IAAI,qDAA+B,CAAC;IACvD,IAAI,EAAE,OAAO;IACb,MAAM,EAAE,QAAQ;CACjB,CAAC,CAAC;AAEH,6CAAqB,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC","sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport { executeLockdown } from '../common/lockdown/lockdown';\nimport { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { OffscreenSnapExecutor } from './OffscreenSnapExecutor';\n\nexecuteLockdown();\nexecuteLockdownMore();\n\n// The stream from the offscreen document to the execution service.\nconst parentStream = new BrowserRuntimePostMessageStream({\n name: 'child',\n target: 'parent',\n});\n\nOffscreenSnapExecutor.initialize(parentStream);\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/offscreen/index.ts"],"names":[],"mappings":";;AAAA,uEAAgF;AAEhF,wEAA2E;AAC3E,oEAAuE;AACvE,mEAAgE;AAEhE,0CAA0C;AAC1C,IAAA,mCAAmB,GAAE,CAAC;AACtB,IAAA,uCAAqB,GAAE,CAAC;AAExB,mEAAmE;AACnE,MAAM,YAAY,GAAG,IAAI,qDAA+B,CAAC;IACvD,IAAI,EAAE,OAAO;IACb,MAAM,EAAE,QAAQ;CACjB,CAAC,CAAC;AAEH,6CAAqB,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC","sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport { executeLockdownEvents } from '../common/lockdown/lockdown-events';\nimport { executeLockdownMore } from '../common/lockdown/lockdown-more';\nimport { OffscreenSnapExecutor } from './OffscreenSnapExecutor';\n\n// Lockdown is already applied in LavaMoat\nexecuteLockdownMore();\nexecuteLockdownEvents();\n\n// The stream from the offscreen document to the execution service.\nconst parentStream = new BrowserRuntimePostMessageStream({\n name: 'child',\n target: 'parent',\n});\n\nOffscreenSnapExecutor.initialize(parentStream);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-execution-environments",
3
- "version": "0.31.0",
3
+ "version": "0.32.1",
4
4
  "description": "Snap sandbox environments for executing SES javascript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,11 +24,12 @@
24
24
  "lint": "yarn lint:eslint && yarn lint:misc --check",
25
25
  "clean": "rimraf '*.tsbuildinfo' 'dist/*' 'src/__GENERATED__/' 'coverage/*' '__test__/*'",
26
26
  "build:clean": "yarn clean && yarn build",
27
- "build:post-tsc": "webpack --mode none && yarn build:concat",
27
+ "build:post-tsc": "yarn build:lavamoat",
28
28
  "build:tsc": "tsc --project tsconfig.build.json",
29
29
  "build": "yarn build:tsc && yarn build:post-tsc",
30
- "build:test": "cross-env NODE_ENV=test webpack --mode none && yarn build:concat",
31
- "build:concat": "concat -o ./dist/webpack/node-process/bundle.js ./dist/webpack/node-process/lockdown.umd.min.js ./dist/webpack/node-process/bundle.js && concat -o ./dist/webpack/node-thread/bundle.js ./dist/webpack/node-thread/lockdown.umd.min.js ./dist/webpack/node-thread/bundle.js",
30
+ "build:test": "yarn build:lavamoat",
31
+ "build:lavamoat": "lavamoat scripts/build.js --policy lavamoat/build-system/policy.json --policyOverride lavamoat/build-system/policy-override.json",
32
+ "build:lavamoat:policy": "yarn build:lavamoat --writeAutoPolicy && node scripts/build.js --writeAutoPolicy",
32
33
  "auto-changelog-init": "auto-changelog init",
33
34
  "prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh",
34
35
  "publish:preview": "yarn npm publish --tag preview",
@@ -36,10 +37,10 @@
36
37
  },
37
38
  "dependencies": {
38
39
  "@metamask/object-multiplex": "^1.2.0",
39
- "@metamask/post-message-stream": "^6.1.0",
40
+ "@metamask/post-message-stream": "^6.1.1",
40
41
  "@metamask/providers": "^10.2.0",
41
- "@metamask/rpc-methods": "^0.31.0",
42
- "@metamask/snaps-utils": "^0.31.0",
42
+ "@metamask/rpc-methods": "^0.32.1",
43
+ "@metamask/snaps-utils": "^0.32.1",
43
44
  "@metamask/utils": "^5.0.0",
44
45
  "eth-rpc-errors": "^4.0.3",
45
46
  "json-rpc-engine": "^6.1.0",
@@ -50,10 +51,13 @@
50
51
  },
51
52
  "devDependencies": {
52
53
  "@babel/core": "^7.20.12",
54
+ "@babel/preset-env": "^7.20.2",
53
55
  "@babel/preset-typescript": "^7.18.6",
56
+ "@browserify/uglifyify": "^6.0.0",
54
57
  "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
55
58
  "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
56
59
  "@lavamoat/allow-scripts": "^2.0.3",
60
+ "@lavamoat/lavapack": "^3.3.0",
57
61
  "@lavamoat/lavatube": "^0.0.1",
58
62
  "@metamask/auto-changelog": "^3.1.0",
59
63
  "@metamask/eslint-config": "^11.0.0",
@@ -71,10 +75,11 @@
71
75
  "@wdio/spec-reporter": "^8.3.0",
72
76
  "@wdio/static-server-service": "^8.3.0",
73
77
  "babel-loader": "^9.1.2",
78
+ "babel-plugin-tsconfig-paths-module-resolver": "^1.0.4",
79
+ "babelify": "^10.0.0",
80
+ "browserify": "^17.0.0",
74
81
  "buffer": "^6.0.3",
75
- "concat": "^1.0.3",
76
- "copy-webpack-plugin": "^10.2.4",
77
- "cross-env": "^7.0.3",
82
+ "common-shakeify": "^1.1.2",
78
83
  "deepmerge": "^4.2.2",
79
84
  "eslint": "^8.27.0",
80
85
  "eslint-config-prettier": "^8.5.0",
@@ -84,33 +89,28 @@
84
89
  "eslint-plugin-node": "^11.1.0",
85
90
  "eslint-plugin-prettier": "^4.2.1",
86
91
  "expect-webdriverio": "^4.1.2",
87
- "html-inline-script-webpack-plugin": "^3.1.0",
88
- "html-webpack-plugin": "^5.5.0",
89
92
  "istanbul-lib-coverage": "^3.2.0",
90
93
  "istanbul-lib-report": "^3.0.0",
91
94
  "istanbul-reports": "^3.1.5",
92
95
  "jest": "^29.0.2",
93
96
  "jest-fetch-mock": "^3.0.3",
97
+ "lavamoat": "^6.4.0",
98
+ "lavamoat-browserify": "^15.5.0",
94
99
  "memfs": "^3.4.13",
95
100
  "prettier": "^2.7.1",
96
101
  "prettier-plugin-packagejson": "^2.2.11",
97
102
  "process": "^0.11.10",
98
103
  "rimraf": "^4.1.2",
99
- "terser-webpack-plugin": "^5.3.6",
100
104
  "ts-jest": "^29.0.0",
101
105
  "ts-node": "^10.9.1",
102
106
  "tsconfig-paths": "^4.1.2",
103
- "tsconfig-paths-webpack-plugin": "^4.0.0",
104
107
  "typescript": "~4.8.4",
105
108
  "vite": "^4.1.4",
106
109
  "vite-tsconfig-paths": "^4.0.5",
107
110
  "wdio-chromedriver-service": "^8.1.1",
108
111
  "wdio-geckodriver-service": "^4.1.0",
109
112
  "webdriverio": "^8.3.10",
110
- "webpack": "^5.68.0",
111
- "webpack-cli": "^4.9.2",
112
- "webpack-merge": "^5.8.0",
113
- "webpackbar": "^5.0.2"
113
+ "yargs": "^17.7.1"
114
114
  },
115
115
  "engines": {
116
116
  "node": ">=16.0.0"