"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_DECIMALS = exports.u64FromCurrency = exports.currencyFromU64 = void 0;
const bn_1 = require("@polkadot/util/bn/bn");
const currencyFromU64 = (u64) => {
    const bytes = [];
    let num = typeof u64 === "number" ? new bn_1.BN(u64) : u64;
    do {
        bytes.unshift(num.modn(256));
        num = num.divn(256);
    } while (num.gtn(0));
    return Buffer.from(bytes).toString("utf8").toLowerCase();
};
exports.currencyFromU64 = currencyFromU64;
const u64FromCurrency = (currency) => {
    const buf = Buffer.from(currency.toLowerCase());
    const size = buf.length;
    return buf.reduce((val, digit, i) => val + Math.pow(256, size - 1 - i) * digit, 0);
};
exports.u64FromCurrency = u64FromCurrency;
exports.DEFAULT_DECIMALS = 9;
