@@ -2,6 +2,7 @@ package beaconapiclient
2
2
3
3
import (
4
4
"context"
5
+ "encoding/hex"
5
6
"encoding/json"
6
7
"fmt"
7
8
"io"
@@ -25,14 +26,14 @@ type ValidatorData struct {
25
26
}
26
27
27
28
type Validator struct {
28
- Pubkey blst. P1Affine `json:"pubkey"`
29
- WithdrawalCredentials string `json:"withdrawal_credentials,string "`
30
- EffectiveBalance uint64 `json:"effective_balance,string"`
31
- Slashed bool `json:"slashed"`
32
- ActivationEligibilityEpoch uint64 `json:"activation_eligibility_epoch,string"`
33
- ActivationEpoch uint64 `json:"activation_epoch,string"`
34
- ExitEpoch uint64 `json:"exit_epoch,string"`
35
- WithdrawalEpoch uint64 `json:"withdrawal_epoch,string"`
29
+ PubkeyHex string `json:"pubkey"`
30
+ WithdrawalCredentials string `json:"withdrawal_credentials"`
31
+ EffectiveBalance uint64 `json:"effective_balance,string"`
32
+ Slashed bool `json:"slashed"`
33
+ ActivationEligibilityEpoch uint64 `json:"activation_eligibility_epoch,string"`
34
+ ActivationEpoch uint64 `json:"activation_epoch,string"`
35
+ ExitEpoch uint64 `json:"exit_epoch,string"`
36
+ WithdrawalEpoch uint64 `json:"withdrawal_epoch,string"`
36
37
}
37
38
38
39
func (c * Client ) GetValidatorByIndex (
@@ -71,3 +72,23 @@ func (c *Client) GetValidatorByIndex(
71
72
72
73
return response , nil
73
74
}
75
+
76
+ func (v * Validator ) GetPubkey () (* blst.P1Affine , error ) {
77
+ pubkeyHex := v .PubkeyHex
78
+ if pubkeyHex [:2 ] == "0x" {
79
+ pubkeyHex = pubkeyHex [2 :]
80
+ }
81
+
82
+ pubkeyBytes , err := hex .DecodeString (pubkeyHex )
83
+ if err != nil {
84
+ return nil , errors .Wrap (err , "failed to hex decode validator pubkey" )
85
+ }
86
+
87
+ pubkey := new (blst.P1Affine )
88
+ pubkey = pubkey .Uncompress (pubkeyBytes )
89
+ if pubkey == nil {
90
+ return nil , errors .New ("failed to deserialize pubkey" )
91
+ }
92
+
93
+ return pubkey , nil
94
+ }
0 commit comments