From 8cd04006603bafc347d80288eeb844b3cd37b2cd Mon Sep 17 00:00:00 2001 From: Kefkius Date: Wed, 29 Oct 2014 21:10:59 -0400 Subject: [PATCH 1/2] add support for arbitrary version bytes --- coinkit/privatekey.py | 8 +++++++- coinkit/publickey.py | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/coinkit/privatekey.py b/coinkit/privatekey.py index 32ca007..c33d6a2 100644 --- a/coinkit/privatekey.py +++ b/coinkit/privatekey.py @@ -27,9 +27,11 @@ class BitcoinPrivateKey(): def wif_version_byte(cls): return (cls._pubkeyhash_version_byte + 128) % 256 - def __init__(self, private_key=None): + def __init__(self, private_key=None, pubkeyhash_version_byte = 0): """ Takes in a private key/secret exponent. """ + self._pubkeyhash_version_byte = pubkeyhash_version_byte + if not private_key: secret_exponent = random_secret_exponent(self._curve.order) elif is_int(private_key): @@ -92,6 +94,10 @@ def passphrase(self): else: raise Exception(_errors["NOT_A_BRAIN_WALLET"]) +class CoinPrivateKey(BitcoinPrivateKey): + def __init__(self, private_key=None, pubkeyhash_version_byte=0): + BitcoinPrivateKey.__init__(self, private_key, pubkeyhash_version_byte) + class LitecoinPrivateKey(BitcoinPrivateKey): _pubkeyhash_version_byte = 48 diff --git a/coinkit/publickey.py b/coinkit/publickey.py index d680c4d..978c8d0 100644 --- a/coinkit/publickey.py +++ b/coinkit/publickey.py @@ -67,6 +67,10 @@ def address(self): """ The address is the hash160 in b58check format. """ return self._hash160.address() +class CoinPublicKey(BitcoinPublicKey): + def __init__(self, public_key, version_byte = 0): + BitcoinPublicKey.__init__(self, public_key, version_byte) + class LitecoinPublicKey(BitcoinPublicKey): _version_byte = 48 From 0197a121c65b9a3673d4e67db395f203afe4b752 Mon Sep 17 00:00:00 2001 From: Kefkius Date: Thu, 30 Oct 2014 11:13:25 -0400 Subject: [PATCH 2/2] add wif version byte parameter --- coinkit/privatekey.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/coinkit/privatekey.py b/coinkit/privatekey.py index c33d6a2..2d5c538 100644 --- a/coinkit/privatekey.py +++ b/coinkit/privatekey.py @@ -27,10 +27,11 @@ class BitcoinPrivateKey(): def wif_version_byte(cls): return (cls._pubkeyhash_version_byte + 128) % 256 - def __init__(self, private_key=None, pubkeyhash_version_byte = 0): + def __init__(self, private_key=None, pubkeyhash_version_byte = 0, wif_version_byte=None): """ Takes in a private key/secret exponent. """ self._pubkeyhash_version_byte = pubkeyhash_version_byte + self._wif_version_byte = wif_version_byte if not private_key: secret_exponent = random_secret_exponent(self._curve.order) @@ -76,8 +77,12 @@ def to_hex(self): return binascii.hexlify(self.to_bin()) def to_wif(self): + if self._wif_version_byte is None: + wif_byte = self.wif_version_byte() + else: + wif_byte = self._wif_version_byte return b58check_encode(self.to_bin(), - version_byte=self.wif_version_byte()) + version_byte=wif_byte) def public_key(self): # lazily calculate and set the public key @@ -95,8 +100,8 @@ def passphrase(self): raise Exception(_errors["NOT_A_BRAIN_WALLET"]) class CoinPrivateKey(BitcoinPrivateKey): - def __init__(self, private_key=None, pubkeyhash_version_byte=0): - BitcoinPrivateKey.__init__(self, private_key, pubkeyhash_version_byte) + def __init__(self, private_key=None, pubkeyhash_version_byte=0, wif_version_byte=None): + BitcoinPrivateKey.__init__(self, private_key, pubkeyhash_version_byte, wif_version_byte) class LitecoinPrivateKey(BitcoinPrivateKey): _pubkeyhash_version_byte = 48