Skip to main content

ContractEnvelope

Struct ContractEnvelope 

Source
pub struct ContractEnvelope { /* private fields */ }
Expand description

A strict semantic Contract plus namespaced, non-semantic ecosystem metadata.

§Extensions are outside the canonical identities

The extension map is side-band data by design: contract_id and interface_id are computed over the Contract alone, so adding, removing, or editing an extension never moves a semantic identity (tests/artifact_identity.rs pins this, and docs/architecture.md’s identity table records it). Only the artifact identity over the envelope bytes (ArtifactKind::ContractEnvelopeJsonV1) covers extensions, because they are in those bytes.

Extension names are validated fail-closed: a reverse-domain namespace (dot-separated segments of lowercase letters, digits, and hyphens) followed by /v<integer> with no leading zero, e.g. org.candid-core.field-names/v1. Values are arbitrary JSON, bounded in aggregate by Limits::max_value_bytes.

§The org.candid-core.field-names/v1 extension (issue #152)

The one extension this repository itself emits, via candid-core compile <path> --envelope: the field-name table as an array of [container, id, name] triples — named labels only, sorted, deduplicated — exactly the table TsNames::from_source_info builds from the provenance sidecar and the TypeScript runtime’s schemaFromContract consumes (hash-enforced, so a lying table fails closed there). The semantic Contract stores only authoritative label ids; this extension lets one self-describing document carry the names too, without touching the canonical format or its identities.

Implementations§

Source§

impl ContractEnvelope

Source

pub fn new(contract: Contract) -> Self

Source

pub fn contract(&self) -> &Contract

Source

pub fn extensions(&self) -> &BTreeMap<String, Value>

Source

pub fn insert_extension( &mut self, name: impl Into<String>, value: Value, limits: &Limits, ) -> Result<(), ContractValidationError>

Source

pub fn insert_extension_with_context( &mut self, name: impl Into<String>, value: Value, context: &RuntimeContext, ) -> Result<(), ContractValidationError>

Source

pub fn validate(&self, limits: &Limits) -> Result<(), ContractValidationError>

Source

pub fn validate_with_context( &self, context: &RuntimeContext, ) -> Result<(), ContractValidationError>

Source

pub fn from_json_with_limits( input: &str, limits: &Limits, ) -> Result<Self, ContractJsonError>

Parse, validate, and canonicalize an envelope JSON document under caller-supplied limits.

Source

pub fn from_json_with_context( input: &str, context: &RuntimeContext, ) -> Result<Self, ContractJsonError>

Bounded parse: max_input_bytes is enforced before decoding, and the nested Contract and the extension map are validated on one budget.

Source

pub fn from_slice_with_limits( input: &[u8], limits: &Limits, ) -> Result<Self, ContractJsonError>

Bounded parse from bytes.

Source

pub fn from_slice_with_context( input: &[u8], context: &RuntimeContext, ) -> Result<Self, ContractJsonError>

Source

pub fn to_json_pretty_with_limits( &self, limits: &Limits, ) -> Result<String, ContractValidationError>

Serialize the envelope under caller-supplied limits.

Source

pub fn to_json_pretty_with_context( &self, context: &RuntimeContext, ) -> Result<String, ContractValidationError>

Like Contract::to_json_pretty_with_context, this revalidates and charges the rendered length against max_canonicalization_work.

Trait Implementations§

Source§

impl Clone for ContractEnvelope

Source§

fn clone(&self) -> ContractEnvelope

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContractEnvelope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ContractEnvelope

Source§

impl PartialEq for ContractEnvelope

Source§

fn eq(&self, other: &ContractEnvelope) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ContractEnvelope

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ContractEnvelope

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.