Skip to content

Commit 52a5aeb

Browse files
motxxclaude
andcommitted
refactor: rename Ground Truth → Anchr throughout protocol layer
- Protocol tag: ["t", "ground-truth"] → ["t", "anchr"] - Constants: GT_* → ANCHR_* (ANCHR_QUERY_REQUEST, etc.) - Query ID prefix: gt_ → anchr_ - Protocol version: ground-truth:v1 → anchr:v1 - All doc comments updated Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ea0d7dc commit 52a5aeb

10 files changed

Lines changed: 46 additions & 47 deletions

src/cashu/wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Cashu ecash wallet for Ground Truth Protocol.
2+
* Cashu ecash wallet for Anchr.
33
*
44
* Provides anonymous payment capabilities:
55
* - Mint tokens from a Cashu mint (backed by Lightning sats)

src/nostr/client.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Nostr relay client for Ground Truth Protocol (NIP-90 DVM).
2+
* Nostr relay client for Anchr (NIP-90 DVM).
33
*
44
* Handles connection to multiple relays, event publishing,
55
* and subscription management. Event kinds follow the NIP-90
@@ -9,8 +9,8 @@
99
import { SimplePool, type SubCloser } from "nostr-tools/pool";
1010
import type { Filter } from "nostr-tools/filter";
1111
import type { Event, VerifiedEvent } from "nostr-tools/core";
12-
import { GT_QUERY_REQUEST, GT_QUERY_RESPONSE, GT_QUERY_SETTLEMENT } from "./events";
13-
import { GT_ORACLE_ATTESTATION } from "./oracle-attestation";
12+
import { ANCHR_QUERY_REQUEST, ANCHR_QUERY_RESPONSE, ANCHR_QUERY_SETTLEMENT } from "./events";
13+
import { ANCHR_ORACLE_ATTESTATION } from "./oracle-attestation";
1414

