python-bitcoinlib icon indicating copy to clipboard operation
python-bitcoinlib copied to clipboard

Decode minikeys (like Casascius coin ones)

Open juestr opened this issue 8 years ago • 4 comments

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

juestr avatar Jul 01 '17 06:07 juestr

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.

petertodd avatar Jul 21 '17 16:07 petertodd

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.

juestr avatar Jul 21 '17 19:07 juestr

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.

petertodd avatar Jul 23 '17 23:07 petertodd

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.

juestr avatar Jul 30 '17 00:07 juestr