Represents a 128-bit field element for AES encryption

Hierarchy

  • { value: Field[][] }
    • Byte16

Constructors

  • Parameters

    • value: Field[][]

    Returns Byte16

Properties

value: Field[][] = ...
_isStruct: true
check: (value: { value: Field[][] }) => void

Add assertions to the proof to check if value is a valid member of type T. This function does not return anything, instead it creates any number of assertions to prove that value is a valid member of the type T.

For instance, calling check function on the type Bool asserts that the value of the element is either 1 or 0.

Type declaration

    • (value: { value: Field[][] }): void
    • Parameters

      • value: { value: Field[][] }

        the element of type T to put assertions on.

      Returns void

COL_SIZE: 4
empty: () => { value: Field[][] }
fromFields: (fields: Field[]) => { value: Field[][] }
fromJSON: (x: { value: string[][] }) => { value: Field[][] }
fromValue: (
    x: { value: Field[][] } | { value: bigint[][] },
) => { value: Field[][] } & (
    value: { value: Field[][] | bigint[][] },
) => { value: Field[][] }

Convert provable type from a normal JS type.

toAuxiliary: (value?: { value: Field[][] }) => any[]

A function that takes value (optional), an element of type T, as argument and returns an array of any type that make up the "auxiliary" (non-provable) data of value.

Type declaration

    • (value?: { value: Field[][] }): any[]
    • Parameters

      • Optionalvalue: { value: Field[][] }

        the element of type T to generate the auxiliary data array from, optional. If not provided, a default value for auxiliary data is returned.

      Returns any[]

      An array of any type describing how this T element is made up of "auxiliary" (non-provable) data.

toCanonical?: (x: { value: Field[][] }) => { value: Field[][] }

Optional method which transforms a provable type into its canonical representation.

This is needed for types that have multiple representations of the same underlying value, and might even not have perfect completeness for some of those representations.

An example is the ForeignField class, which allows non-native field elements to exist in unreduced form. The unreduced form is not perfectly complete, for example, addition of two unreduced field elements can cause a prover error.

Specific protocols need to be able to protect themselves against incomplete operations at all costs. For example, when using actions and reducer, the reducer must be able to produce a proof regardless of the input action. toCanonical() converts any input into a safe form and enables us to handle cases like this generically.

Note: For most types, this method is the identity function. The identity function will also be used when the toCanonical() is not present on a type.

toFields: (value: { value: Field[][] }) => Field[]

A function that takes value, an element of type T, as argument and returns an array of Field elements that make up the provable data of value.

Type declaration

    • (value: { value: Field[][] }): Field[]
    • Parameters

      • value: { value: Field[][] }

        the element of type T to generate the Field array from.

      Returns Field[]

      A Field array describing how this T element is made up of Field elements.

toInput: (
    x: { value: Field[][] },
) => { fields?: Field[]; packed?: [Field, number][] }
toJSON: (x: { value: Field[][] }) => { value: string[][] }
toValue: (x: { value: Field[][] }) => { value: bigint[][] }

Convert provable type to a normal JS type.

Methods

  • Converts the Byte16 instance back into an array of 16 bytes. NONPROVABLE: This function should only be used for testing purposes. The output is in AES column‑major order.

    Returns number[]

    An array of 16 numbers, each between 0 and 255.

  • Converts a Byte16 instance into a 4x4 matrix of Field elements (each one byte) in standard AES column‑major order.

    Returns Field[][]

    A 4x4 matrix of Field elements.

  • Returns a Field representation of the full 128-bit value.

    Returns Field

    Field representation of the Byte16 instance.

  • Converts the Byte16 instance into a 32-character hex string. NONPROVABLE: For testing only.

    Returns string

    A 32-character hex string.

  • Converts a BigInt value into a Byte16 instance. NONPROVABLE: Can be used as witness

    Parameters

    • value: bigint

      the big integer to convert, must be 128 bits

    Returns Byte16

    new Byte16 class

  • Converts an array of 16 bytes into a Byte16 instance. NONPROVABLE: This function should only be used for testing purposes.

    Assumes the input is in AES column‑major order:

    • Bytes 0–3: Column 0
    • Bytes 4–7: Column 1
    • Bytes 8–11: Column 2
    • Bytes 12–15: Column 3

    Parameters

    • bytes: number[]

      An array of 16 numbers, each between 0 and 255.

    Returns Byte16

    A Byte16 instance.

  • Converts a 4x4 matrix (in column‑major order) into a Byte16 instance.

    Parameters

    • cols: Field[][]

      4x4 matrix of byte‑sized Field elements.

    Returns Byte16

    A Byte16 instance.

  • Converts a Field value into a Byte16 instance.

    Parameters

    • field: Field

      field must fit into 128 bits, otherwise behaviour is undefined

    Returns Byte16

    A Byte16 instance representing the field value.

  • Converts a 32-character hex string into a Byte16 instance. NONPROVABLE: For testing only.

    The hex string must be 32 characters long.

    Parameters

    • hex: string

      A 32-character hex string.

    Returns Byte16

    A Byte16 instance.

  • Return the size of the T type in terms of Field type, as Field is the primitive type.

    Returns number

    A number representing the size of the T type in terms of Field type.