upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/nostr.h
blob: 41e59dfaa5198b2ce95bd864d5bfd236f5936f5c (plain)
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
// Copyright (c) 2026 Bitflash developers
// Distributed under the MIT/X11 software license.
//
// Peer discovery over Nostr relays -- replaces the old ThreadIRCSeed. Each
// node publishes a replaceable event (NIP-78, kind 30078) containing its
// "ip:port", signed with Schnorr/secp256k1 (BIP340, the same scheme used by
// Nostr), and subscribes to receive the announcements of other nodes, feeding
// them into the Bitflash address manager.

#ifndef BITFLASH_NOSTR_H
#define BITFLASH_NOSTR_H

#include <string>
#include <vector>

// Thread entry point (signature compatible with _beginthread)
void ThreadNostrSeed(void* parg);

// Public relays used for discovery. Tunable.
extern const char* pszNostrRelays[];
extern const int nNostrRelays;

// Rendezvous meeting relays ("host:port") this node can register its .btf
// service at. It registers at the first reachable one and advertises that in
// its descriptor; if the relay dies it fails over to another, so attacking a
// single relay's IP can't take the network down. Overridable with /rvrelay.
extern std::vector<std::string> vBtfMeetingRelays;
// The relay this node is currently registered at (set by ThreadBtfAccept).
extern std::string strBtfActiveRelay;
// The active relay, or the first seed if none active yet ("" if the list is empty).
std::string BtfActiveRelay();
// Record the relay this node just registered its service at (thread-safe).
void BtfSetActiveRelay(const std::string& relay);

// Copy this node's .btf identity (lazily loading or generating it): the x-only
// pubkey (= the .btf address) and the x25519 secret for the end-to-end channel.
bool BtfGetIdentity(unsigned char pubkey[32], unsigned char enc_sk[32]);

// This node's printable .btf address, or "" if the identity failed to load.
std::string BtfLocalAddress();

// Resolve a .btf address via the public discovery relays: fetch the owner's
// self-certified descriptor and return its meeting node ("host:port") and
// x25519 public key for the end-to-end channel.
bool BtfResolve(const std::string& btfAddr, std::string& meetingHostPort,
                unsigned char enc_pub[32]);

#endif