@iota/bcs
Version:
BCS - Canonical Binary Serialization implementation for JavaScript
15 lines (14 loc) • 469 B
JavaScript
function fromHEX(hexStr) {
const normalized = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr;
const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}}`;
const intArr = padded.match(/.{2}/g)?.map((byte) => parseInt(byte, 16)) ?? [];
return Uint8Array.from(intArr);
}
function toHEX(bytes) {
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
}
export {
fromHEX,
toHEX
};
//# sourceMappingURL=hex.js.map