// Base encoders / decoders just base encode / decode between binary and // textual representation. They are unaware of multibase. /** * Base encoder just encodes bytes into base encoded string. */ export interface BaseEncoder { /** * Base encodes to a **plain** (and not a multibase) string. Unlike * `encode` no multibase prefix is added. * @param bytes */ baseEncode(bytes: Uint8Array): string } /** * Base decoder decodes encoded with matching base encoding into bytes. */ export interface BaseDecoder { /** * Decodes **plain** (and not a multibase) string. Unlike * decode * @param text */ baseDecode(text: string): Uint8Array } /** * Base codec is just dual of encoder and decoder. */ export interface BaseCodec { encoder: BaseEncoder decoder: BaseDecoder } /** * Multibase represents base encoded strings with a prefix first character * describing it's encoding. */ export type Multibase = | string | string & { [0]: Prefix } /** * Multibase encoder for the specific base encoding encodes bytes into * multibase of that encoding. */ export interface MultibaseEncoder { /** * Name of the encoding. */ name: string /** * Prefix character for that base encoding. */ prefix: Prefix /** * Encodes binary data into **multibase** string (which will have a * prefix added). */ encode(bytes: Uint8Array): Multibase } /** * Interface implemented by multibase decoder, that takes multibase strings * to bytes. It may support single encoding like base32 or multiple encodings * like base32, base58btc, base64. If passed multibase is incompatible it will * throw an exception. */ export interface MultibaseDecoder { /** * Decodes **multibase** string (which must have a multibase prefix added). * If prefix does not match * @param multibase */ decode(multibase: Multibase): Uint8Array } /** * Dual of multibase encoder and decoder. */ export interface MultibaseCodec { name: string prefix: Prefix encoder: MultibaseEncoder decoder: MultibaseDecoder } export interface UnibaseDecoder extends MultibaseDecoder { // Reserve this property so it can be used to derive type. readonly decoders?: null readonly prefix: Prefix } export interface CombobaseDecoder extends MultibaseDecoder { readonly decoders: Record> }