예제 #1
0
    def test_ecdsa_sign(self):
        msghash = api.secure_random(32)
        privkey = api.ecdsa_gen_priv()

        vrs = api.ecdsa_sign(msghash, privkey)
        self.assertEqual(tuple, type(vrs))
        self.assertEqual(3, len(vrs))
예제 #2
0
    def test_ecdsa_pub2bytes(self):
        privkey = api.ecdsa_gen_priv()
        self.assertEqual(32, len(privkey))

        pubkey = api.ecdsa_priv2pub(privkey, to_bytes=False)
        self.assertEqual(tuple, type(pubkey))
        self.assertEqual(2, len(pubkey))
        self.assertEqual(int, type(pubkey[0]))
        self.assertEqual(int, type(pubkey[1]))

        pubkey = api.ecdsa_pub2bytes(pubkey)
        self.assertEqual(bytes, type(pubkey))
예제 #3
0
    def test_ecdsa_verify(self):
        msghash = api.secure_random(32)
        privkey = api.ecdsa_gen_priv()
        pubkey = api.ecdsa_priv2pub(privkey, to_bytes=False)

        vrs = api.ecdsa_sign(msghash, privkey)
        self.assertEqual(tuple, type(vrs))
        self.assertEqual(3, len(vrs))

        is_verified = api.ecdsa_verify(*vrs, msghash, pubkey)
        self.assertEqual(bool, type(is_verified))
        self.assertTrue(is_verified)
예제 #4
0
    def gen_privkey(self, create_pubkey: bool = True):
        """
        Generates an ECDSA secp256k1 private key.

        TODO: Throw an error if generating a privkey on a keypair that already
              has a privkey.
        TODO: See issue #77 on Github.

        :param create_pubkey: Create the pubkey or not?
        """
        self.privkey = API.ecdsa_gen_priv()
        if create_pubkey:
            self._gen_pubkey()
예제 #5
0
    def test_ecdsa_priv2pub(self):
        privkey = api.ecdsa_gen_priv()
        self.assertEqual(bytes, type(privkey))
        self.assertEqual(32, len(privkey))

        # Test Serialization
        pubkey = api.ecdsa_priv2pub(privkey)
        self.assertEqual(bytes, type(pubkey))
        self.assertEqual(64, len(pubkey))

        # Test no serialization
        pubkey = api.ecdsa_priv2pub(privkey, to_bytes=False)
        self.assertEqual(tuple, type(pubkey))
        self.assertEqual(2, len(pubkey))
        self.assertEqual(int, type(pubkey[0]))
        self.assertEqual(int, type(pubkey[1]))
예제 #6
0
 def test_ecdsa_gen_priv(self):
     privkey = api.ecdsa_gen_priv()
     self.assertEqual(bytes, type(privkey))
     self.assertEqual(32, len(privkey))