fixes combine list array

This commit is contained in:
otsmr 2025-07-18 21:59:11 +02:00
parent e19fb13ba7
commit ad8dea4fbf
4 changed files with 46 additions and 3 deletions

View file

@ -36,7 +36,7 @@ jobs:
echo "storePassword=${{ secrets.STORE_PASSWORD }}" >> ./android/key.properties echo "storePassword=${{ secrets.STORE_PASSWORD }}" >> ./android/key.properties
echo "keyPassword=${{ secrets.STORE_PASSWORD }}" >> ./android/key.properties echo "keyPassword=${{ secrets.STORE_PASSWORD }}" >> ./android/key.properties
echo "keyAlias=androidreleasekey" >> key.properties echo "keyAlias=androidreleasekey" >> key.properties
echo "storeFile=./android/app/keystore.jks" >> ./android/key.properties echo "storeFile=./keystore.jks" >> ./android/key.properties
- name: Create keystore file - name: Create keystore file
env: env:

View file

@ -824,7 +824,9 @@ Future<String> getMediaBaseFilePath(String type) async {
/// combines two utf8 list /// combines two utf8 list
Uint8List combineUint8Lists(Uint8List list1, Uint8List list2) { Uint8List combineUint8Lists(Uint8List list1, Uint8List list2) {
final combinedLength = 4 + list1.length + list2.length; final combinedLength = 4 + list1.length + list2.length;
final combinedList = Uint8List(combinedLength) final combinedList = Uint8List(combinedLength);
ByteData.sublistView(combinedList).setInt32(0, list1.length);
combinedList
..setRange(4, 4 + list1.length, list1) ..setRange(4, 4 + list1.length, list1)
..setRange(4 + list1.length, combinedLength, list2); ..setRange(4 + list1.length, combinedLength, list2);
return combinedList; return combinedList;

19
lib/src/utils/pow.dart Normal file
View file

@ -0,0 +1,19 @@
import 'package:cryptography_plus/cryptography_plus.dart';
import 'package:drift/drift.dart';
bool isValid(int difficulty, List<int> digest) {
final bits = digest.map((i) => i.toRadixString(2).padLeft(8, '0')).join();
return bits.startsWith('0' * difficulty);
}
Future<int> calculatePoW(Uint8List prefix, int difficulty) async {
var i = 0;
while (true) {
i++;
final s = '$prefix$i';
final digest = (await Sha256().hash(s.codeUnits)).bytes;
if (isValid(difficulty, digest)) {
return i;
}
}
}

View file

@ -1,13 +1,35 @@
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:twonly/src/services/api/media_upload.dart';
import 'package:twonly/src/utils/pow.dart';
import 'package:twonly/src/views/components/animate_icon.dart'; import 'package:twonly/src/views/components/animate_icon.dart';
void main() { void main() {
group('isEmoji', () { group('testing utils', () {
test('test isEmoji function', () { test('test isEmoji function', () {
expect(isEmoji('Hallo'), false); expect(isEmoji('Hallo'), false);
expect(isEmoji('😂'), true); expect(isEmoji('😂'), true);
expect(isEmoji('😂😂'), false); expect(isEmoji('😂😂'), false);
expect(isEmoji('Hallo 😂'), false); expect(isEmoji('Hallo 😂'), false);
}); });
test('test proof-of-work simple', () async {
expect(await calculatePoW(Uint8List.fromList([41, 41, 41, 41]), 6), 33);
});
test('test utils', () async {
final list1 = Uint8List.fromList([41, 41, 41, 41, 41, 41, 41]);
final list2 = Uint8List.fromList([42, 42, 42]);
final combined = combineUint8Lists(list1, list2);
final lists = extractUint8Lists(combined);
expect(list1, lists[0]);
expect(list2, lists[1]);
});
test('encode hex', () async {
final list1 = Uint8List.fromList([41, 41, 41, 41, 41, 41, 41]);
expect(list1, hexToUint8List(uint8ListToHex(list1)));
});
}); });
} }