@metamask/snaps-execution-environments 0.34.1-flask.1 → 0.35.0-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.
Files changed (243) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/cjs/common/BaseSnapExecutor.js +415 -0
  3. package/dist/cjs/common/BaseSnapExecutor.js.map +1 -0
  4. package/dist/cjs/common/commands.js +65 -0
  5. package/dist/cjs/common/commands.js.map +1 -0
  6. package/dist/cjs/common/endowments/commonEndowmentFactory.js +147 -0
  7. package/dist/cjs/common/endowments/commonEndowmentFactory.js.map +1 -0
  8. package/dist/cjs/common/endowments/console.js +134 -0
  9. package/dist/cjs/common/endowments/console.js.map +1 -0
  10. package/dist/cjs/common/endowments/crypto.js +44 -0
  11. package/dist/cjs/common/endowments/crypto.js.map +1 -0
  12. package/dist/cjs/common/endowments/date.js +53 -0
  13. package/dist/cjs/common/endowments/date.js.map +1 -0
  14. package/dist/cjs/common/endowments/index.js +91 -0
  15. package/dist/cjs/common/endowments/index.js.map +1 -0
  16. package/dist/cjs/common/endowments/interval.js +61 -0
  17. package/dist/cjs/common/endowments/interval.js.map +1 -0
  18. package/dist/cjs/common/endowments/math.js +67 -0
  19. package/dist/cjs/common/endowments/math.js.map +1 -0
  20. package/dist/cjs/common/endowments/network.js +206 -0
  21. package/dist/cjs/common/endowments/network.js.map +1 -0
  22. package/dist/cjs/common/endowments/textDecoder.js +28 -0
  23. package/dist/cjs/common/endowments/textDecoder.js.map +1 -0
  24. package/dist/cjs/common/endowments/textEncoder.js +28 -0
  25. package/dist/cjs/common/endowments/textEncoder.js.map +1 -0
  26. package/dist/cjs/common/endowments/timeout.js +63 -0
  27. package/dist/cjs/common/endowments/timeout.js.map +1 -0
  28. package/dist/cjs/common/globalEvents.js +39 -0
  29. package/dist/cjs/common/globalEvents.js.map +1 -0
  30. package/dist/cjs/common/globalObject.js +53 -0
  31. package/dist/{common → cjs/common}/globalObject.js.map +1 -1
  32. package/dist/cjs/common/lockdown/lockdown-events.js +74 -0
  33. package/dist/cjs/common/lockdown/lockdown-events.js.map +1 -0
  34. package/dist/cjs/common/lockdown/lockdown-more.js +73 -0
  35. package/dist/cjs/common/lockdown/lockdown-more.js.map +1 -0
  36. package/dist/cjs/common/lockdown/lockdown.js +30 -0
  37. package/dist/cjs/common/lockdown/lockdown.js.map +1 -0
  38. package/dist/cjs/common/sortParams.js +26 -0
  39. package/dist/cjs/common/sortParams.js.map +1 -0
  40. package/dist/cjs/common/utils.js +116 -0
  41. package/dist/cjs/common/utils.js.map +1 -0
  42. package/dist/cjs/common/validation.js +114 -0
  43. package/dist/cjs/common/validation.js.map +1 -0
  44. package/dist/cjs/iframe/IFrameSnapExecutor.js +50 -0
  45. package/dist/cjs/iframe/IFrameSnapExecutor.js.map +1 -0
  46. package/dist/cjs/iframe/index.js +13 -0
  47. package/dist/cjs/iframe/index.js.map +1 -0
  48. package/dist/cjs/logging.js +15 -0
  49. package/dist/cjs/logging.js.map +1 -0
  50. package/dist/cjs/node-process/ChildProcessSnapExecutor.js +39 -0
  51. package/dist/cjs/node-process/ChildProcessSnapExecutor.js.map +1 -0
  52. package/dist/cjs/node-process/index.js +11 -0
  53. package/dist/cjs/node-process/index.js.map +1 -0
  54. package/dist/cjs/node-thread/ThreadSnapExecutor.js +39 -0
  55. package/dist/cjs/node-thread/ThreadSnapExecutor.js.map +1 -0
  56. package/dist/cjs/node-thread/index.js +11 -0
  57. package/dist/cjs/node-thread/index.js.map +1 -0
  58. package/dist/cjs/offscreen/OffscreenSnapExecutor.js +173 -0
  59. package/dist/cjs/offscreen/OffscreenSnapExecutor.js.map +1 -0
  60. package/dist/cjs/offscreen/index.js +19 -0
  61. package/dist/cjs/offscreen/index.js.map +1 -0
  62. package/dist/cjs/webworker/executor/WebWorkerSnapExecutor.js +45 -0
  63. package/dist/cjs/webworker/executor/WebWorkerSnapExecutor.js.map +1 -0
  64. package/dist/cjs/webworker/executor/index.js +13 -0
  65. package/dist/cjs/webworker/executor/index.js.map +1 -0
  66. package/dist/cjs/webworker/pool/WebWorkerPool.js +248 -0
  67. package/dist/cjs/webworker/pool/WebWorkerPool.js.map +1 -0
  68. package/dist/cjs/webworker/pool/index.js +13 -0
  69. package/dist/cjs/webworker/pool/index.js.map +1 -0
  70. package/dist/esm/common/BaseSnapExecutor.js +400 -0
  71. package/dist/esm/common/BaseSnapExecutor.js.map +1 -0
  72. package/dist/esm/common/commands.js +64 -0
  73. package/dist/esm/common/commands.js.map +1 -0
  74. package/dist/esm/common/endowments/commonEndowmentFactory.js +132 -0
  75. package/dist/esm/common/endowments/commonEndowmentFactory.js.map +1 -0
  76. package/dist/{common → esm/common}/endowments/console.js +46 -33
  77. package/dist/esm/common/endowments/console.js.map +1 -0
  78. package/dist/esm/common/endowments/crypto.js +26 -0
  79. package/dist/esm/common/endowments/crypto.js.map +1 -0
  80. package/dist/{common → esm/common}/endowments/date.js +20 -16
  81. package/dist/esm/common/endowments/date.js.map +1 -0
  82. package/dist/{common → esm/common}/endowments/index.js +33 -35
  83. package/dist/esm/common/endowments/index.js.map +1 -0
  84. package/dist/{common → esm/common}/endowments/interval.js +13 -12
  85. package/dist/esm/common/endowments/interval.js.map +1 -0
  86. package/dist/{common → esm/common}/endowments/math.js +19 -16
  87. package/dist/esm/common/endowments/math.js.map +1 -0
  88. package/dist/esm/common/endowments/network.js +196 -0
  89. package/dist/esm/common/endowments/network.js.map +1 -0
  90. package/dist/esm/common/endowments/textDecoder.js +18 -0
  91. package/dist/esm/common/endowments/textDecoder.js.map +1 -0
  92. package/dist/esm/common/endowments/textEncoder.js +18 -0
  93. package/dist/esm/common/endowments/textEncoder.js.map +1 -0
  94. package/dist/{common → esm/common}/endowments/timeout.js +14 -13
  95. package/dist/esm/common/endowments/timeout.js.map +1 -0
  96. package/dist/esm/common/globalEvents.js +35 -0
  97. package/dist/esm/common/globalEvents.js.map +1 -0
  98. package/dist/esm/common/globalObject.js +36 -0
  99. package/dist/esm/common/globalObject.js.map +1 -0
  100. package/dist/esm/common/lockdown/lockdown-events.js +66 -0
  101. package/dist/esm/common/lockdown/lockdown-events.js.map +1 -0
  102. package/dist/{common → esm/common}/lockdown/lockdown-more.js +15 -22
  103. package/dist/esm/common/lockdown/lockdown-more.js.map +1 -0
  104. package/dist/{common → esm/common}/lockdown/lockdown.js +6 -11
  105. package/dist/esm/common/lockdown/lockdown.js.map +1 -0
  106. package/dist/{common → esm/common}/sortParams.js +7 -13
  107. package/dist/esm/common/sortParams.js.map +1 -0
  108. package/dist/esm/common/utils.js +120 -0
  109. package/dist/esm/common/utils.js.map +1 -0
  110. package/dist/esm/common/validation.js +92 -0
  111. package/dist/esm/common/validation.js.map +1 -0
  112. package/dist/esm/iframe/IFrameSnapExecutor.js +35 -0
  113. package/dist/esm/iframe/IFrameSnapExecutor.js.map +1 -0
  114. package/dist/esm/iframe/index.js +9 -0
  115. package/dist/esm/iframe/index.js.map +1 -0
  116. package/dist/esm/logging.js +10 -0
  117. package/dist/esm/logging.js.map +1 -0
  118. package/dist/esm/node-process/ChildProcessSnapExecutor.js +24 -0
  119. package/dist/esm/node-process/ChildProcessSnapExecutor.js.map +1 -0
  120. package/dist/esm/node-process/index.js +7 -0
  121. package/dist/esm/node-process/index.js.map +1 -0
  122. package/dist/esm/node-thread/ThreadSnapExecutor.js +24 -0
  123. package/dist/esm/node-thread/ThreadSnapExecutor.js.map +1 -0
  124. package/dist/esm/node-thread/index.js +7 -0
  125. package/dist/esm/node-thread/index.js.map +1 -0
  126. package/dist/esm/offscreen/OffscreenSnapExecutor.js +176 -0
  127. package/dist/esm/offscreen/OffscreenSnapExecutor.js.map +1 -0
  128. package/dist/esm/offscreen/index.js +15 -0
  129. package/dist/esm/offscreen/index.js.map +1 -0
  130. package/dist/esm/webworker/executor/WebWorkerSnapExecutor.js +30 -0
  131. package/dist/esm/webworker/executor/WebWorkerSnapExecutor.js.map +1 -0
  132. package/dist/esm/webworker/executor/index.js +9 -0
  133. package/dist/esm/webworker/executor/index.js.map +1 -0
  134. package/dist/esm/webworker/pool/WebWorkerPool.js +245 -0
  135. package/dist/esm/webworker/pool/WebWorkerPool.js.map +1 -0
  136. package/dist/esm/webworker/pool/index.js +9 -0
  137. package/dist/esm/webworker/pool/index.js.map +1 -0
  138. package/package.json +58 -20
  139. package/dist/browserify/iframe/bundle.js +0 -6421
  140. package/dist/browserify/iframe/index.html +0 -11660
  141. package/dist/browserify/node-process/bundle.js +0 -15545
  142. package/dist/browserify/node-thread/bundle.js +0 -15545
  143. package/dist/browserify/offscreen/bundle.js +0 -2478
  144. package/dist/browserify/offscreen/index.html +0 -11660
  145. package/dist/browserify/worker-executor/bundle.js +0 -18072
  146. package/dist/browserify/worker-pool/bundle.js +0 -2492
  147. package/dist/browserify/worker-pool/index.html +0 -11660
  148. package/dist/common/BaseSnapExecutor.js +0 -370
  149. package/dist/common/BaseSnapExecutor.js.map +0 -1
  150. package/dist/common/commands.js +0 -65
  151. package/dist/common/commands.js.map +0 -1
  152. package/dist/common/endowments/commonEndowmentFactory.js +0 -76
  153. package/dist/common/endowments/commonEndowmentFactory.js.map +0 -1
  154. package/dist/common/endowments/console.js.map +0 -1
  155. package/dist/common/endowments/crypto.js +0 -30
  156. package/dist/common/endowments/crypto.js.map +0 -1
  157. package/dist/common/endowments/date.js.map +0 -1
  158. package/dist/common/endowments/index.js.map +0 -1
  159. package/dist/common/endowments/interval.js.map +0 -1
  160. package/dist/common/endowments/math.js.map +0 -1
  161. package/dist/common/endowments/network.js +0 -170
  162. package/dist/common/endowments/network.js.map +0 -1
  163. package/dist/common/endowments/textDecoder.js +0 -18
  164. package/dist/common/endowments/textDecoder.js.map +0 -1
  165. package/dist/common/endowments/textEncoder.js +0 -18
  166. package/dist/common/endowments/textEncoder.js.map +0 -1
  167. package/dist/common/endowments/timeout.js.map +0 -1
  168. package/dist/common/globalEvents.js +0 -47
  169. package/dist/common/globalEvents.js.map +0 -1
  170. package/dist/common/globalObject.js +0 -50
  171. package/dist/common/keyring.d.ts +0 -12
  172. package/dist/common/keyring.js +0 -42
  173. package/dist/common/keyring.js.map +0 -1
  174. package/dist/common/lockdown/lockdown-events.js +0 -60
  175. package/dist/common/lockdown/lockdown-events.js.map +0 -1
  176. package/dist/common/lockdown/lockdown-more.js.map +0 -1
  177. package/dist/common/lockdown/lockdown.js.map +0 -1
  178. package/dist/common/sortParams.js.map +0 -1
  179. package/dist/common/utils.js +0 -133
  180. package/dist/common/utils.js.map +0 -1
  181. package/dist/common/validation.js +0 -109
  182. package/dist/common/validation.js.map +0 -1
  183. package/dist/iframe/IFrameSnapExecutor.js +0 -42
  184. package/dist/iframe/IFrameSnapExecutor.js.map +0 -1
  185. package/dist/iframe/index.js +0 -10
  186. package/dist/iframe/index.js.map +0 -1
  187. package/dist/logging.js +0 -13
  188. package/dist/logging.js.map +0 -1
  189. package/dist/node-process/ChildProcessSnapExecutor.js +0 -30
  190. package/dist/node-process/ChildProcessSnapExecutor.js.map +0 -1
  191. package/dist/node-process/index.js +0 -8
  192. package/dist/node-process/index.js.map +0 -1
  193. package/dist/node-thread/ThreadSnapExecutor.js +0 -30
  194. package/dist/node-thread/ThreadSnapExecutor.js.map +0 -1
  195. package/dist/node-thread/index.js +0 -8
  196. package/dist/node-thread/index.js.map +0 -1
  197. package/dist/offscreen/OffscreenSnapExecutor.js +0 -104
  198. package/dist/offscreen/OffscreenSnapExecutor.js.map +0 -1
  199. package/dist/offscreen/index.js +0 -16
  200. package/dist/offscreen/index.js.map +0 -1
  201. package/dist/openrpc.json +0 -210
  202. package/dist/webworker/executor/WebWorkerSnapExecutor.js +0 -37
  203. package/dist/webworker/executor/WebWorkerSnapExecutor.js.map +0 -1
  204. package/dist/webworker/executor/index.js +0 -10
  205. package/dist/webworker/executor/index.js.map +0 -1
  206. package/dist/webworker/pool/WebWorkerPool.js +0 -168
  207. package/dist/webworker/pool/WebWorkerPool.js.map +0 -1
  208. package/dist/webworker/pool/index.js +0 -10
  209. package/dist/webworker/pool/index.js.map +0 -1
  210. /package/dist/{common → types/common}/BaseSnapExecutor.d.ts +0 -0
  211. /package/dist/{common → types/common}/commands.d.ts +0 -0
  212. /package/dist/{common → types/common}/endowments/commonEndowmentFactory.d.ts +0 -0
  213. /package/dist/{common → types/common}/endowments/console.d.ts +0 -0
  214. /package/dist/{common → types/common}/endowments/crypto.d.ts +0 -0
  215. /package/dist/{common → types/common}/endowments/date.d.ts +0 -0
  216. /package/dist/{common → types/common}/endowments/index.d.ts +0 -0
  217. /package/dist/{common → types/common}/endowments/interval.d.ts +0 -0
  218. /package/dist/{common → types/common}/endowments/math.d.ts +0 -0
  219. /package/dist/{common → types/common}/endowments/network.d.ts +0 -0
  220. /package/dist/{common → types/common}/endowments/textDecoder.d.ts +0 -0
  221. /package/dist/{common → types/common}/endowments/textEncoder.d.ts +0 -0
  222. /package/dist/{common → types/common}/endowments/timeout.d.ts +0 -0
  223. /package/dist/{common → types/common}/globalEvents.d.ts +0 -0
  224. /package/dist/{common → types/common}/globalObject.d.ts +0 -0
  225. /package/dist/{common → types/common}/lockdown/lockdown-events.d.ts +0 -0
  226. /package/dist/{common → types/common}/lockdown/lockdown-more.d.ts +0 -0
  227. /package/dist/{common → types/common}/lockdown/lockdown.d.ts +0 -0
  228. /package/dist/{common → types/common}/sortParams.d.ts +0 -0
  229. /package/dist/{common → types/common}/utils.d.ts +0 -0
  230. /package/dist/{common → types/common}/validation.d.ts +0 -0
  231. /package/dist/{iframe → types/iframe}/IFrameSnapExecutor.d.ts +0 -0
  232. /package/dist/{iframe → types/iframe}/index.d.ts +0 -0
  233. /package/dist/{logging.d.ts → types/logging.d.ts} +0 -0
  234. /package/dist/{node-process → types/node-process}/ChildProcessSnapExecutor.d.ts +0 -0
  235. /package/dist/{node-process → types/node-process}/index.d.ts +0 -0
  236. /package/dist/{node-thread → types/node-thread}/ThreadSnapExecutor.d.ts +0 -0
  237. /package/dist/{node-thread → types/node-thread}/index.d.ts +0 -0
  238. /package/dist/{offscreen → types/offscreen}/OffscreenSnapExecutor.d.ts +0 -0
  239. /package/dist/{offscreen → types/offscreen}/index.d.ts +0 -0
  240. /package/dist/{webworker → types/webworker}/executor/WebWorkerSnapExecutor.d.ts +0 -0
  241. /package/dist/{webworker → types/webworker}/executor/index.d.ts +0 -0
  242. /package/dist/{webworker → types/webworker}/pool/WebWorkerPool.d.ts +0 -0
  243. /package/dist/{webworker → types/webworker}/pool/index.d.ts +0 -0
@@ -0,0 +1,196 @@
1
+ function _check_private_redeclaration(obj, privateCollection) {
2
+ if (privateCollection.has(obj)) {
3
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
4
+ }
5
+ }
6
+ function _class_apply_descriptor_get(receiver, descriptor) {
7
+ if (descriptor.get) {
8
+ return descriptor.get.call(receiver);
9
+ }
10
+ return descriptor.value;
11
+ }
12
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
13
+ if (descriptor.set) {
14
+ descriptor.set.call(receiver, value);
15
+ } else {
16
+ if (!descriptor.writable) {
17
+ throw new TypeError("attempted to set read only private field");
18
+ }
19
+ descriptor.value = value;
20
+ }
21
+ }
22
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
23
+ if (!privateMap.has(receiver)) {
24
+ throw new TypeError("attempted to " + action + " private field on non-instance");
25
+ }
26
+ return privateMap.get(receiver);
27
+ }
28
+ function _class_private_field_get(receiver, privateMap) {
29
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
30
+ return _class_apply_descriptor_get(receiver, descriptor);
31
+ }
32
+ function _class_private_field_init(obj, privateMap, value) {
33
+ _check_private_redeclaration(obj, privateMap);
34
+ privateMap.set(obj, value);
35
+ }
36
+ function _class_private_field_set(receiver, privateMap, value) {
37
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
38
+ _class_apply_descriptor_set(receiver, descriptor, value);
39
+ return value;
40
+ }
41
+ import { withTeardown } from '../utils';
42
+ var _teardownRef = /*#__PURE__*/ new WeakMap(), _ogResponse = /*#__PURE__*/ new WeakMap();
43
+ /**
44
+ * This class wraps a Response object.
45
+ * That way, a teardown process can stop any processes left.
46
+ */ class ResponseWrapper {
47
+ get body() {
48
+ return _class_private_field_get(this, _ogResponse).body;
49
+ }
50
+ get bodyUsed() {
51
+ return _class_private_field_get(this, _ogResponse).bodyUsed;
52
+ }
53
+ get headers() {
54
+ return _class_private_field_get(this, _ogResponse).headers;
55
+ }
56
+ get ok() {
57
+ return _class_private_field_get(this, _ogResponse).ok;
58
+ }
59
+ get redirected() {
60
+ return _class_private_field_get(this, _ogResponse).redirected;
61
+ }
62
+ get status() {
63
+ return _class_private_field_get(this, _ogResponse).status;
64
+ }
65
+ get statusText() {
66
+ return _class_private_field_get(this, _ogResponse).statusText;
67
+ }
68
+ get type() {
69
+ return _class_private_field_get(this, _ogResponse).type;
70
+ }
71
+ get url() {
72
+ return _class_private_field_get(this, _ogResponse).url;
73
+ }
74
+ async text() {
75
+ return withTeardown(_class_private_field_get(this, _ogResponse).text(), this);
76
+ }
77
+ async arrayBuffer() {
78
+ return withTeardown(_class_private_field_get(this, _ogResponse).arrayBuffer(), this);
79
+ }
80
+ async blob() {
81
+ return withTeardown(_class_private_field_get(this, _ogResponse).blob(), this);
82
+ }
83
+ clone() {
84
+ const newResponse = _class_private_field_get(this, _ogResponse).clone();
85
+ return new ResponseWrapper(newResponse, _class_private_field_get(this, _teardownRef));
86
+ }
87
+ async formData() {
88
+ return withTeardown(_class_private_field_get(this, _ogResponse).formData(), this);
89
+ }
90
+ async json() {
91
+ return withTeardown(_class_private_field_get(this, _ogResponse).json(), this);
92
+ }
93
+ constructor(ogResponse, teardownRef){
94
+ _class_private_field_init(this, _teardownRef, {
95
+ writable: true,
96
+ value: void 0
97
+ });
98
+ _class_private_field_init(this, _ogResponse, {
99
+ writable: true,
100
+ value: void 0
101
+ });
102
+ _class_private_field_set(this, _ogResponse, ogResponse);
103
+ _class_private_field_set(this, _teardownRef, teardownRef);
104
+ }
105
+ }
106
+ /**
107
+ * Create a network endowment, consisting of a `fetch` function.
108
+ * This allows us to provide a teardown function, so that we can cancel
109
+ * any pending requests, connections, streams, etc. that may be open when a snap
110
+ * is terminated.
111
+ *
112
+ * This wraps the original implementation of `fetch`,
113
+ * to ensure that a bad actor cannot get access to the original function, thus
114
+ * potentially preventing the network requests from being torn down.
115
+ *
116
+ * @returns An object containing a wrapped `fetch`
117
+ * function, as well as a teardown function.
118
+ */ const createNetwork = ()=>{
119
+ // Open fetch calls or open body streams
120
+ const openConnections = new Set();
121
+ // Track last teardown count
122
+ const teardownRef = {
123
+ lastTeardown: 0
124
+ };
125
+ // Remove items from openConnections after they were garbage collected
126
+ const cleanup = new FinalizationRegistry(/* istanbul ignore next: can't test garbage collection without modifying node parameters */ (callback)=>callback());
127
+ const _fetch = async (input, init)=>{
128
+ const abortController = new AbortController();
129
+ if (init?.signal !== null && init?.signal !== undefined) {
130
+ const originalSignal = init.signal;
131
+ // Merge abort controllers
132
+ originalSignal.addEventListener('abort', ()=>{
133
+ abortController.abort(originalSignal.reason);
134
+ }, {
135
+ once: true
136
+ });
137
+ }
138
+ let res;
139
+ let openFetchConnection;
140
+ try {
141
+ const fetchPromise = fetch(input, {
142
+ ...init,
143
+ signal: abortController.signal
144
+ });
145
+ openFetchConnection = {
146
+ cancel: async ()=>{
147
+ abortController.abort();
148
+ try {
149
+ await fetchPromise;
150
+ } catch {
151
+ /* do nothing */ }
152
+ }
153
+ };
154
+ openConnections.add(openFetchConnection);
155
+ res = new ResponseWrapper(await withTeardown(fetchPromise, teardownRef), teardownRef);
156
+ } finally{
157
+ if (openFetchConnection !== undefined) {
158
+ openConnections.delete(openFetchConnection);
159
+ }
160
+ }
161
+ if (res.body !== null) {
162
+ const body = new WeakRef(res.body);
163
+ const openBodyConnection = {
164
+ cancel: /* istanbul ignore next: see it.todo('can be torn down during body read') test */ async ()=>{
165
+ try {
166
+ await body.deref()?.cancel();
167
+ } catch {
168
+ /* do nothing */ }
169
+ }
170
+ };
171
+ openConnections.add(openBodyConnection);
172
+ cleanup.register(res.body, /* istanbul ignore next: can't test garbage collection without modifying node parameters */ ()=>openConnections.delete(openBodyConnection));
173
+ }
174
+ return harden(res);
175
+ };
176
+ const teardownFunction = async ()=>{
177
+ teardownRef.lastTeardown += 1;
178
+ const promises = [];
179
+ openConnections.forEach(({ cancel })=>promises.push(cancel()));
180
+ openConnections.clear();
181
+ await Promise.all(promises);
182
+ };
183
+ return {
184
+ fetch: harden(_fetch),
185
+ teardownFunction
186
+ };
187
+ };
188
+ const endowmentModule = {
189
+ names: [
190
+ 'fetch'
191
+ ],
192
+ factory: createNetwork
193
+ };
194
+ export default endowmentModule;
195
+
196
+ //# 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":["withTeardown","ResponseWrapper","body","ogResponse","bodyUsed","headers","ok","redirected","status","statusText","type","url","text","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,18 @@
1
+ /**
2
+ * Creates TextDecoder function hardened by SES.
3
+ *
4
+ * @returns An object with the attenuated `TextDecoder` function.
5
+ */ const createTextDecoder = ()=>{
6
+ return {
7
+ TextDecoder: harden(TextDecoder)
8
+ };
9
+ };
10
+ const endowmentModule = {
11
+ names: [
12
+ 'TextDecoder'
13
+ ],
14
+ factory: createTextDecoder
15
+ };
16
+ export default endowmentModule;
17
+
18
+ //# 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,GACD,MAAMA,oBAAoB;IACxB,OAAO;QACLC,aAAaC,OAAOD;IACtB;AACF;AAEA,MAAME,kBAAkB;IACtBC,OAAO;QAAC;KAAc;IACtBC,SAASL;AACX;AACA,eAAeG,gBAAgB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Creates TextEncoder function hardened by SES.
3
+ *
4
+ * @returns An object with the attenuated `TextEncoder` function.
5
+ */ const createTextEncoder = ()=>{
6
+ return {
7
+ TextEncoder: harden(TextEncoder)
8
+ };
9
+ };
10
+ const endowmentModule = {
11
+ names: [
12
+ 'TextEncoder'
13
+ ],
14
+ factory: createTextEncoder
15
+ };
16
+ export default endowmentModule;
17
+
18
+ //# 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,GACD,MAAMA,oBAAoB;IACxB,OAAO;QACLC,aAAaC,OAAOD;IACtB;AACF;AAEA,MAAME,kBAAkB;IACtBC,OAAO;QAAC;KAAc;IACtBC,SAASL;AACX;AACA,eAAeG,gBAAgB"}
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  const MINIMUM_TIMEOUT = 10;
4
2
  /**
5
3
  * Creates a pair of `setTimeout` and `clearTimeout` functions attenuated such
@@ -10,43 +8,46 @@ const MINIMUM_TIMEOUT = 10;
10
8
  *
11
9
  * @returns An object with the attenuated `setTimeout` and `clearTimeout`
12
10
  * functions.
13
- */
14
- const createTimeout = () => {
11
+ */ const createTimeout = ()=>{
15
12
  const registeredHandles = new Map();
16
- const _setTimeout = (handler, timeout) => {
13
+ const _setTimeout = (handler, timeout)=>{
17
14
  if (typeof handler !== 'function') {
18
15
  throw new Error(`The timeout handler must be a function. Received: ${typeof handler}`);
19
16
  }
20
17
  harden(handler);
21
18
  const handle = Object.freeze(Object.create(null));
22
- const platformHandle = setTimeout(() => {
19
+ const platformHandle = setTimeout(()=>{
23
20
  registeredHandles.delete(handle);
24
21
  handler();
25
22
  }, Math.max(MINIMUM_TIMEOUT, timeout ?? 0));
26
23
  registeredHandles.set(handle, platformHandle);
27
24
  return handle;
28
25
  };
29
- const _clearTimeout = (handle) => {
26
+ const _clearTimeout = (handle)=>{
30
27
  const platformHandle = registeredHandles.get(handle);
31
28
  if (platformHandle !== undefined) {
32
29
  clearTimeout(platformHandle);
33
30
  registeredHandles.delete(handle);
34
31
  }
35
32
  };
36
- const teardownFunction = () => {
37
- for (const handle of registeredHandles.keys()) {
33
+ const teardownFunction = ()=>{
34
+ for (const handle of registeredHandles.keys()){
38
35
  _clearTimeout(handle);
39
36
  }
40
37
  };
41
38
  return {
42
39
  setTimeout: harden(_setTimeout),
43
40
  clearTimeout: harden(_clearTimeout),
44
- teardownFunction,
41
+ teardownFunction
45
42
  };
46
43
  };
47
44
  const endowmentModule = {
48
- names: ['setTimeout', 'clearTimeout'],
49
- factory: createTimeout,
45
+ names: [
46
+ 'setTimeout',
47
+ 'clearTimeout'
48
+ ],
49
+ factory: createTimeout
50
50
  };
51
- exports.default = endowmentModule;
51
+ export default endowmentModule;
52
+
52
53
  //# 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":"AAAA,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;AACA,eAAewB,gBAAgB"}
@@ -0,0 +1,35 @@
1
+ import { rootRealmGlobal } from './globalObject';
2
+ /**
3
+ * Adds an event listener platform agnostically, trying both `globalThis.addEventListener` and `globalThis.process.on`
4
+ *
5
+ * @param event - The event to listen for.
6
+ * @param listener - The listener to be triggered when the event occurs.
7
+ * @returns The result of the platform agnostic operation if any.
8
+ * @throws If none of the platform options are present.
9
+ */ export function addEventListener(event, listener) {
10
+ if ('addEventListener' in rootRealmGlobal && typeof rootRealmGlobal.addEventListener === 'function') {
11
+ return rootRealmGlobal.addEventListener(event.toLowerCase(), listener);
12
+ }
13
+ if (rootRealmGlobal.process && 'on' in rootRealmGlobal.process && typeof rootRealmGlobal.process.on === 'function') {
14
+ return rootRealmGlobal.process.on(event, listener);
15
+ }
16
+ throw new Error('Platform agnostic addEventListener failed');
17
+ }
18
+ /**
19
+ * Removes an event listener platform agnostically, trying both `globalThis.removeEventListener` and `globalThis.process.removeListener`
20
+ *
21
+ * @param event - The event to remove the listener for.
22
+ * @param listener - The currently attached listener.
23
+ * @returns The result of the platform agnostic operation if any.
24
+ * @throws If none of the platform options are present.
25
+ */ export function removeEventListener(event, listener) {
26
+ if ('removeEventListener' in rootRealmGlobal && typeof rootRealmGlobal.removeEventListener === 'function') {
27
+ return rootRealmGlobal.removeEventListener(event.toLowerCase(), listener);
28
+ }
29
+ if (rootRealmGlobal.process && 'removeListener' in rootRealmGlobal.process && typeof rootRealmGlobal.process.removeListener === 'function') {
30
+ return rootRealmGlobal.process.removeListener(event, listener);
31
+ }
32
+ throw new Error('Platform agnostic removeEventListener failed');
33
+ }
34
+
35
+ //# 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":["rootRealmGlobal","addEventListener","event","listener","toLowerCase","process","on","Error","removeEventListener","removeListener"],"mappings":"AAAA,SAASA,eAAe,QAAQ,iBAAiB;AAEjD;;;;;;;CAOC,GACD,OAAO,SAASC,iBACdC,KAAa,EACbC,QAAkC;IAElC,IACE,sBAAsBH,mBACtB,OAAOA,gBAAgBC,gBAAgB,KAAK,YAC5C;QACA,OAAOD,gBAAgBC,gBAAgB,CAACC,MAAME,WAAW,IAAID;IAC/D;IAEA,IACEH,gBAAgBK,OAAO,IACvB,QAAQL,gBAAgBK,OAAO,IAC/B,OAAOL,gBAAgBK,OAAO,CAACC,EAAE,KAAK,YACtC;QACA,OAAON,gBAAgBK,OAAO,CAACC,EAAE,CAACJ,OAAOC;IAC3C;IAEA,MAAM,IAAII,MAAM;AAClB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,oBACdN,KAAa,EACbC,QAAkC;IAElC,IACE,yBAAyBH,mBACzB,OAAOA,gBAAgBQ,mBAAmB,KAAK,YAC/C;QACA,OAAOR,gBAAgBQ,mBAAmB,CAACN,MAAME,WAAW,IAAID;IAClE;IAEA,IACEH,gBAAgBK,OAAO,IACvB,oBAAoBL,gBAAgBK,OAAO,IAC3C,OAAOL,gBAAgBK,OAAO,CAACI,cAAc,KAAK,YAClD;QACA,OAAOT,gBAAgBK,OAAO,CAACI,cAAc,CAACP,OAAOC;IACvD;IAEA,MAAM,IAAII,MAAM;AAClB"}
@@ -0,0 +1,36 @@
1
+ var GlobalObjectNames;
2
+ (function(GlobalObjectNames) {
3
+ GlobalObjectNames[// The globalThis entry is incorrectly identified as shadowing the global
4
+ // globalThis.
5
+ /* eslint-disable @typescript-eslint/naming-convention */ // eslint-disable-next-line @typescript-eslint/no-shadow
6
+ "globalThis"] = "globalThis";
7
+ GlobalObjectNames["global"] = "global";
8
+ GlobalObjectNames["self"] = "self";
9
+ GlobalObjectNames["window"] = "window";
10
+ })(GlobalObjectNames || (GlobalObjectNames = {}));
11
+ let _rootRealmGlobal;
12
+ let _rootRealmGlobalName;
13
+ /* istanbul ignore next */ /* eslint-disable no-negated-condition */ if (typeof globalThis !== 'undefined') {
14
+ _rootRealmGlobal = globalThis;
15
+ _rootRealmGlobalName = GlobalObjectNames.globalThis;
16
+ } else if (typeof self !== 'undefined') {
17
+ _rootRealmGlobal = self;
18
+ _rootRealmGlobalName = GlobalObjectNames.self;
19
+ } else if (typeof window !== 'undefined') {
20
+ _rootRealmGlobal = window;
21
+ _rootRealmGlobalName = GlobalObjectNames.window;
22
+ } else if (typeof global !== 'undefined') {
23
+ _rootRealmGlobal = global;
24
+ _rootRealmGlobalName = GlobalObjectNames.global;
25
+ } else {
26
+ throw new Error('Unknown realm type; failed to identify global object.');
27
+ }
28
+ /* eslint-enable no-negated-condition */ /**
29
+ * A platform-agnostic alias for the root realm global object.
30
+ */ const rootRealmGlobal = _rootRealmGlobal;
31
+ /**
32
+ * The string literal corresponding to the name of the root realm global object.
33
+ */ const rootRealmGlobalName = _rootRealmGlobalName;
34
+ export { rootRealmGlobal, rootRealmGlobalName };
35
+
36
+ //# sourceMappingURL=globalObject.js.map
@@ -0,0 +1 @@
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":["GlobalObjectNames","globalThis","global","self","window","_rootRealmGlobal","_rootRealmGlobalName","Error","rootRealmGlobal","rootRealmGlobalName"],"mappings":"IAAA;UAAKA,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,MAAMC,kBAAkBH;AAExB;;CAEC,GACD,MAAMI,sBAAsBH;AAE5B,SAASE,eAAe,EAAEC,mBAAmB,GAAG"}
@@ -0,0 +1,66 @@
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
+ import { hasProperty } from '@metamask/utils';
5
+ /**
6
+ * Targeted Event objects and properties.
7
+ * Note: This is a map of the prototypes that inherit from Events with
8
+ * properties that are identified to leak sensitive objects.
9
+ * Not all browsers support all event types, so checking its existence is required.
10
+ */ const targetEvents = new Map();
11
+ if (hasProperty(globalThis, 'UIEvent')) {
12
+ targetEvents.set(UIEvent.prototype, [
13
+ 'view'
14
+ ]);
15
+ }
16
+ if (hasProperty(globalThis, 'MutationEvent')) {
17
+ targetEvents.set(MutationEvent.prototype, [
18
+ 'relatedNode'
19
+ ]);
20
+ }
21
+ if (hasProperty(globalThis, 'MessageEvent')) {
22
+ targetEvents.set(MessageEvent.prototype, [
23
+ 'source'
24
+ ]);
25
+ }
26
+ if (hasProperty(globalThis, 'FocusEvent')) {
27
+ targetEvents.set(FocusEvent.prototype, [
28
+ 'relatedTarget'
29
+ ]);
30
+ }
31
+ if (hasProperty(globalThis, 'MouseEvent')) {
32
+ targetEvents.set(MouseEvent.prototype, [
33
+ 'relatedTarget',
34
+ 'fromElement',
35
+ 'toElement'
36
+ ]);
37
+ }
38
+ if (hasProperty(globalThis, 'TouchEvent')) {
39
+ targetEvents.set(TouchEvent.prototype, [
40
+ 'targetTouches',
41
+ 'touches'
42
+ ]);
43
+ }
44
+ if (hasProperty(globalThis, 'Event')) {
45
+ targetEvents.set(Event.prototype, [
46
+ 'target',
47
+ 'currentTarget',
48
+ 'srcElement',
49
+ 'composedPath'
50
+ ]);
51
+ }
52
+ /**
53
+ * Attenuate Event objects by replacing its own properties.
54
+ */ export function executeLockdownEvents() {
55
+ targetEvents.forEach((properties, prototype)=>{
56
+ for (const property of properties){
57
+ Object.defineProperty(prototype, property, {
58
+ value: undefined,
59
+ configurable: false,
60
+ writable: false
61
+ });
62
+ }
63
+ });
64
+ }
65
+
66
+ //# 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":["hasProperty","targetEvents","Map","globalThis","set","UIEvent","prototype","MutationEvent","MessageEvent","FocusEvent","MouseEvent","TouchEvent","Event","executeLockdownEvents","forEach","properties","property","Object","defineProperty","value","undefined","configurable","writable"],"mappings":"AAAA,iEAAiE;AACjE,2EAA2E;AAC3E,wCAAwC;AACxC,SAASA,WAAW,QAAQ,kBAAkB;AAE9C;;;;;CAKC,GACD,MAAMC,eAAe,IAAIC;AACzB,IAAIF,YAAYG,YAAY,YAAY;IACtCF,aAAaG,GAAG,CAACC,QAAQC,SAAS,EAAE;QAAC;KAAO;AAC9C;AACA,IAAIN,YAAYG,YAAY,kBAAkB;IAC5CF,aAAaG,GAAG,CAACG,cAAcD,SAAS,EAAE;QAAC;KAAc;AAC3D;AACA,IAAIN,YAAYG,YAAY,iBAAiB;IAC3CF,aAAaG,GAAG,CAACI,aAAaF,SAAS,EAAE;QAAC;KAAS;AACrD;AACA,IAAIN,YAAYG,YAAY,eAAe;IACzCF,aAAaG,GAAG,CAACK,WAAWH,SAAS,EAAE;QAAC;KAAgB;AAC1D;AACA,IAAIN,YAAYG,YAAY,eAAe;IACzCF,aAAaG,GAAG,CAACM,WAAWJ,SAAS,EAAE;QACrC;QACA;QACA;KACD;AACH;AACA,IAAIN,YAAYG,YAAY,eAAe;IACzCF,aAAaG,GAAG,CAACO,WAAWL,SAAS,EAAE;QAAC;QAAiB;KAAU;AACrE;AACA,IAAIN,YAAYG,YAAY,UAAU;IACpCF,aAAaG,GAAG,CAACQ,MAAMN,SAAS,EAAE;QAChC;QACA;QACA;QACA;KACD;AACH;AAEA;;CAEC,GACD,OAAO,SAASO;IACdZ,aAAaa,OAAO,CAAC,CAACC,YAAYT;QAChC,KAAK,MAAMU,YAAYD,WAAY;YACjCE,OAAOC,cAAc,CAACZ,WAAWU,UAAU;gBACzCG,OAAOC;gBACPC,cAAc;gBACdC,UAAU;YACZ;QACF;IACF;AACF"}
@@ -1,9 +1,6 @@
1
- "use strict";
2
1
  // eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment
3
2
  /// <reference path="../../../../../node_modules/ses/index.d.ts" />
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.executeLockdownMore = void 0;
6
- const snaps_utils_1 = require("@metamask/snaps-utils");
3
+ import { logError } from '@metamask/snaps-utils';
7
4
  /**
8
5
  * The SES `lockdown` function only hardens the properties enumerated by the
9
6
  * universalPropertyNames constant specified in 'ses/src/whitelist'. This
@@ -23,8 +20,7 @@ const snaps_utils_1 = require("@metamask/snaps-utils");
23
20
  * We write this function in IIFE format to avoid polluting global scope.
24
21
  *
25
22
  * @throws If the lockdown failed.
26
- */
27
- function executeLockdownMore() {
23
+ */ export function executeLockdownMore() {
28
24
  // Make all "object" and "function" own properties of globalThis
29
25
  // non-configurable and non-writable, when possible.
30
26
  // We call a property that is non-configurable and non-writable,
@@ -32,17 +28,17 @@ function executeLockdownMore() {
32
28
  try {
33
29
  const namedIntrinsics = Reflect.ownKeys(new Compartment().globalThis);
34
30
  // These named intrinsics are not automatically hardened by `lockdown`
35
- const shouldHardenManually = new Set(['eval', 'Function']);
31
+ const shouldHardenManually = new Set([
32
+ 'eval',
33
+ 'Function'
34
+ ]);
36
35
  const globalProperties = new Set([
37
36
  // universalPropertyNames is a constant added by lockdown to global scope
38
37
  // at the time of writing, it is initialized in 'ses/src/whitelist'.
39
38
  // These properties tend to be non-enumerable.
40
- ...namedIntrinsics,
41
- // TODO: Also include the named platform globals
42
- // This grabs every enumerable property on globalThis.
43
- // ...Object.keys(globalThis),
39
+ ...namedIntrinsics
44
40
  ]);
45
- globalProperties.forEach((propertyName) => {
41
+ globalProperties.forEach((propertyName)=>{
46
42
  const descriptor = Reflect.getOwnPropertyDescriptor(globalThis, propertyName);
47
43
  if (descriptor) {
48
44
  if (descriptor.configurable) {
@@ -51,13 +47,12 @@ function executeLockdownMore() {
51
47
  // non-writable.
52
48
  if (hasAccessor(descriptor)) {
53
49
  Object.defineProperty(globalThis, propertyName, {
54
- configurable: false,
50
+ configurable: false
55
51
  });
56
- }
57
- else {
52
+ } else {
58
53
  Object.defineProperty(globalThis, propertyName, {
59
54
  configurable: false,
60
- writable: false,
55
+ writable: false
61
56
  });
62
57
  }
63
58
  }
@@ -66,13 +61,11 @@ function executeLockdownMore() {
66
61
  }
67
62
  }
68
63
  });
69
- }
70
- catch (error) {
71
- (0, snaps_utils_1.logError)('Protecting intrinsics failed:', error);
64
+ } catch (error) {
65
+ logError('Protecting intrinsics failed:', error);
72
66
  throw error;
73
67
  }
74
68
  }
75
- exports.executeLockdownMore = executeLockdownMore;
76
69
  /**
77
70
  * Checks whether the given propertyName descriptor has any accessors, i.e. the
78
71
  * properties `get` or `set`.
@@ -82,8 +75,8 @@ exports.executeLockdownMore = executeLockdownMore;
82
75
  *
83
76
  * @param descriptor - The propertyName descriptor to check.
84
77
  * @returns Whether the propertyName descriptor has any accessors.
85
- */
86
- function hasAccessor(descriptor) {
78
+ */ function hasAccessor(descriptor) {
87
79
  return 'set' in descriptor || 'get' in descriptor;
88
80
  }
81
+
89
82
  //# sourceMappingURL=lockdown-more.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/common/lockdown/lockdown-more.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment\n/// <reference path=\"../../../../../node_modules/ses/index.d.ts\" />\n\nimport { logError } from '@metamask/snaps-utils';\n\n/**\n * The SES `lockdown` function only hardens the properties enumerated by the\n * universalPropertyNames constant specified in 'ses/src/whitelist'. This\n * function makes all function and object properties on the start compartment\n * global non-configurable and non-writable, unless they are already\n * non-configurable.\n *\n * It is critical that this function runs at the right time during\n * initialization, which should always be immediately after `lockdown` has been\n * called. At the time of writing, the modifications this function makes to the\n * runtime environment appear to be non-breaking, but that could change with\n * the addition of dependencies, or the order of our scripts in our HTML files.\n * Exercise caution.\n *\n * See inline comments for implementation details.\n *\n * We write this function in IIFE format to avoid polluting global scope.\n *\n * @throws If the lockdown failed.\n */\nexport function executeLockdownMore() {\n // Make all \"object\" and \"function\" own properties of globalThis\n // non-configurable and non-writable, when possible.\n // We call a property that is non-configurable and non-writable,\n // \"non-modifiable\".\n try {\n const namedIntrinsics = Reflect.ownKeys(new Compartment().globalThis);\n\n // These named intrinsics are not automatically hardened by `lockdown`\n const shouldHardenManually = new Set<symbol | string>(['eval', 'Function']);\n\n const globalProperties = new Set([\n // universalPropertyNames is a constant added by lockdown to global scope\n // at the time of writing, it is initialized in 'ses/src/whitelist'.\n // These properties tend to be non-enumerable.\n ...namedIntrinsics,\n\n // TODO: Also include the named platform globals\n // This grabs every enumerable property on globalThis.\n // ...Object.keys(globalThis),\n ]);\n\n globalProperties.forEach((propertyName) => {\n const descriptor = Reflect.getOwnPropertyDescriptor(\n globalThis,\n propertyName,\n );\n\n if (descriptor) {\n if (descriptor.configurable) {\n // If the property on globalThis is configurable, make it\n // non-configurable. If it has no accessor properties, also make it\n // non-writable.\n if (hasAccessor(descriptor)) {\n Object.defineProperty(globalThis, propertyName, {\n configurable: false,\n });\n } else {\n Object.defineProperty(globalThis, propertyName, {\n configurable: false,\n writable: false,\n });\n }\n }\n\n if (shouldHardenManually.has(propertyName)) {\n harden((globalThis as any)[propertyName]);\n }\n }\n });\n } catch (error) {\n logError('Protecting intrinsics failed:', error);\n throw error;\n }\n}\n\n/**\n * Checks whether the given propertyName descriptor has any accessors, i.e. the\n * properties `get` or `set`.\n *\n * We want to make globals non-writable, and we can't set the `writable`\n * property and accessor properties at the same time.\n *\n * @param descriptor - The propertyName descriptor to check.\n * @returns Whether the propertyName descriptor has any accessors.\n */\nfunction hasAccessor(descriptor: any): boolean {\n return 'set' in descriptor || 'get' in descriptor;\n}\n"],"names":["logError","executeLockdownMore","namedIntrinsics","Reflect","ownKeys","Compartment","globalThis","shouldHardenManually","Set","globalProperties","forEach","propertyName","descriptor","getOwnPropertyDescriptor","configurable","hasAccessor","Object","defineProperty","writable","has","harden","error"],"mappings":"AAAA,qFAAqF;AACrF,mEAAmE;AAEnE,SAASA,QAAQ,QAAQ,wBAAwB;AAEjD;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASC;IACd,gEAAgE;IAChE,oDAAoD;IACpD,gEAAgE;IAChE,oBAAoB;IACpB,IAAI;QACF,MAAMC,kBAAkBC,QAAQC,OAAO,CAAC,IAAIC,cAAcC,UAAU;QAEpE,sEAAsE;QACtE,MAAMC,uBAAuB,IAAIC,IAAqB;YAAC;YAAQ;SAAW;QAE1E,MAAMC,mBAAmB,IAAID,IAAI;YAC/B,yEAAyE;YACzE,oEAAoE;YACpE,8CAA8C;eAC3CN;SAKJ;QAEDO,iBAAiBC,OAAO,CAAC,CAACC;YACxB,MAAMC,aAAaT,QAAQU,wBAAwB,CACjDP,YACAK;YAGF,IAAIC,YAAY;gBACd,IAAIA,WAAWE,YAAY,EAAE;oBAC3B,yDAAyD;oBACzD,mEAAmE;oBACnE,gBAAgB;oBAChB,IAAIC,YAAYH,aAAa;wBAC3BI,OAAOC,cAAc,CAACX,YAAYK,cAAc;4BAC9CG,cAAc;wBAChB;oBACF,OAAO;wBACLE,OAAOC,cAAc,CAACX,YAAYK,cAAc;4BAC9CG,cAAc;4BACdI,UAAU;wBACZ;oBACF;gBACF;gBAEA,IAAIX,qBAAqBY,GAAG,CAACR,eAAe;oBAC1CS,OAAO,AAACd,UAAkB,CAACK,aAAa;gBAC1C;YACF;QACF;IACF,EAAE,OAAOU,OAAO;QACdrB,SAAS,iCAAiCqB;QAC1C,MAAMA;IACR;AACF;AAEA;;;;;;;;;CASC,GACD,SAASN,YAAYH,UAAe;IAClC,OAAO,SAASA,cAAc,SAASA;AACzC"}
@@ -1,29 +1,24 @@
1
- "use strict";
2
1
  // eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment
3
2
  /// <reference path="../../../../../node_modules/ses/index.d.ts" />
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.executeLockdown = void 0;
6
- const snaps_utils_1 = require("@metamask/snaps-utils");
3
+ import { logError } from '@metamask/snaps-utils';
7
4
  /**
8
5
  * Execute SES lockdown in the current context, i.e., the current iframe.
9
6
  *
10
7
  * @throws If the SES lockdown failed.
11
- */
12
- function executeLockdown() {
8
+ */ export function executeLockdown() {
13
9
  try {
14
10
  lockdown({
15
11
  consoleTaming: 'unsafe',
16
12
  errorTaming: 'unsafe',
17
13
  mathTaming: 'unsafe',
18
14
  dateTaming: 'unsafe',
19
- overrideTaming: 'severe',
15
+ overrideTaming: 'severe'
20
16
  });
21
- }
22
- catch (error) {
17
+ } catch (error) {
23
18
  // If the `lockdown` call throws an exception, it should not be able to continue
24
- (0, snaps_utils_1.logError)('Lockdown failed:', error);
19
+ logError('Lockdown failed:', error);
25
20
  throw error;
26
21
  }
27
22
  }
28
- exports.executeLockdown = executeLockdown;
23
+
29
24
  //# sourceMappingURL=lockdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/common/lockdown/lockdown.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment\n/// <reference path=\"../../../../../node_modules/ses/index.d.ts\" />\n\nimport { logError } from '@metamask/snaps-utils';\n\n/**\n * Execute SES lockdown in the current context, i.e., the current iframe.\n *\n * @throws If the SES lockdown failed.\n */\nexport function executeLockdown() {\n try {\n lockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n });\n } catch (error) {\n // If the `lockdown` call throws an exception, it should not be able to continue\n logError('Lockdown failed:', error);\n throw error;\n }\n}\n"],"names":["logError","executeLockdown","lockdown","consoleTaming","errorTaming","mathTaming","dateTaming","overrideTaming","error"],"mappings":"AAAA,qFAAqF;AACrF,mEAAmE;AAEnE,SAASA,QAAQ,QAAQ,wBAAwB;AAEjD;;;;CAIC,GACD,OAAO,SAASC;IACd,IAAI;QACFC,SAAS;YACPC,eAAe;YACfC,aAAa;YACbC,YAAY;YACZC,YAAY;YACZC,gBAAgB;QAClB;IACF,EAAE,OAAOC,OAAO;QACd,gFAAgF;QAChFR,SAAS,oBAAoBQ;QAC7B,MAAMA;IACR;AACF"}