From: Chris Duncan Date: Wed, 9 Jul 2025 20:31:41 +0000 (-0700) Subject: Check data type of input to convert functions. X-Git-Tag: v0.10.5~76 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=bc10bf484e319351bfd7114fc110964dea1541a3;p=libnemo.git Check data type of input to convert functions. --- diff --git a/src/lib/convert.ts b/src/lib/convert.ts index a1d5733..abea692 100644 --- a/src/lib/convert.ts +++ b/src/lib/convert.ts @@ -199,6 +199,9 @@ export class dec { * @returns {Uint8Array} Byte array representation of the input decimal */ static toBytes (decimal: bigint | number | string, padding: number = 0): Uint8Array { + if (decimal == null) { + throw new TypeError(`Failed to convert '${decimal}' from decimal to bytes`) + } if (typeof padding !== 'number') { throw new TypeError('Invalid padding') } @@ -222,6 +225,9 @@ export class dec { * @returns {string} Hexadecimal string representation of the input decimal */ static toHex (decimal: bigint | number | string, padding: number = 0): string { + if (decimal == null) { + throw new TypeError(`Failed to convert '${decimal}' from decimal to hex`) + } if (typeof padding !== 'number') { throw new TypeError('Invalid padding') }