@blockcast/mmt-container 0.4.0 → 0.4.1-main.2e0aa69d293d

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 +5070 -908
  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 +115 -235
  29. package/dist/delivery-catalog.js.map +4 -4
  30. package/dist/fec-manager.d.ts +113 -1
  31. package/dist/fec-manager.d.ts.map +1 -1
  32. package/dist/fec-manager.js +464 -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 +3692 -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 +101 -32
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +422 -189
  70. package/dist/mmtp-router.js.map +2 -2
  71. package/dist/multicast-auth-catalog.d.ts +94 -92
  72. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  73. package/dist/multicast-auth-catalog.js +746 -131
  74. package/dist/multicast-auth-catalog.js.map +4 -4
  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 +140 -12
  80. package/dist/multicast-manager.d.ts.map +1 -1
  81. package/dist/multicast-manager.js +4104 -605
  82. package/dist/multicast-manager.js.map +4 -4
  83. package/dist/multicast-transport.d.ts +16 -3
  84. package/dist/multicast-transport.d.ts.map +1 -1
  85. package/dist/multicast-transport.js +127 -240
  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 +3643 -1197
  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 +90 -6
  98. package/dist/repair-fetch.d.ts.map +1 -1
  99. package/dist/repair-fetch.js +160 -32
  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 +378 -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 +453 -236
  137. package/src/multicast-auth-catalog.ts +196 -231
  138. package/src/multicast-input.ts +148 -124
  139. package/src/multicast-manager.ts +447 -53
  140. package/src/multicast-transport.ts +23 -5
  141. package/src/no-modules.ts +8 -7
  142. package/src/phase14-catalog-override.ts +3 -3
  143. package/src/repair-fetch.ts +306 -42
  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,652 @@
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
+
267
+ // ../mmt-manifest-verify/node_modules/@noble/hashes/esm/utils.js
268
+ function isBytes(a) {
269
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
270
+ }
271
+ function abytes(b, ...lengths) {
272
+ if (!isBytes(b))
273
+ throw new Error("Uint8Array expected");
274
+ if (lengths.length > 0 && !lengths.includes(b.length))
275
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
276
+ }
277
+ function aexists(instance, checkFinished = true) {
278
+ if (instance.destroyed)
279
+ throw new Error("Hash instance has been destroyed");
280
+ if (checkFinished && instance.finished)
281
+ throw new Error("Hash#digest() has already been called");
282
+ }
283
+ function aoutput(out, instance) {
284
+ abytes(out);
285
+ const min = instance.outputLen;
286
+ if (out.length < min) {
287
+ throw new Error("digestInto() expects output buffer of length at least " + min);
288
+ }
289
+ }
290
+ function clean(...arrays) {
291
+ for (let i = 0; i < arrays.length; i++) {
292
+ arrays[i].fill(0);
293
+ }
294
+ }
295
+ function createView(arr) {
296
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
297
+ }
298
+ function rotr(word, shift) {
299
+ return word << 32 - shift | word >>> shift;
300
+ }
301
+ function utf8ToBytes(str) {
302
+ if (typeof str !== "string")
303
+ throw new Error("string expected");
304
+ return new Uint8Array(new TextEncoder().encode(str));
305
+ }
306
+ function toBytes(data) {
307
+ if (typeof data === "string")
308
+ data = utf8ToBytes(data);
309
+ abytes(data);
310
+ return data;
311
+ }
312
+ var Hash = class {
313
+ };
314
+ function createHasher(hashCons) {
315
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
316
+ const tmp = hashCons();
317
+ hashC.outputLen = tmp.outputLen;
318
+ hashC.blockLen = tmp.blockLen;
319
+ hashC.create = () => hashCons();
320
+ return hashC;
321
+ }
322
+
323
+ // ../mmt-manifest-verify/node_modules/@noble/hashes/esm/_md.js
324
+ function setBigUint64(view, byteOffset, value, isLE) {
325
+ if (typeof view.setBigUint64 === "function")
326
+ return view.setBigUint64(byteOffset, value, isLE);
327
+ const _32n = BigInt(32);
328
+ const _u32_max = BigInt(4294967295);
329
+ const wh = Number(value >> _32n & _u32_max);
330
+ const wl = Number(value & _u32_max);
331
+ const h = isLE ? 4 : 0;
332
+ const l = isLE ? 0 : 4;
333
+ view.setUint32(byteOffset + h, wh, isLE);
334
+ view.setUint32(byteOffset + l, wl, isLE);
335
+ }
336
+ function Chi(a, b, c) {
337
+ return a & b ^ ~a & c;
338
+ }
339
+ function Maj(a, b, c) {
340
+ return a & b ^ a & c ^ b & c;
341
+ }
342
+ var HashMD = class extends Hash {
343
+ constructor(blockLen, outputLen, padOffset, isLE) {
344
+ super();
345
+ this.finished = false;
346
+ this.length = 0;
347
+ this.pos = 0;
348
+ this.destroyed = false;
349
+ this.blockLen = blockLen;
350
+ this.outputLen = outputLen;
351
+ this.padOffset = padOffset;
352
+ this.isLE = isLE;
353
+ this.buffer = new Uint8Array(blockLen);
354
+ this.view = createView(this.buffer);
355
+ }
356
+ update(data) {
357
+ aexists(this);
358
+ data = toBytes(data);
359
+ abytes(data);
360
+ const { view, buffer, blockLen } = this;
361
+ const len = data.length;
362
+ for (let pos = 0; pos < len; ) {
363
+ const take = Math.min(blockLen - this.pos, len - pos);
364
+ if (take === blockLen) {
365
+ const dataView = createView(data);
366
+ for (; blockLen <= len - pos; pos += blockLen)
367
+ this.process(dataView, pos);
368
+ continue;
369
+ }
370
+ buffer.set(data.subarray(pos, pos + take), this.pos);
371
+ this.pos += take;
372
+ pos += take;
373
+ if (this.pos === blockLen) {
374
+ this.process(view, 0);
375
+ this.pos = 0;
376
+ }
377
+ }
378
+ this.length += data.length;
379
+ this.roundClean();
380
+ return this;
381
+ }
382
+ digestInto(out) {
383
+ aexists(this);
384
+ aoutput(out, this);
385
+ this.finished = true;
386
+ const { buffer, view, blockLen, isLE } = this;
387
+ let { pos } = this;
388
+ buffer[pos++] = 128;
389
+ clean(this.buffer.subarray(pos));
390
+ if (this.padOffset > blockLen - pos) {
391
+ this.process(view, 0);
392
+ pos = 0;
393
+ }
394
+ for (let i = pos; i < blockLen; i++)
395
+ buffer[i] = 0;
396
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
397
+ this.process(view, 0);
398
+ const oview = createView(out);
399
+ const len = this.outputLen;
400
+ if (len % 4)
401
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
402
+ const outLen = len / 4;
403
+ const state = this.get();
404
+ if (outLen > state.length)
405
+ throw new Error("_sha2: outputLen bigger than state");
406
+ for (let i = 0; i < outLen; i++)
407
+ oview.setUint32(4 * i, state[i], isLE);
408
+ }
409
+ digest() {
410
+ const { buffer, outputLen } = this;
411
+ this.digestInto(buffer);
412
+ const res = buffer.slice(0, outputLen);
413
+ this.destroy();
414
+ return res;
415
+ }
416
+ _cloneInto(to) {
417
+ to || (to = new this.constructor());
418
+ to.set(...this.get());
419
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
420
+ to.destroyed = destroyed;
421
+ to.finished = finished;
422
+ to.length = length;
423
+ to.pos = pos;
424
+ if (length % blockLen)
425
+ to.buffer.set(buffer);
426
+ return to;
427
+ }
428
+ clone() {
429
+ return this._cloneInto();
430
+ }
431
+ };
432
+ var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
433
+ 1779033703,
434
+ 3144134277,
435
+ 1013904242,
436
+ 2773480762,
437
+ 1359893119,
438
+ 2600822924,
439
+ 528734635,
440
+ 1541459225
441
+ ]);
442
+
443
+ // ../mmt-manifest-verify/node_modules/@noble/hashes/esm/sha2.js
444
+ var SHA256_K = /* @__PURE__ */ Uint32Array.from([
445
+ 1116352408,
446
+ 1899447441,
447
+ 3049323471,
448
+ 3921009573,
449
+ 961987163,
450
+ 1508970993,
451
+ 2453635748,
452
+ 2870763221,
453
+ 3624381080,
454
+ 310598401,
455
+ 607225278,
456
+ 1426881987,
457
+ 1925078388,
458
+ 2162078206,
459
+ 2614888103,
460
+ 3248222580,
461
+ 3835390401,
462
+ 4022224774,
463
+ 264347078,
464
+ 604807628,
465
+ 770255983,
466
+ 1249150122,
467
+ 1555081692,
468
+ 1996064986,
469
+ 2554220882,
470
+ 2821834349,
471
+ 2952996808,
472
+ 3210313671,
473
+ 3336571891,
474
+ 3584528711,
475
+ 113926993,
476
+ 338241895,
477
+ 666307205,
478
+ 773529912,
479
+ 1294757372,
480
+ 1396182291,
481
+ 1695183700,
482
+ 1986661051,
483
+ 2177026350,
484
+ 2456956037,
485
+ 2730485921,
486
+ 2820302411,
487
+ 3259730800,
488
+ 3345764771,
489
+ 3516065817,
490
+ 3600352804,
491
+ 4094571909,
492
+ 275423344,
493
+ 430227734,
494
+ 506948616,
495
+ 659060556,
496
+ 883997877,
497
+ 958139571,
498
+ 1322822218,
499
+ 1537002063,
500
+ 1747873779,
501
+ 1955562222,
502
+ 2024104815,
503
+ 2227730452,
504
+ 2361852424,
505
+ 2428436474,
506
+ 2756734187,
507
+ 3204031479,
508
+ 3329325298
509
+ ]);
510
+ var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
511
+ var SHA256 = class extends HashMD {
512
+ constructor(outputLen = 32) {
513
+ super(64, outputLen, 8, false);
514
+ this.A = SHA256_IV[0] | 0;
515
+ this.B = SHA256_IV[1] | 0;
516
+ this.C = SHA256_IV[2] | 0;
517
+ this.D = SHA256_IV[3] | 0;
518
+ this.E = SHA256_IV[4] | 0;
519
+ this.F = SHA256_IV[5] | 0;
520
+ this.G = SHA256_IV[6] | 0;
521
+ this.H = SHA256_IV[7] | 0;
522
+ }
523
+ get() {
524
+ const { A, B, C, D, E, F, G, H } = this;
525
+ return [A, B, C, D, E, F, G, H];
526
+ }
527
+ // prettier-ignore
528
+ set(A, B, C, D, E, F, G, H) {
529
+ this.A = A | 0;
530
+ this.B = B | 0;
531
+ this.C = C | 0;
532
+ this.D = D | 0;
533
+ this.E = E | 0;
534
+ this.F = F | 0;
535
+ this.G = G | 0;
536
+ this.H = H | 0;
537
+ }
538
+ process(view, offset) {
539
+ for (let i = 0; i < 16; i++, offset += 4)
540
+ SHA256_W[i] = view.getUint32(offset, false);
541
+ for (let i = 16; i < 64; i++) {
542
+ const W15 = SHA256_W[i - 15];
543
+ const W2 = SHA256_W[i - 2];
544
+ const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
545
+ const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
546
+ SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
547
+ }
548
+ let { A, B, C, D, E, F, G, H } = this;
549
+ for (let i = 0; i < 64; i++) {
550
+ const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
551
+ const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
552
+ const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
553
+ const T2 = sigma0 + Maj(A, B, C) | 0;
554
+ H = G;
555
+ G = F;
556
+ F = E;
557
+ E = D + T1 | 0;
558
+ D = C;
559
+ C = B;
560
+ B = A;
561
+ A = T1 + T2 | 0;
562
+ }
563
+ A = A + this.A | 0;
564
+ B = B + this.B | 0;
565
+ C = C + this.C | 0;
566
+ D = D + this.D | 0;
567
+ E = E + this.E | 0;
568
+ F = F + this.F | 0;
569
+ G = G + this.G | 0;
570
+ H = H + this.H | 0;
571
+ this.set(A, B, C, D, E, F, G, H);
572
+ }
573
+ roundClean() {
574
+ clean(SHA256_W);
575
+ }
576
+ destroy() {
577
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
578
+ clean(this.buffer);
579
+ }
580
+ };
581
+ var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
582
+
583
+ // ../mmt-manifest-verify/node_modules/@noble/hashes/esm/sha256.js
584
+ var sha2562 = sha256;
585
+
586
+ // ../mmt-manifest-verify/dist/bc-provenance-v2.js
587
+ var BCPV2_HEADER_LENGTH = 68;
588
+ var BCPV2_SIGNATURE_LENGTH = 64;
589
+ var BCPV2_MIN_RECORD_LENGTH = BCPV2_HEADER_LENGTH + 32 + BCPV2_SIGNATURE_LENGTH;
590
+ var text = new TextEncoder();
591
+ var MAGIC = Uint8Array.from([77, 72, 77, 50]);
592
+ var SIGNING_DOMAIN = text.encode("mcast-manifest-v2\0");
593
+ function u16(value) {
594
+ const result = new Uint8Array(2);
595
+ new DataView(result.buffer).setUint16(0, value);
596
+ return result;
597
+ }
598
+ function u32(value) {
599
+ const result = new Uint8Array(4);
600
+ new DataView(result.buffer).setUint32(0, value);
601
+ return result;
602
+ }
603
+ function concat(parts) {
604
+ const out = new Uint8Array(parts.reduce((n, p) => n + p.byteLength, 0));
605
+ let offset = 0;
606
+ for (const part of parts) {
607
+ out.set(part, offset);
608
+ offset += part.byteLength;
609
+ }
610
+ return out;
611
+ }
612
+ function lp16(value) {
613
+ const bytes = typeof value === "string" ? text.encode(value) : value;
614
+ if (bytes.byteLength > 65535)
615
+ throw new Error("lp16 field exceeds u16 length");
616
+ return concat([u16(bytes.byteLength), bytes]);
617
+ }
618
+ function bcProvenanceV2ParamsHash(params) {
619
+ const fec = params.fec;
620
+ return sha2562(concat([
621
+ text.encode("BCPV2-params"),
622
+ lp16(params.codec),
623
+ u32(params.timescale),
624
+ u32(params.groupDurationTicks),
625
+ lp16(fec ? fec.algorithm : "none"),
626
+ u32(fec?.sourceSymbols ?? 0),
627
+ u32(fec?.repairSymbols ?? 0),
628
+ u32(fec?.symbolSize ?? 0),
629
+ u32(fec?.interleaveDepthMs ?? 0)
630
+ ]));
631
+ }
632
+ function bcProvenanceV2Ctx(namespace, packetIds, params) {
633
+ const ids = [...packetIds].sort((a, b) => a - b);
634
+ if (namespace.length > 65535 || ids.length > 65535)
635
+ throw new Error("ctx field count exceeds u16");
636
+ return sha2562(concat([
637
+ text.encode("BCPV2-ctx"),
638
+ u16(namespace.length),
639
+ ...namespace.map(lp16),
640
+ u16(ids.length),
641
+ ...ids.map(u16),
642
+ bcProvenanceV2ParamsHash(params)
643
+ ]));
644
+ }
645
+
1
646
  // src/multicast-auth-catalog.ts
