From b878c010da775b114e0dc06373744b9a2ce56606 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Thu, 21 Jan 2016 08:11:50 +0900 Subject: [PATCH] Minikey: minimum length 20 On second thoughts there seems little reason to accept text of length <= 20 for minikeys. --- lib/bitcoin.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index bc6499fe..7e00d293 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -382,11 +382,12 @@ def is_private_key(key): def is_minikey(text): # Minikeys are typically 22 or 30 characters, but this routine - # permits any length provided the minikey is valid. A valid - # minikey must begin with an 'S', be in base58, and when suffixed - # with '?' have its SHA256 hash begin with a zero byte. They are - # widely used in Casascius physical bitoins. - return (text and text[0] == 'S' and all(c in __b58chars for c in text) + # permits any length of 20 or more provided the minikey is valid. + # A valid minikey must begin with an 'S', be in base58, and when + # suffixed with '?' have its SHA256 hash begin with a zero byte. + # They are widely used in Casascius physical bitoins. + return (len(text) >= 20 and text[0] == 'S' + and all(c in __b58chars for c in text) and ord(sha256(text + '?')[0]) == 0) def minikey_to_private_key(text):