refactor: Offload message signing to Web Worker#3376
Open
mondoreale wants to merge 15 commits intoNET-1663-validationfrom
Open
refactor: Offload message signing to Web Worker#3376mondoreale wants to merge 15 commits intoNET-1663-validationfrom
mondoreale wants to merge 15 commits intoNET-1663-validationfrom
Conversation
…oncerns - SigningService: Container-scoped service that owns the signing worker, provides sign() method, and handles worker lifecycle (lazy init, cleanup) - MessageSigner: Now injects SigningService instead of managing worker directly This decouples the worker management from message signing logic. Each StreamrClient gets its own SigningService instance, with the worker destroyed automatically when the client is destroyed. Test utilities updated with createMessageSigner() helper that uses a mock SigningService (no worker) for faster, simpler tests.
This makes the fake env create clients that share the same signing worker.
Firing up them SigningService instances takes a while in tests.
Transfer signature buffer back to main thread instead of copying, improving performance for large messages.
13dac37 to
3209476
Compare
juslesan
approved these changes
Feb 4, 2026
| } | ||
|
|
||
| async sign(request: SigningRequest): Promise<SigningResult> { | ||
| return this.getWorkerApi().createSignature(request) |
Contributor
There was a problem hiding this comment.
I'm wondering if it would make more sense to just create the worker in the constructor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Offload message signing to a Web Worker to avoid blocking the main thread during cryptographic operations. This mirrors the existing signature validation workerization pattern.
Changes
SigningServicefromMessageSignerfor clearer separation of concernsSigningWorkerandsigningUtilsfor worker-based signing_nodejs,_browser,_jest,_karma)IdentitywithgetPrivateKey()method to detect workerizable identitiesMessageSignerto use worker when identity provides a private key, falling back to direct signing for ERC-1271WORKERSregistryDestroySignalandSigningServicefrom SDK for external usagecreateMockSigningService()andcreateMessageSigner()test utilitiesSigningServiceinFakeEnvironmentfor test compatibilityLimitations and future improvements
EthereumProviderIdentity) cannot be workerized as they require browser UI interactionNote
Medium Risk
Touches core message signing flow and adds worker lifecycle/build configuration; regressions would affect publishing/signature generation across environments.
Overview
Moves message signing onto a dedicated worker thread via new
SigningService/SigningWorker, withMessageSignerchoosing the worker path when theIdentityexposes a private key (and falling back to direct signing forERC_1271).Adds platform-specific
createSigningWorkerfactories and updates build/test tooling (Rollup worker registry + inlined browser worker bundles, Jest/Karma module mapping, and increased timeouts). Tests are refactored to use new helpers (createMessageSigner/mock signing service),FakeEnvironmentnow registers a sharedSigningService, and the SDK exportsSigningServiceandDestroySignal.Written by Cursor Bugbot for commit 3209476. This will update automatically on new commits. Configure here.