@blockcast/mmt-container 0.4.0-main.bbd83cb48eff → 0.4.0-main.c7ae84be5039

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 (152) hide show
  1. package/README.md +28 -14
  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 +778 -272
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +58 -26
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +270 -194
  11. package/dist/carp-catalog.js.map +3 -3
  12. package/dist/catalog-fec-params.d.ts +1 -1
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +6 -13
  15. package/dist/catalog-fec-params.js.map +3 -3
  16. package/dist/catalog-network-source.d.ts +1 -1
  17. package/dist/catalog-network-source.d.ts.map +1 -1
  18. package/dist/catalog-network-source.js.map +1 -1
  19. package/dist/catalog-validator.d.ts +4 -3
  20. package/dist/catalog-validator.d.ts.map +1 -1
  21. package/dist/catalog-validator.js +0 -29
  22. package/dist/catalog-validator.js.map +3 -3
  23. package/dist/delivery-catalog.js +4 -12
  24. package/dist/delivery-catalog.js.map +4 -4
  25. package/dist/fec-manager.js.map +1 -1
  26. package/dist/fec-state.d.ts.map +1 -1
  27. package/dist/fec-state.js +14 -2
  28. package/dist/fec-state.js.map +3 -3
  29. package/dist/fec-worker-setup.js.map +1 -1
  30. package/dist/index.d.ts +2 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +4 -0
  33. package/dist/index.js.map +2 -2
  34. package/dist/iso-block-locator.js.map +1 -1
  35. package/dist/manifest-auth-plan.d.ts +26 -25
  36. package/dist/manifest-auth-plan.d.ts.map +1 -1
  37. package/dist/manifest-auth-plan.js +315 -1163
  38. package/dist/manifest-auth-plan.js.map +4 -4
  39. package/dist/mfu-reassembler.js.map +2 -2
  40. package/dist/mmtp-container-parser.js.map +2 -2
  41. package/dist/mmtp-container-parser.no-modules.js +947 -278
  42. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  43. package/dist/mmtp-decode-pipeline.js.map +2 -2
  44. package/dist/mmtp-fec-session.d.ts +156 -0
  45. package/dist/mmtp-fec-session.d.ts.map +1 -0
  46. package/dist/mmtp-fec-session.js +522 -0
  47. package/dist/mmtp-fec-session.js.map +7 -0
  48. package/dist/mmtp-router.d.ts.map +1 -1
  49. package/dist/mmtp-router.js +17 -0
  50. package/dist/mmtp-router.js.map +2 -2
  51. package/dist/multicast-auth-catalog.d.ts +86 -92
  52. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  53. package/dist/multicast-auth-catalog.js +331 -124
  54. package/dist/multicast-auth-catalog.js.map +3 -3
  55. package/dist/multicast-input.d.ts +26 -4
  56. package/dist/multicast-input.d.ts.map +1 -1
  57. package/dist/multicast-input.js +283 -23
  58. package/dist/multicast-input.js.map +3 -3
  59. package/dist/multicast-manager.d.ts +23 -4
  60. package/dist/multicast-manager.d.ts.map +1 -1
  61. package/dist/multicast-manager.js +59 -29
  62. package/dist/multicast-manager.js.map +4 -4
  63. package/dist/multicast-transport.js +2 -10
  64. package/dist/multicast-transport.js.map +4 -4
  65. package/dist/multicast-unwrap.js.map +2 -2
  66. package/dist/no-modules.d.ts +2 -0
  67. package/dist/no-modules.d.ts.map +1 -1
  68. package/dist/no-modules.js +899 -267
  69. package/dist/no-modules.js.map +4 -4
  70. package/dist/phase14-catalog-override.d.ts +1 -1
  71. package/dist/phase14-catalog-override.d.ts.map +1 -1
  72. package/dist/phase14-catalog-override.js +2 -2
  73. package/dist/phase14-catalog-override.js.map +2 -2
  74. package/dist/repair-fetch.d.ts +23 -1
  75. package/dist/repair-fetch.d.ts.map +1 -1
  76. package/dist/repair-fetch.js +35 -10
  77. package/dist/repair-fetch.js.map +2 -2
  78. package/dist/repair-layers.js.map +1 -1
  79. package/dist/signaling.d.ts +2 -2
  80. package/dist/signaling.d.ts.map +1 -1
  81. package/dist/signaling.js +3 -3
  82. package/dist/signaling.js.map +2 -2
  83. package/dist/source-auth.js +22 -6
  84. package/dist/source-auth.js.map +2 -2
  85. package/dist/switching-set-alignment.d.ts +1 -1
  86. package/dist/switching-set-alignment.js.map +1 -1
  87. package/dist/timestamp-codec.js.map +2 -2
  88. package/dist/wasm-mfu-reassembler.js.map +1 -1
  89. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  90. package/package.json +5 -5
  91. package/schemas/catalog.schema.json +117 -34
  92. package/src/align.ts +52 -21
  93. package/src/carp-catalog.ts +120 -46
  94. package/src/catalog-fec-params.ts +5 -2
  95. package/src/catalog-network-source.ts +1 -1
  96. package/src/catalog-validator.ts +4 -11
  97. package/src/fec-state.ts +3 -2
  98. package/src/index.ts +18 -2
  99. package/src/manifest-auth-plan.ts +39 -91
  100. package/src/mmtp-fec-session.ts +514 -0
  101. package/src/mmtp-router.ts +25 -0
  102. package/src/multicast-auth-catalog.ts +131 -238
  103. package/src/multicast-input.ts +109 -54
  104. package/src/multicast-manager.ts +88 -14
  105. package/src/no-modules.ts +2 -0
  106. package/src/phase14-catalog-override.ts +3 -3
  107. package/src/repair-fetch.ts +79 -14
  108. package/src/signaling.ts +2 -2
  109. package/src/switching-set-alignment.ts +1 -1
  110. package/test-vectors/align.json +108 -32
  111. package/test-vectors/catalog/README.md +55 -3
  112. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  113. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  114. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  115. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  116. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  117. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  118. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  119. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  120. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  121. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  122. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  123. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  124. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  125. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  126. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  127. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  128. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  129. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-out-of-range.json +56 -0
  130. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  131. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  132. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  133. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  134. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  135. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  136. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  137. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  138. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  139. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  140. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  141. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  142. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +2 -2
  143. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  144. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  145. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  146. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  147. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  148. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  149. package/test-vectors/catalog/section-codes.json +27 -1
  150. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  151. package/test-vectors/catalog-validation.json +3 -2
  152. package/test-vectors/catalog-validator-public-api.mjs +14 -9
@@ -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
- }
50
+ return typeof value === "string" && value.trim().length > 0;
113
51
  }
114
- function isValidPublicKeyField(value) {
115
- if (!isNonEmptyString(value)) return false;
116
- try {
117
- decodeEd25519PublicKey(value);
118
- return true;
119
- } catch {
120
- return false;
121
- }
122
- }
123
- function hasOnlyKeys(object, allowed) {
124
- const allowedKeys = new Set(allowed);
125
- return Object.keys(object).every((key) => allowedKeys.has(key));
126
- }
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;
52
+ function isIntegerIn(value, min, max) {
53
+ return Number.isSafeInteger(value) && value >= min && value <= max;
144
54
  }
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
@@ -592,8 +650,7 @@ function isMulticastTrackObject(obj) {
592
650
  function isMulticastEndpoint(obj) {
593
651
  if (typeof obj !== "object" || obj === null) return false;
594
652
  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));
653
+ 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
654
  }
598
655
  function isMulticastCatalogConfig(obj) {
599
656
  if (typeof obj !== "object" || obj === null) return false;
@@ -697,7 +754,7 @@ var CmsfCatalogValidationError = class extends Error {
697
754
  function catalogError(code, path, message) {
698
755
  throw new CmsfCatalogValidationError(code, path, message);
699
756
  }
700
- function validateCmsfMmtpCatalog(value) {
757
+ function validateCmsfMmtpCatalog(value, options = {}) {
701
758
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
702
759
  catalogError("catalog_object", "$", "catalog must be an object");
703
760
  }
@@ -718,6 +775,22 @@ function validateCmsfMmtpCatalog(value) {
718
775
  "commonTrackFields is retired; every track carries its own fields"
719
776
  );
720
777
  }
778
+ const initDataList = catalog["initDataList"];
779
+ if (initDataList !== void 0) {
780
+ if (!Array.isArray(initDataList)) {
781
+ catalogError("catalog_init_data_list", "$.initDataList", "initDataList must be an array");
782
+ }
783
+ initDataList.forEach((entry, i) => {
784
+ const e = entry;
785
+ const entryPath = `$.initDataList[${i}]`;
786
+ 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) {
787
+ catalogError("catalog_init_data_list", entryPath, "entry needs a non-empty string id and type");
788
+ }
789
+ if (e["type"] === "inline" && (typeof e["data"] !== "string" || e["data"].length === 0)) {
790
+ catalogError("catalog_init_data_list", `${entryPath}.data`, 'an "inline" entry needs non-empty data');
791
+ }
792
+ });
793
+ }
721
794
  const tracks = catalog["tracks"];
722
795
  const trackRecords = [];
723
796
  const positiveInteger2 = (input) => Number.isSafeInteger(input) && input > 0;
@@ -769,6 +842,14 @@ function validateCmsfMmtpCatalog(value) {
769
842
  if (keyframeIntervalMs !== void 0 && !positiveNumber(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger2(keyframeIntervalTicks)) {
770
843
  catalogError("track_keyframe_interval", path, "keyframe interval fields must be positive numbers");
771
844
  }
845
+ const anchor = track["presentationAnchorTicks"];
846
+ if (anchor !== void 0 && !Number.isSafeInteger(anchor)) {
847
+ catalogError("track_presentation_anchor", `${path}.presentationAnchorTicks`, "must be a safe integer");
848
+ }
849
+ const initRef = track["initRef"];
850
+ if (initRef !== void 0 && (typeof initRef !== "string" || initRef.length === 0)) {
851
+ catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
852
+ }
772
853
  if (packaging === "fec-repair") {
773
854
  rejectRepairTrackGeometry(path, track, catalogError);
774
855
  validateRepairTrackFields(describeRepairTrack(name, path, track), catalogError);
@@ -776,9 +857,8 @@ function validateCmsfMmtpCatalog(value) {
776
857
  rejectRepairFieldsOnMediaTrack(path, track, catalogError);
777
858
  }
778
859
  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");
860
+ if (track["mmtpMode"] !== "mfu") {
861
+ catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
782
862
  }
783
863
  if (!positiveInteger2(timescale)) {
784
864
  catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
@@ -831,6 +911,9 @@ function validateCmsfMmtpCatalog(value) {
831
911
  }
832
912
  }
833
913
  readFecBlockProfile(config["blockProfile"], `${path}.fec.blockProfile`, algorithm !== "none", catalogError);
914
+ if (algorithm !== "none" && config["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE) {
915
+ catalogError("track_fec", `${path}.fec.symbolSize`, "iso-ssbg1-v1 symbolSize must be at least 14");
916
+ }
834
917
  }
835
918
  }
836
919
  const repairDescriptors = trackRecords.flatMap(
@@ -942,15 +1025,8 @@ function validateCmsfMmtpCatalog(value) {
942
1025
  }
943
1026
  }
944
1027
  }
945
- try {
946
- resolveMulticastAuthCatalog(catalog);
947
- } catch (error) {
948
- catalogError(
949
- "multicast_auth",
950
- "$.multicast.auth",
951
- error instanceof Error ? error.message : "invalid multicast.auth v2 block"
952
- );
953
- }
1028
+ const [multicastIssue] = multicastCatalogIssues(catalog, options);
1029
+ if (multicastIssue) catalogError(multicastIssue.code, multicastIssue.path, multicastIssue.message);
954
1030
  validateArchive(catalog);
955
1031
  return catalog;
956
1032
  }
@@ -976,7 +1052,7 @@ function resolveGroupDurationTicks(timing, timescale) {
976
1052
  const product = timing.groupDurationMs * timescale;
977
1053
  if (product % 1e3 !== 0) {
978
1054
  throw new Error(
979
- `[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)`
1055
+ `[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)`
980
1056
  );
981
1057
  }
982
1058
  return product / 1e3;