예제 #1
0
def show_details(mnemonic, passphrase="", n_accounts=1):
    seed = hexlify(get_seed(mnemonic=mnemonic, passphrase=passphrase))
    print('Seed:\t\t\t\t', seed)

    priv = bip32_master_key(unhexlify(seed), vbytes=VBYTES)
    print('Xpriv:\t\t\t\t', priv)

    key = encode_privkey(bip32_extract_key(priv), 'wif_compressed', vbyte=MAGICBYTE)
    print('Key:\t\t\t\t', key)

    pub = bip32_privtopub(priv)
    print('Derived public key:\t', pub)
    pub_hex = bip32_extract_key(pub)
    print('public key (hex):\t', pub_hex)
    print('Master Key address:\t', pubkey_to_address(pub_hex, magicbyte=MAGICBYTE))

    print("")
    print("TREZOR Keys:")

    account = 0
    derived_private_key = bip32_ckd(bip32_ckd(bip32_ckd(priv, 44+HARDENED), HARDENED), HARDENED+account)
    print('Derived private key:', derived_private_key)

    private_key = encode_privkey(bip32_extract_key(derived_private_key), 'wif_compressed', vbyte=MAGICBYTE)
    print('private key (wif):\t', private_key)

    derived_public_key = bip32_privtopub(derived_private_key)
    print('Derived public key:', derived_public_key)

    public_key_hex = privkey_to_pubkey(private_key)
    print('public key (hex):\t', public_key_hex)

    address = pubkey_to_address(public_key_hex, magicbyte=MAGICBYTE)
    print('address:\t\t\t', address)

    print("")
    print("Account public keys (XPUB)")
    xpubs = []
    for i in range(0, n_accounts):
        derived_private_key = bip32_ckd(bip32_ckd(bip32_ckd(priv, 44+HARDENED), HARDENED+COIN_TYPE), HARDENED+i)
        xpub = bip32_privtopub(derived_private_key)
        print('Account', i, 'xpub:', xpub)
        xpubs.append(xpub)

    return xpubs
예제 #2
0
def get_address_from_xpub(xpub, i):
    """
    Get a Bitcoin address from an xpub key

    :param xpub: The xpub key
    :param i: The index of the address
    :return: A Bitcoin Address
    """
    pub0 = bip32_ckd(xpub, 0)
    public_key = bip32_ckd(pub0, i)
    hex_key = encode_pubkey(bip32_extract_key(public_key), 'hex_compressed')
    address = pubkey_to_address(hex_key, magicbyte=MAGICBYTE)

    return address
def sign(tx, i, priv, hashcode=SIGHASH_ALL):
    i = int(i)
    if (not is_python2
            and isinstance(re, bytes)) or not re.match('^[0-9a-fA-F]*$', tx):
        return binascii.unhexlify(sign(safe_hexlify(tx), i, priv))

    if len(priv) <= 33:
        priv = safe_hexlify(priv)

    pub = privkey_to_pubkey(priv)
    address = pubkey_to_address(pub)
    signing_tx = signature_form(tx, i, p2pkh_script(address), hashcode)
    sig = ecdsa_tx_sign(signing_tx, priv, hashcode)
    txobj = deserialize(tx)
    txobj["ins"][i]["script"] = serialize_script([sig, pub])

    return serialize(txobj)
예제 #4
0
def get_change_addresses_from_xpub(xpub, i=100):
    """
    Get a list of change addresses derived from an xpub key

    :param xpub: The xpub key
    :param i: The number of addresses to derive
    :return: A list of Bitcoin addresses
    """
    address_list = []
    pub0 = bip32_ckd(xpub, 1)

    for i in range(0, i):
        public_key = bip32_ckd(pub0, i)
        hex_key = encode_pubkey(bip32_extract_key(public_key),
                                'hex_compressed')
        address_from_public_key = pubkey_to_address(hex_key,
                                                    magicbyte=MAGICBYTE)
        address_list.append(address_from_public_key)

    return address_list