Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import binascii
- from bitcoin import bin_hash160
- from bitcoin import bip32_serialize
- from bitcoin import compress
- def main(parent_pubkey, pubkey, chaincode, depth, index, network):
- if (network.lower() == "main"):
- network_bytes = b'x04x88xb2x1e'
- elif (network.lower() == "test"):
- network_bytes = b'x04x35x87xcf'
- else:
- sys.exit("network must be either main or test")
- compressed_pubkey_bytes = binascii.unhexlify(compress(pubkey))
- fingerprint_bytes = bin_hash160(binascii.unhexlify(compress(parent_pubkey)))[:4]
- chaincode_bytes = binascii.unhexlify(chaincode)
- deserialized = (network_bytes, int(depth), fingerprint_bytes, int(index), chaincode_bytes, compressed_pubkey_bytes)
- xpub = bip32_serialize(deserialized)
- print(xpub)
- if __name__ == '__main__':
- if (len(sys.argv) < 7):
- sys.exit("USAGE: generate_xpub PARENT_PUBLICKEY PUBLICKEY CHAINCODE DEPTH INDEX (MAIN|TEST)")
- main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6])
Add Comment
Please, Sign In to add comment