@blockcast/mmt-container 0.4.0-main.bb90ce9247fa → 0.4.0-main.bbdfdbf39ded

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.
Files changed (205) hide show
  1. package/README.md +36 -20
  2. package/dist/align.d.ts +24 -18
  3. package/dist/align.d.ts.map +1 -1
  4. package/dist/align.js +23 -4
  5. package/dist/align.js.map +2 -2
  6. package/dist/browser-runtime.js +1721 -705
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +72 -34
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +309 -204
  11. package/dist/carp-catalog.js.map +3 -3
  12. package/dist/catalog-fec-params.d.ts +15 -4
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +137 -50
  15. package/dist/catalog-fec-params.js.map +4 -4
  16. package/dist/catalog-network-source.d.ts +24 -2
  17. package/dist/catalog-network-source.d.ts.map +1 -1
  18. package/dist/catalog-network-source.js +24 -1
  19. package/dist/catalog-network-source.js.map +3 -3
  20. package/dist/catalog-validator.d.ts +4 -3
  21. package/dist/catalog-validator.d.ts.map +1 -1
  22. package/dist/catalog-validator.js +0 -29
  23. package/dist/catalog-validator.js.map +3 -3
  24. package/dist/delivery-catalog.js +100 -230
  25. package/dist/delivery-catalog.js.map +4 -4
  26. package/dist/fec-manager.d.ts +64 -1
  27. package/dist/fec-manager.d.ts.map +1 -1
  28. package/dist/fec-manager.js +275 -62
  29. package/dist/fec-manager.js.map +4 -4
  30. package/dist/fec-state.d.ts +5 -3
  31. package/dist/fec-state.d.ts.map +1 -1
  32. package/dist/fec-state.js +34 -12
  33. package/dist/fec-state.js.map +4 -4
  34. package/dist/fec-worker-setup.d.ts +2 -0
  35. package/dist/fec-worker-setup.d.ts.map +1 -1
  36. package/dist/fec-worker-setup.js +15 -3
  37. package/dist/fec-worker-setup.js.map +3 -3
  38. package/dist/index.d.ts +5 -5
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +14 -8
  41. package/dist/index.js.map +2 -2
  42. package/dist/iso-block-locator.d.ts +29 -0
  43. package/dist/iso-block-locator.d.ts.map +1 -1
  44. package/dist/iso-block-locator.js +100 -17
  45. package/dist/iso-block-locator.js.map +4 -4
  46. package/dist/manifest-auth-plan.d.ts +26 -25
  47. package/dist/manifest-auth-plan.d.ts.map +1 -1
  48. package/dist/manifest-auth-plan.js +331 -1171
  49. package/dist/manifest-auth-plan.js.map +4 -4
  50. package/dist/mfu-reassembler.js +24 -13
  51. package/dist/mfu-reassembler.js.map +3 -3
  52. package/dist/mmtp-container-parser.d.ts.map +1 -1
  53. package/dist/mmtp-container-parser.js +96 -22
  54. package/dist/mmtp-container-parser.js.map +3 -3
  55. package/dist/mmtp-container-parser.no-modules.js +1138 -325
  56. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  57. package/dist/mmtp-decode-pipeline.js +96 -22
  58. package/dist/mmtp-decode-pipeline.js.map +3 -3
  59. package/dist/mmtp-fec-session.d.ts +159 -0
  60. package/dist/mmtp-fec-session.d.ts.map +1 -0
  61. package/dist/mmtp-fec-session.js +531 -0
  62. package/dist/mmtp-fec-session.js.map +7 -0
  63. package/dist/mmtp-router.d.ts +31 -5
  64. package/dist/mmtp-router.d.ts.map +1 -1
  65. package/dist/mmtp-router.js +168 -22
  66. package/dist/mmtp-router.js.map +3 -3
  67. package/dist/multicast-auth-catalog.d.ts +86 -92
  68. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  69. package/dist/multicast-auth-catalog.js +347 -132
  70. package/dist/multicast-auth-catalog.js.map +4 -4
  71. package/dist/multicast-input.d.ts +28 -6
  72. package/dist/multicast-input.d.ts.map +1 -1
  73. package/dist/multicast-input.js +293 -28
  74. package/dist/multicast-input.js.map +3 -3
  75. package/dist/multicast-manager.d.ts +89 -5
  76. package/dist/multicast-manager.d.ts.map +1 -1
  77. package/dist/multicast-manager.js +730 -356
  78. package/dist/multicast-manager.js.map +4 -4
  79. package/dist/multicast-transport.d.ts +12 -2
  80. package/dist/multicast-transport.d.ts.map +1 -1
  81. package/dist/multicast-transport.js +111 -235
  82. package/dist/multicast-transport.js.map +4 -4
  83. package/dist/multicast-unwrap.js +24 -13
  84. package/dist/multicast-unwrap.js.map +3 -3
  85. package/dist/no-modules.d.ts +4 -1
  86. package/dist/no-modules.d.ts.map +1 -1
  87. package/dist/no-modules.js +1087 -309
  88. package/dist/no-modules.js.map +4 -4
  89. package/dist/phase14-catalog-override.d.ts +1 -1
  90. package/dist/phase14-catalog-override.d.ts.map +1 -1
  91. package/dist/phase14-catalog-override.js +2 -2
  92. package/dist/phase14-catalog-override.js.map +2 -2
  93. package/dist/repair-fetch.d.ts +81 -6
  94. package/dist/repair-fetch.d.ts.map +1 -1
  95. package/dist/repair-fetch.js +159 -31
  96. package/dist/repair-fetch.js.map +3 -3
  97. package/dist/repair-layers.d.ts +2 -0
  98. package/dist/repair-layers.d.ts.map +1 -1
  99. package/dist/repair-layers.js +22 -2
  100. package/dist/repair-layers.js.map +3 -3
  101. package/dist/sample-combiner.d.ts +7 -1
  102. package/dist/sample-combiner.d.ts.map +1 -1
  103. package/dist/sample-combiner.js +14 -2
  104. package/dist/sample-combiner.js.map +2 -2
  105. package/dist/signaling.d.ts +2 -2
  106. package/dist/signaling.d.ts.map +1 -1
  107. package/dist/signaling.js +6 -3
  108. package/dist/signaling.js.map +3 -3
  109. package/dist/source-auth.js +2710 -7
  110. package/dist/source-auth.js.map +4 -4
  111. package/dist/switching-set-alignment.d.ts +1 -1
  112. package/dist/switching-set-alignment.js.map +1 -1
  113. package/dist/timestamp-codec.js +24 -13
  114. package/dist/timestamp-codec.js.map +3 -3
  115. package/dist/wasm-mfu-reassembler.js +3 -0
  116. package/dist/wasm-mfu-reassembler.js.map +3 -3
  117. package/dist/wasm-mmtp-container-parser.js +96 -22
  118. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  119. package/package.json +6 -9
  120. package/schemas/catalog.schema.json +124 -37
  121. package/src/align.ts +52 -21
  122. package/src/carp-catalog.ts +163 -61
  123. package/src/catalog-fec-params.ts +66 -20
  124. package/src/catalog-network-source.ts +45 -2
  125. package/src/catalog-validator.ts +4 -11
  126. package/src/fec-manager.ts +239 -63
  127. package/src/fec-state.ts +14 -12
  128. package/src/fec-worker-setup.ts +20 -2
  129. package/src/index.ts +29 -10
  130. package/src/iso-block-locator.ts +97 -6
  131. package/src/manifest-auth-plan.ts +39 -91
  132. package/src/mmtp-container-parser.ts +75 -7
  133. package/src/mmtp-fec-session.ts +533 -0
  134. package/src/mmtp-router.ts +133 -5
  135. package/src/multicast-auth-catalog.ts +131 -238
  136. package/src/multicast-input.ts +119 -61
  137. package/src/multicast-manager.ts +258 -21
  138. package/src/multicast-transport.ts +17 -3
  139. package/src/no-modules.ts +7 -1
  140. package/src/phase14-catalog-override.ts +3 -3
  141. package/src/repair-fetch.ts +283 -39
  142. package/src/repair-layers.ts +22 -2
  143. package/src/sample-combiner.ts +15 -2
  144. package/src/signaling.ts +2 -2
  145. package/src/switching-set-alignment.ts +1 -1
  146. package/test-vectors/align.json +108 -32
  147. package/test-vectors/bc-provenance-v2.json +1526 -0
  148. package/test-vectors/catalog/README.md +65 -4
  149. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  150. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  151. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  152. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  153. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  154. package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
  155. package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
  156. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  157. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  158. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  159. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  160. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  161. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  162. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  163. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  164. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  165. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  166. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  167. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  168. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  169. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  170. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  171. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
  172. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
  173. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  174. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  175. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  176. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  177. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  178. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  179. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  180. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  181. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  182. package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
  183. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  184. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  185. package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
  186. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  187. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  188. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  189. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +2 -2
  190. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  191. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  192. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  193. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  194. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  195. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  196. package/test-vectors/catalog/section-codes.json +30 -1
  197. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  198. package/test-vectors/catalog-validation.json +101 -5
  199. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  200. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
  201. package/dist/fec-codec.d.ts +0 -32
  202. package/dist/fec-codec.d.ts.map +0 -1
  203. package/dist/fec-codec.js +0 -47
  204. package/dist/fec-codec.js.map +0 -7
  205. package/src/fec-codec.ts +0 -61
@@ -8,7 +8,8 @@ declare const process: { env: Record<string, string | undefined> } | undefined;
8
8
  /**
9
9
  * Multicast catalog input contract — validator + builder.
10
10
  *
11
- * Per draft-ramadan-moq-multicast-00 §3 + §4.1, the publisher (FFmpeg,
11
+ * Per draft-ramadan-moq-multicast-01 §3 + §4.1 + §7.2.6
12
+ * (Blockcast/moqcast-draft@fd962fd73d21ed281b60219c11ea61cc9e4e91c4), the publisher (FFmpeg,
12
13
  * cast bridge, GStreamer, OBS-bridge) populates `multicast.endpoints[]`
13
14
  * in the catalog when its output includes a UDP multicast destination.
14
15
  *
@@ -22,17 +23,23 @@ declare const process: { env: Record<string, string | undefined> } | undefined;
22
23
  * perform.
23
24
  *
24
25
  * Validation invariants (per codex review of BLO-3323 v2):
25
- * - protocol === 'ssm' → sourceAddress REQUIRED
26
- * - protocol === 'amt' → a catalog-level `multicast.networkSource` entry of
27
- * type "amt" REQUIRED; its `relay` is required only for
28
- * `discovery: "manual"` ("driad" resolves the relay at runtime).
29
- * A per-endpoint `relayAddress` input is LIFTED into that entry and is
30
- * never emitted onto the endpoint.
31
- * - protocol === 'atsc3' → a catalog-level `multicast.networkSource` entry of
32
- * type "atsc3" REQUIRED; it carries the frequency, PLP, service id and SLS
33
- * URI, which is the only tuning information an ATSC3 receiver has.
34
- * - protocol === 'ssm' | 'asm' → no `networkSource` entry required: a native
35
- * join describes no alternate bearer (BLO-37926).
26
+ * - The emitted mode is the one `sourceAddress` selects (present: SSM,
27
+ * absent: ASM), restated as `protocol`. Input `protocol` "ssm" requires
28
+ * `sourceAddress`, "asm" forbids it.
29
+ * - Input `protocol` "amt" / "atsc3" names a bearer, which draft -01
30
+ * carries as a `networkSource` entry, not a protocol: the `networkSource`
31
+ * entries of that type MOVE onto each endpoint that named it (so they
32
+ * no longer apply to native endpoints) and the protocol is never emitted.
33
+ * An entry of that type is REQUIRED: an AMT one's `relay` only for
34
+ * `discovery: "manual"` ("driad" resolves it at runtime), an ATSC3 one
35
+ * carries the only tuning information an ATSC3 receiver has. A
36
+ * per-endpoint `relayAddress` input is LIFTED into the AMT entry.
37
+ * - Native "ssm" | "asm" requires no `networkSource` entry: a native join
38
+ * describes no alternate bearer (BLO-37926).
39
+ * - `auth` (catalog) and endpoint `auth` follow draft -01 7.2.6 through the
40
+ * shared `multicastCatalogIssues` of `@blockcast/mmt-base`: all or
41
+ * nothing, `senderAddress` on ASM only, bandwidth required, and
42
+ * `(S, G, manifestPort)` clear of every port of its `(S, G)`.
36
43
  * - groupAddress is a valid IPv4 multicast group (224.0.0.0/4)
37
44
  * or IPv6 multicast group (ff00::/8)
38
45
  * - SSM groupAddress MUST be in 232.0.0.0/8 (IPv4) or ff3x::/32 (IPv6),
@@ -46,23 +53,31 @@ declare const process: { env: Record<string, string | undefined> } | undefined;
46
53
  * `signaling_packet_id`. The kind string matches cast's
47
54
  * `multicast_input.rs` so the two ports report the same reason.
48
55
  * - packetIds unique within an endpoint
49
- * - (sourceAddress, groupAddress, port) tuple unique across endpoints
56
+ * - (S, groupAddress, port) tuple unique across endpoints, S being
57
+ * sourceAddress (SSM), auth.senderAddress (protected ASM) or absent
50
58
  * - bandwidth (if present) > 0
51
59
  * - validUntil (if present) is a positive unix-ms timestamp
52
60
  *
53
- * @see draft-ramadan-moq-multicast-00 §4.1
61
+ * @see draft-ramadan-moq-multicast-01 §4.1, §7.2.6
54
62
  * @see .planning/drafts/blo-3323-multicast-catalog-source-of-truth.md
55
63
  */
56
64
 
57
- import { MMTP_PACKET_ID_MAX, MMTP_SIGNALING_PACKET_ID } from "@blockcast/mmt-base";
65
+ import { MMTP_PACKET_ID_MAX, MMTP_SIGNALING_PACKET_ID, multicastCatalogIssues } from "@blockcast/mmt-base";
58
66
  import {
59
67
  type AmtDiscovery,
60
68
  type MulticastCatalogConfig,
61
69
  type MulticastEndpoint,
62
- type MulticastProtocol,
63
70
  type MulticastTrackObject,
64
71
  type NetworkSource,
65
72
  } from "./carp-catalog.js";
73
+ import type { EndpointAuthConfig, MulticastAuthConfig } from "./multicast-auth-catalog.js";
74
+
75
+ /**
76
+ * Publisher input protocol. "ssm" / "asm" restate the mode `sourceAddress`
77
+ * selects; "amt" / "atsc3" (draft -00) name a bearer and are mapped onto an
78
+ * endpoint-level `networkSource`, never emitted.
79
+ */
80
+ export type MulticastInputProtocol = "ssm" | "asm" | "amt" | "atsc3";
66
81
 
67
82
  /**
68
83
  * Strict typed input for one multicast endpoint. The publisher provides
@@ -70,7 +85,7 @@ import {
70
85
  * lifts it into a `MulticastEndpoint` ready to embed in the catalog.
71
86
  */
72
87
  export interface MulticastEndpointInput {
73
- readonly protocol: MulticastProtocol;
88
+ readonly protocol: MulticastInputProtocol;
74
89
  readonly sourceAddress?: string;
75
90
  readonly groupAddress: string;
76
91
  readonly port: number;
@@ -88,8 +103,10 @@ export interface MulticastEndpointInput {
88
103
  * Prefer declaring `MulticastInput.networkSource` directly.
89
104
  */
90
105
  readonly relayAddress?: string;
91
- /** Aggregate bandwidth in bits per second. RECOMMENDED per draft §4.1. */
106
+ /** Aggregate bandwidth in bits per second. RECOMMENDED per draft §4.1; REQUIRED with `auth`. */
92
107
  readonly bandwidth?: number;
108
+ /** Protected-flow parameters (draft -01 7.2.6); REQUIRED exactly when `MulticastInput.auth` is set. */
109
+ readonly auth?: EndpointAuthConfig;
93
110
  }
94
111
 
95
112
  /**
@@ -112,7 +129,9 @@ export interface MulticastInput {
112
129
  */
113
130
  readonly networkSource?: ReadonlyArray<NetworkSource>;
114
131
  /** @deprecated Lifted into `networkSource`; no longer emitted. */
115
- readonly amtFallback?: { readonly discovery: AmtDiscovery; readonly relayDns?: string };
132
+ readonly amtFallback?: { readonly discovery?: AmtDiscovery; readonly relayDns?: string };
133
+ /** bc-provenance version 2 profile and keys (draft -01 7.2.6). */
134
+ readonly auth?: MulticastAuthConfig;
116
135
  readonly version?: number;
117
136
  readonly validUntil?: number;
118
137
  }
