-
Notifications
You must be signed in to change notification settings - Fork 0
/
deposit-data.go
55 lines (44 loc) · 1.59 KB
/
deposit-data.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
54
55
package validator
import (
"github.com/Seb369888/smartnode/shared/types/eth2"
"github.com/ethereum/go-ethereum/common"
eth2types "github.com/wealdtech/go-eth2-types/v2"
"github.com/Seb369888/smartnode/shared/services/beacon"
)
// Get deposit data & root for a given validator key and withdrawal credentials
func GetDepositData(validatorKey *eth2types.BLSPrivateKey, withdrawalCredentials common.Hash, eth2Config beacon.Eth2Config, depositAmount uint64) (eth2.DepositData, common.Hash, error) {
// Build deposit data
dd := eth2.DepositDataNoSignature{
PublicKey: validatorKey.PublicKey().Marshal(),
WithdrawalCredentials: withdrawalCredentials[:],
Amount: depositAmount,
}
// Get signing root
or, err := dd.HashTreeRoot()
if err != nil {
return eth2.DepositData{}, common.Hash{}, err
}
sr := eth2.SigningRoot{
ObjectRoot: or[:],
Domain: eth2types.Domain(eth2types.DomainDeposit, eth2Config.GenesisForkVersion, eth2types.ZeroGenesisValidatorsRoot),
}
// Get signing root with domain
srHash, err := sr.HashTreeRoot()
if err != nil {
return eth2.DepositData{}, common.Hash{}, err
}
// Build deposit data struct (with signature)
var depositData = eth2.DepositData{
PublicKey: dd.PublicKey,
WithdrawalCredentials: dd.WithdrawalCredentials,
Amount: dd.Amount,
Signature: validatorKey.Sign(srHash[:]).Marshal(),
}
// Get deposit data root
depositDataRoot, err := depositData.HashTreeRoot()
if err != nil {
return eth2.DepositData{}, common.Hash{}, err
}
// Return
return depositData, depositDataRoot, nil
}