https://github.com/dolcalmi/stellar-thresh-sig-js
Stellar Javascript two party threshold signatures SDK
https://github.com/dolcalmi/stellar-thresh-sig-js
stellar threshold threshold-eddsa threshold-signature
Last synced: 5 months ago
JSON representation
Stellar Javascript two party threshold signatures SDK
- Host: GitHub
- URL: https://github.com/dolcalmi/stellar-thresh-sig-js
- Owner: dolcalmi
- License: gpl-3.0
- Created: 2020-08-26T15:04:42.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-30T19:51:02.000Z (over 5 years ago)
- Last Synced: 2025-10-11T21:09:44.919Z (9 months ago)
- Topics: stellar, threshold, threshold-eddsa, threshold-signature
- Language: JavaScript
- Homepage:
- Size: 133 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stellar Two-Party Threshold Signature Library
[](https://www.npmjs.org/package/stellar-thresh-sig)
[](https://travis-ci.org/dolcalmi/stellar-thresh-sig-js)
[](https://coveralls.io/github/dolcalmi/stellar-thresh-sig-js?branch=master)
[](https://david-dm.org/dolcalmi/stellar-thresh-sig-js)
[](https://david-dm.org/dolcalmi/stellar-thresh-sig-js?type=dev)
[](https://runkit.com/npm/stellar-thresh-sig)
Stellar Javascript two party threshold signature SDK
## 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/)
(tested on Node 10)
3. Install [nightly Rust](https://github.com/rust-lang/rustup.rs#installation)
(tested on rustc 1.38.0-nightly (0b680cfce 2019-07-09))
```bash
$ rustup toolchain install nightly-2019-07-10
$ rustup default nightly-2019-07-10-x86_64-unknown-linux-gnu # or value from `rustup show` command
$ rustc --version
# rustc 1.38.0-nightly (0b680cfce 2019-07-09)
```
4. Install the package:
```bash
$ npm i stellar-thresh-sig-js
```
Alternatively, clone it:
```bash
$ git clone https://github.com/dolcalmi/stellar-thresh-sig-js
$ cd stellar-thresh-sig-js
$ npm install
```
if you have problems getting a keypair please check [this issue](https://github.com/KZen-networks/thresh-sig-js/issues/18) or run the next command after npm install:
```bash
$ OPENSSL_STATIC=yes OPENSSL_LIB_DIR= npm explore @kzen-networks/thresh-sig -- npm run build-rust
# you can get openssl path with: openssl version -d
```
## Usage
This library extends `Keypair`, `Transaction` and `TransactionBuilder` from Stellar SDK.
You can use it in the same way that you use the Stellar SDK.
### Initialization
``` js
import { Keypair, Transaction, TransactionBuilder } from 'stellar-thresh-sig-js';
```
### Server Party1 Initialization
Before use threshold signatures with this library you must initialize [server (party 1)](https://github.com/KZen-networks/thresh-sig-js)
``` js
import { ThresholdSigServer } from 'stellar-thresh-sig-js';
new ThresholdSigServer().start();
```
from examples:
```bash
$ node ./examples/thresh-sig-server.js
```
with specific port and log mode:
```bash
# log options (off, debug, normal, critical)
$ ROCKET_PORT=8001 ROCKET_LOG=normal node ./examples/thresh-sig-server.js
```
If you want to know more information about ENV variables go to [Rocket ENV variables](https://rocket.rs/v0.4/guide/configuration/#environment-variables)
### Keypair
Create a new random key pair with two-party threshold signature:
``` js
const keypair = await Keypair.randomLocalPartyThreshSig();
// or
const keypair = await Keypair.randomLocalPartyThreshSig('http://your-server.com:8000');
```
Export key pair:
``` js
const keypairJSON = keypair.toJSON();
await saveToFileOrDB(keypairJSON);
```
Restore from json:
``` js
const keypairJSON = await loadFromFileOrDB();
const keypair = Keypair.fromJSON(keypairJSON);
```
Sign data:
``` js
const signature = await keypair.sign(data);
```
Full example in [./examples/keypair.js](examples/keypair.js)
```bash
$ node ./examples/keypair.js
```
### Transaction and TransactionBuilder
Use it in the same way as StellarSdk
``` js
import { TransactionBuilder } from 'stellar-thresh-sig-js';
const transaction = new TransactionBuilder(sender, {
fee,
networkPassphrase: StellarSdk.Networks.TESTNET,
})
.addOperation(...)
.setTimeout(30)
.build();
// the only difference is that sign is an async function.
await transaction.sign(senderKeypair);
```
Full example in [./examples/send-payment.js](examples/send-payment.js)
```bash
$ node ./examples/send-payment.js
```
## Development
Run all tests:
```bash
$ npm i
$ npm test
```
Run a single test suite:
```bash
$ npm run mocha -- test/lib/keypair.spec.js
```
Run a single test (case sensitive):
```bash
$ npm run mocha -- test/lib/keypair.spec.js --grep 'sign'
```
Library based on [Two Party signatures JS SDK](https://github.com/KZen-networks/thresh-sig-js)