mirror of
				https://github.com/hackku21/loc-chain-app.git
				synced 2025-06-13 12:54:05 +00:00 
			
		
		
		
	Merge branch 'feature/firebase-connection' of github.com:hackku21/loc-chain-app into main
This commit is contained in:
		
						commit
						ad62f5f1b0
					
				| @ -3,6 +3,8 @@ import 'package:path_provider/path_provider.dart'; | |||||||
| import 'dart:io'; | import 'dart:io'; | ||||||
| 
 | 
 | ||||||
| class KeyFileManager { | class KeyFileManager { | ||||||
|  |   static KeyPair keyPair = KeyPair(); | ||||||
|  | 
 | ||||||
|   static Future<String> get _localPath async { |   static Future<String> get _localPath async { | ||||||
|     final directory = await getApplicationDocumentsDirectory(); |     final directory = await getApplicationDocumentsDirectory(); | ||||||
|     return directory.path; |     return directory.path; | ||||||
| @ -19,6 +21,9 @@ class KeyFileManager { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   static Future<KeyPair> readKeyPair() async { |   static Future<KeyPair> readKeyPair() async { | ||||||
|  |     if (keyPair.hasPublicKey() && keyPair.hasPrivateKey()) { | ||||||
|  |       return keyPair; | ||||||
|  |     } | ||||||
|     try { |     try { | ||||||
|       String privKey = await _privKeyFile.then( |       String privKey = await _privKeyFile.then( | ||||||
|         (file) => file.readAsString(), |         (file) => file.readAsString(), | ||||||
| @ -26,11 +31,11 @@ class KeyFileManager { | |||||||
|       String pubKey = await _pubKeyFile.then( |       String pubKey = await _pubKeyFile.then( | ||||||
|         (file) => file.readAsString(), |         (file) => file.readAsString(), | ||||||
|       ); |       ); | ||||||
| 
 |       keyPair = KeyPair( | ||||||
|       return KeyPair( |  | ||||||
|         privateKey: privKey, |         privateKey: privKey, | ||||||
|         publicKey: pubKey, |         publicKey: pubKey, | ||||||
|       ); |       ); | ||||||
|  |       return keyPair; | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       print(e); |       print(e); | ||||||
|       return KeyPair(); |       return KeyPair(); | ||||||
| @ -38,9 +43,10 @@ class KeyFileManager { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   static Future<void> writeKeyPair(KeyPair pair) async { |   static Future<void> writeKeyPair(KeyPair pair) async { | ||||||
|  |     keyPair = pair; | ||||||
|     final File privKeyFile = await _privKeyFile; |     final File privKeyFile = await _privKeyFile; | ||||||
|     final File pubKeyFile = await _pubKeyFile; |     final File pubKeyFile = await _pubKeyFile; | ||||||
|     pubKeyFile.writeAsString(pair.publicKey); |     pubKeyFile.writeAsString(keyPair.publicKey); | ||||||
|     privKeyFile.writeAsString(pair.privateKey); |     privKeyFile.writeAsString(keyPair.privateKey); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -3,15 +3,25 @@ import 'package:shared_preferences/shared_preferences.dart'; | |||||||
| import 'package:sqflite/sqflite.dart'; | import 'package:sqflite/sqflite.dart'; | ||||||
| import 'package:fast_rsa/rsa.dart'; | import 'package:fast_rsa/rsa.dart'; | ||||||
| 
 | 
 | ||||||
|  | import 'package:loc_chain_app/util/keyfile_manager.dart'; | ||||||
|  | 
 | ||||||
| import 'dart:io'; | import 'dart:io'; | ||||||
| 
 | 
 | ||||||
| class Transaction { | class Transaction { | ||||||
|   Transaction({required this.otherUserID}) { |   Transaction({required this.hash}) { | ||||||
|     SharedPreferences.getInstance().then((s) => _id = s.getString('id') ?? '0'); |     SharedPreferences.getInstance().then((s) => _id = s.getString('id') ?? '0'); | ||||||
|   } |   } | ||||||
|   late final String _id; |   late final String _id; | ||||||
|   final String otherUserID; |   final String hash; | ||||||
|   static Hash? makeTransactionHash() {} |   static Future<String> makeTransactionHash(String otherUserId) async { | ||||||
|  |     String id = await SharedPreferences.getInstance() | ||||||
|  |         .then((s) => s.getString('id') ?? ''); | ||||||
|  |     bool idLess = id.compareTo(otherUserId) < 0; | ||||||
|  |     var lesser = idLess ? id : otherUserId; | ||||||
|  |     var greater = idLess ? otherUserId : id; | ||||||
|  |     return RSA.signPKCS1v15("$lesser-$greater", Hash.HASH_SHA256, | ||||||
|  |         KeyFileManager.keyPair.privateKey); | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class TransactionsDBManager { | class TransactionsDBManager { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user