Skip to content

Commit

Permalink
cli: Hex-encode secp256k1 keys
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Sep 16, 2022
1 parent 9bc7067 commit 52364e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 2 additions & 4 deletions cli/wallet/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/AlecAivazis/survey/v2"
ethCommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -285,10 +284,9 @@ func (af *fileAccountFactory) DataValidator(kind wallet.ImportKind, rawCfg map[s
}
case wallet.AlgorithmSecp256k1Raw:
// Ensure the private key is hex encoded.
a := strings.TrimPrefix(ans.(string), "0x")
_, err := hex.DecodeString(a)
_, err := hex.DecodeString(ans.(string))
if err != nil {
return fmt.Errorf("private key must be hex-encoded: %w", err)
return fmt.Errorf("private key must be hex-encoded (without leading 0x): %w", err)
}
default:
return fmt.Errorf("unsupported algorithm for %s: %s", wallet.ImportKindPrivateKey, cfg.Algorithm)
Expand Down
9 changes: 8 additions & 1 deletion cli/wallet/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"encoding/base64"
"encoding/hex"

ethCommon "github.com/ethereum/go-ethereum/common"
coreSignature "github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
Expand Down Expand Up @@ -45,13 +46,19 @@ func (a *testAccount) Address() types.Address {
}

func (a *testAccount) EthAddress() *ethCommon.Address {
return &a.testKey.EthAddress
if a.testKey.SigSpec.Secp256k1Eth != nil {
return &a.testKey.EthAddress
}
return nil
}

func (a *testAccount) SignatureAddressSpec() types.SignatureAddressSpec {
return a.testKey.SigSpec
}

func (a *testAccount) UnsafeExport() string {
if a.testKey.SigSpec.Secp256k1Eth != nil {
return hex.EncodeToString(a.testKey.SecretKey)
}
return base64.StdEncoding.EncodeToString(a.testKey.SecretKey)
}

0 comments on commit 52364e6

Please sign in to comment.