ncc-06-js 0.2.1 → 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/DOCS.md +6 -0
- package/README.md +1 -0
- package/index.d.ts +4 -0
- package/package.json +2 -2
- package/src/sidecar-config.js +27 -1
- package/test/sidecar-config.test.js +14 -1
package/DOCS.md
CHANGED
|
@@ -57,6 +57,12 @@ Utilities for locator payload construction and evaluation.
|
|
|
57
57
|
### `buildSidecarConfig(options)`
|
|
58
58
|
- Mirrors the example sidecar setup and derives `ncc02ExpectedKey`, `publishRelays`, and `torControl` from operator intent so you do not need to duplicate those scripts.
|
|
59
59
|
|
|
60
|
+
### `getRelayMode(config)`
|
|
61
|
+
- Returns the normalized `"public"` or `"private"` mode that drives whether the sidecar publishes NCC-05 locators.
|
|
62
|
+
|
|
63
|
+
### `setRelayMode(config, mode)`
|
|
64
|
+
- Normalizes and writes `"public"` or `"private"` back into the config object so you can persistively toggle the relay’s exposure level.
|
|
65
|
+
|
|
60
66
|
### `buildClientConfig(options)`
|
|
61
67
|
- Rehydrates the minimal client config that the example resolver expects; dedupes publication relays, enforces `serviceIdentityUri`, and carries the `expectedK` for NCC-02 pinning.
|
|
62
68
|
|
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ Reusable helpers extracted from the NCC-06 example relay, sidecar, and client im
|
|
|
13
13
|
- **Lightweight protocol helpers** (`parseNostrMessage`, `serializeNostrMessage`, `createReqMessage`) for downstream code that wants to reuse the same framing logic as the example client.
|
|
14
14
|
- **Sidecar config helpers** (`buildSidecarConfig`, `buildClientConfig`) so you can reuse the same config generation logic the example sidecar/client rely on without copying the scripts.
|
|
15
15
|
- **TypeScript definitions** (`index.d.ts`) that describe every exported helper, making it easier to import from TypeScript consumers.
|
|
16
|
+
- **Relay mode helpers** (`getRelayMode`, `setRelayMode`) so you can portrait whether your relay is *public* (publishes NCC-05 locators) or *private* (only maintains an NCC-02 record without advertising endpoints).
|
|
16
17
|
|
|
17
18
|
## Usage
|
|
18
19
|
|
package/index.d.ts
CHANGED
|
@@ -214,6 +214,7 @@ declare module 'ncc-06-js' {
|
|
|
214
214
|
externalEndpoints?: Record<string, unknown>;
|
|
215
215
|
k?: KConfig;
|
|
216
216
|
baseDir?: string;
|
|
217
|
+
relayMode?: 'public' | 'private';
|
|
217
218
|
ncc02ExpectedKeySource?: string;
|
|
218
219
|
}
|
|
219
220
|
export interface SidecarConfig {
|
|
@@ -232,8 +233,11 @@ declare module 'ncc-06-js' {
|
|
|
232
233
|
externalEndpoints: Record<string, unknown>;
|
|
233
234
|
torControl: Record<string, unknown>;
|
|
234
235
|
k: KConfig;
|
|
236
|
+
relayMode: 'public' | 'private';
|
|
235
237
|
}
|
|
236
238
|
export function buildSidecarConfig(options: SidecarConfigOptions): SidecarConfig;
|
|
239
|
+
export function getRelayMode(config?: { relayMode?: string }): 'public' | 'private';
|
|
240
|
+
export function setRelayMode(config?: Record<string, unknown>, mode: 'public' | 'private'): Record<string, unknown>;
|
|
237
241
|
|
|
238
242
|
export interface ClientConfigOptions {
|
|
239
243
|
relayUrl: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ncc-06-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Reusable NCC-06 discovery helpers extracted from the example relay, sidecar, and client.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"lint": "eslint . --ext .js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"ncc-02-js": "^0.2.
|
|
13
|
+
"ncc-02-js": "^0.2.3",
|
|
14
14
|
"ncc-05-js": "^1.1.9",
|
|
15
15
|
"nostr-tools": "^2.19.4",
|
|
16
16
|
"selfsigned": "^5.4.0",
|
package/src/sidecar-config.js
CHANGED
|
@@ -11,6 +11,20 @@ const DEFAULT_TOR_CONTROL = {
|
|
|
11
11
|
timeout: 5000
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
const RELAY_MODE_PUBLIC = 'public';
|
|
15
|
+
const RELAY_MODE_PRIVATE = 'private';
|
|
16
|
+
|
|
17
|
+
function normalizeRelayMode(mode) {
|
|
18
|
+
if (!mode) {
|
|
19
|
+
return RELAY_MODE_PUBLIC;
|
|
20
|
+
}
|
|
21
|
+
const value = String(mode).toLowerCase();
|
|
22
|
+
if (value !== RELAY_MODE_PUBLIC && value !== RELAY_MODE_PRIVATE) {
|
|
23
|
+
throw new Error(`relayMode must be "${RELAY_MODE_PUBLIC}" or "${RELAY_MODE_PRIVATE}"`);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
14
28
|
function uniqueList(items) {
|
|
15
29
|
const seen = new Set();
|
|
16
30
|
return items.filter(item => {
|
|
@@ -24,6 +38,15 @@ function uniqueList(items) {
|
|
|
24
38
|
});
|
|
25
39
|
}
|
|
26
40
|
|
|
41
|
+
export function getRelayMode(config = {}) {
|
|
42
|
+
return normalizeRelayMode(config.relayMode);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function setRelayMode(config = {}, mode) {
|
|
46
|
+
const normalized = normalizeRelayMode(mode);
|
|
47
|
+
return { ...config, relayMode: normalized };
|
|
48
|
+
}
|
|
49
|
+
|
|
27
50
|
/**
|
|
28
51
|
* Build a deployable sidecar config object that mirrors the example's defaults.
|
|
29
52
|
*/
|
|
@@ -42,6 +65,7 @@ export function buildSidecarConfig({
|
|
|
42
65
|
externalEndpoints = {},
|
|
43
66
|
k = {},
|
|
44
67
|
baseDir = process.cwd(),
|
|
68
|
+
relayMode,
|
|
45
69
|
ncc02ExpectedKeySource
|
|
46
70
|
} = {}) {
|
|
47
71
|
if (!serviceSk || !servicePk || !serviceNpub) {
|
|
@@ -58,6 +82,7 @@ export function buildSidecarConfig({
|
|
|
58
82
|
...(publishRelays ?? normalizedPublicationRelays)
|
|
59
83
|
]);
|
|
60
84
|
const keySource = ncc02ExpectedKeySource ?? k.mode ?? 'auto';
|
|
85
|
+
const normalizedRelayMode = normalizeRelayMode(relayMode);
|
|
61
86
|
|
|
62
87
|
return {
|
|
63
88
|
serviceSk,
|
|
@@ -74,7 +99,8 @@ export function buildSidecarConfig({
|
|
|
74
99
|
ncc02ExpectedKeySource: keySource,
|
|
75
100
|
externalEndpoints,
|
|
76
101
|
torControl,
|
|
77
|
-
k
|
|
102
|
+
k,
|
|
103
|
+
relayMode: normalizedRelayMode
|
|
78
104
|
};
|
|
79
105
|
}
|
|
80
106
|
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { test } from 'node:test';
|
|
2
2
|
import { strict as assert } from 'assert';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
buildSidecarConfig,
|
|
5
|
+
buildClientConfig,
|
|
6
|
+
getRelayMode,
|
|
7
|
+
setRelayMode
|
|
8
|
+
} from '../src/sidecar-config.js';
|
|
4
9
|
|
|
5
10
|
test('buildSidecarConfig constructs expected fields based on inputs', () => {
|
|
6
11
|
const cfg = buildSidecarConfig({
|
|
@@ -34,3 +39,11 @@ test('buildClientConfig enforces identity URI and relays', () => {
|
|
|
34
39
|
assert.equal(client.publicationRelays.length, 2);
|
|
35
40
|
assert.equal(client.ncc02ExpectedKey, 'TESTKEY:abc');
|
|
36
41
|
});
|
|
42
|
+
|
|
43
|
+
test('getRelayMode default and setter', () => {
|
|
44
|
+
assert.equal(getRelayMode({}), 'public');
|
|
45
|
+
assert.equal(getRelayMode({ relayMode: 'private' }), 'private');
|
|
46
|
+
const config = setRelayMode({}, 'private');
|
|
47
|
+
assert.equal(config.relayMode, 'private');
|
|
48
|
+
assert.throws(() => setRelayMode({}, 'unknown'));
|
|
49
|
+
});
|