Git Product home page Git Product logo

lisk-musig's Introduction

@alepop/lisk-musig

Three round m-of-m key aggregation for Lisk using the MuSig signature scheme

Installation

npm install @alepop/lisk-musig

Usage

import * as musig from "@alepop/lisk-musig";
import { TransferTransaction } from "@liskhq/lisk-transactions";
import { verifyData, bufferToHex } from "@liskhq/lisk-cryptography";

const keys1 = musig.generateKeyPairFromPassphrase(/* mnemonica */);
const keys2 = musig.generateKeyPairFromPassphrase(/* mnemonica */);

const config = new musig.Config([keys1.publicKey, keys2.publicKey]);

const aggregatePublicKey = config.publicKey;

const tx = new TransferTransaction({
  recipientId: "18160565574430594874L",
  amount: "1000",
  networkIdentifier:
    "e48feb88db5b5cf5ad71d93cdcd1d879b6d5ed187a36b0002cc34e0ef9883255",
  senderPublicKey: aggregatePublicKey
});

const session1 = new musig.Session(config, keys1, tx);
const session2 = new musig.Session(config, keys2, tx);

/* round 1 */
const c1 = session1.getLocalCommitment();
const c2 = session2.getLocalCommitment();
session1.setRemoteCommitment(...c2);
session2.setRemoteCommitment(...c1);

/* roun 2 */
const n1 = session1.getLocalNonce();
const n2 = session2.getLocalNonce();
session1.setRemoteNonce(...n2);
session2.setRemoteNonce(...n1);

/* round 3 */
const s1 = session1.getLocalSignature();
const s2 = session2.getLocalSignature();
session1.setRemoteSignature(...s2);
session2.setRemoteSignature(...s1);

/* Verify the signature */
const signature = session1.aggregateSignature;
const isValid = verifyData(
  tx.getBytes(),
  bufferToHex(signature),
  aggregatePublicKey
);

References

@futuretense/ed25519-musig

lisk-musig's People

Contributors

alepop avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.