@blockcast/mmt-container 0.4.0 → 0.4.1-main.22841c1f0a2d

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 (220) hide show
  1. package/README.md +37 -21
  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 +2037 -881
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +76 -39
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +321 -205
  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 +28 -7
  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/cmcd-producer.d.ts +13 -1
  25. package/dist/cmcd-producer.d.ts.map +1 -1
  26. package/dist/cmcd-producer.js +14 -0
  27. package/dist/cmcd-producer.js.map +2 -2
  28. package/dist/delivery-catalog.js +98 -234
  29. package/dist/delivery-catalog.js.map +4 -4
  30. package/dist/fec-manager.d.ts +108 -1
  31. package/dist/fec-manager.d.ts.map +1 -1
  32. package/dist/fec-manager.js +452 -66
  33. package/dist/fec-manager.js.map +4 -4
  34. package/dist/fec-state.d.ts +2 -1
  35. package/dist/fec-state.d.ts.map +1 -1
  36. package/dist/fec-state.js +18 -3
  37. package/dist/fec-state.js.map +3 -3
  38. package/dist/fec-worker-setup.d.ts +10 -0
  39. package/dist/fec-worker-setup.d.ts.map +1 -1
  40. package/dist/fec-worker-setup.js +15 -4
  41. package/dist/fec-worker-setup.js.map +2 -2
  42. package/dist/held-layer-admission.d.ts +58 -0
  43. package/dist/held-layer-admission.d.ts.map +1 -0
  44. package/dist/held-layer-admission.js +105 -0
  45. package/dist/held-layer-admission.js.map +7 -0
  46. package/dist/index.d.ts +5 -5
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +8 -8
  49. package/dist/index.js.map +2 -2
  50. package/dist/iso-block-locator.d.ts +39 -1
  51. package/dist/iso-block-locator.d.ts.map +1 -1
  52. package/dist/iso-block-locator.js +109 -17
  53. package/dist/iso-block-locator.js.map +3 -3
  54. package/dist/mfu-reassembler.js +21 -13
  55. package/dist/mfu-reassembler.js.map +2 -2
  56. package/dist/mmtp-container-parser.d.ts.map +1 -1
  57. package/dist/mmtp-container-parser.js +93 -22
  58. package/dist/mmtp-container-parser.js.map +2 -2
  59. package/dist/mmtp-container-parser.no-modules.js +3677 -1213
  60. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  61. package/dist/mmtp-decode-pipeline.js +93 -22
  62. package/dist/mmtp-decode-pipeline.js.map +2 -2
  63. package/dist/mmtp-fec-session.d.ts +192 -0
  64. package/dist/mmtp-fec-session.d.ts.map +1 -0
  65. package/dist/mmtp-fec-session.js +640 -0
  66. package/dist/mmtp-fec-session.js.map +7 -0
  67. package/dist/mmtp-router.d.ts +69 -32
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +296 -192
  70. package/dist/mmtp-router.js.map +2 -2
  71. package/dist/multicast-auth-catalog.d.ts +86 -92
  72. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  73. package/dist/multicast-auth-catalog.js +313 -124
  74. package/dist/multicast-auth-catalog.js.map +3 -3
  75. package/dist/multicast-input.d.ts +31 -8
  76. package/dist/multicast-input.d.ts.map +1 -1
  77. package/dist/multicast-input.js +299 -35
  78. package/dist/multicast-input.js.map +3 -3
  79. package/dist/multicast-manager.d.ts +97 -11
  80. package/dist/multicast-manager.d.ts.map +1 -1
  81. package/dist/multicast-manager.js +1022 -527
  82. package/dist/multicast-manager.js.map +4 -4
  83. package/dist/multicast-transport.d.ts +12 -2
  84. package/dist/multicast-transport.d.ts.map +1 -1
  85. package/dist/multicast-transport.js +108 -238
  86. package/dist/multicast-transport.js.map +4 -4
  87. package/dist/multicast-unwrap.js +21 -13
  88. package/dist/multicast-unwrap.js.map +2 -2
  89. package/dist/no-modules.d.ts +5 -3
  90. package/dist/no-modules.d.ts.map +1 -1
  91. package/dist/no-modules.js +3625 -1194
  92. package/dist/no-modules.js.map +4 -4
  93. package/dist/phase14-catalog-override.d.ts +1 -1
  94. package/dist/phase14-catalog-override.d.ts.map +1 -1
  95. package/dist/phase14-catalog-override.js +2 -2
  96. package/dist/phase14-catalog-override.js.map +2 -2
  97. package/dist/repair-fetch.d.ts +81 -6
  98. package/dist/repair-fetch.d.ts.map +1 -1
  99. package/dist/repair-fetch.js +156 -31
  100. package/dist/repair-fetch.js.map +3 -3
  101. package/dist/repair-layers.d.ts +2 -0
  102. package/dist/repair-layers.d.ts.map +1 -1
  103. package/dist/repair-layers.js +19 -2
  104. package/dist/repair-layers.js.map +2 -2
  105. package/dist/sample-combiner.d.ts +7 -1
  106. package/dist/sample-combiner.d.ts.map +1 -1
  107. package/dist/sample-combiner.js +14 -2
  108. package/dist/sample-combiner.js.map +2 -2
  109. package/dist/signaling.d.ts +2 -2
  110. package/dist/signaling.d.ts.map +1 -1
  111. package/dist/signaling.js +3 -3
  112. package/dist/signaling.js.map +2 -2
  113. package/dist/switching-set-alignment.d.ts +1 -1
  114. package/dist/switching-set-alignment.js.map +1 -1
  115. package/dist/timestamp-codec.js +21 -13
  116. package/dist/timestamp-codec.js.map +2 -2
  117. package/dist/wasm-mfu-reassembler.js.map +1 -1
  118. package/dist/wasm-mmtp-container-parser.js +93 -22
  119. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  120. package/package.json +6 -18
  121. package/schemas/catalog.schema.json +133 -38
  122. package/src/align.ts +52 -21
  123. package/src/carp-catalog.ts +188 -68
  124. package/src/catalog-fec-params.ts +28 -3
  125. package/src/catalog-network-source.ts +49 -7
  126. package/src/catalog-validator.ts +4 -11
  127. package/src/cmcd-producer.ts +23 -1
  128. package/src/fec-manager.ts +366 -63
  129. package/src/fec-state.ts +11 -4
  130. package/src/fec-worker-setup.ts +30 -2
  131. package/src/held-layer-admission.ts +161 -0
  132. package/src/index.ts +32 -19
  133. package/src/iso-block-locator.ts +110 -7
  134. package/src/mmtp-container-parser.ts +75 -7
  135. package/src/mmtp-fec-session.ts +606 -0
  136. package/src/mmtp-router.ts +301 -240
  137. package/src/multicast-auth-catalog.ts +134 -238
  138. package/src/multicast-input.ts +148 -124
  139. package/src/multicast-manager.ts +271 -40
  140. package/src/multicast-transport.ts +17 -3
  141. package/src/no-modules.ts +8 -7
  142. package/src/phase14-catalog-override.ts +3 -3
  143. package/src/repair-fetch.ts +283 -39
  144. package/src/repair-layers.ts +22 -2
  145. package/src/sample-combiner.ts +15 -2
  146. package/src/signaling.ts +2 -2
  147. package/src/switching-set-alignment.ts +1 -1
  148. package/test-vectors/align.json +108 -32
  149. package/test-vectors/bc-provenance-v2.json +1526 -0
  150. package/test-vectors/catalog/README.md +71 -4
  151. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  152. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  153. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  154. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  155. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  156. package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
  157. package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
  158. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  159. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  160. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  161. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  162. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  163. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  164. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  165. package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
  166. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  167. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  168. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  169. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  170. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  171. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  172. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  173. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  174. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
  175. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
  176. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  177. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  178. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  179. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  180. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  181. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  182. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  183. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  184. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  185. package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
  186. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  187. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  188. package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
  189. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  190. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  191. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  192. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
  193. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  194. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  195. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  196. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  197. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  198. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  199. package/test-vectors/catalog/section-codes.json +31 -1
  200. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  201. package/test-vectors/catalog-validation.json +101 -5
  202. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  203. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
  204. package/dist/fec-codec.d.ts +0 -32
  205. package/dist/fec-codec.d.ts.map +0 -1
  206. package/dist/fec-codec.js +0 -47
  207. package/dist/fec-codec.js.map +0 -7
  208. package/dist/manifest-auth-plan.d.ts +0 -30
  209. package/dist/manifest-auth-plan.d.ts.map +0 -1
  210. package/dist/manifest-auth-plan.js +0 -1266
  211. package/dist/manifest-auth-plan.js.map +0 -7
  212. package/dist/source-auth.d.ts +0 -2
  213. package/dist/source-auth.d.ts.map +0 -1
  214. package/dist/source-auth.js +0 -1209
  215. package/dist/source-auth.js.map +0 -7
  216. package/src/fec-codec.ts +0 -61
  217. package/src/manifest-auth-plan.ts +0 -107
  218. package/src/source-auth.ts +0 -1
  219. package/test-vectors/generate-source-auth-fixture.mjs +0 -114
  220. package/test-vectors/source-auth-v1.json +0 -61
@@ -28,196 +28,254 @@ function parseFecBlockProfile(value, where) {
28
28
 
29
29
  // ../mmt-base/dist/catalog-fec-source.js
30
30
  var ALL_ROLES = Object.freeze(["video", "audio"]);
31
+ var ISO_SSBG1_MIN_SYMBOL_SIZE = 14;
31
32
 
32
- // src/multicast-auth-catalog.ts
33
- var RAW_ED25519_KEY_LENGTH = 32;
34
- var SOURCE_AUTH_SCOPE_LENGTH = 32;
35
- var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
36
- function encodeBase64Url(bytes) {
37
- let output = "";
38
- for (let i = 0; i < bytes.length; i += 3) {
39
- const b0 = bytes[i];
40
- const b1 = bytes[i + 1];
41
- const b2 = bytes[i + 2];
42
- output += BASE64URL_ALPHABET[b0 >> 2];
43
- output += BASE64URL_ALPHABET[(b0 & 3) << 4 | (b1 === void 0 ? 0 : b1 >> 4)];
44
- if (b1 === void 0) break;
45
- output += BASE64URL_ALPHABET[(b1 & 15) << 2 | (b2 === void 0 ? 0 : b2 >> 6)];
46
- if (b2 === void 0) break;
47
- output += BASE64URL_ALPHABET[b2 & 63];
48
- }
49
- return output;
50
- }
51
- var BASE64URL_DECODE_TABLE = (() => {
52
- const table = new Int8Array(128).fill(-1);
53
- for (let i = 0; i < BASE64URL_ALPHABET.length; i++) {
54
- table[BASE64URL_ALPHABET.charCodeAt(i)] = i;
55
- }
56
- return table;
57
- })();
58
- function decodeBase64Url(text) {
59
- if (text.length % 4 === 1) {
60
- throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text}"`);
61
- }
62
- const bytes = [];
63
- let buffer = 0;
64
- let bits = 0;
65
- for (let i = 0; i < text.length; i++) {
66
- const code = text.charCodeAt(i);
67
- const value = code < 128 ? BASE64URL_DECODE_TABLE[code] : -1;
68
- if (value === void 0 || value < 0) {
69
- throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text}"`);
70
- }
71
- buffer = buffer << 6 | value;
72
- bits += 6;
73
- if (bits >= 8) {
74
- bits -= 8;
75
- bytes.push(buffer >> bits & 255);
76
- }
77
- }
78
- const decoded = Uint8Array.from(bytes);
79
- if (encodeBase64Url(decoded) !== text) {
80
- throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text}"`);
81
- }
82
- return decoded;
83
- }
84
- function decodeAuthScope(authScope) {
85
- const bytes = decodeBase64Url(authScope);
86
- if (bytes.byteLength !== SOURCE_AUTH_SCOPE_LENGTH) {
87
- throw new Error(
88
- `[multicast-auth-catalog] authScope must decode to ${SOURCE_AUTH_SCOPE_LENGTH} raw bytes, got ${bytes.byteLength}`
89
- );
90
- }
91
- return bytes;
92
- }
93
- function decodeEd25519PublicKey(publicKey) {
94
- const bytes = decodeBase64Url(publicKey);
95
- if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
96
- throw new Error(
97
- `[multicast-auth-catalog] public key must decode to ${RAW_ED25519_KEY_LENGTH} raw bytes, got ${bytes.byteLength}`
98
- );
99
- }
100
- return bytes;
33
+ // ../mmt-base/dist/multicast-catalog.js
34
+ var ED25519_PUBLIC_KEY_BASE64URL = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
35
+ var UINT32_MAX = 4294967295;
36
+ var AUTH_MEMBERS = /* @__PURE__ */ new Set(["scheme", "version", "sig", "keys", "minEpoch"]);
37
+ var KEY_MEMBERS = /* @__PURE__ */ new Set(["kid", "publicKey", "firstEpoch"]);
38
+ var ENDPOINT_AUTH_MEMBERS = /* @__PURE__ */ new Set([
39
+ "manifestPort",
40
+ "streamId",
41
+ "senderAddress",
42
+ "maxAuthDelayMs",
43
+ "manifestTimerMs",
44
+ "manifestTrack"
45
+ ]);
46
+ function isObject(value) {
47
+ return typeof value === "object" && value !== null && !Array.isArray(value);
101
48
  }
102
49
  function isNonEmptyString(value) {
103
- return typeof value === "string" && value.length > 0;
104
- }
105
- function isValidAuthScopeField(value) {
106
- if (!isNonEmptyString(value)) return false;
107
- try {
108
- decodeAuthScope(value);
109
- return true;
110
- } catch {
111
- return false;
112
- }
113
- }
114
- function isValidPublicKeyField(value) {
115
- if (!isNonEmptyString(value)) return false;
116
- try {
117
- decodeEd25519PublicKey(value);
118
- return true;
119
- } catch {
120
- return false;
121
- }
50
+ return typeof value === "string" && value.trim().length > 0;
122
51
  }
123
- function hasOnlyKeys(object, allowed) {
124
- const allowedKeys = new Set(allowed);
125
- return Object.keys(object).every((key) => allowedKeys.has(key));
52
+ function isIntegerIn(value, min, max) {
53
+ return Number.isSafeInteger(value) && value >= min && value <= max;
126
54
  }
127
- function isMulticastAuthTrackConfig(obj) {
128
- if (typeof obj !== "object" || obj === null) return false;
129
- const o = obj;
130
- return hasOnlyKeys(o, ["mediaTrack", "manifestTrack", "authScope", "sourceSymbolFormat"]) && isNonEmptyString(o["mediaTrack"]) && isNonEmptyString(o["manifestTrack"]) && o["mediaTrack"] !== o["manifestTrack"] && isValidAuthScopeField(o["authScope"]) && isNonEmptyString(o["sourceSymbolFormat"]);
131
- }
132
- var VALID_COMPACTION = /* @__PURE__ */ new Set(["merkle", "none"]);
133
- var VALID_ENFORCEMENT = /* @__PURE__ */ new Set(["shadow", "enforce"]);
134
- function hasUniqueMulticastAuthTrackBindings(tracks) {
135
- const bindings = tracks.flatMap((track) => {
136
- if (typeof track !== "object" || track === null) return [];
137
- const value = track;
138
- if (typeof value["mediaTrack"] !== "string" || typeof value["sourceSymbolFormat"] !== "string") {
139
- return [];
140
- }
141
- return [JSON.stringify([value["mediaTrack"], value["sourceSymbolFormat"]])];
142
- });
143
- return new Set(bindings).size === bindings.length;
144
- }
145
- function isMulticastAuthConfig(obj) {
146
- if (typeof obj !== "object" || obj === null) return false;
147
- const o = obj;
148
- if (o["scheme"] !== "bc-provenance") return false;
149
- if (o["hash"] !== "blake3") return false;
150
- if (o["sig"] !== "ed25519") return false;
151
- if (!hasOnlyKeys(o, ["scheme", "hash", "sig", "publicKey", "keyId", "previousKey", "compaction", "enforcement", "tracks"])) return false;
152
- if (!isValidPublicKeyField(o["publicKey"])) return false;
153
- if (!isNonEmptyString(o["keyId"])) return false;
154
- if (o["previousKey"] !== void 0 && !isValidPublicKeyField(o["previousKey"])) return false;
155
- if (o["previousKey"] === o["publicKey"]) return false;
156
- if (typeof o["compaction"] !== "string" || !VALID_COMPACTION.has(o["compaction"])) return false;
157
- if (o["enforcement"] !== void 0) {
158
- if (typeof o["enforcement"] !== "string" || !VALID_ENFORCEMENT.has(o["enforcement"])) return false;
159
- }
160
- if (!Array.isArray(o["tracks"]) || o["tracks"].length === 0) return false;
161
- const tracks = o["tracks"];
162
- if (!tracks.every((t) => isMulticastAuthTrackConfig(t))) return false;
163
- const typedTracks = tracks;
164
- const scopes = typedTracks.map((t) => t.authScope);
165
- if (new Set(scopes).size !== scopes.length) return false;
166
- if (!hasUniqueMulticastAuthTrackBindings(typedTracks)) return false;
167
- const manifestTracks = typedTracks.map((t) => t.manifestTrack);
168
- if (new Set(manifestTracks).size !== manifestTracks.length) return false;
169
- return true;
55
+ function multicastEndpointSource(endpoint) {
56
+ if (!isObject(endpoint))
57
+ return void 0;
58
+ const sourceAddress = endpoint["sourceAddress"];
59
+ if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress))
60
+ return void 0;
61
+ const mode = sourceAddress === void 0 ? "asm" : "ssm";
62
+ const protocol = endpoint["protocol"];
63
+ if (protocol !== void 0 && protocol !== mode)
64
+ return void 0;
65
+ const auth = endpoint["auth"];
66
+ const senderAddress = isObject(auth) ? auth["senderAddress"] : void 0;
67
+ if (mode === "ssm")
68
+ return senderAddress === void 0 ? { mode, source: sourceAddress } : void 0;
69
+ if (auth === void 0)
70
+ return { mode };
71
+ return isNonEmptyString(senderAddress) ? { mode, source: senderAddress } : void 0;
170
72
  }
171
- function resolveMulticastAuthMode(playerMode, auth) {
172
- if (playerMode !== void 0) return playerMode;
173
- if (auth === void 0) return "off";
174
- return auth.enforcement ?? "shadow";
73
+ function authIssues(auth) {
74
+ const base = "$.multicast.auth";
75
+ const issue = (path, message) => [
76
+ { code: "multicast_auth", path: `${base}${path}`, message }
77
+ ];
78
+ if (!isObject(auth))
79
+ return issue("", "auth must be an object");
80
+ const unknown = Object.keys(auth).filter((key) => !AUTH_MEMBERS.has(key));
81
+ if (unknown.length > 0) {
82
+ return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -01 7.2.6 defines scheme, version, sig, keys and minEpoch`);
83
+ }
84
+ if (auth["scheme"] !== "bc-provenance")
85
+ return issue(".scheme", 'scheme must be "bc-provenance"');
86
+ if (auth["version"] !== 2)
87
+ return issue(".version", "version must be 2 (bc-provenance version 2, draft -01 7.2)");
88
+ if (auth["sig"] !== "ed25519")
89
+ return issue(".sig", 'sig must be "ed25519"');
90
+ const keys = auth["keys"];
91
+ if (!Array.isArray(keys) || keys.length < 1 || keys.length > 4) {
92
+ return issue(".keys", "keys must be an array of one to four {kid, publicKey, firstEpoch} objects");
93
+ }
94
+ const kids = /* @__PURE__ */ new Set();
95
+ const firstEpochs = /* @__PURE__ */ new Set();
96
+ for (let index = 0; index < keys.length; index++) {
97
+ const key = keys[index];
98
+ const at = `.keys[${index}]`;
99
+ if (!isObject(key) || Object.keys(key).some((member) => !KEY_MEMBERS.has(member))) {
100
+ return issue(at, "a key is exactly {kid, publicKey, firstEpoch}");
101
+ }
102
+ if (!isIntegerIn(key["kid"], 0, UINT32_MAX))
103
+ return issue(`${at}.kid`, "kid must be an unsigned 32-bit integer");
104
+ if (typeof key["publicKey"] !== "string" || !ED25519_PUBLIC_KEY_BASE64URL.test(key["publicKey"])) {
105
+ return issue(`${at}.publicKey`, "publicKey must be a 32-octet Ed25519 key in canonical unpadded base64url");
106
+ }
107
+ if (!isIntegerIn(key["firstEpoch"], 0, UINT32_MAX)) {
108
+ return issue(`${at}.firstEpoch`, "firstEpoch must be an unsigned 32-bit integer");
109
+ }
110
+ if (kids.has(key["kid"]))
111
+ return issue(`${at}.kid`, `kid ${key["kid"]} is repeated; the catalog holds no key set`);
112
+ if (firstEpochs.has(key["firstEpoch"])) {
113
+ return issue(`${at}.firstEpoch`, `firstEpoch ${key["firstEpoch"]} is repeated; the catalog holds no key set`);
114
+ }
115
+ kids.add(key["kid"]);
116
+ firstEpochs.add(key["firstEpoch"]);
117
+ }
118
+ if (!isIntegerIn(auth["minEpoch"], 0, UINT32_MAX)) {
119
+ return issue(".minEpoch", "minEpoch must be an unsigned 32-bit integer");
120
+ }
121
+ return [];
175
122
  }
176
- function resolveMulticastAuthCatalog(catalog, playerMode) {
177
- if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
178
- throw new Error("[multicast-auth-catalog] catalog must be an object");
123
+ function endpointAuthIssue(endpoint, mode, at) {
124
+ const auth = endpoint["auth"];
125
+ if (!isObject(auth))
126
+ return { path: `${at}.auth`, message: "auth must be an object" };
127
+ const unknown = Object.keys(auth).filter((key) => !ENDPOINT_AUTH_MEMBERS.has(key));
128
+ if (unknown.length > 0)
129
+ return { path: `${at}.auth`, message: `auth has unknown member(s) ${unknown.join(", ")}` };
130
+ if (!isIntegerIn(auth["manifestPort"], 1, 65535)) {
131
+ return { path: `${at}.auth.manifestPort`, message: "manifestPort must be an integer from 1 to 65535" };
179
132
  }
180
- const root = catalog;
181
- const rawAuth = root["multicast.auth"];
182
- if (rawAuth === void 0) {
183
- if (playerMode === "enforce") {
184
- throw new Error("[multicast-auth-catalog] player enforce mode requires multicast.auth");
185
- }
186
- return void 0;
133
+ if (!isIntegerIn(auth["streamId"], 0, UINT32_MAX)) {
134
+ return { path: `${at}.auth.streamId`, message: "streamId must be an unsigned 32-bit integer" };
187
135
  }
188
- if (!isMulticastAuthConfig(rawAuth)) {
189
- throw new Error("[multicast-auth-catalog] invalid multicast.auth v2 block");
136
+ if (mode === "ssm" && auth["senderAddress"] !== void 0) {
137
+ return { path: `${at}.auth.senderAddress`, message: "senderAddress must not appear on an SSM endpoint; S is sourceAddress" };
190
138
  }
191
- const rawTracks = root["tracks"];
192
- if (!Array.isArray(rawTracks)) {
193
- throw new Error("[multicast-auth-catalog] catalog tracks must be an array");
139
+ if (mode === "asm" && !isNonEmptyString(auth["senderAddress"])) {
140
+ return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress" };
194
141
  }
195
- const catalogTrackNames = new Set(
196
- rawTracks.flatMap(
197
- (track) => typeof track === "object" && track !== null && typeof track["name"] === "string" ? [track["name"]] : []
198
- )
199
- );
200
- for (const track of rawAuth.tracks) {
201
- if (!catalogTrackNames.has(track.mediaTrack)) {
202
- throw new Error(`[multicast-auth-catalog] unknown mediaTrack "${track.mediaTrack}"`);
203
- }
204
- if (!catalogTrackNames.has(track.manifestTrack)) {
205
- throw new Error(`[multicast-auth-catalog] unknown manifestTrack "${track.manifestTrack}"`);
206
- }
207
- }
208
- return {
209
- keyId: rawAuth.keyId,
210
- acceptedPublicKeys: [
211
- decodeEd25519PublicKey(rawAuth.publicKey),
212
- ...rawAuth.previousKey === void 0 ? [] : [decodeEd25519PublicKey(rawAuth.previousKey)]
213
- ],
214
- mode: resolveMulticastAuthMode(playerMode, rawAuth),
215
- compaction: rawAuth.compaction,
216
- tracks: rawAuth.tracks.map((track) => ({
217
- ...track,
218
- authScope: decodeAuthScope(track.authScope)
219
- }))
142
+ if (auth["maxAuthDelayMs"] !== void 0 && !isIntegerIn(auth["maxAuthDelayMs"], 50, 1e3)) {
143
+ return { path: `${at}.auth.maxAuthDelayMs`, message: "maxAuthDelayMs must be an integer from 50 to 1000" };
144
+ }
145
+ if (auth["manifestTimerMs"] !== void 0 && !isIntegerIn(auth["manifestTimerMs"], 1, Number.MAX_SAFE_INTEGER)) {
146
+ return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be an integer of at least 1" };
147
+ }
148
+ if (auth["manifestTrack"] !== void 0 && !isNonEmptyString(auth["manifestTrack"])) {
149
+ return { path: `${at}.auth.manifestTrack`, message: "manifestTrack must be a non-empty string" };
150
+ }
151
+ if (!isIntegerIn(endpoint["bandwidth"], 1, Number.MAX_SAFE_INTEGER)) {
152
+ return { path: `${at}.bandwidth`, message: "a protected endpoint requires bandwidth, which bounds the receiver's hold queues" };
153
+ }
154
+ return void 0;
155
+ }
156
+ var CATALOG_NAMESPACE = /* @__PURE__ */ Symbol.for("@blockcast/mmt-base/catalogNamespace");
157
+ function multicastCatalogIssues(catalog, options = {}) {
158
+ if (!isObject(catalog))
159
+ return [];
160
+ const issues = [];
161
+ if ("multicast.auth" in catalog) {
162
+ issues.push({
163
+ code: "multicast_auth",
164
+ path: '$["multicast.auth"]',
165
+ message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -01 7.2.6)'
166
+ });
167
+ }
168
+ const multicast = catalog["multicast"];
169
+ if (!isObject(multicast))
170
+ return issues;
171
+ const protectedCatalog = multicast["auth"] !== void 0;
172
+ if (protectedCatalog)
173
+ issues.push(...authIssues(multicast["auth"]));
174
+ const endpoints = multicast["endpoints"];
175
+ if (!Array.isArray(endpoints))
176
+ return issues;
177
+ const tracks = Array.isArray(catalog["tracks"]) ? catalog["tracks"] : [];
178
+ const namespaceOf = /* @__PURE__ */ new Map();
179
+ for (const track of tracks) {
180
+ if (isObject(track) && typeof track["name"] === "string")
181
+ namespaceOf.set(track["name"], track["namespace"]);
182
+ }
183
+ const tagged = catalog[CATALOG_NAMESPACE];
184
+ let referenceNamespace = options.catalogNamespace ?? (typeof tagged === "string" ? tagged : void 0);
185
+ const sources = [];
186
+ for (let index = 0; index < endpoints.length; index++) {
187
+ const endpoint = endpoints[index];
188
+ const at = `$.multicast.endpoints[${index}]`;
189
+ const fail = (code, path, message) => {
190
+ issues.push({ code, path, message, endpointIndex: index });
191
+ };
192
+ sources.push(void 0);
193
+ if (!isObject(endpoint)) {
194
+ fail("multicast_endpoint", at, "endpoint must be an object");
195
+ continue;
196
+ }
197
+ const protocol = endpoint["protocol"];
198
+ if (protocol !== void 0 && protocol !== "ssm" && protocol !== "asm") {
199
+ 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)`);
200
+ continue;
201
+ }
202
+ const hasAuth = endpoint["auth"] !== void 0;
203
+ if (protectedCatalog !== hasAuth) {
204
+ 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");
205
+ continue;
206
+ }
207
+ const sourceAddress = endpoint["sourceAddress"];
208
+ if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress)) {
209
+ fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be a non-empty string");
210
+ continue;
211
+ }
212
+ const mode = sourceAddress === void 0 ? "asm" : "ssm";
213
+ if (protocol !== void 0 && protocol !== mode) {
214
+ fail("multicast_endpoint", `${at}.protocol`, `protocol ${JSON.stringify(protocol)} disagrees with sourceAddress, which selects ${mode}`);
215
+ continue;
216
+ }
217
+ if (!isIntegerIn(endpoint["port"], 1, 65535)) {
218
+ fail("multicast_endpoint", `${at}.port`, "port must be an integer from 1 to 65535");
219
+ continue;
220
+ }
221
+ if (hasAuth) {
222
+ const authIssue = endpointAuthIssue(endpoint, mode, at);
223
+ if (authIssue) {
224
+ fail("multicast_endpoint_auth", authIssue.path, authIssue.message);
225
+ continue;
226
+ }
227
+ }
228
+ sources[index] = multicastEndpointSource(endpoint);
229
+ const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
230
+ for (let refIndex = 0; refIndex < refs.length; refIndex++) {
231
+ const ref = refs[refIndex];
232
+ const name = isObject(ref) ? ref["name"] : ref;
233
+ if (typeof name !== "string")
234
+ continue;
235
+ const namespace = namespaceOf.get(name);
236
+ if (typeof namespace !== "string")
237
+ continue;
238
+ referenceNamespace ??= namespace;
239
+ if (namespace !== referenceNamespace) {
240
+ fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} declares namespace ${JSON.stringify(namespace)}, not the catalog track's ${JSON.stringify(referenceNamespace)}`);
241
+ }
242
+ }
243
+ }
244
+ const tupleOf = (index) => {
245
+ const endpoint = endpoints[index];
246
+ const auth = endpoint["auth"];
247
+ return {
248
+ sg: JSON.stringify([sources[index].source ?? null, endpoint["groupAddress"]]),
249
+ port: endpoint["port"],
250
+ manifestPort: isObject(auth) ? auth["manifestPort"] : void 0
251
+ };
220
252
  };
253
+ for (let index = 0; index < endpoints.length; index++) {
254
+ if (!sources[index])
255
+ continue;
256
+ const own = tupleOf(index);
257
+ const at = `$.multicast.endpoints[${index}]`;
258
+ if (own.manifestPort !== void 0 && own.manifestPort === own.port) {
259
+ issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
260
+ continue;
261
+ }
262
+ for (let other = 0; other < endpoints.length; other++) {
263
+ if (other === index || !sources[other])
264
+ continue;
265
+ const peer = tupleOf(other);
266
+ if (peer.sg !== own.sg)
267
+ continue;
268
+ if (peer.port === own.port) {
269
+ 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 });
270
+ break;
271
+ }
272
+ if (own.manifestPort !== void 0 && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
273
+ 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 });
274
+ break;
275
+ }
276
+ }
277
+ }
278
+ return issues;
221
279
  }
222
280
 
223
281
  // src/repair-layers.ts
@@ -227,6 +285,7 @@ var DEFAULT_REPAIR_PRIORITY = 240;
227
285
  var MAX_RAPTORQ_SOURCE_SYMBOLS = 56403;
228
286
  var MAX_REPAIR_SYMBOLS = 16777215;
229
287
  var MAX_ENCODING_SYMBOL_ID = 16777215;
288
+ var MAX_REED_SOLOMON_BLOCK_SYMBOLS = 255;
230
289
  var RepairContractError = class extends Error {
231
290
  constructor(code, path, message) {
232
291
  super(`[repair-layers:${code}] ${path}: ${message}`);
@@ -409,11 +468,12 @@ function assembleRepairLayers(source, descriptors, fail = throwRepairContractErr
409
468
  if (layered && !positiveInteger(source.sourceSymbols)) {
410
469
  fail("track_fec", `${source.path}.sourceSymbols`, "layered or overlay repair needs a positive integer sourceSymbols on the source");
411
470
  }
412
- if (layered && source.algorithm !== "raptorq") {
471
+ const reedSolomon = source.algorithm === "reed-solomon";
472
+ if (layered && source.algorithm !== "raptorq" && !reedSolomon) {
413
473
  fail(
414
474
  "track_fec",
415
475
  `${source.path}.algorithm`,
416
- "repair layers and overlays are defined only for raptorq: a block code fixes its codeword length, so symbols of a larger P are not symbols of the code a receiver holding fewer layers decodes"
476
+ "repair layers and overlays are defined only for raptorq and reed-solomon (draft-ramadan-moq-fec-01 6.3.4 rule 7)"
417
477
  );
418
478
  }
419
479
  let layerZeroPriority = DEFAULT_REPAIR_PRIORITY;
@@ -472,6 +532,13 @@ function assembleRepairLayers(source, descriptors, fail = throwRepairContractErr
472
532
  `overlay sourceSymbols + repairSymbols - 1 exceeds the 24-bit ESI space (${MAX_ENCODING_SYMBOL_ID})`
473
533
  );
474
534
  }
535
+ if (reedSolomon && sourceSymbols + repairSymbols > MAX_REED_SOLOMON_BLOCK_SYMBOLS) {
536
+ fail(
537
+ "track_fec_bounds",
538
+ `${d.path}.repairSymbols`,
539
+ `reed-solomon overlay sourceSymbols + repairSymbols exceeds ${MAX_REED_SOLOMON_BLOCK_SYMBOLS} (draft-ramadan-moq-fec-01 6.3.4 rule 12)`
540
+ );
541
+ }
475
542
  overlays.push({ repairTrackName: d.name, scope: "keyframe", sourceSymbols, repairSymbols, priority: d.priority });
476
543
  }
477
544
  let offset = layerZeroSymbols;
@@ -516,6 +583,13 @@ function assembleRepairLayers(source, descriptors, fail = throwRepairContractErr
516
583
  `sourceSymbols + total base repair symbols - 1 exceeds the 24-bit ESI space (${MAX_ENCODING_SYMBOL_ID})`
517
584
  );
518
585
  }
586
+ if (reedSolomon && k + totalBaseRepairSymbols > MAX_REED_SOLOMON_BLOCK_SYMBOLS) {
587
+ fail(
588
+ "track_fec_bounds",
589
+ `${source.path}.sourceSymbols`,
590
+ `reed-solomon sourceSymbols + total base repair symbols exceeds ${MAX_REED_SOLOMON_BLOCK_SYMBOLS} (draft-ramadan-moq-fec-01 6.3.4 rule 12)`
591
+ );
592
+ }
519
593
  return { sourceTrackName: source.name, baseLayers, overlays, totalBaseRepairSymbols };
520
594
  }
521
595
 
@@ -565,7 +639,7 @@ function validateSwitchingSet(trackNames) {
565
639
  return { ok: true };
566
640
  }
567
641
  const presentRoles = new Set(roles.filter((r) => r !== "single"));
568
- const required = ["base", "delta", "repair"];
642
+ const required = ["base", "repair"];
569
643
  const missing = required.filter((r) => !presentRoles.has(r));
570
644
  if (missing.length > 0) {
571
645
  return { ok: false, missing };
@@ -577,7 +651,7 @@ function isFecCatalogGeometry(obj) {
577
651
  const o = obj;
578
652
  const algorithm = o["algorithm"];
579
653
  const symbolSize = o["symbolSize"];
580
- return typeof algorithm === "string" && (algorithm === "none" || algorithm === "raptorq" || algorithm === "reed-solomon") && typeof o["sourceSymbols"] === "number" && o["sourceSymbols"] >= 1 && typeof o["repairSymbols"] === "number" && o["repairSymbols"] >= 1 && typeof symbolSize === "number" && symbolSize >= 1 && (algorithm !== "raptorq" || symbolSize % 8 === 0) && typeof o["repairTrack"] === "string" && o["repairTrack"].length > 0;
654
+ return typeof algorithm === "string" && algorithm.length > 0 && typeof o["sourceSymbols"] === "number" && o["sourceSymbols"] >= 1 && typeof o["repairSymbols"] === "number" && o["repairSymbols"] >= 1 && typeof symbolSize === "number" && symbolSize >= 1 && (algorithm !== "raptorq" || symbolSize % 8 === 0) && typeof o["repairTrack"] === "string" && o["repairTrack"].length > 0;
581
655
  }
582
656
  function isFecCatalogConfig(obj) {
583
657
  if (!isFecCatalogGeometry(obj)) return false;
@@ -592,8 +666,7 @@ function isMulticastTrackObject(obj) {
592
666
  function isMulticastEndpoint(obj) {
593
667
  if (typeof obj !== "object" || obj === null) return false;
594
668
  const o = obj;
595
- const protocol = o["protocol"] ?? (typeof o["sourceAddress"] === "string" && o["sourceAddress"].length > 0 ? "ssm" : void 0);
596
- return typeof protocol === "string" && (protocol === "ssm" || protocol === "asm" || protocol === "amt" || protocol === "atsc3") && typeof o["groupAddress"] === "string" && o["groupAddress"].length > 0 && typeof o["port"] === "number" && o["port"] > 0 && o["port"] <= 65535 && Array.isArray(o["tracks"]) && o["tracks"].every((t) => typeof t === "string" || isMulticastTrackObject(t));
669
+ return multicastEndpointSource(o) !== void 0 && typeof o["groupAddress"] === "string" && o["groupAddress"].length > 0 && typeof o["port"] === "number" && o["port"] > 0 && o["port"] <= 65535 && Array.isArray(o["tracks"]) && o["tracks"].every((t) => typeof t === "string" || isMulticastTrackObject(t));
597
670
  }
598
671
  function isMulticastCatalogConfig(obj) {
599
672
  if (typeof obj !== "object" || obj === null) return false;
@@ -697,13 +770,22 @@ var CmsfCatalogValidationError = class extends Error {
697
770
  function catalogError(code, path, message) {
698
771
  throw new CmsfCatalogValidationError(code, path, message);
699
772
  }
700
- function validateCmsfMmtpCatalog(value) {
773
+ function validateNetworkSourceRelays(sources, path) {
774
+ if (!Array.isArray(sources)) return;
775
+ sources.forEach((source, i) => {
776
+ const s = source;
777
+ if (s?.["type"] === "amt" && s["discovery"] === "driad" && s["relay"] !== void 0) {
778
+ catalogError("multicast_network_source", `${path}[${i}].relay`, 'relay must be omitted with discovery "driad"');
779
+ }
780
+ });
781
+ }
782
+ function validateCmsfMmtpCatalog(value, options = {}) {
701
783
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
702
784
  catalogError("catalog_object", "$", "catalog must be an object");
703
785
  }
704
786
  const catalog = value;
705
787
  const rawVersion = catalog["version"];
706
- const normalizedVersion = typeof rawVersion === "string" ? Number.isFinite(Number(rawVersion)) ? Number(rawVersion) : rawVersion.startsWith("draft-ietf-moq-catalogformat") ? 1 : NaN : rawVersion;
788
+ const normalizedVersion = typeof rawVersion === "string" ? Number.isFinite(Number(rawVersion)) ? Number(rawVersion) : rawVersion.startsWith("draft-ietf-moq-catalogformat") || rawVersion === "draft-01" ? 1 : NaN : rawVersion;
707
789
  if (!Number.isInteger(normalizedVersion) || normalizedVersion <= 0) {
708
790
  catalogError("catalog_version", "$.version", "version must be a positive integer or a recognized format tag");
709
791
  }
@@ -718,6 +800,22 @@ function validateCmsfMmtpCatalog(value) {
718
800
  "commonTrackFields is retired; every track carries its own fields"
719
801
  );
720
802
  }
803
+ const initDataList = catalog["initDataList"];
804
+ if (initDataList !== void 0) {
805
+ if (!Array.isArray(initDataList)) {
806
+ catalogError("catalog_init_data_list", "$.initDataList", "initDataList must be an array");
807
+ }
808
+ initDataList.forEach((entry, i) => {
809
+ const e = entry;
810
+ const entryPath = `$.initDataList[${i}]`;
811
+ if (typeof e !== "object" || e === null || Array.isArray(e) || typeof e["id"] !== "string" || e["id"].length === 0 || typeof e["type"] !== "string" || e["type"].length === 0) {
812
+ catalogError("catalog_init_data_list", entryPath, "entry needs a non-empty string id and type");
813
+ }
814
+ if (e["type"] === "inline" && (typeof e["data"] !== "string" || e["data"].length === 0)) {
815
+ catalogError("catalog_init_data_list", `${entryPath}.data`, 'an "inline" entry needs non-empty data');
816
+ }
817
+ });
818
+ }
721
819
  const tracks = catalog["tracks"];
722
820
  const trackRecords = [];
723
821
  const positiveInteger2 = (input) => Number.isSafeInteger(input) && input > 0;
@@ -769,6 +867,14 @@ function validateCmsfMmtpCatalog(value) {
769
867
  if (keyframeIntervalMs !== void 0 && !positiveNumber(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger2(keyframeIntervalTicks)) {
770
868
  catalogError("track_keyframe_interval", path, "keyframe interval fields must be positive numbers");
771
869
  }
870
+ const anchor = track["presentationAnchorTicks"];
871
+ if (anchor !== void 0 && !Number.isSafeInteger(anchor)) {
872
+ catalogError("track_presentation_anchor", `${path}.presentationAnchorTicks`, "must be a safe integer");
873
+ }
874
+ const initRef = track["initRef"];
875
+ if (initRef !== void 0 && (typeof initRef !== "string" || initRef.length === 0)) {
876
+ catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
877
+ }
772
878
  if (packaging === "fec-repair") {
773
879
  rejectRepairTrackGeometry(path, track, catalogError);
774
880
  validateRepairTrackFields(describeRepairTrack(name, path, track), catalogError);
@@ -776,9 +882,8 @@ function validateCmsfMmtpCatalog(value) {
776
882
  rejectRepairFieldsOnMediaTrack(path, track, catalogError);
777
883
  }
778
884
  if (packaging === "mmtp") {
779
- const mmtpMode = track["mmtpMode"];
780
- if (mmtpMode !== "mpu" && mmtpMode !== "mfu") {
781
- catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mpu or mfu");
885
+ if (track["mmtpMode"] !== "mfu") {
886
+ catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
782
887
  }
783
888
  if (!positiveInteger2(timescale)) {
784
889
  catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
@@ -801,8 +906,8 @@ function validateCmsfMmtpCatalog(value) {
801
906
  }
802
907
  const config = fec;
803
908
  const algorithm = config["algorithm"];
804
- if (algorithm !== "none" && algorithm !== "raptorq" && algorithm !== "reed-solomon") {
805
- catalogError("track_fec", `${path}.fec.algorithm`, "algorithm is not supported");
909
+ if (typeof algorithm !== "string" || algorithm.length === 0) {
910
+ catalogError("track_fec", `${path}.fec.algorithm`, "must be a non-empty string");
806
911
  }
807
912
  if ("interleaveDepth" in config || "interleaveMs" in config) {
808
913
  catalogError("track_fec", `${path}.fec`, "interleaveDepthMs is the only supported interleave field");
@@ -831,6 +936,9 @@ function validateCmsfMmtpCatalog(value) {
831
936
  }
832
937
  }
833
938
  readFecBlockProfile(config["blockProfile"], `${path}.fec.blockProfile`, algorithm !== "none", catalogError);
939
+ if (algorithm !== "none" && config["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE) {
940
+ catalogError("track_fec", `${path}.fec.symbolSize`, "iso-ssbg1-v1 symbolSize must be at least 14");
941
+ }
834
942
  }
835
943
  }
836
944
  const repairDescriptors = trackRecords.flatMap(
@@ -880,19 +988,34 @@ function validateCmsfMmtpCatalog(value) {
880
988
  const timescale = BigInt(track["timescale"]);
881
989
  const durationTicks = track["groupDurationTicks"];
882
990
  const ticks = durationTicks !== void 0 ? BigInt(durationTicks) : BigInt(track["groupDurationMs"]) * timescale / 1000n;
883
- const anchor = switchingSets.get(altGroup);
884
- if (anchor && ticks * anchor.timescale !== anchor.ticks * timescale) {
885
- catalogError("track_switching_set", `$.tracks[${index}]`, `group duration does not match ${JSON.stringify(anchor.name)} in altGroup ${altGroup}`);
991
+ const framerate = track["framerate"];
992
+ const intraOnly = positiveNumber(framerate) && Math.abs(Number(ticks) * framerate - Number(timescale)) <= Number(timescale) * 1e-3;
993
+ const members = switchingSets.get(altGroup) ?? [];
994
+ members.push({ index, name: track["name"], ticks, timescale, intraOnly });
995
+ switchingSets.set(altGroup, members);
996
+ }
997
+ for (const [altGroup, members] of switchingSets) {
998
+ const anchor = members.find((member) => !member.intraOnly) ?? members[0];
999
+ for (const member of members) {
1000
+ if (member === anchor || member.ticks * anchor.timescale === anchor.ticks * member.timescale) continue;
1001
+ const nests = member.intraOnly && !anchor.intraOnly && anchor.ticks * member.timescale % (member.ticks * anchor.timescale) === 0n;
1002
+ if (!nests) {
1003
+ catalogError("track_switching_set", `$.tracks[${member.index}]`, `group duration does not match ${JSON.stringify(anchor.name)} in altGroup ${altGroup}`);
1004
+ }
886
1005
  }
887
- if (!anchor) switchingSets.set(altGroup, { name: track["name"], ticks, timescale });
888
1006
  }
889
1007
  const multicast = catalog["multicast"];
890
1008
  if (typeof multicast === "object" && multicast !== null && !Array.isArray(multicast)) {
1009
+ validateNetworkSourceRelays(multicast["networkSource"], "$.multicast.networkSource");
891
1010
  const endpoints = multicast["endpoints"];
892
1011
  if (Array.isArray(endpoints)) {
893
1012
  for (let endpointIndex = 0; endpointIndex < endpoints.length; endpointIndex++) {
894
1013
  const endpoint = endpoints[endpointIndex];
895
1014
  if (typeof endpoint !== "object" || endpoint === null || Array.isArray(endpoint)) continue;
1015
+ validateNetworkSourceRelays(
1016
+ endpoint["networkSource"],
1017
+ `$.multicast.endpoints[${endpointIndex}].networkSource`
1018
+ );
896
1019
  if ("relayAddress" in endpoint) {
897
1020
  catalogError(
898
1021
  "multicast_relay_address",
@@ -932,15 +1055,8 @@ function validateCmsfMmtpCatalog(value) {
932
1055
  }
933
1056
  }
934
1057
  }
935
- try {
936
- resolveMulticastAuthCatalog(catalog);
937
- } catch (error) {
938
- catalogError(
939
- "multicast_auth",
940
- "$.multicast.auth",
941
- error instanceof Error ? error.message : "invalid multicast.auth v2 block"
942
- );
943
- }
1058
+ const [multicastIssue] = multicastCatalogIssues(catalog, options);
1059
+ if (multicastIssue) catalogError(multicastIssue.code, multicastIssue.path, multicastIssue.message);
944
1060
  validateArchive(catalog);
945
1061
  return catalog;
946
1062
  }
@@ -966,7 +1082,7 @@ function resolveGroupDurationTicks(timing, timescale) {
966
1082
  const product = timing.groupDurationMs * timescale;
967
1083
  if (product % 1e3 !== 0) {
968
1084
  throw new Error(
969
- `[carp-catalog] resolveGroupDurationTicks: groupDurationMs=${timing.groupDurationMs} at timescale=${timescale} produces non-integer ticks (${product / 1e3}); publisher must use groupDurationTicks override (mmt-00 \xA74.4.4)`
1085
+ `[carp-catalog] resolveGroupDurationTicks: groupDurationMs=${timing.groupDurationMs} at timescale=${timescale} produces non-integer ticks (${product / 1e3}); publisher must use groupDurationTicks override (mmt-01 \xA74.4.2)`
970
1086
  );
971
1087
  }
972
1088
  return product / 1e3;