Skip to content

fix: return KeyObjects from generateKeyPairSync for Ed/X curves#971

Merged
boorad merged 3 commits intomainfrom
fix/ed25519-keyobject-support
Mar 23, 2026
Merged

fix: return KeyObjects from generateKeyPairSync for Ed/X curves#971
boorad merged 3 commits intomainfrom
fix/ed25519-keyobject-support

Conversation

@boorad
Copy link
Copy Markdown
Collaborator

@boorad boorad commented Mar 22, 2026

Summary

generateKeyPairSync and generateKeyPair for Ed25519/Ed448/X25519/X448 curves were returning raw encoded bytes instead of KeyObject instances when no encoding options were specified. Node.js returns KeyObject by default — this PR aligns with that behavior.

Changes

  • Always generate DER internally, then wrap in KeyObject on the JS side via new ed_createKeyObjects helper
  • Return KeyObject instances by default; only export to PEM/DER when encoding options are explicitly provided
  • Guard undefined format values in ed_formatKeyPairOutput to prevent accidental raw export
  • Deduplicate KeyObject creation across ed_formatKeyPairOutput and both WebCrypto generators
  • Add 15 tests covering all 4 curve types (ed25519, ed448, x25519, x448) — sync, async, PEM/DER encoding, and round-trip export/recreate
  • Add example/.ruby-version to suppress local Ruby version warnings

Testing

Tests run in the React Native example app. The new test suite is registered in useTestsList.ts under keys.edKeyObject.

Fixes #969
Fixes #970

boorad added 2 commits March 22, 2026 19:20
…#970)

Rewrite ed_generateKeyPair to always request DER-encoded keys from
native (SPKI for public, PKCS8 for private), then wrap them in
KeyObjects via KeyObject.createKeyObject. When no encoding is specified
(format = -1), return the KeyObject directly. When encoding is
specified, export from the KeyObject to the requested format.

This follows the same pattern used by RSA key generation
(rsa_formatKeyPairOutput) and fixes both the sync and async paths.

Also adds comprehensive tests for Ed25519/Ed448/X25519/X448 KeyObject
support including round-trip export/recreate verification.
Extract ed_createKeyObjects helper to deduplicate KeyObject creation
across ed_formatKeyPairOutput and both WebCrypto generators. Guard
undefined format values in ed_formatKeyPairOutput, simplify test type
casts, and wrap Buffer.compare args with Buffer.from for type safety.
@boorad boorad self-assigned this Mar 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 22, 2026

🤖 End-to-End Test Results - iOS

Status: ✅ Passed
Platform: iOS
Run: 23415461988

📸 Final Test Screenshot

Maestro Test Results - ios

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 22, 2026

🤖 End-to-End Test Results - Android

Status: ✅ Passed
Platform: Android
Run: 23415461976

📸 Final Test Screenshot

Maestro Test Results - android

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

Ed.diffieHellman() was passing KeyObject instances directly to toAB()
which can't convert them. Now extracts raw bytes via handle.exportKey().
Also updates deriveBits tests to use KeyObject directly from
generateKeyPairSync instead of manually wrapping ArrayBuffer.
@boorad boorad merged commit 193e4c0 into main Mar 23, 2026
7 checks passed
@boorad boorad deleted the fix/ed25519-keyobject-support branch March 23, 2026 00:28
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.

🐛 create PrivateKey error, check also createPublicKey generateKeyPairSync returns bad data - also doc is wrong

1 participant