@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
@@ -15,6 +15,257 @@ var FEC_BLOCK_PROFILES = Object.freeze([
15
15
  "iso-ssbg1-v1"
16
16
  ]);
17
17
 
18
+ // ../mmt-base/dist/catalog-fec-source.js
19
+ var ALL_ROLES = Object.freeze(["video", "audio"]);
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
+
18
269
  // src/multicast-input.ts
19
270
  var MulticastInputError = class extends Error {
20
271
  constructor(kind, endpointIndex, message) {
@@ -58,8 +309,7 @@ function multicastFromConfig(input) {
58
309
  );
59
310
  }
60
311
  }
61
- const seenTuples = /* @__PURE__ */ new Set();
62
- const endpoints = input.endpoints.map((ep, idx) => validateEndpoint(ep, idx, seenTuples));
312
+ const endpoints = input.endpoints.map((ep, idx) => validateEndpoint(ep, idx));
63
313
  const out = { endpoints };
64
314
  const { entries: networkSource, relayFrom } = resolveNetworkSource(input);
65
315
  networkSource.forEach(validateNetworkSourceEntry);
@@ -93,9 +343,20 @@ function multicastFromConfig(input) {
93
343
  throw new MulticastInputError(
94
344
  ep.protocol === "amt" ? "amt_requires_relay" : "atsc3_requires_tuning",
95
345
  idx,
96
- `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" : "")
97
347
  );
98
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
+ }
99
360
  if (input.enabled !== void 0) out.enabled = input.enabled;
100
361
  if (input.version !== void 0) out.version = input.version;
101
362
  if (input.validUntil !== void 0) out.validUntil = input.validUntil;
@@ -107,10 +368,10 @@ function resolveNetworkSource(input) {
107
368
  }
108
369
  const relayDns = input.amtFallback?.relayDns?.trim();
109
370
  const relay = relayDns || input.endpoints.map((ep) => ep.relayAddress?.trim()).find((r) => !!r);
110
- const discovery = input.amtFallback?.discovery ?? (relay ? "manual" : void 0);
111
- if (discovery === void 0) return { entries: [], relayFrom: null };
371
+ const discovery = input.amtFallback?.discovery;
372
+ if (discovery === void 0 && !relay) return { entries: [], relayFrom: null };
112
373
  return {
113
- entries: [{ type: "amt", discovery, ...relay ? { relay } : {} }],
374
+ entries: [{ type: "amt", ...discovery ? { discovery } : {}, ...relay ? { relay } : {} }],
114
375
  relayFrom: !relay ? null : relayDns ? "amtFallback.relayDns" : "endpoint.relayAddress"
115
376
  };
116
377
  }
@@ -123,8 +384,11 @@ function validateNetworkSourceEntry(s, i) {
123
384
  const extra = Object.keys(s).filter((k) => !keys.has(k) && s[k] !== void 0);
124
385
  if (extra.length > 0) throw err("invalid_network_source", `has keys the schema rejects: ${extra.join(", ")}`);
125
386
  if (s.type === "amt") {
126
- if (s.discovery !== "driad" && s.discovery !== "manual") {
127
- 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
+ );
128
392
  }
129
393
  if (s.relay !== void 0) {
130
394
  const relay = typeof s.relay === "string" ? s.relay.trim() : "";
@@ -133,8 +397,8 @@ function validateNetworkSourceEntry(s, i) {
133
397
  }
134
398
  s.relay = relay;
135
399
  }
136
- if (s.discovery === "manual" && s.relay === void 0) {
137
- 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)`);
138
402
  }
139
403
  if (s.port !== void 0 && (!Number.isInteger(s.port) || s.port < 1 || s.port > 65535)) {
140
404
  throw err("invalid_port", `port must be 1..65535; got ${s.port}`);
@@ -143,13 +407,15 @@ function validateNetworkSourceEntry(s, i) {
143
407
  }
144
408
  const inRange = (v, min, max) => Number.isInteger(v) && v >= min && v <= max;
145
409
  if (!inRange(s.frequency, 1, Number.MAX_SAFE_INTEGER)) {
146
- 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}`);
147
411
  }
148
- if (!inRange(s.plpId, 0, 63)) throw err("invalid_network_source", `plpId must be 0..63; got ${s.plpId}`);
149
- 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)) {
150
416
  throw err("invalid_network_source", `serviceId must be 0..65535; got ${s.serviceId}`);
151
417
  }
152
- if (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri)) {
418
+ if (s.slsUri !== void 0 && (typeof s.slsUri !== "string" || !isAbsoluteUri(s.slsUri))) {
153
419
  throw err("invalid_network_source", `slsUri must be an absolute URI; got ${JSON.stringify(s.slsUri)}`);
154
420
  }
155
421
  }
@@ -161,7 +427,7 @@ function isAbsoluteUri(value) {
161
427
  return false;
162
428
  }
163
429
  }
164
- function validateEndpoint(ep, idx, seenTuples) {
430
+ function validateEndpoint(ep, idx) {
165
431
  if (ep.protocol === "ssm" && (!ep.sourceAddress || ep.sourceAddress.length === 0)) {
166
432
  throw new MulticastInputError(
167
433
  "ssm_requires_source",
@@ -169,6 +435,13 @@ function validateEndpoint(ep, idx, seenTuples) {
169
435
  `endpoint[${idx}] protocol=ssm requires sourceAddress`
170
436
  );
171
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
+ }
172
445
  if (!isMulticastGroupAddress(ep.groupAddress)) {
173
446
  throw new MulticastInputError(
174
447
  "invalid_group_address",
@@ -228,23 +501,15 @@ function validateEndpoint(ep, idx, seenTuples) {
228
501
  `endpoint[${idx}] bandwidth must be positive; got ${ep.bandwidth}`
229
502
  );
230
503
  }
231
- const tupleKey = `${ep.sourceAddress ?? ""}|${ep.groupAddress}|${ep.port}`;
232
- if (seenTuples.has(tupleKey)) {
233
- throw new MulticastInputError(
234
- "duplicate_endpoint_tuple",
235
- idx,
236
- `endpoint[${idx}] duplicates (sourceAddress, groupAddress, port) tuple "${tupleKey}"`
237
- );
238
- }
239
- seenTuples.add(tupleKey);
240
504
  const out = {
241
- protocol: ep.protocol,
505
+ protocol: ep.sourceAddress === void 0 ? "asm" : "ssm",
242
506
  groupAddress: ep.groupAddress,
243
507
  port: ep.port,
244
508
  tracks: ep.tracks.map((t) => ({ name: t.name, packetId: t.packetId }))
245
509
  };
246
510
  if (ep.sourceAddress !== void 0) out.sourceAddress = ep.sourceAddress;
247
511
  if (ep.bandwidth !== void 0) out.bandwidth = ep.bandwidth;
512
+ if (ep.auth !== void 0) out.auth = { ...ep.auth };
248
513
  return out;
249
514
  }
250
515
  function isMulticastGroupAddress(addr) {
@@ -287,9 +552,9 @@ function multicastFromEnv(env = globalThis.process?.env ?? {}) {
287
552
  endpoints,
288
553
  ...hasCatalogAmt ? {
289
554
  amtFallback: {
290
- // `"manual"` mirrors `resolveNetworkSource`: a relay named in
291
- // the catalog is, by definition, not discovered.
292
- 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 } : {},
293
558
  ...amtRelayDns ? { relayDns: amtRelayDns } : {}
294
559
  }
295
560
  } : {}