UNPKG

@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.

62 lines (61 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const command_1 = require("@oclif/command"); const Output_1 = require("../../Output"); const { cli } = require('cli-ux'); class Create extends command_1.Command { async run() { var _a; const { args, flags } = this.parse(Create); // Create the key pair for the new DID cli.action.start('Creating input'); // Check if we have been passed a private // key. EC private keys will a "d" property // so use rest syntax (...) to remove. const _b = JSON.parse(args.key), { d } = _b, publicJwk = tslib_1.__rest(_b, ["d"]); let input = { content: { publicKeys: [ { id: (_a = publicJwk.kid) !== null && _a !== void 0 ? _a : 'key-1', type: 'EcdsaSecp256k1VerificationKey2019', publicKeyJwk: publicJwk, purposes: ['authentication', 'keyAgreement'], }, ], }, }; // Add any services to the input if (args.services) { input.content = Object.assign(input.content, JSON.parse(args.services)); } const inputJson = Output_1.default.toJson(input, flags.escape); cli.action.stop(); this.log(inputJson); this.exit(); } } exports.default = Create; Create.description = 'Creates a payload for generating a new ION DID.'; Create.examples = [ '$ ion operation:create {ESCAPED KEY}', '$ ion operation:create {ESCAPED KEY} {ESCAPED SERVICES} --escape', ]; Create.flags = { help: command_1.flags.help({ char: 'h' }), // 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.' }), }; Create.args = [ { name: 'key', required: true, description: 'specifies the public key to use for the create operation.', }, { name: 'services', required: false, description: 'specifies any services to be included in the create operation.', }, ];