def test_cmp_different_address(self): addr1 = Address( "addr1v8fet8gavr6elqt6q50skkjf025zthqu6vr56l5k39sp9aqlvz2g4") addr2 = Address( "addr1XXX" ) # TODO: put some real address here once validation present self.assertNotEqual(addr1, addr2)
def handle_verify(args): data = json.loads(args.json) addr = Address.decode_base58(data['addr']) xpub = binascii.unhexlify(data['xpub']) pub = xpub[:32] msg = data['msg'].encode('utf-8') sig = binascii.unhexlify(data['sig']) # verify address and pubkey if not addr.verify_pubkey(xpub): print('address and xpub is mismatched') return # verify signature and pubkey result = verify(pub, msg, sig) print('signature is right' if result else 'signature is wrong')
def handle_wallet_balance(args): cfg = load_wallet_config(args) root_key = binascii.unhexlify(cfg['root_key']) hdpass = derive_hdpassphase(xpriv_to_xpub(root_key)) # iterate utxo. print('Searching for utxo...') store = Storage(args.root) txouts = [] for txin, txout in store.iter_utxo(): if Address.decode(txout.addr).get_derive_path(hdpass): txouts.append(txout) balance = sum(out.c for out in txouts) print('balance:', balance) print('details:') for out in txouts: print(base58.b58encode(out.addr), out.c)
def handle_sign(args): passphase = input_passphase() cfg = load_wallet_config(args) root_xpriv = binascii.unhexlify(cfg['root_key']) root_xpub = xpriv_to_xpub(root_xpriv) hdpass = derive_hdpassphase(root_xpub) addr = Address.decode_base58(args.addr) path = addr.get_derive_path(hdpass) if path is None: print('the address don\'t belong to this wallet') return xpriv = derive_key(root_xpriv, passphase, path, DERIVATION_V1) xpub = xpriv_to_xpub(xpriv) if not addr.verify_pubkey(xpub): print('the passphase is wrong') return sig = encrypted_sign(xpriv, passphase, args.message.encode('utf-8')) print( json.dumps({ 'xpub': binascii.hexlify(xpub).decode(), 'addr': args.addr, 'msg': args.message, 'sig': binascii.hexlify(sig).decode(), }))
def test_cmp_string_to_address(self): addr1 = "addr1v8fet8gavr6elqt6q50skkjf025zthqu6vr56l5k39sp9aqlvz2g4" addr2 = Address("addr1v8fet8gavr6elqt6q50skkjf025zthqu6vr56l5k39sp9aqlvz2g4") self.assertEqual(addr1, addr2)
def test_cmp_different_address(self): addr1 = Address("addr1v8fet8gavr6elqt6q50skkjf025zthqu6vr56l5k39sp9aqlvz2g4") addr2 = Address("addr1XXX") self.assertNotEqual(addr1, addr2)
def test_cmp_address_to_none(self): addr1 = Address("addr1v8fet8gavr6elqt6q50skkjf025zthqu6vr56l5k39sp9aqlvz2g4") self.assertNotEqual(addr1, None)
def test_cmp_address_to_bytes(self): addr1 = Address("addr1v8fet8gavr6elqt6q50skkjf025zthqu6vr56l5k39sp9aqlvz2g4") addr2 = "addr1v8fet8gavr6elqt6q50skkjf025zthqu6vr56l5k39sp9aqlvz2g4".encode() self.assertEqual(addr1, addr2)
def test_valid_shelley(self): ADDR = "addr1v8fet8gavr6elqt6q50skkjf025zthqu6vr56l5k39sp9aqlvz2g4" addr = Address(ADDR) self.assertEqual(addr.era, Era.SHELLEY)
def test_invalid(self): ADDR = "XXX" with self.assertRaises(ValueError): Address(ADDR)