-
Notifications
You must be signed in to change notification settings - Fork 3
/
hashing.go
43 lines (39 loc) · 1.05 KB
/
hashing.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
package crossdomain
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
// HashCrossDomainMessageV0 computes the pre bedrock cross domain messaging
// hashing scheme.
func HashCrossDomainMessageV0(
target common.Address,
sender common.Address,
data []byte,
nonce *big.Int,
) (common.Hash, error) {
encoded, err := EncodeCrossDomainMessageV0(target, sender, data, nonce)
if err != nil {
return common.Hash{}, err
}
hash := crypto.Keccak256(encoded)
return common.BytesToHash(hash), nil
}
// HashCrossDomainMessageV1 computes the first post bedrock cross domain
// messaging hashing scheme.
func HashCrossDomainMessageV1(
nonce *big.Int,
sender common.Address,
target common.Address,
mntValue *big.Int,
ethValue *big.Int,
gasLimit *big.Int,
data []byte,
) (common.Hash, error) {
encoded, err := EncodeCrossDomainMessageV1(nonce, sender, target, mntValue, ethValue, gasLimit, data)
if err != nil {
return common.Hash{}, err
}
hash := crypto.Keccak256(encoded)
return common.BytesToHash(hash), nil
}