Function createBaseConverter

  • Create a BaseConverter, exposing methods for encoding and decoding Uint8Arrays using bitcoin-style padding: each leading zero in the input is replaced with the zero-index character of the alphabet, then the remainder of the input is encoded as a large number in the specified alphabet.

    For example, using the alphabet 01, the input [0, 15] is encoded 01111 – a single 0 represents the leading padding, followed by the base2 encoded 0x1111 (15). With the same alphabet, the input [0, 0, 255] is encoded 0011111111 - only two 0 characters are required to represent both leading zeros, followed by the base2 encoded 0x11111111 (255).

    This is not compatible with RFC 3548's Base16, Base32, or Base64.

    If the alphabet is malformed, this method returns the error as a string.

    Parameters

    • alphabet: string

      an ordered string that maps each index to a character, e.g. 0123456789.

    Returns BaseConversionError | BaseConverter

Generated using TypeDoc