# @kzen-networks/thresh-sig

> Threshold signatures based on two-party ECDSA

Latest version **0.4.2** (published 2020-08-02) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install @kzen-networks/thresh-sig
pnpm add @kzen-networks/thresh-sig
yarn add @kzen-networks/thresh-sig
bun add @kzen-networks/thresh-sig
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2020-08-02 |
| First published | 2019-05-16 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | ^10.16.0 |
| Dependencies | 5 |
| Unpacked size | 321.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | yes |
| GitHub stars | 110 |
| Author | Oded Leiba |
| Maintainers | oleiba |

## Links

- npm: https://www.npmjs.com/package/@kzen-networks/thresh-sig
- Repository: https://github.com/KZen-networks/thresh-sig
- Homepage: https://github.com/KZen-networks/thresh-sig#readme
- Issues: https://github.com/KZen-networks/thresh-sig/issues
- npm.io page: https://npm.io/package/@kzen-networks/thresh-sig

## Dependencies (5)

- [rocksdb](https://npm.io/package/rocksdb.md) ^4.1.0
- [elliptic](https://npm.io/package/elliptic.md) ^6.5.1
- [neon-cli](https://npm.io/package/neon-cli.md) ^0.2.0
- [@types/rocksdb](https://npm.io/package/@types/rocksdb.md) ^3.0.0
- [@types/elliptic](https://npm.io/package/@types/elliptic.md) ^6.4.9

## Recent versions

- 0.4.2 (latest) — 2020-08-02
- 0.4.1 — 2020-07-19
- 0.4.0 — 2020-05-26
- 0.3.10 — 2020-02-16
- 0.3.9 — 2020-02-15
- 0.3.8 — 2020-02-06
- 0.3.7 — 2019-11-28
- 0.3.6 — 2019-11-24
- 0.3.5 — 2019-11-11
- 0.3.4 — 2019-09-16
- 0.3.3 — 2019-09-16
- 0.3.2 — 2019-09-15
- 0.3.1 — 2019-09-15
- 0.3.0 — 2019-09-12
- 0.2.4 — 2019-09-12
- … 11 more at https://npm.io/package/@kzen-networks/thresh-sig/versions

## README

[![Build Status](https://travis-ci.org/KZen-networks/thresh-sig-js.svg?branch=master)](https://travis-ci.org/KZen-networks/thresh-sig-js)
[![NPM](https://img.shields.io/npm/v/@kzen-networks/thresh-sig.svg)](https://www.npmjs.org/package/@kzen-networks/thresh-sig)

Two Party signatures JS SDK 
=====================================
Supports:

|        Algorithm         |   Curve   |    Compatible blockchains       | 
|-------------------------------|------------------------|------------------------|
|    **ECDSA**    |      Secp256k1 |      Bitcoin, Ethereum           |
|    **Schnorr**    |        Secp256k1 | Zilliqa |
|    **EdDSA** | Curve25519 |  Tezos, Libra |

## Installation:
1. If on Linux, install needed packages:
```sh
$ sudo apt-get update
$ sudo apt-get install libgmp3-dev pkg-config libssl-dev clang libclang-dev
```
2. Install [Node.js](https://nodejs.org/en/download/)<br>
(tested on Node 10)
3. Install [nightly Rust](https://github.com/rust-lang/rustup.rs#installation)<br>
(tested on rustc 1.38.0-nightly (0b680cfce 2019-07-09))
4. Install the package:
```bash
$ npm install @kzen-networks/thresh-sig
```
Alternatively, clone it:
```bash
$ git clone https://github.com/KZen-networks/thresh-sig-js
$ cd thresh-sig-js
$ npm install
$ npm run build
```

## Usage:

Start party one's server 
(acts as the co-signer in the two-party signature scheme):
```js
const { Party1 } = require('@kzen-networks/thresh-sig');
const p1 = new Party1();
p1.launchServer();
```
ECDSA party two:
```js
const { EcdsaParty2 } = require('@kzen-networks/thresh-sig');
const crypto = require('crypto');

const P1_ENDPOINT = 'http://localhost:8000';

(async () => {
    const party2 = new EcdsaParty2(P1_ENDPOINT);
    const party2MasterKeyShare = await party2.generateMasterKey();
    const party2ChildShare = party2.getChildShare(party2MasterKeyShare, 0, 0);
    const msgHash = crypto.createHash('sha256').update('some message').digest();
    const signature = await party2.sign(msgHash, party2ChildShare, 0, 0);
    console.log(JSON.stringify(signature));
    // {"r": <32-bytes-hex>,"s": <32-bytes-hex>,"recid": <0 or 1>}
})();
```

Schnorr party two:
```js
const { SchnorrParty2 } = require('@kzen-networks/thresh-sig');
const crypto = require('crypto');

const P1_ENDPOINT = 'http://localhost:8000';

(async () => {
    const party2 = new SchnorrParty2(P1_ENDPOINT);
    const party2Share = await party2.generateKey();
    const msgHash = crypto.createHash('sha256').update('some message').digest();
    const signature = await party2.sign(msgHash, party2Share);
    console.log(JSON.stringify(signature));
    // {"e": <32-bytes-hex>,"s": <32-bytes-hex>}
})();
```

EdDSA party two:
```js
const { Ed25519Party2 } = require('@kzen-networks/thresh-sig');
const crypto = require('crypto');

const P1_ENDPOINT = 'http://localhost:8000';

(async () => {
    const party2 = new Ed25519Party2(P1_ENDPOINT);
    const party2Share = await party2.generateKey();
    console.log(party2Share.getAggregatedPublicKey().apk.bytes_str);
    // <32-bytes-hex>
    const msgHash = crypto.createHash('sha256').update('some message').digest();
    const signature = await party2.sign(msgHash, party2Share);
    console.log(JSON.stringify(signature));
    // {"R":{"bytes_str":<32-bytes-hex>},"s":<32-bytes-hex>}
})()
```

## Demo:

You can run a command line demo and see the two-party signing protocol in action. <br>
Party one:
```
$ node ./demo/party1.js
🔧 Configured for production.
    => address: 0.0.0.0
    => port: 8000
    => log: critical
    => workers: 24
    => secret key: generated
    => limits: forms = 32KiB
    => keep-alive: 5s
    => tls: disabled
🚀 Rocket has launched from http://0.0.0.0:8000
```
Party two (separate shell) - 
1. ECDSA:
```
$ node ./demo/ecdsa-party2.js
{"r":"b3d6168cc8ab6da64697b9e81c55863078da65cac7bbebc3d3f747dae0c6ac16","s":"449052412e20e510f8d4e31d721b3ef42199a9886a58a058c42d142b5850a177","recid":0}
```
2. Schnorr:
```
$ node ./demo/schnorr-party2.js
{"e":"d960b3fe66d2dc1c2115c93b3e674344d73063c22148ff3bc8d67493ffb19814","s":"ed2ecaa8882ccaac946bf951835033d4326aaff2e1e466ecf1fdda32a6fc762b"}
```
3. EdDSA:
```
$ node ./demo/eddsa-party2.js
{"R":{"bytes_str":"d86c5da0a257fd66acd007776f28d9f7a5083f84c66a41c98104c11cc5e9eaa3"},"s":"9964b5053843d6f6ddfaa25977f14f55676ae8a0e6bf89eafb412f417257abc"}
```

## Contact
Feel free to [reach out](mailto:github@kzencorp.com) or join the KZen Research [Telegram]( https://t.me/kzen_research) for discussions on code and research.

---
_Source: https://npm.io/package/@kzen-networks/thresh-sig · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
