示例#1
0
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
示例#2
0
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)
示例#3
0
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()
示例#4
0
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
示例#5
0
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')
示例#6
0
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')
示例#7
0
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
示例#8
0
def gen_random_privkey():
    return encode_privkey(random_privkey())
示例#9
0
def test_decode_priv():
    key = random_privkey()
    res = decode_privkey(encode_privkey(key))
    assert res == key
示例#10
0
def gen_key_pair():
    key = random_privkey()
    return encode_privkey(key), gen_pub_key(key)