├── README.md └── sample.go /README.md: -------------------------------------------------------------------------------- 1 | ## Demo: Aggregation and verification of signatures 2 | 3 | ### codebase:https://github.com/herumi/bls-eth-go-binary 4 | 5 | ### HOW TO START 6 | 7 | #### First: You need to create a new go project. And make sure you init the mod 8 | go mod init xxx 9 | 10 | #### Second: 11 | go get github.com/herumi/bls-eth-go-binary/ 12 | 13 | #### Run: 14 | go run sample.go 15 | -------------------------------------------------------------------------------- /sample.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/herumi/bls-eth-go-binary/bls" 7 | ) 8 | 9 | var msg string 10 | var msgbyte []byte 11 | var pubs = make(bls.PublicKeys,5) 12 | var signs = make([]bls.Sign,5) 13 | var aggSignbysec bls.Sign 14 | 15 | //The five private keys are signed separately 16 | func Sign() { 17 | for i := 0; i < 5; i++ { 18 | var sec bls.SecretKey 19 | sec.SetByCSPRNG() 20 | msgbyte = []byte(msg) 21 | pubs[i] = *sec.GetPublicKey() 22 | signs[i] = *sec.SignByte(msgbyte) 23 | fmt.Printf("public key !!!!!!!!!!!!!!!!!!!!!!\n") 24 | fmt.Printf("%d,%s\n", i, pubs[i].SerializeToHexStr()) 25 | fmt.Printf("signature !!!!!!!!!!!!!!!!!!!!!!\n") 26 | fmt.Printf("%d,%s\n", i, signs[i].SerializeToHexStr()) 27 | fmt.Printf("verify=%v\n", signs[i].VerifyByte(&pubs[i], msgbyte)) 28 | } 29 | 30 | } 31 | 32 | //Put the five signatures together 33 | func AggregateSign() { 34 | aggSignbysec.Aggregate(signs) 35 | 36 | 37 | } 38 | 39 | //Verify the aggregation signature 40 | func VerifyAggregateFast() { 41 | fmt.Printf("%s\n", aggSignbysec.FastAggregateVerify(pubs, msgbyte)) 42 | 43 | 44 | 45 | } 46 | 47 | 48 | func main() { 49 | bls.Init(bls.BLS12_381) 50 | bls.SetETHmode(bls.EthModeDraft07) 51 | Sign() 52 | AggregateSign() 53 | VerifyAggregateFast() 54 | } 55 | --------------------------------------------------------------------------------