@blockcast/mmt-transport 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -96,7 +96,7 @@ export declare function admittedUnderCatalog(catalog: unknown, endpoint: unknown
96
96
  /**
97
97
  * Indices of `endpoints` that survive every draft -01 receiver rule as the
98
98
  * endpoint array of `catalog`, cross-endpoint rules included: both sides of a
99
- * shared `(S, G, port)` or a clashing `manifestPort` are dropped.
99
+ * shared `(S, G, port)` are dropped.
100
100
  */
101
101
  export declare function admittedEndpointsUnderCatalog(catalog: unknown, endpoints: readonly unknown[]): ReadonlySet<number>;
102
102
  /**
@@ -197,7 +197,7 @@ export function admittedUnderCatalog(catalog, endpoint) {
197
197
  /**
198
198
  * Indices of `endpoints` that survive every draft -01 receiver rule as the
199
199
  * endpoint array of `catalog`, cross-endpoint rules included: both sides of a
200
- * shared `(S, G, port)` or a clashing `manifestPort` are dropped.
200
+ * shared `(S, G, port)` are dropped.
201
201
  */
202
202
  export function admittedEndpointsUnderCatalog(catalog, endpoints) {
203
203
  const root = catalog !== null && typeof catalog === "object" ? catalog : {};
@@ -237,13 +237,74 @@
237
237
  "iso-ssbg1-v1"
238
238
  ]);
239
239
 
240
+ // node_modules/@blockcast/mmt-base/dist/ip-address.js
241
+ var DEC_OCTET = /^(?:0|[1-9]\d{0,2})$/;
242
+ var H16 = /^[0-9A-Fa-f]{1,4}$/;
243
+ function parseIpv4(text) {
244
+ const fields = text.split(".");
245
+ if (fields.length !== 4)
246
+ return void 0;
247
+ const octets = [];
248
+ for (const field of fields) {
249
+ if (!DEC_OCTET.test(field))
250
+ return void 0;
251
+ const value = Number(field);
252
+ if (value > 255)
253
+ return void 0;
254
+ octets.push(value);
255
+ }
256
+ return octets;
257
+ }
258
+ function parseIpv6(text) {
259
+ const halves = text.split("::");
260
+ if (halves.length > 2)
261
+ return void 0;
262
+ const groupsOf = (part) => part === "" ? [] : part.split(":");
263
+ const left = groupsOf(halves[0]);
264
+ const right = halves.length === 2 ? groupsOf(halves[1]) : [];
265
+ const words = [];
266
+ const all = [...left, ...right];
267
+ const last = halves.length === 2 && right.length === 0 ? -1 : all.length - 1;
268
+ for (let index = 0; index < all.length; index++) {
269
+ const group = all[index];
270
+ if (index === last && group.includes(".")) {
271
+ const v4 = parseIpv4(group);
272
+ if (!v4)
273
+ return void 0;
274
+ words.push([v4[0] << 8 | v4[1], v4[2] << 8 | v4[3]]);
275
+ } else if (H16.test(group)) {
276
+ words.push([Number.parseInt(group, 16)]);
277
+ } else {
278
+ return void 0;
279
+ }
280
+ }
281
+ const leftWords = words.slice(0, left.length).flat();
282
+ const rightWords = words.slice(left.length).flat();
283
+ const missing = 8 - leftWords.length - rightWords.length;
284
+ if (halves.length === 2 ? missing < 1 : missing !== 0)
285
+ return void 0;
286
+ const out = new Uint8Array(16);
287
+ [...leftWords, ...new Array(missing).fill(0), ...rightWords].forEach((word, index) => {
288
+ out[index * 2] = word >> 8;
289
+ out[index * 2 + 1] = word & 255;
290
+ });
291
+ return out;
292
+ }
293
+ function parseIpAddressLiteral(text) {
294
+ if (typeof text !== "string")
295
+ return void 0;
296
+ if (text.includes(":"))
297
+ return parseIpv6(text);
298
+ const v4 = parseIpv4(text);
299
+ return v4 ? Uint8Array.from(v4) : void 0;
300
+ }
301
+
240
302
  // node_modules/@blockcast/mmt-base/dist/multicast-catalog.js
