@blockcast/mmt-fec 0.3.0 → 0.4.0

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 (74) hide show
  1. package/README.md +4 -4
  2. package/dist/block-processor.d.ts +19 -20
  3. package/dist/block-processor.d.ts.map +1 -1
  4. package/dist/block-processor.js +27 -93
  5. package/dist/block-processor.js.map +1 -1
  6. package/dist/fec-block-mapper.d.ts +16 -72
  7. package/dist/fec-block-mapper.d.ts.map +1 -1
  8. package/dist/fec-block-mapper.js +17 -96
  9. package/dist/fec-block-mapper.js.map +1 -1
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +3 -3
  13. package/dist/index.js.map +1 -1
  14. package/dist/oti.d.ts +17 -8
  15. package/dist/oti.d.ts.map +1 -1
  16. package/dist/oti.js +9 -1
  17. package/dist/oti.js.map +1 -1
  18. package/dist/repair-group.d.ts +86 -0
  19. package/dist/repair-group.d.ts.map +1 -1
  20. package/dist/repair-group.js +135 -0
  21. package/dist/repair-group.js.map +1 -1
  22. package/package.json +5 -6
  23. package/src/block-processor.ts +31 -110
  24. package/src/fec-block-mapper.ts +23 -108
  25. package/src/index.ts +6 -1
  26. package/src/oti.ts +20 -9
  27. package/src/repair-group.ts +176 -0
  28. package/test-vectors/repair-epoch.json +119 -0
  29. package/node_modules/@blockcast/mmt-alta-parse/README.md +0 -181
  30. package/node_modules/@blockcast/mmt-alta-parse/dist/.build-stamp +0 -0
  31. package/node_modules/@blockcast/mmt-alta-parse/dist/index.d.ts +0 -57
  32. package/node_modules/@blockcast/mmt-alta-parse/dist/index.d.ts.map +0 -1
  33. package/node_modules/@blockcast/mmt-alta-parse/dist/index.js +0 -115
  34. package/node_modules/@blockcast/mmt-alta-parse/dist/index.js.map +0 -1
  35. package/node_modules/@blockcast/mmt-alta-parse/package.json +0 -50
  36. package/node_modules/@blockcast/mmt-alta-parse/src/index.ts +0 -136
  37. package/node_modules/@blockcast/mmt-base/README.md +0 -134
  38. package/node_modules/@blockcast/mmt-base/dist/.build-stamp +0 -0
  39. package/node_modules/@blockcast/mmt-base/dist/fec-block-profile.d.ts +0 -55
  40. package/node_modules/@blockcast/mmt-base/dist/fec-block-profile.d.ts.map +0 -1
  41. package/node_modules/@blockcast/mmt-base/dist/fec-block-profile.js +0 -128
  42. package/node_modules/@blockcast/mmt-base/dist/fec-block-profile.js.map +0 -1
  43. package/node_modules/@blockcast/mmt-base/dist/index.d.ts +0 -7
  44. package/node_modules/@blockcast/mmt-base/dist/index.d.ts.map +0 -1
  45. package/node_modules/@blockcast/mmt-base/dist/index.js +0 -7
  46. package/node_modules/@blockcast/mmt-base/dist/index.js.map +0 -1
  47. package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +0 -292
  48. package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +0 -1
  49. package/node_modules/@blockcast/mmt-base/dist/mmtp.js +0 -612
  50. package/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +0 -1
  51. package/node_modules/@blockcast/mmt-base/dist/net-constants.d.ts +0 -18
  52. package/node_modules/@blockcast/mmt-base/dist/net-constants.d.ts.map +0 -1
  53. package/node_modules/@blockcast/mmt-base/dist/net-constants.js +0 -18
  54. package/node_modules/@blockcast/mmt-base/dist/net-constants.js.map +0 -1
  55. package/node_modules/@blockcast/mmt-base/dist/ntp-short.d.ts +0 -47
  56. package/node_modules/@blockcast/mmt-base/dist/ntp-short.d.ts.map +0 -1
  57. package/node_modules/@blockcast/mmt-base/dist/ntp-short.js +0 -54
  58. package/node_modules/@blockcast/mmt-base/dist/ntp-short.js.map +0 -1
  59. package/node_modules/@blockcast/mmt-base/dist/serial-number.d.ts +0 -57
  60. package/node_modules/@blockcast/mmt-base/dist/serial-number.d.ts.map +0 -1
  61. package/node_modules/@blockcast/mmt-base/dist/serial-number.js +0 -98
  62. package/node_modules/@blockcast/mmt-base/dist/serial-number.js.map +0 -1
  63. package/node_modules/@blockcast/mmt-base/dist/signalling.d.ts +0 -312
  64. package/node_modules/@blockcast/mmt-base/dist/signalling.d.ts.map +0 -1
  65. package/node_modules/@blockcast/mmt-base/dist/signalling.js +0 -637
  66. package/node_modules/@blockcast/mmt-base/dist/signalling.js.map +0 -1
  67. package/node_modules/@blockcast/mmt-base/package.json +0 -49
  68. package/node_modules/@blockcast/mmt-base/src/fec-block-profile.ts +0 -145
  69. package/node_modules/@blockcast/mmt-base/src/index.ts +0 -6
  70. package/node_modules/@blockcast/mmt-base/src/mmtp.ts +0 -892
  71. package/node_modules/@blockcast/mmt-base/src/net-constants.ts +0 -17
  72. package/node_modules/@blockcast/mmt-base/src/ntp-short.ts +0 -67
  73. package/node_modules/@blockcast/mmt-base/src/serial-number.ts +0 -107
  74. package/node_modules/@blockcast/mmt-base/src/signalling.ts +0 -862
@@ -193,3 +193,179 @@ export function repairGroupIdMatches(groupId: bigint, ssStart: number, reference
193
193
  return false;
194
194
  }
195
195
  }
196
+
197
+ /**
198
+ * What a repair FETCH for one block names, or why none is sent: an
199
+ * `iso-ssbg1-v1` block's repair group is the one Group `ext(SS_Start)`
200
+ * (draft-ramadan-moq-fec §7.5).
201
+ *
202
+ * - `no-epoch`: no reference is established for the repair track on this
203
+ * session, so there is no range to request until one is (§7.5).
204
+ * - `epoch-unbounded`: SS_Start is exactly 2^31 from the reference, or
205
+ * extends outside [0, 2^62). The reference is dropped so the next one
206
+ * re-establishes it.
207
+ * - `stale-session`: the request names a session other than the bound one.
208
+ */
209
+ export type RepairGroupPlan =
210
+ | { readonly group: bigint }
211
+ | { readonly reason: "no-epoch" | "epoch-unbounded" | "stale-session" };
212
+
213
+ /** Outcome of reporting a repair track's Largest Location (§7.5 way 2). */
214
+ export type RepairLargestOutcome = "established" | "advanced" | "redundant" | "absent" | "stale-session";
215
+
216
+ /**
217
+ * Counted outcomes of {@link RepairEpochReferences}. A successful
218
+ * {@link RepairEpochReferences.repairGroup} and a same-session `bind` are not
219
+ * counted.
220
+ */
221
+ export interface RepairEpochStats {
222
+ establishedFromLargest: number;
223
+ advancedFromLargest: number;
224
+ largestAbsent: number;
225
+ largestRedundant: number;
226
+ establishedFromGroupId: number;
227
+ admitted: number;
228
+ discarded: number;
229
+ declinedNoEpoch: number;
230
+ epochUnbounded: number;
231
+ staleSession: number;
232
+ sessionResets: number;
233
+ streamResets: number;
234
+ }
235
+
236
+ /**
237
+ * The wrap-epoch reference `r` of each repair track, for one MoQ session
238
+ * (draft-ramadan-moq-fec §7.5). Shared by every native receiver adapter; the
239
+ * adapter owns its MoQ verbs and passes its session as an opaque object.
240
+ *
241
+ * - The adapter calls {@link bind} with the session it holds live, at the
242
+ * synchronous point it reads it. A different session drops every reference:
243
+ * the SS_IDs between a reconnection and the last reference cannot be bounded
244
+ * below 2^31. {@link clear} does the same for a stream or track reset.
245
+ * - Every other call names the session it acts for, and one naming a session
246
+ * other than the bound one changes nothing (`stale-session`). An async
247
+ * continuation that outlived its session therefore cannot install that
248
+ * session's reference, nor wipe the live session's.
249
+ * - `r` is established from a non-discarded repair object's Group ID (way 1,
250
+ * {@link admit}) or a Largest Location (way 2), and only ever advances to a
251
+ * newer Group, so it stays near the live edge for the life of the session.
252
+ * Epoch 0 (way 3) needs proof of observing the instance's first block, which
253
+ * nothing on the wire carries (SS_IDs start anywhere, C.5.2); it is not used.
254
+ */
255
+ export class RepairEpochReferences {
256
+ readonly stats: RepairEpochStats = {
257
+ establishedFromLargest: 0,
258
+ advancedFromLargest: 0,
259
+ largestAbsent: 0,
260
+ largestRedundant: 0,
261
+ establishedFromGroupId: 0,
262
+ admitted: 0,
263
+ discarded: 0,
264
+ declinedNoEpoch: 0,
265
+ epochUnbounded: 0,
266
+ staleSession: 0,
267
+ sessionResets: 0,
268
+ streamResets: 0,
269
+ };
270
+ #session: object | undefined;
271
+ readonly #references = new Map<string, bigint>();
272
+
273
+ /** Make `session` the live one; a different session drops every reference. */
274
+ bind(session: object): void {
275
+ if (this.#session === session) return;
276
+ if (this.#session !== undefined) {
277
+ this.#references.clear();
278
+ this.stats.sessionResets++;
279
+ }
280
+ this.#session = session;
281
+ }
282
+
283
+ /** Drop every reference: the stream or track was reset. */
284
+ clear(): void {
285
+ this.#references.clear();
286
+ this.stats.streamResets++;
287
+ }
288
+
289
+ /** `r` of `repairTrack` on `session`; undefined when none, or the session is not the bound one. */
290
+ reference(session: object, repairTrack: string): bigint | undefined {
291
+ return session === this.#session ? this.#references.get(repairTrack) : undefined;
292
+ }
293
+
294
+ #live(session: object): boolean {
295
+ if (session === this.#session) return true;
296
+ this.stats.staleSession++;
297
+ return false;
298
+ }
299
+
300
+ /**
301
+ * §7.5 way 2: the Largest Location reported for `repairTrack`, whose Group
302
+ * is ext(SS_Start) of the newest repair block. Undefined means an empty
303
+ * track and establishes nothing.
304
+ *
305
+ * @throws RangeError when the Group is not a 62-bit MoQ group id
306
+ */
307
+ establishFromLargestLocation(
308
+ session: object,
309
+ repairTrack: string,
310
+ largestGroup: bigint | undefined,
311
+ ): RepairLargestOutcome {
312
+ if (largestGroup !== undefined) assertGroupId(largestGroup, "Largest Location Group");
313
+ if (!this.#live(session)) return "stale-session";
314
+ if (largestGroup === undefined) {
315
+ this.stats.largestAbsent++;
316
+ return "absent";
317
+ }
318
+ const held = this.#references.get(repairTrack);
319
+ if (held !== undefined && largestGroup <= held) {
320
+ this.stats.largestRedundant++;
321
+ return "redundant";
322
+ }
323
+ this.#references.set(repairTrack, largestGroup);
324
+ if (held === undefined) {
325
+ this.stats.establishedFromLargest++;
326
+ return "established";
327
+ }
328
+ this.stats.advancedFromLargest++;
329
+ return "advanced";
330
+ }
331
+
332
+ /**
333
+ * Screen one repair object received over MoQ (§7.5): false means discard
334
+ * it, leaving every block's state unchanged. An admitted object's Group ID
335
+ * establishes `r` when none is held (way 1) and advances it when newer.
336
+ */
337
+ admit(session: object, repairTrack: string, groupId: bigint, ssStart: number): boolean {
338
+ if (!this.#live(session)) return false;
339
+ const held = this.#references.get(repairTrack);
340
+ if (!repairGroupIdMatches(groupId, ssStart, held)) {
341
+ this.stats.discarded++;
342
+ return false;
343
+ }
344
+ this.stats.admitted++;
345
+ if (held === undefined) this.stats.establishedFromGroupId++;
346
+ if (held === undefined || groupId > held) this.#references.set(repairTrack, groupId);
347
+ return true;
348
+ }
349
+
350
+ /**
351
+ * The repair group of the `iso-ssbg1-v1` block starting at `ssStart`, the
352
+ * scheduler's `RepairFetchRequest.sbn`: the one Group ext(SS_Start).
353
+ */
354
+ repairGroup(session: object, repairTrack: string, ssStart: number): RepairGroupPlan {
355
+ assertSsId(ssStart, "ssStart");
356
+ if (!this.#live(session)) return { reason: "stale-session" };
357
+ const reference = this.#references.get(repairTrack);
358
+ if (reference === undefined) {
359
+ this.stats.declinedNoEpoch++;
360
+ return { reason: "no-epoch" };
361
+ }
362
+ try {
363
+ return { group: extendSsId(reference, ssStart) };
364
+ } catch (error) {
365
+ if (!(error instanceof RangeError)) throw error;
366
+ this.#references.delete(repairTrack);
367
+ this.stats.epochUnbounded++;
368
+ return { reason: "epoch-unbounded" };
369
+ }
370
+ }
371
+ }
@@ -0,0 +1,119 @@
1
+ {
2
+ "$comment": [
3
+ "Canonical receiver vectors for iso-ssbg1-v1 repair epochs and repair",
4
+ "FETCH ranges (draft-ramadan-moq-fec §7.5, BLO-45476). libmmt runs them",
5
+ "against RepairEpochReferences and repairFetchRange; every native receiver",
6
+ "adapter (moqtail, hang) runs the same file against its own wiring.",
7
+ "Hand-authored from the draft, never regenerated from the implementation.",
8
+ "",
9
+ "Group ids are decimal strings (62-bit, beyond Number). Sessions are names;",
10
+ "a runner maps each name to one distinct object. W = 2^32.",
11
+ "epochCases ops: bind | clear | largest (group null = no Largest Location;",
12
+ "expect 'throws' = RangeError) | admit | repairGroup | reference (null = none)."
13
+ ],
14
+ "epochCases": [
15
+ {
16
+ "name": "no reference, then Largest Location extends forward across the wrap and backward",
17
+ "ops": [
18
+ { "op": "bind", "session": "A" },
19
+ { "op": "repairGroup", "session": "A", "track": "r", "ssStart": 16, "expect": { "reason": "no-epoch" } },
20
+ { "op": "largest", "session": "A", "track": "r", "group": "17179869168", "expect": "established" },
21
+ { "op": "repairGroup", "session": "A", "track": "r", "ssStart": 16, "expect": { "group": "17179869200" } },
22
+ { "op": "repairGroup", "session": "A", "track": "r", "ssStart": 4294967280, "expect": { "group": "17179869168" } },
23
+ { "op": "repairGroup", "session": "A", "track": "r", "ssStart": 4294967264, "expect": { "group": "17179869152" } }
24
+ ]
25
+ },
26
+ {
27
+ "name": "an SS_Start exactly 2^31 from r cannot be ordered and drops r",
28
+ "ops": [
29
+ { "op": "bind", "session": "A" },
30
+ { "op": "largest", "session": "A", "track": "r", "group": "17179869168", "expect": "established" },
31
+ { "op": "repairGroup", "session": "A", "track": "r", "ssStart": 2147483632, "expect": { "reason": "epoch-unbounded" } },
32
+ { "op": "reference", "session": "A", "track": "r", "expect": null },
33
+ { "op": "repairGroup", "session": "A", "track": "r", "ssStart": 16, "expect": { "reason": "no-epoch" } }
34
+ ]
35
+ },
36
+ {
37
+ "name": "an extension below group 0 is unbounded",
38
+ "ops": [
39
+ { "op": "bind", "session": "A" },
40
+ { "op": "largest", "session": "A", "track": "r", "group": "5", "expect": "established" },
41
+ { "op": "repairGroup", "session": "A", "track": "r", "ssStart": 4294967295, "expect": { "reason": "epoch-unbounded" } }
42
+ ]
43
+ },
44
+ {
45
+ "name": "admit: discard on SS_Start mismatch, establish, refuse a wrong epoch, advance, never regress",
46
+ "ops": [
47
+ { "op": "bind", "session": "A" },
48
+ { "op": "admit", "session": "A", "track": "r", "groupId": "21474836580", "ssStart": 101, "expect": false },
49
+ { "op": "reference", "session": "A", "track": "r", "expect": null },
50
+ { "op": "admit", "session": "A", "track": "r", "groupId": "21474836580", "ssStart": 100, "expect": true },
51
+ { "op": "reference", "session": "A", "track": "r", "expect": "21474836580" },
52
+ { "op": "admit", "session": "A", "track": "r", "groupId": "17179869284", "ssStart": 100, "expect": false },
53
+ { "op": "admit", "session": "A", "track": "r", "groupId": "21474836530", "ssStart": 50, "expect": true },
54
+ { "op": "reference", "session": "A", "track": "r", "expect": "21474836580" },
55
+ { "op": "admit", "session": "A", "track": "r", "groupId": "21474836680", "ssStart": 200, "expect": true },
56
+ { "op": "reference", "session": "A", "track": "r", "expect": "21474836680" },
57
+ { "op": "repairGroup", "session": "A", "track": "r", "ssStart": 150, "expect": { "group": "21474836630" } }
58
+ ]
59
+ },
60
+ {
61
+ "name": "Largest Location: absent, redundant, advanced, not a 62-bit group id",
62
+ "ops": [
63
+ { "op": "bind", "session": "A" },
64
+ { "op": "largest", "session": "A", "track": "r", "group": null, "expect": "absent" },
65
+ { "op": "largest", "session": "A", "track": "r", "group": "4294967396", "expect": "established" },
66
+ { "op": "largest", "session": "A", "track": "r", "group": "4294967306", "expect": "redundant" },
67
+ { "op": "largest", "session": "A", "track": "r", "group": "4294967396", "expect": "redundant" },
68
+ { "op": "largest", "session": "A", "track": "r", "group": "4294967496", "expect": "advanced" },
69
+ { "op": "reference", "session": "A", "track": "r", "expect": "4294967496" },
70
+ { "op": "largest", "session": "A", "track": "r", "group": "4611686018427387904", "expect": "throws" },
71
+ { "op": "reference", "session": "A", "track": "r", "expect": "4294967496" }
72
+ ]
73
+ },
74
+ {
75
+ "name": "stale generation: a new session drops r, and the old session can neither install nor wipe",
76
+ "ops": [
77
+ { "op": "bind", "session": "A" },
78
+ { "op": "largest", "session": "A", "track": "r", "group": "4294967396", "expect": "established" },
79
+ { "op": "bind", "session": "B" },
80
+ { "op": "reference", "session": "B", "track": "r", "expect": null },
81
+ { "op": "largest", "session": "A", "track": "r", "group": "4294967396", "expect": "stale-session" },
82
+ { "op": "admit", "session": "A", "track": "r", "groupId": "4294967396", "ssStart": 100, "expect": false },
83
+ { "op": "repairGroup", "session": "A", "track": "r", "ssStart": 100, "expect": { "reason": "stale-session" } },
84
+ { "op": "repairGroup", "session": "B", "track": "r", "ssStart": 100, "expect": { "reason": "no-epoch" } },
85
+ { "op": "largest", "session": "B", "track": "r", "group": "8589934692", "expect": "established" },
86
+ { "op": "largest", "session": "A", "track": "r", "group": "4294967396", "expect": "stale-session" },
87
+ { "op": "repairGroup", "session": "B", "track": "r", "ssStart": 100, "expect": { "group": "8589934692" } }
88
+ ]
89
+ },
90
+ {
91
+ "name": "nothing bound yet is stale; rebinding the same session keeps r",
92
+ "ops": [
93
+ { "op": "largest", "session": "A", "track": "r", "group": "100", "expect": "stale-session" },
94
+ { "op": "bind", "session": "A" },
95
+ { "op": "largest", "session": "A", "track": "r", "group": "100", "expect": "established" },
96
+ { "op": "bind", "session": "A" },
97
+ { "op": "reference", "session": "A", "track": "r", "expect": "100" }
98
+ ]
99
+ },
100
+ {
101
+ "name": "a stream reset drops every track's r; tracks are independent",
102
+ "ops": [
103
+ { "op": "bind", "session": "A" },
104
+ { "op": "largest", "session": "A", "track": "video/repair", "group": "100", "expect": "established" },
105
+ { "op": "repairGroup", "session": "A", "track": "audio/repair", "ssStart": 100, "expect": { "reason": "no-epoch" } },
106
+ { "op": "clear" },
107
+ { "op": "repairGroup", "session": "A", "track": "video/repair", "ssStart": 100, "expect": { "reason": "no-epoch" } }
108
+ ]
109
+ }
110
+ ],
111
+ "rangeCases": [
112
+ { "name": "from r, across the wrap", "lostSsId": 16, "kMax": 8, "anchor": { "reference": "17179869168" }, "expect": { "startGroup": "17179869193", "endGroup": "17179869200" } },
113
+ { "name": "floored above the previous block", "lostSsId": 16, "kMax": 8, "anchor": { "previousBlockStart": "17179869194" }, "expect": { "startGroup": "17179869195", "endGroup": "17179869200" } },
114
+ { "name": "K = 1 names one group", "lostSsId": 16, "kMax": 1, "anchor": { "reference": "17179869168" }, "expect": { "startGroup": "17179869200", "endGroup": "17179869200" } },
115
+ { "name": "floored at group 0", "lostSsId": 2, "kMax": 8, "anchor": { "reference": "5" }, "expect": { "startGroup": "0", "endGroup": "2" } },
116
+ { "name": "lost SS_ID at the previous block's start", "lostSsId": 10, "kMax": 8, "anchor": { "previousBlockStart": "17179869194" }, "expect": "throws" },
117
+ { "name": "K = 0", "lostSsId": 16, "kMax": 0, "anchor": { "reference": "17179869168" }, "expect": "throws" }
118
+ ]
119
+ }
@@ -1,181 +0,0 @@
1
- # @blockcast/mmt-alta-parse
2
-
3
- Zero-dependency leaf package that extracts the detached **ALTA authenticator trailer** from an MMTP source packet. ALTA (Authenticated Lightweight TESLA-like Algorithm) is Blockcast's sender-authentication scheme for multicast streams: each MMTP source packet carries a detached signature trailer that downstream consumers (the FEC worker, the FFI core) verify against a catalog-published public key. This package is **the parser only** — it locates the trailer, returns the raw authenticator bytes, and tells the caller where the signed payload ends. Signature verification (Ed25519 / P-256) lives in the consumer that has crypto and the public key in hand.
4
-
5
- It is split into a leaf package with zero `@blockcast/*` dependencies so both `@blockcast/mmt-container` (wire-path parsing) and `@blockcast/fec-worker` (FEC-recovered-source parsing) can share one implementation without creating a package cycle.
6
-
7
- ## Install
8
-
9
- ```bash
10
- pnpm add @blockcast/mmt-alta-parse
11
- ```
12
-
13
- ## Quick start
14
-
15
- ```ts
16
- import { extractAltaTrailer } from "@blockcast/mmt-alta-parse"
17
-
18
- // `wirePacket` is a full MMTP packet as it came off the network (Uint8Array).
19
- const trailer = extractAltaTrailer(wirePacket)
20
-
21
- if (trailer === null) {
22
- // Packet has no ALTA trailer. This is normal for:
23
- // - non-MPU packets (repair, signaling)
24
- // - unsigned streams
25
- // - malformed / truncated packets
26
- return
27
- }
28
-
29
- // `trailer.auth` — the authenticator bytes (no ext_type/ext_length prefix)
30
- // `trailer.signedEnd` — byte offset where the signed payload ends inside wirePacket.
31
- // The signer signed wirePacket.subarray(0, signedEnd).
32
-
33
- const signedPayload = wirePacket.subarray(0, trailer.signedEnd)
34
- // Hand off to a verifier with the catalog-published public key:
35
- // ed25519.verify_detached(trailer.auth, signedPayload, publicKey)
36
- ```
37
-
38
- For FEC-recovered source symbols (where the upstream FEC pipeline has already stripped the 4-byte Source FEC Payload ID), pass `{ skipFecId: true }`:
39
-
40
- ```ts
41
- const trailer = extractAltaTrailer(recoveredSymbol, { skipFecId: true })
42
- ```
43
-
44
- ## Exports
45
-
46
- Per `package.json` (single entry point, ESM only):
47
-
48
- | Export | Kind | Purpose |
49
- |--------|------|---------|
50
- | `extractAltaTrailer(packet, options?)` | function | Parse a wire MMTP packet and return its `AltaTrailer` or `null`. |
51
- | `AltaTrailer` | type | `{ auth: Uint8Array; signedEnd: number }` |
52
- | `MMTP_EXT_TYPE_ALTA_AUTH` | const `0xf0a1` | The MMTP header-extension `ext_type` assigned to the detached ALTA trailer. |
53
- | `MMTP_EXT_TRAILER_HEADER_SIZE` | const `4` | Fixed size of the trailer's `[ext_type][ext_length]` prefix (2 + 2 bytes BE). |
54
-
55
- The package has no runtime dependencies — `package.json` lists `"dependencies": {}`.
56
-
57
- ## ALTA wire format
58
-
59
- The detached ALTA authenticator is appended **after** the declared MPU payload bytes and **before** the optional 4-byte Source FEC Payload ID. ISO/IEC 23008-1 defines `payload_length` as a length-after-field value: it includes the six MPU-header bytes following the field, the MFU data-unit header when present, and the media bytes. The MMTP header-extension `X` bit stays `0` — non-ALTA receivers treat the trailing bytes as data past `payload_length` and discard them per ISO/IEC 23008-1 §9.2.2 ("may be discarded without impacting correct processing").
60
-
61
- Wire layout for a signed source packet:
62
-
63
- ```
64
- | MMTP hdr | length (2) | remaining MPU hdr (6) | MFU hdr? | MFU data | TRAILER | SS_ID? (4) |
65
- \_______________________________________________________/
66
- payload_length bytes start after the field
67
- ^
68
- |
69
- signedEnd
70
- ```
71
-
72
- In MPU-payload coordinates, `signedEnd` is exactly `2 + payload_length`; the returned packet-relative offset also includes the complete, possibly extended MMTP header.
73
-
74
- The trailer itself is:
75
-
76
- ```
77
- | ext_type (2 BE) | ext_length (2 BE) | auth (ext_length bytes) |
78
- 0xf0a1
79
- ```
80
-
81
- - `ext_type = 0xf0a1` identifies the trailer as ALTA. Anything else is rejected (`null` return).
82
- - `ext_length` is the authenticator length in bytes — 64 for Ed25519, 64 for P-256 raw `(r,s)`, or whatever the signer minted.
83
- - The signed range is everything from byte 0 through `signedEnd-1` of the wire packet — i.e. the MMTP header, MPU header, MFU header, and MFU payload, but **not** the trailer itself or the optional FEC payload ID.
84
-
85
- This is the **detached trailer** form (a.k.a. "Path 2 / 08-07") from `draft-ramadan-moq-mmt` §12. It coexists with FEC: the signer signs the source-packet bytes **before** they enter the FEC encoder, so a receiver that recovers a missing source symbol from repair gets the same signed bytes the sender minted. This is the "sign-before-encode" rule — see the parent monorepo Phase 8 spec.
86
-
87
- ### When `extractAltaTrailer` returns `null`
88
-
89
- The function returns `null` (rather than throwing) for every non-trailer outcome — see `src/index.ts:69-115`:
90
-
91
- | Condition | Why |
92
- |-----------|-----|
93
- | Packet shorter than `MMTP_HEADER_SIZE + MPU_HEADER_SIZE` (20 B) | Truncated/malformed |
94
- | Packet type ≠ MPU (`0x00`) | Repair and signaling packets aren't signed per-packet |
95
- | Fragment type ≠ 2 (MFU) | Only timed or non-timed MFU media packets carry trailers |
96
- | `payload_length` cannot contain the MPU-header remainder, structurally required DU header, and media | The declaration ends inside headers or describes a header-only MFU |
97
- | `2 + payload_length` exceeds the pre-FEC packet boundary | Truncated/malformed declaration |
98
- | No bytes between MFU data and SS_ID for the 4-byte trailer header | Unsigned stream |
99
- | `ext_type` ≠ `0xf0a1` | Some other header-extension lives in that slot |
100
- | Declared `ext_length` does not end exactly at the SS_ID boundary | Malformed or ambiguous trailer suffix |
101
-
102
- Callers should treat `null` as "no signature on this packet" and route based on stream policy (require-signed vs allow-unsigned).
103
-
104
- ## Verification flow (where this package fits)
105
-
106
- ```
107
- catalog (CMSF)
108
- │
109
- alta.publicKey (SPKI bytes)
110
- │
111
- ▼
112
- ┌─────────────────────────────────────────────────────┐
113
- │ @blockcast/mmt-container :: mmtp-router │
114
- │ wirePacket → extractAltaTrailer(packet) ──────────┼──► this package
115
- │ ⇒ { auth, signedEnd } │
116
- │ │
117
- │ feedSourceSymbol(..., { auth, payloadEnd: signedEnd })
118
- └────────────────────────┬────────────────────────────┘
119
- │
120
- ▼
121
- ┌─────────────────────────────────────────────────────┐
122
- │ @blockcast/fec-worker (configured with publicKey)│
123
- │ ed25519.verify_detached(auth, │
124
- │ symbol[0..payloadEnd], │
125
- │ publicKey) │
126
- │ → emits altaVerified per packet → FecTrackStats │
127
- └─────────────────────────────────────────────────────┘
128
- ```
129
-
130
- Concretely, in `packages/container/src/mmtp-router.ts:798`, the router calls `extractAltaTrailer(packet)` for every signed source packet on the wire, packages the result as `{ auth, payloadEnd: signedEnd }`, and hands it to the FEC manager. The FEC worker (configured with `alta.publicKey` from the CMSF catalog at `configure()` time) does the actual Ed25519 / P-256 verification and increments per-track `altaVerified` / `altaFailed` counters in `FecTrackStats`. Those counters surface in CMCD as `x-bc-alta-verified` (see `packages/container/src/cmcd-producer.ts:93`).
131
-
132
- ## Why not TESLA
133
-
134
- TESLA (RFC 4082) is the IETF reference for sender-authenticated multicast: it uses delayed-disclosure of MAC keys to amortize signing cost, but at the protocol level it carries 10–20% authentication overhead per stream (depending on key chain depth and disclosure interval). ALTA is Blockcast's lighter variant — same threat model (verify each packet was minted by the legitimate sender, not a rogue injector on the multicast group), measurably lower overhead (~6.91% in production multicast tests). The parent monorepo's `CLAUDE.md` calls this out at `packages/alta/`. ALTA replaces the v2 stub verifier in v3.0 / Phase 8.
135
-
136
- ## Relation to DRM
137
-
138
- ALTA and DRM solve **different** problems and are orthogonal:
139
-
140
- | | ALTA | DRM (Widevine / PlayReady / FairPlay / ClearKey) |
141
- |---|---|---|
142
- | Authenticates | the **sender** | the **receiver** |
143
- | Question | "Did this packet come from the legitimate broadcaster?" | "Is this device authorized to play this content?" |
144
- | Wire layer | Per-MMTP-packet detached trailer | Sample-level CENC encryption + license server |
145
- | Catalog field | `alta.publicKey` | `contentProtection[]` (planned in v4 / M7) |
146
-
147
- A stream can use both — ALTA on the multicast wire (so receivers reject injected packets), CENC + DRM at the sample level (so unauthorized devices can't play). They don't interact.
148
-
149
- ## Specifications
150
-
151
- - **ISO/IEC 23008-1:2023** §9.2.2 (MMTP packet header), §9.2.3 (MPU/MFU header) — the host packet structure
152
- - **draft-ramadan-moq-mmt** §12 — detached authenticator trailer ("Path 2 / 08-07") wire format
153
- - **RFC 8032** — Ed25519 signature algorithm (a typical inhabitant of the trailer)
154
- - **NIST FIPS 186-4** — ECDSA over P-256 (alternative inhabitant)
155
- - **RFC 4082** — TESLA (the heavier scheme ALTA replaces; included for context, not a dependency)
156
- - ATSC A/331 §A — referenced by libmmt for catalog-style key/signaling distribution patterns
157
-
158
- This package is agnostic to the signature algorithm — it only carries opaque bytes.
159
-
160
- ## Related packages
161
-
162
- | Package | Role |
163
- |---------|------|
164
- | `@blockcast/mmt-container` | Consumes this parser via `mmtp-router.ts`; provides the CMSF catalog that distributes `alta.publicKey` to the FEC worker. |
165
- | `@blockcast/fec-worker` | Verifier — receives `{ auth, payloadEnd }` and the catalog public key at configure time, performs the actual Ed25519 / P-256 verification, increments `altaVerified` / `altaFailed` in `FecTrackStats`. |
166
- | `@blockcast/mmt-fec` | Surfaces verification counters to the application via FEC stats snapshots. |
167
-
168
- ## Testing
169
-
170
- ```bash
171
- pnpm test # vitest run
172
- pnpm test:watch # vitest in watch mode
173
- pnpm typecheck # tsc --noEmit
174
- pnpm build # tsc → dist/
175
- ```
176
-
177
- Direct tests in `src/index.test.ts` cover canonical complete/fragmented declarations, ALTA-only and ALTA+FEC suffixes, malformed lengths, and rejection of obsolete boundary conventions. Coverage is also exercised through the re-exported parser in `@blockcast/mmt-container`.
178
-
179
- ## License
180
-
181
- Apache-2.0 — see `LICENSE`.
@@ -1,57 +0,0 @@
1
- /**
2
- * Zero-dependency helper for extracting the detached ALTA authenticator trailer
3
- * from an MMTP source packet.
4
- *
5
- * Lives in its own leaf package so both `@blockcast/mmt-container` (wire-path
6
- * parsing) and `@blockcast/fec-worker` (FEC-recovered-source parsing) can share
7
- * one implementation without creating a package cycle between them.
8
- *
9
- * Spec: ISO/IEC 23008-1:2023 + draft-ramadan-moq-mmt §12 (detached trailer, Path 2).
10
- */
11
- /**
12
- * MMTP header-extension ext_type assigned to the detached ALTA authenticator
13
- * trailer (Path 2 / 08-07). Carried in an `[ext_type][ext_length][auth]`
14
- * block appended after the MPU's declared payload bytes, before the 4-byte
15
- * Source FEC Payload ID. MMTP X-bit stays 0 — non-ALTA MMTP receivers treat
16
- * the trailer as bytes past `payload_length` and skip it (per ISO 23008-1
17
- * §9.2.2 "may be discarded without impacting correct processing").
18
- */
19
- export declare const MMTP_EXT_TYPE_ALTA_AUTH = 61601;
20
- /** Fixed size of the trailer's `[ext_type][ext_length]` prefix (2 + 2 BE). */
21
- export declare const MMTP_EXT_TRAILER_HEADER_SIZE = 4;
22
- /** Result of extracting the detached ALTA authenticator from an MMTP packet. */
23
- export interface AltaTrailer {
24
- /** Authenticator bytes (no ext_type/ext_length prefix, no trailing padding). */
25
- auth: Uint8Array;
26
- /**
27
- * Wire-packet byte offset where the signed payload ends, i.e. where the
28
- * trailer begins. Caller uses this to produce
29
- * `payload = wirePacket.subarray(0, signedEnd)` for verify_detached.
30
- */
31
- signedEnd: number;
32
- }
33
- /**
34
- * Extract the detached ALTA authenticator trailer from an MMTP source packet.
35
- *
36
- * Wire layout:
37
- * `[MMTP hdr][length(2)][remaining MPU hdr(6)][DU?][media][TRAILER][SS_ID?]`
38
- * `payload_length = 6 + DU bytes + media bytes`
39
- *
40
- * Returns `null` when:
41
- * - the packet is too small / malformed,
42
- * - `payload_length` cannot contain the remaining six MPU-header bytes,
43
- * - the declared payload overruns the packet,
44
- * - no bytes remain between `payload_length` and the SS_ID,
45
- * - the trailer's `ext_type` isn't {@link MMTP_EXT_TYPE_ALTA_AUTH},
46
- * - the declared `ext_length` would extend past the SS_ID boundary.
47
- *
48
- * Non-MPU packets (repair, signaling) always return `null`.
49
- *
50
- * @param options.skipFecId When true, do NOT reserve 4 trailing bytes for the
51
- * Source FEC Payload ID. Use on FEC-recovered symbols where the PID has
52
- * already been stripped upstream.
53
- */
54
- export declare function extractAltaTrailer(mmtpPacket: Uint8Array, options?: {
55
- skipFecId?: boolean;
56
- }): AltaTrailer | null;
57
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAiBH;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,QAAS,CAAA;AAE7C,8EAA8E;AAC9E,eAAO,MAAM,4BAA4B,IAAI,CAAA;AAE7C,gFAAgF;AAChF,MAAM,WAAW,WAAW;IAC1B,gFAAgF;IAChF,IAAI,EAAE,UAAU,CAAA;IAChB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,UAAU,EACtB,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAChC,WAAW,GAAG,IAAI,CA4DpB"}