Esempio n. 1
0
    def sign(self, data: bytes) -> bytes:
        """Generates signature from input data which is transaction data

        :param data: data to be signed
        :return signature: signature made from input
        """
        return sign(data, self.__bytes_private_key)
Esempio n. 2
0
    def test_verify_recoverable_sign(self):
        """Verifies recovering a signature."""

        test_requests = [TEST_REQUEST_TRANSFER_ICX, TEST_REQUEST_SCORE_FUNCTION_CALL,
                         TEST_REQUEST_SEND_MESSAGE, TEST_REQUEST_SCORE_UPDATE, TEST_REQUEST_SCORE_ISNTALL]

        for request in test_requests:
            # Serialize a signature
            private_key_object = PrivateKey()
            msg_hash_bytes = sha3_256(serialize(request["params"])).digest()
            sign_bytes = sign(msg_hash_bytes, private_key_object.private_key)

            # Deserialize a signature
            recoverable_sign = private_key_object.ecdsa_recoverable_deserialize(sign_bytes[0:64], sign_bytes[64])
            sign_ = private_key_object.ecdsa_recoverable_convert(recoverable_sign)
            # Verify a signature with a public key
            self.assertTrue(private_key_object.pubkey.ecdsa_verify(msg_hash_bytes, sign_, raw=True))

            # Verify a signature when an message is invalid
            invalid_msg_hash = sha3_256(f'invalid message'.encode()).digest()
            self.assertFalse(private_key_object.pubkey.ecdsa_verify(invalid_msg_hash, sign_, raw=True))

            # Verify a signature when a private key is invalid
            invalid_private_key = PrivateKey()
            self.assertFalse(invalid_private_key.pubkey.ecdsa_verify(msg_hash_bytes, sign_, raw=True))
 def test_check_if_wallet_signed_equally(self):
     msg = serialize(TEST_REQUEST_TRANSFER_ICX["params"])
     message_hash = sha3_256(msg).digest()
     sign1 = signer1.sign(message_hash,
                          bytes.fromhex(self.wallet1.get_private_key()))
     sign2 = signer2.sign(message_hash,
                          bytes.fromhex(self.wallet2.get_private_key()))
     self.assertEqual(sign1, sign2)
Esempio n. 4
0
    def test_verify_recoverable_sign(self):
        """Verifies recovering a signature."""

        test_requests = [
            TEST_REQUEST_TRANSFER_ICX, TEST_REQUEST_SCORE_FUNCTION_CALL,
            TEST_REQUEST_SEND_MESSAGE, TEST_REQUEST_SCORE_UPDATE,
            TEST_REQUEST_SCORE_ISNTALL
        ]

        for request in test_requests:
            # Serialize a signature
            private_key_object: PrivateKey = PrivateKey()
            private_key_bytes: bytes = private_key_object.secret

            msg = serialize(request["params"])
            message_hash = sha3_256(msg).digest()
            sign_bytes = sign(message_hash, private_key_bytes)

            public_key = PublicKey.from_signature_and_message(sign_bytes,
                                                              message_hash,
                                                              hasher=None)
            self.assertEqual(public_key.format(),
                             private_key_object.public_key.format())