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
//! # uftp
//!
//! UFTP 3.1, the USEF Flex Trading Protocol, in Rust. Distribution system operators (DSO),
//! aggregators (AGR) and the Common Reference Operator (CRO) use it to trade grid
//! flexibility. Since version 3 it is maintained by LF Energy as *Shapeshifter*. Not the
//! UDP multicast file-transfer tool of the same name.
//!
//! The crate covers the 26 messages, their XML, their CS1 (Ed25519) signatures, the ISP
//! arithmetic, and the rules a receiver applies. It is *sans I/O*: it reads no clock,
//! random source, file or network. Ids, timestamps, keys and the key lookup come from you.
//!
//! The [documentation site](https://hupe1980.github.io/uftp/) explains the protocol and each
//! part of the crate, and defines the specification notes (`SS-…`) cited in these docs.
//!
//! ```
//! use uftp::jiff::{SignedDuration, Timestamp};
//! use uftp::*;
//!
//! let dso_key = SigningKey::from_seed(&[1; 32]);
//! let directory = Directory::new()
//!     .with(Participant::new("dso.example".parse()?, Role::Dso, dso_key.public_keys([0; 32])));
//! let id = |n: u8| MessageUuid::from_bytes([n; 16]);
//! let now: Timestamp = "2026-11-30T12:00:00Z".parse()?;
//!
//! // A DSO asks for 500 kW less consumption from 17:00 to 19:00 local time (ISPs 69–76).
//! // A conversation starts with its first message; ISPs are PT15M unless set otherwise.
//! let meta = Metadata::new("dso.example".parse()?, "agr.example".parse()?, now, id(1));
//! let header = FlexHeader::new(
//!     meta,
//!     "Europe/Amsterdam".parse()?,
//!     "2026-12-01".parse()?,
//!     "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.clone().into(), Role::Dso, &dso_key)?.to_xml();
//!
//! // The aggregator receives it: every check, in the order the protocol needs.
//! let mut endpoint = Endpoint::new(
//!     OpenOptions::for_recipient("agr.example".parse()?),
//!     SignedDuration::from_mins(15),
//! );
//! let opened = endpoint.receive(document.as_bytes(), now, directory.lookup())?;
//! let received: FlexRequest = opened.into_message().try_into()?;
//! assert_eq!(received, request);
//!
//! // It answers in the same conversation.
//! let response = received.reply(Reply::accepted(id(2), now));
//! assert_eq!(response.header().meta().conversation_id, id(1));
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Receiving
//!
//! [`Endpoint::receive`] runs, in this order:
//! 1. [`open`]: a strict signature check over exactly the received bytes, then the schema,
//!    the sender binding, the sender's role, the type's rules and the recipient;
//! 2. the [`Market`]'s ISP duration and time zone, if set;
//! 3. [`Message::check_time`];
//! 4. the [`Outbox`], if set: a response must answer a request this endpoint
//!    [sent](Endpoint::sent);
//! 5. the [`ReplayGuard`], last, so it remembers only messages it accepted.
//!
//! Each step is public on its own. With the `http` feature, `Endpoint::receive_request`
//! checks the headers before the body, and `uftp::http::response` writes the answer.
//!
//! ## Two ways to say no
//!
//! UFTP 3.1 (Appendix 4 §4) answers a refusal in one of two ways, and a [`Rejection`] knows
//! which:
//!
//! | When | [`Rejection::http_status`] | Then |
//! |---|---|---|
//! | not UFTP XML, too large, a bad header | 400 (411 without a length) | nothing else |
//! | the signature does not verify | 401 | nothing else |
//! | the sender's key cannot be looked up | 419, retry | nothing else |
//! | the sender is over its quota | 429, [`Rejection::retry_after`] | nothing else |
//! | valid, verified, but it breaks a rule | 200 | seal and send [`Rejection::response`] |
//!
//! The Rejected response goes to the sender whose signature verified, never to a domain the
//! message merely names. Its [`RejectionReason`] is one of the specification's 38;
//! [`RejectionReason::source`] cites where each is defined. Reasons that depend on your
//! state, such as a revoked offer, are yours to raise with [`Rejection::because`].
//!
//! A refusal's text is one line you can log and send back: received values are escaped
//! and cut after 64 characters or 128 escaped bytes, and no refusal is longer than 512
//! bytes.
//!
//! ## Sending
//!
//! [`seal`] refuses a message that breaks a rule, so what you send is valid. Build
//! messages with the constructors ([`FlexHeader::new`], [`FlexRequest::new`]) and the flow
//! helpers ([`FlexRequest::offer`], [`FlexOffer::order`]). [`transport`] has the content
//! type, the paths and [`transport::Delivery`] for the status you get back.
//!
//! ## Settling
//!
//! Each month the DSO settles its orders. [`FlexOrder::settlement`] turns an order into
//! an item, and [`FlexSettlement::new`] wraps the items. The aggregator calls
//! [`FlexSettlement::check_against`] with the orders it accepted. It gets back one
//! Accepted or Disputed status per item, or *Missing Settlement Items* if an order of the
//! period is not settled `[UFTP §3.10.1]`. The figures the DSO computes (delivered power,
//! deficiency, penalty) are transported, not computed; [`SettlementIsp`] says how their
//! signs are read.
//!
//! ## Power
//!
//! Every power is an `i64` in watts, positive for consumption `[UFTP §4.2.1]`: a request
//! for 500 kW less is `-500_000`. The XSD's `xs:integer` is unbounded; a power outside the
//! `i64` range is refused when parsed, never clamped.
//!
//! ## Keys
//!
//! [`Directory`] holds participants for configured deployments, with two keys during a
//! rollover. [`dns`] builds the record names of Appendix 4 and parses their keys. Query them
//! with a DNSSEC-validating resolver of your choice.

#![forbid(unsafe_code)]
// docs.rs labels feature-gated items (`http`) on its nightly toolchain.
#![cfg_attr(docsrs, feature(doc_cfg))]

mod cs1;
mod directory;
mod endpoint;
mod envelope;
mod error;
mod flow;
#[cfg(feature = "http")]
pub mod http;
mod isp;
pub mod msg;
mod outbox;
mod reason;
mod replay;
mod settle;
pub mod transport;
mod types;
mod xml;

pub use cs1::{PublicKeys, SigningKey, VerifyingKey};
pub use directory::{Directory, IntoKeys, KeyLookupError, MAX_KEYS, Participant, dns};
pub use endpoint::Endpoint;
pub use envelope::{OpenOptions, Opened, SignedMessage, open, seal};
pub use error::{Disposition, RejectKind, Rejection};
pub use flow::Market;
pub use isp::{DayGrid, IspSpan};
pub use msg::agr_cro::*;
pub use msg::agr_dso::*;
pub use msg::common::*;
pub use msg::cro_dso::*;
pub use msg::metering::*;
pub use msg::{
    DecodeOptions, FlexHeader, Message, Metadata, Reply, ResponseHeader, UnexpectedMessage,
};
pub use outbox::Outbox;
pub use reason::RejectionReason;
pub use replay::ReplayGuard;
pub use types::{
    AcceptedDisputed, AcceptedRejected, ActivationFactor, Amount, AvailableRequested, Currency,
    Ean, EntityAddress, InternetDomain, IspDuration, MessageUuid, MeteringProfileType,
    MeteringUnit, RedispatchBy, Role, SpecVersion, TimeZoneName,
};
pub use xml::Limits;

/// The `jiff` crate, whose `Timestamp` and `civil::Date` appear in this crate's API.
pub use jiff;

/// The `rust_decimal` crate, whose `Decimal` appears in amounts and metering values.
pub use rust_decimal;