all: cleanup imports (#524)

This commit is contained in:
Federico Kunze Küllmer
2021-09-03 18:06:36 +00:00
committed by GitHub
parent 945fa64853
commit c73ce0f812
30 changed files with 238 additions and 247 deletions
+12 -13
View File
@@ -6,11 +6,10 @@ import (
"crypto/subtle"
"fmt"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/crypto"
tmcrypto "github.com/tendermint/tendermint/crypto"
)
@@ -43,13 +42,13 @@ var (
// GenerateKey generates a new random private key. It returns an error upon
// failure.
func GenerateKey() (*PrivKey, error) {
priv, err := ethcrypto.GenerateKey()
priv, err := crypto.GenerateKey()
if err != nil {
return nil, err
}
return &PrivKey{
Key: ethcrypto.FromECDSA(priv),
Key: crypto.FromECDSA(priv),
}, nil
}
@@ -62,7 +61,7 @@ func (privKey PrivKey) Bytes() []byte {
func (privKey PrivKey) PubKey() cryptotypes.PubKey {
ecdsaPrivKey := privKey.ToECDSA()
return &PubKey{
Key: ethcrypto.CompressPubkey(&ecdsaPrivKey.PublicKey),
Key: crypto.CompressPubkey(&ecdsaPrivKey.PublicKey),
}
}
@@ -107,17 +106,17 @@ func (privKey *PrivKey) UnmarshalAminoJSON(bz []byte) error {
// provided hash of the message. The produced signature is 65 bytes
// where the last byte contains the recovery ID.
func (privKey PrivKey) Sign(digestBz []byte) ([]byte, error) {
if len(digestBz) != ethcrypto.DigestLength {
digestBz = ethcrypto.Keccak256Hash(digestBz).Bytes()
if len(digestBz) != crypto.DigestLength {
digestBz = crypto.Keccak256Hash(digestBz).Bytes()
}
return ethcrypto.Sign(digestBz, privKey.ToECDSA())
return crypto.Sign(digestBz, privKey.ToECDSA())
}
// ToECDSA returns the ECDSA private key as a reference to ecdsa.PrivateKey type.
// The function will panic if the private key is invalid.
func (privKey PrivKey) ToECDSA() *ecdsa.PrivateKey {
key, err := ethcrypto.ToECDSA(privKey.Bytes())
key, err := crypto.ToECDSA(privKey.Bytes())
if err != nil {
panic(err)
}
@@ -135,12 +134,12 @@ var (
// Address returns the address of the ECDSA public key.
// The function will panic if the public key is invalid.
func (pubKey PubKey) Address() tmcrypto.Address {
pubk, err := ethcrypto.DecompressPubkey(pubKey.Key)
pubk, err := crypto.DecompressPubkey(pubKey.Key)
if err != nil {
panic(err)
}
return tmcrypto.Address(ethcrypto.PubkeyToAddress(*pubk).Bytes())
return tmcrypto.Address(crypto.PubkeyToAddress(*pubk).Bytes())
}
// Bytes returns the raw bytes of the ECDSA public key.
@@ -196,11 +195,11 @@ func (pubKey *PubKey) UnmarshalAminoJSON(bz []byte) error {
//
// CONTRACT: The signature should be in [R || S] format.
func (pubKey PubKey) VerifySignature(msg []byte, sig []byte) bool {
if len(sig) == ethcrypto.SignatureLength {
if len(sig) == crypto.SignatureLength {
// remove recovery ID (V) if contained in the signature
sig = sig[:len(sig)-1]
}
// the signature needs to be in [R || S] format when provided to VerifySignature
return ethcrypto.VerifySignature(pubKey.Key, ethcrypto.Keccak256Hash(msg).Bytes(), sig)
return crypto.VerifySignature(pubKey.Key, crypto.Keccak256Hash(msg).Bytes(), sig)
}
+3 -3
View File
@@ -8,7 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
@@ -28,12 +28,12 @@ func TestPrivKey(t *testing.T) {
// validate Ethereum address equality
addr := privKey.PubKey().Address()
expectedAddr := ethcrypto.PubkeyToAddress(privKey.ToECDSA().PublicKey)
expectedAddr := crypto.PubkeyToAddress(privKey.ToECDSA().PublicKey)
require.Equal(t, expectedAddr.Bytes(), addr.Bytes())
// validate we can sign some bytes
msg := []byte("hello world")
sigHash := ethcrypto.Keccak256Hash(msg)
sigHash := crypto.Keccak256Hash(msg)
expectedSig, err := secp256k1.Sign(sigHash.Bytes(), privKey.Bytes())
require.NoError(t, err)
+4 -4
View File
@@ -5,8 +5,8 @@ import (
"github.com/btcsuite/btcutil/hdkeychain"
bip39 "github.com/tyler-smith/go-bip39"
ethaccounts "github.com/ethereum/go-ethereum/accounts"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/crypto"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
@@ -59,7 +59,7 @@ func (s ethSecp256k1Algo) Name() hd.PubKeyType {
// Derive derives and returns the eth_secp256k1 private key for the given mnemonic and HD path.
func (s ethSecp256k1Algo) Derive() hd.DeriveFn {
return func(mnemonic string, bip39Passphrase, path string) ([]byte, error) {
hdpath, err := ethaccounts.ParseDerivationPath(path)
hdpath, err := accounts.ParseDerivationPath(path)
if err != nil {
return nil, err
}
@@ -88,7 +88,7 @@ func (s ethSecp256k1Algo) Derive() hd.DeriveFn {
}
privateKeyECDSA := privateKey.ToECDSA()
derivedKey := ethcrypto.FromECDSA(privateKeyECDSA)
derivedKey := crypto.FromECDSA(privateKeyECDSA)
return derivedKey, nil
}