nostr-veil 0.12.1 → 0.15.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 +113 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- 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/profiles/canonical.d.ts +22 -0
- package/dist/profiles/canonical.d.ts.map +1 -0
- package/dist/profiles/canonical.js +169 -0
- package/dist/profiles/canonical.js.map +1 -0
- package/dist/profiles/index.d.ts +5 -0
- package/dist/profiles/index.d.ts.map +1 -0
- package/dist/profiles/index.js +5 -0
- package/dist/profiles/index.js.map +1 -0
- package/dist/profiles/profiles.d.ts +19 -0
- package/dist/profiles/profiles.d.ts.map +1 -0
- package/dist/profiles/profiles.js +263 -0
- package/dist/profiles/profiles.js.map +1 -0
- package/dist/profiles/types.d.ts +54 -0
- package/dist/profiles/types.d.ts.map +1 -0
- package/dist/profiles/types.js +2 -0
- package/dist/profiles/types.js.map +1 -0
- package/dist/profiles/verify.d.ts +4 -0
- package/dist/profiles/verify.d.ts.map +1 -0
- package/dist/profiles/verify.js +148 -0
- package/dist/profiles/verify.js.map +1 -0
- 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 +103 -10
- package/llms.txt +42 -9
- package/package.json +7 -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,13 +144,30 @@ 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
|
|
|
161
|
+
### `nostr-veil/profiles` -- safer deployment profiles
|
|
162
|
+
|
|
163
|
+
| Export | Description |
|
|
164
|
+
|--------|-------------|
|
|
165
|
+
| `USE_CASE_PROFILES` | Built-in machine-readable profiles for the documented use cases |
|
|
166
|
+
| `USE_CASE_PROFILE_BY_ID` | Lookup table keyed by use-case slug |
|
|
167
|
+
| `verifyUseCaseProfile(events, profile, options)` | Verify NIP-85 syntax, proof v2, subject binding, threshold, freshness, accepted circles, and federation policy |
|
|
168
|
+
| `canonicalRelaySubject`, `canonicalNip05Subject`, `canonicalDomainSubject`, `canonicalNpmPackageSubject` | Canonical subject helpers for common real-world identifiers |
|
|
169
|
+
| `canonicalPubkeySubject`, `canonicalEventSubject`, `canonicalAddressSubject` | Canonical subject helpers for Nostr-native subjects |
|
|
170
|
+
|
|
150
171
|
### Signing utility (root export)
|
|
151
172
|
|
|
152
173
|
| Export | Description |
|
|
@@ -166,6 +187,7 @@ The published event carries extra tags on top of the standard NIP-85 format:
|
|
|
166
187
|
- `veil-threshold` -- how many members actually contributed vs. total circle size
|
|
167
188
|
- `veil-agg` -- which aggregate function produced the metric tags (median by default)
|
|
168
189
|
- `veil-sig` (one per contributor) -- the ring signature and a duplicate-detection token
|
|
190
|
+
- `veil-version` -- present only for opt-in proof v2 events
|
|
169
191
|
- `veil-scope` -- present only for a federated circle; see [Cross-circle deduplication](#cross-circle-deduplication)
|
|
170
192
|
|
|
171
193
|
A verifier calls `verifyProof`, which:
|
|
@@ -175,10 +197,91 @@ A verifier calls `verifyProof`, which:
|
|
|
175
197
|
3. Confirms the threshold metadata matches the ring and distinct signatures
|
|
176
198
|
4. Confirms the published metric tags match the aggregate of the signed contributions
|
|
177
199
|
|
|
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.
|
|
200
|
+
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
201
|
|
|
180
202
|
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
203
|
|
|
204
|
+
### Proof v2
|
|
205
|
+
|
|
206
|
+
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.
|
|
207
|
+
|
|
208
|
+
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.
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import { contributeEventAssertion, aggregateEventContributions, verifyProof } from 'nostr-veil'
|
|
212
|
+
|
|
213
|
+
const contribution = contributeEventAssertion(
|
|
214
|
+
circle,
|
|
215
|
+
eventId,
|
|
216
|
+
{ rank: 90 },
|
|
217
|
+
alicePrivkey,
|
|
218
|
+
circle.members.indexOf(alicePubkey),
|
|
219
|
+
{ proofVersion: 'v2' },
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
const assertion = aggregateEventContributions(circle, eventId, [contribution], { proofVersion: 'v2' })
|
|
223
|
+
const result = verifyProof(assertion, { requireProofVersion: 'v2' })
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Old v1 events still verify without changes. Use `requireProofVersion: 'v2'` only when your application policy wants to reject legacy proofs for that workflow.
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Threat model
|
|
231
|
+
|
|
232
|
+
nostr-veil is a privacy layer for already-defined trust circles. It gives you:
|
|
233
|
+
|
|
234
|
+
- Anonymous membership proof: each contribution was signed by some member of the public ring, without revealing which member.
|
|
235
|
+
- Duplicate detection: one member cannot contribute twice within the same circle/scope and subject without reusing the same LSAG key image.
|
|
236
|
+
- Signed metric integrity: `verifyProof` checks the published metric tags against the aggregate of the signed contribution messages.
|
|
237
|
+
- Optional semantic binding: proof v2 binds the assertion kind and subject hint tag into the signed message and election ID.
|
|
238
|
+
- Standard NIP-85 output: non-veil clients can still read the aggregate score.
|
|
239
|
+
|
|
240
|
+
The boundary is deliberately narrow. Pair each limitation with the right
|
|
241
|
+
application control:
|
|
242
|
+
|
|
243
|
+
- The ring membership list is public; use a cover set large enough for the risk
|
|
244
|
+
and avoid circles that reveal vulnerable participants by membership alone.
|
|
245
|
+
- Anonymous metric values are public so anyone can recompute the aggregate;
|
|
246
|
+
publish only metrics your workflow is comfortable exposing.
|
|
247
|
+
- Network, timing, relay, and collector metadata are outside the proof; use
|
|
248
|
+
batching, transport privacy, and careful logging for sensitive collection.
|
|
249
|
+
- Circle quality is social policy; publish admission, rotation, Sybil, and
|
|
250
|
+
conflict rules for circles that drive real decisions.
|
|
251
|
+
- A shared federation `scope` intentionally reveals cross-circle overlap by key
|
|
252
|
+
image; use scoped federation only when deduplication is worth that signal.
|
|
253
|
+
|
|
254
|
+
For sensitive deployments, combine nostr-veil with careful collection,
|
|
255
|
+
transport privacy, key hygiene, and a clear policy for how circles are admitted
|
|
256
|
+
and rotated.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Use cases
|
|
261
|
+
|
|
262
|
+
The shipped primitives support more than user trust scores. See
|
|
263
|
+
[docs/use-cases.md](./docs/use-cases.md) for the implementation field guide:
|
|
264
|
+
one worked page per use case, subject formats, helper functions, metrics,
|
|
265
|
+
proof-v2 verification, and the operational controls needed beyond the proof.
|
|
266
|
+
|
|
267
|
+
Supported today:
|
|
268
|
+
|
|
269
|
+
- User reputation and abuse reporting with kind 30382 user assertions.
|
|
270
|
+
- Source corroboration and peer review, using kind 30382 for pubkeys or kind 30385 for external identifiers.
|
|
271
|
+
- Event and claim verification with kind 30383 event assertions via `aggregateEventContributions`.
|
|
272
|
+
- Article, long-form note, research, grant, and proposal review with kind 30384 addressable assertions via `aggregateAddressableContributions`.
|
|
273
|
+
- Relay, service, vendor, marketplace, package, release, maintainer, NIP-05, and domain reputation with kind 30385 identifier assertions via `aggregateIdentifierContributions`.
|
|
274
|
+
- Community list, labeler, and moderation-list reputation where users can compare curation sources without mapping every reviewer.
|
|
275
|
+
- Federated moderation where scoped circles count overlapping contributors once, not once per circle.
|
|
276
|
+
- Privacy-preserving onboarding where an already-trusted circle can vouch for a new account without naming the individual vouchees.
|
|
277
|
+
|
|
278
|
+
Future profiles:
|
|
279
|
+
|
|
280
|
+
- Anonymous credential or attestation co-signing, once endorsement event formats define subject, expiry, revocation, and presentation rules.
|
|
281
|
+
- Relay or community admission, once a gated-access handshake exists; today nostr-veil can publish the threshold-backed assertion, but it is not the whole anonymous access-control protocol.
|
|
282
|
+
|
|
283
|
+
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.
|
|
284
|
+
|
|
182
285
|
---
|
|
183
286
|
|
|
184
287
|
## Cross-circle deduplication
|
|
@@ -193,6 +296,8 @@ const circleA = createTrustCircle(membersA, { scope: 'community-moderators' })
|
|
|
193
296
|
const circleB = createTrustCircle(membersB, { scope: 'community-moderators' })
|
|
194
297
|
```
|
|
195
298
|
|
|
299
|
+
Scopes are lowercase slugs: letters, digits, dot, hyphen, and underscore.
|
|
300
|
+
|
|
196
301
|
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
302
|
|
|
198
303
|
```ts
|
|
@@ -228,6 +333,7 @@ Each project is independently maintained and published. nostr-veil focuses solel
|
|
|
228
333
|
## Further reading
|
|
229
334
|
|
|
230
335
|
- [IMPACT.md](./IMPACT.md) -- Problem statement and ecosystem impact
|
|
336
|
+
- [docs/use-cases.md](./docs/use-cases.md) -- Concrete implementation map with individual worked use-case pages
|
|
231
337
|
- [CONTRIBUTING.md](./CONTRIBUTING.md) -- Setup, testing, and PR guidelines
|
|
232
338
|
- [SECURITY.md](./SECURITY.md) -- Vulnerability reporting and cryptographic scope
|
|
233
339
|
- [llms.txt](./llms.txt) -- Machine-readable project summary for LLMs
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA"}
|
|
@@ -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,C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AS,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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SubjectFormat } from './types.js';
|
|
2
|
+
/** Canonical 64-char lowercase hex pubkey subject. */
|
|
3
|
+
export declare function canonicalPubkeySubject(pubkey: string): string;
|
|
4
|
+
/** Canonical 64-char lowercase hex event id subject. */
|
|
5
|
+
export declare function canonicalEventSubject(eventId: string): string;
|
|
6
|
+
/** Canonical NIP-33 address subject: `kind:pubkey:d-tag`. */
|
|
7
|
+
export declare function canonicalAddressSubject(kind: number | string, pubkey: string, dTag: string): string;
|
|
8
|
+
/** Canonical relay identifier subject: `relay:wss://host[/path]`. */
|
|
9
|
+
export declare function canonicalRelaySubject(relay: string): string;
|
|
10
|
+
/** Canonical NIP-05 identifier subject. Domain is lowercased; local part is preserved. */
|
|
11
|
+
export declare function canonicalNip05Subject(identifier: string): string;
|
|
12
|
+
/** Canonical domain identifier subject: `domain:example.com`. */
|
|
13
|
+
export declare function canonicalDomainSubject(domain: string): string;
|
|
14
|
+
/** Canonical npm package release subject: `npm:package@version`. */
|
|
15
|
+
export declare function canonicalNpmPackageSubject(name: string, version: string): string;
|
|
16
|
+
/** Canonical vendor identifier subject scoped to a marketplace hostname. */
|
|
17
|
+
export declare function canonicalVendorSubject(marketplace: string, vendorId: string): string;
|
|
18
|
+
/** Canonical source identifier subject scoped to an application namespace. */
|
|
19
|
+
export declare function canonicalSourceSubject(namespace: string, sourceId: string): string;
|
|
20
|
+
export declare function subjectMatchesFormat(subject: string, format: SubjectFormat): boolean;
|
|
21
|
+
export declare function subjectMatchesAnyFormat(subject: string, formats: SubjectFormat[]): boolean;
|
|
22
|
+
//# sourceMappingURL=canonical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../../src/profiles/canonical.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAuC/C,sDAAsD;AACtD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wDAAwD;AACxD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,6DAA6D;AAC7D,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAOnG;AAED,qEAAqE;AACrE,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAY3D;AAED,0FAA0F;AAC1F,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAOhE;AAED,iEAAiE;AACjE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAM7D;AAED,oEAAoE;AACpE,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQhF;AAED,4EAA4E;AAC5E,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpF;AAED,8EAA8E;AAC9E,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMlF;AAwCD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAsBpF;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,E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