throw new TypeError(`Invalid byte length for ${name}`)
}
if (typeof value === 'string') {
- const regex = RegExp(`^[A-Fa-f0-9]{${byteLengthMin << 1},${byteLengthMax << 1}}$`)
- if (!regex.test(value)) {
+ if (/[^0-9a-f]/i.test(value)) {
throw new TypeError(`Invalid hexadecimal characters in ${name} ${value}`)
}
- if (value.length & 1) {
- throw new TypeError(`Invalid hexadecimal length for ${name} ${value}`)
+ if (value.length & 1 || value.length < (byteLengthMin << 1) || value.length > (byteLengthMax << 1)) {
+ throw new TypeError(`Invalid hexadecimal length ${value.length} for ${name} ${value}`)
}
- value = new Uint8Array(value.match(/[A-Fa-f0-9]{2}/g)?.map(b => parseInt(b, 16)) || [])
+ value = new Uint8Array(value.match(/[0-9a-f]{2}/gi)?.map(b => parseInt(b, 16)) || [])
}
if (value instanceof ArrayBuffer) {
value = new Uint8Array(value)
}
try {
const result = await dispatch(data)
- if (typeof result === 'string' && !/^([a-f0-9]{64}|[a-f0-9]{128})$/i.test(result)) {
+ if (typeof result === 'string' && !/^([0-9a-f]{64}|[0-9a-f]{128})$/i.test(result)) {
throw new Error(result)
}
return result