-
Notifications
You must be signed in to change notification settings - Fork 2
/
committablePublicKeys.go
39 lines (30 loc) · 1.38 KB
/
committablePublicKeys.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
package merklesignature
import (
"encoding/binary"
"github.com/algorand/go-stateproof-verification/stateproofcrypto"
)
const KeysInMSS stateproofcrypto.HashID = "KP"
type (
// CommittablePublicKey is used to create a binary representation of public keys in the merkle
// signature scheme.
CommittablePublicKey struct {
VerifyingKey stateproofcrypto.FalconVerifier
Round uint64
}
)
// ToBeHashed returns the sequence of bytes that would be used as an input for the hash function when creating a merkle tree.
// In order to create a more SNARK-friendly commitment we must avoid using the msgpack infrastructure.
// msgpack creates a compressed representation of the struct which might be varied in length, this will
// be bad for creating SNARK
func (e *CommittablePublicKey) ToBeHashed() (stateproofcrypto.HashID, []byte) {
verifyingRawKey := e.VerifyingKey.GetFixedLengthHashableRepresentation()
var roundAsBytes [8]byte
binary.LittleEndian.PutUint64(roundAsBytes[:], e.Round)
var schemeAsBytes [2]byte
binary.LittleEndian.PutUint16(schemeAsBytes[:], CryptoPrimitivesID)
keyCommitment := make([]byte, 0, len(schemeAsBytes)+len(verifyingRawKey)+len(roundAsBytes))
keyCommitment = append(keyCommitment, schemeAsBytes[:]...)
keyCommitment = append(keyCommitment, roundAsBytes[:]...)
keyCommitment = append(keyCommitment, verifyingRawKey...)
return KeysInMSS, keyCommitment
}