@aeternity/aepp-calldata
Version:
Aeternity data serialization library
19 lines (18 loc) • 734 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _FormatError = _interopRequireDefault(require("../Errors/FormatError.cjs"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// TODO consider using Buffer.from(<string>, 'hex') instead
// TODO get rid of this ?
// int2ByteArray(BigInt('0x' + hex.join('')))
const hexStringToByteArray = str => {
const match = str.match(/^(0x)?([a-f0-9]*)$/i);
if (!match) {
throw new _FormatError.default(`Invalid hex string: ${str}`);
}
return new Uint8Array(match[2].split(/(.{1,2})/).filter(el => el).map(el => parseInt(el, 16)));
};
var _default = exports.default = hexStringToByteArray;