Skip to content
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

add support for arbitrary version bytes #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions coinkit/privatekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ 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, 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)
elif is_int(private_key):
Expand Down Expand Up @@ -74,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
Expand All @@ -92,6 +99,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, wif_version_byte=None):
BitcoinPrivateKey.__init__(self, private_key, pubkeyhash_version_byte, wif_version_byte)

class LitecoinPrivateKey(BitcoinPrivateKey):
_pubkeyhash_version_byte = 48

Expand Down
4 changes: 4 additions & 0 deletions coinkit/publickey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down