-
Notifications
You must be signed in to change notification settings - Fork 8
/
keys.go
53 lines (44 loc) · 1.3 KB
/
keys.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
package types
import (
"math/big"
host "github.com/bianjieai/tibc-go/modules/tibc/core/24-host"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
const (
paramsIndex = 104
paramsLenght = 32
)
type ProofKeyConstructor struct {
sourceChain string
destChain string
sequence uint64
}
func NewProofKeyConstructor(sourceChain string, destChain string, sequence uint64) ProofKeyConstructor {
return ProofKeyConstructor{
sourceChain: sourceChain,
destChain: destChain,
sequence: sequence,
}
}
func (k ProofKeyConstructor) GetPacketCommitmentProofKey() []byte {
hash := crypto.Keccak256Hash(
host.PacketCommitmentKey(k.sourceChain, k.destChain, k.sequence),
common.LeftPadBytes(big.NewInt(paramsIndex).Bytes(), paramsLenght),
)
return hash.Bytes()
}
func (k ProofKeyConstructor) GetAckProofKey() []byte {
hash := crypto.Keccak256Hash(
host.PacketAcknowledgementKey(k.sourceChain, k.destChain, k.sequence),
common.LeftPadBytes(big.NewInt(paramsIndex).Bytes(), paramsLenght),
)
return hash.Bytes()
}
func (k ProofKeyConstructor) GetCleanPacketCommitmentProofKey() []byte {
hash := crypto.Keccak256Hash(
host.CleanPacketCommitmentKey(k.sourceChain, k.destChain),
common.LeftPadBytes(big.NewInt(paramsIndex).Bytes(), paramsLenght),
)
return hash.Bytes()
}