v0.0.34 - Add qrexec bridge subcommand and --bridge-source-trusted flag for persistent-signer qrexec transport
This commit is contained in:
@@ -464,7 +464,10 @@ int socket_name_random(char *out, size_t out_len);
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "nostr_common.h"
|
||||
#include "nsigner_transport.h"
|
||||
#include "nsigner_client.h"
|
||||
#include "../cjson/cJSON.h"
|
||||
|
||||
#define SOCKET_NAME_A "nsigner_test_run_a"
|
||||
#define SOCKET_NAME_B "nsigner_test_run_b"
|
||||
@@ -629,7 +632,6 @@ int main(void) {
|
||||
pid_t child;
|
||||
pid_t child2;
|
||||
const char *mnemonic = "\nabandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about\n";
|
||||
char *resp = NULL;
|
||||
int status;
|
||||
|
||||
(void)signal(SIGPIPE, SIG_IGN);
|
||||
@@ -709,40 +711,78 @@ int main(void) {
|
||||
sleep_ms(1000);
|
||||
|
||||
{
|
||||
nsigner_client_t client;
|
||||
nsigner_client_init(&client);
|
||||
if (nsigner_client_connect_unix(&client, SOCKET_NAME_A, 5000) == 0) {
|
||||
if (nsigner_client_get_public_key(&client, "1", "", &resp) == 0) {
|
||||
check_condition("get_public_key response id", strstr(resp, "\"id\":\"1\"") != NULL);
|
||||
check_condition("get_public_key has result", strstr(resp, "\"result\":") != NULL);
|
||||
/*
|
||||
* Use the shared nsigner client from nostr_core_lib.
|
||||
* n_signer handles one request per connection, so we open a fresh
|
||||
* transport+client for each verb (matching the old client behavior).
|
||||
*/
|
||||
nsigner_transport_t *t = NULL;
|
||||
nsigner_client_t *c = NULL;
|
||||
cJSON *params = NULL;
|
||||
cJSON *opts = NULL;
|
||||
cJSON *gpk_result = NULL;
|
||||
cJSON *se_result = NULL;
|
||||
|
||||
/* get_public_key */
|
||||
t = nsigner_transport_open_unix(SOCKET_NAME_A, 5000);
|
||||
if (t != NULL) {
|
||||
c = nsigner_client_new(t);
|
||||
if (c == NULL) {
|
||||
t->close(t);
|
||||
check_condition("connect signer socket for client library", 0);
|
||||
} else {
|
||||
check_condition("get_public_key request roundtrip", 0);
|
||||
params = cJSON_CreateArray();
|
||||
if (nsigner_client_call(c, "get_public_key", params, &gpk_result) == NOSTR_SUCCESS) {
|
||||
check_condition("get_public_key has result", gpk_result != NULL);
|
||||
} else {
|
||||
check_condition("get_public_key request roundtrip", 0);
|
||||
}
|
||||
params = NULL; /* nsigner_client_call took ownership */
|
||||
cJSON_Delete(gpk_result);
|
||||
gpk_result = NULL;
|
||||
}
|
||||
free(resp);
|
||||
resp = NULL;
|
||||
nsigner_client_close(&client);
|
||||
} else {
|
||||
check_condition("connect signer socket for client library", 0);
|
||||
}
|
||||
nsigner_client_free(c);
|
||||
c = NULL;
|
||||
|
||||
nsigner_client_init(&client);
|
||||
if (nsigner_client_connect_unix(&client, SOCKET_NAME_A, 5000) == 0) {
|
||||
if (nsigner_client_sign_event(&client,
|
||||
"2",
|
||||
"{\"kind\":1,\"content\":\"hello\",\"tags\":[],\"created_at\":1700000000}",
|
||||
"main",
|
||||
&resp) == 0) {
|
||||
check_condition("sign_event response id", strstr(resp, "\"id\":\"2\"") != NULL);
|
||||
check_condition("sign_event has result", strstr(resp, "\"result\":") != NULL);
|
||||
/* sign_event (fresh connection) */
|
||||
t = nsigner_transport_open_unix(SOCKET_NAME_A, 5000);
|
||||
if (t != NULL) {
|
||||
c = nsigner_client_new(t);
|
||||
if (c == NULL) {
|
||||
t->close(t);
|
||||
check_condition("connect signer socket for sign_event", 0);
|
||||
} else {
|
||||
check_condition("sign_event request roundtrip", 0);
|
||||
params = cJSON_CreateArray();
|
||||
if (params != NULL) {
|
||||
cJSON_AddItemToArray(params, cJSON_CreateString("{\"kind\":1,\"content\":\"hello\",\"tags\":[],\"created_at\":1700000000}"));
|
||||
opts = cJSON_CreateObject();
|
||||
if (opts != NULL) {
|
||||
cJSON_AddStringToObject(opts, "role", "main");
|
||||
cJSON_AddItemToArray(params, opts);
|
||||
opts = NULL;
|
||||
}
|
||||
if (nsigner_client_call(c, "sign_event", params, &se_result) == NOSTR_SUCCESS) {
|
||||
check_condition("sign_event has result", se_result != NULL);
|
||||
} else {
|
||||
check_condition("sign_event request roundtrip", 0);
|
||||
}
|
||||
params = NULL; /* nsigner_client_call took ownership */
|
||||
cJSON_Delete(se_result);
|
||||
se_result = NULL;
|
||||
}
|
||||
}
|
||||
free(resp);
|
||||
resp = NULL;
|
||||
} else {
|
||||
check_condition("connect signer socket for sign_event", 0);
|
||||
}
|
||||
nsigner_client_close(&client);
|
||||
|
||||
cJSON_Delete(params);
|
||||
cJSON_Delete(opts);
|
||||
cJSON_Delete(gpk_result);
|
||||
cJSON_Delete(se_result);
|
||||
nsigner_client_free(c); /* also closes/frees the transport */
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user