From bc10bf484e319351bfd7114fc110964dea1541a3 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 9 Jul 2025 13:31:41 -0700 Subject: [PATCH] Check data type of input to convert functions. --- src/lib/convert.ts | 6 ++++++ 1 file changed, 6 insertions(+) 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') } -- 2.47.3