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: UuidUnique receipt identifier (UUIDv7, time-sortable).
input_hash: StringSHA-256 of the JCS (RFC 8785) canonical JSON of the calculator inputs.
output_hash: StringSHA-256 of the JCS (RFC 8785) canonical JSON of the numeric output values.
Empty string until populated via with_output_hash.
ruleset_id: StringMachine-readable identifier of the ruleset used.
ruleset_version: StringVersion 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: StringIdentifier of the factor dataset (empty if no factor provider was used).
factor_dataset_version: StringVersion 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: NaiveDateThe 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
impl CalculationReceipt
Sourcepub fn new(
input_hash: impl Into<String>,
ruleset_id: impl Into<String>,
ruleset_version: impl Into<String>,
clock: AssessmentClock,
) -> Self
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.
Sourcepub fn for_ruleset<T: Serialize>(
inputs: &T,
ruleset: &dyn Ruleset,
clock: AssessmentClock,
output_hash: impl Into<String>,
) -> Result<Self, CalcError>
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.
Sourcepub fn with_output_hash(self, hash: impl Into<String>) -> Self
pub fn with_output_hash(self, hash: impl Into<String>) -> Self
Bind the numeric output values to this receipt.
Sourcepub fn with_bundle_version(self, bundle_version: impl Into<String>) -> Self
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.
Sourcepub fn with_factor_provider(self, provider: &dyn FactorProvider) -> Self
pub fn with_factor_provider(self, provider: &dyn FactorProvider) -> Self
Attach factor-provider provenance to this receipt.
Sourcepub fn seal_with_jws(self, jws: String) -> Self
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.
Sourcepub fn canonical_bytes_for_signing(&self) -> Result<Vec<u8>, CalcError>
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
impl Clone for CalculationReceipt
Source§fn clone(&self) -> CalculationReceipt
fn clone(&self) -> CalculationReceipt
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more