Should the private key start with 0x? Private key in invalid format error
kefirsutherman opened this issue · comments
in set_wallet_address()
there's this check to see if the private key is valid
if private_key:
if re.match(r"^0x[0-9a-zA-Z]{64}$", private_key) is None:
raise(IdexException("Private key in invalid format must satisfy 0x[0-9a-zA-Z]{64}"))
Why would the private key start with 0x
? I thought only public addresses started with the 0x prefix? Is there some conversion step I'm missing to convert my private key to a form that starts with 0x? As the code stands now I get this "Private key in invalid format error" every time. Did you mean for this to validate the private key or was this intended to validate public address
instead like this?
if address:
if re.match(r"^0x[0-9a-zA-Z]{64}$", address) is None:
raise(IdexException("Address in invalid format must satisfy 0x[0-9a-zA-Z]{64}"))
self._wallet_address = address.lower()
Hi @kefirsutherman you're correct in that Ethereum private keys don't start with an 0x, however the private key that is given to you by IDEX doesn't follow that convention.
This check is there to make sure that you're using the private key that is provided by IDEX.
Cool. I was wondering what was going on. I've been using a private key from an ethereum address I generated myself not an address generated through idex directly.
I was also getting errors of an invalid signature when trying to place a buy order. And I now see the issue is related. In _generate_signature()
it's removing the 0x chars:
# sign string
v, r, s = ecsign(salted, codecs.decode(self._private_key[2:], 'hex_codec'))
I removed the [2:]
slice and it works for me now with my private key:
# sign string
v, r, s = ecsign(salted, codecs.decode(self._private_key, 'hex_codec'))
@sammchardy Do does this mean that we can't connect using imported accounts? My primary trading address is one I imported in MetaMask.
@dahifi you can use any Ethereum address you control. Just prepend 0x to your public key.