Categorygithub.com/ChainSafe/go-schnorrkel
modulepackage
1.1.0
Repository: https://github.com/chainsafe/go-schnorrkel.git
Documentation: pkg.go.dev

# README

go-schnorrkel

Discord

This repo contains the Go implementation of the sr25519 signature algorithm (schnorr over ristretto25519). The existing Rust implementation is here.

This library is currently able to create sr25519 keys, import sr25519 keys, and sign and verify messages. It is interoperable with the Rust implementation.

The BIP39 implementation in this library is compatible with the rust substrate-bip39 implementation. Note that this is not a standard bip39 implementation.

This library has been audited as of August 2021 and is production-ready. Please see the audit report for the results of the audit.

dependencies

go 1.16

usage

Example: key generation, signing, and verification

package main 

import (
	"fmt"
	
	schnorrkel "github.com/ChainSafe/go-schnorrkel"
)

func main() {
	msg := []byte("hello friends")
	signingCtx := []byte("example")

	signingTranscript := schnorrkel.NewSigningContext(signingCtx, msg)
	verifyTranscript := schnorrkel.NewSigningContext(signingCtx, msg)

	priv, pub, err := schnorrkel.GenerateKeypair()
	if err != nil {
		panic(err)
	}

	sig, err := priv.Sign(signingTranscript)
	if err != nil {
		panic(err)
	}

	ok := pub.Verify(sig, verifyTranscript)
	if !ok {
		fmt.Println("failed to verify signature")
		return
	}

	fmt.Println("verified signature")
}

Please see the godocs for more usage examples.

# Functions

DeriveKeyHard derives a Hard subkey identified by the byte array i and chain code.
DeriveKeySimple derives a Soft subkey identified by byte array i and chain code.
DerviveKeySoft is an alias for DervieKeySimple() used to derive a Soft subkey identified by the byte array i and chain code.
GenerateKeypair generates a new schnorrkel secret key and public key.
GenerateMiniSecretKey generates a mini secret key from random.
GenerateMnemonic returns mnemonic for func MiniSecretKeyFromMnemonic.
HexToBytes turns a 0x prefixed hex string into a byte slice.
MiniSecretKeyFromMnemonic returns a go-schnorrkel MiniSecretKey from a bip39 mnemonic.
MnemonicToEntropy takes a mnemonic string and reverses it to the entropy An error is returned if the mnemonic is invalid.
No description provided by the author
NewExtendedKey creates an ExtendedKey given a DerivableKey and chain code.
NewKeypair creates a new keypair from a public key and secret key.
NewMiniSecretKey derives a mini secret key from a seed.
NewMiniSecretKeyFromHex returns a new MiniSecretKey from the given hex-encoded string.
NewMiniSecretKeyFromRaw derives a mini secret key from little-endian encoded raw bytes.
NewOutput creates a new VRF output from a 64-byte element.
NewPublicKey creates a new public key from input bytes.
NewPublicKeyFromHex returns a PublicKey from a hex-encoded string.
NewRandomElement returns a random ristretto element.
NewRandomScalar returns a random ristretto scalar.
NewSecretKey creates a new secret key from input bytes.
No description provided by the author
NewSignatureFromHex returns a new Signature from the given hex-encoded string.
NewSigningContext returns a new transcript initialized with the context for the signature .see: https://github.com/w3f/schnorrkel/blob/db61369a6e77f8074eb3247f9040ccde55697f20/src/context.rs#L183.
ScalarFromBytes returns a ristretto scalar from the input bytes performs input mod l where l is the group order.
SeedFromMnemonic returns a 64-byte seed from a bip39 mnemonic.
SetKusama sets the VRF kusama option.
TranscriptWithMalleabilityAddressed returns the input transcript with the public key commited to it, addressing VRF output malleability.
VerifyBatch batch verifies the given signatures.

# Constants

No description provided by the author
MAX_VRF_BYTES is the maximum bytes that can be extracted from the VRF via MakeBytes.
MiniSecretKeySize is the length in bytes of a MiniSecretKey.
PublicKeySize is the length in bytes of a PublicKey.
SecretKeySize is the length in bytes of a SecretKey.
SignatureSize is the length in bytes of a signature.
No description provided by the author

# Variables

No description provided by the author
ErrSignatureNotMarkedSchnorrkel is returned when attempting to decode a signature that is not marked as schnorrkel.

# Structs

No description provided by the author
ExtendedKey consists of a DerivableKey which can be a schnorrkel public or private key as well as chain code.
Keypair consists of a PublicKey and a SecretKey.
MiniSecretKey is a secret scalar.
PublicKey is a field element.
SecretKey consists of a secret scalar and a signing nonce.
Signature holds a schnorrkel signature.
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

DerivableKey implements DeriveKey.