nostr-veil 0.1.0 → 0.2.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.
Files changed (57) hide show
  1. package/package.json +2 -2
  2. package/dist/_noble-compat.d.ts +0 -14
  3. package/dist/_noble-compat.d.ts.map +0 -1
  4. package/dist/_noble-compat.js +0 -18
  5. package/dist/_noble-compat.js.map +0 -1
  6. package/dist/duress/alert.d.ts +0 -18
  7. package/dist/duress/alert.d.ts.map +0 -1
  8. package/dist/duress/alert.js +0 -20
  9. package/dist/duress/alert.js.map +0 -1
  10. package/dist/duress/index.d.ts +0 -4
  11. package/dist/duress/index.d.ts.map +0 -1
  12. package/dist/duress/index.js +0 -4
  13. package/dist/duress/index.js.map +0 -1
  14. package/dist/duress/monitor.d.ts +0 -10
  15. package/dist/duress/monitor.d.ts.map +0 -1
  16. package/dist/duress/monitor.js +0 -73
  17. package/dist/duress/monitor.js.map +0 -1
  18. package/dist/duress/types.d.ts +0 -25
  19. package/dist/duress/types.d.ts.map +0 -1
  20. package/dist/duress/types.js +0 -2
  21. package/dist/duress/types.js.map +0 -1
  22. package/dist/identity/disclosure.d.ts +0 -34
  23. package/dist/identity/disclosure.d.ts.map +0 -1
  24. package/dist/identity/disclosure.js +0 -52
  25. package/dist/identity/disclosure.js.map +0 -1
  26. package/dist/identity/index.d.ts +0 -5
  27. package/dist/identity/index.d.ts.map +0 -1
  28. package/dist/identity/index.js +0 -5
  29. package/dist/identity/index.js.map +0 -1
  30. package/dist/identity/persona.d.ts +0 -22
  31. package/dist/identity/persona.d.ts.map +0 -1
  32. package/dist/identity/persona.js +0 -33
  33. package/dist/identity/persona.js.map +0 -1
  34. package/dist/identity/provider.d.ts +0 -23
  35. package/dist/identity/provider.d.ts.map +0 -1
  36. package/dist/identity/provider.js +0 -50
  37. package/dist/identity/provider.js.map +0 -1
  38. package/dist/identity/types.d.ts +0 -13
  39. package/dist/identity/types.d.ts.map +0 -1
  40. package/dist/identity/types.js +0 -2
  41. package/dist/identity/types.js.map +0 -1
  42. package/dist/scorer/graph.d.ts +0 -14
  43. package/dist/scorer/graph.d.ts.map +0 -1
  44. package/dist/scorer/graph.js +0 -71
  45. package/dist/scorer/graph.js.map +0 -1
  46. package/dist/scorer/index.d.ts +0 -4
  47. package/dist/scorer/index.d.ts.map +0 -1
  48. package/dist/scorer/index.js +0 -4
  49. package/dist/scorer/index.js.map +0 -1
  50. package/dist/scorer/rank.d.ts +0 -15
  51. package/dist/scorer/rank.d.ts.map +0 -1
  52. package/dist/scorer/rank.js +0 -40
  53. package/dist/scorer/rank.js.map +0 -1
  54. package/dist/scorer/types.d.ts +0 -30
  55. package/dist/scorer/types.d.ts.map +0 -1
  56. package/dist/scorer/types.js +0 -2
  57. package/dist/scorer/types.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nostr-veil",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Anonymous trust assertions for Nostr. LSAG ring-signature-backed NIP-85 endorsements where contributors are verifiable but unidentifiable.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -88,4 +88,4 @@
88
88
  "typescript": "^5.7.0",
89
89
  "vitest": "^3.0.0"
90
90
  }
