nostr-veil 0.12.1 → 0.14.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 +86 -7
- package/dist/nip85/validators.d.ts +24 -1
- package/dist/nip85/validators.d.ts.map +1 -1
- package/dist/nip85/validators.js +235 -7
- package/dist/nip85/validators.js.map +1 -1
- package/dist/proof/aggregate.d.ts +41 -7
- package/dist/proof/aggregate.d.ts.map +1 -1
- package/dist/proof/aggregate.js +121 -23
- package/dist/proof/aggregate.js.map +1 -1
- package/dist/proof/circle.d.ts +16 -1
- package/dist/proof/circle.d.ts.map +1 -1
- package/dist/proof/circle.js +69 -20
- package/dist/proof/circle.js.map +1 -1
- package/dist/proof/contribute.d.ts +12 -2
- package/dist/proof/contribute.d.ts.map +1 -1
- package/dist/proof/contribute.js +41 -4
- package/dist/proof/contribute.js.map +1 -1
- package/dist/proof/types.d.ts +15 -0
- package/dist/proof/types.d.ts.map +1 -1
- package/dist/proof/verify.d.ts +28 -3
- package/dist/proof/verify.d.ts.map +1 -1
- package/dist/proof/verify.js +251 -70
- package/dist/proof/verify.js.map +1 -1
- package/llms-full.txt +72 -10
- package/llms.txt +17 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
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.
|
|
11
11
|
|
|
12
|
+
**New here?** The [**use-case overview**](https://veil.forgesworn.dev/use-cases/) covers what nostr-veil is, the problem it solves, and practical things you can build on it today.
|
|
13
|
+
|
|
12
14
|
---
|
|
13
15
|
|
|
14
16
|
## Key concepts
|
|
@@ -35,9 +37,9 @@ Today's Nostr trust scores (NIP-85) ask you to pick two:
|
|
|
35
37
|
| Private | ✗ | ✓ |
|
|
36
38
|
| Portable | ✓ | ✓ |
|
|
37
39
|
|
|
38
|
-
Anyone who can see
|
|
40
|
+
Anyone who can see an ordinary score can see who published it, and multi-party reputation usually creates a visible contributor graph. That works fine for benign social signals. It fails 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.
|
|
39
41
|
|
|
40
|
-
nostr-veil solves all three. The output is a standard NIP-85 event that
|
|
42
|
+
nostr-veil solves all three for group assertions. The output is a standard NIP-85 event that NIP-85-aware apps can display. Apps that understand nostr-veil can go further and verify the cryptographic proofs that back the scores.
|
|
41
43
|
|
|
42
44
|
---
|
|
43
45
|
|
|
@@ -130,7 +132,9 @@ The resulting `assertion` is a plain `EventTemplate` you sign and publish like a
|
|
|
130
132
|
| `buildProviderDeclaration(providers, encryptedContent?)` | Build a kind 10040 provider declaration |
|
|
131
133
|
| `parseAssertion(event)` | Parse a raw event into a `ParsedAssertion` |
|
|
132
134
|
| `parseProviderDeclaration(event, decryptFn?)` | Parse a kind 10040 provider declaration into `ParsedProvider[]` (supports optional NIP-44 decryption) |
|
|
133
|
-
| `validateAssertion(event)` | Validate a NIP-85 assertion --
|
|
135
|
+
| `validateAssertion(event, options?)` | Validate a NIP-85 assertion -- pass `{ strict: true }` for kind-specific metric checks and optional subject-hint validation |
|
|
136
|
+
| `validateAssertionStrict(event)` | Strict NIP-85 assertion validation shortcut |
|
|
137
|
+
| `validateProviderDeclarationStrict(event)` | Strict kind 10040 provider declaration validation for plaintext tags; encrypted declarations are accepted when tags are omitted |
|
|
134
138
|
| `assertionFilter({ kind, subject?, provider? })` | Build a relay query filter for assertions |
|
|
135
139
|
| `providerFilter(pubkey)` | Build a relay query filter for a provider declaration |
|
|
136
140
|
| `NIP85_KINDS` | Kind constants: `USER`, `EVENT`, `ADDRESSABLE`, `IDENTIFIER`, `PROVIDER` |
|
|
@@ -140,11 +144,18 @@ The resulting `assertion` is a plain `EventTemplate` you sign and publish like a
|
|
|
140
144
|
| Export | Description |
|
|
141
145
|
|--------|-------------|
|
|
142
146
|
| `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` |
|
|
144
|
-
| `
|
|
145
|
-
| `
|
|
147
|
+
| `contributeAssertion(circle, subject, metrics, privateKey, memberIndex, options?)` | Produce an anonymous ring-signed `Contribution`; v1 by default, v2 when `{ proofVersion: 'v2', kind, subjectTag, subjectTagValue }` is supplied |
|
|
148
|
+
| `contributeEventAssertion(circle, eventId, metrics, privateKey, memberIndex, options?)` | Produce a contribution for a kind 30383 event assertion |
|
|
149
|
+
| `contributeAddressableAssertion(circle, address, metrics, privateKey, memberIndex, options?)` | Produce a contribution for a kind 30384 addressable assertion |
|
|
150
|
+
| `contributeIdentifierAssertion(circle, identifier, kTag, metrics, privateKey, memberIndex, options?)` | Produce a contribution for a kind 30385 identifier assertion |
|
|
151
|
+
| `aggregateContributions(circle, subject, contributions, options?)` | Aggregate user-score contributions into a kind 30382 NIP-85 event with veil tags (default aggregation: median) |
|
|
152
|
+
| `aggregateEventContributions(circle, eventId, contributions, options?)` | Aggregate into a kind 30383 event assertion with `d`/`e` tags |
|
|
153
|
+
| `aggregateAddressableContributions(circle, address, contributions, options?)` | Aggregate into a kind 30384 addressable assertion with `d`/`a` tags |
|
|
154
|
+
| `aggregateIdentifierContributions(circle, identifier, kTag, contributions, options?)` | Aggregate into a kind 30385 identifier assertion with `d`/`k` tags |
|
|
155
|
+
| `verifyProof(event, options?)` | Verify ring signatures, threshold metadata, signed metric aggregation, and optional proof-version requirements |
|
|
146
156
|
| `verifyFederation(events, options?)` | Verify several scoped events together and count distinct contributors across circles ([cross-circle deduplication](#cross-circle-deduplication)) |
|
|
147
157
|
| `canonicalMessage(circleId, subject, metrics)` | Compute the canonical message signed by contributors |
|
|
158
|
+
| `canonicalMessageV2(circleId, subject, metrics, context)` | Compute the opt-in v2 canonical message that binds kind and subject hint tag |
|
|
148
159
|
| `computeCircleId(sortedPubkeys)` | Compute the deterministic circle ID (SHA-256 of colon-joined pubkeys) |
|
|
149
160
|
|
|
150
161
|
### Signing utility (root export)
|
|
@@ -166,6 +177,7 @@ The published event carries extra tags on top of the standard NIP-85 format:
|
|
|
166
177
|
- `veil-threshold` -- how many members actually contributed vs. total circle size
|
|
167
178
|
- `veil-agg` -- which aggregate function produced the metric tags (median by default)
|
|
168
179
|
- `veil-sig` (one per contributor) -- the ring signature and a duplicate-detection token
|
|
180
|
+
- `veil-version` -- present only for opt-in proof v2 events
|
|
169
181
|
- `veil-scope` -- present only for a federated circle; see [Cross-circle deduplication](#cross-circle-deduplication)
|
|
170
182
|
|
|
171
183
|
A verifier calls `verifyProof`, which:
|
|
@@ -175,10 +187,77 @@ A verifier calls `verifyProof`, which:
|
|
|
175
187
|
3. Confirms the threshold metadata matches the ring and distinct signatures
|
|
176
188
|
4. Confirms the published metric tags match the aggregate of the signed contributions
|
|
177
189
|
|
|
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.
|
|
190
|
+
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. The signed metric values are public inside the proof, so nostr-veil hides contributor identity, not the fact that an anonymous contributor submitted a particular score.
|
|
179
191
|
|
|
180
192
|
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
193
|
|
|
194
|
+
### Proof v2
|
|
195
|
+
|
|
196
|
+
The original proof format remains the default. It signs the circle ID, the `d`-tag subject, and numeric metrics, and it uses `veil:v1:<scope-or-circleId>:<subject>` as the LSAG election ID.
|
|
197
|
+
|
|
198
|
+
Proof v2 is additive and opt-in. It signs the same data plus the NIP-85 assertion kind and the subject hint tag/value (`p`, `e`, `a`, or `k`), and derives the key image from that semantic context. That prevents a valid contribution for one assertion class being replayed as another when a subject string is reused.
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
import { contributeEventAssertion, aggregateEventContributions, verifyProof } from 'nostr-veil'
|
|
202
|
+
|
|
203
|
+
const contribution = contributeEventAssertion(
|
|
204
|
+
circle,
|
|
205
|
+
eventId,
|
|
206
|
+
{ rank: 90 },
|
|
207
|
+
alicePrivkey,
|
|
208
|
+
circle.members.indexOf(alicePubkey),
|
|
209
|
+
{ proofVersion: 'v2' },
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
const assertion = aggregateEventContributions(circle, eventId, [contribution], { proofVersion: 'v2' })
|
|
213
|
+
const result = verifyProof(assertion, { requireProofVersion: 'v2' })
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Old v1 events still verify without changes. Use `requireProofVersion: 'v2'` only when your application policy wants to reject legacy proofs for that workflow.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Threat model
|
|
221
|
+
|
|
222
|
+
nostr-veil is a privacy layer for already-defined trust circles. It gives you:
|
|
223
|
+
|
|
224
|
+
- Anonymous membership proof: each contribution was signed by some member of the public ring, without revealing which member.
|
|
225
|
+
- Duplicate detection: one member cannot contribute twice within the same circle/scope and subject without reusing the same LSAG key image.
|
|
226
|
+
- Signed metric integrity: `verifyProof` checks the published metric tags against the aggregate of the signed contribution messages.
|
|
227
|
+
- Optional semantic binding: proof v2 binds the assertion kind and subject hint tag into the signed message and election ID.
|
|
228
|
+
- Standard NIP-85 output: non-veil clients can still read the aggregate score.
|
|
229
|
+
|
|
230
|
+
It does not claim to solve every trust problem by itself:
|
|
231
|
+
|
|
232
|
+
- It does not hide the circle membership list; the ring is public.
|
|
233
|
+
- It does not hide individual anonymous metric values; they are needed so anyone can recompute the aggregate.
|
|
234
|
+
- It does not hide network, timing, relay, or collector metadata.
|
|
235
|
+
- It does not decide whether the circle members are trustworthy, human, independent, or correctly selected.
|
|
236
|
+
- A shared federation `scope` intentionally reveals cross-circle overlap by key image, while still hiding the contributor's identity.
|
|
237
|
+
|
|
238
|
+
For sensitive deployments, combine nostr-veil with careful collection, transport privacy, key hygiene, and a clear policy for how circles are admitted and rotated.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Use cases
|
|
243
|
+
|
|
244
|
+
The shipped primitives support more than user trust scores:
|
|
245
|
+
|
|
246
|
+
- User reputation and abuse reporting with kind 30382 user assertions.
|
|
247
|
+
- Source corroboration and peer review where contributors need protection from retaliation.
|
|
248
|
+
- Event and claim verification with kind 30383 event assertions via `aggregateEventContributions`.
|
|
249
|
+
- Article, long-form note, or research review with kind 30384 addressable assertions via `aggregateAddressableContributions`.
|
|
250
|
+
- Relay, service, vendor, marketplace, or external identifier reputation with kind 30385 identifier assertions via `aggregateIdentifierContributions`.
|
|
251
|
+
- Release, package, and maintainer reputation where reviewers can flag compromised releases or risky maintainership without exposing themselves.
|
|
252
|
+
- NIP-05, domain, and service-provider trust where communities can score identifiers outside a single Nostr pubkey.
|
|
253
|
+
- Community list, labeler, and moderation-list reputation where users can compare curation sources without mapping every reviewer.
|
|
254
|
+
- Federated moderation where scoped circles count overlapping contributors once, not once per circle.
|
|
255
|
+
- Privacy-preserving onboarding where an already-trusted circle can vouch for a new account without naming the individual vouchees.
|
|
256
|
+
- Future anonymous credential or attestation co-signing, once endorsement event formats are agreed: a circle can prove enough members backed a credential without naming which members.
|
|
257
|
+
- Future relay or community admission, once gated-access handshakes exist: a verifier can require a threshold-backed proof without learning which trusted member opened the door.
|
|
258
|
+
|
|
259
|
+
nostr-veil proves that distinct keys from a public trust circle contributed. Trust-circle formation, Sybil policy, revocation, and anonymous access control are separate application-layer decisions.
|
|
260
|
+
|
|
182
261
|
---
|
|
183
262
|
|
|
184
263
|
## Cross-circle deduplication
|
|
@@ -4,6 +4,13 @@ interface RawEvent {
|
|
|
4
4
|
tags: string[][];
|
|
5
5
|
content: string;
|
|
6
6
|
}
|
|
7
|
+
export interface ValidationOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Enable kind-specific NIP-85 checks. Loose validation is kept as the default
|
|
10
|
+
* for backwards compatibility with older callers and extension tags.
|
|
11
|
+
*/
|
|
12
|
+
strict?: boolean;
|
|
13
|
+
}
|
|
7
14
|
/**
|
|
8
15
|
* Validates a NIP-85 assertion event.
|
|
9
16
|
*
|
|
@@ -11,8 +18,11 @@ interface RawEvent {
|
|
|
11
18
|
* - `kind` is one of the four NIP-85 assertion kinds (30382–30385)
|
|
12
19
|
* - A `d` tag is present
|
|
13
20
|
* - `rank`, if present, is a number in the range 0–100
|
|
21
|
+
* - when `{ strict: true }` is passed, kind-specific metric names are checked
|
|
22
|
+
* and optional subject hint tags (`p`, `e`, `a`) are validated if present
|
|
14
23
|
*
|
|
15
24
|
* @param event - A raw Nostr event with `kind`, `tags`, and `content` fields
|
|
25
|
+
* @param options - Optional validation mode. Strict mode is additive and opt-in.
|
|
16
26
|
* @returns A {@link ValidationResult} with `valid` boolean and an array of error strings
|
|
17
27
|
*
|
|
18
28
|
* @example
|
|
@@ -21,6 +31,19 @@ interface RawEvent {
|
|
|
21
31
|
* console.error('Validation failed:', result.errors)
|
|
22
32
|
* }
|
|
23
33
|
*/
|
|
24
|
-
export declare function validateAssertion(event: RawEvent): ValidationResult;
|
|
34
|
+
export declare function validateAssertion(event: RawEvent, options?: ValidationOptions): ValidationResult;
|
|
35
|
+
/**
|
|
36
|
+
* Strict NIP-85 assertion validation. This is equivalent to
|
|
37
|
+
* `validateAssertion(event, { strict: true })`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateAssertionStrict(event: RawEvent): ValidationResult;
|
|
40
|
+
/**
|
|
41
|
+
* Strict validation for plaintext kind 10040 provider declarations.
|
|
42
|
+
*
|
|
43
|
+
* Encrypted provider declarations cannot be inspected without a decrypt
|
|
44
|
+
* function, so this validator accepts the standard encrypted form when content
|
|
45
|
+
* is non-empty and plaintext tags are omitted.
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateProviderDeclarationStrict(event: RawEvent): ValidationResult;
|
|
25
48
|
export {};
|
|
26
49
|
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/nip85/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAUlD,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,EAAE,EAAE,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/nip85/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAUlD,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,EAAE,EAAE,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAwLD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CAiCpG;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,QAAQ,GAAG,gBAAgB,CAEzE;AAED;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,QAAQ,GAAG,gBAAgB,CAmDnF"}
|
package/dist/nip85/validators.js
CHANGED
|
@@ -5,6 +5,174 @@ const ASSERTION_KINDS = new Set([
|
|
|
5
5
|
NIP85_KINDS.ADDRESSABLE,
|
|
6
6
|
NIP85_KINDS.IDENTIFIER,
|
|
7
7
|
]);
|
|
8
|
+
const HEX64_RE = /^[0-9a-f]{64}$/;
|
|
9
|
+
const DECIMAL_INTEGER_RE = /^(0|[1-9]\d*)$/;
|
|
10
|
+
const ADDRESS_RE = /^(0|[1-9]\d*):[0-9a-f]{64}:.*$/;
|
|
11
|
+
const PROVIDER_TAG_RE = /^(0|[1-9]\d*):[A-Za-z0-9_.-]+$/;
|
|
12
|
+
const RELAY_HINT_RE = /^wss?:\/\/.+$/i;
|
|
13
|
+
const META_TAGS = new Set(['d', 'p', 'e', 'a', 'k']);
|
|
14
|
+
const LOOSE_NUMERIC_METRICS = new Set([
|
|
15
|
+
'rank',
|
|
16
|
+
'followers',
|
|
17
|
+
'following',
|
|
18
|
+
'zap_amt_sent',
|
|
19
|
+
'zap_amt_recd',
|
|
20
|
+
'zap_cnt_sent',
|
|
21
|
+
'zap_cnt_recd',
|
|
22
|
+
'post_cnt',
|
|
23
|
+
'reply_cnt',
|
|
24
|
+
'repost_cnt',
|
|
25
|
+
'reaction_cnt',
|
|
26
|
+
]);
|
|
27
|
+
const USER_NUMERIC_METRICS = new Set([
|
|
28
|
+
'followers',
|
|
29
|
+
'rank',
|
|
30
|
+
'first_created_at',
|
|
31
|
+
'post_cnt',
|
|
32
|
+
'reply_cnt',
|
|
33
|
+
'reactions_cnt',
|
|
34
|
+
'zap_amt_recd',
|
|
35
|
+
'zap_amt_sent',
|
|
36
|
+
'zap_cnt_recd',
|
|
37
|
+
'zap_cnt_sent',
|
|
38
|
+
'zap_avg_amt_day_recd',
|
|
39
|
+
'zap_avg_amt_day_sent',
|
|
40
|
+
'reports_cnt_recd',
|
|
41
|
+
'reports_cnt_sent',
|
|
42
|
+
'active_hours_start',
|
|
43
|
+
'active_hours_end',
|
|
44
|
+
]);
|
|
45
|
+
const USER_STRING_METRICS = new Set(['t']);
|
|
46
|
+
const EVENT_NUMERIC_METRICS = new Set([
|
|
47
|
+
'rank',
|
|
48
|
+
'comment_cnt',
|
|
49
|
+
'quote_cnt',
|
|
50
|
+
'repost_cnt',
|
|
51
|
+
'reaction_cnt',
|
|
52
|
+
'zap_cnt',
|
|
53
|
+
'zap_amount',
|
|
54
|
+
]);
|
|
55
|
+
const IDENTIFIER_NUMERIC_METRICS = new Set(['rank', 'comment_cnt', 'reaction_cnt']);
|
|
56
|
+
function tagValues(event, name) {
|
|
57
|
+
return event.tags.filter(t => t[0] === name).map(t => t[1]).filter((v) => typeof v === 'string');
|
|
58
|
+
}
|
|
59
|
+
function isFiniteNumberTag(value) {
|
|
60
|
+
if (value === undefined || value.trim() === '')
|
|
61
|
+
return false;
|
|
62
|
+
return Number.isFinite(Number(value));
|
|
63
|
+
}
|
|
64
|
+
function validateLooseRank(value, errors) {
|
|
65
|
+
const rankValue = Number(value);
|
|
66
|
+
if (isNaN(rankValue) || rankValue < 0 || rankValue > 100) {
|
|
67
|
+
errors.push(`Invalid rank value: "${value}". Must be a number between 0 and 100.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function validateStrictRank(value, errors) {
|
|
71
|
+
const rankValue = Number(value);
|
|
72
|
+
if (value === undefined || value.trim() === '' || !Number.isFinite(rankValue) || rankValue < 0 || rankValue > 100) {
|
|
73
|
+
errors.push(`Invalid rank value: "${value}". Must be a number between 0 and 100.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function requireSingletonTag(event, name, errors) {
|
|
77
|
+
const values = tagValues(event, name);
|
|
78
|
+
if (values.length === 0) {
|
|
79
|
+
errors.push(`Missing required ${name}-tag.`);
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
if (values.length > 1) {
|
|
83
|
+
errors.push(`Duplicate ${name}-tag.`);
|
|
84
|
+
}
|
|
85
|
+
return values[0];
|
|
86
|
+
}
|
|
87
|
+
function validateOptionalMatchingTag(event, name, subject, errors) {
|
|
88
|
+
const values = tagValues(event, name);
|
|
89
|
+
if (values.length === 0)
|
|
90
|
+
return;
|
|
91
|
+
if (values.length > 1) {
|
|
92
|
+
errors.push(`Duplicate ${name}-tag.`);
|
|
93
|
+
}
|
|
94
|
+
if (values[0] !== subject) {
|
|
95
|
+
errors.push(`${name}-tag must match d-tag.`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function validateStrictSubjectTags(event, errors) {
|
|
99
|
+
const subject = requireSingletonTag(event, 'd', errors);
|
|
100
|
+
if (subject === undefined)
|
|
101
|
+
return;
|
|
102
|
+
switch (event.kind) {
|
|
103
|
+
case NIP85_KINDS.USER:
|
|
104
|
+
if (!HEX64_RE.test(subject)) {
|
|
105
|
+
errors.push('User assertion d-tag must be a 64-character lowercase hex pubkey.');
|
|
106
|
+
}
|
|
107
|
+
validateOptionalMatchingTag(event, 'p', subject, errors);
|
|
108
|
+
break;
|
|
109
|
+
case NIP85_KINDS.EVENT:
|
|
110
|
+
if (!HEX64_RE.test(subject)) {
|
|
111
|
+
errors.push('Event assertion d-tag must be a 64-character lowercase hex event id.');
|
|
112
|
+
}
|
|
113
|
+
validateOptionalMatchingTag(event, 'e', subject, errors);
|
|
114
|
+
break;
|
|
115
|
+
case NIP85_KINDS.ADDRESSABLE:
|
|
116
|
+
if (!ADDRESS_RE.test(subject)) {
|
|
117
|
+
errors.push('Addressable assertion d-tag must be a NIP-33 address: kind:pubkey:d-tag.');
|
|
118
|
+
}
|
|
119
|
+
validateOptionalMatchingTag(event, 'a', subject, errors);
|
|
120
|
+
break;
|
|
121
|
+
case NIP85_KINDS.IDENTIFIER: {
|
|
122
|
+
if (subject === '') {
|
|
123
|
+
errors.push('Identifier assertion d-tag must be non-empty.');
|
|
124
|
+
}
|
|
125
|
+
const kTag = requireSingletonTag(event, 'k', errors);
|
|
126
|
+
if (kTag !== undefined && !DECIMAL_INTEGER_RE.test(kTag)) {
|
|
127
|
+
errors.push('Identifier assertion k-tag must be a decimal kind number.');
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function strictMetricSets(kind) {
|
|
134
|
+
switch (kind) {
|
|
135
|
+
case NIP85_KINDS.USER:
|
|
136
|
+
return { numeric: USER_NUMERIC_METRICS, string: USER_STRING_METRICS };
|
|
137
|
+
case NIP85_KINDS.EVENT:
|
|
138
|
+
case NIP85_KINDS.ADDRESSABLE:
|
|
139
|
+
return { numeric: EVENT_NUMERIC_METRICS, string: new Set() };
|
|
140
|
+
case NIP85_KINDS.IDENTIFIER:
|
|
141
|
+
return { numeric: IDENTIFIER_NUMERIC_METRICS, string: new Set() };
|
|
142
|
+
default:
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function validateStrictMetrics(event, errors) {
|
|
147
|
+
const allowed = strictMetricSets(event.kind);
|
|
148
|
+
if (allowed === undefined)
|
|
149
|
+
return;
|
|
150
|
+
const seen = new Set();
|
|
151
|
+
for (const tag of event.tags) {
|
|
152
|
+
const name = tag[0];
|
|
153
|
+
if (META_TAGS.has(name) || name.startsWith('veil-'))
|
|
154
|
+
continue;
|
|
155
|
+
if (seen.has(name)) {
|
|
156
|
+
errors.push(`Duplicate metric tag "${name}".`);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
seen.add(name);
|
|
160
|
+
if (!allowed.numeric.has(name) && !allowed.string.has(name)) {
|
|
161
|
+
errors.push(`Unknown metric tag "${name}" for kind ${event.kind}.`);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (tag[1] === undefined) {
|
|
165
|
+
errors.push(`Metric "${name}" is missing a value.`);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (name === 'rank') {
|
|
169
|
+
validateStrictRank(tag[1], errors);
|
|
170
|
+
}
|
|
171
|
+
else if (allowed.numeric.has(name) && !isFiniteNumberTag(tag[1])) {
|
|
172
|
+
errors.push(`Invalid metric "${name}": "${tag[1]}" is not a finite number.`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
8
176
|
/**
|
|
9
177
|
* Validates a NIP-85 assertion event.
|
|
10
178
|
*
|
|
@@ -12,8 +180,11 @@ const ASSERTION_KINDS = new Set([
|
|
|
12
180
|
* - `kind` is one of the four NIP-85 assertion kinds (30382–30385)
|
|
13
181
|
* - A `d` tag is present
|
|
14
182
|
* - `rank`, if present, is a number in the range 0–100
|
|
183
|
+
* - when `{ strict: true }` is passed, kind-specific metric names are checked
|
|
184
|
+
* and optional subject hint tags (`p`, `e`, `a`) are validated if present
|
|
15
185
|
*
|
|
16
186
|
* @param event - A raw Nostr event with `kind`, `tags`, and `content` fields
|
|
187
|
+
* @param options - Optional validation mode. Strict mode is additive and opt-in.
|
|
17
188
|
* @returns A {@link ValidationResult} with `valid` boolean and an array of error strings
|
|
18
189
|
*
|
|
19
190
|
* @example
|
|
@@ -22,7 +193,7 @@ const ASSERTION_KINDS = new Set([
|
|
|
22
193
|
* console.error('Validation failed:', result.errors)
|
|
23
194
|
* }
|
|
24
195
|
*/
|
|
25
|
-
export function validateAssertion(event) {
|
|
196
|
+
export function validateAssertion(event, options = {}) {
|
|
26
197
|
const errors = [];
|
|
27
198
|
if (!ASSERTION_KINDS.has(event.kind)) {
|
|
28
199
|
errors.push(`Invalid kind: ${event.kind}. Must be one of 30382, 30383, 30384, 30385.`);
|
|
@@ -33,21 +204,78 @@ export function validateAssertion(event) {
|
|
|
33
204
|
}
|
|
34
205
|
const rankTag = event.tags.find(t => t[0] === 'rank');
|
|
35
206
|
if (rankTag !== undefined) {
|
|
36
|
-
|
|
37
|
-
if (isNaN(rankValue) || rankValue < 0 || rankValue > 100) {
|
|
38
|
-
errors.push(`Invalid rank value: "${rankTag[1]}". Must be a number between 0 and 100.`);
|
|
39
|
-
}
|
|
207
|
+
validateLooseRank(rankTag[1], errors);
|
|
40
208
|
}
|
|
41
209
|
// Validate all numeric metric tags are finite numbers
|
|
42
|
-
const NUMERIC_METRICS = new Set(['rank', 'followers', 'following', 'zap_amt_sent', 'zap_amt_recd', 'zap_cnt_sent', 'zap_cnt_recd', 'post_cnt', 'reply_cnt', 'repost_cnt', 'reaction_cnt']);
|
|
43
210
|
for (const tag of event.tags) {
|
|
44
|
-
if (
|
|
211
|
+
if (LOOSE_NUMERIC_METRICS.has(tag[0]) && tag[0] !== 'rank') {
|
|
45
212
|
const value = Number(tag[1]);
|
|
46
213
|
if (!Number.isFinite(value)) {
|
|
47
214
|
errors.push(`Invalid metric "${tag[0]}": "${tag[1]}" is not a finite number.`);
|
|
48
215
|
}
|
|
49
216
|
}
|
|
50
217
|
}
|
|
218
|
+
if (options.strict) {
|
|
219
|
+
validateStrictSubjectTags(event, errors);
|
|
220
|
+
validateStrictMetrics(event, errors);
|
|
221
|
+
}
|
|
222
|
+
return { valid: errors.length === 0, errors };
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Strict NIP-85 assertion validation. This is equivalent to
|
|
226
|
+
* `validateAssertion(event, { strict: true })`.
|
|
227
|
+
*/
|
|
228
|
+
export function validateAssertionStrict(event) {
|
|
229
|
+
return validateAssertion(event, { strict: true });
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Strict validation for plaintext kind 10040 provider declarations.
|
|
233
|
+
*
|
|
234
|
+
* Encrypted provider declarations cannot be inspected without a decrypt
|
|
235
|
+
* function, so this validator accepts the standard encrypted form when content
|
|
236
|
+
* is non-empty and plaintext tags are omitted.
|
|
237
|
+
*/
|
|
238
|
+
export function validateProviderDeclarationStrict(event) {
|
|
239
|
+
const errors = [];
|
|
240
|
+
if (event.kind !== NIP85_KINDS.PROVIDER) {
|
|
241
|
+
errors.push(`Invalid kind: ${event.kind}. Must be 10040 for a provider declaration.`);
|
|
242
|
+
}
|
|
243
|
+
if (event.content !== '' && event.tags.length === 0) {
|
|
244
|
+
return { valid: errors.length === 0, errors };
|
|
245
|
+
}
|
|
246
|
+
if (event.tags.length === 0) {
|
|
247
|
+
errors.push('Provider declaration must contain at least one provider tag or encrypted content.');
|
|
248
|
+
}
|
|
249
|
+
const seen = new Set();
|
|
250
|
+
for (let i = 0; i < event.tags.length; i++) {
|
|
251
|
+
const tag = event.tags[i];
|
|
252
|
+
const name = tag[0];
|
|
253
|
+
if (typeof name !== 'string' || !PROVIDER_TAG_RE.test(name)) {
|
|
254
|
+
errors.push(`Provider tag at index ${i} must use kind:metric format.`);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const [kindText, metric] = name.split(':');
|
|
258
|
+
const kind = Number(kindText);
|
|
259
|
+
if (!ASSERTION_KINDS.has(kind)) {
|
|
260
|
+
errors.push(`Provider tag at index ${i} has unsupported assertion kind: ${kindText}.`);
|
|
261
|
+
}
|
|
262
|
+
if (metric === '') {
|
|
263
|
+
errors.push(`Provider tag at index ${i} has an empty metric name.`);
|
|
264
|
+
}
|
|
265
|
+
const key = `${kindText}:${metric}:${tag[1] ?? ''}`;
|
|
266
|
+
if (seen.has(key)) {
|
|
267
|
+
errors.push(`Duplicate provider declaration for ${kindText}:${metric}.`);
|
|
268
|
+
}
|
|
269
|
+
seen.add(key);
|
|
270
|
+
const servicePubkey = tag[1];
|
|
271
|
+
if (typeof servicePubkey !== 'string' || !HEX64_RE.test(servicePubkey)) {
|
|
272
|
+
errors.push(`Provider tag at index ${i} service pubkey must be a 64-character lowercase hex pubkey.`);
|
|
273
|
+
}
|
|
274
|
+
const relayHint = tag[2];
|
|
275
|
+
if (relayHint !== undefined && relayHint !== '' && !RELAY_HINT_RE.test(relayHint)) {
|
|
276
|
+
errors.push(`Provider tag at index ${i} relay hint must be a websocket URL.`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
51
279
|
return { valid: errors.length === 0, errors };
|
|
52
280
|
}
|
|
53
281
|
//# sourceMappingURL=validators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/nip85/validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAS;IACtC,WAAW,CAAC,IAAI;IAChB,WAAW,CAAC,KAAK;IACjB,WAAW,CAAC,WAAW;IACvB,WAAW,CAAC,UAAU;CACvB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/nip85/validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAS;IACtC,WAAW,CAAC,IAAI;IAChB,WAAW,CAAC,KAAK;IACjB,WAAW,CAAC,WAAW;IACvB,WAAW,CAAC,UAAU;CACvB,CAAC,CAAA;AAgBF,MAAM,QAAQ,GAAG,gBAAgB,CAAA;AACjC,MAAM,kBAAkB,GAAG,gBAAgB,CAAA;AAC3C,MAAM,UAAU,GAAG,gCAAgC,CAAA;AACnD,MAAM,eAAe,GAAG,gCAAgC,CAAA;AACxD,MAAM,aAAa,GAAG,gBAAgB,CAAA;AACtC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AAEpD,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,MAAM;IACN,WAAW;IACX,WAAW;IACX,cAAc;IACd,cAAc;IACd,cAAc;IACd,cAAc;IACd,UAAU;IACV,WAAW;IACX,YAAY;IACZ,cAAc;CACf,CAAC,CAAA;AAEF,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,WAAW;IACX,MAAM;IACN,kBAAkB;IAClB,UAAU;IACV,WAAW;IACX,eAAe;IACf,cAAc;IACd,cAAc;IACd,cAAc;IACd,cAAc;IACd,sBAAsB;IACtB,sBAAsB;IACtB,kBAAkB;IAClB,kBAAkB;IAClB,oBAAoB;IACpB,kBAAkB;CACnB,CAAC,CAAA;AACF,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;AAC1C,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,MAAM;IACN,aAAa;IACb,WAAW;IACX,Y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,IAAI,CAAC,yBAAyB,CAAC,4BAA4B,CAAC,CAAA;QACrE,CAAC;QAED,MAAM,GAAG,GAAG,GAAG,QAAQ,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAA;QACnD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,CAAC,IAAI,CAAC,sCAAsC,QAAQ,IAAI,MAAM,GAAG,CAAC,CAAA;QAC1E,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEb,MAAM,aAAa,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QAC5B,IAAI,OAAO,aAAa,KAAK,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YACvE,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,8DAA8D,CAAC,CAAA;QACvG,CAAC;QAED,MAAM,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QACxB,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAClF,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,sCAAsC,CAAC,CAAA;QAC/E,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;AAC/C,CAAC"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { EventTemplate } from '../nip85/types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AggregateFn, AggregateName, Contribution, ProofVersion, TrustCircle } from './types.js';
|
|
3
|
+
export type AggregateOptions = AggregateFn | {
|
|
4
|
+
aggregateFn?: AggregateFn;
|
|
5
|
+
aggregate?: AggregateName;
|
|
6
|
+
kind?: number;
|
|
7
|
+
proofVersion?: ProofVersion;
|
|
8
|
+
};
|
|
9
|
+
export type TypedAggregateOptions = AggregateFn | {
|
|
10
|
+
aggregateFn?: AggregateFn;
|
|
11
|
+
aggregate?: AggregateName;
|
|
12
|
+
proofVersion?: ProofVersion;
|
|
13
|
+
};
|
|
3
14
|
/**
|
|
4
15
|
* Built-in named aggregate functions. The `veil-agg` tag records which one
|
|
5
16
|
* produced an event's metric tags, letting `verifyProof` recompute the
|
|
@@ -22,13 +33,36 @@ export declare function isAggregateName(name: string): name is AggregateName;
|
|
|
22
33
|
* @param options - Optional configuration
|
|
23
34
|
* @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
35
|
* @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.
|
|
25
|
-
* @param options.kind - NIP-85 assertion kind (default: 30382 USER).
|
|
36
|
+
* @param options.kind - NIP-85 assertion kind (default: 30382 USER). This
|
|
37
|
+
* legacy option is kept for compatibility and still emits the user-style
|
|
38
|
+
* `p` subject tag. Prefer `aggregateEventContributions`,
|
|
39
|
+
* `aggregateAddressableContributions`, or `aggregateIdentifierContributions`
|
|
40
|
+
* for non-user assertion kinds.
|
|
26
41
|
* @returns An unsigned {@link EventTemplate} with proof tags — sign and publish as a standard Nostr event
|
|
27
42
|
* @throws If any LSAG signature is invalid, duplicate key images are detected, or an unknown aggregate name is supplied
|
|
28
43
|
*/
|
|
29
|
-
export declare function aggregateContributions(circle: TrustCircle, subject: string, contributions: Contribution[], options?:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
export declare function aggregateContributions(circle: TrustCircle, subject: string, contributions: Contribution[], options?: AggregateOptions): EventTemplate;
|
|
45
|
+
/**
|
|
46
|
+
* Aggregate anonymous contributions into a kind 30383 event assertion.
|
|
47
|
+
*
|
|
48
|
+
* Emits `d` and `e` tags that both point at the event id. The proof format is
|
|
49
|
+
* still the backwards-compatible v1 format, so `verifyProof` works unchanged.
|
|
50
|
+
*/
|
|
51
|
+
export declare function aggregateEventContributions(circle: TrustCircle, eventId: string, contributions: Contribution[], options?: TypedAggregateOptions): EventTemplate;
|
|
52
|
+
/**
|
|
53
|
+
* Aggregate anonymous contributions into a kind 30384 addressable event assertion.
|
|
54
|
+
*
|
|
55
|
+
* Emits `d` and `a` tags that both point at the NIP-33 address. The proof
|
|
56
|
+
* format is still the backwards-compatible v1 format, so `verifyProof` works
|
|
57
|
+
* unchanged.
|
|
58
|
+
*/
|
|
59
|
+
export declare function aggregateAddressableContributions(circle: TrustCircle, address: string, contributions: Contribution[], options?: TypedAggregateOptions): EventTemplate;
|
|
60
|
+
/**
|
|
61
|
+
* Aggregate anonymous contributions into a kind 30385 identifier assertion.
|
|
62
|
+
*
|
|
63
|
+
* Emits `d` for the identifier and `k` for the identifier kind. The proof
|
|
64
|
+
* format is still the backwards-compatible v1 format, so `verifyProof` works
|
|
65
|
+
* unchanged.
|
|
66
|
+
*/
|
|
67
|
+
export declare function aggregateIdentifierContributions(circle: TrustCircle, identifier: string, kTag: string, contributions: Contribution[], options?: TypedAggregateOptions): EventTemplate;
|
|
34
68
|
//# 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,
|
|
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,EACV,WAAW,EACX,aAAa,EACb,YAAY,EAEZ,YAAY,EAEZ,WAAW,EACZ,MAAM,YAAY,CAAA;AAG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