Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schnorr signer & Multisig Provider #9

Merged
merged 7 commits into from
Oct 24, 2024
Merged

Schnorr signer & Multisig Provider #9

merged 7 commits into from
Oct 24, 2024

Conversation

borislav-itskov
Copy link
Owner

Changes:

  • You no longer need the private key to generate ephemeral nonces. The private key was used as a hashed key in the object but we removed it because it meant you need the private key just to exchange nonces which was inconvenient
  • schnorr signer & multisig provider

Schnorr Signer

This PR introduces a schnorr signer that makes starting up pretty easily. It's main purpose is to hide the complexity behind it.
To initialize a signer, just create a new instance with your private key:

import { SchnorrSigner } from "@borislav.itskov/schnorrkel.js";

const privateKey = hexlify(randomBytes(32));
const signer = new SchnorrSigner(pk1);

And you're ready to go:

const msg = "test message";
const commitment = hashMessage(msg);
const signature = signer.sign(commitment);

This produces a verifiable signature again by the signer:

const result = signer.verify(commitment, signature);

On-chain, there's are two helper functions:

  • signer.getSchnorrAddress() - which provides the schnorr ethereum address used for on-chain verifications
  • signer.getEcrecoverSignature(signature) - which returns the on-chain data needed to successfully verify a signature

Schnorr Multisig Provider

The multisig provider cannot sign as it's not a signer. But he accepts a SchnorrSigner or it's parent class, SchnorrProvider, to help up with setting up the multisig:

const privateKeyHex = hexlify(randomBytes(32));
const publicKey = new Key(Buffer.from(arrayify(computePublicKey(privateKeyHex, true))));
const providerOne = new SchnorrProvider(publicKey);

const privateKeyHexTwo = hexlify(randomBytes(32));
const publicKeyTwo = new Key(Buffer.from(arrayify(computePublicKey(privateKeyHexTwo, true))));
const providerTwo = new SchnorrProvider(publicKeyTwo);

const multisigProvider = new SchnorrMultisigProvider([providerOne, providerTwo]);

OR if you have the signers, you can pass them:

const multisigProvider = new SchnorrMultisigProvider([signerOne, signerTwo]);

Once set up:

  • you have getSchnorrAddress to give you directly the correct schnorr ethereum multisig address of all the signers
  • getPublicNonces - which gets all the required public nonces from all the signers before signing can begin
  • getEcrecoverSignature - a helper to format the on-chain data for the multisig

@borislav-itskov borislav-itskov added the enhancement New feature or request label Oct 23, 2024
@borislav-itskov borislav-itskov self-assigned this Oct 23, 2024
@borislav-itskov borislav-itskov merged commit 392681c into main Oct 24, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant