github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/consensus/hotstuff/bls12-381/crypto_test.go (about)

     1  package bls
     2  
     3  import (
     4  	"encoding/hex"
     5  	"testing"
     6  
     7  	bls12381 "github.com/kilic/bls12-381"
     8  	"gotest.tools/assert"
     9  )
    10  
    11  func TestPrimitiveSign(t *testing.T) {
    12  	privkey := GeneratePrivateKey()
    13  	msg := []byte("primitive signing test")
    14  
    15  	compressed := bls12381.NewG1().ToCompressed(privkey.Public().point)
    16  	t.Log(hex.EncodeToString(compressed), len(compressed))
    17  
    18  	sig, _ := sign(privkey.sec, msg)
    19  	assert.Equal(t, true, verify(privkey.Public().point, msg, sig))
    20  }
    21  
    22  func TestPrimitiveAggregate(t *testing.T) {
    23  	msg := []byte("primitive signing test ")
    24  
    25  	pointg1 := make([]*bls12381.PointG1, 0, 10)
    26  	pointg2 := make([]*bls12381.PointG2, 0, 10)
    27  	for i := 0; i < 10; i++ {
    28  		privkey := GeneratePrivateKey()
    29  		sig, _ := sign(privkey.sec, msg)
    30  		pointg1 = append(pointg1, privkey.Public().point)
    31  		pointg2 = append(pointg2, sig)
    32  	}
    33  
    34  	assert.Equal(t, true, fastAggregateVerify(msg, combine(pointg2...), pointg1...))
    35  }