0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

fix(ext/node): fix missing privateKey.x in curve25519 JWK (#27990)

Fixes https://github.com/denoland/deno/issues/27972
This commit is contained in:
Divy Srivastava 2025-02-06 12:11:42 +05:30 committed by GitHub
parent 28faaee772
commit a401a79c75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View file

@ -1463,19 +1463,28 @@ impl AsymmetricPrivateKey {
AsymmetricPrivateKey::X25519(static_secret) => {
let bytes = static_secret.to_bytes();
let AsymmetricPublicKey::X25519(x) = self.to_public_key() else {
unreachable!();
};
Ok(deno_core::serde_json::json!({
"kty": "OKP",
"crv": "X25519",
"x": bytes_to_b64(x.as_bytes()),
"d": bytes_to_b64(&bytes),
"kty": "OKP",
}))
}
AsymmetricPrivateKey::Ed25519(key) => {
let bytes = key.to_bytes();
let AsymmetricPublicKey::Ed25519(x) = self.to_public_key() else {
unreachable!();
};
Ok(deno_core::serde_json::json!({
"kty": "OKP",
"crv": "Ed25519",
"x": bytes_to_b64(x.as_bytes()),
"d": bytes_to_b64(&bytes),
"kty": "OKP",
}))
}
_ => Err(AsymmetricPrivateKeyJwkError::JwkExportNotImplementedForKeyType),

View file

@ -755,3 +755,16 @@ Deno.test("X509Certificate checkHost", function () {
assertEquals(cert.checkHost("www.google.com"), undefined);
assertEquals(cert.checkHost("agent1"), "agent1");
});
// https://github.com/denoland/deno/issues/27972
Deno.test("curve25519 generate valid private jwk", function () {
const { publicKey, privateKey } = generateKeyPairSync("ed25519", {
publicKeyEncoding: { format: "jwk" },
privateKeyEncoding: { format: "jwk" },
});
// @ts-ignore @types/node broken
assert(!publicKey.d);
// @ts-ignore @types/node broken
assert(privateKey.d);
});