Expand description
§Gordian Envelope: A Flexible Container for Structured Data
§Introduction
The Gordian Envelope protocol specifies a structured format for hierarchical binary data focused on the ability to transmit it in a privacy-focused way. Envelopes are designed to facilitate “smart documents” and have a number of unique features including: easy representation of a variety of semantic structures, a built-in Merkle-like digest tree, deterministic representation using CBOR, and the ability for the holder of a document to selectively encrypt or elide specific parts of a document without invalidating the document structure including the digest tree, or any cryptographic signatures that rely on it.
§Getting Started
[dependencies]
bc-envelope = "0.36.0"§Specification
Gordian Envelope is currently specified in this IETF Internet Draft.
Envelopes are immutable. You create “mutations” by creating new envelopes from old envelopes.
§Basic Envelope Creation
Envelope::newCreates an envelope with asubject.Envelope::new_assertionCreates an assertion envelope with apredicateandobject.
§Adding Assertions
§Adding Assertions with a Predicate and Object
Envelope::add_assertionAdds an assertion to an envelope.Envelope::add_assertion_saltedAdds an optionally salted assertion to an envelope.Envelope::add_optional_assertionOptionally adds an assertion to an envelope.
§Adding Assertions with an Assertion Envelope
Envelope::add_assertion_envelopeAdds an assertion envelope to an envelope.Envelope::add_assertion_envelope_saltedAdds an optionally salted assertion envelope to an envelope.Envelope::add_assertion_envelopesAdds a vector of assertion envelopes to an envelope.Envelope::add_optional_assertion_envelope_saltedOptionally adds an assertion envelope to an envelope.
§Removing and Replacing Assertions
Envelope::remove_assertionRemoves an assertion from an envelope.Envelope::replace_assertionReplaces an assertion in an envelope.Envelope::replace_subjectReplaces the subject of an envelope.
§Queries
§Getting the basic parts of an envelope
Envelope::subjectReturns the subject of an envelope.Envelope::as_predicateIf the envelope’s subject is an assertion return its predicate, else returnNone.Envelope::as_objectIf the envelope’s subject is an assertion return its object, else returnNone.
§Getting assertions on an envelope
Envelope::assertionsReturns the assertions of an envelope.Envelope::has_assertionsReturns whether an envelope has assertions.Envelope::as_assertionIf the envelope’s subject is an assertion return it, else returnNone.
§Getting the specific types of an envelope
Envelope::as_leafThe envelope’s leaf CBOR object, orNoneif the envelope is not a leaf.Envelope::as_known_valueThe envelope’s known value, orNoneif the envelope is not a known value.
§Determining the type of an envelope
Envelope::is_leafReturns whether an envelope is a leaf.Envelope::is_nodeReturns whether an envelope is a node (whether it has at least one assertion).Envelope::is_wrappedReturns whether an envelope is wrapped.Envelope::is_known_valueReturns whether an envelope is a known value.Envelope::is_assertionReturns whether an envelope is an assertion.Envelope::is_encryptedReturns whether an envelope is encrypted.Envelope::is_compressedReturns whether an envelope is compressed.Envelope::is_elidedReturns whether an envelope is elided.
§Determining the type of an envelope’s subject
Envelope::is_subject_assertionReturns whether an envelope’s subject is an assertion.Envelope::is_subject_encryptedReturns whether an envelope’s subject is encrypted.Envelope::is_subject_compressedReturns whether an envelope’s subject is compressed.Envelope::is_subject_elidedReturns whether an envelope’s subject is elided.Envelope::is_subject_obscuredReturns whether an envelope’s subject is obscured.
§Getting assertions and parts of assertions
Envelope::assertion_with_predicateReturns the assertion with the given predicate.Envelope::assertions_with_predicateReturns all assertions with the given predicate.Envelope::object_for_predicateReturns the object of the assertion with the given predicate.Envelope::objects_for_predicateReturns the objects of all assertions with the matching predicate.Envelope::elements_countReturns the number of elements in the envelope.
§Extracting parts of envelopes as specific types
Envelope::extract_subjectReturns the envelope’s subject, decoded as the given type.Envelope::extract_object_for_predicateReturns the object of the assertion with the given predicate, decoded as the given type.Envelope::extract_objects_for_predicateReturns the objects of all assertions with the matching predicate, decoded as the given type.
§Other queries
Envelope::is_internalReturns whether an envelope is internal, that is, if it has child elements.Envelope::is_obscuredReturns whether an envelope is obscured (elided, encrypted, or compressed).
§Wrapping and Unwrapping Envelopes
Envelope::wrapWraps an envelope in a new envelope.Envelope::try_unwrapUnwraps an envelope.
§Formatting Envelopes
§Envelope notation
Envelope::formatFormats an envelope in envelope notation.Envelope::format_optFormats an envelope in envelope notation, with optional annotations.
§Tree notation
Envelope::tree_formatFormats an envelope in envelope tree notation.- [
Envelope::tree_format_with_target] Formats an envelope in envelope tree notation, highlighting a target set of elements.
§CBOR diagnostic notation
Envelope::diagnosticFormats an envelope in CBOR diagnostic notation.Envelope::diagnosticFormats an envelope in CBOR diagnostic notation, with optional annotations.
§CBOR hexadecimal notation
Envelope::hexFormats an envelope in CBOR hexadecimal notation.Envelope::hex_optFormats an envelope in CBOR hexadecimal notation, with optional annotations.
§Working with the Digest Tree
§Semantic equivalence
bc_components::DigestProvider::digestReturns the digest of an envelope.Envelope::digestsReturns the set of digests contained in the envelope’s elements, down to the specified level.Envelope::deep_digestsReturns the set of all digests in the envelope.Envelope::shallow_digestsReturns the set of all digests in the envelope, down to its second level.Envelope::is_equivalent_toTests two envelopes for semantic equivalence.
§Structural identicality
Envelope::structural_digestProduce a value that will necessarily be different if two envelopes differ structurally, even if they are semantically equivalent.Envelope::is_identical_toTests two envelopes for structural equality.
§Signing and Verifying Signatures
§Signing
Envelope::add_signatureCreates a signature for the envelope’s subject and returns a new envelope with a'signed': Signatureassertion.Envelope::add_signature_optCreates a signature for the envelope’s subject and returns a new envelope with a'signed': Signatureassertion.Envelope::add_signaturesCreates several signatures for the envelope’s subject and returns a new envelope with additional'signed': Signatureassertions.Envelope::add_signatures_optCreates several signatures for the envelope’s subject and returns a new envelope with additional'signed': Signatureassertions.Envelope::add_signatureCreates a signature for the envelope’s subject and returns a new envelope with a'signed': Signatureassertion.
§Verifying by returning a boolean
Envelope::is_verified_signatureReturns whether the given signature is valid.Envelope::has_signature_fromReturns whether the envelope’s subject has a valid signature from the given public key.Envelope::has_signatures_fromReturns whether the envelope’s subject has a set of signatures.Envelope::has_signatures_from_thresholdReturns whether the envelope’s subject has some threshold of signatures.
§Verifying by returning a result
Envelope::verify_signatureChecks whether the given signature is valid for the given public key.Envelope::verify_signature_fromChecks whether the envelope’s subject has a valid signature from the given public key.Envelope::verify_signatures_fromChecks whether the envelope’s subject has a set of signatures.Envelope::verify_signatures_from_thresholdChecks whether the envelope’s subject has some threshold of signatures.
§Helpers
Envelope::verify_signatureReturns an array ofSignatures from all of the envelope’ssignedpredicates.Envelope::make_signed_assertionConvenience constructor for asigned: Signatureassertion envelope.
§Splitting Envelopes with SSKR
Envelope::sskr_splitSplits the envelope into a set of SSKR shares.Envelope::sskr_joinCreates a new envelope resulting from the joining a set of envelopes split by SSKR.
§Encryption
Envelope::encrypt_subjectReturns a new envelope with its subject encrypted.Envelope::decrypt_subjectReturns a new envelope with its subject decrypted.
§Public Key Encryption
Envelope::add_recipientReturns a new envelope with an addedhasRecipient: SealedMessageassertion.Envelope::recipientsReturns an array ofSealedMessages from all of the envelope’shasRecipientassertions.Envelope::encrypt_subject_to_recipientsReturns an new envelope with its subject encrypted and ahasRecipientEnvelope::encrypt_subject_to_recipientReturns a new envelope with its subject encrypted and ahasRecipientassertion added for therecipient.Envelope::decrypt_to_recipientReturns a new envelope with its subject decrypted using the recipient’sPrivateKeyBase.
§Compression
Envelope::compressReturns the compressed variant of this envelope.Envelope::decompressReturns the decompressed variant of this envelope.Envelope::compress_subjectReturns this envelope with its subject compressed.Envelope::decompress_subjectReturns this envelope with its subject decompressed.
§Eliding, Encrypting, or Compressing Parts of an Envelope
-
Envelope::elideReturns the elided variant of this envelope. -
Returns a version of this envelope with the given element(s) elided:
-
Returns a version with all elements except the given element(s) elided:
-
As above, but takes a boolean to determine whether to remove or reveal:
-
Returns a version with the given element(s) elided, encrypted, or compressed:
-
Returns a version with all elements except the given element(s) elided, encrypted, or compressed:
-
As above, but takes a boolean to determine whether to remove or reveal:
-
Envelope::unelideReturns the unelided variant of this envelope, given the envelope that was elided.
§Decorrelating Envelopes using Salt
Envelope::add_saltAdd a number of bytes of salt generally proportionate to the size of the object being salted.Envelope::add_salt_with_lenAdd a specified number of bytes of salt.Envelope::add_salt_in_rangeAdd a number of bytes of salt chosen randomly from the given range.
§Walking an Envelope’s Hierarchy
Envelope::walkWalk the envelope, calling the visitor function for each element.
§Envelope Expressions
§Constructing Expressions, Requests, and Responses
Expression::newCreates an envelope with a«function»subject.Parameter::new_namedCreates a new envelope containing a❰parameter❱: valueassertion.Parameter::new_knownOptionally adds a❰parameter❱: valueassertion to the envelope.ExpressionBehavior::with_parameterAdds a❰parameter❱: valueassertion to the envelope.ExpressionBehavior::with_optional_parameterOptionally adds a❰parameter❱: valueassertion to the envelope.Request::newCreates an envelope with anARIDsubject and abody: «function»assertion.Response::new_successCreates an envelope with anARIDsubject and aresult: valueassertion.Response::new_successCreates an envelope with anARIDsubject and aresult: valueassertion for each provided result.Response::new_failureCreates an envelope with anARIDsubject and aerror: valueassertion.Response::new_early_failureCreates an envelope with anunknownsubject and aerror: valueassertion.
§Decoding Parameters and Results
ExpressionBehavior::extract_object_for_parameterReturns the argument for the given parameter, decoded as the given type.ExpressionBehavior::extract_objects_for_parameterReturns an array of arguments for the given parameter, decoded as the given type.ResponseBehavior::resultReturns the object of theresultpredicate.ResponseBehavior::resultReturns the objects of everyresultpredicate.ResponseBehavior::extract_resultReturns the object of theresultpredicate, decoded as the given type.ResponseBehavior::extract_resultReturns the objects of everyresultpredicate, decoded as the given type.ResponseBehavior::extract_resultReturns whether theresultpredicate has theKnownValue.ok.ResponseBehavior::extract_errorReturns the error value, decoded as the given type.
Re-exports§
pub use base::Assertion;pub use base::Envelope;pub use base::EnvelopeCase;pub use base::EnvelopeEncodable;pub use base::Error;pub use base::Result;pub use base::elide;pub use base::elide::ObscureAction;pub use base::walk;pub use base::walk::EdgeType;pub use format::DigestDisplayFormat;pub use format::EnvelopeSummary;pub use format::FormatContext;pub use format::FormatContextOpt;pub use format::GLOBAL_FORMAT_CONTEXT;pub use format::MermaidFormatOpts;pub use format::MermaidOrientation;pub use format::MermaidTheme;pub use format::TreeFormatOpts;pub use extension::SignatureMetadata;pub use extension::attachment::Attachable;pub use extension::attachment::Attachments;pub use extension::expressions::Event;pub use extension::expressions::EventBehavior;pub use extension::expressions::Expression;pub use extension::expressions::ExpressionBehavior;pub use extension::expressions::Function;pub use extension::expressions::IntoExpression;pub use extension::expressions::Parameter;pub use extension::expressions::Request;pub use extension::expressions::RequestBehavior;pub use extension::expressions::Response;pub use extension::expressions::ResponseBehavior;pub use extension::expressions::functions;pub use extension::expressions::parameters;pub use known_values;
Modules§
Macros§
- function_
constant - A macro that declares a function at compile time.
- impl_
attachable - A macro for easily implementing the
Attachabletrait for types with anattachmentsfield. - impl_
envelope_ decodable - parameter_
constant - A macro that declares a parameter at compile time.
- with_
format_ context - A macro to access the global format context for read-only operations.
- with_
format_ context_ mut - A macro to access the global format context for read-write operations.
Structs§
- Known
Value - A value in a namespace of unsigned integers that represents a stand-alone ontological concept.
- Known
Values Store - A store that maps between Known Values and their assigned names.
- Private
KeyBase - A secure foundation for deriving multiple cryptographic keys.
- Public
Keys - A container for an entity’s public cryptographic keys.
Enums§
- Encapsulation
Private Key - A private key used for key encapsulation mechanisms (KEM).
- Signing
Options - Options for configuring signature creation.
Statics§
- KNOWN_
VALUES - The global registry of Known Values.