commit.gno
1.10 Kb · 39 lines
1package types
2
3// COMMITMENT_MAGIC, COMMITMENT_MAGIC_ACK and mergeAck are defined in path.gno.
4
5// CommitPacket returns the Union commitment hash of a single packet.
6func CommitPacket(packet Packet) (H256, error) {
7 return CommitPackets([]Packet{packet})
8}
9
10// CommitPackets returns the Union commitment hash of a packet batch: the
11// keccak of the top-level-dynamic-wrapped ABI packet array.
12func CommitPackets(packets []Packet) (H256, error) {
13 encoded, err := encodeABIPacketArray(packets)
14 if err != nil {
15 return H256{}, err
16 }
17
18 return Keccak(wrapABIEncode(encoded)), nil
19}
20
21// MustCommit unwraps a commitment hash or panics on encoding errors.
22func MustCommit(h H256, err error) H256 {
23 if err != nil {
24 panic(err)
25 }
26
27 return h
28}
29
30// CommitAck returns the Union commitment hash of a single acknowledgement.
31func CommitAck(ack []byte) H256 {
32 return CommitAcks([][]byte{ack})
33}
34
35// CommitAcks returns the Union commitment hash of an acknowledgement batch,
36// with the leading byte replaced by the commitment magic.
37func CommitAcks(acks [][]byte) H256 {
38 return mergeAck(Keccak(wrapABIEncode(encodeABIBytesArray(acks))))
39}