Skip to content

Commit

Permalink
Merge pull request #463 from dajiaji/core-disclose-jwk-extended
Browse files Browse the repository at this point in the history
Disclose JsonWebKeyExtended interface from @hpke/core.
  • Loading branch information
dajiaji authored Nov 6, 2024
2 parents 2347856 + fd307d3 commit df72aac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type {
AeadEncryptionContext,
AeadInterface,
JsonWebKeyExtended,
KdfInterface,
KemInterface,
PreSharedKey,
Expand Down
37 changes: 37 additions & 0 deletions packages/core/test/kemContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit df72aac

Please sign in to comment.