Skip to content

node:crypto: add implemented helper exports to the API manifest #2694

@andrewtdiz

Description

@andrewtdiz

Summary

Several node:crypto exports are already recognized as callable by Perry's runtime/codegen, and docs/runtime-parity.md marks them covered, but they are missing from perry-api-manifest and generated API declarations/reference docs.

This is a manifest/declaration coherence gap: strict native-member checks and declaration-guided users can miss or reject APIs that the runtime already exposes.

Node behavior

On local Node v25.9.0, the following are enumerable node:crypto exports with function/class shape:

const crypto = require("node:crypto");

for (const name of [
  "Hash", "Hmac", "Sign", "Verify",
  "checkPrime", "checkPrimeSync",
  "generateKey", "generateKeySync",
  "generateKeyPair", "generateKeyPairSync",
  "generatePrime", "generatePrimeSync",
  "getCipherInfo", "hkdf", "scrypt",
  "secureHeapUsed", "setFips",
]) {
  console.log(name, typeof crypto[name], crypto[name].length);
}

Representative Node results:

  • Hash, Hmac, Sign, Verify are function-valued constructor exports.
  • checkPrime / checkPrimeSync, generateKey*, generateKeyPair*, generatePrime*, getCipherInfo, hkdf, scrypt, secureHeapUsed, and setFips are enumerable functions.

Current Perry evidence

Current origin/main has implementation/coverage evidence for this cluster:

  • crates/perry-runtime/src/object/native_module.rs::is_native_module_callable_export() lists the names above as callable crypto exports.
  • crates/perry-codegen/src/expr/calls.rs has direct lowering for:
    • legacy crypto.Hash / crypto.Hmac / crypto.Sign / crypto.Verify call paths
    • generateKey, generateKeySync, generateKeyPair, generateKeyPairSync
    • generatePrime, generatePrimeSync, checkPrime, checkPrimeSync
    • getCipherInfo, hkdf, scrypt, secureHeapUsed, and setFips
  • crates/perry-stdlib/src/crypto/ contains backing implementations such as js_crypto_generate_key_sync, js_crypto_generate_key_async, js_crypto_generate_key_pair_async, js_crypto_generate_prime_sync, js_crypto_check_prime_sync, js_crypto_hkdf_async_alg, js_crypto_scrypt_async, js_crypto_get_cipher_info, and js_crypto_secure_heap_used.
  • docs/runtime-parity.md marks these rows covered in the node:crypto section.

But the manifest/declarations omit them:

  • crates/perry-api-manifest/src/entries.rs has entries for adjacent crypto APIs such as createHash, createHmac, pbkdf2, pbkdf2Sync, scryptSync, hkdfSync, generateKeyPairSync, and cipher/sign helpers, but omits much of the callable cluster above.
  • docs/api/perry.d.ts does not declare these exports for module "crypto".
  • docs/src/api/reference.md does not list these exports.

Suggested test surface

Add manifest/API regression coverage that checks:

  • module_has_symbol("crypto", name) succeeds for the implemented callable cluster above.
  • docs/api/perry.d.ts includes function/class declarations for these names.
  • Existing granular crypto fixtures for key generation, KDFs, primes, cipher info, and legacy constructor aliases remain covered.

Scope / non-goals

This is scoped to manifest/declaration/reference-doc coherence for APIs already recognized by Perry runtime/codegen. It excludes crypto.randomFill, which is tracked separately in #2691, argument validation (#2013), WebCrypto/global constructor work (#2576), KeyObject gaps (#2565), Argon2/encapsulation APIs (#2517), and behavior improvements for algorithms that are already tracked elsewhere.

No local target/release/perry binary was available for a compiled runtime repro; this issue is based on Node probes plus current origin/main source inspection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions