Hey everyone, I wanted to share some code I whipped up that might be handy for you.
It's not groundbreaking or anything, but it could definitely help with your security.
The code creates a private key using a random number between 2^204 and 2^256 for various cryptocurrencies and prints it out on your thermal printer without saving any key info on your device.
If you got a kick out of this, let me know =D
Check out the demo video
https://www.youtube.com/watch?v=E7q0ITuXCyk
Here’s my doge wallet 🤪
DMPeovrJCxyDoBH2n7bHsThsSejoHKFKPF
Generating wallets and printing them with a thermal printer
7 replies 221 views
paul.stakeHero Member
Posts: 651 · Reputation: 3798
#2Dec 10, 2017, 01:58 AM
Do you mean "without storing any data on the disk", instead? When the computer generates a private key, it temporarily stores it in memory, and can be accessed by any software with elevated privileges at that time.
It does not enhance security, apart from malware with read access to the disk space. You're still transmitting a private key into a printer with (most often) closed-source firmware, all of which usually have network access.
That's not something I would worry about. If you don't know the equipment you're using, you're at risk, and that wouldn't necessarily be because of the code used. If someone wants to read your PC's memory maliciously, they could access anything on it including banking data
I would worry more about that your code as far as I see it can at least in theory generate private keys outside the valid range.
To my knowledge private keys for Bitcoin must be in the range [1...n-1] with n being the generator point in hex
Chances are miniscule that your random generator produces a value above the maximum allowed value, but anyway it's possible if I read (and understand) your code properly.
Likely such an out-of-valid-bounds condition will be caught when you try to generate the public key from the private key. But who knows how well the imported library functions handle this.
Worst case: you have addresses that burn coins.
And the way you use the range bounds for random number generation looks somewhat odd to me, too. I don't code in Python, I can somewhat read and mostly understand Python code OKish. I wouldn't trust the way you generate random numbers as private keys here.
As long as secp256k1 is secure, I believe this code will also be. The smallest wallet it could generate would have at least
2²⁰⁴ and if you compare it to the most famous and true Bitcoin puzzle, its largest wallet is 2¹⁶⁰
The way I know to protect your cryptos from future quantum computers is to always keep the assets in a wallet where you have never sent a transaction. This way you protect your public key. In other words, if you send funds to someone the unspent should be sent to a new virgin privkey that you have access to.
secp256k1 is secure for more than 15 years, I've not seen any proof of the opposite so far. Your code doesn't prevent the generation of a random number for a private key that is out-of-bounds making the private key invalid.
You can believe what you want, lets hope other used library functions catch such edge cases.
I'm too lazy to calculate the probability that your used random generator will produce a value above the generator point value. We might not see it in our lifetime. I don't like conditionals very much when there could be certainty.
Anyway, lets hope nobody looses coins inspired by your code.
About generate private keys out of range, I just fixed this possible issue, thanks for the warn. However, when this happens, it basically generates an error, but prevention is never too much. I changed this line from: to
If you care about security, you should replace random with secrets (https://docs.python.org/3/library/secrets.html).
?Reply
Sign in to reply to this topic
Related topics
- Creating a list of non-zero wallets and their balances using Python 4
- Restoring wallets from pre-fork days 7
- Best practices for securely storing newly generated wallets programmatically 14
- Ukraine plans to restrict crypto wallets for illegal funds, says finance minister 9
- What Should I Know About Multisig Wallets? 13
- bitcoin-qt sync issues and slow speeds 6