#bitcoin #schnorr

nightly schnorr_fun

BIP340 Schnorr signatures based on secp256kfun

13 releases (4 breaking)

new 0.5.1 Feb 24, 2021
0.5.0 Feb 23, 2021
0.4.1 Dec 18, 2020
0.3.2 Sep 28, 2020
0.1.1 Jul 29, 2020

#110 in Cryptocurrencies

Download history 30/week @ 2020-11-07 2/week @ 2020-11-14 14/week @ 2020-11-21 7/week @ 2020-11-28 11/week @ 2020-12-05 22/week @ 2020-12-12 7/week @ 2020-12-19 19/week @ 2021-01-02 7/week @ 2021-01-09 19/week @ 2021-01-16 3/week @ 2021-01-23 4/week @ 2021-01-30 17/week @ 2021-02-06 48/week @ 2021-02-13 42/week @ 2021-02-20

67 downloads per month

0BSD license

195KB
3.5K SLoC

SchnorrFun! crates_badge docs_badge

Generate and verify Schnorr signatures on secp256k1. Uses secp256kfun.

Schnorr signatures were introduced (and patented until 2008) by their namesake in Efficient Signature Generation by Smart Cards. This implementation is based on the BIP-340 specification, but is flexible enough to be used as a general purpose Schnorr signature scheme.

Use

[dependencies]
schnorr_fun = "0.5"
sha2 = "0.9"

Should use?

This library and secp256kfun are experimental.

Synopsis

use schnorr_fun::{
    fun::{marker::*, Scalar, nonce},
    Schnorr,
    MessageKind,
};
use sha2::Sha256;
use rand::rngs::ThreadRng;
// Use synthetic nonces
let nonce_gen = nonce::Synthetic::<Sha256, nonce::GlobalRng<ThreadRng>>::default();
// Create a BIP-341 compatible instance
let schnorr = Schnorr::<Sha256, _>::new(nonce_gen.clone(),MessageKind::Prehashed);
// Or create an instance for your own application
let schnorr = Schnorr::<Sha256,_>::new(nonce_gen, MessageKind::Plain { tag: "my-app" });
// Generate your public/private key-pair
let keypair = schnorr.new_keypair(Scalar::random(&mut rand::thread_rng()));
let message = b"Chancellor on brink of second bailout for banks"
    .as_ref()
    .mark::<Public>();
// Sign the message with our keypair
let signature = schnorr.sign(&keypair, message);
// Get the verifier's key
let verification_key = keypair.verification_key();
// Check it's valid 🍿
assert!(schnorr.verify(&verification_key, message, &signature));

Features

  • BIP-340 compliant signing and verification
  • Adaptor signatures

Dependencies

~440–760KB
~17K SLoC