コード例 #1
0
    def test_change_password(self):
        rpc = Rpc("http://localhost:8080", True)

        passphrase1 = f"some passphrase {random()}"
        passphrase2 = f"another passphrase {random()}"

        secret = generate_private_key()

        account = rpc.account.import_raw(
            "0x" + binascii.hexlify(secret).decode("ascii"), passphrase1)

        message = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"

        signature1 = rpc.account.sign(message, account, passphrase1)
        expected = sign_ecdsa(bytes.fromhex(message[2:]), secret)

        assert bytes.fromhex(signature1[2:]) == expected

        with pytest.raises(Exception):
            rpc.account.sign(message, account, passphrase2)

        rpc.account.change_password(account, passphrase1, passphrase2)

        with pytest.raises(Exception):
            rpc.account.sign(message, account, passphrase1)

        signature2 = rpc.account.sign(message, account, passphrase2)

        assert bytes.fromhex(signature2[2:]) == expected
コード例 #2
0
def test_sign_verify():
    message = bytes(32)
    priv = generate_private_key()
    pub = get_public_from_private(priv)
    sig = sign_ecdsa(message, priv)

    assert verify_ecdsa(message, sig, pub)
コード例 #3
0
def test_sign_recover():
    message = bytes(32)
    priv = generate_private_key()
    pub = get_public_from_private(priv)
    sig = sign_ecdsa(message, priv)

    assert recover_ecdsa(message, sig) == pub
コード例 #4
0
    def test_sign(self):
        rpc = Rpc("http://localhost:8080", True)

        passphrase = f"some passphrase {random()}"
        secret = generate_private_key()

        account = rpc.account.import_raw(
            "0x" + binascii.hexlify(secret).decode("ascii"), passphrase)
        message = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"

        signature = rpc.account.sign(message, account, passphrase)
        expected = sign_ecdsa(bytes.fromhex(message[2:]), secret)

        assert bytes.fromhex(signature[2:]) == expected
コード例 #5
0
    def test_unlock_with_duration(self):
        rpc = Rpc("http://localhost:8080", True)

        passphrase = f"some passphrase {random()}"
        secret = generate_private_key()

        account = rpc.account.import_raw(
            "0x" + binascii.hexlify(secret).decode("ascii"), passphrase)
        message = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"

        rpc.account.unlock(account, passphrase, 1)

        signature = rpc.account.sign(message, account, None)
        expected = sign_ecdsa(bytes.fromhex(message[2:]), secret)

        assert bytes.fromhex(signature[2:]) == expected

        time.sleep(2)

        with pytest.raises(Exception):
            rpc.account.sign(message, account, None)