241
303
  var ED25519_PUBLIC_KEY_BASE64URL = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
242
304
  var UINT32_MAX = 4294967295;
243
305
  var AUTH_MEMBERS = /* @__PURE__ */ new Set(["scheme", "version", "sig", "keys", "minEpoch"]);
244
306
  var KEY_MEMBERS = /* @__PURE__ */ new Set(["kid", "publicKey", "firstEpoch"]);
245
307
  var ENDPOINT_AUTH_MEMBERS = /* @__PURE__ */ new Set([
246
- "manifestPort",
247
308
  "streamId",
248
309
  "senderAddress",
249
310
  "maxAuthDelayMs",
@@ -253,17 +314,32 @@
253
314
  function isObject(value) {
254
315
  return typeof value === "object" && value !== null && !Array.isArray(value);
255
316
  }
256
- function isNonEmptyString(value) {
257
- return typeof value === "string" && value.trim().length > 0;
258
- }
259
317
  function isIntegerIn(value, min, max) {
260
318
  return Number.isSafeInteger(value) && value >= min && value <= max;
261
319
  }
320
+ var BCP_DEFAULT_MAX_AUTH_DELAY_MS = 200;
321
+ var BCP_DEFAULT_MANIFEST_TIMER_MS = 20;
322
+ function isFiniteNumber(value) {
323
+ return typeof value === "number" && Number.isFinite(value);
324
+ }
325
+ function endpointAuthTiming(auth) {
326
+ const record = isObject(auth) ? auth : {};
327
+ const delay = record["maxAuthDelayMs"];
328
+ const timer = record["manifestTimerMs"];
329
+ const track = record["manifestTrack"];
330
+ const maxAuthDelayMs = !isFiniteNumber(delay) ? BCP_DEFAULT_MAX_AUTH_DELAY_MS : delay < 50 ? 50 : delay > 1e3 ? 1e3 : Number.isInteger(delay) ? delay : BCP_DEFAULT_MAX_AUTH_DELAY_MS;
331
+ const manifestTimerMs = !isFiniteNumber(timer) ? BCP_DEFAULT_MANIFEST_TIMER_MS : timer < 1 || Number.isSafeInteger(timer) ? timer : BCP_DEFAULT_MANIFEST_TIMER_MS;
332
+ return {
333
+ maxAuthDelayMs,
334
+ manifestTimerMs,
335
+ ...typeof track === "string" && track.length > 0 ? { manifestTrack: track } : {}
336
+ };
337
+ }
262
338
  function multicastEndpointSource(endpoint) {
263
339
  if (!isObject(endpoint))
264
340
  return void 0;
265
341
  const sourceAddress = endpoint["sourceAddress"];
266
- if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress))
342
+ if (sourceAddress !== void 0 && !parseIpAddressLiteral(sourceAddress))
267
343
  return void 0;
268
344
  const mode = sourceAddress === void 0 ? "asm" : "ssm";
269
345
  const protocol = endpoint["protocol"];
@@ -275,7 +351,7 @@
275
351
  return senderAddress === void 0 ? { mode, source: sourceAddress } : void 0;
276
352
  if (auth === void 0)
277
353
  return { mode };
278
- return isNonEmptyString(senderAddress) ? { mode, source: senderAddress } : void 0;
354
+ return parseIpAddressLiteral(senderAddress) ? { mode, source: senderAddress } : void 0;
279
355
  }
280
356
  function authIssues(auth) {
281
357
  const base = "$.multicast.auth";
@@ -286,12 +362,12 @@
286
362
  return issue("", "auth must be an object");
287
363
  const unknown = Object.keys(auth).filter((key) => !AUTH_MEMBERS.has(key));
288
364
  if (unknown.length > 0) {
289
- return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -01 7.2.6 defines scheme, version, sig, keys and minEpoch`);
365
+ return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -02 7.2.6 defines scheme, version, sig, keys and minEpoch`);
290
366
  }
