UNPKG

@ethersphere/swarm-cli

Version:
83 lines (82 loc) 3.25 kB
"use strict"; 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Export = void 0; const fs_1 = require("fs"); const furious_commander_1 = require("furious-commander"); const identity_1 = require("../../service/identity"); const types_1 = require("../../service/identity/types"); const error_1 = require("../../utils/error"); const identity_command_1 = require("./identity-command"); class Export extends identity_command_1.IdentityCommand { constructor() { super(...arguments); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'export' }); Object.defineProperty(this, "description", { enumerable: true, configurable: true, writable: true, value: 'Export identity' }); Object.defineProperty(this, "identityName", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "outFile", { enumerable: true, configurable: true, writable: true, value: void 0 }); } async run() { super.init(); const { identity } = await this.getOrPickIdentity(this.identityName); if (identity.identityType === types_1.IdentityType.v3) { this.writeIdentityString(JSON.stringify(identity.wallet, null, 4)); } else if ((0, identity_1.isSimpleWallet)(identity.wallet, identity.identityType)) { this.writeIdentityString(identity.wallet.privateKey); } else { throw new error_1.CommandLineError('Unsupported identity type'); } } writeIdentityString(identity) { if (this.outFile) { (0, fs_1.writeFileSync)(this.outFile, identity); } else { this.console.log(identity); this.console.quiet(identity); } } } __decorate([ (0, furious_commander_1.Argument)({ key: 'name', description: 'Name of the identity to be exported' }), __metadata("design:type", String) ], Export.prototype, "identityName", void 0); __decorate([ (0, furious_commander_1.Option)({ key: 'out-file', alias: 'o', description: 'Export identity to file', }), __metadata("design:type", String) ], Export.prototype, "outFile", void 0); exports.Export = Export;