def test_is_wif_valid(self): WIFS = [ "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn", "5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf", "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU74NMTptX4", "5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAvUcVfH" ] for wif in WIFS: self.assertEqual(is_wif_valid(wif), "BTC") a = wif[:-1] + chr(ord(wif[-1]) + 1) self.assertEqual(is_wif_valid(a), None) NETWORK_NAMES = network_codes() for netcode in NETWORK_NAMES: for se in range(1, 10): key = Key(secret_exponent=se, netcode=netcode) for tv in [True, False]: wif = key.wif(use_uncompressed=tv) self.assertEqual( is_wif_valid(wif, allowable_netcodes=[netcode]), netcode) a = wif[:-1] + chr(ord(wif[-1]) + 1) self.assertEqual( is_wif_valid(a, allowable_netcodes=[netcode]), None)
def main(): if len(sys.argv) != 4: print("usage: %s tx-hex-file-path wif-file-path p2sh-file-path" % sys.argv[0]) sys.exit(-1) # get the tx with open(sys.argv[1], "r") as f: tx_hex = f.readline().strip() tx = Tx.from_hex(tx_hex) # get the WIF with open(sys.argv[2], "r") as f: wif = f.readline().strip() assert is_wif_valid(wif) # create the p2sh_lookup with open(sys.argv[3], "r") as f: p2sh_script_hex = f.readline().strip() p2sh_script = h2b(p2sh_script_hex) # build a dictionary of script hashes to scripts p2sh_lookup = build_p2sh_lookup([p2sh_script]) # sign the transaction with the given WIF sign_tx(tx, wifs=[wif], p2sh_lookup=p2sh_lookup) bad_signature_count = tx.bad_signature_count() print("tx %s now has %d bad signature(s)" % (tx.id(), bad_signature_count)) include_unspents = (bad_signature_count > 0) print("Here is the tx as hex:\n%s" % tx.as_hex(include_unspents=include_unspents))
def test_is_wif_valid(self): WIFS = ["KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn", "5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf", "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU74NMTptX4", "5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAvUcVfH"] for wif in WIFS: self.assertEqual(is_wif_valid(wif), "BTC") a = wif[:-1] + chr(ord(wif[-1])+1) self.assertEqual(is_wif_valid(a), None) for netcode in NETWORK_NAMES: for se in range(1, 10): key = Key(secret_exponent=se, netcode=netcode) for tv in [True, False]: wif = key.wif(use_uncompressed=tv) self.assertEqual(is_wif_valid(wif, allowable_netcodes=[netcode]), netcode) a = wif[:-1] + chr(ord(wif[-1])+1) self.assertEqual(is_wif_valid(a, allowable_netcodes=[netcode]), None)
def test_standard(self): hwif = self.api.create_wallet() wif = self.api.get_key(hwif) self.assertTrue(validate.is_wif_valid(wif, allowable_netcodes=['XTN']))
while 1: print("enter the %s => " % which, end='') netcode = input() if netcode: print(netcode) return netcode print("invalid netcode, please try again") src_address = get_address("source") netcode = get_net_code("netcode") spendables = spendables_for_address(src_address, netcode) print(spendables) while 1: print("enter the WIF for %s=> " % src_address, end='') wif = input() is_valid = is_wif_valid(wif) if is_valid: break print("invalid wif, please try again") key = Key.from_text(wif) if src_address not in (key.address(use_uncompressed=False), key.address(use_uncompressed=True)): print("** WIF doesn't correspond to %s" % src_address) print("The secret exponent is %d" % key.secret_exponent()) dst_address = get_address("destination") tx = create_signed_tx(spendables, payables=[dst_address], wifs=[wif]) print("here is the signed output transaction") print(tx.as_hex())
def test_standard(self): wif = self.api.create_key() self.assertTrue(validate.is_wif_valid(wif, allowable_netcodes=['XTN']))
def key(testnet, wif): wif = unicode_str(wif) netcode = 'XTN' if testnet else 'BTC' if not validate.is_wif_valid(wif, allowable_netcodes=[netcode]): raise exceptions.InvalidWif(wif) return Key.from_text(wif)
def key(testnet, wif): netcode = 'XTN' if testnet else 'BTC' if not validate.is_wif_valid(wif, allowable_netcodes=[netcode]): raise exceptions.InvalidWif(address) return Key.from_text(wif)
while 1: print "enter the %s address=>"%which, address=input(); is_valid=is_address_valid(address) if is_valid: return address print 'invalid address, please try again' src_address=get_address("source") spendables=spendables_for_address(src_address) print spendables while 1: print "enter the WIF for %s" %src_address, wif=input() is_valid=is_wif_valid(wif) if is_valid: break print("invalid wif, please try again") key = key.from_text(wif) if src_address not in (key.address(use_uncompressed=False), key.address(use_uncompressed=True)): print("**WIF doesn't correspond to %s" %src_address) print("The secret exponent is %d"%key.secret_exponent()) dst_address=get_address("destination") tx=create_signed_tx(spendables, payables=[dst_address], wifs=[wif]) print 'here is the signed output transaction' print(tx.as_hex())