291
367
  if (auth["scheme"] !== "bc-provenance")
292
368
  return issue(".scheme", 'scheme must be "bc-provenance"');
293
369
  if (auth["version"] !== 2)
294
- return issue(".version", "version must be 2 (bc-provenance version 2, draft -01 7.2)");
370
+ return issue(".version", "version must be 2 (bc-provenance version 2, draft -02 7.2)");
295
371
  if (auth["sig"] !== "ed25519")
296
372
  return issue(".sig", 'sig must be "ed25519"');
297
373
  const keys = auth["keys"];
@@ -334,26 +410,17 @@
334
410
  const unknown = Object.keys(auth).filter((key) => !ENDPOINT_AUTH_MEMBERS.has(key));
335
411
  if (unknown.length > 0)
336
412
  return { path: `${at}.auth`, message: `auth has unknown member(s) ${unknown.join(", ")}` };
337
- if (!isIntegerIn(auth["manifestPort"], 1, 65535)) {
338
- return { path: `${at}.auth.manifestPort`, message: "manifestPort must be an integer from 1 to 65535" };
339
- }
340
413
  if (!isIntegerIn(auth["streamId"], 0, UINT32_MAX)) {
341
414
  return { path: `${at}.auth.streamId`, message: "streamId must be an unsigned 32-bit integer" };
342
415
  }
343
416
  if (mode === "ssm" && auth["senderAddress"] !== void 0) {
344
417
  return { path: `${at}.auth.senderAddress`, message: "senderAddress must not appear on an SSM endpoint; S is sourceAddress" };
345
418
  }
346
- if (mode === "asm" && !isNonEmptyString(auth["senderAddress"])) {
347
- return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress" };
348
- }
349
- if (auth["maxAuthDelayMs"] !== void 0 && !isIntegerIn(auth["maxAuthDelayMs"], 50, 1e3)) {
350
- return { path: `${at}.auth.maxAuthDelayMs`, message: "maxAuthDelayMs must be an integer from 50 to 1000" };
419
+ if (mode === "asm" && !parseIpAddressLiteral(auth["senderAddress"])) {
420
+ return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress, an RFC 3986 IP address literal" };
351
421
  }
352
- if (auth["manifestTimerMs"] !== void 0 && !isIntegerIn(auth["manifestTimerMs"], 1, Number.MAX_SAFE_INTEGER)) {
353
- return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be an integer of at least 1" };
354
- }
355
- if (auth["manifestTrack"] !== void 0 && !isNonEmptyString(auth["manifestTrack"])) {
356
- return { path: `${at}.auth.manifestTrack`, message: "manifestTrack must be a non-empty string" };
422
+ if (endpointAuthTiming(auth).manifestTimerMs < 1) {
423
+ return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be at least 1" };
357
424
  }
358
425
  if (!isIntegerIn(endpoint["bandwidth"], 1, Number.MAX_SAFE_INTEGER)) {
359
426
  return { path: `${at}.bandwidth`, message: "a protected endpoint requires bandwidth, which bounds the receiver's hold queues" };
@@ -372,7 +439,7 @@
372
439
  issues.push({
373
440
  code: "multicast_auth",
374
441
  path: '$["multicast.auth"]',
375
- message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -01 7.2.6)'
442
+ message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -02 7.2.6)'
376
443
  });
377
444
  }
378
445
  const multicast = catalog["multicast"];
@@ -406,7 +473,7 @@
406
473
  }
407
474
  const protocol = endpoint["protocol"];
