def get_imported_privkey_branch(wallet, m, showprivkey): if m in wallet.imported_privkeys: entries = [] for i, privkey in enumerate(wallet.imported_privkeys[m]): pub = btc.privkey_to_pubkey(privkey) addr = btc.pubkey_to_p2sh_p2wpkh_address( pub, magicbyte=get_p2sh_vbyte()) balance = 0.0 for addrvalue in wallet.unspent.values(): if addr == addrvalue['address']: balance += addrvalue['value'] used = ('used' if balance > 0.0 else 'empty') if showprivkey: wip_privkey = btc.wif_compressed_privkey( privkey, get_p2pk_vbyte()) else: wip_privkey = '' entries.append( WalletViewEntry("m/0", m, -1, i, addr, [balance, balance], used=used, priv=wip_privkey)) return WalletViewBranch("m/0", m, -1, branchentries=entries) return None
def validate_utxo_data(utxo_datas, retrieve=False, segwit=False): """For each txid: N, privkey, first convert the privkey and convert to address, then use the blockchain instance to look up the utxo and check that its address field matches. If retrieve is True, return the set of utxos and their values. """ results = [] for u, priv in utxo_datas: print('validating this utxo: ' + str(u)) hexpriv = btc.from_wif_privkey(priv, vbyte=get_p2pk_vbyte()) if segwit: addr = btc.pubkey_to_p2sh_p2wpkh_address( btc.privkey_to_pubkey(hexpriv), get_p2sh_vbyte()) else: addr = btc.privkey_to_address(hexpriv, magicbyte=get_p2pk_vbyte()) print('claimed address: ' + addr) res = jm_single().bc_interface.query_utxo_set([u]) print('blockchain shows this data: ' + str(res)) if len(res) != 1 or None in res: print("utxo not found on blockchain: " + str(u)) return False if res[0]['address'] != addr: print("privkey corresponds to the wrong address for utxo: " + str(u)) print("blockchain returned address: {}".format(res[0]['address'])) print("your privkey gave this address: " + addr) return False if retrieve: results.append((u, res[0]['value'])) print('all utxos validated OK') if retrieve: return results return True
def wallet_signmessage(wallet, hdpath, message): if hdpath.startswith(wallet.get_root_path()): hp = bip32pathparse(hdpath) m, forchange, k = hp[-3:] key = wallet.get_key(m, forchange, k) addr = wallet.pubkey_to_address(btc.privkey_to_pubkey(key)) print('Using address: ' + addr) else: print('%s is not a valid hd wallet path' % hdpath) return None sig = btc.ecdsa_sign(message, key, formsg=True) retval = "Signature: " + str(sig) + "\n" retval += "To verify this in Bitcoin Core use the RPC command 'verifymessage'" return retval