bls

package
v1.10.3-0...-ec03cfc Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2021 License: LGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PublicKeySizeInBytes    = 48
	BLSSignatureSizeInBytes = 96
)

PublicKeySizeInBytes ..

Variables

View Source
var (
	// BLSPubKeyCache is the Cache of the Deserialized BLS PubKey
	BLSPubKeyCache, _ = lru.New(blsPubKeyCacheSize)
)

Functions

func AggregateMasks

func AggregateMasks(a, b []byte) ([]byte, error)

AggregateMasks computes the bitwise OR of the two given participation masks.

func AggregateSig

func AggregateSig(sigs []*bls.Sign) *bls.Sign

AggregateSig aggregates all the BLS signature into a single multi-signature.

func BytesToBLSPublicKey

func BytesToBLSPublicKey(bytes []byte) (*bls.PublicKey, error)

BytesToBLSPublicKey converts bytes into bls.PublicKey pointer.

func RandPrivateKey

func RandPrivateKey() *bls.SecretKey

RandPrivateKey returns a random private key.

func SeparateSigAndMask

func SeparateSigAndMask(commitSigs []byte) ([]byte, []byte, error)

SeparateSigAndMask parse the commig signature data into signature and bitmap.

Types

type CompletePolicy

type CompletePolicy struct {
}

CompletePolicy is the default policy requiring that all participants have cosigned to make a collective signature valid.

func (CompletePolicy) Check

func (p CompletePolicy) Check(m *Mask) bool

Check verifies that all participants have contributed to a collective signature.

type Mask

type Mask struct {
	Bitmap          []byte
	Publics         []*PublicKeyWrapper
	PublicsIndex    map[SerializedPublicKey]int
	AggregatePublic *bls.PublicKey
}

Mask represents a cosigning participation bitmask.

func NewMask

func NewMask(publics []PublicKeyWrapper, myKey *PublicKeyWrapper) (*Mask, error)

NewMask returns a new participation bitmask for cosigning where all cosigners are disabled by default. If a public key is given it verifies that it is present in the list of keys and sets the corresponding index in the bitmask to 1 (enabled).

func (*Mask) Clear

func (m *Mask) Clear()

Clear clears the existing bits and aggregate public keys.

func (*Mask) CountEnabled

func (m *Mask) CountEnabled() int

CountEnabled returns the number of enabled nodes in the CoSi participation Bitmap.

func (*Mask) CountTotal

func (m *Mask) CountTotal() int

CountTotal returns the total number of nodes this CoSi instance knows.

func (*Mask) GetPubKeyFromMask

func (m *Mask) GetPubKeyFromMask(flag bool) []*bls.PublicKey

GetPubKeyFromMask will return pubkeys which masked either zero or one depending on the flag it is used to show which signers are signed or not in the cosign message

func (*Mask) GetSignedPubKeysFromBitmap

func (m *Mask) GetSignedPubKeysFromBitmap(bitmap []byte) ([]*PublicKeyWrapper, error)

GetSignedPubKeysFromBitmap will return pubkeys that are signed based on the specified bitmap.

func (*Mask) IndexEnabled

func (m *Mask) IndexEnabled(i int) (bool, error)

IndexEnabled checks whether the given index is enabled in the Bitmap or not.

func (*Mask) KeyEnabled

func (m *Mask) KeyEnabled(public SerializedPublicKey) (bool, error)

KeyEnabled checks whether the index, corresponding to the given key, is enabled in the Bitmap or not.

func (*Mask) Len

func (m *Mask) Len() int

Len returns the Bitmap length in bytes.

func (*Mask) Mask

func (m *Mask) Mask() []byte

Mask returns a copy of the participation bitmask.

func (*Mask) SetBit

func (m *Mask) SetBit(i int, enable bool) error

SetBit enables (enable: true) or disables (enable: false) the bit in the participation Bitmap of the given cosigner.

func (*Mask) SetKey

func (m *Mask) SetKey(public SerializedPublicKey, enable bool) error

SetKey set the bit in the Bitmap for the given cosigner

func (*Mask) SetKeysAtomic

func (m *Mask) SetKeysAtomic(publics []*PublicKeyWrapper, enable bool) error

SetKeysAtomic set the bit in the Bitmap for the given cosigners only when all the cosigners are present in the map.

func (*Mask) SetMask

func (m *Mask) SetMask(mask []byte) error

SetMask sets the participation bitmask according to the given byte slice interpreted in little-endian order, i.e., bits 0-7 of byte 0 correspond to cosigners 0-7, bits 0-7 of byte 1 correspond to cosigners 8-15, etc.

type Policy

type Policy interface {
	Check(m *Mask) bool
}

Policy represents a fully customizable cosigning policy deciding what cosigner sets are and aren't sufficient for a collective signature to be considered acceptable to a verifier. The Check method may inspect the set of participants that cosigned by invoking cosi.Mask and/or cosi.MaskBit, and may use any other relevant contextual information (e.g., how security-critical the operation relying on the collective signature is) in determining whether the collective signature was produced by an acceptable set of cosigners.

type PrivateKeyWrapper

type PrivateKeyWrapper struct {
	Pri *bls.SecretKey
	Pub *PublicKeyWrapper
}

PrivateKeyWrapper combines the bls private key and the corresponding public key

func WrapperFromPrivateKey

func WrapperFromPrivateKey(pri *bls.SecretKey) PrivateKeyWrapper

WrapperFromPrivateKey makes a PrivateKeyWrapper from bls secret key

type PublicKeyWrapper

type PublicKeyWrapper struct {
	Bytes  SerializedPublicKey
	Object *bls.PublicKey
}

PublicKeyWrapper defines the bls public key in both serialized and deserialized form.

type SerializedPublicKey

type SerializedPublicKey [PublicKeySizeInBytes]byte

SerializedPublicKey defines the serialized bls public key

func FromLibBLSPublicKeyUnsafe

func FromLibBLSPublicKeyUnsafe(key *bls.PublicKey) *SerializedPublicKey

FromLibBLSPublicKeyUnsafe could give back nil, use only in cases when have invariant that return value won't be nil

func (SerializedPublicKey) Big

func (pk SerializedPublicKey) Big() *big.Int

Big ..

func (*SerializedPublicKey) FromLibBLSPublicKey

func (pk *SerializedPublicKey) FromLibBLSPublicKey(key *bls.PublicKey) error

FromLibBLSPublicKey replaces the key contents with the given key,

func (SerializedPublicKey) Hex

func (pk SerializedPublicKey) Hex() string

Hex returns the hex string of bls public key

func (SerializedPublicKey) IsEmpty

func (pk SerializedPublicKey) IsEmpty() bool

IsEmpty returns whether the bls public key is empty 0 bytes

func (SerializedPublicKey) MarshalText

func (pk SerializedPublicKey) MarshalText() (text []byte, err error)

MarshalText so that we can use this as JSON printable when used as key in a map

type SerializedSignature

type SerializedSignature [BLSSignatureSizeInBytes]byte

SerializedSignature defines the bls signature

type ThresholdPolicy

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

ThresholdPolicy allows to specify a simple t-of-n policy requring that at least the given threshold number of participants t have cosigned to make a collective signature valid.

func NewThresholdPolicy

func NewThresholdPolicy(thold int) *ThresholdPolicy

NewThresholdPolicy returns a new ThresholdPolicy with the given threshold.

func (ThresholdPolicy) Check

func (p ThresholdPolicy) Check(m *Mask) bool

Check verifies that at least a threshold number of participants have contributed to a collective signature.

Jump to

Keyboard shortcuts

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