ofek / bit

Bitcoin made easy.
https://ofek.dev/bit/
MIT License
1.24k stars 216 forks source link

How do you generate a public address? #36

Closed linux-mining closed 6 years ago

linux-mining commented 6 years ago

I'm not sure where else to ask, but I can't seem to generate a public address(for sending transactions). According to your wiki after generating a private key via key = Key() I should be able to use the address attribute. but key.address give back the private key again and key.public_key generates something unusable (at least by a novice).

What am I doing wrong?

ofek commented 6 years ago

Can you paste some output?

linux-mining commented 6 years ago

>>>key = Key() >>>key <PrivateKey: 18wMXwGWsDcdB223wZTez8R7ntV3uS2r7L> >>>key.address '18wMXwGWsDcdB223wZTez8R7ntV3uS2r7L'

ofek commented 6 years ago

https://docs.python.org/3/tutorial/interpreter.html https://github.com/ofek/bit/blob/4568b1df1f4cc1dc4a8e4058f749c6a1f42fb5b2/bit/wallet.py#L404

linux-mining commented 6 years ago

Python 3.5.1 (default, Oct 21 2016, 21:37:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux Type "help", "copyright", "credits" or "license" for more information.

Sorry are you suggesting the wrong interpreter? This is the interpreter I'm using

ofek commented 6 years ago

Everything is working normally. Experiment by doing type(stuff).

linux-mining commented 6 years ago

So how to you generate a public key to share with others?

ofek commented 6 years ago

That's your address.

linux-mining commented 6 years ago

Its a bit concerning that the public key is equal to the private key. I guess I'm getting gas lighted at this point for missing something... <PrivateKey: 18wMXwGWsDcdB223wZTez8R7ntV3uS2r7L> key.address = 18wMXwGWsDcdB223wZTez8R7ntV3uS2r7L ?

ofek commented 6 years ago

It's not equal. I'd strongly advise getting a better grasp of Python before trying anything money-related!

linux-mining commented 6 years ago

Sorry just saw your last comment and it kind of bothers me.

I tested 2 other python implementations before yours and they worked fine without any knowledge of python (their issue trackers are a bit scary). I came to this site for the claims of great speed as I need to generate a lot of addresses on humble hardware.

I often, like many other programmers work on specifications I don't fully understand and often exploit programs that I can't fully inspect due to corporate time constraints. I just need to generate a lot of these and shove them into a database. I couldn't care less about what bitcoin does.

As an old (very old) C/Java programmer, most things look unintelligible to me. I'm sure you think your program is very special and the best at what it does. (maybe it is, who knows!).

For anyone who is in the same spot as me, search for the bitcoin core daemon keypool / wallet db. You can parse out from there. AWK did the trick just fine. Generating key pairs is apparently trivial, it spun up a million in a few minutes so my fears were not really founded anyway.

Anyways, good luck.

ofek commented 6 years ago
Python 3.6.1 | packaged by conda-forge | (default, May 23 2017, 14:21:39) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from bit import Key
>>> key = Key()
>>> key
<PrivateKey: 16XwWCi4egGL2sAnBAEik2eb8TXyfMjBZR>
>>> key.address
'16XwWCi4egGL2sAnBAEik2eb8TXyfMjBZR'
>>> type(key)
<class 'bit.wallet.PrivateKey'>
>>> type(key.address)
<class 'str'>

Does it make sense now?

linux-mining commented 6 years ago

Yes I understand one is apparently a custom class you designed vs a string literal. My interest was more a practical one. I simply needed to generate key pairs. I don't expect you to help my ignorance of bitcoin, it is just not clear to me how to generate these key pairs in the format that most end users expect to use.

Bitcoin core's daemon does exactly what I needed. It will spit out a private/public key pair in what ever format seems to be desired by end users. Issue is solved.

Somebody wants to give key pairs out on a website by demand, I simply seeded about 9 million keys into a database for them. I assume this will last well beyond our contract with them. Already tested and working with testnet addresses.

Thanks for your time.

ofek commented 6 years ago

Did you see this? https://ofek.github.io/bit/guide/keys.html#public-key

linux-mining commented 6 years ago

Yes of course I saw that. My issue is one of my own ignorance believe me. I simply couldn't get a private / public key pair in a format that matched what was specified.

Again, bitcoin core does this by default without any complications via the command line. Issue is resolved.

I can't recall a single instance in the last 20 years where I expected the end user to understand C or Java regardless of whether or not I intended to give assistance. Anyways I wish you good luck and I mean that sincerely.

You can mark as solved. Thanks again.

ofek commented 6 years ago

No problem, take care!

linux-mining commented 6 years ago

A kind soul pointed out to me what I was missing is the export call to generate the private key in the format I was expecting.

That would have helped last night but I appreciate the tip. I may be useful later.