Skip to content

Commit a91a3a6

Browse files
committed
Show signature spec
1 parent 2ac48a1 commit a91a3a6

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

examples/rfc-9421-test/app.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
followingStore,
2020
onStateChange,
2121
} from "./federation.ts";
22+
import { setInboundSigSpec } from "./federation.ts";
2223

2324
const indexHtml = await Deno.readTextFile(
2425
new URL("index.html", import.meta.url),
@@ -37,6 +38,19 @@ interface AppConfig {
3738

3839
export default function createApp(fedi: Fedi, config: AppConfig) {
3940
const app = new Hono();
41+
42+
// Detect signature spec on incoming inbox POSTs before federation handles them.
43+
app.use("*", async (c, next) => {
44+
if (c.req.method === "POST") {
45+
setInboundSigSpec(c.req.header("signature-input") != null
46+
? "rfc9421"
47+
: c.req.header("signature") != null
48+
? "draft-cavage"
49+
: null);
50+
}
51+
await next();
52+
});
53+
4054
app.use(federation(fedi, () => undefined));
4155

4256
app.get("/", (c) => c.html(indexHtml));

examples/rfc-9421-test/federation.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,24 @@ export function emitChange(event: string): void {
4444
for (const cb of changeListeners) cb(event);
4545
}
4646

47+
/**
48+
* Set by Hono middleware before federation handles the request, so that
49+
* `logActivity` can record which signature spec was used.
50+
*/
51+
let lastInboundSigSpec: "rfc9421" | "draft-cavage" | null = null;
52+
export function setInboundSigSpec(
53+
spec: "rfc9421" | "draft-cavage" | null,
54+
): void {
55+
lastInboundSigSpec = spec;
56+
}
57+
4758
/** Log of received activities for inspection. */
4859
export const activityLog: {
4960
timestamp: string;
5061
type: string;
5162
actorId: string | null;
5263
id: string | null;
64+
sigSpec: "rfc9421" | "draft-cavage" | null;
5365
raw: Record<string, unknown>;
5466
}[] = [];
5567

@@ -186,7 +198,9 @@ function logActivity(type: string, activity: Activity) {
186198
type,
187199
actorId: activity.actorId?.href ?? null,
188200
id: activity.id?.href ?? null,
201+
sigSpec: lastInboundSigSpec,
189202
raw: {},
190203
});
204+
lastInboundSigSpec = null;
191205
emitChange("log");
192206
}

examples/rfc-9421-test/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@
191191
overflow: hidden;
192192
text-overflow: ellipsis;
193193
}
194+
.log-sig {
195+
flex-shrink: 0;
196+
font-size: 0.7rem;
197+
padding: 0.05rem 0.35rem;
198+
border-radius: 3px;
199+
font-weight: 600;
200+
}
201+
.log-sig.rfc9421 { background: #d4edda; color: #155724; }
202+
.log-sig.draft-cavage { background: #fff3cd; color: #856404; }
194203
</style>
195204
</head>
196205
<body>
@@ -421,6 +430,12 @@ <h1>RFC 9421 Field Test</h1>
421430
actor.textContent = entry.actorId || "";
422431
}
423432
li.append(time, " ", type, " ", actor);
433+
if (entry.sigSpec) {
434+
const sig = document.createElement("span");
435+
sig.className = `log-sig ${entry.sigSpec}`;
436+
sig.textContent = entry.sigSpec === "rfc9421" ? "RFC 9421" : "draft-cavage";
437+
li.append(" ", sig);
438+
}
424439
ul.appendChild(li);
425440
}
426441
$log.replaceChildren(ul);

0 commit comments

Comments
 (0)