shareNode method
TODO NO NEED FOR THIS shareNode
Implementation
@override
Future<bool> shareNode(
String nodePath, String senderUserId, String receiverUserId) async {
/// check local pairing
/// check cloud pairing
/// get key
/// create cloud event e2ee (if public key - else no e2ee)
/// post event
try {
log("SHARE NODE BETWEEN PAIRED DEVICES");
toolbox_api.Node node = await getNode(':Local:Pairing:$receiverUserId');
String encryptedKey = await node
.getValue('key')
.then((value) => value!.getValue("en").toString());
String agreeValue = await node
.getValue('agreement')
.then((value) => value!.getValue("en").toString());
if (agreeValue == 'out' || agreeValue == 'both') {
try {
log("Agreement valid");
List<String> agreements = await cloud.getMergedAccounts(senderUserId);
if (agreements.contains(receiverUserId) == true) {
ShortUser data =
await cloud.getMergedInfo(senderUserId, receiverUserId);
String? publicKey = data.getPublicKey;
if (publicKey != null) {
try {
final keyVal = Enc.Key.fromUtf8(publicKey);
final iv = Enc.IV.fromLength(16);
final enc =
Enc.Encrypter(Enc.AES(keyVal, mode: Enc.AESMode.cfb64));
// need to decrypt the encryptedKey
// DECRYPT DATA
encryptedKey = enc.decrypt(
encryptedKey.split(':')[1] as Enc.Encrypted,
iv: iv);
} catch (e) {
log("ISSUE DECRYPTING DATA");
}
} else {
encryptedKey = encryptedKey.split(':')[1];
}
// node to send
toolbox_api.Node toShareNode = await getNode(nodePath);
String uuid = await cloud.generateUUID();
Event toPostEvent = Event(
id_event: uuid,
tlp: toShareNode.visibility.toValueString().toUpperCase());
toPostEvent.setOwner = senderUserId;
toPostEvent.setType = 'user';
toPostEvent.encoding = 'ascii';
//EncryptNode
try {
Map<dynamic, dynamic> jsonify =
await encryptCloudData(toShareNode);
toPostEvent.setContent = jsonEncode(jsonify);
} catch (e) {
log("ISSUE ENCRYPTING DATA");
toPostEvent.setContent =
json.encode(await convertNodeToJsonString(toShareNode));
}
await cloud.createEvent(senderUserId, toPostEvent);
} else {
return false;
//throw CloudException('There is no active cloud agreement');
}
} catch (e) {
return false;
//throw CloudException('There is no active cloud agreement');
}
return true;
} else {
return false;
//return false;
}
} catch (e) {
return false;
//throw ReplicationException('Key Node not found');
}
}