package nearenough.protocol;

import org.junit.Test;

import static net.i2p.crypto.eddsa.Utils.hexToBytes;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;

public final class RtEd25519Test {

  @Test
  public void verifyEmptyMessageSignature() throws Exception {
    byte[] pubKey = hexToBytes("d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a");
    byte[] signature = hexToBytes("e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b");

    RtEd25519.Verifier verifier = new RtEd25519.Verifier(pubKey);
    assertThat("empty message didn't validate", verifier.verify(signature));
  }

  @Test
  public void verifyMessageSignature() throws Exception {
    byte[] pubKey = hexToBytes("c0dac102c4533186e25dc43128472353eaabdb878b152aeb8e001f92d90233a7");
    byte[] message = hexToBytes("5f4c8989");
    byte[] signature = hexToBytes("124f6fc6b0d100842769e71bd530664d888df8507df6c56dedfdb509aeb93416e26b918d38aa06305df3095697c18b2aa832eaa52edc0ae49fbae5a85e150c07");

    RtEd25519.Verifier verifier = new RtEd25519.Verifier(pubKey);
    verifier.update(message);
    assertThat("message didn't validate", verifier.verify(signature));
  }

  @Test
  public void signEmptyMessageSignature() throws Exception {
    byte[] seed = hexToBytes("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60");
    byte[] signature = hexToBytes("e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b");

    RtEd25519.Signer signer = new RtEd25519.Signer(seed);
    assertArrayEquals("empty message signature doesn't match", signature, signer.sign());
  }

  @Test
  public void signMessageSignature() throws Exception {
    byte[] seed = hexToBytes("0d4a05b07352a5436e180356da0ae6efa0345ff7fb1572575772e8005ed978e9");
    byte[] message = hexToBytes("cbc77b");
    byte[] signature = hexToBytes("d9868d52c2bebce5f3fa5a79891970f309cb6591e3e1702a70276fa97c24b3a8e58606c38c9758529da50ee31b8219cba45271c689afa60b0ea26c99db19b00c");

    RtEd25519.Signer signer = new RtEd25519.Signer(seed);
    signer.update(message);
    assertArrayEquals("message signature doesn't match", signature, signer.sign());
  }
}

@@ -202,16 +202,59 @@
 yEquals;
+%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Apublic
@@ -2355,11 +2355,557 @@
 ());%0A  %7D
+%0A%0A  @Test%0A  public void roundTripSignAndVerify() throws Exception %7B%0A    byte%5B%5D seed = hexToBytes(%22334a05b07352a5436e180356da0ae6efa0345ff7fb1572575772e8005ed978e9%22);%0A    byte%5B%5D message = %22Hello world%22.getBytes();%0A%0A    RtEd25519.Signer signer = new RtEd25519.Signer(seed);%0A    signer.update(message);%0A    byte%5B%5D signature = signer.sign();%0A%0A    byte%5B%5D pubKey = signer.getPubKey();%0A    RtEd25519.Verifier verifier = new RtEd25519.Verifier(pubKey);%0A    verifier.update(message);%0A%0A    assertTrue(%22signature validates%22, verifier.verify(signature));%0A  %7D
 %0A%7D%0A

Add round-trip sign and verify test