* Convert Base32 string to hexadecimal * @param base32 Base32 encoded string * @returns Hexadecimal string
(base32: string)
| 61 | * @returns Hexadecimal string |
| 62 | */ |
| 63 | private static base32ToHex(base32: string): string { |
| 64 | const base32Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567" |
| 65 | let bits = "" |
| 66 | const hex = [] |
| 67 | |
| 68 | base32 = base32.toUpperCase().replace(/=+$/, "") |
| 69 | |
| 70 | for (let i = 0; i < base32.length; i++) { |
| 71 | const val = base32Chars.indexOf(base32.charAt(i)) |
| 72 | if (val === -1) throw new Error("Invalid base32 character") |
| 73 | bits += this.leftPad(val.toString(2), 5) |
| 74 | } |
| 75 | |
| 76 | for (let i = 0; i + 8 <= bits.length; i += 8) { |
| 77 | const chunk = bits.substr(i, 8) |
| 78 | hex.push(parseInt(chunk, 2).toString(16).padStart(2, "0")) |
| 79 | } |
| 80 | |
| 81 | return hex.join("") |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Left pad a string with zeros |
no test coverage detected