bls

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecretKeySize = 32
	PublicKeySize = 48
	SignatureSize = 96
)
View Source
const PoPMessageSize = PublicKeySize + 4

Variables

View Source
var (
	ErrNoSignatures       = errors.New("no signatures")
	ErrDuplicateSignature = errors.New("duplicate signature")
)

Functions

func AggregateSignatures

func AggregateSignatures(sigs []Signature) (cbls.Signature, error)

func BuildPoPMessage

func BuildPoPMessage(pk PublicKey, height uint32) []byte

BuildPoPMessage constructs the PoP message from the public key and height.

func Verify

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

func VerifyAggregate

func VerifyAggregate(pks []PublicKey, msg []byte, sig cbls.Signature) bool

VerifyAggregate verifies aggregated signature over the same message.

func VerifyPoP

func VerifyPoP(pk PublicKey, height uint32, sig Signature) (bool, error)

VerifyPoP verifies the proof of possession (PoP) signature for the given public key and height. It reconstructs the PoP message and verifies the signature against it.

Types

type KeyGenerationOption

type KeyGenerationOption func(config *keyGenConfig) error

KeyGenerationOption is an option for BLS key generation.

func WithInfo

func WithInfo(data []byte) KeyGenerationOption

WithInfo sets given info for BLS key generation.

func WithNoPreHash

func WithNoPreHash() KeyGenerationOption

func WithRandomSalt

func WithRandomSalt() KeyGenerationOption

WithRandomSalt generates random salt for BLS key generation.

func WithSalt

func WithSalt(salt []byte) KeyGenerationOption

WithSalt sets given salt for BLS key generation.

type PublicKey

type PublicKey [PublicKeySize]byte

PublicKey is 48-byte compressed BLS public key.

func NewPublicKeyFromBase58

func NewPublicKeyFromBase58(s string) (PublicKey, error)

NewPublicKeyFromBase58 creates PublicKey from base58-encoded string.

func NewPublicKeyFromBytes

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

NewPublicKeyFromBytes creates PublicKey from byte slice.

func (*PublicKey) Bytes

func (k *PublicKey) Bytes() []byte

func (PublicKey) MarshalJSON

func (k PublicKey) MarshalJSON() ([]byte, error)

func (PublicKey) String

func (k PublicKey) String() string

func (*PublicKey) UnmarshalJSON

func (k *PublicKey) UnmarshalJSON(value []byte) error

type SecretKey

type SecretKey [SecretKeySize]byte

SecretKey is 32-byte BLS secret key.

func GenerateSecretKey

func GenerateSecretKey(seed []byte, opts ...KeyGenerationOption) (SecretKey, error)

GenerateSecretKey generates BLS secret key from given seed and options. By default, zero salt and nil info are used. That leads to deterministic key generation. To use random salt, use WithRandomSalt() option. In this case, each call of GenerateSecretKey with the same seed will produce different secret keys. To use custom salt or info, use WithSalt() and WithInfo() options respectively.

func NewSecretKeyFromBase58

func NewSecretKeyFromBase58(s string) (SecretKey, error)

func NewSecretKeyFromBytes

func NewSecretKeyFromBytes(b []byte) (SecretKey, error)

NewSecretKeyFromBytes creates BLS secret key from given slice of bytes.

func (*SecretKey) Bytes

func (k *SecretKey) Bytes() []byte

func (*SecretKey) PublicKey

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

func (*SecretKey) String

func (k *SecretKey) String() string

type Signature

type Signature [SignatureSize]byte

Signature is 96-byte compressed BLS signature.

func NewSignatureFromBase58

func NewSignatureFromBase58(s string) (Signature, error)

func NewSignatureFromBytes

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

func ProvePoP

func ProvePoP(sk SecretKey, pk PublicKey, height uint32) ([]byte, Signature, error)

ProvePoP creates a proof of possession (PoP) message from the given public key and height. Then the message is signed with a given secret key. The function returns the PoP message and its signature.

func Sign

func Sign(sk SecretKey, msg []byte) (Signature, error)

Sign calculates 96-byte compressed BLS signature over msg. Default separation tag "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_" is used.

func (*Signature) Bytes

func (s *Signature) Bytes() []byte

func (Signature) MarshalJSON

func (s Signature) MarshalJSON() ([]byte, error)

func (Signature) ShortString

func (s Signature) ShortString() string

func (Signature) String

func (s Signature) String() string

func (*Signature) UnmarshalJSON

func (s *Signature) UnmarshalJSON(value []byte) error

Jump to

Keyboard shortcuts

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