You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.0 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. package bls
  2. import (
  3. "fmt"
  4. "math/big"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestBls(t *testing.T) {
  9. bls, err := NewBLS()
  10. assert.Nil(t, err)
  11. keys0, err := bls.NewKeys()
  12. assert.Nil(t, err)
  13. fmt.Println("privK:", keys0.PrivK)
  14. fmt.Println("pubK:", keys0.PubK)
  15. m0 := []byte("message0")
  16. sig0 := bls.Sign(keys0.PrivK, m0)
  17. fmt.Println("signature:", sig0)
  18. verified := bls.Verify(m0, sig0, keys0.PubK)
  19. fmt.Println("one signature verified:", verified)
  20. assert.True(t, verified)
  21. // signature aggregation
  22. keys1, err := bls.NewKeys()
  23. assert.Nil(t, err)
  24. m1 := []byte("message1")
  25. sig1 := bls.Sign(keys1.PrivK, m1)
  26. keys2, err := bls.NewKeys()
  27. assert.Nil(t, err)
  28. m2 := []byte("message2")
  29. sig2 := bls.Sign(keys2.PrivK, m2)
  30. aggr := bls.AggregateSignatures(sig0, sig1, sig2)
  31. pubKArray := [][3]*big.Int{keys0.PubK, keys1.PubK, keys2.PubK}
  32. mArray := [][]byte{m0, m1, m2}
  33. verified = bls.VerifyAggregatedSignatures(aggr, pubKArray, mArray)
  34. fmt.Println("signature aggregation verified:", verified)
  35. assert.True(t, verified)
  36. }