@blockcast/mmt-container 0.4.0 → 0.4.1-main.47aa22331187

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 (210) hide show
  1. package/README.md +36 -20
  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 +1839 -692
  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 +8 -0
  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 +121 -1
  31. package/dist/fec-manager.d.ts.map +1 -1
  32. package/dist/fec-manager.js +421 -66
  33. package/dist/fec-manager.js.map +3 -3
  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/index.d.ts +5 -5
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +8 -8
  45. package/dist/index.js.map +2 -2
  46. package/dist/iso-block-locator.d.ts +39 -1
  47. package/dist/iso-block-locator.d.ts.map +1 -1
  48. package/dist/iso-block-locator.js +109 -17
  49. package/dist/iso-block-locator.js.map +3 -3
  50. package/dist/manifest-auth-plan.d.ts +26 -25
  51. package/dist/manifest-auth-plan.d.ts.map +1 -1
  52. package/dist/manifest-auth-plan.js +331 -1171
  53. package/dist/manifest-auth-plan.js.map +4 -4
  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 +1137 -317
  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 +159 -0
  64. package/dist/mmtp-fec-session.d.ts.map +1 -0
  65. package/dist/mmtp-fec-session.js +531 -0
  66. package/dist/mmtp-fec-session.js.map +7 -0
  67. package/dist/mmtp-router.d.ts +39 -6
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +184 -27
  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 +347 -132
  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 +94 -5
  80. package/dist/multicast-manager.d.ts.map +1 -1
  81. package/dist/multicast-manager.js +877 -357
  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 +4 -1
  90. package/dist/no-modules.d.ts.map +1 -1
  91. package/dist/no-modules.js +1086 -301
  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/source-auth.js +2710 -7
  114. package/dist/source-auth.js.map +4 -4
  115. package/dist/switching-set-alignment.d.ts +1 -1
  116. package/dist/switching-set-alignment.js.map +1 -1
  117. package/dist/timestamp-codec.js +21 -13
  118. package/dist/timestamp-codec.js.map +2 -2
  119. package/dist/wasm-mfu-reassembler.js.map +1 -1
  120. package/dist/wasm-mmtp-container-parser.js +93 -22
  121. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  122. package/package.json +6 -9
  123. package/schemas/catalog.schema.json +133 -38
  124. package/src/align.ts +52 -21
  125. package/src/carp-catalog.ts +188 -68
  126. package/src/catalog-fec-params.ts +28 -3
  127. package/src/catalog-network-source.ts +49 -7
  128. package/src/catalog-validator.ts +4 -11
  129. package/src/cmcd-producer.ts +17 -0
  130. package/src/fec-manager.ts +452 -63
  131. package/src/fec-state.ts +11 -4
  132. package/src/fec-worker-setup.ts +30 -2
  133. package/src/index.ts +27 -10
  134. package/src/iso-block-locator.ts +110 -7
  135. package/src/manifest-auth-plan.ts +39 -91
  136. package/src/mmtp-container-parser.ts +75 -7
  137. package/src/mmtp-fec-session.ts +533 -0
  138. package/src/mmtp-router.ts +166 -7
  139. package/src/multicast-auth-catalog.ts +131 -238
  140. package/src/multicast-input.ts +148 -124
  141. package/src/multicast-manager.ts +267 -21
  142. package/src/multicast-transport.ts +17 -3
  143. package/src/no-modules.ts +7 -1
  144. package/src/phase14-catalog-override.ts +3 -3
  145. package/src/repair-fetch.ts +283 -39
  146. package/src/repair-layers.ts +22 -2
  147. package/src/sample-combiner.ts +15 -2
  148. package/src/signaling.ts +2 -2
  149. package/src/switching-set-alignment.ts +1 -1
  150. package/test-vectors/align.json +108 -32
  151. package/test-vectors/bc-provenance-v2.json +1526 -0
  152. package/test-vectors/catalog/README.md +71 -4
  153. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  154. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  155. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  156. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  157. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  158. package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
  159. package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
  160. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  161. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  162. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  163. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  164. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  165. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  166. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  167. package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
  168. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  169. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  170. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  171. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  172. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  173. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  174. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  175. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  176. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
  177. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
  178. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  179. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  180. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  181. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  182. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  183. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  184. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  185. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  186. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  187. package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
  188. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  189. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  190. package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
  191. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  192. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  193. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  194. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
  195. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  196. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  197. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  198. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  199. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  200. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  201. package/test-vectors/catalog/section-codes.json +31 -1
  202. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  203. package/test-vectors/catalog-validation.json +101 -5
  204. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  205. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
  206. package/dist/fec-codec.d.ts +0 -32
  207. package/dist/fec-codec.d.ts.map +0 -1
  208. package/dist/fec-codec.js +0 -47
  209. package/dist/fec-codec.js.map +0 -7
  210. package/src/fec-codec.ts +0 -61
