@metamask/snaps-execution-environments 0.35.0-flask.1 → 1.0.0-prerelease.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 (231) hide show
  1. package/CHANGELOG.md +5 -34
  2. package/dist/browserify/iframe/bundle.js +12 -0
  3. package/dist/browserify/iframe/index.html +12128 -0
  4. package/dist/browserify/node-process/bundle.js +12127 -0
  5. package/dist/browserify/node-thread/bundle.js +12127 -0
  6. package/dist/browserify/offscreen/bundle.js +10 -0
  7. package/dist/browserify/offscreen/index.html +12128 -0
  8. package/dist/{types/common → common}/BaseSnapExecutor.d.ts +4 -4
  9. package/dist/common/BaseSnapExecutor.js +370 -0
  10. package/dist/common/BaseSnapExecutor.js.map +1 -0
  11. package/dist/common/commands.js +65 -0
  12. package/dist/common/commands.js.map +1 -0
  13. package/dist/{types/common → common}/endowments/commonEndowmentFactory.d.ts +1 -5
  14. package/dist/common/endowments/commonEndowmentFactory.js +75 -0
  15. package/dist/common/endowments/commonEndowmentFactory.js.map +1 -0
  16. package/dist/{types/common → common}/endowments/crypto.d.ts +0 -4
  17. package/dist/common/endowments/crypto.js +28 -0
  18. package/dist/common/endowments/crypto.js.map +1 -0
  19. package/dist/{esm/common → common}/endowments/date.js +16 -20
  20. package/dist/common/endowments/date.js.map +1 -0
  21. package/dist/{types/common → common}/endowments/index.d.ts +1 -3
  22. package/dist/{esm/common → common}/endowments/index.js +36 -34
  23. package/dist/common/endowments/index.js.map +1 -0
  24. package/dist/{esm/common → common}/endowments/interval.js +12 -13
  25. package/dist/common/endowments/interval.js.map +1 -0
  26. package/dist/{esm/common → common}/endowments/math.js +15 -21
  27. package/dist/common/endowments/math.js.map +1 -0
  28. package/dist/common/endowments/network.js +170 -0
  29. package/dist/common/endowments/network.js.map +1 -0
  30. package/dist/common/endowments/textDecoder.js +18 -0
  31. package/dist/common/endowments/textDecoder.js.map +1 -0
  32. package/dist/common/endowments/textEncoder.js +18 -0
  33. package/dist/common/endowments/textEncoder.js.map +1 -0
  34. package/dist/{esm/common → common}/endowments/timeout.js +13 -14
  35. package/dist/common/endowments/timeout.js.map +1 -0
  36. package/dist/{types/common → common}/globalEvents.d.ts +0 -1
  37. package/dist/common/globalEvents.js +47 -0
  38. package/dist/common/globalEvents.js.map +1 -0
  39. package/dist/common/globalObject.js +50 -0
  40. package/dist/{cjs/common → common}/globalObject.js.map +1 -1
  41. package/dist/common/keyring.d.ts +12 -0
  42. package/dist/common/keyring.js +42 -0
  43. package/dist/common/keyring.js.map +1 -0
  44. package/dist/common/lockdown/lockdown-events.js +60 -0
  45. package/dist/common/lockdown/lockdown-events.js.map +1 -0
  46. package/dist/{esm/common → common}/lockdown/lockdown-more.js +22 -15
  47. package/dist/common/lockdown/lockdown-more.js.map +1 -0
  48. package/dist/{esm/common → common}/lockdown/lockdown.js +11 -6
  49. package/dist/common/lockdown/lockdown.js.map +1 -0
  50. package/dist/{esm/common → common}/sortParams.js +13 -7
  51. package/dist/common/sortParams.js.map +1 -0
  52. package/dist/common/utils.js +133 -0
  53. package/dist/common/utils.js.map +1 -0
  54. package/dist/common/validation.js +109 -0
  55. package/dist/common/validation.js.map +1 -0
  56. package/dist/iframe/IFrameSnapExecutor.js +42 -0
  57. package/dist/iframe/IFrameSnapExecutor.js.map +1 -0
  58. package/dist/iframe/index.js +10 -0
  59. package/dist/iframe/index.js.map +1 -0
  60. package/dist/logging.js +13 -0
  61. package/dist/logging.js.map +1 -0
  62. package/dist/node-process/ChildProcessSnapExecutor.js +30 -0
  63. package/dist/node-process/ChildProcessSnapExecutor.js.map +1 -0
  64. package/dist/node-process/index.js +8 -0
  65. package/dist/node-process/index.js.map +1 -0
  66. package/dist/node-thread/ThreadSnapExecutor.js +30 -0
  67. package/dist/node-thread/ThreadSnapExecutor.js.map +1 -0
  68. package/dist/node-thread/index.js +8 -0
  69. package/dist/node-thread/index.js.map +1 -0
  70. package/dist/offscreen/OffscreenSnapExecutor.js +104 -0
  71. package/dist/offscreen/OffscreenSnapExecutor.js.map +1 -0
  72. package/dist/offscreen/index.js +16 -0
  73. package/dist/offscreen/index.js.map +1 -0
  74. package/dist/openrpc.json +210 -0
  75. package/package.json +26 -67
  76. package/dist/cjs/common/BaseSnapExecutor.js +0 -415
  77. package/dist/cjs/common/BaseSnapExecutor.js.map +0 -1
  78. package/dist/cjs/common/commands.js +0 -65
  79. package/dist/cjs/common/commands.js.map +0 -1
  80. package/dist/cjs/common/endowments/commonEndowmentFactory.js +0 -147
  81. package/dist/cjs/common/endowments/commonEndowmentFactory.js.map +0 -1
  82. package/dist/cjs/common/endowments/console.js +0 -134
  83. package/dist/cjs/common/endowments/console.js.map +0 -1
  84. package/dist/cjs/common/endowments/crypto.js +0 -44
  85. package/dist/cjs/common/endowments/crypto.js.map +0 -1
  86. package/dist/cjs/common/endowments/date.js +0 -53
  87. package/dist/cjs/common/endowments/date.js.map +0 -1
  88. package/dist/cjs/common/endowments/index.js +0 -91
  89. package/dist/cjs/common/endowments/index.js.map +0 -1
  90. package/dist/cjs/common/endowments/interval.js +0 -61
  91. package/dist/cjs/common/endowments/interval.js.map +0 -1
  92. package/dist/cjs/common/endowments/math.js +0 -67
  93. package/dist/cjs/common/endowments/math.js.map +0 -1
  94. package/dist/cjs/common/endowments/network.js +0 -206
  95. package/dist/cjs/common/endowments/network.js.map +0 -1
  96. package/dist/cjs/common/endowments/textDecoder.js +0 -28
  97. package/dist/cjs/common/endowments/textDecoder.js.map +0 -1
  98. package/dist/cjs/common/endowments/textEncoder.js +0 -28
  99. package/dist/cjs/common/endowments/textEncoder.js.map +0 -1
  100. package/dist/cjs/common/endowments/timeout.js +0 -63
  101. package/dist/cjs/common/endowments/timeout.js.map +0 -1
  102. package/dist/cjs/common/globalEvents.js +0 -39
  103. package/dist/cjs/common/globalEvents.js.map +0 -1
  104. package/dist/cjs/common/globalObject.js +0 -53
  105. package/dist/cjs/common/lockdown/lockdown-events.js +0 -74
  106. package/dist/cjs/common/lockdown/lockdown-events.js.map +0 -1
  107. package/dist/cjs/common/lockdown/lockdown-more.js +0 -73
  108. package/dist/cjs/common/lockdown/lockdown-more.js.map +0 -1
  109. package/dist/cjs/common/lockdown/lockdown.js +0 -30
  110. package/dist/cjs/common/lockdown/lockdown.js.map +0 -1
  111. package/dist/cjs/common/sortParams.js +0 -26
  112. package/dist/cjs/common/sortParams.js.map +0 -1
  113. package/dist/cjs/common/utils.js +0 -116
  114. package/dist/cjs/common/utils.js.map +0 -1
  115. package/dist/cjs/common/validation.js +0 -114
  116. package/dist/cjs/common/validation.js.map +0 -1
  117. package/dist/cjs/iframe/IFrameSnapExecutor.js +0 -50
  118. package/dist/cjs/iframe/IFrameSnapExecutor.js.map +0 -1
  119. package/dist/cjs/iframe/index.js +0 -13
  120. package/dist/cjs/iframe/index.js.map +0 -1
  121. package/dist/cjs/logging.js +0 -15
  122. package/dist/cjs/logging.js.map +0 -1
  123. package/dist/cjs/node-process/ChildProcessSnapExecutor.js +0 -39
  124. package/dist/cjs/node-process/ChildProcessSnapExecutor.js.map +0 -1
  125. package/dist/cjs/node-process/index.js +0 -11
  126. package/dist/cjs/node-process/index.js.map +0 -1
  127. package/dist/cjs/node-thread/ThreadSnapExecutor.js +0 -39
  128. package/dist/cjs/node-thread/ThreadSnapExecutor.js.map +0 -1
  129. package/dist/cjs/node-thread/index.js +0 -11
  130. package/dist/cjs/node-thread/index.js.map +0 -1
  131. package/dist/cjs/offscreen/OffscreenSnapExecutor.js +0 -173
  132. package/dist/cjs/offscreen/OffscreenSnapExecutor.js.map +0 -1
  133. package/dist/cjs/offscreen/index.js +0 -19
  134. package/dist/cjs/offscreen/index.js.map +0 -1
  135. package/dist/cjs/webworker/executor/WebWorkerSnapExecutor.js +0 -45
  136. package/dist/cjs/webworker/executor/WebWorkerSnapExecutor.js.map +0 -1
  137. package/dist/cjs/webworker/executor/index.js +0 -13
  138. package/dist/cjs/webworker/executor/index.js.map +0 -1
  139. package/dist/cjs/webworker/pool/WebWorkerPool.js +0 -248
  140. package/dist/cjs/webworker/pool/WebWorkerPool.js.map +0 -1
  141. package/dist/cjs/webworker/pool/index.js +0 -13
  142. package/dist/cjs/webworker/pool/index.js.map +0 -1
  143. package/dist/esm/common/BaseSnapExecutor.js +0 -400
  144. package/dist/esm/common/BaseSnapExecutor.js.map +0 -1
  145. package/dist/esm/common/commands.js +0 -64
  146. package/dist/esm/common/commands.js.map +0 -1
  147. package/dist/esm/common/endowments/commonEndowmentFactory.js +0 -132
  148. package/dist/esm/common/endowments/commonEndowmentFactory.js.map +0 -1
  149. package/dist/esm/common/endowments/console.js +0 -116
  150. package/dist/esm/common/endowments/console.js.map +0 -1
  151. package/dist/esm/common/endowments/crypto.js +0 -26
  152. package/dist/esm/common/endowments/crypto.js.map +0 -1
  153. package/dist/esm/common/endowments/date.js.map +0 -1
  154. package/dist/esm/common/endowments/index.js.map +0 -1
  155. package/dist/esm/common/endowments/interval.js.map +0 -1
  156. package/dist/esm/common/endowments/math.js.map +0 -1
  157. package/dist/esm/common/endowments/network.js +0 -196
  158. package/dist/esm/common/endowments/network.js.map +0 -1
  159. package/dist/esm/common/endowments/textDecoder.js +0 -18
  160. package/dist/esm/common/endowments/textDecoder.js.map +0 -1
  161. package/dist/esm/common/endowments/textEncoder.js +0 -18
  162. package/dist/esm/common/endowments/textEncoder.js.map +0 -1
  163. package/dist/esm/common/endowments/timeout.js.map +0 -1
  164. package/dist/esm/common/globalEvents.js +0 -35
  165. package/dist/esm/common/globalEvents.js.map +0 -1
  166. package/dist/esm/common/globalObject.js +0 -36
  167. package/dist/esm/common/globalObject.js.map +0 -1
  168. package/dist/esm/common/lockdown/lockdown-events.js +0 -66
  169. package/dist/esm/common/lockdown/lockdown-events.js.map +0 -1
  170. package/dist/esm/common/lockdown/lockdown-more.js.map +0 -1
  171. package/dist/esm/common/lockdown/lockdown.js.map +0 -1
  172. package/dist/esm/common/sortParams.js.map +0 -1
  173. package/dist/esm/common/utils.js +0 -120
  174. package/dist/esm/common/utils.js.map +0 -1
  175. package/dist/esm/common/validation.js +0 -92
  176. package/dist/esm/common/validation.js.map +0 -1
  177. package/dist/esm/iframe/IFrameSnapExecutor.js +0 -35
  178. package/dist/esm/iframe/IFrameSnapExecutor.js.map +0 -1
  179. package/dist/esm/iframe/index.js +0 -9
  180. package/dist/esm/iframe/index.js.map +0 -1
  181. package/dist/esm/logging.js +0 -10
  182. package/dist/esm/logging.js.map +0 -1
  183. package/dist/esm/node-process/ChildProcessSnapExecutor.js +0 -24
  184. package/dist/esm/node-process/ChildProcessSnapExecutor.js.map +0 -1
  185. package/dist/esm/node-process/index.js +0 -7
  186. package/dist/esm/node-process/index.js.map +0 -1
  187. package/dist/esm/node-thread/ThreadSnapExecutor.js +0 -24
  188. package/dist/esm/node-thread/ThreadSnapExecutor.js.map +0 -1
  189. package/dist/esm/node-thread/index.js +0 -7
  190. package/dist/esm/node-thread/index.js.map +0 -1
  191. package/dist/esm/offscreen/OffscreenSnapExecutor.js +0 -176
  192. package/dist/esm/offscreen/OffscreenSnapExecutor.js.map +0 -1
  193. package/dist/esm/offscreen/index.js +0 -15
  194. package/dist/esm/offscreen/index.js.map +0 -1
  195. package/dist/esm/webworker/executor/WebWorkerSnapExecutor.js +0 -30
  196. package/dist/esm/webworker/executor/WebWorkerSnapExecutor.js.map +0 -1
  197. package/dist/esm/webworker/executor/index.js +0 -9
  198. package/dist/esm/webworker/executor/index.js.map +0 -1
  199. package/dist/esm/webworker/pool/WebWorkerPool.js +0 -245
  200. package/dist/esm/webworker/pool/WebWorkerPool.js.map +0 -1
  201. package/dist/esm/webworker/pool/index.js +0 -9
  202. package/dist/esm/webworker/pool/index.js.map +0 -1
  203. package/dist/types/common/endowments/console.d.ts +0 -45
  204. package/dist/types/webworker/executor/WebWorkerSnapExecutor.d.ts +0 -13
  205. package/dist/types/webworker/executor/index.d.ts +0 -1
  206. package/dist/types/webworker/pool/WebWorkerPool.d.ts +0 -22
  207. package/dist/types/webworker/pool/index.d.ts +0 -1
  208. /package/dist/{types/common → common}/commands.d.ts +0 -0
  209. /package/dist/{types/common → common}/endowments/date.d.ts +0 -0
  210. /package/dist/{types/common → common}/endowments/interval.d.ts +0 -0
  211. /package/dist/{types/common → common}/endowments/math.d.ts +0 -0
  212. /package/dist/{types/common → common}/endowments/network.d.ts +0 -0
  213. /package/dist/{types/common → common}/endowments/textDecoder.d.ts +0 -0
  214. /package/dist/{types/common → common}/endowments/textEncoder.d.ts +0 -0
  215. /package/dist/{types/common → common}/endowments/timeout.d.ts +0 -0
  216. /package/dist/{types/common → common}/globalObject.d.ts +0 -0
  217. /package/dist/{types/common → common}/lockdown/lockdown-events.d.ts +0 -0
  218. /package/dist/{types/common → common}/lockdown/lockdown-more.d.ts +0 -0
  219. /package/dist/{types/common → common}/lockdown/lockdown.d.ts +0 -0
  220. /package/dist/{types/common → common}/sortParams.d.ts +0 -0
  221. /package/dist/{types/common → common}/utils.d.ts +0 -0
  222. /package/dist/{types/common → common}/validation.d.ts +0 -0
  223. /package/dist/{types/iframe → iframe}/IFrameSnapExecutor.d.ts +0 -0
  224. /package/dist/{types/iframe → iframe}/index.d.ts +0 -0
  225. /package/dist/{types/logging.d.ts → logging.d.ts} +0 -0
  226. /package/dist/{types/node-process → node-process}/ChildProcessSnapExecutor.d.ts +0 -0
  227. /package/dist/{types/node-process → node-process}/index.d.ts +0 -0
  228. /package/dist/{types/node-thread → node-thread}/ThreadSnapExecutor.d.ts +0 -0
  229. /package/dist/{types/node-thread → node-thread}/index.d.ts +0 -0
  230. /package/dist/{types/offscreen → offscreen}/OffscreenSnapExecutor.d.ts +0 -0
  231. /package/dist/{types/offscreen → offscreen}/index.d.ts +0 -0
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  const MINIMUM_TIMEOUT = 10;
2
4
  /**
3
5
  * Creates a pair of `setTimeout` and `clearTimeout` functions attenuated such
@@ -8,46 +10,43 @@ const MINIMUM_TIMEOUT = 10;
8
10
  *
9
11
  * @returns An object with the attenuated `setTimeout` and `clearTimeout`
10
12
  * functions.
11
- */ const createTimeout = ()=>{
13
+ */
14
+ const createTimeout = () => {
12
15
  const registeredHandles = new Map();
13
- const _setTimeout = (handler, timeout)=>{
16
+ const _setTimeout = (handler, timeout) => {
14
17
  if (typeof handler !== 'function') {
15
18
  throw new Error(`The timeout handler must be a function. Received: ${typeof handler}`);
16
19
  }
17
20
  harden(handler);
18
21
  const handle = Object.freeze(Object.create(null));
19
- const platformHandle = setTimeout(()=>{
22
+ const platformHandle = setTimeout(() => {
20
23
  registeredHandles.delete(handle);
21
24
  handler();
22
25
  }, Math.max(MINIMUM_TIMEOUT, timeout ?? 0));
23
26
  registeredHandles.set(handle, platformHandle);
24
27
  return handle;
25
28
  };
26
- const _clearTimeout = (handle)=>{
29
+ const _clearTimeout = (handle) => {
27
30
  const platformHandle = registeredHandles.get(handle);
28
31
  if (platformHandle !== undefined) {
29
32
  clearTimeout(platformHandle);
30
33
  registeredHandles.delete(handle);
31
34
  }
32
35
  };
33
- const teardownFunction = ()=>{
34
- for (const handle of registeredHandles.keys()){
36
+ const teardownFunction = () => {
37
+ for (const handle of registeredHandles.keys()) {
35
38
  _clearTimeout(handle);
36
39
  }
37
40
  };
38
41
  return {
39
42
  setTimeout: harden(_setTimeout),
40
43
  clearTimeout: harden(_clearTimeout),
41
- teardownFunction
44
+ teardownFunction,
42
45
  };
43
46
  };
44
47
  const endowmentModule = {
45
- names: [
46
- 'setTimeout',
47
- 'clearTimeout'
48
- ],
49
- factory: createTimeout
48
+ names: ['setTimeout', 'clearTimeout'],
49
+ factory: createTimeout,
50
50
  };
51
- export default endowmentModule;
52
-
51
+ exports.default = endowmentModule;
53
52
  //# sourceMappingURL=timeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../../src/common/endowments/timeout.ts"],"names":[],"mappings":";;AAAA,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B;;;;;;;;;GASG;AACH,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB,CAAC;IACtD,MAAM,WAAW,GAAG,CAAC,OAAqB,EAAE,OAAgB,EAAW,EAAE;QACvE,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;YACjC,MAAM,IAAI,KAAK,CACb,qDAAqD,OAAO,OAAO,EAAE,CACtE,CAAC;SACH;QACD,MAAM,CAAC,OAAO,CAAC,CAAC;QAChB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAClD,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,EAAE;YACrC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACjC,OAAO,EAAE,CAAC;QACZ,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;QAE5C,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,CAAC,MAAe,EAAQ,EAAE;QAC9C,MAAM,cAAc,GAAG,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,cAAc,KAAK,SAAS,EAAE;YAChC,YAAY,CAAC,cAAqB,CAAC,CAAC;YACpC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SAClC;IACH,CAAC,CAAC;IAEF,MAAM,gBAAgB,GAAG,GAAS,EAAE;QAClC,KAAK,MAAM,MAAM,IAAI,iBAAiB,CAAC,IAAI,EAAE,EAAE;YAC7C,aAAa,CAAC,MAAM,CAAC,CAAC;SACvB;IACH,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC;QAC/B,YAAY,EAAE,MAAM,CAAC,aAAa,CAAC;QACnC,gBAAgB;KACR,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,YAAY,EAAE,cAAc,CAAU;IAC9C,OAAO,EAAE,aAAa;CACvB,CAAC;AACF,kBAAe,eAAe,CAAC","sourcesContent":["const MINIMUM_TIMEOUT = 10;\n\n/**\n * Creates a pair of `setTimeout` and `clearTimeout` functions attenuated such\n * that:\n * - `setTimeout` throws if its \"handler\" parameter is not a function.\n * - `clearTimeout` only clears timeouts created by its sibling `setTimeout`,\n * or else no-ops.\n *\n * @returns An object with the attenuated `setTimeout` and `clearTimeout`\n * functions.\n */\nconst createTimeout = () => {\n const registeredHandles = new Map<unknown, unknown>();\n 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"]}
@@ -1,4 +1,3 @@
1
- /// <reference types="webpack-env" />
2
1
  /// <reference types="node" />
3
2
  /**
4
3
  * Adds an event listener platform agnostically, trying both `globalThis.addEventListener` and `globalThis.process.on`
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeEventListener = exports.addEventListener = void 0;
4
+ const globalObject_1 = require("./globalObject");
5
+ /**
6
+ * Adds an event listener platform agnostically, trying both `globalThis.addEventListener` and `globalThis.process.on`
7
+ *
8
+ * @param event - The event to listen for.
9
+ * @param listener - The listener to be triggered when the event occurs.
10
+ * @returns The result of the platform agnostic operation if any.
11
+ * @throws If none of the platform options are present.
12
+ */
13
+ function addEventListener(event, listener) {
14
+ if ('addEventListener' in globalObject_1.rootRealmGlobal &&
15
+ typeof globalObject_1.rootRealmGlobal.addEventListener === 'function') {
16
+ return globalObject_1.rootRealmGlobal.addEventListener(event.toLowerCase(), listener);
17
+ }
18
+ if (globalObject_1.rootRealmGlobal.process &&
19
+ 'on' in globalObject_1.rootRealmGlobal.process &&
20
+ typeof globalObject_1.rootRealmGlobal.process.on === 'function') {
21
+ return globalObject_1.rootRealmGlobal.process.on(event, listener);
22
+ }
23
+ throw new Error('Platform agnostic addEventListener failed');
24
+ }
25
+ exports.addEventListener = addEventListener;
26
+ /**
27
+ * Removes an event listener platform agnostically, trying both `globalThis.removeEventListener` and `globalThis.process.removeListener`
28
+ *
29
+ * @param event - The event to remove the listener for.
30
+ * @param listener - The currently attached listener.
31
+ * @returns The result of the platform agnostic operation if any.
32
+ * @throws If none of the platform options are present.
33
+ */
34
+ function removeEventListener(event, listener) {
35
+ if ('removeEventListener' in globalObject_1.rootRealmGlobal &&
36
+ typeof globalObject_1.rootRealmGlobal.removeEventListener === 'function') {
37
+ return globalObject_1.rootRealmGlobal.removeEventListener(event.toLowerCase(), listener);
38
+ }
39
+ if (globalObject_1.rootRealmGlobal.process &&
40
+ 'removeListener' in globalObject_1.rootRealmGlobal.process &&
41
+ typeof globalObject_1.rootRealmGlobal.process.removeListener === 'function') {
42
+ return globalObject_1.rootRealmGlobal.process.removeListener(event, listener);
43
+ }
44
+ throw new Error('Platform agnostic removeEventListener failed');
45
+ }
46
+ exports.removeEventListener = removeEventListener;
47
+ //# sourceMappingURL=globalEvents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalEvents.js","sourceRoot":"","sources":["../../src/common/globalEvents.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC9B,KAAa,EACb,QAAkC;IAElC,IACE,kBAAkB,IAAI,8BAAe;QACrC,OAAO,8BAAe,CAAC,gBAAgB,KAAK,UAAU,EACtD;QACA,OAAO,8BAAe,CAAC,gBAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;KACxE;IAED,IACE,8BAAe,CAAC,OAAO;QACvB,IAAI,IAAI,8BAAe,CAAC,OAAO;QAC/B,OAAO,8BAAe,CAAC,OAAO,CAAC,EAAE,KAAK,UAAU,EAChD;QACA,OAAO,8BAAe,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;KACpD;IAED,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;AAC/D,CAAC;AApBD,4CAoBC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,KAAa,EACb,QAAkC;IAElC,IACE,qBAAqB,IAAI,8BAAe;QACxC,OAAO,8BAAe,CAAC,mBAAmB,KAAK,UAAU,EACzD;QACA,OAAO,8BAAe,CAAC,mBAAmB,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;KAC3E;IAED,IACE,8BAAe,CAAC,OAAO;QACvB,gBAAgB,IAAI,8BAAe,CAAC,OAAO;QAC3C,OAAO,8BAAe,CAAC,OAAO,CAAC,cAAc,KAAK,UAAU,EAC5D;QACA,OAAO,8BAAe,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;KAChE;IAED,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;AAClE,CAAC;AApBD,kDAoBC","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"]}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rootRealmGlobalName = exports.rootRealmGlobal = void 0;
4
+ var GlobalObjectNames;
5
+ (function (GlobalObjectNames) {
6
+ // The globalThis entry is incorrectly identified as shadowing the global
7
+ // globalThis.
8
+ /* eslint-disable @typescript-eslint/naming-convention */
9
+ // eslint-disable-next-line @typescript-eslint/no-shadow
10
+ GlobalObjectNames["globalThis"] = "globalThis";
11
+ GlobalObjectNames["global"] = "global";
12
+ GlobalObjectNames["self"] = "self";
13
+ GlobalObjectNames["window"] = "window";
14
+ /* eslint-enavle @typescript-eslint/naming-convention */
15
+ })(GlobalObjectNames || (GlobalObjectNames = {}));
16
+ let _rootRealmGlobal;
17
+ let _rootRealmGlobalName;
18
+ /* istanbul ignore next */
19
+ /* eslint-disable no-negated-condition */
20
+ if (typeof globalThis !== 'undefined') {
21
+ _rootRealmGlobal = globalThis;
22
+ _rootRealmGlobalName = GlobalObjectNames.globalThis;
23
+ }
24
+ else if (typeof self !== 'undefined') {
25
+ _rootRealmGlobal = self;
26
+ _rootRealmGlobalName = GlobalObjectNames.self;
27
+ }
28
+ else if (typeof window !== 'undefined') {
29
+ _rootRealmGlobal = window;
30
+ _rootRealmGlobalName = GlobalObjectNames.window;
31
+ }
32
+ else if (typeof global !== 'undefined') {
33
+ _rootRealmGlobal = global;
34
+ _rootRealmGlobalName = GlobalObjectNames.global;
35
+ }
36
+ else {
37
+ throw new Error('Unknown realm type; failed to identify global object.');
38
+ }
39
+ /* eslint-enable no-negated-condition */
40
+ /**
41
+ * A platform-agnostic alias for the root realm global object.
42
+ */
43
+ const rootRealmGlobal = _rootRealmGlobal;
44
+ exports.rootRealmGlobal = rootRealmGlobal;
45
+ /**
46
+ * The string literal corresponding to the name of the root realm global object.
47
+ */
48
+ const rootRealmGlobalName = _rootRealmGlobalName;
49
+ exports.rootRealmGlobalName = rootRealmGlobalName;
50
+ //# sourceMappingURL=globalObject.js.map
@@ -1 +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":["rootRealmGlobal","rootRealmGlobalName","GlobalObjectNames","globalThis","global","self","window","_rootRealmGlobal","_rootRealmGlobalName","Error"],"mappings":";;;;;;;;;;;IA4CSA,eAAe;eAAfA;;IAAiBC,mBAAmB;eAAnBA;;;IA5C1B;UAAKC,iBAAiB;IAAjBA,kBACH,yEAAyE;IACzE,cAAc;IACd,uDAAuD,GACvD,wDAAwD;IACxDC,gBAAAA;IALGD,kBAMHE,YAAAA;IANGF,kBAOHG,UAAAA;IAPGH,kBAQHI,YAAAA;GARGJ,sBAAAA;AAYL,IAAIK;AACJ,IAAIC;AAEJ,wBAAwB,GACxB,uCAAuC,GACvC,IAAI,OAAOL,eAAe,aAAa;IACrCI,mBAAmBJ;IACnBK,uBAAuBN,kBAAkBC,UAAU;AACrD,OAAO,IAAI,OAAOE,SAAS,aAAa;IACtCE,mBAAmBF;IACnBG,uBAAuBN,kBAAkBG,IAAI;AAC/C,OAAO,IAAI,OAAOC,WAAW,aAAa;IACxCC,mBAAmBD;IACnBE,uBAAuBN,kBAAkBI,MAAM;AACjD,OAAO,IAAI,OAAOF,WAAW,aAAa;IACxCG,mBAAmBH;IACnBI,uBAAuBN,kBAAkBE,MAAM;AACjD,OAAO;IACL,MAAM,IAAIK,MAAM;AAClB;AACA,sCAAsC,GAEtC;;CAEC,GACD,MAAMT,kBAAkBO;AAExB;;CAEC,GACD,MAAMN,sBAAsBO"}
1
+ {"version":3,"file":"globalObject.js","sourceRoot":"","sources":["../../src/common/globalObject.ts"],"names":[],"mappings":";;;AAAA,IAAK,iBAUJ;AAVD,WAAK,iBAAiB;IACpB,yEAAyE;IACzE,cAAc;IACd,yDAAyD;IACzD,wDAAwD;IACxD,8CAAyB,CAAA;IACzB,sCAAiB,CAAA;IACjB,kCAAa,CAAA;IACb,sCAAiB,CAAA;IACjB,wDAAwD;AAC1D,CAAC,EAVI,iBAAiB,KAAjB,iBAAiB,QAUrB;AAED,IAAI,gBAAmC,CAAC;AACxC,IAAI,oBAA4B,CAAC;AAEjC,0BAA0B;AAC1B,yCAAyC;AACzC,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE;IACrC,gBAAgB,GAAG,UAAU,CAAC;IAC9B,oBAAoB,GAAG,iBAAiB,CAAC,UAAU,CAAC;CACrD;KAAM,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;IACtC,gBAAgB,GAAG,IAAI,CAAC;IACxB,oBAAoB,GAAG,iBAAiB,CAAC,IAAI,CAAC;CAC/C;KAAM,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACxC,gBAAgB,GAAG,MAAM,CAAC;IAC1B,oBAAoB,GAAG,iBAAiB,CAAC,MAAM,CAAC;CACjD;KAAM,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACxC,gBAAgB,GAAG,MAAM,CAAC;IAC1B,oBAAoB,GAAG,iBAAiB,CAAC,MAAM,CAAC;CACjD;KAAM;IACL,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;CAC1E;AACD,wCAAwC;AAExC;;GAEG;AACH,MAAM,eAAe,GAAG,gBAAgB,CAAC;AAOhC,0CAAe;AALxB;;GAEG;AACH,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAEvB,kDAAmB","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"]}
@@ -0,0 +1,12 @@
1
+ import { SnapKeyring } from '@metamask/snaps-utils';
2
+ import { Json, JsonRpcNotification, JsonRpcRequest } from '@metamask/utils';
3
+ /**
4
+ * Wraps a SnapKeyring class, returning a handler that can route requests to the exposed functions by the class.
5
+ *
6
+ * @param notify - The BaseSnapExecutor notify function, used for event communication.
7
+ * @param keyring - The SnapKeyring instance.
8
+ * @returns A handler function.
9
+ */
10
+ export declare function wrapKeyring(notify: (requestObject: Omit<JsonRpcNotification<Record<string, Json> | Json[]>, 'jsonrpc'>) => void, keyring?: SnapKeyring): ({ request }: {
11
+ request: JsonRpcRequest<Json[]>;
12
+ }) => unknown;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapKeyring = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ /**
6
+ * Wraps a SnapKeyring class, returning a handler that can route requests to the exposed functions by the class.
7
+ *
8
+ * @param notify - The BaseSnapExecutor notify function, used for event communication.
9
+ * @param keyring - The SnapKeyring instance.
10
+ * @returns A handler function.
11
+ */
12
+ function wrapKeyring(notify, keyring) {
13
+ if (!keyring) {
14
+ throw new Error('Keyring not exported');
15
+ }
16
+ const keyringHandler = ({ request }) => {
17
+ const { method, params } = request;
18
+ if (!(method in keyring)) {
19
+ throw new Error(`Keyring does not expose ${method}`);
20
+ }
21
+ let args = (params ?? []);
22
+ const keyringMethod = keyring[method];
23
+ (0, utils_1.assert)(keyringMethod !== undefined);
24
+ const func = keyringMethod.bind(keyring);
25
+ // Special case for registering events
26
+ if (method === 'on') {
27
+ const data = args[0];
28
+ const listener = (...listenerArgs) => {
29
+ (0, utils_1.assert)((0, utils_1.isValidJson)(listenerArgs), new TypeError('Keyrings .on listener received non-JSON-serializable value.'));
30
+ return notify({
31
+ method: 'SnapKeyringEvent',
32
+ params: { data, args: listenerArgs },
33
+ });
34
+ };
35
+ args = [data, listener];
36
+ }
37
+ return func(...args);
38
+ };
39
+ return keyringHandler;
40
+ }
41
+ exports.wrapKeyring = wrapKeyring;
42
+ //# sourceMappingURL=keyring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring.js","sourceRoot":"","sources":["../../src/common/keyring.ts"],"names":[],"mappings":";;;AACA,2CAMyB;AAEzB;;;;;;GAMG;AACH,SAAgB,WAAW,CACzB,MAKS,EACT,OAAqB;IAErB,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;KACzC;IAED,MAAM,cAAc,GAAG,CAAC,EAAE,OAAO,EAAuC,EAAE,EAAE;QAC1E,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QACnC,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO,CAAC,EAAE;YACxB,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;SACtD;QACD,IAAI,IAAI,GAAG,CAAC,MAAM,IAAI,EAAE,CAAc,CAAC;QACvC,MAAM,aAAa,GAAG,OAAO,CAAC,MAA2B,CAAC,CAAC;QAC3D,IAAA,cAAM,EAAC,aAAa,KAAK,SAAS,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzC,sCAAsC;QACtC,IAAI,MAAM,KAAK,IAAI,EAAE;YACnB,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAS,CAAC;YAC7B,MAAM,QAAQ,GAAG,CAAC,GAAG,YAAuB,EAAE,EAAE;gBAC9C,IAAA,cAAM,EACJ,IAAA,mBAAW,EAAC,YAAY,CAAC,EACzB,IAAI,SAAS,CACX,6DAA6D,CAC9D,CACF,CAAC;gBACF,OAAO,MAAM,CAAC;oBACZ,MAAM,EAAE,kBAAkB;oBAC1B,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE;iBACrC,CAAC,CAAC;YACL,CAAC,CAAC;YACF,IAAI,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;SACzB;QACD,OAAQ,IAAqC,CAAC,GAAG,IAAI,CAAC,CAAC;IACzD,CAAC,CAAC;IACF,OAAO,cAAc,CAAC;AACxB,CAAC;AA1CD,kCA0CC","sourcesContent":["import { SnapKeyring } from '@metamask/snaps-utils';\nimport {\n assert,\n isValidJson,\n Json,\n JsonRpcNotification,\n JsonRpcRequest,\n} from '@metamask/utils';\n\n/**\n * Wraps a SnapKeyring class, returning a handler that can route requests to the exposed functions by the class.\n *\n * @param notify - The BaseSnapExecutor notify function, used for event communication.\n * @param keyring - The SnapKeyring instance.\n * @returns A handler function.\n */\nexport function wrapKeyring(\n notify: (\n requestObject: Omit<\n JsonRpcNotification<Record<string, Json> | Json[]>,\n 'jsonrpc'\n >,\n ) => void,\n keyring?: SnapKeyring,\n) {\n if (!keyring) {\n throw new Error('Keyring not exported');\n }\n\n const keyringHandler = ({ request }: { request: JsonRpcRequest<Json[]> }) => {\n const { method, params } = request;\n if (!(method in keyring)) {\n throw new Error(`Keyring does not expose ${method}`);\n }\n let args = (params ?? []) as unknown[];\n const keyringMethod = keyring[method as keyof SnapKeyring];\n assert(keyringMethod !== undefined);\n const func = keyringMethod.bind(keyring);\n // Special case for registering events\n if (method === 'on') {\n const data = args[0] as Json;\n const listener = (...listenerArgs: unknown[]) => {\n assert(\n isValidJson(listenerArgs),\n new TypeError(\n 'Keyrings .on listener received non-JSON-serializable value.',\n ),\n );\n return notify({\n method: 'SnapKeyringEvent',\n params: { data, args: listenerArgs },\n });\n };\n args = [data, listener];\n }\n return (func as (..._: unknown[]) => unknown)(...args);\n };\n return keyringHandler;\n}\n"]}
@@ -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,6 +1,9 @@
1
+ "use strict";
1
2
  // eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment
2
3
  /// <reference path="../../../../../node_modules/ses/index.d.ts" />
3
- import { logError } from '@metamask/snaps-utils';
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.executeLockdownMore = void 0;
6
+ const snaps_utils_1 = require("@metamask/snaps-utils");
4
7
  /**
5
8
  * The SES `lockdown` function only hardens the properties enumerated by the
6
9
  * universalPropertyNames constant specified in 'ses/src/whitelist'. This
@@ -20,7 +23,8 @@ import { logError } from '@metamask/snaps-utils';
20
23
  * We write this function in IIFE format to avoid polluting global scope.
21
24
  *
22
25
  * @throws If the lockdown failed.
23
- */ export function executeLockdownMore() {
26
+ */
27
+ function executeLockdownMore() {
24
28
  // Make all "object" and "function" own properties of globalThis
25
29
  // non-configurable and non-writable, when possible.
26
30
  // We call a property that is non-configurable and non-writable,
@@ -28,17 +32,17 @@ import { logError } from '@metamask/snaps-utils';
28
32
  try {
29
33
  const namedIntrinsics = Reflect.ownKeys(new Compartment().globalThis);
30
34
  // These named intrinsics are not automatically hardened by `lockdown`
31
- const shouldHardenManually = new Set([
32
- 'eval',
33
- 'Function'
34
- ]);
35
+ const shouldHardenManually = new Set(['eval', 'Function']);
35
36
  const globalProperties = new Set([
36
37
  // universalPropertyNames is a constant added by lockdown to global scope
37
38
  // at the time of writing, it is initialized in 'ses/src/whitelist'.
38
39
  // These properties tend to be non-enumerable.
39
- ...namedIntrinsics
40
+ ...namedIntrinsics,
41
+ // TODO: Also include the named platform globals
42
+ // This grabs every enumerable property on globalThis.
43
+ // ...Object.keys(globalThis),
40
44
  ]);
41
- globalProperties.forEach((propertyName)=>{
45
+ globalProperties.forEach((propertyName) => {
42
46
  const descriptor = Reflect.getOwnPropertyDescriptor(globalThis, propertyName);
43
47
  if (descriptor) {
44
48
  if (descriptor.configurable) {
@@ -47,12 +51,13 @@ import { logError } from '@metamask/snaps-utils';
47
51
  // non-writable.
48
52
  if (hasAccessor(descriptor)) {
49
53
  Object.defineProperty(globalThis, propertyName, {
50
- configurable: false
54
+ configurable: false,
51
55
  });
52
- } else {
56
+ }
57
+ else {
53
58
  Object.defineProperty(globalThis, propertyName, {
54
59
  configurable: false,
55
- writable: false
60
+ writable: false,
56
61
  });
57
62
  }
58
63
  }
@@ -61,11 +66,13 @@ import { logError } from '@metamask/snaps-utils';
61
66
  }
62
67
  }
63
68
  });
64
- } catch (error) {
65
- logError('Protecting intrinsics failed:', error);
69
+ }
70
+ catch (error) {
71
+ (0, snaps_utils_1.logError)('Protecting intrinsics failed:', error);
66
72
  throw error;
67
73
  }
68
74
  }
75
+ exports.executeLockdownMore = executeLockdownMore;
69
76
  /**
70
77
  * Checks whether the given propertyName descriptor has any accessors, i.e. the
71
78
  * properties `get` or `set`.
@@ -75,8 +82,8 @@ import { logError } from '@metamask/snaps-utils';
75
82
  *
76
83
  * @param descriptor - The propertyName descriptor to check.
77
84
  * @returns Whether the propertyName descriptor has any accessors.
78
- */ function hasAccessor(descriptor) {
85
+ */
86
+ function hasAccessor(descriptor) {
79
87
  return 'set' in descriptor || 'get' in descriptor;
80
88
  }
81
-
82
89
  //# sourceMappingURL=lockdown-more.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockdown-more.js","sourceRoot":"","sources":["../../../src/common/lockdown/lockdown-more.ts"],"names":[],"mappings":";AAAA,qFAAqF;AACrF,mEAAmE;;;AAEnE,uDAAiD;AAEjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,mBAAmB;IACjC,gEAAgE;IAChE,oDAAoD;IACpD,gEAAgE;IAChE,oBAAoB;IACpB,IAAI;QACF,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC,UAAU,CAAC,CAAC;QAEtE,sEAAsE;QACtE,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAkB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;QAE5E,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;YAC/B,yEAAyE;YACzE,oEAAoE;YACpE,8CAA8C;YAC9C,GAAG,eAAe;YAElB,gDAAgD;YAChD,sDAAsD;YACtD,8BAA8B;SAC/B,CAAC,CAAC;QAEH,gBAAgB,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;YACxC,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CACjD,UAAU,EACV,YAAY,CACb,CAAC;YAEF,IAAI,UAAU,EAAE;gBACd,IAAI,UAAU,CAAC,YAAY,EAAE;oBAC3B,yDAAyD;oBACzD,mEAAmE;oBACnE,gBAAgB;oBAChB,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE;wBAC3B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,YAAY,EAAE;4BAC9C,YAAY,EAAE,KAAK;yBACpB,CAAC,CAAC;qBACJ;yBAAM;wBACL,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,YAAY,EAAE;4BAC9C,YAAY,EAAE,KAAK;4BACnB,QAAQ,EAAE,KAAK;yBAChB,CAAC,CAAC;qBACJ;iBACF;gBAED,IAAI,oBAAoB,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;oBAC1C,MAAM,CAAE,UAAkB,CAAC,YAAY,CAAC,CAAC,CAAC;iBAC3C;aACF;QACH,CAAC,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,sBAAQ,EAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAtDD,kDAsDC;AAED;;;;;;;;;GASG;AACH,SAAS,WAAW,CAAC,UAAe;IAClC,OAAO,KAAK,IAAI,UAAU,IAAI,KAAK,IAAI,UAAU,CAAC;AACpD,CAAC","sourcesContent":["// eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment\n/// <reference path=\"../../../../../node_modules/ses/index.d.ts\" />\n\nimport { logError } from '@metamask/snaps-utils';\n\n/**\n * The SES `lockdown` function only hardens the properties enumerated by the\n * universalPropertyNames constant specified in 'ses/src/whitelist'. This\n * function makes all function and object properties on the start compartment\n * global non-configurable and non-writable, unless they are already\n * non-configurable.\n *\n * It is critical that this function runs at the right time during\n * initialization, which should always be immediately after `lockdown` has been\n * called. At the time of writing, the modifications this function makes to the\n * runtime environment appear to be non-breaking, but that could change with\n * the addition of dependencies, or the order of our scripts in our HTML files.\n * Exercise caution.\n *\n * See inline comments for implementation details.\n *\n * We write this function in IIFE format to avoid polluting global scope.\n *\n * @throws If the lockdown failed.\n */\nexport function executeLockdownMore() {\n // Make all \"object\" and \"function\" own properties of globalThis\n // non-configurable and non-writable, when possible.\n // We call a property that is non-configurable and non-writable,\n // \"non-modifiable\".\n try {\n const namedIntrinsics = Reflect.ownKeys(new Compartment().globalThis);\n\n // These named intrinsics are not automatically hardened by `lockdown`\n const shouldHardenManually = new Set<symbol | string>(['eval', 'Function']);\n\n const globalProperties = new Set([\n // universalPropertyNames is a constant added by lockdown to global scope\n // at the time of writing, it is initialized in 'ses/src/whitelist'.\n // These properties tend to be non-enumerable.\n ...namedIntrinsics,\n\n // TODO: Also include the named platform globals\n // This grabs every enumerable property on globalThis.\n // ...Object.keys(globalThis),\n ]);\n\n globalProperties.forEach((propertyName) => {\n const descriptor = Reflect.getOwnPropertyDescriptor(\n globalThis,\n propertyName,\n );\n\n if (descriptor) {\n if (descriptor.configurable) {\n // If the property on globalThis is configurable, make it\n // non-configurable. If it has no accessor properties, also make it\n // non-writable.\n if (hasAccessor(descriptor)) {\n Object.defineProperty(globalThis, propertyName, {\n configurable: false,\n });\n } else {\n Object.defineProperty(globalThis, propertyName, {\n configurable: false,\n writable: false,\n });\n }\n }\n\n if (shouldHardenManually.has(propertyName)) {\n harden((globalThis as any)[propertyName]);\n }\n }\n });\n } catch (error) {\n logError('Protecting intrinsics failed:', error);\n throw error;\n }\n}\n\n/**\n * Checks whether the given propertyName descriptor has any accessors, i.e. the\n * properties `get` or `set`.\n *\n * We want to make globals non-writable, and we can't set the `writable`\n * property and accessor properties at the same time.\n *\n * @param descriptor - The propertyName descriptor to check.\n * @returns Whether the propertyName descriptor has any accessors.\n */\nfunction hasAccessor(descriptor: any): boolean {\n return 'set' in descriptor || 'get' in descriptor;\n}\n"]}
@@ -1,24 +1,29 @@
1
+ "use strict";
1
2
  // eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment
2
3
  /// <reference path="../../../../../node_modules/ses/index.d.ts" />
3
- import { logError } from '@metamask/snaps-utils';
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.executeLockdown = void 0;
6
+ const snaps_utils_1 = require("@metamask/snaps-utils");
4
7
  /**
5
8
  * Execute SES lockdown in the current context, i.e., the current iframe.
6
9
  *
7
10
  * @throws If the SES lockdown failed.
8
- */ export function executeLockdown() {
11
+ */
12
+ function executeLockdown() {
9
13
  try {
10
14
  lockdown({
11
15
  consoleTaming: 'unsafe',
12
16
  errorTaming: 'unsafe',
13
17
  mathTaming: 'unsafe',
14
18
  dateTaming: 'unsafe',
15
- overrideTaming: 'severe'
19
+ overrideTaming: 'severe',
16
20
  });
17
- } catch (error) {
21
+ }
22
+ catch (error) {
18
23
  // If the `lockdown` call throws an exception, it should not be able to continue
19
- logError('Lockdown failed:', error);
24
+ (0, snaps_utils_1.logError)('Lockdown failed:', error);
20
25
  throw error;
21
26
  }
22
27
  }
23
-
28
+ exports.executeLockdown = executeLockdown;
24
29
  //# sourceMappingURL=lockdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockdown.js","sourceRoot":"","sources":["../../../src/common/lockdown/lockdown.ts"],"names":[],"mappings":";AAAA,qFAAqF;AACrF,mEAAmE;;;AAEnE,uDAAiD;AAEjD;;;;GAIG;AACH,SAAgB,eAAe;IAC7B,IAAI;QACF,QAAQ,CAAC;YACP,aAAa,EAAE,QAAQ;YACvB,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,QAAQ;YACpB,UAAU,EAAE,QAAQ;YACpB,cAAc,EAAE,QAAQ;SACzB,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,gFAAgF;QAChF,IAAA,sBAAQ,EAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACpC,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAdD,0CAcC","sourcesContent":["// eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment\n/// <reference path=\"../../../../../node_modules/ses/index.d.ts\" />\n\nimport { logError } from '@metamask/snaps-utils';\n\n/**\n * Execute SES lockdown in the current context, i.e., the current iframe.\n *\n * @throws If the SES lockdown failed.\n */\nexport function executeLockdown() {\n try {\n lockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n });\n } catch (error) {\n // If the `lockdown` call throws an exception, it should not be able to continue\n logError('Lockdown failed:', error);\n throw error;\n }\n}\n"]}
@@ -1,4 +1,7 @@
1
+ "use strict";
1
2
  // original source sortParamKeys from: https://github.com/etclabscore/sig.tools/blob/master/src/postMessageServer/postMessageServer.ts#L75-L77
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.sortParamKeys = void 0;
2
5
  /**
3
6
  * Deterministically sort JSON-RPC parameter keys. This makes it possible to
4
7
  * support both arrays and objects as parameters. Objects are sorted and turned
@@ -12,18 +15,21 @@
12
15
  * @returns The values for the sorted keys. If `params` is not provided, this
13
16
  * returns an empty array. If `params` is an array, this returns the same
14
17
  * `params`.
15
- */ export const sortParamKeys = (methodParams, params)=>{
18
+ */
19
+ const sortParamKeys = (methodParams, params) => {
16
20
  if (!params) {
17
21
  return [];
18
22
  }
19
23
  if (params instanceof Array) {
20
24
  return params;
21
25
  }
22
- const methodParamsOrder = methodParams.reduce((paramsOrderObj, paramsName, i)=>({
23
- ...paramsOrderObj,
24
- [paramsName]: i
25
- }), {});
26
- return Object.entries(params).sort(([name1, _1], [name2, _2])=>methodParamsOrder[name1] - methodParamsOrder[name2]).map(([_, val])=>val);
26
+ const methodParamsOrder = methodParams.reduce((paramsOrderObj, paramsName, i) => ({
27
+ ...paramsOrderObj,
28
+ [paramsName]: i,
29
+ }), {});
30
+ return Object.entries(params)
31
+ .sort(([name1, _1], [name2, _2]) => methodParamsOrder[name1] - methodParamsOrder[name2])
32
+ .map(([_, val]) => val);
27
33
  };
28
-
34
+ exports.sortParamKeys = sortParamKeys;
29
35
  //# sourceMappingURL=sortParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sortParams.js","sourceRoot":"","sources":["../../src/common/sortParams.ts"],"names":[],"mappings":";AAAA,8IAA8I;;;AAI9I;;;;;;;;;;;;;GAaG;AACI,MAAM,aAAa,GAAG,CAC3B,YAAsB,EACtB,MAAsB,EACtB,EAAE;IACF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,IAAI,MAAM,YAAY,KAAK,EAAE;QAC3B,OAAO,MAAM,CAAC;KACf;IAED,MAAM,iBAAiB,GAA4B,YAAY,CAAC,MAAM,CACpE,CAAC,cAAc,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAClC,GAAG,cAAc;QACjB,CAAC,UAAU,CAAC,EAAE,CAAC;KAChB,CAAC,EACF,EAAE,CACH,CAAC;IAEF,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;SAC1B,IAAI,CACH,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,CAC3B,iBAAiB,CAAC,KAAK,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CACtD;SACA,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC,CAAC;AA1BW,QAAA,aAAa,iBA0BxB","sourcesContent":["// original source sortParamKeys from: https://github.com/etclabscore/sig.tools/blob/master/src/postMessageServer/postMessageServer.ts#L75-L77\n\nimport { JsonRpcParams } from '@metamask/utils';\n\n/**\n * Deterministically sort JSON-RPC parameter keys. This makes it possible to\n * support both arrays and objects as parameters. Objects are sorted and turned\n * into arrays, for easier consumption by the snap.\n *\n * The order is defined by the `method` parameter.\n *\n * @param methodParams - The parameters of the JSON-RPC method, which\n * determines the ordering for the parameters.\n * @param params - JSON-RPC parameters as object or array.\n * @returns The values for the sorted keys. If `params` is not provided, this\n * returns an empty array. If `params` is an array, this returns the same\n * `params`.\n */\nexport const sortParamKeys = (\n methodParams: string[],\n params?: JsonRpcParams,\n) => {\n if (!params) {\n return [];\n }\n\n if (params instanceof Array) {\n return params;\n }\n\n const methodParamsOrder: { [k: string]: number } = methodParams.reduce(\n (paramsOrderObj, paramsName, i) => ({\n ...paramsOrderObj,\n [paramsName]: i,\n }),\n {},\n );\n\n return Object.entries(params)\n .sort(\n ([name1, _1], [name2, _2]) =>\n methodParamsOrder[name1] - methodParamsOrder[name2],\n )\n .map(([_, val]) => val);\n};\n"]}