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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/README.md +37 -21
  2. package/dist/align.d.ts +24 -18
  3. package/dist/align.d.ts.map +1 -1
  4. package/dist/align.js +23 -4
  5. package/dist/align.js.map +2 -2
  6. package/dist/browser-runtime.js +2037 -881
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +76 -39
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +321 -205
  11. package/dist/carp-catalog.js.map +3 -3
  12. package/dist/catalog-fec-params.d.ts +12 -4
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +40 -17
  15. package/dist/catalog-fec-params.js.map +3 -3
  16. package/dist/catalog-network-source.d.ts +28 -7
  17. package/dist/catalog-network-source.d.ts.map +1 -1
  18. package/dist/catalog-network-source.js +21 -1
  19. package/dist/catalog-network-source.js.map +2 -2
  20. package/dist/catalog-validator.d.ts +4 -3
  21. package/dist/catalog-validator.d.ts.map +1 -1
  22. package/dist/catalog-validator.js +0 -29
  23. package/dist/catalog-validator.js.map +3 -3
  24. package/dist/cmcd-producer.d.ts +13 -1
  25. package/dist/cmcd-producer.d.ts.map +1 -1
  26. package/dist/cmcd-producer.js +14 -0
  27. package/dist/cmcd-producer.js.map +2 -2
  28. package/dist/delivery-catalog.js +98 -234
  29. package/dist/delivery-catalog.js.map +4 -4
  30. package/dist/fec-manager.d.ts +108 -1
  31. package/dist/fec-manager.d.ts.map +1 -1
  32. package/dist/fec-manager.js +452 -66
  33. package/dist/fec-manager.js.map +4 -4
  34. package/dist/fec-state.d.ts +2 -1
  35. package/dist/fec-state.d.ts.map +1 -1
  36. package/dist/fec-state.js +18 -3
  37. package/dist/fec-state.js.map +3 -3
  38. package/dist/fec-worker-setup.d.ts +10 -0
  39. package/dist/fec-worker-setup.d.ts.map +1 -1
  40. package/dist/fec-worker-setup.js +15 -4
  41. package/dist/fec-worker-setup.js.map +2 -2
  42. package/dist/held-layer-admission.d.ts +58 -0
  43. package/dist/held-layer-admission.d.ts.map +1 -0
  44. package/dist/held-layer-admission.js +105 -0
  45. package/dist/held-layer-admission.js.map +7 -0
  46. package/dist/index.d.ts +5 -5
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +8 -8
  49. package/dist/index.js.map +2 -2
  50. package/dist/iso-block-locator.d.ts +39 -1
  51. package/dist/iso-block-locator.d.ts.map +1 -1
  52. package/dist/iso-block-locator.js +109 -17
  53. package/dist/iso-block-locator.js.map +3 -3
  54. package/dist/mfu-reassembler.js +21 -13
  55. package/dist/mfu-reassembler.js.map +2 -2
  56. package/dist/mmtp-container-parser.d.ts.map +1 -1
  57. package/dist/mmtp-container-parser.js +93 -22
  58. package/dist/mmtp-container-parser.js.map +2 -2
  59. package/dist/mmtp-container-parser.no-modules.js +3677 -1213
  60. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  61. package/dist/mmtp-decode-pipeline.js +93 -22
  62. package/dist/mmtp-decode-pipeline.js.map +2 -2
  63. package/dist/mmtp-fec-session.d.ts +192 -0
  64. package/dist/mmtp-fec-session.d.ts.map +1 -0
  65. package/dist/mmtp-fec-session.js +640 -0
  66. package/dist/mmtp-fec-session.js.map +7 -0
  67. package/dist/mmtp-router.d.ts +69 -32
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +296 -192
  70. package/dist/mmtp-router.js.map +2 -2
  71. package/dist/multicast-auth-catalog.d.ts +86 -92
  72. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  73. package/dist/multicast-auth-catalog.js +313 -124
  74. package/dist/multicast-auth-catalog.js.map +3 -3
  75. package/dist/multicast-input.d.ts +31 -8
  76. package/dist/multicast-input.d.ts.map +1 -1
  77. package/dist/multicast-input.js +299 -35
  78. package/dist/multicast-input.js.map +3 -3
  79. package/dist/multicast-manager.d.ts +97 -11
  80. package/dist/multicast-manager.d.ts.map +1 -1
  81. package/dist/multicast-manager.js +1022 -527
  82. package/dist/multicast-manager.js.map +4 -4
  83. package/dist/multicast-transport.d.ts +12 -2
  84. package/dist/multicast-transport.d.ts.map +1 -1
  85. package/dist/multicast-transport.js +108 -238
  86. package/dist/multicast-transport.js.map +4 -4
  87. package/dist/multicast-unwrap.js +21 -13
  88. package/dist/multicast-unwrap.js.map +2 -2
  89. package/dist/no-modules.d.ts +5 -3
  90. package/dist/no-modules.d.ts.map +1 -1
  91. package/dist/no-modules.js +3625 -1194
  92. package/dist/no-modules.js.map +4 -4
  93. package/dist/phase14-catalog-override.d.ts +1 -1
  94. package/dist/phase14-catalog-override.d.ts.map +1 -1
  95. package/dist/phase14-catalog-override.js +2 -2
  96. package/dist/phase14-catalog-override.js.map +2 -2
  97. package/dist/repair-fetch.d.ts +81 -6
  98. package/dist/repair-fetch.d.ts.map +1 -1
  99. package/dist/repair-fetch.js +156 -31
  100. package/dist/repair-fetch.js.map +3 -3
  101. package/dist/repair-layers.d.ts +2 -0
  102. package/dist/repair-layers.d.ts.map +1 -1
  103. package/dist/repair-layers.js +19 -2
  104. package/dist/repair-layers.js.map +2 -2
  105. package/dist/sample-combiner.d.ts +7 -1
  106. package/dist/sample-combiner.d.ts.map +1 -1
  107. package/dist/sample-combiner.js +14 -2
  108. package/dist/sample-combiner.js.map +2 -2
  109. package/dist/signaling.d.ts +2 -2
  110. package/dist/signaling.d.ts.map +1 -1
  111. package/dist/signaling.js +3 -3
  112. package/dist/signaling.js.map +2 -2
  113. package/dist/switching-set-alignment.d.ts +1 -1
  114. package/dist/switching-set-alignment.js.map +1 -1
  115. package/dist/timestamp-codec.js +21 -13
  116. package/dist/timestamp-codec.js.map +2 -2
  117. package/dist/wasm-mfu-reassembler.js.map +1 -1
  118. package/dist/wasm-mmtp-container-parser.js +93 -22
  119. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  120. package/package.json +6 -18
  121. package/schemas/catalog.schema.json +133 -38
  122. package/src/align.ts +52 -21
  123. package/src/carp-catalog.ts +188 -68
  124. package/src/catalog-fec-params.ts +28 -3
  125. package/src/catalog-network-source.ts +49 -7
  126. package/src/catalog-validator.ts +4 -11
  127. package/src/cmcd-producer.ts +23 -1
  128. package/src/fec-manager.ts +366 -63
  129. package/src/fec-state.ts +11 -4
  130. package/src/fec-worker-setup.ts +30 -2
  131. package/src/held-layer-admission.ts +161 -0
  132. package/src/index.ts +32 -19
  133. package/src/iso-block-locator.ts +110 -7
  134. package/src/mmtp-container-parser.ts +75 -7
  135. package/src/mmtp-fec-session.ts +606 -0
  136. package/src/mmtp-router.ts +301 -240
  137. package/src/multicast-auth-catalog.ts +134 -238
  138. package/src/multicast-input.ts +148 -124
  139. package/src/multicast-manager.ts +271 -40
  140. package/src/multicast-transport.ts +17 -3
  141. package/src/no-modules.ts +8 -7
  142. package/src/phase14-catalog-override.ts +3 -3
  143. package/src/repair-fetch.ts +283 -39
  144. package/src/repair-layers.ts +22 -2
  145. package/src/sample-combiner.ts +15 -2
  146. package/src/signaling.ts +2 -2
  147. package/src/switching-set-alignment.ts +1 -1
  148. package/test-vectors/align.json +108 -32
  149. package/test-vectors/bc-provenance-v2.json +1526 -0
  150. package/test-vectors/catalog/README.md +71 -4
  151. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  152. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  153. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  154. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  155. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  156. package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
  157. package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
  158. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  159. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  160. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  161. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  162. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  163. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  164. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  165. package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
  166. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  167. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  168. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  169. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  170. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  171. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  172. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  173. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  174. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
  175. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
  176. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  177. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  178. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  179. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  180. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  181. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  182. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  183. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  184. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  185. package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
  186. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  187. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  188. package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
  189. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  190. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  191. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  192. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
  193. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  194. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  195. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  196. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  197. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  198. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  199. package/test-vectors/catalog/section-codes.json +31 -1
  200. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  201. package/test-vectors/catalog-validation.json +101 -5
  202. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  203. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
  204. package/dist/fec-codec.d.ts +0 -32
  205. package/dist/fec-codec.d.ts.map +0 -1
  206. package/dist/fec-codec.js +0 -47
  207. package/dist/fec-codec.js.map +0 -7
  208. package/dist/manifest-auth-plan.d.ts +0 -30
  209. package/dist/manifest-auth-plan.d.ts.map +0 -1
  210. package/dist/manifest-auth-plan.js +0 -1266
  211. package/dist/manifest-auth-plan.js.map +0 -7
  212. package/dist/source-auth.d.ts +0 -2
  213. package/dist/source-auth.d.ts.map +0 -1
  214. package/dist/source-auth.js +0 -1209
  215. package/dist/source-auth.js.map +0 -7
  216. package/src/fec-codec.ts +0 -61
  217. package/src/manifest-auth-plan.ts +0 -107
  218. package/src/source-auth.ts +0 -1
  219. package/test-vectors/generate-source-auth-fixture.mjs +0 -114
  220. package/test-vectors/source-auth-v1.json +0 -61
@@ -1,6 +1,273 @@
1
+ // ../mmt-base/dist/mmtp.js
2
+ var MPU_HEADER_SIZE = 8;
3
+ var MPU_LENGTH_FIELD_SIZE = 2;
4
+ var MPU_HEADER_REMAINDER_SIZE = MPU_HEADER_SIZE - MPU_LENGTH_FIELD_SIZE;
5
+
6
+ // ../mmt-base/dist/ntp-short.js
7
+ var NTP_SHORT_BITS = 32;
8
+ var NTP_SHORT_MODULUS = 2 ** NTP_SHORT_BITS;
9
+ var NTP_SHORT_HALF_RANGE = 2 ** (NTP_SHORT_BITS - 1);
10
+
11
+ // ../mmt-base/dist/fec-block-profile.js
12
+ var FEC_BLOCK_PROFILES = Object.freeze([
13
+ "iso-ssbg1-v1"
14
+ ]);
15
+
16
+ // ../mmt-base/dist/catalog-fec-source.js
17
+ var ALL_ROLES = Object.freeze(["video", "audio"]);
18
+
19
+ // ../mmt-base/dist/multicast-catalog.js
20
+ var ED25519_PUBLIC_KEY_BASE64URL = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
21
+ var UINT32_MAX = 4294967295;
22
+ var AUTH_MEMBERS = /* @__PURE__ */ new Set(["scheme", "version", "sig", "keys", "minEpoch"]);
23
+ var KEY_MEMBERS = /* @__PURE__ */ new Set(["kid", "publicKey", "firstEpoch"]);
24
+ var ENDPOINT_AUTH_MEMBERS = /* @__PURE__ */ new Set([
25
+ "manifestPort",
26
+ "streamId",
27
+ "senderAddress",
28
+ "maxAuthDelayMs",
29
+ "manifestTimerMs",
30
+ "manifestTrack"
31
+ ]);
32
+ function isObject(value) {
33
+ return typeof value === "object" && value !== null && !Array.isArray(value);
34
+ }
35
+ function isNonEmptyString(value) {
36
+ return typeof value === "string" && value.trim().length > 0;
37
+ }
38
+ function isIntegerIn(value, min, max) {
39
+ return Number.isSafeInteger(value) && value >= min && value <= max;
40
+ }
41
+ function multicastEndpointSource(endpoint) {
42
+ if (!isObject(endpoint))
43
+ return void 0;
44
+ const sourceAddress = endpoint["sourceAddress"];
45
+ if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress))
46
+ return void 0;
47
+ const mode = sourceAddress === void 0 ? "asm" : "ssm";
48
+ const protocol = endpoint["protocol"];
49
+ if (protocol !== void 0 && protocol !== mode)
50
+ return void 0;
51
+ const auth = endpoint["auth"];
52
+ const senderAddress = isObject(auth) ? auth["senderAddress"] : void 0;
53
+ if (mode === "ssm")
54
+ return senderAddress === void 0 ? { mode, source: sourceAddress } : void 0;
55
+ if (auth === void 0)
56
+ return { mode };
57
+ return isNonEmptyString(senderAddress) ? { mode, source: senderAddress } : void 0;
58
+ }
59
+ function authIssues(auth) {
60
+ const base = "$.multicast.auth";
61
+ const issue = (path, message) => [
62
+ { code: "multicast_auth", path: `${base}${path}`, message }
63
+ ];
64
+ if (!isObject(auth))
65
+ return issue("", "auth must be an object");
66
+ const unknown = Object.keys(auth).filter((key) => !AUTH_MEMBERS.has(key));
67
+ if (unknown.length > 0) {
68
+ return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -01 7.2.6 defines scheme, version, sig, keys and minEpoch`);
69
+ }
70
+ if (auth["scheme"] !== "bc-provenance")
71
+ return issue(".scheme", 'scheme must be "bc-provenance"');
72
+ if (auth["version"] !== 2)
73
+ return issue(".version", "version must be 2 (bc-provenance version 2, draft -01 7.2)");
74
+ if (auth["sig"] !== "ed25519")
75
+ return issue(".sig", 'sig must be "ed25519"');
76
+ const keys = auth["keys"];
77
+ if (!Array.isArray(keys) || keys.length < 1 || keys.length > 4) {
78
+ return issue(".keys", "keys must be an array of one to four {kid, publicKey, firstEpoch} objects");
79
+ }
80
+ const kids = /* @__PURE__ */ new Set();
81
+ const firstEpochs = /* @__PURE__ */ new Set();
82
+ for (let index = 0; index < keys.length; index++) {
83
+ const key = keys[index];
84
+ const at = `.keys[${index}]`;
85
+ if (!isObject(key) || Object.keys(key).some((member) => !KEY_MEMBERS.has(member))) {
86
+ return issue(at, "a key is exactly {kid, publicKey, firstEpoch}");
87
+ }
88
+ if (!isIntegerIn(key["kid"], 0, UINT32_MAX))
89
+ return issue(`${at}.kid`, "kid must be an unsigned 32-bit integer");
90
+ if (typeof key["publicKey"] !== "string" || !ED25519_PUBLIC_KEY_BASE64URL.test(key["publicKey"])) {
91
+ return issue(`${at}.publicKey`, "publicKey must be a 32-octet Ed25519 key in canonical unpadded base64url");
92
+ }
93
+ if (!isIntegerIn(key["firstEpoch"], 0, UINT32_MAX)) {
94
+ return issue(`${at}.firstEpoch`, "firstEpoch must be an unsigned 32-bit integer");
95
+ }
96
+ if (kids.has(key["kid"]))
97
+ return issue(`${at}.kid`, `kid ${key["kid"]} is repeated; the catalog holds no key set`);
98
+ if (firstEpochs.has(key["firstEpoch"])) {
99
+ return issue(`${at}.firstEpoch`, `firstEpoch ${key["firstEpoch"]} is repeated; the catalog holds no key set`);
100
+ }
101
+ kids.add(key["kid"]);
102
+ firstEpochs.add(key["firstEpoch"]);
103
+ }
104
+ if (!isIntegerIn(auth["minEpoch"], 0, UINT32_MAX)) {
105
+ return issue(".minEpoch", "minEpoch must be an unsigned 32-bit integer");
106
+ }
107
+ return [];
108
+ }
109
+ function endpointAuthIssue(endpoint, mode, at) {
110
+ const auth = endpoint["auth"];
111
+ if (!isObject(auth))
112
+ return { path: `${at}.auth`, message: "auth must be an object" };
113
+ const unknown = Object.keys(auth).filter((key) => !ENDPOINT_AUTH_MEMBERS.has(key));
114
+ if (unknown.length > 0)
115
+ return { path: `${at}.auth`, message: `auth has unknown member(s) ${unknown.join(", ")}` };
116
+ if (!isIntegerIn(auth["manifestPort"], 1, 65535)) {
117
+ return { path: `${at}.auth.manifestPort`, message: "manifestPort must be an integer from 1 to 65535" };
118
+ }
119
+ if (!isIntegerIn(auth["streamId"], 0, UINT32_MAX)) {
120
+ return { path: `${at}.auth.streamId`, message: "streamId must be an unsigned 32-bit integer" };
121
+ }
122
+ if (mode === "ssm" && auth["senderAddress"] !== void 0) {
123
+ return { path: `${at}.auth.senderAddress`, message: "senderAddress must not appear on an SSM endpoint; S is sourceAddress" };
124
+ }
125
+ if (mode === "asm" && !isNonEmptyString(auth["senderAddress"])) {
126
+ return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress" };
127
+ }
128
+ if (auth["maxAuthDelayMs"] !== void 0 && !isIntegerIn(auth["maxAuthDelayMs"], 50, 1e3)) {
129
+ return { path: `${at}.auth.maxAuthDelayMs`, message: "maxAuthDelayMs must be an integer from 50 to 1000" };
130
+ }
131
+ if (auth["manifestTimerMs"] !== void 0 && !isIntegerIn(auth["manifestTimerMs"], 1, Number.MAX_SAFE_INTEGER)) {
132
+ return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be an integer of at least 1" };
133
+ }
134
+ if (auth["manifestTrack"] !== void 0 && !isNonEmptyString(auth["manifestTrack"])) {
135
+ return { path: `${at}.auth.manifestTrack`, message: "manifestTrack must be a non-empty string" };
136
+ }
137
+ if (!isIntegerIn(endpoint["bandwidth"], 1, Number.MAX_SAFE_INTEGER)) {
138
+ return { path: `${at}.bandwidth`, message: "a protected endpoint requires bandwidth, which bounds the receiver's hold queues" };
139
+ }
140
+ return void 0;
141
+ }
142
+ var CATALOG_NAMESPACE = /* @__PURE__ */ Symbol.for("@blockcast/mmt-base/catalogNamespace");
143
+ function multicastCatalogIssues(catalog, options = {}) {
144
+ if (!isObject(catalog))
145
+ return [];
146
+ const issues = [];
147
+ if ("multicast.auth" in catalog) {
148
+ issues.push({
149
+ code: "multicast_auth",
150
+ path: '$["multicast.auth"]',
151
+ message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -01 7.2.6)'
152
+ });
153
+ }
154
+ const multicast = catalog["multicast"];
155
+ if (!isObject(multicast))
156
+ return issues;
157
+ const protectedCatalog = multicast["auth"] !== void 0;
158
+ if (protectedCatalog)
159
+ issues.push(...authIssues(multicast["auth"]));
160
+ const endpoints = multicast["endpoints"];
161
+ if (!Array.isArray(endpoints))
162
+ return issues;
163
+ const tracks = Array.isArray(catalog["tracks"]) ? catalog["tracks"] : [];
164
+ const namespaceOf = /* @__PURE__ */ new Map();
165
+ for (const track of tracks) {
166
+ if (isObject(track) && typeof track["name"] === "string")
167
+ namespaceOf.set(track["name"], track["namespace"]);
168
+ }
169
+ const tagged = catalog[CATALOG_NAMESPACE];
170
+ let referenceNamespace = options.catalogNamespace ?? (typeof tagged === "string" ? tagged : void 0);
171
+ const sources = [];
172
+ for (let index = 0; index < endpoints.length; index++) {
173
+ const endpoint = endpoints[index];
174
+ const at = `$.multicast.endpoints[${index}]`;
175
+ const fail = (code, path, message) => {
176
+ issues.push({ code, path, message, endpointIndex: index });
177
+ };
178
+ sources.push(void 0);
179
+ if (!isObject(endpoint)) {
180
+ fail("multicast_endpoint", at, "endpoint must be an object");
181
+ continue;
182
+ }
183
+ const protocol = endpoint["protocol"];
184
+ if (protocol !== void 0 && protocol !== "ssm" && protocol !== "asm") {
185
+ fail("multicast_endpoint", `${at}.protocol`, `protocol must be "ssm" or "asm"; a bearer such as ${JSON.stringify(protocol)} is a networkSource entry (draft -01 4.2)`);
186
+ continue;
187
+ }
188
+ const hasAuth = endpoint["auth"] !== void 0;
189
+ if (protectedCatalog !== hasAuth) {
190
+ fail("multicast_endpoint_auth", `${at}.auth`, protectedCatalog ? "every endpoint requires auth when multicast carries auth; a receiver ignores this endpoint" : "auth names no key without multicast.auth; a receiver ignores this endpoint");
191
+ continue;
192
+ }
193
+ const sourceAddress = endpoint["sourceAddress"];
194
+ if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress)) {
195
+ fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be a non-empty string");
196
+ continue;
197
+ }
198
+ const mode = sourceAddress === void 0 ? "asm" : "ssm";
199
+ if (protocol !== void 0 && protocol !== mode) {
200
+ fail("multicast_endpoint", `${at}.protocol`, `protocol ${JSON.stringify(protocol)} disagrees with sourceAddress, which selects ${mode}`);
201
+ continue;
202
+ }
203
+ if (!isIntegerIn(endpoint["port"], 1, 65535)) {
204
+ fail("multicast_endpoint", `${at}.port`, "port must be an integer from 1 to 65535");
205
+ continue;
206
+ }
207
+ if (hasAuth) {
208
+ const authIssue = endpointAuthIssue(endpoint, mode, at);
209
+ if (authIssue) {
210
+ fail("multicast_endpoint_auth", authIssue.path, authIssue.message);
211
+ continue;
212
+ }
213
+ }
214
+ sources[index] = multicastEndpointSource(endpoint);
215
+ const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
216
+ for (let refIndex = 0; refIndex < refs.length; refIndex++) {
217
+ const ref = refs[refIndex];
218
+ const name = isObject(ref) ? ref["name"] : ref;
219
+ if (typeof name !== "string")
220
+ continue;
221
+ const namespace = namespaceOf.get(name);
222
+ if (typeof namespace !== "string")
223
+ continue;
224
+ referenceNamespace ??= namespace;
225
+ if (namespace !== referenceNamespace) {
226
+ fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} declares namespace ${JSON.stringify(namespace)}, not the catalog track's ${JSON.stringify(referenceNamespace)}`);
227
+ }
228
+ }
229
+ }
230
+ const tupleOf = (index) => {
231
+ const endpoint = endpoints[index];
232
+ const auth = endpoint["auth"];
233
+ return {
234
+ sg: JSON.stringify([sources[index].source ?? null, endpoint["groupAddress"]]),
235
+ port: endpoint["port"],
236
+ manifestPort: isObject(auth) ? auth["manifestPort"] : void 0
237
+ };
238
+ };
239
+ for (let index = 0; index < endpoints.length; index++) {
240
+ if (!sources[index])
241
+ continue;
242
+ const own = tupleOf(index);
243
+ const at = `$.multicast.endpoints[${index}]`;
244
+ if (own.manifestPort !== void 0 && own.manifestPort === own.port) {
245
+ issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
246
+ continue;
247
+ }
248
+ for (let other = 0; other < endpoints.length; other++) {
249
+ if (other === index || !sources[other])
250
+ continue;
251
+ const peer = tupleOf(other);
252
+ if (peer.sg !== own.sg)
253
+ continue;
254
+ if (peer.port === own.port) {
255
+ issues.push({ code: "multicast_endpoint", path: `${at}.port`, message: `(S, G, port) is shared with endpoint ${other}; one endpoint object per multicast tuple`, endpointIndex: index });
256
+ break;
257
+ }
258
+ if (own.manifestPort !== void 0 && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
259
+ issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: `manifestPort is a port or manifestPort of endpoint ${other} on the same (S, G)`, endpointIndex: index });
260
+ break;
261
+ }
262
+ }
263
+ }
264
+ return issues;
265
+ }
266
+
1
267
  // src/multicast-auth-catalog.ts
2
268
  var RAW_ED25519_KEY_LENGTH = 32;
3
- var SOURCE_AUTH_SCOPE_LENGTH = 32;
269
+ var DEFAULT_MAX_AUTH_DELAY_MS = 200;
270
+ var DEFAULT_MANIFEST_TIMER_MS = 20;
4
271
  var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
5
272
  function encodeBase64Url(bytes) {
6
273
  let output = "";
@@ -50,15 +317,6 @@ function decodeBase64Url(text) {
50
317
  }
51
318
  return decoded;
52
319
  }
53
- function decodeAuthScope(authScope) {
54
- const bytes = decodeBase64Url(authScope);
55
- if (bytes.byteLength !== SOURCE_AUTH_SCOPE_LENGTH) {
56
- throw new Error(
57
- `[multicast-auth-catalog] authScope must decode to ${SOURCE_AUTH_SCOPE_LENGTH} raw bytes, got ${bytes.byteLength}`
58
- );
59
- }
60
- return bytes;
61
- }
62
320
  function decodeEd25519PublicKey(publicKey) {
63
321
  const bytes = decodeBase64Url(publicKey);
64
322
  if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
@@ -68,135 +326,66 @@ function decodeEd25519PublicKey(publicKey) {
68
326
  }
69
327
  return bytes;
70
328
  }
71
- function isNonEmptyString(value) {
72
- return typeof value === "string" && value.length > 0;
73
- }
74
- function isValidAuthScopeField(value) {
75
- if (!isNonEmptyString(value)) return false;
76
- try {
77
- decodeAuthScope(value);
78
- return true;
79
- } catch {
80
- return false;
81
- }
82
- }
83
- function isValidPublicKeyField(value) {
84
- if (!isNonEmptyString(value)) return false;
85
- try {
86
- decodeEd25519PublicKey(value);
87
- return true;
88
- } catch {
89
- return false;
90
- }
91
- }
92
- function hasOnlyKeys(object, allowed) {
93
- const allowedKeys = new Set(allowed);
94
- return Object.keys(object).every((key) => allowedKeys.has(key));
95
- }
96
- function isMulticastAuthTrackConfig(obj) {
97
- if (typeof obj !== "object" || obj === null) return false;
98
- const o = obj;
99
- return hasOnlyKeys(o, ["mediaTrack", "manifestTrack", "authScope", "sourceSymbolFormat"]) && isNonEmptyString(o["mediaTrack"]) && isNonEmptyString(o["manifestTrack"]) && o["mediaTrack"] !== o["manifestTrack"] && isValidAuthScopeField(o["authScope"]) && isNonEmptyString(o["sourceSymbolFormat"]);
100
- }
101
- var VALID_COMPACTION = /* @__PURE__ */ new Set(["merkle", "none"]);
102
- var VALID_ENFORCEMENT = /* @__PURE__ */ new Set(["shadow", "enforce"]);
103
- function hasUniqueMulticastAuthTrackBindings(tracks) {
104
- const bindings = tracks.flatMap((track) => {
105
- if (typeof track !== "object" || track === null) return [];
106
- const value = track;
107
- if (typeof value["mediaTrack"] !== "string" || typeof value["sourceSymbolFormat"] !== "string") {
108
- return [];
109
- }
110
- return [JSON.stringify([value["mediaTrack"], value["sourceSymbolFormat"]])];
111
- });
112
- return new Set(bindings).size === bindings.length;
113
- }
114
329
  function isMulticastAuthConfig(obj) {
115
- if (typeof obj !== "object" || obj === null) return false;
116
- const o = obj;
117
- if (o["scheme"] !== "bc-provenance") return false;
118
- if (o["hash"] !== "blake3") return false;
119
- if (o["sig"] !== "ed25519") return false;
120
- if (!hasOnlyKeys(o, ["scheme", "hash", "sig", "publicKey", "keyId", "previousKey", "compaction", "enforcement", "tracks"])) return false;
121
- if (!isValidPublicKeyField(o["publicKey"])) return false;
122
- if (!isNonEmptyString(o["keyId"])) return false;
123
- if (o["previousKey"] !== void 0 && !isValidPublicKeyField(o["previousKey"])) return false;
124
- if (o["previousKey"] === o["publicKey"]) return false;
125
- if (typeof o["compaction"] !== "string" || !VALID_COMPACTION.has(o["compaction"])) return false;
126
- if (o["enforcement"] !== void 0) {
127
- if (typeof o["enforcement"] !== "string" || !VALID_ENFORCEMENT.has(o["enforcement"])) return false;
128
- }
129
- if (!Array.isArray(o["tracks"]) || o["tracks"].length === 0) return false;
130
- const tracks = o["tracks"];
131
- if (!tracks.every((t) => isMulticastAuthTrackConfig(t))) return false;
132
- const typedTracks = tracks;
133
- const scopes = typedTracks.map((t) => t.authScope);
134
- if (new Set(scopes).size !== scopes.length) return false;
135
- if (!hasUniqueMulticastAuthTrackBindings(typedTracks)) return false;
136
- const manifestTracks = typedTracks.map((t) => t.manifestTrack);
137
- if (new Set(manifestTracks).size !== manifestTracks.length) return false;
138
- return true;
330
+ return multicastCatalogIssues({ multicast: { auth: obj } }).length === 0;
139
331
  }
