ncc-02-js 0.2.0 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,12 +25,15 @@ npm install ncc-02-js
25
25
  ```javascript
26
26
  import { NCC02Resolver } from 'ncc-02-js';
27
27
 
28
- const resolver = new NCC02Resolver(relay, [trustedCAPubkey]);
28
+ // Initialize with relay URLs and optional trusted CA pubkeys
29
+ const resolver = new NCC02Resolver(['wss://relay.damus.io'], {
30
+ trustedCAPubkeys: ['ca_pubkey_hex']
31
+ });
29
32
 
30
33
  try {
31
34
  const service = await resolver.resolve(ownerPubkey, 'api', {
32
35
  requireAttestation: true,
33
- minLevel: 'verified'
36
+ minLevel: 'verified' // 'self', 'verified', 'hardened'
34
37
  });
35
38
  console.log('Resolved endpoint:', service.endpoint);
36
39
  } catch (err) {
@@ -44,20 +47,69 @@ try {
44
47
  import { NCC02Builder } from 'ncc-02-js';
45
48
 
46
49
  const builder = new NCC02Builder(privateKey);
47
- const event = builder.createServiceRecord('api', 'https://api.example.com', 'sha256:fingerprint');
48
- // publish event to relays...
50
+
51
+ // Example 1: IP-based Service
52
+ const event = builder.createServiceRecord({
53
+ serviceId: 'media',
54
+ endpoint: 'https://203.0.113.45:8443',
55
+ fingerprint: 'sha256:fingerprint',
56
+ expiryDays: 14
57
+ });
58
+
59
+ // Example 2: Tor Onion Service
60
+ const onionEvent = builder.createServiceRecord({
61
+ serviceId: 'wallet',
62
+ endpoint: 'tcp://vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion:80',
63
+ fingerprint: 'sha256:fingerprint',
64
+ expiryDays: 7
65
+ });
66
+ // publish events to relays...
67
+ ```
68
+
69
+ ### 3. Issue an Attestation (CA)
70
+
71
+ ```javascript
72
+ const caBuilder = new NCC02Builder(caPrivateKey);
73
+ const attestation = caBuilder.createAttestation({
74
+ subjectPubkey: ownerPubkey,
75
+ serviceId: 'api',
76
+ serviceEventId: serviceRecordEventId,
77
+ level: 'verified',
78
+ validDays: 30
79
+ });
49
80
  ```
50
81
 
51
- ## API
82
+ ## Trust Model & Security
83
+
84
+ ### Trust Levels
85
+ - `self`: Asserted by the service owner (default if no attestation).
86
+ - `verified`: Attested by a trusted third party.
87
+ - `hardened`: Attested by a third party with stricter verification (e.g., physical proof or long-term history).
88
+
89
+ ### Threat Model
90
+ - **Endpoint Impersonation**: Prevented by binding the endpoint URI to a public key fingerprint (`k` tag).
91
+ - **Man-in-the-Middle (MITM)**: Mitigated via cryptographic pinning of transport-level keys.
92
+ - **Stale Records**: Limited by required expiry (`exp`) and support for revocations.
93
+ - **Relay Censorship**: Mitigated by querying multiple relays (implemented via `SimplePool`).
94
+
95
+ ### Fail-Closed Design
96
+ The library follows a fail-closed principle. If a policy requirement is not met (e.g., `requireAttestation: true` but no valid attestation is found), it throws an `NCC02Error` rather than returning a partially verified record.
97
+
98
+ ## API Reference
99
+
100
+ ### `NCC02Resolver(relays, options)`
101
+ - `relays`: Array of relay URLs.
102
+ - `options.pool`: (Optional) Existing `nostr-tools` SimplePool.
103
+ - `options.trustedCAPubkeys`: (Optional) Array of pubkeys trusted to issue attestations.
52
104
 
53
- ### `NCC02Resolver`
54
- - `resolve(pubkey, serviceId, options)`: Resolves and verifies a service record.
55
- - `verifyEndpoint(resolved, actualFingerprint)`: Helper to check if a connected endpoint matches the record.
105
+ #### `resolve(pubkey, serviceId, options)`
106
+ - `options.requireAttestation`: Fails if no trusted attestation is found.
107
+ - `options.minLevel`: Minimum trust level required.
56
108
 
57
- ### `NCC02Builder`
58
- - `createServiceRecord(id, uri, fingerprint, expiryDays)`
59
- - `createAttestation(subject, srv, eventId, level, validDays)`
60
- - `createRevocation(attestationId, reason)`
109
+ ### `NCC02Builder(privateKey)`
110
+ - `createServiceRecord({ serviceId, endpoint, fingerprint, expiryDays })`
111
+ - `createAttestation({ subjectPubkey, serviceId, serviceEventId, level, validDays })`
112
+ - `createRevocation({ attestationId, reason })`
61
113
 
62
114
  ## License
63
115