Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 28 additions & 8 deletions js/auth/api/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,19 @@ export { Request_2 as Request }
export const RequestSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
id: z.ZodMiniString<string>;
node: z.ZodMiniString<string>;
transport: z.ZodMiniEnum<{
transport: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniCatch<z.ZodMiniEnum<{
http: "http";
iroh: "iroh";
quic: "quic";
rtmp: "rtmp";
srt: "srt";
tcp: "tcp";
unix: "unix";
unknown: "unknown";
webrtc: "webrtc";
websocket: "websocket";
}>;
webtransport: "webtransport";
}>>>;
remote: z.ZodMiniOptional<z.ZodMiniString<string>>;
local: z.ZodMiniOptional<z.ZodMiniString<string>>;
server_name: z.ZodMiniOptional<z.ZodMiniString<string>>;
Expand All @@ -612,14 +617,19 @@ export const RequestSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
}, z.core.$strip>, z.ZodMiniObject<{
id: z.ZodMiniString<string>;
node: z.ZodMiniString<string>;
transport: z.ZodMiniEnum<{
transport: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniCatch<z.ZodMiniEnum<{
http: "http";
iroh: "iroh";
quic: "quic";
rtmp: "rtmp";
srt: "srt";
tcp: "tcp";
unix: "unix";
unknown: "unknown";
webrtc: "webrtc";
websocket: "websocket";
}>;
webtransport: "webtransport";
}>>>;
remote: z.ZodMiniOptional<z.ZodMiniString<string>>;
local: z.ZodMiniOptional<z.ZodMiniString<string>>;
server_name: z.ZodMiniOptional<z.ZodMiniString<string>>;
Expand All @@ -644,14 +654,19 @@ export const RequestSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
}, z.core.$strip>, z.ZodMiniObject<{
id: z.ZodMiniString<string>;
node: z.ZodMiniString<string>;
transport: z.ZodMiniEnum<{
transport: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniCatch<z.ZodMiniEnum<{
http: "http";
iroh: "iroh";
quic: "quic";
rtmp: "rtmp";
srt: "srt";
tcp: "tcp";
unix: "unix";
unknown: "unknown";
webrtc: "webrtc";
websocket: "websocket";
}>;
webtransport: "webtransport";
}>>>;
remote: z.ZodMiniOptional<z.ZodMiniString<string>>;
local: z.ZodMiniOptional<z.ZodMiniString<string>>;
server_name: z.ZodMiniOptional<z.ZodMiniString<string>>;
Expand Down Expand Up @@ -740,14 +755,19 @@ function toPublic_2(set: KeySet): PublicKeySet;

export type Transport = z.infer<typeof TransportSchema>;

export const TransportSchema: z.ZodMiniEnum<{
export const TransportSchema: z.ZodMiniPipe<z.ZodMiniString<string>, z.ZodMiniCatch<z.ZodMiniEnum<{
http: "http";
iroh: "iroh";
quic: "quic";
rtmp: "rtmp";
srt: "srt";
tcp: "tcp";
unix: "unix";
unknown: "unknown";
webrtc: "webrtc";
websocket: "websocket";
}>;
webtransport: "webtransport";
}>>>;

function verify(key: PublicKey | SymmetricKey, token: string): Promise<Claims>;

Expand Down
2 changes: 1 addition & 1 deletion js/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@moq/auth",
"type": "module",
"version": "0.2.2",
"version": "0.2.3",
"description": "Media over QUIC - the authorization contract: requests, grants, and the JWT that rides them",
"license": "(MIT OR Apache-2.0)",
"repository": {
Expand Down
21 changes: 17 additions & 4 deletions js/auth/src/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,24 @@ test("a SETUP token parses as the Rust vector", () => {
}
});

test("a connect must not carry end facts, and an unknown transport is refused", () => {
test("a connect must not carry end facts", () => {
expect(() => RequestSchema.parse({ id: "1", event: "end", node: "n", transport: "quic", path: "/" })).toThrow();
expect(() =>
RequestSchema.parse({ id: "1", event: "connect", node: "n", transport: "carrier-pigeon", path: "/" }),
).toThrow();
});

test("WebTransport and future transport names follow the Rust contract", () => {
for (const [incoming, expected] of [
["webtransport", "webtransport"],
["carrier-pigeon", "unknown"],
] as const) {
const request = RequestSchema.parse({ id: "1", event: "connect", node: "n", transport: incoming, path: "/" });
expect(request.transport).toBe(expected);
}
});

test("malformed transport values are refused", () => {
for (const transport of [undefined, null, 1, {}, []]) {
expect(() => RequestSchema.parse({ id: "1", event: "connect", node: "n", transport, path: "/" })).toThrow();
}
});

test("a grant round trips and is validated", () => {
Expand Down
20 changes: 19 additions & 1 deletion js/auth/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,25 @@ import * as z from "@zod/mini";
import { PatternListSchema } from "./claims.ts";

/** How a session reached the relay; `http` is a one-shot request on the relay's web listener. */
export const TransportSchema = z.enum(["quic", "iroh", "websocket", "tcp", "unix", "http"]);
export const TransportSchema = z.pipe(
z.string(),
z.catch(
z.enum([
"quic",
"iroh",
"websocket",
"tcp",
"unix",
"http",
"rtmp",
"srt",
"webrtc",
"webtransport",
"unknown",
]),
"unknown",
),
);
export type Transport = z.infer<typeof TransportSchema>;

/** The single direction a client declared at SETUP. */
Expand Down
Loading