decryptSuccessActionAesPayload function

dynamic decryptSuccessActionAesPayload(
  1. {LNURLPaySuccessAction successAction,
  2. String preimage}
)

Given a success action, will return the decrypted AES payload. The preimage is the key to decrypt the data.

Implementation

decryptSuccessActionAesPayload({
  LNURLPaySuccessAction successAction,
  String preimage,
}) {
  if (successAction.tag != 'aes') {
    return '';
  }

  final key = Key.fromBase16(preimage);
  final iv = IV.fromBase16(successAction.iv);
  final encrypter = Encrypter(
    AES(
      key,
      mode: AESMode.cbc,
    ),
  );

  final plainText = encrypter.decrypt(
    Encrypted.fromBase16(successAction.cipherText),
    iv: iv,
  );

  return plainText;
}