-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommitment.go
48 lines (39 loc) · 935 Bytes
/
commitment.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
package bbs
import (
"crypto/subtle"
"github.com/mikelodder7/bls12-381"
)
// The type for creating commitments to messages that are hidden during issuance.
type Commitment struct {
value *bls12381.PointG1
}
func (c Commitment) ToCompressed() []byte {
return g1.ToCompressed(c.value)
}
func (c *Commitment) FromCompressed(data []byte) error {
value, err := g1.FromCompressed(data)
if err != nil {
return err
}
c.value = value
return nil
}
func (c Commitment) ToUncompressed() []byte {
return g1.ToUncompressed(c.value)
}
func (c *Commitment) FromUncompressed(data []byte) error {
value, err := g1.FromUncompressed(data)
if err != nil {
return err
}
c.value = value
return nil
}
func (c Commitment) Equal(rhs Commitment) bool {
l := g1.ToCompressed(c.value)
r := g1.ToCompressed(rhs.value)
return subtle.ConstantTimeCompare(l, r) == 0
}
func (c *Commitment) Hash(data []byte) {
c.value = hashToG1(data)
}