Skip to content

Commit

Permalink
Add node:crypto xchacha20 implementation (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas authored Oct 22, 2024
1 parent 0671d42 commit 76a16fc
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 846 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ jobs:
cache-dependency-path: pnpm-lock.yaml

- run: pnpm install && pnpm test -- --bail 1
- run: pnpm run build && npm publish --dry-run

- uses: codecov/codecov-action@v4
if: matrix.os == 'ubuntu-latest' && matrix.node == 22
with:
token: ${{ secrets.CODECOV_TOKEN }}
- run: pnpm run build && npm publish --dry-run

check-runtimes:
runs-on: ubuntu-latest
Expand All @@ -49,8 +50,7 @@ jobs:
with:
deno-version: v2.x

- run: pnpm install && pnpm build
- run: cd example/runtime && bun install
- run: pnpm install && pnpm build && cd example/runtime && pnpm install
- run: bun run example/runtime/main.js
- run: deno run --allow-read example/runtime/main.js
- run: node example/runtime/main.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ dist
# example
bun.lockb
deno.lock
example/browser/pnpm-lock.yaml
example/runtime/pnpm-lock.yaml
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

- Add examples
- Update documentation
- Migrate to vitest
- Migrate to [vitest](https://vitest.dev/)
- Export all modules to allow full customization
- Introduce [`@ecies/ciphers`](https://github.com/ecies/js-ciphers) as symmetric cipher adapter for different platforms
- Use pure JS (`@noble/ciphers`) AES implementation if running in browsers to improve compatibility
- Use `node:crypto`'s chacha20 implementation on Node runtime to improve performance

## 0.4.1 ~ 0.4.8

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This is the JavaScript/TypeScript version of [eciespy](https://github.com/ecies/
npm install eciesjs
```

We recommend using the latest Node runtime although it's still possible to install on old versions (but at least node 16).
We recommend using the latest Node runtime although it's still possible to install on old versions (as long as 16+).

## Quick Start

Expand All @@ -25,22 +25,22 @@ import { PrivateKey, decrypt, encrypt } from "eciesjs";

const sk = new PrivateKey()
const data = Buffer.from("hello world🌍")
const decrypted = decrypt(sk.secret, encrypt(sk.publicKey.toHex(), data))
const decrypted = decrypt(sk.secret, encrypt(sk.publicKey.compressed, data))
console.log(Buffer.from(decrypted).toString())
```

Run the example code above:
Or run the example code:

```bash
$ pnpm build && cd example && pnpm install && node index.js
$ pnpm install && pnpm build && cd example/runtime && pnpm install && node main.js
hello world🌍
```

See [Configuration](#configuration) to control with more granularity.

## Browser Support

This library is browser-friendly, check the [`example/browser`](./example/browser) directory for details. Currently it's necessary to polyfill some node modules (like `node:crypto`, `Buffer`). From v0.5.0, it can run in browsers without polyfill.
This library is browser-friendly, check the [`example/browser`](./example/browser) directory for details. Currently it's necessary to polyfill `Buffer` for backward compatibility. From v0.5.0, it can run in browsers as is.

If you want a WASM version to run directly in modern browsers or on some blockchains, check [`ecies-wasm`](https://github.com/ecies/rs-wasm).

Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For production, run `pnpm build && pnpm preview`

## Runtime example (Node/Bun/Deno)

Run `cd runtime && bun install`
Run `cd runtime && pnpm install`

### Basic usage

Expand Down
Loading

0 comments on commit 76a16fc

Please sign in to comment.