Skip to content

feat(crypto): implement crypto.scryptSync (#1361)#1405

Merged
proggeramlug merged 1 commit into
mainfrom
feat/crypto-scrypt-1361
May 22, 2026
Merged

feat(crypto): implement crypto.scryptSync (#1361)#1405
proggeramlug merged 1 commit into
mainfrom
feat/crypto-scrypt-1361

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

crypto.scryptSync was rejected by the strict-API gate (#463): the existing js_crypto_scrypt returned a hex string and was never wired to the crypto namespace.

Implementation

  • New js_crypto_scrypt_bytes returns a Buffer (matching Node) and reads inputs via bytes_from_ptr, so string and Buffer password/salt both work.
  • Optional cost params are read from the options object in the runtime: N/cost, r/blockSize, p/parallelization, defaulting to Node's N=16384, r=8, p=1.
  • HIR already types scryptSync as Uint8Array, so scryptSync(...).toString('hex') and [i] indexing take the buffer path.
  • Wired through codegen (expr/calls.rs), the FFI decls, and the API manifest (+ regenerated docs).

Validation

Byte-for-byte vs node --experimental-strip-types:

  • default 32-byte and 64-byte keys
  • .length and byte indexing (buf[0])
  • custom { N: 1024, r: 8, p: 1 } options
  • Buffer password/salt inputs

Note

This implements the synchronous form. The callback-style async crypto.scrypt(pw, salt, keylen, cb) is not included — Perry has no native→JS callback path for KDFs today (the existing "async" pbkdf2 is likewise sync-returning), so it's a separate follow-up.

Closes #1361

scryptSync was rejected by the strict-API gate (#463) — the existing
js_crypto_scrypt returned a hex string and was never wired to the crypto
namespace. Add js_crypto_scrypt_bytes, which returns a Buffer (matching
Node) and reads inputs via bytes_from_ptr so string and Buffer
password/salt both work.

Optional cost parameters are read from the options object in the runtime:
N/cost, r/blockSize, p/parallelization, defaulting to Node's N=16384,
r=8, p=1. HIR already types scryptSync as Uint8Array, so
scryptSync(...).toString('hex') and indexing take the buffer path.

Wired through codegen (expr/calls.rs), the FFI decls, and the API
manifest (+ regenerated docs).

Verified byte-for-byte against `node --experimental-strip-types`:
default 32/64-byte keys, .length, byte indexing, custom { N, r, p }
options, and Buffer inputs.

Closes #1361
@proggeramlug proggeramlug merged commit d33e39e into main May 22, 2026
9 checks passed
@proggeramlug proggeramlug deleted the feat/crypto-scrypt-1361 branch May 22, 2026 14:32
proggeramlug added a commit that referenced this pull request May 22, 2026
…sweep (#1414)

Rolls up 26 PRs that merged to main post-v0.5.1023 without version
bumps:

- node:crypto gap-fixes (#1386 #1393 #1394 #1402 #1405): randomInt,
  timingSafeEqual, getHashes/getCiphers, sha224/sha384, base64 digest,
  Buffer hash input, no-arg digest() → Buffer, pbkdf2Sync digest arg,
  scryptSync.
- node:perf_hooks (#1321 + #1328 #1342 coverage): performance + User
  Timing + PerformanceObserver native impl, granular node-suite +
  edge-case coverage.
- #1090 GC checkpoint runtime work (#1324).
- #1311 geisterhand on iOS (#1316 #1383 #1384 #1385).
- #1312 process.env.X (unset) is nullish undefined (#1314).
- #1319 thread-safety hardening for cross-thread runtime statics.
- #1322 exact-head GC evidence packet.
- #1323 wasm timers dispatch through mem_call bridge (#1329).
- #1317 node:timers/promises shadow-segfault fix (#1326).
- #1330 node:process suite (#1331).
- #1292 bcrypt.hash() returns String (#1307).
- #1293 fastify .json()/.body external-fastify dispatch (#1308).
- #1296 app pattern performance gaps.
- #1297 diagnostics_channel parity.
- #1301 iOS App Groups capability (#1313).
- #1318 #1325 os/methods/modern-methods static dispatch.
- #1315 expanded Node parity test coverage.
- #1382 ui-ios stdlib pump for async fetch.
- #1392 ui-wasm reactive state + setText (#1404).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node:crypto — implement crypto.scryptSync / scrypt

1 participant