mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package local
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
|
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
|
"github.com/prysmaticlabs/prysm/v3/validator/keymanager"
|
|
keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4"
|
|
)
|
|
|
|
// ExtractKeystores retrieves the secret keys for specified public keys
|
|
// in the function input, encrypts them using the specified password,
|
|
// and returns their respective EIP-2335 keystores.
|
|
func (_ *Keymanager) ExtractKeystores(
|
|
_ context.Context, publicKeys []bls.PublicKey, password string,
|
|
) ([]*keymanager.Keystore, error) {
|
|
lock.Lock()
|
|
defer lock.Unlock()
|
|
encryptor := keystorev4.New()
|
|
keystores := make([]*keymanager.Keystore, len(publicKeys))
|
|
for i, pk := range publicKeys {
|
|
pubKeyBytes := pk.Marshal()
|
|
secretKey, ok := secretKeysCache[bytesutil.ToBytes48(pubKeyBytes)]
|
|
if !ok {
|
|
return nil, fmt.Errorf(
|
|
"secret key for public key %#x not found in cache",
|
|
pubKeyBytes,
|
|
)
|
|
}
|
|
cryptoFields, err := encryptor.Encrypt(secretKey.Marshal(), password)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(
|
|
err,
|
|
"could not encrypt secret key for public key %#x",
|
|
pubKeyBytes,
|
|
)
|
|
}
|
|
id, err := uuid.NewRandom()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
keystores[i] = &keymanager.Keystore{
|
|
Crypto: cryptoFields,
|
|
ID: id.String(),
|
|
Pubkey: fmt.Sprintf("%x", pubKeyBytes),
|
|
Version: encryptor.Version(),
|
|
Name: encryptor.Name(),
|
|
}
|
|
}
|
|
return keystores, nil
|
|
}
|