feat(crypto): add the Web Cryptography module - #44
Merged
Merged
Conversation
`globalThis.crypto` with `getRandomValues`, `randomUUID` and a `subtle` that covers what a worker actually reaches for: SHA-1 through SHA-512 digests, HMAC sign and verify, AES-GCM and AES-CBC, PBKDF2 and HKDF derivation, and `raw` and `jwk` key import and export. The names are the spec's, so what a developer already knows about `crypto.subtle` transfers unchanged and MDN is the documentation. Errors carry the `DOMException` names the spec observes -- `NotSupportedError`, `OperationError`, `InvalidAccessError` -- alongside Rong's own machine-readable codes. Asymmetric algorithms, AES-CTR, AES-KW and key wrapping are absent. They are recognized by name and rejected with a `NotSupportedError` that says which algorithm it was, so a caller learns what is missing instead of watching a lookup fail. Every algorithm is checked from JavaScript against published RFC and NIST vectors, through the same API a worker sees.
The original suite checked RFC/NIST vectors and happy-path round-trips, so JWK `use`, HMAC import `length`, HKDF `info`, DataView, deriveBits(0), and encrypt of a non-AES algorithm never ran. Reject JWK members of the wrong type and a mismatched `use`, honor HMAC import length, require HKDF info, accept DataView, return empty bits for length 0, and throw NotSupportedError for encrypt/decrypt of algorithms that do not support those operations. Cache CryptoKey.algorithm/usages, run PBKDF2 off the isolate thread, and treat a non-96-bit AES-GCM IV as unimplemented rather than malformed.
Typegen discovers JS-facing crates from `#[js_class]` and fails `--check` when a new module is missing from the policy. Mark crypto as curated like the other Web globals; the published surface stays in the logic-web profile.
butterflyfish
force-pushed
the
feat/webcrypto
branch
from
September 11, 2026 10:07
c615d9f to
cc73736
Compare
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.
What
modules/rong_cryptoinstallsglobalThis.crypto:getRandomValues,randomUUID, and asubtlecovering what a worker actually reaches for.rawandjwk(kty: "oct")Enabled through
rong_modulesas thecryptofeature, and inall.Naming
The JavaScript surface is the spec's, down to
importKeyandgetRandomValues, so what a developer already knows aboutcrypto.subtletransfers unchanged and MDN is the documentation. Errors carry theDOMExceptionnames the spec observes —NotSupportedError,OperationError,InvalidAccessError,DataError— alongside Rong's machine-readable codes.The TypeScript profile follows the same rule:
AlgorithmIdentifierandBufferSourceare the names every Web API signature uses, and the rest oflogic-web.d.tsalready declaresTextEncoder,URLandDOMExceptionunprefixed.What is not here
Asymmetric algorithms (RSASSA-PKCS1-v1_5, RSA-PSS, RSA-OAEP, ECDSA, ECDH, Ed25519, X25519), AES-CTR, AES-KW, and key wrapping. They are recognized by name and rejected with a
NotSupportedErrornaming the algorithm, so a caller learns what is missing rather than watching a lookup fail.Tests
Every algorithm is checked against published RFC and NIST vectors — RFC 2202, RFC 4231, RFC 5869, RFC 6070, RFC 7914, and the McGrew-Viega AES-GCM vectors — both in Rust and from JavaScript through the same API a worker sees.
cargo test -p rong_crypto --features quickjs— 18 passed, including the JavaScript conformance suite.tscon the type profile is clean.Note
cargo clippy -p rong_moduleswith no module feature selected fails on a pre-existingdead_codelint forModuleDescriptor::new. It reproduces onmasterwithout this branch and is left alone here.