nostr-veil 0.30.2 → 0.30.4
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/LICENSE +21 -0
- package/README.md +173 -20
- package/dist/nip85/builders.d.ts +3 -3
- package/dist/nip85/builders.js +3 -3
- package/dist/nip85/tags.d.ts +11 -0
- package/dist/nip85/tags.d.ts.map +1 -0
- package/dist/nip85/tags.js +20 -0
- package/dist/nip85/tags.js.map +1 -0
- package/dist/nip85/validators.d.ts +6 -3
- package/dist/nip85/validators.d.ts.map +1 -1
- package/dist/nip85/validators.js +53 -13
- package/dist/nip85/validators.js.map +1 -1
- package/dist/proof/aggregate.d.ts +3 -3
- package/dist/proof/aggregate.d.ts.map +1 -1
- package/dist/proof/aggregate.js +14 -6
- package/dist/proof/aggregate.js.map +1 -1
- package/dist/proof/circle.d.ts +3 -1
- package/dist/proof/circle.d.ts.map +1 -1
- package/dist/proof/circle.js +5 -1
- package/dist/proof/circle.js.map +1 -1
- package/dist/proof/metric-names.d.ts +5 -0
- package/dist/proof/metric-names.d.ts.map +1 -0
- package/dist/proof/metric-names.js +45 -0
- package/dist/proof/metric-names.js.map +1 -0
- package/dist/proof/verify.d.ts.map +1 -1
- package/dist/proof/verify.js +39 -3
- package/dist/proof/verify.js.map +1 -1
- package/llms-full.txt +126 -29
- package/llms.txt +115 -14
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TheCryptoDonkey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -96,26 +96,55 @@ npm install nostr-veil
|
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
```ts
|
|
99
|
-
import {
|
|
99
|
+
import { schnorr } from '@noble/curves/secp256k1.js'
|
|
100
|
+
import { bytesToHex } from '@noble/hashes/utils.js'
|
|
101
|
+
import {
|
|
102
|
+
createTrustCircle, contributeAssertion, aggregateContributions, verifyProof, signEvent, NIP85_KINDS,
|
|
103
|
+
} from 'nostr-veil'
|
|
104
|
+
|
|
105
|
+
// 0. Generate keys. nostr-veil takes 64-char lowercase hex strings everywhere.
|
|
106
|
+
function generateKeypair() {
|
|
107
|
+
const secret = schnorr.utils.randomSecretKey() // Uint8Array (noble v2)
|
|
108
|
+
return { privkey: bytesToHex(secret), pubkey: bytesToHex(schnorr.getPublicKey(secret)) }
|
|
109
|
+
}
|
|
110
|
+
const alice = generateKeypair()
|
|
111
|
+
const bob = generateKeypair()
|
|
112
|
+
const carol = generateKeypair()
|
|
113
|
+
const subject = generateKeypair() // the account being scored; only its pubkey is used
|
|
114
|
+
const aggregator = generateKeypair() // publishes the result; does not need to be a circle member
|
|
115
|
+
const subjectPubkey = subject.pubkey
|
|
100
116
|
|
|
101
117
|
// 1. Define the circle (three anonymous members)
|
|
102
|
-
const circle = createTrustCircle([
|
|
118
|
+
const circle = createTrustCircle([alice.pubkey, bob.pubkey, carol.pubkey])
|
|
103
119
|
|
|
104
120
|
// 2. Each member contributes independently -- their identity is hidden inside the ring
|
|
105
|
-
const
|
|
106
|
-
|
|
121
|
+
const aliceContribution = contributeAssertion(
|
|
122
|
+
circle, subjectPubkey, { followers: 820, rank: 74 }, alice.privkey, circle.members.indexOf(alice.pubkey),
|
|
123
|
+
)
|
|
124
|
+
const bobContribution = contributeAssertion(
|
|
125
|
+
circle, subjectPubkey, { followers: 900, rank: 80 }, bob.privkey, circle.members.indexOf(bob.pubkey),
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
// 3. Aggregate into a standard NIP-85 kind 30382 user assertion (an unsigned EventTemplate)
|
|
129
|
+
const assertion = aggregateContributions(circle, subjectPubkey, [aliceContribution, bobContribution])
|
|
107
130
|
|
|
108
|
-
//
|
|
109
|
-
const
|
|
131
|
+
// 4. The aggregator signs it as an ordinary Nostr event and publishes it
|
|
132
|
+
const signed = signEvent(assertion, aggregator.privkey)
|
|
110
133
|
|
|
111
|
-
//
|
|
112
|
-
const result = verifyProof(
|
|
134
|
+
// 5. Any client verifies -- two distinct members agreed, no names attached
|
|
135
|
+
const result = verifyProof(signed, { expectedKind: NIP85_KINDS.USER })
|
|
113
136
|
// { valid: true, circleSize: 3, threshold: 2, distinctSigners: 2, errors: [] }
|
|
114
137
|
```
|
|
115
138
|
|
|
116
|
-
|
|
139
|
+
The `@noble/curves` and `@noble/hashes` imports are only used for key generation; nostr-veil already depends on both, so install them directly if your package manager does not hoist them.
|
|
140
|
+
|
|
141
|
+
**Formats.** Pubkeys (circle members, subjects, bundle signers) are 64-char lowercase hex x-only strings. Every `privateKey` argument (`contributeAssertion`, `signEvent`, `createSignedDeploymentBundle`) is a 64-char hex string. A `Uint8Array` is rejected (for example `ValidationError: privateKey must be a string`), so convert noble's byte keys with `bytesToHex` as above.
|
|
142
|
+
|
|
143
|
+
**Important:** `memberIndex` must match the member's position in the *sorted* pubkey array. `createTrustCircle` sorts pubkeys lexicographically -- the index you pass to `contributeAssertion` must reflect that sorted order, not the order you passed to `createTrustCircle`. Always use `circle.members.indexOf(myPubkey)`. A wrong index throws `Private key does not match ring member at signerIndex`.
|
|
117
144
|
|
|
118
|
-
The
|
|
145
|
+
**Who signs what.** The ring signatures live in the `veil-sig` tags. The outer Nostr signature from `signEvent` is made by the aggregator, the party that collects the contributions and publishes the event. Any Nostr key will do and it need not belong to a circle member. `verifyProof` checks the ring proofs only; use `verifySignedEvent(event)` to check the outer id and signature after fetching an event from an untrusted relay.
|
|
146
|
+
|
|
147
|
+
Passing `expectedKind` matters because v1 proofs are not bound to the event kind; see [Proof v2](#proof-v2).
|
|
119
148
|
|
|
120
149
|
---
|
|
121
150
|
|
|
@@ -171,6 +200,7 @@ The resulting `assertion` is a plain `EventTemplate` you sign and publish like a
|
|
|
171
200
|
| `createDeploymentPolicy(profile, options)` | Build a fail-closed deployment policy with accepted circles, expected subject, metric bounds, freshness, threshold, signature requirements, and optional companion evidence requirements |
|
|
172
201
|
| `verifyDeploymentPolicy(events, policy, options?)` | Verify a profile plus deployment-specific controls and supplied companion evidence before acting on a score |
|
|
173
202
|
| `createSignedDeploymentBundle(policy, options)` | Sign a deployment policy and its manifests as trusted operator configuration |
|
|
203
|
+
| `verifySignedDeploymentBundle(bundle, options?)` | Verify only the bundle: shape, expiry and future-`issuedAt` against `now`, the signer's BIP-340 signature, and `trustedPublishers`. Does not look at any events |
|
|
174
204
|
| `verifyDeploymentBundle(events, bundle, options?)` | Verify a signed bundle from trusted publishers, then verify the bundled deployment policy |
|
|
175
205
|
| `verifyProductionDeployment(events, bundle, options?)` | One-call production gate that also requires an expiring bundle and signed relay-fetched events by default |
|
|
176
206
|
| `createProductionDecisionReport(result)`, `verifyProductionDeploymentReport(events, bundle, options?)` | Produce an audit/UI-ready decision report with recommended action, issue remediation, and control status |
|
|
@@ -186,7 +216,7 @@ The resulting `assertion` is a plain `EventTemplate` you sign and publish like a
|
|
|
186
216
|
| `canonicalRelaySubject`, `canonicalServiceSubject`, `canonicalNip05Subject`, `canonicalDomainSubject`, `canonicalLnurlpSubject`, `canonicalNip96Subject`, `canonicalNpmPackageSubject`, `canonicalPackageDigestSubject`, `canonicalGitRepositorySubject`, `canonicalGithubRepositorySubject`, `canonicalMaintainerSubject` | Canonical subject helpers for common real-world identifiers |
|
|
187
217
|
| `canonicalPubkeySubject`, `canonicalEventSubject`, `canonicalAddressSubject` | Canonical subject helpers for Nostr-native subjects |
|
|
188
218
|
|
|
189
|
-
Freshness checks in `verifyCircleManifest`, `verifyDeploymentBundle`,
|
|
219
|
+
Freshness checks in `verifyCircleManifest`, `verifySignedDeploymentBundle`, `verifyDeploymentBundle`,
|
|
190
220
|
`verifyAdmissionPresentation`, and the verifiers built on them are fail closed:
|
|
191
221
|
expiry and future-`issuedAt` checks run against the current time unless you
|
|
192
222
|
pass an explicit `now` (intended for tests and historical verification).
|
|
@@ -210,14 +240,130 @@ can fetch or normalise the observation for you, and the resolver helpers when
|
|
|
210
240
|
your application already has registry, service, or list observations from its
|
|
211
241
|
own infrastructure. Avoid hand-written `pass` records in production.
|
|
212
242
|
|
|
213
|
-
###
|
|
243
|
+
### Root export (`nostr-veil`) -- everything, plus signing
|
|
244
|
+
|
|
245
|
+
The root entry point re-exports all of `nostr-veil/nip85`, `nostr-veil/proof` and `nostr-veil/profiles`, and adds the signing helpers below. One `import ... from 'nostr-veil'` reaches every export in this reference; the subpath exports exist only so you can import a single layer. The signing helpers are available from the root only.
|
|
214
246
|
|
|
215
247
|
| Export | Description |
|
|
216
248
|
|--------|-------------|
|
|
217
|
-
| `signEvent(template, privateKey)` | Sign an unsigned event template with BIP-340 Schnorr -- returns a complete `SignedEvent` |
|
|
249
|
+
| `signEvent(template, privateKey)` | Sign an unsigned event template with BIP-340 Schnorr (`privateKey` is a 64-char hex string) -- returns a complete `SignedEvent` |
|
|
218
250
|
| `verifySignedEvent(event)` | Verify a signed Nostr event id and BIP-340 signature after fetching from an untrusted relay |
|
|
219
251
|
| `computeEventId(event)` | Compute the NIP-01 event ID (SHA-256 of canonical serialisation) |
|
|
220
252
|
|
|
253
|
+
### Options and types
|
|
254
|
+
|
|
255
|
+
**Metrics.** Contributions take `Record<string, number>`. Values must be finite (`NaN` and `Infinity` throw `Metric "<key>" must be a finite number`); integers are not required, and the published tag is `String(value)`. Metric names must not be a single character, start with `veil-`, be a Nostr tag with its own meaning (`expiration`, `alt`, `client`, `nonce`, `content-warning`), or be `__proto__`: contributing throws `Metric name "<name>" is reserved: ...`, aggregation rejects such a contribution, and `verifyProof` rejects an event whose signed metrics use one. This stops a single circle member from injecting a tag such as `expiration` into the published event. By default `verifyProof` accepts at most 128 metrics per signed message and names up to 64 characters. The `nostr-veil/nip85` builders take typed metrics instead (all fields optional): `UserMetrics` (kind 30382: `followers`, `rank`, `first_created_at`, `post_cnt`, `reply_cnt`, `reactions_cnt`, `zap_amt_recd`, `zap_amt_sent`, `zap_cnt_recd`, `zap_cnt_sent`, `zap_avg_amt_day_recd`, `zap_avg_amt_day_sent`, `reports_cnt_recd`, `reports_cnt_sent`, `t` (string), `active_hours_start`, `active_hours_end`), `EventMetrics` (kinds 30383 and 30384: `rank`, `comment_cnt`, `quote_cnt`, `repost_cnt`, `reaction_cnt`, `zap_cnt`, `zap_amount`) and `IdentifierMetrics` (kind 30385: `rank`, `comment_cnt`, `reaction_cnt`).
|
|
256
|
+
|
|
257
|
+
**Aggregation options.** The `options` argument of `aggregateContributions` and the typed `aggregate*Contributions` helpers is either a bare function `(values: number[]) => number` or an object:
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
{
|
|
261
|
+
aggregate?: 'median' | 'mean' | 'sum' | 'min' | 'max' // built-in, default 'median'
|
|
262
|
+
aggregateFn?: (values: number[]) => number // custom; ignored if `aggregate` is set
|
|
263
|
+
proofVersion?: 'v1' | 'v2' // default 'v1'
|
|
264
|
+
kind?: number // aggregateContributions only; legacy, default 30382
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
`median` and `mean` round to an integer; `sum`, `min` and `max` do not. A non-finite result throws, and an unknown `aggregate` name throws `Unknown aggregate function: <name>`. A built-in name is written to the `veil-agg` tag and `verifyProof` reads it from there, so verifying a summed tally needs no option: `aggregateContributions(circle, subject, contributions, { aggregate: 'sum' })` verifies with a bare `verifyProof(event)`. A custom function is written as `veil-agg: custom` and must be passed to the verifier too (`verifyProof(event, { aggregateFn })` or a bare function), otherwise it fails with `veil-agg is "custom": pass the aggregate function via options to verify the metric tags`.
|
|
269
|
+
|
|
270
|
+
**`verifyProof(event, options?)`.** `options` is a bare aggregate function or an object `{ aggregateFn?, expectedKind?, requireProofVersion?, limits? }`:
|
|
271
|
+
|
|
272
|
+
| Option | Type | Meaning |
|
|
273
|
+
|--------|------|---------|
|
|
274
|
+
| `aggregateFn` | `(values: number[]) => number` | Needed only when `veil-agg` is `custom` |
|
|
275
|
+
| `expectedKind` | `number` | Reject events of any other NIP-85 kind. Recommended for v1 proofs, which are not kind-bound |
|
|
276
|
+
| `requireProofVersion` | `'v1' \| 'v2'` | Reject signatures of the other proof version |
|
|
277
|
+
| `limits` | `Partial<VerifyLimits>` | Override `DEFAULT_VERIFY_LIMITS`: `maxRingSize` 1000, `maxSigPayloadBytes` 128000, `maxSignedMessageBytes` 16384, `maxMetricCount` 128, `maxMetricNameLength` 64 |
|
|
278
|
+
|
|
279
|
+
It returns `{ valid, circleSize, threshold, distinctSigners, errors }`.
|
|
280
|
+
|
|
281
|
+
**`contributeAssertion` options and `canonicalMessageV2`.** `contributeAssertion(..., options?)` takes `{ proofVersion?: 'v1' | 'v2', kind?: number, subjectTag?: 'p' | 'e' | 'a' | 'k', subjectTagValue?: string }`; for v2 the defaults are kind 30382, tag `p` and the subject itself. The typed helpers (`contributeEventAssertion`, `contributeAddressableAssertion`, `contributeIdentifierAssertion`) take only `{ proofVersion?: 'v1' | 'v2' }` and fill in the kind and tag. `canonicalMessageV2(circleId, subject, metrics, context)` takes `context` as `{ kind, subjectTag, subjectTagValue }`, all required: `kind` a non-negative safe integer, `subjectTag` one of `p`, `e`, `a`, `k`, and `subjectTagValue` a non-empty string.
|
|
282
|
+
|
|
283
|
+
**NIP-85 parse results.** `parseAssertion(event)` returns `{ kind: number, subject: string, metrics: Record<string, string | number> }`: `subject` is the `d` tag value (empty string if absent) and `metrics` holds every tag except `d`, `p`, `e`, `a`, `k` and `veil-*`; the values are the raw tag strings. `parseProviderDeclaration(event)` returns `ParsedProvider[]`, each `{ kind: number, metric: string, servicePubkey: string, relayHint: string }` (the same shape as the `ProviderEntry` passed to `buildProviderDeclaration`). With a `decryptFn: (ciphertext: string) => Promise<string>` it returns a `Promise<ParsedProvider[]>`.
|
|
284
|
+
|
|
285
|
+
**Profiles options.** All timestamps are Unix seconds. `now` defaults to the current time wherever it appears.
|
|
286
|
+
|
|
287
|
+
| Function | Options |
|
|
288
|
+
|----------|---------|
|
|
289
|
+
| `createCircleManifest(options)` | Required: `issuedAt`, `members`, `name`, `profileIds`, `purpose`. Optional: `expiresAt`, `status` (`'active' \| 'revoked' \| 'superseded'`), `supersedes`, `revokedCircleIds`, `contact`, `evidenceProcess`, `policyUri` |
|
|
290
|
+
| `verifyCircleManifest(manifest, options?)` | `allowSuperseded`, `now`, `profileId`, `revokedCircleIds` |
|
|
291
|
+
| `createDeploymentPolicy(profile, options)` | Required: `expectedSubject`, plus at least one active circle from `acceptedCircleIds` or `circleManifests`. Optional: `expectedSubjectTagValue`, `id` (default: the profile id), `maxAgeSeconds` and `minDistinctSigners` (default: the profile's), `metricPolicies` (`{ [metric]: { required?, min?, max?, integer? } }`), `rejectUnknownMetrics` (default `false`), `requireNostrSignature` (default `false`), `companionEvidence`, `allowSupersededCircleIds` (default `false`), `now` |
|
|
292
|
+
| `createSignedDeploymentBundle(policy, options)` | Required: `id`, `issuedAt`, `privateKey` (hex). Optional: `expiresAt` (must be greater than `issuedAt`). Returns a frozen bundle carrying the `signer` pubkey and `signature` |
|
|
293
|
+
| `verifyUseCaseProfile(events, profile, options?)` | `acceptedCircleIds`, `aggregateFn`, `expectedSubject`, `expectedSubjectTagValue`, `maxAgeSeconds`, `minDistinctSigners`, `now`, `requireKnownCircle` (fails when no accepted circle is supplied unless set to `false`) |
|
|
294
|
+
| `verifyDeploymentPolicy(events, policy, options?)` | `aggregateFn`, `companionEvidence` (the supplied `CompanionEvidence[]`), `now` |
|
|
295
|
+
| `verifySignedDeploymentBundle(bundle, options?)` | `now`, `trustedPublishers` |
|
|
296
|
+
| `verifyDeploymentBundle(events, bundle, options?)` | The `verifyDeploymentPolicy` options plus `trustedPublishers` |
|
|
297
|
+
| `verifyProductionDeployment(events, bundle, options?)` | The `verifyDeploymentBundle` options plus `requireBundleExpiry` and `requireSignedEvents`, both `true` unless set to `false` |
|
|
298
|
+
|
|
299
|
+
`trustedPublishers` is effectively required for bundle verification: without at least one valid pubkey it fails with `no trusted bundle publishers configured`. `verifyProductionDeployment` returns the bundle and policy results plus `{ decision: 'accept' | 'reject', valid, errors, issues }`.
|
|
300
|
+
|
|
301
|
+
### Profiles example
|
|
302
|
+
|
|
303
|
+
A production verifier pins the operator's publisher pubkey, loads a signed deployment bundle, and checks fetched assertions against it. This continues from the quick start (`alice`, `bob`, `carol`, `circle`, `subjectPubkey`, `aggregator`). The built-in `USER_REPUTATION_ABUSE_REPORTING_PROFILE` (id `user-reputation-abuse-reporting`) requires proof v2, at least three distinct signers, and an assertion no older than 300 seconds, so the contributions below are v2 and all three members sign.
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
import {
|
|
307
|
+
USER_REPUTATION_ABUSE_REPORTING_PROFILE,
|
|
308
|
+
createDeploymentPolicy,
|
|
309
|
+
createSignedDeploymentBundle,
|
|
310
|
+
verifyProductionDeployment,
|
|
311
|
+
} from 'nostr-veil/profiles'
|
|
312
|
+
|
|
313
|
+
const operator = generateKeypair() // the deployment operator, separate from circle members
|
|
314
|
+
|
|
315
|
+
// Three members contribute with proof v2, then the aggregator signs and publishes
|
|
316
|
+
const contributions = [alice, bob, carol].map(member => contributeAssertion(
|
|
317
|
+
circle, subjectPubkey, { rank: 80 }, member.privkey, circle.members.indexOf(member.pubkey), { proofVersion: 'v2' },
|
|
318
|
+
))
|
|
319
|
+
const event = signEvent(
|
|
320
|
+
aggregateContributions(circle, subjectPubkey, contributions, { proofVersion: 'v2' }),
|
|
321
|
+
aggregator.privkey,
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
// The operator builds a policy and signs it as a bundle
|
|
325
|
+
const policy = createDeploymentPolicy(USER_REPUTATION_ABUSE_REPORTING_PROFILE, {
|
|
326
|
+
acceptedCircleIds: [circle.circleId],
|
|
327
|
+
expectedSubject: subjectPubkey,
|
|
328
|
+
requireNostrSignature: true, // verifyProductionDeployment rejects a policy without this
|
|
329
|
+
})
|
|
330
|
+
const now = Math.floor(Date.now() / 1000)
|
|
331
|
+
const bundle = createSignedDeploymentBundle(policy, {
|
|
332
|
+
id: 'abuse-reporting-2026-01',
|
|
333
|
+
issuedAt: now,
|
|
334
|
+
expiresAt: now + 24 * 60 * 60, // verifyProductionDeployment rejects a bundle without expiry
|
|
335
|
+
privateKey: operator.privkey,
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
// The verifier pins the operator's pubkey and checks the fetched events
|
|
339
|
+
const verdict = verifyProductionDeployment([event], bundle, { trustedPublishers: [operator.pubkey] })
|
|
340
|
+
// verdict.decision === 'accept', verdict.valid === true, verdict.errors === []
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
A bundle signed by any other key fails with the issue code `bundle.signer_untrusted`. For the other built-in profiles, companion evidence and the report helpers, see [examples/production-recipes.ts](./examples/production-recipes.ts), which runs six production-shaped gates (`npm run test:production-recipes`).
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## CLI
|
|
348
|
+
|
|
349
|
+
Installing the package puts a `nostr-veil` binary on your path (`npx nostr-veil --help` also works).
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
nostr-veil assert user <pubkey> [--json '<metrics>']
|
|
353
|
+
nostr-veil assert event <event-id> [--json '<metrics>']
|
|
354
|
+
nostr-veil assert address <address> [--json '<metrics>']
|
|
355
|
+
nostr-veil assert identifier <id> <k-tag> [--json '<metrics>']
|
|
356
|
+
nostr-veil provider-declare [--json '<entries>']
|
|
357
|
+
nostr-veil verify '<event-json>' [--kind <n>]
|
|
358
|
+
nostr-veil --help
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
- `assert` builds a plain NIP-85 assertion (kind 30382, 30383, 30384 or 30385 respectively) and signs it with one key. It does not make ring signatures; use the library for that. `--json` takes a JSON object of metrics, for example `--json '{"rank":74}'`. Without it the metrics are empty.
|
|
362
|
+
- `provider-declare` builds and signs a kind 10040 provider declaration. `--json` takes a JSON array of `{ kind, metric, servicePubkey, relayHint }` entries.
|
|
363
|
+
- `assert` and `provider-declare` read the signing key from `NOSTR_SECRET_KEY` (64-char hex) or from the file named by `NOSTR_SECRET_KEY_FILE`, which takes precedence. They print the signed event as JSON on stdout, ready to pipe to a relay publisher.
|
|
364
|
+
- `verify` needs no key. `<event-json>` is the event itself as an inline JSON string, not a file path, and it must be the first argument after `verify` (for a file use `nostr-veil verify "$(cat event.json)" --kind 30382`). The event must be a JSON object with a `tags` array. `--kind <n>` takes a non-negative integer and applies the `expectedKind` check; it is recommended for v1 proofs.
|
|
365
|
+
- `verify` prints the `verifyProof` result as JSON. It exits 0 even when `valid` is `false`, and exits 1 only for bad arguments or unparseable JSON, so read the `valid` field rather than the exit code.
|
|
366
|
+
|
|
221
367
|
---
|
|
222
368
|
|
|
223
369
|
## How it works
|
|
@@ -228,7 +374,7 @@ The published event carries extra tags on top of the standard NIP-85 format:
|
|
|
228
374
|
|
|
229
375
|
- `veil-ring` -- the full list of circle members (the group who could have contributed)
|
|
230
376
|
- `veil-threshold` -- how many members actually contributed vs. total circle size
|
|
231
|
-
- `veil-agg` -- which aggregate function produced the metric tags
|
|
377
|
+
- `veil-agg` -- which aggregate function produced the metric tags: `median` (default), `mean`, `sum`, `min`, `max`, or `custom`
|
|
232
378
|
- `veil-sig` (one per contributor) -- the ring signature and a duplicate-detection token
|
|
233
379
|
- `veil-version` -- present only for opt-in proof v2 events
|
|
234
380
|
- `veil-scope` -- present only for a federated circle; see [Cross-circle deduplication](#cross-circle-deduplication)
|
|
@@ -242,7 +388,7 @@ A verifier calls `verifyProof`, which:
|
|
|
242
388
|
|
|
243
389
|
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.
|
|
244
390
|
|
|
245
|
-
|
|
391
|
+
Aggregation is median by default. Pass `{ aggregate: 'mean' | 'sum' | 'min' | 'max' }` to `aggregateContributions` (or any typed `aggregate*Contributions` helper) to choose another built-in. The name is recorded in the `veil-agg` tag and `verifyProof` reads it from there, so a summed tally verifies with a bare `verifyProof(event)`. Only a custom function (`{ aggregateFn }`, recorded as `veil-agg: custom`) must be passed to `verifyProof` as well, otherwise verification fails. See [Options and types](#options-and-types).
|
|
246
392
|
|
|
247
393
|
### Proof v2
|
|
248
394
|
|
|
@@ -250,20 +396,26 @@ The original proof format remains the default. It signs the circle ID, the `d`-t
|
|
|
250
396
|
|
|
251
397
|
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.
|
|
252
398
|
|
|
399
|
+
This continues from the [Quick start](#quick-start): `alice` and `circle` are defined there. `eventId` is the 64-char lowercase hex id of the Nostr event being assessed; the typed helpers throw if it is not.
|
|
400
|
+
|
|
253
401
|
```ts
|
|
254
402
|
import { contributeEventAssertion, aggregateEventContributions, verifyProof } from 'nostr-veil'
|
|
255
403
|
|
|
404
|
+
const eventId = '0123456789abcdef'.repeat(4) // placeholder: use the real event id
|
|
405
|
+
|
|
256
406
|
const contribution = contributeEventAssertion(
|
|
257
407
|
circle,
|
|
258
408
|
eventId,
|
|
259
409
|
{ rank: 90 },
|
|
260
|
-
|
|
261
|
-
circle.members.indexOf(
|
|
410
|
+
alice.privkey,
|
|
411
|
+
circle.members.indexOf(alice.pubkey),
|
|
262
412
|
{ proofVersion: 'v2' },
|
|
263
413
|
)
|
|
264
414
|
|
|
265
|
-
|
|
266
|
-
const
|
|
415
|
+
// One contribution keeps the example short; a real workflow collects several.
|
|
416
|
+
const eventAssertion = aggregateEventContributions(circle, eventId, [contribution], { proofVersion: 'v2' })
|
|
417
|
+
const eventResult = verifyProof(eventAssertion, { requireProofVersion: 'v2' })
|
|
418
|
+
// { valid: true, circleSize: 3, threshold: 1, distinctSigners: 1, errors: [] }
|
|
267
419
|
```
|
|
268
420
|
|
|
269
421
|
Old v1 events still verify without changes. Use `requireProofVersion: 'v2'` only when your application policy wants to reject legacy proofs for that workflow.
|
|
@@ -275,10 +427,11 @@ example, a user assertion re-tagged as an event assertion) and still pass bare
|
|
|
275
427
|
fails unless the event carries the kind your workflow expects:
|
|
276
428
|
|
|
277
429
|
```ts
|
|
430
|
+
// `assertion` is the v1 user assertion from the Quick start
|
|
278
431
|
const result = verifyProof(assertion, { expectedKind: NIP85_KINDS.USER })
|
|
279
432
|
```
|
|
280
433
|
|
|
281
|
-
The CLI equivalent is `nostr-veil verify <event-json> --kind 30382
|
|
434
|
+
The CLI equivalent is `nostr-veil verify '<event-json>' --kind 30382`; see [CLI](#cli).
|
|
282
435
|
|
|
283
436
|
---
|
|
284
437
|
|
package/dist/nip85/builders.d.ts
CHANGED
|
@@ -41,13 +41,13 @@ export declare function buildAddressableAssertion(address: string, metrics: Even
|
|
|
41
41
|
/**
|
|
42
42
|
* Build a kind 30385 identifier assertion with an explicit k-tag.
|
|
43
43
|
*
|
|
44
|
-
* @param identifier -
|
|
45
|
-
* @param kTag - The
|
|
44
|
+
* @param identifier - NIP-73 identifier used as the `d`-tag value, such as a normalised URL or `isbn:<id>`
|
|
45
|
+
* @param kTag - The NIP-73 identifier type: `web`, `isbn`, `geo`, `doi`, `podcast:guid`, `<blockchain>:tx` and so on
|
|
46
46
|
* @param metrics - {@link IdentifierMetrics} to embed as tags (undefined values are omitted)
|
|
47
47
|
* @returns An unsigned {@link EventTemplate} with `d` and `k` tags set accordingly
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
50
|
-
* const tmpl = buildIdentifierAssertion('
|
|
50
|
+
* const tmpl = buildIdentifierAssertion('https://example.com/article', 'web', { rank: 60, reaction_cnt: 15 })
|
|
51
51
|
* const event = signEvent(tmpl, providerPrivkey)
|
|
52
52
|
* await relay.publish(event)
|
|
53
53
|
*/
|
package/dist/nip85/builders.js
CHANGED
|
@@ -81,13 +81,13 @@ export function buildAddressableAssertion(address, metrics) {
|
|
|
81
81
|
/**
|
|
82
82
|
* Build a kind 30385 identifier assertion with an explicit k-tag.
|
|
83
83
|
*
|
|
84
|
-
* @param identifier -
|
|
85
|
-
* @param kTag - The
|
|
84
|
+
* @param identifier - NIP-73 identifier used as the `d`-tag value, such as a normalised URL or `isbn:<id>`
|
|
85
|
+
* @param kTag - The NIP-73 identifier type: `web`, `isbn`, `geo`, `doi`, `podcast:guid`, `<blockchain>:tx` and so on
|
|
86
86
|
* @param metrics - {@link IdentifierMetrics} to embed as tags (undefined values are omitted)
|
|
87
87
|
* @returns An unsigned {@link EventTemplate} with `d` and `k` tags set accordingly
|
|
88
88
|
*
|
|
89
89
|
* @example
|
|
90
|
-
* const tmpl = buildIdentifierAssertion('
|
|
90
|
+
* const tmpl = buildIdentifierAssertion('https://example.com/article', 'web', { rank: 60, reaction_cnt: 15 })
|
|
91
91
|
* const event = signEvent(tmpl, providerPrivkey)
|
|
92
92
|
* await relay.publish(event)
|
|
93
93
|
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tags that any Nostr event may carry and that are never NIP-85 metrics:
|
|
3
|
+
* NIP-40 `expiration`, NIP-31 `alt`, NIP-89 `client`, NIP-32 `L`/`l` labels,
|
|
4
|
+
* the NIP-73 `i` identifier, the NIP-70 `-` protected marker and the NIP-13
|
|
5
|
+
* `nonce`. Strict validation does not read them as metrics, and the proof
|
|
6
|
+
* layer reserves them so they can never be signed as metrics.
|
|
7
|
+
*
|
|
8
|
+
* Internal: not re-exported from `nostr-veil/nip85`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const GENERAL_TAGS: ReadonlySet<string>;
|
|
11
|
+
//# sourceMappingURL=tags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../../src/nip85/tags.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,MAAM,CAS3C,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tags that any Nostr event may carry and that are never NIP-85 metrics:
|
|
3
|
+
* NIP-40 `expiration`, NIP-31 `alt`, NIP-89 `client`, NIP-32 `L`/`l` labels,
|
|
4
|
+
* the NIP-73 `i` identifier, the NIP-70 `-` protected marker and the NIP-13
|
|
5
|
+
* `nonce`. Strict validation does not read them as metrics, and the proof
|
|
6
|
+
* layer reserves them so they can never be signed as metrics.
|
|
7
|
+
*
|
|
8
|
+
* Internal: not re-exported from `nostr-veil/nip85`.
|
|
9
|
+
*/
|
|
10
|
+
export const GENERAL_TAGS = new Set([
|
|
11
|
+
'expiration',
|
|
12
|
+
'alt',
|
|
13
|
+
'client',
|
|
14
|
+
'L',
|
|
15
|
+
'l',
|
|
16
|
+
'i',
|
|
17
|
+
'-',
|
|
18
|
+
'nonce',
|
|
19
|
+
]);
|
|
20
|
+
//# sourceMappingURL=tags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../../src/nip85/tags.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC;IACvD,YAAY;IACZ,KAAK;IACL,QAAQ;IACR,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,OAAO;CACR,CAAC,CAAA"}
|
|
@@ -18,8 +18,11 @@ export interface ValidationOptions {
|
|
|
18
18
|
* - `kind` is one of the four NIP-85 assertion kinds (30382–30385)
|
|
19
19
|
* - A `d` tag is present
|
|
20
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
|
-
*
|
|
21
|
+
* - when `{ strict: true }` is passed, kind-specific metric names are checked,
|
|
22
|
+
* optional subject hint tags (`p`, `e`, `a`) are validated if present, kind
|
|
23
|
+
* 30385 needs one non-empty NIP-73 `k` type, and general-purpose tags
|
|
24
|
+
* (`expiration`, `alt`, `client`, `L`, `l`, `i`, `-`, `nonce`) are not read
|
|
25
|
+
* as metrics; `expiration`, if present, must be one unix timestamp
|
|
23
26
|
*
|
|
24
27
|
* @param event - A raw Nostr event with `kind`, `tags`, and `content` fields
|
|
25
28
|
* @param options - Optional validation mode. Strict mode is additive and opt-in.
|
|
@@ -31,7 +34,7 @@ export interface ValidationOptions {
|
|
|
31
34
|
* console.error('Validation failed:', result.errors)
|
|
32
35
|
* }
|
|
33
36
|
*/
|
|
34
|
-
export declare function validateAssertion(
|
|
37
|
+
export declare function validateAssertion(input: RawEvent, options?: ValidationOptions): ValidationResult;
|
|
35
38
|
/**
|
|
36
39
|
* Strict NIP-85 assertion validation. This is equivalent to
|
|
37
40
|
* `validateAssertion(event, { strict: true })`.
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/nip85/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAWlD,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;AAkND;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CA4CpG;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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NIP85_KINDS } from './types.js';
|
|
2
|
+
import { GENERAL_TAGS } from './tags.js';
|
|
2
3
|
const ASSERTION_KINDS = new Set([
|
|
3
4
|
NIP85_KINDS.USER,
|
|
4
5
|
NIP85_KINDS.EVENT,
|
|
@@ -7,6 +8,8 @@ const ASSERTION_KINDS = new Set([
|
|
|
7
8
|
]);
|
|
8
9
|
const HEX64_RE = /^[0-9a-f]{64}$/;
|
|
9
10
|
const DECIMAL_INTEGER_RE = /^(0|[1-9]\d*)$/;
|
|
11
|
+
// NIP-73 types are short printable ASCII: web, isbn, podcast:guid, <chain>:tx
|
|
12
|
+
const NIP73_K_RE = /^[\x21-\x7e]{1,64}$/;
|
|
10
13
|
const ADDRESS_RE = /^(0|[1-9]\d*):[0-9a-f]{64}:.*$/;
|
|
11
14
|
const PROVIDER_TAG_RE = /^(0|[1-9]\d*):[A-Za-z0-9_.-]+$/;
|
|
12
15
|
const RELAY_HINT_RE = /^wss?:\/\/.+$/i;
|
|
@@ -85,13 +88,14 @@ function requireSingletonTag(event, name, errors) {
|
|
|
85
88
|
return values[0];
|
|
86
89
|
}
|
|
87
90
|
function validateOptionalMatchingTag(event, name, subject, errors) {
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
// Count every tag with this name, including ones with a missing or non-string value
|
|
92
|
+
const tags = event.tags.filter(t => t[0] === name);
|
|
93
|
+
if (tags.length === 0)
|
|
90
94
|
return;
|
|
91
|
-
if (
|
|
95
|
+
if (tags.length > 1) {
|
|
92
96
|
errors.push(`Duplicate ${name}-tag.`);
|
|
93
97
|
}
|
|
94
|
-
if (
|
|
98
|
+
if (tags.some(t => t[1] !== subject)) {
|
|
95
99
|
errors.push(`${name}-tag must match d-tag.`);
|
|
96
100
|
}
|
|
97
101
|
}
|
|
@@ -99,32 +103,39 @@ function validateStrictSubjectTags(event, errors) {
|
|
|
99
103
|
const subject = requireSingletonTag(event, 'd', errors);
|
|
100
104
|
if (subject === undefined)
|
|
101
105
|
return;
|
|
106
|
+
// NIP-85: p, e and a tags MAY repeat the d value as a relay hint, on any kind.
|
|
107
|
+
// i (relay-indexed, NIP-73) is held to the same rule: on kind 30385 d is the i value.
|
|
108
|
+
for (const name of ['p', 'e', 'a', 'i'])
|
|
109
|
+
validateOptionalMatchingTag(event, name, subject, errors);
|
|
110
|
+
if (event.kind !== NIP85_KINDS.IDENTIFIER && tagValues(event, 'k').length > 1) {
|
|
111
|
+
errors.push('Duplicate k-tag.');
|
|
112
|
+
}
|
|
102
113
|
switch (event.kind) {
|
|
103
114
|
case NIP85_KINDS.USER:
|
|
104
115
|
if (!HEX64_RE.test(subject)) {
|
|
105
116
|
errors.push('User assertion d-tag must be a 64-character lowercase hex pubkey.');
|
|
106
117
|
}
|
|
107
|
-
validateOptionalMatchingTag(event, 'p', subject, errors);
|
|
108
118
|
break;
|
|
109
119
|
case NIP85_KINDS.EVENT:
|
|
110
120
|
if (!HEX64_RE.test(subject)) {
|
|
111
121
|
errors.push('Event assertion d-tag must be a 64-character lowercase hex event id.');
|
|
112
122
|
}
|
|
113
|
-
validateOptionalMatchingTag(event, 'e', subject, errors);
|
|
114
123
|
break;
|
|
115
124
|
case NIP85_KINDS.ADDRESSABLE:
|
|
116
125
|
if (!ADDRESS_RE.test(subject)) {
|
|
117
126
|
errors.push('Addressable assertion d-tag must be a NIP-33 address: kind:pubkey:d-tag.');
|
|
118
127
|
}
|
|
119
|
-
validateOptionalMatchingTag(event, 'a', subject, errors);
|
|
120
128
|
break;
|
|
121
129
|
case NIP85_KINDS.IDENTIFIER: {
|
|
122
130
|
if (subject === '') {
|
|
123
131
|
errors.push('Identifier assertion d-tag must be non-empty.');
|
|
124
132
|
}
|
|
133
|
+
// NIP-73 `k` is the identifier type (`web`, `isbn`, `podcast:guid`,
|
|
134
|
+
// `<blockchain>:tx` and so on), not a kind number. NIP-73 grows new
|
|
135
|
+
// types, so any short printable-ASCII value without spaces is accepted.
|
|
125
136
|
const kTag = requireSingletonTag(event, 'k', errors);
|
|
126
|
-
if (kTag !== undefined && !
|
|
127
|
-
errors.push('Identifier assertion k-tag must be a
|
|
137
|
+
if (kTag !== undefined && !NIP73_K_RE.test(kTag)) {
|
|
138
|
+
errors.push('Identifier assertion k-tag must be a NIP-73 type of 1 to 64 printable ASCII characters without spaces, such as web or isbn.');
|
|
128
139
|
}
|
|
129
140
|
break;
|
|
130
141
|
}
|
|
@@ -143,6 +154,18 @@ function strictMetricSets(kind) {
|
|
|
143
154
|
return undefined;
|
|
144
155
|
}
|
|
145
156
|
}
|
|
157
|
+
function validateStrictGeneralTags(event, errors) {
|
|
158
|
+
const expirations = event.tags.filter(t => t[0] === 'expiration');
|
|
159
|
+
if (expirations.length === 0)
|
|
160
|
+
return;
|
|
161
|
+
if (expirations.length > 1) {
|
|
162
|
+
errors.push('Duplicate expiration-tag.');
|
|
163
|
+
}
|
|
164
|
+
const value = expirations[0][1];
|
|
165
|
+
if (typeof value !== 'string' || !DECIMAL_INTEGER_RE.test(value) || !Number.isSafeInteger(Number(value))) {
|
|
166
|
+
errors.push(`Invalid expiration-tag: "${value}". Must be a unix timestamp in seconds.`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
146
169
|
function validateStrictMetrics(event, errors) {
|
|
147
170
|
const allowed = strictMetricSets(event.kind);
|
|
148
171
|
if (allowed === undefined)
|
|
@@ -150,7 +173,11 @@ function validateStrictMetrics(event, errors) {
|
|
|
150
173
|
const seen = new Set();
|
|
151
174
|
for (const tag of event.tags) {
|
|
152
175
|
const name = tag[0];
|
|
153
|
-
if (
|
|
176
|
+
if (typeof name !== 'string') {
|
|
177
|
+
errors.push('Malformed tag: tag name must be a string.');
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (META_TAGS.has(name) || GENERAL_TAGS.has(name) || name.startsWith('veil-'))
|
|
154
181
|
continue;
|
|
155
182
|
if (seen.has(name)) {
|
|
156
183
|
errors.push(`Duplicate metric tag "${name}".`);
|
|
@@ -180,8 +207,11 @@ function validateStrictMetrics(event, errors) {
|
|
|
180
207
|
* - `kind` is one of the four NIP-85 assertion kinds (30382–30385)
|
|
181
208
|
* - A `d` tag is present
|
|
182
209
|
* - `rank`, if present, is a number in the range 0–100
|
|
183
|
-
* - when `{ strict: true }` is passed, kind-specific metric names are checked
|
|
184
|
-
*
|
|
210
|
+
* - when `{ strict: true }` is passed, kind-specific metric names are checked,
|
|
211
|
+
* optional subject hint tags (`p`, `e`, `a`) are validated if present, kind
|
|
212
|
+
* 30385 needs one non-empty NIP-73 `k` type, and general-purpose tags
|
|
213
|
+
* (`expiration`, `alt`, `client`, `L`, `l`, `i`, `-`, `nonce`) are not read
|
|
214
|
+
* as metrics; `expiration`, if present, must be one unix timestamp
|
|
185
215
|
*
|
|
186
216
|
* @param event - A raw Nostr event with `kind`, `tags`, and `content` fields
|
|
187
217
|
* @param options - Optional validation mode. Strict mode is additive and opt-in.
|
|
@@ -193,8 +223,17 @@ function validateStrictMetrics(event, errors) {
|
|
|
193
223
|
* console.error('Validation failed:', result.errors)
|
|
194
224
|
* }
|
|
195
225
|
*/
|
|
196
|
-
export function validateAssertion(
|
|
226
|
+
export function validateAssertion(input, options = {}) {
|
|
197
227
|
const errors = [];
|
|
228
|
+
// Fail closed rather than throw on relay-supplied junk: drop malformed tags and report them
|
|
229
|
+
if (input === null || typeof input !== 'object' || !Array.isArray(input.tags)) {
|
|
230
|
+
return { valid: false, errors: ['Malformed event: tags must be an array.'] };
|
|
231
|
+
}
|
|
232
|
+
const wellFormed = input.tags.filter(t => Array.isArray(t) && typeof t[0] === 'string');
|
|
233
|
+
if (wellFormed.length !== input.tags.length) {
|
|
234
|
+
errors.push('Malformed tag: every tag must be an array whose name is a string.');
|
|
235
|
+
}
|
|
236
|
+
const event = { kind: input.kind, tags: wellFormed, content: input.content };
|
|
198
237
|
if (!ASSERTION_KINDS.has(event.kind)) {
|
|
199
238
|
errors.push(`Invalid kind: ${event.kind}. Must be one of 30382, 30383, 30384, 30385.`);
|
|
200
239
|
}
|
|
@@ -217,6 +256,7 @@ export function validateAssertion(event, options = {}) {
|
|
|
217
256
|
}
|
|
218
257
|
if (options.strict) {
|
|
219
258
|
validateStrictSubjectTags(event, errors);
|
|
259
|
+
validateStrictGeneralTags(event, errors);
|
|
220
260
|
validateStrictMetrics(event, errors);
|
|
221
261
|
}
|
|
222
262
|
return { valid: errors.length === 0, errors };
|
|
@@ -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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