forked from ChainSafe/go-schnorrkel
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbatch_test.go
More file actions
57 lines (45 loc) · 1.26 KB
/
batch_test.go
File metadata and controls
57 lines (45 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package schnorrkel
import (
"fmt"
"github.com/gtank/merlin"
"testing"
)
func TestVerifyBatch(t *testing.T) {
batchSize := 8
message := "hello world"
transcripts := make([]*merlin.Transcript, batchSize, batchSize)
pubkeys := make([]*PublicKey, batchSize, batchSize)
privkeys := make([]*SecretKey, batchSize, batchSize)
signatures := make([]*Signature, batchSize, batchSize)
var err error
for i, _ := range transcripts {
transcripts[i] = merlin.NewTranscript(message)
privkeys[i], pubkeys[i], err = GenerateKeypair()
if err != nil {
fmt.Println(err)
return
}
// produce signatres and make sure all are correct signatures
signingTranscript := merlin.NewTranscript(message)
signatures[i], err = privkeys[i].Sign(signingTranscript)
if err != nil {
fmt.Println(err)
return
}
verificationTranscript := merlin.NewTranscript(message)
ok := pubkeys[i].Verify(signatures[i], verificationTranscript)
if !ok {
t.Fatalf("bad signature")
}
}
ok, _ := VerifyBatch(transcripts, pubkeys, signatures)
if !ok {
t.Fatalf("VerifyBatch failed")
}
// swap two public keys, VerifyBatch should fail
pubkeys[0], pubkeys[1] = pubkeys[1], pubkeys[0]
ok, _ = VerifyBatch(transcripts, pubkeys, signatures)
if ok {
t.Fatalf("VerifyBatch failed")
}
}