@metamask/snaps-controllers 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/cjs/services/ProxyPostMessageStream.js +3 -10
  3. package/dist/cjs/services/ProxyPostMessageStream.js.map +1 -1
  4. package/dist/cjs/services/node/NodeProcessExecutionService.js +13 -1
  5. package/dist/cjs/services/node/NodeProcessExecutionService.js.map +1 -1
  6. package/dist/cjs/services/node/NodeThreadExecutionService.js +14 -1
  7. package/dist/cjs/services/node/NodeThreadExecutionService.js.map +1 -1
  8. package/dist/cjs/services/offscreen/OffscreenExecutionService.js +36 -99
  9. package/dist/cjs/services/offscreen/OffscreenExecutionService.js.map +1 -1
  10. package/dist/cjs/services/proxy/ProxyExecutionService.js +110 -0
  11. package/dist/cjs/services/proxy/ProxyExecutionService.js.map +1 -0
  12. package/dist/cjs/snaps/SnapController.js +198 -93
  13. package/dist/cjs/snaps/SnapController.js.map +1 -1
  14. package/dist/cjs/snaps/endowments/enum.js +1 -0
  15. package/dist/cjs/snaps/endowments/enum.js.map +1 -1
  16. package/dist/cjs/snaps/endowments/index.js +12 -4
  17. package/dist/cjs/snaps/endowments/index.js.map +1 -1
  18. package/dist/cjs/snaps/endowments/signature-insight.js +106 -0
  19. package/dist/cjs/snaps/endowments/signature-insight.js.map +1 -0
  20. package/dist/cjs/utils.js +32 -0
  21. package/dist/cjs/utils.js.map +1 -1
  22. package/dist/esm/services/ProxyPostMessageStream.js +3 -10
  23. package/dist/esm/services/ProxyPostMessageStream.js.map +1 -1
  24. package/dist/esm/services/node/NodeProcessExecutionService.js +13 -1
  25. package/dist/esm/services/node/NodeProcessExecutionService.js.map +1 -1
  26. package/dist/esm/services/node/NodeThreadExecutionService.js +14 -1
  27. package/dist/esm/services/node/NodeThreadExecutionService.js.map +1 -1
  28. package/dist/esm/services/offscreen/OffscreenExecutionService.js +36 -99
  29. package/dist/esm/services/offscreen/OffscreenExecutionService.js.map +1 -1
  30. package/dist/esm/services/proxy/ProxyExecutionService.js +100 -0
  31. package/dist/esm/services/proxy/ProxyExecutionService.js.map +1 -0
  32. package/dist/esm/snaps/SnapController.js +200 -95
  33. package/dist/esm/snaps/SnapController.js.map +1 -1
  34. package/dist/esm/snaps/endowments/enum.js +1 -0
  35. package/dist/esm/snaps/endowments/enum.js.map +1 -1
  36. package/dist/esm/snaps/endowments/index.js +10 -4
  37. package/dist/esm/snaps/endowments/index.js.map +1 -1
  38. package/dist/esm/snaps/endowments/signature-insight.js +99 -0
  39. package/dist/esm/snaps/endowments/signature-insight.js.map +1 -0
  40. package/dist/esm/utils.js +37 -0
  41. package/dist/esm/utils.js.map +1 -1
  42. package/dist/types/services/ProxyPostMessageStream.d.ts +1 -2
  43. package/dist/types/services/offscreen/OffscreenExecutionService.d.ts +5 -22
  44. package/dist/types/services/proxy/ProxyExecutionService.d.ts +39 -0
  45. package/dist/types/snaps/SnapController.d.ts +31 -3
  46. package/dist/types/snaps/endowments/enum.d.ts +1 -0
  47. package/dist/types/snaps/endowments/index.d.ts +12 -0
  48. package/dist/types/snaps/endowments/signature-insight.d.ts +39 -0
  49. package/dist/types/utils.d.ts +99 -0
  50. package/package.json +8 -8
