2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2019-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-16 19:31:05 +00:00
|
|
|
/* eslint-disable no-console */
|
2021-11-10 00:56:56 +00:00
|
|
|
import * as Errors from '../types/errors';
|
|
|
|
import { getCliOptions } from './common';
|
2019-03-28 17:09:26 +00:00
|
|
|
import { keyPair } from './curve';
|
|
|
|
import { writeHexToPath } from './signature';
|
|
|
|
|
|
|
|
const OPTIONS = [
|
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Print this help and exit.',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['key', 'k'],
|
|
|
|
type: 'string',
|
|
|
|
help: 'Path where public key will go',
|
|
|
|
default: 'public.key',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['private', 'p'],
|
|
|
|
type: 'string',
|
|
|
|
help: 'Path where private key will go',
|
|
|
|
default: 'private.key',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
type OptionsType = {
|
|
|
|
key: string;
|
|
|
|
private: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const cliOptions = getCliOptions<OptionsType>(OPTIONS);
|
|
|
|
go(cliOptions).catch(error => {
|
2021-11-10 00:56:56 +00:00
|
|
|
console.error('Something went wrong!', Errors.toLogFormat(error));
|
2019-03-28 17:09:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
async function go(options: OptionsType) {
|
|
|
|
const { key: publicKeyPath, private: privateKeyPath } = options;
|
|
|
|
const { publicKey, privateKey } = keyPair();
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
writeHexToPath(publicKeyPath, publicKey),
|
|
|
|
writeHexToPath(privateKeyPath, privateKey),
|
|
|
|
]);
|
|
|
|
}
|