node/lib/internal/crypto
Filip Skokan 1c16b45d35
lib: refactor internal webidl converters
Rework lib/internal/webidl.js into a documented shared converter module
that follows the Web IDL conversion algorithms more closely.

Improvements:
- Add documented converters and helper factories for primitive values,
  dictionaries, enums, sequences, interfaces, required arguments,
  integers, `Uint8Array`, and `BufferSource`.
- Move WebCrypto onto the shared converters, while keeping compatibility
  wrappers for its existing `BufferSource` and `BigInteger` behavior.
- Use shared converters from Blob, Performance, Web Locks, and
  structured clone option handling.
- Add benchmarks for `ConvertToInt` and WebCrypto Web IDL converter hot
  paths.
- Add focused tests for core converters, WebCrypto converters, integer
  conversion, and buffer source behavior.

Fixes:
- Make the shared `BufferSource` and `Uint8Array` converters reject
  resizable `ArrayBuffer` and growable `SharedArrayBuffer` backing
  stores unless explicitly allowed. WebCrypto preserves its legacy
  resizable backing-store behavior through compatibility wrappers until
  a semver-major follow-up can opt in to the stricter behavior.
- Use Web IDL `ToNumber` and `ToString` behavior for BigInt, Symbol, and
  object primitive conversion.
- Use exact BigInt modulo for 64-bit `ConvertToInt` wrapping and
  document the final Number approximation behavior.
- Normalize mathematical modulo results to `+0` where Web IDL requires
  it.
- Process inherited dictionaries in least-derived to most-derived order,
  sorting members only within each dictionary level.
- Use `IteratorComplete` truthiness for sequence conversion.
- Cover detached buffers, resizable-backed views, growable-backed views,
  cross-realm buffer sources, mutation-after-call behavior, inherited
  dictionary member order, and sequence iterator completion behavior.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62979
Backport-PR-URL: https://github.com/nodejs/node/pull/63563
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-06-23 01:06:46 +01:00
..
aes.js crypto: add WebCrypto CryptoJob mode 2026-06-23 01:06:42 +01:00
argon2.js crypto: pass CryptoKey handles to KDF jobs 2026-06-23 01:06:44 +01:00
certificate.js
cfrg.js crypto: add WebCrypto CryptoJob mode 2026-06-23 01:06:42 +01:00
chacha20_poly1305.js crypto: add WebCrypto CryptoJob mode 2026-06-23 01:06:42 +01:00
cipher.js crypto: align key argument names in docs and error messages 2026-06-23 01:06:35 +01:00
diffiehellman.js crypto: harden WebCrypto against prototype pollution 2026-06-23 01:06:45 +01:00
ec.js crypto: add WebCrypto CryptoJob mode 2026-06-23 01:06:42 +01:00
hash.js crypto: add WebCrypto CryptoJob mode 2026-06-23 01:06:42 +01:00
hashnames.js crypto: add SHA-3 Web Cryptography digest algorithms 2025-08-21 19:01:08 +02:00
hkdf.js crypto: pass CryptoKey handles to KDF jobs 2026-06-23 01:06:44 +01:00
kem.js crypto: unify asymmetric key import through KeyObjectHandle::Init 2026-06-23 01:06:34 +01:00
keygen.js crypto: align key argument names in docs and error messages 2026-06-23 01:06:35 +01:00
keys.js src: add BoringSSL EVP enumeration fallback 2026-06-23 01:06:40 +01:00
mac.js crypto: add WebCrypto CryptoJob mode 2026-06-23 01:06:42 +01:00
ml_dsa.js crypto: add WebCrypto CryptoJob mode 2026-06-23 01:06:42 +01:00
ml_kem.js crypto: add WebCrypto CryptoJob mode 2026-06-23 01:06:42 +01:00
pbkdf2.js crypto: pass CryptoKey handles to KDF jobs 2026-06-23 01:06:44 +01:00
random.js crypto: implement randomUUIDv7() 2026-05-07 15:41:33 +02:00
rsa.js crypto: add WebCrypto CryptoJob mode 2026-06-23 01:06:42 +01:00
scrypt.js crypto: coerce -0 keylen to +0 in pbkdf2 and scrypt 2026-06-18 21:12:34 +01:00
sig.js crypto: accept key data in crypto.diffieHellman() and cleanup DH jobs 2026-06-23 01:06:35 +01:00
util.js crypto: harden WebCrypto against prototype pollution 2026-06-23 01:06:45 +01:00
webcrypto.js crypto: harden WebCrypto against prototype pollution 2026-06-23 01:06:45 +01:00
webcrypto_util.js src: decouple KeyObject and CryptoKey and move CryptoKey to src 2026-06-23 01:06:38 +01:00
webidl.js lib: refactor internal webidl converters 2026-06-23 01:06:46 +01:00
x509.js crypto: harden KeyObject internal slots 2026-06-23 01:06:39 +01:00