-
Notifications
You must be signed in to change notification settings - Fork 5
/
jsdescription.go
40 lines (34 loc) · 906 Bytes
/
jsdescription.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
package ipldzec
import (
"encoding/binary"
"io"
)
type JSDescription struct {
OldVal uint64
NewVal uint64
Anchor []byte
Nullifiers [][]byte
Commitments [][]byte
EphemeralKey []byte
CipherTexts [][]byte
RandomSeed []byte
Macs [][]byte
Proof []byte
}
func (js *JSDescription) WriteTo(w io.Writer) (int, error) {
buf := make([]byte, 16)
binary.LittleEndian.PutUint64(buf, js.OldVal)
binary.LittleEndian.PutUint64(buf[8:], js.NewVal)
return writeMany(w, buf, js.Anchor, js.Nullifiers[0], js.Nullifiers[1], js.Commitments[0], js.Commitments[1], js.EphemeralKey, js.RandomSeed, js.Macs[0], js.Macs[1], js.Proof, js.CipherTexts[0], js.CipherTexts[1])
}
func writeMany(w io.Writer, bs ...[]byte) (int, error) {
var total int
for _, b := range bs {
n, err := w.Write(b)
if err != nil {
return total, err
}
total += n
}
return total, nil
}