envelope.rs

Overview

This file defines the Envelope structure and the BLSSignedEnvelope trait to represent and manage data envelopes that are cryptographically signed using BLS (Boneh–Lynn–Shacham) signature schemes. These envelopes encapsulate arbitrary data (TData) alongside aggregated BLS signatures and track which signers have contributed to the signature aggregation. The file enables creation, signature aggregation, signature verification, and serialization/deserialization of such envelopes, facilitating secure multi-signer cryptographic data handling.

Traits and Structs

BLSSignedEnvelope Trait

The BLSSignedEnvelope trait defines the required interface for any envelope type that supports BLS signatures. It is generic over associated types for the BLS signature scheme, the envelope's data, and the signer index.

Associated Types

Required Methods


Envelope<BLS, TData> Struct

A concrete implementation of the BLSSignedEnvelope trait that holds an aggregated BLS signature, a map of signature occurrences keyed by signer indices, and the data payload.

Type Parameters

Fields

Trait Implementations

Method Details

create

Creates a new envelope instance.

let envelope = Envelope::<MyBLS, MyData>::create(
    initial_aggregated_signature,
    initial_signature_occurrences,
    my_data,
);
add_signature

Adds a new signature from a signer, updating the aggregated signature and signature occurrences map.

envelope.add_signature(&signer_index, &signer_secret)?;
verify_signatures

Verifies the aggregated signature against provided public keys of signers.

let is_valid = envelope.verify_signatures(&signers_pubkey_map)?;
clone_signature_occurrences

Returns a cloned map of signers and their signature counts.

has_signer_index

Checks if a signer index has signed the envelope.

if envelope.has_signer_index(signer_index) {
    // signer has signed
}
signatures_count

Returns the number of unique signers.

signers

Returns an iterator over the signer indices who have signed.

aggregated_signature and data

Accessors for the aggregated signature and envelope data.


EnvelopeSerDe<TSignature, TData> Struct

A helper structure used internally for serialization and deserialization of the Envelope. It stores the aggregated signature, a sorted vector of signature occurrences (to ensure consistent serialization order), and the data.


Implementation Details and Algorithms


Interaction With Other Parts of the System


Visual Diagram

classDiagram
class BLSSignedEnvelope {
<<trait>>
+create()
+add_signature()
+clone_signature_occurrences()
+verify_signatures()
+aggregated_signature()
+data()
+has_signer_index()
+signatures_count()
+signers()
}
class Envelope {
-aggregated_signature
-signature_occurrences
-data
+create()
+add_signature()
+clone_signature_occurrences()
+verify_signatures()
+aggregated_signature()
+data()
+has_signer_index()
+signatures_count()
+signers()
+serialize()
+deserialize()
+fmt()
+debug_fmt()
}
BLSSignedEnvelope <|.. Envelope