Skip to content

Conversation

@mondoreale
Copy link
Contributor

@mondoreale mondoreale commented Jan 29, 2026

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

  • Extract SigningService from MessageSigner for clearer separation of concerns
  • Add SigningWorker and signingUtils for worker-based signing
  • Add platform-specific worker factories (_nodejs, _browser, _jest, _karma)
  • Extend Identity with getPrivateKey() method to detect workerizable identities
  • Update MessageSigner to use worker when identity provides a private key, falling back to direct signing for ERC-1271
  • Consolidate worker bundling in rollup config with declarative WORKERS registry
  • Inline browser worker dependencies to avoid chunk copying issues
  • Export DestroySignal and SigningService from SDK for external usage
  • Add createMockSigningService() and createMessageSigner() test utilities
  • Register SigningService in FakeEnvironment for test compatibility

Limitations and future improvements

  • External wallet identities (EthereumProviderIdentity) cannot be workerized as they require browser UI interaction
  • Worker startup has minor overhead; could consider worker pooling for high-frequency signing scenarios

Note

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, with MessageSigner choosing the worker path when the Identity exposes a private key (and falling back to direct signing for ERC_1271).

Adds platform-specific createSigningWorker factories 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), FakeEnvironment now registers a shared SigningService, and the SDK exports SigningService and DestroySignal.

Written by Cursor Bugbot for commit 3209476. This will update automatically on new commits. Configure here.

@github-actions github-actions bot added the sdk label Jan 29, 2026
@mondoreale mondoreale marked this pull request as ready for review January 29, 2026 15:55
@mondoreale mondoreale marked this pull request as draft January 29, 2026 16:11
…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.
@github-actions github-actions bot added the cli-tools Related to CLI Tools Package label Jan 29, 2026
This makes the fake env create clients that share the same signing worker.
Firing up them SigningService instances takes a while in tests.
@mondoreale mondoreale marked this pull request as ready for review January 29, 2026 20:32
Transfer signature buffer back to main thread instead of copying, improving performance for large messages.
@mondoreale mondoreale force-pushed the worker-based-signing branch from 13dac37 to 3209476 Compare January 29, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli-tools Related to CLI Tools Package sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants