decrypt method
Decrypt the payload with the given key. This also verifies the hmac.
Implementation
@override
Future<Uint8List> decrypt({
required EncryptedPayload payload,
required Uint8List key,
}) async {
// Verify hmac
final verified = await verifyHmac(payload: payload, key: key);
if (!verified) {
throw WalletConnectException('Invalid HMAC');
}
final cipherText = hex.decode(payload.data);
final nonce = hex.decode(payload.iv);
// Decrypt the payload
final algorithm = AesCbc.with256bits(macAlgorithm: MacAlgorithm.empty);
final box = SecretBox(cipherText, nonce: nonce, mac: Mac.empty);
final secretKey = SecretKey(List<int>.unmodifiable(key));
final data = await algorithm.decrypt(box, secretKey: secretKey);
return Uint8List.fromList(data);
}