@@ -1,6 +1,301 @@
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/dist/source-auth.js
268
+ var SOURCE_AUTH_MAX_TRUE_LENGTH = 16 * 1024 * 1024;
269
+ var SIGNATURE_DOMAIN = new TextEncoder().encode("blockcast-mmt-root-v1\0\0\0");
270
+
271
+ // ../mmt-manifest-verify/dist/verifier.js
272
+ function manifestKeyFor(keys, epoch, kid) {
273
+ if (new Set(keys.map((key) => key.kid)).size !== keys.length)
274
+ return void 0;
275
+ if (new Set(keys.map((key) => key.firstEpoch)).size !== keys.length)
276
+ return void 0;
277
+ let signer;
278
+ for (const key of keys) {
279
+ if (key.firstEpoch <= epoch && (signer === void 0 || key.firstEpoch > signer.firstEpoch))
280
+ signer = key;
281
+ }
282
+ if (signer === void 0 || kid !== void 0 && signer.kid !== kid)
283
+ return void 0;
284
+ return signer.publicKey;
285
+ }
286
+
287
+ // ../mmt-manifest-verify/dist/bc-provenance-v2.js
288
+ var BCPV2_HEADER_LENGTH = 68;
289
+ var BCPV2_SIGNATURE_LENGTH = 64;
290
+ var BCPV2_MIN_RECORD_LENGTH = BCPV2_HEADER_LENGTH + 32 + BCPV2_SIGNATURE_LENGTH;
291
+ var text = new TextEncoder();
292
+ var MAGIC = Uint8Array.from([77, 72, 77, 50]);
293
+ var SIGNING_DOMAIN = text.encode("mcast-manifest-v2\0");
294
+
1
295
  // src/multicast-auth-catalog.ts
2
296
  var RAW_ED25519_KEY_LENGTH = 32;
3
- var SOURCE_AUTH_SCOPE_LENGTH = 32;
297
+ var DEFAULT_MAX_AUTH_DELAY_MS = 200;
298
+ var DEFAULT_MANIFEST_TIMER_MS = 20;
4
299
  var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
5
300
  function encodeBase64Url(bytes) {
6
301
  let output = "";
@@ -24,18 +319,18 @@ var BASE64URL_DECODE_TABLE = (() => {
24
319
  }
25
320
  return table;
26
321
  })();
27
- function decodeBase64Url(text) {
28
- if (text.length % 4 === 1) {
29
- throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text}"`);
322
+ function decodeBase64Url(text2) {
323
+ if (text2.length % 4 === 1) {
324
+ throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text2}"`);
30
325
  }
31
326
  const bytes = [];
32
327
  let buffer = 0;
33
328
  let bits = 0;
34
- for (let i = 0; i < text.length; i++) {
35
- const code = text.charCodeAt(i);
329
+ for (let i = 0; i < text2.length; i++) {
330
+ const code = text2.charCodeAt(i);
36
331
  const value = code < 128 ? BASE64URL_DECODE_TABLE[code] : -1;
37
332
  if (value === void 0 || value < 0) {
38
- throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text}"`);
333
+ throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text2}"`);
39
334
  }
40
335
  buffer = buffer << 6 | value;
41
336
  bits += 6;
@@ -45,20 +340,11 @@ function decodeBase64Url(text) {
45
340
  }
46
341
  }
47
342
  const decoded = Uint8Array.from(bytes);
