chattervox
Version:
An AX.25 packet radio chat protocol with support for digital signatures and binary compression. Like IRC over radio waves 📡〰.
113 lines • 5.74 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
const config_1 = require("../config");
const Keystore_1 = require("../Keystore");
const terminal_kit_1 = require("terminal-kit");
function interactiveInit() {
return __awaiter(this, void 0, void 0, function* () {
terminal_kit_1.terminal(`Welcome! It looks like you are using chattervox for the first time.\n`);
terminal_kit_1.terminal(`We'll ask you some questions to create an initial settings configuration.\n\n`);
let conf;
while (true) {
conf = yield askUser();
terminal_kit_1.terminal.yellow(`\n${JSON.stringify(conf, null, 2)}`);
terminal_kit_1.terminal(`\nIs this correct [Y/n]? `);
const correct = (yield terminal_kit_1.terminal.inputField().promise).trim().toLowerCase();
if (correct === '' || correct === 'yes' || correct === 'y')
break;
}
// create the ~/.chattervox dir, config.json, and keystore.json
config_1.init();
const ks = new Keystore_1.Keystore(conf.keystoreFile);
terminal_kit_1.terminal(`\nGenerating ECDSA keypair...`);
const key = ks.genKeyPair(conf.callsign);
yield utils_1.timeout(2000); // delay for dramatic effect, lol
terminal_kit_1.terminal(`\nPublic Key: ^c${key.public}^\n`);
// signatures are created using a private key, but we don't want to include
// the private key in the config file, so instead we use the public key
// as the identifier, and then actually sign with the private key.
conf.signingKey = key.public;
try {
config_1.save(conf);
terminal_kit_1.terminal(`\nSettings saved to ${config_1.defaultConfigPath}\n`);
}
catch (err) {
terminal_kit_1.terminal(`\nError saving settings to ${config_1.defaultConfigPath}\n`);
terminal_kit_1.terminal.processExit();
}
});
}
exports.interactiveInit = interactiveInit;
function askUser() {
return __awaiter(this, void 0, void 0, function* () {
let callsign = yield promptCallsign();
let ssid = yield promptSSID();
terminal_kit_1.terminal(`\nDo you have a dedicated hardware TNC that you would like to use instead of Direwolf (default: no)? `);
let hasDedicatedTNC = (yield terminal_kit_1.terminal.inputField().promise).trim().toLowerCase();
let dedicatedTNC = (hasDedicatedTNC === 'yes' || hasDedicatedTNC === 'y');
let kissPort;
let kissBaud;
if (dedicatedTNC) {
terminal_kit_1.terminal(`\nWhat is the serial port device name of this TNC (e.g. /dev/ttyS0)? `);
kissPort = (yield terminal_kit_1.terminal.inputField().promise).trim();
terminal_kit_1.terminal(`\nWhat is the baud rate for this serial device (default ${config_1.defaultConfig.kissBaud})? `);
const baud = (yield terminal_kit_1.terminal.inputField().promise).trim();
kissBaud = baud === '' ? config_1.defaultConfig.kissBaud : parseInt(baud);
}
else {
terminal_kit_1.terminal(`\nWould you like to connect to Direwolf over serial instead of the default TCP connection (default: no)? `);
let prefersSerialRaw = (yield terminal_kit_1.terminal.inputField().promise).trim().toLowerCase();
let prefersSerial = (prefersSerialRaw === 'yes' || prefersSerialRaw === 'y');
if (prefersSerial) {
kissPort = '/tmp/kisstnc';
}
}
const conf = JSON.parse(JSON.stringify(config_1.defaultConfig));
conf.callsign = callsign;
conf.ssid = ssid;
if (kissPort)
conf.kissPort = kissPort;
if (kissBaud)
conf.kissBaud = kissBaud;
return conf;
});
}
function promptCallsign() {
return __awaiter(this, void 0, void 0, function* () {
terminal_kit_1.terminal(`\nWhat is your call sign (default: ${config_1.defaultConfig.callsign})? `);
let callsign = (yield terminal_kit_1.terminal.inputField().promise).trim().toUpperCase();
if (callsign === '')
return config_1.defaultConfig.callsign;
else if (utils_1.isCallsign(callsign))
return callsign;
else {
terminal_kit_1.terminal('\nCallsign must be between 1 and 6 alphanumeric characters.');
return promptCallsign();
}
});
}
function promptSSID() {
return __awaiter(this, void 0, void 0, function* () {
terminal_kit_1.terminal(`\nWhat SSID would you like to associate with this station (press ENTER to skip)? `);
let ssid = yield terminal_kit_1.terminal.inputField().promise;
if (ssid.trim() === '')
return 0;
else if (!isNaN(parseInt(ssid))) {
let num = parseInt(ssid);
if (num >= 0 && num <= 15)
return num;
}
terminal_kit_1.terminal('\nSSID must be a number between 0 and 15.');
return promptSSID();
});
}
//# sourceMappingURL=init.js.map