Skip to content

Commit 291f57e

Browse files
author
Daisuke Kanda
committed
force assign geth's S256() as Curve value
Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
1 parent 12f1905 commit 291f57e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/wallet/wallet.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/btcsuite/btcd/btcutil/hdkeychain"
11+
gethcrypto "github.com/ethereum/go-ethereum/crypto"
1112
"github.com/btcsuite/btcd/chaincfg"
1213
bip39 "github.com/tyler-smith/go-bip39"
1314
)
@@ -124,7 +125,17 @@ func GetPrvKeyFromHDWallet(seed []byte, hp *HDPathLevel) (*ecdsa.PrivateKey, err
124125
if err != nil {
125126
return nil, err
126127
}
127-
return btcecPrivKey.ToECDSA(), nil
128+
129+
ecdsaPrivKey := btcecPrivKey.ToECDSA()
130+
131+
// The ecdsaPrivKey.Curve refers to pointer of dcrd.secp256k1.S256() and gethcrypto.S256() is embedded it.
132+
// Some environment(such as docker container) seems to return false in compare these values.
133+
// To fix that problem, simply replace ecdsaPrivKey.Curve value with gethcrypto.S256()
134+
if ecdsaPrivKey.Curve.Params().Name == "secp256k1" && ecdsaPrivKey.Curve != gethcrypto.S256() {
135+
ecdsaPrivKey.Curve = gethcrypto.S256()
136+
}
137+
138+
return ecdsaPrivKey, nil
128139
}
129140

130141
func GetPrvKeyFromMnemonicAndHDWPath(mnemonic, path string) (*ecdsa.PrivateKey, error) {

0 commit comments

Comments
 (0)