-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhisper.h
More file actions
65 lines (53 loc) · 2.25 KB
/
Copy pathwhisper.h
File metadata and controls
65 lines (53 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* whisper - Encrypted DM pipe for Nostr (NIP-17 + NIP-44)
*
* Usage:
* echo "secret" | whisper send --to npub1... --nsec nsec1... --relay wss://...
* whisper recv --nsec nsec1... --relay wss://...
*/
#ifndef WHISPER_H
#define WHISPER_H
#include <nostr.h>
#include <stdint.h>
#include <stdbool.h>
/* Exit codes */
#define WHISPER_EXIT_OK 0
#define WHISPER_EXIT_INVALID_ARGS 1
#define WHISPER_EXIT_KEY_ERROR 2
#define WHISPER_EXIT_RELAY_ERROR 3
#define WHISPER_EXIT_CRYPTO_ERROR 4
#define WHISPER_EXIT_TIMEOUT 5
/* Default timeout in milliseconds */
#define WHISPER_DEFAULT_TIMEOUT_MS 5000
/* Configuration for send command */
typedef struct {
const char* recipient; /* npub or hex pubkey */
const char* nsec; /* nsec or hex private key */
const char* nsec_file; /* path to file containing nsec */
const char* relay_url; /* relay URL */
const char* subject; /* optional subject */
const char* reply_to; /* optional event ID to reply to */
int timeout_ms; /* relay timeout */
} whisper_send_config;
/* Configuration for recv command */
typedef struct {
const char* nsec; /* nsec or hex private key */
const char* nsec_file; /* path to file containing nsec */
const char* relay_url; /* relay URL */
int64_t since; /* only messages after this timestamp */
int limit; /* max messages (0 = unlimited) */
bool json_output; /* output raw JSON */
int timeout_ms; /* connection timeout */
} whisper_recv_config;
/* Send a DM, reading content from stdin */
int whisper_send(const whisper_send_config* config);
/* Receive DMs, writing to stdout */
int whisper_recv(const whisper_recv_config* config);
/* Utility: load private key from string or file */
int whisper_load_privkey(const char* nsec_str, const char* nsec_file,
nostr_privkey* privkey, nostr_key* pubkey);
/* Utility: parse pubkey from npub or hex */
int whisper_parse_pubkey(const char* pubkey_str, nostr_key* pubkey);
/* Utility: strip control characters from string (returns malloc'd copy) */
char* whisper_strip_control_chars(const char* input);
#endif /* WHISPER_H */