handle method

  1. @override
Future<DidcommMessage?> handle(
  1. DidcommMessage message
)
override

Actual handling method. variables can be expected to be non-null as configured

Implementation

@override
Future<DidcommMessage?>
handle(DidcommMessage message) async {

  var supportedAttachmentTypes =
    [DidcommMessages.offerCredential, DidcommMessages.requestPresentation];

  var supportedAttachmentTypesString = supportedAttachmentTypes
    .map((e) => e.value).toList(growable: false);

  var attachments = await getPlaintextFromOobAttachments(
      OutOfBandMessage.fromJson(message.toJson()),
      expectedAttachments: supportedAttachmentTypes);

  if (attachments.fold(0, (int i, element) => i + (element.isOk ? 1 : 0)) == 0) {
      throw DidcommServiceException(
          "No valid attachment of (any) type "
          "`${supportedAttachmentTypesString.join(', ')}` was found. "
          "Details: ${attachments.map((e) => e.error).join("\n")}",
        code: 73824723);
  }

  // found a valid attachment
  DidcommPlaintextMessage attachment = attachments.firstWhere((
      element) => element.isOk).unrwap();

  if (attachment.type == DidcommMessages.offerCredential.value) {
    return await _handleOfferCredentialAttachment(attachment);
  } else if (attachment.type == DidcommMessages.requestPresentation.value) {
    return await _handleRequestPresentationAttachment(attachment);
  } else {
    throw DidcommServiceException(
        "Attachment of type `${attachment.type}` is not supported. "
        "Supported types are: "
        "`${supportedAttachmentTypesString.join(', ')}`",
        code: 45983490);
  }

}