diff --git a/lib/src/utils/index.js b/lib/src/utils/index.js index d7e64c82..91f254b9 100644 --- a/lib/src/utils/index.js +++ b/lib/src/utils/index.js @@ -1,4 +1,9 @@ +const hexRegex = /^[0-9A-Fa-f\sx,]+$/; + export function hexToBytes(hex) { + if (!hexRegex.test(hex)) { + throw new Error('hex string contains invalid characters'); + } const cleanHex = hex.replaceAll(' ', '').replaceAll('0x', '').replaceAll(',', ''); const bytes = []; for (let c = 0; c < cleanHex.length; c += 2) {