def test_sign_verify_random(self):
     for _ in range(100):
         sk = secp256k1.generate_secret()
         pk = secp256k1.publickey(sk)
         dig = random.bytes(32)
         sig = secp256k1.sign(sk, dig)
         self.assertTrue(secp256k1.verify(pk, sig, dig))
 def test_verify_recover(self):
     for compressed in [False, True]:
         for _ in range(100):
             sk = secp256k1.generate_secret()
             pk = secp256k1.publickey(sk, compressed)
             dig = random.bytes(32)
             sig = secp256k1.sign(sk, dig, compressed)
             pk2 = secp256k1.verify_recover(sig, dig)
             self.assertEqual(pk, pk2)
 def test_generate_secret(self):
     for _ in range(100):
         sk = secp256k1.generate_secret()
         self.assertTrue(len(sk) == 32)
         self.assertTrue(sk != b'\x00' * 32)
         self.assertTrue(
             sk <
             b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE\xBA\xAE\xDC\xE6\xAF\x48\xA0\x3B\xBF\xD2\x5E\x8C\xD0\x36\x41\x41'
         )
    def test_sign_verify_min_max(self):
        sk = secp256k1.generate_secret()
        pk = secp256k1.publickey(sk)

        dig = bytes([1] + [0] * 31)
        sig = secp256k1.sign(sk, dig)
        self.assertTrue(secp256k1.verify(pk, sig, dig))

        dig = bytes([0] * 31 + [1])
        sig = secp256k1.sign(sk, dig)
        self.assertTrue(secp256k1.verify(pk, sig, dig))

        dig = bytes([0xFF] * 32)
        sig = secp256k1.sign(sk, dig)
        self.assertTrue(secp256k1.verify(pk, sig, dig))