vbuterin / pybitcointools

SImple, common-sense Bitcoin-themed Python ECC library
1.28k stars 856 forks source link

Electrum 2 XPUB public master key #157

Open vstoykovbg opened 7 years ago

vstoykovbg commented 7 years ago

Create keys and addresses from Electrum 2 XPUB public master key

New functions: electrum_pubkey_v2 and electrum_address_v2.

Example code:

#!/usr/bin/python3

from bitcoin import *

this_Electrum_v2_XPUB_master_public_key = "xpub661MyMwAqRbcFdBCo3DNoAd2jxiTshTYz2zdx7wDmnWtkFVe5Egzkb7dwsKbgGPj4SjEHSnRawewD1PJYLbQsZaXVGoaMQVmVc4SMXurZGw"

print ("\n * Public \"receive\" addresses: *\n\n")

for this_idx in range(0,6):

    this_public_key = electrum_pubkey_v2(this_Electrum_v2_XPUB_master_public_key, this_idx, 0) # 0: receive 1: change
    this_public_address = pubkey_to_address(this_public_key)

    this_public_address2 = electrum_address_v2(this_Electrum_v2_XPUB_master_public_key, this_idx, 0) # 0: receive 1: change

    print (this_public_address, this_public_address2)

print ("\n * Public \"change\" addresses: *\n\n")

for this_idx in range(0,6):

    this_public_key = electrum_pubkey_v2(this_Electrum_v2_XPUB_master_public_key, this_idx, 1) # 0: receive 1: change
    this_public_address = pubkey_to_address(this_public_key)

    this_public_address2 = electrum_address_v2(this_Electrum_v2_XPUB_master_public_key, this_idx, 1) # 0: receive 1: change

    print (this_public_address, this_public_address2)