Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: torusresearch/eccrypto
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.6
Choose a base ref
...
head repository: torusresearch/eccrypto
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Run tests

on:
push:
branches-ignore:
- "master"

name: CI

jobs:
test:
name: run tests
strategy:
matrix:
node: ["22.x"]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: "npm"

- name: Install dependencies
run: npm install

- name: Run lint
run: npm run lint

- name: Run build
run: npm run build

- name: Install playwright webkit
run: npx playwright install-deps webkit

- name: Run tests
run: npx playwright install && npm run test:ci
41 changes: 41 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Run tests

on:
push:
branches: [master]

name: Master

jobs:
test:
name: run tests
strategy:
matrix:
node: ["22.x"]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: "npm"

- name: Install dependencies
run: npm install

- name: Run lint
run: npm run lint

- name: Run build
run: npm run build

- name: Install playwright webkit
run: npx playwright install-deps webkit

- name: Run tests
run: npx playwright install && npm run test:ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -2,3 +2,4 @@
/npm-debug.log
/build/
*.swp
dist/
3 changes: 0 additions & 3 deletions .jshintignore

This file was deleted.

87 changes: 0 additions & 87 deletions .jshintrc

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
>=20.x
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
}
47 changes: 27 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# eccrypto [![Build Status](https://travis-ci.org/bitchan/eccrypto.svg?branch=master)](https://travis-ci.org/bitchan/eccrypto)
# eccrypto

[![NPM](https://nodei.co/npm/eccrypto.png)](https://www.npmjs.com/package/eccrypto)
![Build Status](https://github.com/torusresearch/eccrypto/actions/workflows/master.yml/badge.svg)

[![npm downloads](https://img.shields.io/npm/dm/@toruslabs/eccrypto.svg?style=flat-square)](https://www.npmjs.com/package/@toruslabs/eccrypto)

[![NPM](https://nodei.co/npm/@toruslabs/eccrypto.png)](https://www.npmjs.com/package/@toruslabs/eccrypto)

JavaScript Elliptic curve cryptography library for both browserify and node.

@@ -12,11 +16,11 @@ There is currently no any isomorphic ECC library which provides ECDSA, ECDH and

With the help of browserify `eccrypto` provides different implementations for Browser and Node.js with the same API. Because WebCryptoAPI defines asynchronous promise-driven API, implementation for Node needs to use promises too.

* Use Node.js crypto module/library bindings where possible
* Use WebCryptoAPI where possible
* Promise-driven API
* Only secp256k1 curve, only SHA-512 (KDF), HMAC-SHA-256 (HMAC) and AES-256-CBC for ECIES
* Compressed key support
- Use Node.js crypto module/library bindings where possible
- Use WebCryptoAPI where possible
- Promise-driven API
- Only secp256k1 curve, only SHA-512 (KDF), HMAC-SHA-256 (HMAC) and AES-256-CBC for ECIES
- Compressed key support

### Native crypto API limitations

@@ -32,7 +36,7 @@ So we use [seck256k1](https://www.npmjs.com/package/secp256k1) library in Node f

## Possible future goals

* Support other curves/KDF/MAC/symmetric encryption schemes
- Support other curves/KDF/MAC/symmetric encryption schemes

## Usage

@@ -51,13 +55,16 @@ var str = "message to sign";
// Always hash you message to sign!
var msg = crypto.createHash("sha256").update(str).digest();

eccrypto.sign(privateKey, msg).then(function(sig) {
eccrypto.sign(privateKey, msg).then(function (sig) {
console.log("Signature in DER format:", sig);
eccrypto.verify(publicKey, msg, sig).then(function() {
console.log("Signature is OK");
}).catch(function() {
console.log("Signature is BAD");
});
eccrypto
.verify(publicKey, msg, sig)
.then(function () {
console.log("Signature is OK");
})
.catch(function () {
console.log("Signature is BAD");
});
});
```

@@ -71,8 +78,8 @@ var publicKeyA = eccrypto.getPublic(privateKeyA);
var privateKeyB = eccrypto.generatePrivate();
var publicKeyB = eccrypto.getPublic(privateKeyB);

eccrypto.derive(privateKeyA, publicKeyB).then(function(sharedKey1) {
eccrypto.derive(privateKeyB, publicKeyA).then(function(sharedKey2) {
eccrypto.derive(privateKeyA, publicKeyB).then(function (sharedKey1) {
eccrypto.derive(privateKeyB, publicKeyA).then(function (sharedKey2) {
console.log("Both shared keys are equal:", sharedKey1, sharedKey2);
});
});
@@ -89,17 +96,17 @@ var privateKeyB = eccrypto.generatePrivate();
var publicKeyB = eccrypto.getPublic(privateKeyB);

// Encrypting the message for B.
eccrypto.encrypt(publicKeyB, Buffer.from("msg to b")).then(function(encrypted) {
eccrypto.encrypt(publicKeyB, Buffer.from("msg to b")).then(function (encrypted) {
// B decrypting the message.
eccrypto.decrypt(privateKeyB, encrypted).then(function(plaintext) {
eccrypto.decrypt(privateKeyB, encrypted).then(function (plaintext) {
console.log("Message to part B:", plaintext.toString());
});
});

// Encrypting the message for A.
eccrypto.encrypt(publicKeyA, Buffer.from("msg to a")).then(function(encrypted) {
eccrypto.encrypt(publicKeyA, Buffer.from("msg to a")).then(function (encrypted) {
// A decrypting the message.
eccrypto.decrypt(privateKeyA, encrypted).then(function(plaintext) {
eccrypto.decrypt(privateKeyA, encrypted).then(function (plaintext) {
console.log("Message to part A:", plaintext.toString());
});
});
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@toruslabs/config/babel.config");
61 changes: 0 additions & 61 deletions binding.gyp

This file was deleted.

Loading