Skip to content

Commit fcc3382

Browse files
Count kind-0 created_at toward modified when it composes via alsoKnownAs
Address Copilot review on #39: a kind-0 event can contribute alsoKnownAs with no profile fields, so gating the kind-0 created_at on doc.profile alone could understate modified. Gate on (doc.profile || doc.alsoKnownAs).
1 parent 8199af9 commit fcc3382

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/diddoc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ export function buildDidDocument(pubkey, { profile, follows, relays } = {}) {
9696
// into the document, serialized ISO-8601. Representation-only changes are not
9797
// reflected here (those are conveyed by ETag / Last-Modified).
9898
const stamps = [
99-
doc.profile && profile?.created_at,
99+
// kind-0 composes the doc via profile and/or alsoKnownAs
100+
(doc.profile || doc.alsoKnownAs) && profile?.created_at,
100101
doc.follows && follows?.created_at,
101102
doc.service && relays?.created_at,
102103
].filter(Number.isSafeInteger);

test/diddoc.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ test('follows is bounded; the full signed list stays in the kind-3 event', () =>
4848
assert.equal(d.follows.length, 500);
4949
});
5050

51+
test('alsoKnownAs-only kind-0 still contributes its created_at to modified', () => {
52+
const d = buildDidDocument(PK, {
53+
profile: { content: JSON.stringify({ alsoKnownAs: ['https://x.example/#me'] }), created_at: 300 },
54+
});
55+
assert.equal(d.profile, undefined); // no profile fields composed
56+
assert.deepEqual(d.alsoKnownAs, ['https://x.example/#me']);
57+
assert.equal(d.modified, '1970-01-01T00:05:00Z'); // kind-0 created_at (300) still counts
58+
});
59+
5160
test('out-of-range created_at does not throw and is omitted (no modified)', () => {
5261
const d = buildDidDocument(PK, {
5362
profile: { content: JSON.stringify({ name: 'X' }), created_at: 1e308 },

0 commit comments

Comments
 (0)