resolveParties<P> function

PartyResolution resolveParties<P>(
  1. TransportHandler handler,
  2. TrustTaskDocument<P> doc
)

Apply §4.8.1 precedence to produce the final ResolvedParties.

Reports a ConsistencyError when an in-band member is present and disagrees with the transport-derived value for the same party. Callers translate that into an identityMismatch error response (§8.3) — or let consumeInbound do it.

Implementation

PartyResolution resolveParties<P>(
  TransportHandler handler,
  TrustTaskDocument<P> doc,
) {
  final ctx = handler.deriveParties();

  final pairs = <(String, String?, String?)>[
    ('issuer', doc.issuer, ctx.issuer),
    ('recipient', doc.recipient, ctx.recipient),
  ];
  for (final (party, inBand, transport) in pairs) {
    if (inBand != null && transport != null && inBand != transport) {
      return PartyResolution.mismatch(
        ConsistencyError(party: party, inBand: inBand, transport: transport),
      );
    }
  }

  return PartyResolution.resolved(
    ResolvedParties(
      issuer: doc.issuer ?? ctx.issuer,
      recipient: doc.recipient ?? ctx.recipient,
    ),
  );
}