From 7ae6963471a88cb964f5f18cd2f629e5b3fa756c Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 14:48:54 +0900 Subject: [PATCH] Move HkdfSha*Native to @hpke/common. --- packages/common/mod.ts | 6 ++++++ packages/{core => common}/src/kdfs/hkdf.ts | 7 +++++-- packages/core/src/aeads/aesGcm.ts | 7 ++----- packages/core/src/kems/dhkemNative.ts | 7 ++++--- packages/core/src/native.ts | 5 +++-- packages/dhkem-secp256k1/deno.json | 2 +- packages/dhkem-x25519/deno.json | 2 +- packages/dhkem-x25519/src/hkdfSha256.ts | 2 +- packages/dhkem-x448/deno.json | 2 +- packages/dhkem-x448/src/hkdfSha512.ts | 2 +- packages/hybridkem-x25519-kyber768/deno.json | 2 +- 11 files changed, 26 insertions(+), 18 deletions(-) rename packages/{core => common}/src/kdfs/hkdf.ts (95%) diff --git a/packages/common/mod.ts b/packages/common/mod.ts index b15bf9d77..8bf6c7204 100644 --- a/packages/common/mod.ts +++ b/packages/common/mod.ts @@ -17,6 +17,12 @@ export { Ec } from "./src/kems/dhkemPrimitives/ec.ts"; export { Hybridkem } from "./src/kems/hybridkem.ts"; export { XCryptoKey } from "./src/xCryptoKey.ts"; +export { + HkdfSha256Native, + HkdfSha384Native, + HkdfSha512Native, +} from "./src/kdfs/hkdf.ts"; + export { AEAD_USAGES } from "./src/interfaces/aeadEncryptionContext.ts"; export { LABEL_DKP_PRK, LABEL_SK } from "./src/interfaces/dhkemPrimitives.ts"; export { SUITE_ID_HEADER_KEM } from "./src/interfaces/kemInterface.ts"; diff --git a/packages/core/src/kdfs/hkdf.ts b/packages/common/src/kdfs/hkdf.ts similarity index 95% rename from packages/core/src/kdfs/hkdf.ts rename to packages/common/src/kdfs/hkdf.ts index c755eddb7..5f580f1ae 100644 --- a/packages/core/src/kdfs/hkdf.ts +++ b/packages/common/src/kdfs/hkdf.ts @@ -1,6 +1,9 @@ -import type { KdfInterface } from "@hpke/common"; +import type { KdfInterface } from "../interfaces/kdfInterface.ts"; -import { EMPTY, InvalidParamError, KdfId, NativeAlgorithm } from "@hpke/common"; +import { EMPTY } from "../consts.ts"; +import { InvalidParamError } from "../errors.ts"; +import { KdfId } from "../identifiers.ts"; +import { NativeAlgorithm } from "../algorithm.ts"; // b"HPKE-v1" const HPKE_VERSION = new Uint8Array([72, 80, 75, 69, 45, 118, 49]); diff --git a/packages/core/src/aeads/aesGcm.ts b/packages/core/src/aeads/aesGcm.ts index de81c5c36..5ee28a093 100644 --- a/packages/core/src/aeads/aesGcm.ts +++ b/packages/core/src/aeads/aesGcm.ts @@ -1,8 +1,5 @@ -import type { - AeadEncryptionContext, - AeadInterface, -} from "@hpke/common"; -import { AeadId, AEAD_USAGES, NativeAlgorithm } from "@hpke/common"; +import type { AeadEncryptionContext, AeadInterface } from "@hpke/common"; +import { AEAD_USAGES, AeadId, NativeAlgorithm } from "@hpke/common"; export class AesGcmContext extends NativeAlgorithm implements AeadEncryptionContext { diff --git a/packages/core/src/kems/dhkemNative.ts b/packages/core/src/kems/dhkemNative.ts index 26f0b4bb2..1e69af5f0 100644 --- a/packages/core/src/kems/dhkemNative.ts +++ b/packages/core/src/kems/dhkemNative.ts @@ -1,10 +1,11 @@ -import { Dhkem, Ec, KemId } from "@hpke/common"; - import { + Dhkem, + Ec, HkdfSha256Native, HkdfSha384Native, HkdfSha512Native, -} from "../kdfs/hkdf.ts"; + KemId, +} from "@hpke/common"; export class DhkemP256HkdfSha256Native extends Dhkem { public readonly id: KemId = KemId.DhkemP256HkdfSha256; diff --git a/packages/core/src/native.ts b/packages/core/src/native.ts index ac470003e..d12ed2ac8 100644 --- a/packages/core/src/native.ts +++ b/packages/core/src/native.ts @@ -1,9 +1,10 @@ -import { CipherSuiteNative } from "./cipherSuiteNative.ts"; import { HkdfSha256Native, HkdfSha384Native, HkdfSha512Native, -} from "./kdfs/hkdf.ts"; +} from "@hpke/common"; + +import { CipherSuiteNative } from "./cipherSuiteNative.ts"; import { DhkemP256HkdfSha256Native, DhkemP384HkdfSha384Native, diff --git a/packages/dhkem-secp256k1/deno.json b/packages/dhkem-secp256k1/deno.json index 7e209c607..7fddb961a 100644 --- a/packages/dhkem-secp256k1/deno.json +++ b/packages/dhkem-secp256k1/deno.json @@ -47,7 +47,7 @@ }, "tasks": { "test": "deno fmt && deno lint && deno test --import-map=../../import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read", - "test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/core @hpke/dhkem-secp256k1 && npm run test", + "test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/common @hpke/dhkem-secp256k1 && npm run test", "cov": "deno coverage ./coverage --lcov --exclude='test'", "dnt": "deno run --import-map=../../npm/import_map.json -A dnt.ts", "minify": "esbuild ../../npm/packages/dhkem-secp256k1/esm/dhkem-secp256k1/mod.js --bundle --format=esm --minify" diff --git a/packages/dhkem-x25519/deno.json b/packages/dhkem-x25519/deno.json index ac838d91b..c0f6c3a3c 100644 --- a/packages/dhkem-x25519/deno.json +++ b/packages/dhkem-x25519/deno.json @@ -48,7 +48,7 @@ }, "tasks": { "test": "deno fmt && deno lint && deno test --import-map=../../import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read", - "test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/core @hpke/dhkem-x25519 && npm run test", + "test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/common @hpke/dhkem-x25519 && npm run test", "cov": "deno coverage ./coverage --lcov --exclude='test'", "dnt": "deno run --import-map=../../npm/import_map.json -A dnt.ts", "minify": "esbuild ../../npm/packages/dhkem-x25519/esm/dhkem-x25519/mod.js --bundle --format=esm --minify" diff --git a/packages/dhkem-x25519/src/hkdfSha256.ts b/packages/dhkem-x25519/src/hkdfSha256.ts index 8dbdadd11..d8565a4e3 100644 --- a/packages/dhkem-x25519/src/hkdfSha256.ts +++ b/packages/dhkem-x25519/src/hkdfSha256.ts @@ -1,7 +1,7 @@ import { hmac } from "@noble/hashes/hmac"; import { sha256 } from "@noble/hashes/sha256"; -import { HkdfSha256 as HkdfSha256Native } from "@hpke/core"; +import { HkdfSha256Native } from "@hpke/common"; export class HkdfSha256 extends HkdfSha256Native { public override async extract( diff --git a/packages/dhkem-x448/deno.json b/packages/dhkem-x448/deno.json index 1fa5332cc..5cb9c55a9 100644 --- a/packages/dhkem-x448/deno.json +++ b/packages/dhkem-x448/deno.json @@ -48,7 +48,7 @@ }, "tasks": { "test": "deno fmt && deno lint && deno test --import-map=../../import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read", - "test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/core @hpke/dhkem-x448 && npm run test", + "test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/common @hpke/dhkem-x448 && npm run test", "cov": "deno coverage ./coverage --lcov --exclude='test'", "dnt": "deno run --import-map=../../npm/import_map.json -A dnt.ts", "minify": "esbuild ../../npm/packages/dhkem-x448/esm/dhkem-x448/mod.js --bundle --format=esm --minify" diff --git a/packages/dhkem-x448/src/hkdfSha512.ts b/packages/dhkem-x448/src/hkdfSha512.ts index e57b07985..2d185f64e 100644 --- a/packages/dhkem-x448/src/hkdfSha512.ts +++ b/packages/dhkem-x448/src/hkdfSha512.ts @@ -1,7 +1,7 @@ import { hmac } from "@noble/hashes/hmac"; import { sha512 } from "@noble/hashes/sha512"; -import { HkdfSha512 as HkdfSha512Native } from "@hpke/core"; +import { HkdfSha512Native } from "@hpke/common"; export class HkdfSha512 extends HkdfSha512Native { public override async extract( diff --git a/packages/hybridkem-x25519-kyber768/deno.json b/packages/hybridkem-x25519-kyber768/deno.json index 7effe04dd..0b4ed0084 100644 --- a/packages/hybridkem-x25519-kyber768/deno.json +++ b/packages/hybridkem-x25519-kyber768/deno.json @@ -47,7 +47,7 @@ }, "tasks": { "test": "deno fmt && deno lint && deno test --import-map=../../import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read", - "test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/core @hpke/hybridkem-x25519-kyber768 && npm run test", + "test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/common @hpke/hybridkem-x25519-kyber768 && npm run test", "cov": "deno coverage ./coverage --lcov --exclude='test'", "dnt": "deno run --import-map=../../npm/import_map.json -A dnt.ts", "minify": "esbuild ../../npm/packages/hybridkem-x25519-kyber768/esm/hybridkem-x25519-kyber768/mod.js --bundle --format=esm --minify"