loc-chain-app/loc_chain_app/lib/util/transaction_manager.dart

40 lines
1.2 KiB
Dart
Raw Normal View History

2021-04-10 19:55:41 +00:00
import 'package:fast_rsa/model/bridge.pb.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sqflite/sqflite.dart';
import 'package:fast_rsa/rsa.dart';
2021-04-10 21:01:21 +00:00
import 'package:dbcrypt/dbcrypt.dart';
2021-04-10 19:55:41 +00:00
2021-04-10 20:26:51 +00:00
import 'package:loc_chain_app/util/keyfile_manager.dart';
2021-04-10 19:55:41 +00:00
import 'dart:io';
class Transaction {
2021-04-10 22:06:05 +00:00
Transaction({required this.hash, required this.pubKey});
2021-04-10 20:26:51 +00:00
final String hash;
2021-04-10 22:06:05 +00:00
final String pubKey;
2021-04-10 21:01:21 +00:00
static Future<String> generateHash(String otherUserId) async {
2021-04-10 20:26:51 +00:00
String id = await SharedPreferences.getInstance()
2021-04-10 20:36:05 +00:00
.then((s) => s.getString('userName') ?? '');
2021-04-10 20:26:51 +00:00
bool idLess = id.compareTo(otherUserId) < 0;
var lesser = idLess ? id : otherUserId;
var greater = idLess ? otherUserId : id;
2021-04-10 22:44:39 +00:00
// return DBCrypt()
// .hashpw("$lesser-$greater", KeyFileManager.keyPair.privateKey);
return "$lesser-$greater";
2021-04-10 20:26:51 +00:00
}
2021-04-10 22:06:05 +00:00
Future<String> generateP2PPayload(String otherUserId) async =>
"${await generateHash(otherUserId)}:${KeyFileManager.keyPair.publicKey}";
2021-04-10 19:55:41 +00:00
}
class TransactionsDBManager {
static Future<Database> get _localFile async {
return openDatabase('transactions.db');
}
static Future<List<Transaction>?> readTransactions() async {}
static Future<void> writeKeyPair(KeyPair pair) async {}
}