From 40855050227a843ccbc725135c013ec664b6daa8 Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 5 Oct 2024 10:07:32 +0900 Subject: [PATCH] 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/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 + 33 files changed, 257 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%) 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..2da2c1552 --- /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/chacha20poly1305/esm/chacha20poly1305/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/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 },