-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_example_test.go
87 lines (73 loc) · 1.57 KB
/
api_example_test.go
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package musig2_test
import (
"bytes"
"fmt"
mathrand "math/rand"
"github.com/sammyne/musig2"
"github.com/sammyne/musig2/sr25519"
)
func ExampleVerify() {
msg := []byte("hello-world")
mRand := mathrand.New(mathrand.NewSource(123))
privA, err := sr25519.GenerateKey(mRand)
if err != nil {
panic(err)
}
privB, err := sr25519.GenerateKey(mRand)
if err != nil {
panic(err)
}
msA, err := musig2.NewMuSig2(mRand, privA, msg)
if err != nil {
panic(err)
}
msB, err := musig2.NewMuSig2(mRand, privB, msg)
if err != nil {
panic(err)
}
noncesA, err := msA.OurNonces()
if err != nil {
panic(err)
}
noncesB, err := msB.OurNonces()
if err != nil {
panic(err)
}
if err := msA.AddOtherNonces(msB.PublicKey().MustMarshalBinary(), noncesB); err != nil {
panic(err)
}
if err := msB.AddOtherNonces(msA.PublicKey().MustMarshalBinary(), noncesA); err != nil {
panic(err)
}
cosigA, err := msA.OurCosig()
if err != nil {
panic(err)
}
cosigB, err := msB.OurCosig()
if err != nil {
panic(err)
}
if err := msA.AddOtherCosig(msB.PublicKey().MustMarshalBinary(), cosigB); err != nil {
panic(err)
}
if err := msB.AddOtherCosig(msA.PublicKey().MustMarshalBinary(), cosigA); err != nil {
panic(err)
}
sigA, err := msA.Sign()
if err != nil {
panic(err)
}
sigB, err := msB.Sign()
if err != nil {
panic(err)
}
if !bytes.Equal(sigA, sigB) {
panic("mismatch sig")
}
Xs := []*sr25519.PublicKey{&privA.PublicKey, &privB.PublicKey}
if err := musig2.Verify(Xs, msg, sigA); err != nil {
panic(fmt.Sprintf("verify failed: %v", err))
}
// Output:
//
}