Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/utilities/validateUint8Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export default function validateIfUint8Array(input: unknown): Uint8Array | unkno
return input
}

// Handle hex strings
if (typeof input === "string" && input.startsWith("0x")) {
const hexString = input.slice(2) // Remove "0x" prefix
// Validate hex string before conversion
if (hexString.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(hexString)) {
// Handle hex strings (with or without 0x prefix)
if (typeof input === "string") {
const hexString = input.startsWith("0x") ? input.slice(2) : input
const isHex = /^[0-9a-fA-F]+$/.test(hexString) && hexString.length % 2 === 0
if (isHex) {
return Buffer.from(hexString, "hex")
}

Expand Down
Loading