From 34d2fad2973b943eac7c908c63327dc1926f19b6 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 3 Dec 2024 05:10:43 -0800 Subject: [PATCH] Add function to convert base32 to hex. --- src/lib/convert.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/convert.ts b/src/lib/convert.ts index 41bb662..80c8003 100644 --- a/src/lib/convert.ts +++ b/src/lib/convert.ts @@ -5,7 +5,7 @@ import { ALPHABET } from "./constants.js" export const base32 = { /** - * Convert a base32 string to a Uint8Array of bytes. + * Converts a base32 string to a Uint8Array of bytes. * * @param {string} base32 - String to convert * @returns {Uint8Array} Byte array representation of the input string @@ -34,6 +34,15 @@ export const base32 = { output = output.slice(1) } return output + }, + /** + * Converts a base32 string to a hexadecimal string. + * + * @param {string} base32 - String to convert + * @returns {string} Hexadecimal representation of the input base32 + */ + toHex (base32: string): string { + return bytes.toHex(this.toBytes(base32)) } } @@ -54,10 +63,10 @@ export const bin = { return new Uint8Array(bytes) }, /** - * Convert a binary string to a hexadecimal representation + * Convert a binary string to a hexadecimal string. * * @param {string} bin - String to convert - * @returns {string} Hexadecimal representation of the input string + * @returns {string} Hexadecimal string representation of the input binary */ toHex (bin: string): string { return parseInt(bin, 2).toString(16) -- 2.34.1