Class encapsulating a signed POD with functions for common use cases. POD 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.

Most features depending on the POD entries but not the signature are provided by a PODContent instance available via pod.content.

Constructors

  • Parameters

    • content: PODContent
    • signature: string
    • signerPublicKey: string

    Returns POD

Properties

_content: PODContent
_signature: string
_signerPublicKey: string

Accessors

  • get content(): PODContent
  • This POD's data as a PODContent object.

    Returns PODContent

  • get contentID(): bigint
  • The content ID (root hash) of this POD. PODs containing the same data (names and values, regardless of type) will have the same content ID.

    Returns bigint

  • get signature(): string
  • The signature of this POD, in a packed string form. This is an EdDSA-Poseidon signature, with the POD's content ID as the signed message. The signature is made up of 64 bytes, represented in URL-safe Base64.

    Returns string

  • get signerPublicKey(): string
  • The public key of the signer, in a packed string form. This is an EdDSA-Poseidon public key made up of 32 bytes, represnted in URL-safe Base64.

    Returns string

Methods

  • Serializes this instance as a JSON string.

    Returns string

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

    Returns JSONPOD

    a JSON-compatible representation of this POD.

  • Returns boolean

    true if the signature of this POD is valid

  • Deserializes a POD from a JSON string.

    Parameters

    • serializedPOD: string

      a string previously created by #serialize.

    Returns POD

    a new PODContent instance

    Throws

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

  • Rebuilds a POD object from 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

    • jsonPOD: JSONPOD

      the JSON-encoded POD.

    Returns POD

    a new POD object

    Throws

    TypeError if the input is malformed

    Throws

    RangeError if a value is outside of the bounds

  • Factory to create a new POD using saved data signed previously. Derived values such as Merkle tree hashes will be calculated lazily as-needed.

    Note that this method does not verify the signature. To check the validity of your POD, call verifySignature() separately.

    Parameters

    • entries: PODEntries

      saved entries

    • signature: string

      saved signature

    • signerPublicKey: string

      saved public key of signer

    Returns POD

    a new POD

    Throws

    if any arguments are malformed, or any of the entries aren't legal for inclusion in a POD

  • Factory to create a new POD by signing with the given private key. Since signing requires the content ID, this method of creation will immediately calculate the Merkle tree.

    Parameters

    • entries: PODEntries

      the contents of the new POD. These will be Merklized in order by name, regardless of the order of the input.

    • signerPrivateKey: string

      the EdDSA private key of the signer, required to be 32 bytes, encoded as per decodePrivateKey.

    Returns POD

    Throws

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

Generated using TypeDoc