Skip to content

Commit 30ecfca

Browse files
committed
Use node:crypto chacha20-poly1305 on deno
1 parent 5cc507d commit 30ecfca

7 files changed

Lines changed: 119 additions & 118 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ jobs:
7272

7373
- run: pnpm install && pnpm build && cd example && pnpm install
7474

75+
- run: deno task test
76+
7577
- name: check main.js
7678
run: |
7779
./scripts/check-runtime.sh example/main.js

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Bump dependencies
66
- Bump emitted JavaScript target to es2021
7+
- Use `node:crypto`'s chacha20-poly1305 implementation on deno (>=2.7.10)
78

89
## 0.2.5
910

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Otherwise (e.g. browser, react native), it'll use [`@noble/ciphers`](https://git
1717
| ------------ | ---------------- | ---------------- |
1818
| Node | `node:crypto`| `node:crypto`|
1919
| Bun | `node:crypto`| `@noble/ciphers` |
20-
| Deno | `node:crypto`| `@noble/ciphers` |
20+
| Deno | `node:crypto`| `node:crypto` |
2121
| Browser | `@noble/ciphers` | `@noble/ciphers` |
2222
| React Native | `@noble/ciphers` | `@noble/ciphers` |
2323

@@ -66,6 +66,6 @@ If key is fixed and nonce is less than 16 bytes, **avoid randomly generated nonc
6666

6767
## Known limitations
6868

69-
- `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.
70-
- Currently (Apr 2026), `node:crypto`'s `chacha20-poly1305` is neither supported on [deno](https://github.com/denoland/deno/issues/28411) nor [bun](https://github.com/oven-sh/bun/issues/8072), `@noble/ciphers`'s implementation is used on both platforms instead.
69+
- `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/deno.
70+
- Currently (Apr 2026), `node:crypto`'s `chacha20-poly1305` is not supported on [bun](https://github.com/oven-sh/bun/issues/8072), `@noble/ciphers`'s implementation is used instead. From deno 2.7.10, `node:crypto`'s `chacha20-poly1305` is [supported](https://github.com/denoland/deno/issues/28411). Please upgrade deno to use native implementation for better performance.
7171
- Some old versions of `deno` [did not support](https://github.com/denoland/deno/discussions/17964#discussioncomment-10917259) **indirect** conditional exports. For example, if a library uses `@ecies/ciphers`, client code of that library might fall back to the `node:crypto` implementation and would not work properly, specifically `aes-256-gcm` and `chacha20-poly1305`. If you found such a problem, upgrade deno and run with `--conditions deno` (>=2.4.0) or `--unstable-node-conditions deno`(>=2.3.6,<2.4.0).

example/main.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { aes256cbc, aes256gcm } from "@ecies/ciphers/aes";
2-
import { xchacha20 } from "@ecies/ciphers/chacha";
2+
import { chacha20, xchacha20 } from "@ecies/ciphers/chacha";
33

44
import { randomBytes } from "@noble/ciphers/webcrypto";
55

@@ -27,6 +27,12 @@ const ciphers = [
2727
callback: aes256cbc,
2828
aad: undefined,
2929
},
30+
{
31+
keyLength: 32,
32+
nonceLength: 12,
33+
callback: chacha20,
34+
aad: randomBytes(16),
35+
},
3036
{
3137
keyLength: 32,
3238
nonceLength: 24,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"engines": {
1616
"node": ">=16",
1717
"bun": ">=1",
18-
"deno": ">=2"
18+
"deno": ">=2.7.10"
1919
},
2020
"keywords": [
2121
"cryptography",
@@ -45,7 +45,7 @@
4545
"types": "./dist/chacha/node.d.ts",
4646
"browser": "./dist/chacha/noble.js",
4747
"react-native": "./dist/chacha/noble.js",
48-
"deno": "./dist/chacha/noble.js",
48+
"deno": "./dist/chacha/node.js",
4949
"bun": "./dist/chacha/noble.js",
5050
"default": "./dist/chacha/node.js"
5151
}

0 commit comments

Comments
 (0)