@metamask/snaps-controllers 9.14.0 → 9.15.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [9.15.0]
11
+
12
+ ### Added
13
+
14
+ - Add `clientCryptography` property for specifying custom cryptography functions ([#2909](https://github.com/MetaMask/snaps/pull/2909))
15
+
10
16
  ## [9.14.0]
11
17
 
12
18
  ### Added
@@ -574,7 +580,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
574
580
  - The version of the package no longer needs to match the version of all other
575
581
  MetaMask Snaps packages.
576
582
 
577
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.14.0...HEAD
583
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.15.0...HEAD
584
+ [9.15.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.14.0...@metamask/snaps-controllers@9.15.0
578
585
  [9.14.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.13.0...@metamask/snaps-controllers@9.14.0
579
586
  [9.13.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.12.0...@metamask/snaps-controllers@9.13.0
580
587
  [9.12.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.11.1...@metamask/snaps-controllers@9.12.0
@@ -10,8 +10,7 @@ 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 _ProxyPostMessageStream_instances, _ProxyPostMessageStream_stream, _ProxyPostMessageStream_jobId, _ProxyPostMessageStream_onData;
13
- import $metamaskpostmessagestream from "@metamask/post-message-stream";
14
- const { BasePostMessageStream } = $metamaskpostmessagestream;
13
+ import { BasePostMessageStream } from "@metamask/post-message-stream";
15
14
  /**
16
15
  * A post message stream that wraps messages in a job ID, before sending them
17
16
  * over the underlying stream.
@@ -1 +1 @@
1
- {"version":3,"file":"ProxyPostMessageStream.mjs","sourceRoot":"","sources":["../../src/services/ProxyPostMessageStream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAeA;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,qBAAqB;IAK/D;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,EAAE,KAAK,EAA8B;QACvD,KAAK,EAAE,CAAC;;QAZD,iDAA+B;QAE/B,gDAAe;QAYtB,uBAAA,IAAI,kCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,iCAAU,KAAK,MAAA,CAAC;QAEpB,uBAAA,IAAI,sCAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,uBAAA,IAAI,yEAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAgBD;;;;;OAKG;IACH,YAAY,CAAC,IAAsB;QACjC,uBAAA,IAAI,sCAAQ,CAAC,KAAK,CAAC;YACjB,KAAK,EAAE,uBAAA,IAAI,qCAAO;YAClB,IAAI;SACL,CAAC,CAAC;IACL,CAAC;CACF;2NApBS,IAAsB;IAC5B,IAAI,IAAI,CAAC,KAAK,KAAK,uBAAA,IAAI,qCAAO,EAAE,CAAC;QAC/B,OAAO;IACT,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC","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"]}
1
+ {"version":3,"file":"ProxyPostMessageStream.mjs","sourceRoot":"","sources":["../../src/services/ProxyPostMessageStream.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,qBAAqB,EAAE,sCAAsC;AAetE;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,qBAAqB;IAK/D;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,EAAE,KAAK,EAA8B;QACvD,KAAK,EAAE,CAAC;;QAZD,iDAA+B;QAE/B,gDAAe;QAYtB,uBAAA,IAAI,kCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,iCAAU,KAAK,MAAA,CAAC;QAEpB,uBAAA,IAAI,sCAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,uBAAA,IAAI,yEAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAgBD;;;;;OAKG;IACH,YAAY,CAAC,IAAsB;QACjC,uBAAA,IAAI,sCAAQ,CAAC,KAAK,CAAC;YACjB,KAAK,EAAE,uBAAA,IAAI,qCAAO;YAClB,IAAI;SACL,CAAC,CAAC;IACL,CAAC;CACF;2NApBS,IAAsB;IAC5B,IAAI,IAAI,CAAC,KAAK,KAAK,uBAAA,IAAI,qCAAO,EAAE,CAAC;QAC/B,OAAO;IACT,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC","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"]}
@@ -1,5 +1,4 @@
1
- import $metamaskpostmessagestream from "@metamask/post-message-stream";
2
- const { WindowPostMessageStream } = $metamaskpostmessagestream;
1
+ import { WindowPostMessageStream } from "@metamask/post-message-stream";
3
2
  import { createWindow } from "@metamask/snaps-utils";
4
3
  import { AbstractExecutionService } from "../AbstractExecutionService.mjs";
5
4
  export class IframeExecutionService extends AbstractExecutionService {
@@ -1 +1 @@
1
- {"version":3,"file":"IframeExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/iframe/IframeExecutionService.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,YAAY,EAAE,8BAA8B;AAMrD,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AAMvE,MAAM,OAAO,sBAAuB,SAAQ,wBAAgC;IAG1E,YAAY,EACV,SAAS,EACT,SAAS,EACT,iBAAiB,GACqB;QACtC,KAAK,CAAC;YACJ,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAES,YAAY,CAAC,UAAoC;QACzD,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACnD,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,KAAa;QAIzC,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC;YACtC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC9B,EAAE,EAAE,KAAK;SACV,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,uBAAuB,CAAC;YACzC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,YAAY,EAAE,YAAY;YAC1B,YAAY,EAAE,GAAG;SAClB,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;IAC1C,CAAC;CACF","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\nimport { createWindow } from '@metamask/snaps-utils';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\n\ntype IframeExecutionEnvironmentServiceArgs = {\n iframeUrl: URL;\n} & ExecutionServiceArgs;\n\nexport class IframeExecutionService extends AbstractExecutionService<Window> {\n public iframeUrl: URL;\n\n constructor({\n iframeUrl,\n messenger,\n setupSnapProvider,\n }: IframeExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\n });\n this.iframeUrl = iframeUrl;\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<Window>): void {\n document.getElementById(jobWrapper.id)?.remove();\n }\n\n protected async initEnvStream(jobId: string): Promise<{\n worker: Window;\n stream: BasePostMessageStream;\n }> {\n const iframeWindow = await createWindow({\n uri: this.iframeUrl.toString(),\n id: jobId,\n });\n\n const stream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: iframeWindow,\n targetOrigin: '*',\n });\n\n return { worker: iframeWindow, stream };\n }\n}\n"]}
1
+ {"version":3,"file":"IframeExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/iframe/IframeExecutionService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,sCAAsC;AACxE,OAAO,EAAE,YAAY,EAAE,8BAA8B;AAMrD,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AAMvE,MAAM,OAAO,sBAAuB,SAAQ,wBAAgC;IAG1E,YAAY,EACV,SAAS,EACT,SAAS,EACT,iBAAiB,GACqB;QACtC,KAAK,CAAC;YACJ,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAES,YAAY,CAAC,UAAoC;QACzD,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACnD,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,KAAa;QAIzC,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC;YACtC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC9B,EAAE,EAAE,KAAK;SACV,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,uBAAuB,CAAC;YACzC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,YAAY,EAAE,YAAY;YAC1B,YAAY,EAAE,GAAG;SAClB,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;IAC1C,CAAC;CACF","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\nimport { createWindow } from '@metamask/snaps-utils';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\n\ntype IframeExecutionEnvironmentServiceArgs = {\n iframeUrl: URL;\n} & ExecutionServiceArgs;\n\nexport class IframeExecutionService extends AbstractExecutionService<Window> {\n public iframeUrl: URL;\n\n constructor({\n iframeUrl,\n messenger,\n setupSnapProvider,\n }: IframeExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\n });\n this.iframeUrl = iframeUrl;\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<Window>): void {\n document.getElementById(jobWrapper.id)?.remove();\n }\n\n protected async initEnvStream(jobId: string): Promise<{\n worker: Window;\n stream: BasePostMessageStream;\n }> {\n const iframeWindow = await createWindow({\n uri: this.iframeUrl.toString(),\n id: jobId,\n });\n\n const stream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: iframeWindow,\n targetOrigin: '*',\n });\n\n return { worker: iframeWindow, stream };\n }\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import { createRequire as $createRequire } from "module";
2
2
  const $require = $createRequire(import.meta.url);
3
- import $metamaskpostmessagestream from "@metamask/post-message-stream";
4
- const { ProcessParentMessageStream } = $metamaskpostmessagestream;
3
+ import { ProcessParentMessageStream } from "@metamask/post-message-stream";
5
4
  import { fork } from "child_process";
6
5
  import { AbstractExecutionService } from "../index.mjs";
7
6
  export class NodeProcessExecutionService extends AbstractExecutionService {
@@ -1 +1 @@
1
- {"version":3,"file":"NodeProcessExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeProcessExecutionService.ts"],"names":[],"mappings":";;;;AAGA,OAAO,EAAE,IAAI,EAAE,sBAAsB;AAGrC,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,MAAM,OAAO,2BAA4B,SAAQ,wBAAsC;IAC3E,KAAK,CAAC,aAAa;QAI3B,MAAM,MAAM,GAAG,IAAI,kBAEf,+EAA+E,GAEjF;YACE,KAAK,EAAE,MAAM;SACd,CACF,CAAC;QAEF,2EAA2E;QAC3E,mEAAmE;QACnE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACjC,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACjC,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,0BAA0B,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QACnE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,CAAC;IAES,YAAY,CAAC,UAA0C;QAC/D,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;CACF","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 { TerminateJobArgs } 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: TerminateJobArgs<ChildProcess>): void {\n jobWrapper.worker?.kill();\n }\n}\n"]}
1
+ {"version":3,"file":"NodeProcessExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeProcessExecutionService.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,0BAA0B,EAAE,sCAAsC;AAE3E,OAAO,EAAE,IAAI,EAAE,sBAAsB;AAGrC,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,MAAM,OAAO,2BAA4B,SAAQ,wBAAsC;IAC3E,KAAK,CAAC,aAAa;QAI3B,MAAM,MAAM,GAAG,IAAI,kBAEf,+EAA+E,GAEjF;YACE,KAAK,EAAE,MAAM;SACd,CACF,CAAC;QAEF,2EAA2E;QAC3E,mEAAmE;QACnE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACjC,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACjC,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,0BAA0B,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QACnE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,CAAC;IAES,YAAY,CAAC,UAA0C;QAC/D,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;CACF","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 { TerminateJobArgs } 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: TerminateJobArgs<ChildProcess>): void {\n jobWrapper.worker?.kill();\n }\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import { createRequire as $createRequire } from "module";
2
2
  const $require = $createRequire(import.meta.url);
3
- import $metamaskpostmessagestream from "@metamask/post-message-stream";
4
- const { ThreadParentMessageStream } = $metamaskpostmessagestream;
3
+ import { ThreadParentMessageStream } from "@metamask/post-message-stream";
5
4
  // eslint-disable-next-line @typescript-eslint/no-shadow
6
5
  import { Worker } from "worker_threads";
7
6
  import { AbstractExecutionService } from "../index.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"NodeThreadExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeThreadExecutionService.ts"],"names":[],"mappings":";;;;AAEA,wDAAwD;AACxD,OAAO,EAAE,MAAM,EAAE,uBAAuB;AAGxC,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,MAAM,OAAO,0BAA2B,SAAQ,wBAAgC;IACpE,KAAK,CAAC,aAAa;QAI3B,MAAM,MAAM,GAAG,IAAI,MAAM,kBAErB,8EAA8E,GAEhF;YACE,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,IAAI;SACb,CACF,CAAC;QAEF,2EAA2E;QAC3E,mEAAmE;QACnE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAChC,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAChC,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,yBAAyB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,CAAC;IAES,KAAK,CAAC,YAAY,CAC1B,UAAoC;QAEpC,MAAM,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC;IACvC,CAAC;CACF","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 { TerminateJobArgs } 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(\n jobWrapper: TerminateJobArgs<Worker>,\n ): Promise<void> {\n await jobWrapper.worker?.terminate();\n }\n}\n"]}
1
+ {"version":3,"file":"NodeThreadExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/node-js/NodeThreadExecutionService.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,yBAAyB,EAAE,sCAAsC;AAC1E,wDAAwD;AACxD,OAAO,EAAE,MAAM,EAAE,uBAAuB;AAGxC,OAAO,EAAE,wBAAwB,EAAE,qBAAW;AAE9C,MAAM,OAAO,0BAA2B,SAAQ,wBAAgC;IACpE,KAAK,CAAC,aAAa;QAI3B,MAAM,MAAM,GAAG,IAAI,MAAM,kBAErB,8EAA8E,GAEhF;YACE,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,IAAI;SACb,CACF,CAAC;QAEF,2EAA2E;QAC3E,mEAAmE;QACnE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAChC,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAChC,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,yBAAyB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,CAAC;IAES,KAAK,CAAC,YAAY,CAC1B,UAAoC;QAEpC,MAAM,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC;IACvC,CAAC;CACF","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 { TerminateJobArgs } 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(\n jobWrapper: TerminateJobArgs<Worker>,\n ): Promise<void> {\n await jobWrapper.worker?.terminate();\n }\n}\n"]}
@@ -10,8 +10,7 @@ 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 _OffscreenExecutionService_offscreenPromise;
13
- import $metamaskpostmessagestream from "@metamask/post-message-stream";
14
- const { BrowserRuntimePostMessageStream } = $metamaskpostmessagestream;
13
+ import { BrowserRuntimePostMessageStream } from "@metamask/post-message-stream";
15
14
  import { ProxyExecutionService } from "../proxy/ProxyExecutionService.mjs";
16
15
  export class OffscreenExecutionService extends ProxyExecutionService {
17
16
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"OffscreenExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA,OAAO,EAAE,qBAAqB,EAAE,2CAAuC;AAMvE,MAAM,OAAO,yBAA0B,SAAQ,qBAAqB;IAGlE;;;;;;;;;;OAUG;IACH,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,GACyB;QACzC,KAAK,CAAC;YACJ,SAAS;YACT,iBAAiB;YACjB,MAAM,EAAE,IAAI,+BAA+B,CAAC;gBAC1C,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,OAAO;aAChB,CAAC;SACH,CAAC,CAAC;QAzBI,8DAAoC;QA2B3C,uBAAA,IAAI,+CAAqB,gBAAgB,MAAA,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,KAAa;QACzC,MAAM,uBAAA,IAAI,mDAAkB,CAAC;QAE7B,OAAO,MAAM,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport type { ExecutionServiceArgs } from '../AbstractExecutionService';\nimport { ProxyExecutionService } from '../proxy/ProxyExecutionService';\n\ntype OffscreenExecutionEnvironmentServiceArgs = {\n offscreenPromise: Promise<unknown>;\n} & ExecutionServiceArgs;\n\nexport class OffscreenExecutionService extends ProxyExecutionService {\n readonly #offscreenPromise: Promise<unknown>;\n\n /**\n * Create a new offscreen 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.offscreenPromise - A promise that resolves when the offscreen\n * environment is ready.\n */\n constructor({\n messenger,\n setupSnapProvider,\n offscreenPromise,\n }: OffscreenExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\n stream: new BrowserRuntimePostMessageStream({\n name: 'parent',\n target: 'child',\n }),\n });\n\n this.#offscreenPromise = offscreenPromise;\n }\n\n /**\n * Create a new stream for the given job ID. This will wait for the offscreen\n * environment to be ready before creating the stream.\n *\n * @param jobId - The job ID to create a stream for.\n * @returns The stream for the given job ID.\n */\n protected async initEnvStream(jobId: string) {\n await this.#offscreenPromise;\n\n return await super.initEnvStream(jobId);\n }\n}\n"]}
1
+ {"version":3,"file":"OffscreenExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,+BAA+B,EAAE,sCAAsC;AAGhF,OAAO,EAAE,qBAAqB,EAAE,2CAAuC;AAMvE,MAAM,OAAO,yBAA0B,SAAQ,qBAAqB;IAGlE;;;;;;;;;;OAUG;IACH,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,GACyB;QACzC,KAAK,CAAC;YACJ,SAAS;YACT,iBAAiB;YACjB,MAAM,EAAE,IAAI,+BAA+B,CAAC;gBAC1C,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,OAAO;aAChB,CAAC;SACH,CAAC,CAAC;QAzBI,8DAAoC;QA2B3C,uBAAA,IAAI,+CAAqB,gBAAgB,MAAA,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,KAAa;QACzC,MAAM,uBAAA,IAAI,mDAAkB,CAAC;QAE7B,OAAO,MAAM,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport type { ExecutionServiceArgs } from '../AbstractExecutionService';\nimport { ProxyExecutionService } from '../proxy/ProxyExecutionService';\n\ntype OffscreenExecutionEnvironmentServiceArgs = {\n offscreenPromise: Promise<unknown>;\n} & ExecutionServiceArgs;\n\nexport class OffscreenExecutionService extends ProxyExecutionService {\n readonly #offscreenPromise: Promise<unknown>;\n\n /**\n * Create a new offscreen 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.offscreenPromise - A promise that resolves when the offscreen\n * environment is ready.\n */\n constructor({\n messenger,\n setupSnapProvider,\n offscreenPromise,\n }: OffscreenExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\n stream: new BrowserRuntimePostMessageStream({\n name: 'parent',\n target: 'child',\n }),\n });\n\n this.#offscreenPromise = offscreenPromise;\n }\n\n /**\n * Create a new stream for the given job ID. This will wait for the offscreen\n * environment to be ready before creating the stream.\n *\n * @param jobId - The job ID to create a stream for.\n * @returns The stream for the given job ID.\n */\n protected async initEnvStream(jobId: string) {\n await this.#offscreenPromise;\n\n return await super.initEnvStream(jobId);\n }\n}\n"]}
@@ -10,8 +10,7 @@ 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 _WebViewMessageStream_name, _WebViewMessageStream_target, _WebViewMessageStream_webView;
13
- import $metamaskpostmessagestream from "@metamask/post-message-stream";
14
- const { BasePostMessageStream } = $metamaskpostmessagestream;
13
+ import { BasePostMessageStream } from "@metamask/post-message-stream";
15
14
  import { isValidStreamMessage } from "@metamask/post-message-stream/dist/utils.js";
16
15
  import { logError } from "@metamask/snaps-utils";
17
16
  import { assert, bytesToBase64, stringToBytes } from "@metamask/utils";
@@ -1 +1 @@
1
- {"version":3,"file":"WebViewMessageStream.mjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewMessageStream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,OAAO,EAAE,oBAAoB,EAAE,oDAAiD;AAChF,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,wBAAwB;AAcvE;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,qBAAqB;IAO7D;;;;;;;;OAQG;IACH,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAqB;QACzD,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,0DAA0D;QAC1D,yFAAyF;QACzF,UAAU,EAAE;aACT,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;YAChB,uBAAA,IAAI,iCAAY,OAAO,MAAA,CAAC;YACxB,gCAAgC;YAChC,6DAA6D;YAC7D,OAAO,CAAC,uBAAuB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACjD,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,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,oEAAoE;QACpE,8CAA8C;QAC9C,iDAAiD;QACjD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACpC,uBAAA,IAAI,qCAAS,CAAC,gBAAgB,CAAC,uBAAuB,MAAM,IAAI,CAAC,CAAC;IACpE,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 { logError } from '@metamask/snaps-utils';\nimport { assert, bytesToBase64, 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 getWebView: () => Promise<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.getWebView - A asynchronous getter for the webview.\n */\n constructor({ name, target, getWebView }: WebViewStreamArgs) {\n super();\n\n this.#name = name;\n this.#target = target;\n\n this._onMessage = this._onMessage.bind(this);\n\n // This is a bit atypical from other post-message streams.\n // We have to wait for the WebView to fully load before we can continue using the stream.\n getWebView()\n .then((webView) => {\n this.#webView = webView;\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n webView.registerMessageListener(this._onMessage);\n this._handshake();\n })\n .catch((error) => {\n logError(error);\n });\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 base64 encode the message before injecting it.\n // This adds significant performance overhead.\n // TODO: Should we use mobile native base64 here?\n const bytes = stringToBytes(json);\n const base64 = bytesToBase64(bytes);\n this.#webView.injectJavaScript(`window.postMessage('${base64}')`);\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,QAAQ,EAAE,8BAA8B;AACjD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,wBAAwB;AAcvE;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,qBAAqB;IAO7D;;;;;;;;OAQG;IACH,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAqB;QACzD,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,0DAA0D;QAC1D,yFAAyF;QACzF,UAAU,EAAE;aACT,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;YAChB,uBAAA,IAAI,iCAAY,OAAO,MAAA,CAAC;YACxB,gCAAgC;YAChC,6DAA6D;YAC7D,OAAO,CAAC,uBAAuB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACjD,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,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,oEAAoE;QACpE,8CAA8C;QAC9C,iDAAiD;QACjD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACpC,uBAAA,IAAI,qCAAS,CAAC,gBAAgB,CAAC,uBAAuB,MAAM,IAAI,CAAC,CAAC;IACpE,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 { logError } from '@metamask/snaps-utils';\nimport { assert, bytesToBase64, 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 getWebView: () => Promise<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.getWebView - A asynchronous getter for the webview.\n */\n constructor({ name, target, getWebView }: WebViewStreamArgs) {\n super();\n\n this.#name = name;\n this.#target = target;\n\n this._onMessage = this._onMessage.bind(this);\n\n // This is a bit atypical from other post-message streams.\n // We have to wait for the WebView to fully load before we can continue using the stream.\n getWebView()\n .then((webView) => {\n this.#webView = webView;\n // This method is already bound.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n webView.registerMessageListener(this._onMessage);\n this._handshake();\n })\n .catch((error) => {\n logError(error);\n });\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 base64 encode the message before injecting it.\n // This adds significant performance overhead.\n // TODO: Should we use mobile native base64 here?\n const bytes = stringToBytes(json);\n const base64 = bytesToBase64(bytes);\n this.#webView.injectJavaScript(`window.postMessage('${base64}')`);\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"]}
@@ -10,8 +10,7 @@ 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 _WebWorkerExecutionService_documentUrl, _WebWorkerExecutionService_runtimeStream;
13
- import $metamaskpostmessagestream from "@metamask/post-message-stream";
14
- const { WindowPostMessageStream } = $metamaskpostmessagestream;
13
+ import { WindowPostMessageStream } from "@metamask/post-message-stream";
15
14
  import { createWindow } from "@metamask/snaps-utils";
16
15
  import { assert } from "@metamask/utils";
17
16
  import { nanoid } from "nanoid";
@@ -1 +1 @@
1
- {"version":3,"file":"WebWorkerExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/webworker/WebWorkerExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,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,GACwB;QACzC,KAAK,CAAC;YACJ,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAvBL,yDAAkB;QAElB,2DAAuC;QAuBrC,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 }: WebWorkerExecutionEnvironmentServiceArgs) {\n super({\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.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,GACwB;QACzC,KAAK,CAAC;YACJ,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAvBL,yDAAkB;QAElB,2DAAuC;QAuBrC,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 }: WebWorkerExecutionEnvironmentServiceArgs) {\n super({\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"]}
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
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_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_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_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;
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_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_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;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.SnapController = exports.SNAP_APPROVAL_RESULT = exports.SNAP_APPROVAL_UPDATE = exports.SNAP_APPROVAL_INSTALL = exports.controllerName = void 0;
19
19
  const base_controller_1 = require("@metamask/base-controller");
@@ -75,7 +75,7 @@ const name = 'SnapController';
75
75
  * - Start: Initializes the snap in its SES realm with the authorized permissions.
76
76
  */
77
77
  class SnapController extends base_controller_1.BaseController {
78
- 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 = () => ({}), }) {
78
+ 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, }) {
79
79
  super({
80
80
  messenger,
81
81
  metadata: {
@@ -126,6 +126,7 @@ class SnapController extends base_controller_1.BaseController {
126
126
  _SnapController_encryptor.set(this, void 0);
127
127
  _SnapController_getMnemonic.set(this, void 0);
128
128
  _SnapController_getFeatureFlags.set(this, void 0);
129
+ _SnapController_clientCryptography.set(this, void 0);
129
130
  _SnapController_detectSnapLocation.set(this, void 0);
130
131
  _SnapController_snapsRuntimeData.set(this, void 0);
131
132
  _SnapController_rollbackSnapshots.set(this, void 0);
@@ -145,6 +146,7 @@ class SnapController extends base_controller_1.BaseController {
145
146
  __classPrivateFieldSet(this, _SnapController_encryptor, encryptor, "f");
146
147
  __classPrivateFieldSet(this, _SnapController_getMnemonic, getMnemonic, "f");
147
148
  __classPrivateFieldSet(this, _SnapController_getFeatureFlags, getFeatureFlags, "f");
149
+ __classPrivateFieldSet(this, _SnapController_clientCryptography, clientCryptography, "f");
148
150
  __classPrivateFieldSet(this, _SnapController_preinstalledSnaps, preinstalledSnaps, "f");
149
151
  this._onUnhandledSnapError = this._onUnhandledSnapError.bind(this);
150
152
  this._onOutboundRequest = this._onOutboundRequest.bind(this);
@@ -1006,7 +1008,7 @@ class SnapController extends base_controller_1.BaseController {
1006
1008
  }
1007
1009
  }
1008
1010
  exports.SnapController = SnapController;
1009
- _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_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() {
1011
+ _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() {
1010
1012
  const disableGuard = ({ snapId }) => {
1011
1013
  return this.getExpect(snapId).enabled;
1012
1014
  };
@@ -1259,7 +1261,11 @@ async function _SnapController_getSnapEncryptionKey({ snapId, salt: passedSalt,
1259
1261
  }
1260
1262
  const salt = passedSalt ?? __classPrivateFieldGet(this, _SnapController_encryptor, "f").generateSalt();
1261
1263
  const mnemonicPhrase = await __classPrivateFieldGet(this, _SnapController_getMnemonic, "f").call(this);
1262
- const entropy = await (0, snaps_rpc_methods_1.getEncryptionEntropy)({ snapId, mnemonicPhrase });
1264
+ const entropy = await (0, snaps_rpc_methods_1.getEncryptionEntropy)({
1265
+ snapId,
1266
+ mnemonicPhrase,
1267
+ cryptographicFunctions: __classPrivateFieldGet(this, _SnapController_clientCryptography, "f"),
1268
+ });
1263
1269
  const encryptionKey = await __classPrivateFieldGet(this, _SnapController_encryptor, "f").keyFromPassword(entropy, salt, true, keyMetadata);
1264
1270
  const exportedKey = await __classPrivateFieldGet(this, _SnapController_encryptor, "f").exportKey(encryptionKey);
1265
1271
  // Cache exported encryption key in runtime