@metamask/snaps-execution-environments 0.38.1-flask.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/CHANGELOG.md +283 -18
  2. package/dist/browserify/iframe/bundle.js +4 -6
  3. package/dist/browserify/node-process/bundle.js +2 -4
  4. package/dist/browserify/node-thread/bundle.js +2 -4
  5. package/dist/browserify/offscreen/bundle.js +3 -5
  6. package/dist/{types/common → common}/BaseSnapExecutor.d.ts +7 -7
  7. package/dist/common/BaseSnapExecutor.js +370 -0
  8. package/dist/common/BaseSnapExecutor.js.map +1 -0
  9. package/dist/{types/common → common}/commands.d.ts +2 -2
  10. package/dist/common/commands.js +65 -0
  11. package/dist/common/commands.js.map +1 -0
  12. package/dist/{types/common → common}/endowments/commonEndowmentFactory.d.ts +1 -5
  13. package/dist/common/endowments/commonEndowmentFactory.js +75 -0
  14. package/dist/common/endowments/commonEndowmentFactory.js.map +1 -0
  15. package/dist/{types/common → common}/endowments/crypto.d.ts +0 -4
  16. package/dist/common/endowments/crypto.js +28 -0
  17. package/dist/common/endowments/crypto.js.map +1 -0
  18. package/dist/{esm/common → common}/endowments/date.js +16 -20
  19. package/dist/common/endowments/date.js.map +1 -0
  20. package/dist/{types/common → common}/endowments/index.d.ts +3 -5
  21. package/dist/{esm/common → common}/endowments/index.js +36 -34
  22. package/dist/common/endowments/index.js.map +1 -0
  23. package/dist/{esm/common → common}/endowments/interval.js +12 -13
  24. package/dist/common/endowments/interval.js.map +1 -0
  25. package/dist/{esm/common → common}/endowments/math.js +15 -21
  26. package/dist/common/endowments/math.js.map +1 -0
  27. package/dist/common/endowments/network.js +170 -0
  28. package/dist/common/endowments/network.js.map +1 -0
  29. package/dist/common/endowments/textDecoder.js +18 -0
  30. package/dist/common/endowments/textDecoder.js.map +1 -0
  31. package/dist/common/endowments/textEncoder.js +18 -0
  32. package/dist/common/endowments/textEncoder.js.map +1 -0
  33. package/dist/{esm/common → common}/endowments/timeout.js +13 -14
  34. package/dist/common/endowments/timeout.js.map +1 -0
  35. package/dist/{types/common → common}/globalEvents.d.ts +0 -1
  36. package/dist/common/globalEvents.js +47 -0
  37. package/dist/common/globalEvents.js.map +1 -0
  38. package/dist/common/globalObject.js +50 -0
  39. package/dist/{cjs/common → common}/globalObject.js.map +1 -1
  40. package/dist/common/keyring.d.ts +12 -0
  41. package/dist/common/keyring.js +42 -0
  42. package/dist/common/keyring.js.map +1 -0
  43. package/dist/common/lockdown/lockdown-events.js +60 -0
  44. package/dist/common/lockdown/lockdown-events.js.map +1 -0
  45. package/dist/{esm/common → common}/lockdown/lockdown-more.js +23 -16
  46. package/dist/common/lockdown/lockdown-more.js.map +1 -0
  47. package/dist/{esm/common → common}/lockdown/lockdown.js +12 -7
  48. package/dist/common/lockdown/lockdown.js.map +1 -0
  49. package/dist/{types/common → common}/sortParams.d.ts +1 -1
  50. package/dist/{esm/common → common}/sortParams.js +13 -7
  51. package/dist/common/sortParams.js.map +1 -0
  52. package/dist/{types/common → common}/utils.d.ts +4 -5
  53. package/dist/{esm/common → common}/utils.js +56 -43
  54. package/dist/common/utils.js.map +1 -0
  55. package/dist/{types/common → common}/validation.d.ts +10 -2
  56. package/dist/common/validation.js +109 -0
  57. package/dist/common/validation.js.map +1 -0
  58. package/dist/{types/iframe → iframe}/IFrameSnapExecutor.d.ts +1 -1
  59. package/dist/iframe/IFrameSnapExecutor.js +42 -0
  60. package/dist/iframe/IFrameSnapExecutor.js.map +1 -0
  61. package/dist/iframe/index.js +10 -0
  62. package/dist/iframe/index.js.map +1 -0
  63. package/dist/logging.js +13 -0
  64. package/dist/logging.js.map +1 -0
  65. package/dist/node-process/ChildProcessSnapExecutor.js +30 -0
  66. package/dist/node-process/ChildProcessSnapExecutor.js.map +1 -0
  67. package/dist/node-process/index.js +8 -0
  68. package/dist/node-process/index.js.map +1 -0
  69. package/dist/node-thread/ThreadSnapExecutor.js +30 -0
  70. package/dist/node-thread/ThreadSnapExecutor.js.map +1 -0
  71. package/dist/node-thread/index.js +8 -0
  72. package/dist/node-thread/index.js.map +1 -0
  73. package/dist/{types/offscreen → offscreen}/OffscreenSnapExecutor.d.ts +1 -2
  74. package/dist/offscreen/OffscreenSnapExecutor.js +104 -0
  75. package/dist/offscreen/OffscreenSnapExecutor.js.map +1 -0
  76. package/dist/offscreen/index.js +16 -0
  77. package/dist/offscreen/index.js.map +1 -0
  78. package/dist/openrpc.json +210 -0
  79. package/package.json +34 -47
  80. package/dist/browserify/worker-executor/bundle.js +0 -12155
  81. package/dist/browserify/worker-pool/bundle.js +0 -12
  82. package/dist/browserify/worker-pool/index.html +0 -12150
  83. package/dist/cjs/common/BaseSnapExecutor.js +0 -423
  84. package/dist/cjs/common/BaseSnapExecutor.js.map +0 -1
  85. package/dist/cjs/common/commands.js +0 -67
  86. package/dist/cjs/common/commands.js.map +0 -1
  87. package/dist/cjs/common/endowments/commonEndowmentFactory.js +0 -147
  88. package/dist/cjs/common/endowments/commonEndowmentFactory.js.map +0 -1
  89. package/dist/cjs/common/endowments/console.js +0 -134
  90. package/dist/cjs/common/endowments/console.js.map +0 -1
  91. package/dist/cjs/common/endowments/crypto.js +0 -44
  92. package/dist/cjs/common/endowments/crypto.js.map +0 -1
  93. package/dist/cjs/common/endowments/date.js +0 -53
  94. package/dist/cjs/common/endowments/date.js.map +0 -1
  95. package/dist/cjs/common/endowments/index.js +0 -91
  96. package/dist/cjs/common/endowments/index.js.map +0 -1
  97. package/dist/cjs/common/endowments/interval.js +0 -61
  98. package/dist/cjs/common/endowments/interval.js.map +0 -1
  99. package/dist/cjs/common/endowments/math.js +0 -67
  100. package/dist/cjs/common/endowments/math.js.map +0 -1
  101. package/dist/cjs/common/endowments/network.js +0 -206
  102. package/dist/cjs/common/endowments/network.js.map +0 -1
  103. package/dist/cjs/common/endowments/textDecoder.js +0 -28
  104. package/dist/cjs/common/endowments/textDecoder.js.map +0 -1
  105. package/dist/cjs/common/endowments/textEncoder.js +0 -28
  106. package/dist/cjs/common/endowments/textEncoder.js.map +0 -1
  107. package/dist/cjs/common/endowments/timeout.js +0 -63
  108. package/dist/cjs/common/endowments/timeout.js.map +0 -1
  109. package/dist/cjs/common/globalEvents.js +0 -39
  110. package/dist/cjs/common/globalEvents.js.map +0 -1
  111. package/dist/cjs/common/globalObject.js +0 -53
  112. package/dist/cjs/common/lockdown/lockdown-events.js +0 -74
  113. package/dist/cjs/common/lockdown/lockdown-events.js.map +0 -1
  114. package/dist/cjs/common/lockdown/lockdown-more.js +0 -73
  115. package/dist/cjs/common/lockdown/lockdown-more.js.map +0 -1
  116. package/dist/cjs/common/lockdown/lockdown.js +0 -30
  117. package/dist/cjs/common/lockdown/lockdown.js.map +0 -1
  118. package/dist/cjs/common/sortParams.js +0 -26
  119. package/dist/cjs/common/sortParams.js.map +0 -1
  120. package/dist/cjs/common/utils.js +0 -132
  121. package/dist/cjs/common/utils.js.map +0 -1
  122. package/dist/cjs/common/validation.js +0 -94
  123. package/dist/cjs/common/validation.js.map +0 -1
  124. package/dist/cjs/iframe/IFrameSnapExecutor.js +0 -50
  125. package/dist/cjs/iframe/IFrameSnapExecutor.js.map +0 -1
  126. package/dist/cjs/iframe/index.js +0 -13
  127. package/dist/cjs/iframe/index.js.map +0 -1
  128. package/dist/cjs/logging.js +0 -15
  129. package/dist/cjs/logging.js.map +0 -1
  130. package/dist/cjs/node-process/ChildProcessSnapExecutor.js +0 -39
  131. package/dist/cjs/node-process/ChildProcessSnapExecutor.js.map +0 -1
  132. package/dist/cjs/node-process/index.js +0 -11
  133. package/dist/cjs/node-process/index.js.map +0 -1
  134. package/dist/cjs/node-thread/ThreadSnapExecutor.js +0 -39
  135. package/dist/cjs/node-thread/ThreadSnapExecutor.js.map +0 -1
  136. package/dist/cjs/node-thread/index.js +0 -11
  137. package/dist/cjs/node-thread/index.js.map +0 -1
  138. package/dist/cjs/offscreen/OffscreenSnapExecutor.js +0 -173
  139. package/dist/cjs/offscreen/OffscreenSnapExecutor.js.map +0 -1
  140. package/dist/cjs/offscreen/index.js +0 -19
  141. package/dist/cjs/offscreen/index.js.map +0 -1
  142. package/dist/cjs/webworker/executor/WebWorkerSnapExecutor.js +0 -45
  143. package/dist/cjs/webworker/executor/WebWorkerSnapExecutor.js.map +0 -1
  144. package/dist/cjs/webworker/executor/index.js +0 -13
  145. package/dist/cjs/webworker/executor/index.js.map +0 -1
  146. package/dist/cjs/webworker/pool/WebWorkerPool.js +0 -248
  147. package/dist/cjs/webworker/pool/WebWorkerPool.js.map +0 -1
  148. package/dist/cjs/webworker/pool/index.js +0 -13
  149. package/dist/cjs/webworker/pool/index.js.map +0 -1
  150. package/dist/esm/common/BaseSnapExecutor.js +0 -408
  151. package/dist/esm/common/BaseSnapExecutor.js.map +0 -1
  152. package/dist/esm/common/commands.js +0 -66
  153. package/dist/esm/common/commands.js.map +0 -1
  154. package/dist/esm/common/endowments/commonEndowmentFactory.js +0 -132
  155. package/dist/esm/common/endowments/commonEndowmentFactory.js.map +0 -1
  156. package/dist/esm/common/endowments/console.js +0 -116
  157. package/dist/esm/common/endowments/console.js.map +0 -1
  158. package/dist/esm/common/endowments/crypto.js +0 -26
  159. package/dist/esm/common/endowments/crypto.js.map +0 -1
  160. package/dist/esm/common/endowments/date.js.map +0 -1
  161. package/dist/esm/common/endowments/index.js.map +0 -1
  162. package/dist/esm/common/endowments/interval.js.map +0 -1
  163. package/dist/esm/common/endowments/math.js.map +0 -1
  164. package/dist/esm/common/endowments/network.js +0 -196
  165. package/dist/esm/common/endowments/network.js.map +0 -1
  166. package/dist/esm/common/endowments/textDecoder.js +0 -18
  167. package/dist/esm/common/endowments/textDecoder.js.map +0 -1
  168. package/dist/esm/common/endowments/textEncoder.js +0 -18
  169. package/dist/esm/common/endowments/textEncoder.js.map +0 -1
  170. package/dist/esm/common/endowments/timeout.js.map +0 -1
  171. package/dist/esm/common/globalEvents.js +0 -35
  172. package/dist/esm/common/globalEvents.js.map +0 -1
  173. package/dist/esm/common/globalObject.js +0 -36
  174. package/dist/esm/common/globalObject.js.map +0 -1
  175. package/dist/esm/common/lockdown/lockdown-events.js +0 -66
  176. package/dist/esm/common/lockdown/lockdown-events.js.map +0 -1
  177. package/dist/esm/common/lockdown/lockdown-more.js.map +0 -1
  178. package/dist/esm/common/lockdown/lockdown.js.map +0 -1
  179. package/dist/esm/common/sortParams.js.map +0 -1
  180. package/dist/esm/common/utils.js.map +0 -1
  181. package/dist/esm/common/validation.js +0 -69
  182. package/dist/esm/common/validation.js.map +0 -1
  183. package/dist/esm/iframe/IFrameSnapExecutor.js +0 -35
  184. package/dist/esm/iframe/IFrameSnapExecutor.js.map +0 -1
  185. package/dist/esm/iframe/index.js +0 -9
  186. package/dist/esm/iframe/index.js.map +0 -1
  187. package/dist/esm/logging.js +0 -10
  188. package/dist/esm/logging.js.map +0 -1
  189. package/dist/esm/node-process/ChildProcessSnapExecutor.js +0 -24
  190. package/dist/esm/node-process/ChildProcessSnapExecutor.js.map +0 -1
  191. package/dist/esm/node-process/index.js +0 -7
  192. package/dist/esm/node-process/index.js.map +0 -1
  193. package/dist/esm/node-thread/ThreadSnapExecutor.js +0 -24
  194. package/dist/esm/node-thread/ThreadSnapExecutor.js.map +0 -1
  195. package/dist/esm/node-thread/index.js +0 -7
  196. package/dist/esm/node-thread/index.js.map +0 -1
  197. package/dist/esm/offscreen/OffscreenSnapExecutor.js +0 -176
  198. package/dist/esm/offscreen/OffscreenSnapExecutor.js.map +0 -1
  199. package/dist/esm/offscreen/index.js +0 -15
  200. package/dist/esm/offscreen/index.js.map +0 -1
  201. package/dist/esm/webworker/executor/WebWorkerSnapExecutor.js +0 -30
  202. package/dist/esm/webworker/executor/WebWorkerSnapExecutor.js.map +0 -1
  203. package/dist/esm/webworker/executor/index.js +0 -9
  204. package/dist/esm/webworker/executor/index.js.map +0 -1
  205. package/dist/esm/webworker/pool/WebWorkerPool.js +0 -245
  206. package/dist/esm/webworker/pool/WebWorkerPool.js.map +0 -1
  207. package/dist/esm/webworker/pool/index.js +0 -9
  208. package/dist/esm/webworker/pool/index.js.map +0 -1
  209. package/dist/types/common/endowments/console.d.ts +0 -45
  210. package/dist/types/webworker/executor/WebWorkerSnapExecutor.d.ts +0 -13
  211. package/dist/types/webworker/executor/index.d.ts +0 -1
  212. package/dist/types/webworker/pool/WebWorkerPool.d.ts +0 -23
  213. package/dist/types/webworker/pool/index.d.ts +0 -1
  214. /package/dist/{types/common → common}/endowments/date.d.ts +0 -0
  215. /package/dist/{types/common → common}/endowments/interval.d.ts +0 -0
  216. /package/dist/{types/common → common}/endowments/math.d.ts +0 -0
  217. /package/dist/{types/common → common}/endowments/network.d.ts +0 -0
  218. /package/dist/{types/common → common}/endowments/textDecoder.d.ts +0 -0
  219. /package/dist/{types/common → common}/endowments/textEncoder.d.ts +0 -0
  220. /package/dist/{types/common → common}/endowments/timeout.d.ts +0 -0
  221. /package/dist/{types/common → common}/globalObject.d.ts +0 -0
  222. /package/dist/{types/common → common}/lockdown/lockdown-events.d.ts +0 -0
  223. /package/dist/{types/common → common}/lockdown/lockdown-more.d.ts +0 -0
  224. /package/dist/{types/common → common}/lockdown/lockdown.d.ts +0 -0
  225. /package/dist/{types/iframe → iframe}/index.d.ts +0 -0
  226. /package/dist/{types/logging.d.ts → logging.d.ts} +0 -0
  227. /package/dist/{types/node-process → node-process}/ChildProcessSnapExecutor.d.ts +0 -0
  228. /package/dist/{types/node-process → node-process}/index.d.ts +0 -0
  229. /package/dist/{types/node-thread → node-thread}/ThreadSnapExecutor.d.ts +0 -0
  230. /package/dist/{types/node-thread → node-thread}/index.d.ts +0 -0
  231. /package/dist/{types/offscreen → offscreen}/index.d.ts +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/commonEndowmentFactory.ts"],"sourcesContent":["import type { SnapId } from '@metamask/snaps-utils';\n\nimport { rootRealmGlobal } from '../globalObject';\nimport consoleEndowment from './console';\nimport crypto from './crypto';\nimport date from './date';\nimport interval from './interval';\nimport math from './math';\nimport network from './network';\nimport textDecoder from './textDecoder';\nimport textEncoder from './textEncoder';\nimport timeout from './timeout';\n\nexport type EndowmentFactoryOptions = {\n snapId?: SnapId;\n};\n\nexport type EndowmentFactory = {\n names: readonly string[];\n factory: (options?: EndowmentFactoryOptions) => { [key: string]: unknown };\n};\n\nexport type CommonEndowmentSpecification = {\n endowment: unknown;\n name: string;\n bind?: boolean;\n};\n\n// Array of common endowments\nconst commonEndowments: CommonEndowmentSpecification[] = [\n { endowment: AbortController, name: 'AbortController' },\n { endowment: AbortSignal, name: 'AbortSignal' },\n { endowment: ArrayBuffer, name: 'ArrayBuffer' },\n { endowment: atob, name: 'atob', bind: true },\n { endowment: BigInt, name: 'BigInt' },\n { endowment: BigInt64Array, name: 'BigInt64Array' },\n { endowment: BigUint64Array, name: 'BigUint64Array' },\n { endowment: btoa, name: 'btoa', bind: true },\n { endowment: DataView, name: 'DataView' },\n { endowment: Float32Array, name: 'Float32Array' },\n { endowment: Float64Array, name: 'Float64Array' },\n { endowment: Int8Array, name: 'Int8Array' },\n { endowment: Int16Array, name: 'Int16Array' },\n { endowment: Int32Array, name: 'Int32Array' },\n { endowment: Uint8Array, name: 'Uint8Array' },\n { endowment: Uint8ClampedArray, name: 'Uint8ClampedArray' },\n { endowment: Uint16Array, name: 'Uint16Array' },\n { endowment: Uint32Array, name: 'Uint32Array' },\n { endowment: URL, name: 'URL' },\n { endowment: WebAssembly, name: 'WebAssembly' },\n];\n\n/**\n * Creates a consolidated collection of common endowments.\n * This function will return factories for all common endowments including\n * the additionally attenuated. All hardened with SES.\n *\n * @returns An object with common endowments.\n */\nconst buildCommonEndowments = (): EndowmentFactory[] => {\n const endowmentFactories: EndowmentFactory[] = [\n crypto,\n interval,\n math,\n network,\n timeout,\n textDecoder,\n textEncoder,\n date,\n consoleEndowment,\n ];\n\n commonEndowments.forEach((endowmentSpecification) => {\n const endowment = {\n names: [endowmentSpecification.name] as const,\n factory: () => {\n const boundEndowment =\n typeof endowmentSpecification.endowment === 'function' &&\n endowmentSpecification.bind\n ? endowmentSpecification.endowment.bind(rootRealmGlobal)\n : endowmentSpecification.endowment;\n return {\n [endowmentSpecification.name]: harden(boundEndowment),\n } as const;\n },\n };\n endowmentFactories.push(endowment);\n });\n\n return endowmentFactories;\n};\n\nexport default buildCommonEndowments;\n"],"names":["rootRealmGlobal","consoleEndowment","crypto","date","interval","math","network","textDecoder","textEncoder","timeout","commonEndowments","endowment","AbortController","name","AbortSignal","ArrayBuffer","atob","bind","BigInt","BigInt64Array","BigUint64Array","btoa","DataView","Float32Array","Float64Array","Int8Array","Int16Array","Int32Array","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","URL","WebAssembly","buildCommonEndowments","endowmentFactories","forEach","endowmentSpecification","names","factory","boundEndowment","harden","push"],"mappings":"AAEA,SAASA,eAAe,QAAQ,kBAAkB;AAClD,OAAOC,sBAAsB,YAAY;AACzC,OAAOC,YAAY,WAAW;AAC9B,OAAOC,UAAU,SAAS;AAC1B,OAAOC,cAAc,aAAa;AAClC,OAAOC,UAAU,SAAS;AAC1B,OAAOC,aAAa,YAAY;AAChC,OAAOC,iBAAiB,gBAAgB;AACxC,OAAOC,iBAAiB,gBAAgB;AACxC,OAAOC,aAAa,YAAY;AAiBhC,6BAA6B;AAC7B,MAAMC,mBAAmD;IACvD;QAAEC,WAAWC;QAAiBC,MAAM;IAAkB;IACtD;QAAEF,WAAWG;QAAaD,MAAM;IAAc;IAC9C;QAAEF,WAAWI;QAAaF,MAAM;IAAc;IAC9C;QAAEF,WAAWK;QAAMH,MAAM;QAAQI,MAAM;IAAK;IAC5C;QAAEN,WAAWO;QAAQL,MAAM;IAAS;IACpC;QAAEF,WAAWQ;QAAeN,MAAM;IAAgB;IAClD;QAAEF,WAAWS;QAAgBP,MAAM;IAAiB;IACpD;QAAEF,WAAWU;QAAMR,MAAM;QAAQI,MAAM;IAAK;IAC5C;QAAEN,WAAWW;QAAUT,MAAM;IAAW;IACxC;QAAEF,WAAWY;QAAcV,MAAM;IAAe;IAChD;QAAEF,WAAWa;QAAcX,MAAM;IAAe;IAChD;QAAEF,WAAWc;QAAWZ,MAAM;IAAY;IAC1C;QAAEF,WAAWe;QAAYb,MAAM;IAAa;IAC5C;QAAEF,WAAWgB;QAAYd,MAAM;IAAa;IAC5C;QAAEF,WAAWiB;QAAYf,MAAM;IAAa;IAC5C;QAAEF,WAAWkB;QAAmBhB,MAAM;IAAoB;IAC1D;QAAEF,WAAWmB;QAAajB,MAAM;IAAc;IAC9C;QAAEF,WAAWoB;QAAalB,MAAM;IAAc;IAC9C;QAAEF,WAAWqB;QAAKnB,MAAM;IAAM;IAC9B;QAAEF,WAAWsB;QAAapB,MAAM;IAAc;CAC/C;AAED;;;;;;CAMC,GACD,MAAMqB,wBAAwB;IAC5B,MAAMC,qBAAyC;QAC7CjC;QACAE;QACAC;QACAC;QACAG;QACAF;QACAC;QACAL;QACAF;KACD;IAEDS,iBAAiB0B,OAAO,CAAC,CAACC;QACxB,MAAM1B,YAAY;YAChB2B,OAAO;gBAACD,uBAAuBxB,IAAI;aAAC;YACpC0B,SAAS;gBACP,MAAMC,iBACJ,OAAOH,uBAAuB1B,SAAS,KAAK,cAC5C0B,uBAAuBpB,IAAI,GACvBoB,uBAAuB1B,SAAS,CAACM,IAAI,CAACjB,mBACtCqC,uBAAuB1B,SAAS;gBACtC,OAAO;oBACL,CAAC0B,uBAAuBxB,IAAI,CAAC,EAAE4B,OAAOD;gBACxC;YACF;QACF;QACAL,mBAAmBO,IAAI,CAAC/B;IAC1B;IAEA,OAAOwB;AACT;AAEA,eAAeD,sBAAsB"}
