Skip to content

Instantly share code, notes, and snippets.

@devlongs
Created March 24, 2025 19:11
Show Gist options
  • Save devlongs/084cfe7e13d53b2cb4091988bc75436f to your computer and use it in GitHub Desktop.
Save devlongs/084cfe7e13d53b2cb4091988bc75436f to your computer and use it in GitHub Desktop.
export const fromHexString = (inp: Buffer | string): Buffer => {
if (typeof inp === 'string') {
if (inp.startsWith('0x')) {
return Buffer.from(inp.slice(2), 'hex')
}
return Buffer.from(inp, 'hex')
}
// If inp is already a Buffer, just return it
return inp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment