UNPKG

@ethersphere/swarm-cli

Version:
50 lines (49 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IdentityCommand = void 0; const identity_1 = require("../../service/identity"); const error_1 = require("../../utils/error"); const message_1 = require("../../utils/message"); const text_1 = require("../../utils/text"); const root_command_1 = require("../root-command"); const command_log_1 = require("../root-command/command-log"); class IdentityCommand extends root_command_1.RootCommand { throwIfNoIdentities() { if (!this.commandConfig.config.identities) { throw new error_1.CommandLineError(message_1.Message.noIdentity()); } } async getOrPickIdentity(name) { this.throwIfNoIdentities(); if (name) { return { name, identity: this.getIdentityByName(name) }; } if (this.verbosity === command_log_1.VerbosityLevel.Quiet) { throw new error_1.CommandLineError('Identity name must be specified when running in --quiet mode'); } const choices = Object.entries(this.commandConfig.config.identities).map(x => ({ name: `${x[0]} (${(0, identity_1.getPrintableIdentityType)(x[1].identityType)})`, value: x[0], })); const selection = await this.console.promptList(choices, 'Select an identity for this action'); return { name: selection, identity: this.getIdentityByName(selection) }; } printWallet(wallet) { this.console.log((0, text_1.createKeyValue)('Private key', wallet.getPrivateKeyString())); this.console.log((0, text_1.createKeyValue)('Public key', wallet.getPublicKeyString())); this.console.log((0, text_1.createKeyValue)('Address', wallet.getAddressString())); } printWalletQuietly(wallet) { this.console.quiet(wallet.getPrivateKeyString()); this.console.quiet(wallet.getPublicKeyString()); this.console.quiet(wallet.getAddressString()); } getIdentityByName(name) { const { identities } = this.commandConfig.config; if (!identities || !identities[name]) { throw new error_1.CommandLineError(message_1.Message.noSuchIdentity(name)); } return identities[name]; } } exports.IdentityCommand = IdentityCommand;