UNPKG

atomicals-js

Version:
89 lines (88 loc) 3.9 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WalletInitCommand = void 0; const create_key_pair_1 = require("../utils/create-key-pair"); const file_utils_1 = require("../utils/file-utils"); const wallet_path_resolver_1 = require("../utils/wallet-path-resolver"); const fs = __importStar(require("fs")); const walletPath = (0, wallet_path_resolver_1.walletPathResolver)(); class WalletInitCommand { constructor(phrase, path, passphrase, n) { this.phrase = phrase; this.path = path; this.passphrase = passphrase; this.n = n; } run() { return __awaiter(this, void 0, void 0, function* () { if (yield this.walletExists()) { throw "wallet.json exists, please remove it first to initialize another wallet. You may also use 'wallet-create' command to generate a new wallet."; } const { wallet, imported } = yield (0, create_key_pair_1.createPrimaryAndFundingImportedKeyPairs)(this.phrase, this.path, this.passphrase, this.n); const walletDir = `wallets/`; if (!fs.existsSync(walletDir)) { fs.mkdirSync(walletDir); } const created = { phrase: wallet.phrase, passphrase: wallet.passphrase, primary: { address: wallet.primary.address, path: wallet.primary.path, WIF: wallet.primary.WIF }, funding: { address: wallet.funding.address, path: wallet.funding.path, WIF: wallet.funding.WIF }, imported }; yield (0, file_utils_1.jsonFileWriter)(walletPath, created); return { success: true, data: created }; }); } walletExists() { return __awaiter(this, void 0, void 0, function* () { if (yield (0, file_utils_1.jsonFileExists)(walletPath)) { return true; } }); } } exports.WalletInitCommand = WalletInitCommand;