1515
export interface NostrClientConfig {
1616
relayUrls: string[];
@@ -69,7 +69,7 @@ export async function publishEvent(
6969
}
7070

7171
/**
72-
* Subscribe to Ground Truth query request events (DVM kind 5300).
72+
* Subscribe to Anchr query request events (DVM kind 5300).
7373
*/
7474
export function subscribeToQueries(
7575
onEvent: (event: Event) => void,
@@ -83,8 +83,8 @@ export function subscribeToQueries(
8383
const pool = getPool();
8484

8585
const filter: Filter = {
86-
kinds: [GT_QUERY_REQUEST],
87-
"#t": ["ground-truth"],
86+
kinds: [ANCHR_QUERY_REQUEST],
87+
"#t": ["anchr"],
8888
since: Math.floor(Date.now() / 1000) - 3600, // last hour
8989
};
9090

@@ -110,7 +110,7 @@ export function subscribeToResponses(
110110
const pool = getPool();
111111

112112
return pool.subscribeMany(urls, {
113-
kinds: [GT_QUERY_RESPONSE],
113+
kinds: [ANCHR_QUERY_RESPONSE],
114114
"#e": [queryEventId],
115115
}, {
116116
onevent: onEvent,
@@ -130,7 +130,7 @@ export function subscribeToSettlements(
130130
const pool = getPool();
131131

132132
return pool.subscribeMany(urls, {
133-
kinds: [GT_QUERY_SETTLEMENT],
133+
kinds: [ANCHR_QUERY_SETTLEMENT],
134134
"#e": [queryEventId],
135135
}, {
136136
onevent: onEvent,
@@ -150,7 +150,7 @@ export function subscribeToAttestations(
150150
const pool = getPool();
151151

152152
return pool.subscribeMany(urls, {
153-
kinds: [GT_ORACLE_ATTESTATION],
153+
kinds: [ANCHR_ORACLE_ATTESTATION],
154154
"#e": [queryEventId],
155155
}, {
156156
onevent: onEvent,
@@ -172,8 +172,8 @@ export async function fetchRecentQueries(
172172
const pool = getPool();
173173

174174
const filter: Filter = {
175-
kinds: [GT_QUERY_REQUEST],
176-
"#t": ["ground-truth"],
175+
kinds: [ANCHR_QUERY_REQUEST],
176+
"#t": ["anchr"],
177177
since: Math.floor(Date.now() / 1000) - 3600,
178178
limit: options?.limit ?? 50,
179179
};

src/nostr/encryption.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Encryption utilities for Ground Truth Protocol over Nostr.
2+
* Encryption utilities for Anchr over Nostr.
33
*
44
* Two modes:
55
* 1. Region-key encryption: Derive a shared key from region code.
@@ -13,7 +13,7 @@ import { sha256 } from "@noble/hashes/sha2.js";
1313
import { bytesToHex } from "@noble/hashes/utils.js";
1414
import { nip44 } from "nostr-tools";
1515

16-
const PROTOCOL_VERSION = "ground-truth:v1";
16+
const PROTOCOL_VERSION = "anchr:v1";
1717

1818
/**
1919
* Derive a region key from a region code (e.g., "IR", "CN", "JP").

src/nostr/events.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
parseQueryRequestPayload,
88
parseQueryResponsePayload,
99
parseQuerySettlementPayload,
10-
GT_QUERY_REQUEST,
11-
GT_QUERY_RESPONSE,
12-
GT_QUERY_SETTLEMENT,
10+
ANCHR_QUERY_REQUEST,
11+
ANCHR_QUERY_RESPONSE,
12+
ANCHR_QUERY_SETTLEMENT,
1313
type QueryRequestPayload,
1414
} from "./events";
1515

@@ -25,7 +25,7 @@ describe("Nostr events (NIP-90 DVM)", () => {
2525

2626
const event = buildQueryRequestEvent(identity, "query_123", payload, "IR");
2727

28-
expect(event.kind).toBe(GT_QUERY_REQUEST);
28+
expect(event.kind).toBe(ANCHR_QUERY_REQUEST);
2929
expect(event.kind).toBe(5300); // DVM Job Request
3030
expect(event.pubkey).toBe(identity.publicKey);
3131

@@ -34,7 +34,7 @@ describe("Nostr events (NIP-90 DVM)", () => {
3434
expect(dTag?.[1]).toBe("query_123");
3535

3636
const tTags = event.tags.filter((t) => t[0] === "t");
37-
expect(tTags.some((t) => t[1] === "ground-truth")).toBe(true);
37+
expect(tTags.some((t) => t[1] === "anchr")).toBe(true);
3838
expect(tTags.some((t) => t[1] === "photo_proof")).toBe(true);
3939

4040
const regionTag = event.tags.find((t) => t[0] === "region");
@@ -101,7 +101,7 @@ describe("Nostr events (NIP-90 DVM)", () => {
101101
},
102102
);
103103

104-
expect(response.kind).toBe(GT_QUERY_RESPONSE);
104+
expect(response.kind).toBe(ANCHR_QUERY_RESPONSE);
105105
expect(response.pubkey).toBe(worker.publicKey);
106106

107107
// Requester can decrypt
@@ -131,7 +131,7 @@ describe("Nostr events (NIP-90 DVM)", () => {
131131
},
132132
);
133133

134-
expect(settlement.kind).toBe(GT_QUERY_SETTLEMENT);
134+
expect(settlement.kind).toBe(ANCHR_QUERY_SETTLEMENT);
135135

136136
// Check tags
137137
const eTags = settlement.tags.filter((t) => t[0] === "e");

src/nostr/events.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
2-
* Ground Truth Protocol Nostr event builders and parsers.
2+
* Anchr Nostr event builders and parsers.
33
*
44
* Uses NIP-90 Data Vending Machine (DVM) event kinds so that any
55
* DVM-aware client can discover and interact with Anchr queries.
66
*
77
* Event kind mapping (GT constant → DVM kind):
8-
* GT_QUERY_REQUEST = 5300 (DVM Job Request)
9-
* GT_QUERY_RESPONSE = 6300 (DVM Job Result)
10-
* GT_QUERY_SETTLEMENT = 7000 (DVM Job Feedback)
8+
* ANCHR_QUERY_REQUEST = 5300 (DVM Job Request)
9+
* ANCHR_QUERY_RESPONSE = 6300 (DVM Job Result)
10+
* ANCHR_QUERY_SETTLEMENT = 7000 (DVM Job Feedback)
1111
*
1212
* OracleAttestation (30103) remains a custom parametric-replaceable kind.
1313
*/
@@ -16,11 +16,10 @@ import { finalizeEvent, type EventTemplate, type VerifiedEvent } from "nostr-too
1616
import type { NostrIdentity } from "./identity";
1717
import { deriveConversationKey, encryptNip44, decryptNip44 } from "./encryption";
1818

19-
// NIP-90 DVM event kinds for Ground Truth Protocol.
20-
// Constant names kept as GT_* for backward compat; values are DVM kinds.
21-
export const GT_QUERY_REQUEST = 5300; // was 30100 → DVM Job Request
22-
export const GT_QUERY_RESPONSE = 6300; // was 30101 → DVM Job Result
23-
export const GT_QUERY_SETTLEMENT = 7000; // was 30102 → DVM Job Feedback
19+
// NIP-90 DVM event kinds for Anchr.
20+
export const ANCHR_QUERY_REQUEST = 5300; // DVM Job Request
21+
export const ANCHR_QUERY_RESPONSE = 6300; // DVM Job Result
22+
export const ANCHR_QUERY_SETTLEMENT = 7000; // DVM Job Feedback
2423

2524
export interface QueryRequestPayload {
2625
type: string;
@@ -65,7 +64,7 @@ export interface QuerySettlementPayload {
6564
* ["output", "application/json"] - expected result MIME type
6665
* ["encrypted"] - signals that the result should be NIP-44 encrypted
6766
* ["d", <queryId>] - deduplication / replaceable-event tag
68-
* ["t", "ground-truth"] - protocol marker
67+
* ["t", "anchr"] - protocol marker
6968
* ["t", <query_type>] - query type tag
7069
* ["expiration", <unix>] - NIP-40 expiration
7170
* ["region", <code>] - optional region filter
@@ -87,7 +86,7 @@ export function buildQueryRequestEvent(
8786
["output", "application/json"],
8887
["encrypted"],
8988
["d", queryId],
90-
["t", "ground-truth"],
89+
["t", "anchr"],
9190
["t", payload.type],
9291
["expiration", String(Math.floor(payload.expires_at / 1000))],
9392
];
@@ -102,7 +101,7 @@ export function buildQueryRequestEvent(
102101
}
103102

104103
const template: EventTemplate = {
105-
kind: GT_QUERY_REQUEST,
104+
kind: ANCHR_QUERY_REQUEST,
106105
created_at: Math.floor(Date.now() / 1000),
107106
tags,
108107
content: JSON.stringify(payload),
@@ -136,7 +135,7 @@ export function buildQueryResponseEvent(
136135
const encrypted = encryptNip44(JSON.stringify(payload), conversationKey);
137136

138137
const template: EventTemplate = {
139-
kind: GT_QUERY_RESPONSE,
138+
kind: ANCHR_QUERY_RESPONSE,
140139
created_at: Math.floor(Date.now() / 1000),
141140
tags: [
142141
["e", queryEventId],
@@ -163,7 +162,7 @@ export function buildQuerySettlementEvent(
163162
const encrypted = encryptNip44(JSON.stringify(payload), conversationKey);
164163

165164
const template: EventTemplate = {
166-
kind: GT_QUERY_SETTLEMENT,
165+
kind: ANCHR_QUERY_SETTLEMENT,
167166
created_at: Math.floor(Date.now() / 1000),
168167
tags: [
169168
["e", queryEventId],

src/nostr/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export {
1515
regionKeyHex,
1616
} from "./encryption";
1717
export {
18-
GT_QUERY_REQUEST,
19-
GT_QUERY_RESPONSE,
20-
GT_QUERY_SETTLEMENT,
18+
ANCHR_QUERY_REQUEST,
19+
ANCHR_QUERY_RESPONSE,
20+
ANCHR_QUERY_SETTLEMENT,
2121
buildQueryRequestEvent,
2222
buildQueryResponseEvent,
2323
buildQuerySettlementEvent,
@@ -40,7 +40,7 @@ export {
4040
closePool,
4141
} from "./client";
4242
export {
43-
GT_ORACLE_ATTESTATION,
43+
ANCHR_ORACLE_ATTESTATION,
4444
buildOracleAttestationEvent,
4545
parseOracleAttestationPayload,
4646
toOracleAttestation,

src/nostr/nostr-query-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export async function createNostrQuery(
167167
): Promise<Query | null> {
168168
const identity = generateEphemeralIdentity();
169169
const nonce = generateNonce();
170-
const queryId = `gt_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
170+
const queryId = `anchr_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
171171
const ttlMs = options?.ttlMs ?? 600_000;
172172
const expiresAt = Date.now() + ttlMs;
173173

src/nostr/oracle-attestation.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
buildOracleAttestationEvent,
55
parseOracleAttestationPayload,
66
toOracleAttestation,
7-
GT_ORACLE_ATTESTATION,
7+
ANCHR_ORACLE_ATTESTATION,
88
} from "./oracle-attestation";
99
import type { OracleAttestation } from "../oracle/types";
1010

@@ -27,7 +27,7 @@ test("buildOracleAttestationEvent creates valid event", () => {
2727
attestation,
2828
);
2929

30-
expect(event.kind).toBe(GT_ORACLE_ATTESTATION);
30+
expect(event.kind).toBe(ANCHR_ORACLE_ATTESTATION);
3131
expect(event.pubkey).toBe(oracleIdentity.publicKey);
3232

3333
// Tags

src/nostr/oracle-attestation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Oracle attestation events for Ground Truth Protocol.
2+
* Oracle attestation events for Anchr.
33
*
44
* Kind 30103 - OracleAttestation: published by oracle after verification.
55
* Publicly verifiable — anyone can check the oracle's signature and
@@ -10,7 +10,7 @@ import { finalizeEvent, type EventTemplate, type VerifiedEvent } from "nostr-too
1010
import type { NostrIdentity } from "./identity";
1111
import type { OracleAttestation } from "../oracle/types";
1212

13-
export const GT_ORACLE_ATTESTATION = 30103;
13+
export const ANCHR_ORACLE_ATTESTATION = 30103;
1414

1515
export interface OracleAttestationPayload {
1616
oracle_id: string;
@@ -42,13 +42,13 @@ export function buildOracleAttestationEvent(
4242
};
4343

4444
const template: EventTemplate = {
45-
kind: GT_ORACLE_ATTESTATION,
45+
kind: ANCHR_ORACLE_ATTESTATION,
4646
created_at: Math.floor(Date.now() / 1000),
4747
tags: [
4848
["e", queryEventId],
4949
["e", responseEventId],
5050
["d", attestation.query_id],
51-
["t", "ground-truth"],
51+
["t", "anchr"],
5252
["t", "attestation"],
5353
["result", attestation.passed ? "pass" : "fail"],
5454
],

src/nostr/query-bridge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function publishQueryToNostr(
7070

7171
const identity = generateEphemeralIdentity();
7272
const nonce = generateNonce();
73-
const queryId = `gt_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
73+
const queryId = `anchr_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
7474

7575
const payload: QueryRequestPayload = {
7676
type: input.type,

0 commit comments

Comments
 (0)