-
Notifications
You must be signed in to change notification settings - Fork 108
/
voluntary-exit.go
50 lines (39 loc) · 1.22 KB
/
voluntary-exit.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
package validator
import (
"fmt"
"strconv"
"github.com/rocket-pool/rocketpool-go/types"
"github.com/rocket-pool/smartnode/shared/types/eth2"
eth2types "github.com/wealdtech/go-eth2-types/v2"
)
// Get a voluntary exit message signature for a given validator key and index
func GetSignedExitMessage(validatorKey *eth2types.BLSPrivateKey, validatorIndex string, epoch uint64, signatureDomain []byte) (types.ValidatorSignature, error) {
// Parse the validator index
indexNum, err := strconv.ParseUint(validatorIndex, 10, 64)
if err != nil {
return types.ValidatorSignature{}, fmt.Errorf("error parsing validator index (%s): %w", validatorIndex, err)
}
// Build voluntary exit message
exitMessage := eth2.VoluntaryExit{
Epoch: epoch,
ValidatorIndex: indexNum,
}
// Get object root
or, err := exitMessage.HashTreeRoot()
if err != nil {
return types.ValidatorSignature{}, err
}
// Get signing root
sr := eth2.SigningRoot{
ObjectRoot: or[:],
Domain: signatureDomain,
}
srHash, err := sr.HashTreeRoot()
if err != nil {
return types.ValidatorSignature{}, err
}
// Sign message
signature := validatorKey.Sign(srHash[:]).Marshal()
// Return
return types.BytesToValidatorSignature(signature), nil
}