66 lines
2.6 KiB
C
66 lines
2.6 KiB
C
#ifndef SIGNER_H
|
|
#define SIGNER_H
|
|
|
|
#include "../resources/nostr_core_lib/cjson/cJSON.h"
|
|
#include "nsigner_client.h"
|
|
|
|
#include <time.h>
|
|
#include <stdint.h>
|
|
|
|
typedef enum {
|
|
NT_SIGNER_LOCAL = 0,
|
|
NT_SIGNER_NSIGNER = 1,
|
|
NT_SIGNER_NSIGNER_QREXEC = 2,
|
|
NT_SIGNER_NSIGNER_URL = 3
|
|
} nt_signer_kind_t;
|
|
|
|
typedef struct {
|
|
nt_signer_kind_t kind;
|
|
char socket_name[128];
|
|
char qrexec_target[128];
|
|
char qrexec_service[128];
|
|
char endpoint_url[256];
|
|
int url_session_fd;
|
|
nt_nsigner_selector_t selector;
|
|
nt_nsigner_auth_ctx_t url_auth;
|
|
} nt_signer_t;
|
|
|
|
extern nt_signer_t g_signer;
|
|
|
|
void signer_init(void);
|
|
void signer_shutdown(void);
|
|
int signer_init_local(void);
|
|
void signer_set_selector(int has_index, int index, const char *role);
|
|
int signer_init_nsigner(const char *socket_name, const nt_nsigner_selector_t *selector);
|
|
int signer_init_nsigner_qrexec(const char *target_qube, const char *service_name, const nt_nsigner_selector_t *selector);
|
|
int signer_init_nsigner_url(const char *endpoint_url, const nt_nsigner_selector_t *selector);
|
|
int signer_init_nsigner_url_with_session(const char *endpoint_url,
|
|
const nt_nsigner_selector_t *selector,
|
|
int session_fd);
|
|
int signer_init_nsigner_url_with_session_auth(const char *endpoint_url,
|
|
const nt_nsigner_selector_t *selector,
|
|
int session_fd,
|
|
const nt_nsigner_auth_ctx_t *auth_or_null);
|
|
|
|
int signer_create_and_sign(int kind,
|
|
const char *content,
|
|
cJSON *tags,
|
|
time_t timestamp,
|
|
char **signed_event_json_out);
|
|
|
|
int signer_nip04_encrypt(const char *peer_pub_hex, const char *plaintext, char **cipher_out);
|
|
int signer_nip04_decrypt(const char *peer_pub_hex, const char *ciphertext, char **plain_out);
|
|
|
|
int signer_nip44_encrypt(const char *peer_pub_hex, const char *plaintext, char **cipher_out);
|
|
int signer_nip44_decrypt(const char *peer_pub_hex, const char *ciphertext, char **plain_out);
|
|
|
|
int signer_nip44_self_encrypt(const char *plaintext, char **cipher_out);
|
|
int signer_nip44_self_decrypt(const char *sender_pub_hex, const char *ciphertext, char **plain_out);
|
|
|
|
int signer_sign_event_json(const char *unsigned_event_json, char **signed_event_json_out);
|
|
|
|
/* Returns 0 on success. Only works in NT_SIGNER_LOCAL mode; returns -1 for NT_SIGNER_NSIGNER. */
|
|
int signer_get_local_private_key(unsigned char out_priv[32]);
|
|
|
|
#endif /* SIGNER_H */
|