def test_signature_recoverable(self): private_key = PrivateKey(PRIVATE_KEY_BYTES) assert (private_key.public_key.format() == PublicKey( recover( MESSAGE, deserialize_recoverable( private_key.sign_recoverable(MESSAGE)))).format())
def test_signature_correct(self): private_key = PrivateKey() public_key = private_key.public_key message = urandom(200) signature = private_key.sign(message, schnorr=False) assert verify_signature(signature, message, public_key.format(compressed=True)) assert verify_signature(signature, message, public_key.format(compressed=False))
def test_ecdh(self): a = PrivateKey() b = PrivateKey() assert a.ecdh(b.public_key.format()) == b.ecdh(a.public_key.format())
def test_from_der(self): assert PrivateKey.from_der(PRIVATE_KEY_DER).secret == PRIVATE_KEY_BYTES
def test_from_pem(self): assert PrivateKey.from_pem(PRIVATE_KEY_PEM).secret == PRIVATE_KEY_BYTES
def test_from_int(self): assert PrivateKey.from_int(PRIVATE_KEY_NUM).secret == PRIVATE_KEY_BYTES
def test_from_hex(self): assert PrivateKey.from_hex(PRIVATE_KEY_HEX).secret == PRIVATE_KEY_BYTES
def test_to_der(self): assert PrivateKey(PRIVATE_KEY_BYTES).to_der() == PRIVATE_KEY_DER
def test_multiply_update(self): private_key = PrivateKey(b'\x05') new_private_key = private_key.multiply(b'\x05', update=True) assert new_private_key.to_int() == 25 assert private_key is new_private_key
def test_to_int(self): assert PrivateKey(PRIVATE_KEY_BYTES).to_int() == PRIVATE_KEY_NUM
def test_to_hex(self): assert PrivateKey(PRIVATE_KEY_BYTES).to_hex() == PRIVATE_KEY_HEX
def test_signature_invalid_hasher(self): with pytest.raises(ValueError): PrivateKey().sign(MESSAGE, lambda x: sha512(x).digest(), schnorr=False)
def test_signature_deterministic(self): assert PrivateKey(PRIVATE_KEY_BYTES).sign( MESSAGE, schnorr=False) == SIGNATURE_DER
def test_public_key(self): assert PrivateKey( PRIVATE_KEY_BYTES).public_key.format() == PUBLIC_KEY_COMPRESSED
def test_add(self): assert PrivateKey(b'\x01').add(b'\x09').to_int() == 10
def test_to_pem(self): assert PrivateKey(PRIVATE_KEY_BYTES).to_pem() == PRIVATE_KEY_PEM
def test_add_update(self): private_key = PrivateKey(b'\x01') new_private_key = private_key.add(b'\x09', update=True) assert new_private_key.to_int() == 10 assert private_key is new_private_key
def test_multiply(self): assert PrivateKey(b'\x05').multiply(b'\x05').to_int() == 25