openSecretKey method
Opens the secret key for a message event. This is typically done by decrypting the shared secret key for this device, or if this device was not originally included in the list of recipients for the message, than through a message grant this device has received. If neither are possible, it returns null.
Implementation
Future<SecretKey?> openSecretKey(MessageEventModel event) async {
final encryptedSecretKey = event.body.keys[Signing.instance.publicKey];
if (encryptedSecretKey != null) {
return SecretKey(
await _encryption.decryptSharedSecret(
base64Decode(encryptedSecretKey),
event.body.encryptionKey,
),
);
}
final grant = await _db.messageGrants.id(event.hash).get();
if (grant != null) {
return SecretKey(
await _encryption.decryptSharedSecret(
base64Decode(grant.encryptedSecretKey),
grant.issuerEncryptionKey,
),
);
}
return null;
}