mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
9b008522b8
* make demo default * make minimal config a flag * lint * initialize config at the start * gaz * make main method cleaner * remove interop.go * fix test * lint * gaz * Update validator/accounts/interop.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * fix docker build * fix docker build
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package accounts
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
|
"github.com/prysmaticlabs/prysm/shared/interop"
|
|
"github.com/prysmaticlabs/prysm/shared/keystore"
|
|
)
|
|
|
|
// LoadUnencryptedKeys loads the unencrypted keys from the given file path.
|
|
func LoadUnencryptedKeys(path string) (map[string]*keystore.Key, error) {
|
|
log.Warn("Loading encrypted keys from disk. Do not do this in production!")
|
|
|
|
pth, err := filepath.Abs(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
r, err := os.Open(pth)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
validatorKeysUnecrypted, _, err := parseUnencryptedKeysFile(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
validatorKeys := make(map[string]*keystore.Key)
|
|
for _, item := range validatorKeysUnecrypted {
|
|
priv, err := bls.SecretKeyFromBytes(item)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
k, err := keystore.NewKeyFromBLS(priv)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
validatorKeys[hex.EncodeToString(priv.PublicKey().Marshal())] = k
|
|
}
|
|
|
|
return validatorKeys, nil
|
|
}
|
|
|
|
// InteropValidatorKeys deterministically generate the required amount of validator keys
|
|
// according to thr given index and count.
|
|
func InteropValidatorKeys(idx, count uint64) (map[string]*keystore.Key, error) {
|
|
log.Warn("Using interop deterministic generated validator keys.")
|
|
sks, _, err := interop.DeterministicallyGenerateKeys(idx, count)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
validatorKeys := make(map[string]*keystore.Key)
|
|
for _, priv := range sks {
|
|
k, err := keystore.NewKeyFromBLS(priv)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
validatorKeys[hex.EncodeToString(priv.PublicKey().Marshal())] = k
|
|
}
|
|
|
|
return validatorKeys, nil
|
|
}
|