@@ -1,116 +0,0 @@
1
- import { assert } from '@metamask/utils';
2
- import { rootRealmGlobal } from '../globalObject';
3
- export const consoleAttenuatedMethods = new Set([
4
- 'log',
5
- 'assert',
6
- 'error',
7
- 'debug',
8
- 'info',
9
- 'warn'
10
- ]);
11
- /**
12
- * A set of all the `console` values that will be passed to the snap. This has
13
- * all the values that are available in both the browser and Node.js.
14
- */ export const consoleMethods = new Set([
15
- 'debug',
16
- 'error',
17
- 'info',
18
- 'log',
19
- 'warn',
20
- 'dir',
21
- 'dirxml',
22
- 'table',
23
- 'trace',
24
- 'group',
25
- 'groupCollapsed',
26
- 'groupEnd',
27
- 'clear',
28
- 'count',
29
- 'countReset',
30
- 'assert',
31
- 'profile',
32
- 'profileEnd',
33
- 'time',
34
- 'timeLog',
35
- 'timeEnd',
36
- 'timeStamp',
37
- 'context'
38
- ]);
39
- const consoleFunctions = [
40
- 'log',
41
- 'error',
42
- 'debug',
43
- 'info',
44
- 'warn'
45
- ];
46
- /**
47
- * Gets the appropriate (prepended) message to pass to one of the attenuated
48
- * method calls.
49
- *
50
- * @param snapId - Id of the snap that we're getting a message for.
51
- * @param message - The id of the snap that will interact with the endowment.
52
- * @param args - The array of additional arguments.
53
- * @returns An array of arguments to be passed into an attenuated console method call.
54
- */ function getMessage(snapId, message, ...args) {
55
- const prefix = `[Snap: ${snapId}]`;
56
- // If the first argument is a string, prepend the prefix to the message, and keep the
57
- // rest of the arguments as-is.
58
- if (typeof message === 'string') {
59
- return [
60
- `${prefix} ${message}`,
61
- ...args
62
- ];
63
- }
64
- // Otherwise, the `message` is an object, array, etc., so add the prefix as a separate
65
- // message to the arguments.
66
- return [
67
- prefix,
68
- message,
69
- ...args
70
- ];
71
- }
72
- /**
73
- * Create a a {@link console} object, with the same properties as the global
74
- * {@link console} object, but with some methods replaced.
75
- *
76
- * @param options - Factory options used in construction of the endowment.
77
- * @param options.snapId - The id of the snap that will interact with the endowment.
78
- * @returns The {@link console} object with the replaced methods.
79
- */ function createConsole({ snapId } = {}) {
80
- assert(snapId !== undefined);
81
- const keys = Object.getOwnPropertyNames(rootRealmGlobal.console);
82
- const attenuatedConsole = keys.reduce((target, key)=>{
83
- if (consoleMethods.has(key) && !consoleAttenuatedMethods.has(key)) {
84
- return {
85
- ...target,
86
- [key]: rootRealmGlobal.console[key]
87
- };
88
- }
89
- return target;
90
- }, {});
91
- return harden({
92
- console: {
93
- ...attenuatedConsole,
94
- assert: (value, message, ...optionalParams)=>{
95
- rootRealmGlobal.console.assert(value, ...getMessage(snapId, message, ...optionalParams));
96
- },
97
- ...consoleFunctions.reduce((target, key)=>{
98
- return {
99
- ...target,
100
- [key]: (message, ...optionalParams)=>{
101
- rootRealmGlobal.console[key](...getMessage(snapId, message, ...optionalParams));
102
- }
103
- };
104
- }, {})
105
- }
106
- });
107
- }
108
- const endowmentModule = {
109
- names: [
110
- 'console'
111
- ],
112
- factory: createConsole
113
- };
114
- export default endowmentModule;
115
-
116
- //# sourceMappingURL=console.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/console.ts"],"sourcesContent":["import type { SnapId } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\n\nimport { rootRealmGlobal } from '../globalObject';\nimport type { EndowmentFactoryOptions } from './commonEndowmentFactory';\n\nexport const consoleAttenuatedMethods = new Set([\n 'log',\n 'assert',\n 'error',\n 'debug',\n 'info',\n 'warn',\n]);\n\n/**\n * A set of all the `console` values that will be passed to the snap. This has\n * all the values that are available in both the browser and Node.js.\n */\nexport const consoleMethods = new Set([\n 'debug',\n 'error',\n 'info',\n 'log',\n 'warn',\n 'dir',\n 'dirxml',\n 'table',\n 'trace',\n 'group',\n 'groupCollapsed',\n 'groupEnd',\n 'clear',\n 'count',\n 'countReset',\n 'assert',\n 'profile',\n 'profileEnd',\n 'time',\n 'timeLog',\n 'timeEnd',\n 'timeStamp',\n 'context',\n]);\n\nconst consoleFunctions = ['log', 'error', 'debug', 'info', 'warn'] as const;\n\ntype ConsoleFunctions = {\n [Key in typeof consoleFunctions[number]]: typeof rootRealmGlobal.console[Key];\n};\n\n/**\n * Gets the appropriate (prepended) message to pass to one of the attenuated\n * method calls.\n *\n * @param snapId - Id of the snap that we're getting a message for.\n * @param message - The id of the snap that will interact with the endowment.\n * @param args - The array of additional arguments.\n * @returns An array of arguments to be passed into an attenuated console method call.\n */\nfunction getMessage(snapId: SnapId, message: unknown, ...args: unknown[]) {\n const prefix = `[Snap: ${snapId}]`;\n\n // If the first argument is a string, prepend the prefix to the message, and keep the\n // rest of the arguments as-is.\n if (typeof message === 'string') {\n return [`${prefix} ${message}`, ...args];\n }\n\n // Otherwise, the `message` is an object, array, etc., so add the prefix as a separate\n // message to the arguments.\n return [prefix, message, ...args];\n}\n\n/**\n * Create a a {@link console} object, with the same properties as the global\n * {@link console} object, but with some methods replaced.\n *\n * @param options - Factory options used in construction of the endowment.\n * @param options.snapId - The id of the snap that will interact with the endowment.\n * @returns The {@link console} object with the replaced methods.\n */\nfunction createConsole({ snapId }: EndowmentFactoryOptions = {}) {\n assert(snapId !== undefined);\n const keys = Object.getOwnPropertyNames(\n rootRealmGlobal.console,\n ) as (keyof typeof console)[];\n\n const attenuatedConsole = keys.reduce((target, key) => {\n if (consoleMethods.has(key) && !consoleAttenuatedMethods.has(key)) {\n return { ...target, [key]: rootRealmGlobal.console[key] };\n }\n\n return target;\n }, {});\n\n return harden({\n console: {\n ...attenuatedConsole,\n assert: (\n value: any,\n message?: string | undefined,\n ...optionalParams: any[]\n ) => {\n rootRealmGlobal.console.assert(\n value,\n ...getMessage(snapId, message, ...optionalParams),\n );\n },\n ...consoleFunctions.reduce<ConsoleFunctions>((target, key) => {\n return {\n ...target,\n [key]: (message?: unknown, ...optionalParams: any[]) => {\n rootRealmGlobal.console[key](\n ...getMessage(snapId, message, ...optionalParams),\n );\n },\n };\n }, {} as ConsoleFunctions),\n },\n });\n}\n\nconst endowmentModule = {\n names: ['console'] as const,\n factory: createConsole,\n};\n\nexport default endowmentModule;\n"],"names":["assert","rootRealmGlobal","consoleAttenuatedMethods","Set","consoleMethods","consoleFunctions","getMessage","snapId","message","args","prefix","createConsole","undefined","keys","Object","getOwnPropertyNames","console","attenuatedConsole","reduce","target","key","has","harden","value","optionalParams","endowmentModule","names","factory"],"mappings":"AACA,SAASA,MAAM,QAAQ,kBAAkB;AAEzC,SAASC,eAAe,QAAQ,kBAAkB;AAGlD,OAAO,MAAMC,2BAA2B,IAAIC,IAAI;IAC9C;IACA;IACA;IACA;IACA;IACA;CACD,EAAE;AAEH;;;CAGC,GACD,OAAO,MAAMC,iBAAiB,IAAID,IAAI;IACpC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,EAAE;AAEH,MAAME,mBAAmB;IAAC;IAAO;IAAS;IAAS;IAAQ;CAAO;AAMlE;;;;;;;;CAQC,GACD,SAASC,WAAWC,MAAc,EAAEC,OAAgB,EAAE,GAAGC,IAAe;IACtE,MAAMC,SAAS,CAAC,OAAO,EAAEH,OAAO,CAAC,CAAC;IAElC,qFAAqF;IACrF,+BAA+B;IAC/B,IAAI,OAAOC,YAAY,UAAU;QAC/B,OAAO;YAAC,CAAC,EAAEE,OAAO,CAAC,EAAEF,QAAQ,CAAC;eAAKC;SAAK;IAC1C;IAEA,sFAAsF;IACtF,4BAA4B;IAC5B,OAAO;QAACC;QAAQF;WAAYC;KAAK;AACnC;AAEA;;;;;;;CAOC,GACD,SAASE,cAAc,EAAEJ,MAAM,EAA2B,GAAG,CAAC,CAAC;IAC7DP,OAAOO,WAAWK;IAClB,MAAMC,OAAOC,OAAOC,mBAAmB,CACrCd,gBAAgBe,OAAO;IAGzB,MAAMC,oBAAoBJ,KAAKK,MAAM,CAAC,CAACC,QAAQC;QAC7C,IAAIhB,eAAeiB,GAAG,CAACD,QAAQ,CAAClB,yBAAyBmB,GAAG,CAACD,MAAM;YACjE,OAAO;gBAAE,GAAGD,MAAM;gBAAE,CAACC,IAAI,EAAEnB,gBAAgBe,OAAO,CAACI,IAAI;YAAC;QAC1D;QAEA,OAAOD;IACT,GAAG,CAAC;IAEJ,OAAOG,OAAO;QACZN,SAAS;YACP,GAAGC,iBAAiB;YACpBjB,QAAQ,CACNuB,OACAf,SACA,GAAGgB;gBAEHvB,gBAAgBe,OAAO,CAAChB,MAAM,CAC5BuB,UACGjB,WAAWC,QAAQC,YAAYgB;YAEtC;YACA,GAAGnB,iBAAiBa,MAAM,CAAmB,CAACC,QAAQC;gBACpD,OAAO;oBACL,GAAGD,MAAM;oBACT,CAACC,IAAI,EAAE,CAACZ,SAAmB,GAAGgB;wBAC5BvB,gBAAgBe,OAAO,CAACI,IAAI,IACvBd,WAAWC,QAAQC,YAAYgB;oBAEtC;gBACF;YACF,GAAG,CAAC,EAAsB;QAC5B;IACF;AACF;AAEA,MAAMC,kBAAkB;IACtBC,OAAO;QAAC;KAAU;IAClBC,SAAShB;AACX;AAEA,eAAec,gBAAgB"}
@@ -1,26 +0,0 @@
1
- import { rootRealmGlobal } from '../globalObject';
2
- export const createCrypto = ()=>{
3
- if ('crypto' in rootRealmGlobal && typeof rootRealmGlobal.crypto === 'object' && 'SubtleCrypto' in rootRealmGlobal && typeof rootRealmGlobal.SubtleCrypto === 'function') {
4
- return {
5
- crypto: harden(rootRealmGlobal.crypto),
6
- SubtleCrypto: harden(rootRealmGlobal.SubtleCrypto)
7
- };
8
- }
9
- // For now, we expose the experimental webcrypto API for Node.js execution environments
10
- // TODO: Figure out if this is enough long-term or if we should use a polyfill.
11
- /* eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */ const crypto = require('crypto').webcrypto;
12
- return {
13
- crypto: harden(crypto),
14
- SubtleCrypto: harden(crypto.subtle.constructor)
15
- };
16
- };
17
- const endowmentModule = {
18
- names: [
19
- 'crypto',
20
- 'SubtleCrypto'
21
- ],
22
- factory: createCrypto
23
- };
24
- export default endowmentModule;
25
-
26
- //# sourceMappingURL=crypto.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/crypto.ts"],"sourcesContent":["import { rootRealmGlobal } from '../globalObject';\n\nexport const createCrypto = () => {\n if (\n 'crypto' in rootRealmGlobal &&\n typeof rootRealmGlobal.crypto === 'object' &&\n 'SubtleCrypto' in rootRealmGlobal &&\n typeof rootRealmGlobal.SubtleCrypto === 'function'\n ) {\n return {\n crypto: harden(rootRealmGlobal.crypto),\n SubtleCrypto: harden(rootRealmGlobal.SubtleCrypto),\n };\n }\n // For now, we expose the experimental webcrypto API for Node.js execution environments\n // TODO: Figure out if this is enough long-term or if we should use a polyfill.\n /* eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n const crypto = require('crypto').webcrypto;\n return {\n crypto: harden(crypto),\n SubtleCrypto: harden(crypto.subtle.constructor),\n } as const;\n};\n\nconst endowmentModule = {\n names: ['crypto', 'SubtleCrypto'] as const,\n factory: createCrypto,\n};\nexport default endowmentModule;\n"],"names":["rootRealmGlobal","createCrypto","crypto","SubtleCrypto","harden","require","webcrypto","subtle","constructor","endowmentModule","names","factory"],"mappings":"AAAA,SAASA,eAAe,QAAQ,kBAAkB;AAElD,OAAO,MAAMC,eAAe;IAC1B,IACE,YAAYD,mBACZ,OAAOA,gBAAgBE,MAAM,KAAK,YAClC,kBAAkBF,mBAClB,OAAOA,gBAAgBG,YAAY,KAAK,YACxC;QACA,OAAO;YACLD,QAAQE,OAAOJ,gBAAgBE,MAAM;YACrCC,cAAcC,OAAOJ,gBAAgBG,YAAY;QACnD;IACF;IACA,uFAAuF;IACvF,+EAA+E;IAC/E,wHAAwH,GACxH,MAAMD,SAASG,QAAQ,UAAUC,SAAS;IAC1C,OAAO;QACLJ,QAAQE,OAAOF;QACfC,cAAcC,OAAOF,OAAOK,MAAM,CAACC,WAAW;IAChD;AACF,EAAE;AAEF,MAAMC,kBAAkB;IACtBC,OAAO;QAAC;QAAU;KAAe;IACjCC,SAASV;AACX;AACA,eAAeQ,gBAAgB"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/date.ts"],"sourcesContent":["import { rootRealmGlobal } from '../globalObject';\n\n/**\n * Creates a {@link Date} constructor, with most of the same properties as the global object.\n * The Date.now() function has added noise as to limit its precision and prevent potential timing attacks.\n * The Date constructor uses this now() function to seed itself if no arguments are given to the constructor.\n *\n * @returns A modified {@link Date} constructor with limited precision.\n */\nfunction createDate() {\n const keys = Object.getOwnPropertyNames(\n rootRealmGlobal.Date,\n ) as (keyof typeof Date)[];\n\n let currentTime = 0;\n const now = () => {\n const actual = rootRealmGlobal.Date.now();\n const newTime = Math.round(actual + Math.random());\n if (newTime > currentTime) {\n currentTime = newTime;\n }\n return currentTime;\n };\n\n const NewDate = function (...args: unknown[]) {\n return Reflect.construct(\n rootRealmGlobal.Date,\n args.length === 0 ? [now()] : args,\n new.target,\n );\n } as DateConstructor;\n\n keys.forEach((key) => {\n Reflect.defineProperty(NewDate, key, {\n configurable: false,\n writable: false,\n value: key === 'now' ? now : rootRealmGlobal.Date[key],\n });\n });\n\n return { Date: harden(NewDate) };\n}\n\nconst endowmentModule = {\n names: ['Date'] as const,\n factory: createDate,\n};\n\nexport default endowmentModule;\n"],"names":["rootRealmGlobal","createDate","keys","Object","getOwnPropertyNames","Date","currentTime","now","actual","newTime","Math","round","random","NewDate","args","Reflect","construct","length","forEach","key","defineProperty","configurable","writable","value","harden","endowmentModule","names","factory"],"mappings":"AAAA,SAASA,eAAe,QAAQ,kBAAkB;AAElD;;;;;;CAMC,GACD,SAASC;IACP,MAAMC,OAAOC,OAAOC,mBAAmB,CACrCJ,gBAAgBK,IAAI;IAGtB,IAAIC,cAAc;IAClB,MAAMC,MAAM;QACV,MAAMC,SAASR,gBAAgBK,IAAI,CAACE,GAAG;QACvC,MAAME,UAAUC,KAAKC,KAAK,CAACH,SAASE,KAAKE,MAAM;QAC/C,IAAIH,UAAUH,aAAa;YACzBA,cAAcG;QAChB;QACA,OAAOH;IACT;IAEA,MAAMO,UAAU,SAAU,GAAGC,IAAe;QAC1C,OAAOC,QAAQC,SAAS,CACtBhB,gBAAgBK,IAAI,EACpBS,KAAKG,MAAM,KAAK,IAAI;YAACV;SAAM,GAAGO,MAC9B;IAEJ;IAEAZ,KAAKgB,OAAO,CAAC,CAACC;QACZJ,QAAQK,cAAc,CAACP,SAASM,KAAK;YACnCE,cAAc;YACdC,UAAU;YACVC,OAAOJ,QAAQ,QAAQZ,MAAMP,gBAAgBK,IAAI,CAACc,IAAI;QACxD;IACF;IAEA,OAAO;QAAEd,MAAMmB,OAAOX;IAAS;AACjC;AAEA,MAAMY,kBAAkB;IACtBC,OAAO;QAAC;KAAO;IACfC,SAAS1B;AACX;AAEA,eAAewB,gBAAgB"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/index.ts"],"sourcesContent":["import type { StreamProvider } from '@metamask/providers';\nimport type { SnapsGlobalObject } from '@metamask/rpc-methods';\nimport type { SnapId } from '@metamask/snaps-utils';\nimport { logWarning } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\n\nimport { rootRealmGlobal } from '../globalObject';\nimport type { EndowmentFactoryOptions } from './commonEndowmentFactory';\nimport buildCommonEndowments from './commonEndowmentFactory';\n\ntype EndowmentFactoryResult = {\n /**\n * A function that performs any necessary teardown when the snap becomes idle.\n *\n * NOTE:** The endowments are not reconstructed if the snap is re-invoked\n * before being terminated, so the teardown operation must not render the\n * endowments unusable; it should simply restore the endowments to their\n * original state.\n */\n teardownFunction?: () => Promise<void> | void;\n [key: string]: unknown;\n};\n\n/**\n * Retrieve consolidated endowment factories for common endowments.\n */\nconst registeredEndowments = buildCommonEndowments();\n\n/**\n * A map of endowment names to their factory functions. Some endowments share\n * the same factory function, but we only call each factory once for each snap.\n * See {@link createEndowments} for details.\n */\nconst endowmentFactories = registeredEndowments.reduce((factories, builder) => {\n builder.names.forEach((name) => {\n factories.set(name, builder.factory);\n });\n return factories;\n}, new Map<string, (options?: EndowmentFactoryOptions) => EndowmentFactoryResult>());\n\n/**\n * Gets the endowments for a particular Snap. Some endowments, like `setTimeout`\n * and `clearTimeout`, must be attenuated so that they can only affect behavior\n * within the Snap's own realm. Therefore, we use factory functions to create\n * such attenuated / modified endowments. Otherwise, the value that's on the\n * root realm global will be used.\n *\n * @param snap - The Snaps global API object.\n * @param ethereum - The Snap's EIP-1193 provider object.\n * @param snapId - The id of the snap that will use the created endowments.\n * @param endowments - The list of endowments to provide to the snap.\n * @returns An object containing the Snap's endowments.\n */\nexport function createEndowments(\n snap: SnapsGlobalObject,\n ethereum: StreamProvider,\n snapId: SnapId,\n endowments: string[] = [],\n): { endowments: Record<string, unknown>; teardown: () => Promise<void> } {\n const attenuatedEndowments: Record<string, unknown> = {};\n\n // TODO: All endowments should be hardened to prevent covert communication\n // channels. Hardening the returned objects breaks tests elsewhere in the\n // monorepo, so further research is needed.\n const result = endowments.reduce<{\n allEndowments: Record<string, unknown>;\n teardowns: (() => Promise<void> | void)[];\n }>(\n ({ allEndowments, teardowns }, endowmentName) => {\n // First, check if the endowment has a factory, and default to that.\n if (endowmentFactories.has(endowmentName)) {\n if (!hasProperty(attenuatedEndowments, endowmentName)) {\n // Call the endowment factory for the current endowment. If the factory\n // creates multiple endowments, they will all be assigned to the\n // `attenuatedEndowments` object, but will only be passed on to the snap\n // if explicitly listed among its endowment.\n // This may not have an actual use case, but, safety first.\n\n // We just confirmed that endowmentFactories has the specified key.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { teardownFunction, ...endowment } = endowmentFactories.get(\n endowmentName,\n )!({ snapId });\n Object.assign(attenuatedEndowments, endowment);\n if (teardownFunction) {\n teardowns.push(teardownFunction);\n }\n }\n allEndowments[endowmentName] = attenuatedEndowments[endowmentName];\n } else if (endowmentName === 'ethereum') {\n // Special case for adding the EIP-1193 provider.\n allEndowments[endowmentName] = ethereum;\n } else if (endowmentName in rootRealmGlobal) {\n logWarning(`Access to unhardened global ${endowmentName}.`);\n // If the endowment doesn't have a factory, just use whatever is on the\n // global object.\n const globalValue = (rootRealmGlobal as Record<string, unknown>)[\n endowmentName\n ];\n allEndowments[endowmentName] = globalValue;\n } else {\n // If we get to this point, we've been passed an endowment that doesn't\n // exist in our current environment.\n throw new Error(`Unknown endowment: \"${endowmentName}\".`);\n }\n return { allEndowments, teardowns };\n },\n {\n allEndowments: { snap },\n teardowns: [],\n },\n );\n\n const teardown = async () => {\n await Promise.all(\n result.teardowns.map((teardownFunction) => teardownFunction()),\n );\n };\n return { endowments: result.allEndowments, teardown };\n}\n"],"names":["logWarning","hasProperty","rootRealmGlobal","buildCommonEndowments","registeredEndowments","endowmentFactories","reduce","factories","builder","names","forEach","name","set","factory","Map","createEndowments","snap","ethereum","snapId","endowments","attenuatedEndowments","result","allEndowments","teardowns","endowmentName","has","teardownFunction","endowment","get","Object","assign","push","globalValue","Error","teardown","Promise","all","map"],"mappings":"AAGA,SAASA,UAAU,QAAQ,wBAAwB;AACnD,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,SAASC,eAAe,QAAQ,kBAAkB;AAElD,OAAOC,2BAA2B,2BAA2B;AAe7D;;CAEC,GACD,MAAMC,uBAAuBD;AAE7B;;;;CAIC,GACD,MAAME,qBAAqBD,qBAAqBE,MAAM,CAAC,CAACC,WAAWC;IACjEA,QAAQC,KAAK,CAACC,OAAO,CAAC,CAACC;QACrBJ,UAAUK,GAAG,CAACD,MAAMH,QAAQK,OAAO;IACrC;IACA,OAAON;AACT,GAAG,IAAIO;AAEP;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,iBACdC,IAAuB,EACvBC,QAAwB,EACxBC,MAAc,EACdC,aAAuB,EAAE;IAEzB,MAAMC,uBAAgD,CAAC;IAEvD,0EAA0E;IAC1E,yEAAyE;IACzE,2CAA2C;IAC3C,MAAMC,SAASF,WAAWb,MAAM,CAI9B,CAAC,EAAEgB,aAAa,EAAEC,SAAS,EAAE,EAAEC;QAC7B,oEAAoE;QACpE,IAAInB,mBAAmBoB,GAAG,CAACD,gBAAgB;YACzC,IAAI,CAACvB,YAAYmB,sBAAsBI,gBAAgB;gBACrD,uEAAuE;gBACvE,gEAAgE;gBAChE,wEAAwE;gBACxE,4CAA4C;gBAC5C,2DAA2D;gBAE3D,mEAAmE;gBACnE,oEAAoE;gBACpE,MAAM,EAAEE,gBAAgB,EAAE,GAAGC,WAAW,GAAGtB,mBAAmBuB,GAAG,CAC/DJ,eACC;oBAAEN;gBAAO;gBACZW,OAAOC,MAAM,CAACV,sBAAsBO;gBACpC,IAAID,kBAAkB;oBACpBH,UAAUQ,IAAI,CAACL;gBACjB;YACF;YACAJ,aAAa,CAACE,cAAc,GAAGJ,oBAAoB,CAACI,cAAc;QACpE,OAAO,IAAIA,kBAAkB,YAAY;YACvC,iDAAiD;YACjDF,aAAa,CAACE,cAAc,GAAGP;QACjC,OAAO,IAAIO,iBAAiBtB,iBAAiB;YAC3CF,WAAW,CAAC,4BAA4B,EAAEwB,cAAc,CAAC,CAAC;YAC1D,uEAAuE;YACvE,iBAAiB;YACjB,MAAMQ,cAAc,AAAC9B,eAA2C,CAC9DsB,cACD;YACDF,aAAa,CAACE,cAAc,GAAGQ;QACjC,OAAO;YACL,uEAAuE;YACvE,oCAAoC;YACpC,MAAM,IAAIC,MAAM,CAAC,oBAAoB,EAAET,cAAc,EAAE,CAAC;QAC1D;QACA,OAAO;YAAEF;YAAeC;QAAU;IACpC,GACA;QACED,eAAe;YAAEN;QAAK;QACtBO,WAAW,EAAE;IACf;IAGF,MAAMW,WAAW;QACf,MAAMC,QAAQC,GAAG,CACff,OAAOE,SAAS,CAACc,GAAG,CAAC,CAACX,mBAAqBA;IAE/C;IACA,OAAO;QAAEP,YAAYE,OAAOC,aAAa;QAAEY;IAAS;AACtD"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/interval.ts"],"sourcesContent":["const MINIMUM_INTERVAL = 10;\n\n/**\n * Creates a pair of `setInterval` and `clearInterval` functions attenuated such\n * that:\n * - `setInterval` throws if its \"handler\" parameter is not a function.\n * - `clearInterval` only clears timeouts created by its sibling `setInterval`,\n * or else no-ops.\n *\n * @returns An object with the attenuated `setInterval` and `clearInterval`\n * functions.\n */\nconst createInterval = () => {\n const registeredHandles = new Map<unknown, unknown>();\n\n const _setInterval = (handler: TimerHandler, timeout?: number): unknown => {\n if (typeof handler !== 'function') {\n throw new Error(\n `The interval handler must be a function. Received: ${typeof handler}`,\n );\n }\n harden(handler);\n const handle = Object.freeze(Object.create(null));\n const platformHandle = setInterval(\n handler,\n Math.max(MINIMUM_INTERVAL, timeout ?? 0),\n );\n registeredHandles.set(handle, platformHandle);\n return handle;\n };\n\n const _clearInterval = (handle: unknown): void => {\n harden(handle);\n const platformHandle = registeredHandles.get(handle);\n if (platformHandle !== undefined) {\n clearInterval(platformHandle as any);\n registeredHandles.delete(handle);\n }\n };\n\n const teardownFunction = (): void => {\n for (const handle of registeredHandles.keys()) {\n _clearInterval(handle);\n }\n };\n\n return {\n setInterval: harden(_setInterval),\n clearInterval: harden(_clearInterval),\n teardownFunction,\n } as const;\n};\n\nconst endowmentModule = {\n names: ['setInterval', 'clearInterval'] as const,\n factory: createInterval,\n};\nexport default endowmentModule;\n"],"names":["MINIMUM_INTERVAL","createInterval","registeredHandles","Map","_setInterval","handler","timeout","Error","harden","handle","Object","freeze","create","platformHandle","setInterval","Math","max","set","_clearInterval","get","undefined","clearInterval","delete","teardownFunction","keys","endowmentModule","names","factory"],"mappings":"AAAA,MAAMA,mBAAmB;AAEzB;;;;;;;;;CASC,GACD,MAAMC,iBAAiB;IACrB,MAAMC,oBAAoB,IAAIC;IAE9B,MAAMC,eAAe,CAACC,SAAuBC;QAC3C,IAAI,OAAOD,YAAY,YAAY;YACjC,MAAM,IAAIE,MACR,CAAC,mDAAmD,EAAE,OAAOF,QAAQ,CAAC;QAE1E;QACAG,OAAOH;QACP,MAAMI,SAASC,OAAOC,MAAM,CAACD,OAAOE,MAAM,CAAC;QAC3C,MAAMC,iBAAiBC,YACrBT,SACAU,KAAKC,GAAG,CAAChB,kBAAkBM,WAAW;QAExCJ,kBAAkBe,GAAG,CAACR,QAAQI;QAC9B,OAAOJ;IACT;IAEA,MAAMS,iBAAiB,CAACT;QACtBD,OAAOC;QACP,MAAMI,iBAAiBX,kBAAkBiB,GAAG,CAACV;QAC7C,IAAII,mBAAmBO,WAAW;YAChCC,cAAcR;YACdX,kBAAkBoB,MAAM,CAACb;QAC3B;IACF;IAEA,MAAMc,mBAAmB;QACvB,KAAK,MAAMd,UAAUP,kBAAkBsB,IAAI,GAAI;YAC7CN,eAAeT;QACjB;IACF;IAEA,OAAO;QACLK,aAAaN,OAAOJ;QACpBiB,eAAeb,OAAOU;QACtBK;IACF;AACF;AAEA,MAAME,kBAAkB;IACtBC,OAAO;QAAC;QAAe;KAAgB;IACvCC,SAAS1B;AACX;AACA,eAAewB,gBAAgB"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/math.ts"],"sourcesContent":["import { rootRealmGlobal } from '../globalObject';\nimport { createCrypto } from './crypto';\n\n/**\n * Create a {@link Math} object, with the same properties as the global\n * {@link Math} object, but with the {@link Math.random} method replaced.\n *\n * @returns The {@link Math} object with the {@link Math.random} method\n * replaced.\n */\nfunction createMath() {\n // `Math` does not work with `Object.keys`, `Object.entries`, etc., so we\n // need to create a new object with the same properties.\n const keys = Object.getOwnPropertyNames(\n rootRealmGlobal.Math,\n ) as (keyof typeof Math)[];\n\n const math = keys.reduce<Partial<Math>>((target, key) => {\n if (key === 'random') {\n return target;\n }\n\n return { ...target, [key]: rootRealmGlobal.Math[key] };\n }, {});\n\n // Since the math endowment requires crypto, we can leverage the crypto endowment factory to get a hardened and platform agnostic instance of webcrypto\n const { crypto: hardenedCrypto } = createCrypto();\n\n return harden({\n Math: {\n ...math,\n random: () => {\n // NOTE: This is not intended to be a secure replacement for the weak\n // random number generator used by `Math.random`. It is only intended to\n // prevent side channel attacks of `Math.random` by replacing it with an\n // alternative implementation that is not vulnerable to the same\n // attacks.\n //\n // This does not mean that this implementation is secure. It is not\n // intended to be used in a security context, and this implementation\n // may change at any time.\n //\n // To securely generate random numbers, use a cryptographically secure\n // random number generator, such as the one provided by the Web Crypto\n // API:\n //\n // - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey\n // - https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues\n return hardenedCrypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32;\n },\n },\n });\n}\n\nconst endowmentModule = {\n names: ['Math'] as const,\n factory: createMath,\n};\n\nexport default endowmentModule;\n"],"names":["rootRealmGlobal","createCrypto","createMath","keys","Object","getOwnPropertyNames","Math","math","reduce","target","key","crypto","hardenedCrypto","harden","random","getRandomValues","Uint32Array","endowmentModule","names","factory"],"mappings":"AAAA,SAASA,eAAe,QAAQ,kBAAkB;AAClD,SAASC,YAAY,QAAQ,WAAW;AAExC;;;;;;CAMC,GACD,SAASC;IACP,yEAAyE;IACzE,wDAAwD;IACxD,MAAMC,OAAOC,OAAOC,mBAAmB,CACrCL,gBAAgBM,IAAI;IAGtB,MAAMC,OAAOJ,KAAKK,MAAM,CAAgB,CAACC,QAAQC;QAC/C,IAAIA,QAAQ,UAAU;YACpB,OAAOD;QACT;QAEA,OAAO;YAAE,GAAGA,MAAM;YAAE,CAACC,IAAI,EAAEV,gBAAgBM,IAAI,CAACI,IAAI;QAAC;IACvD,GAAG,CAAC;IAEJ,uJAAuJ;IACvJ,MAAM,EAAEC,QAAQC,cAAc,EAAE,GAAGX;IAEnC,OAAOY,OAAO;QACZP,MAAM;YACJ,GAAGC,IAAI;YACPO,QAAQ;gBACN,qEAAqE;gBACrE,wEAAwE;gBACxE,wEAAwE;gBACxE,gEAAgE;gBAChE,WAAW;gBACX,EAAE;gBACF,mEAAmE;gBACnE,qEAAqE;gBACrE,0BAA0B;gBAC1B,EAAE;gBACF,sEAAsE;gBACtE,sEAAsE;gBACtE,OAAO;gBACP,EAAE;gBACF,8EAA8E;gBAC9E,4EAA4E;gBAC5E,OAAOF,eAAeG,eAAe,CAAC,IAAIC,YAAY,GAAG,CAAC,EAAE,GAAG,KAAK;YACtE;QACF;IACF;AACF;AAEA,MAAMC,kBAAkB;IACtBC,OAAO;QAAC;KAAO;IACfC,SAASjB;AACX;AAEA,eAAee,gBAAgB"}
@@ -1,196 +0,0 @@
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
@@ -1 +0,0 @@
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,YAAY,QAAQ,WAAW;IAO7B,4CAET;AAPF;;;CAGC,GACD,MAAMC;IAUJ,IAAIC,OAA0C;QAC5C,OAAO,yBAAA,IAAI,EAAEC,aAAWD,IAAI;IAC9B;IAEA,IAAIE,WAAW;QACb,OAAO,yBAAA,IAAI,EAAED,aAAWC,QAAQ;IAClC;IAEA,IAAIC,UAAU;QACZ,OAAO,yBAAA,IAAI,EAAEF,aAAWE,OAAO;IACjC;IAEA,IAAIC,KAAK;QACP,OAAO,yBAAA,IAAI,EAAEH,aAAWG,EAAE;IAC5B;IAEA,IAAIC,aAAa;QACf,OAAO,yBAAA,IAAI,EAAEJ,aAAWI,UAAU;IACpC;IAEA,IAAIC,SAAS;QACX,OAAO,yBAAA,IAAI,EAAEL,aAAWK,MAAM;IAChC;IAEA,IAAIC,aAAa;QACf,OAAO,yBAAA,IAAI,EAAEN,aAAWM,UAAU;IACpC;IAEA,IAAIC,OAAO;QACT,OAAO,yBAAA,IAAI,EAAEP,aAAWO,IAAI;IAC9B;IAEA,IAAIC,MAAM;QACR,OAAO,yBAAA,IAAI,EAAER,aAAWQ,GAAG;IAC7B;IAEA,MAAMC,OAAO;QACX,OAAOZ,aAAqB,yBAAA,IAAI,EAAEG,aAAWS,IAAI,IAAI,IAAI;IAC3D;IAEA,MAAMC,cAAoC;QACxC,OAAOb,aACL,yBAAA,IAAI,EAAEG,aAAWU,WAAW,IAC5B,IAAI;IAER;IAEA,MAAMC,OAAsB;QAC1B,OAAOd,aAAmB,yBAAA,IAAI,EAAEG,aAAWW,IAAI,IAAI,IAAI;IACzD;IAEAC,QAAkB;QAChB,MAAMC,cAAc,yBAAA,IAAI,EAAEb,aAAWY,KAAK;QAC1C,OAAO,IAAId,gBAAgBe,sCAAa,IAAI,EAAEC;IAChD;IAEA,MAAMC,WAA8B;QAClC,OAAOlB,aAAuB,yBAAA,IAAI,EAAEG,aAAWe,QAAQ,IAAI,IAAI;IACjE;IAEA,MAAMC,OAAqB;QACzB,OAAOnB,aAAa,yBAAA,IAAI,EAAEG,aAAWgB,IAAI,IAAI,IAAI;IACnD;IAnEAC,YAAYjB,UAAoB,EAAEc,WAAqC,CAAE;QAJzE,gCAAS;;mBAAT,KAAA;;QAEA,gCAAA;;mBAAA,KAAA;;uCAGQd,aAAaA;uCACbc,cAAcA;IACtB;AAiEF;AAEA;;;;;;;;;;;;CAYC,GACD,MAAMI,gBAAgB;IACpB,wCAAwC;IACxC,MAAMC,kBAAkB,IAAIC;IAC5B,4BAA4B;IAC5B,MAAMN,cAAc;QAAEO,cAAc;IAAE;IAEtC,sEAAsE;IACtE,MAAMC,UAAU,IAAIC,qBAClB,yFAAyF,GACzF,CAACC,WAAaA;IAGhB,MAAMC,SAAuB,OAC3BC,OACAC;QAEA,MAAMC,kBAAkB,IAAIC;QAC5B,IAAIF,MAAMG,WAAW,QAAQH,MAAMG,WAAWC,WAAW;YACvD,MAAMC,iBAAiBL,KAAKG,MAAM;YAClC,0BAA0B;YAC1BE,eAAeC,gBAAgB,CAC7B,SACA;gBACEL,gBAAgBM,KAAK,CAAC,AAACF,eAAuBG,MAAM;YACtD,GACA;gBAAEC,MAAM;YAAK;QAEjB;QAEA,IAAIC;QACJ,IAAIC;QACJ,IAAI;YACF,MAAMC,eAAeC,MAAMd,OAAO;gBAChC,GAAGC,IAAI;gBACPG,QAAQF,gBAAgBE,MAAM;YAChC;YAEAQ,sBAAsB;gBACpBG,QAAQ;oBACNb,gBAAgBM,KAAK;oBACrB,IAAI;wBACF,MAAMK;oBACR,EAAE,OAAM;oBACN,cAAc,GAChB;gBACF;YACF;YACApB,gBAAgBuB,GAAG,CAACJ;YAEpBD,MAAM,IAAIvC,gBACR,MAAMD,aAAa0C,cAAczB,cACjCA;QAEJ,SAAU;YACR,IAAIwB,wBAAwBP,WAAW;gBACrCZ,gBAAgBwB,MAAM,CAACL;YACzB;QACF;QAEA,IAAID,IAAItC,IAAI,KAAK,MAAM;YACrB,MAAMA,OAAO,IAAI6C,QAAwBP,IAAItC,IAAI;YAEjD,MAAM8C,qBAAqB;gBACzBJ,QACE,+EAA+E,GAC/E;oBACE,IAAI;wBACF,MAAM1C,KAAK+C,KAAK,IAAIL;oBACtB,EAAE,OAAM;oBACN,cAAc,GAChB;gBACF;YACJ;YACAtB,gBAAgBuB,GAAG,CAACG;YACpBvB,QAAQyB,QAAQ,CACdV,IAAItC,IAAI,EACR,yFAAyF,GACzF,IAAMoB,gBAAgBwB,MAAM,CAACE;QAEjC;QACA,OAAOG,OAAOX;IAChB;IAEA,MAAMY,mBAAmB;QACvBnC,YAAYO,YAAY,IAAI;QAC5B,MAAM6B,WAA4B,EAAE;QACpC/B,gBAAgBgC,OAAO,CAAC,CAAC,EAAEV,MAAM,EAAE,GAAKS,SAASE,IAAI,CAACX;QACtDtB,gBAAgBkC,KAAK;QACrB,MAAMC,QAAQC,GAAG,CAACL;IACpB;IAEA,OAAO;QACLV,OAAOQ,OAAOvB;QACdwB;IACF;AACF;AAEA,MAAMO,kBAAkB;IACtBC,OAAO;QAAC;KAAQ;IAChBC,SAASxC;AACX;AACA,eAAesC,gBAAgB"}
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
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 +0,0 @@
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"}
@@ -1,35 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,36 +0,0 @@
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
@@ -1 +0,0 @@
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"}