Skip to content

Instantly share code, notes, and snippets.

@badmofo
Created April 27, 2018 08:34
Show Gist options
  • Save badmofo/87fdfb9b864507bde3483d251c243ac2 to your computer and use it in GitHub Desktop.
Save badmofo/87fdfb9b864507bde3483d251c243ac2 to your computer and use it in GitHub Desktop.
convert bitcoin addr to bitcoin private addr
import bitcoin
def btc_to_btcp(addr):
assert addr[0] in ('1', '3') # we don't support bech32 addrs for now
addr_prefix = b'\x13\x25' if addr[0] == '1' else b'\x13\xaf'
pkh = bitcoin.b58check_to_bin(addr)
assert len(pkh) == 20
return bitcoin.bin_to_b58check(addr_prefix[1:2] + pkh, addr_prefix[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment