29 lines
726 B
Go
29 lines
726 B
Go
package utils
|
|
|
|
import (
|
|
errorsmod "cosmossdk.io/errors"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
|
)
|
|
|
|
// cosmos-sdk crypto/keyring/record.go:138
|
|
func extractPrivKeyFromLocal(rl *keyring.Record_Local) (cryptotypes.PrivKey, error) {
|
|
if rl.PrivKey == nil {
|
|
return nil, keyring.ErrPrivKeyNotAvailable
|
|
}
|
|
|
|
priv, ok := rl.PrivKey.GetCachedValue().(cryptotypes.PrivKey)
|
|
if !ok {
|
|
return nil, errorsmod.Wrap(keyring.ErrCastAny, "PrivKey")
|
|
}
|
|
return priv, nil
|
|
}
|
|
|
|
func ExtractPrivateKey(kr keyring.Keyring, uid string) (cryptotypes.PrivKey, error) {
|
|
ethkr, err := kr.Key(uid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return extractPrivKeyFromLocal(ethkr.GetLocal())
|
|
}
|