-
Notifications
You must be signed in to change notification settings - Fork 633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decode minikeys (like Casascius coin ones) #141
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using str("length is {} yo").format(length)
instead of using the %
operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: