Skip to content

Commit 1b7f0ce

Browse files
Address copilot pass 2 on #2
- doctor.js: thread the canonical WebID (with fragment) through to the Multikey builder. runAll now returns the absolutized profile @id as `webId`, and the connect handler uses that — not the fragmentless docUrl — when calling buildNostrVerificationMethod. Without this the earlier controller-with-fragment fix was undone at the callsite. - doctor.js: drop the unused `docUrl` arg from runLwsCidChecks call. - lib/multikey.js: error message no longer says "lowercase hex" since normalizeHex lowercases first; uppercase input is accepted.
1 parent cc29dac commit 1b7f0ce

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

doctor.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ form.addEventListener('submit', async (e) => {
5353
results.hidden = false;
5454

5555
try {
56-
const { checks, profileFetched, docUrl } = await runAll(url);
56+
const { checks, profileFetched, webId } = await runAll(url);
5757
renderChecks(checks);
58-
if (profileFetched && docUrl) {
59-
lastWebId = docUrl;
58+
if (profileFetched && webId) {
59+
lastWebId = webId;
6060
revealAddKeySection();
6161
} else {
6262
hideAddKeySection();
@@ -76,7 +76,7 @@ form.addEventListener('submit', async (e) => {
7676

7777
async function runAll(webIdUrl) {
7878
const checks = [];
79-
const result = { checks, profileFetched: false, docUrl: null };
79+
const result = { checks, profileFetched: false, docUrl: null, webId: null };
8080

8181
// 1. Resolve the document URL — strip the fragment.
8282
let docUrl;
@@ -148,11 +148,21 @@ async function runAll(webIdUrl) {
148148
checks.push({ status: 'pass', label: 'Profile parses as JSON' });
149149

150150
// Profile was fetched and parsed — safe to root a snippet against this URL.
151+
// Take the canonical WebID from the profile's own @id (absolutized
152+
// against the document URL); fall back to the user-supplied URL if
153+
// the profile didn't declare one. This preserves any fragment (e.g.
154+
// "#me") so verificationMethod controllers will agree with the
155+
// profile's outer controller predicate.
156+
const profileId = profile['@id'] || profile.id;
157+
const canonicalWebId = profileId
158+
? new URL(profileId, docUrl).toString()
159+
: webIdUrl;
151160
result.profileFetched = true;
152161
result.docUrl = docUrl.toString();
162+
result.webId = canonicalWebId;
153163

154164
// 4. Run LWS-CID structural checks.
155-
for (const c of runLwsCidChecks(profile, { webIdUrl, docUrl: docUrl.toString() })) {
165+
for (const c of runLwsCidChecks(profile, { webIdUrl })) {
156166
checks.push(c);
157167
}
158168

lib/multikey.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function nostrPubkeyToMultikey(xOnlyHex, opts = {}) {
2929
throw new Error(`Nostr pubkey must be 32 bytes (64 hex chars); got ${hex.length}`);
3030
}
3131
if (!/^[0-9a-f]{64}$/.test(hex)) {
32-
throw new Error('Nostr pubkey must be lowercase hex (0-9, a-f)');
32+
throw new Error('Nostr pubkey must be hex (0-9, a-f, A-F)');
3333
}
3434

3535
let parity = opts.parity ?? 0x02;

0 commit comments

Comments
 (0)