decrypt method
Future<DidcommMessage>
decrypt(
- WalletStore wallet, {
- Future<
DidDocument> didResolver() = resolveDidDocument,
Decrypt this encrypted message using keys from wallet
.
Implementation
Future<DidcommMessage> decrypt(WalletStore wallet,
{Future<DidDocument> Function(String) didResolver =
resolveDidDocument}) async {
_decodeProtected();
if (protectedHeaderAlg!.startsWith('ECDH-1PU')) {
if (protectedHeaderSkid == null) {
throw Exception('sender id needed when using AuthCrypt');
}
var senderDDO = (await didResolver(protectedHeaderSkid!.split('#').first))
.resolveKeyIds()
.convertAllKeysToJwk();
for (var key in senderDDO.keyAgreement!) {
if (key is VerificationMethod) {
if (key.publicKeyJwk!['kid'] == protectedHeaderSkid ||
key.id == 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');
}
}