ncc-06-js 0.3.0 → 0.3.2
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/DOCS.md +1 -1
- package/README.md +50 -3
- package/package.json +1 -1
package/DOCS.md
CHANGED
|
@@ -79,7 +79,7 @@ Utilities for locator payload construction and evaluation.
|
|
|
79
79
|
- Reads a config block (`k.mode`) and returns the expected `k` string for static/generate/tls modes; used by the sidecar.
|
|
80
80
|
|
|
81
81
|
### Key helpers
|
|
82
|
-
- `generateKeypair()`, `toNpub()`, `fromNsec()` wrap `nostr-tools` key utilities for convenience.
|
|
82
|
+
- `generateKeypair()`, `toNpub()`, `fromNpub()`, `toNsec()`, `fromNsec()` wrap `nostr-tools` key utilities for convenience.
|
|
83
83
|
- `ensureSelfSignedCert(options)` generates a self-signed cert for local `wss://` endpoints.
|
|
84
84
|
|
|
85
85
|
## Endpoint helpers
|
package/README.md
CHANGED
|
@@ -14,6 +14,14 @@ Reusable helpers extracted from the NCC-06 example relay, sidecar, and client im
|
|
|
14
14
|
...
|
|
15
15
|
- **Relay & Service mode helpers** (`getRelayMode`, `setRelayMode`) so you can control whether your service is *public* (publishes NCC-05 locators) or *private`.
|
|
16
16
|
|
|
17
|
+
## Why NCC-06? (Identity vs Location)
|
|
18
|
+
|
|
19
|
+
Unlike DNS, which binds a service to a **location** (domain/IP), NCC-06 binds a service to an **identity** (Public Key / Npub).
|
|
20
|
+
|
|
21
|
+
- **Portability:** Move your service to a new IP, Tor address, or provider instantly. Clients follow the *key*, not the server.
|
|
22
|
+
- **Censorship Resistance:** Discovery happens via decentralized relays, not centralized root servers.
|
|
23
|
+
- **Trust:** End-to-end authentication is built-in. The "K" fingerprint ensures the server you connect to is authorized by the identity you resolved.
|
|
24
|
+
|
|
17
25
|
## Usage
|
|
18
26
|
|
|
19
27
|
Install directly from the repository (example workspace):
|
|
@@ -27,6 +35,7 @@ npm install ../ncc-06-js
|
|
|
27
35
|
```js
|
|
28
36
|
import { resolveServiceEndpoint } from 'ncc-06-js';
|
|
29
37
|
|
|
38
|
+
// "Bootstrap Relays" act as the decentralized directory for finding the service's current location.
|
|
30
39
|
const resolution = await resolveServiceEndpoint({
|
|
31
40
|
bootstrapRelays: ['wss://relay.damus.io'],
|
|
32
41
|
servicePubkey: '...',
|
|
@@ -39,15 +48,53 @@ const resolution = await resolveServiceEndpoint({
|
|
|
39
48
|
console.log('Resolved API endpoint:', resolution.endpoint);
|
|
40
49
|
```
|
|
41
50
|
|
|
42
|
-
###
|
|
51
|
+
### Resolving a Tor Service via Npub
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import { resolveServiceEndpoint, fromNpub } from 'ncc-06-js';
|
|
55
|
+
|
|
56
|
+
const servicePubkey = fromNpub('npub1...');
|
|
57
|
+
|
|
58
|
+
const resolution = await resolveServiceEndpoint({
|
|
59
|
+
bootstrapRelays: ['wss://relay.damus.io'],
|
|
60
|
+
servicePubkey,
|
|
61
|
+
serviceId: 'relay',
|
|
62
|
+
locatorId: 'relay-locator',
|
|
63
|
+
torPreferred: true // Prefer .onion endpoints if available
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
console.log('Resolved Onion Endpoint:', resolution.endpoint);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Configuring an Onion Service Sidecar
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
import { buildExternalEndpoints, buildSidecarConfig } from 'ncc-06-js';
|
|
73
|
+
|
|
74
|
+
// 1. Build endpoints (detects Onion, IPv6, IPv4)
|
|
75
|
+
const endpoints = await buildExternalEndpoints({
|
|
76
|
+
tor: { enabled: true },
|
|
77
|
+
ensureOnionService: async () => ({ address: 'abcdef...', servicePort: 80 })
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// 2. Build config
|
|
81
|
+
const config = buildSidecarConfig({
|
|
82
|
+
secretKey: '...',
|
|
83
|
+
serviceUrl: 'ws://abcdef....onion', // Primary identity URL
|
|
84
|
+
externalEndpoints: endpoints,
|
|
85
|
+
serviceMode: 'public'
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Building a Service Config (No DNS)
|
|
43
90
|
|
|
44
91
|
```js
|
|
45
92
|
import { buildSidecarConfig } from 'ncc-06-js';
|
|
46
93
|
|
|
47
94
|
const config = buildSidecarConfig({
|
|
48
95
|
secretKey: '...',
|
|
49
|
-
serviceUrl: '
|
|
50
|
-
serviceId: 'my-
|
|
96
|
+
serviceUrl: 'tcp://203.0.113.1:9000', // Direct IP or any URI scheme
|
|
97
|
+
serviceId: 'my-custom-service',
|
|
51
98
|
serviceMode: 'public'
|
|
52
99
|
});
|
|
53
100
|
```
|