Path: redb-route/redb.Route.As4/Signals/Receipts.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.As4/Signals/Receipts.cs ---- using System.Xml; using redb.Route.As4.Messaging; using redb.Route.As4.Security; namespace redb.Route.As4.Signals; /// /// AS4 non-repudiation receipts (AS4 profile §3.4, eDelivery AS4 1.16: NonRepudiation = true): the /// content of eb:Receipt is one ebbp:NonRepudiationInformation holding a copy of every /// ds:Reference of the signature of the received message. Built by the receiver; checked by the sender /// against the references it signed, which proves the receiver got exactly those bytes. /// internal static class Receipts { /// The eb:Receipt content for a message whose signature had . public static IReadOnlyList NonRepudiation(IReadOnlyList receivedReferences) { ArgumentNullException.ThrowIfNull(receivedReferences); if (receivedReferences.Count == 0) throw new ArgumentException("A non-repudiation receipt needs the references of a signed message.", nameof(receivedReferences)); var doc = new XmlDocument { PreserveWhitespace = true, XmlResolver = null }; var information = doc.CreateElement("ebbp", "NonRepudiationInformation", EbmsNamespaces.Ebbp); information.SetAttribute("xmlns:ebbp", EbmsNamespaces.Ebbp); doc.AppendChild(information); foreach (var reference in receivedReferences) { var part = doc.CreateElement("ebbp", "MessagePartNRInformation", EbmsNamespaces.Ebbp); part.AppendChild(doc.ImportNode(reference, deep: true)); information.AppendChild(part); } ExclusiveCanonicalizer.DeclareNamespaces(information); return [information]; } /// /// Whether the receipt's non-repudiation information names exactly the references we signed — same URIs, /// same digest values, none missing, none extra. A receipt without it does not prove receipt. /// public static bool ProvesReceiptOf(SignalMessage receipt, IReadOnlyList sentReferences) { ArgumentNullException.ThrowIfNull(receipt); ArgumentNullException.ThrowIfNull(sentReferences); if (receipt.ReceiptContent is null) return false; var echoed = receipt.ReceiptContent .Where(e => e.LocalName == "NonRepudiationInformation" && e.NamespaceURI == EbmsNamespaces.Ebbp) .SelectMany(e => e.ChildNodes.OfType()) .Where(e => e.LocalName == "MessagePartNRInformation" && e.NamespaceURI == EbmsNamespaces.Ebbp) .SelectMany(e => e.ChildNodes.OfType()) .Where(e => e.LocalName == "Reference" && e.NamespaceURI == WsSecurityNames.Ds) .Select(Key) .ToList(); var sent = sentReferences.Select(Key).ToList(); return echoed.Count == sent.Count && new HashSet(echoed, StringComparer.Ordinal).SetEquals(sent); } private static string Key(XmlElement reference) { var digest = reference.ChildNodes.OfType() .FirstOrDefault(e => e.LocalName == "DigestValue" && e.NamespaceURI == WsSecurityNames.Ds)?.InnerText.Trim() ?? ""; return reference.GetAttribute("URI") + "\n" + digest; } }