48
- if (encodeBase64Url(decoded) !== text) {
49
- throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text}"`);
343
+ if (encodeBase64Url(decoded) !== text2) {
344
+ throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text2}"`);
50
345
  }
51
346
  return decoded;
52
347
  }
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
348
  function decodeEd25519PublicKey(publicKey) {
63
349
  const bytes = decodeBase64Url(publicKey);
64
350
  if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
@@ -68,135 +354,64 @@ function decodeEd25519PublicKey(publicKey) {
68
354
  }
69
355
  return bytes;
70
356
  }
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
357
  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;
358
+ return multicastCatalogIssues({ multicast: { auth: obj } }).length === 0;
139
359
  }
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) {
360
+ function resolveMulticastAuthCatalog(catalog, options = {}) {
146
361
  if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
147
362
  throw new Error("[multicast-auth-catalog] catalog must be an object");
148
363
  }
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");
364
+ const issues = multicastCatalogIssues(catalog, options);
365
+ const fatal = issues.find((issue) => issue.endpointIndex === void 0);
366
+ if (fatal) throw new Error(`[multicast-auth-catalog] ${fatal.path}: ${fatal.message}`);
367
+ const multicast = catalog["multicast"];
368
+ const auth = multicast?.["auth"];
369
+ if (auth === void 0) {
370
+ if (options.requireAuth) {
371
+ throw new Error("[multicast-auth-catalog] authentication is pinned but the catalog declares no multicast.auth");
154
372
  }
155
373
  return void 0;
156
374
  }
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
- }
375
+ const ignored = new Set(issues.map((issue) => issue.endpointIndex));
376
+ const endpoints = multicast["endpoints"] ?? [];
377
+ const flows = [];
378
+ endpoints.forEach((endpoint, endpointIndex) => {
379
+ if (ignored.has(endpointIndex)) return;
380
+ const flowAuth = endpoint["auth"];
381
+ flows.push({
382
+ endpointIndex,
383
+ source: endpoint["sourceAddress"] ?? flowAuth.senderAddress,
384
+ groupAddress: endpoint["groupAddress"],
385
+ port: endpoint["port"],
386
+ bandwidth: endpoint["bandwidth"],
387
+ manifestPort: flowAuth.manifestPort,
388
+ streamId: flowAuth.streamId,
389
+ maxAuthDelayMs: flowAuth.maxAuthDelayMs ?? DEFAULT_MAX_AUTH_DELAY_MS,
390
+ manifestTimerMs: flowAuth.manifestTimerMs ?? DEFAULT_MANIFEST_TIMER_MS,
391
+ ...flowAuth.manifestTrack === void 0 ? {} : { manifestTrack: flowAuth.manifestTrack },
392
+ tracks: (endpoint["tracks"] ?? []).map(({ name, packetId }) => ({
393
+ name,
394
+ packetId
395
+ }))
396
+ });
397
+ });
177
398
  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
- }))
399
+ keys: auth.keys.map((key) => ({ kid: key.kid, publicKey: decodeEd25519PublicKey(key.publicKey), firstEpoch: key.firstEpoch })).sort((a, b) => a.firstEpoch - b.firstEpoch),
400
+ minEpoch: auth.minEpoch,
401
+ flows
189
402
  };
190
403
  }
404
+ function multicastAuthKeyFor(resolved, kid, epoch) {
405
+ return manifestKeyFor(resolved.keys, epoch, kid);
406
+ }
191
407
  export {
192
- decodeAuthScope,
408
+ DEFAULT_MANIFEST_TIMER_MS,
409
+ DEFAULT_MAX_AUTH_DELAY_MS,
193
410
  decodeBase64Url,
194
411
  decodeEd25519PublicKey,
195
412
  encodeBase64Url,
196
- hasUniqueMulticastAuthTrackBindings,
197
413
  isMulticastAuthConfig,
198
- isMulticastAuthTrackConfig,
199
- resolveMulticastAuthCatalog,
200
- resolveMulticastAuthMode
414
+ multicastAuthKeyFor,
415
+ resolveMulticastAuthCatalog
201
416
  };
202
417
  //# sourceMappingURL=multicast-auth-catalog.js.map