def test_mix_parameters(self) -> None: zksnark = Groth16() ext_proof = ExtendedProof(proof=Groth16.proof_from_json_dict({ "a": ["1234", "2345"], "b": [["3456", "4567"], ["5678", "6789"]], "c": ["789a", "89ab"], }), inputs=[ "9abc", "abcd", "bcde", "cdef", ]) sig_keypair = gen_signing_keypair() sig_vk = sig_keypair.vk sig = sign(sig_keypair.sk, bytes.fromhex("00112233")) receiver_enc_keypair = generate_encryption_keypair() ciphertexts = [ encrypt(token_bytes(NOTE_LENGTH_BYTES), receiver_enc_keypair.k_pk), encrypt(token_bytes(NOTE_LENGTH_BYTES), receiver_enc_keypair.k_pk), ] mix_params = MixParameters(ext_proof, sig_vk, sig, ciphertexts) mix_params_json = mix_params.to_json() mix_params_2 = MixParameters.from_json(zksnark, mix_params_json) self.assertEqual(mix_params.extended_proof.to_json_dict(), mix_params_2.extended_proof.to_json_dict()) self.assertEqual(encode_vk_to_bytes(mix_params.signature_vk), encode_vk_to_bytes(mix_params_2.signature_vk)) self.assertEqual(mix_params.signature, mix_params_2.signature) self.assertEqual(mix_params.ciphertexts, mix_params_2.ciphertexts)
def test_decryption_invalid_key(self) -> None: """ Tests that ONLY the owner of the receiver key can decrypt the ciphertext. """ sk_1 = encryption.decode_encryption_secret_key(_TEST_SECRET_KEY_1_BYTES) sk = encryption.decode_encryption_secret_key(_TEST_SECRET_KEY_BYTES) pk = encryption.get_encryption_public_key(sk) ciphertext = encryption.encrypt(_TEST_PLAINTEXT, pk) with self.assertRaises(encryption.InvalidSignature): encryption.decrypt(ciphertext, sk_1)
def test_encrypt_decrypt(self) -> None: """ Tests the correct encrypt-decrypt flow: decrypt(encrypt(m)) == m where m is encoded on NOTE_LENGTH/BYTE_LEN bytes. """ sk = encryption.decode_encryption_secret_key(_TEST_SECRET_KEY_BYTES) pk = encryption.get_encryption_public_key(sk) ciphertext = encryption.encrypt(_TEST_PLAINTEXT, pk) plaintext = encryption.decrypt(ciphertext, sk) self.assertEqual(_TEST_PLAINTEXT, plaintext)
def _encrypt_note(out_note: api.ZethNote, pub_key: EncryptionPublicKey) -> bytes: out_note_bytes = proto_utils.zeth_note_to_bytes(out_note) return encrypt(out_note_bytes, pub_key)
def _encrypt_note(out_note: ZethNote, pub_key: EncryptionPublicKey) -> bytes: out_note_bytes = zeth_note_to_bytes(out_note) return encrypt(out_note_bytes, pub_key)