Skip to content

Commit

Permalink
Merge pull request #411 from jwetzell/fix/lib-hex-to-bytes-error
Browse files Browse the repository at this point in the history
hexToBytes should throw an error if invalid format string is supplied
  • Loading branch information
jwetzell committed May 2, 2024
2 parents 517e49d + 715e2cb commit dcc38e5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit dcc38e5

Please sign in to comment.