Compare commits

...
5 Commits
4 changed files with 50 additions and 194 deletions
+2 -2
View File
@@ -11,8 +11,8 @@
*/
#define NT_VERSION_MAJOR 0
#define NT_VERSION_MINOR 0
#define NT_VERSION_PATCH 18
#define NT_VERSION "v0.0.18"
#define NT_VERSION_PATCH 22
#define NT_VERSION "v0.0.22"
#include <ncurses.h>
#include <stdio.h>
+17 -182
View File
@@ -45,21 +45,6 @@ static int menu_prompt(const char *breadcrumb,
return 0;
}
static void menu_noticef(const char *fmt, ...) {
char msg[1024];
va_list ap;
if (!fmt) {
return;
}
va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
tuin_notice(msg);
}
static int menu_load_test_mnemonic(char *out, int out_size) {
FILE *fp;
@@ -199,15 +184,11 @@ void menu_login(void) {
static const TuiMenuItem LOGIN_ITEMS[] = {
{NT_HK("P", "rivate key"), 'p'},
{NT_HK("M", "nemonic"), 'm'},
{"N_" NT_HK("s", "igner"), 's'},
{"Signer - " NT_HK("U", "RL"), 'u'},
{"Signer - " NT_HK("Q", "ube"), 'q'},
{"Signer - " NT_HK("L", "aunch new"), 'l'},
{NT_HK("N", "ew account"), 'n'},
{NT_HK("Q", "uit"), 'q'},
};
static const TuiMenuItem SIGNER_TRANSPORT_ITEMS[] = {
{"URL signer (FIPS/web address)", 'u'},
{"Signer qrexec transport", 's'},
{"Launch n_signer (stub)", 'l'},
{"Back", 'b'},
{"E_" NT_HK("x", "it"), 'x'},
};
TuiMenuState login_state = {0};
@@ -220,12 +201,12 @@ void menu_login(void) {
unsigned char pub[32];
int login_idx;
TuiFrame frame = nt_frame("> Login");
TuiMenu menu = {LOGIN_ITEMS, 5};
TuiMenu menu = {LOGIN_ITEMS, 7};
TuiStatus status = nt_status();
login_idx = tuin_menu_run(&frame, &menu, &status, &login_state);
if (login_idx < 0 || login_idx == 4) {
if (login_idx < 0 || login_idx == 6) {
nt_log("Hasta luego.");
signer_shutdown();
exit(0);
@@ -243,166 +224,15 @@ void menu_login(void) {
continue;
}
} else if (login_idx == 2) {
snprintf(input, sizeof(input), "%s", "s");
snprintf(input, sizeof(input), "%s", "u");
} else if (login_idx == 3) {
snprintf(input, sizeof(input), "%s", "S");
} else if (login_idx == 4) {
snprintf(input, sizeof(input), "%s", "l");
} else if (login_idx == 5) {
snprintf(input, sizeof(input), "%s", "n");
}
if (strcmp(input, "s") == 0 || strcmp(input, "S") == 0) {
char **names = NULL;
int name_count = 0;
if (nsigner_list(&names, &name_count) == 0 && name_count > 0) {
char pubkey_hex[65] = {0};
int selected = 0;
nt_nsigner_selector_t selector = nsigner_selector_default();
char idxbuf[32] = {0};
int nostr_index = 0;
int choose_transport = 0;
int idx;
int local_choice;
TuiMenuState local_state = {0};
TuiMenuItem *local_items = NULL;
char (*labels)[256] = NULL;
local_items = (TuiMenuItem *)calloc((size_t)(name_count + 2), sizeof(TuiMenuItem));
labels = (char(*)[256])calloc((size_t)(name_count + 2), sizeof(*labels));
if (!local_items || !labels) {
for (idx = 0; idx < name_count; idx++) {
free(names[idx]);
}
free(names);
free(local_items);
free(labels);
menu_noticef("Out of memory while building local n_signer menu.");
continue;
}
for (idx = 0; idx < name_count; idx++) {
snprintf(labels[idx], sizeof(labels[idx]), "@%s", names[idx]);
local_items[idx].label = labels[idx];
local_items[idx].shortcut = 0;
}
snprintf(labels[name_count], sizeof(labels[name_count]), "Transport options");
local_items[name_count].label = labels[name_count];
local_items[name_count].shortcut = 't';
snprintf(labels[name_count + 1], sizeof(labels[name_count + 1]), "Back");
local_items[name_count + 1].label = labels[name_count + 1];
local_items[name_count + 1].shortcut = 'b';
{
TuiFrame local_frame = nt_frame("> Login > Signer Local");
TuiMenu local_menu = {local_items, name_count + 2};
TuiStatus local_status = nt_status();
local_choice = tuin_menu_run(&local_frame, &local_menu, &local_status, &local_state);
}
if (local_choice < 0 || local_choice == name_count + 1) {
for (idx = 0; idx < name_count; idx++) {
free(names[idx]);
}
free(names);
free(local_items);
free(labels);
continue;
}
if (local_choice == name_count) {
choose_transport = 1;
} else {
selected = local_choice;
(void)menu_prompt("> Login > Signer Local", "Seed phrase index (0)", "", idxbuf, sizeof(idxbuf));
}
if (idxbuf[0] != '\0') {
nostr_index = atoi(idxbuf);
if (nostr_index < 0) {
nostr_index = 0;
}
}
if (!choose_transport) {
selector.has_nostr_index = 1;
selector.nostr_index = nostr_index;
selector.role[0] = '\0';
menu_render_body("> Login > Signer Local");
nt_log("Waiting for n_signer approval...");
if (nsigner_get_public_key(names[selected], &selector, pubkey_hex) != 0) {
for (idx = 0; idx < name_count; idx++) {
free(names[idx]);
}
free(names);
free(local_items);
free(labels);
tuin_notice("Failed to get public key from n_signer (denied or error).");
continue;
}
signer_init_nsigner(names[selected], &selector);
snprintf(g_state.npub_hex, sizeof(g_state.npub_hex), "%s", pubkey_hex);
{
unsigned char pub_bytes[32];
nostr_hex_to_bytes(pubkey_hex, pub_bytes, 32);
nostr_key_to_bech32(pub_bytes, "npub", g_state.npub_bech32);
}
g_state.nsec_hex[0] = '\0';
g_state.nsec_bech32[0] = '\0';
g_state.seed_phrase[0] = '\0';
g_state.logged_in = 1;
nt_log("Signed in via n_signer (@%s) npub: %s", names[selected], g_state.npub_bech32);
for (idx = 0; idx < name_count; idx++) {
free(names[idx]);
}
free(names);
free(local_items);
free(labels);
if (state_load_user_info_async() != 0) {
nt_log("Failed to start background user-info load.");
} else {
nt_log("Loading profile/relay data in background...");
}
return;
}
for (idx = 0; idx < name_count; idx++) {
free(names[idx]);
}
free(names);
free(local_items);
free(labels);
}
{
int transport_idx;
TuiMenuState transport_state = {0};
TuiFrame transport_frame = nt_frame("> Login > N_signer > Transport");
TuiMenu transport_menu = {SIGNER_TRANSPORT_ITEMS, 4};
TuiStatus transport_status = nt_status();
transport_idx = tuin_menu_run(&transport_frame, &transport_menu, &transport_status, &transport_state);
if (transport_idx == 0) {
snprintf(input, sizeof(input), "%s", "u");
} else if (transport_idx == 1) {
snprintf(input, sizeof(input), "%s", "S");
} else if (transport_idx == 2) {
tuin_notice("Launch n_signer is not implemented yet.");
continue;
} else {
continue;
}
}
}
if (strcmp(input, "u") == 0 || strcmp(input, "U") == 0) {
char pubkey_hex[65] = {0};
char endpoint_url[256];
@@ -416,7 +246,7 @@ void menu_login(void) {
snprintf(endpoint_url, sizeof(endpoint_url), "%s", (saved_endpoint && saved_endpoint[0] != '\0') ? saved_endpoint : "");
(void)menu_prompt("> Login > URL Signer",
"Signer URL (http://<npub>.fips:8080)",
(saved_endpoint && saved_endpoint[0] != '\0') ? saved_endpoint : "",
"",
endpoint_url,
sizeof(endpoint_url));
@@ -572,6 +402,11 @@ void menu_login(void) {
return;
}
if (strcmp(input, "l") == 0 || strcmp(input, "L") == 0) {
tuin_notice("Launch n_signer is not implemented yet.");
continue;
}
if (strcmp(input, "n") == 0) {
char mnemonic[256];
char idxbuf[32];
+30 -9
View File
@@ -7,6 +7,7 @@
#include "../resources/nostr_core_lib/cjson/cJSON.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -17,21 +18,19 @@ static int profile_publish_kind0(const char *content_json) {
void menu_profile(void) {
static const char *fields[] = {"name", "about", "picture", "banner", "website", "lud16", "nip05"};
static const TuiMenuItem PROFILE_ITEMS[] = {
{NT_HK("M", "odify account"), 'm'},
{NT_HK("P", "ost changes and exit."), 'p'},
{"E" NT_HK("x", "it without saving"), 'x'},
};
TuiMenuState menu_state = {0};
char edit_buf[512];
if (g_state.logged_in && g_state.npub_hex[0] != '\0' &&
(!g_state.kind0_json || strcmp(g_state.kind0_json, "{}") == 0)) {
(void)state_load_user_info();
}
while (1) {
TuiFrame frame = nt_frame("> Main Menu > Profile");
TuiMenu menu = {PROFILE_ITEMS, 3};
TuiStatus status = nt_status();
cJSON *meta;
int i;
int idx;
int idx = -1;
tuin_render_header(&frame);
nt_print_reset();
@@ -79,7 +78,29 @@ void menu_profile(void) {
nt_print("%-18s %s", fields[i], (cJSON_IsString(v) && v->valuestring) ? v->valuestring : "");
}
idx = tuin_menu_run(&frame, &menu, &status, &menu_state);
nt_print("");
nt_print("[m] Modify account [p] Post changes and exit [x] Exit without saving");
{
int key = tuin_get_key();
if (key == TUI_KEY_RESIZE) {
cJSON_Delete(meta);
continue;
}
if (tuin_is_escape_key(key)) {
idx = 2;
} else if (key >= 0 && key <= 255) {
char ch = (char)tolower((unsigned char)key);
if (ch == 'm') {
idx = 0;
} else if (ch == 'p') {
idx = 1;
} else if (ch == 'x') {
idx = 2;
}
}
}
if (idx < 0 || idx == 2) {
cJSON_Delete(meta);
break;
+1 -1
View File
@@ -199,7 +199,7 @@ void nt_log_show(void) {
}
pthread_mutex_unlock(&g_log_mutex);
tuin_pager_run_ex(&frame, log_text, &status, 1);
tuin_pager_run(&frame, log_text, &status);
}
void nt_log_clear(void) {