#!/usr/bin/env escript
main(_) ->
Proto = enoise_protocol:from_name("Noise_XX+psk0_25519_ChaChaPoly_Blake2b"),
K = enoise_keypair:new(dh25519),
{kp, dh25519, MyPrivate, MyPublic} = K,
io:format("Created keypair: ~p~n", [K]),
Psk = binary:copy(<<1>>, 32),
{ok, TcpSock} = gen_tcp:connect(
"localhost", 9999, [{active, once}, binary, {reuseaddr, true}], 1000
),
Opts = [
{noise, Proto},
{e, K},
{psk, Psk},
{prologue, <<"CABLE1.0">>}
],
{ok, EConn} = enoise:connect(TcpSock, Opts),
% TODO: is this when we exchange the keys or is this something the rust code does manually?
ok = enoise:send(EConn, <<"ok\n">>),
receive
{noise, EConn, <<"yup\n">>} -> ok
after 1000 -> error(timeout)
end,
enoise:close(EConn).