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'; | ||||
| 
 | ||||
| class KeyFileManager { | ||||
|   static KeyPair keyPair = KeyPair(); | ||||
| 
 | ||||
|   static Future<String> get _localPath async { | ||||
|     final directory = await getApplicationDocumentsDirectory(); | ||||
|     return directory.path; | ||||
| @ -19,6 +21,9 @@ class KeyFileManager { | ||||
|   } | ||||
| 
 | ||||
|   static Future<KeyPair> readKeyPair() async { | ||||
|     if (keyPair.hasPublicKey() && keyPair.hasPrivateKey()) { | ||||
|       return keyPair; | ||||
|     } | ||||
|     try { | ||||
|       String privKey = await _privKeyFile.then( | ||||
|         (file) => file.readAsString(), | ||||
| @ -26,11 +31,11 @@ class KeyFileManager { | ||||
|       String pubKey = await _pubKeyFile.then( | ||||
|         (file) => file.readAsString(), | ||||
|       ); | ||||
| 
 | ||||
|       return KeyPair( | ||||
|       keyPair = KeyPair( | ||||
|         privateKey: privKey, | ||||
|         publicKey: pubKey, | ||||
|       ); | ||||
|       return keyPair; | ||||
|     } catch (e) { | ||||
|       print(e); | ||||
|       return KeyPair(); | ||||
| @ -38,9 +43,10 @@ class KeyFileManager { | ||||
|   } | ||||
| 
 | ||||
|   static Future<void> writeKeyPair(KeyPair pair) async { | ||||
|     keyPair = pair; | ||||
|     final File privKeyFile = await _privKeyFile; | ||||
|     final File pubKeyFile = await _pubKeyFile; | ||||
|     pubKeyFile.writeAsString(pair.publicKey); | ||||
|     privKeyFile.writeAsString(pair.privateKey); | ||||
|     pubKeyFile.writeAsString(keyPair.publicKey); | ||||
|     privKeyFile.writeAsString(keyPair.privateKey); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -3,15 +3,25 @@ import 'package:shared_preferences/shared_preferences.dart'; | ||||
| import 'package:sqflite/sqflite.dart'; | ||||
| import 'package:fast_rsa/rsa.dart'; | ||||
| 
 | ||||
| import 'package:loc_chain_app/util/keyfile_manager.dart'; | ||||
| 
 | ||||
| import 'dart:io'; | ||||
| 
 | ||||
| class Transaction { | ||||
|   Transaction({required this.otherUserID}) { | ||||
|   Transaction({required this.hash}) { | ||||
|     SharedPreferences.getInstance().then((s) => _id = s.getString('id') ?? '0'); | ||||
|   } | ||||
|   late final String _id; | ||||
|   final String otherUserID; | ||||
|   static Hash? makeTransactionHash() {} | ||||
|   final String hash; | ||||
|   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 { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user