@decentralized-identity/ion-cli
Version:
A Command Line Interface (CLI) to make working with the ION network and using ION DIDs easy peasy lemon squeezy.
43 lines (42 loc) • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const Output_1 = require("../../Output");
const ION = require('@decentralized-identity/ion-tools');
const { cli } = require('cli-ux');
class New extends command_1.Command {
async run() {
const { args, flags } = this.parse(New);
// Create the key pair for the new DID
cli.action.start('Generating key pair');
const keyPair = await ION.generateKeyPair(flags.curve);
// Mix in the kid
const privateKey = Object.assign({ kid: args.kid }, keyPair.privateJwk);
const privateKeyJson = Output_1.default.toJson(privateKey, flags.escape);
cli.action.stop();
this.log(privateKeyJson);
this.exit();
}
}
exports.default = New;
New.description = 'Creates a new elliptic curve key for the specified curve, returning a JSON serialized and optionally escaped representation.';
New.examples = [
'$ ion key:new key-1',
'$ ion key:new key-1 --curve secp256k1',
'$ ion key:new key-1 --curve secp256k1 --escape',
];
New.flags = {
help: command_1.flags.help({ char: 'h' }),
// Flag for specifying the curve to use when generating keys
curve: command_1.flags.enum({ description: 'specifies the elliptic curve to use for the keys.', options: ['secp256k1', 'Ed25519'], default: 'secp256k1' }),
// Flag for specifying the JSON string output should be escaped.
escape: command_1.flags.boolean({ description: 'specifies that the output JSON string should be escaped. Use this when using the output as input to another command.' }),
};
New.args = [
{
name: 'kid',
required: false,
description: 'identifier for the key (kid).',
default: 'key-1',
},
];