-
Notifications
You must be signed in to change notification settings - Fork 43
feat(sdk): [NET-1663] Signature validation in worker thread #3308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
juslesan
wants to merge
33
commits into
main
Choose a base branch
from
NET-1663-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
7078919
Draft: validation in worker thread
juslesan 9bf8431
package-lock
juslesan 19ce5d7
DestroySignal to tests
juslesan c4586b8
eslint
juslesan c2a74ed
npm run version
juslesan 2dd5dd4
refactors
juslesan d6481e2
fix issue with StreamMessage passing
juslesan 46a9c6f
revert
juslesan d31d1c1
nodejs workers for validation
juslesan 360dfdc
most unit tests work now
juslesan 494cc21
SignatureValidationData
juslesan 4741a17
esöint
juslesan 49ba698
increase tiemout
juslesan cf1fc06
Merge branch 'main' into NET-1663-validation
juslesan 8eef444
process.exit(0) after a comand is completed to avoid hanging because …
juslesan 642d7a1
Merge branch 'main' into NET-1663-validation
juslesan bde83db
destroy ServerSignatureValidation worker
juslesan 558ee87
fix resend.ts
juslesan 72632f4
Merge remote-tracking branch 'origin/main' into NET-1663-validation
mondoreale 31dbc7d
Install `web-worker`
mondoreale cce4c35
Refactor signature validation – use `web-worker` to unify worker code…
mondoreale 364baf1
Rename `signatureValidation` to `signatureValidationUtils`
mondoreale 5fb810b
Fix filenames
mondoreale 9f2ab70
Use named exports from `comlink`
mondoreale a7c4f0f
Custom expose for nodejs (using Comlink's `nodeAdapter`)
mondoreale 21b3c6e
Release proxy
mondoreale 53a1173
Merge remote-tracking branch 'origin/main' into NET-1663-validation-2
mondoreale c45177f
Fix signature validation tests
mondoreale 856a012
Fix SDK's browser tests
mondoreale 6853ccd
remove process.exit
juslesan ae45762
keep the process.exit
juslesan 7e03be6
Merge remote-tracking branch 'origin/main' into NET-1663-validation
mondoreale 738a126
Add comment explaining `servedFiles` config in SDK's Karma
mondoreale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export { createKarmaConfig } from './createKarmaConfig' | ||
| export type { KarmaConfigOptions } from './createKarmaConfig' | ||
| export { createWebpackConfig } from './createWebpackConfig' |
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
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
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
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
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
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
11 changes: 11 additions & 0 deletions
11
packages/sdk/src/_browser/createSignatureValidationWorker.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * Browser-specific signature validation worker factory. | ||
| */ | ||
| import Worker from 'web-worker' | ||
|
|
||
| export function createSignatureValidationWorker(): InstanceType<typeof Worker> { | ||
| return new Worker( | ||
| new URL('./workers/SignatureValidationWorker.browser.mjs', import.meta.url), | ||
| { type: 'module' } | ||
| ) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * Jest-specific signature validation worker factory. | ||
| */ | ||
| import Worker from 'web-worker' | ||
|
|
||
| export function createSignatureValidationWorker(): InstanceType<typeof Worker> { | ||
| return new Worker( | ||
| new URL('../../dist/workers/SignatureValidationWorker.node.mjs', import.meta.url), | ||
| { type: 'module' } | ||
| ) | ||
| } |
11 changes: 11 additions & 0 deletions
11
packages/sdk/src/_karma/createSignatureValidationWorker.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * Browser-specific signature validation worker factory. | ||
| */ | ||
| import Worker from 'web-worker' | ||
|
|
||
| export function createSignatureValidationWorker(): InstanceType<typeof Worker> { | ||
| return new Worker( | ||
| new URL('../../dist/workers/SignatureValidationWorker.browser.mjs', import.meta.url), | ||
| { type: 'module' } | ||
| ) | ||
| } |
11 changes: 11 additions & 0 deletions
11
packages/sdk/src/_nodejs/createSignatureValidationWorker.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * Node.js-specific signature validation worker factory. | ||
| */ | ||
| import Worker from 'web-worker' | ||
|
|
||
| export function createSignatureValidationWorker(): InstanceType<typeof Worker> { | ||
| return new Worker( | ||
| new URL('./workers/SignatureValidationWorker.node.mjs', import.meta.url), | ||
| { type: 'module' } | ||
| ) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * Unified signature validation using Web Worker. | ||
| * This offloads CPU-intensive cryptographic operations to a separate thread. | ||
| * Works in both browser and Node.js environments via platform-specific config. | ||
| */ | ||
| import { wrap, releaseProxy, type Remote } from 'comlink' | ||
| import { createSignatureValidationWorker } from '@/createSignatureValidationWorker' | ||
| import { SignatureValidationResult, toSignatureValidationData } from './signatureValidationUtils' | ||
| import type { SignatureValidationWorkerApi } from './SignatureValidationWorker' | ||
| import { StreamMessage } from '../protocol/StreamMessage' | ||
|
|
||
| export class SignatureValidation { | ||
| private worker: ReturnType<typeof createSignatureValidationWorker> | ||
| private workerApi: Remote<SignatureValidationWorkerApi> | ||
|
|
||
| constructor() { | ||
| this.worker = createSignatureValidationWorker() | ||
| this.workerApi = wrap<SignatureValidationWorkerApi>(this.worker) | ||
| } | ||
|
|
||
| async validateSignature(message: StreamMessage): Promise<SignatureValidationResult> { | ||
| // Convert class instance to plain serializable data before sending to worker | ||
| const data = toSignatureValidationData(message) | ||
| return this.workerApi.validateSignature(data) | ||
| } | ||
|
|
||
| destroy(): void { | ||
| this.workerApi[releaseProxy]() | ||
| this.worker.terminate() | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { expose } from 'comlink' | ||
| import { | ||
| validateSignatureData, | ||
| SignatureValidationResult, | ||
| SignatureValidationData, | ||
| } from './signatureValidationUtils' | ||
|
|
||
| const workerApi = { | ||
| validateSignature: async ( | ||
| data: SignatureValidationData | ||
| ): Promise<SignatureValidationResult> => { | ||
| return validateSignatureData(data) | ||
| }, | ||
| } | ||
|
|
||
| export type SignatureValidationWorkerApi = typeof workerApi | ||
|
|
||
| expose(workerApi) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent CLI output between subscribe and resend modes
Medium Severity
Subscribe mode logs the full
Messageobject viaJSON.stringify(message)(line 24), but resend mode now logs onlymessage.contentviaJSON.stringify(message.content). This creates inconsistent output where subscribe mode shows all message metadata (streamId, timestamp, publisherId, etc.) while resend mode shows only the payload content.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juslesan, thoughts on this?