@blockcast/mmt-container 0.1.0 → 0.3.0-main.288475b64b3e

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 (800) hide show
  1. package/README.md +538 -0
  2. package/dist/.build-stamp +0 -0
  3. package/dist/__tests__/test-utils.d.ts +71 -0
  4. package/dist/__tests__/test-utils.d.ts.map +1 -0
  5. package/dist/align.d.ts +152 -0
  6. package/dist/align.d.ts.map +1 -0
  7. package/dist/align.js +88 -0
  8. package/dist/align.js.map +7 -0
  9. package/dist/audio-init-parser.d.ts +66 -0
  10. package/dist/audio-init-parser.d.ts.map +1 -0
  11. package/dist/audio-init-parser.js +118 -0
  12. package/dist/audio-init-parser.js.map +7 -0
  13. package/dist/audio-ring-buffer.d.ts +50 -0
  14. package/dist/audio-ring-buffer.d.ts.map +1 -0
  15. package/dist/audio-ring-buffer.js +80 -0
  16. package/dist/audio-ring-buffer.js.map +7 -0
  17. package/dist/authored-timing.d.ts +32 -0
  18. package/dist/authored-timing.d.ts.map +1 -0
  19. package/dist/authored-timing.js +32 -0
  20. package/dist/authored-timing.js.map +7 -0
  21. package/dist/block-policy.d.ts +314 -0
  22. package/dist/block-policy.d.ts.map +1 -0
  23. package/dist/block-policy.js +466 -0
  24. package/dist/block-policy.js.map +7 -0
  25. package/dist/browser-runtime.js +26457 -0
  26. package/dist/browser-runtime.js.map +7 -0
  27. package/dist/carp-catalog.d.ts +445 -0
  28. package/dist/carp-catalog.d.ts.map +1 -0
  29. package/dist/carp-catalog.js +998 -0
  30. package/dist/carp-catalog.js.map +7 -0
  31. package/dist/catalog-fec-params.d.ts +315 -0
  32. package/dist/catalog-fec-params.d.ts.map +1 -0
  33. package/dist/catalog-fec-params.js +730 -0
  34. package/dist/catalog-fec-params.js.map +7 -0
  35. package/dist/catalog-network-source.d.ts +42 -0
  36. package/dist/catalog-network-source.d.ts.map +1 -0
  37. package/dist/catalog-network-source.js +46 -0
  38. package/dist/catalog-network-source.js.map +7 -0
  39. package/dist/catalog-validator.d.ts +18 -0
  40. package/dist/catalog-validator.d.ts.map +1 -0
  41. package/dist/catalog-validator.js +7747 -0
  42. package/dist/catalog-validator.js.map +7 -0
  43. package/dist/cmaf-block-assembler.d.ts +285 -0
  44. package/dist/cmaf-block-assembler.d.ts.map +1 -0
  45. package/dist/cmaf-block-assembler.js +1966 -0
  46. package/dist/cmaf-block-assembler.js.map +7 -0
  47. package/dist/cmaf-group-batcher.d.ts +38 -0
  48. package/dist/cmaf-group-batcher.d.ts.map +1 -0
  49. package/dist/cmaf-group-batcher.js +176 -0
  50. package/dist/cmaf-group-batcher.js.map +7 -0
  51. package/dist/cmcd-producer.d.ts +104 -0
  52. package/dist/cmcd-producer.d.ts.map +1 -0
  53. package/dist/cmcd-producer.js +183 -0
  54. package/dist/cmcd-producer.js.map +7 -0
  55. package/dist/codec-utils.d.ts +384 -0
  56. package/dist/codec-utils.d.ts.map +1 -0
  57. package/dist/codec-utils.js +1546 -0
  58. package/dist/codec-utils.js.map +7 -0
  59. package/dist/conceal-timeline.d.ts +146 -0
  60. package/dist/conceal-timeline.d.ts.map +1 -0
  61. package/dist/conceal-timeline.js +137 -0
  62. package/dist/conceal-timeline.js.map +7 -0
  63. package/dist/delivery-gap.d.ts +75 -0
  64. package/dist/delivery-gap.d.ts.map +1 -0
  65. package/dist/delivery-gap.js +88 -0
  66. package/dist/delivery-gap.js.map +7 -0
  67. package/dist/duplicate-ledger.d.ts +197 -0
  68. package/dist/duplicate-ledger.d.ts.map +1 -0
  69. package/dist/duplicate-ledger.js +226 -0
  70. package/dist/duplicate-ledger.js.map +7 -0
  71. package/dist/fec-codec.d.ts +32 -0
  72. package/dist/fec-codec.d.ts.map +1 -0
  73. package/dist/fec-codec.js +47 -0
  74. package/dist/fec-codec.js.map +7 -0
  75. package/dist/fec-manager.d.ts +589 -0
  76. package/dist/fec-manager.d.ts.map +1 -0
  77. package/dist/fec-manager.js +3840 -0
  78. package/dist/fec-manager.js.map +7 -0
  79. package/dist/fec-starvation-detector.d.ts +59 -0
  80. package/dist/fec-starvation-detector.d.ts.map +1 -0
  81. package/dist/fec-starvation-detector.js +60 -0
  82. package/dist/fec-starvation-detector.js.map +7 -0
  83. package/dist/fec-state.d.ts +140 -0
  84. package/dist/fec-state.d.ts.map +1 -0
  85. package/dist/fec-state.js +86 -0
  86. package/dist/fec-state.js.map +7 -0
  87. package/dist/fec-worker-setup.d.ts +100 -0
  88. package/dist/fec-worker-setup.d.ts.map +1 -0
  89. package/dist/fec-worker-setup.js +671 -0
  90. package/dist/fec-worker-setup.js.map +7 -0
  91. package/dist/fmp4-completion.d.ts +30 -0
  92. package/dist/fmp4-completion.d.ts.map +1 -0
  93. package/dist/fmp4-completion.js +21 -0
  94. package/dist/fmp4-completion.js.map +7 -0
  95. package/dist/fmp4-reader.d.ts +37 -0
  96. package/dist/fmp4-reader.d.ts.map +1 -0
  97. package/dist/fmp4-reader.js +100 -0
  98. package/dist/fmp4-reader.js.map +7 -0
  99. package/dist/index.d.ts +44 -3
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +464 -14
  102. package/dist/index.js.map +7 -1
  103. package/dist/iso-block-locator.d.ts +118 -0
  104. package/dist/iso-block-locator.d.ts.map +1 -0
  105. package/dist/iso-block-locator.js +288 -0
  106. package/dist/iso-block-locator.js.map +7 -0
  107. package/dist/iso-bmff-timing.d.ts +78 -0
  108. package/dist/iso-bmff-timing.d.ts.map +1 -0
  109. package/dist/iso-bmff-timing.js +593 -0
  110. package/dist/iso-bmff-timing.js.map +7 -0
  111. package/dist/loc.d.ts +70 -75
  112. package/dist/loc.d.ts.map +1 -1
  113. package/dist/loc.js +106 -192
  114. package/dist/loc.js.map +7 -1
  115. package/dist/manifest-auth-plan.d.ts +30 -0
  116. package/dist/manifest-auth-plan.d.ts.map +1 -0
  117. package/dist/manifest-auth-plan.js +1266 -0
  118. package/dist/manifest-auth-plan.js.map +7 -0
  119. package/dist/media-router.d.ts +262 -0
  120. package/dist/media-router.d.ts.map +1 -0
  121. package/dist/media-router.js +584 -0
  122. package/dist/media-router.js.map +7 -0
  123. package/dist/mfu-reassembler.d.ts +313 -9
  124. package/dist/mfu-reassembler.d.ts.map +1 -1
  125. package/dist/mfu-reassembler.js +3050 -285
  126. package/dist/mfu-reassembler.js.map +7 -1
  127. package/dist/mfu-reassembly-policy.d.ts +24 -0
  128. package/dist/mfu-reassembly-policy.d.ts.map +1 -0
  129. package/dist/mfu-reassembly-policy.js +99 -0
  130. package/dist/mfu-reassembly-policy.js.map +7 -0
  131. package/dist/mmtp-container-parser.d.ts +573 -0
  132. package/dist/mmtp-container-parser.d.ts.map +1 -0
  133. package/dist/mmtp-container-parser.js +6601 -0
  134. package/dist/mmtp-container-parser.js.map +7 -0
  135. package/dist/mmtp-container-parser.no-modules.js +9645 -0
  136. package/dist/mmtp-container-parser.no-modules.js.map +7 -0
  137. package/dist/mmtp-decode-pipeline.d.ts +138 -0
  138. package/dist/mmtp-decode-pipeline.d.ts.map +1 -0
  139. package/dist/mmtp-decode-pipeline.js +6835 -0
  140. package/dist/mmtp-decode-pipeline.js.map +7 -0
  141. package/dist/mmtp-router.d.ts +702 -0
  142. package/dist/mmtp-router.d.ts.map +1 -0
  143. package/dist/mmtp-router.js +11193 -0
  144. package/dist/mmtp-router.js.map +7 -0
  145. package/dist/mmtp-to-cmaf.d.ts +187 -0
  146. package/dist/mmtp-to-cmaf.d.ts.map +1 -0
  147. package/dist/mmtp-to-cmaf.js +716 -0
  148. package/dist/mmtp-to-cmaf.js.map +7 -0
  149. package/dist/multicast-auth-catalog.d.ts +115 -0
  150. package/dist/multicast-auth-catalog.d.ts.map +1 -0
  151. package/dist/multicast-auth-catalog.js +202 -0
  152. package/dist/multicast-auth-catalog.js.map +7 -0
  153. package/dist/multicast-input.d.ts +141 -0
  154. package/dist/multicast-input.d.ts.map +1 -0
  155. package/dist/multicast-input.js +389 -0
  156. package/dist/multicast-input.js.map +7 -0
  157. package/dist/multicast-manager.d.ts +699 -0
  158. package/dist/multicast-manager.d.ts.map +1 -0
  159. package/dist/multicast-manager.js +19120 -0
  160. package/dist/multicast-manager.js.map +7 -0
  161. package/dist/multicast-transport.d.ts +271 -0
  162. package/dist/multicast-transport.d.ts.map +1 -0
  163. package/dist/multicast-transport.js +2262 -0
  164. package/dist/multicast-transport.js.map +7 -0
  165. package/dist/multicast-unwrap.d.ts +57 -0
  166. package/dist/multicast-unwrap.d.ts.map +1 -0
  167. package/dist/multicast-unwrap.js +417 -0
  168. package/dist/multicast-unwrap.js.map +7 -0
  169. package/dist/no-modules.d.ts +10 -0
  170. package/dist/no-modules.d.ts.map +1 -0
  171. package/dist/no-modules.js +9520 -0
  172. package/dist/no-modules.js.map +7 -0
  173. package/dist/phase14-catalog-override.d.ts +126 -0
  174. package/dist/phase14-catalog-override.d.ts.map +1 -0
  175. package/dist/phase14-catalog-override.js +155 -0
  176. package/dist/phase14-catalog-override.js.map +7 -0
  177. package/dist/repair-fetch.d.ts +281 -0
  178. package/dist/repair-fetch.d.ts.map +1 -0
  179. package/dist/repair-fetch.js +391 -0
  180. package/dist/repair-fetch.js.map +7 -0
  181. package/dist/repair-layers.d.ts +169 -0
  182. package/dist/repair-layers.d.ts.map +1 -0
  183. package/dist/repair-layers.js +351 -0
  184. package/dist/repair-layers.js.map +7 -0
  185. package/dist/sample-combiner.d.ts +212 -0
  186. package/dist/sample-combiner.d.ts.map +1 -0
  187. package/dist/sample-combiner.js +595 -0
  188. package/dist/sample-combiner.js.map +7 -0
  189. package/dist/signaling.d.ts +29 -0
  190. package/dist/signaling.d.ts.map +1 -0
  191. package/dist/signaling.js +568 -0
  192. package/dist/signaling.js.map +7 -0
  193. package/dist/source-auth.d.ts +2 -0
  194. package/dist/source-auth.d.ts.map +1 -0
  195. package/dist/source-auth.js +1209 -0
  196. package/dist/source-auth.js.map +7 -0
  197. package/dist/switching-set-alignment.d.ts +61 -0
  198. package/dist/switching-set-alignment.d.ts.map +1 -0
  199. package/dist/switching-set-alignment.js +70 -0
  200. package/dist/switching-set-alignment.js.map +7 -0
  201. package/dist/timestamp-codec.d.ts +34 -0
  202. package/dist/timestamp-codec.d.ts.map +1 -0
  203. package/dist/timestamp-codec.js +472 -0
  204. package/dist/timestamp-codec.js.map +7 -0
  205. package/dist/track-pipeline-setup.d.ts +83 -0
  206. package/dist/track-pipeline-setup.d.ts.map +1 -0
  207. package/dist/track-pipeline-setup.js +291 -0
  208. package/dist/track-pipeline-setup.js.map +7 -0
  209. package/dist/track-pipeline.d.ts +121 -0
  210. package/dist/track-pipeline.d.ts.map +1 -0
  211. package/dist/track-pipeline.js +209 -0
  212. package/dist/track-pipeline.js.map +7 -0
  213. package/dist/track-session.d.ts +414 -0
  214. package/dist/track-session.d.ts.map +1 -0
  215. package/dist/track-session.js +754 -0
  216. package/dist/track-session.js.map +7 -0
  217. package/dist/transport-pool.d.ts +69 -0
  218. package/dist/transport-pool.d.ts.map +1 -0
  219. package/dist/transport-pool.js +74 -0
  220. package/dist/transport-pool.js.map +7 -0
  221. package/dist/wasm-mfu-reassembler.d.ts +97 -0
  222. package/dist/wasm-mfu-reassembler.d.ts.map +1 -0
  223. package/dist/wasm-mfu-reassembler.js +2132 -0
  224. package/dist/wasm-mfu-reassembler.js.map +7 -0
  225. package/dist/wasm-mmtp-container-parser.d.ts +10 -0
  226. package/dist/wasm-mmtp-container-parser.d.ts.map +1 -0
  227. package/dist/wasm-mmtp-container-parser.js +6855 -0
  228. package/dist/wasm-mmtp-container-parser.js.map +7 -0
  229. package/node_modules/@blockcast/fec-worker/README.md +223 -0
  230. package/node_modules/@blockcast/fec-worker/dist/.build-stamp +0 -0
  231. package/node_modules/@blockcast/fec-worker/dist/block-order.d.ts +22 -0
  232. package/node_modules/@blockcast/fec-worker/dist/block-order.d.ts.map +1 -0
  233. package/node_modules/@blockcast/fec-worker/dist/block-order.js +48 -0
  234. package/node_modules/@blockcast/fec-worker/dist/block-order.js.map +1 -0
  235. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts +92 -0
  236. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts.map +1 -0
  237. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js +345 -0
  238. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js.map +1 -0
  239. package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts +373 -0
  240. package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts.map +1 -0
  241. package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.js +11 -0
  242. package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.js.map +1 -0
  243. package/node_modules/@blockcast/fec-worker/dist/fec-worker.d.ts +14 -0
  244. package/node_modules/@blockcast/fec-worker/dist/fec-worker.d.ts.map +1 -0
  245. package/node_modules/@blockcast/fec-worker/dist/fec-worker.js +764 -0
  246. package/node_modules/@blockcast/fec-worker/dist/fec-worker.js.map +7 -0
  247. package/node_modules/@blockcast/fec-worker/dist/index.d.ts +10 -0
  248. package/node_modules/@blockcast/fec-worker/dist/index.d.ts.map +1 -0
  249. package/node_modules/@blockcast/fec-worker/dist/index.js +8 -0
  250. package/node_modules/@blockcast/fec-worker/dist/index.js.map +1 -0
  251. package/node_modules/@blockcast/fec-worker/dist/shred-fec-worker.d.ts +20 -0
  252. package/node_modules/@blockcast/fec-worker/dist/shred-fec-worker.d.ts.map +1 -0
  253. package/node_modules/@blockcast/fec-worker/dist/shred-fec-worker.js +370 -0
  254. package/node_modules/@blockcast/fec-worker/dist/shred-fec-worker.js.map +7 -0
  255. package/node_modules/@blockcast/fec-worker/dist/shred-worker-client.d.ts +104 -0
  256. package/node_modules/@blockcast/fec-worker/dist/shred-worker-client.d.ts.map +1 -0
  257. package/node_modules/@blockcast/fec-worker/dist/shred-worker-client.js +181 -0
  258. package/node_modules/@blockcast/fec-worker/dist/shred-worker-client.js.map +1 -0
  259. package/node_modules/@blockcast/fec-worker/dist/shred-worker-types.d.ts +194 -0
  260. package/node_modules/@blockcast/fec-worker/dist/shred-worker-types.d.ts.map +1 -0
  261. package/node_modules/@blockcast/fec-worker/dist/shred-worker-types.js +62 -0
  262. package/node_modules/@blockcast/fec-worker/dist/shred-worker-types.js.map +1 -0
  263. package/node_modules/@blockcast/fec-worker/dist/transfer.d.ts +9 -0
  264. package/node_modules/@blockcast/fec-worker/dist/transfer.d.ts.map +1 -0
  265. package/node_modules/@blockcast/fec-worker/dist/transfer.js +13 -0
  266. package/node_modules/@blockcast/fec-worker/dist/transfer.js.map +1 -0
  267. package/node_modules/@blockcast/fec-worker/package.json +59 -0
  268. package/node_modules/@blockcast/fec-worker/src/block-order.ts +59 -0
  269. package/node_modules/@blockcast/fec-worker/src/fec-worker-client.ts +391 -0
  270. package/node_modules/@blockcast/fec-worker/src/fec-worker-types.ts +392 -0
  271. package/node_modules/@blockcast/fec-worker/src/fec-worker.ts +1386 -0
  272. package/node_modules/@blockcast/fec-worker/src/index.ts +35 -0
  273. package/node_modules/@blockcast/fec-worker/src/shred-fec-worker.ts +589 -0
  274. package/node_modules/@blockcast/fec-worker/src/shred-worker-client.ts +222 -0
  275. package/node_modules/@blockcast/fec-worker/src/shred-worker-types.ts +209 -0
  276. package/node_modules/@blockcast/fec-worker/src/transfer.ts +12 -0
  277. package/node_modules/@blockcast/mmt-alta-parse/README.md +181 -0
  278. package/node_modules/@blockcast/mmt-alta-parse/dist/.build-stamp +0 -0
  279. package/node_modules/@blockcast/mmt-alta-parse/dist/index.d.ts +57 -0
  280. package/node_modules/@blockcast/mmt-alta-parse/dist/index.d.ts.map +1 -0
  281. package/node_modules/@blockcast/mmt-alta-parse/dist/index.js +115 -0
  282. package/node_modules/@blockcast/mmt-alta-parse/dist/index.js.map +1 -0
  283. package/node_modules/@blockcast/mmt-alta-parse/package.json +50 -0
  284. package/node_modules/@blockcast/mmt-alta-parse/src/index.ts +136 -0
  285. package/node_modules/@blockcast/mmt-base/README.md +134 -0
  286. package/node_modules/@blockcast/mmt-base/dist/.build-stamp +0 -0
  287. package/node_modules/@blockcast/mmt-base/dist/fec-block-profile.d.ts +55 -0
  288. package/node_modules/@blockcast/mmt-base/dist/fec-block-profile.d.ts.map +1 -0
  289. package/node_modules/@blockcast/mmt-base/dist/fec-block-profile.js +132 -0
  290. package/node_modules/@blockcast/mmt-base/dist/fec-block-profile.js.map +1 -0
  291. package/node_modules/@blockcast/mmt-base/dist/index.d.ts +7 -0
  292. package/node_modules/@blockcast/mmt-base/dist/index.d.ts.map +1 -0
  293. package/node_modules/@blockcast/mmt-base/dist/index.js +7 -0
  294. package/node_modules/@blockcast/mmt-base/dist/index.js.map +1 -0
  295. package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +292 -0
  296. package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -0
  297. package/node_modules/@blockcast/mmt-base/dist/mmtp.js +612 -0
  298. package/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -0
  299. package/node_modules/@blockcast/mmt-base/dist/net-constants.d.ts +18 -0
  300. package/node_modules/@blockcast/mmt-base/dist/net-constants.d.ts.map +1 -0
  301. package/node_modules/@blockcast/mmt-base/dist/net-constants.js +18 -0
  302. package/node_modules/@blockcast/mmt-base/dist/net-constants.js.map +1 -0
  303. package/node_modules/@blockcast/mmt-base/dist/ntp-short.d.ts +47 -0
  304. package/node_modules/@blockcast/mmt-base/dist/ntp-short.d.ts.map +1 -0
  305. package/node_modules/@blockcast/mmt-base/dist/ntp-short.js +54 -0
  306. package/node_modules/@blockcast/mmt-base/dist/ntp-short.js.map +1 -0
  307. package/node_modules/@blockcast/mmt-base/dist/serial-number.d.ts +28 -0
  308. package/node_modules/@blockcast/mmt-base/dist/serial-number.d.ts.map +1 -0
  309. package/node_modules/@blockcast/mmt-base/dist/serial-number.js +44 -0
  310. package/node_modules/@blockcast/mmt-base/dist/serial-number.js.map +1 -0
  311. package/node_modules/@blockcast/mmt-base/dist/signalling.d.ts +314 -0
  312. package/node_modules/@blockcast/mmt-base/dist/signalling.d.ts.map +1 -0
  313. package/node_modules/@blockcast/mmt-base/dist/signalling.js +637 -0
  314. package/node_modules/@blockcast/mmt-base/dist/signalling.js.map +1 -0
  315. package/node_modules/@blockcast/mmt-base/package.json +49 -0
  316. package/node_modules/@blockcast/mmt-base/src/fec-block-profile.ts +145 -0
  317. package/node_modules/@blockcast/mmt-base/src/index.ts +6 -0
  318. package/node_modules/@blockcast/mmt-base/src/mmtp.ts +892 -0
  319. package/node_modules/@blockcast/mmt-base/src/net-constants.ts +17 -0
  320. package/node_modules/@blockcast/mmt-base/src/ntp-short.ts +67 -0
  321. package/node_modules/@blockcast/mmt-base/src/serial-number.ts +49 -0
  322. package/node_modules/@blockcast/mmt-base/src/signalling.ts +860 -0
  323. package/node_modules/@blockcast/mmt-fec/README.md +271 -0
  324. package/node_modules/@blockcast/mmt-fec/dist/.build-stamp +0 -0
  325. package/node_modules/@blockcast/mmt-fec/dist/block-manager.d.ts +82 -0
  326. package/node_modules/@blockcast/mmt-fec/dist/block-manager.d.ts.map +1 -0
  327. package/node_modules/@blockcast/mmt-fec/dist/block-manager.js +296 -0
  328. package/node_modules/@blockcast/mmt-fec/dist/block-manager.js.map +1 -0
  329. package/node_modules/@blockcast/mmt-fec/dist/block-processor.d.ts +105 -0
  330. package/node_modules/@blockcast/mmt-fec/dist/block-processor.d.ts.map +1 -0
  331. package/node_modules/@blockcast/mmt-fec/dist/block-processor.js +222 -0
  332. package/node_modules/@blockcast/mmt-fec/dist/block-processor.js.map +1 -0
  333. package/node_modules/@blockcast/mmt-fec/dist/cmaf-recovery.d.ts +46 -0
  334. package/node_modules/@blockcast/mmt-fec/dist/cmaf-recovery.d.ts.map +1 -0
  335. package/node_modules/@blockcast/mmt-fec/dist/cmaf-recovery.js +96 -0
  336. package/node_modules/@blockcast/mmt-fec/dist/cmaf-recovery.js.map +1 -0
  337. package/node_modules/@blockcast/mmt-fec/dist/cmaf-symbols.d.ts +33 -0
  338. package/node_modules/@blockcast/mmt-fec/dist/cmaf-symbols.d.ts.map +1 -0
  339. package/node_modules/@blockcast/mmt-fec/dist/cmaf-symbols.js +57 -0
  340. package/node_modules/@blockcast/mmt-fec/dist/cmaf-symbols.js.map +1 -0
  341. package/node_modules/@blockcast/mmt-fec/dist/fec-block-mapper.d.ts +149 -0
  342. package/node_modules/@blockcast/mmt-fec/dist/fec-block-mapper.d.ts.map +1 -0
  343. package/node_modules/@blockcast/mmt-fec/dist/fec-block-mapper.js +161 -0
  344. package/node_modules/@blockcast/mmt-fec/dist/fec-block-mapper.js.map +1 -0
  345. package/node_modules/@blockcast/mmt-fec/dist/index.d.ts +28 -0
  346. package/node_modules/@blockcast/mmt-fec/dist/index.d.ts.map +1 -0
  347. package/node_modules/@blockcast/mmt-fec/dist/index.js +28 -0
  348. package/node_modules/@blockcast/mmt-fec/dist/index.js.map +1 -0
  349. package/node_modules/@blockcast/mmt-fec/dist/loc-symbols.d.ts +20 -0
  350. package/node_modules/@blockcast/mmt-fec/dist/loc-symbols.d.ts.map +1 -0
  351. package/node_modules/@blockcast/mmt-fec/dist/loc-symbols.js +28 -0
  352. package/node_modules/@blockcast/mmt-fec/dist/loc-symbols.js.map +1 -0
  353. package/node_modules/@blockcast/mmt-fec/dist/oti.d.ts +258 -0
  354. package/node_modules/@blockcast/mmt-fec/dist/oti.d.ts.map +1 -0
  355. package/node_modules/@blockcast/mmt-fec/dist/oti.js +382 -0
  356. package/node_modules/@blockcast/mmt-fec/dist/oti.js.map +1 -0
  357. package/node_modules/@blockcast/mmt-fec/dist/reorder-buffer.d.ts +41 -0
  358. package/node_modules/@blockcast/mmt-fec/dist/reorder-buffer.d.ts.map +1 -0
  359. package/node_modules/@blockcast/mmt-fec/dist/reorder-buffer.js +81 -0
  360. package/node_modules/@blockcast/mmt-fec/dist/reorder-buffer.js.map +1 -0
  361. package/node_modules/@blockcast/mmt-fec/dist/repair-group.d.ts +82 -0
  362. package/node_modules/@blockcast/mmt-fec/dist/repair-group.d.ts.map +1 -0
  363. package/node_modules/@blockcast/mmt-fec/dist/repair-group.js +170 -0
  364. package/node_modules/@blockcast/mmt-fec/dist/repair-group.js.map +1 -0
  365. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-alta-parse/README.md +181 -0
  366. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-alta-parse/dist/.build-stamp +0 -0
  367. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-alta-parse/dist/index.d.ts +57 -0
  368. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-alta-parse/dist/index.d.ts.map +1 -0
  369. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-alta-parse/dist/index.js +115 -0
  370. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-alta-parse/dist/index.js.map +1 -0
  371. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-alta-parse/package.json +50 -0
  372. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-alta-parse/src/index.ts +136 -0
  373. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/README.md +134 -0
  374. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/.build-stamp +0 -0
  375. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/fec-block-profile.d.ts +55 -0
  376. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/fec-block-profile.d.ts.map +1 -0
  377. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/fec-block-profile.js +132 -0
  378. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/fec-block-profile.js.map +1 -0
  379. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/index.d.ts +7 -0
  380. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/index.d.ts.map +1 -0
  381. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/index.js +7 -0
  382. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/index.js.map +1 -0
  383. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +292 -0
  384. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -0
  385. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js +612 -0
  386. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -0
  387. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/net-constants.d.ts +18 -0
  388. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/net-constants.d.ts.map +1 -0
  389. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/net-constants.js +18 -0
  390. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/net-constants.js.map +1 -0
  391. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/ntp-short.d.ts +47 -0
  392. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/ntp-short.d.ts.map +1 -0
  393. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/ntp-short.js +54 -0
  394. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/ntp-short.js.map +1 -0
  395. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/serial-number.d.ts +28 -0
  396. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/serial-number.d.ts.map +1 -0
  397. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/serial-number.js +44 -0
  398. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/serial-number.js.map +1 -0
  399. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/signalling.d.ts +314 -0
  400. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/signalling.d.ts.map +1 -0
  401. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/signalling.js +637 -0
  402. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/signalling.js.map +1 -0
  403. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/package.json +49 -0
  404. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/fec-block-profile.ts +145 -0
  405. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/index.ts +6 -0
  406. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/mmtp.ts +892 -0
  407. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/net-constants.ts +17 -0
  408. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/ntp-short.ts +67 -0
  409. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/serial-number.ts +49 -0
  410. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/signalling.ts +860 -0
  411. package/node_modules/@blockcast/mmt-fec/package.json +79 -0
  412. package/node_modules/@blockcast/mmt-fec/src/block-manager.ts +371 -0
  413. package/node_modules/@blockcast/mmt-fec/src/block-processor.ts +360 -0
  414. package/node_modules/@blockcast/mmt-fec/src/cmaf-recovery.ts +127 -0
  415. package/node_modules/@blockcast/mmt-fec/src/cmaf-symbols.ts +68 -0
  416. package/node_modules/@blockcast/mmt-fec/src/fec-block-mapper.ts +225 -0
  417. package/node_modules/@blockcast/mmt-fec/src/index.ts +93 -0
  418. package/node_modules/@blockcast/mmt-fec/src/loc-symbols.ts +34 -0
  419. package/node_modules/@blockcast/mmt-fec/src/oti.ts +463 -0
  420. package/node_modules/@blockcast/mmt-fec/src/reorder-buffer.ts +101 -0
  421. package/node_modules/@blockcast/mmt-fec/src/repair-group.ts +195 -0
  422. package/node_modules/@blockcast/mmt-manifest-verify/dist/.build-stamp +0 -0
  423. package/node_modules/@blockcast/mmt-manifest-verify/dist/admission.d.ts +28 -0
  424. package/node_modules/@blockcast/mmt-manifest-verify/dist/admission.d.ts.map +1 -0
  425. package/node_modules/@blockcast/mmt-manifest-verify/dist/admission.js +128 -0
  426. package/node_modules/@blockcast/mmt-manifest-verify/dist/admission.js.map +1 -0
  427. package/node_modules/@blockcast/mmt-manifest-verify/dist/index.d.ts +4 -0
  428. package/node_modules/@blockcast/mmt-manifest-verify/dist/index.d.ts.map +1 -0
  429. package/node_modules/@blockcast/mmt-manifest-verify/dist/index.js +4 -0
  430. package/node_modules/@blockcast/mmt-manifest-verify/dist/index.js.map +1 -0
  431. package/node_modules/@blockcast/mmt-manifest-verify/dist/source-auth.d.ts +37 -0
  432. package/node_modules/@blockcast/mmt-manifest-verify/dist/source-auth.d.ts.map +1 -0
  433. package/node_modules/@blockcast/mmt-manifest-verify/dist/source-auth.js +179 -0
  434. package/node_modules/@blockcast/mmt-manifest-verify/dist/source-auth.js.map +1 -0
  435. package/node_modules/@blockcast/mmt-manifest-verify/dist/verifier.d.ts +99 -0
  436. package/node_modules/@blockcast/mmt-manifest-verify/dist/verifier.d.ts.map +1 -0
  437. package/node_modules/@blockcast/mmt-manifest-verify/dist/verifier.js +492 -0
  438. package/node_modules/@blockcast/mmt-manifest-verify/dist/verifier.js.map +1 -0
  439. package/node_modules/@blockcast/mmt-manifest-verify/package.json +45 -0
  440. package/node_modules/@blockcast/mmt-manifest-verify/src/admission.ts +171 -0
  441. package/node_modules/@blockcast/mmt-manifest-verify/src/index.ts +3 -0
  442. package/node_modules/@blockcast/mmt-manifest-verify/src/source-auth.ts +230 -0
  443. package/node_modules/@blockcast/mmt-manifest-verify/src/verifier.ts +669 -0
  444. package/node_modules/@noble/hashes/LICENSE +21 -0
  445. package/node_modules/@noble/hashes/README.md +521 -0
  446. package/node_modules/@noble/hashes/_assert.d.ts +17 -0
  447. package/node_modules/@noble/hashes/_assert.d.ts.map +1 -0
  448. package/node_modules/@noble/hashes/_assert.js +18 -0
  449. package/node_modules/@noble/hashes/_assert.js.map +1 -0
  450. package/node_modules/@noble/hashes/_blake.d.ts +14 -0
  451. package/node_modules/@noble/hashes/_blake.d.ts.map +1 -0
  452. package/node_modules/@noble/hashes/_blake.js +50 -0
  453. package/node_modules/@noble/hashes/_blake.js.map +1 -0
  454. package/node_modules/@noble/hashes/_md.d.ts +51 -0
  455. package/node_modules/@noble/hashes/_md.d.ts.map +1 -0
  456. package/node_modules/@noble/hashes/_md.js +162 -0
  457. package/node_modules/@noble/hashes/_md.js.map +1 -0
  458. package/node_modules/@noble/hashes/_u64.d.ts +55 -0
  459. package/node_modules/@noble/hashes/_u64.d.ts.map +1 -0
  460. package/node_modules/@noble/hashes/_u64.js +90 -0
  461. package/node_modules/@noble/hashes/_u64.js.map +1 -0
  462. package/node_modules/@noble/hashes/argon2.d.ts +32 -0
  463. package/node_modules/@noble/hashes/argon2.d.ts.map +1 -0
  464. package/node_modules/@noble/hashes/argon2.js +401 -0
  465. package/node_modules/@noble/hashes/argon2.js.map +1 -0
  466. package/node_modules/@noble/hashes/blake1.d.ts +106 -0
  467. package/node_modules/@noble/hashes/blake1.d.ts.map +1 -0
  468. package/node_modules/@noble/hashes/blake1.js +459 -0
  469. package/node_modules/@noble/hashes/blake1.js.map +1 -0
  470. package/node_modules/@noble/hashes/blake2.d.ts +116 -0
  471. package/node_modules/@noble/hashes/blake2.d.ts.map +1 -0
  472. package/node_modules/@noble/hashes/blake2.js +420 -0
  473. package/node_modules/@noble/hashes/blake2.js.map +1 -0
  474. package/node_modules/@noble/hashes/blake2b.d.ts +11 -0
  475. package/node_modules/@noble/hashes/blake2b.d.ts.map +1 -0
  476. package/node_modules/@noble/hashes/blake2b.js +14 -0
  477. package/node_modules/@noble/hashes/blake2b.js.map +1 -0
  478. package/node_modules/@noble/hashes/blake2s.d.ts +20 -0
  479. package/node_modules/@noble/hashes/blake2s.d.ts.map +1 -0
  480. package/node_modules/@noble/hashes/blake2s.js +24 -0
  481. package/node_modules/@noble/hashes/blake2s.js.map +1 -0
  482. package/node_modules/@noble/hashes/blake3.d.ts +54 -0
  483. package/node_modules/@noble/hashes/blake3.d.ts.map +1 -0
  484. package/node_modules/@noble/hashes/blake3.js +255 -0
  485. package/node_modules/@noble/hashes/blake3.js.map +1 -0
  486. package/node_modules/@noble/hashes/crypto.d.ts +2 -0
  487. package/node_modules/@noble/hashes/crypto.d.ts.map +1 -0
  488. package/node_modules/@noble/hashes/crypto.js +5 -0
  489. package/node_modules/@noble/hashes/crypto.js.map +1 -0
  490. package/node_modules/@noble/hashes/cryptoNode.d.ts +2 -0
  491. package/node_modules/@noble/hashes/cryptoNode.d.ts.map +1 -0
  492. package/node_modules/@noble/hashes/cryptoNode.js +18 -0
  493. package/node_modules/@noble/hashes/cryptoNode.js.map +1 -0
  494. package/node_modules/@noble/hashes/eskdf.d.ts +47 -0
  495. package/node_modules/@noble/hashes/eskdf.d.ts.map +1 -0
  496. package/node_modules/@noble/hashes/eskdf.js +166 -0
  497. package/node_modules/@noble/hashes/eskdf.js.map +1 -0
  498. package/node_modules/@noble/hashes/esm/_assert.d.ts +17 -0
  499. package/node_modules/@noble/hashes/esm/_assert.d.ts.map +1 -0
  500. package/node_modules/@noble/hashes/esm/_assert.js +15 -0
  501. package/node_modules/@noble/hashes/esm/_assert.js.map +1 -0
  502. package/node_modules/@noble/hashes/esm/_blake.d.ts +14 -0
  503. package/node_modules/@noble/hashes/esm/_blake.d.ts.map +1 -0
  504. package/node_modules/@noble/hashes/esm/_blake.js +45 -0
  505. package/node_modules/@noble/hashes/esm/_blake.js.map +1 -0
  506. package/node_modules/@noble/hashes/esm/_md.d.ts +51 -0
  507. package/node_modules/@noble/hashes/esm/_md.d.ts.map +1 -0
  508. package/node_modules/@noble/hashes/esm/_md.js +155 -0
  509. package/node_modules/@noble/hashes/esm/_md.js.map +1 -0
  510. package/node_modules/@noble/hashes/esm/_u64.d.ts +55 -0
  511. package/node_modules/@noble/hashes/esm/_u64.d.ts.map +1 -0
  512. package/node_modules/@noble/hashes/esm/_u64.js +67 -0
  513. package/node_modules/@noble/hashes/esm/_u64.js.map +1 -0
  514. package/node_modules/@noble/hashes/esm/argon2.d.ts +32 -0
  515. package/node_modules/@noble/hashes/esm/argon2.d.ts.map +1 -0
  516. package/node_modules/@noble/hashes/esm/argon2.js +392 -0
  517. package/node_modules/@noble/hashes/esm/argon2.js.map +1 -0
  518. package/node_modules/@noble/hashes/esm/blake1.d.ts +106 -0
  519. package/node_modules/@noble/hashes/esm/blake1.d.ts.map +1 -0
  520. package/node_modules/@noble/hashes/esm/blake1.js +452 -0
  521. package/node_modules/@noble/hashes/esm/blake1.js.map +1 -0
  522. package/node_modules/@noble/hashes/esm/blake2.d.ts +116 -0
  523. package/node_modules/@noble/hashes/esm/blake2.d.ts.map +1 -0
  524. package/node_modules/@noble/hashes/esm/blake2.js +413 -0
  525. package/node_modules/@noble/hashes/esm/blake2.js.map +1 -0
  526. package/node_modules/@noble/hashes/esm/blake2b.d.ts +11 -0
  527. package/node_modules/@noble/hashes/esm/blake2b.d.ts.map +1 -0
  528. package/node_modules/@noble/hashes/esm/blake2b.js +11 -0
  529. package/node_modules/@noble/hashes/esm/blake2b.js.map +1 -0
  530. package/node_modules/@noble/hashes/esm/blake2s.d.ts +20 -0
  531. package/node_modules/@noble/hashes/esm/blake2s.d.ts.map +1 -0
  532. package/node_modules/@noble/hashes/esm/blake2s.js +21 -0
  533. package/node_modules/@noble/hashes/esm/blake2s.js.map +1 -0
  534. package/node_modules/@noble/hashes/esm/blake3.d.ts +54 -0
  535. package/node_modules/@noble/hashes/esm/blake3.d.ts.map +1 -0
  536. package/node_modules/@noble/hashes/esm/blake3.js +251 -0
  537. package/node_modules/@noble/hashes/esm/blake3.js.map +1 -0
  538. package/node_modules/@noble/hashes/esm/crypto.d.ts +2 -0
  539. package/node_modules/@noble/hashes/esm/crypto.d.ts.map +1 -0
  540. package/node_modules/@noble/hashes/esm/crypto.js +2 -0
  541. package/node_modules/@noble/hashes/esm/crypto.js.map +1 -0
  542. package/node_modules/@noble/hashes/esm/cryptoNode.d.ts +2 -0
  543. package/node_modules/@noble/hashes/esm/cryptoNode.d.ts.map +1 -0
  544. package/node_modules/@noble/hashes/esm/cryptoNode.js +15 -0
  545. package/node_modules/@noble/hashes/esm/cryptoNode.js.map +1 -0
  546. package/node_modules/@noble/hashes/esm/eskdf.d.ts +47 -0
  547. package/node_modules/@noble/hashes/esm/eskdf.d.ts.map +1 -0
  548. package/node_modules/@noble/hashes/esm/eskdf.js +160 -0
  549. package/node_modules/@noble/hashes/esm/eskdf.js.map +1 -0
  550. package/node_modules/@noble/hashes/esm/hkdf.d.ts +36 -0
  551. package/node_modules/@noble/hashes/esm/hkdf.d.ts.map +1 -0
  552. package/node_modules/@noble/hashes/esm/hkdf.js +82 -0
  553. package/node_modules/@noble/hashes/esm/hkdf.js.map +1 -0
  554. package/node_modules/@noble/hashes/esm/hmac.d.ts +35 -0
  555. package/node_modules/@noble/hashes/esm/hmac.d.ts.map +1 -0
  556. package/node_modules/@noble/hashes/esm/hmac.js +86 -0
  557. package/node_modules/@noble/hashes/esm/hmac.js.map +1 -0
  558. package/node_modules/@noble/hashes/esm/index.d.ts +2 -0
  559. package/node_modules/@noble/hashes/esm/index.d.ts.map +1 -0
  560. package/node_modules/@noble/hashes/esm/index.js +33 -0
  561. package/node_modules/@noble/hashes/esm/index.js.map +1 -0
  562. package/node_modules/@noble/hashes/esm/legacy.d.ts +71 -0
  563. package/node_modules/@noble/hashes/esm/legacy.d.ts.map +1 -0
  564. package/node_modules/@noble/hashes/esm/legacy.js +281 -0
  565. package/node_modules/@noble/hashes/esm/legacy.js.map +1 -0
  566. package/node_modules/@noble/hashes/esm/package.json +10 -0
  567. package/node_modules/@noble/hashes/esm/pbkdf2.d.ts +23 -0
  568. package/node_modules/@noble/hashes/esm/pbkdf2.d.ts.map +1 -0
  569. package/node_modules/@noble/hashes/esm/pbkdf2.js +97 -0
  570. package/node_modules/@noble/hashes/esm/pbkdf2.js.map +1 -0
  571. package/node_modules/@noble/hashes/esm/ripemd160.d.ts +13 -0
  572. package/node_modules/@noble/hashes/esm/ripemd160.d.ts.map +1 -0
  573. package/node_modules/@noble/hashes/esm/ripemd160.js +13 -0
  574. package/node_modules/@noble/hashes/esm/ripemd160.js.map +1 -0
  575. package/node_modules/@noble/hashes/esm/scrypt.d.ts +34 -0
  576. package/node_modules/@noble/hashes/esm/scrypt.d.ts.map +1 -0
  577. package/node_modules/@noble/hashes/esm/scrypt.js +228 -0
  578. package/node_modules/@noble/hashes/esm/scrypt.js.map +1 -0
  579. package/node_modules/@noble/hashes/esm/sha1.d.ts +11 -0
  580. package/node_modules/@noble/hashes/esm/sha1.d.ts.map +1 -0
  581. package/node_modules/@noble/hashes/esm/sha1.js +11 -0
  582. package/node_modules/@noble/hashes/esm/sha1.js.map +1 -0
  583. package/node_modules/@noble/hashes/esm/sha2.d.ts +159 -0
  584. package/node_modules/@noble/hashes/esm/sha2.d.ts.map +1 -0
  585. package/node_modules/@noble/hashes/esm/sha2.js +375 -0
  586. package/node_modules/@noble/hashes/esm/sha2.js.map +1 -0
  587. package/node_modules/@noble/hashes/esm/sha256.d.ts +20 -0
  588. package/node_modules/@noble/hashes/esm/sha256.d.ts.map +1 -0
  589. package/node_modules/@noble/hashes/esm/sha256.js +20 -0
  590. package/node_modules/@noble/hashes/esm/sha256.js.map +1 -0
  591. package/node_modules/@noble/hashes/esm/sha3-addons.d.ts +142 -0
  592. package/node_modules/@noble/hashes/esm/sha3-addons.d.ts.map +1 -0
  593. package/node_modules/@noble/hashes/esm/sha3-addons.js +393 -0
  594. package/node_modules/@noble/hashes/esm/sha3-addons.js.map +1 -0
  595. package/node_modules/@noble/hashes/esm/sha3.d.ts +53 -0
  596. package/node_modules/@noble/hashes/esm/sha3.d.ts.map +1 -0
  597. package/node_modules/@noble/hashes/esm/sha3.js +234 -0
  598. package/node_modules/@noble/hashes/esm/sha3.js.map +1 -0
  599. package/node_modules/@noble/hashes/esm/sha512.d.ts +26 -0
  600. package/node_modules/@noble/hashes/esm/sha512.d.ts.map +1 -0
  601. package/node_modules/@noble/hashes/esm/sha512.js +26 -0
  602. package/node_modules/@noble/hashes/esm/sha512.js.map +1 -0
  603. package/node_modules/@noble/hashes/esm/utils.d.ts +161 -0
  604. package/node_modules/@noble/hashes/esm/utils.d.ts.map +1 -0
  605. package/node_modules/@noble/hashes/esm/utils.js +281 -0
  606. package/node_modules/@noble/hashes/esm/utils.js.map +1 -0
  607. package/node_modules/@noble/hashes/hkdf.d.ts +36 -0
  608. package/node_modules/@noble/hashes/hkdf.d.ts.map +1 -0
  609. package/node_modules/@noble/hashes/hkdf.js +88 -0
  610. package/node_modules/@noble/hashes/hkdf.js.map +1 -0
  611. package/node_modules/@noble/hashes/hmac.d.ts +35 -0
  612. package/node_modules/@noble/hashes/hmac.d.ts.map +1 -0
  613. package/node_modules/@noble/hashes/hmac.js +91 -0
  614. package/node_modules/@noble/hashes/hmac.js.map +1 -0
  615. package/node_modules/@noble/hashes/index.d.ts +1 -0
  616. package/node_modules/@noble/hashes/index.d.ts.map +1 -0
  617. package/node_modules/@noble/hashes/index.js +33 -0
  618. package/node_modules/@noble/hashes/index.js.map +1 -0
  619. package/node_modules/@noble/hashes/legacy.d.ts +71 -0
  620. package/node_modules/@noble/hashes/legacy.d.ts.map +1 -0
  621. package/node_modules/@noble/hashes/legacy.js +287 -0
  622. package/node_modules/@noble/hashes/legacy.js.map +1 -0
  623. package/node_modules/@noble/hashes/package.json +266 -0
  624. package/node_modules/@noble/hashes/pbkdf2.d.ts +23 -0
  625. package/node_modules/@noble/hashes/pbkdf2.d.ts.map +1 -0
  626. package/node_modules/@noble/hashes/pbkdf2.js +101 -0
  627. package/node_modules/@noble/hashes/pbkdf2.js.map +1 -0
  628. package/node_modules/@noble/hashes/ripemd160.d.ts +13 -0
  629. package/node_modules/@noble/hashes/ripemd160.d.ts.map +1 -0
  630. package/node_modules/@noble/hashes/ripemd160.js +16 -0
  631. package/node_modules/@noble/hashes/ripemd160.js.map +1 -0
  632. package/node_modules/@noble/hashes/scrypt.d.ts +34 -0
  633. package/node_modules/@noble/hashes/scrypt.d.ts.map +1 -0
  634. package/node_modules/@noble/hashes/scrypt.js +232 -0
  635. package/node_modules/@noble/hashes/scrypt.js.map +1 -0
  636. package/node_modules/@noble/hashes/sha1.d.ts +11 -0
  637. package/node_modules/@noble/hashes/sha1.d.ts.map +1 -0
  638. package/node_modules/@noble/hashes/sha1.js +14 -0
  639. package/node_modules/@noble/hashes/sha1.js.map +1 -0
  640. package/node_modules/@noble/hashes/sha2.d.ts +159 -0
  641. package/node_modules/@noble/hashes/sha2.d.ts.map +1 -0
  642. package/node_modules/@noble/hashes/sha2.js +384 -0
  643. package/node_modules/@noble/hashes/sha2.js.map +1 -0
  644. package/node_modules/@noble/hashes/sha256.d.ts +20 -0
  645. package/node_modules/@noble/hashes/sha256.d.ts.map +1 -0
  646. package/node_modules/@noble/hashes/sha256.js +23 -0
  647. package/node_modules/@noble/hashes/sha256.js.map +1 -0
  648. package/node_modules/@noble/hashes/sha3-addons.d.ts +142 -0
  649. package/node_modules/@noble/hashes/sha3-addons.d.ts.map +1 -0
  650. package/node_modules/@noble/hashes/sha3-addons.js +402 -0
  651. package/node_modules/@noble/hashes/sha3-addons.js.map +1 -0
  652. package/node_modules/@noble/hashes/sha3.d.ts +53 -0
  653. package/node_modules/@noble/hashes/sha3.d.ts.map +1 -0
  654. package/node_modules/@noble/hashes/sha3.js +239 -0
  655. package/node_modules/@noble/hashes/sha3.js.map +1 -0
  656. package/node_modules/@noble/hashes/sha512.d.ts +26 -0
  657. package/node_modules/@noble/hashes/sha512.d.ts.map +1 -0
  658. package/node_modules/@noble/hashes/sha512.js +29 -0
  659. package/node_modules/@noble/hashes/sha512.js.map +1 -0
  660. package/node_modules/@noble/hashes/src/_assert.ts +22 -0
  661. package/node_modules/@noble/hashes/src/_blake.ts +50 -0
  662. package/node_modules/@noble/hashes/src/_md.ts +176 -0
  663. package/node_modules/@noble/hashes/src/_u64.ts +91 -0
  664. package/node_modules/@noble/hashes/src/argon2.ts +497 -0
  665. package/node_modules/@noble/hashes/src/blake1.ts +534 -0
  666. package/node_modules/@noble/hashes/src/blake2.ts +486 -0
  667. package/node_modules/@noble/hashes/src/blake2b.ts +10 -0
  668. package/node_modules/@noble/hashes/src/blake2s.ts +20 -0
  669. package/node_modules/@noble/hashes/src/blake3.ts +272 -0
  670. package/node_modules/@noble/hashes/src/crypto.ts +9 -0
  671. package/node_modules/@noble/hashes/src/cryptoNode.ts +15 -0
  672. package/node_modules/@noble/hashes/src/eskdf.ts +187 -0
  673. package/node_modules/@noble/hashes/src/hkdf.ts +88 -0
  674. package/node_modules/@noble/hashes/src/hmac.ts +94 -0
  675. package/node_modules/@noble/hashes/src/index.ts +31 -0
  676. package/node_modules/@noble/hashes/src/legacy.ts +293 -0
  677. package/node_modules/@noble/hashes/src/pbkdf2.ts +122 -0
  678. package/node_modules/@noble/hashes/src/ripemd160.ts +12 -0
  679. package/node_modules/@noble/hashes/src/scrypt.ts +257 -0
  680. package/node_modules/@noble/hashes/src/sha1.ts +10 -0
  681. package/node_modules/@noble/hashes/src/sha2.ts +402 -0
  682. package/node_modules/@noble/hashes/src/sha256.ts +24 -0
  683. package/node_modules/@noble/hashes/src/sha3-addons.ts +499 -0
  684. package/node_modules/@noble/hashes/src/sha3.ts +258 -0
  685. package/node_modules/@noble/hashes/src/sha512.ts +34 -0
  686. package/node_modules/@noble/hashes/src/utils.ts +395 -0
  687. package/node_modules/@noble/hashes/utils.d.ts +161 -0
  688. package/node_modules/@noble/hashes/utils.d.ts.map +1 -0
  689. package/node_modules/@noble/hashes/utils.js +313 -0
  690. package/node_modules/@noble/hashes/utils.js.map +1 -0
  691. package/package.json +179 -8
  692. package/schemas/catalog.schema.json +357 -0
  693. package/src/align.ts +239 -0
  694. package/src/audio-init-parser.ts +189 -0
  695. package/src/audio-ring-buffer.ts +120 -0
  696. package/src/authored-timing.ts +63 -0
  697. package/src/block-policy.ts +903 -0
  698. package/src/carp-catalog.ts +1086 -0
  699. package/src/catalog-fec-params.ts +803 -0
  700. package/src/catalog-network-source.ts +74 -0
  701. package/src/catalog-validator.ts +34 -0
  702. package/src/cmaf-block-assembler.ts +1255 -0
  703. package/src/cmaf-group-batcher.ts +104 -0
  704. package/src/cmcd-producer.ts +329 -0
  705. package/src/codec-utils.ts +1984 -0
  706. package/src/conceal-timeline.ts +293 -0
  707. package/src/delivery-gap.ts +147 -0
  708. package/src/duplicate-ledger.ts +372 -0
  709. package/src/fec-codec.ts +61 -0
  710. package/src/fec-manager.ts +4241 -0
  711. package/src/fec-starvation-detector.ts +128 -0
  712. package/src/fec-state.ts +228 -0
  713. package/src/fec-worker-setup.ts +291 -0
  714. package/src/fmp4-completion.ts +47 -0
  715. package/src/fmp4-reader.ts +112 -0
  716. package/src/index.ts +592 -21
  717. package/src/iso-block-locator.ts +329 -0
  718. package/src/iso-bmff-timing.ts +813 -0
  719. package/src/loc.ts +128 -154
  720. package/src/manifest-auth-plan.ts +107 -0
  721. package/src/media-router.ts +841 -0
  722. package/src/mfu-reassembler.ts +3480 -155
  723. package/src/mfu-reassembly-policy.ts +134 -0
  724. package/src/mmtp-container-parser.ts +2406 -0
  725. package/src/mmtp-decode-pipeline.ts +406 -0
  726. package/src/mmtp-router.ts +4712 -0
  727. package/src/mmtp-to-cmaf.ts +977 -0
  728. package/src/multicast-auth-catalog.ts +340 -0
  729. package/src/multicast-input.ts +793 -0
  730. package/src/multicast-manager.ts +2895 -0
  731. package/src/multicast-transport.ts +1058 -0
  732. package/src/multicast-unwrap.ts +132 -0
  733. package/src/no-modules.ts +21 -0
  734. package/src/phase14-catalog-override.ts +336 -0
  735. package/src/repair-fetch.ts +786 -0
  736. package/src/repair-layers.ts +553 -0
  737. package/src/sample-combiner.ts +938 -0
  738. package/src/signaling.ts +78 -0
  739. package/src/source-auth.ts +1 -0
  740. package/src/switching-set-alignment.ts +109 -0
  741. package/src/timestamp-codec.ts +265 -0
  742. package/src/track-pipeline-setup.ts +205 -0
  743. package/src/track-pipeline.ts +332 -0
  744. package/src/track-session.ts +1010 -0
  745. package/src/transport-pool.ts +128 -0
  746. package/src/wasm-mfu-reassembler.ts +405 -0
  747. package/src/wasm-mmtp-container-parser.ts +23 -0
  748. package/test-vectors/align.json +199 -0
  749. package/test-vectors/catalog/README.md +123 -0
  750. package/test-vectors/catalog/negative/archive-origin-with-path.json +33 -0
  751. package/test-vectors/catalog/negative/archive-unknown-field.json +34 -0
  752. package/test-vectors/catalog/negative/fec-block-profile-missing.json +51 -0
  753. package/test-vectors/catalog/negative/fec-block-profile-retired.json +52 -0
  754. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +52 -0
  755. package/test-vectors/catalog/negative/fec-enhancement-repair-removed.json +28 -0
  756. package/test-vectors/catalog/negative/fec-repair-layer-geometry.json +33 -0
  757. package/test-vectors/catalog/negative/fec-repair-layer-missing-symbols.json +31 -0
  758. package/test-vectors/catalog/negative/fec-repair-multiple-depends.json +32 -0
  759. package/test-vectors/catalog/negative/fec-repair-overlay-with-layer.json +34 -0
  760. package/test-vectors/catalog/negative/fec-repair-priority-out-of-band.json +24 -0
  761. package/test-vectors/catalog/negative/fec-repair-source-symbols-without-scope.json +33 -0
  762. package/test-vectors/catalog/negative/legacy-selection-params.json +15 -0
  763. package/test-vectors/catalog/negative/media-track-repair-layer.json +16 -0
  764. package/test-vectors/catalog/negative/missing-mmtp-fields.json +12 -0
  765. package/test-vectors/catalog/negative/multicast-auth-padded-key.json +37 -0
  766. package/test-vectors/catalog/negative/multicast-auth-reused-track-format.json +53 -0
  767. package/test-vectors/catalog/negative/multicast-auth-trailing-pad-bits.json +37 -0
  768. package/test-vectors/catalog/negative/multicast-endpoint-missing-protocol-and-source.json +24 -0
  769. package/test-vectors/catalog/negative/multicast-network-source-empty.json +44 -0
  770. package/test-vectors/catalog/negative/multicast-packet-id-signaling.json +26 -0
  771. package/test-vectors/catalog/negative/network-source-object.json +25 -0
  772. package/test-vectors/catalog/negative/raptorq-source-symbols-over-max.json +24 -0
  773. package/test-vectors/catalog/negative/raptorq-unaligned-symbol.json +27 -0
  774. package/test-vectors/catalog/negative/repair-track-legacy-shape.json +19 -0
  775. package/test-vectors/catalog/negative/track-role-empty.json +16 -0
  776. package/test-vectors/catalog/negative/track-role-non-string.json +16 -0
  777. package/test-vectors/catalog/positive/archive-origin.json +34 -0
  778. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +52 -0
  779. package/test-vectors/catalog/positive/fec-layered-repair.json +106 -0
  780. package/test-vectors/catalog/positive/fec-multicast.json +53 -0
  781. package/test-vectors/catalog/positive/flat-av.json +30 -0
  782. package/test-vectors/catalog/positive/multicast-auth-rotation.json +55 -0
  783. package/test-vectors/catalog/positive/multicast-native-ssm-no-network-source.json +44 -0
  784. package/test-vectors/catalog/positive/ticks-and-mixed-timescales.json +39 -0
  785. package/test-vectors/catalog/positive/track-role.json +49 -0
  786. package/test-vectors/catalog/releases/moqcast-native-v16-v1/catalog.json +65 -0
  787. package/test-vectors/catalog/releases/moqcast-native-v16-v1.archive.sha256 +1 -0
  788. package/test-vectors/catalog-multicast-auth-v1.json +26 -0
  789. package/test-vectors/catalog-validation.json +767 -0
  790. package/test-vectors/catalog-validator-public-api.mjs +25 -0
  791. package/test-vectors/generate-source-auth-fixture.mjs +114 -0
  792. package/test-vectors/hevc-x265-repeat-headers-v1.json +40 -0
  793. package/test-vectors/source-auth-v1.json +61 -0
  794. package/test-vectors/source-contiguity-v1.json +131 -0
  795. package/test-vectors/subsample-placement-v1.json +230 -0
  796. package/dist/mmtp.d.ts +0 -73
  797. package/dist/mmtp.d.ts.map +0 -1
  798. package/dist/mmtp.js +0 -210
  799. package/dist/mmtp.js.map +0 -1
  800. package/src/mmtp.ts +0 -277
@@ -0,0 +1,1386 @@
1
+ /**
2
+ * @blockcast/fec-worker — Worker Entry Point
3
+ *
4
+ * Runs inside DedicatedWorkerGlobalScope. Receives FecWorkerCommand messages,
5
+ * drives the MmtFecDecoder WASM module, emits FecWorkerEvent messages back.
6
+ *
7
+ * WASM bindings are resolved via:
8
+ * 1. (self as any).__MMT_WASM_BINDINGS__ — set by consumer's loader/importmap
9
+ * 2. Falls back to error if not available (no defaults)
10
+ *
11
+ * This file must NOT import DOM globals incompatible with Worker scope.
12
+ */
13
+
14
+ import type {
15
+ FecWorkerCommand,
16
+ FecWorkerEvent,
17
+ FecTrackConfig,
18
+ FecTrackStats,
19
+ FecBlockSnapshot,
20
+ FrameMeta,
21
+ FecBlockProfile,
22
+ } from "./fec-worker-types.js";
23
+ import { toOwnedArrayBuffer } from "./transfer.js";
24
+ import {
25
+ isoBlockContains,
26
+ isoBlocksBehind,
27
+ isoBlocksOverlap,
28
+ serialDistance,
29
+ serialPrecedes,
30
+ } from "./block-order.js";
31
+
32
+ // --- WASM binding types (from mmt-wasm) ---
33
+ // Signatures MUST match a freshly generated external mmt_wasm.d.ts exactly.
34
+ // The decoder derives SBN/ESI internally — do not pre-compute.
35
+ interface WasmFecDecoder {
36
+ /**
37
+ * ISO 23008-1 §C.5.2: ss_id is the flat 32-bit Source Symbol ID; data is
38
+ * the protected packet, unpadded. The decoder builds the ssbg_mode1 symbol
39
+ * and holds it until a repair names the block containing it.
40
+ */
41
+ add_source(
42
+ ss_id: number,
43
+ data: Uint8Array,
44
+ timestamp: number,
45
+ ): Uint8Array | undefined;
46
+ /**
47
+ * ISO 23008-1 §C.5.3: the block is `[ss_start, ss_start + ssb_length)`
48
+ * with K' = ssb_length and repair ESI = ssb_length + rs_id; a recovered
49
+ * block is ssb_length x T bytes of ssbg_mode1 symbols.
50
+ */
51
+ add_repair(
52
+ ss_start: number,
53
+ ssb_length: number,
54
+ rs_id: number,
55
+ data: Uint8Array,
56
+ timestamp: number,
57
+ ): Uint8Array | undefined;
58
+ configure_params(k: number, symbolSize: number): void;
59
+ /**
60
+ * Retire the named blocks (last-chance decode + stats), driven by the
61
+ * manager's exact deadlines. Nothing is synthesised for a lost block:
62
+ * concealment is the sink's hold-last-good-frame.
63
+ */
64
+ cleanup_blocks_detailed(sbns: Uint32Array): void;
65
+ /**
66
+ * Remove decoder blocks, and held unplaced sources, more than
67
+ * interleaveDepth `isoBlocksBehind` the live SS_ID; returns the SS_Starts
68
+ * of the blocks it removed. It runs the decoder's `retire_unplaced` sweep
69
+ * itself, so the Worker never calls that separately: synchronizeDecoderHorizon
70
+ * calls this after every source and repair it accepts, which is what keeps
71
+ * the decoder's unplaced pool bounded when a block's repairs never arrive.
72
+ */
73
+ cleanup_by_ss_start(current: number): Uint32Array;
74
+ /** The block profile the decoder was constructed with. */
75
+ get_block_profile(): string;
76
+ flush(): void;
77
+ pending_blocks(): number;
78
+ reset_stats(): void;
79
+ get_stats(): {
80
+ source_packets: bigint;
81
+ repair_packets: bigint;
82
+ blocks_complete: bigint;
83
+ blocks_recovered: bigint;
84
+ blocks_failed: bigint;
85
+ bytes_recovered: bigint;
86
+ recovery_rate(): number;
87
+ };
88
+ free(): void;
89
+ }
90
+
91
+ interface WasmBindings {
92
+ initSync(module: { module: WebAssembly.Module }): unknown;
93
+ MmtFecDecoder: new (interleaveDepth: number, blockProfile: FecBlockProfile) => WasmFecDecoder;
94
+ }
95
+
96
+ // --- Worker state (local to this Worker instance) ---
97
+
98
+ let wasmDecoder: WasmFecDecoder | null = null;
99
+ let config: FecTrackConfig | null = null;
100
+ let altaEnabled = false;
101
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
+ let altaVerifier: any = null; // JsAltaVerifier instance (loaded from ALTA WASM)
103
+ let snapshotTimer: ReturnType<typeof setInterval> | null = null;
104
+ // blockUpdate events are posted only after a client subscribes (BLO-36599).
105
+ let blockUpdatesSubscribed = false;
106
+
107
+ // Block tracking
108
+ const blocks = new Map<number, FecBlockSnapshot>();
109
+ const acceptedSourceEsis = new Map<number, Set<number>>();
110
+ const acceptedRepairEsis = new Map<number, Set<number>>();
111
+ // iso-ssbg1-v1: sources fed to the decoder before any repair named a block
112
+ // containing them, keyed by SS_ID with their arrival time. Map order is
113
+ // arrival order, which the horizon sweep relies on (retireUnplacedSources).
114
+ const unplacedSources = new Map<number, number>();
115
+ const UINT32_MAX = 0xffff_ffff;
116
+ const UINT24_MAX = 0xff_ffff;
117
+ const SS_ID_SPAN = 0x1_0000_0000;
118
+ // ISO/IEC 23008-1 C.3.3 ssbg_mode1: the two-octet protected-packet length field.
119
+ const SSBG1_LENGTH_FIELD_BYTES = 2;
120
+ // ISO/IEC 23008-1 AL-FEC signaling carries interleave_depth in one byte.
121
+ const MAX_INTERLEAVE_DEPTH = 0xff;
122
+ // Rust stores T as u16 and this decoder profile fixes RFC 6330 Al=8.
123
+ const MAX_SYMBOL_SIZE = 0xfff8;
124
+ // RFC 6330 systematic table limit, enforced by the vendored raptorq decoder.
125
+ const MAX_RAPTORQ_SOURCE_SYMBOLS_PER_BLOCK = 56_403;
126
+
127
+ // Aggregate counters
128
+ let sourceSymbols = 0;
129
+ let repairSymbols = 0;
130
+ let blocksComplete = 0;
131
+ let blocksRecovered = 0;
132
+ let blocksFailed = 0;
133
+ let altaVerified = 0;
134
+ let altaFailed = 0; // Crypto-confirmed tamper (MAC / sig / hash chain mismatch)
135
+ const altaFailedDetails: Array<{
136
+ seq: number;
137
+ error: string;
138
+ authLen: number;
139
+ payloadLen: number;
140
+ path: string; // "direct" | "recovered" | "pending-retry"
141
+ }> = [];
142
+ let altaPending = 0; // Unverifiable but not tamper (no trailer, verifier not ready, anchor missing)
143
+ let altaPendingEvictedCap = 0; // Incoming "pending" packets rejected because the queue was at cap after stale-sweep (flood indicator)
144
+ let altaPendingEvictedTtl = 0; // Deferred-queue entries dropped by TTL (retry window expired)
145
+ let altaError = 0; // verifyDetached threw — infrastructure flake, not tamper
146
+ let altaInitFailed = false; // ALTA configured but WASM init failed; altaEnabled was forced off
147
+ let relayBlocksVerified = 0;
148
+ let relayBlocksFailed = 0;
149
+ let liveSbn = 0;
150
+ // Whether liveSbn has been set by a symbol of this decoder epoch. Block order
151
+ // is serial on the 32-bit SS_ID (block-order.ts, BLO-35597 iso:5), where 0 is
152
+ // a real position, so "nothing seen yet" needs its own state.
153
+ let liveSbnKnown = false;
154
+ let repairSymbolSizeMismatch = 0;
155
+ // Source symbols dropped before WASM, by cause. All three sites below were
156
+ // silent, which left the "block settles at exactly K-1 source symbols" shape
157
+ // (BLO-35597 defect 2) with no evidence to attribute it to. A retired drop
158
+ // means a late symbol past retention; a terminal drop means the block had
159
+ // already settled — `state !== "collecting"`, so complete OR recovered OR
160
+ // FAILED, and the failed arm is the one this issue is chasing (a block aged out
161
+ // by synchronizeDecoderHorizon stays in `blocks` until its SBN retires, so a
162
+ // late symbol for a short block lands here); a duplicate drop means a repeated
163
+ // (SBN, ESI), which on this wire is usually a plain duplicate packet — the
164
+ // router's ledger has deliberate gaps — and only sometimes an SBN/ESI
165
+ // derivation collision.
166
+ //
167
+ // These narrow the cause; they do not uniquely attribute it. A symbol LOST IN
168
+ // TRANSIT never reaches handleFeedSource and increments nothing, so all three
169
+ // reading zero on a short block is NOT evidence of a publisher defect — wire
170
+ // loss is the null hypothesis here, and it produces an identical shape. The
171
+ // discriminator for that residual arm is `block.ssbLength` (set at the repair
172
+ // symbol's declared SSB_length, conflict-checked on arrival):
173
+ // ssbLength < k → genuinely short authored block
174
+ // ssbLength === k, sourceReceived < k → loss or a still-late symbol
175
+ // With no repair symbol yet seen, ssbLength is undefined and both stay open.
176
+ let sourceDroppedRetired = 0;
177
+ let sourceDroppedTerminal = 0;
178
+ let sourceDroppedDuplicate = 0;
179
+ let sourceUnplacedRetired = 0;
180
+
181
+ // Recovery timing
182
+ const recoveryTimes: number[] = [];
183
+
184
+ // ── Deferred ALTA verification queue (08-07 Path 3) ───────────────────────
185
+ //
186
+ // When an ALTA packet arrives whose MAC references point at sequences not yet
187
+ // in the verifier's ring buffer, we can't anchor trust — verify returns "No
188
+ // trust anchor". Typical cause: a predecessor packet was lost and hasn't been
189
+ // FEC-recovered yet. Rather than drop these, hold them in a bounded FIFO and
190
+ // retry verification after every successful verify (direct or FEC-recovered)
191
+ // that seeds the ring buffer with new raw bytes.
192
+ //
193
+ // Zero-copy (1B-B): the queue entry stores a Uint8Array view into the
194
+ // original `data` ArrayBuffer. JS GC keeps the buffer alive via the view
195
+ // reference; no bytes are copied on queue.
196
+ //
197
+ // Timeout entries (TTL exceeded) and cap-rejections count as `altaPending`
198
+ // (2C-B): they're not tamper indicators, they're just packets that couldn't
199
+ // be authenticated within the receive window — either loss or, in the cap
200
+ // case, a flood of unanchorable arrivals (real or attacker-driven) that
201
+ // exceeded the queue budget. See enqueuePendingVerify for the rate-limit
202
+ // protocol.
203
+ interface PendingVerify {
204
+ seq: number;
205
+ auth: Uint8Array;
206
+ payload: Uint8Array;
207
+ arrivalTs: number;
208
+ }
209
+ const pendingVerify = new Map<number, PendingVerify>();
210
+ let pendingVerifyCap = 0;
211
+ let pendingVerifyTtlMs = 0;
212
+
213
+ // --- Helpers ---
214
+
215
+ function emit(event: FecWorkerEvent, transfer?: Transferable[]): void {
216
+ self.postMessage(event, transfer ?? []);
217
+ }
218
+
219
+ function isUint32(value: number): boolean {
220
+ return Number.isInteger(value) && value >= 0 && value <= UINT32_MAX;
221
+ }
222
+
223
+ function isTerminalBlock(block: FecBlockSnapshot): boolean {
224
+ return block.state !== "collecting";
225
+ }
226
+
227
+ function retireAcceptedIds(sbn: number): void {
228
+ acceptedSourceEsis.delete(sbn);
229
+ acceptedRepairEsis.delete(sbn);
230
+ }
231
+
232
+ function clearBlockTracking(): void {
233
+ blocks.clear();
234
+ acceptedSourceEsis.clear();
235
+ acceptedRepairEsis.clear();
236
+ unplacedSources.clear();
237
+ pendingVerify.clear();
238
+ recoveryTimes.length = 0;
239
+ liveSbn = 0;
240
+ liveSbnKnown = false;
241
+ }
242
+
243
+ /**
244
+ * Whether `sbn` has fallen behind the decoder's retained interleave window:
245
+ * more than `interleaveDepth` blocks behind the live SBN. liveSbn only moves
246
+ * forward within a decoder epoch and configure() resets both, so this is the
247
+ * monotonic retirement frontier the decoder horizon implies.
248
+ */
249
+ function isRetiredSbn(sbn: number): boolean {
250
+ if (config === null || !liveSbnKnown) return false;
251
+ // `sbn` is an SS_ID (a block's SS_Start or a source's own SS_ID) and
252
+ // liveSbn the live SS_ID; K is only the maximum block length.
253
+ return isoBlocksBehind(sbn, liveSbn, config.k) > config.interleaveDepth;
254
+ }
255
+
256
+ /**
257
+ * iso-ssbg1-v1: the SS_IDs a known block certainly covers. Every block a
258
+ * repair created has its SSB_length; a cleanup tombstone for a block no
259
+ * repair declared certainly holds only its own SS_Start.
260
+ */
261
+ function isoKnownLength(block: FecBlockSnapshot): number {
262
+ return block.ssbLength ?? 1;
263
+ }
264
+
265
+ /** iso-ssbg1-v1: the known block whose SS_ID range contains `ssId` (ranges never overlap). */
266
+ function findIsoBlock(ssId: number): FecBlockSnapshot | undefined {
267
+ for (const block of blocks.values()) {
268
+ if (isoBlockContains(block.sbn, isoKnownLength(block), ssId)) return block;
269
+ }
270
+ return undefined;
271
+ }
272
+
273
+ /**
274
+ * Whether a terminal block's diagnostics may be deleted. Under iso-ssbg1-v1 a
275
+ * source carries no block identity, so a deleted block cannot refuse a late
276
+ * source of its own: that source would be admitted as unplaced and reopen the
277
+ * block in the decoder. The tombstone therefore stays until its LAST SS_ID is
278
+ * retired, after which the SS_ID retirement check refuses every member.
279
+ */
280
+ function isRetiredBlock(key: number, block: FecBlockSnapshot): boolean {
281
+ return isRetiredSbn((key + isoKnownLength(block) - 1) % SS_ID_SPAN);
282
+ }
283
+
284
+ /**
285
+ * Retire terminal diagnostics only after the decoder's monotonic interleave
286
+ * horizon proves that the SBN can no longer be valid out-of-order media.
287
+ * Admission keeps the compact frontier as the durable tombstone, so deletion
288
+ * never reopens a finalized block.
289
+ */
290
+ function trimBlockRetention(): void {
291
+ for (const [sbn, block] of blocks) {
292
+ if (!isTerminalBlock(block) || !isRetiredBlock(sbn, block)) continue;
293
+ blocks.delete(sbn);
294
+ retireAcceptedIds(sbn);
295
+ }
296
+ }
297
+
298
+ /** Advance the live position: an SS_ID / SS_Start, in serial order. */
299
+ function advanceMediaHorizon(sbn: number): void {
300
+ if (!config) return;
301
+ if (liveSbnKnown && !serialPrecedes(liveSbn, sbn)) return;
302
+ liveSbn = sbn;
303
+ liveSbnKnown = true;
304
+ trimBlockRetention();
305
+ }
306
+
307
+ function markBlockTerminal(
308
+ block: FecBlockSnapshot,
309
+ state: "complete" | "recovered" | "failed",
310
+ ): void {
311
+ block.state = state;
312
+ block.completedTs = performance.now();
313
+ retireAcceptedIds(block.sbn);
314
+ trimBlockRetention();
315
+ }
316
+
317
+ function synchronizeDecoderHorizon(): void {
318
+ if (!wasmDecoder || !liveSbnKnown) return;
319
+ const expired = wasmDecoder.cleanup_by_ss_start(liveSbn);
320
+ for (const sbn of expired) {
321
+ const block = blocks.get(sbn);
322
+ if (!block || isTerminalBlock(block)) {
323
+ retireAcceptedIds(sbn);
324
+ continue;
325
+ }
326
+ markBlockTerminal(block, "failed");
327
+ blocksFailed++;
328
+ emitBlockUpdate(block);
329
+ }
330
+ retireUnplacedSources();
331
+ trimBlockRetention();
332
+ }
333
+
334
+ /**
335
+ * iso-ssbg1-v1: retire unplaced sources behind the horizon, by the same
336
+ * isoBlocksBehind metric as a block start, sweeping in arrival order and
337
+ * stopping at the first live one (amortised O(1) per symbol). A source that
338
+ * arrived out of order behind a newer live one is retired when it reaches the
339
+ * front; until then nothing can place it, because any repair range holding it
340
+ * starts at or before it and is itself retired. One the live position moved
341
+ * at least half the SS_ID space past no longer precedes it serially; it is
342
+ * retired too rather than pinning the sweep.
343
+ */
344
+ function retireUnplacedSources(): void {
345
+ for (const ssId of unplacedSources.keys()) {
346
+ const unreachable = ssId !== liveSbn && !serialPrecedes(ssId, liveSbn);
347
+ if (!unreachable && !isRetiredSbn(ssId)) break;
348
+ unplacedSources.delete(ssId);
349
+ sourceUnplacedRetired++;
350
+ }
351
+ }
352
+
353
+ /**
354
+ * Run detached ALTA verify against the current verifier. Four-state result:
355
+ * - "valid": crypto passed, packet authentic. Caller increments altaVerified.
356
+ * - "failed": crypto confirmed tamper (MAC/sig mismatch, hash chain mismatch).
357
+ * Caller increments altaFailed. Not retryable.
358
+ * - "pending": anchor missing (MAC refs not in buffer, no signature, not
359
+ * early-warmup). Caller may enqueue for retry after the next
360
+ * successful verify seeds the ring buffer.
361
+ * - "error": verifier threw — WASM trap, unmarshal panic, OOM. Caller
362
+ * increments altaError (infrastructure flake, not tamper).
363
+ * The distinction matters for ops alerting: a spike in
364
+ * altaError indicates a runtime problem, not an attack.
365
+ */
366
+ let _lastVerifyError = "";
367
+ function runDetachedVerify(
368
+ auth: Uint8Array,
369
+ payload: Uint8Array,
370
+ ): "valid" | "failed" | "pending" | "error" {
371
+ if (!altaVerifier) return "pending";
372
+ try {
373
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
374
+ const r: any = altaVerifier.verifyDetached(auth, payload);
375
+ if (r.valid) {
376
+ _lastVerifyError = "";
377
+ return "valid";
378
+ }
379
+ const err = (r.error as string | undefined) ?? "";
380
+ _lastVerifyError = err;
381
+ // The bootstrap-friendly verifier returns this specific error string when
382
+ // the only obstacle to verification is a missing anchor (see alta-rs
383
+ // verifier.rs verify()). Distinguishing this from tamper cases keeps us
384
+ // from queuing packets that are definitively invalid.
385
+ if (err.startsWith("No trust anchor")) return "pending";
386
+ return "failed";
387
+ } catch (e) {
388
+ // Ratelimit: first ~N occurrences get logged. A sustained exception
389
+ // stream indicates a real problem — the altaError counter is the
390
+ // durable signal.
391
+ if (altaError < 5) {
392
+ console.warn("[FecWorker] verifyDetached threw:", e);
393
+ }
394
+ return "error";
395
+ }
396
+ }
397
+
398
+ /** Extract u32 BE sequence number from the ALTA authenticator header (offset 0..3). */
399
+ function seqFromAuth(auth: Uint8Array): number {
400
+ return (
401
+ ((auth[0]! << 24) | (auth[1]! << 16) | (auth[2]! << 8) | auth[3]!) >>> 0
402
+ );
403
+ }
404
+
405
+ /**
406
+ * Enqueue a packet whose ALTA verification returned "pending" (anchor
407
+ * missing). Dedupes by sequence number.
408
+ *
409
+ * Flood resistance (08-08 review): when the queue is at cap we do NOT
410
+ * evict the oldest entry. The oldest entry is typically the most
411
+ * load-bearing one — it's the packet whose anchor everything else in the
412
+ * queue is waiting on. Evict-oldest-on-insert let an attacker emitting a
413
+ * stream of "No trust anchor" packets flood out legitimate entries and
414
+ * prevent them from ever anchoring. Instead:
415
+ * 1. First try to free stale TTL'd entries (they'd be evicted on next
416
+ * drain anyway — pulling that forward is free).
417
+ * 2. If still full, reject the NEW entry. altaPendingEvictedCap counts
418
+ * these rejections (rate-limit trigger).
419
+ *
420
+ * Stores Uint8Array views into the original data + auth buffers — no copy.
421
+ * The views keep their underlying ArrayBuffers alive via GC references.
422
+ */
423
+ function enqueuePendingVerify(
424
+ auth: Uint8Array,
425
+ payload: Uint8Array,
426
+ ): void {
427
+ const seq = seqFromAuth(auth);
428
+ if (pendingVerify.has(seq)) return;
429
+
430
+ if (pendingVerify.size >= pendingVerifyCap) {
431
+ // Step 1: sweep stale entries so legitimate traffic isn't penalized
432
+ // by TTL'd junk that happens to still occupy slots.
433
+ const now = performance.now();
434
+ for (const [staleSeq, entry] of pendingVerify) {
435
+ if (now - entry.arrivalTs > pendingVerifyTtlMs) {
436
+ pendingVerify.delete(staleSeq);
437
+ altaPendingEvictedTtl++;
438
+ }
439
+ }
440
+ // Step 2: if the queue is still at cap it's a genuine flood —
441
+ // reject the new entry rather than evict an existing one. The
442
+ // rejected packet counts as altaPendingEvictedCap (which is
443
+ // surfaced up through stats for rate-limit alerting).
444
+ if (pendingVerify.size >= pendingVerifyCap) {
445
+ altaPendingEvictedCap++;
446
+ return;
447
+ }
448
+ }
449
+
450
+ pendingVerify.set(seq, {
451
+ seq,
452
+ auth,
453
+ payload,
454
+ arrivalTs: performance.now(),
455
+ });
456
+ }
457
+
458
+ /**
459
+ * Retry every queued entry. Called after every successful verify (direct
460
+ * source or FEC-recovered) — new raw bytes in the verifier's ring buffer may
461
+ * unblock previously-pending MAC references.
462
+ *
463
+ * Three outcomes per entry:
464
+ * - "valid" → remove from queue, altaVerified++
465
+ * - "failed" → remove from queue, altaFailed++ (tamper on retry)
466
+ * - "pending" → keep in queue, unless TTL expired (then evict as altaPending)
467
+ *
468
+ * Iteration order: Map preserves insertion order, so we drain oldest-first.
469
+ * No-op when the queue is empty or the verifier isn't ready.
470
+ */
471
+ function drainPendingVerify(): void {
472
+ if (pendingVerify.size === 0 || !altaVerifier) return;
473
+ const now = performance.now();
474
+ // Collect keys to avoid mutating Map during iteration
475
+ const keys = Array.from(pendingVerify.keys());
476
+ for (const seq of keys) {
477
+ const entry = pendingVerify.get(seq);
478
+ if (!entry) continue;
479
+ if (now - entry.arrivalTs > pendingVerifyTtlMs) {
480
+ pendingVerify.delete(seq);
481
+ altaPendingEvictedTtl++;
482
+ continue;
483
+ }
484
+ const result = runDetachedVerify(entry.auth, entry.payload);
485
+ if (result === "valid") {
486
+ pendingVerify.delete(seq);
487
+ altaVerified++;
488
+ } else if (result === "failed") {
489
+ pendingVerify.delete(seq);
490
+ altaFailed++;
491
+ if (altaFailedDetails.length < 16) {
492
+ altaFailedDetails.push({
493
+ seq: entry.seq,
494
+ error: _lastVerifyError,
495
+ authLen: entry.auth.length,
496
+ payloadLen: entry.payload.length,
497
+ path: "pending-retry",
498
+ });
499
+ }
500
+ } else if (result === "error") {
501
+ // Infrastructure failure — remove from queue, count as altaError.
502
+ // Keeping it around would just re-throw on every subsequent drain.
503
+ pendingVerify.delete(seq);
504
+ altaError++;
505
+ }
506
+ // "pending" → leave in queue for next drain
507
+ }
508
+ }
509
+
510
+ /**
511
+ * Look up or create a block. `isoSsbLength` creates an iso-ssbg1-v1 block,
512
+ * whose K' is its SSB_length (C.5.3); without it the block has the catalog K.
513
+ */
514
+ function getOrCreateBlock(sbn: number, isoSsbLength?: number): FecBlockSnapshot {
515
+ let block = blocks.get(sbn);
516
+ if (!block) {
517
+ if (!config) throw new Error("[FecWorker] not configured");
518
+ const now = performance.now();
519
+ block = {
520
+ sbn,
521
+ state: "collecting",
522
+ sourceReceived: 0,
523
+ repairReceived: 0,
524
+ k: isoSsbLength ?? config.k,
525
+ repairCount: config.repairCount,
526
+ firstSymbolTs: now,
527
+ lastSymbolTs: now,
528
+ deadlineTs: now + config.deliveryWindowMs,
529
+ altaVerified: 0,
530
+ relayBlockSigValid: null,
531
+ };
532
+ if (isoSsbLength !== undefined) block.ssbLength = isoSsbLength;
533
+ blocks.set(sbn, block);
534
+ trimBlockRetention();
535
+ }
536
+ return block;
537
+ }
538
+
539
+ function buildStatsSnapshot(): FecTrackStats {
540
+ if (!config) throw new Error("[FecWorker] not configured");
541
+ const decoderStats = wasmDecoder?.get_stats();
542
+ const decoder = decoderStats
543
+ ? {
544
+ sourcePackets: Number(decoderStats.source_packets),
545
+ repairPackets: Number(decoderStats.repair_packets),
546
+ blocksComplete: Number(decoderStats.blocks_complete),
547
+ blocksRecovered: Number(decoderStats.blocks_recovered),
548
+ blocksFailed: Number(decoderStats.blocks_failed),
549
+ bytesRecovered: Number(decoderStats.bytes_recovered),
550
+ pendingBlocks: wasmDecoder?.pending_blocks() ?? 0,
551
+ }
552
+ : undefined;
553
+
554
+ const avgRecoveryMs =
555
+ recoveryTimes.length > 0
556
+ ? recoveryTimes.reduce((a, b) => a + b, 0) / recoveryTimes.length
557
+ : 0;
558
+ const maxRecoveryMs =
559
+ recoveryTimes.length > 0 ? Math.max(...recoveryTimes) : 0;
560
+
561
+ // Cap block array to interleave window
562
+ const maxBlocks = Math.max(config.interleaveDepth * 3, 24);
563
+ // Newest first in SS_ID serial order, so the cap keeps the newest blocks
564
+ // across the 2^32 wrap too: every block start precedes the live SS_ID.
565
+ const blockArray = Array.from(blocks.values())
566
+ .sort((a, b) => serialDistance(a.sbn, liveSbn) - serialDistance(b.sbn, liveSbn))
567
+ .slice(0, maxBlocks);
568
+
569
+ return {
570
+ config,
571
+ sourceSymbols,
572
+ repairSymbols,
573
+ blocksComplete,
574
+ blocksRecovered,
575
+ blocksFailed,
576
+ recoveryRate:
577
+ blocksComplete + blocksRecovered > 0
578
+ ? Math.round(
579
+ (blocksRecovered / (blocksRecovered + blocksFailed)) * 100,
580
+ ) || 0
581
+ : 0,
582
+ altaVerified,
583
+ altaFailed,
584
+ altaPending,
585
+ altaPendingEvictedCap,
586
+ altaPendingEvictedTtl,
587
+ altaError,
588
+ altaInitFailed,
589
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
590
+ altaFailedDetails: altaFailedDetails.slice() as any,
591
+ relayBlocksVerified,
592
+ relayBlocksFailed,
593
+ liveSbn,
594
+ blocks: blockArray,
595
+ interleaveWindowBlocks: config.interleaveDepth,
596
+ avgRecoveryMs: Math.round(avgRecoveryMs * 100) / 100,
597
+ maxRecoveryMs: Math.round(maxRecoveryMs * 100) / 100,
598
+ repairSymbolSizeMismatch,
599
+ sourceDroppedRetired,
600
+ sourceDroppedTerminal,
601
+ sourceDroppedDuplicate,
602
+ sourceUnplacedRetired,
603
+ decoder,
604
+ };
605
+ }
606
+
607
+ function emitSnapshot(): void {
608
+ if (!config) return;
609
+ emit({ type: "snapshot", stats: buildStatsSnapshot() });
610
+ }
611
+
612
+ function emitBlockUpdate(block: FecBlockSnapshot): void {
613
+ if (!blockUpdatesSubscribed) return;
614
+ emit({ type: "blockUpdate", block: { ...block } });
615
+ }
616
+
617
+ function emitRecoveredSymbols(
618
+ sbn: number,
619
+ recoveredBlock: Uint8Array,
620
+ block: FecBlockSnapshot,
621
+ ): void {
622
+ if (!config) return;
623
+ const symbolSize = config.symbolSize;
624
+ if (symbolSize <= 0) {
625
+ emit({
626
+ type: "error",
627
+ code: "recovered-symbol-size-unconfigured",
628
+ message: "[FecWorker] recovered block has no configured symbolSize",
629
+ });
630
+ return;
631
+ }
632
+ // The decoder returns only the block's authored source symbols
633
+ // (SSB_length x T); the encoder's zero padding is not media.
634
+ const ssbLength = block.ssbLength ?? config.k;
635
+ if (recoveredBlock.byteLength !== symbolSize * ssbLength) {
636
+ emit({
637
+ type: "error",
638
+ code: "recovered-block-too-short",
639
+ message: `[FecWorker] recovered block has the wrong length: got ${recoveredBlock.byteLength}B, expected ${symbolSize * ssbLength}B (SSB_length=${ssbLength})`,
640
+ });
641
+ return;
642
+ }
643
+
644
+ for (let i = 0; i < ssbLength; i++) {
645
+ const symbol = recoveredBlock.subarray(i * symbolSize, (i + 1) * symbolSize);
646
+ // ssbg_mode1 symbols are emitted whole: the router trims them by their
647
+ // length field. A field past T-2 or non-zero padding means the
648
+ // recovered symbol is not what was sent, so it is refused, not trimmed.
649
+ const invalid = invalidSsbg1Symbol(symbol, symbolSize);
650
+ if (invalid !== null) {
651
+ emit({
652
+ type: "error",
653
+ code: "recovered-ssbg1-symbol-invalid",
654
+ message: `[FecWorker] Dropping recovered ssbg_mode1 symbol (ssStart=${sbn}, esi=${i}, SSB_length=${ssbLength}): ${invalid}`,
655
+ });
656
+ continue;
657
+ }
658
+
659
+ // Source authentication now runs once at router admission in
660
+ // @blockcast/mmt-manifest-verify. The worker only records that this
661
+ // legacy ALTA-enabled symbol bypassed hot-path verification.
662
+ const recoveredAltaVerified: boolean | null = null;
663
+ if (altaEnabled) altaPending++;
664
+
665
+ const buf = toOwnedArrayBuffer(symbol);
666
+ const meta: FrameMeta = {
667
+ altaVerified: recoveredAltaVerified,
668
+ recovered: true,
669
+ sbn,
670
+ esi: i,
671
+ ssbLength,
672
+ };
673
+ emit({ type: "frame", data: buf, meta }, [buf]);
674
+ }
675
+ }
676
+
677
+ /** Why a T-byte ssbg_mode1 symbol is malformed (C.3.3), or null when it is well formed. */
678
+ function invalidSsbg1Symbol(symbol: Uint8Array, symbolSize: number): string | null {
679
+ const length = (symbol[0]! << 8) | symbol[1]!;
680
+ const maxLength = symbolSize - SSBG1_LENGTH_FIELD_BYTES;
681
+ if (length > maxLength) {
682
+ return `length field ${length} exceeds T-2 = ${maxLength}`;
683
+ }
684
+ for (let j = SSBG1_LENGTH_FIELD_BYTES + length; j < symbolSize; j++) {
685
+ if (symbol[j] !== 0) return `non-zero padding at byte ${j} after a ${length}-byte packet`;
686
+ }
687
+ return null;
688
+ }
689
+
690
+ function startSnapshotTimer(): void {
691
+ if (snapshotTimer !== null) clearInterval(snapshotTimer);
692
+ snapshotTimer = setInterval(() => emitSnapshot(), 200);
693
+ }
694
+
695
+ function resolveWasmBindings(): WasmBindings {
696
+ const bindings = (self as unknown as Record<string, unknown>)
697
+ .__MMT_WASM_BINDINGS__ as WasmBindings | undefined;
698
+ if (!bindings) {
699
+ throw new Error(
700
+ "[FecWorker] WASM bindings not available. Set self.__MMT_WASM_BINDINGS__ = { initSync, MmtFecDecoder } before configure.",
701
+ );
702
+ }
703
+ return bindings;
704
+ }
705
+
706
+ /**
707
+ * Refuse a decoder that does not run the configured block profile: one that
708
+ * ignored or predates the constructor argument would apply one profile's
709
+ * block math to the other's wire.
710
+ */
711
+ function verifyDecoderProfile(decoder: WasmFecDecoder, expected: FecBlockProfile): void {
712
+ let actual: unknown;
713
+ try {
714
+ actual = decoder.get_block_profile();
715
+ } catch (err) {
716
+ decoder.free();
717
+ throw new Error(
718
+ `[FecWorker] configure: decoder cannot report its block profile (${err instanceof Error ? err.message : String(err)})`,
719
+ );
720
+ }
721
+ if (actual !== expected) {
722
+ decoder.free();
723
+ throw new Error(
724
+ `[FecWorker] configure: decoder runs block profile ${JSON.stringify(actual)}, not the configured "${expected}"`,
725
+ );
726
+ }
727
+ }
728
+
729
+ function acceptId(ids: Map<number, Set<number>>, key: number, id: number): void {
730
+ let set = ids.get(key);
731
+ if (!set) {
732
+ set = new Set<number>();
733
+ ids.set(key, set);
734
+ }
735
+ set.add(id);
736
+ }
737
+
738
+ /** A block the decoder returned: record its recovery and emit its source symbols. */
739
+ function recordRecovered(key: number, block: FecBlockSnapshot, result: Uint8Array): void {
740
+ const recovered = new Uint8Array(toOwnedArrayBuffer(result));
741
+ const recoveryMs = performance.now() - block.firstSymbolTs;
742
+ recoveryTimes.push(recoveryMs);
743
+ // Cap recovery times array at 1000 entries
744
+ if (recoveryTimes.length > 1000) recoveryTimes.shift();
745
+
746
+ if (block.state === "collecting") {
747
+ markBlockTerminal(block, "recovered");
748
+ blocksRecovered++;
749
+ emitBlockUpdate(block);
750
+ }
751
+ emitRecoveredSymbols(key, recovered, block);
752
+ }
753
+
754
+ /** Settle a block after one of its source symbols was accepted. */
755
+ function settleSourceArrival(
756
+ key: number,
757
+ block: FecBlockSnapshot,
758
+ result: Uint8Array | undefined,
759
+ ): void {
760
+ // Check if block is complete (all authored source symbols received:
761
+ // SSB_length once a repair symbol declared it, otherwise K)
762
+ const authoredLength = block.ssbLength ?? block.k;
763
+ if (
764
+ block.sourceReceived >= authoredLength &&
765
+ block.state === "collecting"
766
+ ) {
767
+ markBlockTerminal(block, "complete");
768
+ blocksComplete++;
769
+ emitBlockUpdate(block);
770
+ }
771
+
772
+ // A source-triggered return can be either clean block completion or recovery
773
+ // of earlier missing symbols after repair arrived. Clean completion is
774
+ // already routed by the source path, so only emit when the block did not
775
+ // reach K source arrivals.
776
+ if (result && result.byteLength > 0 && block.sourceReceived < authoredLength) {
777
+ recordRecovered(key, block, result);
778
+ }
779
+ synchronizeDecoderHorizon();
780
+ }
781
+
782
+ /** Settle a block after one of its repair symbols was accepted. */
783
+ function settleRepairArrival(
784
+ key: number,
785
+ block: FecBlockSnapshot,
786
+ ssbLength: number,
787
+ result: Uint8Array | undefined,
788
+ ): void {
789
+ // Every authored source symbol already arrived: knowing SSB_length makes
790
+ // the block clean. The decoder's return is the source already routed.
791
+ // Otherwise, returned data is the recovered source block: its SSB_length
792
+ // fixed-width authored symbols concatenated. Split it before emitting so
793
+ // MmtpRouter gets the same one-symbol shape as a direct source packet.
794
+ if (block.sourceReceived >= ssbLength && block.state === "collecting") {
795
+ markBlockTerminal(block, "complete");
796
+ blocksComplete++;
797
+ emitBlockUpdate(block);
798
+ } else if (result && result.byteLength > 0) {
799
+ recordRecovered(key, block, result);
800
+ }
801
+ synchronizeDecoderHorizon();
802
+ }
803
+
804
+ /**
805
+ * iso-ssbg1-v1 source admission. A source inside a known block is accounted
806
+ * at ESI = SS_ID - SS_Start. One no repair has placed yet is held unplaced,
807
+ * deduplicated by SS_ID, and still fed to the decoder, which holds it too,
808
+ * until a repair names a range containing it.
809
+ */
810
+ function feedIsoSource(
811
+ cmd: Extract<FecWorkerCommand, { type: "feedSource" }>,
812
+ view: Uint8Array,
813
+ decoder: WasmFecDecoder,
814
+ cfg: FecTrackConfig,
815
+ ): void {
816
+ const maxPacketLength = cfg.symbolSize - SSBG1_LENGTH_FIELD_BYTES;
817
+ if (view.byteLength > maxPacketLength) {
818
+ throw new Error(
819
+ `[FecWorker] feedSource: iso-ssbg1-v1 protected packet of ${view.byteLength}B exceeds T-2 = ${maxPacketLength}B`,
820
+ );
821
+ }
822
+ const block = findIsoBlock(cmd.ssId);
823
+ if (!block) {
824
+ if (isRetiredSbn(cmd.ssId)) {
825
+ sourceDroppedRetired++;
826
+ return;
827
+ }
828
+ if (unplacedSources.has(cmd.ssId)) {
829
+ sourceDroppedDuplicate++;
830
+ return;
831
+ }
832
+ const result = decoder.add_source(cmd.ssId, view, cmd.ts);
833
+ advanceMediaHorizon(cmd.ssId);
834
+ unplacedSources.set(cmd.ssId, performance.now());
835
+ sourceSymbols++;
836
+ if (altaEnabled) altaPending++;
837
+ // No repair has named this source's block, so the decoder cannot have
838
+ // one to recover; data here is a Worker/decoder disagreement that
839
+ // cannot be attributed to a block, and is refused rather than guessed.
840
+ if (result && result.byteLength > 0) {
841
+ emit({
842
+ type: "error",
843
+ code: "recovered-block-unplaced",
844
+ message: `[FecWorker] Dropping a ${result.byteLength}B recovered block returned for SS_ID ${cmd.ssId}, which no known block contains`,
845
+ });
846
+ }
847
+ synchronizeDecoderHorizon();
848
+ return;
849
+ }
850
+
851
+ const key = block.sbn;
852
+ if (isRetiredSbn(key)) {
853
+ sourceDroppedRetired++;
854
+ return;
855
+ }
856
+ if (isTerminalBlock(block)) {
857
+ sourceDroppedTerminal++;
858
+ return;
859
+ }
860
+ const esi = serialDistance(key, cmd.ssId);
861
+ if (acceptedSourceEsis.get(key)?.has(esi)) {
862
+ sourceDroppedDuplicate++;
863
+ return;
864
+ }
865
+
866
+ const result = decoder.add_source(cmd.ssId, view, cmd.ts);
867
+ advanceMediaHorizon(cmd.ssId);
868
+ acceptId(acceptedSourceEsis, key, esi);
869
+ block.sourceReceived++;
870
+ block.lastSymbolTs = performance.now();
871
+ sourceSymbols++;
872
+ if (altaEnabled) altaPending++;
873
+ settleSourceArrival(key, block, result);
874
+ }
875
+
876
+ /** iso-ssbg1-v1: a known block sharing an SS_ID with `[ssStart, ssStart + ssbLength)`. */
877
+ function findOverlappingIsoBlock(
878
+ ssStart: number,
879
+ ssbLength: number,
880
+ ): FecBlockSnapshot | undefined {
881
+ for (const block of blocks.values()) {
882
+ if (isoBlocksOverlap(block.sbn, isoKnownLength(block), ssStart, ssbLength)) return block;
883
+ }
884
+ return undefined;
885
+ }
886
+
887
+ /**
888
+ * iso-ssbg1-v1: create the block a repair first named, with K' = SSB_length,
889
+ * and move every unplaced source in its range into its accounting.
890
+ */
891
+ function placeIsoBlock(ssStart: number, ssbLength: number): FecBlockSnapshot {
892
+ const block = getOrCreateBlock(ssStart, ssbLength);
893
+ for (let esi = 0; esi < ssbLength; esi++) {
894
+ const ssId = (ssStart + esi) % SS_ID_SPAN;
895
+ const arrivalTs = unplacedSources.get(ssId);
896
+ if (arrivalTs === undefined) continue;
897
+ unplacedSources.delete(ssId);
898
+ acceptId(acceptedSourceEsis, ssStart, esi);
899
+ block.sourceReceived++;
900
+ if (arrivalTs < block.firstSymbolTs) block.firstSymbolTs = arrivalTs;
901
+ }
902
+ return block;
903
+ }
904
+
905
+ /**
906
+ * iso-ssbg1-v1 repair admission. The block is `[SS_Start, SS_Start +
907
+ * SSB_length)` keyed by SS_Start, with repair ESI = SSB_length + RS_ID. A
908
+ * known block's SSB_length is checked before deduplication because the
909
+ * dedup key depends on it.
910
+ */
911
+ function feedIsoRepair(
912
+ cmd: Extract<FecWorkerCommand, { type: "feedRepair" }>,
913
+ view: Uint8Array,
914
+ decoder: WasmFecDecoder,
915
+ ): void {
916
+ const key = cmd.ssStart;
917
+ if (isRetiredSbn(key)) return;
918
+ const existingBlock = blocks.get(key);
919
+ if (existingBlock && isTerminalBlock(existingBlock)) return;
920
+ if (existingBlock) {
921
+ if (existingBlock.ssbLength !== cmd.ssbLength) {
922
+ emit({
923
+ type: "error",
924
+ code: "repair-ssb-length-conflict",
925
+ message: `[FecWorker] Dropping repair symbol whose SSB_length ${cmd.ssbLength} conflicts with ${existingBlock.ssbLength} (ssStart=${key})`,
926
+ });
927
+ return;
928
+ }
929
+ } else {
930
+ const overlapped = findOverlappingIsoBlock(key, cmd.ssbLength);
931
+ if (overlapped) {
932
+ emit({
933
+ type: "error",
934
+ code: "repair-block-overlap",
935
+ message: `[FecWorker] Dropping repair symbol whose block (ssStart=${key}, SSB_length=${cmd.ssbLength}) overlaps known block (ssStart=${overlapped.sbn}, SSB_length=${isoKnownLength(overlapped)})`,
936
+ });
937
+ return;
938
+ }
939
+ }
940
+ const repairEsi = cmd.ssbLength + cmd.rsId;
941
+ if (acceptedRepairEsis.get(key)?.has(repairEsi)) return;
942
+
943
+ const result = decoder.add_repair(key, cmd.ssbLength, cmd.rsId, view, cmd.ts);
944
+ advanceMediaHorizon(key);
945
+ const block = existingBlock ?? placeIsoBlock(key, cmd.ssbLength);
946
+ acceptId(acceptedRepairEsis, key, repairEsi);
947
+ block.repairReceived++;
948
+ block.lastSymbolTs = performance.now();
949
+ repairSymbols++;
950
+ settleRepairArrival(key, block, cmd.ssbLength, result);
951
+ }
952
+
953
+ // --- Command handlers ---
954
+
955
+ async function handleConfigure(
956
+ cmd: Extract<FecWorkerCommand, { type: "configure" }>,
957
+ ): Promise<void> {
958
+ if (!cmd.wasmModule) {
959
+ throw new Error("[FecWorker] configure: wasmModule required");
960
+ }
961
+ if (!cmd.config) {
962
+ throw new Error("[FecWorker] configure: config required");
963
+ }
964
+ // The block profile is the one discriminator for two wire-identical block
965
+ // maths, so it is required and never defaulted (BLO-35597).
966
+ const blockProfile: unknown = cmd.config.blockProfile;
967
+ if (blockProfile === undefined) {
968
+ throw new Error(
969
+ '[FecWorker] configure: blockProfile is required: name the FEC block profile ("iso-ssbg1-v1")',
970
+ );
971
+ }
972
+ if (blockProfile !== "iso-ssbg1-v1") {
973
+ throw new Error(
974
+ `[FecWorker] configure: blockProfile must be "iso-ssbg1-v1" (got ${JSON.stringify(blockProfile)})`,
975
+ );
976
+ }
977
+ if (
978
+ !Number.isFinite(cmd.config.interleaveDepth) ||
979
+ !Number.isInteger(cmd.config.interleaveDepth) ||
980
+ cmd.config.interleaveDepth <= 0 ||
981
+ cmd.config.interleaveDepth > MAX_INTERLEAVE_DEPTH
982
+ ) {
983
+ throw new Error(
984
+ `[FecWorker] configure: interleaveDepth must be an integer in 1..${MAX_INTERLEAVE_DEPTH} (got ${cmd.config.interleaveDepth})`,
985
+ );
986
+ }
987
+ if (
988
+ !Number.isFinite(cmd.config.interleaveMs) ||
989
+ cmd.config.interleaveMs <= 0
990
+ ) {
991
+ throw new Error(
992
+ `[FecWorker] configure: interleaveMs must be finite and > 0 (got ${cmd.config.interleaveMs})`,
993
+ );
994
+ }
995
+ if (
996
+ !Number.isFinite(cmd.config.deliveryWindowMs) ||
997
+ cmd.config.deliveryWindowMs <= 0
998
+ ) {
999
+ throw new Error(
1000
+ `[FecWorker] configure: deliveryWindowMs must be > 0 (got ${cmd.config.deliveryWindowMs})`,
1001
+ );
1002
+ }
1003
+ if (
1004
+ !Number.isInteger(cmd.config.k) ||
1005
+ cmd.config.k <= 0 ||
1006
+ cmd.config.k > MAX_RAPTORQ_SOURCE_SYMBOLS_PER_BLOCK
1007
+ ) {
1008
+ throw new Error(
1009
+ `[FecWorker] configure: k must be an integer in 1..${MAX_RAPTORQ_SOURCE_SYMBOLS_PER_BLOCK} (got ${cmd.config.k})`,
1010
+ );
1011
+ }
1012
+ if (
1013
+ !Number.isInteger(cmd.config.symbolSize) ||
1014
+ cmd.config.symbolSize <= 0 ||
1015
+ cmd.config.symbolSize > MAX_SYMBOL_SIZE ||
1016
+ cmd.config.symbolSize % 8 !== 0
1017
+ ) {
1018
+ throw new Error(
1019
+ `[FecWorker] configure: symbolSize must be an 8-byte-aligned integer in 8..${MAX_SYMBOL_SIZE} (got ${cmd.config.symbolSize})`,
1020
+ );
1021
+ }
1022
+
1023
+ const wasm = resolveWasmBindings();
1024
+
1025
+ // Initialize WASM from pre-compiled Module (no fetch, no re-compile)
1026
+ wasm.initSync({ module: cmd.wasmModule });
1027
+
1028
+ // A configure command starts a new decoder epoch. No terminal tombstone,
1029
+ // accepted-symbol ID, or active block from the previous decoder may affect it.
1030
+ wasmDecoder?.free();
1031
+ wasmDecoder = null;
1032
+ clearBlockTracking();
1033
+
1034
+ // Decoder policy and geometry are explicit at the epoch boundary. The WASM
1035
+ // module has no guessed K/T/interleave slow path.
1036
+ const decoder = new wasm.MmtFecDecoder(cmd.config.interleaveDepth, blockProfile);
1037
+ verifyDecoderProfile(decoder, blockProfile);
1038
+ wasmDecoder = decoder;
1039
+ config = cmd.config;
1040
+ altaEnabled = !!cmd.altaPublicKey;
1041
+
1042
+ // Size the deferred-verify queue strictly from catalog-derived FEC
1043
+ // parameters. CLAUDE.md bans Math.max(x, floor) magic — if catalog
1044
+ // values are zero/missing, throw at init rather than silently applying
1045
+ // a hardcoded floor. Consumers of an undersized queue cap would see
1046
+ // altaPendingEvictedCap spike with no actionable signal.
1047
+ // Cap: 1.5× interleave depth — wide enough to hold one full FEC recovery
1048
+ // window plus jitter, narrow enough to bound memory.
1049
+ pendingVerifyCap = Math.ceil(config.interleaveDepth * 1.5);
1050
+ // TTL: 1.5× block duration (K symbols at one per interleave tick) —
1051
+ // after this many ms, any unresolved entry has missed its FEC window.
1052
+ pendingVerifyTtlMs = Math.ceil(config.interleaveMs * config.k * 1.5);
1053
+
1054
+ // Initialize ALTA WASM verifier if public key and WASM module provided (D-05, D-09)
1055
+ altaVerifier = null;
1056
+ altaInitFailed = false;
1057
+ if (cmd.altaPublicKey && cmd.altaWasmModule) {
1058
+ try {
1059
+ // Load ALTA JS glue (wasm-bindgen output from wasm-pack build).
1060
+ // Mirrors the RaptorQ WASM pattern: initSync({ module }) then construct.
1061
+ // Dynamic import path matches the IWA static asset layout.
1062
+ // Cast via string to prevent TypeScript from attempting static resolution
1063
+ // of a runtime-only URL (same pattern as fec-worker-entry.js loading).
1064
+ const altaGlueUrl = '/wasm/alta/alta_rs.js' as string;
1065
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1066
+ const altaGlue: any = await import(/* webpackIgnore: true */ altaGlueUrl);
1067
+ altaGlue.initSync({ module: cmd.altaWasmModule });
1068
+ const keyBytes = new Uint8Array(cmd.altaPublicKey);
1069
+ altaVerifier = new altaGlue.JsAltaVerifier(keyBytes);
1070
+ } catch (e) {
1071
+ // T-08-15: WASM init failure must NOT silently look like "not-ready-yet".
1072
+ // Force altaEnabled = false so handleFeedSource takes the disabled
1073
+ // branch instead of continuously bumping altaPending under the
1074
+ // misleading "verifier not yet ready" comment. altaInitFailed
1075
+ // flag in the snapshot tells consumers this is an error state, not
1076
+ // an opt-out.
1077
+ console.warn('[FecWorker] ALTA WASM init failed, verification disabled:', e);
1078
+ altaVerifier = null;
1079
+ altaEnabled = false;
1080
+ altaInitFailed = true;
1081
+ }
1082
+ }
1083
+
1084
+ wasmDecoder.configure_params(config.k, config.symbolSize);
1085
+
1086
+ // Tell the client which optional commands this Worker accepts, so it can
1087
+ // batch symbols without risking a Worker that predates the batch command.
1088
+ emit({ type: "capabilities", commands: ["feedSymbols", "subscribeBlockUpdates"] });
1089
+
1090
+ // Start periodic snapshot emission (200ms floor)
1091
+ startSnapshotTimer();
1092
+
1093
+ // Emit initial snapshot
1094
+ emitSnapshot();
1095
+ }
1096
+
1097
+ function handleFeedSource(
1098
+ cmd: Extract<FecWorkerCommand, { type: "feedSource" }>,
1099
+ ): void {
1100
+ if (!wasmDecoder) {
1101
+ throw new Error("[FecWorker] feedSource: not configured");
1102
+ }
1103
+ if (!config) {
1104
+ throw new Error("[FecWorker] feedSource: config missing");
1105
+ }
1106
+ if (
1107
+ !isUint32(cmd.ssId) ||
1108
+ !(cmd.data instanceof ArrayBuffer)
1109
+ ) {
1110
+ throw new Error("[FecWorker] feedSource: invalid source symbol");
1111
+ }
1112
+
1113
+ feedIsoSource(cmd, new Uint8Array(cmd.data), wasmDecoder, config);
1114
+ }
1115
+
1116
+ function handleFeedRepair(
1117
+ cmd: Extract<FecWorkerCommand, { type: "feedRepair" }>,
1118
+ ): void {
1119
+ if (!wasmDecoder) {
1120
+ throw new Error("[FecWorker] feedRepair: not configured");
1121
+ }
1122
+ if (!config) {
1123
+ throw new Error("[FecWorker] feedRepair: config missing");
1124
+ }
1125
+ // iso-ssbg1-v1 blocks start at any SS_ID and repair ESI = SSB_length + RS_ID.
1126
+ if (
1127
+ !isUint32(cmd.ssStart) ||
1128
+ !isUint32(cmd.ssbLength) ||
1129
+ cmd.ssbLength <= 0 ||
1130
+ cmd.ssbLength > config.k ||
1131
+ !isUint32(cmd.rsId) ||
1132
+ cmd.ssbLength + cmd.rsId > UINT24_MAX ||
1133
+ !(cmd.data instanceof ArrayBuffer)
1134
+ ) {
1135
+ throw new Error("[FecWorker] feedRepair: invalid repair symbol");
1136
+ }
1137
+
1138
+ const view = new Uint8Array(cmd.data);
1139
+ if (config.symbolSize > 0 && view.byteLength !== config.symbolSize) {
1140
+ repairSymbolSizeMismatch++;
1141
+ if (repairSymbolSizeMismatch <= 5 || repairSymbolSizeMismatch % 100 === 0) {
1142
+ emit({
1143
+ type: "error",
1144
+ code: "repair-symbol-size-mismatch",
1145
+ message: `[FecWorker] Dropping repair symbol with invalid size: got ${view.byteLength}B, expected ${config.symbolSize}B (ssStart=${cmd.ssStart}, ssbLength=${cmd.ssbLength}, rsId=${cmd.rsId})`,
1146
+ });
1147
+ }
1148
+ return;
1149
+ }
1150
+ feedIsoRepair(cmd, view, wasmDecoder);
1151
+ }
1152
+
1153
+ function handleRelayBlockSig(
1154
+ cmd: Extract<FecWorkerCommand, { type: "relayBlockSig" }>,
1155
+ ): void {
1156
+ // No-op AUTH stub: store sig on block, mark as not-yet-verified
1157
+ const block = blocks.get(cmd.sbn);
1158
+ if (block) {
1159
+ // Real verification deferred to ALTA milestone
1160
+ // For now, mark as null (not verified) — will be wired when ALTA is implemented
1161
+ block.relayBlockSigValid = null;
1162
+ emitBlockUpdate(block);
1163
+ }
1164
+ }
1165
+
1166
+ function handleCleanup(
1167
+ cmd: Extract<FecWorkerCommand, { type: "cleanup" }>,
1168
+ ): void {
1169
+ if (
1170
+ !Array.isArray(cmd.sbns) ||
1171
+ cmd.sbns.length === 0 ||
1172
+ !cmd.sbns.every(isUint32)
1173
+ ) {
1174
+ throw new Error("[FecWorker] cleanup: invalid SBNs");
1175
+ }
1176
+ const sbns = [...new Set(cmd.sbns)].sort((a, b) => a - b);
1177
+ const pendingSbns = sbns.filter((sbn) => !isRetiredSbn(sbn));
1178
+ try {
1179
+ if (!wasmDecoder) {
1180
+ throw new Error("[FecWorker] cleanup: not configured");
1181
+ }
1182
+
1183
+ // Call WASM cleanup only after all earlier symbol commands have drained,
1184
+ // and only for the exact SBNs the manager's deadlines named; command
1185
+ // coalescing must not infer ownership from the largest timed-out SBN.
1186
+ if (pendingSbns.length > 0) {
1187
+ wasmDecoder.cleanup_blocks_detailed(Uint32Array.from(pendingSbns));
1188
+ }
1189
+ // Manager deadlines are block-scoped and may expire a newer SBN while an
1190
+ // older interleaved block is still live. Only accepted media progression
1191
+ // advances the shared JS/Rust horizon; cleanup creates exact tombstones.
1192
+
1193
+ // Rust already finalized every SBN behind the media frontier. For each
1194
+ // remaining exact request, mirror the block-scoped WASM boundary immediately
1195
+ // so JS never retains state for a decoder block that is gone.
1196
+ for (const sbn of pendingSbns) {
1197
+ let currentBlock = blocks.get(sbn);
1198
+ if (currentBlock && isTerminalBlock(currentBlock)) {
1199
+ retireAcceptedIds(sbn);
1200
+ continue;
1201
+ }
1202
+ currentBlock ??= getOrCreateBlock(sbn);
1203
+ // Compare with the block's SSB_length; a key no repair declared has
1204
+ // none, so a block the Worker never knew can only have failed.
1205
+ const authoredLength = currentBlock.ssbLength;
1206
+ if (authoredLength !== undefined && currentBlock.sourceReceived >= authoredLength) {
1207
+ markBlockTerminal(currentBlock, "complete");
1208
+ blocksComplete++;
1209
+ } else {
1210
+ markBlockTerminal(currentBlock, "failed");
1211
+ blocksFailed++;
1212
+ }
1213
+ emitBlockUpdate(currentBlock);
1214
+ }
1215
+ } finally {
1216
+ // Message ordering makes this an acknowledgement that every source/repair
1217
+ // command posted before cleanup has completed. The main thread must not
1218
+ // commit failure accounting until it observes this event.
1219
+ emit({ type: "cleanupComplete", sbns });
1220
+ }
1221
+ }
1222
+
1223
+ function handleDispose(): void {
1224
+ // Clear snapshot timer (MUST clear to prevent leaks)
1225
+ if (snapshotTimer !== null) {
1226
+ clearInterval(snapshotTimer);
1227
+ snapshotTimer = null;
1228
+ }
1229
+
1230
+ // Free ALTA verifier WASM object (MUST call to release WASM memory —
1231
+ // Worker.terminate() fires immediately after dispose, so the FinalizationRegistry
1232
+ // callback has no chance to run and this memory would leak without explicit free)
1233
+ if (altaVerifier) {
1234
+ try {
1235
+ altaVerifier.free();
1236
+ } catch (_e) {
1237
+ // Best-effort — verifier may already be freed
1238
+ }
1239
+ altaVerifier = null;
1240
+ }
1241
+
1242
+ // Free WASM decoder (MUST call to release WASM memory)
1243
+ if (wasmDecoder) {
1244
+ wasmDecoder.free();
1245
+ wasmDecoder = null;
1246
+ }
1247
+
1248
+ // Clear deferred-verify queue so pinned ArrayBuffers drop.
1249
+ pendingVerify.clear();
1250
+ pendingVerifyCap = 0;
1251
+ pendingVerifyTtlMs = 0;
1252
+
1253
+ config = null;
1254
+ clearBlockTracking();
1255
+ }
1256
+
1257
+ function handleReset(): void {
1258
+ try {
1259
+ wasmDecoder?.flush();
1260
+ wasmDecoder?.reset_stats();
1261
+ } catch (err) {
1262
+ emit({
1263
+ type: "error",
1264
+ code: "reset-failed",
1265
+ message:
1266
+ err instanceof Error
1267
+ ? `[FecWorker] reset failed: ${err.message}`
1268
+ : `[FecWorker] reset failed: ${String(err)}`,
1269
+ });
1270
+ return;
1271
+ }
1272
+
1273
+ clearBlockTracking();
1274
+ sourceSymbols = 0;
1275
+ repairSymbols = 0;
1276
+ blocksComplete = 0;
1277
+ blocksRecovered = 0;
1278
+ blocksFailed = 0;
1279
+ altaVerified = 0;
1280
+ altaFailed = 0;
1281
+ altaFailedDetails.length = 0;
1282
+ altaPending = 0;
1283
+ altaPendingEvictedCap = 0;
1284
+ altaPendingEvictedTtl = 0;
1285
+ altaError = 0;
1286
+ relayBlocksVerified = 0;
1287
+ relayBlocksFailed = 0;
1288
+ repairSymbolSizeMismatch = 0;
1289
+ sourceDroppedRetired = 0;
1290
+ sourceDroppedTerminal = 0;
1291
+ sourceDroppedDuplicate = 0;
1292
+ sourceUnplacedRetired = 0;
1293
+ emit({ type: "resetComplete" });
1294
+ if (config) emitSnapshot();
1295
+ }
1296
+
1297
+ /**
1298
+ * A batch of symbols fed in one page task (BLO-36599). Each record is
1299
+ * handled exactly as its single-symbol command would be, in order, and a
1300
+ * failing record reports the same `command-failed` error that command would
1301
+ * without stopping the records after it.
1302
+ */
1303
+ function handleFeedSymbols(
1304
+ cmd: Extract<FecWorkerCommand, { type: "feedSymbols" }>,
1305
+ ): void {
1306
+ if (!Array.isArray(cmd.symbols)) {
1307
+ throw new Error("[FecWorker] feedSymbols: symbols must be an array");
1308
+ }
1309
+ for (const symbol of cmd.symbols) {
1310
+ try {
1311
+ if (symbol?.type === "feedSource") handleFeedSource(symbol);
1312
+ else if (symbol?.type === "feedRepair") handleFeedRepair(symbol);
1313
+ else {
1314
+ throw new Error(
1315
+ `[FecWorker] feedSymbols: unknown symbol type ${String((symbol as { type?: unknown } | null)?.type)}`,
1316
+ );
1317
+ }
1318
+ } catch (err) {
1319
+ emit({
1320
+ type: "error",
1321
+ code: "command-failed",
1322
+ message:
1323
+ err instanceof Error ? err.message : `[FecWorker] ${String(err)}`,
1324
+ });
1325
+ }
1326
+ }
1327
+ }
1328
+
1329
+ // --- Main message handler ---
1330
+
1331
+ async function dispatchCommand(cmd: FecWorkerCommand): Promise<void> {
1332
+ try {
1333
+ switch (cmd.type) {
1334
+ case "configure":
1335
+ // handleConfigure is async (ALTA WASM init uses dynamic import).
1336
+ // Await it so feed/cleanup messages cannot run against a partially
1337
+ // configured decoder.
1338
+ await handleConfigure(cmd);
1339
+ break;
1340
+ case "feedSource":
1341
+ handleFeedSource(cmd);
1342
+ break;
1343
+ case "feedRepair":
1344
+ handleFeedRepair(cmd);
1345
+ break;
1346
+ case "feedSymbols":
1347
+ handleFeedSymbols(cmd);
1348
+ break;
1349
+ case "relayBlockSig":
1350
+ handleRelayBlockSig(cmd);
1351
+ break;
1352
+ case "cleanup":
1353
+ handleCleanup(cmd);
1354
+ break;
1355
+ case "reset":
1356
+ handleReset();
1357
+ break;
1358
+ case "subscribeBlockUpdates":
1359
+ blockUpdatesSubscribed = true;
1360
+ break;
1361
+ case "dispose":
1362
+ handleDispose();
1363
+ break;
1364
+ default:
1365
+ emit({
1366
+ type: "error",
1367
+ code: "unknown-command",
1368
+ message: `Unknown command type: ${(cmd as Record<string, unknown>).type}`,
1369
+ });
1370
+ }
1371
+ } catch (err) {
1372
+ emit({
1373
+ type: "error",
1374
+ code: "command-failed",
1375
+ message:
1376
+ err instanceof Error ? err.message : `[FecWorker] ${String(err)}`,
1377
+ });
1378
+ }
1379
+ }
1380
+
1381
+ let commandQueue: Promise<void> = Promise.resolve();
1382
+
1383
+ self.onmessage = (e: MessageEvent<FecWorkerCommand>) => {
1384
+ const cmd = e.data;
1385
+ commandQueue = commandQueue.then(() => dispatchCommand(cmd));
1386
+ };