nostr-bray 3.10.1 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.js +50 -0
- package/dist/identity/tools.d.ts +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/social/notifications.d.ts +2 -2
- package/dist/social/notifications.js +4 -4
- package/dist/social/tools.js +14 -9
- package/dist/tool-groups.js +2 -0
- package/dist/trust-context.d.ts +7 -0
- package/dist/trust-context.js +8 -2
- package/dist/types.d.ts +4 -0
- package/dist/veil/cache.d.ts +4 -0
- package/dist/veil/filter.d.ts +2 -0
- package/dist/veil/filter.js +2 -1
- package/dist/veil/scoring.d.ts +32 -3
- package/dist/veil/scoring.js +201 -44
- package/dist/workflow/tools.d.ts +2 -0
- package/dist/workflow/tools.js +7 -3
- package/llms-full.txt +7 -5
- package/llms.txt +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -243,7 +243,9 @@ Create `~/.config/bray/config.json` (or `~/.nostr/bray.json`):
|
|
|
243
243
|
{
|
|
244
244
|
"bunkerUriFile": "/Users/you/.nostr/bunker-uri",
|
|
245
245
|
"relays": ["wss://relay.damus.io", "wss://nos.lol"],
|
|
246
|
-
"trustMode": "annotate"
|
|
246
|
+
"trustMode": "annotate",
|
|
247
|
+
"veilTrustedCircles": ["<64 lowercase hex circle ID>"],
|
|
248
|
+
"veilTrustedPublishers": ["npub1... or 64 hex"]
|
|
247
249
|
}
|
|
248
250
|
```
|
|
249
251
|
|
|
@@ -251,6 +253,8 @@ Secrets are referenced by **file path** (`bunkerUriFile`, `secretKeyFile`, `nwcU
|
|
|
251
253
|
|
|
252
254
|
`trustMode` is `strict` (hide content from untrusted pubkeys), `annotate` (show trust scores) or `off` (no filtering). The default is `annotate`; an unrecognised value falls back to `annotate`. The `TRUST_MODE` environment variable overrides the config file.
|
|
253
255
|
|
|
256
|
+
`veilTrustedCircles` lists circle IDs (64 lowercase hex, from `computeCircleId`) whose ring proofs count towards Veil trust scores. `veilTrustedPublishers` lists pubkeys (hex or npub) whose assertions and ring proofs count, as if you followed them. Your own follows always count. `VEIL_TRUSTED_CIRCLES` and `VEIL_TRUSTED_PUBLISHERS` take comma-separated lists, merged with the file; an invalid entry stops startup. See [docs/trust-scoring.md](docs/trust-scoring.md).
|
|
257
|
+
|
|
254
258
|
Search order: `BRAY_CONFIG` env var > `$XDG_CONFIG_HOME/bray/config.json` > `~/.nostr/bray.json`.
|
|
255
259
|
|
|
256
260
|
### Environment variables
|
|
@@ -277,6 +281,8 @@ Search order: `BRAY_CONFIG` env var > `$XDG_CONFIG_HOME/bray/config.json` > `~/.
|
|
|
277
281
|
| `TOR_PROXY` | SOCKS5h proxy for Tor; covers relay traffic, NIP-46 signer traffic and the bunker daemon |
|
|
278
282
|
| `NIP04_ENABLED` | Set `1` to enable legacy NIP-04 DMs |
|
|
279
283
|
| `TRUST_MODE` | `strict`, `annotate` (default) or `off`. See the config file section above |
|
|
284
|
+
| `VEIL_TRUSTED_CIRCLES` | Comma-separated circle IDs (64 lowercase hex) whose Veil ring proofs count. Merged with `veilTrustedCircles` |
|
|
285
|
+
| `VEIL_TRUSTED_PUBLISHERS` | Comma-separated npubs or hex whose Veil assertions and ring proofs count. Merged with `veilTrustedPublishers` |
|
|
280
286
|
| `TRANSPORT` | `stdio` (default) or `http` |
|
|
281
287
|
| `PORT` | HTTP port (default 3000) |
|
|
282
288
|
| `BIND_ADDRESS` | HTTP bind address (default `127.0.0.1`) |
|
package/dist/config.d.ts
CHANGED
|
@@ -38,6 +38,10 @@ interface ConfigFile {
|
|
|
38
38
|
dispatchIdentities?: string;
|
|
39
39
|
/** Public keys this process must never sign as. See ContextOptions. */
|
|
40
40
|
forbidPubkeys?: string[];
|
|
41
|
+
/** Circle IDs (64 lowercase hex) whose Veil ring proofs count towards trust scores. */
|
|
42
|
+
veilTrustedCircles?: string[];
|
|
43
|
+
/** Pubkeys (hex or npub) whose Veil assertions and ring proofs count towards trust scores. */
|
|
44
|
+
veilTrustedPublishers?: string[];
|
|
41
45
|
/** Register the tools that mint spending connections (wallet-grant, wallet-refill, wallet-serve). */
|
|
42
46
|
walletService?: boolean;
|
|
43
47
|
}
|
package/dist/config.js
CHANGED
|
@@ -56,6 +56,49 @@ function validateTorRelays(relays, torProxy, allowClearnet) {
|
|
|
56
56
|
throw new Error(`Clearnet relays not allowed with Tor proxy (set ALLOW_CLEARNET_WITH_TOR=1 to override): ${clearnet.join(', ')}`);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Merge a comma-separated environment list with a config file list. An entry
|
|
61
|
+
* that fails validation is a startup error: a misconfigured trust allowlist
|
|
62
|
+
* must not quietly fail open or closed.
|
|
63
|
+
*/
|
|
64
|
+
function mergeList(envValue, fileValue) {
|
|
65
|
+
return [...(envValue ?? '').split(','), ...(fileValue ?? [])]
|
|
66
|
+
.map(s => String(s).trim())
|
|
67
|
+
.filter(Boolean);
|
|
68
|
+
}
|
|
69
|
+
/** Circle IDs are the 64-char lowercase hex SHA-256 from computeCircleId. */
|
|
70
|
+
function parseTrustedCircles(raw) {
|
|
71
|
+
for (const id of raw) {
|
|
72
|
+
if (!HEX_RE.test(id)) {
|
|
73
|
+
throw new Error(`veilTrustedCircles entry "${id}" is not a circle ID: expected 64 lowercase hex characters`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return [...new Set(raw)];
|
|
77
|
+
}
|
|
78
|
+
/** Trusted publishers may be hex or npub; both resolve to lowercase hex. */
|
|
79
|
+
function parseTrustedPublishers(raw) {
|
|
80
|
+
const out = new Set();
|
|
81
|
+
for (const entry of raw) {
|
|
82
|
+
if (/^[0-9a-fA-F]{64}$/.test(entry)) {
|
|
83
|
+
out.add(entry.toLowerCase());
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (entry.toLowerCase().startsWith('nsec1')) {
|
|
87
|
+
throw new Error('veilTrustedPublishers wants a PUBLIC key; that is an nsec. Treat it as exposed.');
|
|
88
|
+
}
|
|
89
|
+
let hex;
|
|
90
|
+
try {
|
|
91
|
+
const decoded = decodeNip19(entry);
|
|
92
|
+
if (decoded.type === 'npub')
|
|
93
|
+
hex = decoded.data;
|
|
94
|
+
}
|
|
95
|
+
catch { /* reported below */ }
|
|
96
|
+
if (!hex)
|
|
97
|
+
throw new Error(`veilTrustedPublishers entry "${entry}" is neither an npub nor 64 hex characters`);
|
|
98
|
+
out.add(hex);
|
|
99
|
+
}
|
|
100
|
+
return [...out];
|
|
101
|
+
}
|
|
59
102
|
/**
|
|
60
103
|
* Load config from a JSON file. Searches in order:
|
|
61
104
|
* 1. BRAY_CONFIG env var (explicit path)
|
|
@@ -362,6 +405,9 @@ export async function loadConfig(options = {}) {
|
|
|
362
405
|
]
|
|
363
406
|
.map((s) => s.trim())
|
|
364
407
|
.filter(Boolean);
|
|
408
|
+
// --- Veil trust anchors ---
|
|
409
|
+
const veilTrustedCircles = parseTrustedCircles(mergeList(process.env.VEIL_TRUSTED_CIRCLES, file.veilTrustedCircles));
|
|
410
|
+
const veilTrustedPublishers = parseTrustedPublishers(mergeList(process.env.VEIL_TRUSTED_PUBLISHERS, file.veilTrustedPublishers));
|
|
365
411
|
// --- Wallet service ---
|
|
366
412
|
// Off unless asked for: wallet-grant, wallet-refill and wallet-serve hand
|
|
367
413
|
// out spending authority over the operator's wallet, which is not
|
|
@@ -398,6 +444,8 @@ export async function loadConfig(options = {}) {
|
|
|
398
444
|
bindAddress,
|
|
399
445
|
dispatchIdentities: undefined,
|
|
400
446
|
forbidPubkeys,
|
|
447
|
+
veilTrustedCircles,
|
|
448
|
+
veilTrustedPublishers,
|
|
401
449
|
walletService: false,
|
|
402
450
|
};
|
|
403
451
|
}
|
|
@@ -426,6 +474,8 @@ export async function loadConfig(options = {}) {
|
|
|
426
474
|
bindAddress,
|
|
427
475
|
dispatchIdentities,
|
|
428
476
|
forbidPubkeys,
|
|
477
|
+
veilTrustedCircles,
|
|
478
|
+
veilTrustedPublishers,
|
|
429
479
|
walletService,
|
|
430
480
|
};
|
|
431
481
|
}
|
package/dist/identity/tools.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export interface ToolDeps {
|
|
|
15
15
|
nip04Enabled?: boolean;
|
|
16
16
|
veilCacheTtl?: number;
|
|
17
17
|
veilCacheMax?: number;
|
|
18
|
+
/** Hex circle IDs whose ring proofs count towards Veil scores. */
|
|
19
|
+
veilTrustedCircles?: string[];
|
|
20
|
+
/** Hex pubkeys whose assertions and ring proofs count towards Veil scores. */
|
|
21
|
+
veilTrustedPublishers?: string[];
|
|
18
22
|
trust?: TrustContext;
|
|
19
23
|
}
|
|
20
24
|
export declare function registerIdentityTools(server: McpServer, deps: ToolDeps): void;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -136,12 +136,16 @@ const trust = new TrustContext(ctx, pool, {
|
|
|
136
136
|
cacheTtl: config.trustCacheTtl,
|
|
137
137
|
cacheMax: config.trustCacheMax,
|
|
138
138
|
trustMode: config.trustMode,
|
|
139
|
+
veilTrustedCircles: config.veilTrustedCircles,
|
|
140
|
+
veilTrustedPublishers: config.veilTrustedPublishers,
|
|
139
141
|
});
|
|
140
142
|
export const deps = {
|
|
141
143
|
ctx, pool, nip65, trust,
|
|
142
144
|
nwcUri: config.nwcUri,
|
|
143
145
|
walletsFile: config.walletsFile,
|
|
144
146
|
nip04Enabled: config.nip04Enabled,
|
|
147
|
+
veilTrustedCircles: config.veilTrustedCircles,
|
|
148
|
+
veilTrustedPublishers: config.veilTrustedPublishers,
|
|
145
149
|
};
|
|
146
150
|
config.secretKey = '';
|
|
147
151
|
config.nwcUri = undefined;
|
|
@@ -30,7 +30,7 @@ export interface FeedEntry {
|
|
|
30
30
|
*
|
|
31
31
|
* @param opts.since - Optional Unix timestamp; only return events newer than this.
|
|
32
32
|
* @param opts.limit - Maximum number of events to fetch (default 50).
|
|
33
|
-
* @param opts.trust - Trust filter mode (`'strict'`, `'
|
|
33
|
+
* @param opts.trust - Trust filter mode (`'strict'`, `'annotate'`, or `'off'`). Has no effect without `_scoring`.
|
|
34
34
|
* @param opts._scoring - Optional Veil scoring engine; scores and filters events by trust when supplied.
|
|
35
35
|
* @returns Classified notifications sorted newest first, each typed as `reply`, `reaction`, `mention`, `zap`, or `other`.
|
|
36
36
|
* @example
|
|
@@ -49,7 +49,7 @@ export declare function handleNotifications(ctx: SigningContext, pool: RelayPool
|
|
|
49
49
|
* @param opts.authors - Optional list of pubkeys (hex) to restrict the feed to.
|
|
50
50
|
* @param opts.since - Optional Unix timestamp; only return events newer than this.
|
|
51
51
|
* @param opts.limit - Maximum number of events to return (default 20).
|
|
52
|
-
* @param opts.trust - Trust filter mode (`'strict'`, `'
|
|
52
|
+
* @param opts.trust - Trust filter mode (`'strict'`, `'annotate'`, or `'off'`). Has no effect without `_scoring`.
|
|
53
53
|
* @param opts._scoring - Optional Veil scoring engine; scores and filters events by trust when supplied.
|
|
54
54
|
* @param opts._trustCtx - Optional trust context; populates `_trust` annotation on each entry.
|
|
55
55
|
* @returns Feed entries sorted by trust then time, each containing `id`, `pubkey`, `content`, `createdAt`, `tags`, and optional trust data.
|
|
@@ -7,7 +7,7 @@ import { toAnnotation } from '../trust-context.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @param opts.since - Optional Unix timestamp; only return events newer than this.
|
|
9
9
|
* @param opts.limit - Maximum number of events to fetch (default 50).
|
|
10
|
-
* @param opts.trust - Trust filter mode (`'strict'`, `'
|
|
10
|
+
* @param opts.trust - Trust filter mode (`'strict'`, `'annotate'`, or `'off'`). Has no effect without `_scoring`.
|
|
11
11
|
* @param opts._scoring - Optional Veil scoring engine; scores and filters events by trust when supplied.
|
|
12
12
|
* @returns Classified notifications sorted newest first, each typed as `reply`, `reaction`, `mention`, `zap`, or `other`.
|
|
13
13
|
* @example
|
|
@@ -25,7 +25,7 @@ export async function handleNotifications(ctx, pool, opts) {
|
|
|
25
25
|
const filtered = events.filter(e => e.kind !== 3); // exclude follows
|
|
26
26
|
if (opts?._scoring && opts.trust !== 'off') {
|
|
27
27
|
const scored = await opts._scoring.scoreEvents(filtered);
|
|
28
|
-
const trustFiltered = filterByTrust(scored, { mode: opts.trust ?? 'strict' });
|
|
28
|
+
const trustFiltered = filterByTrust(scored, { mode: opts.trust ?? 'strict', trustedAuthors: await opts._scoring.trustedAuthors() });
|
|
29
29
|
return trustFiltered
|
|
30
30
|
.map(event => ({ ...classifyNotification(event, ctx.activeNpub), trustScore: event._trustScore }))
|
|
31
31
|
.sort((a, b) => b.createdAt - a.createdAt);
|
|
@@ -99,7 +99,7 @@ function parseZapReceipt(event, base) {
|
|
|
99
99
|
* @param opts.authors - Optional list of pubkeys (hex) to restrict the feed to.
|
|
100
100
|
* @param opts.since - Optional Unix timestamp; only return events newer than this.
|
|
101
101
|
* @param opts.limit - Maximum number of events to return (default 20).
|
|
102
|
-
* @param opts.trust - Trust filter mode (`'strict'`, `'
|
|
102
|
+
* @param opts.trust - Trust filter mode (`'strict'`, `'annotate'`, or `'off'`). Has no effect without `_scoring`.
|
|
103
103
|
* @param opts._scoring - Optional Veil scoring engine; scores and filters events by trust when supplied.
|
|
104
104
|
* @param opts._trustCtx - Optional trust context; populates `_trust` annotation on each entry.
|
|
105
105
|
* @returns Feed entries sorted by trust then time, each containing `id`, `pubkey`, `content`, `createdAt`, `tags`, and optional trust data.
|
|
@@ -120,7 +120,7 @@ export async function handleFeed(ctx, pool, opts) {
|
|
|
120
120
|
let results;
|
|
121
121
|
if (opts._scoring && opts.trust !== 'off') {
|
|
122
122
|
const scored = await opts._scoring.scoreEvents(events);
|
|
123
|
-
const filtered = filterByTrust(scored, { mode: opts.trust ?? 'strict' });
|
|
123
|
+
const filtered = filterByTrust(scored, { mode: opts.trust ?? 'strict', trustedAuthors: await opts._scoring.trustedAuthors() });
|
|
124
124
|
results = filtered.map(e => ({
|
|
125
125
|
id: e.id,
|
|
126
126
|
pubkey: e.pubkey,
|
package/dist/social/tools.js
CHANGED
|
@@ -42,6 +42,14 @@ export function registerSocialTools(server, deps) {
|
|
|
42
42
|
ttl: deps.veilCacheTtl ?? 300_000,
|
|
43
43
|
maxEntries: deps.veilCacheMax ?? 500,
|
|
44
44
|
});
|
|
45
|
+
const veilScoringOptions = {
|
|
46
|
+
trustedCircles: deps.veilTrustedCircles,
|
|
47
|
+
trustedPublishers: deps.veilTrustedPublishers,
|
|
48
|
+
followsTtl: deps.veilCacheTtl ?? 300_000,
|
|
49
|
+
};
|
|
50
|
+
// One instance per registration, so the follow list is fetched once per TTL
|
|
51
|
+
// rather than on every tool call. It reads the identity lazily.
|
|
52
|
+
const scoring = new VeilScoring(deps.pool, trustCache, deps.ctx, veilScoringOptions);
|
|
45
53
|
server.registerTool('social-post', {
|
|
46
54
|
description: 'Post a text note (kind 1) signed by the active identity and publish to relays. Returns { id, pubkey, publish: { success, allAccepted, accepted, rejected } } where success is the majority-quorum signal (true when at least one relay accepted and at least half of attempted relays accepted) and allAccepted is true only when every attempted relay accepted. The most common social action.',
|
|
47
55
|
inputSchema: {
|
|
@@ -68,7 +76,6 @@ export function registerSocialTools(server, deps) {
|
|
|
68
76
|
},
|
|
69
77
|
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
70
78
|
}, async ({ content, replyTo, replyToPubkey, relay }) => {
|
|
71
|
-
const scoring = new VeilScoring(deps.pool, trustCache, deps.ctx.activeNpub);
|
|
72
79
|
const result = await handleSocialReply(deps.ctx, deps.pool, { content, replyTo, replyToPubkey, relay, _scoring: scoring });
|
|
73
80
|
return {
|
|
74
81
|
content: [{ type: 'text', text: JSON.stringify({
|
|
@@ -309,14 +316,13 @@ export function registerSocialTools(server, deps) {
|
|
|
309
316
|
inputSchema: {
|
|
310
317
|
since: z.number().optional().describe('Unix timestamp — only fetch notifications after this time'),
|
|
311
318
|
limit: z.number().int().min(1).max(200).default(50).describe('Max notifications to return'),
|
|
312
|
-
trust: z.enum(['strict', 'annotate', 'off']).
|
|
313
|
-
.describe('Trust filter mode: strict (hide
|
|
319
|
+
trust: z.enum(['strict', 'annotate', 'off']).optional()
|
|
320
|
+
.describe('Trust filter mode: strict (hide authors with no endorsement from you, your follows or a trusted publisher), annotate (show scores), off (no filtering). Defaults to the configured trustMode, which is annotate unless set.'),
|
|
314
321
|
output: z.enum(['json', 'human']).default('human').describe('Response format'),
|
|
315
322
|
},
|
|
316
323
|
annotations: { readOnlyHint: true },
|
|
317
324
|
}, async ({ since, limit, trust, output }) => {
|
|
318
|
-
const
|
|
319
|
-
const notifications = await handleNotifications(deps.ctx, deps.pool, { since, limit, trust, _scoring: scoring });
|
|
325
|
+
const notifications = await handleNotifications(deps.ctx, deps.pool, { since, limit, trust: trust ?? deps.trust?.mode ?? 'annotate', _scoring: scoring });
|
|
320
326
|
return toolResponse(notifications, output, fmt.formatNotifications);
|
|
321
327
|
});
|
|
322
328
|
server.registerTool('social-feed', {
|
|
@@ -325,14 +331,13 @@ export function registerSocialTools(server, deps) {
|
|
|
325
331
|
authors: z.array(hexId).optional().describe('Hex pubkeys to filter by'),
|
|
326
332
|
since: z.number().optional().describe('Unix timestamp — only fetch posts after this time'),
|
|
327
333
|
limit: z.number().int().min(1).max(100).default(20).describe('Max posts to return'),
|
|
328
|
-
trust: z.enum(['strict', 'annotate', 'off']).
|
|
329
|
-
.describe('Trust filter mode: strict (hide
|
|
334
|
+
trust: z.enum(['strict', 'annotate', 'off']).optional()
|
|
335
|
+
.describe('Trust filter mode: strict (hide authors with no endorsement from you, your follows or a trusted publisher), annotate (show scores), off (no filtering). Defaults to the configured trustMode, which is annotate unless set.'),
|
|
330
336
|
output: z.enum(['json', 'human']).default('human').describe('Response format'),
|
|
331
337
|
},
|
|
332
338
|
annotations: { readOnlyHint: true },
|
|
333
339
|
}, async ({ authors, since, limit, trust, output }) => {
|
|
334
|
-
const
|
|
335
|
-
const feed = await handleFeed(deps.ctx, deps.pool, { authors, since, limit, trust, _scoring: scoring });
|
|
340
|
+
const feed = await handleFeed(deps.ctx, deps.pool, { authors, since, limit, trust: trust ?? deps.trust?.mode ?? 'annotate', _scoring: scoring });
|
|
336
341
|
return toolResponse(feed, output, fmt.formatFeed);
|
|
337
342
|
});
|
|
338
343
|
server.registerTool('feed-by-name', {
|
package/dist/tool-groups.js
CHANGED
|
@@ -37,6 +37,8 @@ export function registerAllTools(server, deps, options) {
|
|
|
37
37
|
nip65: deps.nip65,
|
|
38
38
|
veilCacheTtl: options.veilCacheTtl,
|
|
39
39
|
veilCacheMax: options.veilCacheMax,
|
|
40
|
+
veilTrustedCircles: deps.veilTrustedCircles,
|
|
41
|
+
veilTrustedPublishers: deps.veilTrustedPublishers,
|
|
40
42
|
trust: deps.trust,
|
|
41
43
|
});
|
|
42
44
|
registerMarketplaceTools(server, deps);
|
package/dist/trust-context.d.ts
CHANGED
|
@@ -8,12 +8,19 @@ export interface TrustContextOptions {
|
|
|
8
8
|
cacheTtl: number;
|
|
9
9
|
cacheMax: number;
|
|
10
10
|
trustMode: TrustMode;
|
|
11
|
+
/** Hex circle IDs whose ring proofs count towards the Veil score. */
|
|
12
|
+
veilTrustedCircles?: string[];
|
|
13
|
+
/** Hex pubkeys whose assertions and ring proofs count towards the Veil score. */
|
|
14
|
+
veilTrustedPublishers?: string[];
|
|
11
15
|
}
|
|
12
16
|
export interface ProximityInfo {
|
|
13
17
|
distance: number;
|
|
14
18
|
wotScore: number;
|
|
15
19
|
endorsements: number;
|
|
16
20
|
ringEndorsements: number;
|
|
21
|
+
/** Endorsements from outside the trusted set: reported, not scored. */
|
|
22
|
+
untrustedEndorsements: number;
|
|
23
|
+
untrustedRingEndorsements: number;
|
|
17
24
|
mutualFollows: boolean;
|
|
18
25
|
}
|
|
19
26
|
export interface CompositeLevel {
|
package/dist/trust-context.js
CHANGED
|
@@ -116,7 +116,11 @@ export class TrustContext {
|
|
|
116
116
|
this.signet = new SignetAssessor(pool, { ttl: opts.cacheTtl, maxEntries: opts.cacheMax });
|
|
117
117
|
this.vault = new VaultResolver(pool, { ttl: opts.cacheTtl, maxEntries: opts.cacheMax });
|
|
118
118
|
this.veilCache = new TrustCache({ ttl: opts.cacheTtl, maxEntries: opts.cacheMax });
|
|
119
|
-
this.veil = new VeilScoring(pool, this.veilCache,
|
|
119
|
+
this.veil = new VeilScoring(pool, this.veilCache, ctx, {
|
|
120
|
+
trustedCircles: opts.veilTrustedCircles,
|
|
121
|
+
trustedPublishers: opts.veilTrustedPublishers,
|
|
122
|
+
followsTtl: opts.cacheTtl,
|
|
123
|
+
});
|
|
120
124
|
}
|
|
121
125
|
/** Assess trust for a target pubkey across all three dimensions in parallel. */
|
|
122
126
|
async assess(targetPubkeyHex) {
|
|
@@ -137,6 +141,8 @@ export class TrustContext {
|
|
|
137
141
|
wotScore: veilResult.score,
|
|
138
142
|
endorsements: veilResult.endorsements,
|
|
139
143
|
ringEndorsements: veilResult.ringEndorsements,
|
|
144
|
+
untrustedEndorsements: veilResult.untrustedEndorsements,
|
|
145
|
+
untrustedRingEndorsements: veilResult.untrustedRingEndorsements,
|
|
140
146
|
mutualFollows: mutual,
|
|
141
147
|
};
|
|
142
148
|
const level = computeCompositeLevel(verification.tier, distance, access.vaultTiers);
|
|
@@ -166,7 +172,7 @@ export class TrustContext {
|
|
|
166
172
|
pubkey,
|
|
167
173
|
npub: npubEncode(pubkey),
|
|
168
174
|
verification: { tier: null, score: 0, credentials: 0, expired: false },
|
|
169
|
-
proximity: { distance: -1, wotScore: 0, endorsements: 0, ringEndorsements: 0, mutualFollows: false },
|
|
175
|
+
proximity: { distance: -1, wotScore: 0, endorsements: 0, ringEndorsements: 0, untrustedEndorsements: 0, untrustedRingEndorsements: 0, mutualFollows: false },
|
|
170
176
|
access: { vaultTiers: [], theirVaultTiers: [], canDecrypt: false, currentEpoch: '', revoked: false },
|
|
171
177
|
composite: { level: 'unknown', summary: 'Trust assessment disabled', flags: [] },
|
|
172
178
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -76,6 +76,10 @@ export interface BrayConfig {
|
|
|
76
76
|
* and approve its own requests. Enforced in IdentityContext, at the
|
|
77
77
|
* moment an identity is activated. */
|
|
78
78
|
readonly forbidPubkeys?: string[];
|
|
79
|
+
/** Hex circle IDs (computeCircleId of the exact member set) whose Veil ring proofs count towards trust scores. */
|
|
80
|
+
readonly veilTrustedCircles?: string[];
|
|
81
|
+
/** Hex pubkeys whose Veil assertions and ring proofs count towards trust scores. */
|
|
82
|
+
readonly veilTrustedPublishers?: string[];
|
|
79
83
|
}
|
|
80
84
|
export type { SigningContext, ExtendedSigningContext } from './signing-context.js';
|
|
81
85
|
export { hasExtendedIdentity } from './signing-context.js';
|
package/dist/veil/cache.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ export interface TrustCacheEntry {
|
|
|
2
2
|
score: number;
|
|
3
3
|
endorsements: number;
|
|
4
4
|
ringEndorsements: number;
|
|
5
|
+
/** Plain assertions from authors outside the caller's trusted set: reported, not scored. */
|
|
6
|
+
untrustedEndorsements: number;
|
|
7
|
+
/** Ring key images from proofs outside the trusted set: reported, not scored. */
|
|
8
|
+
untrustedRingEndorsements: number;
|
|
5
9
|
}
|
|
6
10
|
export interface TrustCacheOptions {
|
|
7
11
|
ttl: number;
|
package/dist/veil/filter.d.ts
CHANGED
|
@@ -3,5 +3,7 @@ export type TrustMode = 'strict' | 'annotate' | 'off';
|
|
|
3
3
|
export interface FilterOptions {
|
|
4
4
|
mode?: TrustMode;
|
|
5
5
|
threshold?: number;
|
|
6
|
+
/** Authors let through in strict mode even with no endorsements: the caller's follows and trusted publishers. */
|
|
7
|
+
trustedAuthors?: Set<string>;
|
|
6
8
|
}
|
|
7
9
|
export declare function filterByTrust(events: ScoredEvent[], opts?: FilterOptions): ScoredEvent[];
|
package/dist/veil/filter.js
CHANGED
|
@@ -6,5 +6,6 @@ export function filterByTrust(events, opts) {
|
|
|
6
6
|
if (mode === 'annotate')
|
|
7
7
|
return events;
|
|
8
8
|
// strict
|
|
9
|
-
|
|
9
|
+
const trusted = opts?.trustedAuthors;
|
|
10
|
+
return events.filter(e => e._trustScore >= threshold || (trusted?.has(e.pubkey) ?? false));
|
|
10
11
|
}
|
package/dist/veil/scoring.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Event as NostrEvent } from 'nostr-tools';
|
|
2
2
|
import type { RelayPool } from '../relay-pool.js';
|
|
3
|
+
import type { SigningContext } from '../signing-context.js';
|
|
3
4
|
import type { TrustCache, TrustCacheEntry } from './cache.js';
|
|
4
5
|
export interface TrustScoreResult extends TrustCacheEntry {
|
|
5
6
|
pubkey: string;
|
|
@@ -8,12 +9,40 @@ export interface TrustScoreResult extends TrustCacheEntry {
|
|
|
8
9
|
export interface ScoredEvent extends NostrEvent {
|
|
9
10
|
_trustScore: number;
|
|
10
11
|
}
|
|
12
|
+
export interface VeilScoringOptions {
|
|
13
|
+
/** Circle IDs (computeCircleId of the exact member set) whose ring proofs count. */
|
|
14
|
+
trustedCircles?: string[];
|
|
15
|
+
/** Hex pubkeys whose assertions and ring proofs count, as if the caller followed them. */
|
|
16
|
+
trustedPublishers?: string[];
|
|
17
|
+
/** How long the caller's follow list is reused, in milliseconds. Default 5 minutes. */
|
|
18
|
+
followsTtl?: number;
|
|
19
|
+
}
|
|
11
20
|
export declare class VeilScoring {
|
|
12
21
|
private readonly pool;
|
|
13
22
|
private readonly cache;
|
|
14
|
-
private readonly
|
|
15
|
-
|
|
16
|
-
private
|
|
23
|
+
private readonly ctx;
|
|
24
|
+
private readonly trustedCircles;
|
|
25
|
+
private readonly trustedPublishers;
|
|
26
|
+
private readonly followsTtl;
|
|
27
|
+
private readonly followsCache;
|
|
28
|
+
constructor(pool: RelayPool, cache: TrustCache, ctx: Pick<SigningContext, 'activeNpub' | 'activePublicKeyHex'>, opts?: VeilScoringOptions);
|
|
29
|
+
/**
|
|
30
|
+
* The caller's own follow list (latest kind 3) plus the caller's own pubkey.
|
|
31
|
+
* Cached per caller pubkey for the configured TTL, so an identity switch
|
|
32
|
+
* reads its own list.
|
|
33
|
+
*/
|
|
34
|
+
private follows;
|
|
35
|
+
private loadFollows;
|
|
36
|
+
/** Pubkeys whose content a strict filter lets through without endorsements:
|
|
37
|
+
* the caller, the caller's follows and the configured trusted publishers. */
|
|
38
|
+
trustedAuthors(): Promise<Set<string>>;
|
|
17
39
|
scorePubkey(pubkey: string): Promise<TrustScoreResult>;
|
|
40
|
+
/**
|
|
41
|
+
* A ring proof counts when its exact circle is configured, its publisher is
|
|
42
|
+
* a trusted publisher, or every member is in the caller's follows. A
|
|
43
|
+
* fraction of trusted members is not enough: an attacker inside an otherwise
|
|
44
|
+
* trusted ring can sign, and the proof cannot tell them apart.
|
|
45
|
+
*/
|
|
46
|
+
private isTrustedRing;
|
|
18
47
|
scoreEvents(events: NostrEvent[]): Promise<ScoredEvent[]>;
|
|
19
48
|
}
|
package/dist/veil/scoring.js
CHANGED
|
@@ -1,48 +1,145 @@
|
|
|
1
1
|
import { parseAssertion } from 'nostr-veil/nip85';
|
|
2
|
-
import { verifyProof } from 'nostr-veil/proof';
|
|
2
|
+
import { verifyProof, computeCircleId } from 'nostr-veil/proof';
|
|
3
|
+
const DEFAULT_FOLLOWS_TTL = 300_000;
|
|
4
|
+
const HEX64_RE = /^[0-9a-f]{64}$/;
|
|
5
|
+
/** The scope a key image belongs to: the electionId inside the signature JSON,
|
|
6
|
+
* or the raw tag value when that cannot be read. */
|
|
7
|
+
function scopeOf(sigTag) {
|
|
8
|
+
const raw = sigTag[1] ?? '';
|
|
9
|
+
try {
|
|
10
|
+
const parsed = JSON.parse(raw);
|
|
11
|
+
if (parsed && typeof parsed === 'object') {
|
|
12
|
+
const eid = parsed.electionId;
|
|
13
|
+
if (typeof eid === 'string')
|
|
14
|
+
return eid;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch { /* fall back to the raw tag value */ }
|
|
18
|
+
return raw;
|
|
19
|
+
}
|
|
3
20
|
export class VeilScoring {
|
|
4
21
|
pool;
|
|
5
22
|
cache;
|
|
6
|
-
|
|
23
|
+
ctx;
|
|
24
|
+
trustedCircles;
|
|
25
|
+
trustedPublishers;
|
|
26
|
+
followsTtl;
|
|
27
|
+
followsCache = new Map();
|
|
7
28
|
constructor(pool, cache,
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
29
|
+
// Read on every query, never captured: a bunker-backed identity has no
|
|
30
|
+
// npub or pubkey until the bunker has answered, the trust layer is built
|
|
31
|
+
// before that, and an identity switch changes both.
|
|
32
|
+
ctx, opts = {}) {
|
|
12
33
|
this.pool = pool;
|
|
13
34
|
this.cache = cache;
|
|
14
|
-
this.
|
|
35
|
+
this.ctx = ctx;
|
|
36
|
+
this.trustedCircles = new Set((opts.trustedCircles ?? []).map(c => c.toLowerCase()));
|
|
37
|
+
this.trustedPublishers = new Set((opts.trustedPublishers ?? []).map(p => p.toLowerCase()));
|
|
38
|
+
this.followsTtl = opts.followsTtl ?? DEFAULT_FOLLOWS_TTL;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The caller's own follow list (latest kind 3) plus the caller's own pubkey.
|
|
42
|
+
* Cached per caller pubkey for the configured TTL, so an identity switch
|
|
43
|
+
* reads its own list.
|
|
44
|
+
*/
|
|
45
|
+
async follows() {
|
|
46
|
+
const npub = this.ctx.activeNpub;
|
|
47
|
+
// Read-only mode without a pubkey has no identity: nobody is followed and
|
|
48
|
+
// the public key is never read (it throws).
|
|
49
|
+
if (npub === '')
|
|
50
|
+
return { set: new Set(), found: true };
|
|
51
|
+
const self = this.ctx.activePublicKeyHex;
|
|
52
|
+
const hit = this.followsCache.get(self);
|
|
53
|
+
if (hit && Date.now() - hit.storedAt <= this.followsTtl)
|
|
54
|
+
return hit.promise;
|
|
55
|
+
const promise = this.loadFollows(npub, self);
|
|
56
|
+
this.followsCache.set(self, { promise, storedAt: Date.now() });
|
|
57
|
+
// A failed fetch must not be remembered for the whole TTL.
|
|
58
|
+
promise.catch(() => {
|
|
59
|
+
if (this.followsCache.get(self)?.promise === promise)
|
|
60
|
+
this.followsCache.delete(self);
|
|
61
|
+
});
|
|
62
|
+
return promise;
|
|
63
|
+
}
|
|
64
|
+
async loadFollows(npub, self) {
|
|
65
|
+
const events = await this.pool.query(npub, {
|
|
66
|
+
authors: [self],
|
|
67
|
+
kinds: [3],
|
|
68
|
+
limit: 1,
|
|
69
|
+
});
|
|
70
|
+
let latest;
|
|
71
|
+
for (const event of events) {
|
|
72
|
+
// The relay may return anything: only the caller's own list counts.
|
|
73
|
+
if (event.kind !== 3 || event.pubkey !== self)
|
|
74
|
+
continue;
|
|
75
|
+
if (!latest || event.created_at > latest.created_at)
|
|
76
|
+
latest = event;
|
|
77
|
+
}
|
|
78
|
+
const follows = new Set([self]);
|
|
79
|
+
for (const tag of latest?.tags ?? []) {
|
|
80
|
+
if (tag[0] === 'p' && typeof tag[1] === 'string' && HEX64_RE.test(tag[1]))
|
|
81
|
+
follows.add(tag[1]);
|
|
82
|
+
}
|
|
83
|
+
return { set: follows, found: latest !== undefined };
|
|
15
84
|
}
|
|
16
|
-
|
|
17
|
-
|
|
85
|
+
/** Pubkeys whose content a strict filter lets through without endorsements:
|
|
86
|
+
* the caller, the caller's follows and the configured trusted publishers. */
|
|
87
|
+
async trustedAuthors() {
|
|
88
|
+
const follows = await this.follows();
|
|
89
|
+
return new Set([...follows.set, ...this.trustedPublishers]);
|
|
18
90
|
}
|
|
19
91
|
async scorePubkey(pubkey) {
|
|
92
|
+
pubkey = pubkey.toLowerCase();
|
|
93
|
+
// The npub is read first so a bunker identity that is not ready fails here.
|
|
94
|
+
const npub = this.ctx.activeNpub;
|
|
95
|
+
// The result depends on who is asking (their follows), so the score cache
|
|
96
|
+
// is keyed by caller as well as subject. An empty npub is the anonymous
|
|
97
|
+
// read-only caller, whose public key must not be read.
|
|
98
|
+
const cacheKey = npub === '' ? `anon:${pubkey}` : `${this.ctx.activePublicKeyHex}:${pubkey}`;
|
|
20
99
|
// 1. Check cache first
|
|
21
|
-
const cached = this.cache.get(
|
|
100
|
+
const cached = this.cache.get(cacheKey);
|
|
22
101
|
if (cached) {
|
|
23
102
|
return { pubkey, ...cached, flags: [] };
|
|
24
103
|
}
|
|
25
104
|
// 2. Query kind 30382 (NIP-85) assertions from relays
|
|
26
|
-
const events = await this.pool.query(
|
|
105
|
+
const events = await this.pool.query(npub, {
|
|
27
106
|
kinds: [30382],
|
|
28
107
|
'#d': [pubkey],
|
|
29
108
|
});
|
|
30
109
|
// 3. If no events, return score 0 with 'no endorsements found' flag
|
|
31
110
|
if (events.length === 0) {
|
|
32
|
-
const entry = {
|
|
33
|
-
|
|
111
|
+
const entry = {
|
|
112
|
+
score: 0, endorsements: 0, ringEndorsements: 0,
|
|
113
|
+
untrustedEndorsements: 0, untrustedRingEndorsements: 0,
|
|
114
|
+
};
|
|
115
|
+
this.cache.set(cacheKey, entry);
|
|
34
116
|
return { pubkey, ...entry, flags: ['no endorsements found'] };
|
|
35
117
|
}
|
|
118
|
+
const followList = await this.follows();
|
|
119
|
+
const follows = followList.set;
|
|
36
120
|
const flags = [];
|
|
121
|
+
const addFlag = (flag) => {
|
|
122
|
+
if (!flags.includes(flag))
|
|
123
|
+
flags.push(flag);
|
|
124
|
+
};
|
|
125
|
+
// Without a follow list only the caller is trusted, so say so rather than
|
|
126
|
+
// let follows' endorsements look untrusted for no visible reason.
|
|
127
|
+
if (!followList.found)
|
|
128
|
+
addFlag('follow list not found');
|
|
37
129
|
// One endorsement per author, and one ring endorsement per key image: the
|
|
38
|
-
// same assertion or ring proof published several times counts once.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
130
|
+
// same assertion or ring proof published several times counts once.
|
|
131
|
+
const trustedEndorsers = new Set();
|
|
132
|
+
const untrustedEndorsers = new Set();
|
|
133
|
+
const groups = new Map();
|
|
134
|
+
const groupFor = (scope) => {
|
|
135
|
+
let group = groups.get(scope);
|
|
136
|
+
if (!group) {
|
|
137
|
+
group = { trusted: new Set(), trustedSubjectInRing: false, untrusted: new Set(), untrustedSubjectInRing: false };
|
|
138
|
+
groups.set(scope, group);
|
|
139
|
+
}
|
|
140
|
+
return group;
|
|
141
|
+
};
|
|
142
|
+
// 4. Parse assertions and ring proofs
|
|
46
143
|
for (const event of events) {
|
|
47
144
|
// The relay may return anything; count only kind 30382 assertions about
|
|
48
145
|
// this pubkey, so a valid proof about someone else adds nothing.
|
|
@@ -51,35 +148,95 @@ export class VeilScoring {
|
|
|
51
148
|
const parsed = parseAssertion(event);
|
|
52
149
|
if (parsed.subject !== pubkey)
|
|
53
150
|
continue;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
151
|
+
const sigTags = event.tags.filter((t) => t[0] === 'veil-sig');
|
|
152
|
+
if (sigTags.length === 0) {
|
|
153
|
+
// Plain assertion. Vouching for yourself proves nothing.
|
|
154
|
+
if (event.pubkey === pubkey) {
|
|
155
|
+
addFlag('self-endorsement ignored');
|
|
156
|
+
}
|
|
157
|
+
else if (follows.has(event.pubkey) || this.trustedPublishers.has(event.pubkey)) {
|
|
158
|
+
trustedEndorsers.add(event.pubkey);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
untrustedEndorsers.add(event.pubkey);
|
|
162
|
+
}
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
// 5. Ring proof
|
|
166
|
+
const verification = verifyProof(event, { expectedKind: 30382 });
|
|
167
|
+
if (!verification.valid) {
|
|
168
|
+
addFlag('ring proof invalid');
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const ringTag = event.tags.find((t) => t[0] === 'veil-ring');
|
|
172
|
+
const members = ringTag ? ringTag.slice(1) : [];
|
|
173
|
+
const trusted = this.isTrustedRing(event, members, follows);
|
|
174
|
+
const subjectInRing = members.includes(pubkey);
|
|
175
|
+
for (const tag of sigTags) {
|
|
176
|
+
if (typeof tag[2] !== 'string')
|
|
177
|
+
continue;
|
|
178
|
+
const group = groupFor(scopeOf(tag));
|
|
179
|
+
if (trusted) {
|
|
180
|
+
group.trusted.add(tag[2]);
|
|
181
|
+
if (subjectInRing)
|
|
182
|
+
group.trustedSubjectInRing = true;
|
|
67
183
|
}
|
|
68
184
|
else {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
185
|
+
group.untrusted.add(tag[2]);
|
|
186
|
+
if (subjectInRing)
|
|
187
|
+
group.untrustedSubjectInRing = true;
|
|
72
188
|
}
|
|
73
189
|
}
|
|
190
|
+
addFlag(trusted ? 'ring proof verified' : 'ring proof untrusted');
|
|
191
|
+
}
|
|
192
|
+
// 6. Count key images per scope. The ring signature hides which member
|
|
193
|
+
// signed, so when the subject is in a ring one signature per scope may be
|
|
194
|
+
// their own (key images stop a member signing twice per scope).
|
|
195
|
+
const trustedImages = new Set();
|
|
196
|
+
for (const group of groups.values())
|
|
197
|
+
for (const image of group.trusted)
|
|
198
|
+
trustedImages.add(image);
|
|
199
|
+
let ringEndorsements = 0;
|
|
200
|
+
let untrustedRingEndorsements = 0;
|
|
201
|
+
for (const group of groups.values()) {
|
|
202
|
+
const trustedCount = group.trusted.size;
|
|
203
|
+
if (group.trustedSubjectInRing) {
|
|
204
|
+
ringEndorsements += Math.max(0, trustedCount - 1);
|
|
205
|
+
addFlag('subject is a ring member');
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
ringEndorsements += trustedCount;
|
|
209
|
+
}
|
|
210
|
+
// A key image already counted as trusted is not also reported as untrusted.
|
|
211
|
+
let untrustedCount = 0;
|
|
212
|
+
for (const image of group.untrusted)
|
|
213
|
+
if (!trustedImages.has(image))
|
|
214
|
+
untrustedCount++;
|
|
215
|
+
untrustedRingEndorsements += group.untrustedSubjectInRing ? Math.max(0, untrustedCount - 1) : untrustedCount;
|
|
74
216
|
}
|
|
75
|
-
const endorsements =
|
|
76
|
-
const
|
|
77
|
-
//
|
|
217
|
+
const endorsements = trustedEndorsers.size;
|
|
218
|
+
const untrustedEndorsements = untrustedEndorsers.size;
|
|
219
|
+
// 7. Score from trusted counts only: endorsements + ring endorsements weighted higher
|
|
78
220
|
const score = endorsements + (ringEndorsements * 3);
|
|
79
|
-
//
|
|
80
|
-
const entry = {
|
|
81
|
-
|
|
82
|
-
|
|
221
|
+
// 8. Cache result and return
|
|
222
|
+
const entry = {
|
|
223
|
+
score, endorsements, ringEndorsements, untrustedEndorsements, untrustedRingEndorsements,
|
|
224
|
+
};
|
|
225
|
+
this.cache.set(cacheKey, entry);
|
|
226
|
+
return { pubkey, ...entry, flags };
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* A ring proof counts when its exact circle is configured, its publisher is
|
|
230
|
+
* a trusted publisher, or every member is in the caller's follows. A
|
|
231
|
+
* fraction of trusted members is not enough: an attacker inside an otherwise
|
|
232
|
+
* trusted ring can sign, and the proof cannot tell them apart.
|
|
233
|
+
*/
|
|
234
|
+
isTrustedRing(event, members, follows) {
|
|
235
|
+
if (this.trustedCircles.has(computeCircleId(members)))
|
|
236
|
+
return true;
|
|
237
|
+
if (this.trustedPublishers.has(event.pubkey))
|
|
238
|
+
return true;
|
|
239
|
+
return members.length > 0 && members.every(m => follows.has(m));
|
|
83
240
|
}
|
|
84
241
|
async scoreEvents(events) {
|
|
85
242
|
// 1. Get unique authors
|
package/dist/workflow/tools.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface WorkflowDeps {
|
|
|
9
9
|
nip65: Nip65Manager;
|
|
10
10
|
veilCacheTtl: number;
|
|
11
11
|
veilCacheMax: number;
|
|
12
|
+
veilTrustedCircles?: string[];
|
|
13
|
+
veilTrustedPublishers?: string[];
|
|
12
14
|
trust?: TrustContext;
|
|
13
15
|
}
|
|
14
16
|
export declare function registerWorkflowTools(server: McpServer, deps: WorkflowDeps): void;
|
package/dist/workflow/tools.js
CHANGED
|
@@ -8,6 +8,13 @@ import { handleTrustScore, handleFeedDiscover, handleVerifyPerson, handleIdentit
|
|
|
8
8
|
export function registerWorkflowTools(server, deps) {
|
|
9
9
|
// Shared trust cache — persists across calls within a session
|
|
10
10
|
const trustCache = new TrustCache({ ttl: deps.veilCacheTtl, maxEntries: deps.veilCacheMax });
|
|
11
|
+
const veilScoringOptions = {
|
|
12
|
+
trustedCircles: deps.veilTrustedCircles,
|
|
13
|
+
trustedPublishers: deps.veilTrustedPublishers,
|
|
14
|
+
followsTtl: deps.veilCacheTtl,
|
|
15
|
+
};
|
|
16
|
+
// One instance per registration, so the follow list is fetched once per TTL.
|
|
17
|
+
const scoring = new VeilScoring(deps.pool, trustCache, deps.ctx, veilScoringOptions);
|
|
11
18
|
server.registerTool('trust-score', {
|
|
12
19
|
description: 'Compute a trust score for a Nostr identity using the web-of-trust graph and kind 31000 attestations. Accepts any identifier: name, NIP-05, npub, or hex pubkey.',
|
|
13
20
|
inputSchema: {
|
|
@@ -17,7 +24,6 @@ export function registerWorkflowTools(server, deps) {
|
|
|
17
24
|
annotations: { readOnlyHint: true },
|
|
18
25
|
}, async ({ pubkey, depth }) => {
|
|
19
26
|
const resolved = await resolveRecipient(pubkey);
|
|
20
|
-
const scoring = new VeilScoring(deps.pool, trustCache, deps.ctx.activeNpub);
|
|
21
27
|
const result = await handleTrustScore(deps.ctx, deps.pool, scoring, { pubkey: resolved.pubkeyHex, depth }, deps.trust);
|
|
22
28
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
23
29
|
});
|
|
@@ -30,7 +36,6 @@ export function registerWorkflowTools(server, deps) {
|
|
|
30
36
|
},
|
|
31
37
|
annotations: { readOnlyHint: true },
|
|
32
38
|
}, async ({ strategy, limit, query }) => {
|
|
33
|
-
const scoring = new VeilScoring(deps.pool, trustCache, deps.ctx.activeNpub);
|
|
34
39
|
const result = await handleFeedDiscover(deps.ctx, deps.pool, scoring, { strategy, limit, query }, deps.trust);
|
|
35
40
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
36
41
|
});
|
|
@@ -43,7 +48,6 @@ export function registerWorkflowTools(server, deps) {
|
|
|
43
48
|
annotations: { readOnlyHint: true },
|
|
44
49
|
}, async ({ pubkey, method }) => {
|
|
45
50
|
const resolved = await resolveRecipient(pubkey);
|
|
46
|
-
const scoring = new VeilScoring(deps.pool, trustCache, deps.ctx.activeNpub);
|
|
47
51
|
const result = await handleVerifyPerson(deps.ctx, deps.pool, scoring, { pubkey: resolved.pubkeyHex, method }, deps.trust);
|
|
48
52
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
49
53
|
});
|
package/llms-full.txt
CHANGED
|
@@ -35,6 +35,8 @@ Single-process MCP server (stdio or HTTP transport) with 261 tools in 29 groups.
|
|
|
35
35
|
| DISPATCH_IDENTITIES | No | Path to dispatch identities markdown file. The dispatch tools are registered only when this is set |
|
|
36
36
|
| BRAY_HTTP_TOKEN | No | Bearer token the HTTP transport requires. If unset, a random token is generated and printed once on stderr |
|
|
37
37
|
| TRUST_MODE | No | "strict", "annotate" (default) or "off" |
|
|
38
|
+
| VEIL_TRUSTED_CIRCLES | No | Comma-separated circle IDs (64 lowercase hex) whose Veil ring proofs count towards trust scores |
|
|
39
|
+
| VEIL_TRUSTED_PUBLISHERS | No | Comma-separated npubs or hex whose Veil assertions and ring proofs count towards trust scores |
|
|
38
40
|
|
|
39
41
|
*Authentication tiers (use exactly one):
|
|
40
42
|
1. **Bunker** (NIP-46) -- most secure, keys never leave the signer
|
|
@@ -171,13 +173,13 @@ Look up a contact's full profile by name -- no pubkey needed.
|
|
|
171
173
|
|
|
172
174
|
#### social-notifications
|
|
173
175
|
Fetch notifications -- mentions, replies, reactions, zap receipts.
|
|
174
|
-
- Input: since (optional timestamp), limit (default 50), trust ("strict" | "annotate" | "off", default "
|
|
175
|
-
- Smart default: trust: "strict" hides notifications from
|
|
176
|
+
- Input: since (optional timestamp), limit (default 50), trust ("strict" | "annotate" | "off", default: the configured trustMode, "annotate" unless set), output
|
|
177
|
+
- Smart default: trust: "strict" hides notifications from authors with no trusted endorsement (follows and trusted publishers pass)
|
|
176
178
|
|
|
177
179
|
#### social-feed
|
|
178
180
|
Fetch kind 1 text note feed.
|
|
179
|
-
- Input: authors (optional hex pubkeys), since (optional), limit (default 20), trust ("strict" | "annotate" | "off", default "
|
|
180
|
-
- Smart default: trust: "strict" hides posts from
|
|
181
|
+
- Input: authors (optional hex pubkeys), since (optional), limit (default 20), trust ("strict" | "annotate" | "off", default: the configured trustMode, "annotate" unless set), output
|
|
182
|
+
- Smart default: trust: "strict" hides posts from authors with no trusted endorsement (follows and trusted publishers pass)
|
|
181
183
|
|
|
182
184
|
#### feed-by-name
|
|
183
185
|
Fetch recent posts by a contact, searching by name instead of pubkey.
|
|
@@ -1174,7 +1176,7 @@ Execute an action found via search-actions.
|
|
|
1174
1176
|
|
|
1175
1177
|
## Smart Defaults
|
|
1176
1178
|
|
|
1177
|
-
- **Trust-filtered feeds**: social-feed and social-notifications default
|
|
1179
|
+
- **Trust-filtered feeds**: social-feed and social-notifications follow the configured `trustMode` (default "annotate"). Set `trust: "strict"` to hide content from authors with no trusted endorsement, "off" to disable.
|
|
1178
1180
|
- **Contact safety guards**: contacts-follow/unfollow detect >20% list shrinkage (data corruption sign) and warn.
|
|
1179
1181
|
- **DM trust scores**: dm-read annotates each message with `senderTrustScore`.
|
|
1180
1182
|
- **Reply trust warnings**: social-reply computes `authorTrustScore` and warns about untrusted authors.
|
package/llms.txt
CHANGED
|
@@ -136,7 +136,7 @@ search-actions, execute-action
|
|
|
136
136
|
|
|
137
137
|
## Smart defaults
|
|
138
138
|
|
|
139
|
-
- **Trust filtering**: social-feed and social-notifications default
|
|
139
|
+
- **Trust filtering**: social-feed and social-notifications follow the configured `trustMode` (default `annotate`). In `strict`, authors you follow or trust as publishers pass; others need an endorsement from someone you trust.
|
|
140
140
|
- **Contact safety guards**: contacts-follow/unfollow check for >20% list shrinkage and return a warning.
|
|
141
141
|
- **DM trust annotation**: dm-read includes `senderTrustScore` for each message.
|
|
142
142
|
- **Reply trust warnings**: social-reply includes `trustWarning` when replying to untrusted authors.
|
|
@@ -146,7 +146,7 @@ search-actions, execute-action
|
|
|
146
146
|
## Key concepts
|
|
147
147
|
|
|
148
148
|
- **Signing tiers**: Heartwood signing appliance (best) > NIP-46 bunker > ncryptsec > key file > env var (worst). Heartwood adds nsec-tree derivation, per-client permissions, and device-backed attestations.
|
|
149
|
-
- **Trust mode**: the `trustMode` config value (or `TRUST_MODE` env var) is `strict`, `annotate` or `off`, and defaults to `annotate`. The per-call `trust` argument on social-feed and social-notifications takes the same values and defaults to `
|
|
149
|
+
- **Trust mode**: the `trustMode` config value (or `TRUST_MODE` env var) is `strict`, `annotate` or `off`, and defaults to `annotate`. The per-call `trust` argument on social-feed and social-notifications takes the same values and defaults to the configured `trustMode`.
|
|
150
150
|
- **Active identity**: All tools operate as the currently active identity. Use identity-switch to change.
|
|
151
151
|
- **Master/derived**: The master key derives child identities via nsec-tree. Children can be zeroised independently.
|
|
152
152
|
- **NIP-65 relay chasing**: When messaging someone, bray fetches their NIP-65 relay list and writes to their preferred relays.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nostr-bray",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"mcpName": "dev.forgesworn/bray",
|
|
5
5
|
"description": "Trust-aware Nostr MCP server, CLI and TypeScript SDK for AI agents and humans. Three dimensions of trust -- verification, proximity, and access -- woven into every interaction.",
|
|
6
6
|
"type": "module",
|