encryptMessage function
Future<DidcommEncryptedMessage>
encryptMessage({
- required String connectionDid,
- required WalletStore wallet,
- required DidcommPlaintextMessage message,
- required String receiverDid,
will encrypt the message
using the resolved connectionDid
(must be available in the wallet
).
Implementation
Future<DidcommEncryptedMessage> encryptMessage(
{required String connectionDid,
required WalletStore wallet,
required DidcommPlaintextMessage message,
required String receiverDid}) async {
// as per new change of the key type to ed25519
// we will use getPrivateKeyForConnectionDidAsJwk to encrypt the message
// var myPrivateKey =
// await wallet.getPrivateKeyForConnectionDidAsJwk(connectionDid);
var myPrivateKey = await wallet.getKeyAgreementKeyForDidAsJwk(connectionDid);
// @TODO what is that for? Replace me with some useful information
var ddo = await resolveDidDocument(receiverDid);
var keyIds = ddo.resolveKeyIds();
var recipientDDO = keyIds.convertAllKeysToJwk();
// var recipientDDO = (await resolveDidDocument(receiverDid))
// .resolveKeyIds()
// .convertAllKeysToJwk();
var encrypted = DidcommEncryptedMessage.fromPlaintext(
senderPrivateKeyJwk: myPrivateKey!,
recipientPublicKeyJwk: [
(recipientDDO.keyAgreement!.first as VerificationMethod).publicKeyJwk!
],
plaintext: message);
return encrypted;
}