nostr-veil 0.8.4 → 0.12.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.
package/README.md CHANGED
@@ -3,28 +3,41 @@
3
3
  [![CI](https://github.com/forgesworn/nostr-veil/actions/workflows/ci.yml/badge.svg)](https://github.com/forgesworn/nostr-veil/actions/workflows/ci.yml)
4
4
  [![npm](https://img.shields.io/npm/v/nostr-veil)](https://www.npmjs.com/package/nostr-veil)
5
5
  [![licence: MIT](https://img.shields.io/badge/licence-MIT-blue.svg)](./LICENCE)
6
+ [![GitHub Sponsors](https://img.shields.io/github/sponsors/TheCryptoDonkey?logo=githubsponsors&color=ea4aaa&label=Sponsor)](https://github.com/sponsors/TheCryptoDonkey)
6
7
 
7
8
  **Trust scores you can verify without seeing who contributed them.**
8
9
 
9
- Anonymous trust assertions for Nostr. LSAG ring signatures over NIP-85 events so endorsements are verifiable but contributors are unidentifiable.
10
+ A privacy layer for Nostr reputation systems. A group of people can collectively score someone's trustworthiness, and anyone can verify the result -- but nobody can tell which group members actually contributed. Built for abuse reporting, whistleblowing, journalism, and anonymous peer review.
10
11
 
11
- **Who is this for?** Nostr client developers building trust systems where contributor privacy matters -- abuse reporting, whistleblowing, journalism, anonymous peer review. If your users can't afford to be identified when vouching for someone, this is the library.
12
+ ---
13
+
14
+ ## Key concepts
15
+
16
+ If you're new to this space, here's what the jargon means:
17
+
18
+ | Term | Plain English |
19
+ |------|--------------|
20
+ | **Web of Trust (WoT)** | Instead of a central authority deciding who's trustworthy, people vouch for each other. Your reputation is built from the opinions of people who know you. |
21
+ | **NIP-85** | A [Nostr standard](https://github.com/nostr-protocol/nips/blob/master/85.md) for publishing trust scores (e.g. "this person has 800 followers and a rank of 74"). Think of it as a shared format for reputation data. |
22
+ | **Ring signature** | A cryptographic technique where someone signs a message on behalf of a group. A verifier can confirm "someone in this group signed this" but cannot tell who. Like a sealed ballot -- you can count the votes but not trace them. |
23
+ | **LSAG** | Linkable Spontaneous Anonymous Group signature -- a specific type of ring signature that also detects duplicates. If the same person tries to vote twice, the system catches it, without revealing who they are. |
24
+ | **Trust circle** | The group of people who collectively produce a trust score. Each member contributes anonymously; the results are combined (median by default). |
12
25
 
13
26
  ---
14
27
 
15
- ## The Trust Trilemma
28
+ ## The trust trilemma
16
29
 
17
- Today's NIP-85 trust scores ask you to pick two:
30
+ Today's Nostr trust scores (NIP-85) ask you to pick two:
18
31
 
19
- | Property | NIP-85 today | nostr-veil |
32
+ | Property | Standard NIP-85 | With nostr-veil |
20
33
  |-------------|:---:|:---:|
21
34
  | Verifiable | ✓ | ✓ |
22
35
  | Private | ✗ | ✓ |
23
36
  | Portable | ✓ | ✓ |
24
37
 
25
- Anyone who can see the assertions can see exactly who judged you. That works fine for benign social signals. It fails completely the moment the subject matter is sensitive -- abuse reporting, whistleblowing, political dissent. The people who need Web of Trust most are the ones who cannot afford to be identified.
38
+ Anyone who can see the scores can see exactly who gave them. That works fine for benign social signals. It fails completely the moment the subject matter is sensitive -- abuse reporting, whistleblowing, political dissent. The people who need reputation systems most are the ones who cannot afford to be identified.
26
39
 
27
- nostr-veil solves all three. Assertions are standard NIP-85 events that any existing client can consume. Veil-aware clients can go further and verify the cryptographic proofs that back them.
40
+ nostr-veil solves all three. The output is a standard NIP-85 event that any existing Nostr app can display. Apps that understand nostr-veil can go further and verify the cryptographic proofs that back the scores.
28
41
 
29
42
  ---
30
43
 
@@ -38,13 +51,13 @@ graph TB
38
51
  end
39
52
 
40
53
  subgraph Veil["nostr-veil"]
41
- proof["nostr-veil/proof<br/>LSAG ring signatures<br/>anonymous contributions<br/>threshold aggregation"]
42
- nip85["nostr-veil/nip85<br/>Kind 30382–30385 assertions<br/>Kind 10040 providers<br/>builders · parsers · filters"]
54
+ proof["nostr-veil/proof<br/>Ring signatures<br/>Anonymous contributions<br/>Threshold aggregation"]
55
+ nip85["nostr-veil/nip85<br/>Trust score events<br/>Provider declarations<br/>Builders · Parsers · Filters"]
43
56
  end
44
57
 
45
58
  subgraph Crypto["Cryptographic Primitives"]
46
- ringsig["@forgesworn/ring-sig<br/>SAG / LSAG on secp256k1"]
47
- noble["@noble/curves + hashes<br/>Schnorr · SHA-256"]
59
+ ringsig["@forgesworn/ring-sig<br/>Ring signature engine"]
60
+ noble["@noble/curves + hashes<br/>Cryptographic primitives"]
48
61
  end
49
62
 
50
63
  subgraph Companions["Companion Libraries"]
@@ -126,10 +139,11 @@ The resulting `assertion` is a plain `EventTemplate` you sign and publish like a
126
139
 
127
140
  | Export | Description |
128
141
  |--------|-------------|
129
- | `createTrustCircle(memberPubkeys)` | Create a trust circle from an array of pubkeys |
130
- | `contributeAssertion(circle, subject, metrics, privateKey, memberIndex)` | Produce an anonymous `Contribution` using LSAG |
142
+ | `createTrustCircle(memberPubkeys, options?)` | Create a trust circle from an array of pubkeys; pass `{ scope }` to federate circles for [cross-circle deduplication](#cross-circle-deduplication) |
143
+ | `contributeAssertion(circle, subject, metrics, privateKey, memberIndex)` | Produce an anonymous ring-signed `Contribution` |
131
144
  | `aggregateContributions(circle, subject, contributions, options?)` | Aggregate contributions into a NIP-85 event with veil tags (default aggregation: median) |
132
- | `verifyProof(event)` | Verify all LSAG signatures and return a `ProofVerification` |
145
+ | `verifyProof(event, options?)` | Verify ring signatures, threshold metadata, and signed metric aggregation |
146
+ | `verifyFederation(events, options?)` | Verify several scoped events together and count distinct contributors across circles ([cross-circle deduplication](#cross-circle-deduplication)) |
133
147
  | `canonicalMessage(circleId, subject, metrics)` | Compute the canonical message signed by contributors |
134
148
  | `computeCircleId(sortedPubkeys)` | Compute the deterministic circle ID (SHA-256 of colon-joined pubkeys) |
135
149
 
@@ -144,22 +158,56 @@ The resulting `assertion` is a plain `EventTemplate` you sign and publish like a
144
158
 
145
159
  ## How it works
146
160
 
147
- Each member of a trust circle calls `contributeAssertion` independently. Under the hood this calls `lsagSign` from `@forgesworn/ring-sig`, which produces a Linkable Spontaneous Anonymous Group signature over the canonical message `{ circleId, subject, metrics }`.
161
+ Each member of a trust circle independently submits their scores. Under the hood, each submission is wrapped in a ring signature -- a cryptographic envelope that proves "a member of this group signed this" without revealing which member.
148
162
 
149
- The published NIP-85 event carries three extra tags:
163
+ The published event carries extra tags on top of the standard NIP-85 format:
150
164
 
151
- - `veil-ring` -- the full set of member pubkeys (the ring)
152
- - `veil-threshold` -- how many contributions were aggregated out of how many members
153
- - `veil-sig` (one per contribution) -- the serialised LSAG signature and key image
165
+ - `veil-ring` -- the full list of circle members (the group who could have contributed)
166
+ - `veil-threshold` -- how many members actually contributed vs. total circle size
167
+ - `veil-agg` -- which aggregate function produced the metric tags (median by default)
168
+ - `veil-sig` (one per contributor) -- the ring signature and a duplicate-detection token
169
+ - `veil-scope` -- present only for a federated circle; see [Cross-circle deduplication](#cross-circle-deduplication)
154
170
 
155
171
  A verifier calls `verifyProof`, which:
156
172
 
157
- 1. Reconstructs each LSAG signature against the ring
158
- 2. Confirms each signature is valid
159
- 3. Checks key images are distinct -- proving each signer contributed at most once (LSAG linkability property)
160
- 4. Confirms the number of valid, distinct signatures meets the threshold
173
+ 1. Checks each ring signature is valid (a real member signed it)
174
+ 2. Checks the duplicate-detection tokens are all different (nobody voted twice)
175
+ 3. Confirms the threshold metadata matches the ring and distinct signatures
176
+ 4. Confirms the published metric tags match the aggregate of the signed contributions
177
+
178
+ At no point does verification require knowing which member produced which signature. The group membership is public. The identities of the actual contributors are not.
179
+
180
+ By default, verification expects the same median aggregation used by `aggregateContributions`. If you pass a custom `aggregateFn` to `aggregateContributions`, pass the same function to `verifyProof`.
181
+
182
+ ---
183
+
184
+ ## Cross-circle deduplication
185
+
186
+ By default every trust circle is cryptographically isolated. A contributor's duplicate-detection token -- the LSAG key image -- is derived from the circle itself, so the same person contributing to two different circles produces two unrelated tokens. Nobody can tell the circles share a member.
187
+
188
+ That isolation is the right default, but it caps a trust score at one circle. To count honestly across a *federation* of circles all assessing the same subject, give them a shared `scope`:
189
+
190
+ ```ts
191
+ // Two community moderation circles, one federation
192
+ const circleA = createTrustCircle(membersA, { scope: 'community-moderators' })
193
+ const circleB = createTrustCircle(membersB, { scope: 'community-moderators' })
194
+ ```
195
+
196
+ Circles sharing a `scope` derive the key image from the scope rather than the circle, so a contributor who appears in several of them produces the *same* token in each. `verifyFederation` gathers events from across the federation, verifies each one, and counts the distinct contributors -- matched by key image, never by identity:
197
+
198
+ ```ts
199
+ import { verifyFederation } from 'nostr-veil'
200
+
201
+ // Aggregated events from every circle in the federation, all about the same subject
202
+ const result = verifyFederation([circleAEvent, circleBEvent, circleCEvent])
203
+ // { valid: true, scope: 'community-moderators', circleCount: 3,
204
+ // totalSignatures: 7, distinctSigners: 5, ... }
205
+ // distinctSigners < totalSignatures: two contributors signed in more than one circle
206
+ ```
207
+
208
+ A scoped event carries a `veil-scope` tag, which both `verifyProof` and `verifyFederation` read automatically. `verifyFederation` rejects the federation if the events disagree on subject or scope, or if any event is unscoped -- an isolated circle's key images cannot be matched across circles. Circles created without a `scope` behave exactly as before: no tag, fully isolated.
161
209
 
162
- At no point does verification require knowing which member produced which signature. The ring is public. The identities of the actual signers are not.
210
+ **Trade-off.** A shared scope is what enables cross-circle counting, and equally what makes cross-circle membership *overlap* observable: anyone collecting the events can see that one contributor signed in several circles, still without learning who. Use a `scope` when federated counting is worth that signal, and omit it otherwise.
163
211
 
164
212
  ---
165
213
 
@@ -167,9 +215,9 @@ At no point does verification require knowing which member produced which signat
167
215
 
168
216
  nostr-veil is one layer of a broader identity and trust stack:
169
217
 
170
- - [@forgesworn/ring-sig](https://github.com/forgesworn/ring-sig) -- LSAG ring signatures on secp256k1 (the cryptographic primitive)
171
- - [nsec-tree](https://github.com/forgesworn/nsec-tree) -- Deterministic sub-identity derivation (compartmentalised personas for trust circles)
172
- - [canary-kit](https://github.com/forgesworn/canary-kit) -- Coercion-resistant verification and duress detection
218
+ - [@forgesworn/ring-sig](https://github.com/forgesworn/ring-sig) -- The ring signature engine (the core cryptography)
219
+ - [nsec-tree](https://github.com/forgesworn/nsec-tree) -- Generate separate anonymous identities from a single master key
220
+ - [canary-kit](https://github.com/forgesworn/canary-kit) -- Detect when someone is being coerced (duress signals)
173
221
  - [signet](https://github.com/forgesworn/signet) -- Decentralised identity verification for Nostr
174
222
  - [dominion](https://github.com/forgesworn/dominion) -- Epoch-based encrypted content access control
175
223
 
@@ -192,7 +240,7 @@ Each project is independently maintained and published. nostr-veil focuses solel
192
240
  | Library | What it does |
193
241
  |---------|-------------|
194
242
  | [nsec-tree](https://github.com/forgesworn/nsec-tree) | Deterministic sub-identity derivation |
195
- | [ring-sig](https://github.com/forgesworn/ring-sig) | SAG/LSAG ring signatures on secp256k1 |
243
+ | [ring-sig](https://github.com/forgesworn/ring-sig) | Ring signature engine (core cryptography) |
196
244
  | [range-proof](https://github.com/forgesworn/range-proof) | Pedersen commitment range proofs |
197
245
  | [canary-kit](https://github.com/forgesworn/canary-kit) | Coercion-resistant spoken verification |
198
246
  | [spoken-token](https://github.com/forgesworn/spoken-token) | Human-speakable verification tokens |
@@ -1,23 +1,34 @@
1
1
  import type { EventTemplate } from '../nip85/types.js';
2
- import type { TrustCircle, Contribution, AggregateFn } from './types.js';
2
+ import type { TrustCircle, Contribution, AggregateFn, AggregateName } from './types.js';
3
+ /**
4
+ * Built-in named aggregate functions. The `veil-agg` tag records which one
5
+ * produced an event's metric tags, letting `verifyProof` recompute the
6
+ * aggregate without the function being supplied out-of-band.
7
+ */
8
+ export declare const AGGREGATES: Record<AggregateName, AggregateFn>;
9
+ /** True if `name` is a recognised built-in aggregate function. */
10
+ export declare function isAggregateName(name: string): name is AggregateName;
3
11
  /**
4
12
  * Aggregate multiple anonymous contributions into a single NIP-85 event.
5
13
  *
6
14
  * Validates all LSAG signatures and checks key image uniqueness before
7
15
  * aggregating metrics (default: median). The result is a standard NIP-85
8
- * event with additional `veil-ring`, `veil-threshold`, and `veil-sig` tags.
16
+ * event with additional `veil-ring`, `veil-threshold`, `veil-agg`, `veil-sig`,
17
+ * and -- for a circle with a federation scope -- `veil-scope` tags.
9
18
  *
10
19
  * @param circle - Trust circle the contributions belong to
11
20
  * @param subject - The d-tag value (must match what contributors signed)
12
21
  * @param contributions - Array of {@link Contribution} objects from circle members
13
22
  * @param options - Optional configuration
14
- * @param options.aggregateFn - Function to combine metric values (default: median). Receives an array of numbers, returns a single number.
23
+ * @param options.aggregate - Name of a built-in aggregate function: 'median' (default), 'mean', 'sum', 'min', or 'max'. Recorded in the `veil-agg` tag so verifiers can recompute the aggregate automatically.
24
+ * @param options.aggregateFn - A custom function to combine metric values. Recorded as `veil-agg: custom`; verifiers must be passed the same function. Prefer `aggregate` for the standard functions.
15
25
  * @param options.kind - NIP-85 assertion kind (default: 30382 USER). Use `NIP85_KINDS.EVENT` (30383), `NIP85_KINDS.ADDRESSABLE` (30384), or `NIP85_KINDS.IDENTIFIER` (30385) for other assertion types.
16
26
  * @returns An unsigned {@link EventTemplate} with proof tags — sign and publish as a standard Nostr event
17
- * @throws If any LSAG signature is invalid or duplicate key images are detected
27
+ * @throws If any LSAG signature is invalid, duplicate key images are detected, or an unknown aggregate name is supplied
18
28
  */
19
29
  export declare function aggregateContributions(circle: TrustCircle, subject: string, contributions: Contribution[], options?: AggregateFn | {
20
30
  aggregateFn?: AggregateFn;
31
+ aggregate?: AggregateName;
21
32
  kind?: number;
22
33
  }): EventTemplate;
23
34
  //# sourceMappingURL=aggregate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate.d.ts","sourceRoot":"","sources":["../../src/proof/aggregate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAkCxE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,YAAY,EAAE,EAC7B,OAAO,CAAC,EAAE,WAAW,GAAG;IAAE,WAAW,CAAC,EAAE,WAAW,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACnE,aAAa,CAqDf"}
1
+ {"version":3,"file":"aggregate.d.ts","sourceRoot":"","sources":["../../src/proof/aggregate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAWvF;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,WAAW,CAMzD,CAAA;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,aAAa,CAEnE;AA8BD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,YAAY,EAAE,EAC7B,OAAO,CAAC,EAAE,WAAW,GAAG;IAAE,WAAW,CAAC,EAAE,WAAW,CAAC;IAAC,SAAS,CAAC,EAAE,aAAa,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9F,aAAa,CA8Ff"}
@@ -1,5 +1,6 @@
1
1
  import { lsagVerify, hasDuplicateKeyImage } from '@forgesworn/ring-sig';
2
2
  import { NIP85_KINDS } from '../nip85/types.js';
3
+ import { canonicalMessage, computeCircleId, electionId } from './circle.js';
3
4
  function median(values) {
4
5
  const sorted = [...values].sort((a, b) => a - b);
5
6
  const mid = Math.floor(sorted.length / 2);
@@ -7,6 +8,22 @@ function median(values) {
7
8
  ? sorted[mid]
8
9
  : Math.round((sorted[mid - 1] + sorted[mid]) / 2);
9
10
  }
11
+ /**
12
+ * Built-in named aggregate functions. The `veil-agg` tag records which one
13
+ * produced an event's metric tags, letting `verifyProof` recompute the
14
+ * aggregate without the function being supplied out-of-band.
15
+ */
16
+ export const AGGREGATES = {
17
+ median,
18
+ mean: values => Math.round(values.reduce((a, b) => a + b, 0) / values.length),
19
+ sum: values => values.reduce((a, b) => a + b, 0),
20
+ min: values => Math.min(...values),
21
+ max: values => Math.max(...values),
22
+ };
23
+ /** True if `name` is a recognised built-in aggregate function. */
24
+ export function isAggregateName(name) {
25
+ return Object.prototype.hasOwnProperty.call(AGGREGATES, name);
26
+ }
10
27
  function serialiseSig(sig) {
11
28
  // Deterministic sorted-key serialisation. The `ring` and `keyImage` fields
12
29
  // are excluded — ring is in the veil-ring tag, keyImage is the third element
@@ -31,32 +48,75 @@ function serialiseSig(sig) {
31
48
  return sorted;
32
49
  });
33
50
  }
51
+ function sameStringArray(a, b) {
52
+ return a.length === b.length && a.every((value, index) => value === b[index]);
53
+ }
34
54
  /**
35
55
  * Aggregate multiple anonymous contributions into a single NIP-85 event.
36
56
  *
37
57
  * Validates all LSAG signatures and checks key image uniqueness before
38
58
  * aggregating metrics (default: median). The result is a standard NIP-85
39
- * event with additional `veil-ring`, `veil-threshold`, and `veil-sig` tags.
59
+ * event with additional `veil-ring`, `veil-threshold`, `veil-agg`, `veil-sig`,
60
+ * and -- for a circle with a federation scope -- `veil-scope` tags.
40
61
  *
41
62
  * @param circle - Trust circle the contributions belong to
42
63
  * @param subject - The d-tag value (must match what contributors signed)
43
64
  * @param contributions - Array of {@link Contribution} objects from circle members
44
65
  * @param options - Optional configuration
45
- * @param options.aggregateFn - Function to combine metric values (default: median). Receives an array of numbers, returns a single number.
66
+ * @param options.aggregate - Name of a built-in aggregate function: 'median' (default), 'mean', 'sum', 'min', or 'max'. Recorded in the `veil-agg` tag so verifiers can recompute the aggregate automatically.
67
+ * @param options.aggregateFn - A custom function to combine metric values. Recorded as `veil-agg: custom`; verifiers must be passed the same function. Prefer `aggregate` for the standard functions.
46
68
  * @param options.kind - NIP-85 assertion kind (default: 30382 USER). Use `NIP85_KINDS.EVENT` (30383), `NIP85_KINDS.ADDRESSABLE` (30384), or `NIP85_KINDS.IDENTIFIER` (30385) for other assertion types.
47
69
  * @returns An unsigned {@link EventTemplate} with proof tags — sign and publish as a standard Nostr event
48
- * @throws If any LSAG signature is invalid or duplicate key images are detected
70
+ * @throws If any LSAG signature is invalid, duplicate key images are detected, or an unknown aggregate name is supplied
49
71
  */
50
72
  export function aggregateContributions(circle, subject, contributions, options) {
51
- const aggregateFn = typeof options === 'function'
52
- ? options
53
- : options?.aggregateFn ?? median;
73
+ let aggregateFn;
74
+ let aggName;
75
+ if (typeof options === 'function') {
76
+ aggregateFn = options;
77
+ aggName = 'custom';
78
+ }
79
+ else if (options?.aggregate !== undefined) {
80
+ if (!isAggregateName(options.aggregate)) {
81
+ throw new Error(`Unknown aggregate function: ${options.aggregate}`);
82
+ }
83
+ aggregateFn = AGGREGATES[options.aggregate];
84
+ aggName = options.aggregate;
85
+ }
86
+ else if (options?.aggregateFn !== undefined) {
87
+ aggregateFn = options.aggregateFn;
88
+ aggName = 'custom';
89
+ }
90
+ else {
91
+ aggregateFn = median;
92
+ aggName = 'median';
93
+ }
54
94
  const kind = typeof options === 'object' && options !== null && 'kind' in options
55
95
  ? options.kind ?? NIP85_KINDS.USER
56
96
  : NIP85_KINDS.USER;
97
+ if (circle.size !== circle.members.length) {
98
+ throw new Error(`Trust circle size mismatch: size=${circle.size}, members=${circle.members.length}`);
99
+ }
100
+ if (circle.circleId !== computeCircleId(circle.members)) {
101
+ throw new Error('Trust circle circleId does not match its members');
102
+ }
103
+ const expectedElectionId = electionId(circle.scope ?? circle.circleId, subject);
57
104
  // Validate all signatures
58
105
  for (let i = 0; i < contributions.length; i++) {
59
- if (!lsagVerify(contributions[i].signature)) {
106
+ const contribution = contributions[i];
107
+ if (contribution.keyImage !== contribution.signature.keyImage) {
108
+ throw new Error(`Detached key image does not match signature at contribution index ${i}`);
109
+ }
110
+ if (!sameStringArray(contribution.signature.ring, circle.members)) {
111
+ throw new Error(`Signature ring does not match trust circle at contribution index ${i}`);
112
+ }
113
+ if (contribution.signature.electionId !== expectedElectionId) {
114
+ throw new Error(`Signature electionId does not match trust circle subject at contribution index ${i}`);
115
+ }
116
+ if (contribution.signature.message !== canonicalMessage(circle.circleId, subject, contribution.metrics)) {
117
+ throw new Error(`Signature signed message does not match contribution metrics at contribution index ${i}`);
118
+ }
119
+ if (!lsagVerify(contribution.signature)) {
60
120
  throw new Error(`Invalid LSAG signature at contribution index ${i}`);
61
121
  }
62
122
  }
@@ -85,17 +145,20 @@ export function aggregateContributions(circle, subject, contributions, options)
85
145
  }
86
146
  const metricTags = Object.entries(aggregatedMetrics).map(([k, v]) => [k, String(v)]);
87
147
  const sigTags = contributions.map(c => ['veil-sig', serialiseSig(c.signature), c.keyImage]);
88
- return {
89
- kind,
90
- tags: [
91
- ['d', subject],
92
- ['p', subject],
93
- ...metricTags,
94
- ['veil-ring', ...circle.members],
95
- ['veil-threshold', String(contributions.length), String(circle.size)],
96
- ...sigTags,
97
- ],
98
- content: '',
99
- };
148
+ const tags = [
149
+ ['d', subject],
150
+ ['p', subject],
151
+ ...metricTags,
152
+ ['veil-ring', ...circle.members],
153
+ ['veil-threshold', String(contributions.length), String(circle.size)],
154
+ ['veil-agg', aggName],
155
+ ];
156
+ // Only a scoped circle emits veil-scope: unscoped events stay byte-identical
157
+ // to pre-veil-scope output, and verifyProof treats an absent tag as circle-scoped.
158
+ if (circle.scope !== undefined) {
159
+ tags.push(['veil-scope', circle.scope]);
160
+ }
161
+ tags.push(...sigTags);
162
+ return { kind, tags, content: '' };
100
163
  }
101
164
  //# sourceMappingURL=aggregate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate.js","sourceRoot":"","sources":["../../src/proof/aggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,SAAS,MAAM,CAAC,MAAgB;IAC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AAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAA;IAErB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;AACpC,CAAC"}
@@ -1,4 +1,12 @@
1
1
  import type { TrustCircle } from './types.js';
2
+ /** Maximum length of a federation scope string (and of a `veil-scope` tag value). */
3
+ export declare const MAX_SCOPE_LENGTH = 128;
4
+ /**
5
+ * A valid federation scope: a non-empty lowercase slug. Enforced on both the
6
+ * build side ({@link createTrustCircle}) and the verify side, so a mistyped
7
+ * scope fails loudly instead of silently breaking cross-circle deduplication.
8
+ */
9
+ export declare const SCOPE_RE: RegExp;
2
10
  /**
3
11
  * Compute a deterministic circle ID by SHA-256 hashing the colon-joined sorted pubkeys.
4
12
  *
@@ -10,6 +18,21 @@ import type { TrustCircle } from './types.js';
10
18
  * // '3f4a2b…' (64-char hex string)
11
19
  */
12
20
  export declare function computeCircleId(sortedPubkeys: string[]): string;
21
+ /**
22
+ * Build the LSAG electionId that scopes a contributor's key image.
23
+ *
24
+ * An LSAG key image `I = x * H_p(P || electionId)` is identical for a given
25
+ * signer wherever the electionId matches. Passing a circle's `circleId` (the
26
+ * default) isolates every circle: the same person yields an unrelated key image
27
+ * in each. Passing a shared federation `scope` instead lets a set of circles
28
+ * recognise a contributor who appears in several of them, which is what makes
29
+ * cross-circle deduplication possible.
30
+ *
31
+ * @param scope - A circle's `scope` if it has one, otherwise its `circleId`
32
+ * @param subject - The d-tag value the contribution is about
33
+ * @returns The versioned electionId string `veil:v1:<scope>:<subject>`
34
+ */
35
+ export declare function electionId(scope: string, subject: string): string;
13
36
  /**
14
37
  * Produce the canonical JSON message that contributors sign with LSAG.
15
38
  *
@@ -37,14 +60,28 @@ export declare function canonicalMessage(circleId: string, subject: string, metr
37
60
  * appear exactly once; duplicates cause an immediate throw.
38
61
  *
39
62
  * @param memberPubkeys - Array of hex-encoded x-only public keys (64 chars each)
63
+ * @param options - Optional configuration
64
+ * @param options.scope - Federation scope for cross-circle deduplication. When set,
65
+ * every contribution's LSAG key image is scoped to this string rather than the
66
+ * `circleId`, so the same member yields a matching key image in any circle that
67
+ * shares the scope. Must be a lowercase slug ({@link SCOPE_RE}). Omit for the
68
+ * default per-circle isolation.
40
69
  * @returns A {@link TrustCircle} with a stable `members` order and a deterministic `circleId`
41
70
  *
42
71
  * @throws If fewer than 2 pubkeys are supplied
43
72
  * @throws If any pubkey appears more than once in the array
73
+ * @throws If `scope` is empty, longer than {@link MAX_SCOPE_LENGTH}, or not a lowercase slug
44
74
  *
45
75
  * @example
46
76
  * const circle = createTrustCircle([alicePubkey, bobPubkey, carolPubkey])
47
77
  * // { members: ['alice…', 'bob…', 'carol…'], circleId: '3f4a…', size: 3 }
78
+ *
79
+ * @example
80
+ * // Two circles whose shared contributors can be deduplicated:
81
+ * const a = createTrustCircle(membersA, { scope: 'community-moderators' })
82
+ * const b = createTrustCircle(membersB, { scope: 'community-moderators' })
48
83
  */
49
- export declare function createTrustCircle(memberPubkeys: string[]): TrustCircle;
84
+ export declare function createTrustCircle(memberPubkeys: string[], options?: {
85
+ scope?: string;
86
+ }): TrustCircle;
50
87
  //# sourceMappingURL=circle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"circle.d.ts","sourceRoot":"","sources":["../../src/proof/circle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,CAG/D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,MAAM,CAwBR;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,WAAW,CAiBtE"}
1
+ {"version":3,"file":"circle.d.ts","sourceRoot":"","sources":["../../src/proof/circle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,qFAAqF;AACrF,eAAO,MAAM,gBAAgB,MAAM,CAAA;AAEnC;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAmB,CAAA;AAExC;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,CAG/D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,MAAM,CAwBR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3B,WAAW,CA8Bb"}
@@ -1,5 +1,13 @@
1
1
  import { sha256 } from '@noble/hashes/sha2.js';
2
2
  import { bytesToHex } from '@noble/hashes/utils.js';
3
+ /** Maximum length of a federation scope string (and of a `veil-scope` tag value). */
4
+ export const MAX_SCOPE_LENGTH = 128;
5
+ /**
6
+ * A valid federation scope: a non-empty lowercase slug. Enforced on both the
7
+ * build side ({@link createTrustCircle}) and the verify side, so a mistyped
8
+ * scope fails loudly instead of silently breaking cross-circle deduplication.
9
+ */
10
+ export const SCOPE_RE = /^[a-z0-9._-]+$/;
3
11
  /**
4
12
  * Compute a deterministic circle ID by SHA-256 hashing the colon-joined sorted pubkeys.
5
13
  *
@@ -14,6 +22,23 @@ export function computeCircleId(sortedPubkeys) {
14
22
  const input = sortedPubkeys.join(':');
15
23
  return bytesToHex(sha256(new TextEncoder().encode(input)));
16
24
  }
25
+ /**
26
+ * Build the LSAG electionId that scopes a contributor's key image.
27
+ *
28
+ * An LSAG key image `I = x * H_p(P || electionId)` is identical for a given
29
+ * signer wherever the electionId matches. Passing a circle's `circleId` (the
30
+ * default) isolates every circle: the same person yields an unrelated key image
31
+ * in each. Passing a shared federation `scope` instead lets a set of circles
32
+ * recognise a contributor who appears in several of them, which is what makes
33
+ * cross-circle deduplication possible.
34
+ *
35
+ * @param scope - A circle's `scope` if it has one, otherwise its `circleId`
36
+ * @param subject - The d-tag value the contribution is about
37
+ * @returns The versioned electionId string `veil:v1:<scope>:<subject>`
38
+ */
39
+ export function electionId(scope, subject) {
40
+ return `veil:v1:${scope}:${subject}`;
41
+ }
17
42
  /**
18
43
  * Produce the canonical JSON message that contributors sign with LSAG.
19
44
  *
@@ -65,16 +90,28 @@ export function canonicalMessage(circleId, subject, metrics) {
65
90
  * appear exactly once; duplicates cause an immediate throw.
66
91
  *
67
92
  * @param memberPubkeys - Array of hex-encoded x-only public keys (64 chars each)
93
+ * @param options - Optional configuration
94
+ * @param options.scope - Federation scope for cross-circle deduplication. When set,
95
+ * every contribution's LSAG key image is scoped to this string rather than the
96
+ * `circleId`, so the same member yields a matching key image in any circle that
97
+ * shares the scope. Must be a lowercase slug ({@link SCOPE_RE}). Omit for the
98
+ * default per-circle isolation.
68
99
  * @returns A {@link TrustCircle} with a stable `members` order and a deterministic `circleId`
69
100
  *
70
101
  * @throws If fewer than 2 pubkeys are supplied
71
102
  * @throws If any pubkey appears more than once in the array
103
+ * @throws If `scope` is empty, longer than {@link MAX_SCOPE_LENGTH}, or not a lowercase slug
72
104
  *
73
105
  * @example
74
106
  * const circle = createTrustCircle([alicePubkey, bobPubkey, carolPubkey])
75
107
  * // { members: ['alice…', 'bob…', 'carol…'], circleId: '3f4a…', size: 3 }
108
+ *
109
+ * @example
110
+ * // Two circles whose shared contributors can be deduplicated:
111
+ * const a = createTrustCircle(membersA, { scope: 'community-moderators' })
112
+ * const b = createTrustCircle(membersB, { scope: 'community-moderators' })
76
113
  */
77
- export function createTrustCircle(memberPubkeys) {
114
+ export function createTrustCircle(memberPubkeys, options) {
78
115
  if (memberPubkeys.length < 2) {
79
116
  throw new Error('Trust circle requires at least 2 members');
80
117
  }
@@ -88,10 +125,23 @@ export function createTrustCircle(memberPubkeys) {
88
125
  throw new Error(`Duplicate pubkey in trust circle: ${pk}`);
89
126
  seen.add(pk);
90
127
  }
91
- return {
128
+ const circle = {
92
129
  members: sorted,
93
130
  circleId: computeCircleId(sorted),
94
131
  size: sorted.length,
95
132
  };
133
+ if (options?.scope !== undefined) {
134
+ if (typeof options.scope !== 'string' || options.scope.length === 0) {
135
+ throw new Error('Trust circle scope must be a non-empty string');
136
+ }
137
+ if (options.scope.length > MAX_SCOPE_LENGTH) {
138
+ throw new Error(`Trust circle scope exceeds maximum length (${MAX_SCOPE_LENGTH})`);
139
+ }
140
+ if (!SCOPE_RE.test(options.scope)) {
141
+ throw new Error('Trust circle scope must be a lowercase slug (a-z, 0-9, dot, hyphen, underscore)');
142
+ }
143
+ circle.scope = options.scope;
144
+ }
145
+ return circle;
96
146
  }
97
147
  //# sourceMappingURL=circle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"circle.js","sourceRoot":"","sources":["../../src/proof/circle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAGnD;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,aAAuB;IACrD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACrC,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA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,CAAC,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAClE,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,gBAAgB,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,8CAA8C,gBAAgB,GAAG,CAAC,CAAA;QACpF,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAA;QACpG,CAAC;QACD,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;IAC9B,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -3,7 +3,9 @@ import type { TrustCircle, Contribution } from './types.js';
3
3
  * Produce an anonymous contribution to a trust circle assertion.
4
4
  *
5
5
  * Signs the canonical message with an LSAG ring signature so the contributor's
6
- * identity is hidden within the ring. The key image prevents double-signing.
6
+ * identity is hidden within the ring. The key image prevents double-signing; if
7
+ * the circle has a `scope`, that key image is shared across every circle using
8
+ * the same scope, which is what enables cross-circle deduplication.
7
9
  *
8
10
  * @param circle - Trust circle created via {@link createTrustCircle}
9
11
  * @param subject - The d-tag value (hex pubkey for kind 30382)
@@ -1 +1 @@
1
- {"version":3,"file":"contribute.d.ts","sourceRoot":"","sources":["../../src/proof/contribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAG3D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB,YAAY,CAWd"}
1
+ {"version":3,"file":"contribute.d.ts","sourceRoot":"","sources":["../../src/proof/contribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAG3D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB,YAAY,CAWd"}
@@ -1,10 +1,12 @@
1
1
  import { lsagSign } from '@forgesworn/ring-sig';
2
- import { canonicalMessage } from './circle.js';
2
+ import { canonicalMessage, electionId } from './circle.js';
3
3
  /**
4
4
  * Produce an anonymous contribution to a trust circle assertion.
5
5
  *
6
6
  * Signs the canonical message with an LSAG ring signature so the contributor's
7
- * identity is hidden within the ring. The key image prevents double-signing.
7
+ * identity is hidden within the ring. The key image prevents double-signing; if
8
+ * the circle has a `scope`, that key image is shared across every circle using
9
+ * the same scope, which is what enables cross-circle deduplication.
8
10
  *
9
11
  * @param circle - Trust circle created via {@link createTrustCircle}
10
12
  * @param subject - The d-tag value (hex pubkey for kind 30382)
@@ -16,12 +18,12 @@ import { canonicalMessage } from './circle.js';
16
18
  */
17
19
  export function contributeAssertion(circle, subject, metrics, privateKey, memberIndex) {
18
20
  const message = canonicalMessage(circle.circleId, subject, metrics);
19
- const electionId = `veil:v1:${circle.circleId}:${subject}`;
20
- const signature = lsagSign(message, circle.members, memberIndex, privateKey, electionId);
21
+ const eid = electionId(circle.scope ?? circle.circleId, subject);
22
+ const signature = lsagSign(message, circle.members, memberIndex, privateKey, eid);
21
23
  return {
22
24
  signature,
23
25
  keyImage: signature.keyImage,
24
- metrics,
26
+ metrics: { ...metrics },
25
27
  };
26
28
  }
27
29
  //# sourceMappingURL=contribute.js.map