← Back to Pull requests

TS WebCrypto implementation #8720

Open
unknown opened this pull request with 302 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 20, 2026 06:26 UTC
Author

Port SubtleCrypto and the crypto global (Crypto) to TS behind the TS_WEBCRYPTO autogate. Supersedes #8468.

Only the native crypto stays in C++: SubtleCrypto's resource type exposes the backend ops under the gate, created once at bootstrap as the cryptoBackend pseudo-global, and the entropy comes from utils.fillRandomValues / utils.newRandomUUID. The TS modules load on first use (lazy SubtleCrypto / Crypto globals, as JSG's nested types are), so a Worker that never touches WebCrypto loads none of it. Parity tests pin the C++ behaviour first, then the TS classes pass them unchanged at old and new compat dates.

Medians of 5 runs, C++ and TS alternated on the same machine.

| subtle bench, 64 calls | C++ µs | TypeScript µs | Speedup |
| ---------------------- | ------ | ------------- | ------- |
| digest SHA-256 string | 107.7 | 63.7 | 1.69x |
| digest SHA-256 dict | 112.5 | 66.7 | 1.69x |
| encrypt AES-GCM | 160.8 | 134.9 | 1.19x |
| sign HMAC | 121.4 | 106.5 | 1.14x |
| verify HMAC | 115.0 | 107.1 | 1.07x |
| exportKey raw | 109.8 | 43.9 | 2.50x |
| generateKey AES-GCM | 133.4 | 124.9 | 1.07x |

| global bench, 64 calls | C++ µs | TypeScript µs | Speedup |
| ---------------------- | ------ | ------------- | ------- |
| getRandomValues 16 B | 3.7 | 3.3 | 1.10x |
| crypto.subtle | 3.9 | 0.3 | 11.89x |

Cold start, as the benches report it (Change is the TypeScript time against C++; + is slower). The global bench uses crypto only in its handlers; the subtle bench reads crypto.subtle at the top level, so its startup:worker includes loading the TS SubtleCrypto.

| global bench | C++ µs | TypeScript µs | Change |
| --------------- | ------ | ------------- | ------ |
| startup:isolate | 493.6 | 470.3 | -4.7% |
| startup:script | 1890.6 | 1823.5 | -3.5% |
| startup:worker | 2202.0 | 2107.6 | -4.3% |
| startup:total | 4714.4 | 4542.4 | -3.6% |

| subtle bench | C++ µs | TypeScript µs | Change |
| --------------- | ------ | ------------- | ------ |
| startup:isolate | 495.7 | 514.1 | +3.7% |
| startup:script | 1878.0 | 2025.8 | +7.9% |
| startup:worker | 2208.3 | 2868.9 | +29.9% |
| startup:total | 4794.1 | 5616.2 | +17.1% |

Diff: 302 lines (+226 / -76) across 3 files Reviewer: littledivy Review duration: 15392m
All Vouch review confidence checks passed
Residual risk 0.34 = Change Risk (0.63) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.63 · 302 lines diff across 3 files
0.63
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.342
Sensitive Paths sensitive_paths
0.063
Real PR Conversation Timeline
1 comments
"Review active on #8720"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed sensitive_module
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 63.3% (MEDIUM) · Higher = larger blast radius
63.3%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 33.7% · Safe to merge
33.7%