From 10254ba729be503e70a0e0b358c62502020dd9b9 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Tue, 19 Nov 2024 07:42:44 +0000 Subject: [PATCH] utils: add comments --- src/utils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 3453656..d656e66 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -39,10 +39,10 @@ export function bytesToHex(bytes: Uint8Array): string { // We use optimized technique to convert hex string to byte array const asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 } as const; -function asciiToBase16(char: number): number | undefined { - if (char >= asciis._0 && char <= asciis._9) return char - asciis._0; - if (char >= asciis._A && char <= asciis._F) return char - (asciis._A - 10); - if (char >= asciis._a && char <= asciis._f) return char - (asciis._a - 10); +function asciiToBase16(ch: number): number | undefined { + if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48 + if (ch >= asciis._A && ch <= asciis._F) return ch - (asciis._A - 10); // 'B' => 66-(65-10) + if (ch >= asciis._a && ch <= asciis._f) return ch - (asciis._a - 10); // 'b' => 98-(97-10) return; } @@ -62,7 +62,7 @@ export function hexToBytes(hex: string): Uint8Array { const char = hex[hi] + hex[hi + 1]; throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi); } - array[ai] = n1 * 16 + n2; + array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163 } return array; }