using System; using System.Collections.Generic; using System.Linq; namespace StellaOps.Attestor.Envelope; public sealed class DsseEnvelope { public DsseEnvelope( string payloadType, ReadOnlyMemory payload, IEnumerable signatures, string? payloadContentType = null, DsseDetachedPayloadReference? detachedPayload = null) { if (string.IsNullOrWhiteSpace(payloadType)) { throw new ArgumentException("payloadType must be provided.", nameof(payloadType)); } PayloadType = payloadType; Payload = payload; PayloadContentType = payloadContentType; DetachedPayload = detachedPayload; var normalised = signatures?.ToArray() ?? Array.Empty(); if (normalised.Length == 0) { throw new ArgumentException("At least one signature must be supplied.", nameof(signatures)); } // Deterministic ordering (keyid asc, signature asc) for canonical output. Signatures = normalised .OrderBy(static x => x.KeyId ?? string.Empty, StringComparer.Ordinal) .ThenBy(static x => x.Signature, StringComparer.Ordinal) .ToArray(); } public string PayloadType { get; } public ReadOnlyMemory Payload { get; } public string? PayloadContentType { get; } public IReadOnlyList Signatures { get; } public DsseDetachedPayloadReference? DetachedPayload { get; } }