UNPKG

@ethersphere/swarm-cli

Version:
52 lines (51 loc) 2.03 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createWallet = exports.Utility = void 0; const ethereumjs_wallet_1 = __importDefault(require("ethereumjs-wallet")); const promises_1 = require("fs/promises"); const utils_1 = require("../../utils"); const cid_1 = require("./cid"); const create_batch_1 = require("./create-batch"); const get_bee_1 = require("./get-bee"); const lock_1 = require("./lock"); const redeem_1 = require("./redeem"); const unlock_1 = require("./unlock"); class Utility { constructor() { Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'utility' }); Object.defineProperty(this, "description", { enumerable: true, configurable: true, writable: true, value: 'Utility commands related to Swarm and wallets' }); Object.defineProperty(this, "subCommandClasses", { enumerable: true, configurable: true, writable: true, value: [cid_1.Cid, lock_1.Lock, unlock_1.Unlock, get_bee_1.GetBee, redeem_1.Redeem, create_batch_1.CreateBatch] }); } } exports.Utility = Utility; async function createWallet(pathOrPrivateKey, console) { if ((0, utils_1.fileExists)(pathOrPrivateKey)) { const json = await (0, promises_1.readFile)(pathOrPrivateKey, 'utf8'); const password = await console.askForPassword('Enter password to decrypt key file'); const wallet = await ethereumjs_wallet_1.default.fromV3(json, password); return wallet; } if (pathOrPrivateKey.startsWith('0x')) { pathOrPrivateKey = pathOrPrivateKey.slice(2); } return new ethereumjs_wallet_1.default(Buffer.from(pathOrPrivateKey, 'hex')); } exports.createWallet = createWallet;