Skip to content

Commit

Permalink
ed25519 generateKeyPairSync: use publicKey.x instead of privateKey.x
Browse files Browse the repository at this point in the history
Although [RFC7518 6.3.2](https://datatracker.ietf.org/doc/html/rfc7518#section-6.3.2) specifies that private key JWKs must include all the fields present in the public key, this is not the case for the implementation of `node:crypto.generateKeyPairSync` in the deno runtime.

While Node returns the (same) `x` property in both, the `privateKey` and the `publicKey`, Deno only returns the `x` property in `publicKey` (i.e. [no x here](https://github.com/denoland/deno/blob/88490d092751288f736855b2418a4da606a31ce7/ext/node/ops/crypto/keys.rs#L1475)).

This change should not affect any Node users, but would enable the use of libp2p on Deno.
  • Loading branch information
d70-t authored Jan 27, 2025
1 parent 31a15a1 commit a0fc170
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/crypto/src/keys/ed25519/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function generateKey (): Uint8ArrayKeyPair {
// @ts-expect-error node types are missing jwk as a format
const privateKeyRaw = uint8arrayFromString(key.privateKey.d, 'base64url')
// @ts-expect-error node types are missing jwk as a format
const publicKeyRaw = uint8arrayFromString(key.privateKey.x, 'base64url')
const publicKeyRaw = uint8arrayFromString(key.publicKey.x, 'base64url')

return {
privateKey: uint8arrayConcat([privateKeyRaw, publicKeyRaw], privateKeyRaw.byteLength + publicKeyRaw.byteLength),
Expand Down

0 comments on commit a0fc170

Please sign in to comment.