"use strict"; import net from 'net'; import log from '../../io/NamespacedLog.mjs'; const l = log("test-client"); import settings from '../../settings.mjs'; import sleep from '../../lib/async/sleep.mjs'; import Connection from '../../lib/transport/Connection.mjs'; import { encrypt_bytes, decrypt_bytes } from '../../lib/crypto/secretbox.mjs'; export default async function() { const test_key = "H7xKSxvJFoZoNjCKAfxn4E3qUzY3Y/4bjY+qIzxg+78="; const test_key_bytes = Buffer.from(test_key, "base64"); const test_data = "hello, world"; l.log(`TEST_DATA`, test_data); const encrypted = encrypt_bytes(test_key_bytes, Buffer.from(test_data, "utf-8")); l.log(`ENCRYPTED`, encrypted); const decrypted = decrypt_bytes(test_key_bytes, encrypted); l.log(`DECRYPTED`, decrypted); l.log(`DECRYPTED_TEXT`, decrypted.toString("utf-8")); const socket = await Connection.Create(test_key, "::1", settings.cli.port); socket.on("message", (_event, _msg) => { // noop // l.log(`<<< ${event}: ${JSON.stringify(msg)}`); }); for(let i = 0; i < 100; i++) { await sleep(1000); if(!(await socket.send(`test-client`, `hello world ${i}\n`))) break; } }