Exemplo n.º 1
0
    def sign(self, msghash: bytes) -> bytes:
        """
        Signs a hashed message and returns a signature.

        :param msghash: The hashed message to sign

        :return: Signature in bytes
        """
        v, r, s = API.ecdsa_sign(msghash, self.privkey)
        return API.ecdsa_gen_sig(v, r, s)
Exemplo n.º 2
0
    def test_ecdsa_load_sig(self):
        v = 1
        r = int.from_bytes(api.secure_random(32), byteorder='big')
        s = int.from_bytes(api.secure_random(32), byteorder='big')

        sig = api.ecdsa_gen_sig(v, r, s)
        self.assertEqual(bytes, type(sig))
        self.assertEqual(65, len(sig))

        loaded_sig = api.ecdsa_load_sig(sig)
        self.assertEqual(tuple, type(loaded_sig))
        self.assertEqual(3, len(loaded_sig))
        self.assertEqual((v, r, s), loaded_sig)
Exemplo n.º 3
0
    def test_ecdsa_gen_sig(self):
        v, r, s = 1, 2, 3

        sig = api.ecdsa_gen_sig(v, r, s)
        self.assertEqual(bytes, type(sig))
Exemplo n.º 4
0
 def __bytes__(self):
     """
     Implements the __bytes__ call for Signature to transform into a
     transportable mode.
     """
     return API.ecdsa_gen_sig(self._v, self._r, self._s)