@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
30 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeUtf8 = encodeUtf8;
exports.base64ToBytes = base64ToBytes;
exports.readU128LE = readU128LE;
exports.writeU128LE = writeU128LE;
const encoder = new TextEncoder();
/** UTF-8 string → Uint8Array (replaces Buffer.from('string')) */
function encodeUtf8(s) {
return encoder.encode(s);
}
/** Base64 string → Uint8Array (replaces Buffer.from(s, 'base64')) */
function base64ToBytes(s) {
const bin = atob(s);
const bytes = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; i++)
bytes[i] = bin.charCodeAt(i);
return bytes;
}
/** Read a little-endian 128-bit unsigned integer as bigint. Pass an existing DataView to avoid allocation. */
function readU128LE(dv, off) {
return dv.getBigUint64(off, true) + (dv.getBigUint64(off + 8, true) << 64n);
}
/** Write a little-endian 128-bit integer. Pass an existing DataView to avoid allocation. */
function writeU128LE(dv, off, v) {
const mask64 = (1n << 64n) - 1n;
dv.setBigUint64(off, v & mask64, true);
dv.setBigUint64(off + 8, (v >> 64n) & mask64, true);
}
//# sourceMappingURL=bytes.js.map