handle method
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 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 "
"`${supportedAttachmentTypes.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) {
return await _handleOfferCredentialAttachment(attachment);
} else if (attachment.type == DidcommMessages.requestPresentation) {
return await _handleRequestPresentationAttachment(attachment);
} else {
throw DidcommServiceException(
"Attachment of type `${attachment.type}` is not supported. "
"Supported types are: "
"`${supportedAttachmentTypes.join(', ')}`",
code: 45983490);
}
}