@blockcast/mmt-base 0.4.0-main.94b7ef7dcd8d → 0.4.0-main.9d97fa55ba69

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/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export * from './signalling.js';
5
5
  export * from './serial-number.js';
6
6
  export * from './fec-block-profile.js';
7
7
  export * from './catalog-fec-source.js';
8
+ export * from './multicast-catalog.js';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA"}
package/dist/index.js CHANGED
@@ -5,4 +5,5 @@ export * from './signalling.js';
5
5
  export * from './serial-number.js';
6
6
  export * from './fec-block-profile.js';
7
7
  export * from './catalog-fec-source.js';
8
+ export * from './multicast-catalog.js';
8
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The draft-ramadan-moq-multicast-01 endpoint and `auth` rules, written once
3
+ * for both sides of the catalog: `validateCmsfMmtpCatalog` in
4
+ * `@blockcast/mmt-container` throws the first issue, and the receivers in
5
+ * `@blockcast/mmt-transport` ignore every endpoint an issue names (all of
6
+ * them when the issue is catalog-level). It lives here because mmt-base is
7
+ * the only package both depend on.
8
+ *
9
+ * Draft: Blockcast/moqcast-draft@fd962fd73d21ed281b60219c11ea61cc9e4e91c4
10
+ * (PR #2 head; normative text equal to 3162ef93), sections 4.1 and 7.2.6.
11
+ */
12
+ export type MulticastJoinMode = "ssm" | "asm";
13
+ /** An endpoint's join mode and `S` (4.1): `sourceAddress` on SSM,
14
+ * `auth.senderAddress` on protected ASM, absent on unprotected ASM. */
15
+ export interface MulticastEndpointSource {
16
+ mode: MulticastJoinMode;
17
+ source?: string;
18
+ }
19
+ export type MulticastCatalogIssueCode = "multicast_auth" | "multicast_endpoint" | "multicast_endpoint_auth" | "multicast_track";
20
+ export interface MulticastCatalogIssue {
21
+ code: MulticastCatalogIssueCode;
22
+ /** JSONPath of the offending field. */
23
+ path: string;
24
+ message: string;
25
+ /** Endpoint the issue makes a receiver ignore; absent for a catalog-level
26
+ * issue, which leaves the receiver no endpoint at all (7.2.6). */
27
+ endpointIndex?: number;
28
+ }
29
+ /** Canonical unpadded base64url of exactly 32 octets. */
30
+ export declare const ED25519_PUBLIC_KEY_BASE64URL: RegExp;
31
+ /**
32
+ * Join mode and `S` of one endpoint, or `undefined` when its fields disagree
33
+ * and a receiver must ignore it (4.1). `sourceAddress` alone selects the mode;
34
+ * `protocol` may only restate it, so "amt" and "atsc3" (draft -00) are
35
+ * inconsistent here: a bearer is a `networkSource`, never a protocol.
36
+ */
37
+ export declare function multicastEndpointSource(endpoint: unknown): MulticastEndpointSource | undefined;
38
+ /**
39
+ * Where a catalog object carries the namespace of the catalog track it was
40
+ * read from. A symbol, so it is never wire data and survives object spread;
41
+ * `Symbol.for`, so two bundled copies of this module agree on it.
42
+ */
43
+ export declare const CATALOG_NAMESPACE: unique symbol;
44
+ /**
45
+ * `catalog` tagged with the namespace of its catalog track. Every receiver
46
+ * rule that takes the catalog (`multicastCatalogIssues`,
47
+ * `admittedMulticastEndpoints` and the transport selectors built on them)
48
+ * then judges the foreign-namespace rule against it, independent of track
49
+ * order. Tag once, where the catalog track is read.
50
+ */
51
+ export declare function withCatalogNamespace<T extends object>(catalog: T, namespace: string): T;
52
+ /**
53
+ * Every draft -01 4.1 / 7.2.6 violation in `catalog.multicast`, in document
54
+ * order. Packet-id, group-address and track-existence rules are not here; the
55
+ * container validator and the receivers already check those.
56
+ *
57
+ * `catalogNamespace` is the namespace of the catalog track, from `options` or else the
58
+ * catalog's `withCatalogNamespace` tag. Without it the
59
+ * foreign-namespace rule can only compare listed tracks with each other: the
60
+ * first listed track's namespace becomes the reference, so which side of a
61
+ * disagreement is dropped depends on order. It still fails closed; pass
62
+ * `catalogNamespace` wherever the catalog track is known.
63
+ */
64
+ export declare function multicastCatalogIssues(catalog: unknown, options?: {
65
+ catalogNamespace?: string;
66
+ }): MulticastCatalogIssue[];
67
+ /**
68
+ * Indices of the endpoints a receiver may use: none when a catalog-level
69
+ * issue leaves it no key set (7.2.6), otherwise every endpoint no issue
70
+ * names. Other receiver checks (group address, packet ids) still apply.
71
+ */
72
+ export declare function admittedMulticastEndpoints(catalog: unknown, options?: {
73
+ catalogNamespace?: string;
74
+ }): ReadonlySet<number>;
75
+ //# sourceMappingURL=multicast-catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multicast-catalog.d.ts","sourceRoot":"","sources":["../src/multicast-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,KAAK,CAAC;AAE9C;uEACuE;AACvE,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,yBAAyB,GAClC,gBAAgB,GAChB,oBAAoB,GACpB,yBAAyB,GACzB,iBAAiB,CAAC;AAErB,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,yBAAyB,CAAC;IAChC,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB;sEACkE;IAClE,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,yDAAyD;AACzD,eAAO,MAAM,4BAA4B,QAA0C,CAAC;AA4BpF;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,OAAO,GAAG,uBAAuB,GAAG,SAAS,CAY9F;AAqFD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,OAAO,MAA2D,CAAC;AAEnG;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC,CAEvF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAO,GACzC,qBAAqB,EAAE,CAkIzB;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAO,GACzC,WAAW,CAAC,MAAM,CAAC,CAOrB"}
@@ -0,0 +1,318 @@
1
+ /**
2
+ * The draft-ramadan-moq-multicast-01 endpoint and `auth` rules, written once
3
+ * for both sides of the catalog: `validateCmsfMmtpCatalog` in
4
+ * `@blockcast/mmt-container` throws the first issue, and the receivers in
5
+ * `@blockcast/mmt-transport` ignore every endpoint an issue names (all of
6
+ * them when the issue is catalog-level). It lives here because mmt-base is
7
+ * the only package both depend on.
8
+ *
9
+ * Draft: Blockcast/moqcast-draft@fd962fd73d21ed281b60219c11ea61cc9e4e91c4
10
+ * (PR #2 head; normative text equal to 3162ef93), sections 4.1 and 7.2.6.
11
+ */
12
+ /** Canonical unpadded base64url of exactly 32 octets. */
13
+ export const ED25519_PUBLIC_KEY_BASE64URL = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
14
+ const UINT32_MAX = 0xffff_ffff;
15
+ const AUTH_MEMBERS = new Set(["scheme", "version", "sig", "keys", "minEpoch"]);
16
+ const KEY_MEMBERS = new Set(["kid", "publicKey", "firstEpoch"]);
17
+ const ENDPOINT_AUTH_MEMBERS = new Set([
18
+ "manifestPort",
19
+ "streamId",
20
+ "senderAddress",
21
+ "maxAuthDelayMs",
22
+ "manifestTimerMs",
23
+ "manifestTrack",
24
+ ]);
25
+ function isObject(value) {
26
+ return typeof value === "object" && value !== null && !Array.isArray(value);
27
+ }
28
+ function isNonEmptyString(value) {
29
+ return typeof value === "string" && value.trim().length > 0;
30
+ }
31
+ function isIntegerIn(value, min, max) {
32
+ return Number.isSafeInteger(value) && value >= min && value <= max;
33
+ }
34
+ /**
35
+ * Join mode and `S` of one endpoint, or `undefined` when its fields disagree
36
+ * and a receiver must ignore it (4.1). `sourceAddress` alone selects the mode;
37
+ * `protocol` may only restate it, so "amt" and "atsc3" (draft -00) are
38
+ * inconsistent here: a bearer is a `networkSource`, never a protocol.
39
+ */
40
+ export function multicastEndpointSource(endpoint) {
41
+ if (!isObject(endpoint))
42
+ return undefined;
43
+ const sourceAddress = endpoint["sourceAddress"];
44
+ if (sourceAddress !== undefined && !isNonEmptyString(sourceAddress))
45
+ return undefined;
46
+ const mode = sourceAddress === undefined ? "asm" : "ssm";
47
+ const protocol = endpoint["protocol"];
48
+ if (protocol !== undefined && protocol !== mode)
49
+ return undefined;
50
+ const auth = endpoint["auth"];
51
+ const senderAddress = isObject(auth) ? auth["senderAddress"] : undefined;
52
+ if (mode === "ssm")
53
+ return senderAddress === undefined ? { mode, source: sourceAddress } : undefined;
54
+ if (auth === undefined)
55
+ return { mode };
56
+ return isNonEmptyString(senderAddress) ? { mode, source: senderAddress } : undefined;
57
+ }
58
+ function authIssues(auth) {
59
+ const base = "$.multicast.auth";
60
+ const issue = (path, message) => [
61
+ { code: "multicast_auth", path: `${base}${path}`, message },
62
+ ];
63
+ if (!isObject(auth))
64
+ return issue("", "auth must be an object");
65
+ const unknown = Object.keys(auth).filter(key => !AUTH_MEMBERS.has(key));
66
+ if (unknown.length > 0) {
67
+ return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -01 7.2.6 defines scheme, version, sig, keys and minEpoch`);
68
+ }
69
+ if (auth["scheme"] !== "bc-provenance")
70
+ return issue(".scheme", 'scheme must be "bc-provenance"');
71
+ if (auth["version"] !== 2)
72
+ return issue(".version", "version must be 2 (bc-provenance version 2, draft -01 7.2)");
73
+ if (auth["sig"] !== "ed25519")
74
+ return issue(".sig", 'sig must be "ed25519"');
75
+ const keys = auth["keys"];
76
+ if (!Array.isArray(keys) || keys.length < 1 || keys.length > 4) {
77
+ return issue(".keys", "keys must be an array of one to four {kid, publicKey, firstEpoch} objects");
78
+ }
79
+ const kids = new Set();
80
+ const firstEpochs = new Set();
81
+ for (let index = 0; index < keys.length; index++) {
82
+ const key = keys[index];
83
+ const at = `.keys[${index}]`;
84
+ if (!isObject(key) || Object.keys(key).some(member => !KEY_MEMBERS.has(member))) {
85
+ return issue(at, "a key is exactly {kid, publicKey, firstEpoch}");
86
+ }
87
+ if (!isIntegerIn(key["kid"], 0, UINT32_MAX))
88
+ return issue(`${at}.kid`, "kid must be an unsigned 32-bit integer");
89
+ if (typeof key["publicKey"] !== "string" || !ED25519_PUBLIC_KEY_BASE64URL.test(key["publicKey"])) {
90
+ return issue(`${at}.publicKey`, "publicKey must be a 32-octet Ed25519 key in canonical unpadded base64url");
91
+ }
92
+ if (!isIntegerIn(key["firstEpoch"], 0, UINT32_MAX)) {
93
+ return issue(`${at}.firstEpoch`, "firstEpoch must be an unsigned 32-bit integer");
94
+ }
95
+ // A repeated kid or firstEpoch leaves no key set (7.2.6): fail the whole
96
+ // block, never fall back to unauthenticated reception.
97
+ if (kids.has(key["kid"]))
98
+ return issue(`${at}.kid`, `kid ${key["kid"]} is repeated; the catalog holds no key set`);
99
+ if (firstEpochs.has(key["firstEpoch"])) {
100
+ return issue(`${at}.firstEpoch`, `firstEpoch ${key["firstEpoch"]} is repeated; the catalog holds no key set`);
101
+ }
102
+ kids.add(key["kid"]);
103
+ firstEpochs.add(key["firstEpoch"]);
104
+ }
105
+ if (!isIntegerIn(auth["minEpoch"], 0, UINT32_MAX)) {
106
+ return issue(".minEpoch", "minEpoch must be an unsigned 32-bit integer");
107
+ }
108
+ return [];
109
+ }
110
+ function endpointAuthIssue(endpoint, mode, at) {
111
+ const auth = endpoint["auth"];
112
+ if (!isObject(auth))
113
+ return { path: `${at}.auth`, message: "auth must be an object" };
114
+ const unknown = Object.keys(auth).filter(key => !ENDPOINT_AUTH_MEMBERS.has(key));
115
+ if (unknown.length > 0)
116
+ return { path: `${at}.auth`, message: `auth has unknown member(s) ${unknown.join(", ")}` };
117
+ if (!isIntegerIn(auth["manifestPort"], 1, 65535)) {
118
+ return { path: `${at}.auth.manifestPort`, message: "manifestPort must be an integer from 1 to 65535" };
119
+ }
120
+ if (!isIntegerIn(auth["streamId"], 0, UINT32_MAX)) {
121
+ return { path: `${at}.auth.streamId`, message: "streamId must be an unsigned 32-bit integer" };
122
+ }
123
+ if (mode === "ssm" && auth["senderAddress"] !== undefined) {
124
+ return { path: `${at}.auth.senderAddress`, message: "senderAddress must not appear on an SSM endpoint; S is sourceAddress" };
125
+ }
126
+ if (mode === "asm" && !isNonEmptyString(auth["senderAddress"])) {
127
+ return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress" };
128
+ }
129
+ if (auth["maxAuthDelayMs"] !== undefined && !isIntegerIn(auth["maxAuthDelayMs"], 50, 1000)) {
130
+ return { path: `${at}.auth.maxAuthDelayMs`, message: "maxAuthDelayMs must be an integer from 50 to 1000" };
131
+ }
132
+ if (auth["manifestTimerMs"] !== undefined && !isIntegerIn(auth["manifestTimerMs"], 1, Number.MAX_SAFE_INTEGER)) {
133
+ return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be an integer of at least 1" };
134
+ }
135
+ if (auth["manifestTrack"] !== undefined && !isNonEmptyString(auth["manifestTrack"])) {
136
+ return { path: `${at}.auth.manifestTrack`, message: "manifestTrack must be a non-empty string" };
137
+ }
138
+ if (!isIntegerIn(endpoint["bandwidth"], 1, Number.MAX_SAFE_INTEGER)) {
139
+ return { path: `${at}.bandwidth`, message: "a protected endpoint requires bandwidth, which bounds the receiver's hold queues" };
140
+ }
141
+ return undefined;
142
+ }
143
+ /**
144
+ * Where a catalog object carries the namespace of the catalog track it was
145
+ * read from. A symbol, so it is never wire data and survives object spread;
146
+ * `Symbol.for`, so two bundled copies of this module agree on it.
147
+ */
148
+ export const CATALOG_NAMESPACE = Symbol.for("@blockcast/mmt-base/catalogNamespace");
149
+ /**
150
+ * `catalog` tagged with the namespace of its catalog track. Every receiver
151
+ * rule that takes the catalog (`multicastCatalogIssues`,
152
+ * `admittedMulticastEndpoints` and the transport selectors built on them)
153
+ * then judges the foreign-namespace rule against it, independent of track
154
+ * order. Tag once, where the catalog track is read.
155
+ */
156
+ export function withCatalogNamespace(catalog, namespace) {
157
+ return { ...catalog, [CATALOG_NAMESPACE]: namespace };
158
+ }
159
+ /**
160
+ * Every draft -01 4.1 / 7.2.6 violation in `catalog.multicast`, in document
161
+ * order. Packet-id, group-address and track-existence rules are not here; the
162
+ * container validator and the receivers already check those.
163
+ *
164
+ * `catalogNamespace` is the namespace of the catalog track, from `options` or else the
165
+ * catalog's `withCatalogNamespace` tag. Without it the
166
+ * foreign-namespace rule can only compare listed tracks with each other: the
167
+ * first listed track's namespace becomes the reference, so which side of a
168
+ * disagreement is dropped depends on order. It still fails closed; pass
169
+ * `catalogNamespace` wherever the catalog track is known.
170
+ */
171
+ export function multicastCatalogIssues(catalog, options = {}) {
172
+ if (!isObject(catalog))
173
+ return [];
174
+ const issues = [];
175
+ if ("multicast.auth" in catalog) {
176
+ // Fail closed: a draft -00 publisher meant the flow to be protected, and
177
+ // the key it names verifies nothing in bc-provenance version 2.
178
+ issues.push({
179
+ code: "multicast_auth",
180
+ path: '$["multicast.auth"]',
181
+ message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -01 7.2.6)',
182
+ });
183
+ }
184
+ const multicast = catalog["multicast"];
185
+ if (!isObject(multicast))
186
+ return issues;
187
+ const protectedCatalog = multicast["auth"] !== undefined;
188
+ if (protectedCatalog)
189
+ issues.push(...authIssues(multicast["auth"]));
190
+ const endpoints = multicast["endpoints"];
191
+ if (!Array.isArray(endpoints))
192
+ return issues;
193
+ const tracks = Array.isArray(catalog["tracks"]) ? catalog["tracks"] : [];
194
+ const namespaceOf = new Map();
195
+ for (const track of tracks) {
196
+ if (isObject(track) && typeof track["name"] === "string")
197
+ namespaceOf.set(track["name"], track["namespace"]);
198
+ }
199
+ const tagged = catalog[CATALOG_NAMESPACE];
200
+ let referenceNamespace = options.catalogNamespace ?? (typeof tagged === "string" ? tagged : undefined);
201
+ const sources = [];
202
+ for (let index = 0; index < endpoints.length; index++) {
203
+ const endpoint = endpoints[index];
204
+ const at = `$.multicast.endpoints[${index}]`;
205
+ const fail = (code, path, message) => {
206
+ issues.push({ code, path, message, endpointIndex: index });
207
+ };
208
+ sources.push(undefined);
209
+ if (!isObject(endpoint)) {
210
+ fail("multicast_endpoint", at, "endpoint must be an object");
211
+ continue;
212
+ }
213
+ const protocol = endpoint["protocol"];
214
+ if (protocol !== undefined && protocol !== "ssm" && protocol !== "asm") {
215
+ fail("multicast_endpoint", `${at}.protocol`, `protocol must be "ssm" or "asm"; a bearer such as ${JSON.stringify(protocol)} is a networkSource entry (draft -01 4.2)`);
216
+ continue;
217
+ }
218
+ const hasAuth = endpoint["auth"] !== undefined;
219
+ if (protectedCatalog !== hasAuth) {
220
+ fail("multicast_endpoint_auth", `${at}.auth`, protectedCatalog
221
+ ? "every endpoint requires auth when multicast carries auth; a receiver ignores this endpoint"
222
+ : "auth names no key without multicast.auth; a receiver ignores this endpoint");
223
+ continue;
224
+ }
225
+ const sourceAddress = endpoint["sourceAddress"];
226
+ if (sourceAddress !== undefined && !isNonEmptyString(sourceAddress)) {
227
+ fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be a non-empty string");
228
+ continue;
229
+ }
230
+ const mode = sourceAddress === undefined ? "asm" : "ssm";
231
+ if (protocol !== undefined && protocol !== mode) {
232
+ fail("multicast_endpoint", `${at}.protocol`, `protocol ${JSON.stringify(protocol)} disagrees with sourceAddress, which selects ${mode}`);
233
+ continue;
234
+ }
235
+ // The (S, G, port) rule below compares ports with ===, so only an
236
+ // integer may reach it: "5001" and 5001 would otherwise both pass.
237
+ if (!isIntegerIn(endpoint["port"], 1, 65535)) {
238
+ fail("multicast_endpoint", `${at}.port`, "port must be an integer from 1 to 65535");
239
+ continue;
240
+ }
241
+ if (hasAuth) {
242
+ const authIssue = endpointAuthIssue(endpoint, mode, at);
243
+ if (authIssue) {
244
+ fail("multicast_endpoint_auth", authIssue.path, authIssue.message);
245
+ continue;
246
+ }
247
+ }
248
+ sources[index] = multicastEndpointSource(endpoint);
249
+ const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
250
+ for (let refIndex = 0; refIndex < refs.length; refIndex++) {
251
+ const ref = refs[refIndex];
252
+ const name = isObject(ref) ? ref["name"] : ref;
253
+ if (typeof name !== "string")
254
+ continue;
255
+ const namespace = namespaceOf.get(name);
256
+ if (typeof namespace !== "string")
257
+ continue;
258
+ referenceNamespace ??= namespace;
259
+ if (namespace !== referenceNamespace) {
260
+ fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} declares namespace ${JSON.stringify(namespace)}, not the catalog track's ${JSON.stringify(referenceNamespace)}`);
261
+ }
262
+ }
263
+ }
264
+ // One endpoint object per (S, G, port), and a manifestPort that is no port
265
+ // and no other manifestPort of its (S, G) (4.1, 7.2.6). The rule binds the
266
+ // endpoint whose manifestPort clashes; two equal tuples or two equal
267
+ // manifestPorts break it on both sides, so both are named.
268
+ const tupleOf = (index) => {
269
+ const endpoint = endpoints[index];
270
+ const auth = endpoint["auth"];
271
+ return {
272
+ sg: JSON.stringify([sources[index].source ?? null, endpoint["groupAddress"]]),
273
+ port: endpoint["port"],
274
+ manifestPort: isObject(auth) ? auth["manifestPort"] : undefined,
275
+ };
276
+ };
277
+ for (let index = 0; index < endpoints.length; index++) {
278
+ if (!sources[index])
279
+ continue;
280
+ const own = tupleOf(index);
281
+ const at = `$.multicast.endpoints[${index}]`;
282
+ if (own.manifestPort !== undefined && own.manifestPort === own.port) {
283
+ issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
284
+ continue;
285
+ }
286
+ for (let other = 0; other < endpoints.length; other++) {
287
+ if (other === index || !sources[other])
288
+ continue;
289
+ const peer = tupleOf(other);
290
+ if (peer.sg !== own.sg)
291
+ continue;
292
+ if (peer.port === own.port) {
293
+ issues.push({ code: "multicast_endpoint", path: `${at}.port`, message: `(S, G, port) is shared with endpoint ${other}; one endpoint object per multicast tuple`, endpointIndex: index });
294
+ break;
295
+ }
296
+ if (own.manifestPort !== undefined && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
297
+ issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: `manifestPort is a port or manifestPort of endpoint ${other} on the same (S, G)`, endpointIndex: index });
298
+ break;
299
+ }
300
+ }
301
+ }
302
+ return issues;
303
+ }
304
+ /**
305
+ * Indices of the endpoints a receiver may use: none when a catalog-level
306
+ * issue leaves it no key set (7.2.6), otherwise every endpoint no issue
307
+ * names. Other receiver checks (group address, packet ids) still apply.
308
+ */
309
+ export function admittedMulticastEndpoints(catalog, options = {}) {
310
+ const multicast = isObject(catalog) ? catalog["multicast"] : undefined;
311
+ const endpoints = isObject(multicast) && Array.isArray(multicast["endpoints"]) ? multicast["endpoints"] : [];
312
+ const issues = multicastCatalogIssues(catalog, options);
313
+ if (issues.some(issue => issue.endpointIndex === undefined))
314
+ return new Set();
315
+ const ignored = new Set(issues.map(issue => issue.endpointIndex));
316
+ return new Set(endpoints.map((_, index) => index).filter(index => !ignored.has(index)));
317
+ }
318
+ //# sourceMappingURL=multicast-catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multicast-catalog.js","sourceRoot":"","sources":["../src/multicast-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA2BH,yDAAyD;AACzD,MAAM,CAAC,MAAM,4BAA4B,GAAG,uCAAuC,CAAC;AAEpF,MAAM,UAAU,GAAG,WAAW,CAAC;AAC/B,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AAC/E,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;AAChE,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACrC,cAAc;IACd,UAAU;IACV,eAAe;IACf,gBAAgB;IAChB,iBAAiB;IACjB,eAAe;CACf,CAAC,CAAC;A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AC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACzF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockcast/mmt-base",
3
- "version": "0.4.0-main.94b7ef7dcd8d",
3
+ "version": "0.4.0-main.9d97fa55ba69",
4
4
  "description": "Shared MMTP parsing primitives and protocol constants (zero FEC dependency). Hosts MMTP_HEADER_SIZE, parseMMTPHeader, extractMFUPayload and friends, plus wire constants such as DEFAULT_AMT_RELAY_PORT, so @blockcast/mmt-fec, @blockcast/mmt-container and @blockcast/mmt-transport can share one definition without a circular dep.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -5,3 +5,4 @@ export * from './signalling.js'
5
5
  export * from './serial-number.js'
6
6
  export * from './fec-block-profile.js'
7
7
  export * from './catalog-fec-source.js'
8
+ export * from './multicast-catalog.js'
package/src/mmtp.ts CHANGED
@@ -480,7 +480,7 @@ export interface MFUExtraction {
480
480
  * from the payload boundary, even if fecType >= 1 in the MMTP header. Use this for
481
481
  * FEC-recovered symbols where the FEC PID was already stripped before WASM decoding
482
482
  * but the fecType bits in byte 0 still reflect the original packet (FEC Type=1 per
483
- * draft-ramadan-moq-mmt-00 §3.1).
483
+ * draft-ramadan-moq-mmt-01 §3.1).
484
484
  * @param options.overlayDeclared The catalog declares a keyframe overlay for this
485
485
  * source, so a RAP packet carries an 8-byte trailer (see MFUExtractOptions).
486
486
  * @returns Extracted MFU data + metadata, or null if packet is too small
@@ -0,0 +1,350 @@
1
+ /**
2
+ * The draft-ramadan-moq-multicast-01 endpoint and `auth` rules, written once
3
+ * for both sides of the catalog: `validateCmsfMmtpCatalog` in
4
+ * `@blockcast/mmt-container` throws the first issue, and the receivers in
5
+ * `@blockcast/mmt-transport` ignore every endpoint an issue names (all of
6
+ * them when the issue is catalog-level). It lives here because mmt-base is
7
+ * the only package both depend on.
8
+ *
9
+ * Draft: Blockcast/moqcast-draft@fd962fd73d21ed281b60219c11ea61cc9e4e91c4
10
+ * (PR #2 head; normative text equal to 3162ef93), sections 4.1 and 7.2.6.
11
+ */
12
+
13
+ export type MulticastJoinMode = "ssm" | "asm";
14
+
15
+ /** An endpoint's join mode and `S` (4.1): `sourceAddress` on SSM,
16
+ * `auth.senderAddress` on protected ASM, absent on unprotected ASM. */
17
+ export interface MulticastEndpointSource {
18
+ mode: MulticastJoinMode;
19
+ source?: string;
20
+ }
21
+
22
+ export type MulticastCatalogIssueCode =
23
+ | "multicast_auth"
24
+ | "multicast_endpoint"
25
+ | "multicast_endpoint_auth"
26
+ | "multicast_track";
27
+
28
+ export interface MulticastCatalogIssue {
29
+ code: MulticastCatalogIssueCode;
30
+ /** JSONPath of the offending field. */
31
+ path: string;
32
+ message: string;
33
+ /** Endpoint the issue makes a receiver ignore; absent for a catalog-level
34
+ * issue, which leaves the receiver no endpoint at all (7.2.6). */
35
+ endpointIndex?: number;
36
+ }
37
+
38
+ /** Canonical unpadded base64url of exactly 32 octets. */
39
+ export const ED25519_PUBLIC_KEY_BASE64URL = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
40
+
41
+ const UINT32_MAX = 0xffff_ffff;
42
+ const AUTH_MEMBERS = new Set(["scheme", "version", "sig", "keys", "minEpoch"]);
43
+ const KEY_MEMBERS = new Set(["kid", "publicKey", "firstEpoch"]);
44
+ const ENDPOINT_AUTH_MEMBERS = new Set([
45
+ "manifestPort",
46
+ "streamId",
47
+ "senderAddress",
48
+ "maxAuthDelayMs",
49
+ "manifestTimerMs",
50
+ "manifestTrack",
51
+ ]);
52
+
53
+ type JsonObject = Record<string, unknown>;
54
+
55
+ function isObject(value: unknown): value is JsonObject {
56
+ return typeof value === "object" && value !== null && !Array.isArray(value);
57
+ }
58
+
59
+ function isNonEmptyString(value: unknown): value is string {
60
+ return typeof value === "string" && value.trim().length > 0;
61
+ }
62
+
63
+ function isIntegerIn(value: unknown, min: number, max: number): value is number {
64
+ return Number.isSafeInteger(value) && (value as number) >= min && (value as number) <= max;
65
+ }
66
+
67
+ /**
68
+ * Join mode and `S` of one endpoint, or `undefined` when its fields disagree
69
+ * and a receiver must ignore it (4.1). `sourceAddress` alone selects the mode;
70
+ * `protocol` may only restate it, so "amt" and "atsc3" (draft -00) are
71
+ * inconsistent here: a bearer is a `networkSource`, never a protocol.
72
+ */
73
+ export function multicastEndpointSource(endpoint: unknown): MulticastEndpointSource | undefined {
74
+ if (!isObject(endpoint)) return undefined;
75
+ const sourceAddress = endpoint["sourceAddress"];
76
+ if (sourceAddress !== undefined && !isNonEmptyString(sourceAddress)) return undefined;
77
+ const mode: MulticastJoinMode = sourceAddress === undefined ? "asm" : "ssm";
78
+ const protocol = endpoint["protocol"];
79
+ if (protocol !== undefined && protocol !== mode) return undefined;
80
+ const auth = endpoint["auth"];
81
+ const senderAddress = isObject(auth) ? auth["senderAddress"] : undefined;
82
+ if (mode === "ssm") return senderAddress === undefined ? { mode, source: sourceAddress as string } : undefined;
83
+ if (auth === undefined) return { mode };
84
+ return isNonEmptyString(senderAddress) ? { mode, source: senderAddress } : undefined;
85
+ }
86
+
87
+ function authIssues(auth: unknown): MulticastCatalogIssue[] {
88
+ const base = "$.multicast.auth";
89
+ const issue = (path: string, message: string): MulticastCatalogIssue[] => [
90
+ { code: "multicast_auth", path: `${base}${path}`, message },
91
+ ];
92
+ if (!isObject(auth)) return issue("", "auth must be an object");
93
+ const unknown = Object.keys(auth).filter(key => !AUTH_MEMBERS.has(key));
94
+ if (unknown.length > 0) {
95
+ return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -01 7.2.6 defines scheme, version, sig, keys and minEpoch`);
96
+ }
97
+ if (auth["scheme"] !== "bc-provenance") return issue(".scheme", 'scheme must be "bc-provenance"');
98
+ if (auth["version"] !== 2) return issue(".version", "version must be 2 (bc-provenance version 2, draft -01 7.2)");
99
+ if (auth["sig"] !== "ed25519") return issue(".sig", 'sig must be "ed25519"');
100
+ const keys = auth["keys"];
101
+ if (!Array.isArray(keys) || keys.length < 1 || keys.length > 4) {
102
+ return issue(".keys", "keys must be an array of one to four {kid, publicKey, firstEpoch} objects");
103
+ }
104
+ const kids = new Set<number>();
105
+ const firstEpochs = new Set<number>();
106
+ for (let index = 0; index < keys.length; index++) {
107
+ const key = keys[index];
108
+ const at = `.keys[${index}]`;
109
+ if (!isObject(key) || Object.keys(key).some(member => !KEY_MEMBERS.has(member))) {
110
+ return issue(at, "a key is exactly {kid, publicKey, firstEpoch}");
111
+ }
112
+ if (!isIntegerIn(key["kid"], 0, UINT32_MAX)) return issue(`${at}.kid`, "kid must be an unsigned 32-bit integer");
113
+ if (typeof key["publicKey"] !== "string" || !ED25519_PUBLIC_KEY_BASE64URL.test(key["publicKey"])) {
114
+ return issue(`${at}.publicKey`, "publicKey must be a 32-octet Ed25519 key in canonical unpadded base64url");
115
+ }
116
+ if (!isIntegerIn(key["firstEpoch"], 0, UINT32_MAX)) {
117
+ return issue(`${at}.firstEpoch`, "firstEpoch must be an unsigned 32-bit integer");
118
+ }
119
+ // A repeated kid or firstEpoch leaves no key set (7.2.6): fail the whole
120
+ // block, never fall back to unauthenticated reception.
121
+ if (kids.has(key["kid"])) return issue(`${at}.kid`, `kid ${key["kid"]} is repeated; the catalog holds no key set`);
122
+ if (firstEpochs.has(key["firstEpoch"])) {
123
+ return issue(`${at}.firstEpoch`, `firstEpoch ${key["firstEpoch"]} is repeated; the catalog holds no key set`);
124
+ }
125
+ kids.add(key["kid"]);
126
+ firstEpochs.add(key["firstEpoch"]);
127
+ }
128
+ if (!isIntegerIn(auth["minEpoch"], 0, UINT32_MAX)) {
129
+ return issue(".minEpoch", "minEpoch must be an unsigned 32-bit integer");
130
+ }
131
+ return [];
132
+ }
133
+
134
+ function endpointAuthIssue(
135
+ endpoint: JsonObject,
136
+ mode: MulticastJoinMode,
137
+ at: string,
138
+ ): { path: string; message: string } | undefined {
139
+ const auth = endpoint["auth"];
140
+ if (!isObject(auth)) return { path: `${at}.auth`, message: "auth must be an object" };
141
+ const unknown = Object.keys(auth).filter(key => !ENDPOINT_AUTH_MEMBERS.has(key));
142
+ if (unknown.length > 0) return { path: `${at}.auth`, message: `auth has unknown member(s) ${unknown.join(", ")}` };
143
+ if (!isIntegerIn(auth["manifestPort"], 1, 65535)) {
144
+ return { path: `${at}.auth.manifestPort`, message: "manifestPort must be an integer from 1 to 65535" };
145
+ }
146
+ if (!isIntegerIn(auth["streamId"], 0, UINT32_MAX)) {
147
+ return { path: `${at}.auth.streamId`, message: "streamId must be an unsigned 32-bit integer" };
148
+ }
149
+ if (mode === "ssm" && auth["senderAddress"] !== undefined) {
150
+ return { path: `${at}.auth.senderAddress`, message: "senderAddress must not appear on an SSM endpoint; S is sourceAddress" };
151
+ }
152
+ if (mode === "asm" && !isNonEmptyString(auth["senderAddress"])) {
153
+ return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress" };
154
+ }
155
+ if (auth["maxAuthDelayMs"] !== undefined && !isIntegerIn(auth["maxAuthDelayMs"], 50, 1000)) {
156
+ return { path: `${at}.auth.maxAuthDelayMs`, message: "maxAuthDelayMs must be an integer from 50 to 1000" };
157
+ }
158
+ if (auth["manifestTimerMs"] !== undefined && !isIntegerIn(auth["manifestTimerMs"], 1, Number.MAX_SAFE_INTEGER)) {
159
+ return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be an integer of at least 1" };
160
+ }
161
+ if (auth["manifestTrack"] !== undefined && !isNonEmptyString(auth["manifestTrack"])) {
162
+ return { path: `${at}.auth.manifestTrack`, message: "manifestTrack must be a non-empty string" };
163
+ }
164
+ if (!isIntegerIn(endpoint["bandwidth"], 1, Number.MAX_SAFE_INTEGER)) {
165
+ return { path: `${at}.bandwidth`, message: "a protected endpoint requires bandwidth, which bounds the receiver's hold queues" };
166
+ }
167
+ return undefined;
168
+ }
169
+
170
+ /**
171
+ * Where a catalog object carries the namespace of the catalog track it was
172
+ * read from. A symbol, so it is never wire data and survives object spread;
173
+ * `Symbol.for`, so two bundled copies of this module agree on it.
174
+ */
175
+ export const CATALOG_NAMESPACE: unique symbol = Symbol.for("@blockcast/mmt-base/catalogNamespace");
176
+
177
+ /**
178
+ * `catalog` tagged with the namespace of its catalog track. Every receiver
179
+ * rule that takes the catalog (`multicastCatalogIssues`,
180
+ * `admittedMulticastEndpoints` and the transport selectors built on them)
181
+ * then judges the foreign-namespace rule against it, independent of track
182
+ * order. Tag once, where the catalog track is read.
183
+ */
184
+ export function withCatalogNamespace<T extends object>(catalog: T, namespace: string): T {
185
+ return { ...catalog, [CATALOG_NAMESPACE]: namespace };
186
+ }
187
+
188
+ /**
189
+ * Every draft -01 4.1 / 7.2.6 violation in `catalog.multicast`, in document
190
+ * order. Packet-id, group-address and track-existence rules are not here; the
191
+ * container validator and the receivers already check those.
192
+ *
193
+ * `catalogNamespace` is the namespace of the catalog track, from `options` or else the
194
+ * catalog's `withCatalogNamespace` tag. Without it the
195
+ * foreign-namespace rule can only compare listed tracks with each other: the
196
+ * first listed track's namespace becomes the reference, so which side of a
197
+ * disagreement is dropped depends on order. It still fails closed; pass
198
+ * `catalogNamespace` wherever the catalog track is known.
199
+ */
200
+ export function multicastCatalogIssues(
201
+ catalog: unknown,
202
+ options: { catalogNamespace?: string } = {},
203
+ ): MulticastCatalogIssue[] {
204
+ if (!isObject(catalog)) return [];
205
+ const issues: MulticastCatalogIssue[] = [];
206
+ if ("multicast.auth" in catalog) {
207
+ // Fail closed: a draft -00 publisher meant the flow to be protected, and
208
+ // the key it names verifies nothing in bc-provenance version 2.
209
+ issues.push({
210
+ code: "multicast_auth",
211
+ path: '$["multicast.auth"]',
212
+ message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -01 7.2.6)',
213
+ });
214
+ }
215
+ const multicast = catalog["multicast"];
216
+ if (!isObject(multicast)) return issues;
217
+ const protectedCatalog = multicast["auth"] !== undefined;
218
+ if (protectedCatalog) issues.push(...authIssues(multicast["auth"]));
219
+ const endpoints = multicast["endpoints"];
220
+ if (!Array.isArray(endpoints)) return issues;
221
+
222
+ const tracks = Array.isArray(catalog["tracks"]) ? catalog["tracks"] : [];
223
+ const namespaceOf = new Map<string, unknown>();
224
+ for (const track of tracks) {
225
+ if (isObject(track) && typeof track["name"] === "string") namespaceOf.set(track["name"], track["namespace"]);
226
+ }
227
+ const tagged = (catalog as { [CATALOG_NAMESPACE]?: unknown })[CATALOG_NAMESPACE];
228
+ let referenceNamespace = options.catalogNamespace ?? (typeof tagged === "string" ? tagged : undefined);
229
+
230
+ const sources: Array<MulticastEndpointSource | undefined> = [];
231
+ for (let index = 0; index < endpoints.length; index++) {
232
+ const endpoint = endpoints[index];
233
+ const at = `$.multicast.endpoints[${index}]`;
234
+ const fail = (code: MulticastCatalogIssueCode, path: string, message: string) => {
235
+ issues.push({ code, path, message, endpointIndex: index });
236
+ };
237
+ sources.push(undefined);
238
+ if (!isObject(endpoint)) {
239
+ fail("multicast_endpoint", at, "endpoint must be an object");
240
+ continue;
241
+ }
242
+ const protocol = endpoint["protocol"];
243
+ if (protocol !== undefined && protocol !== "ssm" && protocol !== "asm") {
244
+ fail("multicast_endpoint", `${at}.protocol`, `protocol must be "ssm" or "asm"; a bearer such as ${JSON.stringify(protocol)} is a networkSource entry (draft -01 4.2)`);
245
+ continue;
246
+ }
247
+ const hasAuth = endpoint["auth"] !== undefined;
248
+ if (protectedCatalog !== hasAuth) {
249
+ fail(
250
+ "multicast_endpoint_auth",
251
+ `${at}.auth`,
252
+ protectedCatalog
253
+ ? "every endpoint requires auth when multicast carries auth; a receiver ignores this endpoint"
254
+ : "auth names no key without multicast.auth; a receiver ignores this endpoint",
255
+ );
256
+ continue;
257
+ }
258
+ const sourceAddress = endpoint["sourceAddress"];
259
+ if (sourceAddress !== undefined && !isNonEmptyString(sourceAddress)) {
260
+ fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be a non-empty string");
261
+ continue;
262
+ }
263
+ const mode: MulticastJoinMode = sourceAddress === undefined ? "asm" : "ssm";
264
+ if (protocol !== undefined && protocol !== mode) {
265
+ fail("multicast_endpoint", `${at}.protocol`, `protocol ${JSON.stringify(protocol)} disagrees with sourceAddress, which selects ${mode}`);
266
+ continue;
267
+ }
268
+ // The (S, G, port) rule below compares ports with ===, so only an
269
+ // integer may reach it: "5001" and 5001 would otherwise both pass.
270
+ if (!isIntegerIn(endpoint["port"], 1, 65535)) {
271
+ fail("multicast_endpoint", `${at}.port`, "port must be an integer from 1 to 65535");
272
+ continue;
273
+ }
274
+ if (hasAuth) {
275
+ const authIssue = endpointAuthIssue(endpoint, mode, at);
276
+ if (authIssue) {
277
+ fail("multicast_endpoint_auth", authIssue.path, authIssue.message);
278
+ continue;
279
+ }
280
+ }
281
+ sources[index] = multicastEndpointSource(endpoint);
282
+
283
+ const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
284
+ for (let refIndex = 0; refIndex < refs.length; refIndex++) {
285
+ const ref = refs[refIndex];
286
+ const name = isObject(ref) ? ref["name"] : ref;
287
+ if (typeof name !== "string") continue;
288
+ const namespace = namespaceOf.get(name);
289
+ if (typeof namespace !== "string") continue;
290
+ referenceNamespace ??= namespace;
291
+ if (namespace !== referenceNamespace) {
292
+ fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} declares namespace ${JSON.stringify(namespace)}, not the catalog track's ${JSON.stringify(referenceNamespace)}`);
293
+ }
294
+ }
295
+ }
296
+
297
+ // One endpoint object per (S, G, port), and a manifestPort that is no port
298
+ // and no other manifestPort of its (S, G) (4.1, 7.2.6). The rule binds the
299
+ // endpoint whose manifestPort clashes; two equal tuples or two equal
300
+ // manifestPorts break it on both sides, so both are named.
301
+ const tupleOf = (index: number) => {
302
+ const endpoint = endpoints[index] as JsonObject;
303
+ const auth = endpoint["auth"];
304
+ return {
305
+ sg: JSON.stringify([sources[index]!.source ?? null, endpoint["groupAddress"]]),
306
+ port: endpoint["port"],
307
+ manifestPort: isObject(auth) ? auth["manifestPort"] : undefined,
308
+ };
309
+ };
310
+ for (let index = 0; index < endpoints.length; index++) {
311
+ if (!sources[index]) continue;
312
+ const own = tupleOf(index);
313
+ const at = `$.multicast.endpoints[${index}]`;
314
+ if (own.manifestPort !== undefined && own.manifestPort === own.port) {
315
+ issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
316
+ continue;
317
+ }
318
+ for (let other = 0; other < endpoints.length; other++) {
319
+ if (other === index || !sources[other]) continue;
320
+ const peer = tupleOf(other);
321
+ if (peer.sg !== own.sg) continue;
322
+ if (peer.port === own.port) {
323
+ issues.push({ code: "multicast_endpoint", path: `${at}.port`, message: `(S, G, port) is shared with endpoint ${other}; one endpoint object per multicast tuple`, endpointIndex: index });
324
+ break;
325
+ }
326
+ if (own.manifestPort !== undefined && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
327
+ issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: `manifestPort is a port or manifestPort of endpoint ${other} on the same (S, G)`, endpointIndex: index });
328
+ break;
329
+ }
330
+ }
331
+ }
332
+ return issues;
333
+ }
334
+
335
+ /**
336
+ * Indices of the endpoints a receiver may use: none when a catalog-level
337
+ * issue leaves it no key set (7.2.6), otherwise every endpoint no issue
338
+ * names. Other receiver checks (group address, packet ids) still apply.
339
+ */
340
+ export function admittedMulticastEndpoints(
341
+ catalog: unknown,
342
+ options: { catalogNamespace?: string } = {},
343
+ ): ReadonlySet<number> {
344
+ const multicast = isObject(catalog) ? catalog["multicast"] : undefined;
345
+ const endpoints = isObject(multicast) && Array.isArray(multicast["endpoints"]) ? multicast["endpoints"] : [];
346
+ const issues = multicastCatalogIssues(catalog, options);
347
+ if (issues.some(issue => issue.endpointIndex === undefined)) return new Set();
348
+ const ignored = new Set(issues.map(issue => issue.endpointIndex));
349
+ return new Set(endpoints.map((_, index) => index).filter(index => !ignored.has(index)));
350
+ }