javascript-solid-server 0.0.190 → 0.0.191
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/package.json +1 -1
- package/src/server.js +36 -0
- package/test/well-known-nostr-json.test.js +173 -0
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -743,6 +743,14 @@ export function createServer(options = {}) {
|
|
|
743
743
|
'/.well-known/did/nostr/',
|
|
744
744
|
'/.well-known/did/nostr/:pubkeyAndExt',
|
|
745
745
|
'/.well-known/did/nostr/*',
|
|
746
|
+
// /.well-known/nostr.json — NIP-05 mapping (#446). Same WAC-bypass
|
|
747
|
+
// concern as /.well-known/did/nostr/*: the global preHandler skips
|
|
748
|
+
// auth for /.well-known/* (the spec-mandated public namespace),
|
|
749
|
+
// so without 405 blocks the wildcard write handlers would let
|
|
750
|
+
// anyone PUT/DELETE/PATCH this file and hijack the pod's NIP-05
|
|
751
|
+
// identity. GET/HEAD reach the LDP layer normally and serve the
|
|
752
|
+
// file written by --provision-keys.
|
|
753
|
+
'/.well-known/nostr.json',
|
|
746
754
|
]) {
|
|
747
755
|
fastify.put(pat, methodNotAllowed);
|
|
748
756
|
fastify.post(pat, methodNotAllowed);
|
|
@@ -891,6 +899,30 @@ export function createServer(options = {}) {
|
|
|
891
899
|
'Filesystem reads bypass WAC; use FDE / OS keyring / restrictive umask ' +
|
|
892
900
|
'for any pod that matters. See docs/provision-keys.md.'
|
|
893
901
|
);
|
|
902
|
+
|
|
903
|
+
// NIP-05 mapping for the bare domain (#446). Lives at the
|
|
904
|
+
// server root regardless of whether the pod is at / or
|
|
905
|
+
// /<name>/ — `.well-known/` is per-origin, not per-pod.
|
|
906
|
+
// This branch covers BOTH single-user shapes (root pod via
|
|
907
|
+
// createRootPodStructure, named pod via createPodStructure)
|
|
908
|
+
// because the file is logically server-level identity, not
|
|
909
|
+
// pod-internal data. Multi-user aggregation is the next
|
|
910
|
+
// slice of #445. WAC bypass on /.well-known/* is balanced
|
|
911
|
+
// by the 405 method-not-allowed guards registered earlier
|
|
912
|
+
// so an attacker can't PUT-overwrite this mapping.
|
|
913
|
+
await storage.createContainer('/.well-known/');
|
|
914
|
+
const nip05Ok = await storage.write(
|
|
915
|
+
'/.well-known/nostr.json',
|
|
916
|
+
JSON.stringify({ names: { _: creation.ownerKey.publicHex } }, null, 2)
|
|
917
|
+
);
|
|
918
|
+
if (!nip05Ok) {
|
|
919
|
+
fastify.log.warn(
|
|
920
|
+
'Failed to write /.well-known/nostr.json — pod is provisioned ' +
|
|
921
|
+
'but NIP-05 verification will not resolve to this server.'
|
|
922
|
+
);
|
|
923
|
+
} else {
|
|
924
|
+
fastify.log.info(`NIP-05 mapping at ${baseUrl}/.well-known/nostr.json`);
|
|
925
|
+
}
|
|
894
926
|
}
|
|
895
927
|
}
|
|
896
928
|
|
|
@@ -1128,6 +1160,10 @@ export function createServer(options = {}) {
|
|
|
1128
1160
|
);
|
|
1129
1161
|
}
|
|
1130
1162
|
}
|
|
1163
|
+
// NIP-05 mapping is written outside this function (in the
|
|
1164
|
+
// single-user onReady block) so it covers both root pods and
|
|
1165
|
+
// named single-user pods (which take the createPodStructure
|
|
1166
|
+
// path), not just the root case. See #446.
|
|
1131
1167
|
|
|
1132
1168
|
// Generate profile (with the owner key's VM landed in
|
|
1133
1169
|
// verificationMethod when --provision-keys is on). Written last —
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NIP-05 MVP — /.well-known/nostr.json on single-user pods (#446).
|
|
3
|
+
*
|
|
4
|
+
* Implementation is a static file written during pod creation, not
|
|
5
|
+
* a server-side handler. JSS already exposes /.well-known/* as a
|
|
6
|
+
* public namespace (WAC bypass + dotfile allow-list); the LDP GET
|
|
7
|
+
* handler serves the file like any other resource.
|
|
8
|
+
*
|
|
9
|
+
* Acceptance:
|
|
10
|
+
* - single-user + --provision-keys → 200 { names: { _: <hex> } }
|
|
11
|
+
* served at /.well-known/nostr.json, publicly readable, with
|
|
12
|
+
* CORS open for browser-based NIP-05 verifiers.
|
|
13
|
+
* - single-user without --provision-keys → no file written.
|
|
14
|
+
* - multi-user → no file written (next slice of #445 aggregates).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { describe, it, before, after } from 'node:test';
|
|
18
|
+
import assert from 'node:assert';
|
|
19
|
+
import fs from 'fs-extra';
|
|
20
|
+
import { createServer } from '../src/server.js';
|
|
21
|
+
|
|
22
|
+
// Per-describe DATA_DIR suffixes so the three suites in this file
|
|
23
|
+
// don't collide if --test-concurrency is ever raised above 1.
|
|
24
|
+
// Currently 1 per the npm test script, but the latent risk was
|
|
25
|
+
// flagged in the #447 review.
|
|
26
|
+
async function startServer(dataDir, options = {}) {
|
|
27
|
+
await fs.remove(dataDir);
|
|
28
|
+
await fs.ensureDir(dataDir);
|
|
29
|
+
const server = createServer({
|
|
30
|
+
logger: false,
|
|
31
|
+
forceCloseConnections: true,
|
|
32
|
+
root: dataDir,
|
|
33
|
+
...options
|
|
34
|
+
});
|
|
35
|
+
await server.listen({ port: 0, host: '127.0.0.1' });
|
|
36
|
+
const baseUrl = `http://127.0.0.1:${server.server.address().port}`;
|
|
37
|
+
return { server, baseUrl };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function stopServer(server, dataDir) {
|
|
41
|
+
await server.close();
|
|
42
|
+
await fs.remove(dataDir);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('NIP-05 MVP — single-user with provisioned key', () => {
|
|
46
|
+
const DATA_DIR = './test-data-nip05-with-key';
|
|
47
|
+
let server, baseUrl;
|
|
48
|
+
let savedDataRoot;
|
|
49
|
+
|
|
50
|
+
before(async () => {
|
|
51
|
+
savedDataRoot = process.env.DATA_ROOT;
|
|
52
|
+
({ server, baseUrl } = await startServer(DATA_DIR, {
|
|
53
|
+
singleUser: true,
|
|
54
|
+
provisionKeys: true
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
after(async () => {
|
|
59
|
+
await stopServer(server, DATA_DIR);
|
|
60
|
+
if (savedDataRoot === undefined) delete process.env.DATA_ROOT;
|
|
61
|
+
else process.env.DATA_ROOT = savedDataRoot;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('writes the NIP-05 mapping with the reserved `_` name', async () => {
|
|
65
|
+
const onDisk = JSON.parse(
|
|
66
|
+
await fs.readFile(`${DATA_DIR}/.well-known/nostr.json`, 'utf8')
|
|
67
|
+
);
|
|
68
|
+
assert.deepStrictEqual(Object.keys(onDisk.names), ['_'],
|
|
69
|
+
'MVP emits exactly one mapping (the `_` reserved name)');
|
|
70
|
+
assert.match(onDisk.names._, /^[0-9a-f]{64}$/,
|
|
71
|
+
'the `_` mapping must be a 32-byte hex pubkey');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('serves the mapping over HTTP without auth (NIP-05 verifiers are unauth)', async () => {
|
|
75
|
+
const res = await fetch(`${baseUrl}/.well-known/nostr.json`);
|
|
76
|
+
assert.strictEqual(res.status, 200);
|
|
77
|
+
const body = await res.json();
|
|
78
|
+
assert.match(body.names._, /^[0-9a-f]{64}$/);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('matches the same pubkey landed in the WebID profile VM', async () => {
|
|
82
|
+
// Cross-check: the NIP-05 pubkey and the profile's
|
|
83
|
+
// verificationMethod publicKeyMultibase should describe the
|
|
84
|
+
// same key. If they ever diverge, an LWS-CID verifier would
|
|
85
|
+
// accept the profile's VM but a NIP-05 verifier would attest
|
|
86
|
+
// to a different identity for the same domain.
|
|
87
|
+
const onDisk = JSON.parse(
|
|
88
|
+
await fs.readFile(`${DATA_DIR}/.well-known/nostr.json`, 'utf8')
|
|
89
|
+
);
|
|
90
|
+
const profile = JSON.parse(
|
|
91
|
+
await fs.readFile(`${DATA_DIR}/profile/card.jsonld`, 'utf8')
|
|
92
|
+
);
|
|
93
|
+
const vm = profile.verificationMethod[0];
|
|
94
|
+
assert.ok(vm.publicKeyMultibase.includes(onDisk.names._),
|
|
95
|
+
'NIP-05 pubkey hex must appear in the profile VM publicKeyMultibase');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('NIP-05 MVP — single-user without a provisioned key', () => {
|
|
100
|
+
const DATA_DIR = './test-data-nip05-no-key';
|
|
101
|
+
let server;
|
|
102
|
+
let savedDataRoot;
|
|
103
|
+
|
|
104
|
+
before(async () => {
|
|
105
|
+
savedDataRoot = process.env.DATA_ROOT;
|
|
106
|
+
({ server } = await startServer(DATA_DIR, { singleUser: true }));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
after(async () => {
|
|
110
|
+
await stopServer(server, DATA_DIR);
|
|
111
|
+
if (savedDataRoot === undefined) delete process.env.DATA_ROOT;
|
|
112
|
+
else process.env.DATA_ROOT = savedDataRoot;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('does not create the file (nothing to publish)', async () => {
|
|
116
|
+
assert.strictEqual(
|
|
117
|
+
await fs.pathExists(`${DATA_DIR}/.well-known/nostr.json`),
|
|
118
|
+
false,
|
|
119
|
+
'no key → no NIP-05 mapping → no file'
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('NIP-05 MVP — multi-user mode', () => {
|
|
125
|
+
const DATA_DIR = './test-data-nip05-multiuser';
|
|
126
|
+
let server, baseUrl;
|
|
127
|
+
let savedDataRoot;
|
|
128
|
+
|
|
129
|
+
before(async () => {
|
|
130
|
+
savedDataRoot = process.env.DATA_ROOT;
|
|
131
|
+
// No singleUser → multi-user. The MVP only writes the NIP-05
|
|
132
|
+
// file in single-user mode; aggregation across multi-user pods
|
|
133
|
+
// is the next slice of #445.
|
|
134
|
+
({ server, baseUrl } = await startServer(DATA_DIR, {}));
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
after(async () => {
|
|
138
|
+
await stopServer(server, DATA_DIR);
|
|
139
|
+
if (savedDataRoot === undefined) delete process.env.DATA_ROOT;
|
|
140
|
+
else process.env.DATA_ROOT = savedDataRoot;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('still does not write a server-level NIP-05 file when a pod is provisioned with keys', async () => {
|
|
144
|
+
// Actually exercise the code path that *could* have written the
|
|
145
|
+
// file — provision a multi-user pod with provisionKeys: true via
|
|
146
|
+
// POST /.pods. The pod's own /<name>/private/privkey.jsonld
|
|
147
|
+
// lands as expected, but the server-level /.well-known/nostr.json
|
|
148
|
+
// must remain absent because this is multi-user mode.
|
|
149
|
+
const res = await fetch(`${baseUrl}/.pods`, {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
headers: { 'Content-Type': 'application/json' },
|
|
152
|
+
body: JSON.stringify({ name: 'alice', provisionKeys: true })
|
|
153
|
+
});
|
|
154
|
+
assert.strictEqual(res.status, 201, 'pod creation must succeed');
|
|
155
|
+
const body = await res.json();
|
|
156
|
+
assert.ok(body.ownerKey, 'pod-level owner key must still be provisioned');
|
|
157
|
+
|
|
158
|
+
// The pod's own privkey IS on disk — sanity check the multi-user
|
|
159
|
+
// provisioning path still ran.
|
|
160
|
+
assert.strictEqual(
|
|
161
|
+
await fs.pathExists(`${DATA_DIR}/alice/private/privkey.jsonld`),
|
|
162
|
+
true,
|
|
163
|
+
'multi-user pod provisioning still writes the pod-internal privkey'
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
// …but no server-level NIP-05 file.
|
|
167
|
+
assert.strictEqual(
|
|
168
|
+
await fs.pathExists(`${DATA_DIR}/.well-known/nostr.json`),
|
|
169
|
+
false,
|
|
170
|
+
'multi-user mode must not write a server-level NIP-05 mapping'
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
});
|