@swaptoshi/dex-module
Version:
Klayr decentralized exchange (dex) on-chain module
27 lines • 949 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toHexString = toHexString;
exports.bufferToUint256String = bufferToUint256String;
const ALPHABET = '0123456789abcdef';
function toHexString(value, length) {
let _value = BigInt(0);
if (typeof value === 'number')
_value = BigInt(value);
if (typeof value === 'string')
_value = BigInt(value);
if (typeof value === 'bigint')
_value = value;
if (Buffer.isBuffer(value))
_value = BigInt(bufferToUint256String(value));
const buffer = new Array(2 * length);
for (let i = buffer.length; i > 0; i -= 1) {
const index = BigInt(_value) & BigInt(0xf);
buffer[i - 1] = ALPHABET[Number(index)];
_value >>= BigInt(4);
}
return buffer.join('');
}
function bufferToUint256String(value) {
return BigInt(`0x${value.toString('hex')}`).toString();
}
//# sourceMappingURL=hex_strings.js.map