91
- }
91
+ }
@@ -1,14 +0,0 @@
1
- type HexOrBytes = string | Uint8Array;
2
- export declare const schnorr: {
3
- getPublicKey: (privKey: HexOrBytes) => Uint8Array<ArrayBufferLike>;
4
- sign: (msg: HexOrBytes, privKey: HexOrBytes) => Uint8Array<ArrayBufferLike>;
5
- verify: (sig: HexOrBytes, msg: HexOrBytes, pubKey: HexOrBytes) => boolean;
6
- utils: {
7
- randomSecretKey: (seed?: Uint8Array) => Uint8Array;
8
- pointToBytes: (point: import("@noble/curves/abstract/weierstrass.js").WeierstrassPoint<bigint>) => Uint8Array;
9
- lift_x: (x: bigint) => import("@noble/curves/abstract/weierstrass.js").WeierstrassPoint<bigint>;
10
- taggedHash: (tag: string, ...messages: Uint8Array[]) => Uint8Array;
11
- };
12
- };
13
- export { secp256k1 } from '@noble/curves/secp256k1.js';
14
- //# sourceMappingURL=_noble-compat.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_noble-compat.d.ts","sourceRoot":"","sources":["../src/_noble-compat.ts"],"names":[],"mappings":"AAQA,KAAK,UAAU,GAAG,MAAM,GAAG,UAAU,CAAA;AAMrC,eAAO,MAAM,OAAO;4BACM,UAAU;gBACtB,UAAU,WAAW,UAAU;kBAC7B,UAAU,OAAO,UAAU,UAAU,UAAU;;8BAM4qC,CAAC;;;;;CAH3uC,CAAA;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA"}
@@ -1,18 +0,0 @@
1
- /**
2
- * Compatibility shim for @noble/curves/secp256k1 — noble v2 requires Uint8Array
3
- * but Nostr tooling conventionally passes hex strings to schnorr functions.
4
- * This shim re-exports schnorr with hex-string support for the signing layer.
5
- */
6
- import { schnorr as _schnorr } from '@noble/curves/secp256k1.js';
7
- import { hexToBytes } from '@noble/hashes/utils.js';
8
- function coerce(v) {
9
- return typeof v === 'string' ? hexToBytes(v) : v;
10
- }
11
- export const schnorr = {
12
- getPublicKey: (privKey) => _schnorr.getPublicKey(coerce(privKey)),
13
- sign: (msg, privKey) => _schnorr.sign(coerce(msg), coerce(privKey)),
14
- verify: (sig, msg, pubKey) => _schnorr.verify(coerce(sig), coerce(msg), coerce(pubKey)),
15
- utils: _schnorr.utils,
16
- };
17
- export { secp256k1 } from '@noble/curves/secp256k1.js';
18
- //# sourceMappingURL=_noble-compat.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_noble-compat.js","sourceRoot":"","sources":["../src/_noble-compat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAInD,SAAS,MAAM,CAAC,CAAa;IAC3B,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAClD,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,YAAY,EAAE,CAAC,OAAmB,EAAE,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7E,IAAI,EAAE,CAAC,GAAe,EAAE,OAAmB,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3F,MAAM,EAAE,CAAC,GAAe,EAAE,GAAe,EAAE,MAAkB,EAAE,EAAE,CAC/D,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3D,KAAK,EAAE,QAAQ,CAAC,KAAK;CACtB,CAAA;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA"}
@@ -1,18 +0,0 @@
1
- export { decryptDuressAlert } from 'canary-kit/beacon';
2
- /**
3
- * Propagate a duress alert for a group member.
4
- *
5
- * Derives an AES-256 key from the group seed, builds a duress alert payload,
6
- * and encrypts it with AES-256-GCM. Returns the encrypted base64 string
7
- * ready for Nostr event content.
8
- *
9
- * @param memberPubkey - 64-character lowercase hex pubkey of the member under duress.
10
- * @param groupSeed - 64-character lowercase hex group seed (32 bytes).
11
- * @param location - Optional geohash location with precision, or null/undefined.
12
- * @returns Encrypted base64 string.
13
- */
14
- export declare function propagateDuressAlert(memberPubkey: string, groupSeed: string, location?: {
15
- geohash: string;
16
- precision: number;
17
- } | null): Promise<string>;
18
- //# sourceMappingURL=alert.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"alert.d.ts","sourceRoot":"","sources":["../../src/duress/alert.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GACvD,OAAO,CAAC,MAAM,CAAC,CAOjB"}
@@ -1,20 +0,0 @@
1
- import { deriveDuressKey, buildDuressAlert, encryptDuressAlert, } from 'canary-kit/beacon';
2
- export { decryptDuressAlert } from 'canary-kit/beacon';
3
- /**
4
- * Propagate a duress alert for a group member.
5
- *
6
- * Derives an AES-256 key from the group seed, builds a duress alert payload,
7
- * and encrypts it with AES-256-GCM. Returns the encrypted base64 string
8
- * ready for Nostr event content.
9
- *
10
- * @param memberPubkey - 64-character lowercase hex pubkey of the member under duress.
11
- * @param groupSeed - 64-character lowercase hex group seed (32 bytes).
12
- * @param location - Optional geohash location with precision, or null/undefined.
13
- * @returns Encrypted base64 string.
14
- */
15
- export async function propagateDuressAlert(memberPubkey, groupSeed, location) {
16
- const key = deriveDuressKey(groupSeed);
17
- const alert = buildDuressAlert(memberPubkey, location ? { ...location, locationSource: 'beacon' } : null);
18
- return encryptDuressAlert(key, alert);
19
- }
20
- //# sourceMappingURL=alert.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"alert.js","sourceRoot":"","sources":["../../src/duress/alert.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,YAAoB,EACpB,SAAiB,EACjB,QAAwD;IAExD,MAAM,GAAG,GAAG,eAAe,CAAC,SAAS,CAAC,CAAA;IACtC,MAAM,KAAK,GAAG,gBAAgB,CAC5B,YAAY,EACZ,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,cAAc,EAAE,QAAiB,EAAE,CAAC,CAAC,CAAC,IAAI,CACrE,CAAA;IACD,OAAO,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AACvC,CAAC"}
@@ -1,4 +0,0 @@
1
- export * from './types.js';
2
- export * from './monitor.js';
3
- export * from './alert.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/duress/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
@@ -1,4 +0,0 @@
1
- export * from './types.js';
2
- export * from './monitor.js';
3
- export * from './alert.js';
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/duress/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
@@ -1,10 +0,0 @@
1
- import type { DuressMonitor, DuressMonitorOptions } from './types.js';
2
- /**
3
- * Create a timer-based duress monitor.
4
- *
5
- * Tracks heartbeats per member pubkey. When a member fails to check in
6
- * within `toleranceMs`, a duress event is emitted. Pure state machine --
7
- * no relay interaction.
8
- */
9
- export declare function createDuressMonitor(options: DuressMonitorOptions): DuressMonitor;
10
- //# sourceMappingURL=monitor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"monitor.d.ts","sourceRoot":"","sources":["../../src/duress/monitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,aAAa,EACb,oBAAoB,EAErB,MAAM,YAAY,CAAA;AAOnB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAkEhF"}
@@ -1,73 +0,0 @@
1
- /**
2
- * Create a timer-based duress monitor.
3
- *
4
- * Tracks heartbeats per member pubkey. When a member fails to check in
5
- * within `toleranceMs`, a duress event is emitted. Pure state machine --
6
- * no relay interaction.
7
- */
8
- export function createDuressMonitor(options) {
9
- const { toleranceMs } = options;
10
- const members = new Map();
11
- const handlers = [];
12
- let running = false;
13
- function emit(event) {
14
- for (const handler of handlers)
15
- handler(event);
16
- }
17
- function scheduleTimeout(pubkey, lastSeen) {
18
- return setTimeout(() => {
19
- const now = Date.now();
20
- const elapsed = now - lastSeen;
21
- const level = elapsed >= toleranceMs * 2 ? 'critical' : 'warning';
22
- emit({
23
- type: 'heartbeat-missed',
24
- pubkey,
25
- lastSeen,
26
- elapsed,
27
- level,
28
- });
29
- }, toleranceMs);
30
- }
31
- return {
32
- heartbeat(pubkey) {
33
- if (!running)
34
- return;
35
- const now = Date.now();
36
- const existing = members.get(pubkey);
37
- if (existing)
38
- clearTimeout(existing.timeout);
39
- members.set(pubkey, {
40
- lastSeen: now,
41
- timeout: scheduleTimeout(pubkey, now),
42
- });
43
- },
44
- start() {
45
- running = true;
46
- },
47
- stop() {
48
- running = false;
49
- for (const entry of members.values()) {
50
- clearTimeout(entry.timeout);
51
- }
52
- members.clear();
53
- },
54
- on(_event, handler) {
55
- handlers.push(handler);
56
- },
57
- getState() {
58
- const now = Date.now();
59
- const state = new Map();
60
- for (const [pubkey, entry] of members) {
61
- const elapsed = now - entry.lastSeen;
62
- let status = 'active';
63
- if (elapsed >= toleranceMs * 2)
64
- status = 'critical';
65
- else if (elapsed >= toleranceMs)
66
- status = 'warning';
67
- state.set(pubkey, { pubkey, lastSeen: entry.lastSeen, status });
68
- }
69
- return state;
70
- },
71
- };
72
- }
73
- //# sourceMappingURL=monitor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"monitor.js","sourceRoot":"","sources":["../../src/duress/monitor.ts"],"names":[],"mappings":"AAYA;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;IAC/B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC9C,MAAM,QAAQ,GAAoC,EAAE,CAAA;IACpD,IAAI,OAAO,GAAG,KAAK,CAAA;IAEnB,SAAS,IAAI,CAAC,KAAkB;QAC9B,KAAK,MAAM,OAAO,IAAI,QAAQ;YAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAChD,CAAC;IAED,SAAS,eAAe,CAAC,MAAc,EAAE,QAAgB;QACvD,OAAO,UAAU,CAAC,GAAG,EAAE;YACrB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YACtB,MAAM,OAAO,GAAG,GAAG,GAAG,QAAQ,CAAA;YAC9B,MAAM,KAAK,GAAG,OAAO,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAA;YACjE,IAAI,CAAC;gBACH,IAAI,EAAE,kBAAkB;gBACxB,MAAM;gBACN,QAAQ;gBACR,OAAO;gBACP,KAAK;aACN,CAAC,CAAA;QACJ,CAAC,EAAE,WAAW,CAAC,CAAA;IACjB,CAAC;IAED,OAAO;QACL,SAAS,CAAC,MAAc;YACtB,IAAI,CAAC,OAAO;gBAAE,OAAM;YACpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YACtB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YACpC,IAAI,QAAQ;gBAAE,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;YAC5C,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE;gBAClB,QAAQ,EAAE,GAAG;gBACb,OAAO,EAAE,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC;aACtC,CAAC,CAAA;QACJ,CAAC;QAED,KAAK;YACH,OAAO,GAAG,IAAI,CAAA;QAChB,CAAC;QAED,IAAI;YACF,OAAO,GAAG,KAAK,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;gBACrC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;YAC7B,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;QACjB,CAAC;QAED,EAAE,CAAC,MAAgB,EAAE,OAAiC;YACpD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACxB,CAAC;QAED,QAAQ;YACN,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YACtB,MAAM,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAA;YAC/C,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;gBACtC,MAAM,OAAO,GAAG,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAA;gBACpC,IAAI,MAAM,GAA6B,QAAQ,CAAA;gBAC/C,IAAI,OAAO,IAAI,WAAW,GAAG,CAAC;oBAAE,MAAM,GAAG,UAAU,CAAA;qBAC9C,IAAI,OAAO,IAAI,WAAW;oBAAE,MAAM,GAAG,SAAS,CAAA;gBACnD,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAA;YACjE,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -1,25 +0,0 @@
1
- export type AlertLevel = 'warning' | 'critical';
2
- export interface HeartbeatState {
3
- pubkey: string;
4
- lastSeen: number;
5
- status: 'active' | 'warning' | 'critical';
6
- }
7
- export interface DuressEvent {
8
- type: 'heartbeat-missed';
9
- pubkey: string;
10
- lastSeen: number;
11
- elapsed: number;
12
- level: AlertLevel;
13
- }
14
- export interface DuressMonitor {
15
- heartbeat(pubkey: string): void;
16
- start(): void;
17
- stop(): void;
18
- on(event: 'duress', handler: (e: DuressEvent) => void): void;
19
- getState(): Map<string, HeartbeatState>;
20
- }
21
- export interface DuressMonitorOptions {
22
- toleranceMs: number;
23
- checkIntervalMs: number;
24
- }
25
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/duress/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,CAAA;AAE/C,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAA;CAC1C;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,kBAAkB,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,KAAK,IAAI,IAAI,CAAA;IACb,IAAI,IAAI,IAAI,CAAA;IACZ,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,IAAI,GAAG,IAAI,CAAA;IAC5D,QAAQ,IAAI,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;CACxC;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;CACxB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/duress/types.ts"],"names":[],"mappings":""}
@@ -1,34 +0,0 @@
1
- import type { TreeRoot, Identity } from 'nsec-tree';
2
- import type { DisclosureProofs } from './types.js';
3
- import type { EventTemplate } from '../nip85/types.js';
4
- /**
5
- * Prove two identities share a common master key.
6
- *
7
- * @param root - The TreeRoot from which both identities were derived
8
- * @param identityA - First identity (e.g. anonymous persona)
9
- * @param identityB - Second identity (e.g. public journalist key)
10
- * @param mode - `'blind'` (default) hides the derivation path; `'full'` reveals purpose and index
11
- * @returns A pair of {@link LinkageProof} objects — one per identity. A verifier checks both share the same `masterPubkey`.
12
- */
13
- export declare function proveCommonOwnership(root: TreeRoot, identityA: Identity, identityB: Identity, mode?: 'blind' | 'full'): DisclosureProofs;
14
- /**
15
- * Build a kind 30078 event containing linkage proofs for two related identities.
16
- *
17
- * The event embeds a `veil-linkage-a` tag and a `veil-linkage-b` tag, each
18
- * carrying the child pubkey, attestation, and Schnorr signature from the
19
- * corresponding {@link LinkageProof}. A `veil-master` tag contains the shared
20
- * master pubkey that proves both identities belong to the same root key. The
21
- * `d` tag is derived from a SHA-256 hash of the master pubkey, making the
22
- * event addressable without leaking it in plaintext.
23
- *
24
- * @param proofs - A pair of {@link LinkageProof} objects from {@link proveCommonOwnership}
25
- * @returns An unsigned {@link EventTemplate} of kind 30078 ready to sign and publish
26
- *
27
- * @example
28
- * const proofs = proveCommonOwnership(root, personaIdentity, journalistIdentity)
29
- * const tmpl = buildDisclosureEvent(proofs)
30
- * const event = signEvent(tmpl, masterPrivkey)
31
- * await relay.publish(event)
32
- */
33
- export declare function buildDisclosureEvent(proofs: DisclosureProofs): EventTemplate;
34
- //# sourceMappingURL=disclosure.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"disclosure.d.ts","sourceRoot":"","sources":["../../src/identity/disclosure.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAgB,MAAM,WAAW,CAAA;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,QAAQ,EACd,SAAS,EAAE,QAAQ,EACnB,SAAS,EAAE,QAAQ,EACnB,IAAI,GAAE,OAAO,GAAG,MAAgB,GAC/B,gBAAgB,CAGlB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,aAAa,CAgB5E"}
@@ -1,52 +0,0 @@
1
- import { createBlindProof, createFullProof } from 'nsec-tree/proof';
2
- import { sha256 } from '@noble/hashes/sha2.js';
3
- import { bytesToHex } from '@noble/hashes/utils.js';
4
- /**
5
- * Prove two identities share a common master key.
6
- *
7
- * @param root - The TreeRoot from which both identities were derived
8
- * @param identityA - First identity (e.g. anonymous persona)
9
- * @param identityB - Second identity (e.g. public journalist key)
10
- * @param mode - `'blind'` (default) hides the derivation path; `'full'` reveals purpose and index
11
- * @returns A pair of {@link LinkageProof} objects — one per identity. A verifier checks both share the same `masterPubkey`.
12
- */
13
- export function proveCommonOwnership(root, identityA, identityB, mode = 'blind') {
14
- const proveFn = mode === 'blind' ? createBlindProof : createFullProof;
15
- return [proveFn(root, identityA), proveFn(root, identityB)];
16
- }
17
- /**
18
- * Build a kind 30078 event containing linkage proofs for two related identities.
19
- *
20
- * The event embeds a `veil-linkage-a` tag and a `veil-linkage-b` tag, each
21
- * carrying the child pubkey, attestation, and Schnorr signature from the
22
- * corresponding {@link LinkageProof}. A `veil-master` tag contains the shared
23
- * master pubkey that proves both identities belong to the same root key. The
24
- * `d` tag is derived from a SHA-256 hash of the master pubkey, making the
25
- * event addressable without leaking it in plaintext.
26
- *
27
- * @param proofs - A pair of {@link LinkageProof} objects from {@link proveCommonOwnership}
28
- * @returns An unsigned {@link EventTemplate} of kind 30078 ready to sign and publish
29
- *
30
- * @example
31
- * const proofs = proveCommonOwnership(root, personaIdentity, journalistIdentity)
32
- * const tmpl = buildDisclosureEvent(proofs)
33
- * const event = signEvent(tmpl, masterPrivkey)
34
- * await relay.publish(event)
35
- */
36
- export function buildDisclosureEvent(proofs) {
37
- const [proofA, proofB] = proofs;
38
- const dTagHash = bytesToHex(sha256(new TextEncoder().encode(proofA.masterPubkey)));
39
- return {
40
- kind: 30078,
41
- tags: [
42
- ['d', `veil:disclosure:${dTagHash}`],
43
- ['veil-linkage-a', proofA.childPubkey, proofA.attestation, proofA.signature,
44
- ...(proofA.purpose !== undefined ? [proofA.purpose, String(proofA.index)] : [])],
45
- ['veil-linkage-b', proofB.childPubkey, proofB.attestation, proofB.signature,
46
- ...(proofB.purpose !== undefined ? [proofB.purpose, String(proofB.index)] : [])],
47
- ['veil-master', proofA.masterPubkey],
48
- ],
49
- content: '',
50
- };
51
- }
52
- //# sourceMappingURL=disclosure.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"disclosure.js","sourceRoot":"","sources":["../../src/identity/disclosure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAKnD;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAc,EACd,SAAmB,EACnB,SAAmB,EACnB,OAAyB,OAAO;IAEhC,MAAM,OAAO,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,eAAe,CAAA;IACrE,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAA;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAwB;IAC3D,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;IAC/B,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAElF,OAAO;QACL,IAAI,EAAE,KAAK;QACX,IAAI,EAAE;YACJ,CAAC,GAAG,EAAE,mBAAmB,QAAQ,EAAE,CAAC;YACpC,CAAC,gBAAgB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS;gBACzE,GAAG,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAClF,CAAC,gBAAgB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS;gBACzE,GAAG,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAClF,CAAC,aAAa,EAAE,MAAM,CAAC,YAAY,CAAC;SACrC;QACD,OAAO,EAAE,EAAE;KACZ,CAAA;AACH,CAAC"}
@@ -1,5 +0,0 @@
1
- export * from './types.js';
2
- export * from './provider.js';
3
- export * from './persona.js';
4
- export * from './disclosure.js';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA"}
@@ -1,5 +0,0 @@
1
- export * from './types.js';
2
- export * from './provider.js';
3
- export * from './persona.js';
4
- export * from './disclosure.js';
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA"}
@@ -1,22 +0,0 @@
1
- import type { PersonaHandle } from './types.js';
2
- /**
3
- * Derive a named persona from a master nsec using nsec-tree.
4
- *
5
- * The derived persona has its own independent keypair, suitable for anonymous
6
- * participation in trust circles without exposing the master identity. The
7
- * persona can later be linked back to the master key via
8
- * {@link proveCommonOwnership} if selective disclosure is needed.
9
- *
10
- * Call `.destroy()` on the returned handle when done to zeroise all key material.
11
- *
12
- * @param rootNsec - Bech32-encoded master nsec (`nsec1…`) used as the derivation root
13
- * @param name - Human-readable persona name used as the derivation path (e.g. `'whistleblower'`)
14
- * @returns A {@link PersonaHandle} containing the derived `Persona` and a `destroy` method
15
- *
16
- * @example
17
- * const handle = createUserPersona(masterNsec, 'whistleblower')
18
- * const anonPubkey = handle.persona.identity.pubkey
19
- * handle.destroy()
20
- */
21
- export declare function createUserPersona(rootNsec: string, name: string): PersonaHandle;
22
- //# sourceMappingURL=persona.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"persona.d.ts","sourceRoot":"","sources":["../../src/identity/persona.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAU/E"}
@@ -1,33 +0,0 @@
1
- import { fromNsec, zeroise } from 'nsec-tree/core';
2
- import { derivePersona } from 'nsec-tree/persona';
3
- /**
4
- * Derive a named persona from a master nsec using nsec-tree.
5
- *
6
- * The derived persona has its own independent keypair, suitable for anonymous
7
- * participation in trust circles without exposing the master identity. The
8
- * persona can later be linked back to the master key via
9
- * {@link proveCommonOwnership} if selective disclosure is needed.
10
- *
11
- * Call `.destroy()` on the returned handle when done to zeroise all key material.
12
- *
13
- * @param rootNsec - Bech32-encoded master nsec (`nsec1…`) used as the derivation root
14
- * @param name - Human-readable persona name used as the derivation path (e.g. `'whistleblower'`)
15
- * @returns A {@link PersonaHandle} containing the derived `Persona` and a `destroy` method
16
- *
17
- * @example
18
- * const handle = createUserPersona(masterNsec, 'whistleblower')
19
- * const anonPubkey = handle.persona.identity.pubkey
20
- * handle.destroy()
21
- */
22
- export function createUserPersona(rootNsec, name) {
23
- const root = fromNsec(rootNsec);
24
- const persona = derivePersona(root, name);
25
- return {
26
- persona,
27
- destroy() {
28
- zeroise(persona.identity);
29
- root.destroy();
30
- },
31
- };
32
- }
33
- //# sourceMappingURL=persona.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"persona.js","sourceRoot":"","sources":["../../src/identity/persona.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAgB,EAAE,IAAY;IAC9D,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAC/B,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IACzC,OAAO;QACL,OAAO;QACP,OAAO;YACL,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YACzB,IAAI,CAAC,OAAO,EAAE,CAAA;QAChB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -1,23 +0,0 @@
1
- import type { ProviderTree } from './types.js';
2
- /**
3
- * Derive per-algorithm provider identities from a master nsec.
4
- *
5
- * Uses nsec-tree to derive a separate child identity for each algorithm name,
6
- * keeping algorithm-specific signing keys isolated from the master key. Each
7
- * derived identity has a corresponding kind 0 metadata template pre-populated
8
- * with a descriptive name and about text.
9
- *
10
- * Call `.destroy()` on the returned handle when done to zeroise all key material.
11
- *
12
- * @param rootNsec - Bech32-encoded master nsec (`nsec1…`) used as the derivation root
13
- * @param algorithms - Algorithm names to derive identities for (e.g. `['lsag-median', 'lsag-mean']`)
14
- * @returns A {@link ProviderTree} containing the derived identity map, metadata templates, and a `destroy` method
15
- *
16
- * @example
17
- * const tree = createProviderTree(masterNsec, ['lsag-median'])
18
- * const providerIdentity = tree.algorithms.get('lsag-median')!
19
- * // publish tree.metadataTemplates.get('lsag-median') as the provider's kind 0
20
- * tree.destroy()
21
- */
22
- export declare function createProviderTree(rootNsec: string, algorithms: string[]): ProviderTree;
23
- //# sourceMappingURL=provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/identity/provider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,YAAY,CA6BvF"}
@@ -1,50 +0,0 @@
1
- import { fromNsec, derive, zeroise } from 'nsec-tree/core';
2
- /**
3
- * Derive per-algorithm provider identities from a master nsec.
4
- *
5
- * Uses nsec-tree to derive a separate child identity for each algorithm name,
6
- * keeping algorithm-specific signing keys isolated from the master key. Each
7
- * derived identity has a corresponding kind 0 metadata template pre-populated
8
- * with a descriptive name and about text.
9
- *
10
- * Call `.destroy()` on the returned handle when done to zeroise all key material.
11
- *
12
- * @param rootNsec - Bech32-encoded master nsec (`nsec1…`) used as the derivation root
13
- * @param algorithms - Algorithm names to derive identities for (e.g. `['lsag-median', 'lsag-mean']`)
14
- * @returns A {@link ProviderTree} containing the derived identity map, metadata templates, and a `destroy` method
15
- *
16
- * @example
17
- * const tree = createProviderTree(masterNsec, ['lsag-median'])
18
- * const providerIdentity = tree.algorithms.get('lsag-median')!
19
- * // publish tree.metadataTemplates.get('lsag-median') as the provider's kind 0
20
- * tree.destroy()
21
- */
22
- export function createProviderTree(rootNsec, algorithms) {
23
- const root = fromNsec(rootNsec);
24
- const algorithmMap = new Map();
25
- const metadataMap = new Map();
26
- for (const algo of algorithms) {
27
- const identity = derive(root, `veil:provider:${algo}`, 0);
28
- algorithmMap.set(algo, identity);
29
- metadataMap.set(algo, {
30
- kind: 0,
31
- tags: [],
32
- content: JSON.stringify({
33
- name: `Veil Provider: ${algo}`,
34
- about: `NIP-85 trust assertion provider — ${algo} algorithm. Part of the nostr-veil privacy-preserving Web of Trust.`,
35
- }),
36
- });
37
- }
38
- return {
39
- algorithms: algorithmMap,
40
- metadataTemplates: metadataMap,
41
- destroy() {
42
- for (const identity of algorithmMap.values())
43
- zeroise(identity);
44
- algorithmMap.clear();
45
- metadataMap.clear();
46
- root.destroy();
47
- },
48
- };
49
- }
50
- //# sourceMappingURL=provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/identity/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAK1D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB,EAAE,UAAoB;IACvE,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAC/B,MAAM,YAAY,GAAG,IAAI,GAAG,EAAoB,CAAA;IAChD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAyB,CAAA;IAEpD,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,iBAAiB,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA;QACzD,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QAEhC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE;YACpB,IAAI,EAAE,CAAC;YACP,IAAI,EAAE,EAAE;YACR,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;gBACtB,IAAI,EAAE,kBAAkB,IAAI,EAAE;gBAC9B,KAAK,EAAE,qCAAqC,IAAI,qEAAqE;aACtH,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;IAED,OAAO;QACL,UAAU,EAAE,YAAY;QACxB,iBAAiB,EAAE,WAAW;QAC9B,OAAO;YACL,KAAK,MAAM,QAAQ,IAAI,YAAY,CAAC,MAAM,EAAE;gBAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;YAC/D,YAAY,CAAC,KAAK,EAAE,CAAA;YACpB,WAAW,CAAC,KAAK,EAAE,CAAA;YACnB,IAAI,CAAC,OAAO,EAAE,CAAA;QAChB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -1,13 +0,0 @@
1
- import type { Identity, Persona, LinkageProof } from 'nsec-tree';
2
- import type { EventTemplate } from '../nip85/types.js';
3
- export interface ProviderTree {
4
- algorithms: Map<string, Identity>;
5
- metadataTemplates: Map<string, EventTemplate>;
6
- destroy(): void;
7
- }
8
- export interface PersonaHandle {
9
- persona: Persona;
10
- destroy(): void;
11
- }
12
- export type DisclosureProofs = [LinkageProof, LinkageProof];
13
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/identity/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACjC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC7C,OAAO,IAAI,IAAI,CAAA;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,IAAI,IAAI,CAAA;CAChB;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/identity/types.ts"],"names":[],"mappings":""}
@@ -1,14 +0,0 @@
1
- import type { EventTemplate } from '../nip85/types.js';
2
- import type { TrustGraph } from './types.js';
3
- /**
4
- * Builds a trust graph from an array of NIP-85 assertion events.
5
- *
6
- * Each unique subject (d-tag value) becomes a node. Each event becomes an edge.
7
- * Events carrying a `veil-ring` tag are treated as anonymous ring endorsements.
8
- * Metrics are aggregated on each node (last value wins per metric key).
9
- *
10
- * @param events - Array of unsigned NIP-85 assertion events
11
- * @returns A {@link TrustGraph} with nodes keyed by subject pubkey and all edges
12
- */
13
- export declare function buildTrustGraph(events: EventTemplate[]): TrustGraph;
14
- //# sourceMappingURL=graph.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/scorer/graph.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAwB,MAAM,YAAY,CAAA;AAElE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,UAAU,CAkEnE"}
@@ -1,71 +0,0 @@
1
- import { parseAssertion } from '../nip85/parsers.js';
2
- /**
3
- * Builds a trust graph from an array of NIP-85 assertion events.
4
- *
5
- * Each unique subject (d-tag value) becomes a node. Each event becomes an edge.
6
- * Events carrying a `veil-ring` tag are treated as anonymous ring endorsements.
7
- * Metrics are aggregated on each node (last value wins per metric key).
8
- *
9
- * @param events - Array of unsigned NIP-85 assertion events
10
- * @returns A {@link TrustGraph} with nodes keyed by subject pubkey and all edges
11
- */
12
- export function buildTrustGraph(events) {
13
- const nodes = new Map();
14
- const edges = [];
15
- for (const event of events) {
16
- const parsed = parseAssertion(event);
17
- const subject = parsed.subject;
18
- if (subject === '')
19
- continue;
20
- const isRing = event.tags.some(t => t[0] === 'veil-ring');
21
- // Find the provider pubkey from the p-tag
22
- const pTag = event.tags.find(t => t[0] === 'p');
23
- const provider = pTag?.[1] ?? '';
24
- // Convert string metric values to numbers
25
- const numericMetrics = {};
26
- for (const [key, value] of Object.entries(parsed.metrics)) {
27
- const num = Number(value);
28
- if (!isNaN(num)) {
29
- numericMetrics[key] = num;
30
- }
31
- }
32
- // Create or update the node
33
- let node = nodes.get(subject);
34
- if (!node) {
35
- node = {
36
- pubkey: subject,
37
- metrics: {},
38
- endorsements: 0,
39
- ringEndorsements: 0,
40
- providers: [],
41
- };
42
- nodes.set(subject, node);
43
- }
44
- // Aggregate metrics (last value wins per key)
45
- for (const [key, value] of Object.entries(numericMetrics)) {
46
- node.metrics[key] = value;
47
- }
48
- // Count endorsements
49
- if (isRing) {
50
- node.ringEndorsements++;
51
- }
52
- else {
53
- node.endorsements++;
54
- }
55
- // Track unique providers
56
- if (provider !== '' && !node.providers.includes(provider)) {
57
- node.providers.push(provider);
58
- }
59
- // Create the edge
60
- const edge = {
61
- from: provider,
62
- to: subject,
63
- kind: event.kind,
64
- anonymous: isRing,
65
- metrics: numericMetrics,
66
- };
67
- edges.push(edge);
68
- }
69
- return { nodes, edges };
70
- }
71
- //# sourceMappingURL=graph.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/scorer/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAIpD;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB;IACrD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAqB,CAAA;IAC1C,MAAM,KAAK,GAAgB,EAAE,CAAA;IAE7B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;QACpC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;QAC9B,IAAI,OAAO,KAAK,EAAE;YAAE,SAAQ;QAE5B,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,CAAA;QAEzD,0CAA0C;QAC1C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAA;QAC/C,MAAM,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QAEhC,0CAA0C;QAC1C,MAAM,cAAc,GAA2B,EAAE,CAAA;QACjD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1D,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;YACzB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChB,cAAc,CAAC,GAAG,CAAC,GAAG,GAAG,CAAA;YAC3B,CAAC;QACH,CAAC;QAED,4BAA4B;QAC5B,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAC7B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,GAAG;gBACL,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,EAAE;gBACX,YAAY,EAAE,CAAC;gBACf,gBAAgB,EAAE,CAAC;gBACnB,SAAS,EAAE,EAAE;aACd,CAAA;YACD,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAC1B,CAAC;QAED,8CAA8C;QAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YAC1D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QAC3B,CAAC;QAED,qBAAqB;QACrB,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,gBAAgB,EAAE,CAAA;QACzB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,YAAY,EAAE,CAAA;QACrB,CAAC;QAED,yBAAyB;QACzB,IAAI,QAAQ,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC/B,CAAC;QAED,kBAAkB;QAClB,MAAM,IAAI,GAAc;YACtB,IAAI,EAAE,QAAQ;YACd,EAAE,EAAE,OAAO;YACX,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,SAAS,EAAE,MAAM;YACjB,OAAO,EAAE,cAAc;SACxB,CAAA;QACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAClB,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AACzB,CAAC"}
@@ -1,4 +0,0 @@
1
- export * from './types.js';
2
- export { buildTrustGraph } from './graph.js';
3
- export { computeTrustRank } from './rank.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scorer/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA"}
@@ -1,4 +0,0 @@
1
- export * from './types.js';
2
- export { buildTrustGraph } from './graph.js';
3
- export { computeTrustRank } from './rank.js';
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scorer/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA"}
@@ -1,15 +0,0 @@
1
- import type { TrustGraph, TrustRank } from './types.js';
2
- /**
3
- * Computes trust rankings from a trust graph.
4
- *
5
- * Ring endorsements are weighted 2x:
6
- * `score = endorsements + (ringEndorsements * 2)`
7
- *
8
- * Scores are normalised to a 0-100 scale against the theoretical maximum
9
- * for the graph (total edges, with each ring edge counting double).
10
- *
11
- * @param graph - A {@link TrustGraph} produced by `buildTrustGraph`
12
- * @returns An array of {@link TrustRank} entries sorted by rank descending
13
- */
14
- export declare function computeTrustRank(graph: TrustGraph): TrustRank[];
15
- //# sourceMappingURL=rank.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rank.d.ts","sourceRoot":"","sources":["../../src/scorer/rank.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEvD;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,EAAE,CA+B/D"}
@@ -1,40 +0,0 @@
1
- /**
2
- * Computes trust rankings from a trust graph.
3
- *
4
- * Ring endorsements are weighted 2x:
5
- * `score = endorsements + (ringEndorsements * 2)`
6
- *
7
- * Scores are normalised to a 0-100 scale against the theoretical maximum
8
- * for the graph (total edges, with each ring edge counting double).
9
- *
10
- * @param graph - A {@link TrustGraph} produced by `buildTrustGraph`
11
- * @returns An array of {@link TrustRank} entries sorted by rank descending
12
- */
13
- export function computeTrustRank(graph) {
14
- if (graph.nodes.size === 0)
15
- return [];
16
- // Calculate theoretical max: total edges with ring edges counting double
17
- let theoreticalMax = 0;
18
- for (const edge of graph.edges) {
19
- theoreticalMax += edge.anonymous ? 2 : 1;
20
- }
21
- // Avoid division by zero when there are nodes but no meaningful edges
22
- if (theoreticalMax === 0)
23
- theoreticalMax = 1;
24
- const ranks = [];
25
- for (const [pubkey, node] of graph.nodes) {
26
- const rawScore = node.endorsements + (node.ringEndorsements * 2);
27
- const rank = Math.round((rawScore / theoreticalMax) * 100);
28
- ranks.push({
29
- pubkey,
30
- rank,
31
- endorsements: node.endorsements,
32
- ringEndorsements: node.ringEndorsements,
33
- providers: node.providers.length,
34
- });
35
- }
36
- // Sort by rank descending, then by pubkey for stable ordering
37
- ranks.sort((a, b) => b.rank - a.rank || a.pubkey.localeCompare(b.pubkey));
38
- return ranks;
39
- }
40
- //# sourceMappingURL=rank.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rank.js","sourceRoot":"","sources":["../../src/scorer/rank.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAiB;IAChD,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IAErC,yEAAyE;IACzE,IAAI,cAAc,GAAG,CAAC,CAAA;IACtB,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC/B,cAAc,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC1C,CAAC;IAED,sEAAsE;IACtE,IAAI,cAAc,KAAK,CAAC;QAAE,cAAc,GAAG,CAAC,CAAA;IAE5C,MAAM,KAAK,GAAgB,EAAE,CAAA;IAE7B,KAAK,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,GAAG,CAAC,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAA;QAChE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,cAAc,CAAC,GAAG,GAAG,CAAC,CAAA;QAE1D,KAAK,CAAC,IAAI,CAAC;YACT,MAAM;YACN,IAAI;YACJ,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM;SACjC,CAAC,CAAA;IACJ,CAAC;IAED,8DAA8D;IAC9D,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAEzE,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -1,30 +0,0 @@
1
- /** A node in the trust graph representing a single subject (user, event, etc.) */
2
- export interface TrustNode {
3
- pubkey: string;
4
- metrics: Record<string, number>;
5
- endorsements: number;
6
- ringEndorsements: number;
7
- providers: string[];
8
- }
9
- /** A directed edge from a provider to a subject, carrying assertion metrics */
10
- export interface TrustEdge {
11
- from: string;
12
- to: string;
13
- kind: number;
14
- anonymous: boolean;
15
- metrics: Record<string, number>;
16
- }
17
- /** The full trust graph: nodes keyed by subject pubkey, plus all edges */
18
- export interface TrustGraph {
19
- nodes: Map<string, TrustNode>;
20
- edges: TrustEdge[];
21
- }
22
- /** A ranked entry for a single subject after trust scoring */
23
- export interface TrustRank {
24
- pubkey: string;
25
- rank: number;
26
- endorsements: number;
27
- ringEndorsements: number;
28
- providers: number;
29
- }
30
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/scorer/types.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,YAAY,EAAE,MAAM,CAAA;IACpB,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,+EAA+E;AAC/E,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC;AAED,0EAA0E;AAC1E,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC7B,KAAK,EAAE,SAAS,EAAE,CAAA;CACnB;AAED,8DAA8D;AAC9D,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;CAClB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/scorer/types.ts"],"names":[],"mappings":""}