@metamask/snaps-controllers 3.6.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.
- package/CHANGELOG.md +19 -1
- package/dist/cjs/cronjob/CronjobController.js +2 -2
- package/dist/cjs/cronjob/CronjobController.js.map +1 -1
- package/dist/cjs/services/ProxyPostMessageStream.js +3 -10
- package/dist/cjs/services/ProxyPostMessageStream.js.map +1 -1
- package/dist/cjs/services/node/NodeProcessExecutionService.js +13 -1
- package/dist/cjs/services/node/NodeProcessExecutionService.js.map +1 -1
- package/dist/cjs/services/node/NodeThreadExecutionService.js +14 -1
- package/dist/cjs/services/node/NodeThreadExecutionService.js.map +1 -1
- package/dist/cjs/services/offscreen/OffscreenExecutionService.js +36 -99
- package/dist/cjs/services/offscreen/OffscreenExecutionService.js.map +1 -1
- package/dist/cjs/services/proxy/ProxyExecutionService.js +110 -0
- package/dist/cjs/services/proxy/ProxyExecutionService.js.map +1 -0
- package/dist/cjs/snaps/SnapController.js +206 -96
- package/dist/cjs/snaps/SnapController.js.map +1 -1
- package/dist/cjs/snaps/endowments/enum.js +1 -0
- package/dist/cjs/snaps/endowments/enum.js.map +1 -1
- package/dist/cjs/snaps/endowments/index.js +12 -4
- package/dist/cjs/snaps/endowments/index.js.map +1 -1
- package/dist/cjs/snaps/endowments/signature-insight.js +106 -0
- package/dist/cjs/snaps/endowments/signature-insight.js.map +1 -0
- package/dist/cjs/utils.js +32 -0
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/cronjob/CronjobController.js +2 -2
- package/dist/esm/cronjob/CronjobController.js.map +1 -1
- package/dist/esm/services/ProxyPostMessageStream.js +3 -10
- package/dist/esm/services/ProxyPostMessageStream.js.map +1 -1
- package/dist/esm/services/node/NodeProcessExecutionService.js +13 -1
- package/dist/esm/services/node/NodeProcessExecutionService.js.map +1 -1
- package/dist/esm/services/node/NodeThreadExecutionService.js +14 -1
- package/dist/esm/services/node/NodeThreadExecutionService.js.map +1 -1
- package/dist/esm/services/offscreen/OffscreenExecutionService.js +36 -99
- package/dist/esm/services/offscreen/OffscreenExecutionService.js.map +1 -1
- package/dist/esm/services/proxy/ProxyExecutionService.js +100 -0
- package/dist/esm/services/proxy/ProxyExecutionService.js.map +1 -0
- package/dist/esm/snaps/SnapController.js +208 -98
- package/dist/esm/snaps/SnapController.js.map +1 -1
- package/dist/esm/snaps/endowments/enum.js +1 -0
- package/dist/esm/snaps/endowments/enum.js.map +1 -1
- package/dist/esm/snaps/endowments/index.js +10 -4
- package/dist/esm/snaps/endowments/index.js.map +1 -1
- package/dist/esm/snaps/endowments/signature-insight.js +99 -0
- package/dist/esm/snaps/endowments/signature-insight.js.map +1 -0
- package/dist/esm/utils.js +37 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/cronjob/CronjobController.d.ts +2 -2
- package/dist/types/services/ProxyPostMessageStream.d.ts +1 -2
- package/dist/types/services/offscreen/OffscreenExecutionService.d.ts +5 -22
- package/dist/types/services/proxy/ProxyExecutionService.d.ts +39 -0
- package/dist/types/snaps/SnapController.d.ts +33 -20
- package/dist/types/snaps/endowments/enum.d.ts +1 -0
- package/dist/types/snaps/endowments/index.d.ts +12 -0
- package/dist/types/snaps/endowments/signature-insight.d.ts +39 -0
- package/dist/types/utils.d.ts +99 -0
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,22 @@ 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
|
+
|
|
19
|
+
## [4.0.0]
|
|
20
|
+
### Changed
|
|
21
|
+
- **BREAKING:** Remove `:snapAdded` event ([#2073](https://github.com/MetaMask/snaps/pull/2073))
|
|
22
|
+
- **BREAKING:** Remove `:snapRemoved` event ([#2076](https://github.com/MetaMask/snaps/pull/2076))
|
|
23
|
+
- Populate subject metadata when snaps are added to state ([#2069](https://github.com/MetaMask/snaps/pull/2069))
|
|
24
|
+
|
|
9
25
|
## [3.6.0]
|
|
10
26
|
### Changed
|
|
11
27
|
- Revert usage of `DecompressionStream` ([#2052](https://github.com/MetaMask/snaps/pull/2052))
|
|
@@ -152,7 +168,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
152
168
|
- The version of the package no longer needs to match the version of all other
|
|
153
169
|
MetaMask Snaps packages.
|
|
154
170
|
|
|
155
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@
|
|
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
|
|
173
|
+
[4.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.6.0...@metamask/snaps-controllers@4.0.0
|
|
156
174
|
[3.6.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.5.1...@metamask/snaps-controllers@3.6.0
|
|
157
175
|
[3.5.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.5.0...@metamask/snaps-controllers@3.5.1
|
|
158
176
|
[3.5.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.4.1...@metamask/snaps-controllers@3.5.0
|
|
@@ -214,7 +214,7 @@ class CronjobController extends _basecontroller.BaseController {
|
|
|
214
214
|
*/ destroy() {
|
|
215
215
|
super.destroy();
|
|
216
216
|
/* eslint-disable @typescript-eslint/unbound-method */ this.messagingSystem.unsubscribe('SnapController:snapInstalled', this._handleSnapRegisterEvent);
|
|
217
|
-
this.messagingSystem.unsubscribe('SnapController:
|
|
217
|
+
this.messagingSystem.unsubscribe('SnapController:snapUninstalled', this._handleSnapUnregisterEvent);
|
|
218
218
|
this.messagingSystem.unsubscribe('SnapController:snapEnabled', this._handleSnapRegisterEvent);
|
|
219
219
|
this.messagingSystem.unsubscribe('SnapController:snapDisabled', this._handleSnapUnregisterEvent);
|
|
220
220
|
this.messagingSystem.unsubscribe('SnapController:snapUpdated', this._handleEventSnapUpdated);
|
|
@@ -283,7 +283,7 @@ class CronjobController extends _basecontroller.BaseController {
|
|
|
283
283
|
this._handleEventSnapUpdated = this._handleEventSnapUpdated.bind(this);
|
|
284
284
|
// Subscribe to Snap events
|
|
285
285
|
/* eslint-disable @typescript-eslint/unbound-method */ this.messagingSystem.subscribe('SnapController:snapInstalled', this._handleSnapRegisterEvent);
|
|
286
|
-
this.messagingSystem.subscribe('SnapController:
|
|
286
|
+
this.messagingSystem.subscribe('SnapController:snapUninstalled', this._handleSnapUnregisterEvent);
|
|
287
287
|
this.messagingSystem.subscribe('SnapController:snapEnabled', this._handleSnapRegisterEvent);
|
|
288
288
|
this.messagingSystem.subscribe('SnapController:snapDisabled', this._handleSnapUnregisterEvent);
|
|
289
289
|
this.messagingSystem.subscribe('SnapController:snapUpdated', this._handleEventSnapUpdated);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cronjob/CronjobController.ts"],"sourcesContent":["import type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { GetPermissions } from '@metamask/permission-controller';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type {\n TruncatedSnap,\n CronjobSpecification,\n} from '@metamask/snaps-utils';\nimport {\n HandlerType,\n parseCronExpression,\n logError,\n} from '@metamask/snaps-utils';\nimport { Duration, inMilliseconds } from '@metamask/utils';\n\nimport type {\n GetAllSnaps,\n HandleSnapRequest,\n SnapDisabled,\n SnapEnabled,\n SnapInstalled,\n SnapRemoved,\n SnapUpdated,\n} from '..';\nimport { getRunnableSnaps, SnapEndowments } from '..';\nimport { getCronjobCaveatJobs } from '../snaps/endowments/cronjob';\nimport { Timer } from '../snaps/Timer';\n\nexport type CronjobControllerActions =\n | GetAllSnaps\n | HandleSnapRequest\n | GetPermissions;\n\nexport type CronjobControllerEvents =\n | SnapInstalled\n | SnapRemoved\n | SnapUpdated\n | SnapEnabled\n | SnapDisabled;\n\nexport type CronjobControllerMessenger = RestrictedControllerMessenger<\n 'CronjobController',\n CronjobControllerActions,\n CronjobControllerEvents,\n CronjobControllerActions['type'],\n CronjobControllerEvents['type']\n>;\n\nexport const DAILY_TIMEOUT = inMilliseconds(24, Duration.Hour);\n\nexport type CronjobControllerArgs = {\n messenger: CronjobControllerMessenger;\n /**\n * Persisted state that will be used for rehydration.\n */\n state?: CronjobControllerState;\n};\n\nexport type Cronjob = {\n timer?: Timer;\n id: string;\n snapId: SnapId;\n} & CronjobSpecification;\n\nexport type StoredJobInformation = {\n lastRun: number;\n};\n\nexport type CronjobControllerState = {\n jobs: Record<string, StoredJobInformation>;\n};\n\nconst controllerName = 'CronjobController';\n\n/**\n * Use this controller to register and schedule periodically executed jobs\n * using RPC method hooks.\n */\nexport class CronjobController extends BaseController<\n typeof controllerName,\n CronjobControllerState,\n CronjobControllerMessenger\n> {\n #messenger: CronjobControllerMessenger;\n\n #dailyTimer!: Timer;\n\n #timers: Map<string, Timer>;\n\n // Mapping from jobId to snapId\n #snapIds: Map<string, string>;\n\n constructor({ messenger, state }: CronjobControllerArgs) {\n super({\n messenger,\n metadata: {\n jobs: { persist: true, anonymous: false },\n },\n name: controllerName,\n state: {\n jobs: {},\n ...state,\n },\n });\n this.#timers = new Map();\n this.#snapIds = new Map();\n this.#messenger = messenger;\n\n this._handleSnapRegisterEvent = this._handleSnapRegisterEvent.bind(this);\n this._handleSnapUnregisterEvent =\n this._handleSnapUnregisterEvent.bind(this);\n this._handleEventSnapUpdated = this._handleEventSnapUpdated.bind(this);\n\n // Subscribe to Snap events\n /* eslint-disable @typescript-eslint/unbound-method */\n this.messagingSystem.subscribe(\n 'SnapController:snapInstalled',\n this._handleSnapRegisterEvent,\n );\n\n this.messagingSystem.subscribe(\n 'SnapController:snapRemoved',\n this._handleSnapUnregisterEvent,\n );\n\n this.messagingSystem.subscribe(\n 'SnapController:snapEnabled',\n this._handleSnapRegisterEvent,\n );\n\n this.messagingSystem.subscribe(\n 'SnapController:snapDisabled',\n this._handleSnapUnregisterEvent,\n );\n\n this.messagingSystem.subscribe(\n 'SnapController:snapUpdated',\n this._handleEventSnapUpdated,\n );\n /* eslint-enable @typescript-eslint/unbound-method */\n\n this.dailyCheckIn().catch((error) => {\n logError(error);\n });\n }\n\n /**\n * Retrieve all cronjob specifications for all runnable snaps.\n *\n * @returns Array of Cronjob specifications.\n */\n private getAllJobs(): Cronjob[] {\n const snaps = this.messagingSystem.call('SnapController:getAll');\n const filteredSnaps = getRunnableSnaps(snaps);\n\n const jobs = filteredSnaps.map((snap) => this.getSnapJobs(snap.id));\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return jobs.flat().filter((job) => job !== undefined) as Cronjob[];\n }\n\n /**\n * Retrieve all Cronjob specifications for a Snap.\n *\n * @param snapId - ID of a Snap.\n * @returns Array of Cronjob specifications.\n */\n private getSnapJobs(snapId: SnapId): Cronjob[] | undefined {\n const permissions = this.#messenger.call(\n 'PermissionController:getPermissions',\n snapId,\n );\n\n const permission = permissions?.[SnapEndowments.Cronjob];\n const definitions = getCronjobCaveatJobs(permission);\n\n return definitions?.map((definition, idx) => {\n return { ...definition, id: `${snapId}-${idx}`, snapId };\n });\n }\n\n /**\n * Register cron jobs for a given snap by getting specification from a permission caveats.\n * Once registered, each job will be scheduled.\n *\n * @param snapId - ID of a snap.\n */\n register(snapId: SnapId) {\n const jobs = this.getSnapJobs(snapId);\n jobs?.forEach((job) => this.schedule(job));\n }\n\n /**\n * Schedule a new job.\n * This will interpret the cron expression and tell the timer to execute the job\n * at the next suitable point in time.\n * Job last run state will be initialized afterwards.\n *\n * Note: Schedule will be skipped if the job's execution time is too far in the future and\n * will be revisited on a daily check.\n *\n * @param job - Cronjob specification.\n */\n private schedule(job: Cronjob) {\n if (this.#timers.has(job.id)) {\n return;\n }\n\n const parsed = parseCronExpression(job.expression);\n const next = parsed.next();\n const now = new Date();\n const ms = next.getTime() - now.getTime();\n\n // Don't schedule this job yet as it is too far in the future\n if (ms > DAILY_TIMEOUT) {\n return;\n }\n\n const timer = new Timer(ms);\n timer.start(() => {\n this.executeCronjob(job).catch((error) => {\n // TODO: Decide how to handle errors.\n logError(error);\n });\n\n this.#timers.delete(job.id);\n this.schedule(job);\n });\n\n if (!this.state.jobs[job.id]?.lastRun) {\n this.updateJobLastRunState(job.id, 0); // 0 for init, never ran actually\n }\n\n this.#timers.set(job.id, timer);\n this.#snapIds.set(job.id, job.snapId);\n }\n\n /**\n * Execute job.\n *\n * @param job - Cronjob specification.\n */\n private async executeCronjob(job: Cronjob) {\n this.updateJobLastRunState(job.id, Date.now());\n await this.#messenger.call('SnapController:handleRequest', {\n snapId: job.snapId,\n origin: '',\n handler: HandlerType.OnCronjob,\n request: job.request,\n });\n }\n\n /**\n * Unregister all jobs related to the given snapId.\n *\n * @param snapId - ID of a snap.\n */\n unregister(snapId: string) {\n const jobs = [...this.#snapIds.entries()].filter(\n ([_, jobSnapId]) => jobSnapId === snapId,\n );\n\n if (jobs.length) {\n jobs.forEach(([id]) => {\n const timer = this.#timers.get(id);\n if (timer) {\n timer.cancel();\n this.#timers.delete(id);\n this.#snapIds.delete(id);\n }\n });\n }\n }\n\n /**\n * Update time of a last run for the Cronjob specified by ID.\n *\n * @param jobId - ID of a cron job.\n * @param lastRun - Unix timestamp when the job was last ran.\n */\n private updateJobLastRunState(jobId: string, lastRun: number) {\n this.update((state) => {\n state.jobs[jobId] = {\n lastRun,\n };\n });\n }\n\n /**\n * Runs every 24 hours to check if new jobs need to be scheduled.\n *\n * This is necessary for longer running jobs that execute with more than 24 hours between them.\n */\n async dailyCheckIn() {\n const jobs = this.getAllJobs();\n\n for (const job of jobs) {\n const parsed = parseCronExpression(job.expression);\n const lastRun = this.state.jobs[job.id]?.lastRun;\n // If a job was supposed to run while we were shut down but wasn't we run it now\n if (\n lastRun !== undefined &&\n parsed.hasPrev() &&\n parsed.prev().getTime() > lastRun\n ) {\n await this.executeCronjob(job);\n }\n\n // Try scheduling, will fail if an existing scheduled job is found\n this.schedule(job);\n }\n\n this.#dailyTimer = new Timer(DAILY_TIMEOUT);\n this.#dailyTimer.start(() => {\n this.dailyCheckIn().catch((error) => {\n // TODO: Decide how to handle errors.\n logError(error);\n });\n });\n }\n\n /**\n * Run controller teardown process and unsubscribe from Snap events.\n */\n destroy() {\n super.destroy();\n\n /* eslint-disable @typescript-eslint/unbound-method */\n this.messagingSystem.unsubscribe(\n 'SnapController:snapInstalled',\n this._handleSnapRegisterEvent,\n );\n\n this.messagingSystem.unsubscribe(\n 'SnapController:snapRemoved',\n this._handleSnapUnregisterEvent,\n );\n\n this.messagingSystem.unsubscribe(\n 'SnapController:snapEnabled',\n this._handleSnapRegisterEvent,\n );\n\n this.messagingSystem.unsubscribe(\n 'SnapController:snapDisabled',\n this._handleSnapUnregisterEvent,\n );\n\n this.messagingSystem.unsubscribe(\n 'SnapController:snapUpdated',\n this._handleEventSnapUpdated,\n );\n /* eslint-enable @typescript-eslint/unbound-method */\n\n this.#snapIds.forEach((snapId) => {\n this.unregister(snapId);\n });\n }\n\n /**\n * Handle events that should cause cronjobs to be registered.\n *\n * @param snap - Basic Snap information.\n */\n private _handleSnapRegisterEvent(snap: TruncatedSnap) {\n this.register(snap.id);\n }\n\n /**\n * Handle events that should cause cronjobs to be unregistered.\n *\n * @param snap - Basic Snap information.\n */\n private _handleSnapUnregisterEvent(snap: TruncatedSnap) {\n this.unregister(snap.id);\n }\n\n /**\n * Handle cron jobs on 'snapUpdated' event.\n *\n * @param snap - Basic Snap information.\n */\n private _handleEventSnapUpdated(snap: TruncatedSnap) {\n this.unregister(snap.id);\n this.register(snap.id);\n }\n}\n"],"names":["DAILY_TIMEOUT","CronjobController","inMilliseconds","Duration","Hour","controllerName","BaseController","getAllJobs","snaps","messagingSystem","call","filteredSnaps","getRunnableSnaps","jobs","map","snap","getSnapJobs","id","flat","filter","job","undefined","snapId","permissions","messenger","permission","SnapEndowments","Cronjob","definitions","getCronjobCaveatJobs","definition","idx","register","forEach","schedule","timers","has","parsed","parseCronExpression","expression","next","now","Date","ms","getTime","timer","Timer","start","executeCronjob","catch","error","logError","delete","state","lastRun","updateJobLastRunState","set","snapIds","origin","handler","HandlerType","OnCronjob","request","unregister","entries","_","jobSnapId","length","get","cancel","jobId","update","dailyCheckIn","hasPrev","prev","dailyTimer","destroy","unsubscribe","_handleSnapRegisterEvent","_handleSnapUnregisterEvent","_handleEventSnapUpdated","constructor","metadata","persist","anonymous","name","Map","bind","subscribe"],"mappings":";;;;;;;;;;;IAgDaA,aAAa;eAAbA;;IA8BAC,iBAAiB;eAAjBA;;;gCA7EkB;4BAWxB;uBACkC;kBAWQ;yBACZ;uBACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBf,MAAMD,gBAAgBE,IAAAA,qBAAc,EAAC,IAAIC,eAAQ,CAACC,IAAI;AAwB7D,MAAMC,iBAAiB;IAWrB,0CAEA,2CAEA,uCAEA,+BAA+B;AAC/B;AAZK,MAAMJ,0BAA0BK,8BAAc;IAoEnD;;;;GAIC,GACD,AAAQC,aAAwB;QAC9B,MAAMC,QAAQ,IAAI,CAACC,eAAe,CAACC,IAAI,CAAC;QACxC,MAAMC,gBAAgBC,IAAAA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ACV,wBAAwB;QAG/B,IAAI,CAACrE,eAAe,CAAC+E,SAAS,CAC5B,8BACA,IAAI,CAACT,0BAA0B;QAGjC,IAAI,CAACtE,eAAe,CAAC+E,SAAS,CAC5B,8BACA,IAAI,CAACV,wBAAwB;QAG/B,IAAI,CAACrE,eAAe,CAAC+E,SAAS,CAC5B,+BACA,IAAI,CAACT,0BAA0B;QAGjC,IAAI,CAACtE,eAAe,CAAC+E,SAAS,CAC5B,8BACA,IAAI,CAACR,uBAAuB;QAE9B,mDAAmD,GAEnD,IAAI,CAACR,YAAY,GAAGvB,KAAK,CAAC,CAACC;YACzBC,IAAAA,oBAAQ,EAACD;QACX;IACF;AAiPF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/cronjob/CronjobController.ts"],"sourcesContent":["import type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { GetPermissions } from '@metamask/permission-controller';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type {\n TruncatedSnap,\n CronjobSpecification,\n} from '@metamask/snaps-utils';\nimport {\n HandlerType,\n parseCronExpression,\n logError,\n} from '@metamask/snaps-utils';\nimport { Duration, inMilliseconds } from '@metamask/utils';\n\nimport type {\n GetAllSnaps,\n HandleSnapRequest,\n SnapDisabled,\n SnapEnabled,\n SnapInstalled,\n SnapUninstalled,\n SnapUpdated,\n} from '..';\nimport { getRunnableSnaps, SnapEndowments } from '..';\nimport { getCronjobCaveatJobs } from '../snaps/endowments/cronjob';\nimport { Timer } from '../snaps/Timer';\n\nexport type CronjobControllerActions =\n | GetAllSnaps\n | HandleSnapRequest\n | GetPermissions;\n\nexport type CronjobControllerEvents =\n | SnapInstalled\n | SnapUninstalled\n | SnapUpdated\n | SnapEnabled\n | SnapDisabled;\n\nexport type CronjobControllerMessenger = RestrictedControllerMessenger<\n 'CronjobController',\n CronjobControllerActions,\n CronjobControllerEvents,\n CronjobControllerActions['type'],\n CronjobControllerEvents['type']\n>;\n\nexport const DAILY_TIMEOUT = inMilliseconds(24, Duration.Hour);\n\nexport type CronjobControllerArgs = {\n messenger: CronjobControllerMessenger;\n /**\n * Persisted state that will be used for rehydration.\n */\n state?: CronjobControllerState;\n};\n\nexport type Cronjob = {\n timer?: Timer;\n id: string;\n snapId: SnapId;\n} & CronjobSpecification;\n\nexport type StoredJobInformation = {\n lastRun: number;\n};\n\nexport type CronjobControllerState = {\n jobs: Record<string, StoredJobInformation>;\n};\n\nconst controllerName = 'CronjobController';\n\n/**\n * Use this controller to register and schedule periodically executed jobs\n * using RPC method hooks.\n */\nexport class CronjobController extends BaseController<\n typeof controllerName,\n CronjobControllerState,\n CronjobControllerMessenger\n> {\n #messenger: CronjobControllerMessenger;\n\n #dailyTimer!: Timer;\n\n #timers: Map<string, Timer>;\n\n // Mapping from jobId to snapId\n #snapIds: Map<string, string>;\n\n constructor({ messenger, state }: CronjobControllerArgs) {\n super({\n messenger,\n metadata: {\n jobs: { persist: true, anonymous: false },\n },\n name: controllerName,\n state: {\n jobs: {},\n ...state,\n },\n });\n this.#timers = new Map();\n this.#snapIds = new Map();\n this.#messenger = messenger;\n\n this._handleSnapRegisterEvent = this._handleSnapRegisterEvent.bind(this);\n this._handleSnapUnregisterEvent =\n this._handleSnapUnregisterEvent.bind(this);\n this._handleEventSnapUpdated = this._handleEventSnapUpdated.bind(this);\n\n // Subscribe to Snap events\n /* eslint-disable @typescript-eslint/unbound-method */\n this.messagingSystem.subscribe(\n 'SnapController:snapInstalled',\n this._handleSnapRegisterEvent,\n );\n\n this.messagingSystem.subscribe(\n 'SnapController:snapUninstalled',\n this._handleSnapUnregisterEvent,\n );\n\n this.messagingSystem.subscribe(\n 'SnapController:snapEnabled',\n this._handleSnapRegisterEvent,\n );\n\n this.messagingSystem.subscribe(\n 'SnapController:snapDisabled',\n this._handleSnapUnregisterEvent,\n );\n\n this.messagingSystem.subscribe(\n 'SnapController:snapUpdated',\n this._handleEventSnapUpdated,\n );\n /* eslint-enable @typescript-eslint/unbound-method */\n\n this.dailyCheckIn().catch((error) => {\n logError(error);\n });\n }\n\n /**\n * Retrieve all cronjob specifications for all runnable snaps.\n *\n * @returns Array of Cronjob specifications.\n */\n private getAllJobs(): Cronjob[] {\n const snaps = this.messagingSystem.call('SnapController:getAll');\n const filteredSnaps = getRunnableSnaps(snaps);\n\n const jobs = filteredSnaps.map((snap) => this.getSnapJobs(snap.id));\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return jobs.flat().filter((job) => job !== undefined) as Cronjob[];\n }\n\n /**\n * Retrieve all Cronjob specifications for a Snap.\n *\n * @param snapId - ID of a Snap.\n * @returns Array of Cronjob specifications.\n */\n private getSnapJobs(snapId: SnapId): Cronjob[] | undefined {\n const permissions = this.#messenger.call(\n 'PermissionController:getPermissions',\n snapId,\n );\n\n const permission = permissions?.[SnapEndowments.Cronjob];\n const definitions = getCronjobCaveatJobs(permission);\n\n return definitions?.map((definition, idx) => {\n return { ...definition, id: `${snapId}-${idx}`, snapId };\n });\n }\n\n /**\n * Register cron jobs for a given snap by getting specification from a permission caveats.\n * Once registered, each job will be scheduled.\n *\n * @param snapId - ID of a snap.\n */\n register(snapId: SnapId) {\n const jobs = this.getSnapJobs(snapId);\n jobs?.forEach((job) => this.schedule(job));\n }\n\n /**\n * Schedule a new job.\n * This will interpret the cron expression and tell the timer to execute the job\n * at the next suitable point in time.\n * Job last run state will be initialized afterwards.\n *\n * Note: Schedule will be skipped if the job's execution time is too far in the future and\n * will be revisited on a daily check.\n *\n * @param job - Cronjob specification.\n */\n private schedule(job: Cronjob) {\n if (this.#timers.has(job.id)) {\n return;\n }\n\n const parsed = parseCronExpression(job.expression);\n const next = parsed.next();\n const now = new Date();\n const ms = next.getTime() - now.getTime();\n\n // Don't schedule this job yet as it is too far in the future\n if (ms > DAILY_TIMEOUT) {\n return;\n }\n\n const timer = new Timer(ms);\n timer.start(() => {\n this.executeCronjob(job).catch((error) => {\n // TODO: Decide how to handle errors.\n logError(error);\n });\n\n this.#timers.delete(job.id);\n this.schedule(job);\n });\n\n if (!this.state.jobs[job.id]?.lastRun) {\n this.updateJobLastRunState(job.id, 0); // 0 for init, never ran actually\n }\n\n this.#timers.set(job.id, timer);\n this.#snapIds.set(job.id, job.snapId);\n }\n\n /**\n * Execute job.\n *\n * @param job - Cronjob specification.\n */\n private async executeCronjob(job: Cronjob) {\n this.updateJobLastRunState(job.id, Date.now());\n await this.#messenger.call('SnapController:handleRequest', {\n snapId: job.snapId,\n origin: '',\n handler: HandlerType.OnCronjob,\n request: job.request,\n });\n }\n\n /**\n * Unregister all jobs related to the given snapId.\n *\n * @param snapId - ID of a snap.\n */\n unregister(snapId: string) {\n const jobs = [...this.#snapIds.entries()].filter(\n ([_, jobSnapId]) => jobSnapId === snapId,\n );\n\n if (jobs.length) {\n jobs.forEach(([id]) => {\n const timer = this.#timers.get(id);\n if (timer) {\n timer.cancel();\n this.#timers.delete(id);\n this.#snapIds.delete(id);\n }\n });\n }\n }\n\n /**\n * Update time of a last run for the Cronjob specified by ID.\n *\n * @param jobId - ID of a cron job.\n * @param lastRun - Unix timestamp when the job was last ran.\n */\n private updateJobLastRunState(jobId: string, lastRun: number) {\n this.update((state) => {\n state.jobs[jobId] = {\n lastRun,\n };\n });\n }\n\n /**\n * Runs every 24 hours to check if new jobs need to be scheduled.\n *\n * This is necessary for longer running jobs that execute with more than 24 hours between them.\n */\n async dailyCheckIn() {\n const jobs = this.getAllJobs();\n\n for (const job of jobs) {\n const parsed = parseCronExpression(job.expression);\n const lastRun = this.state.jobs[job.id]?.lastRun;\n // If a job was supposed to run while we were shut down but wasn't we run it now\n if (\n lastRun !== undefined &&\n parsed.hasPrev() &&\n parsed.prev().getTime() > lastRun\n ) {\n await this.executeCronjob(job);\n }\n\n // Try scheduling, will fail if an existing scheduled job is found\n this.schedule(job);\n }\n\n this.#dailyTimer = new Timer(DAILY_TIMEOUT);\n this.#dailyTimer.start(() => {\n this.dailyCheckIn().catch((error) => {\n // TODO: Decide how to handle errors.\n logError(error);\n });\n });\n }\n\n /**\n * Run controller teardown process and unsubscribe from Snap events.\n */\n destroy() {\n super.destroy();\n\n /* eslint-disable @typescript-eslint/unbound-method */\n this.messagingSystem.unsubscribe(\n 'SnapController:snapInstalled',\n this._handleSnapRegisterEvent,\n );\n\n this.messagingSystem.unsubscribe(\n 'SnapController:snapUninstalled',\n this._handleSnapUnregisterEvent,\n );\n\n this.messagingSystem.unsubscribe(\n 'SnapController:snapEnabled',\n this._handleSnapRegisterEvent,\n );\n\n this.messagingSystem.unsubscribe(\n 'SnapController:snapDisabled',\n this._handleSnapUnregisterEvent,\n );\n\n this.messagingSystem.unsubscribe(\n 'SnapController:snapUpdated',\n this._handleEventSnapUpdated,\n );\n /* eslint-enable @typescript-eslint/unbound-method */\n\n this.#snapIds.forEach((snapId) => {\n this.unregister(snapId);\n });\n }\n\n /**\n * Handle events that should cause cronjobs to be registered.\n *\n * @param snap - Basic Snap information.\n */\n private _handleSnapRegisterEvent(snap: TruncatedSnap) {\n this.register(snap.id);\n }\n\n /**\n * Handle events that should cause cronjobs to be unregistered.\n *\n * @param snap - Basic Snap information.\n */\n private _handleSnapUnregisterEvent(snap: TruncatedSnap) {\n this.unregister(snap.id);\n }\n\n /**\n * Handle cron jobs on 'snapUpdated' event.\n *\n * @param snap - Basic Snap information.\n */\n private _handleEventSnapUpdated(snap: TruncatedSnap) {\n this.unregister(snap.id);\n this.register(snap.id);\n }\n}\n"],"names":["DAILY_TIMEOUT","CronjobController","inMilliseconds","Duration","Hour","controllerName","BaseController","getAllJobs","snaps","messagingSystem","call","filteredSnaps","getRunnableSnaps","jobs","map","snap","getSnapJobs","id","flat","filter","job","undefined","snapId","permissions","messenger","permission","SnapEndowments","Cronjob","definitions","getCronjobCaveatJobs","definition","idx","register","forEach","schedule","timers","has","parsed","parseCronExpression","expression","next","now","Date","ms","getTime","timer","Timer","start","executeCronjob","catch","error","logError","delete","state","lastRun","updateJobLastRunState","set","snapIds","origin","handler","HandlerType","OnCronjob","request","unregister","entries","_","jobSnapId","length","get","cancel","jobId","update","dailyCheckIn","hasPrev","prev","dailyTimer","destroy","unsubscribe","_handleSnapRegisterEvent","_handleSnapUnregisterEvent","_handleEventSnapUpdated","constructor","metadata","persist","anonymous","name","Map","bind","subscribe"],"mappings":";;;;;;;;;;;IAgDaA,aAAa;eAAbA;;IA8BAC,iBAAiB;eAAjBA;;;gCA7EkB;4BAWxB;uBACkC;kBAWQ;yBACZ;uBACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBf,MAAMD,gBAAgBE,IAAAA,qBAAc,EAAC,IAAIC,eAAQ,CAACC,IAAI;AAwB7D,MAAMC,iBAAiB;IAWrB,0CAEA,2CAEA,uCAEA,+BAA+B;AAC/B;AAZK,MAAMJ,0BAA0BK,8BAAc;IAoEnD;;;;GAIC,GACD,AAAQC,aAAwB;QAC9B,MAAMC,QAAQ,IAAI,CAACC,eAAe,CAACC,IAAI,CAAC;QACxC,MAAMC,gBAAgBC,IAAAA,kBAAgB,EAACJ;QAEvC,MAAMK,OAAOF,cAAcG,GAAG,CAAC,CAACC,OAAS,IAAI,CAACC,WAAW,CAACD,KAAKE,EAAE;QACjE,4EAA4E;QAC5E,OAAOJ,KAAKK,IAAI,GAAGC,MAAM,CAAC,CAACC,MAAQA,QAAQC;IAC7C;IAEA;;;;;GAKC,GACD,AAAQL,YAAYM,MAAc,EAAyB;QACzD,MAAMC,cAAc,yBAAA,IAAI,EAAEC,YAAUd,IAAI,CACtC,uCACAY;QAGF,MAAMG,aAAaF,aAAa,CAACG,gBAAc,CAACC,OAAO,CAAC;QACxD,MAAMC,cAAcC,IAAAA,6BAAoB,EAACJ;QAEzC,OAAOG,aAAad,IAAI,CAACgB,YAAYC;YACnC,OAAO;gBAAE,GAAGD,UAAU;gBAAEb,IAAI,CAAC,EAAEK,OAAO,CAAC,EAAES,IAAI,CAAC;gBAAET;YAAO;QACzD;IACF;IAEA;;;;;GAKC,GACDU,SAASV,MAAc,EA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AAEsE,SAAS;oBAAMC,WAAW;gBAAM;YAC1C;YACAC,MAAMhF;YACNgD,OAAO;gBACLxC,MAAM,CAAC;gBACP,GAAGwC,KAAK;YACV;QACF;QApBF,gCAAA;;mBAAA,KAAA;;QAEA,gCAAA;;mBAAA,KAAA;;QAEA,gCAAA;;mBAAA,KAAA;;QAGA,gCAAA;;mBAAA,KAAA;;uCAcQlB,SAAS,IAAImD;uCACb7B,UAAU,IAAI6B;uCACd9D,YAAYA;QAElB,IAAI,CAACsD,wBAAwB,GAAG,IAAI,CAACA,wBAAwB,CAACS,IAAI,CAAC,IAAI;QACvE,IAAI,CAACR,0BAA0B,GAC7B,IAAI,CAACA,0BAA0B,CAACQ,IAAI,CAAC,IAAI;QAC3C,IAAI,CAACP,uBAAuB,GAAG,IAAI,CAACA,uBAAuB,CAACO,IAAI,CAAC,IAAI;QAErE,2BAA2B;QAC3B,oDAAoD,GACpD,IAAI,CAAC9E,eAAe,CAAC+E,SAAS,CAC5B,gCACA,IAAI,CAACV,wBAAwB;QAG/B,IAAI,CAACrE,eAAe,CAAC+E,SAAS,CAC5B,kCACA,IAAI,CAACT,0BAA0B;QAGjC,IAAI,CAACtE,eAAe,CAAC+E,SAAS,CAC5B,8BACA,IAAI,CAACV,wBAAwB;QAG/B,IAAI,CAACrE,eAAe,CAAC+E,SAAS,CAC5B,+BACA,IAAI,CAACT,0BAA0B;QAGjC,IAAI,CAACtE,eAAe,CAAC+E,SAAS,CAC5B,8BACA,IAAI,CAACR,uBAAuB;QAE9B,mDAAmD,GAEnD,IAAI,CAACR,YAAY,GAAGvB,KAAK,CAAC,CAACC;YACzBC,IAAAA,oBAAQ,EAACD;QACX;IACF;AAiPF"}
|
|
@@ -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(),
|
|
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
|
-
|
|
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
|
|
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;
|
|
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;
|
|
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
|
|
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
|
|
21
|
-
if (
|
|
22
|
-
|
|
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
|
|
22
|
+
return fn;
|
|
25
23
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
69
|
-
class OffscreenExecutionService extends
|
|
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.
|
|
94
|
-
|
|
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,
|
|
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';\
|
|
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"}
|