How to make sure, Bitcoin private key and bitcoin address generator tools are generating valid key pair?

0

2

I find lots of tools/scripts written in python which can generate random number then using this random number it generates Bitcoin Private key(WIF) -> Bitcoin Address pair.

I have tried verifying few pairs using www.bitaddress.org >> Wallet Details by entering WIF key and verifying with output address.

But How can one make sure, the tools/scripts will always generate valid address and key pair ?

or is this like this way

if it generates one valid address and key pair it means all the future address and key pairs will be valid ?

i was looking at this https://github.com/shirriff/bitcoin-code

from makeAddr.py

import random, keyUtils
private_key = ''.join(['%x' % random.randrange(16) for x in range(0, 64)])
print keyUtils.privateKeyToWif(private_key)
print keyUtils.keyToAddr(private_key)

i know random number/string generated using this method is not very much secure, but i am talking in terms of valid WIF and address pair.

AMB

Posted 2017-08-18T15:21:13.553

Reputation: 292

Read the rfc's and write your own is only real way. There could be bugs? But outside of that this is good question. I think bitcoin.org recommends some.marshal craft 2017-08-19T04:03:35.093

Answers

1

you need to make sure that the private is lower than 1.158 * 10^77 (115792089237316195423570985008687907852837564279074904382605163141518161494337) and

In your case you could do

 import random, keyUtils 
 private_key = ''.join(['%x' %random.randrange(16) for x in range(0, 64)]) 
 print keyUtils.privateKeyToWif(private_key)
 print keyUtils.keyToAddr(private_key)

 from ecdsa.curves import SECP256k1
 decoded_private_key = int(private_key,16)
 if decoded_private_key > 0 and  decoded_private_key < SECP256k1.generator.order():
     print 'valid'
 else:
     print 'invalid'

carvmarc

Posted 2017-08-18T15:21:13.553

Reputation: 126

File "mycode\bitcoin-code-master\makeAddr.py", line 8, in <module> if decoded_private_key > 0 and decode_private_key < SECP256k1.generator.order(): NameError: name 'decode_private_key' is not definedAMB 2017-08-19T04:08:18.150

dang, idk how i too missed that.AMB 2017-08-19T04:16:44.140