EncryptionHandshake { public AuthInitiateMessage createAuthInitiate(@Nullable byte[] token, ECKey key) { AuthInitiateMessage message = new AuthInitiateMessage(); boolean isToken; if (token == null) { isToken = false; BigInteger secretScalar = remotePublicKey.multiply(key.getPrivKey()).normalize().getXCoord().toBigInteger(); token = ByteUtil.bigIntegerToBytes(secretScalar, NONCE_SIZE); } else { isToken = true; } byte[] nonce = initiatorNonce; byte[] signed = xor(token, nonce); message.signature = ephemeralKey.sign(signed); message.isTokenUsed = isToken; message.ephemeralPublicHash = sha3(ephemeralKey.getPubKeyPoint().getEncoded(false), 1, 64); message.publicKey = key.getPubKeyPoint(); message.nonce = initiatorNonce; return message; } EncryptionHandshake(ECPoint remotePublicKey);  EncryptionHandshake(); AuthInitiateMessage createAuthInitiate(@Nullable byte[] token, ECKey key); byte[] encryptAuthMessage(AuthInitiateMessage message); byte[] encryptAuthReponse(AuthResponseMessage message); AuthResponseMessage decryptAuthResponse(byte[] ciphertext, ECKey myKey); AuthInitiateMessage decryptAuthInitiate(byte[] ciphertext, ECKey myKey); void handleAuthResponse(ECKey myKey, byte[] initiatePacket, byte[] responsePacket); byte[] handleAuthInitiate(byte[] initiatePacket, ECKey key); static byte recIdFromSignatureV(int v); Secrets getSecrets(); ECPoint getRemotePublicKey(); boolean isInitiator(); static final int NONCE_SIZE; static final int MAC_SIZE; static final int SECRET_SIZE; }
@Test public void testCreateAuthInitiate() throws Exception { AuthInitiateMessage message = initiator.createAuthInitiate(new byte[32], myKey); int expectedLength = 65+32+64+32+1; byte[] buffer = message.encode(); assertEquals(expectedLength, buffer.length); }