decrypt method
Decrypt this encrypted message using keys from wallet
.
Implementation
Future<DidcommMessage> decrypt(WalletStore wallet) async {
_decodeProtected();
if (protectedHeaderAlg!.startsWith('ECDH-1PU')) {
if (protectedHeaderSkid == null) {
throw Exception('sender id needed when using AuthCrypt');
}
var senderDDO =
(await resolveDidDocument(protectedHeaderSkid!.split('#').first))
.resolveKeyIds()
.convertAllKeysToJwk();
for (var key in senderDDO.keyAgreement!) {
if (key is VerificationMethod) {
if (key.publicKeyJwk!['kid'] == protectedHeaderSkid) {
return decryptWithJwk(
await _searchPrivateKey(wallet), key.publicKeyJwk);
}
}
}
throw Exception('No key found in did document');
} else if (protectedHeaderAlg!.startsWith('ECDH-ES')) {
return decryptWithJwk(await _searchPrivateKey(wallet));
} else {
throw Exception('Unknown algorithm');
}
}