Luxor Forums - White Hat & Community Forums
Simple Bitcoin Wallet With Python!
#1
It's been a little while since someone posted in the Python section, and I love Python!!


Requirements
Now that you should have those installed we can start coding!


The first thing we are going to do is import the Pybitcointools module we installed.
from bitcoin import *

Now that we have that imported we can now use the bitcoin library in our program. Next, we are going to generate a private key...
from bitcoin import *

privateKey = random_key()

print (privateKey)
So what we did there was set a variable privateKey and called random_key() from the bitcoin library to generate random private keys. Then we used print (privateKey) to print out our private key, so if  you run the program you will see a bitcoin private key!

Now that we can generate private keys, we need to generate the public keys for those private keys.
from bitcoin import *

privateKey = random_key()
publicKey = privtopub(privateKey)

print (privateKey)
print (publicKey)
Now you can see we set another variable publicKey and called privtopub() from the bitcoin library which stands for 'private key to public key' to get the public key. Notice inside the parenthesis of privtopub() we put our private key variable, we did that so we get the public key from the same private key we generated. We also added another print to print out our public key aswell, so if you run the program now you will get a private key along with it's public key.

So we have a private & public key... Now it's time to get an address!
from bitcoin import *

privateKey = random_key()
publicKey = privtopub(privateKey)
address = pubtoaddr(publicKey)

print (privateKey)
print (publicKey)
print (address)
What we did here was set yet another variable address and called pubtoaddr() from the bitcoin library which stands for.... You guessed it, "public key to address". As you can see inside the parenthesis of pubtoaddr() we put our public key variable, that way we get the address from the same private/public key we generated. And we add another print to print our address with the private/public key, so if you run the program now you get a generated bitcoin private key. public key, and address!

We now have a bitcoin address/private key generator you can actually send bitcoin to! But one small problem... If you keep running the program you will notice each time you run the program it generates a new private key/address. So lets say you don't want to generate new private keys/addresses, and you want to keep generating the same private key/address and use it! Here's how you can do that!
from bitcoin import *

privateKey = sha256("LuxorForums Bitcoin Wallet")
publicKey = privtopub(privateKey)
address = pubtoaddr(publicKey)

print (privateKey)
print (publicKey)
print (address)
What we did here was change our privateKey variable from generating new random private keys, to generate the same private key by setting a passphrase to our private key. I used "LuxorForums Bitcoin Wallet" as the passphrase for this tutorial, you can use anything you can think of.  Now when you run the program you will get the same private/public key and address over & over as long as your passphrase doesn't change.

So if you run the following code above using my passphrase, you will generate:
"0b627b12f48c6b0ca147aea4426f4b22bec32b9d44e8f8ee0eb36374925607ec",
"04799de39266e1dfcdf175d0fa09e14af0f6518e05cbffab433a11809554cfbdf001cd25a2fb00904aadc05311df0b0cb67301e4bfbff7465a2a7975e30e50398e",
"1ChKxPC8Pa4hPNbygL8H8nbB4wyofAf2q1"
which is a bitcoin private key, public key, and address you can actually send bitcoin to.


And that's how simple it is to create your own bitcoin wallet! And all you have to do is remember that passphrase! So for me I'd have to remember "LuxorForums Bitcoin Wallet" if I wanted to use this as my bitcoin wallet. And anytime I want to get my address or private keys I can just create this small program and use my passphrase. This type of wallet is known as a "brain wallet" because you can remember your passphrase in your brain... duh. Rolleyes

If you have any questions, leave them below and I'll be glad to answer them! Pirate Bitcoin  



Warning:
I don't recommend you use this type of wallet for storing your bitcoin as a weak passphrase could be guessed by someone else, this is just of an example of how bitcoin wallets work and how you can generate your own wallets.
#2
Can you do something like a 10 phrase passcode for this kind of methodology that I have seen in other cryptowallets?

Obviously, if using a 10 phrase passcode would require an excellent memory, or actually printing out the passcodes on paper and storing that paper in a secure location. (fire-proof personal lockbox or bank safety deposit box)

Digital off-site storage is not recommended due to the potential for bad hackers getting ahold of that.
Owner

[Image: xwXpx1Z.png]
#3
(03-14-2018, 09:29 PM)Serpius Wrote: Can you do something like a 10 phrase passcode for this kind of methodology that I have seen in other cryptowallets?

Yes, you can make the passphrase as long as you'd like. However it is said that humans aren't very good at creating strong phrases which is why wallets like Ledger generate them for you.
Possibly Related Threads...
Thread
Author
  /  
Last Post
Replies: 0
Views: 773
06-09-2017, 05:57 PM
Last PostSteyr
Replies: 0
Views: 598
06-09-2017, 05:22 PM
Last PostSteyr
Replies: 0
Views: 253
08-21-2012, 04:02 PM
Last Postdabys07
Replies: 6
Views: 675
08-20-2012, 11:55 AM
Last PostNullVoid