UNPKG

simple-nano-wallet

Version:

Benskalz' simple-nano-wallet rewritten in TypeScript with some additional features.

37 lines (36 loc) 1.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Tools = void 0; const bignumber_js_1 = __importDefault(require("bignumber.js")); class Tools { constructor(config) { this.config = config; } get decimal() { return this.config.decimalPlaces; } /** * Convert NANO/XDG/BAN to RAW * @param amount Amount in NANO/XDG/BAN (mega) to convert to RAW * @returns RAW amount */ megaToRaw(amount) { const value = new bignumber_js_1.default(amount.toString()); return value.shiftedBy(this.decimal).toFixed(0); } ; /** * Convert RAW to NANO/XDG/BAN * @param amount Amount in RAW to convert to NANO/XDG/BAN (mega) * @returns NANO/XDG/BAN amount */ rawToMega(amount) { const value = new bignumber_js_1.default(amount.toString()); return value.shiftedBy(-(this.decimal)).toFixed(this.decimal, 1); } ; } exports.Tools = Tools;