From: Chris Duncan Date: Fri, 22 Aug 2025 09:04:52 +0000 (-0700) Subject: Allow byte conversion to hex from buffer as well as typed array. X-Git-Tag: v0.10.5~41^2~5 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=c30850b74b82c4ff40d91e59203f272f2c51125a;p=libnemo.git Allow byte conversion to hex from buffer as well as typed array. --- diff --git a/src/lib/convert.ts b/src/lib/convert.ts index c270fb3..ba29b6a 100644 --- a/src/lib/convert.ts +++ b/src/lib/convert.ts @@ -151,7 +151,8 @@ export class bytes { * @param {Uint8Array} bytes - Byte array to convert * @returns {string} Hexadecimal string representation of the input bytes */ - static toHex (bytes: Uint8Array): string { + static toHex (bytes: ArrayBuffer | Uint8Array): string { + if (bytes instanceof ArrayBuffer) bytes = new Uint8Array(bytes) if (bytes.buffer instanceof ArrayBuffer && bytes.buffer.detached) return '' return [...bytes] .map(byte => byte.toString(16).padStart(2, '0'))