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_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_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_pub_key(key: CF) -> str: return encode_pubkey(pubkey(key))
def gen_address_from_priv(key) -> str: return gen_address(pubkey(key))
def gen_address_from_priv(priv: CF) -> str: return gen_address(pubkey(priv))
def gen_pub_key(key: CF): return checksum(to_bytes(pubkey(key)))