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))
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))
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)
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()
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]))
def test_ecdsa_gen_priv(self): privkey = api.ecdsa_gen_priv() self.assertEqual(bytes, type(privkey)) self.assertEqual(32, len(privkey))