Exemple #1
0
 def test_sign_verify(self):
     for i in range(10):
         key = crypto.ZilKey.generate_key_pair()
         l = 1 + i * 512
         msg = crypto.rand_bytes(l) + crypto.rand_string(l).encode()
         signature = key.sign(msg)
         assert key.verify(signature, msg)
Exemple #2
0
    def create_work(self):
        header = crypto.rand_bytes(32)
        block_num = crypto.int_to_bytes(self.block, n_bytes=8)

        return {
            "header": header,  # 32 bytes
            "block_num": block_num,  # 8 bytes
        }
Exemple #3
0
    def test_sign_verify(self):
        for i in range(10):
            msg = crypto.rand_bytes(1 + i * 512)
            key = crypto.ZilKey.generate_key_pair()

            signature1 = schnorr.sign(msg, key.keypair_bytes.private)
            signature2 = schnorr.sign(msg, key.keypair_bytes.private)

            assert signature1 != signature2
            assert schnorr.verify(msg, signature1, key.keypair_bytes.public)
            assert schnorr.verify(msg, signature2, key.keypair_bytes.public)
Exemple #4
0
    def test_rand(self):
        assert isinstance(crypto.rand_bytes(12), bytes)
        assert isinstance(crypto.rand_hex_str(12), str)

        assert crypto.rand_bytes(1) != crypto.rand_bytes(1)
        assert len(crypto.rand_bytes(11)) == 11
        assert len(crypto.rand_bytes(999)) == 999

        for i in range(-99, 1):
            with pytest.raises(ValueError):
                crypto.rand_bytes(i)

        assert crypto.rand_hex_str(2) != crypto.rand_hex_str(2)
        assert len(crypto.rand_hex_str(11)) == 11
        assert len(crypto.rand_hex_str(999)) == 999
        assert len(crypto.rand_hex_str(1000)) == 1000
        assert len(crypto.rand_hex_str(999, prefix="0x")) == 999 + 2

        for i in range(-99, 1):
            with pytest.raises(ValueError):
                crypto.rand_hex_str(i)