package/CHANGELOG.md CHANGED
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [4.1.0]
10
+ ### Added
11
+ - Add support for signature insights ([#2074](https://github.com/MetaMask/snaps/pull/2074))
12
+ - Add support for initial connections ([#2048](https://github.com/MetaMask/snaps/pull/2048))
13
+ - Add support for preinstalled snaps ([#2008](https://github.com/MetaMask/snaps/pull/2008))
14
+ - Add additional install events ([#2087](https://github.com/MetaMask/snaps/pull/2087))
15
+
16
+ ### Changed
17
+ - Bump several MetaMask dependencies ([#2086](https://github.com/MetaMask/snaps/pull/2086), [#2100](https://github.com/MetaMask/snaps/pull/2100))
18
+
9
19
  ## [4.0.0]
10
20
  ### Changed
11
21
  - **BREAKING:** Remove `:snapAdded` event ([#2073](https://github.com/MetaMask/snaps/pull/2073))
@@ -158,7 +168,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
158
168
  - The version of the package no longer needs to match the version of all other
159
169
  MetaMask Snaps packages.
160
170
 
161
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@4.0.0...HEAD
171
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@4.1.0...HEAD
172
+ [4.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@4.0.0...@metamask/snaps-controllers@4.1.0
162
173
  [4.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.6.0...@metamask/snaps-controllers@4.0.0
163
174
  [3.6.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.5.1...@metamask/snaps-controllers@3.6.0
164
175
  [3.5.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.5.0...@metamask/snaps-controllers@3.5.1
@@ -59,7 +59,7 @@ function _class_private_method_init(obj, privateSet) {
59
59
  _check_private_redeclaration(obj, privateSet);
60
60
  privateSet.add(obj);
61
61
  }
62
- var _stream = /*#__PURE__*/ new WeakMap(), _jobId = /*#__PURE__*/ new WeakMap(), _extra = /*#__PURE__*/ new WeakMap(), /**
62
+ var _stream = /*#__PURE__*/ new WeakMap(), _jobId = /*#__PURE__*/ new WeakMap(), /**
63
63
  * Handle incoming data from the underlying stream. This checks that the job
64
64
  * ID matches the expected job ID, and pushes the data to the stream if so.
65
65
  *
@@ -74,8 +74,7 @@ class ProxyPostMessageStream extends _postmessagestream.BasePostMessageStream {
74
74
  */ _postMessage(data) {
75
75
  _class_private_field_get(this, _stream).write({
76
76
  jobId: _class_private_field_get(this, _jobId),
77
- data,
78
- extra: _class_private_field_get(this, _extra)
77
+ data
79
78
  });
80
79
  }
81
80
  /**
@@ -84,8 +83,7 @@ class ProxyPostMessageStream extends _postmessagestream.BasePostMessageStream {
84
83
  * @param args - The constructor arguments.
85
84
  * @param args.stream - The underlying stream to use for communication.
86
85
  * @param args.jobId - The ID of the job this stream is associated with.
87
- * @param args.extra - Extra data to include in the post message.
88
- */ constructor({ stream, jobId, extra }){
86
+ */ constructor({ stream, jobId }){
89
87
  super();
90
88
  _class_private_method_init(this, _onData);
91
89
  _class_private_field_init(this, _stream, {
@@ -96,13 +94,8 @@ class ProxyPostMessageStream extends _postmessagestream.BasePostMessageStream {
96
94
  writable: true,
97
95
  value: void 0
98
96
  });
99
- _class_private_field_init(this, _extra, {
100
- writable: true,
101
- value: void 0
102
- });
103
97
  _class_private_field_set(this, _stream, stream);
104
98
  _class_private_field_set(this, _jobId, jobId);
105
- _class_private_field_set(this, _extra, extra);
106
99
  _class_private_field_get(this, _stream).on('data', _class_private_method_get(this, _onData, onData).bind(this));
107
100
  }
108
101
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/ProxyPostMessageStream.ts"],"sourcesContent":["import { BasePostMessageStream } from '@metamask/post-message-stream';\nimport type { JsonRpcRequest } from '@metamask/utils';\n\nexport type ProxyPostMessageStreamArgs = {\n stream: BasePostMessageStream;\n jobId: string;\n extra?: Record<string, unknown>;\n};\n\nexport type ProxyPostMessage = {\n jobId: string;\n data: JsonRpcRequest;\n extra?: Record<string, unknown>;\n};\n\n/**\n * A post message stream that wraps messages in a job ID, before sending them\n * over the underlying stream.\n */\nexport class ProxyPostMessageStream extends BasePostMessageStream {\n readonly #stream: BasePostMessageStream;\n\n readonly #jobId: string;\n\n readonly #extra?: Record<string, unknown>;\n\n /**\n * Initializes a new `ProxyPostMessageStream` instance.\n *\n * @param args - The constructor arguments.\n * @param args.stream - The underlying stream to use for communication.\n * @param args.jobId - The ID of the job this stream is associated with.\n * @param args.extra - Extra data to include in the post message.\n */\n constructor({ stream, jobId, extra }: ProxyPostMessageStreamArgs) {\n super();\n\n this.#stream = stream;\n this.#jobId = jobId;\n this.#extra = extra;\n\n this.#stream.on('data', this.#onData.bind(this));\n }\n\n /**\n * Handle incoming data from the underlying stream. This checks that the job\n * ID matches the expected job ID, and pushes the data to the stream if so.\n *\n * @param data - The data to handle.\n */\n #onData(data: ProxyPostMessage) {\n if (data.jobId !== this.#jobId) {\n return;\n }\n\n this.push(data.data);\n }\n\n /**\n * Write data to the underlying stream. This wraps the data in an object with\n * the job ID.\n *\n * @param data - The data to write.\n */\n _postMessage(data: ProxyPostMessage) {\n this.#stream.write({\n jobId: this.#jobId,\n data,\n extra: this.#extra,\n });\n }\n}\n"],"names":["ProxyPostMessageStream","BasePostMessageStream","_postMessage","data","stream","write","jobId","extra","constructor","on","onData","bind","push"],"mappings":";;;;+BAmBaA;;;eAAAA;;;mCAnByB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoB3B,uCAEA,sCAEA,sCAoBT;;;;;GAKC,GACD;AA/BK,MAAMA,+BAA+BC,wCAAqB;IAuC/D;;;;;GAKC,GACDC,aAAaC,IAAsB,EAAE;QACnC,yBAAA,IAAI,EAAEC,SAAOC,KAAK,CAAC;YACjBC,KAAK,2BAAE,IAAI,EAAEA;YACbH;YACAI,KAAK,2BAAE,IAAI,EAAEA;QACf;IACF;IA5CA;;;;;;;GAOC,GACDC,YAAY,EAAEJ,MAAM,EAAEE,KAAK,EAAEC,KAAK,EAA8B,CAAE;QAChE,KAAK;QAeP,iCAAA;QA9BA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;uCAaQH,SAASA;uCACTE,QAAQA;uCACRC,QAAQA;QAEd,yBAAA,IAAI,EAAEH,SAAOK,EAAE,CAAC,QAAQ,0BAAA,IAAI,EAAEC,SAAAA,QAAOC,IAAI,CAAC,IAAI;IAChD;AA6BF;AArBE,SAAA,OAAQR,IAAsB;IAC5B,IAAIA,KAAKG,KAAK,8BAAK,IAAI,EAAEA,SAAO;QAC9B;IACF;IAEA,IAAI,CAACM,IAAI,CAACT,KAAKA,IAAI;AACrB"}
1
+ {"version":3,"sources":["../../../src/services/ProxyPostMessageStream.ts"],"sourcesContent":["import { BasePostMessageStream } from '@metamask/post-message-stream';\nimport type { JsonRpcRequest } from '@metamask/utils';\n\nexport type ProxyPostMessageStreamArgs = {\n stream: BasePostMessageStream;\n jobId: string;\n extra?: Record<string, unknown>;\n};\n\nexport type ProxyPostMessage = {\n jobId: string;\n data: JsonRpcRequest;\n extra?: Record<string, unknown>;\n};\n\n/**\n * A post message stream that wraps messages in a job ID, before sending them\n * over the underlying stream.\n */\nexport class ProxyPostMessageStream extends BasePostMessageStream {\n readonly #stream: BasePostMessageStream;\n\n readonly #jobId: string;\n\n /**\n * Initializes a new `ProxyPostMessageStream` instance.\n *\n * @param args - The constructor arguments.\n * @param args.stream - The underlying stream to use for communication.\n * @param args.jobId - The ID of the job this stream is associated with.\n */\n constructor({ stream, jobId }: ProxyPostMessageStreamArgs) {\n super();\n\n this.#stream = stream;\n this.#jobId = jobId;\n\n this.#stream.on('data', this.#onData.bind(this));\n }\n\n /**\n * Handle incoming data from the underlying stream. This checks that the job\n * ID matches the expected job ID, and pushes the data to the stream if so.\n *\n * @param data - The data to handle.\n */\n #onData(data: ProxyPostMessage) {\n if (data.jobId !== this.#jobId) {\n return;\n }\n\n this.push(data.data);\n }\n\n /**\n * Write data to the underlying stream. This wraps the data in an object with\n * the job ID.\n *\n * @param data - The data to write.\n */\n _postMessage(data: ProxyPostMessage) {\n this.#stream.write({\n jobId: this.#jobId,\n data,\n });\n }\n}\n"],"names":["ProxyPostMessageStream","BasePostMessageStream","_postMessage","data","stream","write","jobId","constructor","on","onData","bind","push"],"mappings":";;;;+BAmBaA;;;eAAAA;;;mCAnByB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoB3B,uCAEA,sCAkBT;;;;;GAKC,GACD;AA3BK,MAAMA,+BAA+BC,wCAAqB;IAmC/D;;;;;GAKC,GACDC,aAAaC,IAAsB,EAAE;QACnC,yBAAA,IAAI,EAAEC,SAAOC,KAAK,CAAC;YACjBC,KAAK,2BAAE,IAAI,EAAEA;YACbH;QACF;IACF;IAzCA;;;;;;GAMC,GACDI,YAAY,EAAEH,MAAM,EAAEE,KAAK,EAA8B,CAAE;QACzD,KAAK;QAcP,iCAAA;QA1BA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;uCAYQF,SAASA;uCACTE,QAAQA;QAEd,yBAAA,IAAI,EAAEF,SAAOI,EAAE,CAAC,QAAQ,0BAAA,IAAI,EAAEC,SAAAA,QAAOC,IAAI,CAAC,IAAI;IAChD;AA4BF;AApBE,SAAA,OAAQP,IAAsB;IAC5B,IAAIA,KAAKG,KAAK,8BAAK,IAAI,EAAEA,SAAO;QAC9B;IACF;IAEA,IAAI,CAACK,IAAI,CAACR,KAAKA,IAAI;AACrB"}
@@ -13,7 +13,19 @@ const _child_process = require("child_process");
13
13
  const _ = require("..");
14
14
  class NodeProcessExecutionService extends _.AbstractExecutionService {
15
15
  async initEnvStream() {
16
- const worker = (0, _child_process.fork)(require.resolve('@metamask/snaps-execution-environments/dist/browserify/node-process/bundle.js'));
16
+ const worker = (0, _child_process.fork)(require.resolve('@metamask/snaps-execution-environments/dist/browserify/node-process/bundle.js'), {
17
+ stdio: 'pipe'
18
+ });
19
+ // Capturing `stdout` and `stderr` from the worker prevents the worker from
20
+ // writing to them directly, making it easier to capture them Jest.
21
+ worker.stdout?.on('data', (data)=>{
22
+ // eslint-disable-next-line no-console
23
+ console.log(data.toString());
24
+ });
25
+ worker.stderr?.on('data', (data)=>{
26
+ // eslint-disable-next-line no-console
27
+ console.error(data.toString());
28
+ });
17
29
  const stream = new _postmessagestream.ProcessParentMessageStream({
18
30
  process: worker
19
31
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/services/node/NodeProcessExecutionService.ts"],"sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { ProcessParentMessageStream } from '@metamask/post-message-stream';\nimport type { ChildProcess } from 'child_process';\nimport { fork } from 'child_process';\n\nimport type { Job } from '..';\nimport { AbstractExecutionService } from '..';\n\nexport class NodeProcessExecutionService extends AbstractExecutionService<ChildProcess> {\n protected async initEnvStream(): Promise<{\n worker: ChildProcess;\n stream: BasePostMessageStream;\n }> {\n const worker = fork(\n require.resolve(\n '@metamask/snaps-execution-environments/dist/browserify/node-process/bundle.js',\n ),\n );\n\n const stream = new ProcessParentMessageStream({ process: worker });\n return Promise.resolve({ worker, stream });\n }\n\n protected terminateJob(jobWrapper: Job<ChildProcess>): void {\n jobWrapper.worker.kill();\n }\n}\n"],"names":["NodeProcessExecutionService","AbstractExecutionService","initEnvStream","worker","fork","require","resolve","stream","ProcessParentMessageStream","process","Promise","terminateJob","jobWrapper","kill"],"mappings":";;;;+BAQaA;;;eAAAA;;;mCAP8B;+BAEtB;kBAGoB;AAElC,MAAMA,oCAAoCC,0BAAwB;IACvE,MAAgBC,gBAGb;QACD,MAAMC,SAASC,IAAAA,mBAAI,EACjBC,QAAQC,OAAO,CACb;QAIJ,MAAMC,SAAS,IAAIC,6CAA0B,CAAC;YAAEC,SAASN;QAAO;QAChE,OAAOO,QAAQJ,OAAO,CAAC;YAAEH;YAAQI;QAAO;IAC1C;IAEUI,aAAaC,UAA6B,EAAQ;QAC1DA,WAAWT,MAAM,CAACU,IAAI;IACxB;AACF"}
1
+ {"version":3,"sources":["../../../../src/services/node/NodeProcessExecutionService.ts"],"sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { ProcessParentMessageStream } from '@metamask/post-message-stream';\nimport type { ChildProcess } from 'child_process';\nimport { fork } from 'child_process';\n\nimport type { Job } from '..';\nimport { AbstractExecutionService } from '..';\n\nexport class NodeProcessExecutionService extends AbstractExecutionService<ChildProcess> {\n protected async initEnvStream(): Promise<{\n worker: ChildProcess;\n stream: BasePostMessageStream;\n }> {\n const worker = fork(\n require.resolve(\n '@metamask/snaps-execution-environments/dist/browserify/node-process/bundle.js',\n ),\n {\n stdio: 'pipe',\n },\n );\n\n // Capturing `stdout` and `stderr` from the worker prevents the worker from\n // writing to them directly, making it easier to capture them Jest.\n worker.stdout?.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n });\n\n worker.stderr?.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.error(data.toString());\n });\n\n const stream = new ProcessParentMessageStream({ process: worker });\n return Promise.resolve({ worker, stream });\n }\n\n protected terminateJob(jobWrapper: Job<ChildProcess>): void {\n jobWrapper.worker.kill();\n }\n}\n"],"names":["NodeProcessExecutionService","AbstractExecutionService","initEnvStream","worker","fork","require","resolve","stdio","stdout","on","data","console","log","toString","stderr","error","stream","ProcessParentMessageStream","process","Promise","terminateJob","jobWrapper","kill"],"mappings":";;;;+BAQaA;;;eAAAA;;;mCAP8B;+BAEtB;kBAGoB;AAElC,MAAMA,oCAAoCC,0BAAwB;IACvE,MAAgBC,gBAGb;QACD,MAAMC,SAASC,IAAAA,mBAAI,EACjBC,QAAQC,OAAO,CACb,kFAEF;YACEC,OAAO;QACT;QAGF,2EAA2E;QAC3E,mEAAmE;QACnEJ,OAAOK,MAAM,EAAEC,GAAG,QAAQ,CAACC;YACzB,sCAAsC;YACtCC,QAAQC,GAAG,CAACF,KAAKG,QAAQ;QAC3B;QAEAV,OAAOW,MAAM,EAAEL,GAAG,QAAQ,CAACC;YACzB,sCAAsC;YACtCC,QAAQI,KAAK,CAACL,KAAKG,QAAQ;QAC7B;QAEA,MAAMG,SAAS,IAAIC,6CAA0B,CAAC;YAAEC,SAASf;QAAO;QAChE,OAAOgB,QAAQb,OAAO,CAAC;YAAEH;YAAQa;QAAO;IAC1C;IAEUI,aAAaC,UAA6B,EAAQ;QAC1DA,WAAWlB,MAAM,CAACmB,IAAI;IACxB;AACF"}
@@ -13,7 +13,20 @@ const _worker_threads = require("worker_threads");
13
13
  const _ = require("..");
14
14
  class NodeThreadExecutionService extends _.AbstractExecutionService {
15
15
  async initEnvStream() {
16
- const worker = new _worker_threads.Worker(require.resolve('@metamask/snaps-execution-environments/dist/browserify/node-thread/bundle.js'));
16
+ const worker = new _worker_threads.Worker(require.resolve('@metamask/snaps-execution-environments/dist/browserify/node-thread/bundle.js'), {
17
+ stdout: true,
18
+ stderr: true
19
+ });
20
+ // Capturing `stdout` and `stderr` from the worker prevents the worker from
21
+ // writing to them directly, making it easier to capture them Jest.
22
+ worker.stdout.on('data', (data)=>{
23
+ // eslint-disable-next-line no-console
24
+ console.log(data.toString());
25
+ });
26
+ worker.stderr.on('data', (data)=>{
27
+ // eslint-disable-next-line no-console
28
+ console.error(data.toString());
29
+ });
17
30
  const stream = new _postmessagestream.ThreadParentMessageStream({
18
31
  thread: worker
19
32
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/services/node/NodeThreadExecutionService.ts"],"sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { ThreadParentMessageStream } from '@metamask/post-message-stream';\n// eslint-disable-next-line @typescript-eslint/no-shadow\nimport { Worker } from 'worker_threads';\n\nimport type { Job } from '..';\nimport { AbstractExecutionService } from '..';\n\nexport class NodeThreadExecutionService extends AbstractExecutionService<Worker> {\n protected async initEnvStream(): Promise<{\n worker: Worker;\n stream: BasePostMessageStream;\n }> {\n const worker = new Worker(\n require.resolve(\n '@metamask/snaps-execution-environments/dist/browserify/node-thread/bundle.js',\n ),\n );\n const stream = new ThreadParentMessageStream({ thread: worker });\n return Promise.resolve({ worker, stream });\n }\n\n protected async terminateJob(jobWrapper: Job<Worker>): Promise<void> {\n await jobWrapper.worker.terminate();\n }\n}\n"],"names":["NodeThreadExecutionService","AbstractExecutionService","initEnvStream","worker","Worker","require","resolve","stream","ThreadParentMessageStream","thread","Promise","terminateJob","jobWrapper","terminate"],"mappings":";;;;+BAQaA;;;eAAAA;;;mCAP6B;gCAEnB;kBAGkB;AAElC,MAAMA,mCAAmCC,0BAAwB;IACtE,MAAgBC,gBAGb;QACD,MAAMC,SAAS,IAAIC,sBAAM,CACvBC,QAAQC,OAAO,CACb;QAGJ,MAAMC,SAAS,IAAIC,4CAAyB,CAAC;YAAEC,QAAQN;QAAO;QAC9D,OAAOO,QAAQJ,OAAO,CAAC;YAAEH;YAAQI;QAAO;IAC1C;IAEA,MAAgBI,aAAaC,UAAuB,EAAiB;QACnE,MAAMA,WAAWT,MAAM,CAACU,SAAS;IACnC;AACF"}
1
+ {"version":3,"sources":["../../../../src/services/node/NodeThreadExecutionService.ts"],"sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { ThreadParentMessageStream } from '@metamask/post-message-stream';\n// eslint-disable-next-line @typescript-eslint/no-shadow\nimport { Worker } from 'worker_threads';\n\nimport type { Job } from '..';\nimport { AbstractExecutionService } from '..';\n\nexport class NodeThreadExecutionService extends AbstractExecutionService<Worker> {\n protected async initEnvStream(): Promise<{\n worker: Worker;\n stream: BasePostMessageStream;\n }> {\n const worker = new Worker(\n require.resolve(\n '@metamask/snaps-execution-environments/dist/browserify/node-thread/bundle.js',\n ),\n {\n stdout: true,\n stderr: true,\n },\n );\n\n // Capturing `stdout` and `stderr` from the worker prevents the worker from\n // writing to them directly, making it easier to capture them Jest.\n worker.stdout.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.log(data.toString());\n });\n\n worker.stderr.on('data', (data) => {\n // eslint-disable-next-line no-console\n console.error(data.toString());\n });\n\n const stream = new ThreadParentMessageStream({ thread: worker });\n return Promise.resolve({ worker, stream });\n }\n\n protected async terminateJob(jobWrapper: Job<Worker>): Promise<void> {\n await jobWrapper.worker.terminate();\n }\n}\n"],"names":["NodeThreadExecutionService","AbstractExecutionService","initEnvStream","worker","Worker","require","resolve","stdout","stderr","on","data","console","log","toString","error","stream","ThreadParentMessageStream","thread","Promise","terminateJob","jobWrapper","terminate"],"mappings":";;;;+BAQaA;;;eAAAA;;;mCAP6B;gCAEnB;kBAGkB;AAElC,MAAMA,mCAAmCC,0BAAwB;IACtE,MAAgBC,gBAGb;QACD,MAAMC,SAAS,IAAIC,sBAAM,CACvBC,QAAQC,OAAO,CACb,iFAEF;YACEC,QAAQ;YACRC,QAAQ;QACV;QAGF,2EAA2E;QAC3E,mEAAmE;QACnEL,OAAOI,MAAM,CAACE,EAAE,CAAC,QAAQ,CAACC;YACxB,sCAAsC;YACtCC,QAAQC,GAAG,CAACF,KAAKG,QAAQ;QAC3B;QAEAV,OAAOK,MAAM,CAACC,EAAE,CAAC,QAAQ,CAACC;YACxB,sCAAsC;YACtCC,QAAQG,KAAK,CAACJ,KAAKG,QAAQ;QAC7B;QAEA,MAAME,SAAS,IAAIC,4CAAyB,CAAC;YAAEC,QAAQd;QAAO;QAC9D,OAAOe,QAAQZ,OAAO,CAAC;YAAEH;YAAQY;QAAO;IAC1C;IAEA,MAAgBI,aAAaC,UAAuB,EAAiB;QACnE,MAAMA,WAAWjB,MAAM,CAACkB,SAAS;IACnC;AACF"}
@@ -9,48 +9,21 @@ Object.defineProperty(exports, "OffscreenExecutionService", {
9
9
  }
10
10
  });
11
11
  const _postmessagestream = require("@metamask/post-message-stream");
12
- const _nanoid = require("nanoid");
13
- const _AbstractExecutionService = require("../AbstractExecutionService");
14
- const _ProxyPostMessageStream = require("../ProxyPostMessageStream");
12
+ const _ProxyExecutionService = require("../proxy/ProxyExecutionService");
15
13
  function _check_private_redeclaration(obj, privateCollection) {
16
14
  if (privateCollection.has(obj)) {
17
15
  throw new TypeError("Cannot initialize the same private elements twice on an object");
18
16
  }
19
17
  }
20
- function _class_apply_descriptor_get(receiver, descriptor) {
21
- if (descriptor.get) {
22
- return descriptor.get.call(receiver);
18
+ function _class_private_method_get(receiver, privateSet, fn) {
19
+ if (!privateSet.has(receiver)) {
20
+ throw new TypeError("attempted to get private field on non-instance");
23
21
  }
24
- return descriptor.value;
22
+ return fn;
25
23
  }
26
- function _class_apply_descriptor_set(receiver, descriptor, value) {
27
- if (descriptor.set) {
28
- descriptor.set.call(receiver, value);
29
- } else {
30
- if (!descriptor.writable) {
31
- throw new TypeError("attempted to set read only private field");
32
- }
33
- descriptor.value = value;
34
- }
35
- }
36
- function _class_extract_field_descriptor(receiver, privateMap, action) {
37
- if (!privateMap.has(receiver)) {
38
- throw new TypeError("attempted to " + action + " private field on non-instance");
39
- }
40
- return privateMap.get(receiver);
41
- }
42
- function _class_private_field_get(receiver, privateMap) {
43
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
44
- return _class_apply_descriptor_get(receiver, descriptor);
45
- }
46
- function _class_private_field_init(obj, privateMap, value) {
47
- _check_private_redeclaration(obj, privateMap);
48
- privateMap.set(obj, value);
49
- }
50
- function _class_private_field_set(receiver, privateMap, value) {
51
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
52
- _class_apply_descriptor_set(receiver, descriptor, value);
53
- return value;
24
+ function _class_private_method_init(obj, privateSet) {
25
+ _check_private_redeclaration(obj, privateSet);
26
+ privateSet.add(obj);
54
27
  }
55
28
  function _define_property(obj, key, value) {
56
29
  if (key in obj) {
@@ -65,24 +38,8 @@ function _define_property(obj, key, value) {
65
38
  }
66
39
  return obj;
67
40
  }
68
- var _runtimeStream = /*#__PURE__*/ new WeakMap();
69
- class OffscreenExecutionService extends _AbstractExecutionService.AbstractExecutionService {
70
- /**
71
- * Send a termination command to the offscreen document.
72
- *
73
- * @param job - The job to terminate.
74
- */ async terminateJob(job) {
75
- // The `AbstractExecutionService` will have already closed the job stream,
76
- // so we write to the runtime stream directly.
77
- _class_private_field_get(this, _runtimeStream).write({
78
- jobId: job.id,
79
- data: {
80
- jsonrpc: '2.0',
81
- method: 'terminateJob',
82
- id: (0, _nanoid.nanoid)()
83
- }
84
- });
85
- }
41
+ var _createDocument = /*#__PURE__*/ new WeakSet();
42
+ class OffscreenExecutionService extends _ProxyExecutionService.ProxyExecutionService {
86
43
  /**
87
44
  * Create a new stream for the specified job. This wraps the runtime stream
88
45
  * in a stream specific to the job.
@@ -90,38 +47,8 @@ class OffscreenExecutionService extends _AbstractExecutionService.AbstractExecut
90
47
  * @param jobId - The job ID.
91
48
  */ async initEnvStream(jobId) {
92
49
  // Lazily create the offscreen document.
93
- await this.createDocument();
94
- const stream = new _ProxyPostMessageStream.ProxyPostMessageStream({
95
- stream: _class_private_field_get(this, _runtimeStream),
96
- extra: {
97
- // TODO: Rather than injecting the frame URL here, we should come up
98
- // with a better way to do this. The frame URL is needed to avoid hard
99
- // coding it in the offscreen execution environment.
100
- frameUrl: this.frameUrl.toString()
101
- },
102
- jobId
103
- });
104
- return {
105
- worker: jobId,
106
- stream
107
- };
108
- }
109
- /**
110
- * Creates the offscreen document to be used as the execution environment.
111
- *
112
- * If the document already exists, this does nothing.
113
- */ async createDocument() {
114
- // Extensions can only have a single offscreen document.
115
- if (await chrome.offscreen.hasDocument()) {
116
- return;
117
- }
118
- await chrome.offscreen.createDocument({
119
- justification: 'MetaMask Snaps Execution Environment',
120
- reasons: [
121
- 'IFRAME_SCRIPTING'
122
- ],
123
- url: this.documentUrl.toString()
124
- });
50
+ await _class_private_method_get(this, _createDocument, createDocument).call(this);
51
+ return super.initEnvStream(jobId);
125
52
  }
126
53
  /**
127
54
  * Create a new offscreen execution service.
@@ -130,30 +57,40 @@ class OffscreenExecutionService extends _AbstractExecutionService.AbstractExecut
130
57
  * @param args.documentUrl - The URL of the offscreen document to use as the
131
58
  * execution environment. This must be a URL relative to the location where
132
59
  * this is called. This cannot be a public (http(s)) URL.
133
- * @param args.frameUrl - The URL of the iframe to load inside the offscreen
134
- * document.
135
60
  * @param args.messenger - The messenger to use for communication with the
136
61
  * `SnapController`.
137
62
  * @param args.setupSnapProvider - The function to use to set up the snap
138
63
  * provider.
139
- */ constructor({ documentUrl, frameUrl, messenger, setupSnapProvider }){
64
+ */ constructor({ documentUrl, messenger, setupSnapProvider }){
140
65
  super({
141
66
  messenger,
142
- setupSnapProvider
67
+ setupSnapProvider,
68
+ stream: new _postmessagestream.BrowserRuntimePostMessageStream({
69
+ name: 'parent',
70
+ target: 'child'
71
+ })
143
72
  });
73
+ /**
74
+ * Creates the offscreen document to be used as the execution environment.
75
+ *
76
+ * If the document already exists, this does nothing.
77
+ */ _class_private_method_init(this, _createDocument);
144
78
  _define_property(this, "documentUrl", void 0);
145
- _define_property(this, "frameUrl", void 0);
146
- _class_private_field_init(this, _runtimeStream, {
147
- writable: true,
148
- value: void 0
149
- });
150
79
  this.documentUrl = documentUrl;
151
- this.frameUrl = frameUrl;
152
- _class_private_field_set(this, _runtimeStream, new _postmessagestream.BrowserRuntimePostMessageStream({
153
- name: 'parent',
154
- target: 'child'
155
- }));
156
80
  }
157
81
  }
82
+ async function createDocument() {
83
+ // Extensions can only have a single offscreen document.
84
+ if (await chrome.offscreen.hasDocument()) {
85
+ return;
86
+ }
87
+ await chrome.offscreen.createDocument({
88
+ justification: 'MetaMask Snaps Execution Environment',
89
+ reasons: [
90
+ 'IFRAME_SCRIPTING'
91
+ ],
92
+ url: this.documentUrl.toString()
93
+ });
94
+ }
158
95
 
159
96
  //# sourceMappingURL=OffscreenExecutionService.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/services/offscreen/OffscreenExecutionService.ts"],"sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\nimport { nanoid } from 'nanoid';\n\nimport type { ExecutionServiceArgs, Job } from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport { ProxyPostMessageStream } from '../ProxyPostMessageStream';\n\ntype OffscreenExecutionEnvironmentServiceArgs = {\n documentUrl: URL;\n frameUrl: URL;\n} & ExecutionServiceArgs;\n\nexport class OffscreenExecutionService extends AbstractExecutionService<string> {\n public readonly documentUrl: URL;\n\n public readonly frameUrl: URL;\n\n readonly #runtimeStream: BrowserRuntimePostMessageStream;\n\n /**\n * Create a new offscreen execution service.\n *\n * @param args - The constructor arguments.\n * @param args.documentUrl - The URL of the offscreen document to use as the\n * execution environment. This must be a URL relative to the location where\n * this is called. This cannot be a public (http(s)) URL.\n * @param args.frameUrl - The URL of the iframe to load inside the offscreen\n * document.\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 frameUrl,\n messenger,\n setupSnapProvider,\n }: OffscreenExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\n });\n\n this.documentUrl = documentUrl;\n this.frameUrl = frameUrl;\n this.#runtimeStream = new BrowserRuntimePostMessageStream({\n name: 'parent',\n target: 'child',\n });\n }\n\n /**\n * Send a termination command to the offscreen document.\n *\n * @param job - The job to terminate.\n */\n protected async terminateJob(job: Job<string>) {\n // The `AbstractExecutionService` will have already closed the job stream,\n // so we write to the runtime stream directly.\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 */\n protected async initEnvStream(jobId: string) {\n // Lazily create the offscreen document.\n await this.createDocument();\n\n const stream = new ProxyPostMessageStream({\n stream: this.#runtimeStream,\n extra: {\n // TODO: Rather than injecting the frame URL here, we should come up\n // with a better way to do this. The frame URL is needed to avoid hard\n // coding it in the offscreen execution environment.\n frameUrl: this.frameUrl.toString(),\n },\n jobId,\n });\n\n return { worker: jobId, stream };\n }\n\n /**\n * Creates the offscreen document to be used as the execution environment.\n *\n * If the document already exists, this does nothing.\n */\n private async createDocument() {\n // Extensions can only have a single offscreen document.\n if (await chrome.offscreen.hasDocument()) {\n return;\n }\n\n await chrome.offscreen.createDocument({\n justification: 'MetaMask Snaps Execution Environment',\n reasons: ['IFRAME_SCRIPTING' as chrome.offscreen.Reason],\n url: this.documentUrl.toString(),\n });\n }\n}\n"],"names":["OffscreenExecutionService","AbstractExecutionService","terminateJob","job","runtimeStream","write","jobId","id","data","jsonrpc","method","nanoid","initEnvStream","createDocument","stream","ProxyPostMessageStream","extra","frameUrl","toString","worker","chrome","offscreen","hasDocument","justification","reasons","url","documentUrl","constructor","messenger","setupSnapProvider","BrowserRuntimePostMessageStream","name","target"],"mappings":";;;;+BAYaA;;;eAAAA;;;mCAZmC;wBACzB;0CAGkB;wCACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAY5B;AALJ,MAAMA,kCAAkCC,kDAAwB;IAwCrE;;;;GAIC,GACD,MAAgBC,aAAaC,GAAgB,EAAE;QAC7C,0EAA0E;QAC1E,8CAA8C;QAC9C,yBAAA,IAAI,EAAEC,gBAAcC,KAAK,CAAC;YACxBC,OAAOH,IAAII,EAAE;YACbC,MAAM;gBACJC,SAAS;gBACTC,QAAQ;gBACRH,IAAII,IAAAA,cAAM;YACZ;QACF;IACF;IAEA;;;;;GAKC,GACD,MAAgBC,cAAcN,KAAa,EAAE;QAC3C,wCAAwC;QACxC,MAAM,IAAI,CAACO,cAAc;QAEzB,MAAMC,SAAS,IAAIC,8CAAsB,CAAC;YACxCD,MAAM,2BAAE,IAAI,EAAEV;YACdY,OAAO;gBACL,oEAAoE;gBACpE,sEAAsE;gBACtE,oDAAoD;gBACpDC,UAAU,IAAI,CAACA,QAAQ,CAACC,QAAQ;YAClC;YACAZ;QACF;QAEA,OAAO;YAAEa,QAAQb;YAAOQ;QAAO;IACjC;IAEA;;;;GAIC,GACD,MAAcD,iBAAiB;QAC7B,wDAAwD;QACxD,IAAI,MAAMO,OAAOC,SAAS,CAACC,WAAW,IAAI;YACxC;QACF;QAEA,MAAMF,OAAOC,SAAS,CAACR,cAAc,CAAC;YACpCU,eAAe;YACfC,SAAS;gBAAC;aAA8C;YACxDC,KAAK,IAAI,CAACC,WAAW,CAACR,QAAQ;QAChC;IACF;IA3FA;;;;;;;;;;;;;GAaC,GACDS,YAAY,EACVD,WAAW,EACXT,QAAQ,EACRW,SAAS,EACTC,iBAAiB,EACwB,CAAE;QAC3C,KAAK,CAAC;YACJD;YACAC;QACF;QA7BF,uBAAgBH,eAAhB,KAAA;QAEA,uBAAgBT,YAAhB,KAAA;QAEA,gCAAS;;mBAAT,KAAA;;QA2BE,IAAI,CAACS,WAAW,GAAGA;QACnB,IAAI,CAACT,QAAQ,GAAGA;uCACVb,gBAAgB,IAAI0B,kDAA+B,CAAC;YACxDC,MAAM;YACNC,QAAQ;QACV;IACF;AA6DF"}
1
+ {"version":3,"sources":["../../../../src/services/offscreen/OffscreenExecutionService.ts"],"sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport type { ExecutionServiceArgs } from '../AbstractExecutionService';\nimport { ProxyExecutionService } from '../proxy/ProxyExecutionService';\n\ntype OffscreenExecutionEnvironmentServiceArgs = {\n documentUrl: URL;\n} & ExecutionServiceArgs;\n\nexport class OffscreenExecutionService extends ProxyExecutionService {\n public readonly documentUrl: URL;\n\n /**\n * Create a new offscreen execution service.\n *\n * @param args - The constructor arguments.\n * @param args.documentUrl - The URL of the offscreen document to use as the\n * execution environment. This must be a URL relative to the location where\n * this is called. This cannot be a public (http(s)) URL.\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 }: OffscreenExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\n stream: new BrowserRuntimePostMessageStream({\n name: 'parent',\n target: 'child',\n }),\n });\n\n this.documentUrl = documentUrl;\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 */\n protected async initEnvStream(jobId: string) {\n // Lazily create the offscreen document.\n await this.#createDocument();\n\n return super.initEnvStream(jobId);\n }\n\n /**\n * Creates the offscreen document to be used as the execution environment.\n *\n * If the document already exists, this does nothing.\n */\n async #createDocument() {\n // Extensions can only have a single offscreen document.\n if (await chrome.offscreen.hasDocument()) {\n return;\n }\n\n await chrome.offscreen.createDocument({\n justification: 'MetaMask Snaps Execution Environment',\n reasons: ['IFRAME_SCRIPTING' as chrome.offscreen.Reason],\n url: this.documentUrl.toString(),\n });\n }\n}\n"],"names":["OffscreenExecutionService","ProxyExecutionService","initEnvStream","jobId","createDocument","constructor","documentUrl","messenger","setupSnapProvider","stream","BrowserRuntimePostMessageStream","name","target","chrome","offscreen","hasDocument","justification","reasons","url","toString"],"mappings":";;;;+BASaA;;;eAAAA;;;mCATmC;uCAGV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAwD9B;AAlDD,MAAMA,kCAAkCC,4CAAqB;IAgClE;;;;;GAKC,GACD,MAAgBC,cAAcC,KAAa,EAAE;QAC3C,wCAAwC;QACxC,MAAM,0BAAA,IAAI,EAAEC,iBAAAA,qBAAN,IAAI;QAEV,OAAO,KAAK,CAACF,cAAcC;IAC7B;IAxCA;;;;;;;;;;;GAWC,GACDE,YAAY,EACVC,WAAW,EACXC,SAAS,EACTC,iBAAiB,EACwB,CAAE;QAC3C,KAAK,CAAC;YACJD;YACAC;YACAC,QAAQ,IAAIC,kDAA+B,CAAC;gBAC1CC,MAAM;gBACNC,QAAQ;YACV;QACF;QAkBF;;;;GAIC,GACD,iCAAM;QAjDN,uBAAgBN,eAAhB,KAAA;QA4BE,IAAI,CAACA,WAAW,GAAGA;IACrB;AAgCF;AAZE,eAAA;IACE,wDAAwD;IACxD,IAAI,MAAMO,OAAOC,SAAS,CAACC,WAAW,IAAI;QACxC;IACF;IAEA,MAAMF,OAAOC,SAAS,CAACV,cAAc,CAAC;QACpCY,eAAe;QACfC,SAAS;YAAC;SAA8C;QACxDC,KAAK,IAAI,CAACZ,WAAW,CAACa,QAAQ;IAChC;AACF"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ProxyExecutionService", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ProxyExecutionService;
9
+ }
10
+ });
11
+ const _nanoid = require("nanoid");
12
+ const _AbstractExecutionService = require("../AbstractExecutionService");
13
+ const _ProxyPostMessageStream = require("../ProxyPostMessageStream");
14
+ function _check_private_redeclaration(obj, privateCollection) {
15
+ if (privateCollection.has(obj)) {
16
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
17
+ }
18
+ }
19
+ function _class_apply_descriptor_get(receiver, descriptor) {
20
+ if (descriptor.get) {
21
+ return descriptor.get.call(receiver);
22
+ }
23
+ return descriptor.value;
24
+ }
25
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
26
+ if (descriptor.set) {
27
+ descriptor.set.call(receiver, value);
28
+ } else {
29
+ if (!descriptor.writable) {
30
+ throw new TypeError("attempted to set read only private field");
31
+ }
32
+ descriptor.value = value;
33
+ }
34
+ }
35
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
36
+ if (!privateMap.has(receiver)) {
37
+ throw new TypeError("attempted to " + action + " private field on non-instance");
38
+ }
39
+ return privateMap.get(receiver);
40
+ }
41
+ function _class_private_field_get(receiver, privateMap) {
42
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
43
+ return _class_apply_descriptor_get(receiver, descriptor);
44
+ }
45
+ function _class_private_field_init(obj, privateMap, value) {
46
+ _check_private_redeclaration(obj, privateMap);
47
+ privateMap.set(obj, value);
48
+ }
49
+ function _class_private_field_set(receiver, privateMap, value) {
50
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
51
+ _class_apply_descriptor_set(receiver, descriptor, value);
52
+ return value;
53
+ }
54
+ var _stream = /*#__PURE__*/ new WeakMap();
55
+ class ProxyExecutionService extends _AbstractExecutionService.AbstractExecutionService {
56
+ /**
57
+ * Send a termination command to the proxy stream.
58
+ *
59
+ * @param job - The job to terminate.
60
+ */ async terminateJob(job) {
61
+ // The `AbstractExecutionService` will have already closed the job stream,
62
+ // so we write to the runtime stream directly.
63
+ _class_private_field_get(this, _stream).write({
64
+ jobId: job.id,
65
+ data: {
66
+ jsonrpc: '2.0',
67
+ method: 'terminateJob',
68
+ id: (0, _nanoid.nanoid)()
69
+ }
70
+ });
71
+ }
72
+ /**
73
+ * Create a new stream for the specified job. This wraps the root stream
74
+ * in a stream specific to the job.
75
+ *
76
+ * @param jobId - The job ID.
77
+ */ async initEnvStream(jobId) {
78
+ const stream = new _ProxyPostMessageStream.ProxyPostMessageStream({
79
+ stream: _class_private_field_get(this, _stream),
80
+ jobId
81
+ });
82
+ return {
83
+ worker: jobId,
84
+ stream
85
+ };
86
+ }
87
+ /**
88
+ * Create a new proxy execution service.
89
+ *
90
+ * @param args - The constructor arguments.
91
+ * @param args.messenger - The messenger to use for communication with the
92
+ * `SnapController`.
93
+ * @param args.setupSnapProvider - The function to use to set up the snap
94
+ * provider.
95
+ * @param args.stream - The stream to use for communicating with the proxy
96
+ * executor.
97
+ */ constructor({ stream, messenger, setupSnapProvider }){
98
+ super({
99
+ messenger,
100
+ setupSnapProvider
101
+ });
102
+ _class_private_field_init(this, _stream, {
103
+ writable: true,
104
+ value: void 0
105
+ });
106
+ _class_private_field_set(this, _stream, stream);
107
+ }
108
+ }
109
+
110
+ //# sourceMappingURL=ProxyExecutionService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/services/proxy/ProxyExecutionService.ts"],"sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { nanoid } from 'nanoid';\n\nimport type { ExecutionServiceArgs, Job } 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 }: ProxyExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\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: Job<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 */\n protected async initEnvStream(jobId: string) {\n const stream = new ProxyPostMessageStream({\n stream: this.#stream,\n jobId,\n });\n\n return { worker: jobId, stream };\n }\n}\n"],"names":["ProxyExecutionService","AbstractExecutionService","terminateJob","job","stream","write","jobId","id","data","jsonrpc","method","nanoid","initEnvStream","ProxyPostMessageStream","worker","constructor","messenger","setupSnapProvider"],"mappings":";;;;+BAWaA;;;eAAAA;;;wBAVU;0CAGkB;wCACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAO5B;AADJ,MAAMA,8BAA8BC,kDAAwB;IA2BjE;;;;GAIC,GACD,MAAgBC,aAAaC,GAAgB,EAAE;QAC7C,0EAA0E;QAC1E,8CAA8C;QAC9C,yBAAA,IAAI,EAAEC,SAAOC,KAAK,CAAC;YACjBC,OAAOH,IAAII,EAAE;YACbC,MAAM;gBACJC,SAAS;gBACTC,QAAQ;gBACRH,IAAII,IAAAA,cAAM;YACZ;QACF;IACF;IAEA;;;;;GAKC,GACD,MAAgBC,cAAcN,KAAa,EAAE;QAC3C,MAAMF,SAAS,IAAIS,8CAAsB,CAAC;YACxCT,MAAM,2BAAE,IAAI,EAAEA;YACdE;QACF;QAEA,OAAO;YAAEQ,QAAQR;YAAOF;QAAO;IACjC;IAvDA;;;;;;;;;;GAUC,GACDW,YAAY,EACVX,MAAM,EACNY,SAAS,EACTC,iBAAiB,EACoB,CAAE;QACvC,KAAK,CAAC;YACJD;YACAC;QACF;QArBF,gCAAS;;mBAAT,KAAA;;uCAuBQb,SAASA;IACjB;AAkCF"}