UNPKG

@ethersphere/swarm-cli

Version:
49 lines (48 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Utility = void 0; exports.createWallet = createWallet; const wallet_1 = 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 lock_1 = require("./lock"); const rchash_1 = require("./rchash"); 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, redeem_1.Redeem, create_batch_1.CreateBatch, rchash_1.Rchash] }); } } 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 wallet_1.Wallet.fromV3(json, password); return wallet; } if (pathOrPrivateKey.startsWith('0x')) { pathOrPrivateKey = pathOrPrivateKey.slice(2); } return new wallet_1.Wallet(Buffer.from(pathOrPrivateKey, 'hex')); }