@metamask/snaps-controllers 10.0.0 → 11.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 (152) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/cronjob/CronjobController.cjs +15 -1
  3. package/dist/cronjob/CronjobController.cjs.map +1 -1
  4. package/dist/cronjob/CronjobController.d.cts.map +1 -1
  5. package/dist/cronjob/CronjobController.d.mts.map +1 -1
  6. package/dist/cronjob/CronjobController.mjs +15 -1
  7. package/dist/cronjob/CronjobController.mjs.map +1 -1
  8. package/dist/interface/SnapInterfaceController.cjs.map +1 -1
  9. package/dist/interface/SnapInterfaceController.d.cts.map +1 -1
  10. package/dist/interface/SnapInterfaceController.d.mts.map +1 -1
  11. package/dist/interface/SnapInterfaceController.mjs.map +1 -1
  12. package/dist/multichain/MultichainRouter.cjs.map +1 -1
  13. package/dist/multichain/MultichainRouter.mjs.map +1 -1
  14. package/dist/node.cjs +1 -1
  15. package/dist/node.cjs.map +1 -1
  16. package/dist/node.mjs +1 -1
  17. package/dist/node.mjs.map +1 -1
  18. package/dist/react-native.cjs +1 -1
  19. package/dist/react-native.cjs.map +1 -1
  20. package/dist/react-native.mjs +1 -1
  21. package/dist/react-native.mjs.map +1 -1
  22. package/dist/services/AbstractExecutionService.cjs +7 -2
  23. package/dist/services/AbstractExecutionService.cjs.map +1 -1
  24. package/dist/services/AbstractExecutionService.d.cts +1 -1
  25. package/dist/services/AbstractExecutionService.d.cts.map +1 -1
  26. package/dist/services/AbstractExecutionService.d.mts +1 -1
  27. package/dist/services/AbstractExecutionService.d.mts.map +1 -1
  28. package/dist/services/AbstractExecutionService.mjs +7 -2
  29. package/dist/services/AbstractExecutionService.mjs.map +1 -1
  30. package/dist/services/ExecutionService.cjs +0 -1
  31. package/dist/services/ExecutionService.cjs.map +1 -1
  32. package/dist/services/ExecutionService.d.cts +7 -7
  33. package/dist/services/ExecutionService.d.cts.map +1 -1
  34. package/dist/services/ExecutionService.d.mts +7 -7
  35. package/dist/services/ExecutionService.d.mts.map +1 -1
  36. package/dist/services/ExecutionService.mjs +0 -1
  37. package/dist/services/ExecutionService.mjs.map +1 -1
  38. package/dist/services/browser.cjs +0 -1
  39. package/dist/services/browser.cjs.map +1 -1
  40. package/dist/services/browser.d.cts +1 -1
  41. package/dist/services/browser.d.cts.map +1 -1
  42. package/dist/services/browser.d.mts +1 -1
  43. package/dist/services/browser.d.mts.map +1 -1
  44. package/dist/services/browser.mjs +0 -1
  45. package/dist/services/browser.mjs.map +1 -1
  46. package/dist/services/index.cjs +0 -1
  47. package/dist/services/index.cjs.map +1 -1
  48. package/dist/services/index.d.cts +1 -1
  49. package/dist/services/index.d.cts.map +1 -1
  50. package/dist/services/index.d.mts +1 -1
  51. package/dist/services/index.d.mts.map +1 -1
  52. package/dist/services/index.mjs +0 -1
  53. package/dist/services/index.mjs.map +1 -1
  54. package/dist/services/node-js/NodeThreadExecutionService.cjs +3 -1
  55. package/dist/services/node-js/NodeThreadExecutionService.cjs.map +1 -1
  56. package/dist/services/node-js/NodeThreadExecutionService.d.cts.map +1 -1
  57. package/dist/services/node-js/NodeThreadExecutionService.d.mts.map +1 -1
  58. package/dist/services/node-js/NodeThreadExecutionService.mjs +3 -1
  59. package/dist/services/node-js/NodeThreadExecutionService.mjs.map +1 -1
  60. package/dist/services/proxy/ProxyExecutionService.cjs +3 -0
  61. package/dist/services/proxy/ProxyExecutionService.cjs.map +1 -1
  62. package/dist/services/proxy/ProxyExecutionService.d.cts.map +1 -1
  63. package/dist/services/proxy/ProxyExecutionService.d.mts.map +1 -1
  64. package/dist/services/proxy/ProxyExecutionService.mjs +3 -0
  65. package/dist/services/proxy/ProxyExecutionService.mjs.map +1 -1
  66. package/dist/services/webview/WebViewExecutionService.cjs +1 -1
  67. package/dist/services/webview/WebViewExecutionService.cjs.map +1 -1
  68. package/dist/services/webview/WebViewExecutionService.d.cts +2 -2
  69. package/dist/services/webview/WebViewExecutionService.d.cts.map +1 -1
  70. package/dist/services/webview/WebViewExecutionService.d.mts +2 -2
  71. package/dist/services/webview/WebViewExecutionService.d.mts.map +1 -1
  72. package/dist/services/webview/WebViewExecutionService.mjs +1 -1
  73. package/dist/services/webview/WebViewExecutionService.mjs.map +1 -1
  74. package/dist/services/webview/WebViewMessageStream.cjs +3 -0
  75. package/dist/services/webview/WebViewMessageStream.cjs.map +1 -1
  76. package/dist/services/webview/WebViewMessageStream.d.cts.map +1 -1
  77. package/dist/services/webview/WebViewMessageStream.d.mts.map +1 -1
  78. package/dist/services/webview/WebViewMessageStream.mjs +3 -0
  79. package/dist/services/webview/WebViewMessageStream.mjs.map +1 -1
  80. package/dist/services/webworker/WebWorkerExecutionService.cjs +6 -0
  81. package/dist/services/webworker/WebWorkerExecutionService.cjs.map +1 -1
  82. package/dist/services/webworker/WebWorkerExecutionService.d.cts.map +1 -1
  83. package/dist/services/webworker/WebWorkerExecutionService.d.mts.map +1 -1
  84. package/dist/services/webworker/WebWorkerExecutionService.mjs +6 -0
  85. package/dist/services/webworker/WebWorkerExecutionService.mjs.map +1 -1
  86. package/dist/snaps/RequestQueue.cjs.map +1 -1
  87. package/dist/snaps/RequestQueue.d.cts.map +1 -1
  88. package/dist/snaps/RequestQueue.d.mts.map +1 -1
  89. package/dist/snaps/RequestQueue.mjs.map +1 -1
  90. package/dist/snaps/SnapController.cjs +22 -21
  91. package/dist/snaps/SnapController.cjs.map +1 -1
  92. package/dist/snaps/SnapController.d.cts +14 -14
  93. package/dist/snaps/SnapController.d.cts.map +1 -1
  94. package/dist/snaps/SnapController.d.mts +14 -14
  95. package/dist/snaps/SnapController.d.mts.map +1 -1
  96. package/dist/snaps/SnapController.mjs +22 -25
  97. package/dist/snaps/SnapController.mjs.map +1 -1
  98. package/dist/snaps/Timer.cjs +3 -0
  99. package/dist/snaps/Timer.cjs.map +1 -1
  100. package/dist/snaps/Timer.d.cts.map +1 -1
  101. package/dist/snaps/Timer.d.mts.map +1 -1
  102. package/dist/snaps/Timer.mjs +3 -0
  103. package/dist/snaps/Timer.mjs.map +1 -1
  104. package/dist/snaps/location/http.cjs +6 -0
  105. package/dist/snaps/location/http.cjs.map +1 -1
  106. package/dist/snaps/location/http.d.cts +2 -2
  107. package/dist/snaps/location/http.d.cts.map +1 -1
  108. package/dist/snaps/location/http.d.mts +2 -2
  109. package/dist/snaps/location/http.d.mts.map +1 -1
  110. package/dist/snaps/location/http.mjs +6 -0
  111. package/dist/snaps/location/http.mjs.map +1 -1
  112. package/dist/snaps/location/location.cjs.map +1 -1
  113. package/dist/snaps/location/location.d.cts +2 -2
  114. package/dist/snaps/location/location.d.cts.map +1 -1
  115. package/dist/snaps/location/location.d.mts +2 -2
  116. package/dist/snaps/location/location.d.mts.map +1 -1
  117. package/dist/snaps/location/location.mjs.map +1 -1
  118. package/dist/snaps/location/npm.cjs +1 -0
  119. package/dist/snaps/location/npm.cjs.map +1 -1
  120. package/dist/snaps/location/npm.d.cts +5 -5
  121. package/dist/snaps/location/npm.d.cts.map +1 -1
  122. package/dist/snaps/location/npm.d.mts +5 -5
  123. package/dist/snaps/location/npm.d.mts.map +1 -1
  124. package/dist/snaps/location/npm.mjs +1 -0
  125. package/dist/snaps/location/npm.mjs.map +1 -1
  126. package/dist/snaps/registry/json.cjs.map +1 -1
  127. package/dist/snaps/registry/json.mjs.map +1 -1
  128. package/dist/snaps/registry/registry.cjs.map +1 -1
  129. package/dist/snaps/registry/registry.d.cts +0 -1
  130. package/dist/snaps/registry/registry.d.cts.map +1 -1
  131. package/dist/snaps/registry/registry.d.mts +0 -1
  132. package/dist/snaps/registry/registry.d.mts.map +1 -1
  133. package/dist/snaps/registry/registry.mjs.map +1 -1
  134. package/dist/types/controllers.cjs +0 -1
  135. package/dist/types/controllers.cjs.map +1 -1
  136. package/dist/types/controllers.d.cts +1 -3
  137. package/dist/types/controllers.d.cts.map +1 -1
  138. package/dist/types/controllers.d.mts +1 -3
  139. package/dist/types/controllers.d.mts.map +1 -1
  140. package/dist/types/controllers.mjs +0 -1
  141. package/dist/types/controllers.mjs.map +1 -1
  142. package/dist/types/index.cjs +0 -16
  143. package/dist/types/index.cjs.map +1 -1
  144. package/dist/types/index.d.cts +2 -2
  145. package/dist/types/index.d.cts.map +1 -1
  146. package/dist/types/index.d.mts +2 -2
  147. package/dist/types/index.d.mts.map +1 -1
  148. package/dist/types/index.mjs +1 -2
  149. package/dist/types/index.mjs.map +1 -1
  150. package/package.json +13 -26
  151. package/react-native.d.ts +0 -2
  152. package/react-native.js +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"ProxyExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAG3E,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,oCAAoC,GAAG;IAC1C,MAAM,EAAE,qBAAqB,CAAC;CAC/B,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,qBAAsB,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAGzE;;;;;;;;;;OAUG;gBACS,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,oCAAoC;IAWvC;;;;OAIG;cACa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAa1D;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;CAoB5C"}
