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

    Class Envelope

    A flexible container for structured data with built-in integrity verification.

    Gordian Envelope is the primary data structure of this library. It provides a way to encapsulate and organize data with cryptographic integrity, privacy features, and selective disclosure capabilities.

    Key characteristics of envelopes:

    • Immutability: Envelopes are immutable. Operations that appear to "modify" an envelope actually create a new envelope. This immutability is fundamental to maintaining the integrity of the envelope's digest tree.

    • Efficient Cloning: Envelopes use shallow copying for efficient O(1) cloning. Since they're immutable, clones share the same underlying data.

    • Semantic Structure: Envelopes can represent various semantic relationships through subjects, predicates, and objects (similar to RDF triples).

    • Digest Tree: Each envelope maintains a Merkle-like digest tree that ensures the integrity of its contents and enables verification of individual parts.

    • Privacy Features: Envelopes support selective disclosure through elision, encryption, and compression of specific parts, while maintaining the overall integrity of the structure.

    • Deterministic Representation: Envelopes use deterministic CBOR encoding to ensure consistent serialization across platforms.

    The Gordian Envelope specification is defined in an IETF Internet Draft, and this implementation closely follows that specification.

    // Create an envelope representing a person
    const person = Envelope.from("person")
    .addAssertion("name", "Alice")
    .addAssertion("age", 30)
    .addAssertion("email", "alice@example.com");

    // Create a partially redacted version by eliding the email
    const redacted = person.elide({ removing: [/// person.assertionWithPredicate("email")
    ] });

    // The digest of both envelopes remains the same
    assert(person.digest().equals(redacted.digest()));

    Implements

    Index
    confirmContainsTarget confirmContainsSet proofContainsTarget proofContainsSet addAttachment attachmentConformsTo attachmentPayload attachmentVendor expectAttachment attachments validateAttachment addEdgeEnvelope edgeIsA edgeSource edgeSubject edgeTarget edges edgesMatching validateEdge addRecipient decryptSubjectToRecipient decryptToRecipient encryptSubjectToRecipient encryptSubjectToRecipients encryptToRecipients recipients addSecret isLockedWithPassword isLockedWithSshAgent lock lockSubject lockSubjectWith lockWith unlock unlockSubject unlockSubjectWith unlockWith addSignature addSignatures hasSignatureFrom hasSignatureFromReturningMetadata hasSignaturesFrom hasSignaturesFromThreshold isVerifiedSignature makeSignedAssertion sign signatures verify verifyReturningMetadata verifySignature verifySignatureFrom verifySignatureFromReturningMetadata verifySignaturesFrom verifySignaturesFromThreshold sskrSplit addType expectType expectTypeValue getType hasType hasTypeValue types diagnostic hex mermaidFormat format formatFlat shortId summary treeFormat encryptToRecipient seal unseal from fromOptional fromCase assertion node fromAssertion knownValue encrypted compressed elided leaf wrap digest subject isSubjectAssertion isSubjectObscured untaggedCbor toCbor cborTags toUR fromCbor fromBytes fromUntaggedCbor addAssertion addAssertionEnvelope toString addAssertionEnvelopes addOptionalAssertionEnvelope addOptionalAssertion addSalt pipe addNonemptyStringAssertion addAssertions addAssertionIf addAssertionEnvelopeIf removeAssertion replaceAssertion replaceSubject assertions isFalse isTrue isBool isNumber isSubjectNumber isNaN isSubjectNaN isNull asBytes asArray asMap asText asLeaf asKnownValue expectKnownValue isKnownValue isSubjectUnit checkSubjectUnit hasAssertions asAssertion expectAssertion asPredicate expectPredicate asObject expectObject isAssertion isElided isLeaf isNode isWrapped isInternal isObscured assertionsWithPredicate assertionWithPredicate optionalAssertionWithPredicate objectForPredicate optionalObjectForPredicate objectsForPredicate elementsCount isSubjectEncrypted isSubjectCompressed isSubjectElided setPosition position removePosition wrap unwrap walk digests deepDigests shallowDigests structuralDigest object predicate elide unelide nodesMatching walkUnelide walkReplace isEquivalentTo isIdenticalTo walkDecrypt walkDecompress expectLeaf expectString expectNumber expectBoolean expectBytes expectNull expectDate expectSubject expectObjectForPredicate optionalObjectForPredicateAs objectForPredicateOr expectObjectsForPredicate encryptSubject decryptSubject encrypt decrypt isEncrypted compress decompress compressSubject decompressSubject isCompressed
    • get case(): EnvelopeCase

      Returns a reference to the underlying envelope case.

      The EnvelopeCase enum represents the specific structural variant of this envelope. This method provides access to that underlying variant for operations that need to differentiate between the different envelope types.

      Returns EnvelopeCase

      The EnvelopeCase that defines this envelope's structure.

    • get UNIT(): Envelope

      Unit envelopes have the known value ''. They represent a position where no meaningful data can exist. In this sense they make a semantically stronger assertion than null, which represents a position where no meaningful data currently exists, but could exist in the future.

      Returns Envelope

    • Method form of confirmContainsTarget from @blockchaincommons/envelope/proof.

      Parameters

      Returns boolean

    • Method form of confirmContainsSet from @blockchaincommons/envelope/proof.

      Parameters

      • ...args: [target: Set<Digest>, proof: Envelope]

      Returns boolean

    • Method form of proofContainsTarget from @blockchaincommons/envelope/proof.

      Parameters

      Returns Envelope | undefined

    • Method form of proofContainsSet from @blockchaincommons/envelope/proof.

      Parameters

      • ...args: [target: Set<Digest>]

      Returns Envelope | undefined

    • Method form of addAttachment from @blockchaincommons/envelope/attachment.

      Parameters

      • ...args: [payload: EnvelopeInput, vendor: string, conformsTo?: string]

      Returns Envelope

    • Method form of attachmentConformsTo from @blockchaincommons/envelope/attachment.

      Parameters

      • ...args: []

      Returns string | undefined

    • Method form of attachmentPayload from @blockchaincommons/envelope/attachment.

      Parameters

      • ...args: []

      Returns Envelope

    • Method form of attachmentVendor from @blockchaincommons/envelope/attachment.

      Parameters

      • ...args: []

      Returns string

    • Method form of validateAttachment from @blockchaincommons/envelope/attachment.

      Parameters

      • ...args: []

      Returns void

    • Method form of edgeIsA from @blockchaincommons/envelope/edge.

      Parameters

      • ...args: []

      Returns Envelope

    • Method form of edgeSource from @blockchaincommons/envelope/edge.

      Parameters

      • ...args: []

      Returns Envelope

    • Method form of edgeSubject from @blockchaincommons/envelope/edge.

      Parameters

      • ...args: []

      Returns Envelope

    • Method form of edgeTarget from @blockchaincommons/envelope/edge.

      Parameters

      • ...args: []

      Returns Envelope

    • Method form of edges from @blockchaincommons/envelope/edge.

      Parameters

      • ...args: []

      Returns Envelope[]

    • Method form of validateEdge from @blockchaincommons/envelope/edge.

      Parameters

      • ...args: []

      Returns void

    • Method form of addRecipient from @blockchaincommons/envelope/recipient.

      Parameters

      • ...args: [recipient: Encrypter, contentKey: SymmetricKey, options: RecipientOptions]

      Returns Envelope

    • Method form of decryptSubjectToRecipient from @blockchaincommons/envelope/recipient.

      Parameters

      • ...args: [recipient: Decrypter]

      Returns Envelope

    • Method form of decryptToRecipient from @blockchaincommons/envelope/recipient.

      Parameters

      • ...args: [recipient: Decrypter]

      Returns Envelope

    • Method form of encryptSubjectToRecipient from @blockchaincommons/envelope/recipient.

      Parameters

      Returns Envelope

    • Method form of encryptSubjectToRecipients from @blockchaincommons/envelope/recipient.

      Parameters

      • ...args: [recipients: Encrypter[], options: RngOptions]

      Returns Envelope

    • Method form of encryptToRecipients from @blockchaincommons/envelope/recipient.

      Parameters

      • ...args: [recipients: Encrypter[], options: RngOptions]

      Returns Envelope

    • Method form of recipients from @blockchaincommons/envelope/recipient.

      Parameters

      • ...args: []

      Returns SealedMessage[]

    • Method form of addSecret from @blockchaincommons/envelope/secret.

      Parameters

      • ...args: [
            method: KeyDerivationMethod,
            secret: Uint8Array<ArrayBufferLike>,
            contentKey: SymmetricKey,
        ]

      Returns Envelope

    • Method form of isLockedWithPassword from @blockchaincommons/envelope/secret.

      Parameters

      • ...args: []

      Returns boolean

    • Method form of isLockedWithSshAgent from @blockchaincommons/envelope/secret.

      Parameters

      • ...args: []

      Returns boolean

    • Method form of lock from @blockchaincommons/envelope/secret.

      Parameters

      • ...args: [
            method: KeyDerivationMethod,
            secret: Uint8Array<ArrayBufferLike>,
            options: RngOptions,
        ]

      Returns Envelope

    • Method form of lockSubject from @blockchaincommons/envelope/secret.

      Parameters

      • ...args: [
            method: KeyDerivationMethod,
            secret: Uint8Array<ArrayBufferLike>,
            options: RngOptions,
        ]

      Returns Envelope

    • Method form of lockSubjectWith from @blockchaincommons/envelope/secret.

      Parameters

      Returns Promise<Envelope>

    • Method form of lockWith from @blockchaincommons/envelope/secret.

      Parameters

      Returns Promise<Envelope>

    • Method form of unlock from @blockchaincommons/envelope/secret.

      Parameters

      • ...args: [secret: Uint8Array<ArrayBufferLike>]

      Returns Envelope

    • Method form of unlockSubject from @blockchaincommons/envelope/secret.

      Parameters

      • ...args: [secret: Uint8Array<ArrayBufferLike>]

      Returns Envelope

    • Method form of unlockSubjectWith from @blockchaincommons/envelope/secret.

      Parameters

      • ...args: [agent: SshAgent, id: string]

      Returns Promise<Envelope>

    • Method form of unlockWith from @blockchaincommons/envelope/secret.

      Parameters

      • ...args: [agent: SshAgent, id: string]

      Returns Promise<Envelope>

    • Method form of addSignatures from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [signers: readonly (Signer | { signer: Signer } & SignOptions)[]]

      Returns Envelope

    • Method form of hasSignatureFrom from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [verifier: Verifier]

      Returns boolean

    • Method form of hasSignatureFromReturningMetadata from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [verifier: Verifier]

      Returns Envelope | undefined

    • Method form of hasSignaturesFrom from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [verifiers: Verifier[]]

      Returns boolean

    • Method form of hasSignaturesFromThreshold from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [verifiers: Verifier[], threshold?: number]

      Returns boolean

    • Method form of isVerifiedSignature from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [signature: Signature, verifier: Verifier]

      Returns boolean

    • Method form of makeSignedAssertion from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [signature: Signature, note?: string]

      Returns Envelope

    • Method form of signatures from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: []

      Returns Envelope[]

    • Method form of verify from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [verifier: Verifier]

      Returns Envelope

    • Method form of verifyReturningMetadata from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [verifier: Verifier]

      Returns { envelope: Envelope; metadata: Envelope }

      • envelope: Envelope

        The unwrapped envelope.

      • metadata: Envelope

        The metadata bound to the signature (the unit envelope when there was none).

    • Method form of verifySignature from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [signature: Signature, verifier: Verifier]

      Returns Envelope

    • Method form of verifySignatureFrom from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [verifier: Verifier]

      Returns Envelope

    • Method form of verifySignatureFromReturningMetadata from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [verifier: Verifier]

      Returns Envelope

    • Method form of verifySignaturesFrom from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [verifiers: Verifier[]]

      Returns Envelope

    • Method form of verifySignaturesFromThreshold from @blockchaincommons/envelope/signature.

      Parameters

      • ...args: [verifiers: Verifier[], threshold?: number]

      Returns Envelope

    • Method form of sskrSplit from @blockchaincommons/envelope/sskr.

      Parameters

      • ...args: [spec: Spec, contentKey: SymmetricKey, RngOptions?]

      Returns Envelope[][]

    • Method form of expectType from @blockchaincommons/envelope/types.

      Parameters

      Returns void

    • Method form of expectTypeValue from @blockchaincommons/envelope/types.

      Parameters

      • ...args: [t: KnownValue]

      Returns void

    • Method form of getType from @blockchaincommons/envelope/types.

      Parameters

      • ...args: []

      Returns Envelope

    • Method form of hasType from @blockchaincommons/envelope/types.

      Parameters

      Returns boolean

    • Method form of hasTypeValue from @blockchaincommons/envelope/types.

      Parameters

      • ...args: [t: KnownValue]

      Returns boolean

    • Method form of types from @blockchaincommons/envelope/types.

      Parameters

      • ...args: []

      Returns Envelope[]

    • Method form of hex from @blockchaincommons/envelope/format.

      Parameters

      Returns string

    • Method form of format from @blockchaincommons/envelope/format.

      Parameters

      Returns string

    • Method form of formatFlat from @blockchaincommons/envelope/format.

      Parameters

      Returns string

    • Method form of shortId from @blockchaincommons/envelope/format.

      Parameters

      • ...args: [format: "short" | "full" | "ur"]

      Returns string

    • Method form of summary from @blockchaincommons/envelope/format.

      Parameters

      Returns string

    • Method form of seal from @blockchaincommons/envelope/seal.

      Parameters

      • ...args: [sender: Signer, recipient: Encrypter, SealOptions?]

      Returns Envelope

    • Method form of unseal from @blockchaincommons/envelope/seal.

      Parameters

      • ...args: [senderPublicKey: Verifier, recipient: Decrypter]

      Returns Envelope

    • Creates an envelope with a subject, which can be any value that can be encoded as an envelope.

      Parameters

      Returns Envelope

      A new envelope containing the subject

      const envelope = Envelope.from("Hello, world!");
      const numberEnvelope = Envelope.from(42);
      const binaryEnvelope = Envelope.from(new Uint8Array([1, 2, 3]));
    • Creates an envelope with a subject, or undefined if the subject is absent (undefined or JS null).

      port ↔ reference note: the reference Envelope::new_or_none returns Option<Envelope> — the None branch fires only on None. We follow the same convention as Envelope.from(x ?? null) and treat JS null and undefined interchangeably as the absent case.

      Parameters

      • subject: EnvelopeInput | undefined

        The optional subject value (undefined or null triggers the absent branch).

      Returns Envelope | undefined

      A new envelope or undefined

    • Creates an envelope from an EnvelopeCase.

      This is an internal method used by extensions to create envelopes from custom case types like compressed or encrypted.

      Parameters

      Returns Envelope

      A new envelope with the given case

    • Creates an envelope with a subject and validated assertions.

      All assertions must be assertion or obscured envelopes.

      Parameters

      • subject: Envelope

        The subject envelope

      • assertions: readonly Envelope[]

        The assertions to attach

      • __namedParameters: { unchecked?: boolean } = {}

      Returns Envelope

      A new node envelope

      If any assertion is not valid

    • Creates an envelope with a known value.

      Parameters

      • value: number | bigint | KnownValue

        The known value (can be a KnownValue instance or a number/bigint)

      Returns Envelope

      A new known value envelope

    • Creates an envelope with encrypted content.

      Err(Error::MissingDigest) when the message has no AAD digest.

      Parameters

      • encryptedMessage: EncryptedMessage

        The encrypted message

      Returns Envelope

      A new encrypted envelope

      If the encrypted message doesn't have a digest

    • Creates an envelope with compressed content.

      Err(Error::MissingDigest) when the compressed value has no digest.

      Parameters

      • compressed: Compressed

        The compressed data

      Returns Envelope

      A new compressed envelope

      If the compressed data doesn't have a digest

    • Creates an elided envelope containing only a digest.

      Parameters

      • digest: Digest

        The digest of the elided content

      Returns Envelope

      A new elided envelope

    • Creates a leaf envelope containing a CBOR value.

      Parameters

      • value: unknown

        The value to encode as CBOR

      Returns Envelope

      A new leaf envelope

    • Returns the subject of this envelope.

      For different envelope cases:

      • Node: Returns the subject envelope
      • Other cases: Returns the envelope itself

      Returns Envelope

      The subject envelope

    • Checks if the envelope's subject is an assertion.

      Returns boolean

      true if the subject is an assertion, false otherwise

    • Checks if the envelope's subject is obscured (elided, encrypted, or compressed).

      Returns boolean

      true if the subject is obscured, false otherwise

    • Returns the untagged CBOR representation of this envelope.

      Returns Cbor

      The untagged CBOR

    • Returns the tagged CBOR representation of this envelope.

      All envelopes are tagged with TAG_ENVELOPE (200).

      Returns Cbor

      The tagged CBOR

    • Decodes an envelope from its tagged CBOR (tag 200): the reference's TryFrom<CBOR> / from_tagged_cbor.

      Parameters

      • cbor: Cbor

      Returns Envelope

      EnvelopeError with code Cbor whose message is the dcbor Display and whose cause is the CborError: WrongType for an untagged value, WrongTag for another tag (the expected tag named as the global tags store names it), else what fromUntaggedCbor reports.

    • Decodes an envelope from tagged CBOR bytes: the reference's try_from_cbor_data.

      Parameters

      • data: Uint8Array

      Returns Envelope

      EnvelopeError with code Cbor whose message is the dcbor Display of the byte-level failure (early end of CBOR data, the decoded CBOR had 1 extra bytes at the end, a CBOR numeric value was encoded in non-canonical form, …) and whose cause is the CborError; then as fromCbor.

    • Decodes an envelope from its untagged CBOR (the content of tag 200): the reference's from_untagged_cbor. A tag-24 or tag-201 value is a leaf, a tag-200 value a wrapped envelope, tag 40002 an encrypted message, tag 40003 a compressed value, a 32-byte string an elided envelope, an array a node, a single-element map an assertion and an unsigned integer a known value.

      Parameters

      • cbor: Cbor

      Returns Envelope

      EnvelopeError with code Cbor whose message is the dcbor Display the reference returns and whose cause is the CborError: the dcbor error of a malformed component as it is, else Custom with the reference's text (unknown envelope tag: <n>, invalid digest size: expected 32, got <n>, node must have at least two elements, invalid format, assertion must be a map with exactly one element, a digest was expected but not found, invalid envelope). A failure inside an assertion's key or value nests as dcbor error: <message>.

    • Creates a string representation of this envelope.

      Returns string

      A string representation

    • Adds a salt assertion of random bytes so that this envelope's digest cannot be correlated with another envelope of the same content.

      By default the salt length is proportional to the envelope's size (5–25 %, at least 8 bytes; the reference's add_salt_using); give length (add_salt_with_len_using), a range (add_salt_in_range_using), or the exact salt (add_salt_instance) instead. rng overrides the secure default. The salt itself comes from components' Salt, whose checks the reference's Salt::new_* make.

      Parameters

      Returns Envelope

      EnvelopeError with code InvalidParameter for a length or bound that is not a non-negative integer; Components (the components message, e.g. data too short: salt expected at least 8, got 7) for a length below 8 or a bound the reference rejects.

    • Applies fn to this envelope: e.pipe(sign, key).pipe(encryptSubject, k) chains the subpath functions without the /all facade.

      Type Parameters

      • A extends unknown[]
      • R

      Parameters

      Returns R

    • Adds assertion when condition holds; this envelope otherwise.

      Parameters

      • condition: boolean
      • assertionEnvelope: Envelope

      Returns Envelope

    • true when the subject is the boolean false (the reference's is_false: subject extraction, so a node whose subject is false qualifies).

      Returns boolean

    • true when the subject is the boolean true (the reference's is_true).

      Returns boolean

    • true when the subject is a boolean (the reference's is_bool).

      Returns boolean

    • true when the envelope is a number leaf.

      Returns boolean

    • true when the envelope is a node whose subject is a number.

      Returns boolean

    • true when the envelope is the NaN leaf.

      Returns boolean

    • true when the envelope is a node whose subject is NaN.

      Returns boolean

    • true when the subject is null (the reference's is_null: subject extraction).

      Returns boolean

    • A copy of the subject's bytes, or undefined when it is not a byte-string leaf.

      Returns Uint8Array<ArrayBuffer> | undefined

    • A copy of the subject's array, or undefined when it is not an array leaf.

      Returns readonly Cbor[] | undefined

    • A copy of the subject's map, or undefined when it is not a map leaf.

      Returns CborMap | undefined

    • The subject's text, or undefined when it is not a text leaf.

      Returns string | undefined

    • The subject's CBOR, or undefined when it is not a leaf.

      Returns Cbor | undefined

    • The known value, or undefined when the subject is not one.

      Returns KnownValue | undefined

    • The known value, or undefined when the subject is not one.

      Returns KnownValue

      EnvelopeError with code NotKnownValue.

    • true when the envelope is a known value.

      Returns boolean

    • true when the envelope is a node whose subject is the unit known value.

      Returns boolean

    • Throws SubjectNotUnit unless the subject is the unit known value.

      Returns Envelope

      EnvelopeError with code SubjectNotUnit.

    • true when the envelope is a node with at least one assertion.

      Returns boolean

    • The predicate, or undefined when this envelope is not an assertion.

      Returns Envelope

      EnvelopeError with code NotAssertion.

    • true when the envelope is an assertion.

      Returns boolean

    • true when the envelope is a node (a subject with assertions).

      Returns boolean

    • true when the envelope is a wrapped envelope.

      Returns boolean

    • true when the envelope is internal (a node, a wrapped envelope or an assertion, never a leaf or known value).

      Returns boolean

    • true when the envelope is obscured (elided, encrypted or compressed).

      Returns boolean

    • The single assertion with predicate, or undefined; AmbiguousPredicate when there are several.

      Parameters

      Returns Envelope | undefined

      EnvelopeError with code AmbiguousPredicate.

    • The object of the single assertion with predicate, or undefined; AmbiguousPredicate when there are several.

      Parameters

      Returns Envelope | undefined

      EnvelopeError with code AmbiguousPredicate.

    • The number of elements in the tree (the subject, the assertions and their parts).

      Returns number

    • true when the envelope is encrypted or a node whose subject is (recursively).

      Returns boolean

    • true when the envelope is compressed or a node whose subject is (recursively).

      Returns boolean

    • true when the envelope is elided or a node whose subject is (recursively).

      Returns boolean

    • Adds a 'position' assertion with the given ordinal (the reference's set_position(usize)): a non-negative safe integer number, or a bigint in 0 ..= 2⁶⁴ − 1 for the exact form.

      Parameters

      • position: number | bigint

      Returns Envelope

      EnvelopeError with code InvalidParameter for any other value; InvalidFormat when the envelope already has several positions.

    • The value of the 'position' assertion (the reference's position(), extract_subject::<usize>()): a number when at most 2⁵³ − 1, a bigint otherwise. A negative integer wraps to 2⁶⁴ + n, as the reference's usize::try_from(CBOR) wraps it.

      Returns number | bigint

      EnvelopeError with code NonexistentPredicate / AmbiguousPredicate when there is not exactly one position; Cbor (dcbor error: <Display>) when its object is not an integer in range.

    • Visits every node of the tree depth-first, threading state; hideNodes visits only the leaves' structure.

      Type Parameters

      • State

      Parameters

      Returns void

    • Returns the set of digests in the envelope, down to the specified level.

      the reference uses HashSet<Digest> which dedupes by content; native JS Set dedupes by reference, so we route inserts through a hex-keyed Map before materialising the final Set. That keeps the public signature (Set<Digest>) while guaranteeing each value appears at most once, which is what every consumer of these methods actually wants.

      Parameters

      • levelLimit: number

      Returns Set<Digest>

    • Returns all digests in the envelope at all levels.

      Returns Set<Digest>

    • Returns the digests in the envelope down to its second level.

      Returns Set<Digest>

    • structure mode, building an image:

      • Each obscured case prepends a 1-byte discriminator: 0 for Encrypted, 1 for Elided, 2 for Compressed (matching the the reference order).
      • Every node — obscured or not — appends its 32-byte digest bytes.

      The full image is then SHA-256-hashed via Digest.fromImage.

      Unlike Envelope.digest (which captures semantic identity), structuralDigest captures the envelope's structural form too, including where elision / encryption / compression has been applied. Two envelopes whose digest()s match are semantically equivalent; their structuralDigest()s match only if the structures themselves are identical.

      Returns Digest

    • Elide this envelope, or with options elide (or encrypt or compress) parts of it: removing obscures the elements whose digests are listed, revealing obscures everything but the listed elements and their ancestors. action defaults to "elide".

      Parameters

      Returns Envelope

    • Set<Digest> for backward compatibility with callers, but the underlying dedup is by hex content (via a hex-keyed Map) so two Digest instances that represent the same hash bytes count once, matching the reference's HashSet<Digest> semantics.

      Parameters

      • targetDigests: Set<Digest> | undefined
      • obscureTypes: ObscureType[]

      Returns Set<Digest>

    • Two envelopes are equivalent if they have the same digest (semantic equivalence). This is a weaker comparison than isIdenticalTo which also checks the case type.

      Parameters

      Returns boolean

    • short-circuit on a semantic mismatch (different digest()), then fall through to a Envelope.structuralDigest comparison. Two envelopes whose digests match but whose structures differ — e.g. an envelope and a version of it with one assertion elided — are not identical.

      Parameters

      Returns boolean

    • Recursively walks the envelope and decrypts every encrypted node it can. For an Encrypted node, each provided key is tried in order; the first one that successfully decrypts wins, and the recursion continues into the result so chains of nested encryption peel off one layer per matching key. Nodes whose decryption fails for every key are returned unchanged — matching the reference's if let Ok(decrypted) = ... pattern.

      Structural sharing: if a recursion produces an envelope that is Envelope.isIdenticalTo the original, the original instance is reused instead of allocating a new node.

      Parameters

      • keys: SymmetricKey[]

      Returns Envelope

    • Recursively walks the envelope and decompresses any compressed node whose digest is in targetDigests (or every compressed node if targetDigests is undefined). Decompression failures are tolerated — the original node is returned in that case, mirroring the reference's if let Ok(decompressed) = ... pattern.

      Parameters

      • OptionaltargetDigests: Set<Digest>

      Returns Envelope

    • The leaf's CBOR: the reference's try_leaf().

      Returns Cbor

      EnvelopeError with code NotLeaf when the envelope is not a leaf.

    • The leaf's text: the reference's String::try_from(envelope).

      Returns string

      EnvelopeError with code NotLeaf when the envelope is not a leaf; Cbor (dcbor error: <Display>, cause the CborError) when the leaf is not text.

    • The leaf's number as dcbor's expectFloat reads it: the reference's f64::try_from(envelope). An integer the f64 cannot represent exactly is rejected (OutOfRange), as the reference rejects it.

      Returns number

      EnvelopeError with code NotLeaf when the envelope is not a leaf; Cbor (dcbor error: <Display>, cause the CborError) when the leaf is not a representable number.

    • The leaf's boolean: the reference's bool::try_from(envelope).

      Returns boolean

      EnvelopeError with code NotLeaf / Cbor as expectString.

    • A copy of the leaf's bytes: the reference's ByteString::try_from(envelope).

      Returns Uint8Array<ArrayBuffer>

      EnvelopeError with code NotLeaf / Cbor as expectString.

    • null when the leaf is the null value.

      Returns null

      EnvelopeError with code NotLeaf / Cbor as expectString.

    • The subject's tag-1 date as a Date (millisecond precision): the reference's extract_subject::<Date>() viewed as a Date; use expectSubject(CborDate.fromTaggedCbor) for the exact value.

      Returns Date

      EnvelopeError as expectSubject.

    • A copy with the subject encrypted by key (ChaCha20-Poly1305 over the subject's CBOR, the digest as AAD): the reference's encrypt_subject.

      Parameters

      Returns Envelope

      EnvelopeError with code AlreadyEncrypted when the subject is encrypted or compressed; AlreadyElided when it is elided.

    • A copy with the subject decrypted by key (the reference's decrypt_subject).

      Parameters

      • key: SymmetricKey

      Returns Envelope

      EnvelopeError with code NotEncrypted when the subject is not encrypted; Components (components error: <Display>) when the key does not open it; Cbor (dcbor error: <Display>) when the plaintext is not an envelope; MissingDigest / InvalidDigest on a digest mismatch.

    • true when the envelope is encrypted.

      Returns boolean

    • A copy compressed (deflate over its CBOR): the reference's compress; this envelope when already compressed.

      Returns Envelope

      EnvelopeError with code AlreadyEncrypted when the envelope is encrypted; AlreadyElided when it is elided.

    • A copy decompressed (the reference's decompress).

      Returns Envelope

      EnvelopeError with code NotCompressed when the envelope is not compressed; Components (components error: <Display>) for a corrupt stream; Cbor (dcbor error: <Display>) when the data is not an envelope; MissingDigest / InvalidDigest on a digest mismatch.

    • true when the envelope is compressed.

      Returns boolean