/**
 * Class to help with base32 Encoding/Decoding using RFC4648.
 */ export class Base32 { internal private static readonly _ALPHABET : string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567" ; param base32 returns throws public static decode ( base32 ) { let bits = 0 ; let value = 0 ; base32 = base32 . replace ( /=+$/ , "" ) ; let index = 0 ; const output = new Uint8Array ( Math . trunc ( ( base32 . length * 5 ) / 8 ) ) ; for ( let i = 0 ; i < base32 . length ; i ++ ) { const idx = Base32 . _ALPHABET . indexOf ( base32 [ i ] ) ; if ( idx === - 1 ) { throw new Error ( `"Invalid character found '${ base32 [ i ] }'` ) ; } value = ( value << 5 ) | idx ; bits += 5 ; if ( bits >= 8 ) { output [ index ++ ] = ( value >>> ( bits - 8 ) ) & 255 ; bits -= 8 ; } } return output ; } param bytes returns public static encode ( bytes ) { let bits = 0 ; let value = 0 ; let output = "" ; for ( let i = 0 ; i < bytes . byteLength ; i ++ ) { value = ( value << 8 ) | bytes [ i ] ; bits += 8 ; while ( bits >= 5 ) { output += Base32 . _ALPHABET [ ( value >>> ( bits - 5 ) ) & 31 ] ; bits -= 5 ; } } if ( bits > 0 ) { output += Base32 . _ALPHABET [ ( value << ( 5 - bits ) ) & 31 ] ; } while ( output . length % 8 !== 0 ) { output += "=" ; } return output ; } }