aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Derrick Farris <mr.dcfarris@gmail.com> 2023-02-15 15:48:11 -0600
committerGravatar GitHub <noreply@github.com> 2023-02-15 13:48:11 -0800
commit1c221d33b0def3810c262bd19a4bf8060389dae0 (patch)
tree578a259544ca5b95ab8661fece28559d3ed3b29c
parente67b4e73b57d152c4897acd66cf1347cbdf20444 (diff)
downloadbun-1c221d33b0def3810c262bd19a4bf8060389dae0.tar.gz
bun-1c221d33b0def3810c262bd19a4bf8060389dae0.tar.zst
bun-1c221d33b0def3810c262bd19a4bf8060389dae0.zip
fix(webcrypto): fix ed25519 CryptoKey.algorithm (#2082)
-rw-r--r--src/bun.js/bindings/webcrypto/CryptoKeyOKP.cpp20
-rw-r--r--test/bun.js/web-crypto.test.ts17
2 files changed, 28 insertions, 9 deletions
diff --git a/src/bun.js/bindings/webcrypto/CryptoKeyOKP.cpp b/src/bun.js/bindings/webcrypto/CryptoKeyOKP.cpp
index a4138d8c9..b7dc55018 100644
--- a/src/bun.js/bindings/webcrypto/CryptoKeyOKP.cpp
+++ b/src/bun.js/bindings/webcrypto/CryptoKeyOKP.cpp
@@ -232,17 +232,19 @@ bool CryptoKeyOKP::isValidOKPAlgorithm(CryptoAlgorithmIdentifier algorithm)
auto CryptoKeyOKP::algorithm() const -> KeyAlgorithm
{
- CryptoEcKeyAlgorithm result;
+ CryptoKeyAlgorithm result;
+ // FIXME: This should be set to the actual algorithm name in the case of X25519
result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
- switch (m_curve) {
- case NamedCurve::X25519:
- result.namedCurve = X25519;
- break;
- case NamedCurve::Ed25519:
- result.namedCurve = Ed25519;
- break;
- }
+ // This is commented out because the spec doesn't define the namedCurve field for OKP keys
+ // switch (m_curve) {
+ // case NamedCurve::X25519:
+ // result.namedCurve = X25519;
+ // break;
+ // case NamedCurve::Ed25519:
+ // result.namedCurve = Ed25519;
+ // break;
+ // }
return result;
}
diff --git a/test/bun.js/web-crypto.test.ts b/test/bun.js/web-crypto.test.ts
index d7afd523c..250282b96 100644
--- a/test/bun.js/web-crypto.test.ts
+++ b/test/bun.js/web-crypto.test.ts
@@ -72,3 +72,20 @@ describe("Web Crypto", () => {
expect(isSigValid).toBe(true);
});
});
+
+describe("Ed25519", () => {
+ describe("generateKey", () => {
+ it("should return CryptoKeys without namedCurve in algorithm field", async () => {
+ const { publicKey, privateKey } = (await crypto.subtle.generateKey("Ed25519", true, [
+ "sign",
+ "verify",
+ ])) as CryptoKeyPair;
+ expect(publicKey.algorithm!.name).toBe("Ed25519");
+ // @ts-ignore
+ expect(publicKey.algorithm!.namedCurve).toBe(undefined);
+ expect(privateKey.algorithm!.name).toBe("Ed25519");
+ // @ts-ignore
+ expect(privateKey.algorithm!.namedCurve).toBe(undefined);
+ });
+ });
+});