| | | 1 | | using System.Globalization; |
| | | 2 | | using AsiBackbone.Core.Audit; |
| | | 3 | | using AsiBackbone.Core.CapabilityGrants; |
| | | 4 | | using AsiBackbone.Core.Emissions; |
| | | 5 | | using AsiBackbone.Core.Outbox; |
| | | 6 | | using AsiBackbone.Core.Serialization; |
| | | 7 | | |
| | | 8 | | namespace AsiBackbone.Core.Signing; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Builds deterministic, provider-neutral signing payloads for AsiBackbone governance artifacts. |
| | | 12 | | /// </summary> |
| | | 13 | | public static class CanonicalPayloadBuilder |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Builds a canonical payload for decision receipt. |
| | | 17 | | /// </summary> |
| | | 18 | | public static CanonicalPayload ForDecisionReceipt(IDecisionReceipt receipt, CanonicalPayloadOptions? options = null) |
| | | 19 | | { |
| | 55 | 20 | | ArgumentNullException.ThrowIfNull(receipt); |
| | 55 | 21 | | CanonicalPayloadOptions effectiveOptions = options ?? CanonicalPayloadOptions.Default; |
| | 55 | 22 | | string decisionReceiptId = GetDecisionReceiptId(receipt); |
| | | 23 | | |
| | 55 | 24 | | return CanonicalPayload.Create( |
| | 55 | 25 | | CanonicalArtifactTypes.DecisionReceipt, |
| | 55 | 26 | | decisionReceiptId, |
| | 55 | 27 | | receipt.SchemaVersion, |
| | 55 | 28 | | effectiveOptions.CanonicalizationVersion, |
| | 55 | 29 | | effectiveOptions.HashAlgorithm, |
| | 55 | 30 | | BuildDecisionReceiptContent(receipt, effectiveOptions, decisionReceiptId)); |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Builds a canonical payload for a persistence-ready audit ledger record. |
| | | 35 | | /// </summary> |
| | | 36 | | public static CanonicalPayload ForAuditLedgerRecord(AuditLedgerRecord record, CanonicalPayloadOptions? options = nul |
| | | 37 | | { |
| | 26 | 38 | | ArgumentNullException.ThrowIfNull(record); |
| | 26 | 39 | | CanonicalPayloadOptions effectiveOptions = options ?? CanonicalPayloadOptions.Default; |
| | | 40 | | |
| | 26 | 41 | | SortedDictionary<string, object?> content = BuildDecisionReceiptContent(record, effectiveOptions, record.Decisio |
| | 26 | 42 | | content["acknowledgmentId"] = record.AcknowledgmentId; |
| | 26 | 43 | | content["capabilityGrantId"] = record.CapabilityTokenId; |
| | 26 | 44 | | content["handshakeId"] = record.HandshakeId; |
| | 26 | 45 | | content["previousRecordHash"] = record.PreviousRecordHash; |
| | 26 | 46 | | content["recordedUtc"] = FormatUtc(record.RecordedUtc); |
| | 26 | 47 | | content["recordId"] = record.RecordId; |
| | | 48 | | |
| | 26 | 49 | | return CanonicalPayload.Create( |
| | 26 | 50 | | CanonicalArtifactTypes.AuditLedgerRecord, |
| | 26 | 51 | | record.RecordId, |
| | 26 | 52 | | record.SchemaVersion, |
| | 26 | 53 | | effectiveOptions.CanonicalizationVersion, |
| | 26 | 54 | | effectiveOptions.HashAlgorithm, |
| | 26 | 55 | | content); |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Builds a canonical payload for an decision receipt lifecycle event. |
| | | 60 | | /// </summary> |
| | | 61 | | public static CanonicalPayload ForDecisionReceiptLifecycleEvent(DecisionReceiptLifecycleEvent lifecycleEvent, Canoni |
| | | 62 | | { |
| | 22 | 63 | | ArgumentNullException.ThrowIfNull(lifecycleEvent); |
| | 22 | 64 | | CanonicalPayloadOptions effectiveOptions = options ?? CanonicalPayloadOptions.Default; |
| | | 65 | | |
| | 22 | 66 | | SortedDictionary<string, object?> content = new(StringComparer.Ordinal) |
| | 22 | 67 | | { |
| | 22 | 68 | | ["auditResidueId"] = lifecycleEvent.DecisionReceiptId, |
| | 22 | 69 | | ["correlationId"] = lifecycleEvent.CorrelationId, |
| | 22 | 70 | | ["eventId"] = lifecycleEvent.EventId, |
| | 22 | 71 | | ["metadata"] = FilterMetadata(lifecycleEvent.Metadata, effectiveOptions), |
| | 22 | 72 | | ["occurredUtc"] = FormatUtc(lifecycleEvent.OccurredUtc), |
| | 22 | 73 | | ["operationName"] = lifecycleEvent.OperationName, |
| | 22 | 74 | | ["outcome"] = lifecycleEvent.Outcome, |
| | 22 | 75 | | ["stage"] = CanonicalEnumWireNames.ForLifecycleStage(lifecycleEvent.Stage), |
| | 22 | 76 | | ["stageSequence"] = lifecycleEvent.StageSequence, |
| | 22 | 77 | | ["traceId"] = lifecycleEvent.TraceId |
| | 22 | 78 | | }; |
| | | 79 | | |
| | 22 | 80 | | return CanonicalPayload.Create( |
| | 22 | 81 | | CanonicalArtifactTypes.DecisionReceiptLifecycleEvent, |
| | 22 | 82 | | lifecycleEvent.EventId, |
| | 22 | 83 | | GovernanceSchemaVersions.StableArtifactsV1, |
| | 22 | 84 | | effectiveOptions.CanonicalizationVersion, |
| | 22 | 85 | | effectiveOptions.HashAlgorithm, |
| | 22 | 86 | | content); |
| | | 87 | | } |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// Builds a canonical payload for a governance emission envelope. |
| | | 91 | | /// </summary> |
| | | 92 | | public static CanonicalPayload ForGovernanceEmissionEnvelope(GovernanceEmissionEnvelope envelope, CanonicalPayloadOp |
| | | 93 | | { |
| | 44 | 94 | | ArgumentNullException.ThrowIfNull(envelope); |
| | 44 | 95 | | CanonicalPayloadOptions effectiveOptions = options ?? CanonicalPayloadOptions.Default; |
| | | 96 | | |
| | 44 | 97 | | return CanonicalPayload.Create( |
| | 44 | 98 | | CanonicalArtifactTypes.GovernanceEmissionEnvelope, |
| | 44 | 99 | | envelope.EnvelopeId, |
| | 44 | 100 | | envelope.SchemaVersion, |
| | 44 | 101 | | effectiveOptions.CanonicalizationVersion, |
| | 44 | 102 | | effectiveOptions.HashAlgorithm, |
| | 44 | 103 | | BuildGovernanceEmissionEnvelopeContent(envelope, effectiveOptions)); |
| | | 104 | | } |
| | | 105 | | |
| | | 106 | | /// <summary> |
| | | 107 | | /// Builds a canonical payload for a durable outbox entry. |
| | | 108 | | /// </summary> |
| | | 109 | | public static CanonicalPayload ForGovernanceOutboxEntry(GovernanceOutboxEntry entry, CanonicalPayloadOptions? option |
| | | 110 | | { |
| | 16 | 111 | | ArgumentNullException.ThrowIfNull(entry); |
| | 16 | 112 | | CanonicalPayloadOptions effectiveOptions = options ?? CanonicalPayloadOptions.Default; |
| | | 113 | | |
| | 16 | 114 | | SortedDictionary<string, object?> content = new(StringComparer.Ordinal) |
| | 16 | 115 | | { |
| | 16 | 116 | | ["createdUtc"] = FormatUtc(entry.CreatedUtc), |
| | 16 | 117 | | ["deadLetterReason"] = entry.DeadLetterReason, |
| | 16 | 118 | | ["envelope"] = BuildGovernanceEmissionEnvelopeContent(entry.Envelope, effectiveOptions), |
| | 16 | 119 | | ["lastError"] = BuildGovernanceEmissionErrorContent(entry.LastError), |
| | 16 | 120 | | ["maxRetryCount"] = entry.MaxRetryCount, |
| | 16 | 121 | | ["metadata"] = FilterMetadata(entry.Metadata, effectiveOptions), |
| | 16 | 122 | | ["nextRetryUtc"] = FormatUtc(entry.NextRetryUtc), |
| | 16 | 123 | | ["outboxEntryId"] = entry.OutboxEntryId, |
| | 16 | 124 | | ["providerName"] = entry.ProviderName, |
| | 16 | 125 | | ["providerRecordId"] = entry.ProviderRecordId, |
| | 16 | 126 | | ["retryCount"] = entry.RetryCount, |
| | 16 | 127 | | ["status"] = CanonicalEnumWireNames.ForEmissionStatus(entry.Status), |
| | 16 | 128 | | ["updatedUtc"] = FormatUtc(entry.UpdatedUtc) |
| | 16 | 129 | | }; |
| | | 130 | | |
| | 16 | 131 | | return CanonicalPayload.Create( |
| | 16 | 132 | | CanonicalArtifactTypes.GovernanceOutboxEntry, |
| | 16 | 133 | | entry.OutboxEntryId, |
| | 16 | 134 | | entry.Envelope.SchemaVersion, |
| | 16 | 135 | | effectiveOptions.CanonicalizationVersion, |
| | 16 | 136 | | effectiveOptions.HashAlgorithm, |
| | 16 | 137 | | content); |
| | | 138 | | } |
| | | 139 | | |
| | | 140 | | /// <summary> |
| | | 141 | | /// Builds a canonical payload for a capability grant grant. |
| | | 142 | | /// </summary> |
| | | 143 | | /// <remarks> |
| | | 144 | | /// <para> |
| | | 145 | | /// Every field the grant carries is included, so the resulting hash binds the whole grant rather than a subset of |
| | | 146 | | /// it. A payload that omits a field leaves that field outside the proof while |
| | | 147 | | /// <see cref="CapabilityGrantValidator" /> still enforces it, which lets a modified value pass |
| | | 148 | | /// validation against a signature computed before the change. Scopes are normalized to a sorted, de-duplicated, |
| | | 149 | | /// ordinal set, so two grants that differ only in scope ordering produce the same hash. |
| | | 150 | | /// </para> |
| | | 151 | | /// <para> |
| | | 152 | | /// Metadata is the one exception, and deliberately so: it is filtered through |
| | | 153 | | /// <see cref="CanonicalPayloadOptions.AllowsMetadataKey" />, whose allow-list is empty by default. With default |
| | | 154 | | /// options no grant metadata reaches the proof at all, which keeps unbounded and potentially sensitive host data |
| | | 155 | | /// out of hashed payloads. A host that puts security-relevant data in grant metadata has no binding for it until |
| | | 156 | | /// that key is added to the allow-list. |
| | | 157 | | /// </para> |
| | | 158 | | /// </remarks> |
| | | 159 | | /// <param name="grant">The capability grant grant to canonicalize.</param> |
| | | 160 | | /// <param name="options">Canonicalization options, including the metadata allow-list.</param> |
| | | 161 | | /// <returns>A deterministic canonical payload for the grant.</returns> |
| | | 162 | | public static CanonicalPayload ForCapabilityGrant(CapabilityGrant grant, CanonicalPayloadOptions? options = null) |
| | | 163 | | { |
| | 148 | 164 | | ArgumentNullException.ThrowIfNull(grant); |
| | 147 | 165 | | CanonicalPayloadOptions effectiveOptions = options ?? CanonicalPayloadOptions.Default; |
| | | 166 | | |
| | 147 | 167 | | SortedDictionary<string, object?> content = new(StringComparer.Ordinal) |
| | 147 | 168 | | { |
| | 147 | 169 | | ["acknowledgmentId"] = grant.AcknowledgmentId, |
| | 147 | 170 | | ["audience"] = grant.Audience, |
| | 147 | 171 | | ["expiresUtc"] = FormatUtc(grant.ExpiresUtc), |
| | 147 | 172 | | ["gatewayBinding"] = grant.GatewayBinding, |
| | 147 | 173 | | ["handshakeId"] = grant.HandshakeId, |
| | 147 | 174 | | ["issuedUtc"] = FormatUtc(grant.IssuedUtc), |
| | 147 | 175 | | ["issuer"] = grant.Issuer, |
| | 147 | 176 | | ["metadata"] = FilterMetadata(grant.Metadata, effectiveOptions), |
| | 147 | 177 | | ["notBeforeUtc"] = FormatUtc(grant.NotBeforeUtc), |
| | 147 | 178 | | ["operationName"] = grant.OperationName, |
| | 147 | 179 | | ["policyHash"] = grant.PolicyHash, |
| | 147 | 180 | | ["policyVersion"] = grant.PolicyVersion, |
| | 147 | 181 | | ["resourceBinding"] = grant.ResourceBinding, |
| | 147 | 182 | | ["scopes"] = NormalizeStringSet(grant.Scopes), |
| | 147 | 183 | | ["subjectId"] = grant.SubjectId, |
| | 147 | 184 | | ["tokenId"] = grant.TokenId |
| | 147 | 185 | | }; |
| | | 186 | | |
| | | 187 | | // A use limit supplied only at the validation call site is unsigned local policy that the issuer never |
| | | 188 | | // authorized. Binding it requires the grant to record the schema version that carries it, so grants signed unde |
| | | 189 | | // the earlier version continue to hash exactly as they did and keep verifying. |
| | 147 | 190 | | if (!string.Equals(grant.SchemaVersion, GovernanceSchemaVersions.StableArtifactsV1, StringComparison.Ordinal)) |
| | | 191 | | { |
| | 4 | 192 | | content["maxUseCount"] = grant.MaxUseCount; |
| | | 193 | | } |
| | | 194 | | |
| | 147 | 195 | | return CanonicalPayload.Create( |
| | 147 | 196 | | CanonicalArtifactTypes.CapabilityGrant, |
| | 147 | 197 | | grant.TokenId, |
| | 147 | 198 | | grant.SchemaVersion, |
| | 147 | 199 | | effectiveOptions.CanonicalizationVersion, |
| | 147 | 200 | | effectiveOptions.HashAlgorithm, |
| | 147 | 201 | | content); |
| | | 202 | | } |
| | | 203 | | |
| | | 204 | | private static SortedDictionary<string, object?> BuildDecisionReceiptContent( |
| | | 205 | | IDecisionReceipt receipt, |
| | | 206 | | CanonicalPayloadOptions options, |
| | | 207 | | string decisionReceiptId) |
| | | 208 | | { |
| | 81 | 209 | | return new SortedDictionary<string, object?>(StringComparer.Ordinal) |
| | 81 | 210 | | { |
| | 81 | 211 | | ["actorDisplayName"] = receipt.ActorDisplayName, |
| | 81 | 212 | | ["actorId"] = receipt.ActorId, |
| | 81 | 213 | | ["actorType"] = CanonicalEnumWireNames.ForActorType(receipt.ActorType), |
| | 81 | 214 | | ["auditResidueId"] = decisionReceiptId, |
| | 81 | 215 | | ["constraintCount"] = receipt.ConstraintCount, |
| | 81 | 216 | | ["constraintSetHash"] = receipt.ConstraintSetHash, |
| | 81 | 217 | | ["correlationId"] = receipt.CorrelationId, |
| | 81 | 218 | | ["decisionLatencyMs"] = receipt.DecisionLatencyMs, |
| | 81 | 219 | | ["decisionStage"] = receipt.DecisionStage, |
| | 81 | 220 | | ["emitterProvider"] = receipt.EmitterProvider, |
| | 81 | 221 | | ["emitterStatus"] = receipt.EmitterStatus, |
| | 81 | 222 | | ["eventId"] = receipt.EventId, |
| | 81 | 223 | | ["gatewayExecutionId"] = receipt.GatewayExecutionId, |
| | 81 | 224 | | ["metadata"] = FilterMetadata(receipt.Metadata, options), |
| | 81 | 225 | | ["occurredUtc"] = FormatUtc(receipt.OccurredUtc), |
| | 81 | 226 | | ["operationName"] = receipt.OperationName, |
| | 81 | 227 | | ["organizationHash"] = receipt.OrganizationHash, |
| | 81 | 228 | | ["outboxSequence"] = receipt.OutboxSequence, |
| | 81 | 229 | | ["outcome"] = receipt.Outcome, |
| | 81 | 230 | | ["parentSpanId"] = receipt.ParentSpanId, |
| | 81 | 231 | | ["policyHash"] = receipt.PolicyHash, |
| | 81 | 232 | | ["policyScope"] = receipt.PolicyScope, |
| | 81 | 233 | | ["policyVersion"] = receipt.PolicyVersion, |
| | 81 | 234 | | ["reasonCodes"] = NormalizeStringSet(receipt.ReasonCodes), |
| | 81 | 235 | | ["riskScore"] = receipt.RiskScore, |
| | 81 | 236 | | ["schemaVersion"] = receipt.SchemaVersion, |
| | 81 | 237 | | ["spanId"] = receipt.SpanId, |
| | 81 | 238 | | ["tenantHash"] = receipt.TenantHash, |
| | 81 | 239 | | ["traceId"] = receipt.TraceId |
| | 81 | 240 | | }; |
| | | 241 | | } |
| | | 242 | | |
| | | 243 | | private static SortedDictionary<string, object?> BuildGovernanceEmissionEnvelopeContent(GovernanceEmissionEnvelope e |
| | | 244 | | { |
| | 60 | 245 | | return new SortedDictionary<string, object?>(StringComparer.Ordinal) |
| | 60 | 246 | | { |
| | 60 | 247 | | ["actorId"] = envelope.ActorId, |
| | 60 | 248 | | ["auditResidueId"] = envelope.DecisionReceiptId, |
| | 60 | 249 | | ["correlationId"] = envelope.CorrelationId, |
| | 60 | 250 | | ["createdUtc"] = FormatUtc(envelope.CreatedUtc), |
| | 60 | 251 | | ["decisionStage"] = envelope.DecisionStage, |
| | 60 | 252 | | ["emitterProvider"] = envelope.EmitterProvider, |
| | 60 | 253 | | ["emitterStatus"] = envelope.EmitterStatus, |
| | 60 | 254 | | ["envelopeId"] = envelope.EnvelopeId, |
| | 60 | 255 | | ["eventId"] = envelope.EventId, |
| | 60 | 256 | | ["eventType"] = CanonicalEnumWireNames.ForEmissionEventType(envelope.EventType), |
| | 60 | 257 | | ["gatewayExecutionId"] = envelope.GatewayExecutionId, |
| | 60 | 258 | | ["lifecycleStage"] = envelope.LifecycleStage.HasValue |
| | 60 | 259 | | ? CanonicalEnumWireNames.ForLifecycleStage(envelope.LifecycleStage.Value) |
| | 60 | 260 | | : null, |
| | 60 | 261 | | ["lifecycleStageSequence"] = envelope.LifecycleStageSequence, |
| | 60 | 262 | | ["metadata"] = FilterMetadata(envelope.Metadata, options), |
| | 60 | 263 | | ["occurredUtc"] = FormatUtc(envelope.OccurredUtc), |
| | 60 | 264 | | ["operationName"] = envelope.OperationName, |
| | 60 | 265 | | ["outboxSequence"] = envelope.OutboxSequence, |
| | 60 | 266 | | ["outcome"] = envelope.Outcome, |
| | 60 | 267 | | ["parentSpanId"] = envelope.ParentSpanId, |
| | 60 | 268 | | ["payload"] = BuildGovernanceEmissionPayloadContent(envelope.Payload, options), |
| | 60 | 269 | | ["policyHash"] = envelope.PolicyHash, |
| | 60 | 270 | | ["policyVersion"] = envelope.PolicyVersion, |
| | 60 | 271 | | ["schemaVersion"] = envelope.SchemaVersion, |
| | 60 | 272 | | ["spanId"] = envelope.SpanId, |
| | 60 | 273 | | ["traceId"] = envelope.TraceId |
| | 60 | 274 | | }; |
| | | 275 | | } |
| | | 276 | | |
| | | 277 | | private static SortedDictionary<string, object?>? BuildGovernanceEmissionPayloadContent(GovernanceEmissionPayload? p |
| | | 278 | | { |
| | 60 | 279 | | return payload is null |
| | 60 | 280 | | ? null |
| | 60 | 281 | | : new SortedDictionary<string, object?>(StringComparer.Ordinal) |
| | 60 | 282 | | { |
| | 60 | 283 | | ["contentHash"] = payload.ContentHash, |
| | 60 | 284 | | ["contentType"] = payload.ContentType, |
| | 60 | 285 | | ["metadata"] = FilterMetadata(payload.Metadata, options), |
| | 60 | 286 | | ["payloadType"] = payload.PayloadType, |
| | 60 | 287 | | ["schemaVersion"] = payload.SchemaVersion, |
| | 60 | 288 | | ["sizeBytes"] = payload.SizeBytes |
| | 60 | 289 | | }; |
| | | 290 | | } |
| | | 291 | | |
| | | 292 | | private static SortedDictionary<string, object?>? BuildGovernanceEmissionErrorContent(GovernanceEmissionError? error |
| | | 293 | | { |
| | 16 | 294 | | return error is null |
| | 16 | 295 | | ? null |
| | 16 | 296 | | : new SortedDictionary<string, object?>(StringComparer.Ordinal) |
| | 16 | 297 | | { |
| | 16 | 298 | | ["code"] = error.Code, |
| | 16 | 299 | | ["isRetryable"] = error.IsRetryable, |
| | 16 | 300 | | ["message"] = error.Message, |
| | 16 | 301 | | ["providerErrorCode"] = error.ProviderErrorCode, |
| | 16 | 302 | | ["providerName"] = error.ProviderName |
| | 16 | 303 | | }; |
| | | 304 | | } |
| | | 305 | | |
| | | 306 | | // Shared by every canonical payload builder in this assembly so all artifacts apply the metadata filtering and |
| | | 307 | | // normalization rules published for asibackbone.canonical-json.v1. |
| | | 308 | | internal static SortedDictionary<string, object?> FilterMetadata(IReadOnlyDictionary<string, string>? metadata, Cano |
| | | 309 | | { |
| | 351 | 310 | | SortedDictionary<string, object?> filteredMetadata = new(StringComparer.Ordinal); |
| | | 311 | | |
| | 351 | 312 | | if (metadata is null || metadata.Count == 0) |
| | | 313 | | { |
| | 296 | 314 | | return filteredMetadata; |
| | | 315 | | } |
| | | 316 | | |
| | 301 | 317 | | foreach (KeyValuePair<string, string> item in metadata) |
| | | 318 | | { |
| | 96 | 319 | | if (!options.AllowsMetadataKey(item.Key)) |
| | | 320 | | { |
| | | 321 | | continue; |
| | | 322 | | } |
| | | 323 | | |
| | 54 | 324 | | string normalizedKey = item.Key.Trim(); |
| | | 325 | | |
| | | 326 | | // Trimming keys before hashing makes "k" and " k" the same key. Overwriting silently made the hashed payloa |
| | | 327 | | // depend on enumeration order, so the same logical metadata could hash two ways and one key's value could |
| | | 328 | | // displace another's inside the signed payload. |
| | 54 | 329 | | if (filteredMetadata.ContainsKey(normalizedKey)) |
| | | 330 | | { |
| | 1 | 331 | | throw new ArgumentException( |
| | 1 | 332 | | $"Canonical payload metadata contains keys that collide after trimming: '{normalizedKey}'. Normalize |
| | 1 | 333 | | nameof(metadata)); |
| | | 334 | | } |
| | | 335 | | |
| | 53 | 336 | | filteredMetadata[normalizedKey] = item.Value?.Trim() ?? string.Empty; |
| | | 337 | | } |
| | | 338 | | |
| | 54 | 339 | | return filteredMetadata; |
| | | 340 | | } |
| | | 341 | | |
| | | 342 | | private static string[] NormalizeStringSet(IEnumerable<string> values) |
| | | 343 | | { |
| | 227 | 344 | | return [.. values |
| | 227 | 345 | | .Where(value => !string.IsNullOrWhiteSpace(value)) |
| | 227 | 346 | | .Select(value => value.Trim()) |
| | 227 | 347 | | .Distinct(StringComparer.Ordinal) |
| | 227 | 348 | | .OrderBy(value => value, StringComparer.Ordinal)]; |
| | | 349 | | } |
| | | 350 | | |
| | | 351 | | private static string? FormatUtc(DateTimeOffset? timestamp) |
| | | 352 | | { |
| | 163 | 353 | | return timestamp.HasValue ? FormatUtc(timestamp.Value) : null; |
| | | 354 | | } |
| | | 355 | | |
| | | 356 | | private static string FormatUtc(DateTimeOffset timestamp) |
| | | 357 | | { |
| | 582 | 358 | | return timestamp.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'", CultureInfo.InvariantCulture); |
| | | 359 | | } |
| | | 360 | | |
| | | 361 | | private static string GetDecisionReceiptId(IDecisionReceipt receipt) |
| | | 362 | | { |
| | 55 | 363 | | return string.IsNullOrWhiteSpace(receipt.DecisionReceiptId) |
| | 55 | 364 | | ? receipt.EventId |
| | 55 | 365 | | : receipt.DecisionReceiptId; |
| | | 366 | | } |
| | | 367 | | } |