@metamask/snaps-execution-environments 9.1.0 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,4 +7,6 @@
7
7
 
8
8
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
9
9
 
10
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
11
+
10
12
  /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -1,4 +1,4 @@
1
- <!doctype html><html><head><meta charset="utf-8"/><title>MetaMask Snaps Execution Environment</title><script>// ses@1.13.0
1
+ <!doctype html><html><head><meta charset="utf-8"/><title>MetaMask Snaps Execution Environment</title><script>// ses@1.13.1
2
2
  (functors => options => {
3
3
  'use strict';
4
4
 
@@ -2088,9 +2088,11 @@ freeze(makeEnvironmentCaptor);
2088
2088
  // === 4. immutable-arraybuffer ./index.js ===
2089
2089
  ({imports:$h͏_imports,liveVar:$h͏_live,onceVar:$h͏_once,import:$h͏_import,importMeta:$h͏____meta})=>(function(){'use strict';$h͏_imports([]);/* global globalThis */
2090
2090
 
2091
- const { setPrototypeOf, getOwnPropertyDescriptors } = Object;
2091
+ const { setPrototypeOf, getOwnPropertyDescriptors, defineProperties } = Object;
2092
2092
  const { apply } = Reflect;
2093
2093
  const { prototype: arrayBufferPrototype } = ArrayBuffer;
2094
+ // Capture structuredClone before it could be scuttled.
2095
+ const { structuredClone: originalStructuredCloneMaybe } = globalThis;
2094
2096
 
2095
2097
  const {
2096
2098
  slice,
@@ -2126,12 +2128,14 @@ let arrayBufferTransfer;
2126
2128
 
2127
2129
  if (transfer) {
2128
2130
  arrayBufferTransfer = arrayBuffer => apply(transfer, arrayBuffer, []);
2129
- } else if (globalThis.structuredClone) {
2131
+ } else if (originalStructuredCloneMaybe) {
2130
2132
  arrayBufferTransfer = arrayBuffer => {
2131
2133
  // Hopefully, a zero-length slice is cheap, but still enforces that
2132
2134
  // `arrayBuffer` is a genuine `ArrayBuffer` exotic object.
2133
2135
  arrayBufferSlice(arrayBuffer, 0, 0);
2134
- return globalThis.structuredClone(arrayBuffer, { transfer: [arrayBuffer] });
2136
+ return originalStructuredCloneMaybe(arrayBuffer, {
2137
+ transfer: [arrayBuffer],
2138
+ });
2135
2139
  };
2136
2140
  } else {
2137
2141
  // Indeed, Node <= 16 has neither.
@@ -2230,6 +2234,16 @@ const {
2230
2234
 
2231
2235
  setPrototypeOf(immutableArrayBufferPrototype, arrayBufferPrototype);
2232
2236
 
2237
+ // See https://github.com/endojs/endo/tree/master/packages/immutable-arraybuffer#purposeful-violation
2238
+ defineProperties(immutableArrayBufferPrototype, {
2239
+ [Symbol.toStringTag]: {
2240
+ value: 'ImmutableArrayBuffer',
2241
+ writable: false,
2242
+ enumerable: false,
2243
+ configurable: true,
2244
+ },
2245
+ });
2246
+
2233
2247
  /**
2234
2248
  * Transfer the contents to a new Immutable ArrayBuffer
2235
2249
  *
@@ -5335,6 +5349,8 @@ const CommonMath = {
5335
5349
  '[[Proto]]': '%ArrayBufferPrototype%',
5336
5350
  byteLength: getter,
5337
5351
  slice: fn,
5352
+ // See https://github.com/endojs/endo/tree/master/packages/immutable-arraybuffer#purposeful-violation
5353
+ '@@toStringTag': 'string',
5338
5354
  // See https://github.com/tc39/proposal-resizablearraybuffer
5339
5355
  transfer: fn,
5340
5356
  resize: fn,
@@ -11835,18 +11851,49 @@ function validateModuleSource(moduleSource, moduleSpecifier) {
11835
11851
 
11836
11852
 
11837
11853
 
11854
+ /**
11855
+ * @import {ImportHook, ImportMetaHook, ImportNowHook, ModuleDescriptor, ModuleExportsNamespace, ModuleMap, ModuleMapHook, ResolveHook, ModuleSource, CompartmentOptions} from '../types.js'
11856
+ * @import {Transform} from './lockdown.js'
11857
+ * @import {DeferredExports} from './module-proxy.js'
11858
+ */
11838
11859
 
11839
- /** @import {ModuleDescriptor, ModuleExportsNamespace} from '../types.js' */
11840
-
11841
- // moduleAliases associates every public module exports namespace with its
11842
- // corresponding compartment and specifier so they can be used to link modules
11843
- // across compartments.
11844
- // The mechanism to thread an alias is to use the compartment.module function
11845
- // to obtain the exports namespace of a foreign module and pass it into another
11846
- // compartment's moduleMap constructor option.
11860
+ /**
11861
+ * Associates every public module exports namespace with its corresponding
11862
+ * compartment and specifier so they can be used to link modules across
11863
+ * compartments. The mechanism to thread an alias is to use the
11864
+ * {@link Compartment.module} function to obtain the exports namespace of a foreign
11865
+ * module and pass it into another compartment's `moduleMap` constructor option
11866
+ * @type {WeakMap<ModuleExportsNamespace, Compartment>}
11867
+ *
11868
+ */
11847
11869
  const moduleAliases = new WeakMap();
11848
11870
 
11849
- // privateFields captures the private state for each compartment.
11871
+ /**
11872
+ * Private fields for `Compartment` instances
11873
+ * @typedef {object} CompartmentFields
11874
+ * @property {string} name
11875
+ * @property {object} globalObject
11876
+ * @property {Array<Transform>} globalTransforms
11877
+ * @property {(source: string, options?: {localTransforms?: Array<Transform>}) => void} safeEvaluate
11878
+ * @property {ResolveHook} resolveHook
11879
+ * @property {ImportHook} importHook
11880
+ * @property {ImportNowHook} importNowHook
11881
+ * @property {ModuleMap} moduleMap
11882
+ * @property {ModuleMapHook} moduleMapHook
11883
+ * @property {ImportMetaHook} importMetaHook
11884
+ * @property {Map<string, ModuleSource>} moduleRecords
11885
+ * @property {Array<Transform>} __shimTransforms__
11886
+ * @property {DeferredExports} deferredExports
11887
+ * @property {Map<string, ModuleDescriptor>} instances
11888
+ * @property {Compartment} [parentCompartment]
11889
+ * @property {boolean} noNamespaceBox
11890
+ * @property {(fullSpecifier: string) => Promise<ModuleExportsNamespace>} compartmentImport
11891
+ */
11892
+
11893
+ /**
11894
+ * Captures the private state for each {@link Compartment}
11895
+ * @type {WeakMap<Compartment, CompartmentFields>}
11896
+ */
11850
11897
  const privateFields = new WeakMap();
11851
11898
 
11852
11899
  const InertCompartment = function Compartment(
@@ -11862,6 +11909,7 @@ const privateFields = new WeakMap();
11862
11909
  /**
11863
11910
  * @param {Compartment} compartment
11864
11911
  * @param {string} specifier
11912
+ * @returns {{namespace: ModuleExportsNamespace}}
11865
11913
  */$h͏_once.InertCompartment(InertCompartment);
11866
11914
  const compartmentImportNow = (compartment, specifier) => {
11867
11915
  const { execute, exportsProxy } = link(
@@ -11874,27 +11922,20 @@ const compartmentImportNow = (compartment, specifier) => {
11874
11922
  return exportsProxy;
11875
11923
  };
11876
11924
 
11925
+ /** @type {Compartment & {constructor: typeof InertCompartment}} */
11877
11926
  const CompartmentPrototype = {
11878
11927
  constructor: InertCompartment,
11879
11928
 
11880
11929
  get globalThis() {
11881
- return weakmapGet(privateFields, this).globalObject;
11930
+ return /** @type {CompartmentFields} */ (weakmapGet(privateFields, this))
11931
+ .globalObject;
11882
11932
  },
11883
11933
 
11884
11934
  get name() {
11885
- return weakmapGet(privateFields, this).name;
11935
+ return /** @type {CompartmentFields} */ (weakmapGet(privateFields, this))
11936
+ .name;
11886
11937
  },
11887
11938
 
11888
- /**
11889
- * @param {string} source is a JavaScript program grammar construction.
11890
- * @param {object} [options]
11891
- * @param {Array<import('./lockdown-shim').Transform>} [options.transforms]
11892
- * @param {boolean} [options.sloppyGlobalsMode]
11893
- * @param {object} [options.__moduleShimLexicals__]
11894
- * @param {boolean} [options.__evadeHtmlCommentTest__]
11895
- * @param {boolean} [options.__evadeImportExpressionTest__]
11896
- * @param {boolean} [options.__rejectSomeDirectEvalExpressions__]
11897
- */
11898
11939
  evaluate(source, options = {}) {
11899
11940
  const compartmentFields = weakmapGet(privateFields, this);
11900
11941
  return compartmentEvaluate(compartmentFields, source, options);
@@ -11916,7 +11957,9 @@ const compartmentImportNow = (compartment, specifier) => {
11916
11957
  },
11917
11958
 
11918
11959
  async import(specifier) {
11919
- const { noNamespaceBox } = weakmapGet(privateFields, this);
11960
+ const { noNamespaceBox } = /** @type {CompartmentFields} */ (
11961
+ weakmapGet(privateFields, this)
11962
+ );
11920
11963
 
11921
11964
  if (typeof specifier !== 'string') {
11922
11965
  throw TypeError('first argument of import() must be a string');
@@ -11955,7 +11998,7 @@ const compartmentImportNow = (compartment, specifier) => {
11955
11998
  }
11956
11999
 
11957
12000
  loadNow(privateFields, moduleAliases, this, specifier);
11958
- return compartmentImportNow(/** @type {Compartment} */ (this), specifier);
12001
+ return compartmentImportNow(this, specifier);
11959
12002
  },
11960
12003
  };
11961
12004
 
@@ -11986,15 +12029,35 @@ defineProperties(InertCompartment, {
11986
12029
  * @returns {Compartment['constructor']}
11987
12030
  */
11988
12031
 
11989
- // In order to facilitate migration from the deprecated signature
11990
- // of the compartment constructor,
11991
- // new Compartent(globals?, modules?, options?)
11992
- // to the new signature:
11993
- // new Compartment(options?)
11994
- // where globals and modules are expressed in the options bag instead of
11995
- // positional arguments, this function detects the temporary sigil __options__
11996
- // on the first argument and coerces compartments arguments into a single
11997
- // compartments object.
12032
+ /**
12033
+ * "Options bag"-style `Compartment` constructor arguments.
12034
+ * @typedef {[options?: CompartmentOptions & { __options__: true }]} CompartmentOptionsArgs
12035
+ */
12036
+
12037
+ /**
12038
+ * Legacy `Compartment` constructor arguments.
12039
+ *
12040
+ * @deprecated
12041
+ * @typedef {[globals?: Map<string, any>, modules?: Map<string, ModuleDescriptor>, options?: CompartmentOptions]} LegacyCompartmentOptionsArgs
12042
+ */
12043
+
12044
+ /**
12045
+ * In order to facilitate migration from the deprecated signature of the
12046
+ * compartment constructor,
12047
+ *
12048
+ * `new Compartent(globals?, modules?, options?)`
12049
+ *
12050
+ * to the new signature:
12051
+ *
12052
+ * `new Compartment(options?)`
12053
+ *
12054
+ * ...where globals and modules are expressed in the options bag instead of
12055
+ * positional arguments, this function detects the temporary sigil __options__
12056
+ * on the first argument and coerces compartments arguments into a single
12057
+ * compartments object.
12058
+ * @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
12059
+ * @returns {CompartmentOptions}
12060
+ */
11998
12061
  const compartmentOptions = (...args) => {
11999
12062
  if (args.length === 0) {
12000
12063
  return {};
@@ -12016,7 +12079,7 @@ defineProperties(InertCompartment, {
12016
12079
  globals = /** @type {Map<string, any>} */ ({}),
12017
12080
  modules = /** @type {Map<string, ModuleDescriptor>} */ ({}),
12018
12081
  options = {},
12019
- ] = args;
12082
+ ] = /** @type {LegacyCompartmentOptionsArgs} */ (args);
12020
12083
  assertEqual(
12021
12084
  options.modules,
12022
12085
  undefined,
@@ -12042,6 +12105,10 @@ defineProperties(InertCompartment, {
12042
12105
  markVirtualizedNativeFunction,
12043
12106
  { parentCompartment = undefined, enforceNew = false } = {},
12044
12107
  ) => {
12108
+ /**
12109
+ *
12110
+ * @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
12111
+ */
12045
12112
  function Compartment(...args) {
12046
12113
  if (enforceNew && new.target === undefined) {
12047
12114
  throw TypeError(