From fd307d36a4958872b4e0d0af63d16973b99d61f3 Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Wed, 6 Nov 2024 22:59:23 +0900 Subject: [PATCH] Disclose JsonWebKeyExtended interface from @hpke/core. --- packages/core/mod.ts | 1 + packages/core/test/kemContext.test.ts | 37 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/packages/core/mod.ts b/packages/core/mod.ts index c78baefb8..a943f6f39 100644 --- a/packages/core/mod.ts +++ b/packages/core/mod.ts @@ -1,6 +1,7 @@ export type { AeadEncryptionContext, AeadInterface, + JsonWebKeyExtended, KdfInterface, KemInterface, PreSharedKey, diff --git a/packages/core/test/kemContext.test.ts b/packages/core/test/kemContext.test.ts index 8635b1872..8a7e778f1 100644 --- a/packages/core/test/kemContext.test.ts +++ b/packages/core/test/kemContext.test.ts @@ -2,6 +2,7 @@ import { assertEquals, assertRejects } from "@std/assert"; import { describe, it } from "@std/testing/bdd"; import { isDeno, isDenoV1, loadCrypto } from "@hpke/common"; +import type { JsonWebKeyExtended } from "../mod.ts"; import { DeriveKeyPairError, DeserializeError, @@ -744,6 +745,42 @@ describe("importKey", () => { assertEquals(privKey.usages.length, 0); }); + it("should return a valid private key for DhkemP256HkdfSha256 from JWK with JsonWebKeyExtended interface", async () => { + const kemContext = new DhkemP256HkdfSha256(); + + const jwk: JsonWebKeyExtended = { + kty: "EC", + crv: "P-256", + // kid: "P-256-01", + x: "-eZXC6nV-xgthy8zZMCN8pcYSeE2XfWWqckA2fsxHPc", + y: "BGU5soLgsu_y7GN2I3EPUXS9EZ7Sw0qif-V70JtInFI", + d: "kwibx3gas6Kz1V2fyQHKSnr-ybflddSjN0eOnbmLmyo", + key_ops: ["deriveBits"], + }; + const privKey = await kemContext.importKey("jwk", jwk, false); + + // assert + assertEquals(privKey.usages.length, 1); + assertEquals(privKey.usages[0], "deriveBits"); + }); + + it("should return a valid public key for DhkemP256HkdfSha256 from JWK with JsonWebKeyExtended interface", async () => { + const kemContext = new DhkemP256HkdfSha256(); + + const jwk: JsonWebKeyExtended = { + kty: "EC", + crv: "P-256", + // kid: "P-256-01", + x: "-eZXC6nV-xgthy8zZMCN8pcYSeE2XfWWqckA2fsxHPc", + y: "BGU5soLgsu_y7GN2I3EPUXS9EZ7Sw0qif-V70JtInFI", + key_ops: [], + }; + const privKey = await kemContext.importKey("jwk", jwk, true); + + // assert + assertEquals(privKey.usages.length, 0); + }); + it("should return a valid private key for DhkemP384HkdfSha384 from JWK", async () => { const kemContext = new DhkemP384HkdfSha384();