Skip to content

Commit

Permalink
Add chacha20-poly1305 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas authored Nov 28, 2024
1 parent 71ad109 commit 402f970
Show file tree
Hide file tree
Showing 16 changed files with 494 additions and 370 deletions.
7 changes: 5 additions & 2 deletions .cspell.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
"chacha",
"ecies",
"hchacha",
"webcrypto",
"xchacha"
],
"ignorePaths": [
"LICENSE",
".git",
".github",
".gitignore",
".cspell.jsonc",
"LICENSE",
"package.json"
"settings.json",
"package.json",
"pnpm-lock.yaml"
]
}
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ jobs:
- name: check main.js
run: |
./scripts/check-runtime.sh example/main.js
- name: check main.js on mininum supported node version
run: |
curl -sL https://nodejs.org/download/release/v16.0.0/node-v16.0.0-linux-x64.tar.gz | tar -xz
./node-v16.0.0-linux-x64/bin/node example/main.js && rm -rf node-v16.0.0-linux-x64
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# Release Notes

## 0.2.2

- Add `chacha20-poly1305` support
- Bump dependencies
- Add minimum supported node (16.0.0) runtime check in CI

## 0.2.1

- Add React Native package exports

## 0.2.0

- Add xchacha20-poly1305 support
- Add `xchacha20-poly1305` support

## 0.1.0

- First beta version release with aes-256-gcm and aes-256-cbc support
- First beta version release with `aes-256-gcm` and `aes-256-cbc` support
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# @ecies/ciphers

[![License](https://img.shields.io/github/license/ecies/js-ciphers.svg)](https://github.com/ecies/js-ciphers)
[![Npm Package](https://img.shields.io/npm/v/@ecies/ciphers.svg)](https://www.npmjs.com/package/@ecies/ciphers)
[![NPM Package](https://img.shields.io/npm/v/@ecies/ciphers.svg)](https://www.npmjs.com/package/@ecies/ciphers)
![NPM Downloads](https://img.shields.io/npm/dm/@ecies/ciphers)
[![Install size](https://packagephobia.com/badge?p=@ecies/ciphers)](https://packagephobia.com/result?p=@ecies/ciphers)
[![CI](https://img.shields.io/github/actions/workflow/status/ecies/js-ciphers/ci.yml)](https://github.com/ecies/js-ciphers/actions)
[![Codecov](https://img.shields.io/codecov/c/github/ecies/js-ciphers.svg)](https://codecov.io/gh/ecies/js-ciphers)

Expand All @@ -15,6 +17,8 @@ On node (or bun), it'll use [`node:crypto`](https://nodejs.org/api/crypto.html#c
> You may need to polyfill [`crypto.getRandomValues`](https://github.com/LinusU/react-native-get-random-values) for React Native.
>
> There are some limitations, see [Known limitations](#known-limitations) below.
>
> This library is tree-shakeable, unused code will be excluded by bundlers.
Check the [example](./example/) folder for bun/deno usage.

Expand Down Expand Up @@ -44,11 +48,15 @@ The API follows `@noble/ciphers`'s API for ease of use, you can check their [exa
- `aes-256-cbc`
- **Only for legacy applications**. You should use `xchacha20-poly1305` or `aes-256-gcm` as possible.
- Nonce is always 16 bytes.
- `chacha20-poly1305`
- Nonce is always 12 bytes.
- `xchacha20-poly1305`
- Nonce is always 24 bytes.

If key is fixed and nonce is less than 16 bytes, avoid randomly generated nonce.

## Known limitations

- `xchacha20-poly1305` is implemented with pure JS [`hchacha`](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha#section-2.2) function and `node:crypto`'s `chacha20-poly1305`.
- Currently (Oct 2024), `node:crypto`'s `chacha20-poly1305` is not supported on deno and [bun](https://github.com/oven-sh/bun/issues/8072), `@noble/ciphers`'s implementation is used on both platforms instead.
- `xchacha20-poly1305` is implemented with pure JS [`hchacha20`](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha#section-2.2) function and `node:crypto`'s `chacha20-poly1305` on node.
- Currently (Nov 2024), `node:crypto`'s `chacha20-poly1305` is not supported on deno and [bun](https://github.com/oven-sh/bun/issues/8072), `@noble/ciphers`'s implementation is used on both platforms instead.
- `deno` does not support **indirect** conditional exports. If you use this library to build another library, client code of your library probably falls back to the `node:crypto` implementation and may not work properly, specifically `aes-256-gcm` (16 bytes nonce) and `chacha20-poly1305`.
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "git+https://github.com/ecies/js-ciphers.git"
},
"version": "0.2.1",
"version": "0.2.2",
"engines": {
"node": ">=16",
"bun": ">=1",
Expand All @@ -22,12 +22,15 @@
"cipher",
"aes",
"chacha",
"chacha20",
"chacha20poly1305",
"xchacha20",
"xchacha20poly1305"
],
"files": [
"dist"
],
"main": "dist/index.js",
"exports": {
".": null,
"./aes": {
Expand Down Expand Up @@ -56,10 +59,10 @@
"@noble/ciphers": "^1.0.0"
},
"devDependencies": {
"@types/node": "^22.8.6",
"@vitest/coverage-v8": "^2.1.4",
"typescript": "^5.6.3",
"vitest": "^2.1.4"
"@types/node": "^22.10.1",
"@vitest/coverage-v8": "^2.1.6",
"typescript": "^5.7.2",
"vitest": "^2.1.6"
},
"packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee"
"packageManager": "pnpm@9.14.2+sha512.6e2baf77d06b9362294152c851c4f278ede37ab1eba3a55fda317a4a17b209f4dbb973fb250a77abc463a341fcb1f17f17cfa24091c4eb319cda0d9b84278387"
}
Loading

0 comments on commit 402f970

Please sign in to comment.