fix p2p transactions

This commit is contained in:
Zachary Atkins 2021-04-10 17:44:39 -05:00
parent 68f06e5f05
commit dbc0f84d58
2 changed files with 21 additions and 10 deletions

View File

@ -42,13 +42,15 @@ class Connect {
_userName,
strategy,
onConnectionInitiated: onConnectionInit,
onConnectionResult: (String id, Status status) {
onConnectionResult: (String id, Status status) async {
// Called when connection is accepted/rejected
// if connection is accepted send the transaction
endpointMap.forEach((key, value) async {
String str = await Transaction.generateHash(key);
Nearby().sendBytesPayload(key, Uint8List.fromList(str.codeUnits));
});
if (status != Status.CONNECTED) {
return;
}
// Connected to other device, send combined hash and pub key
String str = await Transaction.generateHash(id);
Nearby().sendBytesPayload(id, Uint8List.fromList(str.codeUnits));
},
onDisconnected: (String id) {
// Callled whenever a discoverer disconnects from advertiser
@ -69,8 +71,15 @@ class Connect {
userName,
id,
onConnectionInitiated: onConnectionInit,
onConnectionResult: (id, status) {
showSnackbar(status);
onConnectionResult: (String id, Status status) async {
// Called when connection is accepted/rejected
// if connection is accepted send the transaction
if (status != Status.CONNECTED) {
return;
}
// Connected to other device, send combined hash and pub key
String str = await Transaction.generateHash(id);
Nearby().sendBytesPayload(id, Uint8List.fromList(str.codeUnits));
},
onDisconnected: (id) {
endpointMap.remove(id);
@ -114,8 +123,9 @@ class Connect {
transactionMap[_otherId] =
Transaction(hash: combinedHash, pubKey: publicKey);
// sign combined hash with our private key
showSnackbar('Received $_otherId payload: $combinedHash');
print('Received $_otherId payload: $combinedHash:$publicKey');
// upload hash+otherKey to firebase
transactionMap.remove(_otherId);
},
onPayloadTransferUpdate: (endid, payloadTransferUpdate) {
if (payloadTransferUpdate.status == PayloadStatus.IN_PROGRESS) {

View File

@ -19,8 +19,9 @@ class Transaction {
bool idLess = id.compareTo(otherUserId) < 0;
var lesser = idLess ? id : otherUserId;
var greater = idLess ? otherUserId : id;
return DBCrypt()
.hashpw("$lesser-$greater", KeyFileManager.keyPair.privateKey);
// return DBCrypt()
// .hashpw("$lesser-$greater", KeyFileManager.keyPair.privateKey);
return "$lesser-$greater";
}
Future<String> generateP2PPayload(String otherUserId) async =>