Skip to main content

CalculationReceipt

Struct CalculationReceipt 

Source
pub struct CalculationReceipt {
    pub receipt_id: Uuid,
    pub input_hash: String,
    pub output_hash: String,
    pub ruleset_id: String,
    pub ruleset_version: String,
    pub bundle_version: Option<String>,
    pub factor_dataset_id: String,
    pub factor_dataset_version: String,
    pub factor_set_hash: Option<String>,
    pub assessed_as_of: NaiveDate,
    pub computed_at: DateTime<Utc>,
    pub jws: Option<String>,
}
Expand description

Proof-of-calculation envelope emitted by every calculator function.

Carries enough information to reproduce or audit the result: both inputs and numeric outputs are JCS-hashed (RFC 8785) so an auditor can verify the same inputs produce the same outputs, and the exact ruleset + factor dataset versions are recorded. The receipt may be signed by the vault via seal_with_jws after calling canonical_bytes_for_signing.

Intended to be stored alongside the computed value in the proof-bound store.

Fields§

§receipt_id: Uuid

Unique receipt identifier (UUIDv7, time-sortable).

§input_hash: String

SHA-256 of the JCS (RFC 8785) canonical JSON of the calculator inputs.

§output_hash: String

SHA-256 of the JCS (RFC 8785) canonical JSON of the numeric output values. Empty string until populated via with_output_hash.

§ruleset_id: String

Machine-readable identifier of the ruleset used.

§ruleset_version: String

Version of the ruleset (semver-shaped string).

§bundle_version: Option<String>

Version of the signed Compliance-Current bundle that delivered this ruleset. None when the ruleset came from the built-in baseline (no signed bundle involved).

§factor_dataset_id: String

Identifier of the factor dataset (empty if no factor provider was used).

§factor_dataset_version: String

Version of the factor dataset (empty if no factor provider was used).

§factor_set_hash: Option<String>

SHA-256 of the full factor table at calculation time. None when the calculation did not use a FactorProvider.

§assessed_as_of: NaiveDate

The date whose law this calculation was performed against — the product’s regulated triggering event, not the day it was computed.

Without this an auditor can see which ruleset was cited but not whether it was the right one to cite, because ruleset selection is a function of this date. It is the difference between a receipt that can be re-verified and one that can only be re-read.

§computed_at: DateTime<Utc>

UTC timestamp when the calculation ran.

§jws: Option<String>

JWS signature produced by the vault/engine after calculation. None until the caller calls seal_with_jws.

Implementations§

Source§

impl CalculationReceipt

Source

pub fn new( input_hash: impl Into<String>, ruleset_id: impl Into<String>, ruleset_version: impl Into<String>, clock: AssessmentClock, ) -> Self

Both timestamps come from clock — the receipt never reads the wall clock itself, so replaying a stored calculation reproduces its dates exactly rather than stamping today’s.

Source

pub fn for_ruleset<T: Serialize>( inputs: &T, ruleset: &dyn Ruleset, clock: AssessmentClock, output_hash: impl Into<String>, ) -> Result<Self, CalcError>

Build the receipt for a calculate() call: hashes inputs, cites ruleset’s id/version, and attaches output_hash. The one-liner every calculator’s calculate() should use instead of hand-assembling CalculationReceipt::new(...).with_output_hash(...) — see co2e::calculator::calculate / repairability::calculator::calculate.

Source

pub fn with_output_hash(self, hash: impl Into<String>) -> Self

Bind the numeric output values to this receipt.

Source

pub fn with_bundle_version(self, bundle_version: impl Into<String>) -> Self

Stamp the signed Compliance-Current bundle version that delivered this ruleset. Leave unset (None) for the built-in baseline rulesets.

Source

pub fn with_factor_provider(self, provider: &dyn FactorProvider) -> Self

Attach factor-provider provenance to this receipt.

Source

pub fn seal_with_jws(self, jws: String) -> Self

Attach a JWS signature produced by the external signing infrastructure. Call after canonical_bytes_for_signing to avoid signing the jws field itself.

Source

pub fn canonical_bytes_for_signing(&self) -> Result<Vec<u8>, CalcError>

JCS-canonical bytes of this receipt without the jws field.

Pass these bytes to the vault’s signing infrastructure, then call seal_with_jws with the resulting JWS to produce the final sealed receipt.

Trait Implementations§

Source§

impl Clone for CalculationReceipt

Source§

fn clone(&self) -> CalculationReceipt

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 CalculationReceipt

Source§

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

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

impl<'de> Deserialize<'de> for CalculationReceipt

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CalculationReceipt

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

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.