validateBasic<P> function

RejectReason? validateBasic<P>(
  1. TrustTaskDocument<P> doc,
  2. DateTime now,
  3. String myVid
)

SPEC §7.2 items 4 and 5a — expiry and wrong-recipient.

⚠ This is not the full §7.2 check. Items 1–3 (framework schema, payload schema, unknown type) belong to the caller's parse and dispatch; items 5b, 7 and 8 need the specification's policy and live in enforceSpecPolicy. consumeInbound bundles 4–8.

Returns null when the document passes.

Implementation

RejectReason? validateBasic<P>(
  TrustTaskDocument<P> doc,
  DateTime now,
  String myVid,
) {
  final expiresAtRaw = doc.expiresAt;
  if (expiresAtRaw != null) {
    final expiresAt = DateTime.tryParse(expiresAtRaw);
    if (expiresAt == null) {
      return const RejectReason(
        code: StandardCode.malformedRequest,
        message: 'expiresAt is not a valid RFC 3339 timestamp',
      );
    }
    // §4.2 / §7.2 item 4: inclusive bound — `now >= expiresAt` is expired.
    if (!expiresAt.isAfter(now)) {
      return RejectReason(
        code: StandardCode.expired,
        message: 'document expired at $expiresAtRaw',
      );
    }
  }

  final recipient = doc.recipient;
  if (recipient != null && recipient != myVid) {
    return const RejectReason(
      code: StandardCode.wrongRecipient,
      message: 'in-band recipient does not identify this consumer',
    );
  }

  return null;
}