diff --git a/bin/nostr_console.dart b/bin/nostr_console.dart index 4197df8..94037b2 100644 --- a/bin/nostr_console.dart +++ b/bin/nostr_console.dart @@ -464,3 +464,4 @@ Future main(List arguments) async { return; } } + diff --git a/lib/console_ui.dart b/lib/console_ui.dart index 0244546..5b826e7 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -570,16 +570,16 @@ void printPubkeys(Set pubkey) { void printPubkeyResult(Set pubkey) { if( pubkey.isEmpty) { - print("There is no pubkey for that given name."); + stdout.write("There is no pubkey for that given name.\n"); return; } else { if( pubkey.length == 1) { - print("There is 1 public key for the given name, which is: "); + stdout.write("There is 1 public key for the given name, which is: \n"); } else { - print("There are ${pubkey.length} public keys for the given name, which are: "); + stdout.write("There are ${pubkey.length} public keys for the given name, which are: \n"); } + printPubkeys(pubkey); } - printPubkeys(pubkey); } Future otherOptionsMenuUi(Store node) async { @@ -1573,7 +1573,7 @@ Future socialMenuUi(Store node) async { stdout.write("Printing profile of a user; type username or first few letters of user's public key( or full public key): "); String? $tempUserName = stdin.readLineSync(); String userName = $tempUserName??""; - stdout.write( "user name: $userName"); + stdout.write( "Entered name/pubkey: $userName\n"); if( userName != "") { Set pubkey = getPublicKeyFromName(userName); diff --git a/lib/event_ds.dart b/lib/event_ds.dart index 448e162..c5dd213 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -1357,21 +1357,34 @@ Set getPublicKeyFromName(String inquiredName) { if( inquiredName.isEmpty) { return {}; } + + inquiredName = inquiredName.toLowerCase(); + Set pubkeys = {}; gKindONames.forEach((pubkey, userInfo) { // check both the user name, and the pubkey to search for the user // check username if( userInfo.name != null) { int minNameLen = min( inquiredName.length, (userInfo.name?.length)??0); - if( inquiredName.toLowerCase() == userInfo.name?.substring(0, minNameLen).toLowerCase()) { + if( inquiredName == userInfo.name?.substring(0, minNameLen).toLowerCase()) { pubkeys.add(pubkey); } } // check public key - if( inquiredName.length >= 2 && inquiredName.length <= pubkey.length) { - if( pubkey.substring(0, inquiredName.length) == inquiredName) { - pubkeys.add(pubkey); + if (inquiredName.startsWith("npub")) { // check npub + String? hexKey = getHexPubkeyFromNpub(inquiredName); + if (hexKey != null) { + pubkeys.add(hexKey); + //stdout.write("found user"); + } else { + //stdout.write("") + } + } else { // in case it is a hex key + if (inquiredName.length >= 2 && inquiredName.length <= pubkey.length) { + if (pubkey.substring(0, inquiredName.length) == inquiredName) { + pubkeys.add(pubkey); + } } } }); @@ -1780,3 +1793,15 @@ String myGetPublicKey(String prikey) { } return pubkey; } + +String? getHexPubkeyFromNpub(String npubKey) { + Map npubMap = bech32Decode(npubKey); + String? npubPubkey = npubMap["data"]; + + if (npubPubkey != null) { + return npubPubkey; + } else { + //print("Could not parse the given npub/public key. Exiting."); + return null; + } +} diff --git a/lib/utils.dart b/lib/utils.dart index 6bffd78..05e9580 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -1,5 +1,6 @@ import 'dart:io'; import 'package:qr/qr.dart'; +import 'package:nostr_console/nip_019.dart'; enum enumRoomType { kind4, kind40, kind140, RoomLocationTag, RoomTTag}