NormalizeEnvelope trims identifier fields, validates the envelope, and returns a safe cloned copy for downstream use.
(env Envelope, opts ValidateOptions)
| 82 | // NormalizeEnvelope trims identifier fields, validates the envelope, and |
| 83 | // returns a safe cloned copy for downstream use. |
| 84 | func NormalizeEnvelope(env Envelope, opts ValidateOptions) (Envelope, error) { |
| 85 | opts = opts.withDefaults() |
| 86 | |
| 87 | normalized := normalizeEnvelopeCopy(env) |
| 88 | if err := validateEnvelopeHeader(normalized); err != nil { |
| 89 | return Envelope{}, err |
| 90 | } |
| 91 | if err := validateEnvelopeParticipants(normalized); err != nil { |
| 92 | return Envelope{}, err |
| 93 | } |
| 94 | if err := validateEnvelopeReferences(normalized); err != nil { |
| 95 | return Envelope{}, err |
| 96 | } |
| 97 | if err := validateEnvelopeBodyAndFreshness(normalized, opts); err != nil { |
| 98 | return Envelope{}, err |
| 99 | } |
| 100 | return normalized, nil |
| 101 | } |
| 102 | |
| 103 | // ValidateEnvelope validates one envelope without returning a normalized copy. |
| 104 | func ValidateEnvelope(env Envelope, opts ValidateOptions) error { |