Skip to content
This repository was archived by the owner on Sep 10, 2019. It is now read-only.
Merged
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
4 changes: 3 additions & 1 deletion neocore/Cryptography/Helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

long = int

ADDRESS_VERSION = 23


def double_sha256(ba):
"""
Expand Down Expand Up @@ -70,7 +72,7 @@ def scripthash_to_address(scripthash):
Returns:
str: base58 encoded string representing the wallet address.
"""
sb = bytearray([23]) + scripthash
sb = bytearray([ADDRESS_VERSION]) + scripthash
c256 = bin_dbl_sha256(sb)[0:4]
outb = sb + bytearray(c256)
return base58.b58encode(bytes(outb))
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cryptography.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ def test_publickey_to_redeemscript_to_scripthash_to_address(self):
self.assertEqual(scripthash, expected_scripthash)
self.assertEqual(address, expected_address)

def test_scripthash_to_address_with_alternative_version(self):
default_address_version = Helper.ADDRESS_VERSION
Helper.ADDRESS_VERSION = 42
scripthash = binascii.unhexlify('42112378ffa32c4c65d513aa350689dff6381154')
expected_address = 'J1DfV2jS511SMtP6dH5ckr3Nwf26kbFx7s'
address = Helper.scripthash_to_address(scripthash)

self.assertEqual(address, expected_address)

Helper.ADDRESS_VERSION = default_address_version

def test_publickey_to_scripthash(self):
expected_scripthash = binascii.unhexlify('79ecf967a02f9bdbd147fc97b18efd7877d27f78')
priv_key = KeyPair.PrivateKeyFromWIF('L44B5gGEpqEDRS9vVPz7QT35jcBG2r3CZwSwQ4fCewXAhAhqGVpP')
Expand Down