Encodes the input to a field element for signing. Used when working with messages that are specified as JS objects. This encoder object will contain the mapping from message name (key in JS object) to an encoding function.

TODO: Support identity encoder for values that are already field elements.

Constructors

Properties

defaultEncoder?: EncodeFunc
encoders?: Map<string, EncodeFunc>

Methods

  • Parameters

    • value: unknown
    • strict: boolean = false

    Returns Uint8Array

  • Parameters

    • value: unknown
    • strict: boolean = false

    Returns Uint8Array

  • Encode a message with given name and value. Will throw an error if no appropriate encoder found.

    Parameters

    • name: string
    • value: unknown
    • strict: boolean = false

      If set to false and no appropriate encoder is found but the value is a bytearray, it will encode it using the built-in mechanism

    Returns Uint8Array

  • Encode a message with given name and value. Will throw an error if no appropriate encoder found.

    Parameters

    • name: string
    • value: unknown
    • strict: boolean = false

      If set to false and no appropriate encoder is found but the value is a bytearray, it will encode it using the built-in mechanism

    Returns Uint8Array

  • Encode messages given as JS object. It flattens the object into a sorted list and encodes each value as per the known encoding functions. Returns 2 arrays, 1st with message names and 2nd with encoded values.

    Parameters

    • messages: object
    • strict: boolean = false

      If set to false and no appropriate encoder is found but the value is a bytearray, it will encode it using the built-in mechanism

    Returns [string[], Uint8Array[]]

  • Encode messages given as JS object. It flattens the object into a sorted list and encodes each value as per the known encoding functions. Returns a Map with names as keys and encoded messages as values.

    Parameters

    • messages: object
    • strict: boolean = false

      If set to false and no appropriate encoder is found but the value is a bytearray, it will encode it using the built-in mechanism

    Returns Map<string, Uint8Array>

  • Encode messages given as JS object. It flattens the object into a sorted list and encodes each value as per the known encoding functions. Returns a Map with names as keys and encoded messages as values.

    Parameters

    • messages: object
    • strict: boolean = false

      If set to false and no appropriate encoder is found but the value is a bytearray, it will encode it using the built-in mechanism

    Returns Map<string, Uint8Array>

  • Encode messages given as JS object. It flattens the object into a sorted list and encodes each value as per the known encoding functions. Returns an object with names as keys and encoded messages as values.

    Parameters

    • messages: object
    • strict: boolean = false

      If set to false and no appropriate encoder is found but the value is a bytearray, it will encode it using the built-in mechanism

    Returns {
        [name: string]: Uint8Array;
    }

    • [name: string]: Uint8Array
  • Encode messages given as JS object. It flattens the object into a sorted list and encodes each value as per the known encoding functions. Returns an object with names as keys and encoded messages as values.

    Parameters

    • messages: object
    • strict: boolean = false

      If set to false and no appropriate encoder is found but the value is a bytearray, it will encode it using the built-in mechanism

    Returns {
        [name: string]: Uint8Array;
    }

    • [name: string]: Uint8Array
  • Encode messages given as JS object. It flattens the object into a sorted list and encodes each value as per the known encoding functions. Returns 2 arrays, 1st with message names and 2nd with encoded values.

    Parameters

    • messages: object
    • strict: boolean = false

      If set to false and no appropriate encoder is found but the value is a bytearray, it will encode it using the built-in mechanism

    Returns [string[], Uint8Array[]]

  • Returns an encoding function to be used on a message that is a boolean, encoded as positive int (0 or 1)

    Returns EncodeFunc

  • Returns an encoding function to be used on a message that can be a positive, negative or decimal number, eg. -2.35

    Parameters

    • minimum: number

      The minimum negative value that the message can take

    • maxDecimalPlaces: number

      The maximum decimal places

    Returns EncodeFunc

  • Returns a function that can convert any number to a positive integer when its minimum negative value and maximum decimal places are known. Does that by adding an offset of abs(minimum) and then multiplying it by 10^max_decimal_places

    Parameters

    • minimum: number
    • maxDecimalPlaces: number

    Returns ToPositiveIntFunc

  • Returns an encoding function to convert utf-8 string message. It might fail if the encoding target cannot be made a string

    Returns EncodeFunc

  • Returns an encoding function to convert utf-8 string message. It might fail if the encoding target cannot be made a string

    Returns EncodeFunc

  • Returns an encoding function to be used on a message that can be a positive or negative integer.

    Parameters

    • minimum: number

      The minimum negative value that the message can take

    Returns EncodeFunc

  • Returns a function that can convert any input integer to a positive integer when its minimum negative value is known. Does that by adding an offset of abs(minimum) to the input

    Parameters

    • minimum: number

    Returns ToPositiveIntFunc

  • Returns an encoding function to be used on a message that can be a positive decimal number, eg. 2.7

    Parameters

    • maxDecimalPlaces: number

      The maximum decimal places

    Returns EncodeFunc

  • Returns a function that can convert any positive number to a positive integer when its maximum decimal places are known. Does that by multiplying it by 10^max_decimal_places, eg. 23.452 -> 23452

    Parameters

    • maxDecimalPlaces: number

    Returns ToPositiveIntFunc

  • Returns a reversible encoding function to be used on a string message. The output can of the EncodeFunc can be reversed.

    Parameters

    • compress: boolean = false

    Returns EncodeFunc