npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lorhansohaky/schnorrkel.js

v1.1.2

Published

Schnorr signatures

Downloads

8

Readme

Schnorr Signatures

A javaScript library for signing and verifying Schnorr Signatures.

It can be used for single and multi signatures with and without exposing the public keys individually.

Requirements | Installing | Examples | License | Contributing

npm version license GitHub Workflow Status GitHub issues

npm downloads Libraries.io dependency status for GitHub repo GitHub pull requests

Requirements:

  • Node: >=16.x, <=20.x
  • npm (Node.js package manager) v9.x.x

Installing

Package manager

$ npm install @lorhansohaky/schnorrkel.js

Using yarn:

$ yarn add @lorhansohaky/schnorrkel.js

Git

git clone https://github.com/LorhanSohaky/schnorrkel.js
cd schnorrkel.js
npm install

Examples

Single Signatures

We refer to Single Signatures as ones that have a single signer.

Sign:

import Schnorrkel from '@lorhansohaky/schnorrkel.js/'
import { generateRandomKeys } from '@lorhansohaky/schnorrkel.js/core'

const keyPair = generateRandomKeys()
const privateKey = randomBytes(32) // Buffer
const msg = 'test message'
const {signature, finalPublicNonce} = Schnorrkel.sign(keyPair.privateKey, msg)

Offchain verification:

const publicKey: Buffer = ... (derived from the privateKey)
// signature and finalPublicNonce come from s
const result = Schnorrkel.verify(signature, msg, finalPublicNonce, publicKey)

You can see the full implementation in tests/schnorrkel/sign.test.ts and tests/schnorrkel/verify.test.ts in this repository.

Multisig

Schnorr multisignatures work on the basis n/n - all of the signers need to sign in order for the signature to be valid. Below are all the steps needed to craft a successful multisig.

Public nonces

Public nonces need to be exchanged between signers before they sign. Normally, the Signer should implement this library as define a getPublicNonces method that will call the library and return the nonces. For our test example, we're going to call the schnorrkel library directly:

import Schnorrkel from '@lorhansohaky/schnorrkel.js/'
import { generateRandomKeys } from '@lorhansohaky/schnorrkel.js/core'

const schnorrkel = new Schnorrkel()

const keyPair1 = generateRandomKeys()
const keyPair2 = generateRandomKeys()
const publicNonces1 = schnorrkel.generatePublicNonces(keyPair1.privateKey)
const publicNonces2 = schnorrkel.generatePublicNonces(keyPair2.privateKey)

You can see the full implementation in tests/unsafe-schnorrkel/generatePublicNonces.test.ts in this repository.

sign

After we have them, here is how to sign:

import Schnorrkel from '@lorhansohaky/schnorrkel.js/'
import { generateRandomKeys } from '@lorhansohaky/schnorrkel.js/core'

const schnorrkelOne = new Schnorrkel()
const schnorrkelTwo = new Schnorrkel()

const keyPairOne = generateRandomKeys()
const keyPairTwo = generateRandomKeys()

const publicNoncesOne = schnorrkelOne.generatePublicNonces(keyPairOne.privateKey)
const publicNoncesTwo = schnorrkelTwo.generatePublicNonces(keyPairTwo.privateKey)

const publicKeys = [keyPair1.publicKey, keyPair2.publicKey]
const publicNonces = [publicNoncesOne, publicNoncesTwo]
const combinedPublicKey = schnorrkel.getCombinedPublicKey(publicKeys)

const msg = 'test message'

const signatureOne = schnorrkelOne.multiSigSign(keyPairOne.privateKey, msg, combinedPublicKey, publicNonces)
const signatureTwo = schnorrkelTwo.multiSigSign(keyPairTwo.privateKey, msg, combinedPublicKey, publicNonces)

const signatures = [signatureOne.signature, signatureTwo.signature]
const signaturesSummed = Schnorrkel.sumSigs(signatures)
const result = Schnorrkel.verify(signaturesSummed, msg, signatureTwo.finalPublicNonce, combinedPublicKeyTwo.combinedKey)

You can see the full implementation in tests/schnorrkel/sumSigs.test.ts, tests/unsafe-schnorrkel/multiSigSign.test.ts and tests/schnorrkel/verify.test.ts in this repository.