Skip to content

Commit

Permalink
Introduce @hpke/common for @hpke/core and @hpke/chacha20poly1305.
Browse files Browse the repository at this point in the history
  • Loading branch information
dajiaji committed Oct 5, 2024
1 parent 20d58b2 commit 51293f7
Show file tree
Hide file tree
Showing 33 changed files with 257 additions and 29 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci_browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci_node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 11 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"workspace": [
"./packages/common",
"./packages/core",
"./packages/chacha20poly1305",
"./packages/dhkem-x25519",
Expand Down Expand Up @@ -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",
Expand All @@ -60,32 +63,36 @@
"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",
"dnt:dhkem-x448": "cd packages/dhkem-x448 && deno task dnt",
"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",
"npm-link:dhkem-x448": "cd npm/packages/dhkem-x448 && npm link",
"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",
"npm-pack:dhkem-x448": "cd npm/packages/dhkem-x448 && npm pack --dry-run",
"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",
Expand Down
1 change: 1 addition & 0 deletions npm/import_map.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 17 additions & 0 deletions npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "hpke-js",
"private": true,
"workspaces": [
"packages/common",
"packages/core",
"packages/chacha20poly1305",
"packages/dhkem-x25519",
Expand Down
1 change: 1 addition & 0 deletions packages/chacha20poly1305/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"module": "es2022",
"target": "es2022",
"paths": {
"@hpke/common": ["../common/mod.ts"],
"@hpke/core": ["../core/mod.ts"],
"@noble/*": ["../../npm/node_modules/@noble/*"]
},
Expand Down
21 changes: 21 additions & 0 deletions packages/common/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 24 additions & 0 deletions packages/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h1 align="center">@hpke/common</h1>

<div align="center">
<a href="https://jsr.io/@hpke/common"><img src="https://jsr.io/badges/@hpke/common" alt="JSR"/></a>
</div>

<div align="center">
A TypeScript <a href="https://datatracker.ietf.org/doc/html/rfc9180">Hybrid Public Key Encryption (HPKE)</a> internal-use common module for <a href="https://jsr.io/@hpke">@hpke family modules</a>.
</div>

<div align="center">
</div>

## 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.
45 changes: 45 additions & 0 deletions packages/common/deno.json
Original file line number Diff line number Diff line change
@@ -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/chacha20poly1305/mod.js --bundle --format=esm --minify"
}
}
64 changes: 64 additions & 0 deletions packages/common/dnt.ts
Original file line number Diff line number Diff line change
@@ -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");
4 changes: 4 additions & 0 deletions packages/common/mod.ts
Original file line number Diff line number Diff line change
@@ -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";
File renamed without changes.
6 changes: 3 additions & 3 deletions packages/core/mod.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/aeads/aesGcm.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/aeads/exportOnly.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Loading

0 comments on commit 51293f7

Please sign in to comment.