408
475
  if (protocol !== void 0 && protocol !== "ssm" && protocol !== "asm") {
409
- 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)`);
476
+ fail("multicast_endpoint", `${at}.protocol`, `protocol must be "ssm" or "asm"; a bearer such as ${JSON.stringify(protocol)} is a networkSource entry (draft -02 4.2)`);
410
477
  continue;
411
478
  }
412
479
  const hasAuth = endpoint["auth"] !== void 0;
@@ -415,8 +482,18 @@
415
482
  continue;
416
483
  }
417
484
  const sourceAddress = endpoint["sourceAddress"];
418
- if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress)) {
419
- fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be a non-empty string");
485
+ const sourceBytes = sourceAddress === void 0 ? void 0 : parseIpAddressLiteral(sourceAddress);
486
+ if (sourceAddress !== void 0 && !sourceBytes) {
487
+ fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be an RFC 3986 IPv4address or IPv6address literal");
488
+ continue;
489
+ }
490
+ const groupBytes = parseIpAddressLiteral(endpoint["groupAddress"]);
491
+ if (!groupBytes) {
492
+ fail("multicast_endpoint", `${at}.groupAddress`, "groupAddress must be an RFC 3986 IPv4address or IPv6address literal");
493
+ continue;
494
+ }
495
+ if (sourceBytes && sourceBytes.length !== groupBytes.length) {
496
+ fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress and groupAddress are of different address families");
420
497
  continue;
421
498
  }
422
499
  const mode = sourceAddress === void 0 ? "asm" : "ssm";
@@ -435,7 +512,13 @@
435
512
  continue;
436
513
  }
437
514
  }
438
- sources[index] = multicastEndpointSource(endpoint);
515
+ const source = multicastEndpointSource(endpoint);
516
+ const senderBytes = source?.mode === "asm" && source.source !== void 0 ? parseIpAddressLiteral(source.source) : void 0;
517
+ if (senderBytes && senderBytes.length !== groupBytes.length) {
518
+ fail("multicast_endpoint_auth", `${at}.auth.senderAddress`, "senderAddress and groupAddress are of different address families");
519
+ continue;
520
+ }
521
+ sources[index] = source;
439
522
  const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
440
523
  for (let refIndex = 0; refIndex < refs.length; refIndex++) {
441
524
  const ref = refs[refIndex];
@@ -451,38 +534,23 @@
451
534
  }
452
535
  }
453
536
  }
537
+ const addressKey = (text) => {
538
+ const bytes = text === void 0 ? void 0 : parseIpAddressLiteral(text);
539
+ return bytes ? `${bytes.length}:${bytes.join(".")}` : "-";
540
+ };
454
541
  const tupleOf = (index) => {
455
542
  const endpoint = endpoints[index];
456
- const auth = endpoint["auth"];
457
- return {
458
- sg: JSON.stringify([sources[index].source ?? null, endpoint["groupAddress"]]),
459
- port: endpoint["port"],
460
- manifestPort: isObject(auth) ? auth["manifestPort"] : void 0
461
- };
543
+ return `${addressKey(sources[index].source)}|${addressKey(endpoint["groupAddress"])}|${endpoint["port"]}`;
462
544
  };
463
545
  for (let index = 0; index < endpoints.length; index++) {
464
546
  if (!sources[index])
465
547
  continue;
466
548
  const own = tupleOf(index);
467
- const at = `$.multicast.endpoints[${index}]`;
468
- if (own.manifestPort !== void 0 && own.manifestPort === own.port) {
469
- issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
470
- continue;
471
- }
472
549
  for (let other = 0; other < endpoints.length; other++) {
473
- if (other === index || !sources[other])
474
- continue;
475
- const peer = tupleOf(other);
476
- if (peer.sg !== own.sg)
550
+ if (other === index || !sources[other] || tupleOf(other) !== own)
477
551
  continue;
478
- if (peer.port === own.port) {
479
- 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 });
480
- break;
481
- }
482
- if (own.manifestPort !== void 0 && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
483
- 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 });
484
- break;
485
- }
552
+ issues.push({ code: "multicast_endpoint", path: `$.multicast.endpoints[${index}].port`, message: `(S, G, port) is shared with endpoint ${other}; one endpoint object per multicast tuple`, endpointIndex: index });
553
+ break;
486
554
  }
487
555
  }
488
556
  return issues;