fortesp / bitcoinaddress

Bitcoin Wallet Address Generator
https://pypi.org/project/bitcoinaddress/
MIT License
146 stars 54 forks source link

'seed' is not stored as instance variable in __init__ method of Key class #3

Closed jeanmonet closed 4 years ago

jeanmonet commented 4 years ago

First of all, thank you for sharing this library.

I noticed that the __init__ method of the Key class does not store the optionally passed seed value as an instance variable: https://github.com/fortesp/bitcoinaddress/blob/b7f4385b71688f162652e99b4bbe762a96969d12/bitcoinaddress/key.py#L12

Also, the generate() method does not try to use self.seed in case it was defined upon instantiation.

Consequently, when you do:

key = Key('some seed')
key.generate()

It will generate from a random seed instead of the value passed upon instantiation. For example here: https://github.com/fortesp/bitcoinaddress/blob/b7f4385b71688f162652e99b4bbe762a96969d12/bitcoinaddress/wallet.py#L11

To work, it would need to look like this (currently):

key = Key()
key.generate('some seed')

(Unrelated: it would be interesting if the Address class would provide convenience functions to convert one format to another without having a private key. The use case would be: I have a bc1 address and want to know its base58 version starting with 1 etc. This means one can have an Address instance without having a private key, but at least one version of the public key.)

fortesp commented 4 years ago

Thank you for posting this. I will fix it. For the unrelated it can be done. Just not sure if would be better to decouple that responsibility from the Address class. I will add it in the TODO Projects here. Thanks.