Compare commits

..
18 Commits
Author SHA1 Message Date
Laan Tungir 2e8ab08b9c Fix NIP-03 OpenTimestamps parsing, multi-calendar proofs, upgrades, tests, and CLI tooling 2026-07-16 20:38:48 -04:00
Laan Tungir 0ee8b70445 Add nostr_bip39_get_wordlist() public accessor for BIP-39 wordlist 2026-07-11 16:37:46 -04:00
Laan Tungir 4216a347d3 Fix qrexec transport reconnect: blocking waitpid for old child, sync nsigner_client.c with reconnect logic 2026-07-11 14:52:28 -04:00
Laan Tungir 5a9bd08b2e Add qrexec transport, nostr_index selector, and index_not_allowed error code for n_signer client 2026-07-11 14:25:25 -04:00
Laan Tungir b76cff4a45 nsigner client: reconnect per call (server closes connection after each request); ignore SIGPIPE in client. Fixes live unix round-trip crash. 2026-07-08 09:44:56 -04:00
Laan Tungir e842de3e68 nsigner integration: signer abstraction + local/remote backends (unix/serial/tcp/fds), *_with_signer variants across NIP-01/17/42/46/60/61/blossom, note_poster driver, build-flag gating, docs 2026-07-08 06:52:41 -04:00
Laan Tungir 4a504231a0 Fix websocket frame parsing and stabilize relay pool sync query 2026-05-05 07:36:04 -04:00
Laan Tungir e115d2e03f chore: stop tracking compiled build artifacts 2026-05-02 09:50:08 -04:00
Laan Tungir 7a63f0db57 chore: maintenance cleanup and release increment 2026-05-02 09:36:18 -04:00
Laan Tungir ba97b1a6e3 Fixed for ipv6 2026-04-24 06:51:09 -04:00
Laan Tungir 693e21423e from c_fips 2026-04-17 11:01:56 -04:00
Laan Tungir 654bdd2186 Add RFC8439 Poly1305 MAC and ChaCha20-Poly1305 AEAD with vector tests 2026-04-13 16:28:41 -04:00
Laan Tungir 13ad24b676 Add Poly1305 and ChaCha20-Poly1305 AEAD with RFC 8439 tests 2026-04-13 16:01:35 -04:00
Laan Tungir 392b863292 Release v0.6.0: embedded ESP32 support docs and external esp32_send_kind4 example 2026-04-12 15:51:27 -04:00
Laan Tungir 8c5562edb0 Fix NIP-59 dynamic buffer sizing for NIP-17 gift wraps 2026-04-11 15:53:44 -04:00
Laan Tungir ef8e68b952 Implemented cooldown period in relay connection to prevent flapping 2026-04-10 06:13:02 -04:00
Laan Tungir 25bdce7337 Add per-relay EOSE timeout fallback and robust subscription EOSE completion 2026-04-07 07:41:50 -04:00
laantungir b3110218fc Update README checklist with not-applicable NIP markers and legend 2026-03-22 11:53:37 -04:00
106 changed files with 2016 additions and 881 deletions
-1
View File
@@ -1 +0,0 @@
0.6.6
+1 -1
View File
@@ -1 +1 @@
0.6.11
0.6.7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+43 -7
View File
@@ -319,8 +319,9 @@ static int do_stamp(const char* file_path, const char* calendar_url,
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);
/* Try to upgrade the proof by re-submitting to all calendars */
char* upgraded = nostr_nip03_stamp_with_multiple_calendars(
digest_hex, calendars_to_use, num_to_use, 30);
if (upgraded) {
free(ots_b64);
ots_b64 = upgraded;
@@ -500,14 +501,49 @@ static int do_upgrade(const char* ots_path, const char* file_path,
return 0;
}
(void)calendar_url; /* upgrade now uses pending-attestation URIs from proof */
(void)file_path;
/* Use multiple calendars for upgrade */
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",
};
printf("📤 Checking pending attestations and fetching upgrades...\n");
/* Determine which calendars to use */
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 = 4;
}
printf("📤 Re-submitting to %d calendar(s)...\n", num_to_use);
/* Get the digest: try extracting from proof, or compute from file */
char digest_hex[65] = {0};
int have_digest = 0;
/* Try extracting from the proof (works for full DetachedTimestampFile) */
/* The upgrade_proof function does this internally, but we need the digest
* for the multi-calendar stamp function */
if (file_path) {
if (compute_file_sha256_hex(file_path, digest_hex) == 0) {
have_digest = 1;
}
}
char* upgraded = NULL;
/* Use the tree-walking upgrade which correctly queries commitment hashes */
upgraded = nostr_nip03_upgrade_proof_tree(ots_b64, 30);
if (have_digest) {
printf(" Digest: %s\n", digest_hex);
upgraded = nostr_nip03_stamp_with_multiple_calendars(
digest_hex, calendars_to_use, num_to_use, 30);
} else {
/* Fall back to single-calendar upgrade via embedded digest */
upgraded = nostr_nip03_upgrade_proof(ots_b64, calendar_url, 30);
}
if (!upgraded) {
printf("⏳ No upgrade available yet. The proof is still pending.\n");
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-14
View File
@@ -120,20 +120,6 @@ 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.
+4 -22
View File
@@ -195,10 +195,9 @@ cJSON** synchronous_query_relays_with_progress(
continue;
}
// 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);
// 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);
if (len > 0) {
buffer[len] = '\0';
@@ -323,23 +322,6 @@ 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);
@@ -598,7 +580,7 @@ publish_result_t* synchronous_publish_event_with_progress(
}
// Try to receive message (short timeout to keep UI responsive)
char buffer[262144];
char buffer[8192];
int len = nostr_ws_receive(relay->client, buffer, sizeof(buffer)-1, 50);
if (len > 0) {
+24 -446
View File
@@ -375,361 +375,6 @@ static int ots_parse_file(const unsigned char* data, size_t data_len,
return ots_parse_timestamp(data, data_len, &pos, list, 0);
}
/* ========================================================================== */
/* Tree-Walking Upgrade Logic */
/* ========================================================================== */
/*
* Walk the proof tree and find all pending attestations with their
* commitment hashes. For each, fetch the upgraded proof from the calendar
* via GET /timestamp/<commitment-hash>. If an upgraded proof is found,
* replace the pending attestation in the original proof bytes.
*
* This implements the same logic as the reference otsclient upgrade_timestamp():
* - Walk the tree, computing intermediate hashes by applying ops
* - For each PendingAttestation, get the commitment hash (sub_stamp.msg)
* - Call GET /timestamp/<commitment-hash> on the calendar
* - If the response contains a Bitcoin attestation, splice it in
*/
/* Track a pending attestation location in the proof */
typedef struct {
unsigned char commitment[128]; /* The commitment hash at this point (can be >32 bytes) */
size_t commitment_len; /* Length of the commitment */
char uri[256]; /* Calendar URI (null-terminated) */
size_t att_start; /* Byte offset of the 0x00 attestation tag */
size_t att_end; /* Byte offset after the attestation */
} ots_pending_location_t;
#define OTS_MAX_PENDING_LOCATIONS 32
typedef struct {
ots_pending_location_t locations[OTS_MAX_PENDING_LOCATIONS];
int count;
} ots_pending_location_list_t;
/* Compute SHA-256 of data */
static int compute_sha256(const unsigned char* data, size_t len, unsigned char* out) {
return nostr_sha256(data, len, out);
}
/* Apply an op to a message and return the result */
static int apply_op(unsigned char op, const unsigned char* arg, size_t arg_len,
const unsigned char* msg, size_t msg_len,
unsigned char* result, size_t* result_len) {
if (op == OTS_OP_APPEND) {
/* result = msg + arg */
if (msg_len + arg_len > 4096) return -1;
memcpy(result, msg, msg_len);
memcpy(result + msg_len, arg, arg_len);
*result_len = msg_len + arg_len;
} else if (op == OTS_OP_PREPEND) {
/* result = arg + msg */
if (msg_len + arg_len > 4096) return -1;
memcpy(result, arg, arg_len);
memcpy(result + arg_len, msg, msg_len);
*result_len = msg_len + arg_len;
} else if (op == OTS_OP_SHA256) {
/* result = SHA256(msg) */
compute_sha256(msg, msg_len, result);
*result_len = 32;
} else if (op == OTS_OP_RIPEMD160) {
/* Not commonly used in OTS proofs, skip */
return -1;
} else if (op == OTS_OP_REVERSE) {
/* result = reverse(msg) */
if (msg_len > 4096) return -1;
for (size_t i = 0; i < msg_len; i++) {
result[i] = msg[msg_len - 1 - i];
}
*result_len = msg_len;
} else if (op == OTS_OP_HEXLIFY) {
/* result = hex(msg) */
if (msg_len * 2 > 4096) return -1;
nostr_bytes_to_hex(msg, msg_len, (char*)result);
*result_len = msg_len * 2;
} else {
return -1;
}
return 0;
}
/*
* Walk the proof tree tracking commitment hashes and finding pending attestations.
* Records the byte positions of each pending attestation for later replacement.
*/
static int walk_tree_for_pending(const unsigned char* data, size_t data_len,
size_t* pos, const unsigned char* current_msg,
size_t msg_len,
ots_pending_location_list_t* locations, int depth) {
if (depth > 256 || *pos >= data_len) return -1;
unsigned char tag = data[*pos];
(*pos)++;
/* Handle 0xff separators */
while (tag == OTS_TAG_SEPARATOR) {
if (*pos >= data_len) return -1;
unsigned char sep_tag = data[*pos];
(*pos)++;
if (sep_tag == OTS_TAG_ATTESTATION) {
/* Attestation after separator - check if pending */
size_t att_start = *pos - 1; /* Position of the 0x00 tag */
ots_attestation_t att;
if (ots_parse_attestation(data, data_len, pos, &att) != 0) return -1;
size_t att_end = *pos;
if (att.type == OTS_ATTESTATION_PENDING && locations->count < OTS_MAX_PENDING_LOCATIONS) {
ots_pending_location_t* loc = &locations->locations[locations->count];
size_t copy_len = msg_len < sizeof(loc->commitment) ? msg_len : sizeof(loc->commitment);
memcpy(loc->commitment, current_msg, copy_len);
loc->commitment_len = copy_len;
size_t uri_copy_len = att.uri_len < sizeof(loc->uri) - 1 ? att.uri_len : sizeof(loc->uri) - 1;
memcpy(loc->uri, att.uri, uri_copy_len);
loc->uri[uri_copy_len] = '\0';
loc->att_start = att_start;
loc->att_end = att_end;
locations->count++;
}
} else {
/* Op after separator - process op and recurse */
unsigned char result[4096];
size_t result_len = 0;
if (sep_tag == OTS_OP_APPEND || sep_tag == OTS_OP_PREPEND) {
const unsigned char* arg;
size_t arg_len;
if (ots_read_varbytes(data, data_len, pos, &arg, &arg_len) != 0) return -1;
if (apply_op(sep_tag, arg, arg_len, current_msg, msg_len, result, &result_len) != 0) return -1;
} else {
if (apply_op(sep_tag, NULL, 0, current_msg, msg_len, result, &result_len) != 0) return -1;
}
if (walk_tree_for_pending(data, data_len, pos, result, result_len, locations, depth + 1) != 0)
return -1;
}
if (*pos >= data_len) return -1;
tag = data[*pos];
(*pos)++;
}
/* Process the final tag */
if (tag == OTS_TAG_ATTESTATION) {
size_t att_start = *pos - 1;
ots_attestation_t att;
if (ots_parse_attestation(data, data_len, pos, &att) != 0) return -1;
size_t att_end = *pos;
if (att.type == OTS_ATTESTATION_PENDING && locations->count < OTS_MAX_PENDING_LOCATIONS) {
ots_pending_location_t* loc = &locations->locations[locations->count];
size_t copy_len = msg_len < sizeof(loc->commitment) ? msg_len : sizeof(loc->commitment);
memcpy(loc->commitment, current_msg, copy_len);
loc->commitment_len = copy_len;
size_t uri_copy_len = att.uri_len < sizeof(loc->uri) - 1 ? att.uri_len : sizeof(loc->uri) - 1;
memcpy(loc->uri, att.uri, uri_copy_len);
loc->uri[uri_copy_len] = '\0';
loc->att_start = att_start;
loc->att_end = att_end;
locations->count++;
}
} else {
/* Op - process and recurse */
unsigned char result[4096];
size_t result_len = 0;
if (tag == OTS_OP_APPEND || tag == OTS_OP_PREPEND) {
const unsigned char* arg;
size_t arg_len;
if (ots_read_varbytes(data, data_len, pos, &arg, &arg_len) != 0) return -1;
if (apply_op(tag, arg, arg_len, current_msg, msg_len, result, &result_len) != 0) return -1;
} else {
if (apply_op(tag, NULL, 0, current_msg, msg_len, result, &result_len) != 0) return -1;
}
if (walk_tree_for_pending(data, data_len, pos, result, result_len, locations, depth + 1) != 0)
return -1;
}
return 0;
}
/*
* Fetch an upgraded proof from a calendar via GET /timestamp/<commitment-hash>
* Returns the raw proof bytes (caller must free), or NULL on error/404.
*/
static unsigned char* fetch_upgraded_proof(const char* calendar_uri,
const unsigned char* commitment, size_t commitment_len,
int timeout_seconds,
size_t* out_len) {
char commitment_hex[65];
nostr_bytes_to_hex(commitment, commitment_len, commitment_hex);
char full_url[512];
snprintf(full_url, sizeof(full_url), "%s/timestamp/%s", calendar_uri, commitment_hex);
nostr_http_request_t req = {0};
req.method = "GET";
req.url = full_url;
req.timeout_seconds = timeout_seconds > 0 ? timeout_seconds : 10;
req.follow_redirects = 1;
req.max_redirects = 3;
const char* headers[] = { "Accept: application/octet-stream", NULL };
req.headers = headers;
nostr_http_response_t resp = {0};
if (nostr_http_request(&req, &resp) != NOSTR_SUCCESS ||
resp.status_code != 200 || !resp.body || resp.body_len == 0) {
nostr_http_response_free(&resp);
return NULL;
}
/* Copy the response body */
unsigned char* proof = (unsigned char*)malloc(resp.body_len);
if (proof) {
memcpy(proof, resp.body, resp.body_len);
*out_len = resp.body_len;
}
nostr_http_response_free(&resp);
return proof;
}
/*
* Check if a raw timestamp proof contains a Bitcoin attestation.
*/
static int has_bitcoin_attestation(const unsigned char* data, size_t data_len) {
ots_attestation_list_t list;
if (ots_parse_file(data, data_len, &list) != 0) return 0;
for (int i = 0; i < list.count; i++) {
if (list.attestations[i].type == OTS_ATTESTATION_BITCOIN ||
list.attestations[i].type == OTS_ATTESTATION_LITECOIN) {
return 1;
}
}
return 0;
}
/*
* Upgrade a proof by walking the tree, finding pending attestations,
* fetching upgraded proofs from calendars, and splicing them in.
*
* Returns a new base64-encoded proof (caller must free), or NULL on error.
*/
char* nostr_nip03_upgrade_proof_tree(const char* ots_data_base64,
int timeout_seconds) {
if (!ots_data_base64) return NULL;
size_t input_len = strlen(ots_data_base64);
size_t max_decoded_len = (input_len / 4) * 3 + 3;
unsigned char* data = (unsigned char*)malloc(max_decoded_len);
if (!data) return NULL;
size_t data_len = base64_decode(ots_data_base64, data);
if (data_len == 0) {
free(data);
return NULL;
}
/* Find the start of the timestamp tree and the file digest */
size_t pos = 0;
unsigned char file_digest[32];
size_t digest_len = 32;
if (data_len >= OTS_HEADER_MAGIC_LEN &&
memcmp(data, OTS_HEADER_MAGIC, OTS_HEADER_MAGIC_LEN) == 0) {
pos = OTS_HEADER_MAGIC_LEN;
uint64_t version;
if (ots_read_varuint(data, data_len, &pos, &version) != 0) { free(data); return NULL; }
if (pos >= data_len) { free(data); return NULL; }
unsigned char hash_op = data[pos++];
digest_len = ots_digest_length(hash_op);
if (digest_len == 0 || pos + digest_len > data_len) { free(data); return NULL; }
memcpy(file_digest, data + pos, digest_len);
pos += digest_len;
} else {
/* Raw timestamp - can't upgrade without knowing the digest */
free(data);
return NULL;
}
/* Walk the tree to find all pending attestations */
ots_pending_location_list_t locations;
memset(&locations, 0, sizeof(locations));
size_t tree_pos = pos;
if (walk_tree_for_pending(data, data_len, &tree_pos, file_digest, digest_len,
&locations, 0) != 0) {
free(data);
return NULL;
}
if (locations.count == 0) {
/* No pending attestations - nothing to upgrade */
free(data);
return NULL;
}
/* For each pending attestation, try to fetch an upgraded proof */
int upgraded = 0;
for (int i = 0; i < locations.count; i++) {
ots_pending_location_t* loc = &locations.locations[i];
size_t upgraded_len = 0;
unsigned char* upgraded_proof = fetch_upgraded_proof(
loc->uri, loc->commitment, loc->commitment_len, timeout_seconds, &upgraded_len);
if (!upgraded_proof) {
continue;
}
if (!has_bitcoin_attestation(upgraded_proof, upgraded_len)) {
free(upgraded_proof);
continue;
}
/* We have an upgraded proof with a Bitcoin attestation!
* Replace the pending attestation bytes [att_start, att_end) with
* the upgraded proof bytes. */
size_t old_att_len = loc->att_end - loc->att_start;
size_t new_data_len = data_len - old_att_len + upgraded_len;
unsigned char* new_data = (unsigned char*)malloc(new_data_len);
if (!new_data) { free(upgraded_proof); continue; }
/* Copy: [0..att_start) + upgraded_proof + [att_end..data_len) */
memcpy(new_data, data, loc->att_start);
memcpy(new_data + loc->att_start, upgraded_proof, upgraded_len);
memcpy(new_data + loc->att_start + upgraded_len, data + loc->att_end,
data_len - loc->att_end);
free(upgraded_proof);
free(data);
data = new_data;
data_len = new_data_len;
upgraded = 1;
/* Only need one Bitcoin attestation */
break;
}
if (!upgraded) {
free(data);
return NULL;
}
/* Base64 encode the upgraded proof */
size_t b64_size = ((data_len + 2) / 3) * 4 + 1;
char* b64 = (char*)malloc(b64_size);
if (b64) {
base64_encode(data, data_len, b64, b64_size);
}
free(data);
return b64;
}
/* ========================================================================== */
/* NIP-03 Public API */
/* ========================================================================== */
@@ -1055,25 +700,24 @@ char* nostr_nip03_upgrade_proof(const char* ots_data_base64,
return NULL;
}
/* Fetch the upgraded proof from the calendar's /timestamp/<hash> endpoint.
* This is the correct API for retrieving upgraded proofs — it returns the
* current proof which may include Bitcoin attestations if the digest has
* been committed since the original submission.
* (POST /digest always returns a fresh pending proof, not the upgraded one.) */
char digest_hex_str[65];
nostr_bytes_to_hex(digest, 32, digest_hex_str);
/* Re-submit the digest to the calendar's /digest endpoint.
* The calendar will return the current proof, which may include
* new Bitcoin attestations if the digest has been committed since
* the original submission. */
char full_url[512];
snprintf(full_url, sizeof(full_url), "%s/timestamp/%s", calendar_url, digest_hex_str);
snprintf(full_url, sizeof(full_url), "%s/digest", calendar_url);
nostr_http_request_t req = {0};
req.method = "GET";
req.method = "POST";
req.url = full_url;
req.body = digest;
req.body_len = 32;
req.timeout_seconds = timeout_seconds > 0 ? timeout_seconds : 10;
req.follow_redirects = 1;
req.max_redirects = 3;
const char* headers[] = {
"Content-Type: application/octet-stream",
"Accept: application/octet-stream",
NULL
};
@@ -1104,19 +748,27 @@ char* nostr_nip03_upgrade_proof_with_digest(const char* digest_hex,
int timeout_seconds) {
if (!digest_hex || !calendar_url) return NULL;
/* Fetch the upgraded proof from the calendar's /timestamp/<hash> endpoint.
* This returns the current proof which may include Bitcoin attestations. */
/* Convert hex digest to binary */
unsigned char digest[32];
if (nostr_hex_to_bytes(digest_hex, digest, 32) != 0) {
return NULL;
}
/* Re-submit the digest to the calendar's /digest endpoint */
char full_url[512];
snprintf(full_url, sizeof(full_url), "%s/timestamp/%s", calendar_url, digest_hex);
snprintf(full_url, sizeof(full_url), "%s/digest", calendar_url);
nostr_http_request_t req = {0};
req.method = "GET";
req.method = "POST";
req.url = full_url;
req.body = digest;
req.body_len = 32;
req.timeout_seconds = timeout_seconds > 0 ? timeout_seconds : 10;
req.follow_redirects = 1;
req.max_redirects = 3;
const char* headers[] = {
"Content-Type: application/octet-stream",
"Accept: application/octet-stream",
NULL
};
@@ -1433,81 +1085,7 @@ char* nostr_nip03_upgrade_proof_multi(const char* digest_hex,
calendar_count = NOSTR_OTS_DEFAULT_CALENDAR_COUNT;
}
/* Convert hex digest to binary */
unsigned char digest[32];
if (nostr_hex_to_bytes(digest_hex, digest, 32) != 0) {
return NULL;
}
/* Fetch upgraded proof from each calendar via GET /timestamp/<hash> */
const unsigned char* raw_proofs[16];
size_t raw_proof_lens[16];
unsigned char* proof_buffers[16];
int success_count = 0;
for (int i = 0; i < calendar_count && i < 16; i++) {
if (!calendar_urls[i]) continue;
char full_url[512];
snprintf(full_url, sizeof(full_url), "%s/timestamp/%s", calendar_urls[i], digest_hex);
nostr_http_request_t req = {0};
req.method = "GET";
req.url = full_url;
req.timeout_seconds = timeout_seconds > 0 ? timeout_seconds : 10;
req.follow_redirects = 1;
req.max_redirects = 3;
const char* headers[] = {
"Accept: application/octet-stream",
NULL
};
req.headers = headers;
nostr_http_response_t resp = {0};
if (nostr_http_request(&req, &resp) != NOSTR_SUCCESS ||
resp.status_code != 200 || !resp.body || resp.body_len == 0) {
nostr_http_response_free(&resp);
continue; /* Calendar may not have this digest (404) */
}
/* Copy the raw proof data */
unsigned char* proof_copy = (unsigned char*)malloc(resp.body_len);
if (proof_copy) {
memcpy(proof_copy, resp.body, resp.body_len);
raw_proofs[success_count] = proof_copy;
raw_proof_lens[success_count] = resp.body_len;
proof_buffers[success_count] = proof_copy;
success_count++;
}
nostr_http_response_free(&resp);
}
if (success_count == 0) {
return NULL; /* No calendar had an upgraded proof */
}
/* Build a combined DetachedTimestampFile */
size_t out_len = 0;
unsigned char* ots_data = build_dts_file(digest, 32,
raw_proofs, raw_proof_lens,
success_count, &out_len);
/* Free the individual proof buffers */
for (int i = 0; i < success_count; i++) {
free(proof_buffers[i]);
}
if (!ots_data) return NULL;
/* Base64 encode */
size_t b64_size = ((out_len + 2) / 3) * 4 + 1;
char* b64 = (char*)malloc(b64_size);
if (b64) {
base64_encode(ots_data, out_len, b64, b64_size);
}
free(ots_data);
return b64;
/* Re-submit to all calendars to get current proofs */
return nostr_nip03_stamp_with_multiple_calendars(digest_hex, calendar_urls,
calendar_count, timeout_seconds);
}
-16
View File
@@ -135,22 +135,6 @@ 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
*
+2 -13
View File
@@ -2,10 +2,10 @@
#define NOSTR_CORE_H
// Version information (auto-updated by increment_and_push.sh)
#define VERSION "v0.6.11"
#define VERSION "v0.6.7"
#define VERSION_MAJOR 0
#define VERSION_MINOR 6
#define VERSION_PATCH 11
#define VERSION_PATCH 7
/*
* NOSTR Core Library - Complete API Reference
@@ -304,17 +304,6 @@ 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,
+6 -113
View File
@@ -284,26 +284,6 @@ 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, int has_nostr_index, int nostr_index) {
@@ -360,7 +340,7 @@ static int signer_remote_get_public_key(nostr_signer_t* signer, char out_pubkey_
return NOSTR_ERROR_MEMORY_FAILED;
}
rc = nsigner_client_call(signer->u.remote.client, "nostr_get_public_key", params, &result);
rc = nsigner_client_call(signer->u.remote.client, "get_public_key", params, &result);
if (rc != NOSTR_SUCCESS) {
return rc;
}
@@ -412,7 +392,7 @@ static int signer_remote_sign_event(nostr_signer_t* signer, const cJSON* unsigne
return NOSTR_ERROR_MEMORY_FAILED;
}
rc = nsigner_client_call(signer->u.remote.client, "nostr_sign_event", params, &result);
rc = nsigner_client_call(signer->u.remote.client, "sign_event", params, &result);
if (rc != NOSTR_SUCCESS) {
return rc;
}
@@ -501,96 +481,28 @@ 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, "nostr_nip04_encrypt", peer_pubkey_hex, plaintext, ciphertext_out);
return signer_remote_encrypt_decrypt(signer, "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, "nostr_nip04_decrypt", peer_pubkey_hex, ciphertext, plaintext_out);
return signer_remote_encrypt_decrypt(signer, "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, "nostr_nip44_encrypt", peer_pubkey_hex, plaintext, ciphertext_out);
return signer_remote_encrypt_decrypt(signer, "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, "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;
return signer_remote_encrypt_decrypt(signer, "nip44_decrypt", peer_pubkey_hex, ciphertext, plaintext_out);
}
#endif /* NOSTR_ENABLE_NSIGNER_CLIENT */
@@ -747,25 +659,6 @@ 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;
-10
View File
@@ -19,16 +19,6 @@ 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,
+1 -13
View File
@@ -1021,20 +1021,8 @@ int nsigner_transport_list_serial(char paths[][64], int max_paths) {
while ((ent = readdir(dir)) != NULL) {
int n;
int is_serial = 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) {
if (strncmp(ent->d_name, "ttyACM", 6) != 0) {
continue;
}
+9 -44
View File
@@ -57,15 +57,6 @@ 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
@@ -717,27 +708,10 @@ static int tls_recv(void* ctx, void* data, size_t len, int timeout_ms) {
if (!tls->ssl_connected || !tls->ssl) {
return -1;
}
/* 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. */
// 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
if (timeout_ms > 0) {
fd_set readfds;
struct timeval tv;
@@ -745,6 +719,7 @@ 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;
@@ -766,26 +741,16 @@ static int tls_recv(void* ctx, void* data, size_t len, int timeout_ms) {
const int max_attempts = 10;
while (attempts < max_attempts) {
/* 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));
int ret = SSL_read(tls->ssl, data, len);
if (ret > 0) {
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;
return ret; // Success
}
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
@@ -798,7 +763,7 @@ static int tls_recv(void* ctx, void* data, size_t len, int timeout_ms) {
}
attempts++;
continue;
continue; // Retry the SSL read
} else if (err == SSL_ERROR_WANT_WRITE) {
return -1;
-106
View File
@@ -1,106 +0,0 @@
# 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.
+1 -9
View File
@@ -3,14 +3,6 @@
> Status: M1M6 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
@@ -23,7 +15,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 methods (`nostr_get_public_key`, `nostr_sign_event`, `nostr_nip04_*`, `nostr_nip44_*`)
- the JSON-RPC verbs (`get_public_key`, `sign_event`, `nip04_*`, `nip44_*`)
- a per-project `signer.h` abstraction wrapping local-vs-remote signing
Meanwhile, `nostr_core_lib` exposes ~30+ functions that take a raw
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
+4 -66
View File
@@ -11,7 +11,6 @@
#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;
@@ -45,7 +44,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\":\"nostr_get_public_key\",\"params\":[]}";
const char* msg = "{\"id\":\"1\",\"method\":\"get_public_key\",\"params\":[]}";
char* out = NULL;
size_t out_len = 0;
int ok = 0;
@@ -81,7 +80,7 @@ cleanup:
static int test_framing_fragmented_read_reassembly(void) {
int fds[2] = {-1, -1};
const char* msg = "{\"id\":\"2\",\"method\":\"nostr_sign_event\",\"params\":[\"abc\"]}";
const char* msg = "{\"id\":\"2\",\"method\":\"sign_event\",\"params\":[\"abc\"]}";
unsigned int len = (unsigned int)strlen(msg);
unsigned char hdr[4];
char* out = NULL;
@@ -251,7 +250,7 @@ static int test_fds_transport_round_trip_via_client(void) {
}
req[req_len] = '\0';
if (strstr(req, "\"method\":\"nostr_get_public_key\"") == NULL) {
if (strstr(req, "\"method\":\"get_public_key\"") == NULL) {
free(req);
_exit(6);
}
@@ -294,7 +293,7 @@ static int test_fds_transport_round_trip_via_client(void) {
goto cleanup;
}
if (nsigner_client_call(client, "nostr_get_public_key", params, &result) != NOSTR_SUCCESS) {
if (nsigner_client_call(client, "get_public_key", params, &result) != NOSTR_SUCCESS) {
params = NULL;
goto cleanup;
}
@@ -333,66 +332,6 @@ 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");
@@ -403,7 +342,6 @@ 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;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
ref: refs/heads/master
+8
View File
@@ -0,0 +1,8 @@
[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
View File
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
+15
View File
@@ -0,0 +1,15 @@
#!/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+"$@"}
:
+24
View File
@@ -0,0 +1,24 @@
#!/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
}
+174
View File
@@ -0,0 +1,174 @@
#!/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;
}
+8
View File
@@ -0,0 +1,8 @@
#!/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
+14
View File
@@ -0,0 +1,14 @@
#!/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+"$@"}
:
+49
View File
@@ -0,0 +1,49 @@
#!/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 --
+13
View File
@@ -0,0 +1,13 @@
#!/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"
:
+53
View File
@@ -0,0 +1,53 @@
#!/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
+169
View File
@@ -0,0 +1,169 @@
#!/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
+24
View File
@@ -0,0 +1,24 @@
#!/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
+42
View File
@@ -0,0 +1,42 @@
#!/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
+78
View File
@@ -0,0 +1,78 @@
#!/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
+77
View File
@@ -0,0 +1,77 @@
#!/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
+128
View File
@@ -0,0 +1,128 @@
#!/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
+6
View File
@@ -0,0 +1,6 @@
# 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]
# *~
+76
View File
@@ -0,0 +1,76 @@
# 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
View File
@@ -0,0 +1 @@
ref: refs/heads/master
+8
View File
@@ -0,0 +1,8 @@
[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
View File
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
+15
View File
@@ -0,0 +1,15 @@
#!/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+"$@"}
:
+24
View File
@@ -0,0 +1,24 @@
#!/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
}
+174
View File
@@ -0,0 +1,174 @@
#!/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;
}
+8
View File
@@ -0,0 +1,8 @@
#!/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
+14
View File
@@ -0,0 +1,14 @@
#!/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+"$@"}
:
+49
View File
@@ -0,0 +1,49 @@
#!/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 --
+13
View File
@@ -0,0 +1,13 @@
#!/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"
:
+53
View File
@@ -0,0 +1,53 @@
#!/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
+169
View File
@@ -0,0 +1,169 @@
#!/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
+24
View File
@@ -0,0 +1,24 @@
#!/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
+42
View File
@@ -0,0 +1,42 @@
#!/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
+78
View File
@@ -0,0 +1,78 @@
#!/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
+77
View File
@@ -0,0 +1,77 @@
#!/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
+128
View File
@@ -0,0 +1,128 @@
#!/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

Some files were not shown because too many files have changed in this diff Show More