From: Chris Duncan Date: Tue, 3 Dec 2024 13:10:43 +0000 (-0800) Subject: Add function to convert base32 to hex. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=34d2fad2973b943eac7c908c63327dc1926f19b6;p=libnemo.git Add function to convert base32 to hex. --- 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)