if (typeof value === 'string') {
const regex = RegExp(`^[A-Fa-f0-9]{${byteLengthMin << 1},${byteLengthMax << 1}}$`)
if (!regex.test(value)) {
- throw new TypeError(`Invalid ${name} ${value}`)
+ throw new TypeError(`Invalid hexadecimal characters in ${name} ${value}`)
+ }
+ if (value.length & 1) {
+ throw new TypeError(`Invalid hexadecimal length for ${name} ${value}`)
}
value = new Uint8Array(value.match(/[A-Fa-f0-9]{2}/g)?.map(b => parseInt(b, 16)) || [])
}