@blockcast/mmt-container 0.4.0-main.bbd83cb48eff → 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 (191) hide show
  1. package/README.md +31 -17
  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 +1192 -375
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +67 -31
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +291 -199
  11. package/dist/carp-catalog.js.map +3 -3
  12. package/dist/catalog-fec-params.d.ts +12 -4
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +40 -17
  15. package/dist/catalog-fec-params.js.map +3 -3
  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 +21 -1
  19. package/dist/catalog-network-source.js.map +2 -2
  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 +18 -12
  25. package/dist/delivery-catalog.js.map +4 -4
  26. package/dist/fec-manager.d.ts +49 -1
  27. package/dist/fec-manager.d.ts.map +1 -1
  28. package/dist/fec-manager.js +176 -23
  29. package/dist/fec-manager.js.map +3 -3
  30. package/dist/fec-state.d.ts +2 -1
  31. package/dist/fec-state.d.ts.map +1 -1
  32. package/dist/fec-state.js +18 -3
  33. package/dist/fec-state.js.map +3 -3
  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 +2 -1
  37. package/dist/fec-worker-setup.js.map +2 -2
  38. package/dist/index.d.ts +5 -5
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +8 -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 +97 -17
  45. package/dist/iso-block-locator.js.map +3 -3
  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.map +2 -2
  51. package/dist/mmtp-container-parser.js.map +2 -2
  52. package/dist/mmtp-container-parser.no-modules.js +1014 -289
  53. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  54. package/dist/mmtp-decode-pipeline.js.map +2 -2
  55. package/dist/mmtp-fec-session.d.ts +159 -0
  56. package/dist/mmtp-fec-session.d.ts.map +1 -0
  57. package/dist/mmtp-fec-session.js +531 -0
  58. package/dist/mmtp-fec-session.js.map +7 -0
  59. package/dist/mmtp-router.d.ts +17 -1
  60. package/dist/mmtp-router.d.ts.map +1 -1
  61. package/dist/mmtp-router.js +29 -0
  62. package/dist/mmtp-router.js.map +2 -2
  63. package/dist/multicast-auth-catalog.d.ts +86 -92
  64. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  65. package/dist/multicast-auth-catalog.js +347 -132
  66. package/dist/multicast-auth-catalog.js.map +4 -4
  67. package/dist/multicast-input.d.ts +28 -6
  68. package/dist/multicast-input.d.ts.map +1 -1
  69. package/dist/multicast-input.js +290 -28
  70. package/dist/multicast-input.js.map +3 -3
  71. package/dist/multicast-manager.d.ts +40 -5
  72. package/dist/multicast-manager.d.ts.map +1 -1
  73. package/dist/multicast-manager.js +293 -54
  74. package/dist/multicast-manager.js.map +4 -4
  75. package/dist/multicast-transport.d.ts +6 -0
  76. package/dist/multicast-transport.d.ts.map +1 -1
  77. package/dist/multicast-transport.js +18 -11
  78. package/dist/multicast-transport.js.map +4 -4
  79. package/dist/multicast-unwrap.js.map +2 -2
  80. package/dist/no-modules.d.ts +4 -1
  81. package/dist/no-modules.d.ts.map +1 -1
  82. package/dist/no-modules.js +964 -274
  83. package/dist/no-modules.js.map +4 -4
  84. package/dist/phase14-catalog-override.d.ts +1 -1
  85. package/dist/phase14-catalog-override.d.ts.map +1 -1
  86. package/dist/phase14-catalog-override.js +2 -2
  87. package/dist/phase14-catalog-override.js.map +2 -2
  88. package/dist/repair-fetch.d.ts +81 -6
  89. package/dist/repair-fetch.d.ts.map +1 -1
  90. package/dist/repair-fetch.js +156 -31
  91. package/dist/repair-fetch.js.map +3 -3
  92. package/dist/repair-layers.d.ts +2 -0
  93. package/dist/repair-layers.d.ts.map +1 -1
  94. package/dist/repair-layers.js +19 -2
  95. package/dist/repair-layers.js.map +2 -2
  96. package/dist/signaling.d.ts +2 -2
  97. package/dist/signaling.d.ts.map +1 -1
  98. package/dist/signaling.js +3 -3
  99. package/dist/signaling.js.map +2 -2
  100. package/dist/source-auth.js +2710 -7
  101. package/dist/source-auth.js.map +4 -4
  102. package/dist/switching-set-alignment.d.ts +1 -1
  103. package/dist/switching-set-alignment.js.map +1 -1
  104. package/dist/timestamp-codec.js.map +2 -2
  105. package/dist/wasm-mfu-reassembler.js.map +1 -1
  106. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  107. package/package.json +6 -9
  108. package/schemas/catalog.schema.json +124 -37
  109. package/src/align.ts +52 -21
  110. package/src/carp-catalog.ts +131 -52
  111. package/src/catalog-fec-params.ts +28 -3
  112. package/src/catalog-network-source.ts +45 -2
  113. package/src/catalog-validator.ts +4 -11
  114. package/src/fec-manager.ts +128 -14
  115. package/src/fec-state.ts +11 -4
  116. package/src/fec-worker-setup.ts +4 -1
  117. package/src/index.ts +24 -10
  118. package/src/iso-block-locator.ts +97 -6
  119. package/src/manifest-auth-plan.ts +39 -91
  120. package/src/mmtp-fec-session.ts +533 -0
  121. package/src/mmtp-router.ts +57 -0
  122. package/src/multicast-auth-catalog.ts +131 -238
  123. package/src/multicast-input.ts +119 -61
  124. package/src/multicast-manager.ts +115 -14
  125. package/src/multicast-transport.ts +3 -0
  126. package/src/no-modules.ts +7 -1
  127. package/src/phase14-catalog-override.ts +3 -3
  128. package/src/repair-fetch.ts +283 -39
  129. package/src/repair-layers.ts +22 -2
  130. package/src/signaling.ts +2 -2
  131. package/src/switching-set-alignment.ts +1 -1
  132. package/test-vectors/align.json +108 -32
  133. package/test-vectors/bc-provenance-v2.json +1526 -0
  134. package/test-vectors/catalog/README.md +60 -3
  135. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  136. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  137. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  138. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  139. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  140. package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
  141. package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
  142. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  143. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  144. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  145. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  146. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  147. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  148. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  149. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  150. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  151. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  152. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  153. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  154. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  155. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  156. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  157. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
  158. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
  159. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  160. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  161. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  162. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  163. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  164. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  165. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  166. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  167. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  168. package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
  169. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  170. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  171. package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
  172. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  173. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  174. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  175. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +2 -2
  176. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  177. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  178. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  179. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  180. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  181. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  182. package/test-vectors/catalog/section-codes.json +30 -1
  183. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  184. package/test-vectors/catalog-validation.json +6 -5
  185. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  186. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
  187. package/dist/fec-codec.d.ts +0 -32
  188. package/dist/fec-codec.d.ts.map +0 -1
  189. package/dist/fec-codec.js +0 -47
  190. package/dist/fec-codec.js.map +0 -7
  191. package/src/fec-codec.ts +0 -61
@@ -18,6 +18,254 @@ var FEC_BLOCK_PROFILES = Object.freeze([
18
18
  // ../mmt-base/dist/catalog-fec-source.js
19
19
  var ALL_ROLES = Object.freeze(["video", "audio"]);
20
20
 
21
+ // ../mmt-base/dist/multicast-catalog.js
22
+ var ED25519_PUBLIC_KEY_BASE64URL = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
23
+ var UINT32_MAX = 4294967295;
24
+ var AUTH_MEMBERS = /* @__PURE__ */ new Set(["scheme", "version", "sig", "keys", "minEpoch"]);
25
+ var KEY_MEMBERS = /* @__PURE__ */ new Set(["kid", "publicKey", "firstEpoch"]);
26
+ var ENDPOINT_AUTH_MEMBERS = /* @__PURE__ */ new Set([
27
+ "manifestPort",
28
+ "streamId",
29
+ "senderAddress",
30
+ "maxAuthDelayMs",
31
+ "manifestTimerMs",
32
+ "manifestTrack"
33
+ ]);
34
+ function isObject(value) {
35
+ return typeof value === "object" && value !== null && !Array.isArray(value);
36
+ }
37
+ function isNonEmptyString(value) {
38
+ return typeof value === "string" && value.trim().length > 0;
39
+ }
40
+ function isIntegerIn(value, min, max) {
41
+ return Number.isSafeInteger(value) && value >= min && value <= max;
42
+ }
43
+ function multicastEndpointSource(endpoint) {
44
+ if (!isObject(endpoint))
45
+ return void 0;
46
+ const sourceAddress = endpoint["sourceAddress"];
47
+ if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress))
48
+ return void 0;
49
+ const mode = sourceAddress === void 0 ? "asm" : "ssm";
50
+ const protocol = endpoint["protocol"];
51
+ if (protocol !== void 0 && protocol !== mode)
52
+ return void 0;
53
+ const auth = endpoint["auth"];
54
+ const senderAddress = isObject(auth) ? auth["senderAddress"] : void 0;
55
+ if (mode === "ssm")
56
+ return senderAddress === void 0 ? { mode, source: sourceAddress } : void 0;
57
+ if (auth === void 0)
58
+ return { mode };
59
+ return isNonEmptyString(senderAddress) ? { mode, source: senderAddress } : void 0;
60
+ }
61
+ function authIssues(auth) {
62
+ const base = "$.multicast.auth";
63
+ const issue = (path, message) => [
64
+ { code: "multicast_auth", path: `${base}${path}`, message }
65
+ ];
66
+ if (!isObject(auth))
67
+ return issue("", "auth must be an object");
68
+ const unknown = Object.keys(auth).filter((key) => !AUTH_MEMBERS.has(key));
69
+ if (unknown.length > 0) {
70
+ return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -01 7.2.6 defines scheme, version, sig, keys and minEpoch`);
71
+ }
72
+ if (auth["scheme"] !== "bc-provenance")
73
+ return issue(".scheme", 'scheme must be "bc-provenance"');
74
+ if (auth["version"] !== 2)
75
+ return issue(".version", "version must be 2 (bc-provenance version 2, draft -01 7.2)");
76
+ if (auth["sig"] !== "ed25519")
77
+ return issue(".sig", 'sig must be "ed25519"');
78
+ const keys = auth["keys"];
79
+ if (!Array.isArray(keys) || keys.length < 1 || keys.length > 4) {
80
+ return issue(".keys", "keys must be an array of one to four {kid, publicKey, firstEpoch} objects");
81
+ }
82
+ const kids = /* @__PURE__ */ new Set();
83
+ const firstEpochs = /* @__PURE__ */ new Set();
84
+ for (let index = 0; index < keys.length; index++) {
85
+ const key = keys[index];
86
+ const at = `.keys[${index}]`;
87
+ if (!isObject(key) || Object.keys(key).some((member) => !KEY_MEMBERS.has(member))) {
88
+ return issue(at, "a key is exactly {kid, publicKey, firstEpoch}");
89
+ }
90
+ if (!isIntegerIn(key["kid"], 0, UINT32_MAX))
91
+ return issue(`${at}.kid`, "kid must be an unsigned 32-bit integer");
92
+ if (typeof key["publicKey"] !== "string" || !ED25519_PUBLIC_KEY_BASE64URL.test(key["publicKey"])) {
93
+ return issue(`${at}.publicKey`, "publicKey must be a 32-octet Ed25519 key in canonical unpadded base64url");
94
+ }
95
+ if (!isIntegerIn(key["firstEpoch"], 0, UINT32_MAX)) {
96
+ return issue(`${at}.firstEpoch`, "firstEpoch must be an unsigned 32-bit integer");
97
+ }
98
+ if (kids.has(key["kid"]))
99
+ return issue(`${at}.kid`, `kid ${key["kid"]} is repeated; the catalog holds no key set`);
100
+ if (firstEpochs.has(key["firstEpoch"])) {
101
+ return issue(`${at}.firstEpoch`, `firstEpoch ${key["firstEpoch"]} is repeated; the catalog holds no key set`);
102
+ }
103
+ kids.add(key["kid"]);
104
+ firstEpochs.add(key["firstEpoch"]);
105
+ }
106
+ if (!isIntegerIn(auth["minEpoch"], 0, UINT32_MAX)) {
107
+ return issue(".minEpoch", "minEpoch must be an unsigned 32-bit integer");
108
+ }
109
+ return [];
110
+ }
111
+ function endpointAuthIssue(endpoint, mode, at) {
112
+ const auth = endpoint["auth"];
113
+ if (!isObject(auth))
114
+ return { path: `${at}.auth`, message: "auth must be an object" };
115
+ const unknown = Object.keys(auth).filter((key) => !ENDPOINT_AUTH_MEMBERS.has(key));
116
+ if (unknown.length > 0)
117
+ return { path: `${at}.auth`, message: `auth has unknown member(s) ${unknown.join(", ")}` };
118
+ if (!isIntegerIn(auth["manifestPort"], 1, 65535)) {
119
+ return { path: `${at}.auth.manifestPort`, message: "manifestPort must be an integer from 1 to 65535" };
120
+ }
121
+ if (!isIntegerIn(auth["streamId"], 0, UINT32_MAX)) {
122
+ return { path: `${at}.auth.streamId`, message: "streamId must be an unsigned 32-bit integer" };
123
+ }
124
+ if (mode === "ssm" && auth["senderAddress"] !== void 0) {
125
+ return { path: `${at}.auth.senderAddress`, message: "senderAddress must not appear on an SSM endpoint; S is sourceAddress" };
126
+ }
127
+ if (mode === "asm" && !isNonEmptyString(auth["senderAddress"])) {
128
+ return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress" };
129
+ }
130
+ if (auth["maxAuthDelayMs"] !== void 0 && !isIntegerIn(auth["maxAuthDelayMs"], 50, 1e3)) {
131
+ return { path: `${at}.auth.maxAuthDelayMs`, message: "maxAuthDelayMs must be an integer from 50 to 1000" };
132
+ }
133
+ if (auth["manifestTimerMs"] !== void 0 && !isIntegerIn(auth["manifestTimerMs"], 1, Number.MAX_SAFE_INTEGER)) {
134
+ return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be an integer of at least 1" };
135
+ }
136
+ if (auth["manifestTrack"] !== void 0 && !isNonEmptyString(auth["manifestTrack"])) {
137
+ return { path: `${at}.auth.manifestTrack`, message: "manifestTrack must be a non-empty string" };
138
+ }
139
+ if (!isIntegerIn(endpoint["bandwidth"], 1, Number.MAX_SAFE_INTEGER)) {
140
+ return { path: `${at}.bandwidth`, message: "a protected endpoint requires bandwidth, which bounds the receiver's hold queues" };
141
+ }
142
+ return void 0;
143
+ }
144
+ var CATALOG_NAMESPACE = /* @__PURE__ */ Symbol.for("@blockcast/mmt-base/catalogNamespace");
145
+ function multicastCatalogIssues(catalog, options = {}) {
146
+ if (!isObject(catalog))
147
+ return [];
148
+ const issues = [];
149
+ if ("multicast.auth" in catalog) {
150
+ issues.push({
151
+ code: "multicast_auth",
152
+ path: '$["multicast.auth"]',
153
+ message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -01 7.2.6)'
154
+ });
155
+ }
156
+ const multicast = catalog["multicast"];
157
+ if (!isObject(multicast))
158
+ return issues;
159
+ const protectedCatalog = multicast["auth"] !== void 0;
160
+ if (protectedCatalog)
161
+ issues.push(...authIssues(multicast["auth"]));
162
+ const endpoints = multicast["endpoints"];
163
+ if (!Array.isArray(endpoints))
164
+ return issues;
165
+ const tracks = Array.isArray(catalog["tracks"]) ? catalog["tracks"] : [];
166
+ const namespaceOf = /* @__PURE__ */ new Map();
167
+ for (const track of tracks) {
168
+ if (isObject(track) && typeof track["name"] === "string")
169
+ namespaceOf.set(track["name"], track["namespace"]);
170
+ }
171
+ const tagged = catalog[CATALOG_NAMESPACE];
172
+ let referenceNamespace = options.catalogNamespace ?? (typeof tagged === "string" ? tagged : void 0);
173
+ const sources = [];
174
+ for (let index = 0; index < endpoints.length; index++) {
175
+ const endpoint = endpoints[index];
176
+ const at = `$.multicast.endpoints[${index}]`;
177
+ const fail = (code, path, message) => {
178
+ issues.push({ code, path, message, endpointIndex: index });
179
+ };
180
+ sources.push(void 0);
181
+ if (!isObject(endpoint)) {
182
+ fail("multicast_endpoint", at, "endpoint must be an object");
183
+ continue;
184
+ }
185
+ const protocol = endpoint["protocol"];
186
+ if (protocol !== void 0 && protocol !== "ssm" && protocol !== "asm") {
187
+ 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)`);
188
+ continue;
189
+ }
190
+ const hasAuth = endpoint["auth"] !== void 0;
191
+ if (protectedCatalog !== hasAuth) {
192
+ fail("multicast_endpoint_auth", `${at}.auth`, protectedCatalog ? "every endpoint requires auth when multicast carries auth; a receiver ignores this endpoint" : "auth names no key without multicast.auth; a receiver ignores this endpoint");
193
+ continue;
194
+ }
195
+ const sourceAddress = endpoint["sourceAddress"];
196
+ if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress)) {
197
+ fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be a non-empty string");
198
+ continue;
199
+ }
200
+ const mode = sourceAddress === void 0 ? "asm" : "ssm";
201
+ if (protocol !== void 0 && protocol !== mode) {
202
+ fail("multicast_endpoint", `${at}.protocol`, `protocol ${JSON.stringify(protocol)} disagrees with sourceAddress, which selects ${mode}`);
203
+ continue;
204
+ }
205
+ if (!isIntegerIn(endpoint["port"], 1, 65535)) {
206
+ fail("multicast_endpoint", `${at}.port`, "port must be an integer from 1 to 65535");
207
+ continue;
208
+ }
209
+ if (hasAuth) {
210
+ const authIssue = endpointAuthIssue(endpoint, mode, at);
211
+ if (authIssue) {
212
+ fail("multicast_endpoint_auth", authIssue.path, authIssue.message);
213
+ continue;
214
+ }
215
+ }
216
+ sources[index] = multicastEndpointSource(endpoint);
217
+ const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
218
+ for (let refIndex = 0; refIndex < refs.length; refIndex++) {
219
+ const ref = refs[refIndex];
220
+ const name = isObject(ref) ? ref["name"] : ref;
221
+ if (typeof name !== "string")
222
+ continue;
223
+ const namespace = namespaceOf.get(name);
224
+ if (typeof namespace !== "string")
225
+ continue;
226
+ referenceNamespace ??= namespace;
227
+ if (namespace !== referenceNamespace) {
228
+ fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} declares namespace ${JSON.stringify(namespace)}, not the catalog track's ${JSON.stringify(referenceNamespace)}`);
229
+ }
230
+ }
231
+ }
232
+ const tupleOf = (index) => {
233
+ const endpoint = endpoints[index];
234
+ const auth = endpoint["auth"];
235
+ return {
236
+ sg: JSON.stringify([sources[index].source ?? null, endpoint["groupAddress"]]),
237
+ port: endpoint["port"],
238
+ manifestPort: isObject(auth) ? auth["manifestPort"] : void 0
239
+ };
240
+ };
241
+ for (let index = 0; index < endpoints.length; index++) {
242
+ if (!sources[index])
243
+ continue;
244
+ const own = tupleOf(index);
245
+ const at = `$.multicast.endpoints[${index}]`;
246
+ if (own.manifestPort !== void 0 && own.manifestPort === own.port) {
247
+ issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
248
+ continue;
249
+ }
250
+ for (let other = 0; other < endpoints.length; other++) {
251
+ if (other === index || !sources[other])
252
+ continue;
253
+ const peer = tupleOf(other);
254
+ if (peer.sg !== own.sg)
255
+ continue;
256
+ if (peer.port === own.port) {
257
+ 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 });
258
+ break;
259
+ }
260
+ if (own.manifestPort !== void 0 && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
261
+ 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 });
262
+ break;
263
+ }
264
+ }
265
+ }
266
+ return issues;
267
+ }
268
+
21
269
  // src/multicast-input.ts
22
270
  var MulticastInputError = class extends Error {
23
271
  constructor(kind, endpointIndex, message) {
@@ -61,8 +309,7 @@ function multicastFromConfig(input) {
61
309
  );
62
310
  }
63
311
  }
64
- const seenTuples = /* @__PURE__ */ new Set();
65
- const endpoints = input.endpoints.map((ep, idx) => validateEndpoint(ep, idx, seenTuples));
312
+ const endpoints = input.endpoints.map((ep, idx) => validateEndpoint(ep, idx));
66
313
  const out = { endpoints };
67
314
  const { entries: networkSource, relayFrom } = resolveNetworkSource(input);
68
315
  networkSource.forEach(validateNetworkSourceEntry);
@@ -96,9 +343,20 @@ function multicastFromConfig(input) {
96
343
  throw new MulticastInputError(
97
344
  ep.protocol === "amt" ? "amt_requires_relay" : "atsc3_requires_tuning",
98
345
  idx,
99
- `endpoint[${idx}] protocol=${ep.protocol} requires a multicast.networkSource entry of type "${ep.protocol}"` + (ep.protocol === "atsc3" ? " carrying frequency, plpId, serviceId and slsUri \u2014 an ATSC3 endpoint is not tunable without them" : "")
346
+ `endpoint[${idx}] protocol=${ep.protocol} requires a multicast.networkSource entry of type "${ep.protocol}"` + (ep.protocol === "atsc3" ? " carrying at least its frequency (kHz) \u2014 an ATSC3 endpoint is not tunable without it" : "")
100
347
  );
101
348
  });
349
+ input.endpoints.forEach((ep, idx) => {
350
+ if (ep.protocol !== "amt" && ep.protocol !== "atsc3") return;
351
+ endpoints[idx].networkSource = networkSource.filter((s) => s.type === ep.protocol).map((s) => ({ ...s }));
352
+ });
353
+ if (input.auth !== void 0) out.auth = input.auth;
354
+ const [issue] = multicastCatalogIssues({ multicast: out });
355
+ if (issue) {
356
+ const kind = issue.code === "multicast_auth" ? "invalid_multicast_auth" : issue.code === "multicast_endpoint_auth" ? "invalid_endpoint_auth" : issue.path.endsWith(".port") ? "duplicate_endpoint_tuple" : "protocol_source_mismatch";
357
+ const where = issue.endpointIndex === void 0 ? "" : `endpoint[${issue.endpointIndex}] `;
358
+ throw new MulticastInputError(kind, issue.endpointIndex ?? null, `${where}${issue.path.replace("$.multicast.", "")}: ${issue.message}`);
359
+ }
102
360
  if (input.enabled !== void 0) out.enabled = input.enabled;
103
361
  if (input.version !== void 0) out.version = input.version;
104
362
  if (input.validUntil !== void 0) out.validUntil = input.validUntil;
@@ -110,10 +368,10 @@ function resolveNetworkSource(input) {
110
368
  }
111
369
  const relayDns = input.amtFallback?.relayDns?.trim();
112
370
  const relay = relayDns || input.endpoints.map((ep) => ep.relayAddress?.trim()).find((r) => !!r);
113
- const discovery = input.amtFallback?.discovery ?? (relay ? "manual" : void 0);
114
- if (discovery === void 0) return { entries: [], relayFrom: null };
371
+ const discovery = input.amtFallback?.discovery;
372
+ if (discovery === void 0 && !relay) return { entries: [], relayFrom: null };
115
373
  return {
116
- entries: [{ type: "amt", discovery, ...relay ? { relay } : {} }],
374
+ entries: [{ type: "amt", ...discovery ? { discovery } : {}, ...relay ? { relay } : {} }],
117
375
  relayFrom: !relay ? null : relayDns ? "amtFallback.relayDns" : "endpoint.relayAddress"
118
376
  };
119
377
  }
@@ -126,8 +384,11 @@ function validateNetworkSourceEntry(s, i) {
126
384
  const extra = Object.keys(s).filter((k) => !keys.has(k) && s[k] !== void 0);
127
385
  if (extra.length > 0) throw err("invalid_network_source", `has keys the schema rejects: ${extra.join(", ")}`);
128
386
  if (s.type === "amt") {
129
- if (s.discovery !== "driad" && s.discovery !== "manual") {
130
- throw err("invalid_amt_discovery", `discovery must be "driad" or "manual"; got ${JSON.stringify(s.discovery)}`);
387
+ if (s.discovery !== void 0 && s.discovery !== "dns" && s.discovery !== "driad" && s.discovery !== "manual") {
388
+ throw err(
389
+ "invalid_amt_discovery",
390
+ `discovery must be "dns", "driad" or "manual" when present; got ${JSON.stringify(s.discovery)}`
391
+ );
131
392
  }
132
393
  if (s.relay !== void 0) {
133
394
  const relay = typeof s.relay === "string" ? s.relay.trim() : "";
@@ -136,8 +397,8 @@ function validateNetworkSourceEntry(s, i) {
136
397
  }
137
398
  s.relay = relay;
138
399
  }
139
- if (s.discovery === "manual" && s.relay === void 0) {
140
- throw err("amt_requires_relay", `discovery="manual" requires a relay ("driad" resolves it at runtime)`);
400
+ if ((s.discovery === "dns" || s.discovery === "manual") && s.relay === void 0) {
401
+ throw err("amt_requires_relay", `discovery="${s.discovery}" requires a relay ("driad" resolves it at runtime)`);
141
402
  }
142
403
  if (s.port !== void 0 && (!Number.isInteger(s.port) || s.port < 1 || s.port > 65535)) {
143
404
  throw err("invalid_port", `port must be 1..65535; got ${s.port}`);
@@ -146,13 +407,15 @@ function validateNetworkSourceEntry(s, i) {
146
407
  }
147
408
  const inRange = (v, min, max) => Number.isInteger(v) && v >= min && v <= max;
148
409
  if (!inRange(s.frequency, 1, Number.MAX_SAFE_INTEGER)) {
149
- throw err("invalid_network_source", `frequency must be a positive integer; got ${s.frequency}`);
410
+ throw err("invalid_network_source", `frequency must be a positive integer in kHz; got ${s.frequency}`);
150
411
  }
151
- if (!inRange(s.plpId, 0, 63)) throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
152
- if (!inRange(s.serviceId, 0, 65535)) {
412
+ if (s.plpId !== void 0 && !inRange(s.plpId, 0, 63)) {
413
+ throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
414
+ }
415
+ if (s.serviceId !== void 0 && !inRange(s.serviceId, 0, 65535)) {
153
416
  throw err("invalid_network_source", `serviceId must be 0..65535; got ${s.serviceId}`);
154
417
  }
155
- if (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri)) {
418
+ if (s.slsUri !== void 0 && (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri))) {
156
419
  throw err("invalid_network_source", `slsUri must be an absolute URI; got ${JSON.stringify(s.slsUri)}`);
157
420
  }
158
421
  }
@@ -164,7 +427,7 @@ function isAbsoluteUri(value) {
164
427
  return false;
165
428
  }
166
429
  }
167
- function validateEndpoint(ep, idx, seenTuples) {
430
+ function validateEndpoint(ep, idx) {
168
431
  if (ep.protocol === "ssm" && (!ep.sourceAddress || ep.sourceAddress.length === 0)) {
169
432
  throw new MulticastInputError(
170
433
  "ssm_requires_source",
@@ -172,6 +435,13 @@ function validateEndpoint(ep, idx, seenTuples) {
172
435
  `endpoint[${idx}] protocol=ssm requires sourceAddress`
173
436
  );
174
437
  }
438
+ if (ep.protocol === "asm" && ep.sourceAddress !== void 0) {
439
+ throw new MulticastInputError(
440
+ "protocol_source_mismatch",
441
+ idx,
442
+ `endpoint[${idx}] protocol=asm with sourceAddress "${ep.sourceAddress}"; sourceAddress selects SSM (draft -01 4.1)`
443
+ );
444
+ }
175
445
  if (!isMulticastGroupAddress(ep.groupAddress)) {
176
446
  throw new MulticastInputError(
177
447
  "invalid_group_address",
@@ -231,23 +501,15 @@ function validateEndpoint(ep, idx, seenTuples) {
231
501
  `endpoint[${idx}] bandwidth must be positive; got ${ep.bandwidth}`
232
502
  );
233
503
  }
234
- const tupleKey = `${ep.sourceAddress ?? ""}|${ep.groupAddress}|${ep.port}`;
235
- if (seenTuples.has(tupleKey)) {
236
- throw new MulticastInputError(
237
- "duplicate_endpoint_tuple",
238
- idx,
239
- `endpoint[${idx}] duplicates (sourceAddress, groupAddress, port) tuple "${tupleKey}"`
240
- );
241
- }
242
- seenTuples.add(tupleKey);
243
504
  const out = {
244
- protocol: ep.protocol,
505
+ protocol: ep.sourceAddress === void 0 ? "asm" : "ssm",
245
506
  groupAddress: ep.groupAddress,
246
507
  port: ep.port,
247
508
  tracks: ep.tracks.map((t) => ({ name: t.name, packetId: t.packetId }))
248
509
  };
249
510
  if (ep.sourceAddress !== void 0) out.sourceAddress = ep.sourceAddress;
250
511
  if (ep.bandwidth !== void 0) out.bandwidth = ep.bandwidth;
512
+ if (ep.auth !== void 0) out.auth = { ...ep.auth };
251
513
  return out;
252
514
  }
253
515
  function isMulticastGroupAddress(addr) {
@@ -290,9 +552,9 @@ function multicastFromEnv(env = globalThis.process?.env ?? {}) {
290
552
  endpoints,
291
553
  ...hasCatalogAmt ? {
292
554
  amtFallback: {
293
- // `"manual"` mirrors `resolveNetworkSource`: a relay named in
294
- // the catalog is, by definition, not discovered.
295
- discovery: amtDiscovery ?? "manual",
555
+ // No default: an omitted discovery with a relay hostname is
556
+ // "dns" (draft-ramadan-moq-multicast-01 4.2.1).
557
+ ...amtDiscovery ? { discovery: amtDiscovery } : {},
296
558
  ...amtRelayDns ? { relayDns: amtRelayDns } : {}
297
559
  }
298
560
  } : {}