"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createServer = exports.connect = exports.NoiseState = exports.NoiseSocket = exports.NoiseServer = exports.NoiseError = void 0;
const crypto = __importStar(require("@node-dlc/crypto"));
const net_1 = require("net");
const noise_server_1 = require("./noise-server");
const noise_socket_1 = require("./noise-socket");
const noise_state_1 = require("./noise-state");
var noise_error_1 = require("./noise-error");
Object.defineProperty(exports, "NoiseError", { enumerable: true, get: function () { return noise_error_1.NoiseError; } });
var noise_server_2 = require("./noise-server");
Object.defineProperty(exports, "NoiseServer", { enumerable: true, get: function () { return noise_server_2.NoiseServer; } });
var noise_socket_2 = require("./noise-socket");
Object.defineProperty(exports, "NoiseSocket", { enumerable: true, get: function () { return noise_socket_2.NoiseSocket; } });
var noise_state_2 = require("./noise-state");
Object.defineProperty(exports, "NoiseState", { enumerable: true, get: function () { return noise_state_2.NoiseState; } });
/**
 * Connect to a remote noise socket server.
 */
function connect({ ls, es, rpk, host, port = 9735, logger, }) {
    if (!es) {
        es = crypto.createPrivateKey();
    }
    const noiseLogger = logger
        ? logger.sub('noise', rpk.slice(0, 8).toString('hex'))
        : undefined;
    const noiseState = new noise_state_1.NoiseState({ ls, es, logger: noiseLogger });
    const socket = new net_1.Socket();
    const instance = new noise_socket_1.NoiseSocket({
        socket,
        noiseState,
        rpk,
        logger: noiseLogger,
    });
    socket.connect({ host, port });
    return instance;
}
exports.connect = connect;
/**
 * Factory function to create a new server
 */
function createServer({ ls, esFactory }, connListener) {
    return new noise_server_1.NoiseServer({ ls, esFactory }, connListener);
}
exports.createServer = createServer;
//# sourceMappingURL=index.js.map