Documentation ¶
Index ¶
- Constants
- Variables
- func AggregateMasks(a, b []byte) ([]byte, error)
- func AggregateSig(sigs []*bls.Sign) *bls.Sign
- func BytesToBLSPublicKey(bytes []byte) (*bls.PublicKey, error)
- func RandPrivateKey() *bls.SecretKey
- func SeparateSigAndMask(commitSigs []byte) ([]byte, []byte, error)
- type CompletePolicy
- type Mask
- func (m *Mask) Clear()
- func (m *Mask) CountEnabled() int
- func (m *Mask) CountTotal() int
- func (m *Mask) GetPubKeyFromMask(flag bool) []*bls.PublicKey
- func (m *Mask) GetSignedPubKeysFromBitmap(bitmap []byte) ([]*PublicKeyWrapper, error)
- func (m *Mask) IndexEnabled(i int) (bool, error)
- func (m *Mask) KeyEnabled(public SerializedPublicKey) (bool, error)
- func (m *Mask) Len() int
- func (m *Mask) Mask() []byte
- func (m *Mask) SetBit(i int, enable bool) error
- func (m *Mask) SetKey(public SerializedPublicKey, enable bool) error
- func (m *Mask) SetKeysAtomic(publics []*PublicKeyWrapper, enable bool) error
- func (m *Mask) SetMask(mask []byte) error
- type Policy
- type PrivateKeyWrapper
- type PublicKeyWrapper
- type SerializedPublicKey
- type SerializedSignature
- type ThresholdPolicy
Constants ¶
const ( PublicKeySizeInBytes = 48 BLSSignatureSizeInBytes = 96 )
PublicKeySizeInBytes ..
Variables ¶
var (
// BLSPubKeyCache is the Cache of the Deserialized BLS PubKey
BLSPubKeyCache, _ = lru.New(blsPubKeyCacheSize)
)
Functions ¶
func AggregateMasks ¶
AggregateMasks computes the bitwise OR of the two given participation masks.
func AggregateSig ¶
AggregateSig aggregates all the BLS signature into a single multi-signature.
func BytesToBLSPublicKey ¶
BytesToBLSPublicKey converts bytes into bls.PublicKey pointer.
func RandPrivateKey ¶
RandPrivateKey returns a random private key.
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 ¶
CountEnabled returns the number of enabled nodes in the CoSi participation Bitmap.
func (*Mask) CountTotal ¶
CountTotal returns the total number of nodes this CoSi instance knows.
func (*Mask) GetPubKeyFromMask ¶
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 ¶
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) SetBit ¶
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.
type Policy ¶
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.
func WrapperPublicKeyFromString ¶
func WrapperPublicKeyFromString(pubkey string) (*PublicKeyWrapper, error)
WrapperPublicKeyFromString makes a PublicKeyWrapper from public key hex string
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) 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.