Skip to content

Commit 0f54c42

Browse files
committed
Use node:crypto aes on deno
1 parent 402f970 commit 0f54c42

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## 0.2.3
4+
5+
- Use `node:crypto`'s aes implementation on deno
6+
37
## 0.2.2
48

59
- Add `chacha20-poly1305` support

README.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

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

1010
Node/Pure JavaScript symmetric ciphers adapter.
1111

12-
On browsers (or React Native, deno), it'll use [`@noble/ciphers`](https://github.com/paulmillr/noble-ciphers)'s implementation for compatibility.
12+
If native implementations are available on some platforms (e.g. node, deno, bun), it'll use [`node:crypto`](https://nodejs.org/api/crypto.html#cryptocreatecipherivalgorithm-key-iv-options) for efficiency.
1313

14-
On node (or bun), it'll use [`node:crypto`](https://nodejs.org/api/crypto.html#cryptocreatecipherivalgorithm-key-iv-options)'s implementation for efficiency.
14+
Otherwise (e.g. browser, react native), it'll use [`@noble/ciphers`](https://github.com/paulmillr/noble-ciphers) for compatibility.
15+
16+
| | aes | chacha |
17+
| ------------ | ---------------- | ---------------- |
18+
| Node | `node:crypto`| `node:crypto`|
19+
| Bun | `node:crypto`| `@noble/ciphers` |
20+
| Deno | `node:crypto`| `@noble/ciphers` |
21+
| Browser | `@noble/ciphers` | `@noble/ciphers` |
22+
| React Native | `@noble/ciphers` | `@noble/ciphers` |
1523

1624
> [!NOTE]
1725
> You may need to polyfill [`crypto.getRandomValues`](https://github.com/LinusU/react-native-get-random-values) for React Native.
@@ -58,5 +66,5 @@ If key is fixed and nonce is less than 16 bytes, avoid randomly generated nonce.
5866
## Known limitations
5967

6068
- `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.
61-
- 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.
62-
- `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`.
69+
- Currently (Mar 2025), `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.
70+
- Some old versions of `deno` [do not support](https://github.com/denoland/deno/discussions/17964#discussioncomment-10917259) **indirect** conditional exports. If you use this library to build another library, client code of your library may fall back to the `node:crypto` implementation and not work properly, specifically `aes-256-gcm` (16 bytes nonce) and `chacha20-poly1305`.

example/main.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ const ciphers = [
3838
for (const { keyLength, nonceLength, callback, aad } of ciphers) {
3939
const key = randomBytes(keyLength);
4040
const nonce = randomBytes(nonceLength);
41+
console.log(`${callback.name} (nonce length ${nonce.length}) decrypted:`);
4142
const cipher = callback(key, nonce, aad);
42-
console.log(
43-
`${callback.name} (nonce length ${nonce.length}) decrypted:`,
44-
decoder.decode(cipher.decrypt(cipher.encrypt(msg)))
45-
);
43+
console.log(decoder.decode(cipher.decrypt(cipher.encrypt(msg))));
4644
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"types": "./dist/aes/node.d.ts",
3838
"browser": "./dist/aes/noble.js",
3939
"react-native": "./dist/aes/noble.js",
40-
"deno": "./dist/aes/noble.js",
40+
"deno": "./dist/aes/deno.js",
4141
"bun": "./dist/aes/node.js",
4242
"default": "./dist/aes/node.js"
4343
},

0 commit comments

Comments
 (0)