@nexex/cli
Version:
58 lines • 2.65 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 });
const chalk_1 = __importDefault(require("chalk"));
const ethers_1 = require("ethers");
const fs_1 = __importDefault(require("fs"));
const prompts_1 = __importDefault(require("prompts"));
const Base_1 = require("../../Base");
const WalletBase_1 = __importDefault(require("../../WalletBase"));
class WalletImport extends WalletBase_1.default {
async run() {
const { flags, args: { pk } } = this.parse(WalletImport);
if (fs_1.default.existsSync(this.walletPath())) {
const response = await prompts_1.default({
type: 'confirm',
name: 'answer',
message: `Wallet detected. Do you want to overwrite?`
}, { onCancel: () => this.exit(1) });
if (!response.answer) {
console.log(chalk_1.default.yellow('skipped'));
this.exit(0);
}
}
const passphrase = await this.readPassphrase();
const wallet = new ethers_1.Wallet(pk);
fs_1.default.writeFileSync(this.walletPath(), await wallet.encrypt(passphrase), { encoding: 'utf-8' });
console.log(wallet.address, chalk_1.default.green(' Imported'));
}
}
WalletImport.description = 'describe the command here';
WalletImport.examples = [
`$ nexex-cli hello
hello world from ./src/hello.ts!
`
];
WalletImport.flags = {
...WalletBase_1.default.flags
};
WalletImport.args = [{ name: 'pk' }];
__decorate([
Base_1.initDir,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], WalletImport.prototype, "run", null);
exports.default = WalletImport;
//# sourceMappingURL=import.js.map