2
647
  var RAW_ED25519_KEY_LENGTH = 32;
3
- var SOURCE_AUTH_SCOPE_LENGTH = 32;
648
+ var DEFAULT_MAX_AUTH_DELAY_MS = 200;
649
+ var DEFAULT_MANIFEST_TIMER_MS = 20;
4
650
  var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
5
651
  function encodeBase64Url(bytes) {
6
652
  let output = "";
@@ -24,18 +670,18 @@ var BASE64URL_DECODE_TABLE = (() => {
24
670
  }
25
671
  return table;
26
672
  })();
27
- function decodeBase64Url(text) {
28
- if (text.length % 4 === 1) {
29
- throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text}"`);
673
+ function decodeBase64Url(text2) {
674
+ if (text2.length % 4 === 1) {
675
+ throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text2}"`);
30
676
  }
31
677
  const bytes = [];
32
678
  let buffer = 0;
33
679
  let bits = 0;
34
- for (let i = 0; i < text.length; i++) {
35
- const code = text.charCodeAt(i);
680
+ for (let i = 0; i < text2.length; i++) {
681
+ const code = text2.charCodeAt(i);
36
682
  const value = code < 128 ? BASE64URL_DECODE_TABLE[code] : -1;
37
683
  if (value === void 0 || value < 0) {
38
- throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text}"`);
684
+ throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text2}"`);
39
685
  }
40
686
  buffer = buffer << 6 | value;
41
687
  bits += 6;
@@ -45,20 +691,11 @@ function decodeBase64Url(text) {
45
691
  }
46
692
  }
