Class encapsulating an unsigned POD with functions for common use cases. PODContent instances are immutable (within the limits of TypeScript), but derived data (such as the Merkle tree of entries) is calculated lazily as it is needed.

A POD is made up of PODEntries, built into a Merkle tree (in sorted order) to produce a root hash called the Content ID, which is then signed. To create a POD, use one of the static factory methods of this class.

PODContent instances are usually contained in a signed POD instance.

Constructors

  • Parameters

    • map: PODMap
    • Optional merkleTree: LeanIMT<bigint>

    Returns PODContent

Properties

_map: PODMap
_merkleTree?: PODMerkleTree

Accessors

  • get contentID(): bigint
  • The content ID (root hash) of this POD.

    Returns bigint

  • get merkleTree(): LeanIMT<bigint>
  • Returns LeanIMT<bigint>

  • get merkleTreeDepth(): number
  • The depth of the Merkle tree representation of this POD. The proofs generated by this POD will be no longer than this, but may be shorter due to the optimizations of the Lean-IMT datastructure (see @zk-kit/imt).

    Returns number

  • get size(): number
  • The number of entries in this POD.

    Returns number

Methods

  • Parameters

    • entryName: string

    Returns PODEntryInfo

  • Returns PODEntries

    the contents of this POD as a PODEntries object. Mutating this object will not change this PODContent instance.

  • Generates all necessary info about a single POD entry needed to populate a proof circuit. This includes a membership proof, as well name hash, value hash, and optionally the value itself. Note that name strings never appear in circuits directly. Values only appear in circuits if they are numeric values which fit in a single circuit signal.

    Parameters

    • entryName: string

      the entry name to look up

    Returns PODEntryCircuitSignals

    an object containing info for circuit inputs

    Throws

    if the entry name is not found

  • Creates a new proof of membership for an entry by the given name.

    Parameters

    • entryName: string

      the entry name to look up

    Returns PODEntryProof

    a membership proof for the given entry

    Throws

    if the entry name is not found

  • Gets an entry value by name, without its type tag. Mutating the returned value will not change this PODContent instance.

    Parameters

    • name: string

      the entry name to look up

    Returns undefined | string | bigint

    the value, or undefined if there is no value by that name

  • Gets an entry value by name. Mutating the returned will not change this PODContent instance.

    Parameters

    • name: string

      the entry name to look up

    Returns undefined | PODValue

    the value, or undefined if there is no value by that name

  • Returns {
        name: string;
        value: PODValue;
    }[]

    the entries of this POD, in sorted order. Mutating this result will not change this PODContent instance.

  • Returns string[]

    the names of all entries in this POD, in sorted order. Mutating this result will not change this PODContent instance.

  • Serializes this instance's entries as a JSON string, in a way which properly preserves all types.

    Returns string

  • Converts the entries to a JSON-compatible format which can be safely serialized using JSON.stringify without any loss of information. To reconstitute a PODContent object from JSON, see fromJSON.

    Returns JSONPODEntries

    a JSON-compatible representation of this POD.

  • Deserializes POD entries from JSON.

    Parameters

    • serializedEntries: string

      a string previously created by #serialize.

    Returns PODContent

    a new PODContent instance

    Throws

    if the string isn't valid JSON, or represents entries which aren't legal for inclusion in a POD

  • Factory for creating a new POD from entries. The entries do not need to be in sorted order, but will be sorted in the resulting PODContent.

    Parameters

    Returns PODContent

    a new PODContent

    Throws

    if any of the entries aren't legal for inclusion in a POD

  • Rebuilds a PODContent object from entries in the JSON-compatible format produced by toJSON. The input can be taken directly from JSON.parse and will be fully validated by this function.

    Parameters

    Returns PODContent

    a new POD object

    Throws

    if the input is malformed

  • Checks the validity of a POD membership proof by recomputing hashes.

    Validity depends only on the name hash and value hash included in the membership proof. This method doesn't check (and has no access to) the hash pre-image name or value.

    Parameters

    Returns boolean

    true if the proof is valid.

Generated using TypeDoc