Decode minikeys (like Casascius coin ones)#141
Decode minikeys (like Casascius coin ones)#141juestr wants to merge 7 commits intopetertodd:masterfrom
Conversation
bitcoin/base58.py
Outdated
| minikey = minikey.encode('ascii') | ||
| length = len(minikey) | ||
| if length not in [22, 30]: | ||
| raise InvalidMinikeyError('Minikey length %d is not 22 or 30' % length) |
There was a problem hiding this comment.
I suggest using str("length is {} yo").format(length) instead of using the % operator.
There was a problem hiding this comment.
Would you please explain why?
- % is not deprecated, and I find it even more readable
- % is used throughout the whole project
- for this use case the extra power of format provides no benefit as far as I can see
|
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. |
This adds decode_minikey to
base58.pyminikey.py. It checks for format and checksum errors.There are some test cases and an example cli tool: