-
Notifications
You must be signed in to change notification settings - Fork 0
/
voluntary-exit.go
41 lines (32 loc) · 1008 Bytes
/
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
package validator
import (
"github.com/Seb369888/poolsea-go/types"
"github.com/Seb369888/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 uint64, epoch uint64, signatureDomain []byte) (types.ValidatorSignature, error) {
// Build voluntary exit message
exitMessage := eth2.VoluntaryExit{
Epoch: epoch,
ValidatorIndex: validatorIndex,
}
// 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
}