@@ -127,6 +146,17 @@ export type MulticastInputErrorKind =
127
146
  */
128
147
  | "invalid_endpoints"
129
148
  | "ssm_requires_source"
149
+ /** Input `protocol` "asm" with a `sourceAddress`, which selects SSM. */
150
+ | "protocol_source_mismatch"
151
+ /** `MulticastInput.auth` fails draft -01 7.2.6 (version, keys, a repeated kid or firstEpoch). */
152
+ | "invalid_multicast_auth"
153
+ /**
154
+ * An endpoint's `auth` fails draft -01 7.2.6: present without
155
+ * `MulticastInput.auth` or absent with it, `senderAddress` on SSM or
156
+ * missing on ASM, a timer out of range, no `bandwidth`, or a
157
+ * `manifestPort` that is a port or manifestPort of its `(S, G)`.
158
+ */
159
+ | "invalid_endpoint_auth"
130
160
  /**
131
161
  * Deliberately overloaded, unlike its one-site mirror
132
162
  * `atsc3_requires_tuning`: an AMT relay can be missing at two layers, and
@@ -138,8 +168,8 @@ export type MulticastInputErrorKind =
138
168
  | "amt_requires_relay"
139
169
  /**
140
170
  * An `atsc3` endpoint with no `networkSource` entry of type `"atsc3"`. The
141
- * ATSC3 entry carries the frequency, PLP, service id and SLS URI — the only
142
- * tuning information there is — so without it the endpoint names a broadcast
171
+ * ATSC3 entry carries the frequency (kHz; PLP, service id and SLS URI are
172
+ * optional) — the only tuning information there is — so without it the endpoint names a broadcast
143
173
  * nobody can tune to. The AMT mirror of this is `amt_requires_relay`; native
144
174
  * joins ("ssm", "asm") describe no bearer and are exempt (BLO-37926).
145
175
  */
@@ -242,8 +272,7 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
242
272
  }
243
273
  }
244
274
 
245
- const seenTuples = new Set<string>();
246
- const endpoints: MulticastEndpoint[] = input.endpoints.map((ep, idx) => validateEndpoint(ep, idx, seenTuples));
275
+ const endpoints: MulticastEndpoint[] = input.endpoints.map((ep, idx) => validateEndpoint(ep, idx));
247
276
 
248
277
  const out: MulticastCatalogConfig = { endpoints };
249
278
  const { entries: networkSource, relayFrom } = resolveNetworkSource(input);
@@ -312,8 +341,8 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
312
341
  //
313
342
  // The two arms are about different values, so they name different
314
343
  // fields. The demoted arm is about `discovery`: a derived entry is only
315
- // `"driad"` when `amtFallback.discovery` said so (the default is
316
- // `"manual"`), so `amtFallback` is always the actionable field there.
344
+ // `"driad"` when `amtFallback.discovery` said so (there is no default),
345
+ // so `amtFallback` is always the actionable field there.
317
346
  // The set clause is about the *relay*, which `resolveNetworkSource`
318
347
  // takes from `amtFallback.relayDns` or from the endpoint
319
348
  // `relayAddress` values -- and saying "amtFallback" to an operator who
@@ -375,11 +404,35 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
375
404
  `endpoint[${idx}] protocol=${ep.protocol} requires a multicast.networkSource entry of ` +
376
405
  `type "${ep.protocol}"` +
377
406
  (ep.protocol === "atsc3"
378
- ? " carrying frequency, plpId, serviceId and slsUri — an ATSC3 endpoint is not tunable without them"
407
+ ? " carrying at least its frequency (kHz) — an ATSC3 endpoint is not tunable without it"
379
408
  : ""),
380
409
  );
381
410
  });
382
411
 
412
+ // Draft -01 4.2: a bearer is a networkSource entry. An endpoint that named
413
+ // one as its protocol gets that type's entries as its own networkSource.
414
+ // They are copied, not moved: the catalog-level array already applied to
415
+ // every endpoint under -00 readers, and still does under -01.
416
+ input.endpoints.forEach((ep, idx) => {
417
+ if (ep.protocol !== "amt" && ep.protocol !== "atsc3") return;
418
+ endpoints[idx]!.networkSource = networkSource.filter((s) => s.type === ep.protocol).map((s) => ({ ...s }));
419
+ });
420
+
421
+ if (input.auth !== undefined) out.auth = input.auth;
422
+ const [issue] = multicastCatalogIssues({ multicast: out });
423
+ if (issue) {
424
+ const kind: MulticastInputErrorKind =
425
+ issue.code === "multicast_auth"
426
+ ? "invalid_multicast_auth"
427
+ : issue.code === "multicast_endpoint_auth"
428
+ ? "invalid_endpoint_auth"
429
+ : issue.path.endsWith(".port")
430
+ ? "duplicate_endpoint_tuple"
431
+ : "protocol_source_mismatch";
432
+ const where = issue.endpointIndex === undefined ? "" : `endpoint[${issue.endpointIndex}] `;
433
+ throw new MulticastInputError(kind, issue.endpointIndex ?? null, `${where}${issue.path.replace("$.multicast.", "")}: ${issue.message}`);
434
+ }
435
+
383
436
  if (input.enabled !== undefined) out.enabled = input.enabled;
384
437
  if (input.version !== undefined) out.version = input.version;
385
438
  if (input.validUntil !== undefined) out.validUntil = input.validUntil;
@@ -391,9 +444,10 @@ export function multicastFromConfig(input: MulticastInput): MulticastCatalogConf
391
444
  *
392
445
  * An explicit `input.networkSource` is authoritative and used as given.
393
446
  * Otherwise one AMT entry is derived from the deprecated inputs it replaces:
394
- * `amtFallback.discovery`/`relayDns` and any endpoint `relayAddress`;
395
- * `discovery` defaults to `"manual"` because a relay named in the catalog is,
396
- * by definition, not discovered. Endpoint relays that disagree with the result
447
+ * `amtFallback.discovery`/`relayDns` and any endpoint `relayAddress`.
448
+ * `discovery` is copied only when given: draft-ramadan-moq-multicast-01 4.2.1
449
+ * reads an omitted `discovery` with a hostname `relay` as `"dns"`, so no
450
+ * default is written. Endpoint relays that disagree with the result
397
451
  * are rejected by `multicastFromConfig`, not resolved here.
398
452
  *
399
453
  * `relayFrom` reports which deprecated input supplied the derived relay, so
@@ -411,10 +465,10 @@ function resolveNetworkSource(input: MulticastInput): {
411
465
 
412
466
  const relayDns = input.amtFallback?.relayDns?.trim();
413
467
  const relay = relayDns || input.endpoints.map((ep) => ep.relayAddress?.trim()).find((r) => !!r);
414
- const discovery = input.amtFallback?.discovery ?? (relay ? "manual" : undefined);
415
- if (discovery === undefined) return { entries: [], relayFrom: null };
468
+ const discovery = input.amtFallback?.discovery;
469
+ if (discovery === undefined && !relay) return { entries: [], relayFrom: null };
416
470
  return {
417
- entries: [{ type: "amt", discovery, ...(relay ? { relay } : {}) }],
471
+ entries: [{ type: "amt", ...(discovery ? { discovery } : {}), ...(relay ? { relay } : {}) }],
418
472
  relayFrom: !relay ? null : relayDns ? "amtFallback.relayDns" : "endpoint.relayAddress",
419
473
  };
420
474
  }
@@ -425,7 +479,7 @@ const ATSC3_SOURCE_KEYS = new Set(["type", "frequency", "plpId", "serviceId", "s
425
479
  /**
426
480
  * One `networkSource[]` entry against `catalog.schema.json` `$defs/networkSource`
427
481
  * (and moq-rs `NetworkSource`), plus the one semantic rule the schema leaves
428
- * out: `discovery: "manual"` names its relay. These helpers are consumed
482
+ * out: `discovery: "dns"` and `"manual"` name their relay. These helpers are consumed
429
483
  * out-of-tree from plain JS, so the `NetworkSource` type is no guarantee.
430
484
  */
431
485
  function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
@@ -443,8 +497,11 @@ function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
443
497
  if (extra.length > 0) throw err("invalid_network_source", `has keys the schema rejects: ${extra.join(", ")}`);
444
498
 
445
499
  if (s.type === "amt") {
446
- if (s.discovery !== "driad" && s.discovery !== "manual") {
447
- throw err("invalid_amt_discovery", `discovery must be "driad" or "manual"; got ${JSON.stringify(s.discovery)}`);
500
+ if (s.discovery !== undefined && s.discovery !== "dns" && s.discovery !== "driad" && s.discovery !== "manual") {
501
+ throw err(
502
+ "invalid_amt_discovery",
503
+ `discovery must be "dns", "driad" or "manual" when present; got ${JSON.stringify(s.discovery)}`,
504
+ );
448
505
  }
449
506
  if (s.relay !== undefined) {
450
507
  // Canonicalize, don't just check: the conflict guard in
@@ -459,8 +516,8 @@ function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
459
516
  }
460
517
  s.relay = relay;
461
518
  }
462
- if (s.discovery === "manual" && s.relay === undefined) {
463
- throw err("amt_requires_relay", `discovery="manual" requires a relay ("driad" resolves it at runtime)`);
519
+ if ((s.discovery === "dns" || s.discovery === "manual") && s.relay === undefined) {
520
+ throw err("amt_requires_relay", `discovery="${s.discovery}" requires a relay ("driad" resolves it at runtime)`);
464
521
  }
465
522
  if (s.port !== undefined && (!Number.isInteger(s.port) || s.port < 1 || s.port > 65535)) {
466
523
  throw err("invalid_port", `port must be 1..65535; got ${s.port}`);
@@ -469,13 +526,16 @@ function validateNetworkSourceEntry(s: NetworkSource, i: number): void {
469
526
  }
470
527
  const inRange = (v: number, min: number, max: number) => Number.isInteger(v) && v >= min && v <= max;
471
528
  if (!inRange(s.frequency, 1, Number.MAX_SAFE_INTEGER)) {
472
- throw err("invalid_network_source", `frequency must be a positive integer; got ${s.frequency}`);
529
+ throw err("invalid_network_source", `frequency must be a positive integer in kHz; got ${s.frequency}`);
530
+ }
531
+ // Draft -01 4.2.2: only frequency (kHz) is REQUIRED; the rest are checked when set.
532
+ if (s.plpId !== undefined && !inRange(s.plpId, 0, 63)) {
533
+ throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
473
534
  }
474
- if (!inRange(s.plpId, 0, 63)) throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
475
- if (!inRange(s.serviceId, 0, 65535)) {
535
+ if (s.serviceId !== undefined && !inRange(s.serviceId, 0, 65535)) {
476
536
  throw err("invalid_network_source", `serviceId must be 0..65535; got ${s.serviceId}`);
477
537
  }
478
- if (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri)) {
538
+ if (s.slsUri !== undefined && (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri))) {
479
539
  throw err("invalid_network_source", `slsUri must be an absolute URI; got ${JSON.stringify(s.slsUri)}`);
480
540
  }
481
541
  }
@@ -489,11 +549,7 @@ function isAbsoluteUri(value: string): boolean {
489
549
  }
490
550
  }
491
551
 
492
- function validateEndpoint(
493
- ep: MulticastEndpointInput,
494
- idx: number,
495
- seenTuples: Set<string>,
496
- ): MulticastEndpoint {
552
+ function validateEndpoint(ep: MulticastEndpointInput, idx: number): MulticastEndpoint {
497
553
  if (ep.protocol === "ssm" && (!ep.sourceAddress || ep.sourceAddress.length === 0)) {
498
554
  throw new MulticastInputError(
499
555
  "ssm_requires_source",
@@ -501,6 +557,13 @@ function validateEndpoint(
501
557
  `endpoint[${idx}] protocol=ssm requires sourceAddress`,
502
558
  );
503
559
  }
560
+ if (ep.protocol === "asm" && ep.sourceAddress !== undefined) {
561
+ throw new MulticastInputError(
562
+ "protocol_source_mismatch",
563
+ idx,
564
+ `endpoint[${idx}] protocol=asm with sourceAddress "${ep.sourceAddress}"; sourceAddress selects SSM (draft -01 4.1)`,
565
+ );
566
+ }
504
567
  // NOTE: `protocol: "amt"` no longer requires a per-endpoint relay here. The
505
568
  // relay is catalog-level (`multicast.networkSource`), which this function
506
569
  // cannot see; `multicastFromConfig` enforces it once both halves are in hand.
@@ -570,18 +633,12 @@ function validateEndpoint(
570
633
  );
571
634
  }
572
635
 
573
- const tupleKey = `${ep.sourceAddress ?? ""}|${ep.groupAddress}|${ep.port}`;
574
- if (seenTuples.has(tupleKey)) {
575
- throw new MulticastInputError(
576
- "duplicate_endpoint_tuple",
577
- idx,
578
- `endpoint[${idx}] duplicates (sourceAddress, groupAddress, port) tuple "${tupleKey}"`,
579
- );
580
- }
581
- seenTuples.add(tupleKey);
582
-
636
+ // Tuple uniqueness is keyed on S, which needs `auth`; `multicastFromConfig`
637
+ // checks it with the rest of draft -01 4.1 once the catalog is composed.
638
+ // The emitted protocol restates the mode `sourceAddress` selects; a bearer
639
+ // input protocol is never emitted.
583
640
  const out: MulticastEndpoint = {
584
- protocol: ep.protocol,
641
+ protocol: ep.sourceAddress === undefined ? "asm" : "ssm",
585
642
  groupAddress: ep.groupAddress,
586
643
  port: ep.port,
587
644
  tracks: ep.tracks.map((t) => ({ name: t.name, packetId: t.packetId })),
@@ -590,6 +647,7 @@ function validateEndpoint(
590
647
  // `relayAddress` is deliberately NOT copied: the relay is lifted to
591
648
  // catalog-level `multicast.networkSource` by `multicastFromConfig`.
592
649
  if (ep.bandwidth !== undefined) out.bandwidth = ep.bandwidth;
650
+ if (ep.auth !== undefined) out.auth = { ...ep.auth };
593
651
  return out;
594
652
  }
595
653
 
@@ -689,9 +747,9 @@ export function multicastFromEnv(
689
747
  ...(hasCatalogAmt
690
748
  ? {
691
749
  amtFallback: {
692
- // `"manual"` mirrors `resolveNetworkSource`: a relay named in
693
- // the catalog is, by definition, not discovered.
694
- discovery: (amtDiscovery ?? "manual") as AmtDiscovery,
750
+ // No default: an omitted discovery with a relay hostname is
751
+ // "dns" (draft-ramadan-moq-multicast-01 4.2.1).
752
+ ...(amtDiscovery ? { discovery: amtDiscovery as AmtDiscovery } : {}),
695
753
  ...(amtRelayDns ? { relayDns: amtRelayDns } : {}),
696
754
  },
697
755
  }
@@ -757,7 +815,7 @@ function readEndpointAt(env: Record<string, string | undefined>, idx: number): M
757
815
  const relay = lookup("RELAY");
758
816
 
759
817
  return {
760
- protocol: lookup("PROTOCOL") as MulticastProtocol,
818
+ protocol: lookup("PROTOCOL") as MulticastInputProtocol,
761
819
  groupAddress: lookup("GROUP") ?? "",
762
820
  port,
763
821
  tracks,