upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/btfaddr.h
diff options
context:
space:
mode:
authorBitflash-sh <btf01@proton.me>2026-07-24 11:18:11 -0300
committerBitflash-sh <btf01@proton.me>2026-07-24 11:18:11 -0300
commit51d617e70f90a972185917ea0096c1ecef2bfa8b (patch)
tree9fbbcd867de9de9d0776afdd02f594ba312c46eb /src/btfaddr.h
Bitflash: fair-launch release
Satoshi's bitcoin-0.1.0 reborn with RandomX CPU proof of work, anonymous .btf addressing over Nostr with CGNAT rendezvous, automatic peer discovery, a headless Linux node, and Windows GUI wallet. Fair launch, no premine, 21M cap.
Diffstat (limited to 'src/btfaddr.h')
-rw-r--r--src/btfaddr.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/btfaddr.h b/src/btfaddr.h
new file mode 100644
index 0000000..1addf8f
--- /dev/null
+++ b/src/btfaddr.h
@@ -0,0 +1,72 @@
1// Copyright (c) 2026 Bitflash developers
2// Distributed under the MIT/X11 software license.
3//
4// Bitflash hidden services -- self-certifying `.btf` addresses (a Tor `.onion`
5// analogue, ported from the Itzal design). An address IS the service's public
6// key: base32(pubkey[32] || checksum[2]).btf, derived from the owner's
7// secp256k1 x-only key, so it cannot be forged (no CA, no DNS). Resolving it
8// means proving a descriptor is signed by exactly this key.
9//
10// This is the ADDRESS + DESCRIPTOR layer. Reachability (rendezvous over the
11// embedded Nostr relays so the origin IP is never exposed) builds on top.
12
13#ifndef BITFLASH_BTFADDR_H
14#define BITFLASH_BTFADDR_H
15
16#include <string>
17#include <vector>
18#include <stdint.h>
19
20namespace btf
21{
22
23// Pseudo-TLD, resolved inside the Bitflash client, never by real DNS.
24extern const char* TLD; // ".btf"
25
26// RFC 4648 base32, lowercase, no padding (case-insensitive hostname label).
27std::string Base32Encode(const unsigned char* data, size_t n);
28bool Base32Decode(const std::string& s, std::vector<unsigned char>& out);
29
30// Derive the `.btf` address for a 32-byte x-only public key.
31std::string Address(const unsigned char pubkey[32]);
32
33// True if a hostname is a `.btf` address (case-insensitive, optional trailing dot).
34bool IsBtf(const std::string& host);
35
36// Parse a `.btf` address back to its 32-byte public key, verifying the checksum.
37// Returns false if the label isn't valid base32, is too short, or checksum fails.
38bool ParseAddress(const std::string& addr, unsigned char pubkeyOut[32]);
39
40
41// ---- Service descriptor (published later on Nostr) -------------------------
42//
43// A descriptor tells a client how to REACH a service after resolving its
44// address: "service <pubkey> is reachable via <meeting_node>, encrypt end-to-end
45// to my x25519 key <enc>". It is signed by the service key and self-certifying:
46// the client requires the signature to verify under the exact pubkey the
47// address decodes to, so nobody can publish a descriptor for an address they
48// don't own (no hijacking, even via a malicious relay).
49
50struct Descriptor
51{
52 unsigned char pubkey[32];
53 std::string enc; // service x25519 public key (hex) for the E2E channel
54 std::string meeting_node; // rendezvous node the service is registered at
55 uint64_t created;
56};
57
58// Sign a descriptor. `ctx` is a secp256k1_context* (passed as void* to keep this
59// header free of secp headers); `seckey` is the 32-byte service secret key.
60// Returns the descriptor JSON as a string, or "" on failure.
61std::string SignDescriptor(void* ctx, const unsigned char seckey[32],
62 const std::string& enc, const std::string& meeting_node,
63 uint64_t created);
64
65// Verify a descriptor is validly signed by `expect_pubkey` (the key the resolved
66// `.btf` address encodes). Returns true and fills `out` on success.
67bool VerifyDescriptor(void* ctx, const std::string& jsonStr,
68 const unsigned char expect_pubkey[32], Descriptor& out);
69
70} // namespace btf
71
72#endif