47
693
  const decoded = Uint8Array.from(bytes);
48
- if (encodeBase64Url(decoded) !== text) {
49
- throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text}"`);
694
+ if (encodeBase64Url(decoded) !== text2) {
695
+ throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text2}"`);
50
696
  }
51
697
  return decoded;
52
698
  }
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
699
  function decodeEd25519PublicKey(publicKey) {
63
700
  const bytes = decodeBase64Url(publicKey);
64
701
  if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
@@ -68,135 +705,113 @@ function decodeEd25519PublicKey(publicKey) {
68
705
  }
69
706
  return bytes;
70
707
  }
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
708
  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;
139
- }
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) {
709
+ return multicastCatalogIssues({ multicast: { auth: obj } }).length === 0;
710
+ }
711
+ function resolveMulticastAuthCatalog(catalog, options = {}) {
146
712
  if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
147
713
  throw new Error("[multicast-auth-catalog] catalog must be an object");
148
714
  }
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");
715
+ const issues = multicastCatalogIssues(catalog, options);
716
+ const fatal = issues.find((issue) => issue.endpointIndex === void 0);
717
+ if (fatal) throw new Error(`[multicast-auth-catalog] ${fatal.path}: ${fatal.message}`);
718
+ const multicast = catalog["multicast"];
719
+ const auth = multicast?.["auth"];
720
+ if (auth === void 0) {
721
+ if (options.requireAuth) {
722
+ throw new Error("[multicast-auth-catalog] authentication is pinned but the catalog declares no multicast.auth");
154
723
  }
155
724
  return void 0;
156
725
  }
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}"`);
726
+ const ignored = new Set(issues.map((issue) => issue.endpointIndex));
727
+ const endpoints = multicast["endpoints"] ?? [];
728
+ const catalogTracks = catalog["tracks"] ?? [];
729
+ const flows = [];
730
+ endpoints.forEach((endpoint, endpointIndex) => {
731
+ if (ignored.has(endpointIndex)) return;
732
+ const flowAuth = endpoint["auth"];
733
+ const tracks = (endpoint["tracks"] ?? []).map(({ name, packetId }) => ({
734
+ name,
735
+ packetId
736
+ }));
737
+ let ctx;
738
+ if (options.namespaceFields !== void 0) {
739
+ const params = ctxParams(catalogTracks, tracks);
740
+ if (params === void 0) return;
741
+ ctx = bcProvenanceV2Ctx(options.namespaceFields, tracks.map((track) => track.packetId), params);
175
742
  }
743
+ flows.push({
744
+ endpointIndex,
745
+ source: endpoint["sourceAddress"] ?? flowAuth.senderAddress,
746
+ groupAddress: endpoint["groupAddress"],
747
+ port: endpoint["port"],
748
+ bandwidth: endpoint["bandwidth"],
749
+ manifestPort: flowAuth.manifestPort,
750
+ streamId: flowAuth.streamId,
751
+ maxAuthDelayMs: flowAuth.maxAuthDelayMs ?? DEFAULT_MAX_AUTH_DELAY_MS,
752
+ manifestTimerMs: flowAuth.manifestTimerMs ?? DEFAULT_MANIFEST_TIMER_MS,
753
+ ...flowAuth.manifestTrack === void 0 ? {} : { manifestTrack: flowAuth.manifestTrack },
754
+ tracks,
755
+ ...ctx === void 0 ? {} : { ctx }
756
+ });
757
+ });
758
+ return {
759
+ keys: auth.keys.map((key) => ({ kid: key.kid, publicKey: decodeEd25519PublicKey(key.publicKey), firstEpoch: key.firstEpoch })).sort((a, b) => a.firstEpoch - b.firstEpoch),
760
+ minEpoch: auth.minEpoch,
761
+ flows
762
+ };
763
+ }
764
+ function positiveInteger(value) {
765
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 0;
766
+ }
767
+ function ctxParams(catalogTracks, listed) {
768
+ const byName = new Map(catalogTracks.map((track) => [track["name"], track]));
769
+ const ordered = [...listed].sort((a, b) => a.packetId - b.packetId).map(({ name }) => byName.get(name));
770
+ let entry = ordered.find((track) => track !== void 0 && track["packaging"] !== "fec-repair");
771
+ if (entry === void 0) {
772
+ const repair = ordered.find((track) => track !== void 0);
773
+ if (repair === void 0) return void 0;
774
+ const depends = repair["depends"];
775
+ entry = Array.isArray(depends) && depends.length === 1 ? byName.get(depends[0]) : catalogTracks.find((track) => track["fec"]?.["repairTrack"] === repair["name"]);
776
+ if (entry === void 0) return void 0;
176
777
  }
778
+ const timescale = positiveInteger(entry["timescale"]);
779
+ const ms = positiveInteger(entry["groupDurationMs"]);
780
+ const groupDurationTicks = positiveInteger(entry["groupDurationTicks"]) || (timescale && ms * timescale % 1e3 === 0 ? ms * timescale / 1e3 : 0);
781
+ const fec = entry["fec"];
177
782
  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
- }))
783
+ codec: typeof entry["codec"] === "string" ? entry["codec"] : "",
784
+ timescale,
785
+ groupDurationTicks,
786
+ ...fec === void 0 || fec === null ? {} : {
787
+ fec: {
788
+ algorithm: String(fec["algorithm"]),
789
+ sourceSymbols: Number(fec["sourceSymbols"] ?? 0),
790
+ repairSymbols: Number(fec["repairSymbols"] ?? 0),
791
+ symbolSize: Number(fec["symbolSize"] ?? 0),
792
+ interleaveDepthMs: Number(fec["interleaveDepthMs"] ?? 0)
793
+ }
794
+ }
189
795
  };
190
796
  }
797
+ function multicastAuthKeyFor(resolved, kid, epoch) {
798
+ const signers = resolved.keys.filter((key) => key.firstEpoch <= epoch);
799
+ const signer = signers[signers.length - 1];
800
+ return signer?.kid === kid ? signer.publicKey : void 0;
801
+ }
191
802
  export {
192
- decodeAuthScope,
803
+ DEFAULT_MANIFEST_TIMER_MS,
804
+ DEFAULT_MAX_AUTH_DELAY_MS,
193
805
  decodeBase64Url,
194
806
  decodeEd25519PublicKey,
195
807
  encodeBase64Url,
196
- hasUniqueMulticastAuthTrackBindings,
197
808
  isMulticastAuthConfig,
198
- isMulticastAuthTrackConfig,
199
- resolveMulticastAuthCatalog,
200
- resolveMulticastAuthMode
809
+ multicastAuthKeyFor,
810
+ resolveMulticastAuthCatalog
201
811
  };
812
+ /*! Bundled license information:
813
+
814
+ @noble/hashes/esm/utils.js:
815
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
816
+ */
202
817
  //# sourceMappingURL=multicast-auth-catalog.js.map