bls

package module
v0.0.0-...-c928c43 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: Apache-2.0 Imports: 9 Imported by: 23

README

BLS

Just a simple library that wraps github.com/supranational/blst for a much more comprehensible UX and UI, compatible with Ethereum 2.0

Current Functionalities:

Benchmarks

This library has an internal cache which may alleviate key decompression. it takes more memory though.

goos: darwin
goarch: arm64
pkg: github.com/Giulio2002/bls
BenchmarkAggregateSigCached-12       	    1592	    692514 ns/op	   11450 B/op	      96 allocs/op
BenchmarkAggregateSigNonCached-12    	     924	   1233480 ns/op	   12550 B/op	     108 allocs/op
PASS

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Private key errors
	ErrZeroPrivateKey        = errors.New("bls(private): zero key")
	ErrDeserializePrivateKey = errors.New("bls(private): could not deserialize")
	// Public key errors
	ErrDeserializePublicKey = errors.New("bls(public): could not deserialize")
	ErrInfinitePublicKey    = errors.New("bls(public): infinity")
	// Signature errors
	ErrDeserializeSignature    = errors.New("bls(signature): could not deserialize")
	ErrNotGroupSignature       = errors.New("bls(signature): signature is not in group")
	ErrNoSignaturesToAggregate = errors.New("bls(signature): no signatures to aggregate")
	// Caching Errors
	ErrCacheNotEnabled = errors.New("cache(): cache not enabled")
)
View Source
var InfiniteSignature = [96]byte{0xC0}

InfiniteSignature represents an infinite signature (G2 Point at Infinity).

Functions

func AggregatePublickKeys

func AggregatePublickKeys(pubs [][]byte) ([]byte, error)

func AggregateSignatures

func AggregateSignatures(sigs [][]byte) ([]byte, error)

func ClearCache

func ClearCache()

func CompressPublicKey

func CompressPublicKey(p PublicKey) []byte

func LoadPublicKeyIntoCache

func LoadPublicKeyIntoCache(publicKey []byte, validate bool) error

func SetEnabledCaching

func SetEnabledCaching(caching bool)

func Verify

func Verify(signature []byte, msg []byte, publicKeyBytes []byte) (bool, error)

Verify verify signature against one public key.

func VerifyAggregate

func VerifyAggregate(signature []byte, msg []byte, publicKeysBytes [][]byte) (bool, error)

VerifyAggregate verify signature against many public keys.

func VerifyMultipleSignatures

func VerifyMultipleSignatures(sigs [][]byte, msgs [][]byte, pubKeys [][]byte) (bool, error)

VerifyMultipleSignatures verifies a non-singular set of signatures and its respective pubkeys and messages. This method provides a safe way to verify multiple signatures at once. We pick a number randomly from 1 to max uint64 and then multiply the signature by it. We continue doing this for all signatures and its respective pubkeys. S* = S_1 * r_1 + S_2 * r_2 + ... + S_n * r_n P'_{i,j} = P_{i,j} * r_i e(S*, G) = \prod_{i=1}^n \prod_{j=1}^{m_i} e(P'_{i,j}, M_{i,j}) Using this we can verify multiple signatures safely.

Types

type PrivateKey

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

PrivateKey defines a BLS private key.

func GenerateKey

func GenerateKey() (*PrivateKey, error)

GenerateKey creates a new random private key.

func NewPrivateKeyFromBytes

func NewPrivateKeyFromBytes(privKey []byte) (*PrivateKey, error)

PrivateKeyFromBytes creates a BLS private key from bytes.

func (*PrivateKey) Bytes

func (p *PrivateKey) Bytes() []byte

func (*PrivateKey) PublicKey

func (p *PrivateKey) PublicKey() PublicKey

PublicKey retrieve public key from the private key.

func (*PrivateKey) Sign

func (p *PrivateKey) Sign(msg []byte) *Signature

Sign a message with BLS.

type PublicKey

type PublicKey *blst.P1Affine

PublicKey wraps the CGO object of the BLST library and give us easy access to its methods.

func NewPublicKey

func NewPublicKey() PublicKey

NewPublicKey makes new empty Public Key.

func NewPublicKeyFromBytes

func NewPublicKeyFromBytes(b []byte) (PublicKey, error)

NewPublicKeyFromBytes Derive new public key from a 48 long byte slice.

type Signature

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

Signature wraps CGO object repressenting the signature.

func NewSignature

func NewSignature() *Signature

NewSignature creates a new empty signature.

func NewSignatureFromBytes

func NewSignatureFromBytes(b []byte) (*Signature, error)

NewSignatureFromBytes creates a new signature from a 96 bytes long slice.

func (Signature) Bytes

func (s Signature) Bytes() []byte

Verify verify signature against one public key.

func (Signature) Verify

func (s Signature) Verify(msg []byte, pk PublicKey) bool

Verify verify signature against one public key.

func (Signature) VerifyAggregate

func (s Signature) VerifyAggregate(msg []byte, publicKeys []PublicKey) bool

VerifyAggregate verify signature against many public keys.

Jump to

Keyboard shortcuts

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