@signumjs/util
Version:
Useful utilities and tools for building Signum Network applications
30 lines • 1 kB
JavaScript
;
/**
* Original work Copyright (c) 2018 PoC-Consortium
* Modified work Copyright (c) 2019 Burst Apps Team
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertHexStringToByteArray = void 0;
/**
* Converts an hexadecimal string to byte array
* @param hex The hexadecimal string to be converted
* @return {number[]} An byte array representing the hexadecimal input
*
* @category conversion
*/
const convertHexStringToByteArray = (hex) => {
if (hex.length % 2) {
throw new Error(`Invalid Hex String: ${hex}`);
}
const bytes = new Uint8Array(hex.length / 2);
for (let c = 0; c < hex.length; c += 2) {
const byte = parseInt(hex.substr(c, 2), 16);
if (Number.isNaN(byte)) {
throw new Error(`Invalid Hex String: ${hex}`);
}
bytes[c / 2] = byte;
}
return bytes;
};
exports.convertHexStringToByteArray = convertHexStringToByteArray;
//# sourceMappingURL=convertHexStringToByteArray.js.map