From 04b3c60522fe423dcb90467d8c9ae220739d3a28 Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 10:07:32 +0900 Subject: [PATCH 01/13] Introduce @hpke/common for @hpke/core and @hpke/chacha20poly1305. --- .github/workflows/ci_browser.yml | 10 +++ .github/workflows/ci_node.yml | 8 +++ .github/workflows/publish.yml | 22 +++++++ deno.json | 15 +++-- npm/import_map.json | 1 + npm/package-lock.json | 17 +++++ npm/package.json | 1 + packages/chacha20poly1305/tsconfig.json | 1 + packages/common/LICENSE | 21 ++++++ packages/common/README.md | 24 +++++++ packages/common/deno.json | 45 +++++++++++++ packages/common/dnt.ts | 64 +++++++++++++++++++ packages/common/mod.ts | 4 ++ packages/{core => common}/src/identifiers.ts | 0 .../src/interfaces/aeadEncryptionContext.ts | 0 .../src/interfaces/aeadInterface.ts | 0 packages/common/tsconfig.json | 12 ++++ packages/core/mod.ts | 6 +- packages/core/src/aeads/aesGcm.ts | 8 +-- packages/core/src/aeads/exportOnly.ts | 6 +- packages/core/src/cipherSuiteNative.ts | 4 +- packages/core/src/encryptionContext.ts | 2 +- packages/core/src/interfaces/aeadParams.ts | 2 +- .../core/src/interfaces/cipherSuiteParams.ts | 4 +- packages/core/src/interfaces/kdfInterface.ts | 2 +- packages/core/src/interfaces/kemInterface.ts | 2 +- packages/core/src/interfaces/keyInfo.ts | 2 +- packages/core/src/kdfs/hkdf.ts | 2 +- packages/core/src/kems/dhkem.ts | 2 +- packages/core/src/kems/dhkemNative.ts | 2 +- packages/core/src/kems/dhkemPrimitives/ec.ts | 2 +- packages/core/src/kems/hybridkem.ts | 2 +- packages/core/test/utils.ts | 2 +- packages/core/tsconfig.json | 3 + packages/dhkem-secp256k1/tsconfig.json | 1 + packages/dhkem-x25519/tsconfig.json | 1 + packages/dhkem-x448/tsconfig.json | 1 + packages/hpke-js/tsconfig.json | 1 + .../hybridkem-x25519-kyber768/tsconfig.json | 1 + 39 files changed, 274 insertions(+), 29 deletions(-) create mode 100644 packages/common/LICENSE create mode 100644 packages/common/README.md create mode 100644 packages/common/deno.json create mode 100644 packages/common/dnt.ts create mode 100644 packages/common/mod.ts rename packages/{core => common}/src/identifiers.ts (100%) rename packages/{core => common}/src/interfaces/aeadEncryptionContext.ts (100%) rename packages/{core => common}/src/interfaces/aeadInterface.ts (100%) create mode 100644 packages/common/tsconfig.json diff --git a/.github/workflows/ci_browser.yml b/.github/workflows/ci_browser.yml index 6054f294f..cffcc7115 100644 --- a/.github/workflows/ci_browser.yml +++ b/.github/workflows/ci_browser.yml @@ -45,6 +45,16 @@ jobs: cp -rf ../hybridkem-x25519-kyber768/test/runtimes/browsers/pages/* test/runtimes/browsers/pages/hybridkem-x25519-kyber768 mkdir test/runtimes/browsers/pages/dhkem-secp256k1 cp -rf ../dhkem-secp256k1/test/runtimes/browsers/pages/* test/runtimes/browsers/pages/dhkem-secp256k1 + - name: Build docs for @hpke/common + working-directory: ./packages/common + run: | + npx typedoc --name "@hpke/common" --out ../hpke-js/test/runtimes/browsers/pages/common/docs mod.ts + deno task minify > ../hpke-js/test/runtimes/browsers/pages/core/src/hpke-common.js + deno task minify > ../hpke-js/test/runtimes/browsers/pages/dhkem-x25519/src/hpke-common.js + deno task minify > ../hpke-js/test/runtimes/browsers/pages/dhkem-x448/src/hpke-common.js + deno task minify > ../hpke-js/test/runtimes/browsers/pages/chacha20poly1305/src/hpke-common.js + deno task minify > ../hpke-js/test/runtimes/browsers/pages/hybridkem-x25519-kyber768/src/hpke-common.js + deno task minify > ../hpke-js/test/runtimes/browsers/pages/dhkem-secp256k1/src/hpke-common.js - name: Build docs for @hpke/core working-directory: ./packages/core run: | diff --git a/.github/workflows/ci_node.yml b/.github/workflows/ci_node.yml index 72d7d1f8a..72150fa4c 100644 --- a/.github/workflows/ci_node.yml +++ b/.github/workflows/ci_node.yml @@ -25,6 +25,14 @@ jobs: - name: Run dnt & minify run: | npm install -g esbuild + - name: Run dnt & minify for /common + working-directory: ./packages/common + run: | + deno task dnt + deno task minify > ../../npm/packages/common/hpke-common.min.js + - name: Publish to npm (dry) for /packages/common + working-directory: ./npm/packages/common + run: npm publish --dry-run - name: Run dnt & minify for /core working-directory: ./packages/core run: | diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index abfdd4c15..8783a620f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,6 +18,28 @@ jobs: - name: Run deno publish run: npx jsr publish + publish-common: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + registry-url: https://registry.npmjs.org/ + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + - name: Run dnt + working-directory: ./packages/common + run: | + npm install -g esbuild + deno task dnt + - name: Publish to npm + working-directory: ./npm/packages/common + run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + publish-core: runs-on: ubuntu-latest steps: diff --git a/deno.json b/deno.json index 369104870..aa439d18e 100644 --- a/deno.json +++ b/deno.json @@ -1,5 +1,6 @@ { "workspace": [ + "./packages/common", "./packages/core", "./packages/chacha20poly1305", "./packages/dhkem-x25519", @@ -43,7 +44,9 @@ ] }, "tasks": { + "test:all": "deno task test && deno task test:cloudflare", "test": "deno fmt && deno lint && deno test --import-map=./import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read", + "test:common": "cd packages/common && deno task test", "test:core": "cd packages/core && deno task test", "test:chacha20poly1305": "cd packages/chacha20poly1305 && deno task test", "test:dhkem-x25519": "cd packages/dhkem-x25519 && deno task test", @@ -60,8 +63,9 @@ "test:cloudflare:hybridkem-x25519-kyber768": "cd packages/hybridkem-x25519-kyber768 && deno task test:cloudflare", "test:cloudflare:hpke-js": "cd packages/hpke-js && deno task test:cloudflare", "cov": "deno coverage ./coverage --lcov --exclude='test'", - "dnt": "deno task dnt:core && deno task dnt:chacha20poly1305 && deno task dnt:dhkem-x25519 && deno task dnt:dhkem-x448 && deno task dnt:dhkem-secp256k1 && deno task dnt:hybridkem-x25519-kyber768 && deno task dnt:hpke-js", "npm": "deno task dnt && deno task npm-link && deno task npm-pack", + "dnt": "deno task dnt:common && deno task dnt:core && deno task dnt:chacha20poly1305 && deno task dnt:dhkem-x25519 && deno task dnt:dhkem-x448 && deno task dnt:dhkem-secp256k1 && deno task dnt:hybridkem-x25519-kyber768 && deno task dnt:hpke-js", + "dnt:common": "cd packages/common && deno task dnt", "dnt:core": "cd packages/core && deno task dnt", "dnt:chacha20poly1305": "cd packages/chacha20poly1305 && deno task dnt", "dnt:dhkem-x25519": "cd packages/dhkem-x25519 && deno task dnt", @@ -69,7 +73,8 @@ "dnt:dhkem-secp256k1": "cd packages/dhkem-secp256k1 && deno task dnt", "dnt:hybridkem-x25519-kyber768": "cd packages/hybridkem-x25519-kyber768 && deno task dnt", "dnt:hpke-js": "cd packages/hpke-js && deno task dnt", - "npm-link": "deno task npm-link:core && deno task npm-link:chacha20poly1305 && deno task npm-link:dhkem-x25519 && deno task npm-link:dhkem-x448 && deno task npm-link:dhkem-secp256k1 && deno task npm-link:hybridkem-x25519-kyber768 && deno task npm-link:hpke-js", + "npm-link": "deno task npm-link:common && deno task npm-link:core && deno task npm-link:chacha20poly1305 && deno task npm-link:dhkem-x25519 && deno task npm-link:dhkem-x448 && deno task npm-link:dhkem-secp256k1 && deno task npm-link:hybridkem-x25519-kyber768 && deno task npm-link:hpke-js", + "npm-link:common": "cd npm/packages/common && npm link", "npm-link:core": "cd npm/packages/core && npm link", "npm-link:chacha20poly1305": "cd npm/packages/chacha20poly1305 && npm link", "npm-link:dhkem-x25519": "cd npm/packages/dhkem-x25519 && npm link", @@ -77,7 +82,8 @@ "npm-link:dhkem-secp256k1": "cd npm/packages/dhkem-secp256k1 && npm link", "npm-link:hybridkem-x25519-kyber768": "cd npm/packages/hybridkem-x25519-kyber768 && npm link", "npm-link:hpke-js": "cd npm/packages/hpke-js && npm link", - "npm-pack": "deno task npm-pack:core && deno task npm-pack:chacha20poly1305 && deno task npm-pack:dhkem-x25519 && deno task npm-pack:dhkem-x448 && deno task npm-pack:dhkem-secp256k1 && deno task npm-pack:hybridkem-x25519-kyber768 && deno task npm-pack:hpke-js", + "npm-pack": "deno task npm-pack:common && deno task npm-pack:core && deno task npm-pack:chacha20poly1305 && deno task npm-pack:dhkem-x25519 && deno task npm-pack:dhkem-x448 && deno task npm-pack:dhkem-secp256k1 && deno task npm-pack:hybridkem-x25519-kyber768 && deno task npm-pack:hpke-js", + "npm-pack:common": "cd npm/packages/common && npm pack --dry-run", "npm-pack:core": "cd npm/packages/core && npm pack --dry-run", "npm-pack:chacha20poly1305": "cd npm/packages/chacha20poly1305 && npm pack --dry-run", "npm-pack:dhkem-x25519": "cd npm/packages/dhkem-x25519 && npm pack --dry-run", @@ -85,7 +91,8 @@ "npm-pack:dhkem-secp256k1": "cd npm/packages/dhkem-secp256k1 && npm pack --dry-run", "npm-pack:hybridkem-x25519-kyber768": "cd npm/packages/hybridkem-x25519-kyber768 && npm pack --dry-run", "npm-pack:hpke-js": "cd npm/packages/hpke-js && npm pack --dry-run", - "bun-link": "deno task bun-link:core && deno task bun-link:chacha20poly1305 && deno task bun-link:dhkem-x25519 && deno task bun-link:dhkem-x448 && deno task bun-link:dhkem-secp256k1 && deno task bun-link:hybridkem-x25519-kyber768 && deno task bun-link:hpke-js", + "bun-link": "deno task bun-link:common && deno task bun-link:core && deno task bun-link:chacha20poly1305 && deno task bun-link:dhkem-x25519 && deno task bun-link:dhkem-x448 && deno task bun-link:dhkem-secp256k1 && deno task bun-link:hybridkem-x25519-kyber768 && deno task bun-link:hpke-js", + "bun-link:common": "cd npm/packages/common && bun link", "bun-link:core": "cd npm/packages/core && bun link", "bun-link:chacha20poly1305": "cd npm/packages/chacha20poly1305 && bun link", "bun-link:dhkem-x25519": "cd npm/packages/dhkem-x25519 && bun link", diff --git a/npm/import_map.json b/npm/import_map.json index f1a135510..7cf280ded 100644 --- a/npm/import_map.json +++ b/npm/import_map.json @@ -1,6 +1,7 @@ { "imports": { "@deno/dnt": "jsr:@deno/dnt@^0.41.3", + "@hpke/common": "npm:@hpke/common@^0.1.0", "@hpke/core": "npm:@hpke/core@^1.3.0", "@hpke/chacha20poly1305": "npm:@hpke/chacha20poly1305@^1.3.0", "@hpke/dhkem-x25519": "npm:@hpke/dhkem-x25519@^1.3.0", diff --git a/npm/package-lock.json b/npm/package-lock.json index 003e2198a..1482f1512 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -6,6 +6,7 @@ "": { "name": "hpke-js", "workspaces": [ + "packages/common", "packages/core", "packages/chacha20poly1305", "packages/dhkem-x25519", @@ -37,6 +38,10 @@ "resolved": "packages/chacha20poly1305", "link": true }, + "node_modules/@hpke/common": { + "resolved": "packages/common", + "link": true + }, "node_modules/@hpke/core": { "resolved": "packages/core", "link": true @@ -160,6 +165,18 @@ "node": ">=16.0.0" } }, + "packages/common": { + "name": "@hpke/common", + "version": "0.1.0", + "license": "MIT", + "devDependencies": { + "@types/node": "^20.9.0", + "picocolors": "^1.0.0" + }, + "engines": { + "node": ">=16.0.0" + } + }, "packages/core": { "name": "@hpke/core", "version": "1.3.1", diff --git a/npm/package.json b/npm/package.json index 7e1792a80..44a3cbea4 100644 --- a/npm/package.json +++ b/npm/package.json @@ -2,6 +2,7 @@ "name": "hpke-js", "private": true, "workspaces": [ + "packages/common", "packages/core", "packages/chacha20poly1305", "packages/dhkem-x25519", diff --git a/packages/chacha20poly1305/tsconfig.json b/packages/chacha20poly1305/tsconfig.json index dc935c69b..b5d3f1720 100644 --- a/packages/chacha20poly1305/tsconfig.json +++ b/packages/chacha20poly1305/tsconfig.json @@ -3,6 +3,7 @@ "module": "es2022", "target": "es2022", "paths": { + "@hpke/common": ["../common/mod.ts"], "@hpke/core": ["../core/mod.ts"], "@noble/*": ["../../npm/node_modules/@noble/*"] }, diff --git a/packages/common/LICENSE b/packages/common/LICENSE new file mode 100644 index 000000000..b909019a7 --- /dev/null +++ b/packages/common/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Ajitomi Daisuke + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/common/README.md b/packages/common/README.md new file mode 100644 index 000000000..e32f4a297 --- /dev/null +++ b/packages/common/README.md @@ -0,0 +1,24 @@ +

@hpke/common

+ +
+JSR +
+ +
+A TypeScript Hybrid Public Key Encryption (HPKE) internal-use common module for @hpke family modules. +
+ +
+
+ +## Installation + +Do not install this package directly, it is an internal package used by +[@hpke/core](https://jsr.io/@hpke/core), +[@hpke/chacha20poly1305](https://jsr.io/@hpke/chacha20poly1305) and so on. Use +either of them instead. + +## Contributing + +We welcome all kind of contributions, filing issues, suggesting new features or +sending PRs. diff --git a/packages/common/deno.json b/packages/common/deno.json new file mode 100644 index 000000000..e4d8c41c3 --- /dev/null +++ b/packages/common/deno.json @@ -0,0 +1,45 @@ +{ + "name": "@hpke/common", + "version": "0.1.0", + "exports": "./mod.ts", + "publish": { + "exclude": [ + "dnt.ts", + "tsconfig.json" + ] + }, + "fmt": { + "include": [ + "**/*.md", + "**/*.json", + "dnt.ts", + "mod.ts", + "src/" + ], + "exclude": [ + "**/*/*.js", + "**/*/npm/", + "coverage/*.json" + ] + }, + "lint": { + "include": [ + "**/*.md", + "**/*.json", + "dnt.ts", + "mod.ts", + "src/" + ], + "exclude": [ + "**/*/*.js", + "**/*/npm/", + "coverage/*.json" + ] + }, + "tasks": { + "test": "deno fmt && deno lint && deno test --import-map=../../import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read", + "cov": "deno coverage ./coverage --lcov --exclude='test'", + "dnt": "deno run --import-map=../../import_map.json -A dnt.ts", + "minify": "esbuild ../../npm/packages/common/esm/mod.js --bundle --format=esm --minify" + } +} diff --git a/packages/common/dnt.ts b/packages/common/dnt.ts new file mode 100644 index 000000000..3d26169fd --- /dev/null +++ b/packages/common/dnt.ts @@ -0,0 +1,64 @@ +import { build, emptyDir } from "@deno/dnt"; + +await emptyDir("../../npm/packages/common"); + +const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json")); + +await build({ + entryPoints: ["./mod.ts"], + outDir: "../../npm/packages/common", + typeCheck: "both", + test: true, + declaration: true, + scriptModule: "umd", + importMap: "../../import_map.json", + compilerOptions: { + lib: ["ES2022", "DOM"], + }, + shims: { + deno: "dev", + }, + testPattern: "test/**/*.test.ts", + package: { + name: denoPkg.name, + version: denoPkg.version, + description: + "A Hybrid Public Key Encryption (HPKE) internal-use common module for @hpke family modules.", + repository: { + type: "git", + url: "git+https://github.com/dajiaji/hpke-js.git", + }, + homepage: "https://github.com/dajiaji/hpke-js/tree/main/common#readme", + license: "MIT", + module: "./esm/mod.js", + main: "./script/mod.js", + types: "./esm/mod.d.ts", + sideEffects: false, + exports: { + ".": { + "import": "./esm/mod.js", + "require": "./script/mod.js", + }, + "./package.json": "./package.json", + }, + keywords: [ + "hpke", + "rfc9180", + "hkdf", + "dh", + "security", + "encryption", + ], + engines: { + "node": ">=16.0.0", + }, + author: "Ajitomi Daisuke", + bugs: { + url: "https://github.com/dajiaji/hpke-js/issues", + }, + }, +}); + +// post build steps +Deno.copyFileSync("LICENSE", "../../npm/packages/common/LICENSE"); +Deno.copyFileSync("README.md", "../../npm/packages/common/README.md"); diff --git a/packages/common/mod.ts b/packages/common/mod.ts new file mode 100644 index 000000000..bc1fe4ff4 --- /dev/null +++ b/packages/common/mod.ts @@ -0,0 +1,4 @@ +export type { AeadEncryptionContext } from "./src/interfaces/aeadEncryptionContext.ts"; +export type { AeadInterface } from "./src/interfaces/aeadInterface.ts"; +export { AeadId, KdfId, KemId, Mode } from "./src/identifiers.ts"; +export { AEAD_USAGES } from "./src/interfaces/aeadEncryptionContext.ts"; diff --git a/packages/core/src/identifiers.ts b/packages/common/src/identifiers.ts similarity index 100% rename from packages/core/src/identifiers.ts rename to packages/common/src/identifiers.ts diff --git a/packages/core/src/interfaces/aeadEncryptionContext.ts b/packages/common/src/interfaces/aeadEncryptionContext.ts similarity index 100% rename from packages/core/src/interfaces/aeadEncryptionContext.ts rename to packages/common/src/interfaces/aeadEncryptionContext.ts diff --git a/packages/core/src/interfaces/aeadInterface.ts b/packages/common/src/interfaces/aeadInterface.ts similarity index 100% rename from packages/core/src/interfaces/aeadInterface.ts rename to packages/common/src/interfaces/aeadInterface.ts diff --git a/packages/common/tsconfig.json b/packages/common/tsconfig.json new file mode 100644 index 000000000..5004a1ced --- /dev/null +++ b/packages/common/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "es2022", + "target": "es2022", + "noEmit": true, + "allowImportingTsExtensions": true + }, + "include": [ + "mod.ts", + "src/**/*" + ] +} diff --git a/packages/core/mod.ts b/packages/core/mod.ts index 8bd60fe62..8bcd283ad 100644 --- a/packages/core/mod.ts +++ b/packages/core/mod.ts @@ -1,5 +1,5 @@ -export type { AeadEncryptionContext } from "./src/interfaces/aeadEncryptionContext.ts"; -export type { AeadInterface } from "./src/interfaces/aeadInterface.ts"; +export type { AeadEncryptionContext } from "@hpke/common"; +export type { AeadInterface } from "@hpke/common"; export type { CipherSuiteParams } from "./src/interfaces/cipherSuiteParams.ts"; export type { EncryptionContext, @@ -16,7 +16,7 @@ export type { SenderContextParams } from "./src/interfaces/senderContextParams.t export { Aes128Gcm, Aes256Gcm } from "./src/aeads/aesGcm.ts"; export { ExportOnly } from "./src/aeads/exportOnly.ts"; export * from "./src/errors.ts"; -export { AeadId, KdfId, KemId } from "./src/identifiers.ts"; +export { AeadId, KdfId, KemId } from "@hpke/common"; export { CipherSuite, diff --git a/packages/core/src/aeads/aesGcm.ts b/packages/core/src/aeads/aesGcm.ts index 74353e5e4..f0d556dba 100644 --- a/packages/core/src/aeads/aesGcm.ts +++ b/packages/core/src/aeads/aesGcm.ts @@ -1,9 +1,9 @@ -import type { AeadEncryptionContext } from "../interfaces/aeadEncryptionContext.ts"; -import type { AeadInterface } from "../interfaces/aeadInterface.ts"; +import type { AeadEncryptionContext } from "@hpke/common"; +import type { AeadInterface } from "@hpke/common"; import { NativeAlgorithm } from "../algorithm.ts"; -import { AeadId } from "../identifiers.ts"; -import { AEAD_USAGES } from "../interfaces/aeadEncryptionContext.ts"; +import { AeadId } from "@hpke/common"; +import { AEAD_USAGES } from "@hpke/common"; export class AesGcmContext extends NativeAlgorithm implements AeadEncryptionContext { diff --git a/packages/core/src/aeads/exportOnly.ts b/packages/core/src/aeads/exportOnly.ts index 51679cca5..c4cda8d8d 100644 --- a/packages/core/src/aeads/exportOnly.ts +++ b/packages/core/src/aeads/exportOnly.ts @@ -1,7 +1,7 @@ -import type { AeadEncryptionContext } from "../interfaces/aeadEncryptionContext.ts"; -import type { AeadInterface } from "../interfaces/aeadInterface.ts"; +import type { AeadEncryptionContext } from "@hpke/common"; +import type { AeadInterface } from "@hpke/common"; -import { AeadId } from "../identifiers.ts"; +import { AeadId } from "@hpke/common"; import { NotSupportedError } from "../errors.ts"; diff --git a/packages/core/src/cipherSuiteNative.ts b/packages/core/src/cipherSuiteNative.ts index da5ab7eed..a08f187b4 100644 --- a/packages/core/src/cipherSuiteNative.ts +++ b/packages/core/src/cipherSuiteNative.ts @@ -1,4 +1,4 @@ -import type { AeadInterface } from "./interfaces/aeadInterface.ts"; +import type { AeadInterface } from "@hpke/common"; import type { AeadParams } from "./interfaces/aeadParams.ts"; import type { CipherSuiteParams } from "./interfaces/cipherSuiteParams.ts"; import type { @@ -19,7 +19,7 @@ import { RecipientExporterContextImpl, SenderExporterContextImpl, } from "./exporterContext.ts"; -import { AeadId, Mode } from "./identifiers.ts"; +import { AeadId, Mode } from "@hpke/common"; import { RecipientContextImpl } from "./recipientContext.ts"; import { SenderContextImpl } from "./senderContext.ts"; import { i2Osp } from "./utils/misc.ts"; diff --git a/packages/core/src/encryptionContext.ts b/packages/core/src/encryptionContext.ts index 2be447cdf..2ee6a009d 100644 --- a/packages/core/src/encryptionContext.ts +++ b/packages/core/src/encryptionContext.ts @@ -1,4 +1,4 @@ -import type { AeadInterface } from "./interfaces/aeadInterface.ts"; +import type { AeadInterface } from "@hpke/common"; import type { AeadParams } from "./interfaces/aeadParams.ts"; import type { KeyInfo } from "./interfaces/keyInfo.ts"; import type { KdfInterface } from "./interfaces/kdfInterface.ts"; diff --git a/packages/core/src/interfaces/aeadParams.ts b/packages/core/src/interfaces/aeadParams.ts index 6452a4d28..40d5452e1 100644 --- a/packages/core/src/interfaces/aeadParams.ts +++ b/packages/core/src/interfaces/aeadParams.ts @@ -1,4 +1,4 @@ -import type { AeadInterface } from "./aeadInterface.ts"; +import type { AeadInterface } from "@hpke/common"; /** * The AEAD parameters for building a encryption context. diff --git a/packages/core/src/interfaces/cipherSuiteParams.ts b/packages/core/src/interfaces/cipherSuiteParams.ts index 46129cc39..9c9b04c3e 100644 --- a/packages/core/src/interfaces/cipherSuiteParams.ts +++ b/packages/core/src/interfaces/cipherSuiteParams.ts @@ -1,5 +1,5 @@ -import type { AeadId, KdfId, KemId } from "../identifiers.ts"; -import type { AeadInterface } from "./aeadInterface.ts"; +import type { AeadId, KdfId, KemId } from "@hpke/common"; +import type { AeadInterface } from "@hpke/common"; import type { KdfInterface } from "./kdfInterface.ts"; import type { KemInterface } from "./kemInterface.ts"; diff --git a/packages/core/src/interfaces/kdfInterface.ts b/packages/core/src/interfaces/kdfInterface.ts index da5771b9c..4f7c9db64 100644 --- a/packages/core/src/interfaces/kdfInterface.ts +++ b/packages/core/src/interfaces/kdfInterface.ts @@ -1,4 +1,4 @@ -import type { KdfId } from "../identifiers.ts"; +import type { KdfId } from "@hpke/common"; /** * The KDF interface. diff --git a/packages/core/src/interfaces/kemInterface.ts b/packages/core/src/interfaces/kemInterface.ts index c171e4552..13934b9a3 100644 --- a/packages/core/src/interfaces/kemInterface.ts +++ b/packages/core/src/interfaces/kemInterface.ts @@ -1,6 +1,6 @@ import type { RecipientContextParams } from "./recipientContextParams.ts"; import type { SenderContextParams } from "./senderContextParams.ts"; -import type { KemId } from "../identifiers.ts"; +import type { KemId } from "@hpke/common"; // b"KEM" export const SUITE_ID_HEADER_KEM: Uint8Array = new Uint8Array([ diff --git a/packages/core/src/interfaces/keyInfo.ts b/packages/core/src/interfaces/keyInfo.ts index 046ae1e01..a8482323a 100644 --- a/packages/core/src/interfaces/keyInfo.ts +++ b/packages/core/src/interfaces/keyInfo.ts @@ -1,4 +1,4 @@ -import type { AeadEncryptionContext } from "./aeadEncryptionContext.ts"; +import type { AeadEncryptionContext } from "@hpke/common"; export interface KeyInfo { key: AeadEncryptionContext; diff --git a/packages/core/src/kdfs/hkdf.ts b/packages/core/src/kdfs/hkdf.ts index cb38a49bc..2918f7435 100644 --- a/packages/core/src/kdfs/hkdf.ts +++ b/packages/core/src/kdfs/hkdf.ts @@ -3,7 +3,7 @@ import type { KdfInterface } from "../interfaces/kdfInterface.ts"; import { NativeAlgorithm } from "../algorithm.ts"; import { EMPTY } from "../consts.ts"; import { InvalidParamError } from "../errors.ts"; -import { KdfId } from "../identifiers.ts"; +import { KdfId } from "@hpke/common"; // b"HPKE-v1" const HPKE_VERSION = new Uint8Array([72, 80, 75, 69, 45, 118, 49]); diff --git a/packages/core/src/kems/dhkem.ts b/packages/core/src/kems/dhkem.ts index c107daffe..b83e8ce15 100644 --- a/packages/core/src/kems/dhkem.ts +++ b/packages/core/src/kems/dhkem.ts @@ -1,5 +1,5 @@ import type { KdfInterface } from "../interfaces/kdfInterface.ts"; -import type { KemId } from "../identifiers.ts"; +import type { KemId } from "@hpke/common"; import type { KemInterface } from "../interfaces/kemInterface.ts"; import type { DhkemPrimitives } from "../interfaces/dhkemPrimitives.ts"; import type { SenderContextParams } from "../interfaces/senderContextParams.ts"; diff --git a/packages/core/src/kems/dhkemNative.ts b/packages/core/src/kems/dhkemNative.ts index 01269e667..4b8742f34 100644 --- a/packages/core/src/kems/dhkemNative.ts +++ b/packages/core/src/kems/dhkemNative.ts @@ -1,4 +1,4 @@ -import { KemId } from "../identifiers.ts"; +import { KemId } from "@hpke/common"; import { HkdfSha256Native, HkdfSha384Native, diff --git a/packages/core/src/kems/dhkemPrimitives/ec.ts b/packages/core/src/kems/dhkemPrimitives/ec.ts index 317a48fef..ca2555938 100644 --- a/packages/core/src/kems/dhkemPrimitives/ec.ts +++ b/packages/core/src/kems/dhkemPrimitives/ec.ts @@ -9,7 +9,7 @@ import { NotSupportedError, SerializeError, } from "../../errors.ts"; -import { KemId } from "../../identifiers.ts"; +import { KemId } from "@hpke/common"; import { KEM_USAGES, LABEL_DKP_PRK } from "../../interfaces/dhkemPrimitives.ts"; import { Bignum } from "../../utils/bignum.ts"; import { base64UrlToBytes, i2Osp } from "../../utils/misc.ts"; diff --git a/packages/core/src/kems/hybridkem.ts b/packages/core/src/kems/hybridkem.ts index dab6ba8ca..0de574561 100644 --- a/packages/core/src/kems/hybridkem.ts +++ b/packages/core/src/kems/hybridkem.ts @@ -11,7 +11,7 @@ import { NotSupportedError, SerializeError, } from "../errors.ts"; -import { KemId } from "../identifiers.ts"; +import { KemId } from "@hpke/common"; import { LABEL_DKP_PRK, LABEL_SK } from "../interfaces/dhkemPrimitives.ts"; import { SUITE_ID_HEADER_KEM } from "../interfaces/kemInterface.ts"; import { concat, i2Osp, isCryptoKeyPair } from "../utils/misc.ts"; diff --git a/packages/core/test/utils.ts b/packages/core/test/utils.ts index 68cad7121..4d57a843f 100644 --- a/packages/core/test/utils.ts +++ b/packages/core/test/utils.ts @@ -1,4 +1,4 @@ -import { KemId } from "../src/identifiers.ts"; +import { KemId } from "@hpke/common"; // deno-lint-ignore no-explicit-any export const isNode = () => (globalThis as any).process?.versions?.node != null; diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 5004a1ced..ed70c6419 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -2,6 +2,9 @@ "compilerOptions": { "module": "es2022", "target": "es2022", + "paths": { + "@hpke/common": ["../common/mod.ts"] + }, "noEmit": true, "allowImportingTsExtensions": true }, diff --git a/packages/dhkem-secp256k1/tsconfig.json b/packages/dhkem-secp256k1/tsconfig.json index 086f69a0c..37db229ff 100644 --- a/packages/dhkem-secp256k1/tsconfig.json +++ b/packages/dhkem-secp256k1/tsconfig.json @@ -3,6 +3,7 @@ "module": "es2022", "target": "es2022", "paths": { + "@hpke/common": ["../common/mod.ts"], "@hpke/core": ["../core/mod.ts"], "@hpke/dhkem-x25519": ["../dhkem-x25519/mod.ts"], "@noble/*": ["../../npm/node_modules/@noble/*"] diff --git a/packages/dhkem-x25519/tsconfig.json b/packages/dhkem-x25519/tsconfig.json index dc935c69b..b5d3f1720 100644 --- a/packages/dhkem-x25519/tsconfig.json +++ b/packages/dhkem-x25519/tsconfig.json @@ -3,6 +3,7 @@ "module": "es2022", "target": "es2022", "paths": { + "@hpke/common": ["../common/mod.ts"], "@hpke/core": ["../core/mod.ts"], "@noble/*": ["../../npm/node_modules/@noble/*"] }, diff --git a/packages/dhkem-x448/tsconfig.json b/packages/dhkem-x448/tsconfig.json index dc935c69b..b5d3f1720 100644 --- a/packages/dhkem-x448/tsconfig.json +++ b/packages/dhkem-x448/tsconfig.json @@ -3,6 +3,7 @@ "module": "es2022", "target": "es2022", "paths": { + "@hpke/common": ["../common/mod.ts"], "@hpke/core": ["../core/mod.ts"], "@noble/*": ["../../npm/node_modules/@noble/*"] }, diff --git a/packages/hpke-js/tsconfig.json b/packages/hpke-js/tsconfig.json index e9893b531..66aaad846 100644 --- a/packages/hpke-js/tsconfig.json +++ b/packages/hpke-js/tsconfig.json @@ -3,6 +3,7 @@ "module": "es2022", "target": "es2022", "paths": { + "@hpke/common": ["../common/mod.ts"], "@hpke/core": ["../core/mod.ts"], "@hpke/chacha20poly1305": ["../chacha20poly1305/mod.ts"], "@hpke/dhkem-x25519": ["../dhkem-x25519/mod.ts"], diff --git a/packages/hybridkem-x25519-kyber768/tsconfig.json b/packages/hybridkem-x25519-kyber768/tsconfig.json index 086f69a0c..37db229ff 100644 --- a/packages/hybridkem-x25519-kyber768/tsconfig.json +++ b/packages/hybridkem-x25519-kyber768/tsconfig.json @@ -3,6 +3,7 @@ "module": "es2022", "target": "es2022", "paths": { + "@hpke/common": ["../common/mod.ts"], "@hpke/core": ["../core/mod.ts"], "@hpke/dhkem-x25519": ["../dhkem-x25519/mod.ts"], "@noble/*": ["../../npm/node_modules/@noble/*"] From e358c2c831ce44edad3620282cc1da251b06ebf7 Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 13:31:40 +0900 Subject: [PATCH 02/13] Move @hpke/core funcs for development to @hpke/common. --- npm/package-lock.json | 1 + packages/common/mod.ts | 19 ++++++++ packages/{core => common}/src/algorithm.ts | 0 packages/{core => common}/src/consts.ts | 2 +- packages/{core => common}/src/errors.ts | 0 .../src/interfaces/dhkemInterface.ts | 0 .../src/interfaces/dhkemPrimitives.ts | 0 .../src/interfaces/kdfInterface.ts | 2 +- .../src/interfaces/kemInterface.ts | 6 +-- .../src/interfaces/keyScheduleParams.ts | 0 .../src/interfaces/preSharedKey.ts | 0 .../src/interfaces/recipientContextParams.ts | 0 .../src/interfaces/senderContextParams.ts | 0 packages/{core => common}/src/kems/dhkem.ts | 2 +- .../src/kems/dhkemPrimitives/ec.ts | 2 +- packages/{core => common}/src/utils/bignum.ts | 0 packages/{core => common}/src/utils/misc.ts | 14 ++++++ packages/{core => common}/test/bignum.test.ts | 0 packages/{core => common}/test/errors.test.ts | 0 packages/{core => common}/test/misc.test.ts | 3 +- packages/core/mod.ts | 46 ++++++++++++------- packages/core/src/aeads/aesGcm.ts | 5 +- packages/core/src/aeads/exportOnly.ts | 8 +--- packages/core/src/cipherSuiteNative.ts | 31 ++++++++----- packages/core/src/encryptionContext.ts | 18 ++------ packages/core/src/exporterContext.ts | 10 ++-- .../core/src/interfaces/cipherSuiteParams.ts | 12 +++-- packages/core/src/kdfs/hkdf.ts | 7 +-- packages/core/src/kems/dhkemNative.ts | 5 +- packages/core/src/kems/hybridkem.ts | 27 ++++++----- packages/core/src/recipientContext.ts | 4 +- packages/core/src/senderContext.ts | 7 ++- packages/core/src/utils/emitNotSupported.ts | 2 +- .../dhkem-secp256k1/src/dhkemSecp256k1.ts | 2 +- packages/dhkem-secp256k1/src/secp256k1.ts | 2 +- packages/dhkem-x25519/src/dhkemX25519.ts | 2 +- packages/dhkem-x25519/src/x25519.ts | 2 +- packages/dhkem-x448/src/dhkemX448.ts | 2 +- packages/dhkem-x448/src/x448.ts | 2 +- packages/hpke-js/src/cipherSuite.ts | 3 +- packages/hpke-js/src/kems/dhkemP256.ts | 2 +- packages/hpke-js/src/kems/dhkemP384.ts | 2 +- packages/hpke-js/src/kems/dhkemP521.ts | 2 +- packages/hpke-js/test/dhkemPrimitives.test.ts | 2 +- .../hpke-js/test/encryptionContext.test.ts | 8 ++-- packages/hpke-js/test/kdfContext.test.ts | 3 +- .../src/hybridkemX25519Kyber768.ts | 5 +- .../src/kemKyber768.ts | 5 +- 48 files changed, 162 insertions(+), 115 deletions(-) rename packages/{core => common}/src/algorithm.ts (100%) rename packages/{core => common}/src/consts.ts (78%) rename packages/{core => common}/src/errors.ts (100%) rename packages/{core => common}/src/interfaces/dhkemInterface.ts (100%) rename packages/{core => common}/src/interfaces/dhkemPrimitives.ts (100%) rename packages/{core => common}/src/interfaces/kdfInterface.ts (98%) rename packages/{core => common}/src/interfaces/kemInterface.ts (95%) rename packages/{core => common}/src/interfaces/keyScheduleParams.ts (100%) rename packages/{core => common}/src/interfaces/preSharedKey.ts (100%) rename packages/{core => common}/src/interfaces/recipientContextParams.ts (100%) rename packages/{core => common}/src/interfaces/senderContextParams.ts (100%) rename packages/{core => common}/src/kems/dhkem.ts (99%) rename packages/{core => common}/src/kems/dhkemPrimitives/ec.ts (99%) rename packages/{core => common}/src/utils/bignum.ts (100%) rename packages/{core => common}/src/utils/misc.ts (79%) rename packages/{core => common}/test/bignum.test.ts (100%) rename packages/{core => common}/test/errors.test.ts (100%) rename packages/{core => common}/test/misc.test.ts (94%) diff --git a/npm/package-lock.json b/npm/package-lock.json index 1482f1512..335338a40 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -170,6 +170,7 @@ "version": "0.1.0", "license": "MIT", "devDependencies": { + "@deno/shim-deno": "~0.18.0", "@types/node": "^20.9.0", "picocolors": "^1.0.0" }, diff --git a/packages/common/mod.ts b/packages/common/mod.ts index bc1fe4ff4..9a25c80d3 100644 --- a/packages/common/mod.ts +++ b/packages/common/mod.ts @@ -1,4 +1,23 @@ export type { AeadEncryptionContext } from "./src/interfaces/aeadEncryptionContext.ts"; export type { AeadInterface } from "./src/interfaces/aeadInterface.ts"; +export type { DhkemPrimitives } from "./src/interfaces/dhkemPrimitives.ts"; +export type { DhkemInterface } from "./src/interfaces/dhkemInterface.ts"; +export type { KdfInterface } from "./src/interfaces/kdfInterface.ts"; +export type { KemInterface } from "./src/interfaces/kemInterface.ts"; +export type { KeyScheduleParams } from "./src/interfaces/keyScheduleParams.ts"; +export type { PreSharedKey } from "./src/interfaces/preSharedKey.ts"; +export type { RecipientContextParams } from "./src/interfaces/recipientContextParams.ts"; +export type { SenderContextParams } from "./src/interfaces/senderContextParams.ts"; + +export * from "./src/errors.ts"; +export { NativeAlgorithm } from "./src/algorithm.ts"; export { AeadId, KdfId, KemId, Mode } from "./src/identifiers.ts"; +export { Dhkem } from "./src/kems/dhkem.ts"; +export { Ec } from "./src/kems/dhkemPrimitives/ec.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"; +export { EMPTY, INPUT_LENGTH_LIMIT, MINIMUM_PSK_LENGTH } from "./src/consts.ts"; + +export { concat, i2Osp, isCryptoKeyPair, xor } from "./src/utils/misc.ts"; diff --git a/packages/core/src/algorithm.ts b/packages/common/src/algorithm.ts similarity index 100% rename from packages/core/src/algorithm.ts rename to packages/common/src/algorithm.ts diff --git a/packages/core/src/consts.ts b/packages/common/src/consts.ts similarity index 78% rename from packages/core/src/consts.ts rename to packages/common/src/consts.ts index 6eb2c9325..f291e3be9 100644 --- a/packages/core/src/consts.ts +++ b/packages/common/src/consts.ts @@ -5,4 +5,4 @@ export const INPUT_LENGTH_LIMIT = 8192; export const MINIMUM_PSK_LENGTH = 32; // b"" -export const EMPTY = new Uint8Array(0); +export const EMPTY: Uint8Array = new Uint8Array(0); diff --git a/packages/core/src/errors.ts b/packages/common/src/errors.ts similarity index 100% rename from packages/core/src/errors.ts rename to packages/common/src/errors.ts diff --git a/packages/core/src/interfaces/dhkemInterface.ts b/packages/common/src/interfaces/dhkemInterface.ts similarity index 100% rename from packages/core/src/interfaces/dhkemInterface.ts rename to packages/common/src/interfaces/dhkemInterface.ts diff --git a/packages/core/src/interfaces/dhkemPrimitives.ts b/packages/common/src/interfaces/dhkemPrimitives.ts similarity index 100% rename from packages/core/src/interfaces/dhkemPrimitives.ts rename to packages/common/src/interfaces/dhkemPrimitives.ts diff --git a/packages/core/src/interfaces/kdfInterface.ts b/packages/common/src/interfaces/kdfInterface.ts similarity index 98% rename from packages/core/src/interfaces/kdfInterface.ts rename to packages/common/src/interfaces/kdfInterface.ts index 4f7c9db64..da5771b9c 100644 --- a/packages/core/src/interfaces/kdfInterface.ts +++ b/packages/common/src/interfaces/kdfInterface.ts @@ -1,4 +1,4 @@ -import type { KdfId } from "@hpke/common"; +import type { KdfId } from "../identifiers.ts"; /** * The KDF interface. diff --git a/packages/core/src/interfaces/kemInterface.ts b/packages/common/src/interfaces/kemInterface.ts similarity index 95% rename from packages/core/src/interfaces/kemInterface.ts rename to packages/common/src/interfaces/kemInterface.ts index 13934b9a3..dbe16e17b 100644 --- a/packages/core/src/interfaces/kemInterface.ts +++ b/packages/common/src/interfaces/kemInterface.ts @@ -1,6 +1,6 @@ -import type { RecipientContextParams } from "./recipientContextParams.ts"; -import type { SenderContextParams } from "./senderContextParams.ts"; -import type { KemId } from "@hpke/common"; +import type { RecipientContextParams } from "../interfaces/recipientContextParams.ts"; +import type { SenderContextParams } from "../interfaces/senderContextParams.ts"; +import type { KemId } from "../identifiers.ts"; // b"KEM" export const SUITE_ID_HEADER_KEM: Uint8Array = new Uint8Array([ diff --git a/packages/core/src/interfaces/keyScheduleParams.ts b/packages/common/src/interfaces/keyScheduleParams.ts similarity index 100% rename from packages/core/src/interfaces/keyScheduleParams.ts rename to packages/common/src/interfaces/keyScheduleParams.ts diff --git a/packages/core/src/interfaces/preSharedKey.ts b/packages/common/src/interfaces/preSharedKey.ts similarity index 100% rename from packages/core/src/interfaces/preSharedKey.ts rename to packages/common/src/interfaces/preSharedKey.ts diff --git a/packages/core/src/interfaces/recipientContextParams.ts b/packages/common/src/interfaces/recipientContextParams.ts similarity index 100% rename from packages/core/src/interfaces/recipientContextParams.ts rename to packages/common/src/interfaces/recipientContextParams.ts diff --git a/packages/core/src/interfaces/senderContextParams.ts b/packages/common/src/interfaces/senderContextParams.ts similarity index 100% rename from packages/core/src/interfaces/senderContextParams.ts rename to packages/common/src/interfaces/senderContextParams.ts diff --git a/packages/core/src/kems/dhkem.ts b/packages/common/src/kems/dhkem.ts similarity index 99% rename from packages/core/src/kems/dhkem.ts rename to packages/common/src/kems/dhkem.ts index b83e8ce15..c107daffe 100644 --- a/packages/core/src/kems/dhkem.ts +++ b/packages/common/src/kems/dhkem.ts @@ -1,5 +1,5 @@ import type { KdfInterface } from "../interfaces/kdfInterface.ts"; -import type { KemId } from "@hpke/common"; +import type { KemId } from "../identifiers.ts"; import type { KemInterface } from "../interfaces/kemInterface.ts"; import type { DhkemPrimitives } from "../interfaces/dhkemPrimitives.ts"; import type { SenderContextParams } from "../interfaces/senderContextParams.ts"; diff --git a/packages/core/src/kems/dhkemPrimitives/ec.ts b/packages/common/src/kems/dhkemPrimitives/ec.ts similarity index 99% rename from packages/core/src/kems/dhkemPrimitives/ec.ts rename to packages/common/src/kems/dhkemPrimitives/ec.ts index ca2555938..317a48fef 100644 --- a/packages/core/src/kems/dhkemPrimitives/ec.ts +++ b/packages/common/src/kems/dhkemPrimitives/ec.ts @@ -9,7 +9,7 @@ import { NotSupportedError, SerializeError, } from "../../errors.ts"; -import { KemId } from "@hpke/common"; +import { KemId } from "../../identifiers.ts"; import { KEM_USAGES, LABEL_DKP_PRK } from "../../interfaces/dhkemPrimitives.ts"; import { Bignum } from "../../utils/bignum.ts"; import { base64UrlToBytes, i2Osp } from "../../utils/misc.ts"; diff --git a/packages/core/src/utils/bignum.ts b/packages/common/src/utils/bignum.ts similarity index 100% rename from packages/core/src/utils/bignum.ts rename to packages/common/src/utils/bignum.ts diff --git a/packages/core/src/utils/misc.ts b/packages/common/src/utils/misc.ts similarity index 79% rename from packages/core/src/utils/misc.ts rename to packages/common/src/utils/misc.ts index df65e73b7..63b7597c1 100644 --- a/packages/core/src/utils/misc.ts +++ b/packages/common/src/utils/misc.ts @@ -49,3 +49,17 @@ export function base64UrlToBytes(v: string): Uint8Array { } return ret; } + +/** + * XOR for Uint8Array. + */ +export function xor(a: Uint8Array, b: Uint8Array): Uint8Array { + if (a.byteLength !== b.byteLength) { + throw new Error("xor: different length inputs"); + } + const buf = new Uint8Array(a.byteLength); + for (let i = 0; i < a.byteLength; i++) { + buf[i] = a[i] ^ b[i]; + } + return buf; +} diff --git a/packages/core/test/bignum.test.ts b/packages/common/test/bignum.test.ts similarity index 100% rename from packages/core/test/bignum.test.ts rename to packages/common/test/bignum.test.ts diff --git a/packages/core/test/errors.test.ts b/packages/common/test/errors.test.ts similarity index 100% rename from packages/core/test/errors.test.ts rename to packages/common/test/errors.test.ts diff --git a/packages/core/test/misc.test.ts b/packages/common/test/misc.test.ts similarity index 94% rename from packages/core/test/misc.test.ts rename to packages/common/test/misc.test.ts index d5b1ab030..bfda79a41 100644 --- a/packages/core/test/misc.test.ts +++ b/packages/common/test/misc.test.ts @@ -1,8 +1,7 @@ import { assertEquals, assertThrows } from "@std/assert"; import { describe, it } from "@std/testing/bdd"; -import { xor } from "../src/encryptionContext.ts"; -import { i2Osp } from "../src/utils/misc.ts"; +import { i2Osp, xor } from "../src/utils/misc.ts"; describe("i2Osp", () => { describe("with valid params (5, 1)", () => { diff --git a/packages/core/mod.ts b/packages/core/mod.ts index 8bcd283ad..872309b4a 100644 --- a/packages/core/mod.ts +++ b/packages/core/mod.ts @@ -1,23 +1,42 @@ -export type { AeadEncryptionContext } from "@hpke/common"; -export type { AeadInterface } from "@hpke/common"; +export type { + AeadEncryptionContext, + AeadInterface, + KdfInterface, + KemInterface, + PreSharedKey, + RecipientContextParams, + SenderContextParams, +} from "@hpke/common"; + export type { CipherSuiteParams } from "./src/interfaces/cipherSuiteParams.ts"; export type { EncryptionContext, RecipientContext, SenderContext, } from "./src/interfaces/encryptionContext.ts"; -export type { KdfInterface } from "./src/interfaces/kdfInterface.ts"; -export type { KemInterface } from "./src/interfaces/kemInterface.ts"; -export type { PreSharedKey } from "./src/interfaces/preSharedKey.ts"; -export type { RecipientContextParams } from "./src/interfaces/recipientContextParams.ts"; export type { CipherSuiteSealResponse } from "./src/interfaces/responses.ts"; -export type { SenderContextParams } from "./src/interfaces/senderContextParams.ts"; +export { + AeadId, + BaseError, + DecapError, + DeriveKeyPairError, + DeserializeError, + EncapError, + ExportError, + HpkeError, + InvalidParamError, + KdfId, + KemId, + MessageLimitReachedError, + NotSupportedError, + OpenError, + SealError, + SerializeError, + ValidationError, +} from "@hpke/common"; export { Aes128Gcm, Aes256Gcm } from "./src/aeads/aesGcm.ts"; export { ExportOnly } from "./src/aeads/exportOnly.ts"; -export * from "./src/errors.ts"; -export { AeadId, KdfId, KemId } from "@hpke/common"; - export { CipherSuite, DhkemP256HkdfSha256, @@ -29,12 +48,5 @@ export { } from "./src/native.ts"; // Followings are disclosed for hpke-js family modules -export type { DhkemInterface } from "./src/interfaces/dhkemInterface.ts"; -export type { DhkemPrimitives } from "./src/interfaces/dhkemPrimitives.ts"; - -export { Dhkem } from "./src/kems/dhkem.ts"; -export { Ec } from "./src/kems/dhkemPrimitives/ec.ts"; export { Hybridkem } from "./src/kems/hybridkem.ts"; export { XCryptoKey } from "./src/xCryptoKey.ts"; - -export { INPUT_LENGTH_LIMIT } from "./src/consts.ts"; diff --git a/packages/core/src/aeads/aesGcm.ts b/packages/core/src/aeads/aesGcm.ts index f0d556dba..e63497c40 100644 --- a/packages/core/src/aeads/aesGcm.ts +++ b/packages/core/src/aeads/aesGcm.ts @@ -1,7 +1,6 @@ -import type { AeadEncryptionContext } from "@hpke/common"; -import type { AeadInterface } from "@hpke/common"; +import type { AeadEncryptionContext, AeadInterface } from "@hpke/common"; -import { NativeAlgorithm } from "../algorithm.ts"; +import { NativeAlgorithm } from "@hpke/common"; import { AeadId } from "@hpke/common"; import { AEAD_USAGES } from "@hpke/common"; diff --git a/packages/core/src/aeads/exportOnly.ts b/packages/core/src/aeads/exportOnly.ts index c4cda8d8d..b3ad45631 100644 --- a/packages/core/src/aeads/exportOnly.ts +++ b/packages/core/src/aeads/exportOnly.ts @@ -1,9 +1,5 @@ -import type { AeadEncryptionContext } from "@hpke/common"; -import type { AeadInterface } from "@hpke/common"; - -import { AeadId } from "@hpke/common"; - -import { NotSupportedError } from "../errors.ts"; +import type { AeadEncryptionContext, AeadInterface } from "@hpke/common"; +import { AeadId, NotSupportedError } from "@hpke/common"; /** * The ExportOnly mode for HPKE AEAD implementing {@link AeadInterface}. diff --git a/packages/core/src/cipherSuiteNative.ts b/packages/core/src/cipherSuiteNative.ts index a08f187b4..0cf4016cb 100644 --- a/packages/core/src/cipherSuiteNative.ts +++ b/packages/core/src/cipherSuiteNative.ts @@ -1,28 +1,37 @@ -import type { AeadInterface } from "@hpke/common"; +import type { + AeadInterface, + KdfInterface, + KemInterface, + KeyScheduleParams, + RecipientContextParams, + SenderContextParams, +} from "@hpke/common"; + +import { + AeadId, + EMPTY, + i2Osp, + INPUT_LENGTH_LIMIT, + InvalidParamError, + MINIMUM_PSK_LENGTH, + Mode, + NativeAlgorithm, +} from "@hpke/common"; + import type { AeadParams } from "./interfaces/aeadParams.ts"; import type { CipherSuiteParams } from "./interfaces/cipherSuiteParams.ts"; import type { RecipientContext, SenderContext, } from "./interfaces/encryptionContext.ts"; -import type { KdfInterface } from "./interfaces/kdfInterface.ts"; -import type { KemInterface } from "./interfaces/kemInterface.ts"; -import type { KeyScheduleParams } from "./interfaces/keyScheduleParams.ts"; -import type { RecipientContextParams } from "./interfaces/recipientContextParams.ts"; import type { CipherSuiteSealResponse } from "./interfaces/responses.ts"; -import type { SenderContextParams } from "./interfaces/senderContextParams.ts"; -import { NativeAlgorithm } from "./algorithm.ts"; -import { EMPTY, INPUT_LENGTH_LIMIT, MINIMUM_PSK_LENGTH } from "./consts.ts"; -import { InvalidParamError } from "./errors.ts"; import { RecipientExporterContextImpl, SenderExporterContextImpl, } from "./exporterContext.ts"; -import { AeadId, Mode } from "@hpke/common"; import { RecipientContextImpl } from "./recipientContext.ts"; import { SenderContextImpl } from "./senderContext.ts"; -import { i2Osp } from "./utils/misc.ts"; // b"base_nonce" // deno-fmt-ignore diff --git a/packages/core/src/encryptionContext.ts b/packages/core/src/encryptionContext.ts index 2ee6a009d..5e436d8ec 100644 --- a/packages/core/src/encryptionContext.ts +++ b/packages/core/src/encryptionContext.ts @@ -1,22 +1,10 @@ -import type { AeadInterface } from "@hpke/common"; +import type { AeadInterface, KdfInterface } from "@hpke/common"; +import { i2Osp, MessageLimitReachedError, xor } from "@hpke/common"; + import type { AeadParams } from "./interfaces/aeadParams.ts"; import type { KeyInfo } from "./interfaces/keyInfo.ts"; -import type { KdfInterface } from "./interfaces/kdfInterface.ts"; -import { MessageLimitReachedError } from "./errors.ts"; import { ExporterContextImpl } from "./exporterContext.ts"; -import { i2Osp } from "./utils/misc.ts"; - -export function xor(a: Uint8Array, b: Uint8Array): Uint8Array { - if (a.byteLength !== b.byteLength) { - throw new Error("xor: different length inputs"); - } - const buf = new Uint8Array(a.byteLength); - for (let i = 0; i < a.byteLength; i++) { - buf[i] = a[i] ^ b[i]; - } - return buf; -} export class EncryptionContextImpl extends ExporterContextImpl { // AEAD id. diff --git a/packages/core/src/exporterContext.ts b/packages/core/src/exporterContext.ts index bfd151ca1..98cb48357 100644 --- a/packages/core/src/exporterContext.ts +++ b/packages/core/src/exporterContext.ts @@ -1,9 +1,13 @@ +import type { KdfInterface } from "@hpke/common"; +import { + ExportError, + INPUT_LENGTH_LIMIT, + InvalidParamError, +} from "@hpke/common"; + import type { Encapsulator } from "./interfaces/encapsulator.ts"; import type { EncryptionContext } from "./interfaces/encryptionContext.ts"; -import type { KdfInterface } from "./interfaces/kdfInterface.ts"; -import { INPUT_LENGTH_LIMIT } from "./consts.ts"; -import { ExportError, InvalidParamError } from "./errors.ts"; import { emitNotSupported } from "./utils/emitNotSupported.ts"; // b"sec" diff --git a/packages/core/src/interfaces/cipherSuiteParams.ts b/packages/core/src/interfaces/cipherSuiteParams.ts index 9c9b04c3e..ab22d3d6a 100644 --- a/packages/core/src/interfaces/cipherSuiteParams.ts +++ b/packages/core/src/interfaces/cipherSuiteParams.ts @@ -1,7 +1,11 @@ -import type { AeadId, KdfId, KemId } from "@hpke/common"; -import type { AeadInterface } from "@hpke/common"; -import type { KdfInterface } from "./kdfInterface.ts"; -import type { KemInterface } from "./kemInterface.ts"; +import type { + AeadId, + AeadInterface, + KdfId, + KdfInterface, + KemId, + KemInterface, +} from "@hpke/common"; /** * The parameters used to configure the `CipherSuite`. diff --git a/packages/core/src/kdfs/hkdf.ts b/packages/core/src/kdfs/hkdf.ts index 2918f7435..c755eddb7 100644 --- a/packages/core/src/kdfs/hkdf.ts +++ b/packages/core/src/kdfs/hkdf.ts @@ -1,9 +1,6 @@ -import type { KdfInterface } from "../interfaces/kdfInterface.ts"; +import type { KdfInterface } from "@hpke/common"; -import { NativeAlgorithm } from "../algorithm.ts"; -import { EMPTY } from "../consts.ts"; -import { InvalidParamError } from "../errors.ts"; -import { KdfId } from "@hpke/common"; +import { EMPTY, InvalidParamError, KdfId, NativeAlgorithm } from "@hpke/common"; // b"HPKE-v1" const HPKE_VERSION = new Uint8Array([72, 80, 75, 69, 45, 118, 49]); diff --git a/packages/core/src/kems/dhkemNative.ts b/packages/core/src/kems/dhkemNative.ts index 4b8742f34..26f0b4bb2 100644 --- a/packages/core/src/kems/dhkemNative.ts +++ b/packages/core/src/kems/dhkemNative.ts @@ -1,11 +1,10 @@ -import { KemId } from "@hpke/common"; +import { Dhkem, Ec, KemId } from "@hpke/common"; + import { HkdfSha256Native, HkdfSha384Native, HkdfSha512Native, } from "../kdfs/hkdf.ts"; -import { Dhkem } from "./dhkem.ts"; -import { Ec } from "./dhkemPrimitives/ec.ts"; export class DhkemP256HkdfSha256Native extends Dhkem { public readonly id: KemId = KemId.DhkemP256HkdfSha256; diff --git a/packages/core/src/kems/hybridkem.ts b/packages/core/src/kems/hybridkem.ts index 0de574561..37eb2293d 100644 --- a/packages/core/src/kems/hybridkem.ts +++ b/packages/core/src/kems/hybridkem.ts @@ -1,20 +1,25 @@ -import type { DhkemInterface } from "../interfaces/dhkemInterface.ts"; -import type { KdfInterface } from "../interfaces/kdfInterface.ts"; -import type { KemInterface } from "../interfaces/kemInterface.ts"; -import type { SenderContextParams } from "../interfaces/senderContextParams.ts"; -import type { RecipientContextParams } from "../interfaces/recipientContextParams.ts"; +import type { + DhkemInterface, + KdfInterface, + KemInterface, + RecipientContextParams, + SenderContextParams, +} from "@hpke/common"; -import { EMPTY } from "../consts.ts"; import { DeserializeError, + EMPTY, InvalidParamError, + KemId, + LABEL_DKP_PRK, + LABEL_SK, NotSupportedError, SerializeError, -} from "../errors.ts"; -import { KemId } from "@hpke/common"; -import { LABEL_DKP_PRK, LABEL_SK } from "../interfaces/dhkemPrimitives.ts"; -import { SUITE_ID_HEADER_KEM } from "../interfaces/kemInterface.ts"; -import { concat, i2Osp, isCryptoKeyPair } from "../utils/misc.ts"; + SUITE_ID_HEADER_KEM, +} from "@hpke/common"; + +import { concat, i2Osp, isCryptoKeyPair } from "@hpke/common"; + import { XCryptoKey } from "../xCryptoKey.ts"; export class Hybridkem implements KemInterface { diff --git a/packages/core/src/recipientContext.ts b/packages/core/src/recipientContext.ts index 5e5786076..340fb04c4 100644 --- a/packages/core/src/recipientContext.ts +++ b/packages/core/src/recipientContext.ts @@ -1,5 +1,5 @@ -import { EMPTY } from "./consts.ts"; -import { OpenError } from "./errors.ts"; +import { EMPTY, OpenError } from "@hpke/common"; + import { EncryptionContextImpl } from "./encryptionContext.ts"; export class RecipientContextImpl extends EncryptionContextImpl { diff --git a/packages/core/src/senderContext.ts b/packages/core/src/senderContext.ts index 5c887a276..0940588a6 100644 --- a/packages/core/src/senderContext.ts +++ b/packages/core/src/senderContext.ts @@ -1,9 +1,8 @@ +import type { KdfInterface } from "@hpke/common"; +import { EMPTY, SealError } from "@hpke/common"; + import type { AeadParams } from "./interfaces/aeadParams.ts"; import type { Encapsulator } from "./interfaces/encapsulator.ts"; -import type { KdfInterface } from "./interfaces/kdfInterface.ts"; - -import { EMPTY } from "./consts.ts"; -import { SealError } from "./errors.ts"; import { EncryptionContextImpl } from "./encryptionContext.ts"; export class SenderContextImpl extends EncryptionContextImpl diff --git a/packages/core/src/utils/emitNotSupported.ts b/packages/core/src/utils/emitNotSupported.ts index d8b0c51ad..2b5296fcf 100644 --- a/packages/core/src/utils/emitNotSupported.ts +++ b/packages/core/src/utils/emitNotSupported.ts @@ -1,4 +1,4 @@ -import { NotSupportedError } from "../errors.ts"; +import { NotSupportedError } from "@hpke/common"; export function emitNotSupported(): Promise { return new Promise((_resolve, reject) => { diff --git a/packages/dhkem-secp256k1/src/dhkemSecp256k1.ts b/packages/dhkem-secp256k1/src/dhkemSecp256k1.ts index 9cae97c2d..2fdca86bc 100644 --- a/packages/dhkem-secp256k1/src/dhkemSecp256k1.ts +++ b/packages/dhkem-secp256k1/src/dhkemSecp256k1.ts @@ -1,4 +1,4 @@ -import { Dhkem, KemId } from "@hpke/core"; +import { Dhkem, KemId } from "@hpke/common"; import { HkdfSha256 } from "@hpke/dhkem-x25519"; import { Secp256k1 } from "./secp256k1.ts"; diff --git a/packages/dhkem-secp256k1/src/secp256k1.ts b/packages/dhkem-secp256k1/src/secp256k1.ts index 3d6957d87..bf94946fa 100644 --- a/packages/dhkem-secp256k1/src/secp256k1.ts +++ b/packages/dhkem-secp256k1/src/secp256k1.ts @@ -1,6 +1,6 @@ import { secp256k1 } from "@noble/curves/secp256k1"; -import type { DhkemPrimitives, KdfInterface } from "@hpke/core"; +import type { DhkemPrimitives, KdfInterface } from "@hpke/common"; import { DeriveKeyPairError, diff --git a/packages/dhkem-x25519/src/dhkemX25519.ts b/packages/dhkem-x25519/src/dhkemX25519.ts index bd48448db..f405276f1 100644 --- a/packages/dhkem-x25519/src/dhkemX25519.ts +++ b/packages/dhkem-x25519/src/dhkemX25519.ts @@ -1,4 +1,4 @@ -import { Dhkem, KemId } from "@hpke/core"; +import { Dhkem, KemId } from "@hpke/common"; import { HkdfSha256 } from "./hkdfSha256.ts"; import { X25519 } from "./x25519.ts"; diff --git a/packages/dhkem-x25519/src/x25519.ts b/packages/dhkem-x25519/src/x25519.ts index f76ee2dd1..3e89adf65 100644 --- a/packages/dhkem-x25519/src/x25519.ts +++ b/packages/dhkem-x25519/src/x25519.ts @@ -1,6 +1,6 @@ import { x25519 } from "@noble/curves/ed25519"; -import type { DhkemPrimitives, KdfInterface } from "@hpke/core"; +import type { DhkemPrimitives, KdfInterface } from "@hpke/common"; import { DeriveKeyPairError, diff --git a/packages/dhkem-x448/src/dhkemX448.ts b/packages/dhkem-x448/src/dhkemX448.ts index 27125cd7c..093743f8c 100644 --- a/packages/dhkem-x448/src/dhkemX448.ts +++ b/packages/dhkem-x448/src/dhkemX448.ts @@ -1,4 +1,4 @@ -import { Dhkem, KemId } from "@hpke/core"; +import { Dhkem, KemId } from "@hpke/common"; import { HkdfSha512 } from "./hkdfSha512.ts"; import { X448 } from "./x448.ts"; diff --git a/packages/dhkem-x448/src/x448.ts b/packages/dhkem-x448/src/x448.ts index 4c4d45a9e..4543a6b67 100644 --- a/packages/dhkem-x448/src/x448.ts +++ b/packages/dhkem-x448/src/x448.ts @@ -1,6 +1,6 @@ import { x448 } from "@noble/curves/ed448"; -import type { DhkemPrimitives, KdfInterface } from "@hpke/core"; +import type { DhkemPrimitives, KdfInterface } from "@hpke/common"; import { DeriveKeyPairError, diff --git a/packages/hpke-js/src/cipherSuite.ts b/packages/hpke-js/src/cipherSuite.ts index a6978c7f8..c6923300c 100644 --- a/packages/hpke-js/src/cipherSuite.ts +++ b/packages/hpke-js/src/cipherSuite.ts @@ -1,4 +1,5 @@ -import type { CipherSuiteParams, KemInterface } from "@hpke/core"; +import type { KemInterface } from "@hpke/common"; +import type { CipherSuiteParams } from "@hpke/core"; import { AeadId, diff --git a/packages/hpke-js/src/kems/dhkemP256.ts b/packages/hpke-js/src/kems/dhkemP256.ts index 6214f3442..34ea33d65 100644 --- a/packages/hpke-js/src/kems/dhkemP256.ts +++ b/packages/hpke-js/src/kems/dhkemP256.ts @@ -1,4 +1,4 @@ -import { Dhkem, Ec, KemId } from "@hpke/core"; +import { Dhkem, Ec, KemId } from "@hpke/common"; import { HkdfSha256 } from "@hpke/dhkem-x25519"; export class DhkemP256HkdfSha256 extends Dhkem { diff --git a/packages/hpke-js/src/kems/dhkemP384.ts b/packages/hpke-js/src/kems/dhkemP384.ts index b45628156..92a69133c 100644 --- a/packages/hpke-js/src/kems/dhkemP384.ts +++ b/packages/hpke-js/src/kems/dhkemP384.ts @@ -1,4 +1,4 @@ -import { Dhkem, Ec, KemId } from "@hpke/core"; +import { Dhkem, Ec, KemId } from "@hpke/common"; import { HkdfSha384 } from "../kdfs/hkdfSha384.ts"; export class DhkemP384HkdfSha384 extends Dhkem { diff --git a/packages/hpke-js/src/kems/dhkemP521.ts b/packages/hpke-js/src/kems/dhkemP521.ts index eec6f2f8f..ba5313b8c 100644 --- a/packages/hpke-js/src/kems/dhkemP521.ts +++ b/packages/hpke-js/src/kems/dhkemP521.ts @@ -1,4 +1,4 @@ -import { Dhkem, Ec, KemId } from "@hpke/core"; +import { Dhkem, Ec, KemId } from "@hpke/common"; import { HkdfSha512 } from "@hpke/dhkem-x448"; diff --git a/packages/hpke-js/test/dhkemPrimitives.test.ts b/packages/hpke-js/test/dhkemPrimitives.test.ts index d67c485f3..0ccb7a528 100644 --- a/packages/hpke-js/test/dhkemPrimitives.test.ts +++ b/packages/hpke-js/test/dhkemPrimitives.test.ts @@ -1,7 +1,7 @@ import { assertEquals, assertRejects } from "@std/assert"; import { describe, it } from "@std/testing/bdd"; -import { DeserializeError, Ec, KemId } from "@hpke/core"; +import { DeserializeError, Ec, KemId } from "@hpke/common"; import { HkdfSha256, X25519 } from "@hpke/dhkem-x25519"; import { HkdfSha512, X448 } from "@hpke/dhkem-x448"; diff --git a/packages/hpke-js/test/encryptionContext.test.ts b/packages/hpke-js/test/encryptionContext.test.ts index 64141d0ac..86f08558c 100644 --- a/packages/hpke-js/test/encryptionContext.test.ts +++ b/packages/hpke-js/test/encryptionContext.test.ts @@ -3,21 +3,21 @@ import { describe, it } from "@std/testing/bdd"; import { AeadId, - Aes128Gcm, DecapError, DeserializeError, EncapError, ExportError, - ExportOnly, + i2Osp, InvalidParamError, KdfId, KemId, NotSupportedError, OpenError, -} from "@hpke/core"; +} from "@hpke/common"; + +import { Aes128Gcm, ExportOnly } from "@hpke/core"; import { HkdfSha256 } from "@hpke/dhkem-x25519"; -import { i2Osp } from "../../core/src/utils/misc.ts"; import { EncryptionContextImpl } from "../../core/src/encryptionContext.ts"; import { CipherSuite } from "../src/cipherSuite.ts"; import { loadSubtleCrypto } from "../../core/test/utils.ts"; diff --git a/packages/hpke-js/test/kdfContext.test.ts b/packages/hpke-js/test/kdfContext.test.ts index 9d9b144eb..c5ab4dde6 100644 --- a/packages/hpke-js/test/kdfContext.test.ts +++ b/packages/hpke-js/test/kdfContext.test.ts @@ -1,13 +1,12 @@ import { assertEquals, assertRejects } from "@std/assert"; import { describe, it } from "@std/testing/bdd"; -import { AeadId, KdfId, KemId } from "@hpke/core"; +import { AeadId, i2Osp, KdfId, KemId } from "@hpke/common"; import { HkdfSha256 } from "@hpke/dhkem-x25519"; import { HkdfSha512 } from "@hpke/dhkem-x448"; import { HkdfSha384 } from "../src/kdfs/hkdfSha384.ts"; -import { i2Osp } from "../../core/src/utils/misc.ts"; import { loadCrypto } from "../../core/test/utils.ts"; // deno-fmt-ignore diff --git a/packages/hybridkem-x25519-kyber768/src/hybridkemX25519Kyber768.ts b/packages/hybridkem-x25519-kyber768/src/hybridkemX25519Kyber768.ts index 55497e745..0a67496dd 100644 --- a/packages/hybridkem-x25519-kyber768/src/hybridkemX25519Kyber768.ts +++ b/packages/hybridkem-x25519-kyber768/src/hybridkemX25519Kyber768.ts @@ -1,6 +1,7 @@ -import type { DhkemInterface } from "@hpke/core"; +import type { DhkemInterface } from "@hpke/common"; -import { Dhkem, Hybridkem, KemId } from "@hpke/core"; +import { Dhkem, KemId } from "@hpke/common"; +import { Hybridkem } from "@hpke/core"; import { HkdfSha256, X25519 } from "@hpke/dhkem-x25519"; import { KemKyber768 } from "./kemKyber768.ts"; diff --git a/packages/hybridkem-x25519-kyber768/src/kemKyber768.ts b/packages/hybridkem-x25519-kyber768/src/kemKyber768.ts index 6b589fa94..ccebfee7a 100644 --- a/packages/hybridkem-x25519-kyber768/src/kemKyber768.ts +++ b/packages/hybridkem-x25519-kyber768/src/kemKyber768.ts @@ -17,8 +17,9 @@ import { KemId, NotSupportedError, SerializeError, - XCryptoKey, -} from "@hpke/core"; +} from "@hpke/common"; + +import { XCryptoKey } from "@hpke/core"; import { Kyber768 } from "./kyber/kyber768.ts"; From e316251d90392d97bfb587fb7d489f9ff6c6a2ad Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 13:36:32 +0900 Subject: [PATCH 03/13] Bump @hpke/common to 0.2.0. --- npm/import_map.json | 2 +- npm/package-lock.json | 2 +- packages/common/deno.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm/import_map.json b/npm/import_map.json index 7cf280ded..465952d78 100644 --- a/npm/import_map.json +++ b/npm/import_map.json @@ -1,7 +1,7 @@ { "imports": { "@deno/dnt": "jsr:@deno/dnt@^0.41.3", - "@hpke/common": "npm:@hpke/common@^0.1.0", + "@hpke/common": "npm:@hpke/common@^0.2.0", "@hpke/core": "npm:@hpke/core@^1.3.0", "@hpke/chacha20poly1305": "npm:@hpke/chacha20poly1305@^1.3.0", "@hpke/dhkem-x25519": "npm:@hpke/dhkem-x25519@^1.3.0", diff --git a/npm/package-lock.json b/npm/package-lock.json index 335338a40..2f5ead6b0 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -167,7 +167,7 @@ }, "packages/common": { "name": "@hpke/common", - "version": "0.1.0", + "version": "0.2.0", "license": "MIT", "devDependencies": { "@deno/shim-deno": "~0.18.0", diff --git a/packages/common/deno.json b/packages/common/deno.json index e4d8c41c3..b1d5a74c5 100644 --- a/packages/common/deno.json +++ b/packages/common/deno.json @@ -1,6 +1,6 @@ { "name": "@hpke/common", - "version": "0.1.0", + "version": "0.2.0", "exports": "./mod.ts", "publish": { "exclude": [ From 937475900132e373f689f227d7bcdfde9b85bd0b Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 14:06:28 +0900 Subject: [PATCH 04/13] Move XCryptoKey and Hybridkem to @hpke/common. --- packages/common/mod.ts | 2 ++ .../{core => common}/src/kems/hybridkem.ts | 26 ++++++++----------- packages/{core => common}/src/xCryptoKey.ts | 0 packages/core/mod.ts | 4 --- packages/dhkem-secp256k1/src/secp256k1.ts | 2 +- packages/dhkem-x25519/src/x25519.ts | 2 +- packages/dhkem-x448/src/x448.ts | 2 +- packages/hpke-js/test/conformanceTester.ts | 4 +-- .../src/hybridkemX25519Kyber768.ts | 3 +-- .../src/kemKyber768.ts | 5 ++-- 10 files changed, 21 insertions(+), 29 deletions(-) rename packages/{core => common}/src/kems/hybridkem.ts (91%) rename packages/{core => common}/src/xCryptoKey.ts (100%) diff --git a/packages/common/mod.ts b/packages/common/mod.ts index 9a25c80d3..b15bf9d77 100644 --- a/packages/common/mod.ts +++ b/packages/common/mod.ts @@ -14,6 +14,8 @@ export { NativeAlgorithm } from "./src/algorithm.ts"; export { AeadId, KdfId, KemId, Mode } from "./src/identifiers.ts"; export { Dhkem } from "./src/kems/dhkem.ts"; export { Ec } from "./src/kems/dhkemPrimitives/ec.ts"; +export { Hybridkem } from "./src/kems/hybridkem.ts"; +export { XCryptoKey } from "./src/xCryptoKey.ts"; export { AEAD_USAGES } from "./src/interfaces/aeadEncryptionContext.ts"; export { LABEL_DKP_PRK, LABEL_SK } from "./src/interfaces/dhkemPrimitives.ts"; diff --git a/packages/core/src/kems/hybridkem.ts b/packages/common/src/kems/hybridkem.ts similarity index 91% rename from packages/core/src/kems/hybridkem.ts rename to packages/common/src/kems/hybridkem.ts index 37eb2293d..27fccbafb 100644 --- a/packages/core/src/kems/hybridkem.ts +++ b/packages/common/src/kems/hybridkem.ts @@ -1,25 +1,21 @@ -import type { - DhkemInterface, - KdfInterface, - KemInterface, - RecipientContextParams, - SenderContextParams, -} from "@hpke/common"; +import type { DhkemInterface } from "../interfaces/dhkemInterface.ts"; +import type { KdfInterface } from "../interfaces/kdfInterface.ts"; +import type { KemInterface } from "../interfaces/kemInterface.ts"; +import type { SenderContextParams } from "../interfaces/senderContextParams.ts"; +import type { RecipientContextParams } from "../interfaces/recipientContextParams.ts"; +import { EMPTY } from "../consts.ts"; import { DeserializeError, - EMPTY, InvalidParamError, - KemId, - LABEL_DKP_PRK, - LABEL_SK, NotSupportedError, SerializeError, - SUITE_ID_HEADER_KEM, -} from "@hpke/common"; - -import { concat, i2Osp, isCryptoKeyPair } from "@hpke/common"; +} from "../errors.ts"; +import { KemId } from "../identifiers.ts"; +import { LABEL_DKP_PRK, LABEL_SK } from "../interfaces/dhkemPrimitives.ts"; +import { SUITE_ID_HEADER_KEM } from "../interfaces/kemInterface.ts"; +import { concat, i2Osp, isCryptoKeyPair } from "../utils/misc.ts"; import { XCryptoKey } from "../xCryptoKey.ts"; export class Hybridkem implements KemInterface { diff --git a/packages/core/src/xCryptoKey.ts b/packages/common/src/xCryptoKey.ts similarity index 100% rename from packages/core/src/xCryptoKey.ts rename to packages/common/src/xCryptoKey.ts diff --git a/packages/core/mod.ts b/packages/core/mod.ts index 872309b4a..6a1dda219 100644 --- a/packages/core/mod.ts +++ b/packages/core/mod.ts @@ -46,7 +46,3 @@ export { HkdfSha384, HkdfSha512, } from "./src/native.ts"; - -// Followings are disclosed for hpke-js family modules -export { Hybridkem } from "./src/kems/hybridkem.ts"; -export { XCryptoKey } from "./src/xCryptoKey.ts"; diff --git a/packages/dhkem-secp256k1/src/secp256k1.ts b/packages/dhkem-secp256k1/src/secp256k1.ts index bf94946fa..003a13733 100644 --- a/packages/dhkem-secp256k1/src/secp256k1.ts +++ b/packages/dhkem-secp256k1/src/secp256k1.ts @@ -8,7 +8,7 @@ import { NotSupportedError, SerializeError, XCryptoKey, -} from "@hpke/core"; +} from "@hpke/common"; const ALG_NAME = "ECDH"; const EMPTY = new Uint8Array(); diff --git a/packages/dhkem-x25519/src/x25519.ts b/packages/dhkem-x25519/src/x25519.ts index 3e89adf65..af8212168 100644 --- a/packages/dhkem-x25519/src/x25519.ts +++ b/packages/dhkem-x25519/src/x25519.ts @@ -8,7 +8,7 @@ import { NotSupportedError, SerializeError, XCryptoKey, -} from "@hpke/core"; +} from "@hpke/common"; const ALG_NAME = "X25519"; const EMPTY = new Uint8Array(); diff --git a/packages/dhkem-x448/src/x448.ts b/packages/dhkem-x448/src/x448.ts index 4543a6b67..83fb2dc45 100644 --- a/packages/dhkem-x448/src/x448.ts +++ b/packages/dhkem-x448/src/x448.ts @@ -8,7 +8,7 @@ import { NotSupportedError, SerializeError, XCryptoKey, -} from "@hpke/core"; +} from "@hpke/common"; const ALG_NAME = "X448"; const EMPTY = new Uint8Array(); diff --git a/packages/hpke-js/test/conformanceTester.ts b/packages/hpke-js/test/conformanceTester.ts index 2a5be13c1..9037b5b5e 100644 --- a/packages/hpke-js/test/conformanceTester.ts +++ b/packages/hpke-js/test/conformanceTester.ts @@ -1,6 +1,6 @@ import { assertEquals, assertRejects } from "@std/assert"; -import type { PreSharedKey, XCryptoKey } from "@hpke/core"; +import type { PreSharedKey, XCryptoKey } from "@hpke/common"; import { AeadId, @@ -9,7 +9,7 @@ import { KdfId, KemId, NotSupportedError, -} from "@hpke/core"; +} from "@hpke/common"; import type { TestVector } from "./testVector.ts"; diff --git a/packages/hybridkem-x25519-kyber768/src/hybridkemX25519Kyber768.ts b/packages/hybridkem-x25519-kyber768/src/hybridkemX25519Kyber768.ts index 0a67496dd..dd9fef7d1 100644 --- a/packages/hybridkem-x25519-kyber768/src/hybridkemX25519Kyber768.ts +++ b/packages/hybridkem-x25519-kyber768/src/hybridkemX25519Kyber768.ts @@ -1,7 +1,6 @@ import type { DhkemInterface } from "@hpke/common"; +import { Dhkem, Hybridkem, KemId } from "@hpke/common"; -import { Dhkem, KemId } from "@hpke/common"; -import { Hybridkem } from "@hpke/core"; import { HkdfSha256, X25519 } from "@hpke/dhkem-x25519"; import { KemKyber768 } from "./kemKyber768.ts"; diff --git a/packages/hybridkem-x25519-kyber768/src/kemKyber768.ts b/packages/hybridkem-x25519-kyber768/src/kemKyber768.ts index ccebfee7a..db18c09d0 100644 --- a/packages/hybridkem-x25519-kyber768/src/kemKyber768.ts +++ b/packages/hybridkem-x25519-kyber768/src/kemKyber768.ts @@ -5,7 +5,7 @@ import type { KemInterface, RecipientContextParams, SenderContextParams, -} from "@hpke/core"; +} from "@hpke/common"; import { DecapError, @@ -17,10 +17,9 @@ import { KemId, NotSupportedError, SerializeError, + XCryptoKey, } from "@hpke/common"; -import { XCryptoKey } from "@hpke/core"; - import { Kyber768 } from "./kyber/kyber768.ts"; const ALG_NAME = "Keyber768"; From ae7efcb3a1fa3fd0d7ccbd5e5fedc9b0477cf691 Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 14:13:07 +0900 Subject: [PATCH 05/13] Usee @hpke/common instead of @hpke/core. --- packages/chacha20poly1305/deno.json | 2 +- packages/chacha20poly1305/src/chacha20Poly1305.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/chacha20poly1305/deno.json b/packages/chacha20poly1305/deno.json index 1644543d0..27b0fd01f 100644 --- a/packages/chacha20poly1305/deno.json +++ b/packages/chacha20poly1305/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/chacha20poly1305 && npm run test", + "test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/common @hpke/chacha20poly1305 && npm run test", "cov": "deno coverage ./coverage --lcov --exclude='test'", "dnt": "deno run --import-map=../../import_map.json -A dnt.ts", "minify": "esbuild ../../npm/packages/chacha20poly1305/esm/chacha20poly1305/mod.js --bundle --format=esm --minify" diff --git a/packages/chacha20poly1305/src/chacha20Poly1305.ts b/packages/chacha20poly1305/src/chacha20Poly1305.ts index 8f579f6cc..ef69065b1 100644 --- a/packages/chacha20poly1305/src/chacha20Poly1305.ts +++ b/packages/chacha20poly1305/src/chacha20Poly1305.ts @@ -1,7 +1,7 @@ import { chacha20poly1305 } from "@noble/ciphers/chacha"; -import type { AeadEncryptionContext, AeadInterface } from "@hpke/core"; -import { AeadId } from "@hpke/core"; +import type { AeadEncryptionContext, AeadInterface } from "@hpke/common"; +import { AeadId } from "@hpke/common"; export class Chacha20Poly1305Context implements AeadEncryptionContext { private _key: Uint8Array; From 0df6a773676b81be8b621a19ca5e521d8530428a Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 14:27:12 +0900 Subject: [PATCH 06/13] Bump @hpke/common to 0.3.0. --- npm/import_map.json | 2 +- npm/package-lock.json | 2 +- packages/common/deno.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm/import_map.json b/npm/import_map.json index 465952d78..9dfd4c8c7 100644 --- a/npm/import_map.json +++ b/npm/import_map.json @@ -1,7 +1,7 @@ { "imports": { "@deno/dnt": "jsr:@deno/dnt@^0.41.3", - "@hpke/common": "npm:@hpke/common@^0.2.0", + "@hpke/common": "npm:@hpke/common@^0.3.0", "@hpke/core": "npm:@hpke/core@^1.3.0", "@hpke/chacha20poly1305": "npm:@hpke/chacha20poly1305@^1.3.0", "@hpke/dhkem-x25519": "npm:@hpke/dhkem-x25519@^1.3.0", diff --git a/npm/package-lock.json b/npm/package-lock.json index 2f5ead6b0..bfe47b081 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -167,7 +167,7 @@ }, "packages/common": { "name": "@hpke/common", - "version": "0.2.0", + "version": "0.3.0", "license": "MIT", "devDependencies": { "@deno/shim-deno": "~0.18.0", diff --git a/packages/common/deno.json b/packages/common/deno.json index b1d5a74c5..3b9a0765e 100644 --- a/packages/common/deno.json +++ b/packages/common/deno.json @@ -1,6 +1,6 @@ { "name": "@hpke/common", - "version": "0.2.0", + "version": "0.3.0", "exports": "./mod.ts", "publish": { "exclude": [ From eb476fb34347e0e572fd6cafaa132fa7ade79295 Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 14:32:46 +0900 Subject: [PATCH 07/13] Unify import from @hpke/common. --- packages/core/src/aeads/aesGcm.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/src/aeads/aesGcm.ts b/packages/core/src/aeads/aesGcm.ts index e63497c40..de81c5c36 100644 --- a/packages/core/src/aeads/aesGcm.ts +++ b/packages/core/src/aeads/aesGcm.ts @@ -1,8 +1,8 @@ -import type { AeadEncryptionContext, AeadInterface } from "@hpke/common"; - -import { NativeAlgorithm } from "@hpke/common"; -import { AeadId } from "@hpke/common"; -import { AEAD_USAGES } from "@hpke/common"; +import type { + AeadEncryptionContext, + AeadInterface, +} from "@hpke/common"; +import { AeadId, AEAD_USAGES, NativeAlgorithm } from "@hpke/common"; export class AesGcmContext extends NativeAlgorithm implements AeadEncryptionContext { From 7ae6963471a88cb964f5f18cd2f629e5b3fa756c Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 14:48:54 +0900 Subject: [PATCH 08/13] 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" From 0128533cc2968347779fdd2f3eb7d7f5c9bceb50 Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 14:52:38 +0900 Subject: [PATCH 09/13] Bump @hpke/common to 0.4.0. --- npm/import_map.json | 2 +- npm/package-lock.json | 2 +- packages/common/deno.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm/import_map.json b/npm/import_map.json index 9dfd4c8c7..136b30a09 100644 --- a/npm/import_map.json +++ b/npm/import_map.json @@ -1,7 +1,7 @@ { "imports": { "@deno/dnt": "jsr:@deno/dnt@^0.41.3", - "@hpke/common": "npm:@hpke/common@^0.3.0", + "@hpke/common": "npm:@hpke/common@^0.4.0", "@hpke/core": "npm:@hpke/core@^1.3.0", "@hpke/chacha20poly1305": "npm:@hpke/chacha20poly1305@^1.3.0", "@hpke/dhkem-x25519": "npm:@hpke/dhkem-x25519@^1.3.0", diff --git a/npm/package-lock.json b/npm/package-lock.json index bfe47b081..b9b29843d 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -167,7 +167,7 @@ }, "packages/common": { "name": "@hpke/common", - "version": "0.3.0", + "version": "0.4.0", "license": "MIT", "devDependencies": { "@deno/shim-deno": "~0.18.0", diff --git a/packages/common/deno.json b/packages/common/deno.json index 3b9a0765e..8230906c4 100644 --- a/packages/common/deno.json +++ b/packages/common/deno.json @@ -1,6 +1,6 @@ { "name": "@hpke/common", - "version": "0.3.0", + "version": "0.4.0", "exports": "./mod.ts", "publish": { "exclude": [ From 6273cfd42d9a317f7005cc410e9d59292cbe21a0 Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 15:02:31 +0900 Subject: [PATCH 10/13] Use LABEL_* defined on @hpke/common. --- packages/dhkem-secp256k1/src/secp256k1.ts | 10 +++------- packages/dhkem-x25519/src/x25519.ts | 10 +++------- packages/dhkem-x448/src/x448.ts | 10 +++------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/packages/dhkem-secp256k1/src/secp256k1.ts b/packages/dhkem-secp256k1/src/secp256k1.ts index 003a13733..7f641ee57 100644 --- a/packages/dhkem-secp256k1/src/secp256k1.ts +++ b/packages/dhkem-secp256k1/src/secp256k1.ts @@ -5,21 +5,17 @@ import type { DhkemPrimitives, KdfInterface } from "@hpke/common"; import { DeriveKeyPairError, DeserializeError, + EMPTY, + LABEL_DKP_PRK, + LABEL_SK, NotSupportedError, SerializeError, XCryptoKey, } from "@hpke/common"; const ALG_NAME = "ECDH"; -const EMPTY = new Uint8Array(); // The key usages for KEM. const KEM_USAGES: KeyUsage[] = ["deriveBits"]; -// b"dkp_prk" deno-fmt-ignore -const LABEL_DKP_PRK: Uint8Array = new Uint8Array([ - 100, 107, 112, 95, 112, 114, 107, -]); -// b"sk" -const LABEL_SK: Uint8Array = new Uint8Array([115, 107]); export class Secp256k1 implements DhkemPrimitives { private _hkdf: KdfInterface; diff --git a/packages/dhkem-x25519/src/x25519.ts b/packages/dhkem-x25519/src/x25519.ts index af8212168..609a934ee 100644 --- a/packages/dhkem-x25519/src/x25519.ts +++ b/packages/dhkem-x25519/src/x25519.ts @@ -5,21 +5,17 @@ import type { DhkemPrimitives, KdfInterface } from "@hpke/common"; import { DeriveKeyPairError, DeserializeError, + EMPTY, + LABEL_DKP_PRK, + LABEL_SK, NotSupportedError, SerializeError, XCryptoKey, } from "@hpke/common"; const ALG_NAME = "X25519"; -const EMPTY = new Uint8Array(); // The key usages for KEM. const KEM_USAGES: KeyUsage[] = ["deriveBits"]; -// b"dkp_prk" deno-fmt-ignore -const LABEL_DKP_PRK: Uint8Array = new Uint8Array([ - 100, 107, 112, 95, 112, 114, 107, -]); -// b"sk" -const LABEL_SK: Uint8Array = new Uint8Array([115, 107]); function base64UrlToBytes(v: string): Uint8Array { const base64 = v.replace(/-/g, "+").replace(/_/g, "/"); diff --git a/packages/dhkem-x448/src/x448.ts b/packages/dhkem-x448/src/x448.ts index 83fb2dc45..114ec8340 100644 --- a/packages/dhkem-x448/src/x448.ts +++ b/packages/dhkem-x448/src/x448.ts @@ -5,21 +5,17 @@ import type { DhkemPrimitives, KdfInterface } from "@hpke/common"; import { DeriveKeyPairError, DeserializeError, + EMPTY, + LABEL_DKP_PRK, + LABEL_SK, NotSupportedError, SerializeError, XCryptoKey, } from "@hpke/common"; const ALG_NAME = "X448"; -const EMPTY = new Uint8Array(); // The key usages for KEM. const KEM_USAGES: KeyUsage[] = ["deriveBits"]; -// b"dkp_prk" deno-fmt-ignore -const LABEL_DKP_PRK: Uint8Array = new Uint8Array([ - 100, 107, 112, 95, 112, 114, 107, -]); -// b"sk" -const LABEL_SK: Uint8Array = new Uint8Array([115, 107]); function base64UrlToBytes(v: string): Uint8Array { const base64 = v.replace(/-/g, "+").replace(/_/g, "/"); From 01ff8f402c1303ea36c2d255002023ada5337d3b Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 15:08:16 +0900 Subject: [PATCH 11/13] Disclose KEM_USAGES on @hpke/common. --- packages/common/mod.ts | 1 + packages/dhkem-secp256k1/src/secp256k1.ts | 3 +-- packages/dhkem-x25519/src/x25519.ts | 3 +-- packages/dhkem-x448/src/x448.ts | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/common/mod.ts b/packages/common/mod.ts index 8bf6c7204..a3844b740 100644 --- a/packages/common/mod.ts +++ b/packages/common/mod.ts @@ -24,6 +24,7 @@ export { } from "./src/kdfs/hkdf.ts"; export { AEAD_USAGES } from "./src/interfaces/aeadEncryptionContext.ts"; +export { KEM_USAGES } from "./src/interfaces/dhkemPrimitives.ts"; export { LABEL_DKP_PRK, LABEL_SK } from "./src/interfaces/dhkemPrimitives.ts"; export { SUITE_ID_HEADER_KEM } from "./src/interfaces/kemInterface.ts"; export { EMPTY, INPUT_LENGTH_LIMIT, MINIMUM_PSK_LENGTH } from "./src/consts.ts"; diff --git a/packages/dhkem-secp256k1/src/secp256k1.ts b/packages/dhkem-secp256k1/src/secp256k1.ts index 7f641ee57..b80dbad06 100644 --- a/packages/dhkem-secp256k1/src/secp256k1.ts +++ b/packages/dhkem-secp256k1/src/secp256k1.ts @@ -6,6 +6,7 @@ import { DeriveKeyPairError, DeserializeError, EMPTY, + KEM_USAGES, LABEL_DKP_PRK, LABEL_SK, NotSupportedError, @@ -14,8 +15,6 @@ import { } from "@hpke/common"; const ALG_NAME = "ECDH"; -// The key usages for KEM. -const KEM_USAGES: KeyUsage[] = ["deriveBits"]; export class Secp256k1 implements DhkemPrimitives { private _hkdf: KdfInterface; diff --git a/packages/dhkem-x25519/src/x25519.ts b/packages/dhkem-x25519/src/x25519.ts index 609a934ee..52e7916be 100644 --- a/packages/dhkem-x25519/src/x25519.ts +++ b/packages/dhkem-x25519/src/x25519.ts @@ -6,6 +6,7 @@ import { DeriveKeyPairError, DeserializeError, EMPTY, + KEM_USAGES, LABEL_DKP_PRK, LABEL_SK, NotSupportedError, @@ -14,8 +15,6 @@ import { } from "@hpke/common"; const ALG_NAME = "X25519"; -// The key usages for KEM. -const KEM_USAGES: KeyUsage[] = ["deriveBits"]; function base64UrlToBytes(v: string): Uint8Array { const base64 = v.replace(/-/g, "+").replace(/_/g, "/"); diff --git a/packages/dhkem-x448/src/x448.ts b/packages/dhkem-x448/src/x448.ts index 114ec8340..b386eeede 100644 --- a/packages/dhkem-x448/src/x448.ts +++ b/packages/dhkem-x448/src/x448.ts @@ -6,6 +6,7 @@ import { DeriveKeyPairError, DeserializeError, EMPTY, + KEM_USAGES, LABEL_DKP_PRK, LABEL_SK, NotSupportedError, @@ -14,8 +15,6 @@ import { } from "@hpke/common"; const ALG_NAME = "X448"; -// The key usages for KEM. -const KEM_USAGES: KeyUsage[] = ["deriveBits"]; function base64UrlToBytes(v: string): Uint8Array { const base64 = v.replace(/-/g, "+").replace(/_/g, "/"); From a9a215e8d3750bd06f346ad4ded223b04e9bcfe7 Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 15:13:07 +0900 Subject: [PATCH 12/13] Add test/ to publish:exlude. --- packages/common/deno.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/common/deno.json b/packages/common/deno.json index 8230906c4..9e9b48655 100644 --- a/packages/common/deno.json +++ b/packages/common/deno.json @@ -5,6 +5,7 @@ "publish": { "exclude": [ "dnt.ts", + "test/", "tsconfig.json" ] }, @@ -14,7 +15,8 @@ "**/*.json", "dnt.ts", "mod.ts", - "src/" + "src/", + "test/" ], "exclude": [ "**/*/*.js", @@ -28,7 +30,8 @@ "**/*.json", "dnt.ts", "mod.ts", - "src/" + "src/", + "test/" ], "exclude": [ "**/*/*.js", From 421c00f40f89eb300e60ec17832a26f4b5cf91bc Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 15:16:50 +0900 Subject: [PATCH 13/13] Bump @hpke/common to 0.5.0. --- npm/import_map.json | 2 +- npm/package-lock.json | 2 +- packages/common/deno.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm/import_map.json b/npm/import_map.json index 136b30a09..f77c96784 100644 --- a/npm/import_map.json +++ b/npm/import_map.json @@ -1,7 +1,7 @@ { "imports": { "@deno/dnt": "jsr:@deno/dnt@^0.41.3", - "@hpke/common": "npm:@hpke/common@^0.4.0", + "@hpke/common": "npm:@hpke/common@^0.5.0", "@hpke/core": "npm:@hpke/core@^1.3.0", "@hpke/chacha20poly1305": "npm:@hpke/chacha20poly1305@^1.3.0", "@hpke/dhkem-x25519": "npm:@hpke/dhkem-x25519@^1.3.0", diff --git a/npm/package-lock.json b/npm/package-lock.json index b9b29843d..2f92807a1 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -167,7 +167,7 @@ }, "packages/common": { "name": "@hpke/common", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "devDependencies": { "@deno/shim-deno": "~0.18.0", diff --git a/packages/common/deno.json b/packages/common/deno.json index 9e9b48655..0765b3fea 100644 --- a/packages/common/deno.json +++ b/packages/common/deno.json @@ -1,6 +1,6 @@ { "name": "@hpke/common", - "version": "0.4.0", + "version": "0.5.0", "exports": "./mod.ts", "publish": { "exclude": [