fix p2p transactions

main
Zachary Atkins 3 years ago
parent 68f06e5f05
commit dbc0f84d58

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

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

Loading…
Cancel
Save