140
- function resolveMulticastAuthMode(playerMode, auth) {
141
- if (playerMode !== void 0) return playerMode;
142
- if (auth === void 0) return "off";
143
- return auth.enforcement ?? "shadow";
144
- }
145
- function resolveMulticastAuthCatalog(catalog, playerMode) {
332
+ function resolveMulticastAuthCatalog(catalog, options = {}) {
146
333
  if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
147
334
  throw new Error("[multicast-auth-catalog] catalog must be an object");
148
335
  }
149
- const root = catalog;
150
- const rawAuth = root["multicast.auth"];
151
- if (rawAuth === void 0) {
152
- if (playerMode === "enforce") {
153
- throw new Error("[multicast-auth-catalog] player enforce mode requires multicast.auth");
336
+ const issues = multicastCatalogIssues(catalog, options);
337
+ const fatal = issues.find((issue) => issue.endpointIndex === void 0);
338
+ if (fatal) throw new Error(`[multicast-auth-catalog] ${fatal.path}: ${fatal.message}`);
339
+ const multicast = catalog["multicast"];
340
+ const auth = multicast?.["auth"];
341
+ if (auth === void 0) {
342
+ if (options.requireAuth) {
343
+ throw new Error("[multicast-auth-catalog] authentication is pinned but the catalog declares no multicast.auth");
154
344
  }
155
345
  return void 0;
156
346
  }
157
- if (!isMulticastAuthConfig(rawAuth)) {
158
- throw new Error("[multicast-auth-catalog] invalid multicast.auth v2 block");
159
- }
160
- const rawTracks = root["tracks"];
161
- if (!Array.isArray(rawTracks)) {
162
- throw new Error("[multicast-auth-catalog] catalog tracks must be an array");
163
- }
164
- const catalogTrackNames = new Set(
165
- rawTracks.flatMap(
166
- (track) => typeof track === "object" && track !== null && typeof track["name"] === "string" ? [track["name"]] : []
167
- )
168
- );
169
- for (const track of rawAuth.tracks) {
170
- if (!catalogTrackNames.has(track.mediaTrack)) {
171
- throw new Error(`[multicast-auth-catalog] unknown mediaTrack "${track.mediaTrack}"`);
172
- }
173
- if (!catalogTrackNames.has(track.manifestTrack)) {
174
- throw new Error(`[multicast-auth-catalog] unknown manifestTrack "${track.manifestTrack}"`);
175
- }
176
- }
347
+ const ignored = new Set(issues.map((issue) => issue.endpointIndex));
348
+ const endpoints = multicast["endpoints"] ?? [];
349
+ const flows = [];
350
+ endpoints.forEach((endpoint, endpointIndex) => {
351
+ if (ignored.has(endpointIndex)) return;
352
+ const flowAuth = endpoint["auth"];
353
+ flows.push({
354
+ endpointIndex,
355
+ source: endpoint["sourceAddress"] ?? flowAuth.senderAddress,
356
+ groupAddress: endpoint["groupAddress"],
357
+ port: endpoint["port"],
358
+ bandwidth: endpoint["bandwidth"],
359
+ manifestPort: flowAuth.manifestPort,
360
+ streamId: flowAuth.streamId,
361
+ maxAuthDelayMs: flowAuth.maxAuthDelayMs ?? DEFAULT_MAX_AUTH_DELAY_MS,
362
+ manifestTimerMs: flowAuth.manifestTimerMs ?? DEFAULT_MANIFEST_TIMER_MS,
363
+ ...flowAuth.manifestTrack === void 0 ? {} : { manifestTrack: flowAuth.manifestTrack },
364
+ tracks: (endpoint["tracks"] ?? []).map(({ name, packetId }) => ({
365
+ name,
366
+ packetId
367
+ }))
368
+ });
369
+ });
177
370
  return {
178
- keyId: rawAuth.keyId,
179
- acceptedPublicKeys: [
180
- decodeEd25519PublicKey(rawAuth.publicKey),
181
- ...rawAuth.previousKey === void 0 ? [] : [decodeEd25519PublicKey(rawAuth.previousKey)]
182
- ],
183
- mode: resolveMulticastAuthMode(playerMode, rawAuth),
184
- compaction: rawAuth.compaction,
185
- tracks: rawAuth.tracks.map((track) => ({
186
- ...track,
187
- authScope: decodeAuthScope(track.authScope)
188
- }))
371
+ keys: auth.keys.map((key) => ({ kid: key.kid, publicKey: decodeEd25519PublicKey(key.publicKey), firstEpoch: key.firstEpoch })).sort((a, b) => a.firstEpoch - b.firstEpoch),
372
+ minEpoch: auth.minEpoch,
373
+ flows
189
374
  };
190
375
  }
376
+ function multicastAuthKeyFor(resolved, kid, epoch) {
377
+ const signers = resolved.keys.filter((key) => key.firstEpoch <= epoch);
378
+ const signer = signers[signers.length - 1];
379
+ return signer?.kid === kid ? signer.publicKey : void 0;
380
+ }
191
381
  export {
192
- decodeAuthScope,
382
+ DEFAULT_MANIFEST_TIMER_MS,
383
+ DEFAULT_MAX_AUTH_DELAY_MS,
193
384
  decodeBase64Url,
194
385
  decodeEd25519PublicKey,
195
386
  encodeBase64Url,
196
- hasUniqueMulticastAuthTrackBindings,
197
387
  isMulticastAuthConfig,
198
- isMulticastAuthTrackConfig,
199
- resolveMulticastAuthCatalog,
200
- resolveMulticastAuthMode
388
+ multicastAuthKeyFor,
389
+ resolveMulticastAuthCatalog
201
390
  };
202
391
  //# sourceMappingURL=multicast-auth-catalog.js.map