Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a53455190 | ||
|
|
61581afcc9 | ||
|
|
36eb6afa72 | ||
|
|
160421c673 | ||
|
|
024b490ac1 | ||
|
|
9240f44ea3 | ||
|
|
933cf03ce7 | ||
|
|
27da465295 | ||
|
|
6ebab823a8 | ||
|
|
a3337e5207 | ||
|
|
932c770f6f | ||
|
|
be3a32b488 | ||
|
|
3236e02f41 | ||
|
|
b51bcb4943 | ||
|
|
af06f23939 | ||
|
|
fc337cf921 | ||
|
|
f478a780d7 | ||
|
|
2e7eacc02e | ||
|
|
ec8eb5555b | ||
|
|
a3a68f0fde | ||
|
|
2fe36acde4 | ||
|
|
f470759b96 | ||
|
|
fb3c9dbc76 | ||
|
|
303013a518 | ||
|
|
f7e179dd85 | ||
|
|
a3f7a1bbfd | ||
|
|
a595747aff | ||
|
|
39ebfcd90a | ||
|
|
63972d974d | ||
|
|
13fd364ca3 | ||
|
|
cb4ff93906 | ||
|
|
4d0d794a9a | ||
|
|
ae672b7047 | ||
|
|
0a8a813fcf | ||
|
|
ea40aec6b8 | ||
|
|
98cfd81b01 | ||
|
|
d8d3f9b28c | ||
|
|
669793dd67 | ||
|
|
e21c8eb5be | ||
|
|
20006df228 | ||
|
|
adc7aa9dcf | ||
|
|
1a549afa19 | ||
|
|
6ee62e6575 | ||
|
|
5afe802e8f | ||
|
|
e77973aea0 | ||
|
|
ea84795911 | ||
|
|
481bf3158d | ||
|
|
23e68bdc83 | ||
|
|
4dc753cdcc | ||
|
|
64b7c7ec33 | ||
|
|
f3068f82f3 | ||
|
|
a8dc2ed046 | ||
|
|
9a3965243c | ||
|
|
23c2a58c2b | ||
|
|
45fb6d061d | ||
|
|
c0784fc890 | ||
|
|
499accf440 | ||
|
|
6b95ad37c5 | ||
|
|
54a6044083 | ||
|
|
0f897ab1b3 | ||
|
|
0d910ca181 | ||
|
|
9a63550863 | ||
|
|
eb7a9e6098 | ||
|
|
8585e7649c | ||
|
|
55e2a9c68e | ||
|
|
445ab7a8f4 | ||
|
|
33129d82fd | ||
|
|
c0d095e57b | ||
|
|
e40f3037d3 | ||
|
|
77d92dbcf9 | ||
|
|
1da4f6751e | ||
|
|
3ebfdc06c0 | ||
|
|
d8b342ca3f | ||
|
|
df23fd618a | ||
|
|
19452f45c2 | ||
|
|
711a7cc15c | ||
|
|
58cabadc44 | ||
|
|
77186c88dd | ||
|
|
2036d0165b | ||
|
|
40dd3aa20b | ||
|
|
00df0cad99 | ||
|
|
05fe1df8aa | ||
|
|
98a802552b | ||
|
|
9fd4c61df7 | ||
|
|
76e883fad4 | ||
|
|
c3a9482882 | ||
|
|
8ed9262c65 | ||
|
|
6014a250dd | ||
|
|
f50384962d | ||
|
|
c569c0c346 | ||
|
|
3d2537603c | ||
|
|
d6a0bd67b2 | ||
|
|
9191d446d3 | ||
|
|
f1c22bdf53 | ||
|
|
993ca0f2a1 | ||
|
|
77fadc2683 | ||
|
|
2637378bf0 | ||
|
|
c109c93382 | ||
|
|
0ace93e303 | ||
|
|
af2117b574 | ||
|
|
6d7b709f9a | ||
|
|
5a7c796873 | ||
|
|
3aaa46bb9b | ||
|
|
d257ae49f1 | ||
|
|
ae4aa7cf80 | ||
|
|
e137560d64 | ||
|
|
ca6b4754f9 |
@@ -29,8 +29,14 @@ build/
|
||||
/examples/keypair_generation
|
||||
/examples/mnemonic_derivation
|
||||
/examples/mnemonic_generation
|
||||
/examples/ots_tool
|
||||
/examples/relay_pool
|
||||
/examples/send_nip17_dm
|
||||
/examples/simple_keygen
|
||||
/examples/timestamping
|
||||
/examples/utility_functions
|
||||
/examples/version_test
|
||||
|
||||
# Local OpenTimestamps CLI output
|
||||
/examples/timestamped_*
|
||||
/examples/*.ots
|
||||
|
||||
@@ -42,16 +42,37 @@ else()
|
||||
nostr_core/nostr_log.c
|
||||
nostr_core/request_validator.c
|
||||
nostr_core/nip001.c
|
||||
nostr_core/nip003.c
|
||||
nostr_core/nip004.c
|
||||
nostr_core/nip005.c
|
||||
nostr_core/nip006.c
|
||||
nostr_core/nip011.c
|
||||
nostr_core/nip013.c
|
||||
nostr_core/nip017.c
|
||||
nostr_core/nip019.c
|
||||
nostr_core/nip021.c
|
||||
nostr_core/nip042.c
|
||||
nostr_core/nip044.c
|
||||
nostr_core/nip046.c
|
||||
nostr_core/nip059.c
|
||||
nostr_core/nip060.c
|
||||
nostr_core/nip061.c
|
||||
nostr_core/nostr_signer.c
|
||||
nostr_core/nsigner_transport.c
|
||||
nostr_core/nsigner_client.c
|
||||
nostr_core/utils.c
|
||||
nostr_core/nostr_http.c
|
||||
nostr_core/core_relays.c
|
||||
nostr_core/core_relay_pool.c
|
||||
nostr_core/cashu_mint.c
|
||||
nostr_core/blossom_client.c
|
||||
nostr_core/crypto/nostr_secp256k1.c
|
||||
nostr_core/crypto/nostr_aes.c
|
||||
nostr_core/crypto/nostr_chacha20.c
|
||||
nostr_core/crypto/nostr_poly1305.c
|
||||
nostr_core/crypto/nostr_chacha20poly1305.c
|
||||
cjson/cJSON.c
|
||||
nostr_websocket/nostr_websocket_openssl.c
|
||||
platform/linux.c
|
||||
)
|
||||
|
||||
@@ -63,4 +84,36 @@ else()
|
||||
nostr_websocket
|
||||
)
|
||||
target_compile_definitions(nostr_core PRIVATE NOSTR_ENABLE_NSIGNER_CLIENT=1)
|
||||
target_compile_definitions(nostr_core PRIVATE ENABLE_FILE_LOGGING ENABLE_WEBSOCKET_LOGGING ENABLE_DEBUG_LOGGING)
|
||||
|
||||
# Link system dependencies
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PkgConfig_FOUND)
|
||||
pkg_check_modules(SECP256K1 QUIET libsecp256k1)
|
||||
pkg_check_modules(OPENSSL QUIET openssl)
|
||||
pkg_check_modules(CURL QUIET libcurl)
|
||||
endif()
|
||||
|
||||
if(SECP256K1_FOUND)
|
||||
target_include_directories(nostr_core PRIVATE ${SECP256K1_INCLUDE_DIRS})
|
||||
target_link_libraries(nostr_core PRIVATE ${SECP256K1_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(nostr_core PRIVATE secp256k1)
|
||||
endif()
|
||||
|
||||
if(OPENSSL_FOUND)
|
||||
target_include_directories(nostr_core PRIVATE ${OPENSSL_INCLUDE_DIRS})
|
||||
target_link_libraries(nostr_core PRIVATE ${OPENSSL_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(nostr_core PRIVATE ssl crypto)
|
||||
endif()
|
||||
|
||||
if(CURL_FOUND)
|
||||
target_include_directories(nostr_core PRIVATE ${CURL_INCLUDE_DIRS})
|
||||
target_link_libraries(nostr_core PRIVATE ${CURL_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(nostr_core PRIVATE curl)
|
||||
endif()
|
||||
|
||||
target_link_libraries(nostr_core PRIVATE z dl pthread m)
|
||||
endif()
|
||||
|
||||
@@ -434,6 +434,14 @@ Covered modules and functions:
|
||||
- NIP-01 (`nostr_core/nip001.h`)
|
||||
- `cJSON* nostr_create_and_sign_event_with_signer(int kind, const char* content, cJSON* tags, nostr_signer_t* signer, time_t timestamp);`
|
||||
|
||||
- NIP-03 OpenTimestamps (`nostr_core/nip003.h`)
|
||||
- `cJSON* nostr_nip03_create_proof_event_with_signer(const char* target_event_id, int target_event_kind, const char* ots_data_base64, const char* relay_url, nostr_signer_t* signer);`
|
||||
- `char* nostr_nip03_request_timestamp(const char* event_id_hex, const char* calendar_url, int timeout_seconds);`
|
||||
- `int nostr_nip03_is_proof_complete(const char* ots_data_base64);`
|
||||
- `int nostr_nip03_get_attestation_info(const char* ots_data_base64, int* has_bitcoin, int* has_litecoin, int* has_pending, uint64_t* bitcoin_height, uint64_t* litecoin_height, char** pending_uri_out);`
|
||||
- `char* nostr_nip03_upgrade_proof(const char* ots_data_base64, const char* calendar_url, int timeout_seconds);`
|
||||
- `int nostr_nip03_verify_proof(const char* ots_data_base64, const char* target_digest_hex, uint64_t* block_height_out, time_t* block_time_out);`
|
||||
|
||||
- NIP-17 (`nostr_core/nip017.h`)
|
||||
- `cJSON* nostr_nip17_create_relay_list_event_with_signer(const char** relay_urls, int num_relays, nostr_signer_t* signer);`
|
||||
- `int nostr_nip17_send_dm_with_signer(cJSON* dm_event, const char** recipient_pubkeys, int num_recipients, nostr_signer_t* signer, cJSON** gift_wraps_out, int max_gift_wraps, long max_delay_sec);`
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
0.6.6
|
||||
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,644 @@
|
||||
/*
|
||||
* OpenTimestamps Command-Line Tool
|
||||
*
|
||||
* A simple tool for timestamping files with OpenTimestamps.
|
||||
*
|
||||
* Usage:
|
||||
* ./ots_tool stamp Interactive: type text, save to file, submit to OTS
|
||||
* ./ots_tool stamp <file> Timestamp an existing file
|
||||
* ./ots_tool check <file.ots> Check if a proof is complete
|
||||
* ./ots_tool verify <file> <file.ots> Verify a proof against a file
|
||||
* ./ots_tool upgrade <file.ots> Upgrade a pending proof
|
||||
*
|
||||
* The "stamp" command:
|
||||
* 1. If no file argument, prompts for text input and saves it to a .txt file
|
||||
* 2. Computes the SHA-256 hash of the file
|
||||
* 3. Submits the hash to an OpenTimestamps calendar
|
||||
* 4. Saves the initial .ots proof to <file>.ots
|
||||
* 5. Polls every 60 seconds to check if the proof is complete
|
||||
* 6. When complete, saves the upgraded proof and verifies it
|
||||
*
|
||||
* Options:
|
||||
* --calendar <url> Use a specific OTS calendar (default: https://alice.btc.calendar.opentimestamps.org)
|
||||
* --interval <sec> Poll interval in seconds (default: 60)
|
||||
* --max-wait <min> Maximum wait time in minutes (default: 120 = 2 hours)
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include "nostr_core/nostr_core.h"
|
||||
#include "nostr_core/nip003.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define DEFAULT_CALENDAR "https://alice.btc.calendar.opentimestamps.org"
|
||||
#define DEFAULT_INTERVAL_SEC 60
|
||||
#define DEFAULT_MAX_WAIT_MIN 120
|
||||
|
||||
/* Read an entire file into a malloc'd buffer. Returns NULL on error. */
|
||||
static unsigned char* read_file(const char* path, size_t* len_out) {
|
||||
FILE* f = fopen(path, "rb");
|
||||
if (!f) return NULL;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
long size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
if (size < 0) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned char* buf = (unsigned char*)malloc(size + 1);
|
||||
if (!buf) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t nread = fread(buf, 1, size, f);
|
||||
fclose(f);
|
||||
|
||||
if (nread != (size_t)size) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf[size] = '\0';
|
||||
*len_out = (size_t)size;
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Write data to a file. Returns 0 on success, -1 on error. */
|
||||
static int write_file(const char* path, const unsigned char* data, size_t len) {
|
||||
FILE* f = fopen(path, "wb");
|
||||
if (!f) return -1;
|
||||
|
||||
size_t nwritten = fwrite(data, 1, len, f);
|
||||
fclose(f);
|
||||
|
||||
return (nwritten == len) ? 0 : -1;
|
||||
}
|
||||
|
||||
/* Compute SHA-256 of a file and return as hex string (64 chars + null). */
|
||||
static int compute_file_sha256_hex(const char* path, char* hex_out) {
|
||||
size_t file_len = 0;
|
||||
unsigned char* file_data = read_file(path, &file_len);
|
||||
if (!file_data) return -1;
|
||||
|
||||
unsigned char digest[32];
|
||||
int rc = nostr_sha256(file_data, file_len, digest);
|
||||
free(file_data);
|
||||
|
||||
if (rc != NOSTR_SUCCESS) return -1;
|
||||
|
||||
nostr_bytes_to_hex(digest, 32, hex_out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Convert base64 string to binary file and save. */
|
||||
static int save_base64_to_file(const char* path, const char* b64) {
|
||||
if (!b64) return -1;
|
||||
|
||||
size_t b64_len = strlen(b64);
|
||||
size_t max_decoded = (b64_len / 4) * 3 + 3;
|
||||
unsigned char* data = (unsigned char*)malloc(max_decoded);
|
||||
if (!data) return -1;
|
||||
|
||||
size_t data_len = base64_decode(b64, data);
|
||||
if (data_len == 0) {
|
||||
free(data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rc = write_file(path, data, data_len);
|
||||
free(data);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Read a binary file and convert to base64 string. Caller must free. */
|
||||
static char* read_file_as_base64(const char* path) {
|
||||
size_t file_len = 0;
|
||||
unsigned char* file_data = read_file(path, &file_len);
|
||||
if (!file_data) return NULL;
|
||||
|
||||
size_t b64_size = ((file_len + 2) / 3) * 4 + 1;
|
||||
char* b64 = (char*)malloc(b64_size);
|
||||
if (!b64) {
|
||||
free(file_data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
base64_encode(file_data, file_len, b64, b64_size);
|
||||
free(file_data);
|
||||
return b64;
|
||||
}
|
||||
|
||||
static void print_usage(const char* prog) {
|
||||
printf("OpenTimestamps Command-Line Tool\n");
|
||||
printf("\n");
|
||||
printf("Usage:\n");
|
||||
printf(" %s stamp Interactive: type text, save, submit to OTS\n", prog);
|
||||
printf(" %s stamp <file> Timestamp an existing file\n", prog);
|
||||
printf(" %s check <file.ots> Check if a proof is complete\n", prog);
|
||||
printf(" %s verify <file> <file.ots> Verify a proof against a file\n", prog);
|
||||
printf(" %s upgrade <file.ots> [file] Upgrade a pending proof (optional: original file)\n", prog);
|
||||
printf("\n");
|
||||
printf("Options:\n");
|
||||
printf(" --calendar <url> OTS calendar URL (default: %s)\n", DEFAULT_CALENDAR);
|
||||
printf(" --interval <sec> Poll interval in seconds (default: %d)\n", DEFAULT_INTERVAL_SEC);
|
||||
printf(" --max-wait <min> Max wait time in minutes (default: %d)\n", DEFAULT_MAX_WAIT_MIN);
|
||||
printf("\n");
|
||||
printf("Examples:\n");
|
||||
printf(" %s stamp # Type text, timestamp it\n", prog);
|
||||
printf(" %s stamp mydocument.txt # Timestamp a file\n", prog);
|
||||
printf(" %s check mydocument.txt.ots # Check proof status\n", prog);
|
||||
printf(" %s verify mydocument.txt mydocument.txt.ots # Verify proof\n", prog);
|
||||
}
|
||||
|
||||
static int do_stamp(const char* file_path, const char* calendar_url,
|
||||
int interval_sec, int max_wait_min) {
|
||||
char auto_file[256] = {0};
|
||||
const char* target_file = file_path;
|
||||
|
||||
/* If no file specified, prompt for text input */
|
||||
if (!target_file) {
|
||||
printf("📝 Enter text to timestamp (press Enter twice to finish):\n\n");
|
||||
|
||||
/* Read multi-line input until empty line */
|
||||
char* content = NULL;
|
||||
size_t content_cap = 0;
|
||||
size_t content_len = 0;
|
||||
char line[1024];
|
||||
int empty_count = 0;
|
||||
|
||||
while (fgets(line, sizeof(line), stdin)) {
|
||||
if (line[0] == '\n') {
|
||||
empty_count++;
|
||||
if (empty_count >= 1 && content_len > 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
empty_count = 0;
|
||||
}
|
||||
|
||||
size_t line_len = strlen(line);
|
||||
if (content_len + line_len + 1 > content_cap) {
|
||||
content_cap = (content_len + line_len + 1) * 2;
|
||||
char* new_content = (char*)realloc(content, content_cap);
|
||||
if (!new_content) {
|
||||
free(content);
|
||||
printf("❌ Out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
content = new_content;
|
||||
}
|
||||
memcpy(content + content_len, line, line_len);
|
||||
content_len += line_len;
|
||||
content[content_len] = '\0';
|
||||
}
|
||||
|
||||
if (!content || content_len == 0) {
|
||||
printf("❌ No text entered.\n");
|
||||
free(content);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Generate a filename based on timestamp */
|
||||
time_t now = time(NULL);
|
||||
struct tm* tm_info = localtime(&now);
|
||||
strftime(auto_file, sizeof(auto_file), "timestamped_%Y%m%d_%H%M%S.txt", tm_info);
|
||||
|
||||
/* Save the text to a file */
|
||||
if (write_file(auto_file, (const unsigned char*)content, content_len) != 0) {
|
||||
printf("❌ Failed to save text to file: %s\n", auto_file);
|
||||
free(content);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("\n💾 Saved text to: %s (%zu bytes)\n", auto_file, content_len);
|
||||
free(content);
|
||||
target_file = auto_file;
|
||||
}
|
||||
|
||||
/* Compute SHA-256 of the file */
|
||||
char digest_hex[65];
|
||||
if (compute_file_sha256_hex(target_file, digest_hex) != 0) {
|
||||
printf("❌ Failed to compute SHA-256 of file: %s\n", target_file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("🔐 SHA-256: %s\n", digest_hex);
|
||||
|
||||
/* Submit to multiple OTS calendars for redundancy */
|
||||
const char* default_calendars[] = {
|
||||
"https://alice.btc.calendar.opentimestamps.org",
|
||||
"https://bob.btc.calendar.opentimestamps.org",
|
||||
"https://finney.calendar.eternitywall.com",
|
||||
"https://btc.calendar.catallaxy.com",
|
||||
};
|
||||
int num_calendars = 4;
|
||||
|
||||
/* If a specific calendar was specified, use only that one */
|
||||
const char** calendars_to_use;
|
||||
int num_to_use;
|
||||
if (strcmp(calendar_url, DEFAULT_CALENDAR) != 0) {
|
||||
calendars_to_use = &calendar_url;
|
||||
num_to_use = 1;
|
||||
} else {
|
||||
calendars_to_use = default_calendars;
|
||||
num_to_use = num_calendars;
|
||||
}
|
||||
|
||||
printf("\n📤 Submitting to %d OpenTimestamps calendar(s)...\n", num_to_use);
|
||||
|
||||
/* Submit to all calendars and create a combined DetachedTimestampFile */
|
||||
char* ots_b64 = nostr_nip03_stamp_with_multiple_calendars(
|
||||
digest_hex, calendars_to_use, num_to_use, 30);
|
||||
if (!ots_b64) {
|
||||
printf("❌ Failed to submit to any calendar.\n");
|
||||
printf(" Check your internet connection and try again.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Save the .ots proof */
|
||||
char ots_path[512];
|
||||
snprintf(ots_path, sizeof(ots_path), "%s.ots", target_file);
|
||||
|
||||
if (save_base64_to_file(ots_path, ots_b64) != 0) {
|
||||
printf("❌ Failed to save .ots proof to: %s\n", ots_path);
|
||||
free(ots_b64);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("✅ Proof saved to: %s\n", ots_path);
|
||||
|
||||
/* Show attestation info - list all pending calendars */
|
||||
char** pending_uris = NULL;
|
||||
int pending_count = nostr_nip03_get_pending_uris(ots_b64, &pending_uris, 16);
|
||||
if (pending_count > 0) {
|
||||
printf(" Pending at %d calendar(s):\n", pending_count);
|
||||
for (int i = 0; i < pending_count; i++) {
|
||||
printf(" • %s\n", pending_uris[i]);
|
||||
free(pending_uris[i]);
|
||||
}
|
||||
free(pending_uris);
|
||||
}
|
||||
|
||||
/* Check if already complete (unlikely but possible) */
|
||||
int complete = nostr_nip03_is_proof_complete(ots_b64);
|
||||
if (complete == 1) {
|
||||
printf("\n🎉 Proof is already complete!\n");
|
||||
free(ots_b64);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Poll for completion */
|
||||
int max_attempts = (max_wait_min * 60) / interval_sec;
|
||||
printf("\n⏳ Waiting for Bitcoin attestation...\n");
|
||||
printf(" Polling every %d seconds (max %d minutes)\n", interval_sec, max_wait_min);
|
||||
printf(" Press Ctrl+C to stop. The .ots file can be checked later with 'check'.\n\n");
|
||||
|
||||
int attempts = 0;
|
||||
while (!complete && attempts < max_attempts) {
|
||||
attempts++;
|
||||
|
||||
time_t now = time(NULL);
|
||||
char time_str[26];
|
||||
ctime_r(&now, time_str);
|
||||
time_str[24] = '\0';
|
||||
|
||||
printf("[%s] Attempt %d/%d: %s\n", time_str, attempts, max_attempts,
|
||||
complete ? "✅ COMPLETE" : "⏳ PENDING");
|
||||
fflush(stdout);
|
||||
|
||||
if (complete) break;
|
||||
|
||||
sleep(interval_sec);
|
||||
|
||||
/* Try to upgrade the proof by walking the tree and fetching upgraded sub-proofs */
|
||||
char* upgraded = nostr_nip03_upgrade_proof_tree(ots_b64, 30);
|
||||
if (upgraded) {
|
||||
free(ots_b64);
|
||||
ots_b64 = upgraded;
|
||||
|
||||
/* Save the upgraded proof */
|
||||
save_base64_to_file(ots_path, ots_b64);
|
||||
|
||||
/* Check if now complete */
|
||||
complete = nostr_nip03_is_proof_complete(ots_b64);
|
||||
}
|
||||
}
|
||||
|
||||
if (complete) {
|
||||
printf("\n🎉 SUCCESS! Proof is complete with a Bitcoin attestation!\n");
|
||||
|
||||
/* Save the final proof */
|
||||
save_base64_to_file(ots_path, ots_b64);
|
||||
printf(" Final proof saved to: %s\n", ots_path);
|
||||
|
||||
/* Show attestation details */
|
||||
int has_bitcoin = 0;
|
||||
uint64_t btc_height = 0;
|
||||
if (nostr_nip03_get_attestation_info(ots_b64, &has_bitcoin, NULL, NULL,
|
||||
&btc_height, NULL, NULL) == 0) {
|
||||
if (has_bitcoin) {
|
||||
printf(" Bitcoin block height: %llu\n", (unsigned long long)btc_height);
|
||||
}
|
||||
}
|
||||
|
||||
/* Verify the proof */
|
||||
uint64_t verify_height = 0;
|
||||
int verify_rc = nostr_nip03_verify_proof(ots_b64, digest_hex, &verify_height, NULL);
|
||||
if (verify_rc == 0) {
|
||||
printf(" ✅ Verified: file digest matches, Bitcoin height=%llu\n",
|
||||
(unsigned long long)verify_height);
|
||||
} else {
|
||||
printf(" ⚠️ Verification returned: %d\n", verify_rc);
|
||||
}
|
||||
} else {
|
||||
printf("\n⏳ Proof is still pending after %d minutes.\n", max_wait_min);
|
||||
printf(" The .ots file has been saved: %s\n", ots_path);
|
||||
printf(" Check again later with: ./ots_tool check %s\n", ots_path);
|
||||
printf(" Or upgrade with: ./ots_tool upgrade %s\n", ots_path);
|
||||
}
|
||||
|
||||
free(ots_b64);
|
||||
return complete ? 0 : 2;
|
||||
}
|
||||
|
||||
static int do_check(const char* ots_path) {
|
||||
printf("🔎 Checking proof: %s\n\n", ots_path);
|
||||
|
||||
char* ots_b64 = read_file_as_base64(ots_path);
|
||||
if (!ots_b64) {
|
||||
printf("❌ Failed to read .ots file: %s\n", ots_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int complete = nostr_nip03_is_proof_complete(ots_b64);
|
||||
|
||||
if (complete == 1) {
|
||||
printf("✅ Proof is COMPLETE (has Bitcoin/Litecoin attestation)\n");
|
||||
} else if (complete == 0) {
|
||||
printf("⏳ Proof is PENDING (no Bitcoin attestation yet)\n");
|
||||
} else {
|
||||
printf("❌ Failed to parse proof (invalid OTS file?)\n");
|
||||
free(ots_b64);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Show detailed attestation info */
|
||||
int has_bitcoin = 0, has_litecoin = 0, has_pending = 0;
|
||||
uint64_t btc_height = 0, ltc_height = 0;
|
||||
|
||||
if (nostr_nip03_get_attestation_info(ots_b64, &has_bitcoin, &has_litecoin, &has_pending,
|
||||
&btc_height, <c_height, NULL) == 0) {
|
||||
if (has_bitcoin) {
|
||||
printf(" ✅ Bitcoin attestation: block height %llu\n", (unsigned long long)btc_height);
|
||||
}
|
||||
if (has_litecoin) {
|
||||
printf(" ✅ Litecoin attestation: block height %llu\n", (unsigned long long)ltc_height);
|
||||
}
|
||||
}
|
||||
|
||||
/* Show all pending calendar URIs */
|
||||
if (has_pending) {
|
||||
char** pending_uris = NULL;
|
||||
int pending_count = nostr_nip03_get_pending_uris(ots_b64, &pending_uris, 16);
|
||||
if (pending_count > 0) {
|
||||
printf(" ⏳ Pending at %d calendar(s):\n", pending_count);
|
||||
for (int i = 0; i < pending_count; i++) {
|
||||
printf(" • %s\n", pending_uris[i]);
|
||||
free(pending_uris[i]);
|
||||
}
|
||||
free(pending_uris);
|
||||
}
|
||||
}
|
||||
|
||||
free(ots_b64);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_verify(const char* file_path, const char* ots_path) {
|
||||
printf("🔍 Verifying proof...\n");
|
||||
printf(" File: %s\n", file_path);
|
||||
printf(" Proof: %s\n\n", ots_path);
|
||||
|
||||
/* Compute SHA-256 of the file */
|
||||
char digest_hex[65];
|
||||
if (compute_file_sha256_hex(file_path, digest_hex) != 0) {
|
||||
printf("❌ Failed to compute SHA-256 of file: %s\n", file_path);
|
||||
return 1;
|
||||
}
|
||||
printf(" File SHA-256: %s\n", digest_hex);
|
||||
|
||||
/* Read the .ots file */
|
||||
char* ots_b64 = read_file_as_base64(ots_path);
|
||||
if (!ots_b64) {
|
||||
printf("❌ Failed to read .ots file: %s\n", ots_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Verify the proof */
|
||||
uint64_t block_height = 0;
|
||||
time_t block_time = 0;
|
||||
int rc = nostr_nip03_verify_proof(ots_b64, digest_hex, &block_height, &block_time);
|
||||
|
||||
switch (rc) {
|
||||
case 0:
|
||||
printf("\n✅ Proof VERIFIED!\n");
|
||||
printf(" Bitcoin block height: %llu\n", (unsigned long long)block_height);
|
||||
printf(" The file's hash is committed in the Bitcoin blockchain.\n");
|
||||
free(ots_b64);
|
||||
return 0;
|
||||
|
||||
case 1:
|
||||
printf("\n⏳ Proof is valid but still PENDING (no Bitcoin attestation yet).\n");
|
||||
printf(" The file digest matches the proof.\n");
|
||||
printf(" Wait for the calendar to commit to the blockchain, then run:\n");
|
||||
printf(" ./ots_tool upgrade %s\n", ots_path);
|
||||
free(ots_b64);
|
||||
return 1;
|
||||
|
||||
case -1:
|
||||
printf("\n❌ Failed to parse OTS proof. The .ots file may be corrupted.\n");
|
||||
free(ots_b64);
|
||||
return 1;
|
||||
|
||||
case -2:
|
||||
printf("\n❌ DIGEST MISMATCH! The proof does not match this file.\n");
|
||||
printf(" The file may have been modified after timestamping.\n");
|
||||
free(ots_b64);
|
||||
return 1;
|
||||
|
||||
default:
|
||||
printf("\n❌ Unknown error: %d\n", rc);
|
||||
free(ots_b64);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int do_upgrade(const char* ots_path, const char* file_path,
|
||||
const char* calendar_url) {
|
||||
printf("⬆️ Upgrading proof: %s\n\n", ots_path);
|
||||
|
||||
char* ots_b64 = read_file_as_base64(ots_path);
|
||||
if (!ots_b64) {
|
||||
printf("❌ Failed to read .ots file: %s\n", ots_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check current status */
|
||||
int was_complete = nostr_nip03_is_proof_complete(ots_b64);
|
||||
if (was_complete == 1) {
|
||||
printf("✅ Proof is already complete! No upgrade needed.\n");
|
||||
free(ots_b64);
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)calendar_url; /* upgrade now uses pending-attestation URIs from proof */
|
||||
(void)file_path;
|
||||
|
||||
printf("📤 Checking pending attestations and fetching upgrades...\n");
|
||||
|
||||
char* upgraded = NULL;
|
||||
/* Use the tree-walking upgrade which correctly queries commitment hashes */
|
||||
upgraded = nostr_nip03_upgrade_proof_tree(ots_b64, 30);
|
||||
|
||||
if (!upgraded) {
|
||||
printf("⏳ No upgrade available yet. The proof is still pending.\n");
|
||||
printf(" Bitcoin attestations typically take 1-12 hours.\n");
|
||||
if (!file_path) {
|
||||
printf(" Tip: provide the original file path to enable digest-based upgrade:\n");
|
||||
printf(" ./ots_tool upgrade %s <original-file>\n", ots_path);
|
||||
}
|
||||
free(ots_b64);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Save the upgraded proof */
|
||||
if (save_base64_to_file(ots_path, upgraded) != 0) {
|
||||
printf("❌ Failed to save upgraded proof.\n");
|
||||
free(ots_b64);
|
||||
free(upgraded);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check if now complete */
|
||||
int complete = nostr_nip03_is_proof_complete(upgraded);
|
||||
if (complete == 1) {
|
||||
printf("✅ Upgrade successful! Proof is now COMPLETE with a Bitcoin attestation.\n");
|
||||
|
||||
int has_bitcoin = 0;
|
||||
uint64_t btc_height = 0;
|
||||
if (nostr_nip03_get_attestation_info(upgraded, &has_bitcoin, NULL, NULL,
|
||||
&btc_height, NULL, NULL) == 0) {
|
||||
if (has_bitcoin) {
|
||||
printf(" Bitcoin block height: %llu\n", (unsigned long long)btc_height);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("⏳ Upgrade received but proof is still pending.\n");
|
||||
printf(" The upgraded proof has been saved. Try again later.\n");
|
||||
}
|
||||
|
||||
printf(" Updated proof saved to: %s\n", ots_path);
|
||||
|
||||
free(ots_b64);
|
||||
free(upgraded);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (nostr_init() != NOSTR_SUCCESS) {
|
||||
fprintf(stderr, "Failed to initialize NOSTR library\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* calendar_url = DEFAULT_CALENDAR;
|
||||
int interval_sec = DEFAULT_INTERVAL_SEC;
|
||||
int max_wait_min = DEFAULT_MAX_WAIT_MIN;
|
||||
|
||||
enum { MODE_NONE, MODE_STAMP, MODE_CHECK, MODE_VERIFY, MODE_UPGRADE } mode = MODE_NONE;
|
||||
const char* arg1 = NULL;
|
||||
const char* arg2 = NULL;
|
||||
|
||||
/* Parse arguments */
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
|
||||
print_usage(argv[0]);
|
||||
nostr_cleanup();
|
||||
return 0;
|
||||
} else if (strcmp(argv[i], "--calendar") == 0 && i + 1 < argc) {
|
||||
calendar_url = argv[++i];
|
||||
} else if (strcmp(argv[i], "--interval") == 0 && i + 1 < argc) {
|
||||
interval_sec = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "--max-wait") == 0 && i + 1 < argc) {
|
||||
max_wait_min = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "stamp") == 0) {
|
||||
mode = MODE_STAMP;
|
||||
} else if (strcmp(argv[i], "check") == 0) {
|
||||
mode = MODE_CHECK;
|
||||
} else if (strcmp(argv[i], "verify") == 0) {
|
||||
mode = MODE_VERIFY;
|
||||
} else if (strcmp(argv[i], "upgrade") == 0) {
|
||||
mode = MODE_UPGRADE;
|
||||
} else if (argv[i][0] != '-') {
|
||||
if (!arg1) {
|
||||
arg1 = argv[i];
|
||||
} else if (!arg2) {
|
||||
arg2 = argv[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int rc = 0;
|
||||
|
||||
switch (mode) {
|
||||
case MODE_STAMP:
|
||||
rc = do_stamp(arg1, calendar_url, interval_sec, max_wait_min);
|
||||
break;
|
||||
|
||||
case MODE_CHECK:
|
||||
if (!arg1) {
|
||||
printf("❌ Missing .ots file path\n");
|
||||
print_usage(argv[0]);
|
||||
rc = 1;
|
||||
} else {
|
||||
rc = do_check(arg1);
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_VERIFY:
|
||||
if (!arg1 || !arg2) {
|
||||
printf("❌ Missing file or .ots path\n");
|
||||
print_usage(argv[0]);
|
||||
rc = 1;
|
||||
} else {
|
||||
rc = do_verify(arg1, arg2);
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_UPGRADE:
|
||||
if (!arg1) {
|
||||
printf("❌ Missing .ots file path\n");
|
||||
print_usage(argv[0]);
|
||||
rc = 1;
|
||||
} else {
|
||||
rc = do_upgrade(arg1, arg2, calendar_url);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
print_usage(argv[0]);
|
||||
rc = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
nostr_cleanup();
|
||||
return rc;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
* NIP-03 OpenTimestamps Example
|
||||
*
|
||||
* This example demonstrates the full NIP-03 timestamping workflow:
|
||||
* 1. Create a Nostr event
|
||||
* 2. Submit the event ID to an OpenTimestamps calendar
|
||||
* 3. Poll for proof completion (Bitcoin attestation)
|
||||
* 4. Create a NIP-03 proof event (kind 1040)
|
||||
* 5. Verify the proof
|
||||
*
|
||||
* Usage:
|
||||
* ./timestamping # Create and timestamp a test event
|
||||
* ./timestamping <event_id> # Timestamp an existing event ID
|
||||
* ./timestamping --verify <ots_b64> # Verify a proof
|
||||
*
|
||||
* Note: Bitcoin attestations typically take 1-12 hours to appear.
|
||||
* The OpenTimestamps calendars commit to the Bitcoin blockchain
|
||||
* periodically, so you may need to wait and poll for completion.
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include "nostr_core/nostr_core.h"
|
||||
#include "nostr_core/nip003.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#define DEFAULT_CALENDAR_URL "https://alice.btc.calendar.opentimestamps.org"
|
||||
#define POLL_INTERVAL_SEC 300 /* 5 minutes */
|
||||
#define MAX_POLL_ATTEMPTS 144 /* 12 hours total */
|
||||
|
||||
static void print_usage(const char* prog_name) {
|
||||
printf("NIP-03 OpenTimestamps Example\n");
|
||||
printf("\n");
|
||||
printf("Usage:\n");
|
||||
printf(" %s Create and timestamp a test event\n", prog_name);
|
||||
printf(" %s <event_id> Timestamp an existing event ID (64-char hex)\n", prog_name);
|
||||
printf(" %s --verify <ots_b64> Verify a base64-encoded OTS proof\n", prog_name);
|
||||
printf(" %s --check <ots_b64> Check if a proof is complete\n", prog_name);
|
||||
printf("\n");
|
||||
printf("Options:\n");
|
||||
printf(" --calendar <url> Use a specific OTS calendar URL\n");
|
||||
printf(" --interval <seconds> Poll interval in seconds (default: %d)\n", POLL_INTERVAL_SEC);
|
||||
printf(" --max-attempts <n> Max poll attempts (default: %d)\n", MAX_POLL_ATTEMPTS);
|
||||
printf("\n");
|
||||
printf("Common calendar URLs:\n");
|
||||
printf(" https://alice.btc.calendar.opentimestamps.org\n");
|
||||
printf(" https://bob.btc.calendar.opentimestamps.org\n");
|
||||
printf(" https://finney.calendar.eternitywall.com\n");
|
||||
}
|
||||
|
||||
static void print_attestation_info(const char* ots_b64) {
|
||||
int has_bitcoin = 0, has_litecoin = 0, has_pending = 0;
|
||||
uint64_t btc_height = 0, ltc_height = 0;
|
||||
char* pending_uri = NULL;
|
||||
|
||||
if (nostr_nip03_get_attestation_info(ots_b64, &has_bitcoin, &has_litecoin, &has_pending,
|
||||
&btc_height, <c_height, &pending_uri) != 0) {
|
||||
printf(" ⚠️ Failed to parse attestation info\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (has_bitcoin) {
|
||||
printf(" ✅ Bitcoin attestation: block height %llu\n", (unsigned long long)btc_height);
|
||||
}
|
||||
if (has_litecoin) {
|
||||
printf(" ✅ Litecoin attestation: block height %llu\n", (unsigned long long)ltc_height);
|
||||
}
|
||||
if (has_pending) {
|
||||
if (pending_uri) {
|
||||
printf(" ⏳ Pending at: %s\n", pending_uri);
|
||||
free(pending_uri);
|
||||
}
|
||||
}
|
||||
if (!has_bitcoin && !has_litecoin && !has_pending) {
|
||||
printf(" ⚠️ No attestations found\n");
|
||||
}
|
||||
}
|
||||
|
||||
static int do_timestamp(const char* event_id_hex, const char* calendar_url,
|
||||
int poll_interval, int max_attempts) {
|
||||
printf("📅 NIP-03 Timestamping\n");
|
||||
printf(" Event ID: %s\n", event_id_hex);
|
||||
printf(" Calendar: %s\n", calendar_url);
|
||||
printf("\n");
|
||||
|
||||
/* Step 1: Submit to calendar */
|
||||
printf("📤 Submitting to OpenTimestamps calendar...\n");
|
||||
char* ots_b64 = nostr_nip03_request_timestamp(event_id_hex, calendar_url, 30);
|
||||
if (!ots_b64) {
|
||||
printf("❌ Failed to submit to calendar.\n");
|
||||
printf(" Check your internet connection and the calendar URL.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("✅ Initial proof received.\n");
|
||||
print_attestation_info(ots_b64);
|
||||
printf("\n");
|
||||
|
||||
/* Step 2: Poll for completion */
|
||||
printf("⏳ Polling for Bitcoin attestation (every %d seconds, max %d attempts)...\n",
|
||||
poll_interval, max_attempts);
|
||||
|
||||
int complete = 0;
|
||||
int attempts = 0;
|
||||
|
||||
while (!complete && attempts < max_attempts) {
|
||||
attempts++;
|
||||
complete = nostr_nip03_is_proof_complete(ots_b64);
|
||||
|
||||
time_t now = time(NULL);
|
||||
char time_str[26];
|
||||
ctime_r(&now, time_str);
|
||||
time_str[24] = '\0';
|
||||
|
||||
printf("[%s] Attempt %d/%d: %s\n", time_str, attempts, max_attempts,
|
||||
complete ? "✅ COMPLETE" : "⏳ PENDING");
|
||||
|
||||
if (!complete) {
|
||||
sleep(poll_interval);
|
||||
|
||||
/* Try to upgrade the proof */
|
||||
char* upgraded = nostr_nip03_upgrade_proof(ots_b64, calendar_url, 30);
|
||||
if (upgraded) {
|
||||
free(ots_b64);
|
||||
ots_b64 = upgraded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (complete) {
|
||||
printf("\n🎉 SUCCESS! The proof is now complete with a Bitcoin attestation.\n");
|
||||
print_attestation_info(ots_b64);
|
||||
|
||||
/* Verify the proof */
|
||||
uint64_t block_height = 0;
|
||||
int verify_rc = nostr_nip03_verify_proof(ots_b64, event_id_hex, &block_height, NULL);
|
||||
if (verify_rc == 0) {
|
||||
printf(" ✅ Proof verified: digest matches, Bitcoin height=%llu\n",
|
||||
(unsigned long long)block_height);
|
||||
} else {
|
||||
printf(" ⚠️ Proof verification returned: %d\n", verify_rc);
|
||||
}
|
||||
|
||||
/* Create the NIP-03 proof event */
|
||||
unsigned char private_key[32];
|
||||
unsigned char public_key[32];
|
||||
nostr_generate_keypair(private_key, public_key);
|
||||
|
||||
cJSON* proof_event = nostr_nip03_create_proof_event(event_id_hex, 1, ots_b64, NULL, private_key);
|
||||
if (proof_event) {
|
||||
char* json = cJSON_Print(proof_event);
|
||||
printf("\n📄 NIP-03 Proof Event (kind 1040):\n%s\n", json);
|
||||
free(json);
|
||||
cJSON_Delete(proof_event);
|
||||
}
|
||||
|
||||
/* Print the base64 OTS data for storage */
|
||||
printf("\n📦 OTS proof (base64, save this):\n%s\n", ots_b64);
|
||||
} else {
|
||||
printf("\n⏳ Proof is still pending after %d attempts.\n", attempts);
|
||||
printf(" Bitcoin attestations can take several hours.\n");
|
||||
printf(" Save the OTS proof and check again later:\n%s\n", ots_b64);
|
||||
}
|
||||
|
||||
free(ots_b64);
|
||||
return complete ? 0 : 2;
|
||||
}
|
||||
|
||||
static int do_verify(const char* ots_b64, const char* target_digest_hex) {
|
||||
printf("🔍 Verifying OTS proof...\n\n");
|
||||
|
||||
uint64_t block_height = 0;
|
||||
time_t block_time = 0;
|
||||
|
||||
int rc = nostr_nip03_verify_proof(ots_b64, target_digest_hex, &block_height, &block_time);
|
||||
|
||||
switch (rc) {
|
||||
case 0:
|
||||
printf("✅ Proof verified!\n");
|
||||
printf(" Bitcoin block height: %llu\n", (unsigned long long)block_height);
|
||||
print_attestation_info(ots_b64);
|
||||
return 0;
|
||||
case 1:
|
||||
printf("⏳ Proof is valid but has no Bitcoin attestation (still pending).\n");
|
||||
print_attestation_info(ots_b64);
|
||||
return 1;
|
||||
case -1:
|
||||
printf("❌ Failed to parse OTS proof.\n");
|
||||
return 1;
|
||||
case -2:
|
||||
printf("❌ Digest mismatch! The proof does not match the expected digest.\n");
|
||||
return 1;
|
||||
default:
|
||||
printf("❌ Unknown error: %d\n", rc);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int do_check(const char* ots_b64) {
|
||||
printf("🔎 Checking OTS proof status...\n\n");
|
||||
|
||||
int complete = nostr_nip03_is_proof_complete(ots_b64);
|
||||
|
||||
if (complete == 1) {
|
||||
printf("✅ Proof is COMPLETE (has Bitcoin/Litecoin attestation)\n");
|
||||
} else if (complete == 0) {
|
||||
printf("⏳ Proof is PENDING (no Bitcoin attestation yet)\n");
|
||||
} else {
|
||||
printf("❌ Failed to parse proof (error)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
print_attestation_info(ots_b64);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (nostr_init() != NOSTR_SUCCESS) {
|
||||
fprintf(stderr, "Failed to initialize NOSTR library\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* calendar_url = DEFAULT_CALENDAR_URL;
|
||||
int poll_interval = POLL_INTERVAL_SEC;
|
||||
int max_attempts = MAX_POLL_ATTEMPTS;
|
||||
const char* event_id = NULL;
|
||||
const char* ots_b64 = NULL;
|
||||
const char* verify_digest = NULL;
|
||||
|
||||
enum { MODE_TIMESTAMP, MODE_VERIFY, MODE_CHECK } mode = MODE_TIMESTAMP;
|
||||
|
||||
/* Parse arguments */
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
|
||||
print_usage(argv[0]);
|
||||
nostr_cleanup();
|
||||
return 0;
|
||||
} else if (strcmp(argv[i], "--verify") == 0) {
|
||||
mode = MODE_VERIFY;
|
||||
/* OTS data is provided as a positional argument */
|
||||
} else if (strcmp(argv[i], "--check") == 0) {
|
||||
mode = MODE_CHECK;
|
||||
/* OTS data is provided as a positional argument */
|
||||
} else if (strcmp(argv[i], "--calendar") == 0 && i + 1 < argc) {
|
||||
calendar_url = argv[++i];
|
||||
} else if (strcmp(argv[i], "--interval") == 0 && i + 1 < argc) {
|
||||
poll_interval = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "--max-attempts") == 0 && i + 1 < argc) {
|
||||
max_attempts = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "--digest") == 0 && i + 1 < argc) {
|
||||
verify_digest = argv[++i];
|
||||
} else if (argv[i][0] != '-' && !event_id && !ots_b64) {
|
||||
if (mode == MODE_VERIFY || mode == MODE_CHECK) {
|
||||
if (!ots_b64) ots_b64 = argv[i];
|
||||
} else {
|
||||
event_id = argv[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int rc = 0;
|
||||
|
||||
switch (mode) {
|
||||
case MODE_TIMESTAMP:
|
||||
if (!event_id) {
|
||||
/* Create a test event */
|
||||
printf("🧪 Creating a test event to timestamp...\n");
|
||||
unsigned char private_key[32];
|
||||
unsigned char public_key[32];
|
||||
nostr_generate_keypair(private_key, public_key);
|
||||
|
||||
char content[128];
|
||||
snprintf(content, sizeof(content), "NIP-03 timestamp test at %ld", time(NULL));
|
||||
|
||||
cJSON* event = nostr_create_and_sign_event(1, content, NULL, private_key, 0);
|
||||
if (!event) {
|
||||
printf("❌ Failed to create test event\n");
|
||||
nostr_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
cJSON* id_item = cJSON_GetObjectItem(event, "id");
|
||||
if (!id_item || !cJSON_IsString(id_item)) {
|
||||
printf("❌ Failed to get event ID\n");
|
||||
cJSON_Delete(event);
|
||||
nostr_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* event_json = cJSON_Print(event);
|
||||
printf("📄 Test event:\n%s\n\n", event_json);
|
||||
free(event_json);
|
||||
|
||||
rc = do_timestamp(id_item->valuestring, calendar_url, poll_interval, max_attempts);
|
||||
cJSON_Delete(event);
|
||||
} else {
|
||||
rc = do_timestamp(event_id, calendar_url, poll_interval, max_attempts);
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_VERIFY:
|
||||
if (!ots_b64) {
|
||||
printf("❌ Missing OTS proof (base64)\n");
|
||||
print_usage(argv[0]);
|
||||
rc = 1;
|
||||
} else {
|
||||
rc = do_verify(ots_b64, verify_digest);
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_CHECK:
|
||||
if (!ots_b64) {
|
||||
printf("❌ Missing OTS proof (base64)\n");
|
||||
print_usage(argv[0]);
|
||||
rc = 1;
|
||||
} else {
|
||||
rc = do_check(ots_b64);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
nostr_cleanup();
|
||||
return rc;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -120,6 +120,20 @@ int nsigner_client_compute_body_hash_hex(const cJSON* params, char out_hash_hex[
|
||||
#endif
|
||||
```
|
||||
|
||||
### n_signer wire methods
|
||||
|
||||
The remote signer backend uses n_signer's role-based Nostr methods:
|
||||
|
||||
- `nostr_get_public_key`
|
||||
- `nostr_sign_event`
|
||||
- `nostr_nip04_encrypt` / `nostr_nip04_decrypt`
|
||||
- `nostr_nip44_encrypt` / `nostr_nip44_decrypt`
|
||||
|
||||
These wire names are distinct from both the public `nostr_signer_*` C API and the
|
||||
unprefixed NIP-46 method names. In particular, n_signer's unprefixed `get_public_key`
|
||||
is algorithm-based; this library uses `nostr_get_public_key` because remote signer
|
||||
factories select keys by `role` or `nostr_index`.
|
||||
|
||||
### Auth and framing notes
|
||||
|
||||
- Framing is 4-byte big-endian payload length + JSON payload.
|
||||
|
||||
@@ -1378,28 +1378,72 @@ cJSON** nostr_relay_pool_query_sync(
|
||||
int connected_count = 0;
|
||||
|
||||
for (int i = 0; i < relay_count && connected_count < NOSTR_POOL_MAX_RELAYS; i++) {
|
||||
relay_connection_t* relay = find_relay_by_url(pool, relay_urls[i]);
|
||||
relay_connection_t* relay = NULL;
|
||||
int ensure_rc = -1;
|
||||
|
||||
query_sync_debug_log("connect_step_start idx=%d/%d relay=%s connected_so_far=%d",
|
||||
i + 1,
|
||||
relay_count,
|
||||
relay_urls[i] ? relay_urls[i] : "(null)",
|
||||
connected_count);
|
||||
|
||||
relay = find_relay_by_url(pool, relay_urls[i]);
|
||||
query_sync_debug_log("find_relay idx=%d relay=%s found=%s",
|
||||
i + 1,
|
||||
relay_urls[i] ? relay_urls[i] : "(null)",
|
||||
relay ? "yes" : "no");
|
||||
|
||||
if (!relay) {
|
||||
// Add relay if it doesn't exist
|
||||
if (nostr_relay_pool_add_relay(pool, relay_urls[i]) == NOSTR_SUCCESS) {
|
||||
int add_rc = nostr_relay_pool_add_relay(pool, relay_urls[i]);
|
||||
query_sync_debug_log("add_relay idx=%d relay=%s rc=%d",
|
||||
i + 1,
|
||||
relay_urls[i] ? relay_urls[i] : "(null)",
|
||||
add_rc);
|
||||
if (add_rc == NOSTR_SUCCESS) {
|
||||
relay = find_relay_by_url(pool, relay_urls[i]);
|
||||
query_sync_debug_log("find_relay_after_add idx=%d relay=%s found=%s",
|
||||
i + 1,
|
||||
relay_urls[i] ? relay_urls[i] : "(null)",
|
||||
relay ? "yes" : "no");
|
||||
}
|
||||
}
|
||||
|
||||
if (relay && ensure_relay_connection(relay) == 0) {
|
||||
|
||||
if (!relay) {
|
||||
query_sync_debug_log("connect_step_skip idx=%d relay=%s reason=no_relay_object",
|
||||
i + 1,
|
||||
relay_urls[i] ? relay_urls[i] : "(null)");
|
||||
continue;
|
||||
}
|
||||
|
||||
query_sync_debug_log("ensure_connection_begin idx=%d relay=%s", i + 1, relay->url);
|
||||
ensure_rc = ensure_relay_connection(relay);
|
||||
query_sync_debug_log("ensure_connection_end idx=%d relay=%s rc=%d ws_client=%s state=%d",
|
||||
i + 1,
|
||||
relay->url,
|
||||
ensure_rc,
|
||||
relay->ws_client ? "set" : "null",
|
||||
(int)relay->status);
|
||||
|
||||
if (ensure_rc == 0) {
|
||||
connected_relays[connected_count++] = relay;
|
||||
|
||||
|
||||
// Add subscription timing for latency measurement
|
||||
add_subscription_timing(relay, subscription_id);
|
||||
|
||||
|
||||
// Send REQ message
|
||||
int send_rc = nostr_relay_send_req(relay->ws_client, subscription_id, filter);
|
||||
query_sync_debug_log("send_req relay=%s sub_id=%s rc=%d", relay->url, subscription_id, send_rc);
|
||||
query_sync_debug_log("send_req relay=%s sub_id=%s rc=%d connected_count=%d", relay->url, subscription_id, send_rc, connected_count);
|
||||
if (send_rc < 0) {
|
||||
// Remove timing if send failed
|
||||
remove_subscription_timing(relay, subscription_id);
|
||||
connected_count--; // Don't count failed connections
|
||||
query_sync_debug_log("send_req_failed relay=%s sub_id=%s connected_count=%d", relay->url, subscription_id, connected_count);
|
||||
}
|
||||
} else {
|
||||
query_sync_debug_log("connect_step_skip idx=%d relay=%s reason=ensure_failed rc=%d",
|
||||
i + 1,
|
||||
relay->url,
|
||||
ensure_rc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1417,11 +1461,17 @@ cJSON** nostr_relay_pool_query_sync(
|
||||
query_sync_debug_log("query_loop_start sub_id=%s timeout_ms=%d timeout_seconds=%d connected_relays=%d", subscription_id, timeout_ms, timeout_seconds, connected_count);
|
||||
|
||||
while (time(NULL) - start_time < timeout_seconds && eose_count < connected_count) {
|
||||
query_sync_debug_log("query_loop_tick sub_id=%s elapsed_s=%d timeout_s=%d eose=%d/%d",
|
||||
subscription_id,
|
||||
(int)(time(NULL) - start_time),
|
||||
timeout_seconds,
|
||||
eose_count,
|
||||
connected_count);
|
||||
for (int i = 0; i < connected_count; i++) {
|
||||
relay_connection_t* relay = connected_relays[i];
|
||||
|
||||
char buffer[65536];
|
||||
int len = nostr_ws_receive(relay->ws_client, buffer, sizeof(buffer) - 1, 100);
|
||||
char buffer[262144];
|
||||
int len = nostr_ws_receive(relay->ws_client, buffer, sizeof(buffer) - 1, 1000);
|
||||
query_sync_debug_log("receive relay=%s len=%d", relay->url, len);
|
||||
if (len > 0) {
|
||||
buffer[len] = '\0';
|
||||
|
||||
@@ -195,9 +195,10 @@ cJSON** synchronous_query_relays_with_progress(
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to receive message (short timeout to keep UI responsive)
|
||||
char buffer[8192];
|
||||
int len = nostr_ws_receive(relay->client, buffer, sizeof(buffer)-1, 50);
|
||||
// Try to receive message (1000ms timeout to allow relay time
|
||||
// to respond — matches nostr_relay_pool_query_sync behavior)
|
||||
char buffer[262144];
|
||||
int len = nostr_ws_receive(relay->client, buffer, sizeof(buffer)-1, 1000);
|
||||
|
||||
if (len > 0) {
|
||||
buffer[len] = '\0';
|
||||
@@ -322,6 +323,23 @@ cJSON** synchronous_query_relays_with_progress(
|
||||
nostr_ws_close(relay->client);
|
||||
relay->client = NULL;
|
||||
}
|
||||
} else if (msg_type && (strcmp(msg_type, "NOTICE") == 0 ||
|
||||
strcmp(msg_type, "CLOSED") == 0)) {
|
||||
/* Capture NOTICE and CLOSED messages from the relay.
|
||||
* These often contain auth-required or restriction
|
||||
* notices. Pass the message content to the callback. */
|
||||
const char* notice_msg = "";
|
||||
if (cJSON_IsArray(parsed) && cJSON_GetArraySize(parsed) >= 2) {
|
||||
cJSON* msg_json = cJSON_GetArrayItem(parsed, 1);
|
||||
if (msg_json && cJSON_IsString(msg_json)) {
|
||||
notice_msg = cJSON_GetStringValue(msg_json);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(relay->url, msg_type, notice_msg,
|
||||
relay->events_received, relay_count,
|
||||
completed_relays, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
if (msg_type) free(msg_type);
|
||||
@@ -580,7 +598,7 @@ publish_result_t* synchronous_publish_event_with_progress(
|
||||
}
|
||||
|
||||
// Try to receive message (short timeout to keep UI responsive)
|
||||
char buffer[8192];
|
||||
char buffer[262144];
|
||||
int len = nostr_ws_receive(relay->client, buffer, sizeof(buffer)-1, 50);
|
||||
|
||||
if (len > 0) {
|
||||
|
||||
+1348
-32
File diff suppressed because it is too large
Load Diff
+188
-3
@@ -6,7 +6,9 @@
|
||||
#define NOSTR_NIP03_H
|
||||
|
||||
#include "nostr_common.h"
|
||||
#include "nostr_signer.h"
|
||||
#include "cjson/cJSON.h"
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -14,6 +16,10 @@ extern "C" {
|
||||
|
||||
#define NOSTR_KIND_OT_PROOF 1040
|
||||
|
||||
/* Default OTS calendars for multi-calendar stamping */
|
||||
#define NOSTR_OTS_DEFAULT_CALENDAR_COUNT 4
|
||||
extern const char* NOSTR_OTS_DEFAULT_CALENDARS[NOSTR_OTS_DEFAULT_CALENDAR_COUNT];
|
||||
|
||||
/**
|
||||
* Create a NIP-03 OpenTimestamps proof event (kind 1040)
|
||||
*
|
||||
@@ -30,6 +36,22 @@ cJSON* nostr_nip03_create_proof_event(const char* target_event_id,
|
||||
const char* relay_url,
|
||||
const unsigned char* private_key);
|
||||
|
||||
/**
|
||||
* Create a NIP-03 OpenTimestamps proof event using a signer (kind 1040)
|
||||
*
|
||||
* @param target_event_id The ID of the event being timestamped (hex string)
|
||||
* @param target_event_kind The kind of the event being timestamped
|
||||
* @param ots_data_base64 Base64 encoded .ots file content
|
||||
* @param relay_url Optional relay URL where the target event can be found
|
||||
* @param signer Signer handle for signing the proof event
|
||||
* @return cJSON* The signed proof event, or NULL on error
|
||||
*/
|
||||
cJSON* nostr_nip03_create_proof_event_with_signer(const char* target_event_id,
|
||||
int target_event_kind,
|
||||
const char* ots_data_base64,
|
||||
const char* relay_url,
|
||||
nostr_signer_t* signer);
|
||||
|
||||
/**
|
||||
* Request a timestamp for an event ID from an OpenTimestamps calendar
|
||||
*
|
||||
@@ -46,25 +68,188 @@ char* nostr_nip03_request_timestamp(const char* event_id_hex,
|
||||
int timeout_seconds);
|
||||
|
||||
/**
|
||||
* Check if an OTS proof is complete (has a Bitcoin attestation)
|
||||
* Check if an OTS proof is complete (has a Bitcoin or Litecoin attestation)
|
||||
*
|
||||
* Parses the OTS binary file format and searches for a Bitcoin block header
|
||||
* attestation (tag 0588960d73d71901) or Litecoin attestation (tag 06856e0d73d71901).
|
||||
* A proof with only pending attestations is not yet complete.
|
||||
*
|
||||
* @param ots_data_base64 Base64 encoded .ots file content
|
||||
* @return int 1 if complete, 0 if pending, -1 on error
|
||||
* @return int 1 if complete (has Bitcoin/Litecoin attestation), 0 if pending, -1 on error
|
||||
*/
|
||||
int nostr_nip03_is_proof_complete(const char* ots_data_base64);
|
||||
|
||||
/**
|
||||
* Get detailed attestation information from an OTS proof
|
||||
*
|
||||
* Parses the OTS file and extracts information about all attestations found.
|
||||
*
|
||||
* @param ots_data_base64 Base64 encoded .ots file content
|
||||
* @param has_bitcoin Output: 1 if a Bitcoin attestation is present (optional, NULL to skip)
|
||||
* @param has_litecoin Output: 1 if a Litecoin attestation is present (optional, NULL to skip)
|
||||
* @param has_pending Output: 1 if any pending attestations are present (optional, NULL to skip)
|
||||
* @param bitcoin_height Output: Bitcoin block height (optional, NULL to skip)
|
||||
* @param litecoin_height Output: Litecoin block height (optional, NULL to skip)
|
||||
* @param pending_uri_out Output: First pending calendar URI (optional, NULL to skip, caller must free)
|
||||
* @return int 0 on success, -1 on parse error
|
||||
*/
|
||||
int nostr_nip03_get_attestation_info(const char* ots_data_base64,
|
||||
int* has_bitcoin,
|
||||
int* has_litecoin,
|
||||
int* has_pending,
|
||||
uint64_t* bitcoin_height,
|
||||
uint64_t* litecoin_height,
|
||||
char** pending_uri_out);
|
||||
|
||||
/**
|
||||
* Upgrade an OTS proof by fetching missing attestations from a calendar
|
||||
*
|
||||
* Sends the current proof to the calendar's /upgrade endpoint and returns
|
||||
* the updated proof. The calendar may return the same proof if no new
|
||||
* attestations are available, or an upgraded proof with Bitcoin/Litecoin
|
||||
* attestations.
|
||||
*
|
||||
* @param ots_data_base64 Current base64 encoded .ots file content
|
||||
* @param calendar_url The OTS calendar URL
|
||||
* @param timeout_seconds Request timeout
|
||||
* @return char* New base64 encoded .ots data, or NULL on error/no change (caller must free)
|
||||
* @return char* New base64 encoded .ots data, or NULL on error (caller must free)
|
||||
*/
|
||||
char* nostr_nip03_upgrade_proof(const char* ots_data_base64,
|
||||
const char* calendar_url,
|
||||
int timeout_seconds);
|
||||
|
||||
/**
|
||||
* Upgrade an OTS proof by re-submitting the digest to a calendar
|
||||
*
|
||||
* This is the preferred upgrade method for raw timestamp proofs (returned by
|
||||
* the calendar /digest endpoint) which don't contain the file digest.
|
||||
* Re-submits the digest to the calendar, which returns the current proof
|
||||
* that may include new Bitcoin attestations.
|
||||
*
|
||||
* @param digest_hex The 64-char hex SHA-256 digest of the timestamped data
|
||||
* @param calendar_url The OTS calendar URL
|
||||
* @param timeout_seconds Request timeout
|
||||
* @return char* New base64 encoded .ots data, or NULL on error (caller must free)
|
||||
*/
|
||||
char* nostr_nip03_upgrade_proof_with_digest(const char* digest_hex,
|
||||
const char* calendar_url,
|
||||
int timeout_seconds);
|
||||
|
||||
/**
|
||||
* Upgrade an OTS proof by walking the proof tree and fetching upgraded sub-proofs
|
||||
*
|
||||
* This is the correct upgrade mechanism, matching the reference ots client:
|
||||
* 1. Parses the proof tree
|
||||
* 2. Walks the tree computing intermediate commitment hashes
|
||||
* 3. For each PendingAttestation, calls GET /timestamp/<commitment-hash>
|
||||
* 4. If the calendar returns a proof with a Bitcoin attestation, splices it in
|
||||
*
|
||||
* @param ots_data_base64 Base64 encoded DetachedTimestampFile
|
||||
* @param timeout_seconds Per-request timeout
|
||||
* @return char* New base64 encoded upgraded proof, or NULL if no upgrade available (caller must free)
|
||||
*/
|
||||
char* nostr_nip03_upgrade_proof_tree(const char* ots_data_base64,
|
||||
int timeout_seconds);
|
||||
|
||||
/**
|
||||
* Get all pending calendar URIs from an OTS proof
|
||||
*
|
||||
* @param ots_data_base64 Base64 encoded .ots file content
|
||||
* @param uris_out Array of char* pointers (caller must free each string and the array)
|
||||
* @param max_uris Maximum number of URIs to return
|
||||
* @return int Number of pending URIs found, or -1 on error
|
||||
*/
|
||||
int nostr_nip03_get_pending_uris(const char* ots_data_base64,
|
||||
char*** uris_out,
|
||||
int max_uris);
|
||||
|
||||
/**
|
||||
* Create a full DetachedTimestampFile (.ots) from a digest
|
||||
*
|
||||
* Wraps a SHA-256 digest in the OTS DetachedTimestampFile format with the
|
||||
* proper header magic, version, hash op, and digest. This is the standard
|
||||
* .ots file format that can be verified by the `ots` command-line tool.
|
||||
*
|
||||
* @param digest_hex The 64-char hex SHA-256 digest
|
||||
* @return char* Base64 encoded DetachedTimestampFile, or NULL on error (caller must free)
|
||||
*/
|
||||
char* nostr_nip03_create_ots_file(const char* digest_hex);
|
||||
|
||||
/**
|
||||
* Submit a digest to multiple calendars and create a combined proof
|
||||
*
|
||||
* Submits the digest to each calendar, collects all the returned timestamps,
|
||||
* and combines them into a single DetachedTimestampFile with a fork operation.
|
||||
* This is the recommended way to timestamp data — using multiple calendars
|
||||
* provides redundancy.
|
||||
*
|
||||
* @param digest_hex The 64-char hex SHA-256 digest
|
||||
* @param calendar_urls Array of calendar URLs
|
||||
* @param calendar_count Number of calendars
|
||||
* @param timeout_seconds Per-request timeout
|
||||
* @return char* Base64 encoded DetachedTimestampFile with all calendar proofs, or NULL on error
|
||||
*/
|
||||
char* nostr_nip03_stamp_with_multiple_calendars(const char* digest_hex,
|
||||
const char** calendar_urls,
|
||||
int calendar_count,
|
||||
int timeout_seconds);
|
||||
|
||||
/**
|
||||
* Request a timestamp for an event ID from multiple OTS calendars
|
||||
*
|
||||
* Submits the event ID to multiple calendars and combines the results into a
|
||||
* single DetachedTimestampFile. Uses the default calendars if none specified.
|
||||
*
|
||||
* @param event_id_hex The event ID to timestamp (64-char hex string)
|
||||
* @param calendar_urls Array of calendar URLs (NULL to use defaults)
|
||||
* @param calendar_count Number of calendars (0 to use defaults)
|
||||
* @param timeout_seconds Per-request timeout
|
||||
* @return char* Base64 encoded DetachedTimestampFile, or NULL on error (caller must free)
|
||||
*/
|
||||
char* nostr_nip03_request_timestamp_multi(const char* event_id_hex,
|
||||
const char** calendar_urls,
|
||||
int calendar_count,
|
||||
int timeout_seconds);
|
||||
|
||||
/**
|
||||
* Upgrade an OTS proof by re-submitting to multiple calendars
|
||||
*
|
||||
* Re-submits the digest to all specified calendars (or defaults) and returns
|
||||
* a new combined proof. The proof may now contain Bitcoin attestations if
|
||||
* any calendar has committed since the original submission.
|
||||
*
|
||||
* @param digest_hex The 64-char hex SHA-256 digest
|
||||
* @param calendar_urls Array of calendar URLs (NULL to use defaults)
|
||||
* @param calendar_count Number of calendars (0 to use defaults)
|
||||
* @param timeout_seconds Per-request timeout
|
||||
* @return char* New base64 encoded DetachedTimestampFile, or NULL on error (caller must free)
|
||||
*/
|
||||
char* nostr_nip03_upgrade_proof_multi(const char* digest_hex,
|
||||
const char** calendar_urls,
|
||||
int calendar_count,
|
||||
int timeout_seconds);
|
||||
|
||||
/**
|
||||
* Verify an OTS proof structurally
|
||||
*
|
||||
* Parses the OTS file, optionally verifies the file digest matches the
|
||||
* expected target, and checks for a Bitcoin block header attestation.
|
||||
*
|
||||
* Note: Full on-chain verification (checking the Bitcoin block header's
|
||||
* merkle root) requires fetching the block header from a blockchain API.
|
||||
* This function performs structural verification only.
|
||||
*
|
||||
* @param ots_data_base64 Base64 encoded .ots file content
|
||||
* @param target_digest_hex Expected SHA256 digest of the timestamped data (64-char hex, or NULL to skip)
|
||||
* @param block_height_out Output: Bitcoin block height (optional, NULL to skip)
|
||||
* @param block_time_out Output: Block time (optional, NULL to skip, always 0 for structural verification)
|
||||
* @return int 0 on success (verified), 1 if no Bitcoin attestation found, -1 on parse error, -2 on digest mismatch
|
||||
*/
|
||||
int nostr_nip03_verify_proof(const char* ots_data_base64,
|
||||
const char* target_digest_hex,
|
||||
uint64_t* block_height_out,
|
||||
time_t* block_time_out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#define NOSTR_ERROR_NIP05_NAME_NOT_FOUND -19
|
||||
#define NOSTR_ERROR_NIP05_PUBKEY_MISMATCH -20
|
||||
#define NOSTR_ERROR_EVENT_INVALID_STRUCTURE -30
|
||||
/* nsigner remote backend errors */
|
||||
#define NOSTR_ERROR_NSIGNER_POLICY_DENIED -2001
|
||||
#define NOSTR_ERROR_NSIGNER_INDEX_NOT_ALLOWED -2002
|
||||
#define NOSTR_ERROR_EVENT_INVALID_ID -31
|
||||
#define NOSTR_ERROR_EVENT_INVALID_PUBKEY -32
|
||||
#define NOSTR_ERROR_EVENT_INVALID_SIGNATURE -33
|
||||
|
||||
+13
-2
@@ -2,10 +2,10 @@
|
||||
#define NOSTR_CORE_H
|
||||
|
||||
// Version information (auto-updated by increment_and_push.sh)
|
||||
#define VERSION "v0.6.5"
|
||||
#define VERSION "v0.6.11"
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 6
|
||||
#define VERSION_PATCH 5
|
||||
#define VERSION_PATCH 11
|
||||
|
||||
/*
|
||||
* NOSTR Core Library - Complete API Reference
|
||||
@@ -304,6 +304,17 @@ cJSON** nostr_relay_pool_query_sync(
|
||||
cJSON* filter,
|
||||
int* event_count,
|
||||
int timeout_ms);
|
||||
// Same as above but also reports whether all relays sent EOSE (vs timed out).
|
||||
// out_got_eose is set to 1 if all connected relays sent EOSE, 0 if any timed
|
||||
// out. May be NULL if the caller doesn't care.
|
||||
cJSON** nostr_relay_pool_query_sync_with_eose(
|
||||
nostr_relay_pool_t* pool,
|
||||
const char** relay_urls,
|
||||
int relay_count,
|
||||
cJSON* filter,
|
||||
int* event_count,
|
||||
int timeout_ms,
|
||||
int* out_got_eose);
|
||||
cJSON* nostr_relay_pool_get_event(
|
||||
nostr_relay_pool_t* pool,
|
||||
const char** relay_urls,
|
||||
|
||||
+167
-10
@@ -30,6 +30,8 @@ struct nostr_signer {
|
||||
struct {
|
||||
nsigner_client_t* client;
|
||||
char role[64];
|
||||
int nostr_index; /* -1 = not set; when set, overrides role */
|
||||
int has_nostr_index; /* 1 if nostr_index is set */
|
||||
} remote;
|
||||
#endif
|
||||
} u;
|
||||
@@ -282,9 +284,29 @@ static int signer_local_nip44_decrypt(nostr_signer_t* signer,
|
||||
return NOSTR_SUCCESS;
|
||||
}
|
||||
|
||||
static int signer_local_derive_hmac(nostr_signer_t* signer,
|
||||
const char* data,
|
||||
char out_digest_hex[65]) {
|
||||
unsigned char mac[32];
|
||||
|
||||
if (!signer || !data || !out_digest_hex) {
|
||||
return NOSTR_ERROR_INVALID_INPUT;
|
||||
}
|
||||
|
||||
if (nostr_hmac_sha256(signer->u.local.private_key, 32,
|
||||
(const unsigned char*)data, strlen(data),
|
||||
mac) != 0) {
|
||||
return NOSTR_ERROR_CRYPTO_FAILED;
|
||||
}
|
||||
|
||||
nostr_bytes_to_hex(mac, 32, out_digest_hex);
|
||||
memset(mac, 0, sizeof(mac));
|
||||
return NOSTR_SUCCESS;
|
||||
}
|
||||
|
||||
#if defined(NOSTR_ENABLE_NSIGNER_CLIENT)
|
||||
|
||||
static cJSON* signer_remote_params_with_selector(cJSON* params, const char* role) {
|
||||
static cJSON* signer_remote_params_with_selector(cJSON* params, const char* role, int has_nostr_index, int nostr_index) {
|
||||
cJSON* selector;
|
||||
|
||||
if (params == NULL) {
|
||||
@@ -294,6 +316,18 @@ static cJSON* signer_remote_params_with_selector(cJSON* params, const char* role
|
||||
}
|
||||
}
|
||||
|
||||
/* nostr_index takes precedence over role when set */
|
||||
if (has_nostr_index) {
|
||||
selector = cJSON_CreateObject();
|
||||
if (selector == NULL) {
|
||||
cJSON_Delete(params);
|
||||
return NULL;
|
||||
}
|
||||
cJSON_AddNumberToObject(selector, "nostr_index", nostr_index);
|
||||
cJSON_AddItemToArray(params, selector);
|
||||
return params;
|
||||
}
|
||||
|
||||
if (role == NULL || role[0] == '\0') {
|
||||
return params;
|
||||
}
|
||||
@@ -319,12 +353,14 @@ static int signer_remote_get_public_key(nostr_signer_t* signer, char out_pubkey_
|
||||
return NOSTR_ERROR_INVALID_INPUT;
|
||||
}
|
||||
|
||||
params = signer_remote_params_with_selector(NULL, signer->u.remote.role);
|
||||
params = signer_remote_params_with_selector(NULL, signer->u.remote.role,
|
||||
signer->u.remote.has_nostr_index,
|
||||
signer->u.remote.nostr_index);
|
||||
if (params == NULL) {
|
||||
return NOSTR_ERROR_MEMORY_FAILED;
|
||||
}
|
||||
|
||||
rc = nsigner_client_call(signer->u.remote.client, "get_public_key", params, &result);
|
||||
rc = nsigner_client_call(signer->u.remote.client, "nostr_get_public_key", params, &result);
|
||||
if (rc != NOSTR_SUCCESS) {
|
||||
return rc;
|
||||
}
|
||||
@@ -369,12 +405,14 @@ static int signer_remote_sign_event(nostr_signer_t* signer, const cJSON* unsigne
|
||||
cJSON_AddItemToArray(params, cJSON_CreateString(event_json));
|
||||
free(event_json);
|
||||
|
||||
params = signer_remote_params_with_selector(params, signer->u.remote.role);
|
||||
params = signer_remote_params_with_selector(params, signer->u.remote.role,
|
||||
signer->u.remote.has_nostr_index,
|
||||
signer->u.remote.nostr_index);
|
||||
if (params == NULL) {
|
||||
return NOSTR_ERROR_MEMORY_FAILED;
|
||||
}
|
||||
|
||||
rc = nsigner_client_call(signer->u.remote.client, "sign_event", params, &result);
|
||||
rc = nsigner_client_call(signer->u.remote.client, "nostr_sign_event", params, &result);
|
||||
if (rc != NOSTR_SUCCESS) {
|
||||
return rc;
|
||||
}
|
||||
@@ -427,7 +465,9 @@ static int signer_remote_encrypt_decrypt(nostr_signer_t* signer,
|
||||
cJSON_AddItemToArray(params, cJSON_CreateString(peer_pubkey_hex));
|
||||
cJSON_AddItemToArray(params, cJSON_CreateString(in));
|
||||
|
||||
params = signer_remote_params_with_selector(params, signer->u.remote.role);
|
||||
params = signer_remote_params_with_selector(params, signer->u.remote.role,
|
||||
signer->u.remote.has_nostr_index,
|
||||
signer->u.remote.nostr_index);
|
||||
if (params == NULL) {
|
||||
return NOSTR_ERROR_MEMORY_FAILED;
|
||||
}
|
||||
@@ -461,28 +501,96 @@ static int signer_remote_nip04_encrypt(nostr_signer_t* signer,
|
||||
const char* peer_pubkey_hex,
|
||||
const char* plaintext,
|
||||
char** ciphertext_out) {
|
||||
return signer_remote_encrypt_decrypt(signer, "nip04_encrypt", peer_pubkey_hex, plaintext, ciphertext_out);
|
||||
return signer_remote_encrypt_decrypt(signer, "nostr_nip04_encrypt", peer_pubkey_hex, plaintext, ciphertext_out);
|
||||
}
|
||||
|
||||
static int signer_remote_nip04_decrypt(nostr_signer_t* signer,
|
||||
const char* peer_pubkey_hex,
|
||||
const char* ciphertext,
|
||||
char** plaintext_out) {
|
||||
return signer_remote_encrypt_decrypt(signer, "nip04_decrypt", peer_pubkey_hex, ciphertext, plaintext_out);
|
||||
return signer_remote_encrypt_decrypt(signer, "nostr_nip04_decrypt", peer_pubkey_hex, ciphertext, plaintext_out);
|
||||
}
|
||||
|
||||
static int signer_remote_nip44_encrypt(nostr_signer_t* signer,
|
||||
const char* peer_pubkey_hex,
|
||||
const char* plaintext,
|
||||
char** ciphertext_out) {
|
||||
return signer_remote_encrypt_decrypt(signer, "nip44_encrypt", peer_pubkey_hex, plaintext, ciphertext_out);
|
||||
return signer_remote_encrypt_decrypt(signer, "nostr_nip44_encrypt", peer_pubkey_hex, plaintext, ciphertext_out);
|
||||
}
|
||||
|
||||
static int signer_remote_nip44_decrypt(nostr_signer_t* signer,
|
||||
const char* peer_pubkey_hex,
|
||||
const char* ciphertext,
|
||||
char** plaintext_out) {
|
||||
return signer_remote_encrypt_decrypt(signer, "nip44_decrypt", peer_pubkey_hex, ciphertext, plaintext_out);
|
||||
return signer_remote_encrypt_decrypt(signer, "nostr_nip44_decrypt", peer_pubkey_hex, ciphertext, plaintext_out);
|
||||
}
|
||||
|
||||
static int signer_remote_derive_hmac(nostr_signer_t* signer,
|
||||
const char* data,
|
||||
char out_digest_hex[65]) {
|
||||
cJSON* params;
|
||||
cJSON* opts = NULL;
|
||||
cJSON* result = NULL;
|
||||
cJSON* parsed = NULL;
|
||||
cJSON* digest_item = NULL;
|
||||
const char* digest_str = NULL;
|
||||
int rc;
|
||||
|
||||
if (!signer || !data || !out_digest_hex) {
|
||||
return NOSTR_ERROR_INVALID_INPUT;
|
||||
}
|
||||
|
||||
params = cJSON_CreateArray();
|
||||
if (params == NULL) {
|
||||
return NOSTR_ERROR_MEMORY_FAILED;
|
||||
}
|
||||
cJSON_AddItemToArray(params, cJSON_CreateString(data));
|
||||
|
||||
/* Build the options object with algorithm:"secp256k1" and the selector
|
||||
* (role or nostr_index). The derive verb requires index, so when
|
||||
* has_nostr_index is set we include it; otherwise we include role (the
|
||||
* nsigner derive handler requires index, so callers using the remote
|
||||
* backend must set nostr_index via nostr_signer_nsigner_set_nostr_index
|
||||
* before calling derive_hmac). */
|
||||
opts = cJSON_CreateObject();
|
||||
if (opts == NULL) {
|
||||
cJSON_Delete(params);
|
||||
return NOSTR_ERROR_MEMORY_FAILED;
|
||||
}
|
||||
cJSON_AddStringToObject(opts, "algorithm", "secp256k1");
|
||||
if (signer->u.remote.has_nostr_index) {
|
||||
cJSON_AddNumberToObject(opts, "index", signer->u.remote.nostr_index);
|
||||
} else if (signer->u.remote.role[0] != '\0') {
|
||||
cJSON_AddStringToObject(opts, "role", signer->u.remote.role);
|
||||
}
|
||||
cJSON_AddItemToArray(params, opts);
|
||||
|
||||
rc = nsigner_client_call(signer->u.remote.client, "derive", params, &result);
|
||||
if (rc != NOSTR_SUCCESS) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* result is a JSON string: {"algorithm":"secp256k1","key_id":"...","digest":"<64hex>"} */
|
||||
if (!cJSON_IsString(result) || result->valuestring == NULL) {
|
||||
cJSON_Delete(result);
|
||||
return NOSTR_ERROR_NIP46_INVALID_RESPONSE;
|
||||
}
|
||||
parsed = cJSON_Parse(result->valuestring);
|
||||
cJSON_Delete(result);
|
||||
if (parsed == NULL) {
|
||||
return NOSTR_ERROR_NIP46_INVALID_RESPONSE;
|
||||
}
|
||||
digest_item = cJSON_GetObjectItemCaseSensitive(parsed, "digest");
|
||||
if (!cJSON_IsString(digest_item) || digest_item->valuestring == NULL ||
|
||||
strlen(digest_item->valuestring) != 64) {
|
||||
cJSON_Delete(parsed);
|
||||
return NOSTR_ERROR_NIP46_INVALID_RESPONSE;
|
||||
}
|
||||
digest_str = digest_item->valuestring;
|
||||
memcpy(out_digest_hex, digest_str, 64);
|
||||
out_digest_hex[64] = '\0';
|
||||
cJSON_Delete(parsed);
|
||||
return NOSTR_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* NOSTR_ENABLE_NSIGNER_CLIENT */
|
||||
@@ -639,6 +747,25 @@ int nostr_signer_nip44_decrypt(nostr_signer_t* signer,
|
||||
return NOSTR_ERROR_INVALID_INPUT;
|
||||
}
|
||||
|
||||
int nostr_signer_derive_hmac(nostr_signer_t* signer,
|
||||
const char* data,
|
||||
char out_digest_hex[65]) {
|
||||
if (!signer || !data || !out_digest_hex) {
|
||||
return NOSTR_ERROR_INVALID_INPUT;
|
||||
}
|
||||
|
||||
if (signer->backend == NOSTR_SIGNER_BACKEND_LOCAL) {
|
||||
return signer_local_derive_hmac(signer, data, out_digest_hex);
|
||||
}
|
||||
#if defined(NOSTR_ENABLE_NSIGNER_CLIENT)
|
||||
if (signer->backend == NOSTR_SIGNER_BACKEND_NSIGNER_REMOTE) {
|
||||
return signer_remote_derive_hmac(signer, data, out_digest_hex);
|
||||
}
|
||||
#endif
|
||||
|
||||
return NOSTR_ERROR_INVALID_INPUT;
|
||||
}
|
||||
|
||||
#if defined(NOSTR_ENABLE_NSIGNER_CLIENT)
|
||||
static nostr_signer_t* nostr_signer_nsigner_from_transport(nsigner_transport_t* transport, const char* role) {
|
||||
nsigner_client_t* client = NULL;
|
||||
@@ -720,4 +847,34 @@ int nostr_signer_nsigner_set_auth(nostr_signer_t* signer,
|
||||
|
||||
return nsigner_client_set_auth(signer->u.remote.client, auth_privkey, label);
|
||||
}
|
||||
|
||||
nostr_signer_t* nostr_signer_nsigner_qrexec(const char* target_qube, const char* service_name, const char* role, int timeout_ms) {
|
||||
nsigner_transport_t* transport;
|
||||
|
||||
transport = nsigner_transport_open_qrexec(target_qube, service_name, timeout_ms);
|
||||
return nostr_signer_nsigner_from_transport(transport, role);
|
||||
}
|
||||
|
||||
int nostr_signer_nsigner_set_nostr_index(nostr_signer_t* signer, int nostr_index) {
|
||||
if (signer == NULL) {
|
||||
return NOSTR_ERROR_INVALID_INPUT;
|
||||
}
|
||||
|
||||
if (signer->backend != NOSTR_SIGNER_BACKEND_NSIGNER_REMOTE || signer->u.remote.client == NULL) {
|
||||
return NOSTR_ERROR_INVALID_INPUT;
|
||||
}
|
||||
|
||||
if (nostr_index < 0) {
|
||||
/* Clear the nostr_index selector, fall back to role */
|
||||
signer->u.remote.has_nostr_index = 0;
|
||||
signer->u.remote.nostr_index = -1;
|
||||
} else {
|
||||
/* Set nostr_index; clear role to avoid ambiguous selector */
|
||||
signer->u.remote.has_nostr_index = 1;
|
||||
signer->u.remote.nostr_index = nostr_index;
|
||||
memset(signer->u.remote.role, 0, sizeof(signer->u.remote.role));
|
||||
}
|
||||
|
||||
return NOSTR_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -19,6 +19,16 @@ void nostr_signer_free(nostr_signer_t* signer);
|
||||
int nostr_signer_get_public_key(nostr_signer_t* signer, char out_pubkey_hex[65]);
|
||||
int nostr_signer_sign_event(nostr_signer_t* signer, const cJSON* unsigned_event, cJSON** signed_event_out);
|
||||
|
||||
/* Derive a deterministic MAC over caller-supplied data using the signer's
|
||||
* secp256k1 private key: out = HMAC-SHA256(privkey, data).
|
||||
* data is a NUL-terminated UTF-8 string. out_digest_hex receives 64 lowercase
|
||||
* hex chars + NUL. For the local backend this computes directly; for the
|
||||
* nsigner remote backend it calls the "derive" verb (algorithm:"secp256k1").
|
||||
* Returns NOSTR_SUCCESS or an error code. */
|
||||
int nostr_signer_derive_hmac(nostr_signer_t* signer,
|
||||
const char* data,
|
||||
char out_digest_hex[65]);
|
||||
|
||||
/* Encryption verbs (for parity with upcoming remote backends) */
|
||||
int nostr_signer_nip04_encrypt(nostr_signer_t* signer,
|
||||
const char* peer_pubkey_hex,
|
||||
@@ -42,10 +52,18 @@ nostr_signer_t* nostr_signer_nsigner_unix(const char* socket_name, const char* r
|
||||
nostr_signer_t* nostr_signer_nsigner_serial(const char* device_path, const char* role, int timeout_ms);
|
||||
nostr_signer_t* nostr_signer_nsigner_tcp(const char* host, int port, const char* role, int timeout_ms);
|
||||
nostr_signer_t* nostr_signer_nsigner_fds(int read_fd, int write_fd, const char* role, int timeout_ms);
|
||||
nostr_signer_t* nostr_signer_nsigner_qrexec(const char* target_qube, const char* service_name, const char* role, int timeout_ms);
|
||||
/* TCP mode requires auth envelope per n_signer; set this before making calls. */
|
||||
int nostr_signer_nsigner_set_auth(nostr_signer_t* signer,
|
||||
const unsigned char auth_privkey[32],
|
||||
const char* label);
|
||||
/*
|
||||
* Set the nostr_index selector for the remote nsigner backend. When set,
|
||||
* requests use {"nostr_index":N} instead of {"role":"..."}. This is mutually
|
||||
* exclusive with the role parameter (setting index clears role).
|
||||
* Returns NOSTR_SUCCESS or an error code.
|
||||
*/
|
||||
int nostr_signer_nsigner_set_nostr_index(nostr_signer_t* signer, int nostr_index);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
|
||||
#include "nsigner_client.h"
|
||||
|
||||
#if defined(NOSTR_ENABLE_NSIGNER_CLIENT)
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -10,10 +13,23 @@
|
||||
#include "nip001.h"
|
||||
#include "utils.h"
|
||||
|
||||
/* Ensure a broken connection returns EPIPE instead of killing the process. */
|
||||
static void nsigner_client_ignore_sigpipe_once(void) {
|
||||
static int done = 0;
|
||||
if (!done) {
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = SIG_IGN;
|
||||
(void)sigaction(SIGPIPE, &sa, NULL);
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
struct nsigner_client {
|
||||
nsigner_transport_t* transport;
|
||||
unsigned long long next_id;
|
||||
int auth_enabled;
|
||||
int connected; /* whether the transport has an open connection ready for a request */
|
||||
unsigned char auth_privkey[32];
|
||||
char auth_label[64];
|
||||
char last_error[256];
|
||||
@@ -173,6 +189,7 @@ nsigner_client_t* nsigner_client_new(nsigner_transport_t* transport) {
|
||||
|
||||
client->transport = transport;
|
||||
client->next_id = 1;
|
||||
client->connected = 1; /* transport was opened connected by its constructor */
|
||||
nsigner_client_set_error(client, "ok");
|
||||
return client;
|
||||
}
|
||||
@@ -234,6 +251,23 @@ int nsigner_client_call(nsigner_client_t* client,
|
||||
|
||||
*out_result = NULL;
|
||||
|
||||
nsigner_client_ignore_sigpipe_once();
|
||||
|
||||
/*
|
||||
* The n_signer server closes the connection after handling a single framed
|
||||
* request (one-request-per-connection model). Reconnect before every call
|
||||
* except the first (the transport was opened connected by the constructor).
|
||||
* Transports that do not support reconnection (fd-pair) skip this.
|
||||
*/
|
||||
if (client->connected && client->transport->reconnect != NULL) {
|
||||
if (client->transport->reconnect(client->transport) != 0) {
|
||||
nsigner_client_set_error(client, "transport reconnect failed");
|
||||
cJSON_Delete(params);
|
||||
return NOSTR_ERROR_IO_FAILED;
|
||||
}
|
||||
}
|
||||
client->connected = 1;
|
||||
|
||||
rc = nsigner_client_next_id(client, id_buf);
|
||||
if (rc != NOSTR_SUCCESS) {
|
||||
cJSON_Delete(params);
|
||||
|
||||
+387
-12
@@ -16,6 +16,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <netdb.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
@@ -30,12 +31,35 @@
|
||||
#define CRTSCTS 0
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
NSIGNER_TRANSPORT_KIND_FD = 0,
|
||||
NSIGNER_TRANSPORT_KIND_UNIX = 1,
|
||||
NSIGNER_TRANSPORT_KIND_TCP = 2,
|
||||
NSIGNER_TRANSPORT_KIND_SERIAL = 3,
|
||||
NSIGNER_TRANSPORT_KIND_QREXEC = 4
|
||||
} nsigner_transport_kind_t;
|
||||
|
||||
/* Forward declarations: reconnect helpers use these before their definitions. */
|
||||
static void nsigner_termios_make_raw(struct termios* tio);
|
||||
static int nsigner_set_socket_timeouts(int fd, int timeout_ms);
|
||||
static int nsigner_connect_with_timeout(int fd, const struct sockaddr* addr, socklen_t addr_len, int timeout_ms);
|
||||
|
||||
typedef struct {
|
||||
nsigner_transport_kind_t kind;
|
||||
int read_fd;
|
||||
int write_fd;
|
||||
int timeout_ms;
|
||||
int close_read_fd;
|
||||
int close_write_fd;
|
||||
/* Reconnection parameters (used by unix/tcp/serial). */
|
||||
char socket_name[108]; /* unix: abstract name without leading '@' */
|
||||
char host[256]; /* tcp: host */
|
||||
int port; /* tcp: port */
|
||||
char device_path[256]; /* serial: device path */
|
||||
/* qrexec: target qube and service name */
|
||||
char qrexec_target[128]; /* qrexec: target qube name */
|
||||
char qrexec_service[128];/* qrexec: service name (e.g. "qubes.NsignerRpc") */
|
||||
pid_t qrexec_pid; /* qrexec: child process pid (0 = none) */
|
||||
} nsigner_fd_transport_ctx_t;
|
||||
|
||||
static int nsigner_write_full(int fd, const void* buf, size_t len) {
|
||||
@@ -197,6 +221,284 @@ static int nsigner_fd_recv_framed(nsigner_transport_t* t, char** out_json, size_
|
||||
return nsigner_transport_recv_framed_fd_timeout(ctx->read_fd, out_json, out_len, ctx->timeout_ms);
|
||||
}
|
||||
|
||||
static void nsigner_fd_close_fds(nsigner_fd_transport_ctx_t* ctx) {
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->close_read_fd && ctx->read_fd >= 0) {
|
||||
int read_fd = ctx->read_fd;
|
||||
close(read_fd);
|
||||
ctx->read_fd = -1;
|
||||
if (ctx->write_fd == read_fd) {
|
||||
ctx->write_fd = -1;
|
||||
}
|
||||
}
|
||||
if (ctx->close_write_fd && ctx->write_fd >= 0) {
|
||||
close(ctx->write_fd);
|
||||
ctx->write_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int nsigner_fd_reconnect_unix(nsigner_fd_transport_ctx_t* ctx) {
|
||||
struct sockaddr_un addr;
|
||||
size_t name_len;
|
||||
socklen_t addr_len;
|
||||
int fd;
|
||||
|
||||
name_len = strlen(ctx->socket_name);
|
||||
if (name_len > (sizeof(addr.sun_path) - 2)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nsigner_set_socket_timeouts(fd, ctx->timeout_ms) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
addr.sun_path[0] = '\0';
|
||||
memcpy(&addr.sun_path[1], ctx->socket_name, name_len);
|
||||
|
||||
addr_len = (socklen_t)(sizeof(sa_family_t) + 1 + name_len);
|
||||
if (nsigner_connect_with_timeout(fd, (struct sockaddr*)&addr, addr_len, ctx->timeout_ms) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->read_fd = fd;
|
||||
ctx->write_fd = fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int nsigner_fd_reconnect_tcp(nsigner_fd_transport_ctx_t* ctx) {
|
||||
struct addrinfo hints;
|
||||
struct addrinfo* addrs = NULL;
|
||||
struct addrinfo* ai;
|
||||
char port_buf[16];
|
||||
int fd = -1;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
|
||||
snprintf(port_buf, sizeof(port_buf), "%d", ctx->port);
|
||||
if (getaddrinfo(ctx->host, port_buf, &hints, &addrs) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (ai = addrs; ai != NULL; ai = ai->ai_next) {
|
||||
fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
||||
if (fd < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nsigner_connect_with_timeout(fd, ai->ai_addr, ai->ai_addrlen, ctx->timeout_ms) == 0 &&
|
||||
nsigner_set_socket_timeouts(fd, ctx->timeout_ms) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
|
||||
freeaddrinfo(addrs);
|
||||
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->read_fd = fd;
|
||||
ctx->write_fd = fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int nsigner_fd_reconnect_serial(nsigner_fd_transport_ctx_t* ctx) {
|
||||
struct termios tio;
|
||||
int fd;
|
||||
|
||||
fd = open(ctx->device_path, O_RDWR | O_NOCTTY | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tcgetattr(fd, &tio) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
nsigner_termios_make_raw(&tio);
|
||||
tio.c_cflag |= (CLOCAL | CREAD);
|
||||
tio.c_cflag &= ~(CRTSCTS | CSTOPB | PARENB);
|
||||
tio.c_cflag = (tio.c_cflag & ~CSIZE) | CS8;
|
||||
tio.c_iflag &= ~(IXON | IXOFF | IXANY);
|
||||
tio.c_cc[VMIN] = 0;
|
||||
tio.c_cc[VTIME] = 0;
|
||||
|
||||
(void)cfsetispeed(&tio, B115200);
|
||||
(void)cfsetospeed(&tio, B115200);
|
||||
|
||||
if (tcsetattr(fd, TCSANOW, &tio) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->read_fd = fd;
|
||||
ctx->write_fd = fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Forward declaration */
|
||||
static int nsigner_fd_reconnect_qrexec(nsigner_fd_transport_ctx_t* ctx);
|
||||
|
||||
/* Lazy connect for qrexec: if no fds are open, spawn the process now. */
|
||||
static int nsigner_qrexec_ensure_connected(nsigner_fd_transport_ctx_t* ctx) {
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (ctx->read_fd >= 0 && ctx->write_fd >= 0) {
|
||||
return 0; /* already connected */
|
||||
}
|
||||
return nsigner_fd_reconnect_qrexec(ctx);
|
||||
}
|
||||
|
||||
static int nsigner_qrexec_send_framed(nsigner_transport_t* t, const char* json, size_t len) {
|
||||
nsigner_fd_transport_ctx_t* ctx;
|
||||
if (t == NULL || t->ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
ctx = (nsigner_fd_transport_ctx_t*)t->ctx;
|
||||
if (nsigner_qrexec_ensure_connected(ctx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return nsigner_fd_send_framed(t, json, len);
|
||||
}
|
||||
|
||||
static int nsigner_qrexec_recv_framed(nsigner_transport_t* t, char** out_json, size_t* out_len) {
|
||||
nsigner_fd_transport_ctx_t* ctx;
|
||||
if (t == NULL || t->ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
ctx = (nsigner_fd_transport_ctx_t*)t->ctx;
|
||||
if (nsigner_qrexec_ensure_connected(ctx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return nsigner_fd_recv_framed(t, out_json, out_len);
|
||||
}
|
||||
|
||||
static int nsigner_fd_reconnect_qrexec(nsigner_fd_transport_ctx_t* ctx) {
|
||||
int stdin_pipe[2] = { -1, -1 };
|
||||
int stdout_pipe[2] = { -1, -1 };
|
||||
pid_t pid;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Reap any previous child — blocking wait. The parent nsigner_fd_reconnect
|
||||
* already closed the old fds, so the child should have exited. */
|
||||
if (ctx->qrexec_pid > 0) {
|
||||
int status;
|
||||
(void)waitpid(ctx->qrexec_pid, &status, 0);
|
||||
ctx->qrexec_pid = 0;
|
||||
}
|
||||
|
||||
/* Create pipes: stdin_pipe[1] = we write, stdin_pipe[0] = child reads
|
||||
* stdout_pipe[0] = we read, stdout_pipe[1] = child writes */
|
||||
if (pipe(stdin_pipe) != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (pipe(stdout_pipe) != 0) {
|
||||
close(stdin_pipe[0]); close(stdin_pipe[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
close(stdin_pipe[0]); close(stdin_pipe[1]);
|
||||
close(stdout_pipe[0]); close(stdout_pipe[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
/* Child: dup pipes onto stdin/stdout, exec qrexec-client-vm */
|
||||
(void)close(stdin_pipe[1]);
|
||||
(void)close(stdout_pipe[0]);
|
||||
if (dup2(stdin_pipe[0], STDIN_FILENO) < 0) {
|
||||
_exit(127);
|
||||
}
|
||||
if (dup2(stdout_pipe[1], STDOUT_FILENO) < 0) {
|
||||
_exit(127);
|
||||
}
|
||||
(void)close(stdin_pipe[0]);
|
||||
(void)close(stdout_pipe[1]);
|
||||
/* Redirect stderr to /dev/null so it doesn't corrupt our pipe */
|
||||
{
|
||||
int devnull = open("/dev/null", O_WRONLY);
|
||||
if (devnull >= 0) {
|
||||
(void)dup2(devnull, STDERR_FILENO);
|
||||
(void)close(devnull);
|
||||
}
|
||||
}
|
||||
(void)execlp("qrexec-client-vm", "qrexec-client-vm",
|
||||
ctx->qrexec_target, ctx->qrexec_service, (char*)NULL);
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
/* Parent */
|
||||
(void)close(stdin_pipe[0]);
|
||||
(void)close(stdout_pipe[1]);
|
||||
|
||||
ctx->read_fd = stdout_pipe[0];
|
||||
ctx->write_fd = stdin_pipe[1];
|
||||
ctx->close_read_fd = 1;
|
||||
ctx->close_write_fd = 1;
|
||||
ctx->qrexec_pid = pid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int nsigner_fd_reconnect(nsigner_transport_t* t) {
|
||||
nsigner_fd_transport_ctx_t* ctx;
|
||||
int rc;
|
||||
|
||||
if (t == NULL || t->ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ctx = (nsigner_fd_transport_ctx_t*)t->ctx;
|
||||
|
||||
/* Close any existing fds first. */
|
||||
nsigner_fd_close_fds(ctx);
|
||||
|
||||
switch (ctx->kind) {
|
||||
case NSIGNER_TRANSPORT_KIND_UNIX:
|
||||
rc = nsigner_fd_reconnect_unix(ctx);
|
||||
break;
|
||||
case NSIGNER_TRANSPORT_KIND_TCP:
|
||||
rc = nsigner_fd_reconnect_tcp(ctx);
|
||||
break;
|
||||
case NSIGNER_TRANSPORT_KIND_SERIAL:
|
||||
rc = nsigner_fd_reconnect_serial(ctx);
|
||||
break;
|
||||
case NSIGNER_TRANSPORT_KIND_QREXEC:
|
||||
rc = nsigner_fd_reconnect_qrexec(ctx);
|
||||
break;
|
||||
default:
|
||||
/* FD-pair transport does not support reconnection. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void nsigner_fd_close(nsigner_transport_t* t) {
|
||||
nsigner_fd_transport_ctx_t* ctx;
|
||||
|
||||
@@ -206,17 +508,12 @@ static void nsigner_fd_close(nsigner_transport_t* t) {
|
||||
|
||||
ctx = (nsigner_fd_transport_ctx_t*)t->ctx;
|
||||
if (ctx != NULL) {
|
||||
if (ctx->close_read_fd && ctx->read_fd >= 0) {
|
||||
int read_fd = ctx->read_fd;
|
||||
close(read_fd);
|
||||
ctx->read_fd = -1;
|
||||
if (ctx->write_fd == read_fd) {
|
||||
ctx->write_fd = -1;
|
||||
}
|
||||
}
|
||||
if (ctx->close_write_fd && ctx->write_fd >= 0) {
|
||||
close(ctx->write_fd);
|
||||
ctx->write_fd = -1;
|
||||
nsigner_fd_close_fds(ctx);
|
||||
/* Reap qrexec child process if any */
|
||||
if (ctx->qrexec_pid > 0) {
|
||||
int status;
|
||||
(void)waitpid(ctx->qrexec_pid, &status, 0);
|
||||
ctx->qrexec_pid = 0;
|
||||
}
|
||||
free(ctx);
|
||||
}
|
||||
@@ -236,6 +533,7 @@ static int nsigner_fd_ctx_init(nsigner_transport_t* t,
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->kind = NSIGNER_TRANSPORT_KIND_FD;
|
||||
ctx->read_fd = read_fd;
|
||||
ctx->write_fd = write_fd;
|
||||
ctx->timeout_ms = timeout_ms;
|
||||
@@ -245,6 +543,7 @@ static int nsigner_fd_ctx_init(nsigner_transport_t* t,
|
||||
t->ctx = ctx;
|
||||
t->send_framed = nsigner_fd_send_framed;
|
||||
t->recv_framed = nsigner_fd_recv_framed;
|
||||
t->reconnect = NULL; /* fd-pair transport does not support reconnection */
|
||||
t->close = nsigner_fd_close;
|
||||
return 0;
|
||||
}
|
||||
@@ -399,6 +698,10 @@ nsigner_transport_t* nsigner_transport_open_unix(const char* socket_name, int ti
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->kind = NSIGNER_TRANSPORT_KIND_UNIX;
|
||||
snprintf(ctx->socket_name, sizeof(ctx->socket_name), "%s", socket_name);
|
||||
t->reconnect = nsigner_fd_reconnect;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -478,6 +781,11 @@ nsigner_transport_t* nsigner_transport_open_tcp(const char* host, int port, int
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->kind = NSIGNER_TRANSPORT_KIND_TCP;
|
||||
snprintf(ctx->host, sizeof(ctx->host), "%s", host);
|
||||
ctx->port = port;
|
||||
t->reconnect = nsigner_fd_reconnect;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -541,6 +849,10 @@ nsigner_transport_t* nsigner_transport_open_serial(const char* device_path, int
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->kind = NSIGNER_TRANSPORT_KIND_SERIAL;
|
||||
snprintf(ctx->device_path, sizeof(ctx->device_path), "%s", device_path);
|
||||
t->reconnect = nsigner_fd_reconnect;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -576,6 +888,57 @@ nsigner_transport_t* nsigner_transport_open_fds(int read_fd, int write_fd, int t
|
||||
return t;
|
||||
}
|
||||
|
||||
nsigner_transport_t* nsigner_transport_open_qrexec(const char* target_qube, const char* service_name, int timeout_ms) {
|
||||
nsigner_transport_t* t = NULL;
|
||||
nsigner_fd_transport_ctx_t* ctx = NULL;
|
||||
|
||||
if (target_qube == NULL || target_qube[0] == '\0' ||
|
||||
service_name == NULL || service_name[0] == '\0') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (timeout_ms <= 0) {
|
||||
timeout_ms = 30000; /* qrexec may involve dom0 policy prompts */
|
||||
}
|
||||
|
||||
t = (nsigner_transport_t*)calloc(1, sizeof(*t));
|
||||
if (t == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx = (nsigner_fd_transport_ctx_t*)calloc(1, sizeof(*ctx));
|
||||
if (ctx == NULL) {
|
||||
free(t);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize ctx fields directly (no initial fds — reconnect spawns the process) */
|
||||
ctx->kind = NSIGNER_TRANSPORT_KIND_QREXEC;
|
||||
ctx->read_fd = -1;
|
||||
ctx->write_fd = -1;
|
||||
ctx->timeout_ms = timeout_ms;
|
||||
ctx->close_read_fd = 0;
|
||||
ctx->close_write_fd = 0;
|
||||
ctx->qrexec_pid = 0;
|
||||
t->ctx = ctx;
|
||||
t->send_framed = nsigner_qrexec_send_framed;
|
||||
t->recv_framed = nsigner_qrexec_recv_framed;
|
||||
t->reconnect = nsigner_fd_reconnect;
|
||||
t->close = nsigner_fd_close;
|
||||
|
||||
/* Set qrexec parameters */
|
||||
strncpy(ctx->qrexec_target, target_qube, sizeof(ctx->qrexec_target) - 1);
|
||||
ctx->qrexec_target[sizeof(ctx->qrexec_target) - 1] = '\0';
|
||||
strncpy(ctx->qrexec_service, service_name, sizeof(ctx->qrexec_service) - 1);
|
||||
ctx->qrexec_service[sizeof(ctx->qrexec_service) - 1] = '\0';
|
||||
|
||||
/* No initial connect — qrexec-client-vm is spawned on the first
|
||||
* reconnect (which nsigner_client_call does before each request).
|
||||
* Spawning here would block waiting for a dom0 policy prompt that
|
||||
* may never come if the caller hasn't sent a request yet. */
|
||||
return t;
|
||||
}
|
||||
|
||||
int nsigner_transport_list_unix(char names[][64], int max_names) {
|
||||
FILE* fp;
|
||||
char line[512];
|
||||
@@ -658,8 +1021,20 @@ int nsigner_transport_list_serial(char paths[][64], int max_paths) {
|
||||
|
||||
while ((ent = readdir(dir)) != NULL) {
|
||||
int n;
|
||||
int is_serial = 0;
|
||||
|
||||
if (strncmp(ent->d_name, "ttyACM", 6) != 0) {
|
||||
/* USB CDC-ACM devices (e.g. n_signer firmware using TinyUSB CDC). */
|
||||
if (strncmp(ent->d_name, "ttyACM", 6) == 0) {
|
||||
is_serial = 1;
|
||||
}
|
||||
/* USB-serial adapters (FTDI / CH340 / CP210x / PL2303). These show up
|
||||
* as /dev/ttyUSB* and speak the same 115200 8N1 framing as CDC-ACM,
|
||||
* so they are valid n_signer serial transports too. */
|
||||
if (strncmp(ent->d_name, "ttyUSB", 6) == 0) {
|
||||
is_serial = 1;
|
||||
}
|
||||
|
||||
if (!is_serial) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,14 @@ typedef struct nsigner_transport nsigner_transport_t;
|
||||
struct nsigner_transport {
|
||||
int (*send_framed)(nsigner_transport_t* t, const char* json, size_t len);
|
||||
int (*recv_framed)(nsigner_transport_t* t, char** out_json, size_t* out_len); /* caller frees *out_json */
|
||||
/*
|
||||
* Re-establish the underlying connection. The n_signer server closes the
|
||||
* connection after handling a single framed request, so the client must
|
||||
* reconnect before each call. Returns 0 on success, non-zero on failure.
|
||||
* May be NULL for transports that do not support reconnection (e.g. fd-pair);
|
||||
* callers should treat a NULL reconnect as "not supported".
|
||||
*/
|
||||
int (*reconnect)(nsigner_transport_t* t);
|
||||
void (*close)(nsigner_transport_t* t);
|
||||
void* ctx;
|
||||
};
|
||||
@@ -38,6 +46,14 @@ nsigner_transport_t* nsigner_transport_open_serial(const char* device_path, int
|
||||
*/
|
||||
nsigner_transport_t* nsigner_transport_open_fds(int read_fd, int write_fd, int timeout_ms);
|
||||
|
||||
/*
|
||||
* Qubes qrexec transport: spawns `qrexec-client-vm <target_qube> <service_name>`
|
||||
* as a subprocess and pipes framed I/O through its stdin/stdout. Each reconnect
|
||||
* re-spawns the subprocess (qrexec handles one request per invocation).
|
||||
* Only works on Qubes OS AppVMs; on other hosts the exec will fail.
|
||||
*/
|
||||
nsigner_transport_t* nsigner_transport_open_qrexec(const char* target_qube, const char* service_name, int timeout_ms);
|
||||
|
||||
/* Enumerate /proc/net/unix abstract sockets beginning with @nsigner, returns count copied. */
|
||||
int nsigner_transport_list_unix(char names[][64], int max_names);
|
||||
|
||||
|
||||
@@ -1331,6 +1331,11 @@ static int find_word_index(const char* word) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char * const *nostr_bip39_get_wordlist(int *count) {
|
||||
if (count) *count = 2048;
|
||||
return BIP39_WORDLIST;
|
||||
}
|
||||
|
||||
int nostr_bip39_mnemonic_from_bytes(const unsigned char* entropy, size_t entropy_len,
|
||||
char* mnemonic) {
|
||||
if (!entropy || !mnemonic || entropy_len < 16 || entropy_len > 32) return -1;
|
||||
|
||||
@@ -24,6 +24,11 @@ void nostr_bytes_to_hex(const unsigned char *bytes, size_t len, char *hex);
|
||||
// Convert hexadecimal string to bytes
|
||||
int nostr_hex_to_bytes(const char *hex, unsigned char *bytes, size_t len);
|
||||
|
||||
// Get the BIP-39 English wordlist (2048 words). Returns a pointer to a
|
||||
// static array; count is set to 2048 if non-NULL. The pointer is valid
|
||||
// for the lifetime of the process.
|
||||
const char * const *nostr_bip39_get_wordlist(int *count);
|
||||
|
||||
// Base64 encoding function
|
||||
size_t base64_encode(const unsigned char *data, size_t len, char *output,
|
||||
size_t output_size);
|
||||
|
||||
@@ -12,6 +12,18 @@
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <sys/select.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
static int ws_connect_debug_enabled(void) {
|
||||
static int initialized = 0;
|
||||
static int enabled = 0;
|
||||
if (!initialized) {
|
||||
const char* env = getenv("NOSTR_WS_CONNECT_DEBUG");
|
||||
enabled = (env && env[0] != '\0' && strcmp(env, "0") != 0);
|
||||
initialized = 1;
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// OpenSSL headers
|
||||
#include <openssl/ssl.h>
|
||||
@@ -23,7 +35,7 @@
|
||||
#define WS_MAGIC_STRING "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
||||
#define WS_KEY_LEN 24
|
||||
#define MAX_HEADER_SIZE 4096
|
||||
#define MAX_FRAME_SIZE 65536
|
||||
#define MAX_FRAME_SIZE 262144
|
||||
|
||||
// Transport layer abstraction
|
||||
typedef struct {
|
||||
@@ -45,6 +57,15 @@ typedef struct {
|
||||
SSL_CTX* ssl_ctx;
|
||||
SSL* ssl;
|
||||
int ssl_connected;
|
||||
/* Internal read buffer: SSL_read may return more bytes than the
|
||||
* caller requested (a full TLS record at once). Without buffering
|
||||
* the excess, those bytes are lost — which breaks ws_receive_frame
|
||||
* when it asks for a 2-byte header but SSL_read returns a full
|
||||
* event message. This caused the caching backfill to only receive
|
||||
* 1 event per query from TLS relays. */
|
||||
char read_buf[65536];
|
||||
size_t read_buf_len; /* total bytes in read_buf */
|
||||
size_t read_buf_pos; /* offset of next byte to consume */
|
||||
} tls_transport_t;
|
||||
|
||||
// WebSocket client structure
|
||||
@@ -423,6 +444,12 @@ static int tcp_connect(void* ctx, const char* host, int port) {
|
||||
struct addrinfo* rp = NULL;
|
||||
char port_str[16];
|
||||
int ret;
|
||||
int addr_idx = 0;
|
||||
time_t connect_start = time(NULL);
|
||||
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr, "[nostr_ws][connect] tcp_connect_start host=%s port=%d\n", host ? host : "(null)", port);
|
||||
}
|
||||
|
||||
tcp->socket_fd = -1;
|
||||
|
||||
@@ -434,26 +461,120 @@ static int tcp_connect(void* ctx, const char* host, int port) {
|
||||
snprintf(port_str, sizeof(port_str), "%d", port);
|
||||
ret = getaddrinfo(host, port_str, &hints, &result);
|
||||
if (ret != 0 || !result) {
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr, "[nostr_ws][connect] getaddrinfo_failed host=%s port=%d ret=%d err=%s\n",
|
||||
host ? host : "(null)",
|
||||
port,
|
||||
ret,
|
||||
gai_strerror(ret));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||
int fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
||||
addr_idx++;
|
||||
if (fd < 0) {
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr, "[nostr_ws][connect] socket_failed host=%s port=%d addr_idx=%d family=%d errno=%d\n",
|
||||
host ? host : "(null)",
|
||||
port,
|
||||
addr_idx,
|
||||
rp->ai_family,
|
||||
errno);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (connect(fd, rp->ai_addr, rp->ai_addrlen) == 0) {
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr, "[nostr_ws][connect] connect_attempt host=%s port=%d addr_idx=%d family=%d\n",
|
||||
host ? host : "(null)",
|
||||
port,
|
||||
addr_idx,
|
||||
rp->ai_family);
|
||||
}
|
||||
|
||||
int flags = fcntl(fd, F_GETFL, 0);
|
||||
if (flags >= 0) {
|
||||
(void)fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
}
|
||||
|
||||
int connect_rc = connect(fd, rp->ai_addr, rp->ai_addrlen);
|
||||
if (connect_rc == 0) {
|
||||
tcp->socket_fd = fd;
|
||||
if (flags >= 0) {
|
||||
(void)fcntl(fd, F_SETFL, flags);
|
||||
}
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr, "[nostr_ws][connect] connect_success host=%s port=%d addr_idx=%d elapsed_s=%ld\n",
|
||||
host ? host : "(null)",
|
||||
port,
|
||||
addr_idx,
|
||||
(long)(time(NULL) - connect_start));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (connect_rc < 0 && errno == EINPROGRESS) {
|
||||
fd_set wfds;
|
||||
struct timeval tv;
|
||||
int sel_rc;
|
||||
int so_error = 0;
|
||||
socklen_t so_error_len = sizeof(so_error);
|
||||
|
||||
FD_ZERO(&wfds);
|
||||
FD_SET(fd, &wfds);
|
||||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
sel_rc = select(fd + 1, NULL, &wfds, NULL, &tv);
|
||||
if (sel_rc > 0 && FD_ISSET(fd, &wfds) &&
|
||||
getsockopt(fd, SOL_SOCKET, SO_ERROR, &so_error, &so_error_len) == 0 &&
|
||||
so_error == 0) {
|
||||
tcp->socket_fd = fd;
|
||||
if (flags >= 0) {
|
||||
(void)fcntl(fd, F_SETFL, flags);
|
||||
}
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr, "[nostr_ws][connect] connect_success_after_wait host=%s port=%d addr_idx=%d elapsed_s=%ld\n",
|
||||
host ? host : "(null)",
|
||||
port,
|
||||
addr_idx,
|
||||
(long)(time(NULL) - connect_start));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr, "[nostr_ws][connect] connect_timeout_or_error host=%s port=%d addr_idx=%d select_rc=%d so_error=%d elapsed_s=%ld\n",
|
||||
host ? host : "(null)",
|
||||
port,
|
||||
addr_idx,
|
||||
sel_rc,
|
||||
so_error,
|
||||
(long)(time(NULL) - connect_start));
|
||||
}
|
||||
} else if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr, "[nostr_ws][connect] connect_failed host=%s port=%d addr_idx=%d errno=%d elapsed_s=%ld\n",
|
||||
host ? host : "(null)",
|
||||
port,
|
||||
addr_idx,
|
||||
errno,
|
||||
(long)(time(NULL) - connect_start));
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
freeaddrinfo(result);
|
||||
|
||||
if (tcp->socket_fd < 0) {
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr, "[nostr_ws][connect] tcp_connect_end host=%s port=%d rc=-1 elapsed_s=%ld\n",
|
||||
host ? host : "(null)",
|
||||
port,
|
||||
(long)(time(NULL) - connect_start));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -464,6 +585,13 @@ static int tcp_connect(void* ctx, const char* host, int port) {
|
||||
(void)setsockopt(tcp->socket_fd, SOL_SOCKET, SO_RCVTIMEO, &io_timeout, sizeof(io_timeout));
|
||||
(void)setsockopt(tcp->socket_fd, SOL_SOCKET, SO_SNDTIMEO, &io_timeout, sizeof(io_timeout));
|
||||
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr, "[nostr_ws][connect] tcp_connect_end host=%s port=%d rc=0 elapsed_s=%ld\n",
|
||||
host ? host : "(null)",
|
||||
port,
|
||||
(long)(time(NULL) - connect_start));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -589,10 +717,27 @@ static int tls_recv(void* ctx, void* data, size_t len, int timeout_ms) {
|
||||
if (!tls->ssl_connected || !tls->ssl) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Always use select() to ensure proper blocking behavior
|
||||
// If SSL has pending data, use zero timeout to return immediately
|
||||
// Otherwise use the full timeout to block until data arrives
|
||||
|
||||
/* Serve from the internal read buffer first. SSL_read may have
|
||||
* returned more bytes than the caller requested on a previous call
|
||||
* (a full TLS record), and we buffered the excess. Without this,
|
||||
* ws_receive_frame loses the extra bytes when it asks for a 2-byte
|
||||
* header but SSL_read returns a full event message. */
|
||||
if (tls->read_buf_pos < tls->read_buf_len) {
|
||||
size_t avail = tls->read_buf_len - tls->read_buf_pos;
|
||||
size_t to_copy = (avail < len) ? avail : len;
|
||||
memcpy(data, tls->read_buf + tls->read_buf_pos, to_copy);
|
||||
tls->read_buf_pos += to_copy;
|
||||
if (tls->read_buf_pos >= tls->read_buf_len) {
|
||||
tls->read_buf_len = 0;
|
||||
tls->read_buf_pos = 0;
|
||||
}
|
||||
return (int)to_copy;
|
||||
}
|
||||
|
||||
/* Buffer is empty — refill it with a single SSL_read, then serve
|
||||
* the requested bytes from it. This ensures excess bytes are
|
||||
* preserved for subsequent tls_recv calls. */
|
||||
if (timeout_ms > 0) {
|
||||
fd_set readfds;
|
||||
struct timeval tv;
|
||||
@@ -600,7 +745,6 @@ static int tls_recv(void* ctx, void* data, size_t len, int timeout_ms) {
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(tls->socket_fd, &readfds);
|
||||
|
||||
// If SSL has buffered data, use zero timeout; otherwise use full timeout
|
||||
if (SSL_pending(tls->ssl) > 0) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
@@ -622,16 +766,26 @@ static int tls_recv(void* ctx, void* data, size_t len, int timeout_ms) {
|
||||
const int max_attempts = 10;
|
||||
|
||||
while (attempts < max_attempts) {
|
||||
int ret = SSL_read(tls->ssl, data, len);
|
||||
/* Read into the internal buffer (up to its capacity), then copy
|
||||
* the requested number of bytes to the caller's output. */
|
||||
int ret = SSL_read(tls->ssl, tls->read_buf, sizeof(tls->read_buf));
|
||||
|
||||
if (ret > 0) {
|
||||
return ret; // Success
|
||||
tls->read_buf_len = (size_t)ret;
|
||||
tls->read_buf_pos = 0;
|
||||
size_t to_copy = (tls->read_buf_len < len) ? tls->read_buf_len : len;
|
||||
memcpy(data, tls->read_buf, to_copy);
|
||||
tls->read_buf_pos = to_copy;
|
||||
if (tls->read_buf_pos >= tls->read_buf_len) {
|
||||
tls->read_buf_len = 0;
|
||||
tls->read_buf_pos = 0;
|
||||
}
|
||||
return (int)to_copy;
|
||||
}
|
||||
|
||||
int err = SSL_get_error(tls->ssl, ret);
|
||||
|
||||
if (err == SSL_ERROR_WANT_READ) {
|
||||
// Check if more data is available on socket
|
||||
fd_set readfds;
|
||||
struct timeval tv = {0, 100000}; // 100ms timeout
|
||||
|
||||
@@ -644,7 +798,7 @@ static int tls_recv(void* ctx, void* data, size_t len, int timeout_ms) {
|
||||
}
|
||||
|
||||
attempts++;
|
||||
continue; // Retry the SSL read
|
||||
continue;
|
||||
|
||||
} else if (err == SSL_ERROR_WANT_WRITE) {
|
||||
return -1;
|
||||
@@ -891,13 +1045,22 @@ static int ws_send_frame(nostr_ws_client_t* client, ws_opcode_t opcode, const ch
|
||||
static int ws_receive_frame(nostr_ws_client_t* client, ws_opcode_t* opcode, char* payload, size_t* payload_len, int timeout_ms) {
|
||||
if (!client || !opcode || !payload || !payload_len) return -1;
|
||||
|
||||
char header[14]; // Max header size
|
||||
unsigned char header[14]; // Max header size
|
||||
size_t header_len = 2; // Minimum header size
|
||||
|
||||
// Read basic header
|
||||
int header_result = client->transport->recv(&client->transport_ctx, header, 2, timeout_ms);
|
||||
|
||||
if (header_result != 2) {
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr,
|
||||
"[nostr_ws][frame] short_header host=%s port=%d got=%d expected=2 timeout_ms=%d errno=%d\n",
|
||||
client->host ? client->host : "(null)",
|
||||
client->port,
|
||||
header_result,
|
||||
timeout_ms,
|
||||
errno);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -909,12 +1072,28 @@ static int ws_receive_frame(nostr_ws_client_t* client, ws_opcode_t* opcode, char
|
||||
// Extended length
|
||||
if (len == 126) {
|
||||
if (client->transport->recv(&client->transport_ctx, header + 2, 2, timeout_ms) != 2) {
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr,
|
||||
"[nostr_ws][frame] short_ext16 host=%s port=%d timeout_ms=%d errno=%d\n",
|
||||
client->host ? client->host : "(null)",
|
||||
client->port,
|
||||
timeout_ms,
|
||||
errno);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
len = ((uint16_t)header[2] << 8) | (uint8_t)header[3];
|
||||
header_len = 4;
|
||||
} else if (len == 127) {
|
||||
if (client->transport->recv(&client->transport_ctx, header + 2, 8, timeout_ms) != 8) {
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr,
|
||||
"[nostr_ws][frame] short_ext64 host=%s port=%d timeout_ms=%d errno=%d\n",
|
||||
client->host ? client->host : "(null)",
|
||||
client->port,
|
||||
timeout_ms,
|
||||
errno);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
// For simplicity, we don't support 64-bit lengths
|
||||
@@ -927,6 +1106,14 @@ static int ws_receive_frame(nostr_ws_client_t* client, ws_opcode_t* opcode, char
|
||||
uint32_t mask = 0;
|
||||
if (masked) {
|
||||
if (client->transport->recv(&client->transport_ctx, header + header_len, 4, timeout_ms) != 4) {
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr,
|
||||
"[nostr_ws][frame] short_mask host=%s port=%d timeout_ms=%d errno=%d\n",
|
||||
client->host ? client->host : "(null)",
|
||||
client->port,
|
||||
timeout_ms,
|
||||
errno);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
mask = ((uint32_t)header[header_len] << 24) |
|
||||
@@ -940,10 +1127,30 @@ static int ws_receive_frame(nostr_ws_client_t* client, ws_opcode_t* opcode, char
|
||||
if (len > *payload_len) {
|
||||
char discard[1024];
|
||||
uint64_t remaining = len;
|
||||
int drain_timeout_ms = timeout_ms < 5000 ? 5000 : timeout_ms;
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr,
|
||||
"[nostr_ws][frame] payload_too_large host=%s port=%d frame_len=%llu buffer_cap=%zu drain_timeout_ms=%d\n",
|
||||
client->host ? client->host : "(null)",
|
||||
client->port,
|
||||
(unsigned long long)len,
|
||||
*payload_len,
|
||||
drain_timeout_ms);
|
||||
}
|
||||
while (remaining > 0) {
|
||||
size_t chunk = remaining > sizeof(discard) ? sizeof(discard) : (size_t)remaining;
|
||||
int got = client->transport->recv(&client->transport_ctx, discard, chunk, timeout_ms);
|
||||
int got = client->transport->recv(&client->transport_ctx, discard, chunk, drain_timeout_ms);
|
||||
if (got <= 0) {
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr,
|
||||
"[nostr_ws][frame] discard_read_failed host=%s port=%d got=%d drain_timeout_ms=%d errno=%d remaining=%llu\n",
|
||||
client->host ? client->host : "(null)",
|
||||
client->port,
|
||||
got,
|
||||
drain_timeout_ms,
|
||||
errno,
|
||||
(unsigned long long)remaining);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
remaining -= (uint64_t)got;
|
||||
@@ -959,7 +1166,19 @@ static int ws_receive_frame(nostr_ws_client_t* client, ws_opcode_t* opcode, char
|
||||
payload + received,
|
||||
len - received,
|
||||
timeout_ms);
|
||||
if (chunk <= 0) return -1;
|
||||
if (chunk <= 0) {
|
||||
if (ws_connect_debug_enabled()) {
|
||||
fprintf(stderr,
|
||||
"[nostr_ws][frame] payload_read_failed host=%s port=%d got=%d need_remaining=%zu timeout_ms=%d errno=%d\n",
|
||||
client->host ? client->host : "(null)",
|
||||
client->port,
|
||||
chunk,
|
||||
len - received,
|
||||
timeout_ms,
|
||||
errno);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
received += chunk;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
# Plan: n_signer Verb Name Migration for nostr_core_lib
|
||||
|
||||
## Context
|
||||
|
||||
`n_signer` has completed a verb-name migration (see [`n_signer/plans/legacy_verb_aliases.md`](../../n_signer/plans/legacy_verb_aliases.md)). The legacy verb names are gone from the n_signer wire protocol. This document covers the fixes needed in `nostr_core_lib` — the shared C client library that many other projects vendor.
|
||||
|
||||
**Reference:** the new n_signer API is documented in [`n_signer/README.md`](../../n_signer/README.md) §4 (API).
|
||||
|
||||
## What changed in n_signer
|
||||
|
||||
The Nostr protocol verbs gained a `nostr_` prefix. The algorithm-based verbs (`sign`, `verify`, `encapsulate`, `decapsulate`, `derive_shared_secret`, `get_public_key`) are unchanged. The old alias verbs (`sign_data`, `ssh_sign`, `verify_signature`, `kem_encapsulate`, `kem_decapsulate`, `otp_encrypt`, `otp_decrypt`) are gone.
|
||||
|
||||
| Legacy n_signer verb | New n_signer verb |
|
||||
|----------------------|-------------------|
|
||||
| `sign_event` | `nostr_sign_event` |
|
||||
| `mine_event` | `nostr_mine_event` |
|
||||
| `nip04_encrypt` | `nostr_nip04_encrypt` |
|
||||
| `nip04_decrypt` | `nostr_nip04_decrypt` |
|
||||
| `nip44_encrypt` | `nostr_nip44_encrypt` |
|
||||
| `nip44_decrypt` | `nostr_nip44_decrypt` |
|
||||
| `get_public_key` (role-based) | `nostr_get_public_key` |
|
||||
|
||||
**Important distinction:** `get_public_key` is now **algorithm-based** (takes `algorithm`+`index`). The role-based Nostr pubkey verb is `nostr_get_public_key` (takes `nostr_index`/`role`). Since `nostr_core_lib`'s remote signer always uses role-based selectors (`nostr_index`/`role`), the correct replacement is `nostr_get_public_key`.
|
||||
|
||||
## What does NOT change
|
||||
|
||||
- **NIP-46 standard method names** in [`nostr_core/nip046.c`](../nostr_core/nip046.c) — the strings `"sign_event"`, `"get_public_key"`, `"nip04_encrypt"`, `"nip44_encrypt"`, etc. at lines 111-131 are the **NIP-46 wire protocol** (the standard that relays and other bunkers speak). These must stay as-is. They are NOT n_signer verbs.
|
||||
- **High-level C API function names** in [`nostr_core/nostr_signer.h`](../nostr_core/nostr_signer.h) — `nostr_signer_get_public_key()`, `nostr_signer_sign_event()`, `nostr_signer_nip04_encrypt()`, etc. are the nostr_core_lib's own API surface. These names are fine — they're C function names, not wire verbs. Renaming them would break every consumer for no protocol reason.
|
||||
- **The `nostr_signer_local` backend** — local signing doesn't call n_signer at all; it uses libsecp256k1 directly. No changes needed.
|
||||
|
||||
## Files to change
|
||||
|
||||
### 1. `nostr_core/nostr_signer.c` — the remote signer backend
|
||||
|
||||
This is the only file that calls n_signer verbs via `nsigner_client_call()`. All calls use role-based selectors (`nostr_index`/`role`), so all map to the `nostr_*` verbs.
|
||||
|
||||
| Line | Current verb string | New verb string |
|
||||
|------|---------------------|-----------------|
|
||||
| 343 | `"get_public_key"` | `"nostr_get_public_key"` |
|
||||
| 395 | `"sign_event"` | `"nostr_sign_event"` |
|
||||
| 484 | `"nip04_encrypt"` | `"nostr_nip04_encrypt"` |
|
||||
| 491 | `"nip04_decrypt"` | `"nostr_nip04_decrypt"` |
|
||||
| 498 | `"nip44_encrypt"` | `"nostr_nip44_encrypt"` |
|
||||
| 505 | `"nip44_decrypt"` | `"nostr_nip44_decrypt"` |
|
||||
|
||||
These are simple string-literal replacements. The `signer_remote_params_with_selector()` function (line 289) builds `{"nostr_index": N}` or `{"role": "..."}` selectors — these are still valid for the `nostr_*` verbs, so no selector changes needed.
|
||||
|
||||
**Response format note:** `nostr_get_public_key` returns a plain 64-hex-char string by default (same as the old role-based `get_public_key`). The existing parsing at line 348 (`strlen(result->valuestring) != 64`) continues to work. If the caller ever passes `{"format":"structured"}`, the response would be a JSON object string — but the current code doesn't request structured format, so no change needed.
|
||||
|
||||
### 2. `tests/nsigner_client_test.c` — the mock client test
|
||||
|
||||
| Line | Current verb string | New verb string |
|
||||
|------|---------------------|-----------------|
|
||||
| 296 | `"get_public_key"` | `"nostr_get_public_key"` |
|
||||
|
||||
This test uses a mock transport (fds pair) that returns a canned response — it doesn't actually call n_signer. The verb string just needs to match what the real client would send. Update it for consistency.
|
||||
|
||||
### 3. `nostr_core/NSIGNER_INTEGRATION.md` — integration doc
|
||||
|
||||
This doc references the high-level C API function names (`nostr_signer_get_public_key`, `nostr_signer_sign_event`, etc.) which are NOT changing. However, if it documents the underlying n_signer wire verbs anywhere, those references should be updated to the `nostr_*` names. Scan for any wire-verb documentation and update.
|
||||
|
||||
### 4. `plans/nsigner_integration_plan.md` — historical plan
|
||||
|
||||
This is a historical planning doc. Update any wire-verb references for accuracy, or add a note pointing to this migration plan.
|
||||
|
||||
## Files that do NOT need changes
|
||||
|
||||
- `nostr_core/nip046.c` — NIP-46 standard method names (stay as-is, see above).
|
||||
- `nostr_core/nsigner_client.c` — generic transport/client, doesn't hardcode verb names.
|
||||
- `nostr_core/nsigner_transport.c` — transport layer, no verb names.
|
||||
- `nostr_core/nostr_signer.h` — high-level API declarations (function names stay).
|
||||
- `tests/signer_modules_test.c` — tests the local signer, not n_signer verbs.
|
||||
- `tests/nip01_test.c` — NIP-01 tests, no n_signer verb calls.
|
||||
|
||||
## Verification
|
||||
|
||||
1. `grep -rn '"sign_event"\|"nip04_encrypt"\|"nip04_decrypt"\|"nip44_encrypt"\|"nip44_decrypt"\|"mine_event"\|"sign_data"\|"ssh_sign"\|"verify_signature"\|"kem_encapsulate"\|"kem_decapsulate"\|"otp_encrypt"\|"otp_decrypt"' nostr_core/nostr_signer.c` returns no matches.
|
||||
2. `grep -rn '"get_public_key"' nostr_core/nostr_signer.c` returns no matches (replaced by `nostr_get_public_key`).
|
||||
3. `grep -rn '"sign_event"\|"nip04_encrypt"\|"nip44_encrypt"' nostr_core/nip046.c` still returns matches (NIP-46 standard names — these stay).
|
||||
4. Build clean: `bash build.sh` or the project's build target.
|
||||
5. Tests pass: `./build/nsigner_client_test` (or equivalent).
|
||||
|
||||
## Downstream consumers (inherit the fix)
|
||||
|
||||
Once `nostr_core_lib` is updated, these projects that vendor it will pick up the fix when they update their vendored copy:
|
||||
|
||||
- `sovereign_browser/nostr_core_lib/`
|
||||
- `didactyl/nostr_core_lib/`
|
||||
- `fips/nostr_core_lib/`
|
||||
- `fips_access_point/` (if it vendors nostr_core_lib)
|
||||
- `screen_capture/nostr_core_lib/`
|
||||
- `n_os_tr/includes/nostr_core_lib/` and `n_os_tr/includes/didactyl/nostr_core_lib/`
|
||||
|
||||
Each downstream project should update its vendored `nostr_core/nostr_signer.c` with the same 6 string-literal changes. The `nip046.c` file in each vendored copy should NOT be changed (NIP-46 standard names).
|
||||
|
||||
## Projects with their own n_signer clients (separate fixes)
|
||||
|
||||
These projects have their own n_signer client code (not vendored from nostr_core_lib) and need separate fixes:
|
||||
|
||||
- **`nostr_terminal/src/nsigner_client.c`** — many call sites (lines 1054-1452): `"get_public_key"`→`"nostr_get_public_key"`, `"sign_event"`→`"nostr_sign_event"`, `"nip04_encrypt"`→`"nostr_nip04_encrypt"`, `"nip44_encrypt"`→`"nostr_nip44_encrypt"`. Also vendored into `n_os_tr/includes/nostr_terminal/`.
|
||||
- **`codium_nostr_extension/src/signer/nsignerBackend.ts`** — `"get_public_key"` (line 65)→`"nostr_get_public_key"`, `"sign_event"` (line 76)→`"nostr_sign_event"`.
|
||||
- **`nostr_push/nostr_push`** (bash script) — `"sign_event"` (line 394)→`"nostr_sign_event"`, `"get_public_key"`→`"nostr_get_public_key"`.
|
||||
- **`laantungir_website/scripts/get_nsigner_pubkey.js`** — `"get_public_key"` (line 68)→`"nostr_get_public_key"`.
|
||||
- **`laantungir_website/scripts/publish_nostr.js`** — `"get_public_key"` (line 102)→`"nostr_get_public_key"`, `"sign_event"` (line 112)→`"nostr_sign_event"`.
|
||||
- **`sovereign_browser/src/nostr_bridge.c`** — `"nip04_encrypt"` (line 4525)→`"nostr_nip04_encrypt"`, `"nip44_encrypt"` (line 4529)→`"nostr_nip44_encrypt"`.
|
||||
- **`nostr_login_lite`** — check `src/signers/nsigner-webserial.js`, `nsigner-webusb.js`, and the built `www/` bundle for verb calls.
|
||||
@@ -0,0 +1,135 @@
|
||||
# NIP-03 OpenTimestamps Fix Plan
|
||||
|
||||
## Problem Analysis
|
||||
|
||||
The NIP-03 timestamping implementation in `nostr_core/nip003.c` was never working properly due to several critical bugs in the OTS proof parsing and upgrade logic.
|
||||
|
||||
## OTS Binary Format (Verified against real .ots file)
|
||||
|
||||
### File Structure
|
||||
1. **Header magic** (31 bytes): `\x00OpenTimestamps\x00\x00Proof\x00\xbf\x89\xe2\xe8\x84\xe8\x92\x94`
|
||||
2. **Major version** (LEB128 varuint): typically `0x01`
|
||||
3. **File hash op** (1 byte): `0x08` = SHA256
|
||||
4. **File digest** (32 bytes for SHA256)
|
||||
5. **Timestamp tree** (recursive structure)
|
||||
|
||||
### Timestamp Tree Format
|
||||
- Read a tag byte
|
||||
- `0xff` = separator (read next tag, process it, continue looping)
|
||||
- `0x00` = attestation follows
|
||||
- Any other byte = op code (process op, then recursively parse sub-timestamp)
|
||||
- The last tag (not preceded by `0xff`) is the final item
|
||||
|
||||
### Attestation Format (after `0x00` tag)
|
||||
- 8-byte attestation tag:
|
||||
- `83dfe30d2ef90c8e` = PendingAttestation
|
||||
- `0588960d73d71901` = BitcoinBlockHeaderAttestation
|
||||
- `06856e0d73d71901` = LitecoinBlockHeaderAttestation
|
||||
- varuint payload length
|
||||
- payload bytes:
|
||||
- Pending: varbytes (URI string like "https://alice.btc.calendar.opentimestamps.org")
|
||||
- Bitcoin: varuint (block height)
|
||||
- Litecoin: varuint (block height)
|
||||
|
||||
### Op Codes
|
||||
- `0x02` = SHA1 (CryptOp, 20-byte digest)
|
||||
- `0x03` = RIPEMD160 (CryptOp, 20-byte digest)
|
||||
- `0x08` = SHA256 (CryptOp, 32-byte digest)
|
||||
- `0x67` = KECCAK256 (CryptOp, 32-byte digest)
|
||||
- `0xf0` = Append (BinaryOp: varbytes argument)
|
||||
- `0xf1` = Prepend (BinaryOp: varbytes argument)
|
||||
- `0xf2` = Reverse (UnaryOp)
|
||||
- `0xf3` = Hexlify (UnaryOp)
|
||||
|
||||
### LEB128 Varuint Format
|
||||
- Read bytes, each contributes 7 bits (low bits)
|
||||
- High bit (0x80) = continue reading
|
||||
- Low bit = final byte
|
||||
|
||||
### Varbytes Format
|
||||
- varuint length prefix
|
||||
- followed by that many bytes
|
||||
|
||||
## Bugs Found
|
||||
|
||||
### Bug 1: Broken `is_proof_complete` (nip003.c:128)
|
||||
```c
|
||||
if (len > 150) {
|
||||
complete = 1;
|
||||
}
|
||||
```
|
||||
Uses a size heuristic instead of parsing the OTS format. A pending proof can be >150 bytes, and a complete proof might be smaller. Should parse the binary format and look for Bitcoin/Litecoin attestation tags.
|
||||
|
||||
### Bug 2: Flawed `upgrade_proof` (nip003.c:184)
|
||||
```c
|
||||
if (resp.body_len <= len) {
|
||||
nostr_http_response_free(&resp);
|
||||
return NULL;
|
||||
}
|
||||
```
|
||||
Rejects any response that isn't strictly larger. A calendar may return the same proof if nothing changed, or a differently-serialized proof. Should compare content, not just length.
|
||||
|
||||
### Bug 3: CMakeLists.txt missing NIP-03
|
||||
The CMake build only includes a subset of NIPs. `nip003.c` and many other NIP source files are missing from the library build target.
|
||||
|
||||
### Bug 4: No proof verification function
|
||||
No way to verify a proof is cryptographically valid against the Bitcoin blockchain.
|
||||
|
||||
### Bug 5: No signer variant
|
||||
All other NIPs have `_with_signer` variants but NIP-03 only has raw private key version.
|
||||
|
||||
## Implementation Plan
|
||||
|
||||
### Step 1: Add OTS parser to nip003.c
|
||||
Add static helper functions:
|
||||
- `ots_read_varuint(data, pos)` - read LEB128 varuint
|
||||
- `ots_read_varbytes(data, pos)` - read varbytes
|
||||
- `ots_parse_timestamp(data, pos, len, results)` - recursively parse timestamp tree
|
||||
- `ots_find_attestations(data, len)` - top-level parser that finds all attestations
|
||||
|
||||
### Step 2: Fix `nostr_nip03_is_proof_complete`
|
||||
Replace the size heuristic with proper parsing:
|
||||
- Parse the OTS file format
|
||||
- Walk the timestamp tree
|
||||
- Return 1 if any Bitcoin (`0588960d73d71901`) or Litecoin (`06856e0d73d71901`) attestation is found
|
||||
- Return 0 if only pending attestations found
|
||||
- Return -1 on parse error
|
||||
|
||||
### Step 3: Fix `nostr_nip03_upgrade_proof`
|
||||
- Remove the `resp.body_len <= len` check
|
||||
- Accept any valid 200 response with non-empty body
|
||||
- Return the base64-encoded response
|
||||
|
||||
### Step 4: Add `nostr_nip03_verify_proof`
|
||||
New function that:
|
||||
- Parses the OTS proof
|
||||
- Extracts Bitcoin attestation(s) with block height(s)
|
||||
- Optionally fetches the Bitcoin block header from a blockchain API
|
||||
- Verifies the merkle root matches the computed digest
|
||||
- Returns the timestamp (block time) on success
|
||||
|
||||
### Step 5: Add `nostr_nip03_create_proof_event_with_signer`
|
||||
Mirror the pattern used by other NIPs for signer support.
|
||||
|
||||
### Step 6: Fix CMakeLists.txt
|
||||
Add all missing NIP source files to the library build target.
|
||||
|
||||
### Step 7: Add example program
|
||||
Create `examples/timestamping.c` demonstrating the full workflow:
|
||||
- Create a Nostr event
|
||||
- Submit to OTS calendar
|
||||
- Poll for completion
|
||||
- Create proof event
|
||||
- Verify proof
|
||||
|
||||
### Step 8: Fix live test
|
||||
Fix the broken curl debug command in `tests/nip03_live_test.c`.
|
||||
|
||||
### Step 9: Add unit tests
|
||||
Add tests for:
|
||||
- OTS parsing with known test vectors
|
||||
- Proof completeness detection (pending vs complete)
|
||||
- Varuint/varbytes encoding/decoding
|
||||
|
||||
### Step 10: Update documentation
|
||||
Update `README.md` and `nostr_core.h` with NIP-03 function documentation.
|
||||
@@ -3,6 +3,14 @@
|
||||
> Status: M1–M6 implemented. This plan remains as architecture history; for current usage/integration contract see:
|
||||
> - `README.md` → "Signer abstraction & nsigner integration"
|
||||
> - `nostr_core/NSIGNER_INTEGRATION.md`
|
||||
> - `plans/n_signer_verb_migration.md` for the completed Nostr wire-method prefix migration
|
||||
>
|
||||
> **Wire-method update:** n_signer's role-based Nostr methods are now
|
||||
> `nostr_get_public_key`, `nostr_sign_event`, `nostr_nip04_encrypt`,
|
||||
> `nostr_nip04_decrypt`, `nostr_nip44_encrypt`, and `nostr_nip44_decrypt`.
|
||||
> The unprefixed `get_public_key` method is algorithm-based and is not used by the
|
||||
> role/`nostr_index` selectors in this library. Public `nostr_signer_*` C API names
|
||||
> and standard NIP-46 method names are unchanged.
|
||||
>
|
||||
> This plan originally described pulling the **caller-side** signer-integration glue out of per-project implementations and into `nostr_core_lib`,
|
||||
> so any project that already links the library can sign **locally**, via a **running
|
||||
@@ -15,7 +23,7 @@ re-implement the *same* caller-side integration with n_signer:
|
||||
|
||||
- 4-byte big-endian length-prefixed framing
|
||||
- kind-27235 auth envelope (`nsigner_rpc` / `nsigner_method` / `nsigner_body_hash`)
|
||||
- the JSON-RPC verbs (`get_public_key`, `sign_event`, `nip04_*`, `nip44_*`)
|
||||
- the JSON-RPC methods (`nostr_get_public_key`, `nostr_sign_event`, `nostr_nip04_*`, `nostr_nip44_*`)
|
||||
- a per-project `signer.h` abstraction wrapping local-vs-remote signing
|
||||
|
||||
Meanwhile, `nostr_core_lib` exposes ~30+ functions that take a raw
|
||||
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
+53
-7
@@ -2,6 +2,8 @@
|
||||
* NOSTR Core Library - NIP-03 Live Network Test
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include "nostr_core/nostr_core.h"
|
||||
#include "nostr_core/nip003.h"
|
||||
#include <stdio.h>
|
||||
@@ -51,11 +53,17 @@ int main() {
|
||||
char* ots_b64 = nostr_nip03_request_timestamp(event_id, CALENDAR_URL, 15);
|
||||
if (!ots_b64) {
|
||||
printf("❌ Failed to submit to calendar. Trying with curl to debug...\n");
|
||||
/* Use a temp file for the binary digest to avoid shell escaping issues */
|
||||
char cmd[1024];
|
||||
snprintf(cmd, sizeof(cmd), "curl -s -X POST --data-binary @- %s/digest <<EOF\n$(echo \"%s\" | xxd -r -p)\nEOF\n", CALENDAR_URL, event_id);
|
||||
printf("Running: %s\n", cmd);
|
||||
system(cmd);
|
||||
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
"echo '%s' | xxd -r -p > /tmp/ots_digest.bin && "
|
||||
"curl -s -X POST --data-binary @/tmp/ots_digest.bin -H 'Content-Type: application/octet-stream' %s/digest | xxd | head -20",
|
||||
event_id, CALENDAR_URL);
|
||||
printf("Running debug command...\n");
|
||||
int rc = system(cmd);
|
||||
(void)rc;
|
||||
printf("\n");
|
||||
|
||||
cJSON_Delete(event);
|
||||
nostr_cleanup();
|
||||
return 1;
|
||||
@@ -86,16 +94,54 @@ int main() {
|
||||
|
||||
if (complete) {
|
||||
printf("\n🎉 SUCCESS! The proof is now complete with a Bitcoin attestation.\n");
|
||||
|
||||
|
||||
// Get attestation details
|
||||
int has_bitcoin = 0, has_pending = 0;
|
||||
uint64_t btc_height = 0;
|
||||
char* pending_uri = NULL;
|
||||
if (nostr_nip03_get_attestation_info(ots_b64, &has_bitcoin, NULL, &has_pending,
|
||||
&btc_height, NULL, &pending_uri) == 0) {
|
||||
if (has_bitcoin) {
|
||||
printf(" Bitcoin block height: %llu\n", (unsigned long long)btc_height);
|
||||
}
|
||||
if (has_pending && pending_uri) {
|
||||
printf(" Pending calendar: %s\n", pending_uri);
|
||||
free(pending_uri);
|
||||
}
|
||||
}
|
||||
|
||||
// Verify the proof structurally
|
||||
uint64_t verify_height = 0;
|
||||
int verify_rc = nostr_nip03_verify_proof(ots_b64, event_id, &verify_height, NULL);
|
||||
if (verify_rc == 0) {
|
||||
printf(" ✅ Proof verified: digest matches, Bitcoin height=%llu\n",
|
||||
(unsigned long long)verify_height);
|
||||
} else if (verify_rc == -2) {
|
||||
printf(" ⚠️ Proof verification: digest mismatch\n");
|
||||
} else {
|
||||
printf(" ⚠️ Proof verification returned: %d\n", verify_rc);
|
||||
}
|
||||
|
||||
// Create the final Nostr event
|
||||
cJSON* proof_event = nostr_nip03_create_proof_event(event_id, 1, ots_b64, NULL, private_key);
|
||||
char* json = cJSON_Print(proof_event);
|
||||
printf("\nFinal NIP-03 Event:\n%s\n", json);
|
||||
|
||||
|
||||
free(json);
|
||||
cJSON_Delete(proof_event);
|
||||
} else {
|
||||
printf("\n❌ Test timed out after %d minutes. The proof is still pending.\n", attempts);
|
||||
printf("\n❌ Test timed out after %d attempts. The proof is still pending.\n", attempts);
|
||||
|
||||
// Show pending attestation info
|
||||
int has_pending = 0;
|
||||
char* pending_uri = NULL;
|
||||
if (nostr_nip03_get_attestation_info(ots_b64, NULL, NULL, &has_pending,
|
||||
NULL, NULL, &pending_uri) == 0) {
|
||||
if (has_pending && pending_uri) {
|
||||
printf(" Pending at: %s\n", pending_uri);
|
||||
free(pending_uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(ots_b64);
|
||||
|
||||
Executable
BIN
Binary file not shown.
@@ -49,6 +49,174 @@ void test_nip03_create_proof_event() {
|
||||
cJSON_Delete(event);
|
||||
}
|
||||
|
||||
void test_nip03_create_proof_event_with_signer() {
|
||||
printf("🧪 Testing NIP-03 proof event creation with signer...\n");
|
||||
|
||||
unsigned char private_key[32];
|
||||
unsigned char public_key[32];
|
||||
nostr_generate_keypair(private_key, public_key);
|
||||
|
||||
nostr_signer_t* signer = nostr_signer_local(private_key);
|
||||
assert(signer != NULL);
|
||||
|
||||
const char* target_id = "e71c6ea722987debdb60f81f9ea4f604b5ac0664120dd64fb9d23abc4ec7c323";
|
||||
int target_kind = 1;
|
||||
const char* ots_b64 = "base64encodedotsdata";
|
||||
|
||||
cJSON* event = nostr_nip03_create_proof_event_with_signer(target_id, target_kind, ots_b64, NULL, signer);
|
||||
assert(event != NULL);
|
||||
|
||||
// Verify kind
|
||||
cJSON* kind = cJSON_GetObjectItem(event, "kind");
|
||||
assert(kind != NULL && kind->valueint == 1040);
|
||||
|
||||
// Verify content
|
||||
cJSON* content = cJSON_GetObjectItem(event, "content");
|
||||
assert(content != NULL && strcmp(content->valuestring, ots_b64) == 0);
|
||||
|
||||
// Verify tags (no relay URL, so e_tag has only 2 elements)
|
||||
cJSON* tags = cJSON_GetObjectItem(event, "tags");
|
||||
assert(tags != NULL && cJSON_GetArraySize(tags) == 2);
|
||||
|
||||
cJSON* e_tag = cJSON_GetArrayItem(tags, 0);
|
||||
assert(strcmp(cJSON_GetArrayItem(e_tag, 0)->valuestring, "e") == 0);
|
||||
assert(strcmp(cJSON_GetArrayItem(e_tag, 1)->valuestring, target_id) == 0);
|
||||
assert(cJSON_GetArraySize(e_tag) == 2); /* no relay URL */
|
||||
|
||||
printf("✅ NIP-03 proof event creation with signer test passed!\n");
|
||||
cJSON_Delete(event);
|
||||
nostr_signer_free(signer);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a real pending OTS proof (base64 encoded) from the OpenTimestamps
|
||||
* calendar. It contains only pending attestations (no Bitcoin attestation),
|
||||
* so is_proof_complete should return 0.
|
||||
*
|
||||
* The proof was generated for a test file and submitted to 3 calendars:
|
||||
* - alice.btc.calendar.opentimestamps.org
|
||||
* - bob.btc.calendar.opentimestamps.org
|
||||
* - finney.calendar.eternitywall.com
|
||||
*
|
||||
* File digest (SHA256): dd4861b2521f83430a93696ca83b085b7fb8fd17ed6a2cee9496ec87d9fd0d6c
|
||||
*/
|
||||
static const char* PENDING_OTS_B64 =
|
||||
"AE9wZW5UaW1lc3RhbXBzAABQcm9vZgC/ieLohOiSlAEI3UhhslIfg0MKk2lsqDsIW3+4/Rftaizu"
|
||||
"lJbsh9n9DWzwEPH1H7z7SBTEU40qNFhcPKcI//AIxd2zXDTCN5cI8BCIgv8EsqQXO7DY4MNvo50e"
|
||||
"CPEgksMhj36iAZdVcrXi4Q+Y/opid1wVrerjQ+gjGP5DB3wI8QRqVlUo8Ai72PBveP4l/QCD3+MN"
|
||||
"LvkMji4taHR0cHM6Ly9hbGljZS5idGMuY2FsZW5kYXIub3BlbnRpbWVzdGFtcHMub3Jn//AIb923"
|
||||
"oTIXfHkI8BDEnrX0tZZwN/drZnEOh+sACPEgcsd1lsM45YKtSytPZWr+Wkn3MMffWkFzj0qK7ehe"
|
||||
"90wI8QRqVlUo8AjeBSDPqcrx9QCD3+MNLvkMjiwraHR0cHM6Ly9ib2IuYnRjLmNhbGVuZGFyLm9w"
|
||||
"ZW50aW1lc3RhbXBzLm9yZ/AQjt5nZXTx0ZchzqvQ2HoNoAjxIKzXgsLhE8UXDdGZSuVT9f5FvggB"
|
||||
"2nwYP7dmO/NjZwO1CPEEalZVKfAIeB6WGBjHG7gAg9/jDS75DI4pKGh0dHBzOi8vZmlubmV5LmNh"
|
||||
"bGVuZGFyLmV0ZXJuaXR5d2FsbC5jb20=";
|
||||
|
||||
void test_nip03_is_proof_complete_pending() {
|
||||
printf("🧪 Testing NIP-03 is_proof_complete with pending proof...\n");
|
||||
|
||||
int result = nostr_nip03_is_proof_complete(PENDING_OTS_B64);
|
||||
printf(" Result: %d (expected 0 = pending)\n", result);
|
||||
assert(result == 0);
|
||||
|
||||
printf("✅ NIP-03 is_proof_complete (pending) test passed!\n");
|
||||
}
|
||||
|
||||
void test_nip03_get_attestation_info_pending() {
|
||||
printf("🧪 Testing NIP-03 get_attestation_info with pending proof...\n");
|
||||
|
||||
int has_bitcoin = 0, has_litecoin = 0, has_pending = 0;
|
||||
uint64_t btc_height = 0, ltc_height = 0;
|
||||
char* pending_uri = NULL;
|
||||
|
||||
int rc = nostr_nip03_get_attestation_info(PENDING_OTS_B64,
|
||||
&has_bitcoin, &has_litecoin, &has_pending,
|
||||
&btc_height, <c_height, &pending_uri);
|
||||
assert(rc == 0);
|
||||
assert(has_bitcoin == 0);
|
||||
assert(has_litecoin == 0);
|
||||
assert(has_pending == 1);
|
||||
assert(pending_uri != NULL);
|
||||
|
||||
printf(" Pending URI: %s\n", pending_uri);
|
||||
/* Should be one of the known calendar URLs */
|
||||
assert(strstr(pending_uri, "opentimestamps.org") != NULL ||
|
||||
strstr(pending_uri, "eternitywall.com") != NULL);
|
||||
|
||||
free(pending_uri);
|
||||
|
||||
printf("✅ NIP-03 get_attestation_info (pending) test passed!\n");
|
||||
}
|
||||
|
||||
void test_nip03_is_proof_complete_invalid() {
|
||||
printf("🧪 Testing NIP-03 is_proof_complete with invalid data...\n");
|
||||
|
||||
/* Invalid base64 / not an OTS file */
|
||||
int result = nostr_nip03_is_proof_complete("notavalidotsfile");
|
||||
printf(" Result: %d (expected -1 = error)\n", result);
|
||||
assert(result == -1);
|
||||
|
||||
/* NULL input */
|
||||
result = nostr_nip03_is_proof_complete(NULL);
|
||||
assert(result == -1);
|
||||
|
||||
printf("✅ NIP-03 is_proof_complete (invalid) test passed!\n");
|
||||
}
|
||||
|
||||
void test_nip03_verify_proof_pending() {
|
||||
printf("🧪 Testing NIP-03 verify_proof with pending proof...\n");
|
||||
|
||||
/* The file digest for this proof */
|
||||
const char* expected_digest = "dd4861b2521f83430a93696ca83b085b7fb8fd17ed6a2cee9496ec87d9fd0d6c";
|
||||
|
||||
uint64_t block_height = 0;
|
||||
time_t block_time = 0;
|
||||
|
||||
int rc = nostr_nip03_verify_proof(PENDING_OTS_B64, expected_digest,
|
||||
&block_height, &block_time);
|
||||
printf(" Result: %d (expected 1 = no bitcoin attestation)\n", rc);
|
||||
/* Should return 1 (no Bitcoin attestation found, but digest matches) */
|
||||
assert(rc == 1);
|
||||
|
||||
/* Test with wrong digest */
|
||||
rc = nostr_nip03_verify_proof(PENDING_OTS_B64,
|
||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
&block_height, &block_time);
|
||||
printf(" Result with wrong digest: %d (expected -2 = digest mismatch)\n", rc);
|
||||
assert(rc == -2);
|
||||
|
||||
printf("✅ NIP-03 verify_proof (pending) test passed!\n");
|
||||
}
|
||||
|
||||
void test_nip03_create_and_verify_roundtrip() {
|
||||
printf("🧪 Testing NIP-03 create proof event + verify roundtrip...\n");
|
||||
|
||||
unsigned char private_key[32];
|
||||
unsigned char public_key[32];
|
||||
nostr_generate_keypair(private_key, public_key);
|
||||
|
||||
/* Create a proof event with the pending OTS data */
|
||||
const char* target_id = "dd4861b2521f83430a93696ca83b085b7fb8fd17ed6a2cee9496ec87d9fd0d6c";
|
||||
cJSON* proof_event = nostr_nip03_create_proof_event(target_id, 1, PENDING_OTS_B64, NULL, private_key);
|
||||
assert(proof_event != NULL);
|
||||
|
||||
/* Verify the event is valid */
|
||||
int validate_rc = nostr_validate_event(proof_event);
|
||||
assert(validate_rc == NOSTR_SUCCESS);
|
||||
|
||||
/* Extract the OTS data from the event content and check completeness */
|
||||
cJSON* content = cJSON_GetObjectItem(proof_event, "content");
|
||||
assert(content != NULL && cJSON_IsString(content));
|
||||
int complete = nostr_nip03_is_proof_complete(content->valuestring);
|
||||
assert(complete == 0); /* pending */
|
||||
|
||||
char* json = cJSON_Print(proof_event);
|
||||
printf(" Created proof event (kind 1040), %zu bytes\n", strlen(json));
|
||||
free(json);
|
||||
|
||||
cJSON_Delete(proof_event);
|
||||
printf("✅ NIP-03 create + verify roundtrip test passed!\n");
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (nostr_init() != NOSTR_SUCCESS) {
|
||||
fprintf(stderr, "Failed to initialize NOSTR library\n");
|
||||
@@ -56,9 +224,16 @@ int main() {
|
||||
}
|
||||
|
||||
test_nip03_create_proof_event();
|
||||
test_nip03_create_proof_event_with_signer();
|
||||
test_nip03_is_proof_complete_pending();
|
||||
test_nip03_get_attestation_info_pending();
|
||||
test_nip03_is_proof_complete_invalid();
|
||||
test_nip03_verify_proof_pending();
|
||||
test_nip03_create_and_verify_roundtrip();
|
||||
|
||||
// Note: We don't test nostr_nip03_request_timestamp here as it requires a live OTS calendar
|
||||
// and network access, which might be flaky in a test environment.
|
||||
// See tests/nip03_live_test.c for live network tests.
|
||||
|
||||
nostr_cleanup();
|
||||
printf("\n🎉 All NIP-03 tests passed!\n");
|
||||
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -11,6 +11,7 @@
|
||||
#include "../nostr_core/nsigner_client.h"
|
||||
#include "../nostr_core/utils.h"
|
||||
#include "../cjson/cJSON.h"
|
||||
#include "../nostr_core/nostr_signer.h"
|
||||
|
||||
static int test_count = 0;
|
||||
static int passed_count = 0;
|
||||
@@ -44,7 +45,7 @@ static int write_full_fd(int fd, const unsigned char* buf, size_t len) {
|
||||
|
||||
static int test_framing_round_trip(void) {
|
||||
int fds[2] = {-1, -1};
|
||||
const char* msg = "{\"id\":\"1\",\"method\":\"get_public_key\",\"params\":[]}";
|
||||
const char* msg = "{\"id\":\"1\",\"method\":\"nostr_get_public_key\",\"params\":[]}";
|
||||
char* out = NULL;
|
||||
size_t out_len = 0;
|
||||
int ok = 0;
|
||||
@@ -80,7 +81,7 @@ cleanup:
|
||||
|
||||
static int test_framing_fragmented_read_reassembly(void) {
|
||||
int fds[2] = {-1, -1};
|
||||
const char* msg = "{\"id\":\"2\",\"method\":\"sign_event\",\"params\":[\"abc\"]}";
|
||||
const char* msg = "{\"id\":\"2\",\"method\":\"nostr_sign_event\",\"params\":[\"abc\"]}";
|
||||
unsigned int len = (unsigned int)strlen(msg);
|
||||
unsigned char hdr[4];
|
||||
char* out = NULL;
|
||||
@@ -250,7 +251,7 @@ static int test_fds_transport_round_trip_via_client(void) {
|
||||
}
|
||||
req[req_len] = '\0';
|
||||
|
||||
if (strstr(req, "\"method\":\"get_public_key\"") == NULL) {
|
||||
if (strstr(req, "\"method\":\"nostr_get_public_key\"") == NULL) {
|
||||
free(req);
|
||||
_exit(6);
|
||||
}
|
||||
@@ -293,7 +294,7 @@ static int test_fds_transport_round_trip_via_client(void) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (nsigner_client_call(client, "get_public_key", params, &result) != NOSTR_SUCCESS) {
|
||||
if (nsigner_client_call(client, "nostr_get_public_key", params, &result) != NOSTR_SUCCESS) {
|
||||
params = NULL;
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -332,6 +333,66 @@ cleanup:
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* Local-signer derive_hmac: HMAC-SHA256(privkey, data) via the high-level API
|
||||
* must match nostr_hmac_sha256 computed directly with the same privkey. */
|
||||
static int test_local_derive_hmac_matches_reference(void) {
|
||||
unsigned char privkey[32];
|
||||
nostr_signer_t* signer = NULL;
|
||||
char got_hex[65];
|
||||
unsigned char ref_mac[32];
|
||||
char ref_hex[65];
|
||||
int ok = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
privkey[i] = (unsigned char)(i + 1);
|
||||
}
|
||||
|
||||
signer = nostr_signer_local(privkey);
|
||||
if (signer == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (nostr_signer_derive_hmac(signer, "sovereign-browser/bookmarks-folder-id-v1:Work/Projects", got_hex) != NOSTR_SUCCESS) {
|
||||
nostr_signer_free(signer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (nostr_hmac_sha256(privkey, 32,
|
||||
(const unsigned char*)"sovereign-browser/bookmarks-folder-id-v1:Work/Projects",
|
||||
strlen("sovereign-browser/bookmarks-folder-id-v1:Work/Projects"),
|
||||
ref_mac) != 0) {
|
||||
nostr_signer_free(signer);
|
||||
return 0;
|
||||
}
|
||||
nostr_bytes_to_hex(ref_mac, 32, ref_hex);
|
||||
|
||||
ok = (strlen(got_hex) == 64 && strcmp(got_hex, ref_hex) == 0);
|
||||
|
||||
/* Determinism: same input -> same digest. */
|
||||
{
|
||||
char got2_hex[65];
|
||||
if (nostr_signer_derive_hmac(signer, "sovereign-browser/bookmarks-folder-id-v1:Work/Projects", got2_hex) == NOSTR_SUCCESS) {
|
||||
ok = ok && (strcmp(got_hex, got2_hex) == 0);
|
||||
} else {
|
||||
ok = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Opaqueness: different input -> different digest. */
|
||||
{
|
||||
char other_hex[65];
|
||||
if (nostr_signer_derive_hmac(signer, "sovereign-browser/bookmarks-folder-id-v1:Personal", other_hex) == NOSTR_SUCCESS) {
|
||||
ok = ok && (strcmp(got_hex, other_hex) != 0);
|
||||
} else {
|
||||
ok = 0;
|
||||
}
|
||||
}
|
||||
|
||||
nostr_signer_free(signer);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
#if !defined(NOSTR_ENABLE_NSIGNER_CLIENT)
|
||||
printf("nsigner client disabled in this build; skipping\n");
|
||||
@@ -342,6 +403,7 @@ int main(void) {
|
||||
run_result("auth body hash matches sha256(compact params)", test_body_hash_matches_sha256_compact_params());
|
||||
run_result("/proc/net/unix discovery parser no-crash", test_unix_discovery_no_crash());
|
||||
run_result("fds transport client round-trip over framed fd pair", test_fds_transport_round_trip_via_client());
|
||||
run_result("local signer derive_hmac matches reference HMAC-SHA256", test_local_derive_hmac_matches_reference());
|
||||
|
||||
printf("\nTotal: %d Passed: %d Failed: %d\n", test_count, passed_count, test_count - passed_count);
|
||||
return (test_count == passed_count) ? 0 : 1;
|
||||
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -1 +0,0 @@
|
||||
ref: refs/heads/master
|
||||
@@ -1,8 +0,0 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = true
|
||||
[remote "origin"]
|
||||
url = git@git.laantungir.net:laantungir/nostr_core_lib.git
|
||||
fetch = +refs/*:refs/*
|
||||
mirror = true
|
||||
@@ -1 +0,0 @@
|
||||
Unnamed repository; edit this file 'description' to name the repository.
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to check the commit log message taken by
|
||||
# applypatch from an e-mail message.
|
||||
#
|
||||
# The hook should exit with non-zero status after issuing an
|
||||
# appropriate message if it wants to stop the commit. The hook is
|
||||
# allowed to edit the commit message file.
|
||||
#
|
||||
# To enable this hook, rename this file to "applypatch-msg".
|
||||
|
||||
. git-sh-setup
|
||||
commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
|
||||
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
|
||||
:
|
||||
@@ -1,24 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to check the commit log message.
|
||||
# Called by "git commit" with one argument, the name of the file
|
||||
# that has the commit message. The hook should exit with non-zero
|
||||
# status after issuing an appropriate message if it wants to stop the
|
||||
# commit. The hook is allowed to edit the commit message file.
|
||||
#
|
||||
# To enable this hook, rename this file to "commit-msg".
|
||||
|
||||
# Uncomment the below to add a Signed-off-by line to the message.
|
||||
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
|
||||
# hook is more suited to it.
|
||||
#
|
||||
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
|
||||
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
|
||||
|
||||
# This example catches duplicate Signed-off-by lines.
|
||||
|
||||
test "" = "$(grep '^Signed-off-by: ' "$1" |
|
||||
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
|
||||
echo >&2 Duplicate Signed-off-by lines.
|
||||
exit 1
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use IPC::Open2;
|
||||
|
||||
# An example hook script to integrate Watchman
|
||||
# (https://facebook.github.io/watchman/) with git to speed up detecting
|
||||
# new and modified files.
|
||||
#
|
||||
# The hook is passed a version (currently 2) and last update token
|
||||
# formatted as a string and outputs to stdout a new update token and
|
||||
# all files that have been modified since the update token. Paths must
|
||||
# be relative to the root of the working tree and separated by a single NUL.
|
||||
#
|
||||
# To enable this hook, rename this file to "query-watchman" and set
|
||||
# 'git config core.fsmonitor .git/hooks/query-watchman'
|
||||
#
|
||||
my ($version, $last_update_token) = @ARGV;
|
||||
|
||||
# Uncomment for debugging
|
||||
# print STDERR "$0 $version $last_update_token\n";
|
||||
|
||||
# Check the hook interface version
|
||||
if ($version ne 2) {
|
||||
die "Unsupported query-fsmonitor hook version '$version'.\n" .
|
||||
"Falling back to scanning...\n";
|
||||
}
|
||||
|
||||
my $git_work_tree = get_working_dir();
|
||||
|
||||
my $retry = 1;
|
||||
|
||||
my $json_pkg;
|
||||
eval {
|
||||
require JSON::XS;
|
||||
$json_pkg = "JSON::XS";
|
||||
1;
|
||||
} or do {
|
||||
require JSON::PP;
|
||||
$json_pkg = "JSON::PP";
|
||||
};
|
||||
|
||||
launch_watchman();
|
||||
|
||||
sub launch_watchman {
|
||||
my $o = watchman_query();
|
||||
if (is_work_tree_watched($o)) {
|
||||
output_result($o->{clock}, @{$o->{files}});
|
||||
}
|
||||
}
|
||||
|
||||
sub output_result {
|
||||
my ($clockid, @files) = @_;
|
||||
|
||||
# Uncomment for debugging watchman output
|
||||
# open (my $fh, ">", ".git/watchman-output.out");
|
||||
# binmode $fh, ":utf8";
|
||||
# print $fh "$clockid\n@files\n";
|
||||
# close $fh;
|
||||
|
||||
binmode STDOUT, ":utf8";
|
||||
print $clockid;
|
||||
print "\0";
|
||||
local $, = "\0";
|
||||
print @files;
|
||||
}
|
||||
|
||||
sub watchman_clock {
|
||||
my $response = qx/watchman clock "$git_work_tree"/;
|
||||
die "Failed to get clock id on '$git_work_tree'.\n" .
|
||||
"Falling back to scanning...\n" if $? != 0;
|
||||
|
||||
return $json_pkg->new->utf8->decode($response);
|
||||
}
|
||||
|
||||
sub watchman_query {
|
||||
my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty')
|
||||
or die "open2() failed: $!\n" .
|
||||
"Falling back to scanning...\n";
|
||||
|
||||
# In the query expression below we're asking for names of files that
|
||||
# changed since $last_update_token but not from the .git folder.
|
||||
#
|
||||
# To accomplish this, we're using the "since" generator to use the
|
||||
# recency index to select candidate nodes and "fields" to limit the
|
||||
# output to file names only. Then we're using the "expression" term to
|
||||
# further constrain the results.
|
||||
my $last_update_line = "";
|
||||
if (substr($last_update_token, 0, 1) eq "c") {
|
||||
$last_update_token = "\"$last_update_token\"";
|
||||
$last_update_line = qq[\n"since": $last_update_token,];
|
||||
}
|
||||
my $query = <<" END";
|
||||
["query", "$git_work_tree", {$last_update_line
|
||||
"fields": ["name"],
|
||||
"expression": ["not", ["dirname", ".git"]]
|
||||
}]
|
||||
END
|
||||
|
||||
# Uncomment for debugging the watchman query
|
||||
# open (my $fh, ">", ".git/watchman-query.json");
|
||||
# print $fh $query;
|
||||
# close $fh;
|
||||
|
||||
print CHLD_IN $query;
|
||||
close CHLD_IN;
|
||||
my $response = do {local $/; <CHLD_OUT>};
|
||||
|
||||
# Uncomment for debugging the watch response
|
||||
# open ($fh, ">", ".git/watchman-response.json");
|
||||
# print $fh $response;
|
||||
# close $fh;
|
||||
|
||||
die "Watchman: command returned no output.\n" .
|
||||
"Falling back to scanning...\n" if $response eq "";
|
||||
die "Watchman: command returned invalid output: $response\n" .
|
||||
"Falling back to scanning...\n" unless $response =~ /^\{/;
|
||||
|
||||
return $json_pkg->new->utf8->decode($response);
|
||||
}
|
||||
|
||||
sub is_work_tree_watched {
|
||||
my ($output) = @_;
|
||||
my $error = $output->{error};
|
||||
if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) {
|
||||
$retry--;
|
||||
my $response = qx/watchman watch "$git_work_tree"/;
|
||||
die "Failed to make watchman watch '$git_work_tree'.\n" .
|
||||
"Falling back to scanning...\n" if $? != 0;
|
||||
$output = $json_pkg->new->utf8->decode($response);
|
||||
$error = $output->{error};
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
# Uncomment for debugging watchman output
|
||||
# open (my $fh, ">", ".git/watchman-output.out");
|
||||
# close $fh;
|
||||
|
||||
# Watchman will always return all files on the first query so
|
||||
# return the fast "everything is dirty" flag to git and do the
|
||||
# Watchman query just to get it over with now so we won't pay
|
||||
# the cost in git to look up each individual file.
|
||||
my $o = watchman_clock();
|
||||
$error = $output->{error};
|
||||
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
output_result($o->{clock}, ("/"));
|
||||
$last_update_token = $o->{clock};
|
||||
|
||||
eval { launch_watchman() };
|
||||
return 0;
|
||||
}
|
||||
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub get_working_dir {
|
||||
my $working_dir;
|
||||
if ($^O =~ 'msys' || $^O =~ 'cygwin') {
|
||||
$working_dir = Win32::GetCwd();
|
||||
$working_dir =~ tr/\\/\//;
|
||||
} else {
|
||||
require Cwd;
|
||||
$working_dir = Cwd::cwd();
|
||||
}
|
||||
|
||||
return $working_dir;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to prepare a packed repository for use over
|
||||
# dumb transports.
|
||||
#
|
||||
# To enable this hook, rename this file to "post-update".
|
||||
|
||||
exec git update-server-info
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed
|
||||
# by applypatch from an e-mail message.
|
||||
#
|
||||
# The hook should exit with non-zero status after issuing an
|
||||
# appropriate message if it wants to stop the commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-applypatch".
|
||||
|
||||
. git-sh-setup
|
||||
precommit="$(git rev-parse --git-path hooks/pre-commit)"
|
||||
test -x "$precommit" && exec "$precommit" ${1+"$@"}
|
||||
:
|
||||
@@ -1,49 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed.
|
||||
# Called by "git commit" with no arguments. The hook should
|
||||
# exit with non-zero status after issuing an appropriate message if
|
||||
# it wants to stop the commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-commit".
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=$(git hash-object -t tree /dev/null)
|
||||
fi
|
||||
|
||||
# If you want to allow non-ASCII filenames set this variable to true.
|
||||
allownonascii=$(git config --type=bool hooks.allownonascii)
|
||||
|
||||
# Redirect output to stderr.
|
||||
exec 1>&2
|
||||
|
||||
# Cross platform projects tend to avoid non-ASCII filenames; prevent
|
||||
# them from being added to the repository. We exploit the fact that the
|
||||
# printable range starts at the space character and ends with tilde.
|
||||
if [ "$allownonascii" != "true" ] &&
|
||||
# Note that the use of brackets around a tr range is ok here, (it's
|
||||
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
||||
# the square bracket bytes happen to fall in the designated range.
|
||||
test $(git diff-index --cached --name-only --diff-filter=A -z $against |
|
||||
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||
then
|
||||
cat <<\EOF
|
||||
Error: Attempt to add a non-ASCII file name.
|
||||
|
||||
This can cause problems if you want to work with people on other platforms.
|
||||
|
||||
To be portable it is advisable to rename the file.
|
||||
|
||||
If you know what you are doing you can disable this check using:
|
||||
|
||||
git config hooks.allownonascii true
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If there are whitespace errors, print the offending file names and fail.
|
||||
exec git diff-index --check --cached $against --
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed.
|
||||
# Called by "git merge" with no arguments. The hook should
|
||||
# exit with non-zero status after issuing an appropriate message to
|
||||
# stderr if it wants to stop the merge commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-merge-commit".
|
||||
|
||||
. git-sh-setup
|
||||
test -x "$GIT_DIR/hooks/pre-commit" &&
|
||||
exec "$GIT_DIR/hooks/pre-commit"
|
||||
:
|
||||
@@ -1,53 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# An example hook script to verify what is about to be pushed. Called by "git
|
||||
# push" after it has checked the remote status, but before anything has been
|
||||
# pushed. If this script exits with a non-zero status nothing will be pushed.
|
||||
#
|
||||
# This hook is called with the following parameters:
|
||||
#
|
||||
# $1 -- Name of the remote to which the push is being done
|
||||
# $2 -- URL to which the push is being done
|
||||
#
|
||||
# If pushing without using a named remote those arguments will be equal.
|
||||
#
|
||||
# Information about the commits which are being pushed is supplied as lines to
|
||||
# the standard input in the form:
|
||||
#
|
||||
# <local ref> <local oid> <remote ref> <remote oid>
|
||||
#
|
||||
# This sample shows how to prevent push of commits where the log message starts
|
||||
# with "WIP" (work in progress).
|
||||
|
||||
remote="$1"
|
||||
url="$2"
|
||||
|
||||
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
|
||||
|
||||
while read local_ref local_oid remote_ref remote_oid
|
||||
do
|
||||
if test "$local_oid" = "$zero"
|
||||
then
|
||||
# Handle delete
|
||||
:
|
||||
else
|
||||
if test "$remote_oid" = "$zero"
|
||||
then
|
||||
# New branch, examine all commits
|
||||
range="$local_oid"
|
||||
else
|
||||
# Update to existing branch, examine new commits
|
||||
range="$remote_oid..$local_oid"
|
||||
fi
|
||||
|
||||
# Check for WIP commit
|
||||
commit=$(git rev-list -n 1 --grep '^WIP' "$range")
|
||||
if test -n "$commit"
|
||||
then
|
||||
echo >&2 "Found WIP commit in $local_ref, not pushing"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
@@ -1,169 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2006, 2008 Junio C Hamano
|
||||
#
|
||||
# The "pre-rebase" hook is run just before "git rebase" starts doing
|
||||
# its job, and can prevent the command from running by exiting with
|
||||
# non-zero status.
|
||||
#
|
||||
# The hook is called with the following parameters:
|
||||
#
|
||||
# $1 -- the upstream the series was forked from.
|
||||
# $2 -- the branch being rebased (or empty when rebasing the current branch).
|
||||
#
|
||||
# This sample shows how to prevent topic branches that are already
|
||||
# merged to 'next' branch from getting rebased, because allowing it
|
||||
# would result in rebasing already published history.
|
||||
|
||||
publish=next
|
||||
basebranch="$1"
|
||||
if test "$#" = 2
|
||||
then
|
||||
topic="refs/heads/$2"
|
||||
else
|
||||
topic=`git symbolic-ref HEAD` ||
|
||||
exit 0 ;# we do not interrupt rebasing detached HEAD
|
||||
fi
|
||||
|
||||
case "$topic" in
|
||||
refs/heads/??/*)
|
||||
;;
|
||||
*)
|
||||
exit 0 ;# we do not interrupt others.
|
||||
;;
|
||||
esac
|
||||
|
||||
# Now we are dealing with a topic branch being rebased
|
||||
# on top of master. Is it OK to rebase it?
|
||||
|
||||
# Does the topic really exist?
|
||||
git show-ref -q "$topic" || {
|
||||
echo >&2 "No such branch $topic"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Is topic fully merged to master?
|
||||
not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
|
||||
if test -z "$not_in_master"
|
||||
then
|
||||
echo >&2 "$topic is fully merged to master; better remove it."
|
||||
exit 1 ;# we could allow it, but there is no point.
|
||||
fi
|
||||
|
||||
# Is topic ever merged to next? If so you should not be rebasing it.
|
||||
only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
|
||||
only_next_2=`git rev-list ^master ${publish} | sort`
|
||||
if test "$only_next_1" = "$only_next_2"
|
||||
then
|
||||
not_in_topic=`git rev-list "^$topic" master`
|
||||
if test -z "$not_in_topic"
|
||||
then
|
||||
echo >&2 "$topic is already up to date with master"
|
||||
exit 1 ;# we could allow it, but there is no point.
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
|
||||
/usr/bin/perl -e '
|
||||
my $topic = $ARGV[0];
|
||||
my $msg = "* $topic has commits already merged to public branch:\n";
|
||||
my (%not_in_next) = map {
|
||||
/^([0-9a-f]+) /;
|
||||
($1 => 1);
|
||||
} split(/\n/, $ARGV[1]);
|
||||
for my $elem (map {
|
||||
/^([0-9a-f]+) (.*)$/;
|
||||
[$1 => $2];
|
||||
} split(/\n/, $ARGV[2])) {
|
||||
if (!exists $not_in_next{$elem->[0]}) {
|
||||
if ($msg) {
|
||||
print STDERR $msg;
|
||||
undef $msg;
|
||||
}
|
||||
print STDERR " $elem->[1]\n";
|
||||
}
|
||||
}
|
||||
' "$topic" "$not_in_next" "$not_in_master"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
<<\DOC_END
|
||||
|
||||
This sample hook safeguards topic branches that have been
|
||||
published from being rewound.
|
||||
|
||||
The workflow assumed here is:
|
||||
|
||||
* Once a topic branch forks from "master", "master" is never
|
||||
merged into it again (either directly or indirectly).
|
||||
|
||||
* Once a topic branch is fully cooked and merged into "master",
|
||||
it is deleted. If you need to build on top of it to correct
|
||||
earlier mistakes, a new topic branch is created by forking at
|
||||
the tip of the "master". This is not strictly necessary, but
|
||||
it makes it easier to keep your history simple.
|
||||
|
||||
* Whenever you need to test or publish your changes to topic
|
||||
branches, merge them into "next" branch.
|
||||
|
||||
The script, being an example, hardcodes the publish branch name
|
||||
to be "next", but it is trivial to make it configurable via
|
||||
$GIT_DIR/config mechanism.
|
||||
|
||||
With this workflow, you would want to know:
|
||||
|
||||
(1) ... if a topic branch has ever been merged to "next". Young
|
||||
topic branches can have stupid mistakes you would rather
|
||||
clean up before publishing, and things that have not been
|
||||
merged into other branches can be easily rebased without
|
||||
affecting other people. But once it is published, you would
|
||||
not want to rewind it.
|
||||
|
||||
(2) ... if a topic branch has been fully merged to "master".
|
||||
Then you can delete it. More importantly, you should not
|
||||
build on top of it -- other people may already want to
|
||||
change things related to the topic as patches against your
|
||||
"master", so if you need further changes, it is better to
|
||||
fork the topic (perhaps with the same name) afresh from the
|
||||
tip of "master".
|
||||
|
||||
Let's look at this example:
|
||||
|
||||
o---o---o---o---o---o---o---o---o---o "next"
|
||||
/ / / /
|
||||
/ a---a---b A / /
|
||||
/ / / /
|
||||
/ / c---c---c---c B /
|
||||
/ / / \ /
|
||||
/ / / b---b C \ /
|
||||
/ / / / \ /
|
||||
---o---o---o---o---o---o---o---o---o---o---o "master"
|
||||
|
||||
|
||||
A, B and C are topic branches.
|
||||
|
||||
* A has one fix since it was merged up to "next".
|
||||
|
||||
* B has finished. It has been fully merged up to "master" and "next",
|
||||
and is ready to be deleted.
|
||||
|
||||
* C has not merged to "next" at all.
|
||||
|
||||
We would want to allow C to be rebased, refuse A, and encourage
|
||||
B to be deleted.
|
||||
|
||||
To compute (1):
|
||||
|
||||
git rev-list ^master ^topic next
|
||||
git rev-list ^master next
|
||||
|
||||
if these match, topic has not merged in next at all.
|
||||
|
||||
To compute (2):
|
||||
|
||||
git rev-list master..topic
|
||||
|
||||
if this is empty, it is fully merged to "master".
|
||||
|
||||
DOC_END
|
||||
@@ -1,24 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to make use of push options.
|
||||
# The example simply echoes all push options that start with 'echoback='
|
||||
# and rejects all pushes when the "reject" push option is used.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-receive".
|
||||
|
||||
if test -n "$GIT_PUSH_OPTION_COUNT"
|
||||
then
|
||||
i=0
|
||||
while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"
|
||||
do
|
||||
eval "value=\$GIT_PUSH_OPTION_$i"
|
||||
case "$value" in
|
||||
echoback=*)
|
||||
echo "echo from the pre-receive-hook: ${value#*=}" >&2
|
||||
;;
|
||||
reject)
|
||||
exit 1
|
||||
esac
|
||||
i=$((i + 1))
|
||||
done
|
||||
fi
|
||||
@@ -1,42 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to prepare the commit log message.
|
||||
# Called by "git commit" with the name of the file that has the
|
||||
# commit message, followed by the description of the commit
|
||||
# message's source. The hook's purpose is to edit the commit
|
||||
# message file. If the hook fails with a non-zero status,
|
||||
# the commit is aborted.
|
||||
#
|
||||
# To enable this hook, rename this file to "prepare-commit-msg".
|
||||
|
||||
# This hook includes three examples. The first one removes the
|
||||
# "# Please enter the commit message..." help message.
|
||||
#
|
||||
# The second includes the output of "git diff --name-status -r"
|
||||
# into the message, just before the "git status" output. It is
|
||||
# commented because it doesn't cope with --amend or with squashed
|
||||
# commits.
|
||||
#
|
||||
# The third example adds a Signed-off-by line to the message, that can
|
||||
# still be edited. This is rarely a good idea.
|
||||
|
||||
COMMIT_MSG_FILE=$1
|
||||
COMMIT_SOURCE=$2
|
||||
SHA1=$3
|
||||
|
||||
/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
|
||||
|
||||
# case "$COMMIT_SOURCE,$SHA1" in
|
||||
# ,|template,)
|
||||
# /usr/bin/perl -i.bak -pe '
|
||||
# print "\n" . `git diff --cached --name-status -r`
|
||||
# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;;
|
||||
# *) ;;
|
||||
# esac
|
||||
|
||||
# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
|
||||
# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
|
||||
# if test -z "$COMMIT_SOURCE"
|
||||
# then
|
||||
# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
|
||||
# fi
|
||||
@@ -1,78 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# An example hook script to update a checked-out tree on a git push.
|
||||
#
|
||||
# This hook is invoked by git-receive-pack(1) when it reacts to git
|
||||
# push and updates reference(s) in its repository, and when the push
|
||||
# tries to update the branch that is currently checked out and the
|
||||
# receive.denyCurrentBranch configuration variable is set to
|
||||
# updateInstead.
|
||||
#
|
||||
# By default, such a push is refused if the working tree and the index
|
||||
# of the remote repository has any difference from the currently
|
||||
# checked out commit; when both the working tree and the index match
|
||||
# the current commit, they are updated to match the newly pushed tip
|
||||
# of the branch. This hook is to be used to override the default
|
||||
# behaviour; however the code below reimplements the default behaviour
|
||||
# as a starting point for convenient modification.
|
||||
#
|
||||
# The hook receives the commit with which the tip of the current
|
||||
# branch is going to be updated:
|
||||
commit=$1
|
||||
|
||||
# It can exit with a non-zero status to refuse the push (when it does
|
||||
# so, it must not modify the index or the working tree).
|
||||
die () {
|
||||
echo >&2 "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Or it can make any necessary changes to the working tree and to the
|
||||
# index to bring them to the desired state when the tip of the current
|
||||
# branch is updated to the new commit, and exit with a zero status.
|
||||
#
|
||||
# For example, the hook can simply run git read-tree -u -m HEAD "$1"
|
||||
# in order to emulate git fetch that is run in the reverse direction
|
||||
# with git push, as the two-tree form of git read-tree -u -m is
|
||||
# essentially the same as git switch or git checkout that switches
|
||||
# branches while keeping the local changes in the working tree that do
|
||||
# not interfere with the difference between the branches.
|
||||
|
||||
# The below is a more-or-less exact translation to shell of the C code
|
||||
# for the default behaviour for git's push-to-checkout hook defined in
|
||||
# the push_to_deploy() function in builtin/receive-pack.c.
|
||||
#
|
||||
# Note that the hook will be executed from the repository directory,
|
||||
# not from the working tree, so if you want to perform operations on
|
||||
# the working tree, you will have to adapt your code accordingly, e.g.
|
||||
# by adding "cd .." or using relative paths.
|
||||
|
||||
if ! git update-index -q --ignore-submodules --refresh
|
||||
then
|
||||
die "Up-to-date check failed"
|
||||
fi
|
||||
|
||||
if ! git diff-files --quiet --ignore-submodules --
|
||||
then
|
||||
die "Working directory has unstaged changes"
|
||||
fi
|
||||
|
||||
# This is a rough translation of:
|
||||
#
|
||||
# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX
|
||||
if git cat-file -e HEAD 2>/dev/null
|
||||
then
|
||||
head=HEAD
|
||||
else
|
||||
head=$(git hash-object -t tree --stdin </dev/null)
|
||||
fi
|
||||
|
||||
if ! git diff-index --quiet --cached --ignore-submodules $head --
|
||||
then
|
||||
die "Working directory has staged changes"
|
||||
fi
|
||||
|
||||
if ! git read-tree -u -m "$commit"
|
||||
then
|
||||
die "Could not update working tree to new HEAD"
|
||||
fi
|
||||
@@ -1,77 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# An example hook script to validate a patch (and/or patch series) before
|
||||
# sending it via email.
|
||||
#
|
||||
# The hook should exit with non-zero status after issuing an appropriate
|
||||
# message if it wants to prevent the email(s) from being sent.
|
||||
#
|
||||
# To enable this hook, rename this file to "sendemail-validate".
|
||||
#
|
||||
# By default, it will only check that the patch(es) can be applied on top of
|
||||
# the default upstream branch without conflicts in a secondary worktree. After
|
||||
# validation (successful or not) of the last patch of a series, the worktree
|
||||
# will be deleted.
|
||||
#
|
||||
# The following config variables can be set to change the default remote and
|
||||
# remote ref that are used to apply the patches against:
|
||||
#
|
||||
# sendemail.validateRemote (default: origin)
|
||||
# sendemail.validateRemoteRef (default: HEAD)
|
||||
#
|
||||
# Replace the TODO placeholders with appropriate checks according to your
|
||||
# needs.
|
||||
|
||||
validate_cover_letter () {
|
||||
file="$1"
|
||||
# TODO: Replace with appropriate checks (e.g. spell checking).
|
||||
true
|
||||
}
|
||||
|
||||
validate_patch () {
|
||||
file="$1"
|
||||
# Ensure that the patch applies without conflicts.
|
||||
git am -3 "$file" || return
|
||||
# TODO: Replace with appropriate checks for this patch
|
||||
# (e.g. checkpatch.pl).
|
||||
true
|
||||
}
|
||||
|
||||
validate_series () {
|
||||
# TODO: Replace with appropriate checks for the whole series
|
||||
# (e.g. quick build, coding style checks, etc.).
|
||||
true
|
||||
}
|
||||
|
||||
# main -------------------------------------------------------------------------
|
||||
|
||||
if test "$GIT_SENDEMAIL_FILE_COUNTER" = 1
|
||||
then
|
||||
remote=$(git config --default origin --get sendemail.validateRemote) &&
|
||||
ref=$(git config --default HEAD --get sendemail.validateRemoteRef) &&
|
||||
worktree=$(mktemp --tmpdir -d sendemail-validate.XXXXXXX) &&
|
||||
git worktree add -fd --checkout "$worktree" "refs/remotes/$remote/$ref" &&
|
||||
git config --replace-all sendemail.validateWorktree "$worktree"
|
||||
else
|
||||
worktree=$(git config --get sendemail.validateWorktree)
|
||||
fi || {
|
||||
echo "sendemail-validate: error: failed to prepare worktree" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
unset GIT_DIR GIT_WORK_TREE
|
||||
cd "$worktree" &&
|
||||
|
||||
if grep -q "^diff --git " "$1"
|
||||
then
|
||||
validate_patch "$1"
|
||||
else
|
||||
validate_cover_letter "$1"
|
||||
fi &&
|
||||
|
||||
if test "$GIT_SENDEMAIL_FILE_COUNTER" = "$GIT_SENDEMAIL_FILE_TOTAL"
|
||||
then
|
||||
git config --unset-all sendemail.validateWorktree &&
|
||||
trap 'git worktree remove -ff "$worktree"' EXIT &&
|
||||
validate_series
|
||||
fi
|
||||
@@ -1,128 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to block unannotated tags from entering.
|
||||
# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
|
||||
#
|
||||
# To enable this hook, rename this file to "update".
|
||||
#
|
||||
# Config
|
||||
# ------
|
||||
# hooks.allowunannotated
|
||||
# This boolean sets whether unannotated tags will be allowed into the
|
||||
# repository. By default they won't be.
|
||||
# hooks.allowdeletetag
|
||||
# This boolean sets whether deleting tags will be allowed in the
|
||||
# repository. By default they won't be.
|
||||
# hooks.allowmodifytag
|
||||
# This boolean sets whether a tag may be modified after creation. By default
|
||||
# it won't be.
|
||||
# hooks.allowdeletebranch
|
||||
# This boolean sets whether deleting branches will be allowed in the
|
||||
# repository. By default they won't be.
|
||||
# hooks.denycreatebranch
|
||||
# This boolean sets whether remotely creating branches will be denied
|
||||
# in the repository. By default this is allowed.
|
||||
#
|
||||
|
||||
# --- Command line
|
||||
refname="$1"
|
||||
oldrev="$2"
|
||||
newrev="$3"
|
||||
|
||||
# --- Safety check
|
||||
if [ -z "$GIT_DIR" ]; then
|
||||
echo "Don't run this script from the command line." >&2
|
||||
echo " (if you want, you could supply GIT_DIR then run" >&2
|
||||
echo " $0 <ref> <oldrev> <newrev>)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
|
||||
echo "usage: $0 <ref> <oldrev> <newrev>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- Config
|
||||
allowunannotated=$(git config --type=bool hooks.allowunannotated)
|
||||
allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch)
|
||||
denycreatebranch=$(git config --type=bool hooks.denycreatebranch)
|
||||
allowdeletetag=$(git config --type=bool hooks.allowdeletetag)
|
||||
allowmodifytag=$(git config --type=bool hooks.allowmodifytag)
|
||||
|
||||
# check for no description
|
||||
projectdesc=$(sed -e '1q' "$GIT_DIR/description")
|
||||
case "$projectdesc" in
|
||||
"Unnamed repository"* | "")
|
||||
echo "*** Project description file hasn't been set" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# --- Check types
|
||||
# if $newrev is 0000...0000, it's a commit to delete a ref.
|
||||
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
|
||||
if [ "$newrev" = "$zero" ]; then
|
||||
newrev_type=delete
|
||||
else
|
||||
newrev_type=$(git cat-file -t $newrev)
|
||||
fi
|
||||
|
||||
case "$refname","$newrev_type" in
|
||||
refs/tags/*,commit)
|
||||
# un-annotated tag
|
||||
short_refname=${refname##refs/tags/}
|
||||
if [ "$allowunannotated" != "true" ]; then
|
||||
echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
|
||||
echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/tags/*,delete)
|
||||
# delete tag
|
||||
if [ "$allowdeletetag" != "true" ]; then
|
||||
echo "*** Deleting a tag is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/tags/*,tag)
|
||||
# annotated tag
|
||||
if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
|
||||
then
|
||||
echo "*** Tag '$refname' already exists." >&2
|
||||
echo "*** Modifying a tag is not allowed in this repository." >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/heads/*,commit)
|
||||
# branch
|
||||
if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
|
||||
echo "*** Creating a branch is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/heads/*,delete)
|
||||
# delete branch
|
||||
if [ "$allowdeletebranch" != "true" ]; then
|
||||
echo "*** Deleting a branch is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/remotes/*,commit)
|
||||
# tracking branch
|
||||
;;
|
||||
refs/remotes/*,delete)
|
||||
# delete tracking branch
|
||||
if [ "$allowdeletebranch" != "true" ]; then
|
||||
echo "*** Deleting a tracking branch is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# Anything else (is there anything else?)
|
||||
echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# --- Finished
|
||||
exit 0
|
||||
@@ -1,6 +0,0 @@
|
||||
# git ls-files --others --exclude-from=.git/info/exclude
|
||||
# Lines that start with '#' are comments.
|
||||
# For a project mostly in C, the following would be a good set of
|
||||
# exclude patterns (uncomment them if you want to use them):
|
||||
# *.[oa]
|
||||
# *~
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,76 +0,0 @@
|
||||
# pack-refs with: peeled fully-peeled sorted
|
||||
e115d2e03f5d28b993c64da1663933c4e4cde129 refs/heads/master
|
||||
6369fb0cf3e7df34851913534a265878ac1e9828 refs/tags/v0.1.0
|
||||
6369fb0cf3e7df34851913534a265878ac1e9828 refs/tags/v0.1.1
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.10
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.11
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.12
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.13
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.14
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.15
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.16
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.17
|
||||
cfde3bcb0fb493c6a7cbd4fbfe87ef47b6cceda2 refs/tags/v0.1.18
|
||||
ac85ab6f0799f6a0c209f3efba5feb39d95bafc3 refs/tags/v0.1.19
|
||||
6369fb0cf3e7df34851913534a265878ac1e9828 refs/tags/v0.1.2
|
||||
ac85ab6f0799f6a0c209f3efba5feb39d95bafc3 refs/tags/v0.1.20
|
||||
ac85ab6f0799f6a0c209f3efba5feb39d95bafc3 refs/tags/v0.1.21
|
||||
bb673cc1a479e0d2a8f7bfef361b1c0bf3fade81 refs/tags/v0.1.22
|
||||
bb673cc1a479e0d2a8f7bfef361b1c0bf3fade81 refs/tags/v0.1.23
|
||||
2de890da5ccc11255ba8b6e210f098a3566be1a1 refs/tags/v0.1.24
|
||||
8c610b6e369df848c553edbc882ec4ef5a269bbf refs/tags/v0.1.25
|
||||
dfe8a20e2e97feb67a7506e22c0c3ba766f22f2c refs/tags/v0.1.26
|
||||
a2b700cf40ebce4b9c05d561b2271d04aa1a83f6 refs/tags/v0.1.27
|
||||
7cf7ffe025adf43ee8ed90e48fdd7c080bd9f4b4 refs/tags/v0.1.28
|
||||
7cf7ffe025adf43ee8ed90e48fdd7c080bd9f4b4 refs/tags/v0.1.29
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.3
|
||||
e8c0fcdf634f0de320675499486db729661f757b refs/tags/v0.1.30
|
||||
e8c0fcdf634f0de320675499486db729661f757b refs/tags/v0.1.31
|
||||
04f22e6f47d7ac161d88b0a6a440523d4cbfa788 refs/tags/v0.1.32
|
||||
ace0b5a7927f99e701c28b0a5d5623ac139cb7dc refs/tags/v0.1.33
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.4
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.5
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.6
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.7
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.8
|
||||
3108661b0a6f6ab33201bc6c9c405a161273978e refs/tags/v0.1.9
|
||||
64aee10a21447f0e839c2d32ead947a6af61b026 refs/tags/v0.2.0
|
||||
4a096ff35f35c3877839bfd44dcba11ae0a839cf refs/tags/v0.2.1
|
||||
9e9fcba96cd38aca50d67e6a74272f14f13e48c1 refs/tags/v0.2.2
|
||||
31947d12b735396e2c202f8dced51736ffe80106 refs/tags/v0.2.3
|
||||
0f72d7433a875a15c163baaea4030f837498b9ad refs/tags/v0.2.4
|
||||
d52ac9c10695bbae7960000512fad6df8cee8762 refs/tags/v0.2.5
|
||||
9bf74e76ce9e8e8c86eaf731d8e36f153972bea1 refs/tags/v0.2.6
|
||||
df50ca1273b47ddf2c5695336118651488225619 refs/tags/v0.4.10
|
||||
5c51ab1f9f72ea727e21249a1a8b8321784b85f9 refs/tags/v0.4.11
|
||||
81814e8518d5ac9a1060317ec36755187b1cd3ea refs/tags/v0.4.12
|
||||
79d98587d3d25f4f8778b97e8db9244195c729a8 refs/tags/v0.4.13
|
||||
cdeb569a16940242ac790eb54e17b12ad2f0b519 refs/tags/v0.4.3
|
||||
d7a8aa1dc4ad9021b49cadc1726418e660a0c00d refs/tags/v0.4.4
|
||||
4e06d8f723a07b77a3558a1dd5a768d18bd282cb refs/tags/v0.4.5
|
||||
c6896eebb4047d5fe5c61d589d373fff211d8284 refs/tags/v0.4.6
|
||||
2c128a6295a790e5915b7cc77f7a6716bbdb5e1d refs/tags/v0.4.7
|
||||
e87d7364ff2d5d8011d77588532fbf653d09891d refs/tags/v0.4.8
|
||||
d384ade7902b8a9f81c5280ae5bff890afc9fd2f refs/tags/v0.4.9
|
||||
363b7e9adfc0ead83aba054a86a897b01c0a508a refs/tags/v0.5.0
|
||||
af4f7cace95206873830de6d4cf72d59bb2d3b61 refs/tags/v0.5.1
|
||||
2a861298da59c45da7e7628b53acc0bb8278582e refs/tags/v0.5.10
|
||||
4c09cf2b266682253341206978b18d379c77cf87 refs/tags/v0.5.11
|
||||
b0a2279bcd59ddeef80bec22817ce61af5a7d099 refs/tags/v0.5.12
|
||||
b3110218fc0c9118fd335d7ff481bc35ad1beaa4 refs/tags/v0.5.13
|
||||
25bdce73376ee29bdda65959bd929dc74655b4a3 refs/tags/v0.5.14
|
||||
ef8e68b952ca9d3499e37d9607fc4e44dac8a369 refs/tags/v0.5.15
|
||||
8c5562edb09722075c8c039ec9040030447b9f40 refs/tags/v0.5.16
|
||||
84257b2f5865e1963251003c527286125bb549c7 refs/tags/v0.5.2
|
||||
7aea4b07df314bbf43a4f55b12c764b5141982e2 refs/tags/v0.5.3
|
||||
6c6bcba650e8805279fffe4427a67051aaa89f9a refs/tags/v0.5.4
|
||||
afe3e4787f0e3bbfa493c1cf94372016ab52c9a5 refs/tags/v0.5.5
|
||||
c81db98e3f25c56a808b6c7b3b4df6f4355966dd refs/tags/v0.5.6
|
||||
2b80abc3ae6b3060e5ea06316529df88e9ed2276 refs/tags/v0.5.7
|
||||
5760a3a7d0660cd58aa8e99919a71e187da4f785 refs/tags/v0.5.8
|
||||
b512be79aba5e10cafad60d8b8acdffa4d4e8b94 refs/tags/v0.5.9
|
||||
392b8632923a624e0bbc6ec3a14c0be088c86538 refs/tags/v0.6.0
|
||||
654bdd218649d0fb98ef2f74ba681630259e9a20 refs/tags/v0.6.1
|
||||
693e21423eff56ee6456900cda9812ca7aadb37c refs/tags/v0.6.2
|
||||
ba97b1a6e38514713c0ec790f3170f79337a4d8c refs/tags/v0.6.3
|
||||
7a63f0db57814dc4e467972131ce55b4c4aa0c89 refs/tags/v0.6.4
|
||||
@@ -1 +0,0 @@
|
||||
ref: refs/heads/master
|
||||
@@ -1,8 +0,0 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = true
|
||||
[remote "origin"]
|
||||
url = git@git.laantungir.net:laantungir/nostr_core_lib.git
|
||||
fetch = +refs/*:refs/*
|
||||
mirror = true
|
||||
@@ -1 +0,0 @@
|
||||
Unnamed repository; edit this file 'description' to name the repository.
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to check the commit log message taken by
|
||||
# applypatch from an e-mail message.
|
||||
#
|
||||
# The hook should exit with non-zero status after issuing an
|
||||
# appropriate message if it wants to stop the commit. The hook is
|
||||
# allowed to edit the commit message file.
|
||||
#
|
||||
# To enable this hook, rename this file to "applypatch-msg".
|
||||
|
||||
. git-sh-setup
|
||||
commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
|
||||
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
|
||||
:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user