Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

# Changelog

## 0.4.17

- Bump dependencies
- Prepare for ESM

## 0.4.16

- Bump dependencies
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@ For security, see [Security](#security).
## Quick Start

```typescript
// example/runtime/quick-start.js
import { PrivateKey, decrypt, encrypt } from "eciesjs";

const encoder = new TextEncoder();
const decoder = new TextDecoder();

const sk = new PrivateKey();
const data = Buffer.from("hello world🌍");
const data = encoder.encode("hello world🌍");
const decrypted = decrypt(sk.secret, encrypt(sk.publicKey.toBytes(), data));
console.log(Buffer.from(decrypted).toString());
console.log(decoder.decode(decrypted));
```

Or run the example code:

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

Expand All @@ -56,19 +60,19 @@ See [Configuration](#configuration) to control with more granularity.

Parameters:

- **receiverRawPK** - Receiver's public key, hex `string` or `Uint8Array`
- **data** - Data to encrypt
- `receiverRawPK` - Receiver's public key, hex `string` or `Uint8Array`
- `data` - Data to encrypt

Returns: **Buffer**
Returns: `Buffer`

### `decrypt(receiverRawSK: string | Uint8Array, data: Uint8Array): Buffer`

Parameters:

- **receiverRawSK** - Receiver's private key, hex `string` or `Uint8Array`
- **data** - Data to decrypt
- `receiverRawSK` - Receiver's private key, hex `string` or `Uint8Array`
- `data` - Data to decrypt

Returns: **Buffer**
Returns: `Buffer`

### `PrivateKey`

Expand Down
2 changes: 1 addition & 1 deletion biome.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.2.5/schema.json",
"$schema": "https://biomejs.dev/schemas/2.3.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
Expand Down
2 changes: 1 addition & 1 deletion example/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"eciesjs": "file:../.."
},
"devDependencies": {
"vite": "^7.1.12",
"vite": "^7.2.1",
"vite-bundle-visualizer": "^1.2.1"
}
}
23 changes: 18 additions & 5 deletions example/browser/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ const sk = new PrivateKey();
const encoder = new TextEncoder();
const decoder = new TextDecoder();

export function setup(encryptedElement, textElement, decryptedElement) {
const text = "hello eciesjs🔒";
export function setup(inputElement, textElement, encryptedElement, decryptedElement) {
let encrypted;

encryptedElement.innerHTML = "click me to encrypt";
let text = inputElement.value;
textElement.innerHTML = text;
encryptedElement.innerHTML = "click me to encrypt";
decryptedElement.innerHTML = "click me to decrypt";

const _encrypt = () => {
Expand All @@ -38,8 +37,20 @@ export function setup(encryptedElement, textElement, decryptedElement) {
textElement.innerHTML = "click encrypt button first";
}
};
const _onTextInput = (e) => {
const target = e.target;
if (target) {
encrypted = undefined;
const value = target.value;
text = value;
textElement.innerHTML = value;
encryptedElement.innerHTML = "click me to encrypt";
decryptedElement.innerHTML = "click me to decrypt";
}
};
encryptedElement.addEventListener("click", () => _encrypt());
decryptedElement.addEventListener("click", () => _decrypt());
inputElement.addEventListener("input", _onTextInput);
}

document.querySelector("#app").innerHTML = `
Expand All @@ -49,12 +60,14 @@ document.querySelector("#app").innerHTML = `
<button id="encrypted" type="button"></button>
<button id="decrypted" type="button"></button>
</div>
<input id="text-input" type="text" value="hello eciesjs🔒" />
<p id="text"></p>
</div>
`;

setup(
document.querySelector("#encrypted"),
document.querySelector("#text-input"),
document.querySelector("#text"),
document.querySelector("#encrypted"),
document.querySelector("#decrypted")
);
9 changes: 9 additions & 0 deletions example/browser/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ p {
word-break: break-all;
}

input {
font-size: 1em;
padding: 0.5em;
border-radius: 8px;
border: 1px solid #ccc;
width: 80%;
max-width: 400px;
}

#app {
max-width: 1280px;
margin: 0 auto;
Expand Down
39 changes: 26 additions & 13 deletions example/runtime/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { Buffer } from "node:buffer";
import { ECIES_CONFIG, PrivateKey, decrypt, encrypt } from "eciesjs";

// because deno does not support indirect conditional exports by default
// it falls to node:crypto's implementation
// despite that @ecies/ciphers exports @noble/ciphers implementation to deno
// see: https://github.com/denoland/deno/issues/23757#issuecomment-3010699763
// you need to run with `--conditions deno` (>=2.4.0) or
// `--unstable-node-conditions` (>=2.3.6,<2.4.0) if next line is uncommented
// ECIES_CONFIG.symmetricAlgorithm = "xchacha20";

const sk = new PrivateKey();
const data = Buffer.from("hello world🌍");
const decrypted = decrypt(sk.secret, encrypt(sk.publicKey.toBytes(), data));
console.log(Buffer.from(decrypted).toString());
const encoder = new TextEncoder();
const decoder = new TextDecoder();

const run = (curve, algorithm, message) => {
ECIES_CONFIG.ellipticCurve = curve;
// because deno does not support indirect conditional exports by default
// it falls to node:crypto's implementation
// despite that @ecies/ciphers exports @noble/ciphers implementation to deno
// see: https://github.com/denoland/deno/issues/23757#issuecomment-3010699763
// you need to run with `--conditions deno` (>=2.4.0) or
// `--unstable-node-conditions` (>=2.3.6,<2.4.0) for xchacha20 support
ECIES_CONFIG.symmetricAlgorithm = algorithm;

const sk = new PrivateKey();
const data = encoder.encode(message);
const decrypted = decrypt(sk.secret, encrypt(sk.publicKey.toBytes(), data));
console.log(`${curve} ${algorithm}: ` + decoder.decode(decrypted));
};

const msg = "hello world🌍";
run("secp256k1", "aes-256-gcm", msg);
run("secp256k1", "xchacha20", msg);
run("x25519", "aes-256-gcm", msg);
run("x25519", "xchacha20", msg);
run("ed25519", "aes-256-gcm", msg);
run("ed25519", "xchacha20", msg);
9 changes: 9 additions & 0 deletions example/runtime/quick-start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PrivateKey, decrypt, encrypt } from "eciesjs";

const encoder = new TextEncoder();
const decoder = new TextDecoder();

const sk = new PrivateKey();
const data = encoder.encode("hello world🌍");
const decrypted = decrypt(sk.secret, encrypt(sk.publicKey.toBytes(), data));
console.log(decoder.decode(decrypted));
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@
"test:browser": "node ./scripts/gen-browser-tests.mjs && cd tests-browser && pnpm test"
},
"dependencies": {
"@ecies/ciphers": "^0.2.4",
"@ecies/ciphers": "^0.2.5",
"@noble/ciphers": "^1.3.0",
"@noble/curves": "^1.9.7",
"@noble/hashes": "^1.8.0"
},
"devDependencies": {
"@biomejs/biome": "2.2.5",
"@types/node": "^24.9.2",
"@vitest/coverage-v8": "^4.0.5",
"@biomejs/biome": "2.3.4",
"@types/node": "^24.10.0",
"@vitest/coverage-v8": "^4.0.7",
"typescript": "^5.9.3",
"undici": "^7.16.0",
"vitest": "^4.0.5"
"vitest": "^4.0.7"
},
"pnpm": {
"onlyBuiltDependencies": [
"@biomejs/biome",
"esbuild"
]
},
"packageManager": "pnpm@10.19.0+sha512.c9fc7236e92adf5c8af42fd5bf1612df99c2ceb62f27047032f4720b33f8eacdde311865e91c411f2774f618d82f320808ecb51718bfa82c060c4ba7c76a32b8"
"packageManager": "pnpm@10.20.0+sha512.cf9998222162dd85864d0a8102e7892e7ba4ceadebbf5a31f9c2fce48dfce317a9c53b9f6464d1ef9042cba2e02ae02a9f7c143a2b438cd93c91840f0192b9dd"
}
Loading