From f3054378624e22411a88892f46f5ab259789e469 Mon Sep 17 00:00:00 2001 From: Vishal <64505169+vishalxl@users.noreply.github.com> Date: Fri, 18 Nov 2022 19:57:59 +0530 Subject: [PATCH] changed name colors a bit; handled case if incoming DM is wrong format little change of looking up name so one letter names can be looked up --- lib/event_ds.dart | 50 ++++++++++++++++++++++++++--------------------- lib/settings.dart | 6 +++--- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lib/event_ds.dart b/lib/event_ds.dart index 0925d6c..646be6e 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -422,29 +422,34 @@ class EventData { String? decryptDirectMessage() { int ivIndex = content.indexOf("?iv="); - var iv = content.substring( ivIndex + 4, content.length); - var enc_str = content.substring(0, ivIndex); + if( ivIndex > 0) { + var iv = content.substring( ivIndex + 4, content.length); + var enc_str = content.substring(0, ivIndex); - String userKey = userPrivateKey ; - String otherUserPubKey = "02" + pubkey; - if( pubkey == userPublicKey) { // if user themselve is the sender change public key used to decrypt - userKey = userPrivateKey; - int numPtags = 0; - tags.forEach((tag) { - if(tag[0] == "p" ) { - otherUserPubKey = "02" + tag[1]; - numPtags++; + String userKey = userPrivateKey ; + String otherUserPubKey = "02" + pubkey; + if( pubkey == userPublicKey) { // if user themselve is the sender change public key used to decrypt + userKey = userPrivateKey; + int numPtags = 0; + tags.forEach((tag) { + if(tag[0] == "p" ) { + otherUserPubKey = "02" + tag[1]; + numPtags++; + } + }); + // if there are more than one p tags, we don't know who its for + if( numPtags != 1) { + if( gDebug >= 0) printInColor(" in translateAndExpand: got event $id with number of p tags != one : $numPtags . not decrypting", redColor); + return null; } - }); - // if there are more than one p tags, we don't know who its for - if( numPtags != 1) { - if( gDebug >= 0) printInColor(" in translateAndExpand: got event $id with number of p tags != one : $numPtags . not decrypting", redColor); - return null; - } - } + } - var decrypted = myPrivateDecrypt( userKey, otherUserPubKey, enc_str, iv); // use bob's privatekey and alic's publickey means bob can read message from alic - return decrypted; + var decrypted = myPrivateDecrypt( userKey, otherUserPubKey, enc_str, iv); // use bob's privatekey and alic's publickey means bob can read message from alic + return decrypted; + } else { + if(gDebug > 0) print("Invalid content for dm, could not get ivIndex: $content"); + return null; + } } Channel? getChannelForMessage(List? listChannel, String messageId) { @@ -1079,7 +1084,7 @@ String getAuthorName(String pubkey, [int len = 3]) { // returns full public key(s) for the given username( which can be first few letters of pubkey, or the user name) Set getPublicKeyFromName(String inquiredName) { - if( inquiredName.length < 2) { + if( inquiredName.length < 1) { return {}; } Set pubkeys = {}; @@ -1094,7 +1099,7 @@ Set getPublicKeyFromName(String inquiredName) { } // check public key - if( inquiredName.length <= pubkey.length) { + if( inquiredName.length >= 2 && inquiredName.length <= pubkey.length) { if( pubkey.substring(0, inquiredName.length) == inquiredName) { pubkeys.add(pubkey); } @@ -1521,6 +1526,7 @@ try { String myEncrypt( String privateString, String publicString, String plainText) { + print("private = ${privateString.length} public = ${publicString.length}"); Uint8List uintInputText = convert.Utf8Encoder().convert(plainText); final encryptedString = myEncryptRaw(privateString, publicString, uintInputText); return encryptedString; diff --git a/lib/settings.dart b/lib/settings.dart index e77b0cb..c514dbb 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -167,9 +167,9 @@ List nameColorPalette = [brightMagentaColor, brightBlueColor, brightCyan */ -Map pubkeyColor = { '0': brightMagentaColor, '1': brightMagentaColor, - '2': brightBlueColor, '3': brightBlueColor, - '4': brightCyanColor, '5': brightCyanColor, +Map pubkeyColor = { '0': magentaColor, '1': brightMagentaColor, + '2': blueColor, '3': brightBlueColor, + '4': cyanColor, '5': brightCyanColor, '6': brightGreenColor, '7': brightGreenColor, '8': brightYellowColor,'9': brightYellowColor, 'a': brightRedColor, 'b': brightRedColor,