@ethersphere/swarm-cli
Version:
CLI tool for Bee
94 lines (93 loc) • 4.21 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Show = void 0;
const ethereumjs_wallet_1 = __importDefault(require("ethereumjs-wallet"));
const furious_commander_1 = require("furious-commander");
const process_1 = require("process");
const identity_1 = require("../../service/identity");
const utils_1 = require("../../utils");
const error_1 = require("../../utils/error");
const message_1 = require("../../utils/message");
const identity_command_1 = require("./identity-command");
class Show extends identity_command_1.IdentityCommand {
constructor() {
super(...arguments);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'show'
});
Object.defineProperty(this, "description", {
enumerable: true,
configurable: true,
writable: true,
value: 'Print private key, public key and address of an identity'
});
Object.defineProperty(this, "identityName", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "password", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
}
async run() {
super.init();
const { identity } = await this.getOrPickIdentity(this.identityName);
await this.maybePromptForSensitive();
if ((0, identity_1.isV3Wallet)(identity.wallet, identity.identityType)) {
if (!this.password) {
this.password = await this.console.askForPassword(message_1.Message.existingV3Password());
}
const wallet = await ethereumjs_wallet_1.default.fromV3(identity.wallet, this.password);
this.printWallet(wallet);
this.printWalletQuietly(wallet);
}
else if ((0, identity_1.isSimpleWallet)(identity.wallet, identity.identityType)) {
const wallet = ethereumjs_wallet_1.default.fromPrivateKey(Buffer.from((0, utils_1.normalizePrivateKey)(identity.wallet.privateKey), 'hex'));
this.printWallet(wallet);
this.printWalletQuietly(wallet);
}
else {
throw new error_1.CommandLineError('Unsupported identity type');
}
}
async maybePromptForSensitive() {
if (this.yes) {
return;
}
if (this.quiet && !this.yes) {
throw new error_1.CommandLineError(message_1.Message.requireOptionConfirmation('yes', 'This will print sensitive information to the console'));
}
if (!(await this.console.confirmAndDelete('This will print sensitive information to the console. Continue?'))) {
(0, process_1.exit)(0);
}
}
}
__decorate([
(0, furious_commander_1.Argument)({ key: 'name', description: 'Name of the identity to show' }),
__metadata("design:type", String)
], Show.prototype, "identityName", void 0);
__decorate([
(0, furious_commander_1.Option)({ key: 'password', alias: 'P', description: 'Password of the wallet' }),
__metadata("design:type", String)
], Show.prototype, "password", void 0);
exports.Show = Show;