schnorrkel

package module
v0.0.0-...-00427f7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

go-schnorrkel

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.

dependencies

go 1.13

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 {
		fmt.Println(err)
		return
	}

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKeypair

func GenerateKeypair() (*SecretKey, *PublicKey, error)

GenerateKeypair generates a new schnorrkel secret key and public key

func NewRandomElement

func NewRandomElement() (*r255.Element, error)

NewRandomElement returns a random ristretto element

func NewRandomScalar

func NewRandomScalar() (*r255.Scalar, error)

NewRandomScalar returns a random ristretto scalar

func NewSigningContext

func NewSigningContext(context, msg []byte) *merlin.Transcript

NewSigningContext returns a new transcript initialized with the context for the signature .see: https://github.com/w3f/schnorrkel/blob/db61369a6e77f8074eb3247f9040ccde55697f20/src/context.rs#L183

func ScalarFromBytes

func ScalarFromBytes(b [32]byte) (*r255.Scalar, error)

ScalarFromBytes returns a ristretto scalar from the input bytes performs input mod l where l is the group order

Types

type MiniSecretKey

type MiniSecretKey struct {
	// contains filtered or unexported fields
}

MiniSecretKey is a secret scalar

func NewMiniSecretKey

func NewMiniSecretKey(b [64]byte) *MiniSecretKey

NewMiniSecretKey derives a mini secret key from a byte array

func NewMiniSecretKeyFromRaw

func NewMiniSecretKeyFromRaw(b [32]byte) (*MiniSecretKey, error)

NewMiniSecretKeyFromRaw derives a mini secret key from little-endian encoded raw bytes.

func NewRandomMiniSecretKey

func NewRandomMiniSecretKey() (*MiniSecretKey, error)

NewRandomMiniSecretKey generates a mini secret key from random

func (*MiniSecretKey) Decode

func (s *MiniSecretKey) Decode(in [32]byte) (err error)

func (*MiniSecretKey) ExpandEd25519

func (s *MiniSecretKey) ExpandEd25519() *SecretKey

ExpandEd25519 expands a mini secret key into a secret key https://github.com/w3f/schnorrkel/blob/43f7fc00724edd1ef53d5ae13d82d240ed6202d5/src/keys.rs#L196

func (*MiniSecretKey) ExpandUniform

func (s *MiniSecretKey) ExpandUniform() *SecretKey

ExpandUniform

func (*MiniSecretKey) Public

func (s *MiniSecretKey) Public() *PublicKey

Public gets the public key corresponding to this mini secret key

type PublicKey

type PublicKey struct {
	// contains filtered or unexported fields
}

PublicKey is a member

func NewPublicKey

func NewPublicKey(b [32]byte) PublicKey

func (*PublicKey) Compress

func (p *PublicKey) Compress() [32]byte

Compress returns the encoding of the point underlying the public key

func (*PublicKey) Decode

func (p *PublicKey) Decode(in [32]byte) error

func (*PublicKey) Encode

func (p *PublicKey) Encode() [32]byte

Encode is a wrapper around compress

func (*PublicKey) Verify

func (p *PublicKey) Verify(s *Signature, t *merlin.Transcript) bool

Verify verifies a schnorr signature with format: (R, s) where y is the public key 1. k = scalar(transcript.extract_bytes()) 2. R' = -ky + gs 3. return R' == R

type SecretKey

type SecretKey struct {
	// contains filtered or unexported fields
}

SecretKey consists of a secret scalar and a signing nonce change type key to *r255.scalar

func (*SecretKey) Decode

func (s *SecretKey) Decode(in [32]byte) error

Decode forms the secret key from the input bytes

func (*SecretKey) Encode

func (s *SecretKey) Encode() [32]byte

Encode returns the secret key as bytes

func (*SecretKey) Public

func (s *SecretKey) Public() (*PublicKey, error)

Public gets the public key corresponding to this secret key

func (*SecretKey) Sign

func (sk *SecretKey) Sign(t *merlin.Transcript) (*Signature, error)

Sign uses the schnorr signature algorithm to sign a message See the following for the transcript message https://github.com/w3f/schnorrkel/blob/db61369a6e77f8074eb3247f9040ccde55697f20/src/sign.rs#L158 Schnorr w/ transcript, secret key x: 1. choose random r from group 2. R = gr 3. k = scalar(transcript.extract_bytes()) 4. s = kx + r signature: (R, s) public key used for verification: y = g^x

type Signature

type Signature struct {
	R *r255.Element
	S *r255.Scalar
}

Signature holds a schnorrkel signature

func (*Signature) Decode

func (s *Signature) Decode(in [64]byte) error

Decode sets a Signature from bytes see: https://github.com/w3f/schnorrkel/blob/db61369a6e77f8074eb3247f9040ccde55697f20/src/sign.rs#L100

func (*Signature) Encode

func (s *Signature) Encode() [64]byte

Encode turns a signature into a byte array see: https://github.com/w3f/schnorrkel/blob/db61369a6e77f8074eb3247f9040ccde55697f20/src/sign.rs#L77

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL