@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
@@ -1,49 +1,37 @@
1
1
  /**
2
- * `multicast.auth` v2 — catalog representation for per-track source-auth
3
- * scopes and manifest tracks (BLO-16700 decision).
2
+ * `multicast.auth` and an endpoint's `auth`: bc-provenance version 2, per
3
+ * draft-ramadan-moq-multicast-01 7.2.6 at
4
+ * Blockcast/moqcast-draft@fd962fd73d21ed281b60219c11ea61cc9e4e91c4.
4
5
  *
5
- * Reconciles two previously-accepted, mutually incompatible contracts:
6
- * - BLO-16481 (S0): every publisher session/track/source-symbol-format
7
- * needs its own fresh, unpredictable 32-byte `auth_scope`, bound into
8
- * the signed per-group Merkle root (see `sourceAuthSignaturePreimage`
9
- * in ./source-auth.ts).
10
- * - BLO-16485 (S3 draft): a singular `multicast.auth` block with one
11
- * `manifestTrack` string and no `authScope` field at all — unable to
12
- * describe two protected tracks (e.g. audio + video) in one session.
6
+ * The block lives in the `multicast` object, never the root: the root dotted
7
+ * key `"multicast.auth"` was draft -00's (libmmt called its `tracks[]` shape
8
+ * "multicast.auth v2 (BLO-16700)", which is the draft's bc-provenance
9
+ * version 1) and is refused. `multicast.auth` declares the profile and its
10
+ * keys; an endpoint's `auth` marks that endpoint's flow protected and carries
11
+ * the flow's parameters. There is no verify-and-report mode (7.2.7): a
12
+ * receiver that implements the profile enforces it.
13
13
  *
14
- * `multicast.auth` v2 keeps one shared signing identity (scheme, hash,
15
- * sig, publicKey, keyId, previousKey, compaction, enforcement) but moves
16
- * `manifestTrack` into a `tracks[]` array, one entry per protected media
17
- * track, each carrying its own `manifestTrack` name, `authScope`, and
18
- * `sourceSymbolFormat`. This is additive over the S3 draft shape (every
19
- * top-level field the draft specified still exists at the top level) —
20
- * only `manifestTrack` moves from top-level into each track entry.
21
- *
22
- * `manifestTrack` is carried as an opaque string field, deliberately NOT
23
- * run through `parseTrackRole`/`VALID_ROLE_SUFFIXES` in ./carp-catalog.ts.
24
- * `carp-catalog.ts` only recognises `base`/`delta`/`repair` role suffixes
25
- * and throws on anything else (including a hypothetical `manifest` role);
26
- * resolving BLO-16485's "manifest-track name collision" MANDATORY item by
27
- * adding a role would force every catalog consumer to learn a fourth role
28
- * and would break `validateSwitchingSet`'s base/delta/repair completeness
29
- * check. Carrying it as a typed field here avoids both.
14
+ * The rules are `multicastCatalogIssues` in `@blockcast/mmt-base`, shared with
15
+ * the transport receivers; this module decodes what they admit.
30
16
  */
31
17
 
18
+ import { multicastCatalogIssues } from "@blockcast/mmt-base";
19
+ import type { BcpV2Key } from "@blockcast/mmt-manifest-verify";
20
+
32
21
  export type MulticastAuthScheme = "bc-provenance";
33
- export type MulticastAuthHash = "blake3";
34
22
  export type MulticastAuthSig = "ed25519";
35
- export type MulticastAuthCompaction = "merkle" | "none";
36
- export type MulticastAuthEnforcement = "shadow" | "enforce";
37
- export type MulticastAuthMode = "off" | MulticastAuthEnforcement;
38
23
 
39
24
  const RAW_ED25519_KEY_LENGTH = 32;
40
- const SOURCE_AUTH_SCOPE_LENGTH = 32;
25
+
26
+ /** Default `maxAuthDelayMs` and `manifestTimerMs` of an endpoint's `auth`. */
27
+ export const DEFAULT_MAX_AUTH_DELAY_MS = 200;
28
+ export const DEFAULT_MANIFEST_TIMER_MS = 20;
41
29
 
42
30
  const BASE64URL_ALPHABET =
43
31
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
44
32
 
45
33
  /** Encode raw bytes as unpadded base64url — the one accepted encoding for
46
- * `authScope`/`publicKey`/`previousKey` (BLO-16483's operator quickstart). */
34
+ * `multicast.auth.keys[].publicKey`. */
47
35
  export function encodeBase64Url(bytes: Uint8Array): string {
48
36
  let output = "";
49
37
  for (let i = 0; i < bytes.length; i += 3) {
@@ -97,18 +85,6 @@ export function decodeBase64Url(text: string): Uint8Array {
97
85
  return decoded;
98
86
  }
99
87
 
100
- /** Decode + length-validate an `authScope` field. Throws unless it decodes
101
- * to exactly `SOURCE_AUTH_SCOPE_LENGTH` (32) raw bytes. */
102
- export function decodeAuthScope(authScope: string): Uint8Array {
103
- const bytes = decodeBase64Url(authScope);
104
- if (bytes.byteLength !== SOURCE_AUTH_SCOPE_LENGTH) {
105
- throw new Error(
106
- `[multicast-auth-catalog] authScope must decode to ${SOURCE_AUTH_SCOPE_LENGTH} raw bytes, got ${bytes.byteLength}`,
107
- );
108
- }
109
- return bytes;
110
- }
111
-
112
88
  /** Decode a catalog key in the only accepted representation: exactly 32 raw
113
89
  * ed25519 bytes encoded as canonical, unpadded base64url. */
114
90
  export function decodeEd25519PublicKey(publicKey: string): Uint8Array {
@@ -121,220 +97,140 @@ export function decodeEd25519PublicKey(publicKey: string): Uint8Array {
121
97
  return bytes;
122
98
  }
123
99
 
124
- /**
125
- * One protected media track's manifest + scope binding.
126
- *
127
- * - `mediaTrack`: the actual media track name (e.g. `"video/base"`).
128
- * - `manifestTrack`: the sibling track carrying this track's signed
129
- * manifest objects (see ./source-auth.ts `SourceAuthObjectEntry`/
130
- * `SourceAuthGroupClose`). Opaque string — not role-parsed.
131
- * - `authScope`: this track's unique 32-byte scope, raw bytes as unpadded
132
- * base64url. BLO-16481 requires a scope fresh per (publisher session,
133
- * track, source-symbol format) — a track publishing under two source-
134
- * symbol formats in the same session MUST appear as two entries here,
135
- * each with its own scope.
136
- * - `sourceSymbolFormat`: names the deployed source-symbol profile this
137
- * track's authenticated bytes are derived from (e.g.
138
- * `"full-mmtp-packet"` or `"fec-padded-recovery"`, the two formats
139
- * BLO-16481's S0 fixture covers).
140
- */
141
- export interface MulticastAuthTrackConfig {
142
- mediaTrack: string;
143
- manifestTrack: string;
144
- authScope: string;
145
- sourceSymbolFormat: string;
100
+ /** One `multicast.auth.keys[]` entry: `kid` and `firstEpoch` are u32,
101
+ * `publicKey` the 32-octet Ed25519 key in canonical unpadded base64url. */
102
+ export interface MulticastAuthKey {
103
+ kid: number;
104
+ publicKey: string;
105
+ firstEpoch: number;
146
106
  }
147
107
 
148
- /**
149
- * `multicast.auth` v2 — supersedes the BLO-16485 draft's singular
150
- * `manifestTrack`/no-`authScope` shape (BLO-16700 decision).
151
- */
108
+ /** `multicast.auth` (7.2.6). `hash_alg` is a record octet, not a member. */
152
109
  export interface MulticastAuthConfig {
153
110
  scheme: MulticastAuthScheme;
154
- hash: MulticastAuthHash;
111
+ version: 2;
155
112
  sig: MulticastAuthSig;
156
- /** Raw 32-byte ed25519 public key, unpadded base64url. */
157
- publicKey: string;
158
- keyId: string;
159
- /** Raw 32-byte ed25519 public key, unpadded base64url. Accepted
160
- * alongside `publicKey` during a key-rotation overlap window. */
161
- previousKey?: string;
162
- compaction: MulticastAuthCompaction;
163
- /** Player-config-wins default; catalog value only selects the default
164
- * when the player hasn't pinned one (S3 enforcement precedence). */
165
- enforcement?: MulticastAuthEnforcement;
166
- tracks: MulticastAuthTrackConfig[];
167
- }
168
-
169
- function isNonEmptyString(value: unknown): value is string {
170
- return typeof value === "string" && value.length > 0;
171
- }
172
-
173
- function isValidAuthScopeField(value: unknown): value is string {
174
- if (!isNonEmptyString(value)) return false;
175
- try {
176
- decodeAuthScope(value);
177
- return true;
178
- } catch {
179
- return false;
180
- }
181
- }
182
-
183
- function isValidPublicKeyField(value: unknown): value is string {
184
- if (!isNonEmptyString(value)) return false;
185
- try {
186
- decodeEd25519PublicKey(value);
187
- return true;
188
- } catch {
189
- return false;
190
- }
191
- }
192
-
193
- function hasOnlyKeys(object: Record<string, unknown>, allowed: readonly string[]): boolean {
194
- const allowedKeys = new Set(allowed);
195
- return Object.keys(object).every((key) => allowedKeys.has(key));
196
- }
197
-
198
- export function isMulticastAuthTrackConfig(obj: unknown): obj is MulticastAuthTrackConfig {
199
- if (typeof obj !== "object" || obj === null) return false;
200
- const o = obj as Record<string, unknown>;
201
- return (
202
- hasOnlyKeys(o, ["mediaTrack", "manifestTrack", "authScope", "sourceSymbolFormat"]) &&
203
- isNonEmptyString(o["mediaTrack"]) &&
204
- isNonEmptyString(o["manifestTrack"]) &&
205
- o["mediaTrack"] !== o["manifestTrack"] &&
206
- isValidAuthScopeField(o["authScope"]) &&
207
- isNonEmptyString(o["sourceSymbolFormat"])
208
- );
209
- }
210
-
211
- const VALID_COMPACTION = new Set<string>(["merkle", "none"]);
212
- const VALID_ENFORCEMENT = new Set<string>(["shadow", "enforce"]);
213
-
214
- /** Semantic uniqueness rule shared by runtime parsing and the published
215
- * catalog schema's `uniqueMulticastAuthTrackBindings` keyword. */
216
- export function hasUniqueMulticastAuthTrackBindings(tracks: readonly unknown[]): boolean {
217
- const bindings = tracks.flatMap((track) => {
218
- if (typeof track !== "object" || track === null) return [];
219
- const value = track as Record<string, unknown>;
220
- if (typeof value["mediaTrack"] !== "string" || typeof value["sourceSymbolFormat"] !== "string") {
221
- return [];
222
- }
223
- return [JSON.stringify([value["mediaTrack"], value["sourceSymbolFormat"]])];
224
- });
225
- return new Set(bindings).size === bindings.length;
226
- }
227
-
113
+ /** One to four keys; `kid` and `firstEpoch` each distinct. */
114
+ keys: MulticastAuthKey[];
115
+ /** Lowest `epoch` a receiver accepts at join. */
116
+ minEpoch: number;
117
+ }
118
+
119
+ /** An endpoint's `auth` (7.2.6). A protected endpoint also declares `bandwidth`. */
120
+ export interface EndpointAuthConfig {
121
+ /** Destination port of the record datagrams on the endpoint's `(S, G)`. */
122
+ manifestPort: number;
123
+ /** u32 chosen per channel generation. */
124
+ streamId: number;
125
+ /** `S` of a protected ASM endpoint; never on SSM. */
126
+ senderAddress?: string;
127
+ /** 50..1000, default 200. */
128
+ maxAuthDelayMs?: number;
129
+ /** At least 1, default 20. */
130
+ manifestTimerMs?: number;
131
+ /** MoQ track mirroring the records. */
132
+ manifestTrack?: string;
133
+ }
134
+
135
+ /** Structural check of a `multicast.auth` block, duplicate `kid` and
136
+ * `firstEpoch` included. */
228
137
  export function isMulticastAuthConfig(obj: unknown): obj is MulticastAuthConfig {
229
- if (typeof obj !== "object" || obj === null) return false;
230
- const o = obj as Record<string, unknown>;
231
-
232
- if (o["scheme"] !== "bc-provenance") return false;
233
- if (o["hash"] !== "blake3") return false;
234
- if (o["sig"] !== "ed25519") return false;
235
- if (!hasOnlyKeys(o, ["scheme", "hash", "sig", "publicKey", "keyId", "previousKey", "compaction", "enforcement", "tracks"])) return false;
236
- if (!isValidPublicKeyField(o["publicKey"])) return false;
237
- if (!isNonEmptyString(o["keyId"])) return false;
238
- if (o["previousKey"] !== undefined && !isValidPublicKeyField(o["previousKey"])) return false;
239
- if (o["previousKey"] === o["publicKey"]) return false;
240
- if (typeof o["compaction"] !== "string" || !VALID_COMPACTION.has(o["compaction"])) return false;
241
- if (o["enforcement"] !== undefined) {
242
- if (typeof o["enforcement"] !== "string" || !VALID_ENFORCEMENT.has(o["enforcement"])) return false;
243
- }
244
-
245
- if (!Array.isArray(o["tracks"]) || o["tracks"].length === 0) return false;
246
- const tracks = o["tracks"] as unknown[];
247
- if (!tracks.every((t) => isMulticastAuthTrackConfig(t))) return false;
248
- const typedTracks = tracks as MulticastAuthTrackConfig[];
249
-
250
- // BLO-16481: a fresh scope per track — catalog-declared scopes must be
251
- // pairwise distinct within one auth block.
252
- const scopes = typedTracks.map((t) => t.authScope);
253
- if (new Set(scopes).size !== scopes.length) return false;
254
- if (!hasUniqueMulticastAuthTrackBindings(typedTracks)) return false;
255
-
256
- // Each entry must point at its own manifest track.
257
- const manifestTracks = typedTracks.map((t) => t.manifestTrack);
258
- if (new Set(manifestTracks).size !== manifestTracks.length) return false;
259
-
260
- return true;
138
+ return multicastCatalogIssues({ multicast: { auth: obj } }).length === 0;
139
+ }
140
+
141
+ /** A protected flow as a receiver binds it: one per protected endpoint. */
142
+ export interface ResolvedMulticastAuthFlow {
143
+ /** Index of the endpoint in `multicast.endpoints`. */
144
+ endpointIndex: number;
145
+ /** `S`: `sourceAddress` on SSM, `auth.senderAddress` on ASM. */
146
+ source: string;
147
+ groupAddress: string;
148
+ port: number;
149
+ bandwidth: number;
150
+ manifestPort: number;
151
+ streamId: number;
152
+ maxAuthDelayMs: number;
153
+ manifestTimerMs: number;
154
+ manifestTrack?: string;
155
+ tracks: Array<{ name: string; packetId: number }>;
261
156
  }
262
157
 
263
158
  export interface ResolvedMulticastAuthConfig {
264
- keyId: string;
265
- /** Current key first, followed by the overlap key when advertised. */
266
- acceptedPublicKeys: Uint8Array[];
267
- mode: MulticastAuthMode;
268
- compaction: MulticastAuthCompaction;
269
- tracks: Array<Omit<MulticastAuthTrackConfig, "authScope"> & { authScope: Uint8Array }>;
270
- }
271
-
272
- /** Player configuration is authoritative, including an explicit `off`.
273
- * Catalog enforcement is only a default; an auth block without it defaults
274
- * to shadow, while a catalog without auth defaults to off. */
275
- export function resolveMulticastAuthMode(
276
- playerMode: MulticastAuthMode | undefined,
277
- auth: MulticastAuthConfig | undefined,
278
- ): MulticastAuthMode {
279
- if (playerMode !== undefined) return playerMode;
280
- if (auth === undefined) return "off";
281
- return auth.enforcement ?? "shadow";
159
+ /** Decoded keys, ascending by `firstEpoch`. */
160
+ keys: BcpV2Key[];
161
+ minEpoch: number;
162
+ flows: ResolvedMulticastAuthFlow[];
282
163
  }
283
164
 
284
- /** Parse and resolve the catalog auth block into verifier-ready raw keys and
285
- * scopes. Invalid blocks and dangling media/manifest track references fail
286
- * closed instead of silently falling back to unauthenticated playback. */
165
+ /**
166
+ * Resolve `multicast.auth` and every protected endpoint into decoded keys and
167
+ * per-endpoint flows. Returns `undefined` for an unprotected catalog unless
168
+ * `requireAuth` pins authentication (7.2.7), which then throws.
169
+ *
170
+ * A catalog-level fault (no key set: a malformed block, a repeated `kid` or
171
+ * `firstEpoch`, the retired root key) throws, so nothing is admitted and
172
+ * nothing falls back to unauthenticated reception. An endpoint the rules make
173
+ * a receiver ignore yields no flow; the others still bind.
174
+ */
287
175
  export function resolveMulticastAuthCatalog(
288
176
  catalog: unknown,
289
- playerMode?: MulticastAuthMode,
177
+ options: { requireAuth?: boolean; catalogNamespace?: string } = {},
290
178
  ): ResolvedMulticastAuthConfig | undefined {
291
179
  if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
292
180
  throw new Error("[multicast-auth-catalog] catalog must be an object");
293
181
  }
294
- const root = catalog as Record<string, unknown>;
295
- const rawAuth = root["multicast.auth"];
296
- if (rawAuth === undefined) {
297
- if (playerMode === "enforce") {
298
- throw new Error("[multicast-auth-catalog] player enforce mode requires multicast.auth");
182
+ const issues = multicastCatalogIssues(catalog, options);
183
+ const fatal = issues.find((issue) => issue.endpointIndex === undefined);
184
+ if (fatal) throw new Error(`[multicast-auth-catalog] ${fatal.path}: ${fatal.message}`);
185
+ const multicast = (catalog as Record<string, unknown>)["multicast"] as Record<string, unknown> | undefined;
186
+ const auth = multicast?.["auth"] as MulticastAuthConfig | undefined;
187
+ if (auth === undefined) {
188
+ if (options.requireAuth) {
189
+ throw new Error("[multicast-auth-catalog] authentication is pinned but the catalog declares no multicast.auth");
299
190
  }
300
191
  return undefined;
301
192
  }
302
- if (!isMulticastAuthConfig(rawAuth)) {
303
- throw new Error("[multicast-auth-catalog] invalid multicast.auth v2 block");
304
- }
305
-
306
- const rawTracks = root["tracks"];
307
- if (!Array.isArray(rawTracks)) {
308
- throw new Error("[multicast-auth-catalog] catalog tracks must be an array");
309
- }
310
- const catalogTrackNames = new Set(
311
- rawTracks.flatMap((track) =>
312
- typeof track === "object" && track !== null &&
313
- typeof (track as Record<string, unknown>)["name"] === "string"
314
- ? [(track as Record<string, unknown>)["name"] as string]
315
- : []
316
- ),
317
- );
318
- for (const track of rawAuth.tracks) {
319
- if (!catalogTrackNames.has(track.mediaTrack)) {
320
- throw new Error(`[multicast-auth-catalog] unknown mediaTrack "${track.mediaTrack}"`);
321
- }
322
- if (!catalogTrackNames.has(track.manifestTrack)) {
323
- throw new Error(`[multicast-auth-catalog] unknown manifestTrack "${track.manifestTrack}"`);
324
- }
325
- }
326
-
193
+ const ignored = new Set(issues.map((issue) => issue.endpointIndex));
194
+ const endpoints = (multicast!["endpoints"] ?? []) as Array<Record<string, unknown>>;
195
+ const flows: ResolvedMulticastAuthFlow[] = [];
196
+ endpoints.forEach((endpoint, endpointIndex) => {
197
+ if (ignored.has(endpointIndex)) return;
198
+ const flowAuth = endpoint["auth"] as EndpointAuthConfig;
199
+ flows.push({
200
+ endpointIndex,
201
+ source: (endpoint["sourceAddress"] ?? flowAuth.senderAddress) as string,
202
+ groupAddress: endpoint["groupAddress"] as string,
203
+ port: endpoint["port"] as number,
204
+ bandwidth: endpoint["bandwidth"] as number,
205
+ manifestPort: flowAuth.manifestPort,
206
+ streamId: flowAuth.streamId,
207
+ maxAuthDelayMs: flowAuth.maxAuthDelayMs ?? DEFAULT_MAX_AUTH_DELAY_MS,
208
+ manifestTimerMs: flowAuth.manifestTimerMs ?? DEFAULT_MANIFEST_TIMER_MS,
209
+ ...(flowAuth.manifestTrack === undefined ? {} : { manifestTrack: flowAuth.manifestTrack }),
210
+ tracks: ((endpoint["tracks"] ?? []) as Array<{ name: string; packetId: number }>).map(({ name, packetId }) => ({
211
+ name,
212
+ packetId,
213
+ })),
214
+ });
215
+ });
327
216
  return {
328
- keyId: rawAuth.keyId,
329
- acceptedPublicKeys: [
330
- decodeEd25519PublicKey(rawAuth.publicKey),
331
- ...(rawAuth.previousKey === undefined ? [] : [decodeEd25519PublicKey(rawAuth.previousKey)]),
332
- ],
333
- mode: resolveMulticastAuthMode(playerMode, rawAuth),
334
- compaction: rawAuth.compaction,
335
- tracks: rawAuth.tracks.map((track) => ({
336
- ...track,
337
- authScope: decodeAuthScope(track.authScope),
338
- })),
217
+ keys: auth.keys
218
+ .map((key) => ({ kid: key.kid, publicKey: decodeEd25519PublicKey(key.publicKey), firstEpoch: key.firstEpoch }))
219
+ .sort((a, b) => a.firstEpoch - b.firstEpoch),
220
+ minEpoch: auth.minEpoch,
221
+ flows,
339
222
  };
340
223
  }
224
+
225
+ /** The key that signs a record of `kid` at `epoch`, or `undefined` when that
226
+ * `kid` does not sign it (7.2.7: such a record is dropped before verification). */
227
+ export function multicastAuthKeyFor(
228
+ resolved: ResolvedMulticastAuthConfig,
229
+ kid: number,
230
+ epoch: number,
231
+ ): Uint8Array | undefined {
232
+ // `keys` is ascending by firstEpoch with unique kid and firstEpoch (resolve throws otherwise).
233
+ const signers = resolved.keys.filter((key) => key.firstEpoch <= epoch);
234
+ const signer = signers[signers.length - 1];
235
+ return signer?.kid === kid ? signer.publicKey : undefined;
236
+ }