@blockchaincommons/envelope - v1.0.0-beta.4
    Preparing search index...

    Class Assertion

    A predicate-object relationship representing an assertion about a subject.

    In Gordian Envelope, assertions are the basic building blocks for attaching information to a subject. An assertion consists of a predicate (which states what is being asserted) and an object (which provides the assertion's value).

    Assertions can be attached to envelope subjects to form semantic statements like: "subject hasAttribute value" or "document signedBy signature".

    Assertions are equivalent to RDF (Resource Description Framework) triples, where:

    • The envelope's subject is the subject of the triple
    • The assertion's predicate is the predicate of the triple
    • The assertion's object is the object of the triple

    Generally you do not create an instance of this type directly, but instead use Envelope.assertion(), or the various functions on Envelope that create assertions.

    Implements

    Index
    • Creates a new assertion and calculates its digest.

      This constructor takes a predicate and object, both of which are converted to envelopes using the ToEnvelope trait. It then calculates the assertion's digest by combining the digests of the predicate and object.

      The digest is calculated according to the Gordian Envelope specification, which ensures that semantically equivalent assertions always produce the same digest.

      Parameters

      • predicate: ToEnvelope | Envelope

        The predicate of the assertion, which states what is being asserted

      • object: ToEnvelope | Envelope

        The object of the assertion, which provides the assertion's value

      Returns Assertion

      A new assertion with the specified predicate, object, and calculated digest.

      // Direct method - create an assertion envelope
      const assertionEnvelope = Envelope.assertion("name", "Alice");

      // Or create and add an assertion to a subject
      const person = Envelope.from("person").addAssertion("name", "Alice");
    • Returns the predicate of the assertion.

      The predicate states what is being asserted about the subject. It is typically a string or known value, but can be any envelope.

      Returns Envelope

      A clone of the assertion's predicate envelope.

    • Returns the object of the assertion.

      The object provides the value or content of the assertion. It can be any type that can be represented as an envelope.

      Returns Envelope

      A clone of the assertion's object envelope.

    • Checks if two assertions are equal based on digest equality.

      Two assertions are considered equal if they have the same digest, regardless of how they were constructed.

      Parameters

      • other: Assertion

        The other assertion to compare with

      Returns boolean

      true if the assertions are equal, false otherwise

    • Converts this assertion to CBOR.

      The CBOR representation of an assertion is a map with a single key-value pair, where the key is the predicate's CBOR and the value is the object's CBOR.

      Returns Cbor

      A CBOR representation of this assertion

    • Attempts to create an assertion from a CBOR value.

      The CBOR must be a map with exactly one entry, where the key represents the predicate and the value represents the object.

      Parameters

      • cbor: Cbor

        The CBOR value to convert

      Returns Assertion

      A new Assertion instance

      EnvelopeError with code InvalidAssertion when the CBOR is not a single-element map; Cbor (dcbor error: <Display>) when the key or the value is not an envelope

    • Attempts to create an assertion from a CBOR map.

      The map must have exactly one entry, where the key represents the predicate and the value represents the object. This is used in the deserialization process.

      Parameters

      • map: CborMap

        The CBOR map to convert

      Returns Assertion

      A new Assertion instance

      EnvelopeError with code InvalidAssertion when the map does not have exactly one entry; Cbor (dcbor error: <Display>) when the key or the value is not an envelope

    • Creates a string representation of this assertion for debugging.

      Returns string

      A string representation