fix: return KeyObjects from generateKeyPairSync for Ed/X curves#971
Merged
fix: return KeyObjects from generateKeyPairSync for Ed/X curves#971
Conversation
…#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.
Contributor
🤖 End-to-End Test Results - iOSStatus: ✅ Passed 📸 Final Test ScreenshotScreenshot automatically captured from End-to-End tests and will expire in 30 days This comment is automatically updated on each test run. |
Contributor
🤖 End-to-End Test Results - AndroidStatus: ✅ Passed 📸 Final Test ScreenshotScreenshot 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.
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.


Summary
generateKeyPairSyncandgenerateKeyPairfor Ed25519/Ed448/X25519/X448 curves were returning raw encoded bytes instead ofKeyObjectinstances when no encoding options were specified. Node.js returnsKeyObjectby default — this PR aligns with that behavior.Changes
KeyObjecton the JS side via newed_createKeyObjectshelperKeyObjectinstances by default; only export to PEM/DER when encoding options are explicitly providedundefinedformat values ined_formatKeyPairOutputto prevent accidental raw exported_formatKeyPairOutputand both WebCrypto generatorsexample/.ruby-versionto suppress local Ruby version warningsTesting
Tests run in the React Native example app. The new test suite is registered in
useTestsList.tsunderkeys.edKeyObject.Fixes #969
Fixes #970