generateQrCode method
Implementation
Future<QRCode?> generateQrCode() async {
final data = Uint8Buffer();
// why 11? https://github.com/matrix-org/matrix-js-sdk/commit/275ea6aacbfc6623e7559a7649ca5cab207903d9
randomSharedSecretForQRCode =
encodeBase64Unpadded(uc.secureRandomBytes(11));
final mode = getOurQRMode();
data.addAll(ascii.encode(prefix));
data.add(version);
data.add(mode.code);
final encodedTxnId = utf8.encode(transactionId!);
final txnIdLen = encodedTxnId.length;
final tmpBuf = Uint8List(2);
ByteData.view(tmpBuf.buffer).setUint16(0, txnIdLen);
data.addAll(tmpBuf);
data.addAll(encodedTxnId);
final keys = await getKeys(mode);
if (keys != null) {
data.addAll(base64decodeUnpadded(keys.$1));
data.addAll(base64decodeUnpadded(keys.$2));
} else {
return null;
}
data.addAll(base64decodeUnpadded(randomSharedSecretForQRCode!));
return QRCode(randomSharedSecretForQRCode!, data);
}