1
+ {"version":3,"file":"ProxyExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAG3E,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,oCAAoC,GAAG;IAC1C,MAAM,EAAE,qBAAqB,CAAC;CAC/B,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,qBAAsB,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAGzE;;;;;;;;;;OAUG;gBACS,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,oCAAoC;IAWvC;;;;OAIG;cAIa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAa1D;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;CAoB5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"ProxyExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAG3E,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,oCAAoC,GAAG;IAC1C,MAAM,EAAE,qBAAqB,CAAC;CAC/B,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,qBAAsB,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAGzE;;;;;;;;;;OAUG;gBACS,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,oCAAoC;IAWvC;;;;OAIG;cACa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAa1D;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;CAoB5C"}
1
+ {"version":3,"file":"ProxyExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAG3E,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,oCAAoC,GAAG;IAC1C,MAAM,EAAE,qBAAqB,CAAC;CAC/B,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,qBAAsB,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAGzE;;;;;;;;;;OAUG;gBACS,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,oCAAoC;IAWvC;;;;OAIG;cAIa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAa1D;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;CAoB5C"}
@@ -40,6 +40,9 @@ export class ProxyExecutionService extends AbstractExecutionService {
40
40
  *
41
41
  * @param job - The job to terminate.
42
42
  */
43
+ // TODO: Either fix this lint violation or explain why it's necessary to
44
+ // ignore.
45
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
43
46
  async terminateJob(job) {
44
47
  // The `AbstractExecutionService` will have already closed the job stream,
45
48
  // so we write to the runtime stream directly.
@@ -1 +1 @@
1
- {"version":3,"file":"ProxyExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,eAAe;AAMhC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAMnE,MAAM,OAAO,qBAAsB,SAAQ,wBAAgC;IAGzE;;;;;;;;;;OAUG;IACH,YAAY,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EAC8B;QACrC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;YACjB,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QAxBI,gDAA+B;QA0BtC,uBAAA,IAAI,iCAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,YAAY,CAAC,GAA6B;QACxD,0EAA0E;QAC1E,8CAA8C;QAC9C,uBAAA,IAAI,qCAAQ,CAAC,KAAK,CAAC;YACjB,KAAK,EAAE,GAAG,CAAC,EAAE;YACb,IAAI,EAAE;gBACJ,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,cAAc;gBACtB,EAAE,EAAE,MAAM,EAAE;aACb;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,KAAa;QACzC,MAAM,MAAM,GAAG,IAAI,sBAAsB,CAAC;YACxC,MAAM,EAAE,uBAAA,IAAI,qCAAQ;YACpB,KAAK;SACN,CAAC,CAAC;QAEH,0DAA0D;QAC1D,iFAAiF;QACjF,2DAA2D;QAC3D,sFAAsF;QACtF,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC7B,MAAM,CAAC,KAAK,CAAC;gBACX,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE;aACvD,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACnC,CAAC;CACF","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { nanoid } from 'nanoid';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport { ProxyPostMessageStream } from '../ProxyPostMessageStream';\n\ntype ProxyExecutionEnvironmentServiceArgs = {\n stream: BasePostMessageStream;\n} & ExecutionServiceArgs;\n\nexport class ProxyExecutionService extends AbstractExecutionService<string> {\n readonly #stream: BasePostMessageStream;\n\n /**\n * Create a new proxy execution service.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n * @param args.stream - The stream to use for communicating with the proxy\n * executor.\n */\n constructor({\n stream,\n messenger,\n setupSnapProvider,\n ...args\n }: ProxyExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n usePing: false,\n });\n\n this.#stream = stream;\n }\n\n /**\n * Send a termination command to the proxy stream.\n *\n * @param job - The job to terminate.\n */\n protected async terminateJob(job: TerminateJobArgs<string>) {\n // The `AbstractExecutionService` will have already closed the job stream,\n // so we write to the runtime stream directly.\n this.#stream.write({\n jobId: job.id,\n data: {\n jsonrpc: '2.0',\n method: 'terminateJob',\n id: nanoid(),\n },\n });\n }\n\n /**\n * Create a new stream for the specified job. This wraps the root stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(jobId: string) {\n const stream = new ProxyPostMessageStream({\n stream: this.#stream,\n jobId,\n });\n\n // Send a request and await any response before continuing\n // This simulates the behaviour of non-proxy environments by effectively awaiting\n // the load of the environment inside the proxy environment\n // This assumes the proxy environment is already loaded before this function is called\n await new Promise((resolve) => {\n stream.once('data', resolve);\n stream.write({\n name: 'command',\n data: { jsonrpc: '2.0', method: 'ping', id: nanoid() },\n });\n });\n\n return { worker: jobId, stream };\n }\n}\n"]}
1
+ {"version":3,"file":"ProxyExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,eAAe;AAMhC,OAAO,EAAE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,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACnC,CAAC;CACF","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { nanoid } from 'nanoid';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport { ProxyPostMessageStream } from '../ProxyPostMessageStream';\n\ntype ProxyExecutionEnvironmentServiceArgs = {\n stream: BasePostMessageStream;\n} & ExecutionServiceArgs;\n\nexport class ProxyExecutionService extends AbstractExecutionService<string> {\n readonly #stream: BasePostMessageStream;\n\n /**\n * Create a new proxy execution service.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n * @param args.stream - The stream to use for communicating with the proxy\n * executor.\n */\n constructor({\n stream,\n messenger,\n setupSnapProvider,\n ...args\n }: ProxyExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n usePing: false,\n });\n\n this.#stream = stream;\n }\n\n /**\n * Send a termination command to the proxy stream.\n *\n * @param job - The job to terminate.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n protected async terminateJob(job: TerminateJobArgs<string>) {\n // The `AbstractExecutionService` will have already closed the job stream,\n // so we write to the runtime stream directly.\n this.#stream.write({\n jobId: job.id,\n data: {\n jsonrpc: '2.0',\n method: 'terminateJob',\n id: nanoid(),\n },\n });\n }\n\n /**\n * Create a new stream for the specified job. This wraps the root stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(jobId: string) {\n const stream = new ProxyPostMessageStream({\n stream: this.#stream,\n jobId,\n });\n\n // Send a request and await any response before continuing\n // This simulates the behaviour of non-proxy environments by effectively awaiting\n // the load of the environment inside the proxy environment\n // This assumes the proxy environment is already loaded before this function is called\n await new Promise((resolve) => {\n stream.once('data', resolve);\n stream.write({\n name: 'command',\n data: { jsonrpc: '2.0', method: 'ping', id: nanoid() },\n });\n });\n\n return { worker: jobId, stream };\n }\n}\n"]}
@@ -13,8 +13,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _WebViewExecutionService_createWebView, _WebViewExecutionService_removeWebView;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.WebViewExecutionService = void 0;
16
- const AbstractExecutionService_1 = require("../AbstractExecutionService.cjs");
17
16
  const WebViewMessageStream_1 = require("./WebViewMessageStream.cjs");
17
+ const AbstractExecutionService_1 = require("../AbstractExecutionService.cjs");
18
18
  class WebViewExecutionService extends AbstractExecutionService_1.AbstractExecutionService {
19
19
  constructor({ messenger, setupSnapProvider, createWebView, removeWebView, ...args }) {
20
20
  super({
@@ -1 +1 @@
1
- {"version":3,"file":"WebViewExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,8EAGqC;AAErC,qEAA8D;AAO9D,MAAa,uBAAwB,SAAQ,mDAA0C;IAKrF,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACqB;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAfI,yDAAe;QAEf,yDAAe;QActB,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,KAAa;QACzC,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,KAAK,CAAC,CAAC;QAEjD,MAAM,MAAM,GAAG,IAAI,2CAAoB,CAAC;YACtC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACrC,CAAC;IAES,YAAY,CAAC,UAA8C;QACnE,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,UAAU,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AA3CD,0DA2CC","sourcesContent":["import type { TerminateJobArgs } from '../AbstractExecutionService';\nimport {\n AbstractExecutionService,\n type ExecutionServiceArgs,\n} from '../AbstractExecutionService';\nimport type { WebViewInterface } from './WebViewMessageStream';\nimport { WebViewMessageStream } from './WebViewMessageStream';\n\nexport type WebViewExecutionServiceArgs = ExecutionServiceArgs & {\n createWebView: (jobId: string) => Promise<WebViewInterface>;\n removeWebView: (jobId: string) => void;\n};\n\nexport class WebViewExecutionService extends AbstractExecutionService<WebViewInterface> {\n readonly #createWebView;\n\n readonly #removeWebView;\n\n constructor({\n messenger,\n setupSnapProvider,\n createWebView,\n removeWebView,\n ...args\n }: WebViewExecutionServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n this.#createWebView = createWebView;\n this.#removeWebView = removeWebView;\n }\n\n /**\n * Create a new stream for the specified job. This wraps the runtime stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(jobId: string) {\n const webView = await this.#createWebView(jobId);\n\n const stream = new WebViewMessageStream({\n name: 'parent',\n target: 'child',\n webView,\n });\n\n return { worker: webView, stream };\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<WebViewInterface>): void {\n this.#removeWebView(jobWrapper.id);\n }\n}\n"]}
1
+ {"version":3,"file":"WebViewExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,qEAA8D;AAC9D,8EAAuE;AAWvE,MAAa,uBAAwB,SAAQ,mDAA0C;IAKrF,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACqB;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAfI,yDAAe;QAEf,yDAAe;QActB,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,KAAa;QACzC,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,KAAK,CAAC,CAAC;QAEjD,MAAM,MAAM,GAAG,IAAI,2CAAoB,CAAC;YACtC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACrC,CAAC;IAES,YAAY,CAAC,UAA8C;QACnE,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,UAAU,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AA3CD,0DA2CC","sourcesContent":["import type { WebViewInterface } from './WebViewMessageStream';\nimport { WebViewMessageStream } from './WebViewMessageStream';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\n\nexport type WebViewExecutionServiceArgs = ExecutionServiceArgs & {\n createWebView: (jobId: string) => Promise<WebViewInterface>;\n removeWebView: (jobId: string) => void;\n};\n\nexport class WebViewExecutionService extends AbstractExecutionService<WebViewInterface> {\n readonly #createWebView;\n\n readonly #removeWebView;\n\n constructor({\n messenger,\n setupSnapProvider,\n createWebView,\n removeWebView,\n ...args\n }: WebViewExecutionServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n this.#createWebView = createWebView;\n this.#removeWebView = removeWebView;\n }\n\n /**\n * Create a new stream for the specified job. This wraps the runtime stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(jobId: string) {\n const webView = await this.#createWebView(jobId);\n\n const stream = new WebViewMessageStream({\n name: 'parent',\n target: 'child',\n webView,\n });\n\n return { worker: webView, stream };\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<WebViewInterface>): void {\n this.#removeWebView(jobWrapper.id);\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
- import type { TerminateJobArgs } from "../AbstractExecutionService.cjs";
2
- import { AbstractExecutionService, type ExecutionServiceArgs } from "../AbstractExecutionService.cjs";
3
1
  import type { WebViewInterface } from "./WebViewMessageStream.cjs";
4
2
  import { WebViewMessageStream } from "./WebViewMessageStream.cjs";
3
+ import { AbstractExecutionService } from "../AbstractExecutionService.cjs";
4
+ import type { ExecutionServiceArgs, TerminateJobArgs } from "../AbstractExecutionService.cjs";
5
5
  export type WebViewExecutionServiceArgs = ExecutionServiceArgs & {
6
6
  createWebView: (jobId: string) => Promise<WebViewInterface>;
7
7
  removeWebView: (jobId: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"WebViewExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAoC;AACpE,OAAO,EACL,wBAAwB,EACxB,KAAK,oBAAoB,EAC1B,wCAAoC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,mCAA+B;AAC/D,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAE9D,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG;IAC/D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,qBAAa,uBAAwB,SAAQ,wBAAwB,CAAC,gBAAgB,CAAC;;gBAKzE,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACR,EAAE,2BAA2B;IAU9B;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;IAY3C,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,IAAI;CAG7E"}
1
+ {"version":3,"file":"WebViewExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,mCAA+B;AAC/D,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AAErC,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG;IAC/D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,qBAAa,uBAAwB,SAAQ,wBAAwB,CAAC,gBAAgB,CAAC;;gBAKzE,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACR,EAAE,2BAA2B;IAU9B;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;IAY3C,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,IAAI;CAG7E"}
@@ -1,7 +1,7 @@
1
- import type { TerminateJobArgs } from "../AbstractExecutionService.mjs";
2
- import { AbstractExecutionService, type ExecutionServiceArgs } from "../AbstractExecutionService.mjs";
3
1
  import type { WebViewInterface } from "./WebViewMessageStream.mjs";
4
2
  import { WebViewMessageStream } from "./WebViewMessageStream.mjs";
3
+ import { AbstractExecutionService } from "../AbstractExecutionService.mjs";
4
+ import type { ExecutionServiceArgs, TerminateJobArgs } from "../AbstractExecutionService.mjs";
5
5
  export type WebViewExecutionServiceArgs = ExecutionServiceArgs & {
6
6
  createWebView: (jobId: string) => Promise<WebViewInterface>;
7
7
  removeWebView: (jobId: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"WebViewExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAoC;AACpE,OAAO,EACL,wBAAwB,EACxB,KAAK,oBAAoB,EAC1B,wCAAoC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,mCAA+B;AAC/D,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAE9D,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG;IAC/D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,qBAAa,uBAAwB,SAAQ,wBAAwB,CAAC,gBAAgB,CAAC;;gBAKzE,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACR,EAAE,2BAA2B;IAU9B;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;IAY3C,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,IAAI;CAG7E"}
1
+ {"version":3,"file":"WebViewExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,mCAA+B;AAC/D,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AAErC,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG;IAC/D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,qBAAa,uBAAwB,SAAQ,wBAAwB,CAAC,gBAAgB,CAAC;;gBAKzE,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACR,EAAE,2BAA2B;IAU9B;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;IAY3C,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,IAAI;CAG7E"}
@@ -10,8 +10,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _WebViewExecutionService_createWebView, _WebViewExecutionService_removeWebView;
13
- import { AbstractExecutionService } from "../AbstractExecutionService.mjs";
14
13
  import { WebViewMessageStream } from "./WebViewMessageStream.mjs";
14
+ import { AbstractExecutionService } from "../AbstractExecutionService.mjs";
15
15
  export class WebViewExecutionService extends AbstractExecutionService {
16
16
  constructor({ messenger, setupSnapProvider, createWebView, removeWebView, ...args }) {
17
17
  super({
@@ -1 +1 @@
1
- {"version":3,"file":"WebViewExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EACL,wBAAwB,EAEzB,wCAAoC;AAErC,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAO9D,MAAM,OAAO,uBAAwB,SAAQ,wBAA0C;IAKrF,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACqB;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAfI,yDAAe;QAEf,yDAAe;QActB,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,KAAa;QACzC,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,KAAK,CAAC,CAAC;QAEjD,MAAM,MAAM,GAAG,IAAI,oBAAoB,CAAC;YACtC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACrC,CAAC;IAES,YAAY,CAAC,UAA8C;QACnE,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,UAAU,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;CACF","sourcesContent":["import type { TerminateJobArgs } from '../AbstractExecutionService';\nimport {\n AbstractExecutionService,\n type ExecutionServiceArgs,\n} from '../AbstractExecutionService';\nimport type { WebViewInterface } from './WebViewMessageStream';\nimport { WebViewMessageStream } from './WebViewMessageStream';\n\nexport type WebViewExecutionServiceArgs = ExecutionServiceArgs & {\n createWebView: (jobId: string) => Promise<WebViewInterface>;\n removeWebView: (jobId: string) => void;\n};\n\nexport class WebViewExecutionService extends AbstractExecutionService<WebViewInterface> {\n readonly #createWebView;\n\n readonly #removeWebView;\n\n constructor({\n messenger,\n setupSnapProvider,\n createWebView,\n removeWebView,\n ...args\n }: WebViewExecutionServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n this.#createWebView = createWebView;\n this.#removeWebView = removeWebView;\n }\n\n /**\n * Create a new stream for the specified job. This wraps the runtime stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(jobId: string) {\n const webView = await this.#createWebView(jobId);\n\n const stream = new WebViewMessageStream({\n name: 'parent',\n target: 'child',\n webView,\n });\n\n return { worker: webView, stream };\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<WebViewInterface>): void {\n this.#removeWebView(jobWrapper.id);\n }\n}\n"]}
1
+ {"version":3,"file":"WebViewExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AAWvE,MAAM,OAAO,uBAAwB,SAAQ,wBAA0C;IAKrF,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACqB;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAfI,yDAAe;QAEf,yDAAe;QActB,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,KAAa;QACzC,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,KAAK,CAAC,CAAC;QAEjD,MAAM,MAAM,GAAG,IAAI,oBAAoB,CAAC;YACtC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACrC,CAAC;IAES,YAAY,CAAC,UAA8C;QACnE,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,UAAU,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;CACF","sourcesContent":["import type { WebViewInterface } from './WebViewMessageStream';\nimport { WebViewMessageStream } from './WebViewMessageStream';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\n\nexport type WebViewExecutionServiceArgs = ExecutionServiceArgs & {\n createWebView: (jobId: string) => Promise<WebViewInterface>;\n removeWebView: (jobId: string) => void;\n};\n\nexport class WebViewExecutionService extends AbstractExecutionService<WebViewInterface> {\n readonly #createWebView;\n\n readonly #removeWebView;\n\n constructor({\n messenger,\n setupSnapProvider,\n createWebView,\n removeWebView,\n ...args\n }: WebViewExecutionServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n this.#createWebView = createWebView;\n this.#removeWebView = removeWebView;\n }\n\n /**\n * Create a new stream for the specified job. This wraps the runtime stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(jobId: string) {\n const webView = await this.#createWebView(jobId);\n\n const stream = new WebViewMessageStream({\n name: 'parent',\n target: 'child',\n webView,\n });\n\n return { worker: webView, stream };\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<WebViewInterface>): void {\n this.#removeWebView(jobWrapper.id);\n }\n}\n"]}
@@ -54,6 +54,9 @@ class WebViewMessageStream extends post_message_stream_1.BasePostMessageStream {
54
54
  const bytes = new Uint8Array((0, utils_2.stringToBytes)(json));
55
55
  __classPrivateFieldGet(this, _WebViewMessageStream_webView, "f").injectJavaScript(`window.postMessage([${bytes.toString()}])`);
56
56
  }
57
+ // TODO: Either fix this lint violation or explain why it's necessary to
58
+ // ignore.
59
+ // eslint-disable-next-line no-restricted-syntax
57
60
  _onMessage(event) {
58
61
  if (typeof event.data !== 'string') {
59
62
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"WebViewMessageStream.cjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uEAAsE;AACtE,uEAAgF;AAChF,2CAAwD;AAcxD;;GAEG;AACH,MAAa,oBAAqB,SAAQ,2CAAqB;IAO7D;;;;;;;;OAQG;IACH,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAqB;QACtD,KAAK,EAAE,CAAC;QAhBV,6CAAM;QAEN,+CAAQ;QAER,gDAAuC;QAcrC,uBAAA,IAAI,8BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QAEtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE7C,uBAAA,IAAI,iCAAY,OAAO,MAAA,CAAC;QACxB,gCAAgC;QAChC,6DAA6D;QAC7D,uBAAA,IAAI,qCAAS,CAAC,uBAAuB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACvD,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAES,YAAY,CAAC,IAAa;QAClC,IAAA,cAAM,EAAC,uBAAA,IAAI,qCAAS,CAAC,CAAC;QACtB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;YAC1B,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,IAAI;SACL,CAAC,CAAC;QAEH,6DAA6D;QAC7D,kEAAkE;QAClE,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAA,qBAAa,EAAC,IAAI,CAAC,CAAC,CAAC;QAElD,uBAAA,IAAI,qCAAS,CAAC,gBAAgB,CAAC,uBAAuB,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC;IAEO,UAAU,CAAC,KAAuB;QACxC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEvC,gEAAgE;QAChE,0CAA0C;QAC1C,IAAI,CAAC,IAAA,4BAAoB,EAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,uBAAA,IAAI,kCAAM,EAAE,CAAC;YACpE,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,QAAQ;QACN,IAAA,cAAM,EAAC,uBAAA,IAAI,qCAAS,CAAC,CAAC;QACtB,gCAAgC;QAChC,6DAA6D;QAC7D,uBAAA,IAAI,qCAAS,CAAC,yBAAyB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC3D,CAAC;CACF;AAnED,oDAmEC","sourcesContent":["import type { PostMessageEvent } from '@metamask/post-message-stream';\nimport { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { isValidStreamMessage } from '@metamask/post-message-stream/dist/utils';\nimport { assert, stringToBytes } from '@metamask/utils';\n\nexport type WebViewInterface = {\n injectJavaScript(js: string): void;\n registerMessageListener(listener: (event: PostMessageEvent) => void): void;\n unregisterMessageListener(listener: (event: PostMessageEvent) => void): void;\n};\n\nexport type WebViewStreamArgs = {\n name: string;\n target: string;\n webView: WebViewInterface;\n};\n\n/**\n * A special postMessage stream used to interface with a WebView.\n */\nexport class WebViewMessageStream extends BasePostMessageStream {\n #name;\n\n #target;\n\n #webView: WebViewInterface | undefined;\n\n /**\n * Creates a stream for communicating with other streams inside a WebView.\n *\n * @param args - Options bag.\n * @param args.name - The name of the stream. Used to differentiate between\n * multiple streams sharing the same window object.\n * @param args.target - The name of the stream to exchange messages with.\n * @param args.webView - A reference to the WebView.\n */\n constructor({ name, target, webView }: WebViewStreamArgs) {\n super();\n\n this.#name = name;\n this.#target = target;\n\n this._onMessage = this._onMessage.bind(this);\n\n this.#webView = webView;\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.registerMessageListener(this._onMessage);\n this._handshake();\n }\n\n protected _postMessage(data: unknown): void {\n assert(this.#webView);\n const json = JSON.stringify({\n target: this.#target,\n data,\n });\n\n // To prevent XSS, we encode the message before injecting it.\n // This adds significant performance overhead for larger messages.\n const bytes = new Uint8Array(stringToBytes(json));\n\n this.#webView.injectJavaScript(`window.postMessage([${bytes.toString()}])`);\n }\n\n private _onMessage(event: PostMessageEvent): void {\n if (typeof event.data !== 'string') {\n return;\n }\n\n const message = JSON.parse(event.data);\n\n // Notice that we don't check targetWindow or targetOrigin here.\n // This doesn't seem possible to do in RN.\n if (!isValidStreamMessage(message) || message.target !== this.#name) {\n return;\n }\n\n this._onData(message.data);\n }\n\n _destroy() {\n assert(this.#webView);\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.unregisterMessageListener(this._onMessage);\n }\n}\n"]}
1
+ {"version":3,"file":"WebViewMessageStream.cjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uEAAsE;AACtE,uEAAgF;AAChF,2CAAwD;AAcxD;;GAEG;AACH,MAAa,oBAAqB,SAAQ,2CAAqB;IAO7D;;;;;;;;OAQG;IACH,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAqB;QACtD,KAAK,EAAE,CAAC;QAhBD,6CAAM;QAEN,+CAAQ;QAER,gDAAuC;QAc9C,uBAAA,IAAI,8BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QAEtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE7C,uBAAA,IAAI,iCAAY,OAAO,MAAA,CAAC;QACxB,gCAAgC;QAChC,6DAA6D;QAC7D,uBAAA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} from '@metamask/post-message-stream';\nimport { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { isValidStreamMessage } from '@metamask/post-message-stream/dist/utils';\nimport { assert, stringToBytes } from '@metamask/utils';\n\nexport type WebViewInterface = {\n injectJavaScript(js: string): void;\n registerMessageListener(listener: (event: PostMessageEvent) => void): void;\n unregisterMessageListener(listener: (event: PostMessageEvent) => void): void;\n};\n\nexport type WebViewStreamArgs = {\n name: string;\n target: string;\n webView: WebViewInterface;\n};\n\n/**\n * A special postMessage stream used to interface with a WebView.\n */\nexport class WebViewMessageStream extends BasePostMessageStream {\n readonly #name;\n\n readonly #target;\n\n readonly #webView: WebViewInterface | undefined;\n\n /**\n * Creates a stream for communicating with other streams inside a WebView.\n *\n * @param args - Options bag.\n * @param args.name - The name of the stream. Used to differentiate between\n * multiple streams sharing the same window object.\n * @param args.target - The name of the stream to exchange messages with.\n * @param args.webView - A reference to the WebView.\n */\n constructor({ name, target, webView }: WebViewStreamArgs) {\n super();\n\n this.#name = name;\n this.#target = target;\n\n this._onMessage = this._onMessage.bind(this);\n\n this.#webView = webView;\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.registerMessageListener(this._onMessage);\n this._handshake();\n }\n\n protected _postMessage(data: unknown): void {\n assert(this.#webView);\n const json = JSON.stringify({\n target: this.#target,\n data,\n });\n\n // To prevent XSS, we encode the message before injecting it.\n // This adds significant performance overhead for larger messages.\n const bytes = new Uint8Array(stringToBytes(json));\n\n this.#webView.injectJavaScript(`window.postMessage([${bytes.toString()}])`);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private _onMessage(event: PostMessageEvent): void {\n if (typeof event.data !== 'string') {\n return;\n }\n\n const message = JSON.parse(event.data);\n\n // Notice that we don't check targetWindow or targetOrigin here.\n // This doesn't seem possible to do in RN.\n if (!isValidStreamMessage(message) || message.target !== this.#name) {\n return;\n }\n\n this._onData(message.data);\n }\n\n _destroy() {\n assert(this.#webView);\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.unregisterMessageListener(this._onMessage);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"WebViewMessageStream.d.cts","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,sCAAsC;AACtE,OAAO,EAAE,qBAAqB,EAAE,sCAAsC;AAItE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,uBAAuB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAAC;IAC3E,yBAAyB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAAC;CAC9E,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,qBAAqB;;IAO7D;;;;;;;;OAQG;gBACS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,iBAAiB;IAexD,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAc3C,OAAO,CAAC,UAAU;IAgBlB,QAAQ;CAMT"}
1
+ {"version":3,"file":"WebViewMessageStream.d.cts","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,sCAAsC;AACtE,OAAO,EAAE,qBAAqB,EAAE,sCAAsC;AAItE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI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B,SAAQ,qBAAqB;;IAO7D;;;;;;;;OAQG;gBACS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,iBAAiB;IAexD,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAc3C,OAAO,CAAC,UAAU;IAgBlB,QAAQ;CAMT"}
1
+ {"version":3,"file":"WebViewMessageStream.d.mts","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,sCAAsC;AACtE,OAAO,EAAE,qBAAqB,EAAE,sCAAsC;AAItE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,uBAAuB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAAC;IAC3E,yBAAyB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAAC;CAC9E,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,qBAAqB;;IAO7D;;;;;;;;OAQG;gBACS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,iBAAiB;IAexD,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAiB3C,OAAO,CAAC,UAAU;IAgBlB,QAAQ;CAMT"}
@@ -51,6 +51,9 @@ export class WebViewMessageStream extends BasePostMessageStream {
51
51
  const bytes = new Uint8Array(stringToBytes(json));
52
52
  __classPrivateFieldGet(this, _WebViewMessageStream_webView, "f").injectJavaScript(`window.postMessage([${bytes.toString()}])`);
53
53
  }
54
+ // TODO: Either fix this lint violation or explain why it's necessary to
55
+ // ignore.
56
+ // eslint-disable-next-line no-restricted-syntax
54
57
  _onMessage(event) {
55
58
  if (typeof event.data !== 'string') {
56
59
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"WebViewMessageStream.mjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,qBAAqB,EAAE,sCAAsC;AACtE,OAAO,EAAE,oBAAoB,EAAE,oDAAiD;AAChF,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,wBAAwB;AAcxD;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,qBAAqB;IAO7D;;;;;;;;OAQG;IACH,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAqB;QACtD,KAAK,EAAE,CAAC;QAhBV,6CAAM;QAEN,+CAAQ;QAER,gDAAuC;QAcrC,uBAAA,IAAI,8BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QAEtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE7C,uBAAA,IAAI,iCAAY,OAAO,MAAA,CAAC;QACxB,gCAAgC;QAChC,6DAA6D;QAC7D,uBAAA,IAAI,qCAAS,CAAC,uBAAuB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACvD,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAES,YAAY,CAAC,IAAa;QAClC,MAAM,CAAC,uBAAA,IAAI,qCAAS,CAAC,CAAC;QACtB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;YAC1B,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,IAAI;SACL,CAAC,CAAC;QAEH,6DAA6D;QAC7D,kEAAkE;QAClE,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QAElD,uBAAA,IAAI,qCAAS,CAAC,gBAAgB,CAAC,uBAAuB,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC;IAEO,UAAU,CAAC,KAAuB;QACxC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEvC,gEAAgE;QAChE,0CAA0C;QAC1C,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,uBAAA,IAAI,kCAAM,EAAE,CAAC;YACpE,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,QAAQ;QACN,MAAM,CAAC,uBAAA,IAAI,qCAAS,CAAC,CAAC;QACtB,gCAAgC;QAChC,6DAA6D;QAC7D,uBAAA,IAAI,qCAAS,CAAC,yBAAyB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC3D,CAAC;CACF","sourcesContent":["import type { PostMessageEvent } from '@metamask/post-message-stream';\nimport { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { isValidStreamMessage } from '@metamask/post-message-stream/dist/utils';\nimport { assert, stringToBytes } from '@metamask/utils';\n\nexport type WebViewInterface = {\n injectJavaScript(js: string): void;\n registerMessageListener(listener: (event: PostMessageEvent) => void): void;\n unregisterMessageListener(listener: (event: PostMessageEvent) => void): void;\n};\n\nexport type WebViewStreamArgs = {\n name: string;\n target: string;\n webView: WebViewInterface;\n};\n\n/**\n * A special postMessage stream used to interface with a WebView.\n */\nexport class WebViewMessageStream extends BasePostMessageStream {\n #name;\n\n #target;\n\n #webView: WebViewInterface | undefined;\n\n /**\n * Creates a stream for communicating with other streams inside a WebView.\n *\n * @param args - Options bag.\n * @param args.name - The name of the stream. Used to differentiate between\n * multiple streams sharing the same window object.\n * @param args.target - The name of the stream to exchange messages with.\n * @param args.webView - A reference to the WebView.\n */\n constructor({ name, target, webView }: WebViewStreamArgs) {\n super();\n\n this.#name = name;\n this.#target = target;\n\n this._onMessage = this._onMessage.bind(this);\n\n this.#webView = webView;\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.registerMessageListener(this._onMessage);\n this._handshake();\n }\n\n protected _postMessage(data: unknown): void {\n assert(this.#webView);\n const json = JSON.stringify({\n target: this.#target,\n data,\n });\n\n // To prevent XSS, we encode the message before injecting it.\n // This adds significant performance overhead for larger messages.\n const bytes = new Uint8Array(stringToBytes(json));\n\n this.#webView.injectJavaScript(`window.postMessage([${bytes.toString()}])`);\n }\n\n private _onMessage(event: PostMessageEvent): void {\n if (typeof event.data !== 'string') {\n return;\n }\n\n const message = JSON.parse(event.data);\n\n // Notice that we don't check targetWindow or targetOrigin here.\n // This doesn't seem possible to do in RN.\n if (!isValidStreamMessage(message) || message.target !== this.#name) {\n return;\n }\n\n this._onData(message.data);\n }\n\n _destroy() {\n assert(this.#webView);\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.unregisterMessageListener(this._onMessage);\n }\n}\n"]}
1
+ {"version":3,"file":"WebViewMessageStream.mjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,qBAAqB,EAAE,sCAAsC;AACtE,OAAO,EAAE,oBAAoB,EAAE,oDAAiD;AAChF,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,wBAAwB;AAcxD;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,qBAAqB;IAO7D;;;;;;;;OAQG;IACH,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAqB;QACtD,KAAK,EAAE,CAAC;QAhBD,6CAAM;QAEN,+CAAQ;QAER,gDAAuC;QAc9C,u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CAAC;IAED,QAAQ;QACN,MAAM,CAAC,uBAAA,IAAI,qCAAS,CAAC,CAAC;QACtB,gCAAgC;QAChC,6DAA6D;QAC7D,uBAAA,IAAI,qCAAS,CAAC,yBAAyB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC3D,CAAC;CACF","sourcesContent":["import type { PostMessageEvent } from '@metamask/post-message-stream';\nimport { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { isValidStreamMessage } from '@metamask/post-message-stream/dist/utils';\nimport { assert, stringToBytes } from '@metamask/utils';\n\nexport type WebViewInterface = {\n injectJavaScript(js: string): void;\n registerMessageListener(listener: (event: PostMessageEvent) => void): void;\n unregisterMessageListener(listener: (event: PostMessageEvent) => void): void;\n};\n\nexport type WebViewStreamArgs = {\n name: string;\n target: string;\n webView: WebViewInterface;\n};\n\n/**\n * A special postMessage stream used to interface with a WebView.\n */\nexport class WebViewMessageStream extends BasePostMessageStream {\n readonly #name;\n\n readonly #target;\n\n readonly #webView: WebViewInterface | undefined;\n\n /**\n * Creates a stream for communicating with other streams inside a WebView.\n *\n * @param args - Options bag.\n * @param args.name - The name of the stream. Used to differentiate between\n * multiple streams sharing the same window object.\n * @param args.target - The name of the stream to exchange messages with.\n * @param args.webView - A reference to the WebView.\n */\n constructor({ name, target, webView }: WebViewStreamArgs) {\n super();\n\n this.#name = name;\n this.#target = target;\n\n this._onMessage = this._onMessage.bind(this);\n\n this.#webView = webView;\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.registerMessageListener(this._onMessage);\n this._handshake();\n }\n\n protected _postMessage(data: unknown): void {\n assert(this.#webView);\n const json = JSON.stringify({\n target: this.#target,\n data,\n });\n\n // To prevent XSS, we encode the message before injecting it.\n // This adds significant performance overhead for larger messages.\n const bytes = new Uint8Array(stringToBytes(json));\n\n this.#webView.injectJavaScript(`window.postMessage([${bytes.toString()}])`);\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private _onMessage(event: PostMessageEvent): void {\n if (typeof event.data !== 'string') {\n return;\n }\n\n const message = JSON.parse(event.data);\n\n // Notice that we don't check targetWindow or targetOrigin here.\n // This doesn't seem possible to do in RN.\n if (!isValidStreamMessage(message) || message.target !== this.#name) {\n return;\n }\n\n this._onData(message.data);\n }\n\n _destroy() {\n assert(this.#webView);\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#webView.unregisterMessageListener(this._onMessage);\n }\n}\n"]}
@@ -47,6 +47,9 @@ class WebWorkerExecutionService extends AbstractExecutionService_1.AbstractExecu
47
47
  *
48
48
  * @param job - The job to terminate.
49
49
  */
50
+ // TODO: Either fix this lint violation or explain why it's necessary to
51
+ // ignore.
52
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
50
53
  async terminateJob(job) {
51
54
  // The `AbstractExecutionService` will have already closed the job stream,
52
55
  // so we write to the runtime stream directly.
@@ -83,6 +86,9 @@ class WebWorkerExecutionService extends AbstractExecutionService_1.AbstractExecu
83
86
  *
84
87
  * If the document already exists, this does nothing.
85
88
  */
89
+ // TODO: Either fix this lint violation or explain why it's necessary to
90
+ // ignore.
91
+ // eslint-disable-next-line no-restricted-syntax
86
92
  async createDocument() {
87
93
  // We only want to create a single pool.
88
94
  if (document.getElementById(exports.WORKER_POOL_ID)) {
@@ -1 +1 @@
1
- {"version":3,"file":"WebWorkerExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/webworker/WebWorkerExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uEAAwE;AACxE,uDAAqD;AACrD,2CAAyC;AACzC,mCAAgC;AAMhC,8EAAuE;AACvE,0EAAmE;AAMtD,QAAA,cAAc,GAAG,mBAAmB,CAAC;AAElD,MAAa,yBAA0B,SAAQ,mDAAgC;IAK7E;;;;;;;;;;OAUG;IACH,YAAY,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACkC;QACzC,KAA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IAAI,4CAAkB,IAAI,6CAAuB,CAAC;YAChD,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,YAAY,EAAE,MAAM;YACpB,YAAY,EAAE,GAAG;SAClB,CAAC,MAAA,CAAC;IACL,CAAC;CACF;AAhGD,8DAgGC","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\nimport { createWindow } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport { ProxyPostMessageStream } from '../ProxyPostMessageStream';\n\ntype WebWorkerExecutionEnvironmentServiceArgs = {\n documentUrl: URL;\n} & ExecutionServiceArgs;\n\nexport const WORKER_POOL_ID = 'snaps-worker-pool';\n\nexport class WebWorkerExecutionService extends AbstractExecutionService<string> {\n #documentUrl: URL;\n\n #runtimeStream?: BasePostMessageStream;\n\n /**\n * Create a new webworker execution service.\n *\n * @param args - The constructor arguments.\n * @param args.documentUrl - The URL of the worker pool document to use as the\n * execution environment.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n */\n constructor({\n documentUrl,\n messenger,\n setupSnapProvider,\n ...args\n }: WebWorkerExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n\n this.#documentUrl = documentUrl;\n }\n\n /**\n * Send a termination command to the worker pool document.\n *\n * @param job - The job to terminate.\n */\n protected async terminateJob(job: TerminateJobArgs<string>) {\n // The `AbstractExecutionService` will have already closed the job stream,\n // so we write to the runtime stream directly.\n assert(this.#runtimeStream, 'Runtime stream not initialized.');\n this.#runtimeStream.write({\n jobId: job.id,\n data: {\n jsonrpc: '2.0',\n method: 'terminateJob',\n id: nanoid(),\n },\n });\n }\n\n /**\n * Create a new stream for the specified job. This wraps the runtime stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(jobId: string) {\n // Lazily create the worker pool document.\n await this.createDocument();\n\n // `createDocument` should have initialized the runtime stream.\n assert(this.#runtimeStream, 'Runtime stream not initialized.');\n\n const stream = new ProxyPostMessageStream({\n stream: this.#runtimeStream,\n jobId,\n });\n\n return { worker: jobId, stream };\n }\n\n /**\n * Creates the worker pool document to be used as the execution environment.\n *\n * If the document already exists, this does nothing.\n */\n private async createDocument() {\n // We only want to create a single pool.\n if (document.getElementById(WORKER_POOL_ID)) {\n return;\n }\n\n const window = await createWindow({\n uri: this.#documentUrl.href,\n id: WORKER_POOL_ID,\n sandbox: false,\n });\n\n this.#runtimeStream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: window,\n targetOrigin: '*',\n });\n }\n}\n"]}
1
+ {"version":3,"file":"WebWorkerExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/webworker/WebWorkerExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uEAAwE;AACxE,uDAAqD;AACrD,2CAAyC;AACzC,mCAAgC;AAMhC,8EAAuE;AACvE,0EAAmE;AAMtD,QAAA,cAAc,GAAG,mBAAmB,CAAC;AAElD,MAAa,yBAA0B,SAAQ,mDAAgC;IAK7E;;;;;;;;;;OAUG;IACH,YAAY,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACkC;QACzC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAzBI,yDAAkB;QAE3B,2DAAuC;QAyBrC,uBAAA,IAAI,0CAAgB,WAAW,MAAA,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACH,wEAAwE;IACxE,WAAW;IACX,kEAAkE;IACxD,KAAK,CAAC,YAAY,CAAC,GAA6B;QACxD,0EAA0E;QAC1E,8CAA8C;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asePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\nimport { createWindow } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport { ProxyPostMessageStream } from '../ProxyPostMessageStream';\n\ntype WebWorkerExecutionEnvironmentServiceArgs = {\n documentUrl: URL;\n} & ExecutionServiceArgs;\n\nexport const WORKER_POOL_ID = 'snaps-worker-pool';\n\nexport class WebWorkerExecutionService extends AbstractExecutionService<string> {\n readonly #documentUrl: URL;\n\n #runtimeStream?: BasePostMessageStream;\n\n /**\n * Create a new webworker execution service.\n *\n * @param args - The constructor arguments.\n * @param args.documentUrl - The URL of the worker pool document to use as the\n * execution environment.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n */\n constructor({\n documentUrl,\n messenger,\n setupSnapProvider,\n ...args\n }: WebWorkerExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n\n this.#documentUrl = documentUrl;\n }\n\n /**\n * Send a termination command to the worker pool document.\n *\n * @param job - The job to terminate.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n protected async terminateJob(job: TerminateJobArgs<string>) {\n // The `AbstractExecutionService` will have already closed the job stream,\n // so we write to the runtime stream directly.\n assert(this.#runtimeStream, 'Runtime stream not initialized.');\n this.#runtimeStream.write({\n jobId: job.id,\n data: {\n jsonrpc: '2.0',\n method: 'terminateJob',\n id: nanoid(),\n },\n });\n }\n\n /**\n * Create a new stream for the specified job. This wraps the runtime stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(jobId: string) {\n // Lazily create the worker pool document.\n await this.createDocument();\n\n // `createDocument` should have initialized the runtime stream.\n assert(this.#runtimeStream, 'Runtime stream not initialized.');\n\n const stream = new ProxyPostMessageStream({\n stream: this.#runtimeStream,\n jobId,\n });\n\n return { worker: jobId, stream };\n }\n\n /**\n * Creates the worker pool document to be used as the execution environment.\n *\n * If the document already exists, this does nothing.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private async createDocument() {\n // We only want to create a single pool.\n if (document.getElementById(WORKER_POOL_ID)) {\n return;\n }\n\n const window = await createWindow({\n uri: this.#documentUrl.href,\n id: WORKER_POOL_ID,\n sandbox: false,\n });\n\n this.#runtimeStream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: window,\n targetOrigin: '*',\n });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"WebWorkerExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/webworker/WebWorkerExecutionService.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,wCAAwC,GAAG;IAC9C,WAAW,EAAE,GAAG,CAAC;CAClB,GAAG,oBAAoB,CAAC;AAEzB,eAAO,MAAM,cAAc,sBAAsB,CAAC;AAElD,qBAAa,yBAA0B,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAK7E;;;;;;;;;;OAUG;gBACS,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,wCAAwC;IAU3C;;;;OAIG;cACa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAc1D;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;IAe3C;;;;OAIG;YACW,cAAc;CAmB7B"}
1
+ {"version":3,"file":"WebWorkerExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/webworker/WebWorkerExecutionService.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,wCAAwC,GAAG;IAC9C,WAAW,EAAE,GAAG,CAAC;CAClB,GAAG,oBAAoB,CAAC;AAEzB,eAAO,MAAM,cAAc,sBAAsB,CAAC;AAElD,qBAAa,yBAA0B,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAK7E;;;;;;;;;;OAUG;gBACS,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,wCAAwC;IAU3C;;;;OAIG;cAIa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAc1D;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;IAe3C;;;;OAIG;YAIW,cAAc;CAmB7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"WebWorkerExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/webworker/WebWorkerExecutionService.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,wCAAwC,GAAG;IAC9C,WAAW,EAAE,GAAG,CAAC;CAClB,GAAG,oBAAoB,CAAC;AAEzB,eAAO,MAAM,cAAc,sBAAsB,CAAC;AAElD,qBAAa,yBAA0B,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAK7E;;;;;;;;;;OAUG;gBACS,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,wCAAwC;IAU3C;;;;OAIG;cACa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAc1D;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;IAe3C;;;;OAIG;YACW,cAAc;CAmB7B"}
1
+ {"version":3,"file":"WebWorkerExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/webworker/WebWorkerExecutionService.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,wCAAwC,GAAG;IAC9C,WAAW,EAAE,GAAG,CAAC;CAClB,GAAG,oBAAoB,CAAC;AAEzB,eAAO,MAAM,cAAc,sBAAsB,CAAC;AAElD,qBAAa,yBAA0B,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAK7E;;;;;;;;;;OAUG;gBACS,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,wCAAwC;IAU3C;;;;OAIG;cAIa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAc1D;;;;;;OAMG;cACa,aAAa,CAAC,KAAK,EAAE,MAAM;;;;IAe3C;;;;OAIG;YAIW,cAAc;CAmB7B"}
@@ -44,6 +44,9 @@ export class WebWorkerExecutionService extends AbstractExecutionService {
44
44
  *
45
45
  * @param job - The job to terminate.
46
46
  */
47
+ // TODO: Either fix this lint violation or explain why it's necessary to
48
+ // ignore.
49
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
47
50
  async terminateJob(job) {
48
51
  // The `AbstractExecutionService` will have already closed the job stream,
49
52
  // so we write to the runtime stream directly.
@@ -80,6 +83,9 @@ export class WebWorkerExecutionService extends AbstractExecutionService {
80
83
  *
81
84
  * If the document already exists, this does nothing.
82
85
  */
86
+ // TODO: Either fix this lint violation or explain why it's necessary to
87
+ // ignore.
88
+ // eslint-disable-next-line no-restricted-syntax
83
89
  async createDocument() {
84
90
  // We only want to create a single pool.
85
91
  if (document.getElementById(WORKER_POOL_ID)) {
@@ -1 +1 @@
1
- {"version":3,"file":"WebWorkerExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/webworker/WebWorkerExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,uBAAuB,EAAE,sCAAsC;AACxE,OAAO,EAAE,YAAY,EAAE,8BAA8B;AACrD,OAAO,EAAE,MAAM,EAAE,wBAAwB;AACzC,OAAO,EAAE,MAAM,EAAE,eAAe;AAMhC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAMnE,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAElD,MAAM,OAAO,yBAA0B,SAAQ,wBAAgC;IAK7E;;;;;;;;;;OAUG;IACH,YAAY,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACkC;QACzC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAzBL,yDAAkB;QAElB,2DAAuC;QAyBrC,uBAAA,IAAI,0CAAgB,WAAW,MAAA,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,YAAY,CAAC,GAA6B;QACxD,0EAA0E;QAC1E,8CAA8C;QAC9C,MAAM,CAAC,uBAAA,IAAI,gDAAe,EAAE,iCAAiC,CAAC,CAAC;QAC/D,uBAAA,IAAI,gDAAe,CAAC,KAAK,CAAC;YACxB,KAAK,EAAE,GAAG,CAAC,EAAE;YACb,IAAI,EAAE;gBACJ,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,cAAc;gBACtB,EAAE,EAAE,MAAM,EAAE;aACb;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,KAAa;QACzC,0CAA0C;QAC1C,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAE5B,+DAA+D;QAC/D,MAAM,CAAC,uBAAA,IAAI,gDAAe,EAAE,iCAAiC,CAAC,CAAC;QAE/D,MAAM,MAAM,GAAG,IAAI,sBAAsB,CAAC;YACxC,MAAM,EAAE,uBAAA,IAAI,gDAAe;YAC3B,KAAK;SACN,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,cAAc;QAC1B,wCAAwC;QACxC,IAAI,QAAQ,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,CAAC;YAC5C,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC;YAChC,GAAG,EAAE,uBAAA,IAAI,8CAAa,CAAC,IAAI;YAC3B,EAAE,EAAE,cAAc;YAClB,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QAEH,uBAAA,IAAI,4CAAkB,IAAI,uBAAuB,CAAC;YAChD,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,YAAY,EAAE,MAAM;YACpB,YAAY,EAAE,GAAG;SAClB,CAAC,MAAA,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\nimport { createWindow } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport { ProxyPostMessageStream } from '../ProxyPostMessageStream';\n\ntype WebWorkerExecutionEnvironmentServiceArgs = {\n documentUrl: URL;\n} & ExecutionServiceArgs;\n\nexport const WORKER_POOL_ID = 'snaps-worker-pool';\n\nexport class WebWorkerExecutionService extends AbstractExecutionService<string> {\n #documentUrl: URL;\n\n #runtimeStream?: BasePostMessageStream;\n\n /**\n * Create a new webworker execution service.\n *\n * @param args - The constructor arguments.\n * @param args.documentUrl - The URL of the worker pool document to use as the\n * execution environment.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n */\n constructor({\n documentUrl,\n messenger,\n setupSnapProvider,\n ...args\n }: WebWorkerExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n\n this.#documentUrl = documentUrl;\n }\n\n /**\n * Send a termination command to the worker pool document.\n *\n * @param job - The job to terminate.\n */\n protected async terminateJob(job: TerminateJobArgs<string>) {\n // The `AbstractExecutionService` will have already closed the job stream,\n // so we write to the runtime stream directly.\n assert(this.#runtimeStream, 'Runtime stream not initialized.');\n this.#runtimeStream.write({\n jobId: job.id,\n data: {\n jsonrpc: '2.0',\n method: 'terminateJob',\n id: nanoid(),\n },\n });\n }\n\n /**\n * Create a new stream for the specified job. This wraps the runtime stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(jobId: string) {\n // Lazily create the worker pool document.\n await this.createDocument();\n\n // `createDocument` should have initialized the runtime stream.\n assert(this.#runtimeStream, 'Runtime stream not initialized.');\n\n const stream = new ProxyPostMessageStream({\n stream: this.#runtimeStream,\n jobId,\n });\n\n return { worker: jobId, stream };\n }\n\n /**\n * Creates the worker pool document to be used as the execution environment.\n *\n * If the document already exists, this does nothing.\n */\n private async createDocument() {\n // We only want to create a single pool.\n if (document.getElementById(WORKER_POOL_ID)) {\n return;\n }\n\n const window = await createWindow({\n uri: this.#documentUrl.href,\n id: WORKER_POOL_ID,\n sandbox: false,\n });\n\n this.#runtimeStream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: window,\n targetOrigin: '*',\n });\n }\n}\n"]}
1
+ {"version":3,"file":"WebWorkerExecutionService.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Ae,EAAE,iCAAiC,CAAC,CAAC;QAE/D,MAAM,MAAM,GAAG,IAAI,sBAAsB,CAAC;YACxC,MAAM,EAAE,uBAAA,IAAI,gDAAe;YAC3B,KAAK;SACN,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,wEAAwE;IACxE,WAAW;IACX,gDAAgD;IACxC,KAAK,CAAC,cAAc;QAC1B,wCAAwC;QACxC,IAAI,QAAQ,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,CAAC;YAC5C,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC;YAChC,GAAG,EAAE,uBAAA,IAAI,8CAAa,CAAC,IAAI;YAC3B,EAAE,EAAE,cAAc;YAClB,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QAEH,uBAAA,IAAI,4CAAkB,IAAI,uBAAuB,CAAC;YAChD,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,YAAY,EAAE,MAAM;YACpB,YAAY,EAAE,GAAG;SAClB,CAAC,MAAA,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\nimport { createWindow } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport { ProxyPostMessageStream } from '../ProxyPostMessageStream';\n\ntype WebWorkerExecutionEnvironmentServiceArgs = {\n documentUrl: URL;\n} & ExecutionServiceArgs;\n\nexport const WORKER_POOL_ID = 'snaps-worker-pool';\n\nexport class WebWorkerExecutionService extends AbstractExecutionService<string> {\n readonly #documentUrl: URL;\n\n #runtimeStream?: BasePostMessageStream;\n\n /**\n * Create a new webworker execution service.\n *\n * @param args - The constructor arguments.\n * @param args.documentUrl - The URL of the worker pool document to use as the\n * execution environment.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n */\n constructor({\n documentUrl,\n messenger,\n setupSnapProvider,\n ...args\n }: WebWorkerExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n\n this.#documentUrl = documentUrl;\n }\n\n /**\n * Send a termination command to the worker pool document.\n *\n * @param job - The job to terminate.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n protected async terminateJob(job: TerminateJobArgs<string>) {\n // The `AbstractExecutionService` will have already closed the job stream,\n // so we write to the runtime stream directly.\n assert(this.#runtimeStream, 'Runtime stream not initialized.');\n this.#runtimeStream.write({\n jobId: job.id,\n data: {\n jsonrpc: '2.0',\n method: 'terminateJob',\n id: nanoid(),\n },\n });\n }\n\n /**\n * Create a new stream for the specified job. This wraps the runtime stream\n * in a stream specific to the job.\n *\n * @param jobId - The job ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(jobId: string) {\n // Lazily create the worker pool document.\n await this.createDocument();\n\n // `createDocument` should have initialized the runtime stream.\n assert(this.#runtimeStream, 'Runtime stream not initialized.');\n\n const stream = new ProxyPostMessageStream({\n stream: this.#runtimeStream,\n jobId,\n });\n\n return { worker: jobId, stream };\n }\n\n /**\n * Creates the worker pool document to be used as the execution environment.\n *\n * If the document already exists, this does nothing.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private async createDocument() {\n // We only want to create a single pool.\n if (document.getElementById(WORKER_POOL_ID)) {\n return;\n }\n\n const window = await createWindow({\n uri: this.#documentUrl.href,\n id: WORKER_POOL_ID,\n sandbox: false,\n });\n\n this.#runtimeStream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: window,\n targetOrigin: '*',\n });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"RequestQueue.cjs","sourceRoot":"","sources":["../../src/snaps/RequestQueue.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAKvB,YAAY,YAAoB;QAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAc;QAC7B,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,YAAY,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAc;QAC7B,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,qBAAqB,MAAM,0CAA0C,CACtE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAC,MAAc;QACvB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF;AA/CD,oCA+CC","sourcesContent":["export class RequestQueue {\n public readonly maxQueueSize: number;\n\n private readonly queueSizes: Map<string, number>;\n\n constructor(maxQueueSize: number) {\n this.maxQueueSize = maxQueueSize;\n this.queueSizes = new Map<string, number>();\n }\n\n /**\n * Increments the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n */\n public increment(origin: string) {\n const currentCount = this.queueSizes.get(origin) ?? 0;\n if (currentCount >= this.maxQueueSize) {\n throw new Error('Maximum number of requests reached. Try again later.');\n }\n this.queueSizes.set(origin, currentCount + 1);\n }\n\n /**\n * Decrements the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n */\n public decrement(origin: string) {\n const currentCount = this.queueSizes.get(origin) ?? 0;\n if (currentCount === 0) {\n throw new Error(\n `Cannot decrement, ${origin} does not have any outstanding requests.`,\n );\n }\n this.queueSizes.set(origin, currentCount - 1);\n }\n\n /**\n * Gets the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n * @returns The queue count for the origin.\n */\n public get(origin: string): number {\n return this.queueSizes.get(origin) ?? 0;\n }\n}\n"]}
1
+ {"version":3,"file":"RequestQueue.cjs","sourceRoot":"","sources":["../../src/snaps/RequestQueue.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAQvB,YAAY,YAAoB;QAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAc;QAC7B,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,YAAY,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAc;QAC7B,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,qBAAqB,MAAM,0CAA0C,CACtE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAC,MAAc;QACvB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF;AAlDD,oCAkDC","sourcesContent":["export class RequestQueue {\n public readonly maxQueueSize: number;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly queueSizes: Map<string, number>;\n\n constructor(maxQueueSize: number) {\n this.maxQueueSize = maxQueueSize;\n this.queueSizes = new Map<string, number>();\n }\n\n /**\n * Increments the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n */\n public increment(origin: string) {\n const currentCount = this.queueSizes.get(origin) ?? 0;\n if (currentCount >= this.maxQueueSize) {\n throw new Error('Maximum number of requests reached. Try again later.');\n }\n this.queueSizes.set(origin, currentCount + 1);\n }\n\n /**\n * Decrements the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n */\n public decrement(origin: string) {\n const currentCount = this.queueSizes.get(origin) ?? 0;\n if (currentCount === 0) {\n throw new Error(\n `Cannot decrement, ${origin} does not have any outstanding requests.`,\n );\n }\n this.queueSizes.set(origin, currentCount - 1);\n }\n\n /**\n * Gets the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n * @returns The queue count for the origin.\n */\n public get(origin: string): number {\n return this.queueSizes.get(origin) ?? 0;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"RequestQueue.d.cts","sourceRoot":"","sources":["../../src/snaps/RequestQueue.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;IACvB,SAAgB,YAAY,EAAE,MAAM,CAAC;IAErC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;gBAErC,YAAY,EAAE,MAAM;IAKhC;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM;IAQ/B;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM;IAU/B;;;;;OAKG;IACI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAGnC"}
1
+ {"version":3,"file":"RequestQueue.d.cts","sourceRoot":"","sources":["../../src/snaps/RequestQueue.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;IACvB,SAAgB,YAAY,EAAE,MAAM,CAAC;IAKrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;gBAErC,YAAY,EAAE,MAAM;IAKhC;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM;IAQ/B;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM;IAU/B;;;;;OAKG;IACI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAGnC"}
@@ -1 +1 @@
1
- {"version":3,"file":"RequestQueue.d.mts","sourceRoot":"","sources":["../../src/snaps/RequestQueue.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;IACvB,SAAgB,YAAY,EAAE,MAAM,CAAC;IAErC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;gBAErC,YAAY,EAAE,MAAM;IAKhC;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM;IAQ/B;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM;IAU/B;;;;;OAKG;IACI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAGnC"}
1
+ {"version":3,"file":"RequestQueue.d.mts","sourceRoot":"","sources":["../../src/snaps/RequestQueue.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;IACvB,SAAgB,YAAY,EAAE,MAAM,CAAC;IAKrC,OAAO,CAA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AAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["export class RequestQueue {\n public readonly maxQueueSize: number;\n\n private readonly queueSizes: Map<string, number>;\n\n constructor(maxQueueSize: number) {\n this.maxQueueSize = maxQueueSize;\n this.queueSizes = new Map<string, number>();\n }\n\n /**\n * Increments the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n */\n public increment(origin: string) {\n const currentCount = this.queueSizes.get(origin) ?? 0;\n if (currentCount >= this.maxQueueSize) {\n throw new Error('Maximum number of requests reached. Try again later.');\n }\n this.queueSizes.set(origin, currentCount + 1);\n }\n\n /**\n * Decrements the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n */\n public decrement(origin: string) {\n const currentCount = this.queueSizes.get(origin) ?? 0;\n if (currentCount === 0) {\n throw new Error(\n `Cannot decrement, ${origin} does not have any outstanding requests.`,\n );\n }\n this.queueSizes.set(origin, currentCount - 1);\n }\n\n /**\n * Gets the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n * @returns The queue count for the origin.\n */\n public get(origin: string): number {\n return this.queueSizes.get(origin) ?? 0;\n }\n}\n"]}
1
+ {"version":3,"file":"RequestQueue.mjs","sourceRoot":"","sources":["../../src/snaps/RequestQueue.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAY;IAQvB,YAAY,YAAoB;QAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAc;QAC7B,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,YAAY,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAc;QAC7B,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,qBAAqB,MAAM,0CAA0C,CACtE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAC,MAAc;QACvB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["export class RequestQueue {\n public readonly maxQueueSize: number;\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line no-restricted-syntax\n private readonly queueSizes: Map<string, number>;\n\n constructor(maxQueueSize: number) {\n this.maxQueueSize = maxQueueSize;\n this.queueSizes = new Map<string, number>();\n }\n\n /**\n * Increments the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n */\n public increment(origin: string) {\n const currentCount = this.queueSizes.get(origin) ?? 0;\n if (currentCount >= this.maxQueueSize) {\n throw new Error('Maximum number of requests reached. Try again later.');\n }\n this.queueSizes.set(origin, currentCount + 1);\n }\n\n /**\n * Decrements the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n */\n public decrement(origin: string) {\n const currentCount = this.queueSizes.get(origin) ?? 0;\n if (currentCount === 0) {\n throw new Error(\n `Cannot decrement, ${origin} does not have any outstanding requests.`,\n );\n }\n this.queueSizes.set(origin, currentCount - 1);\n }\n\n /**\n * Gets the queue count for a particular origin.\n *\n * @param origin - A string identifying the origin.\n * @returns The queue count for the origin.\n */\n public get(origin: string): number {\n return this.queueSizes.get(origin) ?? 0;\n }\n}\n"]}
@@ -10,10 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- var _SnapController_instances, _SnapController_closeAllConnections, _SnapController_dynamicPermissions, _SnapController_environmentEndowmentPermissions, _SnapController_excludedPermissions, _SnapController_featureFlags, _SnapController_fetchFunction, _SnapController_idleTimeCheckInterval, _SnapController_maxIdleTime, _SnapController_encryptor, _SnapController_getMnemonic, _SnapController_getFeatureFlags, _SnapController_clientCryptography, _SnapController_detectSnapLocation, _SnapController_snapsRuntimeData, _SnapController_rollbackSnapshots, _SnapController_timeoutForLastRequestStatus, _SnapController_statusMachine, _SnapController_preinstalledSnaps, _SnapController_initializeStateMachine, _SnapController_registerMessageHandlers, _SnapController_handlePreinstalledSnaps, _SnapController_pollForLastRequestStatus, _SnapController_blockSnap, _SnapController_unblockSnap, _SnapController_assertIsInstallAllowed, _SnapController_assertCanInstallSnaps, _SnapController_assertCanUsePlatform, _SnapController_stopSnapsLastRequestPastMax, _SnapController_transition, _SnapController_terminateSnap, _SnapController_getSnapEncryptionKey, _SnapController_hasCachedEncryptionKey, _SnapController_decryptSnapState, _SnapController_encryptSnapState, _SnapController_getStateToPersist, _SnapController_persistSnapState, _SnapController_handleInitialConnections, _SnapController_addSnapToSubject, _SnapController_removeSnapFromSubjects, _SnapController_revokeAllSnapPermissions, _SnapController_createApproval, _SnapController_updateApproval, _SnapController_resolveAllowlistVersion, _SnapController_add, _SnapController_startSnap, _SnapController_getEndowments, _SnapController_set, _SnapController_validateSnapPermissions, _SnapController_validatePlatformVersion, _SnapController_getExecutionTimeout, _SnapController_getRpcRequestHandler, _SnapController_createInterface, _SnapController_assertInterfaceExists, _SnapController_transformSnapRpcRequestResult, _SnapController_transformOnAssetsLookupResult, _SnapController_transformOnAssetsConversionResult, _SnapController_assertSnapRpcRequestResult, _SnapController_recordSnapRpcRequestStart, _SnapController_recordSnapRpcRequestFinish, _SnapController_getRollbackSnapshot, _SnapController_createRollbackSnapshot, _SnapController_rollbackSnap, _SnapController_rollbackSnaps, _SnapController_getRuntime, _SnapController_getRuntimeExpect, _SnapController_setupRuntime, _SnapController_calculatePermissionsChange, _SnapController_isSubjectConnectedToSnap, _SnapController_calculateConnectionsChange, _SnapController_updatePermissions, _SnapController_isValidUpdate, _SnapController_callLifecycleHook, _SnapController_handleLock;
13
+ var _SnapController_instances, _SnapController_closeAllConnections, _SnapController_dynamicPermissions, _SnapController_environmentEndowmentPermissions, _SnapController_excludedPermissions, _SnapController_featureFlags, _SnapController_fetchFunction, _SnapController_idleTimeCheckInterval, _SnapController_maxIdleTime, _SnapController_encryptor, _SnapController_getMnemonicSeed, _SnapController_getFeatureFlags, _SnapController_clientCryptography, _SnapController_detectSnapLocation, _SnapController_snapsRuntimeData, _SnapController_rollbackSnapshots, _SnapController_timeoutForLastRequestStatus, _SnapController_statusMachine, _SnapController_preinstalledSnaps, _SnapController_initializeStateMachine, _SnapController_registerMessageHandlers, _SnapController_handlePreinstalledSnaps, _SnapController_pollForLastRequestStatus, _SnapController_blockSnap, _SnapController_unblockSnap, _SnapController_assertIsInstallAllowed, _SnapController_assertCanInstallSnaps, _SnapController_assertCanUsePlatform, _SnapController_stopSnapsLastRequestPastMax, _SnapController_transition, _SnapController_terminateSnap, _SnapController_getSnapEncryptionKey, _SnapController_hasCachedEncryptionKey, _SnapController_decryptSnapState, _SnapController_encryptSnapState, _SnapController_getStateToPersist, _SnapController_persistSnapState, _SnapController_handleInitialConnections, _SnapController_addSnapToSubject, _SnapController_removeSnapFromSubjects, _SnapController_revokeAllSnapPermissions, _SnapController_createApproval, _SnapController_updateApproval, _SnapController_resolveAllowlistVersion, _SnapController_add, _SnapController_startSnap, _SnapController_getEndowments, _SnapController_set, _SnapController_validateSnapPermissions, _SnapController_validatePlatformVersion, _SnapController_getExecutionTimeout, _SnapController_getRpcRequestHandler, _SnapController_createInterface, _SnapController_assertInterfaceExists, _SnapController_transformSnapRpcRequestResult, _SnapController_transformOnAssetsLookupResult, _SnapController_transformOnAssetsConversionResult, _SnapController_assertSnapRpcRequestResult, _SnapController_recordSnapRpcRequestStart, _SnapController_recordSnapRpcRequestFinish, _SnapController_getRollbackSnapshot, _SnapController_createRollbackSnapshot, _SnapController_rollbackSnap, _SnapController_rollbackSnaps, _SnapController_getRuntime, _SnapController_getRuntimeExpect, _SnapController_setupRuntime, _SnapController_calculatePermissionsChange, _SnapController_isSubjectConnectedToSnap, _SnapController_calculateConnectionsChange, _SnapController_updatePermissions, _SnapController_isValidUpdate, _SnapController_callLifecycleHook, _SnapController_handleLock;
17
14
  Object.defineProperty(exports, "__esModule", { value: true });
18
15
  exports.SnapController = exports.SNAP_APPROVAL_RESULT = exports.SNAP_APPROVAL_UPDATE = exports.SNAP_APPROVAL_INSTALL = exports.controllerName = void 0;
19
16
  const base_controller_1 = require("@metamask/base-controller");
@@ -26,16 +23,16 @@ const utils_1 = require("@metamask/utils");
26
23
  const fsm_1 = require("@xstate/fsm");
27
24
  const async_mutex_1 = require("async-mutex");
28
25
  const nanoid_1 = require("nanoid");
29
- const semver_1 = __importDefault(require("semver"));
30
- const fsm_2 = require("../fsm.cjs");
31
- const logging_1 = require("../logging.cjs");
32
- const utils_2 = require("../utils.cjs");
26
+ const semver_1 = require("semver");
33
27
  const constants_1 = require("./constants.cjs");
34
28
  const location_1 = require("./location/index.cjs");
35
29
  const registry_1 = require("./registry/index.cjs");
36
30
  const RequestQueue_1 = require("./RequestQueue.cjs");
37
31
  const selectors_1 = require("./selectors.cjs");
38
32
  const Timer_1 = require("./Timer.cjs");
33
+ const fsm_2 = require("../fsm.cjs");
34
+ const logging_1 = require("../logging.cjs");
35
+ const utils_2 = require("../utils.cjs");
39
36
  exports.controllerName = 'SnapController';
40
37
  // TODO: Figure out how to name these
41
38
  exports.SNAP_APPROVAL_INSTALL = 'wallet_installSnap';
@@ -66,7 +63,6 @@ function truncateSnap(snap) {
66
63
  }
67
64
  return serialized;
68
65
  }, {});
69
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
70
66
  return truncatedSnap;
71
67
  }
72
68
  /*
@@ -76,7 +72,7 @@ function truncateSnap(snap) {
76
72
  * - Start: Initializes the snap in its SES realm with the authorized permissions.
77
73
  */
78
74
  class SnapController extends base_controller_1.BaseController {
79
- constructor({ closeAllConnections, messenger, state, dynamicPermissions = ['eth_accounts'], environmentEndowmentPermissions = [], excludedPermissions = {}, idleTimeCheckInterval = (0, utils_1.inMilliseconds)(5, utils_1.Duration.Second), maxIdleTime = (0, utils_1.inMilliseconds)(30, utils_1.Duration.Second), maxRequestTime = (0, utils_1.inMilliseconds)(60, utils_1.Duration.Second), fetchFunction = globalThis.fetch.bind(undefined), featureFlags = {}, detectSnapLocation: detectSnapLocationFunction = location_1.detectSnapLocation, preinstalledSnaps = null, encryptor, getMnemonic, getFeatureFlags = () => ({}), clientCryptography, }) {
75
+ constructor({ closeAllConnections, messenger, state, dynamicPermissions = ['eth_accounts'], environmentEndowmentPermissions = [], excludedPermissions = {}, idleTimeCheckInterval = (0, utils_1.inMilliseconds)(5, utils_1.Duration.Second), maxIdleTime = (0, utils_1.inMilliseconds)(30, utils_1.Duration.Second), maxRequestTime = (0, utils_1.inMilliseconds)(60, utils_1.Duration.Second), fetchFunction = globalThis.fetch.bind(undefined), featureFlags = {}, detectSnapLocation: detectSnapLocationFunction = location_1.detectSnapLocation, preinstalledSnaps = null, encryptor, getMnemonicSeed, getFeatureFlags = () => ({}), clientCryptography, }) {
80
76
  super({
81
77
  messenger,
82
78
  metadata: {
@@ -125,7 +121,7 @@ class SnapController extends base_controller_1.BaseController {
125
121
  _SnapController_idleTimeCheckInterval.set(this, void 0);
126
122
  _SnapController_maxIdleTime.set(this, void 0);
127
123
  _SnapController_encryptor.set(this, void 0);
128
- _SnapController_getMnemonic.set(this, void 0);
124
+ _SnapController_getMnemonicSeed.set(this, void 0);
129
125
  _SnapController_getFeatureFlags.set(this, void 0);
130
126
  _SnapController_clientCryptography.set(this, void 0);
131
127
  _SnapController_detectSnapLocation.set(this, void 0);
@@ -145,7 +141,7 @@ class SnapController extends base_controller_1.BaseController {
145
141
  this.maxRequestTime = maxRequestTime;
146
142
  __classPrivateFieldSet(this, _SnapController_detectSnapLocation, detectSnapLocationFunction, "f");
147
143
  __classPrivateFieldSet(this, _SnapController_encryptor, encryptor, "f");
148
- __classPrivateFieldSet(this, _SnapController_getMnemonic, getMnemonic, "f");
144
+ __classPrivateFieldSet(this, _SnapController_getMnemonicSeed, getMnemonicSeed, "f");
149
145
  __classPrivateFieldSet(this, _SnapController_getFeatureFlags, getFeatureFlags, "f");
150
146
  __classPrivateFieldSet(this, _SnapController_clientCryptography, clientCryptography, "f");
151
147
  __classPrivateFieldSet(this, _SnapController_preinstalledSnaps, preinstalledSnaps, "f");
@@ -200,7 +196,10 @@ class SnapController extends base_controller_1.BaseController {
200
196
  return __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_unblockSnap).call(this, snapId);
201
197
  }));
202
198
  }
203
- _onUnhandledSnapError(snapId, _error) {
199
+ _onUnhandledSnapError(snapId, error) {
200
+ // Log the error that caused the crash
201
+ // so it gets raised to the developer for debugging purposes.
202
+ (0, snaps_utils_1.logError)(`Unhandled error from "${snapId}":`, error);
204
203
  this.stopSnap(snapId, snaps_utils_1.SnapStatusEvents.Crash).catch((stopSnapError) => {
205
204
  // TODO: Decide how to handle errors.
206
205
  (0, snaps_utils_1.logError)(stopSnapError);
@@ -233,7 +232,7 @@ class SnapController extends base_controller_1.BaseController {
233
232
  async startSnap(snapId) {
234
233
  __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_assertCanUsePlatform).call(this);
235
234
  const snap = this.state.snaps[snapId];
236
- if (snap.enabled === false) {
235
+ if (!snap.enabled) {
237
236
  throw new Error(`Snap "${snapId}" is disabled.`);
238
237
  }
239
238
  await __classPrivateFieldGet(this, _SnapController_instances, "m", _SnapController_startSnap).call(this, {
@@ -725,6 +724,9 @@ class SnapController extends base_controller_1.BaseController {
725
724
  * @param versionRange - The semver range of the snap to install.
726
725
  * @returns The resulting snap object, or an error if something went wrong.
727
726
  */
727
+ // TODO: Either fix this lint violation or explain why it's necessary to
728
+ // ignore.
729
+ // eslint-disable-next-line no-restricted-syntax
728
730
  async processRequestedSnap(origin, snapId, location, versionRange) {
729
731
  const existingSnap = this.getTruncated(snapId);
730
732
  // For devX we always re-install local snaps.
@@ -941,6 +943,7 @@ class SnapController extends base_controller_1.BaseController {
941
943
  * @param pendingApproval - Pending approval to update.
942
944
  * @returns The snap's approvedPermissions.
943
945
  */
946
+ // eslint-disable-next-line no-restricted-syntax
944
947
  async authorize(snapId, pendingApproval) {
945
948
  (0, logging_1.log)(`Authorizing snap: ${snapId}`);
946
949
  const snapsState = this.state.snaps;
@@ -1032,7 +1035,7 @@ class SnapController extends base_controller_1.BaseController {
1032
1035
  }
1033
1036
  }
1034
1037
  exports.SnapController = SnapController;
1035
- _SnapController_closeAllConnections = new WeakMap(), _SnapController_dynamicPermissions = new WeakMap(), _SnapController_environmentEndowmentPermissions = new WeakMap(), _SnapController_excludedPermissions = new WeakMap(), _SnapController_featureFlags = new WeakMap(), _SnapController_fetchFunction = new WeakMap(), _SnapController_idleTimeCheckInterval = new WeakMap(), _SnapController_maxIdleTime = new WeakMap(), _SnapController_encryptor = new WeakMap(), _SnapController_getMnemonic = new WeakMap(), _SnapController_getFeatureFlags = new WeakMap(), _SnapController_clientCryptography = new WeakMap(), _SnapController_detectSnapLocation = new WeakMap(), _SnapController_snapsRuntimeData = new WeakMap(), _SnapController_rollbackSnapshots = new WeakMap(), _SnapController_timeoutForLastRequestStatus = new WeakMap(), _SnapController_statusMachine = new WeakMap(), _SnapController_preinstalledSnaps = new WeakMap(), _SnapController_instances = new WeakSet(), _SnapController_initializeStateMachine = function _SnapController_initializeStateMachine() {
1038
+ _SnapController_closeAllConnections = new WeakMap(), _SnapController_dynamicPermissions = new WeakMap(), _SnapController_environmentEndowmentPermissions = new WeakMap(), _SnapController_excludedPermissions = new WeakMap(), _SnapController_featureFlags = new WeakMap(), _SnapController_fetchFunction = new WeakMap(), _SnapController_idleTimeCheckInterval = new WeakMap(), _SnapController_maxIdleTime = new WeakMap(), _SnapController_encryptor = new WeakMap(), _SnapController_getMnemonicSeed = new WeakMap(), _SnapController_getFeatureFlags = new WeakMap(), _SnapController_clientCryptography = new WeakMap(), _SnapController_detectSnapLocation = new WeakMap(), _SnapController_snapsRuntimeData = new WeakMap(), _SnapController_rollbackSnapshots = new WeakMap(), _SnapController_timeoutForLastRequestStatus = new WeakMap(), _SnapController_statusMachine = new WeakMap(), _SnapController_preinstalledSnaps = new WeakMap(), _SnapController_instances = new WeakSet(), _SnapController_initializeStateMachine = function _SnapController_initializeStateMachine() {
1036
1039
  const disableGuard = ({ snapId }) => {
1037
1040
  return this.getExpect(snapId).enabled;
1038
1041
  };
@@ -1285,10 +1288,10 @@ async function _SnapController_getSnapEncryptionKey({ snapId, salt: passedSalt,
1285
1288
  };
1286
1289
  }
1287
1290
  const salt = passedSalt ?? __classPrivateFieldGet(this, _SnapController_encryptor, "f").generateSalt();
1288
- const mnemonicPhrase = await __classPrivateFieldGet(this, _SnapController_getMnemonic, "f").call(this);
1291
+ const seed = await __classPrivateFieldGet(this, _SnapController_getMnemonicSeed, "f").call(this);
1289
1292
  const entropy = await (0, snaps_rpc_methods_1.getEncryptionEntropy)({
1290
1293
  snapId,
1291
- mnemonicPhrase,
1294
+ seed,
1292
1295
  cryptographicFunctions: __classPrivateFieldGet(this, _SnapController_clientCryptography, "f"),
1293
1296
  });
1294
1297
  const encryptionKey = await __classPrivateFieldGet(this, _SnapController_encryptor, "f").keyFromPassword(entropy, salt, true, keyMetadata);
@@ -1579,8 +1582,6 @@ async function _SnapController_getEndowments(snapId) {
1579
1582
  ...new Set([...snaps_utils_1.DEFAULT_ENDOWMENTS, ...allEndowments]),
1580
1583
  ];
1581
1584
  if (dedupedEndowments.length <
1582
- // This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313
1583
- // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
1584
1585
  snaps_utils_1.DEFAULT_ENDOWMENTS.length + allEndowments.length) {
1585
1586
  (0, snaps_utils_1.logError)(`Duplicate endowments found for ${snapId}. Default endowments should not be requested.`, allEndowments);
1586
1587
  }
@@ -1675,7 +1676,7 @@ async function _SnapController_getEndowments(snapId) {
1675
1676
  if (platformVersion === undefined) {
1676
1677
  return;
1677
1678
  }
1678
- if (semver_1.default.gt(platformVersion, (0, snaps_utils_1.getPlatformVersion)())) {
1679
+ if ((0, semver_1.gt)(platformVersion, (0, snaps_utils_1.getPlatformVersion)())) {
1679
1680
  const message = `The Snap "${snapId}" requires platform version "${platformVersion}" which is greater than the current platform version "${(0, snaps_utils_1.getPlatformVersion)()}".`;
1680
1681
  if (__classPrivateFieldGet(this, _SnapController_featureFlags, "f").rejectInvalidPlatformVersion) {
1681
1682
  throw new Error(message);
@@ -1695,7 +1696,7 @@ async function _SnapController_getEndowments(snapId) {
1695
1696
  // because otherwise we would lose context on the correct startPromise.
1696
1697
  const startPromises = new Map();
1697
1698
  const rpcHandler = async ({ origin, handler: handlerType, request, timeout, }) => {
1698
- if (this.state.snaps[snapId].enabled === false) {
1699
+ if (!this.state.snaps[snapId].enabled) {
1699
1700
  throw new Error(`Snap "${snapId}" is disabled.`);
1700
1701
  }
1701
1702
  if (this.state.snaps[snapId].status === snaps_utils_1.SnapStatus.Installing) {