I had been hearing about Bitcoin for years, but I had never truly explored how the underlying technology worked. One day, I decided to go deep, not just to read about it, but to build something real.
So I set myself a challenge: implement a Bitcoin wallet from scratch, to understand how cryptographic keys, signatures, and address derivation work.As I progressed, I focused on making a cold wallet.
What Is a Cold Wallet?A cold wallet is a cryptocurrency wallet that stays completely offline. It never connects to the internet, which protects your private keys. You can generate keys, public adresses, view balances, and sign transactions safely. It's one of the most secure ways to store digital assets.
How Bitcoin Works? (Explained Like You're 10)Imagine a giant space with more treasure chests than atoms in the universe. 99.99999% are empty, and it’s impossible to check them all, it would take forever.
When creating a Bitcoin wallet, you randomly choose a number which corresponds to the position of one chest in this vast universe that number becomes your secret key also known as your seed.
You then generate a public address, derived from your seed, which others can see to send coins, but only you know the position of the chest.
Since the seed is just a long numbers, it is hard to remember, so we convert the seed into a list of 24 words (like "apple", "river", "moon"), called a mnemonic phrase, for easy backup and recovery.
This is the seed that Bitcoin Card Wallet will use, keeping it out of reach from everything while still allowing Bitcoin sending and receiving operations.
Why the M5Stack Cardputer ?The Cardputer is a compact embedded device with a screen, keyboard, SD slot, HID support, and USB-C port making it ideal for isolated cryptographic applications. It’s inexpensive, portable, and well-made.
Building It from the Ground UpTo understand how Bitcoin wallets actually work, I started by implementing the core building blocks:
- 🔐 Mnemonic phrase generation (BIP-39 standard)
- 🧾 Public XPUB generation
- 🔑 Deterministic key derivation (BIP-32 / BIP-44 paths)
- ✍️ Offline digital signature using PSBT structures
At the heart of it all is the seed, a large, unpredictable number that acts as the root of your wallet. Getting this part right is critical for security, so I designed a custom entropy system to make sure it’s truly random.
- 🧬 ESP32 hardware random
- ⚙️ A deterministic pseudorandom generator
- 🎲 The ESP software random function
- 🖱️ User input entropy from button presses timing
All these values are XOR-mixed to produce a single high-entropy seed. This approach ensures that even if one source is weak or compromised, the final result remains unpredictable and secure.
Secure Seed StorageBecause the Cardputer may be reflashed or reused, internal memory isn't reliable for sensitive key material. The SD cards can be accessed by other firmware which is not secure enough.
✅ The firmware supports storing the secret key on an RFID tag using the M5Stack RFID2 module. It can be stored encrypted or plain (not recommended), and loaded when needed for signing or restoring the wallet.
✅ Manual mnemonic entry is also supported at any time, so it is possible to store the seed solely on paper and load it when it's needed.
Using the InterfaceThe user interacts through the device’s built-in screen and keyboard.Operations like key generation, public key export, signature generation, QRCode, USB Typing, and PSBT file handling can be done fully offline, with no network exposure.
For full technical details — including how the seed is generated, how keys are derived, how to interact with PSBT files, and how to interface the Cardputer with popular wallets like Sparrow, check out the official GitHub repository.
You’ll also find many other open-source firmwares I’ve developed for the M5Stack Cardputer. You can also find them ready to flash on the M5Burner software.
Comments