handle method

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

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

Implementation

@override
Future<Presentation> handle(DidcommMessage message) async {
  var requestPresentation = RequestPresentation.fromJson(message.toJson());

  var res = await searchForMatchingCredentials(
    message: requestPresentation,
    wallet: wallet!,
  );

  var allCredentialFlattened = res.fold(
      <VerifiableCredential>[],
      (List<VerifiableCredential> l, FilterResult e) =>
          l..addAll(e.credentials));

  List<FilterResult> finalSend = [];
  for (var result in res) {
    if (result.fulfilled) {
      finalSend.add(FilterResult(
          credentials: allCredentialFlattened,
          matchingDescriptorIds: result.matchingDescriptorIds,
          presentationDefinitionId: result.presentationDefinitionId,
          submissionRequirement: result.submissionRequirement));
    } else {
      throw Exception('Cant\'t fulfill presentation definition');
    }
  }

  var vp = await buildPresentation(finalSend, wallet!,
      requestPresentation.presentationDefinition.first.challenge);

  var presentationMessage = Presentation(
      to: [requestPresentation.from!],
      replyTo: replyTo,
      verifiablePresentation: [VerifiablePresentation.fromJson(vp)],
      threadId: requestPresentation.threadId ?? requestPresentation.id);

  return presentationMessage;
}