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_bytes2pub(self): privkey = api.ecdsa_gen_priv() self.assertEqual(32, len(privkey)) pubkey_tuple = api.ecdsa_priv2pub(privkey, to_bytes=False) self.assertEqual(tuple, type(pubkey_tuple)) self.assertEqual(2, len(pubkey_tuple)) self.assertEqual(int, type(pubkey_tuple[0])) self.assertEqual(int, type(pubkey_tuple[1])) pubkey_bytes = api.ecdsa_priv2pub(privkey) self.assertEqual(bytes, type(pubkey_bytes)) pubkey = api.ecdsa_bytes2pub(pubkey_bytes) self.assertEqual(tuple, type(pubkey)) self.assertEqual(2, len(pubkey)) self.assertEqual(int, type(pubkey[0])) self.assertEqual(int, type(pubkey[1])) self.assertEqual(pubkey_tuple, 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_pubkey(self): self.pubkey = API.ecdsa_priv2pub(self.privkey)
def _gen_pubkey(self): self.pubkey = PublicKey(API.ecdsa_priv2pub(self.privkey))