blsmultisig

package
v0.0.0-...-7ece11e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CCmprPnSz Compress point size
	CCmprPnSz = 32
	// CBigIntSz Big Int Byte array size
	CBigIntSz = 32
	// CMaskByte 0b10000000
	CMaskByte = 0x80
	// CNotMaskB 0b01111111
	CNotMaskB = 0x7F
	// CPKSz Public key size
	CPKSz = 128
	// CSKSz Secret key size
	CSKSz = 32
)
View Source
const (
	// CErr Error prefix
	CErr = "Details error: "
	// CErrInps Error input length
	CErrInps = "Input params error"
	// CErrCmpr Error when work with (de)compress
	CErrCmpr = "(De)Compress error"
)
View Source
const (
	UnExpectedError = iota
	InvalidPrivateKeyErr
	InvalidPublicKeyErr
	InvalidDataSignErr
	InvalidInputParamsSizeErr
	InvalidCommitteeInfoErr
	DecompressFromByteErr
	MemCacheErr
	JSONError
)

Variables

View Source
var (

	// CommonPKs cache list publickey point in an epoch
	CommonPKs []*bn256.G2
	// CommonAPs cache list publickey^a_i point in an epoch
	CommonAPs []*bn256.G2
	// CommonAis cache list a_i integer in an epoch
	CommonAis []*big.Int
)
View Source
var Cacher *cache.Cache
View Source
var ErrCodeMessage = map[int]struct {
	Code    int
	Message string
}{
	UnExpectedError:           {-1100, "Unexpected error"},
	InvalidPrivateKeyErr:      {-1101, "Private key is invalid"},
	InvalidPublicKeyErr:       {-1102, "Public key is invalid"},
	InvalidDataSignErr:        {-1103, "Signed data is invalid"},
	InvalidCommitteeInfoErr:   {-1104, "Committee's info is invalid"},
	InvalidInputParamsSizeErr: {-1105, "Len of Input Params is invalid"},
	DecompressFromByteErr:     {-1106, "Decompress bytes array to Elliptic point error"},
	JSONError:                 {-1107, "JSON Marshal, Unmarshal error"},
	MemCacheErr:               {-1108, "Memcache error"},
}

Functions

func AKGen

func AKGen(idxPKByte []byte, combinedPKBytes []byte) *bn256.G2

AKGen take a seed and return BLS secret key

func APKGen

func APKGen(committee []PublicKey, idx []int) *bn256.G2

func AiGen

func AiGen(listPKBytes []PublicKey, id int) *big.Int

func B2G1P

func B2G1P(bytes []byte) *bn256.G1

B2G1P is Bytes to Point, in BLS-BFT, it also called H0

func B2I

func B2I(bytes []byte) *big.Int

B2I convert byte array to big int which belong to Fp

func CmprG1

func CmprG1(pn *bn256.G1) []byte

CmprG1 take a point in G1 group and return bytes array

func CmprG2

func CmprG2(pn *bn256.G2) []byte

CmprG2 take a point in G1 group and return bytes array

func Combine

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

Combine combine list of bls signature

func DecmprG1

func DecmprG1(bytes []byte) (*bn256.G1, error)

DecmprG1 is

func DecmprG2

func DecmprG2(bytes []byte) (*bn256.G2, error)

DecmprG2 is

func G1P2I

func G1P2I(point *bn256.G1) *big.Int

G1P2I is Point to Big Int

func Hash4Bls

func Hash4Bls(data []byte) []byte

Hash4Bls is Hash function for calculate block hash this is different from hash function for calculate transaction hash

func I2Bytes

func I2Bytes(bn *big.Int, length int) []byte

I2Bytes take an integer and return bytes arrays of it with fixed length

func I2G1P

func I2G1P(bigInt *big.Int) *bn256.G1

I2G1P is Big Int to Point, in BLS-BFT, it called H0

func KeyGen

func KeyGen(seed []byte) (*big.Int, *bn256.G2)

KeyGen take an input seed and return BLS Key

func NewBLSSignatureError

func NewBLSSignatureError(key int, err error) error

func PKGen

func PKGen(sk *big.Int) *bn256.G2

PKGen take a secret key and return BLS public key

func SKGen

func SKGen(seed []byte) *big.Int

SKGen take a seed and return BLS secret key

func Sign

func Sign(data, skBytes []byte, selfIdx int, committee []PublicKey) ([]byte, error)

Sign return BLS signature

func Verify

func Verify(sig, data []byte, signersIdx []int, committee []PublicKey) (bool, error)

Verify verify BLS sig on given data and list public key

Types

type BLSSignatureError

type BLSSignatureError struct {
	Code    int
	Message string
	// contains filtered or unexported fields
}

func (BLSSignatureError) Error

func (e BLSSignatureError) Error() string

type PublicKey

type PublicKey []byte

PublicKey is bytes of PublicKey point compressed

func PKBytes

func PKBytes(pk *bn256.G2) PublicKey

PKBytes take input publickey point and return publickey bytes

type SecretKey

type SecretKey []byte

SecretKey is bytes of SecretKey big Int in Fp

func SKBytes

func SKBytes(sk *big.Int) SecretKey

SKBytes take input secretkey integer and return secretkey bytes

Jump to

Keyboard shortcuts

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