Skip to content

Commit

Permalink
feat: encode 20-byte h160 to p2pkh and p2sh
Browse files Browse the repository at this point in the history
  • Loading branch information
enigbe committed Feb 18, 2022
1 parent 92476bd commit 3c98a7f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,26 @@ def p2pkh_script(h160):
"""
Takes a hash160 and returns the p2pkh ScriptPubKey
"""
return Script([0x76, 0xa9, h160, 0x88, 0xac])
return Script([0x76, 0xa9, h160, 0x88, 0xac])

def h160_to_p2pkh_address(h160: bytes, testnet=False):
"""
Encodes a 20-byte H160 to P2PKH address
"""
if testnet:
prefix = b'\x6f'
else:
prefix = b'\x00'

return encode_base58_checksum(prefix + h160)

def h160_to_p2sh_address(h160: bytes, testnet=False):
"""
Encodes a 20-byte H160 to P2PKH address
"""
if testnet:
prefix = b'\xc4'
else:
prefix = b'\x05'

return encode_base58_checksum(prefix + h160)

0 comments on commit 3c98a7f

Please sign in to comment.