handle method
Actual handling method. variables can be expected to be non-null as configured
Implementation
@override
Future<IssueCredential?> handle(DidcommMessage message) async {
message as DidcommPlaintextMessage;
var request = RequestCredential.fromJson(message.toJson());
var credential = request.detail!.first.credential;
if (!credential.context.contains('https://schema.org')) {
credential.context.add('https://schema.org');
}
// sign the requested credential
// (normally we had to check before that,
// that the data in it is the same we offered)
// Hint: the REST API does some very basic check for that (see handler there)
late String signed;
try {
signed = await signCredential(wallet!, credential,
challenge: request.detail!.first.options.challenge);
} on Exception catch (e) {
throw DidcommServiceException(
"Could not sign the credential "
"due to `${e.toString()}`",
baseException: e,
code: 3459340);
}
// issue the credential
var issue = IssueCredential(
threadId: message.threadId ?? message.id,
from: getConversationDid(message, wallet!),
to: [message.from!],
replyTo: replyTo,
pleaseAck: true,
credentials: [VerifiableCredential.fromJson(signed)]);
// patch ack as per didcomm spec (make sure the message contains
// itself to be acked)
issue.pleaseAck ??= [];
if (!(issue.pleaseAck!.contains('') ||
issue.pleaseAck!.contains(issue.id))) {
issue.pleaseAck!.add(issue.id);
}
return issue;
}