python-bitcoinlib
python-bitcoinlib copied to clipboard
Decode minikeys (like Casascius coin ones)
This adds decode_minikey to ~~base58.py~~ minikey.py. It checks for format and checksum errors.
There are some test cases and an example cli tool:
$ ./examples/minikey.py -h
usage: minikey.py [-h] minikey
Decode a minikey to base58 format.
positional arguments:
minikey the minikey
optional arguments:
-h, --help show this help message and exit
Security warning: arguments may be visible to other users on the same host.
$ ./examples/minikey.py S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy
5JPy8Zg7z4P7RSLsiqcqyeAF1935zjNUdMxcDeVrtU1oarrgnB7
I think the minikey functionality should be in a different file than base58.
Also, it doesn't make sense to decode minikeys to base58 - minikey decoding should be done to/from raw private keys.
Right, I was blinded by my use case. Btw there is no way to create a minikey from a raw key, it's one way only. I am going to extract everything to a minikey.py when I find time.
Ah right, I should have realized a minikey is obviously a one-way transformation.
Note that you also may consider just making this functionality a separate Python library - it might even be easier for people to find that way given that they may not be expecting to find such an old standard in a newer library.
It's just a few lines of code so I moved it to minikey.py and fixed the return type. If you don't want it in here at all that's fine for me too.
Btw, the magic constructor of CBitcoinSecret confused me quite a bit.