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:
parent
28faaee772
commit
a401a79c75
2 changed files with 24 additions and 2 deletions
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue