nostr-bray 3.10.0 → 3.10.1

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.
@@ -3,7 +3,7 @@ import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { generateSecretKey } from 'nostr-tools/pure';
5
5
  import { bytesToHex } from 'nostr-tools/utils';
6
- import { readStateFile, writeStateFile } from './state.js';
6
+ import { readStateFileStrict, writeStateFile } from './state.js';
7
7
  const NSEC_TREE_PROFILES_DIR = join(homedir(), '.nsec-tree', 'profiles');
8
8
  const BUNKER_KEYS_FILE = 'bunker-keys.json';
9
9
  /**
@@ -25,7 +25,12 @@ export function readNsecTreeProfileMnemonic(name, baseDir = NSEC_TREE_PROFILES_D
25
25
  * operator managing key files. Stored in bray's state dir.
26
26
  */
27
27
  export function getOrCreateBunkerKey(label, stateDir) {
28
- const keys = readStateFile(BUNKER_KEYS_FILE, stateDir);
28
+ // An unreadable file is not replaced: a new key would change the bunker://
29
+ // link and orphan every client approved under the old one.
30
+ const keys = readStateFileStrict(BUNKER_KEYS_FILE, stateDir);
31
+ if (keys === null) {
32
+ throw new Error(`${BUNKER_KEYS_FILE} in the bray state directory is unreadable; fix it or move it aside (a new key means a new bunker:// link and re-approving every client)`);
33
+ }
29
34
  const existing = keys[label];
30
35
  if (typeof existing === 'string' && /^[0-9a-f]{64}$/i.test(existing))
31
36
  return existing;
@@ -234,7 +234,7 @@ export async function dispatch(args) {
234
234
  process.exit(1);
235
235
  }
236
236
  const { getPublicKey } = await import('nostr-tools/pure');
237
- const { readStateFile, readStateFileStrict, writeStateFile } = await import('../../state.js');
237
+ const { readStateFileStrict, writeStateFile } = await import('../../state.js');
238
238
  let bunkerPk;
239
239
  let which;
240
240
  if (args.includes('--daemon-pubkey')) {
@@ -276,7 +276,11 @@ export async function dispatch(args) {
276
276
  const profile = opt('--profile');
277
277
  const label = persona ?? profile ?? 'default';
278
278
  const startHint = persona ? ` --persona ${persona}` : profile ? ` --profile ${profile}` : '';
279
- const keys = readStateFile('bunker-keys.json');
279
+ const keys = readStateFileStrict('bunker-keys.json');
280
+ if (keys === null) {
281
+ console.error('bunker authorize: bunker-keys.json in the bray state directory is unreadable; fix it or move it aside, then retry');
282
+ process.exit(1);
283
+ }
280
284
  const hex = keys[label];
281
285
  if (typeof hex !== 'string' || !/^[0-9a-f]{64}$/i.test(hex)) {
282
286
  console.error(`bunker authorize: no bunker daemon key for "${label}" yet. Start the daemon once (bray bunker${startHint}), or pass --daemon-pubkey <the daemon's pubkey>.`);
@@ -426,7 +430,13 @@ export async function dispatch(args) {
426
430
  else {
427
431
  // No explicit key: persist a STABLE one per identity so the bunker:// URI
428
432
  // survives restarts without the operator managing key files.
429
- bunkerKeyHex = getOrCreateBunkerKey(persona ?? profileName ?? 'default');
433
+ try {
434
+ bunkerKeyHex = getOrCreateBunkerKey(persona ?? profileName ?? 'default');
435
+ }
436
+ catch (err) {
437
+ console.error(`bunker: ${err.message}`);
438
+ process.exit(1);
439
+ }
430
440
  }
431
441
  const relays = config.relays.length > 0
432
442
  ? config.relays
@@ -34,8 +34,14 @@ export class VeilScoring {
34
34
  return { pubkey, ...entry, flags: ['no endorsements found'] };
35
35
  }
36
36
  const flags = [];
37
- let endorsements = 0;
38
- let ringEndorsements = 0;
37
+ // One endorsement per author, and one ring endorsement per key image: the
38
+ // same assertion or ring proof published several times counts once. This
39
+ // stops replays, not Sybils: a key image is per circle scope and subject,
40
+ // so one key that joins several circles (rings need no consent) still
41
+ // counts once per circle. Weighting rings by trusted circles would need an
42
+ // allowlist of circles or publishers.
43
+ const endorsers = new Set();
44
+ const ringKeyImages = new Set();
39
45
  // 4. Parse assertions and count endorsements
40
46
  for (const event of events) {
41
47
  // The relay may return anything; count only kind 30382 assertions about
@@ -45,13 +51,16 @@ export class VeilScoring {
45
51
  const parsed = parseAssertion(event);
46
52
  if (parsed.subject !== pubkey)
47
53
  continue;
48
- endorsements++;
54
+ endorsers.add(event.pubkey);
49
55
  // 5. Check for veil-sig tags and verify ring proofs
50
56
  const hasVeilSig = event.tags.some((t) => t[0] === 'veil-sig');
51
57
  if (hasVeilSig) {
52
58
  const verification = verifyProof(event, { expectedKind: 30382 });
53
59
  if (verification.valid) {
54
- ringEndorsements += verification.distinctSigners;
60
+ for (const tag of event.tags) {
61
+ if (tag[0] === 'veil-sig' && typeof tag[2] === 'string')
62
+ ringKeyImages.add(tag[2]);
63
+ }
55
64
  if (!flags.includes('ring proof verified')) {
56
65
  flags.push('ring proof verified');
57
66
  }
@@ -63,6 +72,8 @@ export class VeilScoring {
63
72
  }
64
73
  }
65
74
  }
75
+ const endorsements = endorsers.size;
76
+ const ringEndorsements = ringKeyImages.size;
66
77
  // 6. Compute score: endorsements + ring endorsements weighted higher
67
78
  const score = endorsements + (ringEndorsements * 3);
68
79
  // 7. Cache result and return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nostr-bray",
3
- "version": "3.10.0",
3
+ "version": "3.10.1",
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",