def test_decode_pub(): key = random_privkey() ans = pubkey(key) ret = decode_pubkey(gen_pub_key(key)) assert ans == ret key = random_privkey() ans = pubkey(key) ret = decode_pubkey(gen_pub_key(key)) assert ans == ret
def test_addr(): key = random_privkey() pub = gen_pub_key(key) addr = gen_address_from_priv(key) assert addr == pubkey_to_address(pub) key = random_privkey() pub = gen_pub_key(key) addr = gen_address_from_priv(key) assert addr == pubkey_to_address(pub)
def test_sign(): msg = 'test' priv = ecdsa.random_privkey() pub = ecdsa.pubkey(priv) sig = ecdsa.sign(priv, msg) assert ecdsa.verify(pub, sig, msg) ecdsa.proof()
def test_priv_encode(): key = random_privkey() encoded = encode_privkey(key) ans = bitcoin.encode_privkey(key.value, 'wif_compressed') t1 = base58.b58decode(ans) t2 = base58.b58decode(encoded) assert t1 == t2 assert encoded == ans
def wonder(type, pattern): pattern = re.compile(pattern) try: while 1: priv = encode_privkey(random_privkey(), type) if pattern.match(priv): print('Found: %s' % priv) except KeyboardInterrupt: print('Quit')
def wonder_pub(type, pattern): pattern = re.compile(pattern) try: while 1: priv = random_privkey() priv_str = encode_privkey(priv, type) pub = priv_to_pub(priv, type) if pattern.match(pub): print('Found: %s with private key %s' % (pub, priv_str)) except KeyboardInterrupt: print('Quit')
def test_recover(): msg = 'test' mhash = hashlib.sha256(msg.encode()).digest() priv = ecdsa.random_privkey() pub = ecdsa.pubkey(priv) sig = ecdsa.sign(priv, msg) assert ecdsa.verify(pub, sig, msg) res = ecdsa.recover_via_msg(sig, msg) vrs = sig[0].value, sig[1].value, sig[2].value ans = bitcoin.ecdsa_raw_recover(mhash, vrs) assert (pub.value[0].value, pub.value[1].value) == ans assert pub == res
def gen_random_privkey(): return encode_privkey(random_privkey())
def test_decode_priv(): key = random_privkey() res = decode_privkey(encode_privkey(key)) assert res == key
def gen_key_pair(): key = random_privkey() return encode_privkey(key), gen_pub_key(key)