Exemplo n.º 1
0
    def _public_key_from_secret(self, secret):
        """
        Get a public key from a provided secret passphrase

        :param secret: secret passphrase (bytes)
        :return: public key (string)
        """

        return self._compress_public_key(sha256(secret))
Exemplo n.º 2
0
    def _private_key_from_secret(self, secret):
        """
        Get a private key from a provided secret passphrase

        :param secret: secret passphrase (bytes)
        :return: private key (string)
        """

        return hexlify(sha256(secret))
Exemplo n.º 3
0
    def _get_hash(self, skip_signature=True, skip_second_signature=True):
        """
        Computes the hash for the transaction

        :param skip_signature: boolean
        :param skip_second_signature: boolean
        :return: hash (bytes)
        """

        return sha256(self._to_bytes(skip_signature, skip_second_signature))
Exemplo n.º 4
0
    def test_signature_1(self):
        signature = Signature("secret").sign(sha256(
            "message".encode()))["signature"]

        self.assertIsNotNone(signature)
        self.assertIsNotNone(signature, str)
        self.assertEqual(
            signature,
            "304402202f43daad19f64dd114d55c1488e4ecaee1ce79183008e21e663e24dc882c9b9d022023d0f4e9f63ac43404625b43dbd8df77a774b9e9f33e0d8ff569f6b6b5014e38"
        )
Exemplo n.º 5
0
    def test_signature_2(self):
        signature = Signature("secret just to make sure it works").sign(
            sha256("message data".encode()))["signature"]

        self.assertIsNotNone(signature)
        self.assertIsNotNone(signature, str)
        self.assertEqual(
            signature,
            "304402203aef6f3c4aaa0cb597b8e9b80248983641ae909a8700feea8609bdddb0db6bd40220364735b3fed0a4e0b19e78d7c36658bbd36db8658afce4e227f4aad78318407b"
        )
Exemplo n.º 6
0
    def sign(self, secret, second_secret=False):
        """
        Signs the transaction with signatures and an id

        :param secret: secret passphrase (string or bytes)
        :param second_secret: second secret passphrase (string or bytes)
        """

        self._sign(secret)
        if second_secret:
            self._second_sign(second_secret)
        self._id = hexlify(sha256(self._to_bytes(False, False)))
Exemplo n.º 7
0
    def test_verify_2(self):
        public_key = Keys("secret just to make sure it works").get_public_key()
        message = sha256("message data".encode())
        signature = "304402203aef6f3c4aaa0cb597b8e9b80248983641ae909a8700feea8609bdddb0db6bd40220364735b3fed0a4e0b19e78d7c36658bbd36db8658afce4e227f4aad78318407b"

        self.assertTrue(Signature.verify(public_key, message, signature))
Exemplo n.º 8
0
    def test_verify_1(self):
        public_key = Keys("secret").get_public_key()
        message = sha256("message".encode())
        signature = "304402202f43daad19f64dd114d55c1488e4ecaee1ce79183008e21e663e24dc882c9b9d022023d0f4e9f63ac43404625b43dbd8df77a774b9e9f33e0d8ff569f6b6b5014e38"

        self.assertTrue(Signature.verify(public_key, message, signature))