From 6ae08003eee99b279ede1ec44ecb2ea2b8961a74 Mon Sep 17 00:00:00 2001 From: Samuel Laferriere Date: Thu, 8 Aug 2024 16:36:36 -0700 Subject: [PATCH] refactor(ecdsa/utils): use strings.TrimPrefix to trim 0x prefix --- crypto/ecdsa/utils.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crypto/ecdsa/utils.go b/crypto/ecdsa/utils.go index 00896218..e7ee72d9 100644 --- a/crypto/ecdsa/utils.go +++ b/crypto/ecdsa/utils.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/ethereum/go-ethereum/common" gethcommon "github.com/ethereum/go-ethereum/common" @@ -116,9 +117,7 @@ func GetAddressFromKeyStoreFile(keyStoreFile string) (gethcommon.Address, error) } func KeyAndAddressFromHexKey(hexkey string) (*ecdsa.PrivateKey, common.Address, error) { - if len(hexkey) > 2 && hexkey[:2] == "0x" { - hexkey = hexkey[2:] - } + hexkey = strings.TrimPrefix(hexkey, "0x") ecdsaSk, err := crypto.HexToECDSA(hexkey) if err != nil { return nil, common.Address{}, fmt.Errorf("failed to convert hexkey %s to ecdsa key: %w", hexkey, err)