uftp 0.2.0

UFTP 3.1, the USEF Flex Trading Protocol (LF Energy Shapeshifter), in Rust: all 26 messages, CS1 signing and a receive pipeline for DSOs and aggregators.
Documentation
//! A DSO asks for flexibility, an aggregator verifies and accepts, the DSO reads the answer.
//! Run with `cargo run --example flex_request`.

use uftp::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Keys come from the caller's key store; fixed seeds keep the example short.
    let dso = SigningKey::from_seed(&[1; 32]);
    let agr = SigningKey::from_seed(&[2; 32]);
    let dso_domain: InternetDomain = "dso.example".parse()?;
    let agr_domain: InternetDomain = "agr.example".parse()?;
    // Where receivers find the senders' published keys (DNS in production).
    let (dso_keys, agr_keys) = (dso.public_keys([0; 32]), agr.public_keys([0; 32]));
    let directory = Directory::new()
        .with(Participant::new(dso_domain.clone(), Role::Dso, dso_keys))
        .with(Participant::new(agr_domain.clone(), Role::Agr, agr_keys));
    let id = |n: u8| MessageUuid::from_bytes([n; 16]);
    let now = "2026-11-30T12:00:00Z".parse()?;

    // 1. The DSO needs 500 kW less consumption tomorrow from 17:00 to 19:00 (ISPs 69–76).
    let meta = Metadata::new(dso_domain.clone(), agr_domain.clone(), now, id(1));
    let (zone, day) = ("Europe/Amsterdam".parse()?, "2026-12-01".parse()?);
    let header = FlexHeader::new(meta, zone, day, "ean.871685900012636543".parse()?);
    let isps = vec![FlexRequestIsp::requested(IspSpan::new(69, 8)?, -500_000, 0)];
    let request = FlexRequest::new(header, "2026-11-30T18:00:00Z".parse()?, isps);
    let document = seal(&request.into(), Role::Dso, &dso)?.to_xml();

    // 2. The aggregator opens it: strict signature check, sender binding, schema, rules.
    let at_agr = OpenOptions::for_recipient(agr_domain);
    let opened = open(document.as_bytes(), &at_agr, directory.lookup())?;
    let received: FlexRequest = opened.into_message().try_into()?;
    println!(
        "AGR got a FlexRequest for {}",
        received.header.congestion_point
    );

    // 3. It accepts, in the same conversation, and seals the response with its own key.
    let response = received.reply(Reply::accepted(id(2), now));
    let answer = seal(&response.into(), Role::Agr, &agr)?.to_xml();

    // 4. The DSO opens the answer.
    let at_dso = OpenOptions::for_recipient(dso_domain);
    let reply = open(answer.as_bytes(), &at_dso, directory.lookup())?;
    let r: FlexRequestResponse = reply.into_message().try_into()?;
    println!(
        "DSO got {} for {}",
        r.header().result(),
        r.flex_request_message_id()
    );
    Ok(())
}