@blockcast/mmt-container 0.4.0-main.bbd83cb48eff → 0.4.0-main.c7ae84be5039
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.
- package/README.md +28 -14
- package/dist/align.d.ts +24 -18
- package/dist/align.d.ts.map +1 -1
- package/dist/align.js +23 -4
- package/dist/align.js.map +2 -2
- package/dist/browser-runtime.js +778 -272
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +58 -26
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +270 -194
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +1 -1
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +6 -13
- package/dist/catalog-fec-params.js.map +3 -3
- package/dist/catalog-network-source.d.ts +1 -1
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js.map +1 -1
- package/dist/catalog-validator.d.ts +4 -3
- package/dist/catalog-validator.d.ts.map +1 -1
- package/dist/catalog-validator.js +0 -29
- package/dist/catalog-validator.js.map +3 -3
- package/dist/delivery-catalog.js +4 -12
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.js.map +1 -1
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +14 -2
- package/dist/fec-state.js.map +3 -3
- package/dist/fec-worker-setup.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.js.map +1 -1
- package/dist/manifest-auth-plan.d.ts +26 -25
- package/dist/manifest-auth-plan.d.ts.map +1 -1
- package/dist/manifest-auth-plan.js +315 -1163
- package/dist/manifest-auth-plan.js.map +4 -4
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +947 -278
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.d.ts +156 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +522 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +17 -0
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-auth-catalog.d.ts +86 -92
- package/dist/multicast-auth-catalog.d.ts.map +1 -1
- package/dist/multicast-auth-catalog.js +331 -124
- package/dist/multicast-auth-catalog.js.map +3 -3
- package/dist/multicast-input.d.ts +26 -4
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +283 -23
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +23 -4
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +59 -29
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.js +2 -10
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +2 -0
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +899 -267
- package/dist/no-modules.js.map +4 -4
- package/dist/phase14-catalog-override.d.ts +1 -1
- package/dist/phase14-catalog-override.d.ts.map +1 -1
- package/dist/phase14-catalog-override.js +2 -2
- package/dist/phase14-catalog-override.js.map +2 -2
- package/dist/repair-fetch.d.ts +23 -1
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +35 -10
- package/dist/repair-fetch.js.map +2 -2
- package/dist/repair-layers.js.map +1 -1
- package/dist/signaling.d.ts +2 -2
- package/dist/signaling.d.ts.map +1 -1
- package/dist/signaling.js +3 -3
- package/dist/signaling.js.map +2 -2
- package/dist/source-auth.js +22 -6
- package/dist/source-auth.js.map +2 -2
- package/dist/switching-set-alignment.d.ts +1 -1
- package/dist/switching-set-alignment.js.map +1 -1
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +1 -1
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +5 -5
- package/schemas/catalog.schema.json +117 -34
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +120 -46
- package/src/catalog-fec-params.ts +5 -2
- package/src/catalog-network-source.ts +1 -1
- package/src/catalog-validator.ts +4 -11
- package/src/fec-state.ts +3 -2
- package/src/index.ts +18 -2
- package/src/manifest-auth-plan.ts +39 -91
- package/src/mmtp-fec-session.ts +514 -0
- package/src/mmtp-router.ts +25 -0
- package/src/multicast-auth-catalog.ts +131 -238
- package/src/multicast-input.ts +109 -54
- package/src/multicast-manager.ts +88 -14
- package/src/no-modules.ts +2 -0
- package/src/phase14-catalog-override.ts +3 -3
- package/src/repair-fetch.ts +79 -14
- package/src/signaling.ts +2 -2
- package/src/switching-set-alignment.ts +1 -1
- package/test-vectors/align.json +108 -32
- package/test-vectors/catalog/README.md +55 -3
- package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
- package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
- package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
- package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
- package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
- package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
- package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
- package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
- package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
- package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
- package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
- package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
- package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
- package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +2 -2
- package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
- package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
- package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
- package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
- package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
- package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
- package/test-vectors/catalog/section-codes.json +27 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +3 -2
- package/test-vectors/catalog-validator-public-api.mjs +14 -9
|
@@ -41,7 +41,9 @@ var BlockcastMmt = (() => {
|
|
|
41
41
|
FEC_INACTIVE_REASONS: () => FEC_INACTIVE_REASONS,
|
|
42
42
|
ManifestVerifier: () => ManifestVerifier,
|
|
43
43
|
MmtpContainerParser: () => MmtpContainerParser,
|
|
44
|
+
MmtpFecSession: () => MmtpFecSession,
|
|
44
45
|
MmtpToCmaf: () => MmtpToCmaf,
|
|
46
|
+
catalogAmtNetworkSource: () => catalogAmtNetworkSource,
|
|
45
47
|
catalogDeclaresFec: () => catalogDeclaresFec,
|
|
46
48
|
catalogFecInterleaveMs: () => catalogFecInterleaveMs,
|
|
47
49
|
computeFecTimeout: () => computeFecTimeout,
|
|
@@ -348,6 +350,57 @@ var BlockcastMmt = (() => {
|
|
|
348
350
|
ssId: (mmtpPacket[off] << 24 | mmtpPacket[off + 1] << 16 | mmtpPacket[off + 2] << 8 | mmtpPacket[off + 3]) >>> 0
|
|
349
351
|
};
|
|
350
352
|
}
|
|
353
|
+
var REPAIR_FEC_PID_SIZE = 13;
|
|
354
|
+
function readRepairFecPayloadIdFields(mmtpPacket, parsedHeader) {
|
|
355
|
+
let header;
|
|
356
|
+
if (parsedHeader) {
|
|
357
|
+
header = parsedHeader;
|
|
358
|
+
} else {
|
|
359
|
+
try {
|
|
360
|
+
header = parseMMTPHeader(mmtpPacket);
|
|
361
|
+
} catch {
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (header.packetType !== PACKET_TYPE_REPAIR || header.fecType !== 2)
|
|
366
|
+
return null;
|
|
367
|
+
const off = header.headerLength;
|
|
368
|
+
if (mmtpPacket.length < off + REPAIR_FEC_PID_SIZE)
|
|
369
|
+
return null;
|
|
370
|
+
const ssStart = (mmtpPacket[off] << 24 | mmtpPacket[off + 1] << 16 | mmtpPacket[off + 2] << 8 | mmtpPacket[off + 3]) >>> 0;
|
|
371
|
+
const rsbLength = mmtpPacket[off + 4] << 16 | mmtpPacket[off + 5] << 8 | mmtpPacket[off + 6];
|
|
372
|
+
const rsId = mmtpPacket[off + 7] << 16 | mmtpPacket[off + 8] << 8 | mmtpPacket[off + 9];
|
|
373
|
+
const ssbLength = mmtpPacket[off + 10] << 16 | mmtpPacket[off + 11] << 8 | mmtpPacket[off + 12];
|
|
374
|
+
return {
|
|
375
|
+
packetId: header.packetId,
|
|
376
|
+
ssStart,
|
|
377
|
+
rsbLength,
|
|
378
|
+
rsId,
|
|
379
|
+
ssbLength,
|
|
380
|
+
dataOffset: off + REPAIR_FEC_PID_SIZE
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function parseMoqRepairFrameWithHeader(frame, header) {
|
|
384
|
+
return moqRepairFrameFrom(frame, readRepairFecPayloadIdFields(frame, header));
|
|
385
|
+
}
|
|
386
|
+
function moqRepairFrameFrom(frame, repairId) {
|
|
387
|
+
if (!repairId)
|
|
388
|
+
return null;
|
|
389
|
+
const symbolData = frame.subarray(repairId.dataOffset);
|
|
390
|
+
if (repairId.rsbLength === 0 || repairId.ssbLength === 0 || repairId.rsId >= repairId.rsbLength || symbolData.length === 0)
|
|
391
|
+
return null;
|
|
392
|
+
return {
|
|
393
|
+
packetId: repairId.packetId,
|
|
394
|
+
ssStart: repairId.ssStart,
|
|
395
|
+
rsbLength: repairId.rsbLength,
|
|
396
|
+
rsId: repairId.rsId,
|
|
397
|
+
ssbLength: repairId.ssbLength,
|
|
398
|
+
symbolData
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// ../mmt-base/dist/net-constants.js
|
|
403
|
+
var DEFAULT_AMT_RELAY_PORT = 2268;
|
|
351
404
|
|
|
352
405
|
// ../mmt-base/dist/ntp-short.js
|
|
353
406
|
var NTP_SHORT_BITS = 32;
|
|
@@ -356,6 +409,26 @@ var BlockcastMmt = (() => {
|
|
|
356
409
|
|
|
357
410
|
// ../mmt-base/dist/serial-number.js
|
|
358
411
|
var SERIAL32_SPAN = 4294967296;
|
|
412
|
+
var SERIAL32_HALF = 2147483648;
|
|
413
|
+
function assertUint32(value, name) {
|
|
414
|
+
if (!Number.isInteger(value) || value < 0 || value >= SERIAL32_SPAN) {
|
|
415
|
+
throw new RangeError(`${name} must be a uint32 (got ${value})`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function serial32Add(s, n) {
|
|
419
|
+
assertUint32(s, "s");
|
|
420
|
+
if (!Number.isInteger(n) || n <= -SERIAL32_HALF || n >= SERIAL32_HALF) {
|
|
421
|
+
throw new RangeError(`serial addend must lie in (-2^31, 2^31) (got ${n})`);
|
|
422
|
+
}
|
|
423
|
+
return (s + n + SERIAL32_SPAN) % SERIAL32_SPAN;
|
|
424
|
+
}
|
|
425
|
+
function serial32Distance(from, to) {
|
|
426
|
+
return to - from >>> 0;
|
|
427
|
+
}
|
|
428
|
+
function serial32Precedes(a, b) {
|
|
429
|
+
const distance = serial32Distance(a, b);
|
|
430
|
+
return distance !== 0 && distance < SERIAL32_HALF;
|
|
431
|
+
}
|
|
359
432
|
|
|
360
433
|
// ../mmt-base/dist/fec-block-profile.js
|
|
361
434
|
var FEC_BLOCK_PROFILES = Object.freeze([
|
|
@@ -372,6 +445,35 @@ var BlockcastMmt = (() => {
|
|
|
372
445
|
}
|
|
373
446
|
throw new Error(`${where} must be "iso-ssbg1-v1" (got ${JSON.stringify(value)})`);
|
|
374
447
|
}
|
|
448
|
+
var SSBG1_LENGTH_FIELD_BYTES = 2;
|
|
449
|
+
function ssbg1MaxPacketLength(symbolSize) {
|
|
450
|
+
return symbolSize - SSBG1_LENGTH_FIELD_BYTES;
|
|
451
|
+
}
|
|
452
|
+
function ssbg1FitsSymbol(packetLength, symbolSize) {
|
|
453
|
+
return Number.isSafeInteger(packetLength) && packetLength >= 0 && packetLength <= ssbg1MaxPacketLength(symbolSize) && packetLength <= 65535;
|
|
454
|
+
}
|
|
455
|
+
function trimSsbg1SourceSymbol(symbol) {
|
|
456
|
+
if (symbol.byteLength < SSBG1_LENGTH_FIELD_BYTES)
|
|
457
|
+
return null;
|
|
458
|
+
const length = symbol[0] << 8 | symbol[1];
|
|
459
|
+
const end = SSBG1_LENGTH_FIELD_BYTES + length;
|
|
460
|
+
if (end > symbol.byteLength)
|
|
461
|
+
return null;
|
|
462
|
+
for (let i = end; i < symbol.byteLength; i++) {
|
|
463
|
+
if (symbol[i] !== 0)
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
return symbol.subarray(SSBG1_LENGTH_FIELD_BYTES, end);
|
|
467
|
+
}
|
|
468
|
+
function isoBlockContains(ssStart, ssbLength, ssId) {
|
|
469
|
+
return serial32Distance(ssStart, ssId) < ssbLength;
|
|
470
|
+
}
|
|
471
|
+
function isoBlocksBehindLowerBound(a, b, kMax) {
|
|
472
|
+
if (!Number.isSafeInteger(kMax) || kMax <= 0) {
|
|
473
|
+
throw new Error(`iso-ssbg1-v1 block horizon needs a positive maximum K (got ${kMax})`);
|
|
474
|
+
}
|
|
475
|
+
return serial32Precedes(a, b) ? Math.floor(serial32Distance(a, b) / kMax) : 0;
|
|
476
|
+
}
|
|
375
477
|
|
|
376
478
|
// ../mmt-base/dist/catalog-fec-source.js
|
|
377
479
|
var ALL_ROLES = Object.freeze(["video", "audio"]);
|
|
@@ -385,6 +487,266 @@ var BlockcastMmt = (() => {
|
|
|
385
487
|
const ms = block["interleaveDepthMs"];
|
|
386
488
|
return ms === void 0 || typeof ms === "number" && Number.isSafeInteger(ms) && ms >= 0;
|
|
387
489
|
}
|
|
490
|
+
function isPositiveSafeInteger(value) {
|
|
491
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
492
|
+
}
|
|
493
|
+
var ISO_SSBG1_MIN_SYMBOL_SIZE = 14;
|
|
494
|
+
function catalogFecDeclaresUnconfigurableInstance(fec) {
|
|
495
|
+
const block = recordOf(fec);
|
|
496
|
+
if (block === void 0 || block["algorithm"] === "none")
|
|
497
|
+
return false;
|
|
498
|
+
if (!(isPositiveSafeInteger(block["sourceSymbols"]) && isPositiveSafeInteger(block["symbolSize"])))
|
|
499
|
+
return true;
|
|
500
|
+
return block["blockProfile"] === "iso-ssbg1-v1" && block["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// ../mmt-base/dist/multicast-catalog.js
|
|
504
|
+
var ED25519_PUBLIC_KEY_BASE64URL = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
|
|
505
|
+
var UINT32_MAX = 4294967295;
|
|
506
|
+
var AUTH_MEMBERS = /* @__PURE__ */ new Set(["scheme", "version", "sig", "keys", "minEpoch"]);
|
|
507
|
+
var KEY_MEMBERS = /* @__PURE__ */ new Set(["kid", "publicKey", "firstEpoch"]);
|
|
508
|
+
var ENDPOINT_AUTH_MEMBERS = /* @__PURE__ */ new Set([
|
|
509
|
+
"manifestPort",
|
|
510
|
+
"streamId",
|
|
511
|
+
"senderAddress",
|
|
512
|
+
"maxAuthDelayMs",
|
|
513
|
+
"manifestTimerMs",
|
|
514
|
+
"manifestTrack"
|
|
515
|
+
]);
|
|
516
|
+
function isObject(value) {
|
|
517
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
518
|
+
}
|
|
519
|
+
function isNonEmptyString(value) {
|
|
520
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
521
|
+
}
|
|
522
|
+
function isIntegerIn(value, min, max) {
|
|
523
|
+
return Number.isSafeInteger(value) && value >= min && value <= max;
|
|
524
|
+
}
|
|
525
|
+
function multicastEndpointSource(endpoint) {
|
|
526
|
+
if (!isObject(endpoint))
|
|
527
|
+
return void 0;
|
|
528
|
+
const sourceAddress = endpoint["sourceAddress"];
|
|
529
|
+
if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress))
|
|
530
|
+
return void 0;
|
|
531
|
+
const mode = sourceAddress === void 0 ? "asm" : "ssm";
|
|
532
|
+
const protocol = endpoint["protocol"];
|
|
533
|
+
if (protocol !== void 0 && protocol !== mode)
|
|
534
|
+
return void 0;
|
|
535
|
+
const auth = endpoint["auth"];
|
|
536
|
+
const senderAddress = isObject(auth) ? auth["senderAddress"] : void 0;
|
|
537
|
+
if (mode === "ssm")
|
|
538
|
+
return senderAddress === void 0 ? { mode, source: sourceAddress } : void 0;
|
|
539
|
+
if (auth === void 0)
|
|
540
|
+
return { mode };
|
|
541
|
+
return isNonEmptyString(senderAddress) ? { mode, source: senderAddress } : void 0;
|
|
542
|
+
}
|
|
543
|
+
function authIssues(auth) {
|
|
544
|
+
const base = "$.multicast.auth";
|
|
545
|
+
const issue = (path, message) => [
|
|
546
|
+
{ code: "multicast_auth", path: `${base}${path}`, message }
|
|
547
|
+
];
|
|
548
|
+
if (!isObject(auth))
|
|
549
|
+
return issue("", "auth must be an object");
|
|
550
|
+
const unknown = Object.keys(auth).filter((key) => !AUTH_MEMBERS.has(key));
|
|
551
|
+
if (unknown.length > 0) {
|
|
552
|
+
return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -01 7.2.6 defines scheme, version, sig, keys and minEpoch`);
|
|
553
|
+
}
|
|
554
|
+
if (auth["scheme"] !== "bc-provenance")
|
|
555
|
+
return issue(".scheme", 'scheme must be "bc-provenance"');
|
|
556
|
+
if (auth["version"] !== 2)
|
|
557
|
+
return issue(".version", "version must be 2 (bc-provenance version 2, draft -01 7.2)");
|
|
558
|
+
if (auth["sig"] !== "ed25519")
|
|
559
|
+
return issue(".sig", 'sig must be "ed25519"');
|
|
560
|
+
const keys = auth["keys"];
|
|
561
|
+
if (!Array.isArray(keys) || keys.length < 1 || keys.length > 4) {
|
|
562
|
+
return issue(".keys", "keys must be an array of one to four {kid, publicKey, firstEpoch} objects");
|
|
563
|
+
}
|
|
564
|
+
const kids = /* @__PURE__ */ new Set();
|
|
565
|
+
const firstEpochs = /* @__PURE__ */ new Set();
|
|
566
|
+
for (let index = 0; index < keys.length; index++) {
|
|
567
|
+
const key = keys[index];
|
|
568
|
+
const at = `.keys[${index}]`;
|
|
569
|
+
if (!isObject(key) || Object.keys(key).some((member) => !KEY_MEMBERS.has(member))) {
|
|
570
|
+
return issue(at, "a key is exactly {kid, publicKey, firstEpoch}");
|
|
571
|
+
}
|
|
572
|
+
if (!isIntegerIn(key["kid"], 0, UINT32_MAX))
|
|
573
|
+
return issue(`${at}.kid`, "kid must be an unsigned 32-bit integer");
|
|
574
|
+
if (typeof key["publicKey"] !== "string" || !ED25519_PUBLIC_KEY_BASE64URL.test(key["publicKey"])) {
|
|
575
|
+
return issue(`${at}.publicKey`, "publicKey must be a 32-octet Ed25519 key in canonical unpadded base64url");
|
|
576
|
+
}
|
|
577
|
+
if (!isIntegerIn(key["firstEpoch"], 0, UINT32_MAX)) {
|
|
578
|
+
return issue(`${at}.firstEpoch`, "firstEpoch must be an unsigned 32-bit integer");
|
|
579
|
+
}
|
|
580
|
+
if (kids.has(key["kid"]))
|
|
581
|
+
return issue(`${at}.kid`, `kid ${key["kid"]} is repeated; the catalog holds no key set`);
|
|
582
|
+
if (firstEpochs.has(key["firstEpoch"])) {
|
|
583
|
+
return issue(`${at}.firstEpoch`, `firstEpoch ${key["firstEpoch"]} is repeated; the catalog holds no key set`);
|
|
584
|
+
}
|
|
585
|
+
kids.add(key["kid"]);
|
|
586
|
+
firstEpochs.add(key["firstEpoch"]);
|
|
587
|
+
}
|
|
588
|
+
if (!isIntegerIn(auth["minEpoch"], 0, UINT32_MAX)) {
|
|
589
|
+
return issue(".minEpoch", "minEpoch must be an unsigned 32-bit integer");
|
|
590
|
+
}
|
|
591
|
+
return [];
|
|
592
|
+
}
|
|
593
|
+
function endpointAuthIssue(endpoint, mode, at) {
|
|
594
|
+
const auth = endpoint["auth"];
|
|
595
|
+
if (!isObject(auth))
|
|
596
|
+
return { path: `${at}.auth`, message: "auth must be an object" };
|
|
597
|
+
const unknown = Object.keys(auth).filter((key) => !ENDPOINT_AUTH_MEMBERS.has(key));
|
|
598
|
+
if (unknown.length > 0)
|
|
599
|
+
return { path: `${at}.auth`, message: `auth has unknown member(s) ${unknown.join(", ")}` };
|
|
600
|
+
if (!isIntegerIn(auth["manifestPort"], 1, 65535)) {
|
|
601
|
+
return { path: `${at}.auth.manifestPort`, message: "manifestPort must be an integer from 1 to 65535" };
|
|
602
|
+
}
|
|
603
|
+
if (!isIntegerIn(auth["streamId"], 0, UINT32_MAX)) {
|
|
604
|
+
return { path: `${at}.auth.streamId`, message: "streamId must be an unsigned 32-bit integer" };
|
|
605
|
+
}
|
|
606
|
+
if (mode === "ssm" && auth["senderAddress"] !== void 0) {
|
|
607
|
+
return { path: `${at}.auth.senderAddress`, message: "senderAddress must not appear on an SSM endpoint; S is sourceAddress" };
|
|
608
|
+
}
|
|
609
|
+
if (mode === "asm" && !isNonEmptyString(auth["senderAddress"])) {
|
|
610
|
+
return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress" };
|
|
611
|
+
}
|
|
612
|
+
if (auth["maxAuthDelayMs"] !== void 0 && !isIntegerIn(auth["maxAuthDelayMs"], 50, 1e3)) {
|
|
613
|
+
return { path: `${at}.auth.maxAuthDelayMs`, message: "maxAuthDelayMs must be an integer from 50 to 1000" };
|
|
614
|
+
}
|
|
615
|
+
if (auth["manifestTimerMs"] !== void 0 && !isIntegerIn(auth["manifestTimerMs"], 1, Number.MAX_SAFE_INTEGER)) {
|
|
616
|
+
return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be an integer of at least 1" };
|
|
617
|
+
}
|
|
618
|
+
if (auth["manifestTrack"] !== void 0 && !isNonEmptyString(auth["manifestTrack"])) {
|
|
619
|
+
return { path: `${at}.auth.manifestTrack`, message: "manifestTrack must be a non-empty string" };
|
|
620
|
+
}
|
|
621
|
+
if (!isIntegerIn(endpoint["bandwidth"], 1, Number.MAX_SAFE_INTEGER)) {
|
|
622
|
+
return { path: `${at}.bandwidth`, message: "a protected endpoint requires bandwidth, which bounds the receiver's hold queues" };
|
|
623
|
+
}
|
|
624
|
+
return void 0;
|
|
625
|
+
}
|
|
626
|
+
var CATALOG_NAMESPACE = /* @__PURE__ */ Symbol.for("@blockcast/mmt-base/catalogNamespace");
|
|
627
|
+
function multicastCatalogIssues(catalog, options = {}) {
|
|
628
|
+
if (!isObject(catalog))
|
|
629
|
+
return [];
|
|
630
|
+
const issues = [];
|
|
631
|
+
if ("multicast.auth" in catalog) {
|
|
632
|
+
issues.push({
|
|
633
|
+
code: "multicast_auth",
|
|
634
|
+
path: '$["multicast.auth"]',
|
|
635
|
+
message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -01 7.2.6)'
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
const multicast = catalog["multicast"];
|
|
639
|
+
if (!isObject(multicast))
|
|
640
|
+
return issues;
|
|
641
|
+
const protectedCatalog = multicast["auth"] !== void 0;
|
|
642
|
+
if (protectedCatalog)
|
|
643
|
+
issues.push(...authIssues(multicast["auth"]));
|
|
644
|
+
const endpoints = multicast["endpoints"];
|
|
645
|
+
if (!Array.isArray(endpoints))
|
|
646
|
+
return issues;
|
|
647
|
+
const tracks = Array.isArray(catalog["tracks"]) ? catalog["tracks"] : [];
|
|
648
|
+
const namespaceOf = /* @__PURE__ */ new Map();
|
|
649
|
+
for (const track of tracks) {
|
|
650
|
+
if (isObject(track) && typeof track["name"] === "string")
|
|
651
|
+
namespaceOf.set(track["name"], track["namespace"]);
|
|
652
|
+
}
|
|
653
|
+
const tagged = catalog[CATALOG_NAMESPACE];
|
|
654
|
+
let referenceNamespace = options.catalogNamespace ?? (typeof tagged === "string" ? tagged : void 0);
|
|
655
|
+
const sources = [];
|
|
656
|
+
for (let index = 0; index < endpoints.length; index++) {
|
|
657
|
+
const endpoint = endpoints[index];
|
|
658
|
+
const at = `$.multicast.endpoints[${index}]`;
|
|
659
|
+
const fail = (code, path, message) => {
|
|
660
|
+
issues.push({ code, path, message, endpointIndex: index });
|
|
661
|
+
};
|
|
662
|
+
sources.push(void 0);
|
|
663
|
+
if (!isObject(endpoint)) {
|
|
664
|
+
fail("multicast_endpoint", at, "endpoint must be an object");
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
const protocol = endpoint["protocol"];
|
|
668
|
+
if (protocol !== void 0 && protocol !== "ssm" && protocol !== "asm") {
|
|
669
|
+
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)`);
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
const hasAuth = endpoint["auth"] !== void 0;
|
|
673
|
+
if (protectedCatalog !== hasAuth) {
|
|
674
|
+
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");
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
const sourceAddress = endpoint["sourceAddress"];
|
|
678
|
+
if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress)) {
|
|
679
|
+
fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be a non-empty string");
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
const mode = sourceAddress === void 0 ? "asm" : "ssm";
|
|
683
|
+
if (protocol !== void 0 && protocol !== mode) {
|
|
684
|
+
fail("multicast_endpoint", `${at}.protocol`, `protocol ${JSON.stringify(protocol)} disagrees with sourceAddress, which selects ${mode}`);
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
if (!isIntegerIn(endpoint["port"], 1, 65535)) {
|
|
688
|
+
fail("multicast_endpoint", `${at}.port`, "port must be an integer from 1 to 65535");
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
if (hasAuth) {
|
|
692
|
+
const authIssue = endpointAuthIssue(endpoint, mode, at);
|
|
693
|
+
if (authIssue) {
|
|
694
|
+
fail("multicast_endpoint_auth", authIssue.path, authIssue.message);
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
sources[index] = multicastEndpointSource(endpoint);
|
|
699
|
+
const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
|
|
700
|
+
for (let refIndex = 0; refIndex < refs.length; refIndex++) {
|
|
701
|
+
const ref = refs[refIndex];
|
|
702
|
+
const name = isObject(ref) ? ref["name"] : ref;
|
|
703
|
+
if (typeof name !== "string")
|
|
704
|
+
continue;
|
|
705
|
+
const namespace = namespaceOf.get(name);
|
|
706
|
+
if (typeof namespace !== "string")
|
|
707
|
+
continue;
|
|
708
|
+
referenceNamespace ?? (referenceNamespace = namespace);
|
|
709
|
+
if (namespace !== referenceNamespace) {
|
|
710
|
+
fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} declares namespace ${JSON.stringify(namespace)}, not the catalog track's ${JSON.stringify(referenceNamespace)}`);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
const tupleOf = (index) => {
|
|
715
|
+
const endpoint = endpoints[index];
|
|
716
|
+
const auth = endpoint["auth"];
|
|
717
|
+
return {
|
|
718
|
+
sg: JSON.stringify([sources[index].source ?? null, endpoint["groupAddress"]]),
|
|
719
|
+
port: endpoint["port"],
|
|
720
|
+
manifestPort: isObject(auth) ? auth["manifestPort"] : void 0
|
|
721
|
+
};
|
|
722
|
+
};
|
|
723
|
+
for (let index = 0; index < endpoints.length; index++) {
|
|
724
|
+
if (!sources[index])
|
|
725
|
+
continue;
|
|
726
|
+
const own = tupleOf(index);
|
|
727
|
+
const at = `$.multicast.endpoints[${index}]`;
|
|
728
|
+
if (own.manifestPort !== void 0 && own.manifestPort === own.port) {
|
|
729
|
+
issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
for (let other = 0; other < endpoints.length; other++) {
|
|
733
|
+
if (other === index || !sources[other])
|
|
734
|
+
continue;
|
|
735
|
+
const peer = tupleOf(other);
|
|
736
|
+
if (peer.sg !== own.sg)
|
|
737
|
+
continue;
|
|
738
|
+
if (peer.port === own.port) {
|
|
739
|
+
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 });
|
|
740
|
+
break;
|
|
741
|
+
}
|
|
742
|
+
if (own.manifestPort !== void 0 && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
|
|
743
|
+
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 });
|
|
744
|
+
break;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
return issues;
|
|
749
|
+
}
|
|
388
750
|
|
|
389
751
|
// src/mfu-reassembler.ts
|
|
390
752
|
function fragmentProvenance(fragment) {
|
|
@@ -7067,197 +7429,6 @@ var BlockcastMmt = (() => {
|
|
|
7067
7429
|
});
|
|
7068
7430
|
}
|
|
7069
7431
|
|
|
7070
|
-
// src/multicast-auth-catalog.ts
|
|
7071
|
-
var RAW_ED25519_KEY_LENGTH = 32;
|
|
7072
|
-
var SOURCE_AUTH_SCOPE_LENGTH = 32;
|
|
7073
|
-
var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
7074
|
-
function encodeBase64Url(bytes) {
|
|
7075
|
-
let output = "";
|
|
7076
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
7077
|
-
const b0 = bytes[i];
|
|
7078
|
-
const b1 = bytes[i + 1];
|
|
7079
|
-
const b2 = bytes[i + 2];
|
|
7080
|
-
output += BASE64URL_ALPHABET[b0 >> 2];
|
|
7081
|
-
output += BASE64URL_ALPHABET[(b0 & 3) << 4 | (b1 === void 0 ? 0 : b1 >> 4)];
|
|
7082
|
-
if (b1 === void 0) break;
|
|
7083
|
-
output += BASE64URL_ALPHABET[(b1 & 15) << 2 | (b2 === void 0 ? 0 : b2 >> 6)];
|
|
7084
|
-
if (b2 === void 0) break;
|
|
7085
|
-
output += BASE64URL_ALPHABET[b2 & 63];
|
|
7086
|
-
}
|
|
7087
|
-
return output;
|
|
7088
|
-
}
|
|
7089
|
-
var BASE64URL_DECODE_TABLE = (() => {
|
|
7090
|
-
const table = new Int8Array(128).fill(-1);
|
|
7091
|
-
for (let i = 0; i < BASE64URL_ALPHABET.length; i++) {
|
|
7092
|
-
table[BASE64URL_ALPHABET.charCodeAt(i)] = i;
|
|
7093
|
-
}
|
|
7094
|
-
return table;
|
|
7095
|
-
})();
|
|
7096
|
-
function decodeBase64Url(text) {
|
|
7097
|
-
if (text.length % 4 === 1) {
|
|
7098
|
-
throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text}"`);
|
|
7099
|
-
}
|
|
7100
|
-
const bytes = [];
|
|
7101
|
-
let buffer = 0;
|
|
7102
|
-
let bits = 0;
|
|
7103
|
-
for (let i = 0; i < text.length; i++) {
|
|
7104
|
-
const code = text.charCodeAt(i);
|
|
7105
|
-
const value = code < 128 ? BASE64URL_DECODE_TABLE[code] : -1;
|
|
7106
|
-
if (value === void 0 || value < 0) {
|
|
7107
|
-
throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text}"`);
|
|
7108
|
-
}
|
|
7109
|
-
buffer = buffer << 6 | value;
|
|
7110
|
-
bits += 6;
|
|
7111
|
-
if (bits >= 8) {
|
|
7112
|
-
bits -= 8;
|
|
7113
|
-
bytes.push(buffer >> bits & 255);
|
|
7114
|
-
}
|
|
7115
|
-
}
|
|
7116
|
-
const decoded = Uint8Array.from(bytes);
|
|
7117
|
-
if (encodeBase64Url(decoded) !== text) {
|
|
7118
|
-
throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text}"`);
|
|
7119
|
-
}
|
|
7120
|
-
return decoded;
|
|
7121
|
-
}
|
|
7122
|
-
function decodeAuthScope(authScope) {
|
|
7123
|
-
const bytes = decodeBase64Url(authScope);
|
|
7124
|
-
if (bytes.byteLength !== SOURCE_AUTH_SCOPE_LENGTH) {
|
|
7125
|
-
throw new Error(
|
|
7126
|
-
`[multicast-auth-catalog] authScope must decode to ${SOURCE_AUTH_SCOPE_LENGTH} raw bytes, got ${bytes.byteLength}`
|
|
7127
|
-
);
|
|
7128
|
-
}
|
|
7129
|
-
return bytes;
|
|
7130
|
-
}
|
|
7131
|
-
function decodeEd25519PublicKey(publicKey) {
|
|
7132
|
-
const bytes = decodeBase64Url(publicKey);
|
|
7133
|
-
if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
|
|
7134
|
-
throw new Error(
|
|
7135
|
-
`[multicast-auth-catalog] public key must decode to ${RAW_ED25519_KEY_LENGTH} raw bytes, got ${bytes.byteLength}`
|
|
7136
|
-
);
|
|
7137
|
-
}
|
|
7138
|
-
return bytes;
|
|
7139
|
-
}
|
|
7140
|
-
function isNonEmptyString(value) {
|
|
7141
|
-
return typeof value === "string" && value.length > 0;
|
|
7142
|
-
}
|
|
7143
|
-
function isValidAuthScopeField(value) {
|
|
7144
|
-
if (!isNonEmptyString(value)) return false;
|
|
7145
|
-
try {
|
|
7146
|
-
decodeAuthScope(value);
|
|
7147
|
-
return true;
|
|
7148
|
-
} catch {
|
|
7149
|
-
return false;
|
|
7150
|
-
}
|
|
7151
|
-
}
|
|
7152
|
-
function isValidPublicKeyField(value) {
|
|
7153
|
-
if (!isNonEmptyString(value)) return false;
|
|
7154
|
-
try {
|
|
7155
|
-
decodeEd25519PublicKey(value);
|
|
7156
|
-
return true;
|
|
7157
|
-
} catch {
|
|
7158
|
-
return false;
|
|
7159
|
-
}
|
|
7160
|
-
}
|
|
7161
|
-
function hasOnlyKeys(object, allowed) {
|
|
7162
|
-
const allowedKeys = new Set(allowed);
|
|
7163
|
-
return Object.keys(object).every((key) => allowedKeys.has(key));
|
|
7164
|
-
}
|
|
7165
|
-
function isMulticastAuthTrackConfig(obj) {
|
|
7166
|
-
if (typeof obj !== "object" || obj === null) return false;
|
|
7167
|
-
const o = obj;
|
|
7168
|
-
return hasOnlyKeys(o, ["mediaTrack", "manifestTrack", "authScope", "sourceSymbolFormat"]) && isNonEmptyString(o["mediaTrack"]) && isNonEmptyString(o["manifestTrack"]) && o["mediaTrack"] !== o["manifestTrack"] && isValidAuthScopeField(o["authScope"]) && isNonEmptyString(o["sourceSymbolFormat"]);
|
|
7169
|
-
}
|
|
7170
|
-
var VALID_COMPACTION = /* @__PURE__ */ new Set(["merkle", "none"]);
|
|
7171
|
-
var VALID_ENFORCEMENT = /* @__PURE__ */ new Set(["shadow", "enforce"]);
|
|
7172
|
-
function hasUniqueMulticastAuthTrackBindings(tracks) {
|
|
7173
|
-
const bindings = tracks.flatMap((track) => {
|
|
7174
|
-
if (typeof track !== "object" || track === null) return [];
|
|
7175
|
-
const value = track;
|
|
7176
|
-
if (typeof value["mediaTrack"] !== "string" || typeof value["sourceSymbolFormat"] !== "string") {
|
|
7177
|
-
return [];
|
|
7178
|
-
}
|
|
7179
|
-
return [JSON.stringify([value["mediaTrack"], value["sourceSymbolFormat"]])];
|
|
7180
|
-
});
|
|
7181
|
-
return new Set(bindings).size === bindings.length;
|
|
7182
|
-
}
|
|
7183
|
-
function isMulticastAuthConfig(obj) {
|
|
7184
|
-
if (typeof obj !== "object" || obj === null) return false;
|
|
7185
|
-
const o = obj;
|
|
7186
|
-
if (o["scheme"] !== "bc-provenance") return false;
|
|
7187
|
-
if (o["hash"] !== "blake3") return false;
|
|
7188
|
-
if (o["sig"] !== "ed25519") return false;
|
|
7189
|
-
if (!hasOnlyKeys(o, ["scheme", "hash", "sig", "publicKey", "keyId", "previousKey", "compaction", "enforcement", "tracks"])) return false;
|
|
7190
|
-
if (!isValidPublicKeyField(o["publicKey"])) return false;
|
|
7191
|
-
if (!isNonEmptyString(o["keyId"])) return false;
|
|
7192
|
-
if (o["previousKey"] !== void 0 && !isValidPublicKeyField(o["previousKey"])) return false;
|
|
7193
|
-
if (o["previousKey"] === o["publicKey"]) return false;
|
|
7194
|
-
if (typeof o["compaction"] !== "string" || !VALID_COMPACTION.has(o["compaction"])) return false;
|
|
7195
|
-
if (o["enforcement"] !== void 0) {
|
|
7196
|
-
if (typeof o["enforcement"] !== "string" || !VALID_ENFORCEMENT.has(o["enforcement"])) return false;
|
|
7197
|
-
}
|
|
7198
|
-
if (!Array.isArray(o["tracks"]) || o["tracks"].length === 0) return false;
|
|
7199
|
-
const tracks = o["tracks"];
|
|
7200
|
-
if (!tracks.every((t) => isMulticastAuthTrackConfig(t))) return false;
|
|
7201
|
-
const typedTracks = tracks;
|
|
7202
|
-
const scopes = typedTracks.map((t) => t.authScope);
|
|
7203
|
-
if (new Set(scopes).size !== scopes.length) return false;
|
|
7204
|
-
if (!hasUniqueMulticastAuthTrackBindings(typedTracks)) return false;
|
|
7205
|
-
const manifestTracks = typedTracks.map((t) => t.manifestTrack);
|
|
7206
|
-
if (new Set(manifestTracks).size !== manifestTracks.length) return false;
|
|
7207
|
-
return true;
|
|
7208
|
-
}
|
|
7209
|
-
function resolveMulticastAuthMode(playerMode, auth) {
|
|
7210
|
-
if (playerMode !== void 0) return playerMode;
|
|
7211
|
-
if (auth === void 0) return "off";
|
|
7212
|
-
return auth.enforcement ?? "shadow";
|
|
7213
|
-
}
|
|
7214
|
-
function resolveMulticastAuthCatalog(catalog, playerMode) {
|
|
7215
|
-
if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
|
|
7216
|
-
throw new Error("[multicast-auth-catalog] catalog must be an object");
|
|
7217
|
-
}
|
|
7218
|
-
const root = catalog;
|
|
7219
|
-
const rawAuth = root["multicast.auth"];
|
|
7220
|
-
if (rawAuth === void 0) {
|
|
7221
|
-
if (playerMode === "enforce") {
|
|
7222
|
-
throw new Error("[multicast-auth-catalog] player enforce mode requires multicast.auth");
|
|
7223
|
-
}
|
|
7224
|
-
return void 0;
|
|
7225
|
-
}
|
|
7226
|
-
if (!isMulticastAuthConfig(rawAuth)) {
|
|
7227
|
-
throw new Error("[multicast-auth-catalog] invalid multicast.auth v2 block");
|
|
7228
|
-
}
|
|
7229
|
-
const rawTracks = root["tracks"];
|
|
7230
|
-
if (!Array.isArray(rawTracks)) {
|
|
7231
|
-
throw new Error("[multicast-auth-catalog] catalog tracks must be an array");
|
|
7232
|
-
}
|
|
7233
|
-
const catalogTrackNames = new Set(
|
|
7234
|
-
rawTracks.flatMap(
|
|
7235
|
-
(track) => typeof track === "object" && track !== null && typeof track["name"] === "string" ? [track["name"]] : []
|
|
7236
|
-
)
|
|
7237
|
-
);
|
|
7238
|
-
for (const track of rawAuth.tracks) {
|
|
7239
|
-
if (!catalogTrackNames.has(track.mediaTrack)) {
|
|
7240
|
-
throw new Error(`[multicast-auth-catalog] unknown mediaTrack "${track.mediaTrack}"`);
|
|
7241
|
-
}
|
|
7242
|
-
if (!catalogTrackNames.has(track.manifestTrack)) {
|
|
7243
|
-
throw new Error(`[multicast-auth-catalog] unknown manifestTrack "${track.manifestTrack}"`);
|
|
7244
|
-
}
|
|
7245
|
-
}
|
|
7246
|
-
return {
|
|
7247
|
-
keyId: rawAuth.keyId,
|
|
7248
|
-
acceptedPublicKeys: [
|
|
7249
|
-
decodeEd25519PublicKey(rawAuth.publicKey),
|
|
7250
|
-
...rawAuth.previousKey === void 0 ? [] : [decodeEd25519PublicKey(rawAuth.previousKey)]
|
|
7251
|
-
],
|
|
7252
|
-
mode: resolveMulticastAuthMode(playerMode, rawAuth),
|
|
7253
|
-
compaction: rawAuth.compaction,
|
|
7254
|
-
tracks: rawAuth.tracks.map((track) => ({
|
|
7255
|
-
...track,
|
|
7256
|
-
authScope: decodeAuthScope(track.authScope)
|
|
7257
|
-
}))
|
|
7258
|
-
};
|
|
7259
|
-
}
|
|
7260
|
-
|
|
7261
7432
|
// src/repair-layers.ts
|
|
7262
7433
|
var REPAIR_PRIORITY_MIN = 192;
|
|
7263
7434
|
var REPAIR_PRIORITY_MAX = 255;
|
|
@@ -7641,7 +7812,7 @@ var BlockcastMmt = (() => {
|
|
|
7641
7812
|
function catalogError(code, path, message) {
|
|
7642
7813
|
throw new CmsfCatalogValidationError(code, path, message);
|
|
7643
7814
|
}
|
|
7644
|
-
function validateCmsfMmtpCatalog(value) {
|
|
7815
|
+
function validateCmsfMmtpCatalog(value, options = {}) {
|
|
7645
7816
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
7646
7817
|
catalogError("catalog_object", "$", "catalog must be an object");
|
|
7647
7818
|
}
|
|
@@ -7662,6 +7833,22 @@ var BlockcastMmt = (() => {
|
|
|
7662
7833
|
"commonTrackFields is retired; every track carries its own fields"
|
|
7663
7834
|
);
|
|
7664
7835
|
}
|
|
7836
|
+
const initDataList = catalog["initDataList"];
|
|
7837
|
+
if (initDataList !== void 0) {
|
|
7838
|
+
if (!Array.isArray(initDataList)) {
|
|
7839
|
+
catalogError("catalog_init_data_list", "$.initDataList", "initDataList must be an array");
|
|
7840
|
+
}
|
|
7841
|
+
initDataList.forEach((entry, i) => {
|
|
7842
|
+
const e = entry;
|
|
7843
|
+
const entryPath = `$.initDataList[${i}]`;
|
|
7844
|
+
if (typeof e !== "object" || e === null || Array.isArray(e) || typeof e["id"] !== "string" || e["id"].length === 0 || typeof e["type"] !== "string" || e["type"].length === 0) {
|
|
7845
|
+
catalogError("catalog_init_data_list", entryPath, "entry needs a non-empty string id and type");
|
|
7846
|
+
}
|
|
7847
|
+
if (e["type"] === "inline" && (typeof e["data"] !== "string" || e["data"].length === 0)) {
|
|
7848
|
+
catalogError("catalog_init_data_list", `${entryPath}.data`, 'an "inline" entry needs non-empty data');
|
|
7849
|
+
}
|
|
7850
|
+
});
|
|
7851
|
+
}
|
|
7665
7852
|
const tracks = catalog["tracks"];
|
|
7666
7853
|
const trackRecords = [];
|
|
7667
7854
|
const positiveInteger2 = (input) => Number.isSafeInteger(input) && input > 0;
|
|
@@ -7713,6 +7900,14 @@ var BlockcastMmt = (() => {
|
|
|
7713
7900
|
if (keyframeIntervalMs !== void 0 && !positiveNumber(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger2(keyframeIntervalTicks)) {
|
|
7714
7901
|
catalogError("track_keyframe_interval", path, "keyframe interval fields must be positive numbers");
|
|
7715
7902
|
}
|
|
7903
|
+
const anchor = track["presentationAnchorTicks"];
|
|
7904
|
+
if (anchor !== void 0 && !Number.isSafeInteger(anchor)) {
|
|
7905
|
+
catalogError("track_presentation_anchor", `${path}.presentationAnchorTicks`, "must be a safe integer");
|
|
7906
|
+
}
|
|
7907
|
+
const initRef = track["initRef"];
|
|
7908
|
+
if (initRef !== void 0 && (typeof initRef !== "string" || initRef.length === 0)) {
|
|
7909
|
+
catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
|
|
7910
|
+
}
|
|
7716
7911
|
if (packaging === "fec-repair") {
|
|
7717
7912
|
rejectRepairTrackGeometry(path, track, catalogError);
|
|
7718
7913
|
validateRepairTrackFields(describeRepairTrack(name, path, track), catalogError);
|
|
@@ -7720,9 +7915,8 @@ var BlockcastMmt = (() => {
|
|
|
7720
7915
|
rejectRepairFieldsOnMediaTrack(path, track, catalogError);
|
|
7721
7916
|
}
|
|
7722
7917
|
if (packaging === "mmtp") {
|
|
7723
|
-
|
|
7724
|
-
|
|
7725
|
-
catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mpu or mfu");
|
|
7918
|
+
if (track["mmtpMode"] !== "mfu") {
|
|
7919
|
+
catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
|
|
7726
7920
|
}
|
|
7727
7921
|
if (!positiveInteger2(timescale)) {
|
|
7728
7922
|
catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
|
|
@@ -7775,6 +7969,9 @@ var BlockcastMmt = (() => {
|
|
|
7775
7969
|
}
|
|
7776
7970
|
}
|
|
7777
7971
|
readFecBlockProfile(config["blockProfile"], `${path}.fec.blockProfile`, algorithm !== "none", catalogError);
|
|
7972
|
+
if (algorithm !== "none" && config["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE) {
|
|
7973
|
+
catalogError("track_fec", `${path}.fec.symbolSize`, "iso-ssbg1-v1 symbolSize must be at least 14");
|
|
7974
|
+
}
|
|
7778
7975
|
}
|
|
7779
7976
|
}
|
|
7780
7977
|
const repairDescriptors = trackRecords.flatMap(
|
|
@@ -7886,15 +8083,8 @@ var BlockcastMmt = (() => {
|
|
|
7886
8083
|
}
|
|
7887
8084
|
}
|
|
7888
8085
|
}
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
} catch (error) {
|
|
7892
|
-
catalogError(
|
|
7893
|
-
"multicast_auth",
|
|
7894
|
-
"$.multicast.auth",
|
|
7895
|
-
error instanceof Error ? error.message : "invalid multicast.auth v2 block"
|
|
7896
|
-
);
|
|
7897
|
-
}
|
|
8086
|
+
const [multicastIssue] = multicastCatalogIssues(catalog, options);
|
|
8087
|
+
if (multicastIssue) catalogError(multicastIssue.code, multicastIssue.path, multicastIssue.message);
|
|
7898
8088
|
validateArchive(catalog);
|
|
7899
8089
|
return catalog;
|
|
7900
8090
|
}
|
|
@@ -7913,6 +8103,36 @@ var BlockcastMmt = (() => {
|
|
|
7913
8103
|
}
|
|
7914
8104
|
return Math.ceil(interleaveDepthMs * safetyFactor);
|
|
7915
8105
|
}
|
|
8106
|
+
function fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs) {
|
|
8107
|
+
if (!Number.isFinite(interleaveDepthMs) || !(interleaveDepthMs > 0)) {
|
|
8108
|
+
throw new Error(`[FEC] interleaveDepthMs must be a finite value > 0 (got ${interleaveDepthMs}ms). Fix encoder config.`);
|
|
8109
|
+
}
|
|
8110
|
+
if (!(reorderToleranceMs >= 0) || !Number.isFinite(reorderToleranceMs)) {
|
|
8111
|
+
throw new Error(`[FEC] reorderToleranceMs must be a finite value >= 0 (got ${reorderToleranceMs}ms). It is a catalog value (fec.reorderToleranceMs), not a local default.`);
|
|
8112
|
+
}
|
|
8113
|
+
return Math.ceil(interleaveDepthMs + reorderToleranceMs);
|
|
8114
|
+
}
|
|
8115
|
+
function deriveFecRetentionBlocks(deliveryWindowMs, interleaveDepthMs) {
|
|
8116
|
+
const blocks = tryDeriveFecRetentionBlocks(deliveryWindowMs, interleaveDepthMs);
|
|
8117
|
+
if (blocks !== void 0)
|
|
8118
|
+
return blocks;
|
|
8119
|
+
if (!Number.isFinite(interleaveDepthMs) || !(interleaveDepthMs > 0)) {
|
|
8120
|
+
throw new Error(`[FEC] interleaveDepthMs must be a finite value > 0 (got ${interleaveDepthMs}ms). Fix encoder config.`);
|
|
8121
|
+
}
|
|
8122
|
+
if (!Number.isFinite(deliveryWindowMs) || !(deliveryWindowMs > 0)) {
|
|
8123
|
+
throw new Error(`[FEC] deliveryWindowMs must be a finite value > 0 (got ${deliveryWindowMs}ms). It is derived from catalog geometry, not a local default.`);
|
|
8124
|
+
}
|
|
8125
|
+
throw new Error(`[FEC] retention of ${Math.ceil(deliveryWindowMs / interleaveDepthMs) + 1} blocks exceeds the 255 the decoder and the ISO/IEC 23008-1 AL-FEC signaling byte accept (deliveryWindowMs=${deliveryWindowMs}ms over interleaveDepthMs=${interleaveDepthMs}ms). Fix the catalog geometry: a span this short cannot carry a window this wide.`);
|
|
8126
|
+
}
|
|
8127
|
+
var MAX_FEC_RETENTION_BLOCKS = 255;
|
|
8128
|
+
function tryDeriveFecRetentionBlocks(deliveryWindowMs, interleaveDepthMs) {
|
|
8129
|
+
if (!Number.isFinite(interleaveDepthMs) || !(interleaveDepthMs > 0))
|
|
8130
|
+
return void 0;
|
|
8131
|
+
if (!Number.isFinite(deliveryWindowMs) || !(deliveryWindowMs > 0))
|
|
8132
|
+
return void 0;
|
|
8133
|
+
const blocks = Math.ceil(deliveryWindowMs / interleaveDepthMs) + 1;
|
|
8134
|
+
return blocks > MAX_FEC_RETENTION_BLOCKS ? void 0 : blocks;
|
|
8135
|
+
}
|
|
7916
8136
|
|
|
7917
8137
|
// ../fec/dist/repair-group.js
|
|
7918
8138
|
var WRAP_EPOCH_BITS = 30n;
|
|
@@ -7935,13 +8155,13 @@ var BlockcastMmt = (() => {
|
|
|
7935
8155
|
function recordOf2(value) {
|
|
7936
8156
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
7937
8157
|
}
|
|
7938
|
-
function
|
|
8158
|
+
function isPositiveSafeInteger2(value) {
|
|
7939
8159
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
7940
8160
|
}
|
|
7941
8161
|
function catalogDeclaresFec(fec) {
|
|
7942
8162
|
const block = recordOf2(fec);
|
|
7943
8163
|
if (block === void 0 || block["algorithm"] === "none") return false;
|
|
7944
|
-
return
|
|
8164
|
+
return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block) && !catalogFecDeclaresUnconfigurableInstance(block);
|
|
7945
8165
|
}
|
|
7946
8166
|
function requireBoolean(value, field) {
|
|
7947
8167
|
if (typeof value !== "boolean") {
|
|
@@ -7969,6 +8189,367 @@ var BlockcastMmt = (() => {
|
|
|
7969
8189
|
return INACTIVE["reliable-moq"];
|
|
7970
8190
|
}
|
|
7971
8191
|
|
|
8192
|
+
// src/mmtp-fec-session.ts
|
|
8193
|
+
var PATH_BITS = { moq: 1, multicast: 2 };
|
|
8194
|
+
var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
|
|
8195
|
+
var _decoder, _blocks, _settled, _have, _newest, _prunedAt, _repairPacketId, _stats3, _MmtpFecSession_instances, drop_fn2, noteNewest_fn, blockStartOf_fn, countHeld_fn, noteMixed_fn, behindHorizon_fn, settle_fn, settleClean_fn, settleDecoded_fn, retireBehindHorizon_fn;
|
|
8196
|
+
var MmtpFecSession = class {
|
|
8197
|
+
/**
|
|
8198
|
+
* @throws when the catalog block lacks or misstates a field the session
|
|
8199
|
+
* needs: the block profile, K, T, `interleaveDepthMs` or
|
|
8200
|
+
* `reorderToleranceMs`. None is defaulted.
|
|
8201
|
+
*/
|
|
8202
|
+
constructor(config) {
|
|
8203
|
+
__privateAdd(this, _MmtpFecSession_instances);
|
|
8204
|
+
__privateAdd(this, _decoder);
|
|
8205
|
+
/** Blocks a repair has defined and that are not settled yet, by SS_Start. */
|
|
8206
|
+
__privateAdd(this, _blocks, /* @__PURE__ */ new Map());
|
|
8207
|
+
/** SS_Starts of settled blocks, so a later repair for one is refused. */
|
|
8208
|
+
__privateAdd(this, _settled, /* @__PURE__ */ new Set());
|
|
8209
|
+
/**
|
|
8210
|
+
* SS_IDs whose packet the parser has, with the PATH_BITS of the path it was
|
|
8211
|
+
* received on, or 0 for one the session recovered.
|
|
8212
|
+
*/
|
|
8213
|
+
__privateAdd(this, _have, /* @__PURE__ */ new Map());
|
|
8214
|
+
__privateAdd(this, _newest);
|
|
8215
|
+
/** The newest SS_ID when the remembered SS_IDs were last pruned. */
|
|
8216
|
+
__privateAdd(this, _prunedAt);
|
|
8217
|
+
__privateAdd(this, _repairPacketId);
|
|
8218
|
+
__privateAdd(this, _stats3, {
|
|
8219
|
+
sourceSymbols: 0,
|
|
8220
|
+
repairSymbols: 0,
|
|
8221
|
+
blocksClean: 0,
|
|
8222
|
+
blocksRecovered: 0,
|
|
8223
|
+
blocksFailed: 0,
|
|
8224
|
+
blocksReleased: 0,
|
|
8225
|
+
packetsRecovered: 0,
|
|
8226
|
+
packetsLost: 0,
|
|
8227
|
+
dropped: {},
|
|
8228
|
+
sourceSymbolsByPath: { moq: 0, multicast: 0 },
|
|
8229
|
+
repairSymbolsByPath: { moq: 0, multicast: 0 },
|
|
8230
|
+
mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 }
|
|
8231
|
+
});
|
|
8232
|
+
const fec = config?.fec;
|
|
8233
|
+
if (!fec || typeof fec !== "object") {
|
|
8234
|
+
throw new Error("MmtpFecSession: the catalog fec block is required");
|
|
8235
|
+
}
|
|
8236
|
+
this.blockProfile = parseFecBlockProfile(fec.blockProfile, "fec.blockProfile");
|
|
8237
|
+
this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
|
|
8238
|
+
this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
|
|
8239
|
+
const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
|
|
8240
|
+
const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
|
|
8241
|
+
this.retentionBlocks = deriveFecRetentionBlocks(
|
|
8242
|
+
fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs),
|
|
8243
|
+
interleaveDepthMs
|
|
8244
|
+
);
|
|
8245
|
+
if (typeof config.Decoder !== "function") {
|
|
8246
|
+
throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
|
|
8247
|
+
}
|
|
8248
|
+
const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile);
|
|
8249
|
+
try {
|
|
8250
|
+
decoder.configure_params(this.sourceSymbols, this.symbolSize);
|
|
8251
|
+
} catch (error) {
|
|
8252
|
+
decoder.free();
|
|
8253
|
+
throw error;
|
|
8254
|
+
}
|
|
8255
|
+
__privateSet(this, _decoder, decoder);
|
|
8256
|
+
}
|
|
8257
|
+
/** True once release() ran. */
|
|
8258
|
+
get released() {
|
|
8259
|
+
return __privateGet(this, _decoder) === null;
|
|
8260
|
+
}
|
|
8261
|
+
get stats() {
|
|
8262
|
+
return {
|
|
8263
|
+
...__privateGet(this, _stats3),
|
|
8264
|
+
dropped: { ...__privateGet(this, _stats3).dropped },
|
|
8265
|
+
sourceSymbolsByPath: { ...__privateGet(this, _stats3).sourceSymbolsByPath },
|
|
8266
|
+
repairSymbolsByPath: { ...__privateGet(this, _stats3).repairSymbolsByPath },
|
|
8267
|
+
mixedPath: { ...__privateGet(this, _stats3).mixedPath }
|
|
8268
|
+
};
|
|
8269
|
+
}
|
|
8270
|
+
/**
|
|
8271
|
+
* Feeds one received source packet: the MMTP packet without its four-byte
|
|
8272
|
+
* Source FEC Payload ID, under the SS_ID that ID stated. This is what
|
|
8273
|
+
* MmtpContainerParser's onSourceSymbol() hands over. `path` is where it
|
|
8274
|
+
* was received; a caller that only subscribes over MoQT can leave it out.
|
|
8275
|
+
*
|
|
8276
|
+
* @returns the protected packets of this packet's block that it recovered,
|
|
8277
|
+
* in SS_ID order, for the caller to feed to its parser with
|
|
8278
|
+
* `{skipFecPayloadId: true, recovered: true}`. Usually empty.
|
|
8279
|
+
*/
|
|
8280
|
+
addSource(ssId, packet, path = "moq") {
|
|
8281
|
+
const decoder = __privateGet(this, _decoder);
|
|
8282
|
+
if (!decoder) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:released");
|
|
8283
|
+
const pathBit = PATH_BITS[path];
|
|
8284
|
+
if (!pathBit) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:unknown-path");
|
|
8285
|
+
if (!Number.isInteger(ssId) || ssId < 0 || ssId > 4294967295) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:bad-ss-id");
|
|
8286
|
+
if (!ssbg1FitsSymbol(packet.byteLength, this.symbolSize)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:exceeds-symbol");
|
|
8287
|
+
if (__privateGet(this, _have).has(ssId)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:duplicate");
|
|
8288
|
+
__privateGet(this, _have).set(ssId, pathBit);
|
|
8289
|
+
__privateGet(this, _stats3).sourceSymbols++;
|
|
8290
|
+
__privateGet(this, _stats3).sourceSymbolsByPath[path]++;
|
|
8291
|
+
__privateMethod(this, _MmtpFecSession_instances, noteNewest_fn).call(this, ssId);
|
|
8292
|
+
const start = __privateMethod(this, _MmtpFecSession_instances, blockStartOf_fn).call(this, ssId);
|
|
8293
|
+
const block = start === void 0 ? void 0 : __privateGet(this, _blocks).get(start);
|
|
8294
|
+
if (block) {
|
|
8295
|
+
block.received++;
|
|
8296
|
+
block.paths |= pathBit;
|
|
8297
|
+
}
|
|
8298
|
+
let output;
|
|
8299
|
+
try {
|
|
8300
|
+
output = decoder.add_source(ssId, packet, 0);
|
|
8301
|
+
} catch {
|
|
8302
|
+
__privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:decoder-refused");
|
|
8303
|
+
output = void 0;
|
|
8304
|
+
}
|
|
8305
|
+
const recovered = [];
|
|
8306
|
+
if (start !== void 0 && block) {
|
|
8307
|
+
if (output) {
|
|
8308
|
+
recovered.push(...__privateMethod(this, _MmtpFecSession_instances, settleDecoded_fn).call(this, start, block, output));
|
|
8309
|
+
} else if (block.received >= block.ssbLength) {
|
|
8310
|
+
__privateMethod(this, _MmtpFecSession_instances, settleClean_fn).call(this, start);
|
|
8311
|
+
}
|
|
8312
|
+
}
|
|
8313
|
+
__privateMethod(this, _MmtpFecSession_instances, retireBehindHorizon_fn).call(this);
|
|
8314
|
+
return recovered;
|
|
8315
|
+
}
|
|
8316
|
+
/**
|
|
8317
|
+
* Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
|
|
8318
|
+
* 23008-1 C.5.3). A repair track carries one repair flow, so the first
|
|
8319
|
+
* repair packet fixes its packet ID and a packet of any other is refused.
|
|
8320
|
+
* `path` is where it was received, as for addSource().
|
|
8321
|
+
*
|
|
8322
|
+
* @returns the protected packets this repair symbol recovered, as for
|
|
8323
|
+
* addSource().
|
|
8324
|
+
*/
|
|
8325
|
+
addRepair(packet, path = "moq") {
|
|
8326
|
+
const decoder = __privateGet(this, _decoder);
|
|
8327
|
+
if (!decoder) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:released");
|
|
8328
|
+
const pathBit = PATH_BITS[path];
|
|
8329
|
+
if (!pathBit) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:unknown-path");
|
|
8330
|
+
let header;
|
|
8331
|
+
try {
|
|
8332
|
+
header = parseMMTPHeader(packet);
|
|
8333
|
+
} catch {
|
|
8334
|
+
return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:malformed");
|
|
8335
|
+
}
|
|
8336
|
+
const frame = parseMoqRepairFrameWithHeader(packet, header);
|
|
8337
|
+
if (!frame) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:malformed");
|
|
8338
|
+
if (__privateGet(this, _repairPacketId) === void 0) {
|
|
8339
|
+
__privateSet(this, _repairPacketId, frame.packetId);
|
|
8340
|
+
} else if (frame.packetId !== __privateGet(this, _repairPacketId)) {
|
|
8341
|
+
return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:foreign-packet-id");
|
|
8342
|
+
}
|
|
8343
|
+
if (frame.symbolData.byteLength !== this.symbolSize) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:symbol-size");
|
|
8344
|
+
if (frame.ssbLength > this.sourceSymbols) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:ssb-length");
|
|
8345
|
+
const start = frame.ssStart;
|
|
8346
|
+
let block = __privateGet(this, _blocks).get(start);
|
|
8347
|
+
if (block && block.ssbLength !== frame.ssbLength) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:conflicting-ssb-length");
|
|
8348
|
+
if (!block) {
|
|
8349
|
+
if (__privateGet(this, _settled).has(start)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:block-settled");
|
|
8350
|
+
if (__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, start)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:behind-horizon");
|
|
8351
|
+
block = { ssbLength: frame.ssbLength, received: 0, paths: 0 };
|
|
8352
|
+
__privateMethod(this, _MmtpFecSession_instances, countHeld_fn).call(this, start, block);
|
|
8353
|
+
__privateGet(this, _blocks).set(start, block);
|
|
8354
|
+
}
|
|
8355
|
+
__privateMethod(this, _MmtpFecSession_instances, noteNewest_fn).call(this, serial32Add(start, frame.ssbLength - 1));
|
|
8356
|
+
if (block.received >= block.ssbLength) {
|
|
8357
|
+
__privateMethod(this, _MmtpFecSession_instances, settleClean_fn).call(this, start);
|
|
8358
|
+
__privateMethod(this, _MmtpFecSession_instances, retireBehindHorizon_fn).call(this);
|
|
8359
|
+
return [];
|
|
8360
|
+
}
|
|
8361
|
+
let output;
|
|
8362
|
+
try {
|
|
8363
|
+
output = decoder.add_repair(start, frame.ssbLength, frame.rsId, frame.symbolData, 0);
|
|
8364
|
+
} catch {
|
|
8365
|
+
return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:decoder-refused");
|
|
8366
|
+
}
|
|
8367
|
+
__privateGet(this, _stats3).repairSymbols++;
|
|
8368
|
+
__privateGet(this, _stats3).repairSymbolsByPath[path]++;
|
|
8369
|
+
block.paths |= pathBit;
|
|
8370
|
+
const recovered = output ? __privateMethod(this, _MmtpFecSession_instances, settleDecoded_fn).call(this, start, block, output) : [];
|
|
8371
|
+
__privateMethod(this, _MmtpFecSession_instances, retireBehindHorizon_fn).call(this);
|
|
8372
|
+
return recovered;
|
|
8373
|
+
}
|
|
8374
|
+
/**
|
|
8375
|
+
* Frees the decoder and every block. Blocks still unsettled are counted as
|
|
8376
|
+
* released, not failed: nothing proved them unrecoverable. Idempotent;
|
|
8377
|
+
* returns whether this call released anything.
|
|
8378
|
+
*/
|
|
8379
|
+
release() {
|
|
8380
|
+
const decoder = __privateGet(this, _decoder);
|
|
8381
|
+
if (!decoder) return false;
|
|
8382
|
+
__privateSet(this, _decoder, null);
|
|
8383
|
+
__privateGet(this, _stats3).blocksReleased += __privateGet(this, _blocks).size;
|
|
8384
|
+
for (const block of __privateGet(this, _blocks).values()) __privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "released");
|
|
8385
|
+
__privateGet(this, _blocks).clear();
|
|
8386
|
+
__privateGet(this, _settled).clear();
|
|
8387
|
+
__privateGet(this, _have).clear();
|
|
8388
|
+
decoder.free();
|
|
8389
|
+
return true;
|
|
8390
|
+
}
|
|
8391
|
+
};
|
|
8392
|
+
_decoder = new WeakMap();
|
|
8393
|
+
_blocks = new WeakMap();
|
|
8394
|
+
_settled = new WeakMap();
|
|
8395
|
+
_have = new WeakMap();
|
|
8396
|
+
_newest = new WeakMap();
|
|
8397
|
+
_prunedAt = new WeakMap();
|
|
8398
|
+
_repairPacketId = new WeakMap();
|
|
8399
|
+
_stats3 = new WeakMap();
|
|
8400
|
+
_MmtpFecSession_instances = new WeakSet();
|
|
8401
|
+
drop_fn2 = function(reason) {
|
|
8402
|
+
__privateGet(this, _stats3).dropped[reason] = (__privateGet(this, _stats3).dropped[reason] ?? 0) + 1;
|
|
8403
|
+
return [];
|
|
8404
|
+
};
|
|
8405
|
+
noteNewest_fn = function(ssId) {
|
|
8406
|
+
if (__privateGet(this, _newest) === void 0 || serial32Precedes(__privateGet(this, _newest), ssId)) __privateSet(this, _newest, ssId);
|
|
8407
|
+
};
|
|
8408
|
+
blockStartOf_fn = function(ssId) {
|
|
8409
|
+
for (const [start, block] of __privateGet(this, _blocks)) {
|
|
8410
|
+
if (isoBlockContains(start, block.ssbLength, ssId)) return start;
|
|
8411
|
+
}
|
|
8412
|
+
return void 0;
|
|
8413
|
+
};
|
|
8414
|
+
/** Counts the sources of a new block the parser already has, and their paths. */
|
|
8415
|
+
countHeld_fn = function(start, block) {
|
|
8416
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
8417
|
+
const pathBit = __privateGet(this, _have).get(serial32Add(start, i));
|
|
8418
|
+
if (pathBit === void 0) continue;
|
|
8419
|
+
block.received++;
|
|
8420
|
+
block.paths |= pathBit;
|
|
8421
|
+
}
|
|
8422
|
+
};
|
|
8423
|
+
noteMixed_fn = function(block, outcome) {
|
|
8424
|
+
if ((block.paths & MIXED_PATHS) === MIXED_PATHS) __privateGet(this, _stats3).mixedPath[outcome]++;
|
|
8425
|
+
};
|
|
8426
|
+
/** The decoder's own rule: more than its retention behind, counted from below. */
|
|
8427
|
+
behindHorizon_fn = function(start) {
|
|
8428
|
+
const newest = __privateGet(this, _newest);
|
|
8429
|
+
if (newest === void 0) return false;
|
|
8430
|
+
return isoBlocksBehindLowerBound(start, newest, this.sourceSymbols) > this.retentionBlocks;
|
|
8431
|
+
};
|
|
8432
|
+
settle_fn = function(start) {
|
|
8433
|
+
__privateGet(this, _blocks).delete(start);
|
|
8434
|
+
__privateGet(this, _settled).add(start);
|
|
8435
|
+
};
|
|
8436
|
+
settleClean_fn = function(start) {
|
|
8437
|
+
const block = __privateGet(this, _blocks).get(start);
|
|
8438
|
+
if (!block) return;
|
|
8439
|
+
__privateMethod(this, _MmtpFecSession_instances, settle_fn).call(this, start);
|
|
8440
|
+
__privateGet(this, _stats3).blocksClean++;
|
|
8441
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "clean");
|
|
8442
|
+
try {
|
|
8443
|
+
__privateGet(this, _decoder)?.cleanup_blocks_detailed(Uint32Array.of(start));
|
|
8444
|
+
} catch {
|
|
8445
|
+
}
|
|
8446
|
+
};
|
|
8447
|
+
/**
|
|
8448
|
+
* The decoder returns a completed block as its K' ssbg_mode1 symbols,
|
|
8449
|
+
* concatenated: split by T, trim by each symbol's length field, and hand
|
|
8450
|
+
* back the packets the parser does not have yet.
|
|
8451
|
+
*/
|
|
8452
|
+
settleDecoded_fn = function(start, block, output) {
|
|
8453
|
+
__privateMethod(this, _MmtpFecSession_instances, settle_fn).call(this, start);
|
|
8454
|
+
if (output.byteLength !== block.ssbLength * this.symbolSize) {
|
|
8455
|
+
__privateGet(this, _stats3).blocksFailed++;
|
|
8456
|
+
__privateGet(this, _stats3).packetsLost += block.ssbLength - block.received;
|
|
8457
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "failed");
|
|
8458
|
+
__privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "block:decoded-length");
|
|
8459
|
+
return [];
|
|
8460
|
+
}
|
|
8461
|
+
const recovered = [];
|
|
8462
|
+
let refused = 0;
|
|
8463
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
8464
|
+
const ssId = serial32Add(start, i);
|
|
8465
|
+
if (__privateGet(this, _have).has(ssId)) continue;
|
|
8466
|
+
const symbol = output.subarray(i * this.symbolSize, (i + 1) * this.symbolSize);
|
|
8467
|
+
const packet = trimSsbg1SourceSymbol(symbol);
|
|
8468
|
+
if (!packet) {
|
|
8469
|
+
refused++;
|
|
8470
|
+
continue;
|
|
8471
|
+
}
|
|
8472
|
+
__privateGet(this, _have).set(ssId, 0);
|
|
8473
|
+
recovered.push(packet.slice());
|
|
8474
|
+
}
|
|
8475
|
+
if (refused > 0) {
|
|
8476
|
+
__privateGet(this, _stats3).blocksFailed++;
|
|
8477
|
+
__privateGet(this, _stats3).packetsLost += refused;
|
|
8478
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "failed");
|
|
8479
|
+
__privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "block:bad-ssbg1-symbol");
|
|
8480
|
+
} else if (recovered.length === 0) {
|
|
8481
|
+
__privateGet(this, _stats3).blocksClean++;
|
|
8482
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "clean");
|
|
8483
|
+
} else {
|
|
8484
|
+
__privateGet(this, _stats3).blocksRecovered++;
|
|
8485
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "recovered");
|
|
8486
|
+
}
|
|
8487
|
+
__privateGet(this, _stats3).packetsRecovered += recovered.length;
|
|
8488
|
+
return recovered;
|
|
8489
|
+
};
|
|
8490
|
+
/**
|
|
8491
|
+
* Retires every block, and every SS_ID the session remembers, that the
|
|
8492
|
+
* newest SS_ID has moved past the retention. An unsettled block retired
|
|
8493
|
+
* here is a failure: more of its sources were lost than its repair could
|
|
8494
|
+
* restore, or its repair never arrived.
|
|
8495
|
+
*/
|
|
8496
|
+
retireBehindHorizon_fn = function() {
|
|
8497
|
+
const decoder = __privateGet(this, _decoder);
|
|
8498
|
+
const newest = __privateGet(this, _newest);
|
|
8499
|
+
if (!decoder || newest === void 0) return;
|
|
8500
|
+
try {
|
|
8501
|
+
decoder.cleanup_by_ss_start(newest);
|
|
8502
|
+
} catch {
|
|
8503
|
+
}
|
|
8504
|
+
for (const [start, block] of __privateGet(this, _blocks)) {
|
|
8505
|
+
if (!__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, start)) continue;
|
|
8506
|
+
__privateMethod(this, _MmtpFecSession_instances, settle_fn).call(this, start);
|
|
8507
|
+
__privateGet(this, _stats3).blocksFailed++;
|
|
8508
|
+
__privateGet(this, _stats3).packetsLost += block.ssbLength - block.received;
|
|
8509
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "failed");
|
|
8510
|
+
}
|
|
8511
|
+
const prunedAt = __privateGet(this, _prunedAt);
|
|
8512
|
+
if (prunedAt !== void 0 && serial32Distance(prunedAt, newest) < this.sourceSymbols) return;
|
|
8513
|
+
__privateSet(this, _prunedAt, newest);
|
|
8514
|
+
for (const ssId of __privateGet(this, _have).keys()) {
|
|
8515
|
+
if (__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, ssId)) __privateGet(this, _have).delete(ssId);
|
|
8516
|
+
}
|
|
8517
|
+
for (const start of __privateGet(this, _settled)) {
|
|
8518
|
+
if (__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, start)) __privateGet(this, _settled).delete(start);
|
|
8519
|
+
}
|
|
8520
|
+
};
|
|
8521
|
+
function requirePositiveInteger(value, path) {
|
|
8522
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
8523
|
+
throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`);
|
|
8524
|
+
}
|
|
8525
|
+
return value;
|
|
8526
|
+
}
|
|
8527
|
+
function requireNumber(value, path) {
|
|
8528
|
+
if (typeof value !== "number") {
|
|
8529
|
+
throw new Error(`MmtpFecSession: ${path} is required (got ${String(value)}); it is never defaulted`);
|
|
8530
|
+
}
|
|
8531
|
+
return value;
|
|
8532
|
+
}
|
|
8533
|
+
|
|
8534
|
+
// src/catalog-network-source.ts
|
|
8535
|
+
function normalizePort(value) {
|
|
8536
|
+
const n = typeof value === "number" ? value : typeof value === "string" ? Number(value) : Number.NaN;
|
|
8537
|
+
return Number.isInteger(n) && n > 0 && n <= 65535 ? n : void 0;
|
|
8538
|
+
}
|
|
8539
|
+
function catalogAmtNetworkSource(networkSource) {
|
|
8540
|
+
const entries = Array.isArray(networkSource) ? networkSource : networkSource ? [networkSource] : [];
|
|
8541
|
+
for (const raw of entries) {
|
|
8542
|
+
if (!raw || typeof raw !== "object") continue;
|
|
8543
|
+
const ns = raw;
|
|
8544
|
+
if (ns.type !== "amt") continue;
|
|
8545
|
+
if (ns.discovery === "driad") continue;
|
|
8546
|
+
const relay = typeof ns.relay === "string" ? ns.relay.trim() : "";
|
|
8547
|
+
if (!relay) continue;
|
|
8548
|
+
return { relay, port: normalizePort(ns.port) ?? DEFAULT_AMT_RELAY_PORT };
|
|
8549
|
+
}
|
|
8550
|
+
return void 0;
|
|
8551
|
+
}
|
|
8552
|
+
|
|
7972
8553
|
// src/mmtp-to-cmaf.ts
|
|
7973
8554
|
function box(type, ...children2) {
|
|
7974
8555
|
let size = 8;
|
|
@@ -8011,8 +8592,8 @@ var BlockcastMmt = (() => {
|
|
|
8011
8592
|
}
|
|
8012
8593
|
var KEYFRAME_FLAGS = 33554432;
|
|
8013
8594
|
var DELTA_FLAGS = 16842752;
|
|
8014
|
-
var
|
|
8015
|
-
var MAX_TRACK_ID =
|
|
8595
|
+
var UINT32_MAX2 = 4294967295;
|
|
8596
|
+
var MAX_TRACK_ID = UINT32_MAX2 - 1;
|
|
8016
8597
|
var INT32_MIN = -2147483648;
|
|
8017
8598
|
var INT32_MAX = 2147483647;
|
|
8018
8599
|
function assertTrackId(trackId, label) {
|
|
@@ -8021,8 +8602,8 @@ var BlockcastMmt = (() => {
|
|
|
8021
8602
|
}
|
|
8022
8603
|
}
|
|
8023
8604
|
function assertTimescale(timescale, label) {
|
|
8024
|
-
if (!Number.isInteger(timescale) || timescale <= 0 || timescale >
|
|
8025
|
-
throw new RangeError(`${label} must be an integer in 1..${
|
|
8605
|
+
if (!Number.isInteger(timescale) || timescale <= 0 || timescale > UINT32_MAX2) {
|
|
8606
|
+
throw new RangeError(`${label} must be an integer in 1..${UINT32_MAX2}, got ${timescale}`);
|
|
8026
8607
|
}
|
|
8027
8608
|
}
|
|
8028
8609
|
function assertCompositionTimeOffsets(samples) {
|
|
@@ -9086,7 +9667,7 @@ var BlockcastMmt = (() => {
|
|
|
9086
9667
|
var SOURCE_AUTH_GROUP_CLOSE_LENGTH = 112;
|
|
9087
9668
|
var SOURCE_AUTH_MAX_OBJECTS_PER_GROUP = 4096;
|
|
9088
9669
|
var SOURCE_AUTH_MAX_TRUE_LENGTH = 16 * 1024 * 1024;
|
|
9089
|
-
var
|
|
9670
|
+
var SOURCE_AUTH_SCOPE_LENGTH = 32;
|
|
9090
9671
|
var SIGNATURE_DOMAIN = new TextEncoder().encode("blockcast-mmt-root-v1\0\0\0");
|
|
9091
9672
|
function requireBytes(name, value, length) {
|
|
9092
9673
|
if (value.byteLength !== length) {
|
|
@@ -9163,7 +9744,7 @@ var BlockcastMmt = (() => {
|
|
|
9163
9744
|
throw new Error(`objectCount must be between 1 and ${SOURCE_AUTH_MAX_OBJECTS_PER_GROUP}`);
|
|
9164
9745
|
}
|
|
9165
9746
|
requireU64("groupId", groupId);
|
|
9166
|
-
requireBytes("authScope", authScope,
|
|
9747
|
+
requireBytes("authScope", authScope, SOURCE_AUTH_SCOPE_LENGTH);
|
|
9167
9748
|
requireBytes("root", root, 32);
|
|
9168
9749
|
const preimage = new Uint8Array(100);
|
|
9169
9750
|
const view2 = new DataView(preimage.buffer);
|
|
@@ -9214,6 +9795,20 @@ var BlockcastMmt = (() => {
|
|
|
9214
9795
|
}
|
|
9215
9796
|
|
|
9216
9797
|
// ../mmt-manifest-verify/dist/verifier.js
|
|
9798
|
+
function manifestKeyFor(keys, epoch, kid) {
|
|
9799
|
+
if (new Set(keys.map((key) => key.kid)).size !== keys.length)
|
|
9800
|
+
return void 0;
|
|
9801
|
+
if (new Set(keys.map((key) => key.firstEpoch)).size !== keys.length)
|
|
9802
|
+
return void 0;
|
|
9803
|
+
let signer;
|
|
9804
|
+
for (const key of keys) {
|
|
9805
|
+
if (key.firstEpoch <= epoch && (signer === void 0 || key.firstEpoch > signer.firstEpoch))
|
|
9806
|
+
signer = key;
|
|
9807
|
+
}
|
|
9808
|
+
if (signer === void 0 || kid !== void 0 && signer.kid !== kid)
|
|
9809
|
+
return void 0;
|
|
9810
|
+
return signer.publicKey;
|
|
9811
|
+
}
|
|
9217
9812
|
function manifestBindingId(trackName, sourceSymbolFormat) {
|
|
9218
9813
|
return JSON.stringify([trackName, sourceSymbolFormat]);
|
|
9219
9814
|
}
|
|
@@ -9242,7 +9837,7 @@ var BlockcastMmt = (() => {
|
|
|
9242
9837
|
return diff === 0;
|
|
9243
9838
|
};
|
|
9244
9839
|
var isPromiseLike = (value) => typeof value === "object" && value !== null && typeof value.then === "function";
|
|
9245
|
-
var _config, _verifySignature, _onFailure, _tracks2,
|
|
9840
|
+
var _config, _verifySignature, _onFailure, _tracks2, _stats4, _disposed2, _ManifestVerifier_instances, requireTrack_fn, group_fn, validateIdentity_fn, admitAgainstEntry_fn, rejectOrShadow_fn, resolvePending_fn, closeGroup_fn, finishGroupSignature_fn, verifyAcceptedSignature_fn, failGroup_fn, removePending_fn, quarantine_fn, enforceCap_fn, giveUpOnPending_fn, failOpenTrack_fn, failOpenGroup_fn, releaseAllQuarantine_fn, failure_fn;
|
|
9246
9841
|
var ManifestVerifier = class {
|
|
9247
9842
|
constructor(options) {
|
|
9248
9843
|
__privateAdd(this, _ManifestVerifier_instances);
|
|
@@ -9250,7 +9845,7 @@ var BlockcastMmt = (() => {
|
|
|
9250
9845
|
__privateAdd(this, _verifySignature);
|
|
9251
9846
|
__privateAdd(this, _onFailure);
|
|
9252
9847
|
__privateAdd(this, _tracks2, /* @__PURE__ */ new Map());
|
|
9253
|
-
__privateAdd(this,
|
|
9848
|
+
__privateAdd(this, _stats4, {
|
|
9254
9849
|
verified: 0,
|
|
9255
9850
|
failures: Object.fromEntries(FAILURE_REASONS.map((reason) => [reason, 0])),
|
|
9256
9851
|
quarantinedBytes: 0
|
|
@@ -9268,10 +9863,10 @@ var BlockcastMmt = (() => {
|
|
|
9268
9863
|
for (const track of __privateGet(this, _tracks2).values())
|
|
9269
9864
|
quarantined += track.quarantine.length;
|
|
9270
9865
|
return {
|
|
9271
|
-
verified: __privateGet(this,
|
|
9272
|
-
failures: { ...__privateGet(this,
|
|
9866
|
+
verified: __privateGet(this, _stats4).verified,
|
|
9867
|
+
failures: { ...__privateGet(this, _stats4).failures },
|
|
9273
9868
|
quarantined,
|
|
9274
|
-
quarantinedBytes: __privateGet(this,
|
|
9869
|
+
quarantinedBytes: __privateGet(this, _stats4).quarantinedBytes
|
|
9275
9870
|
};
|
|
9276
9871
|
}
|
|
9277
9872
|
setMode(mode) {
|
|
@@ -9292,11 +9887,12 @@ var BlockcastMmt = (() => {
|
|
|
9292
9887
|
}
|
|
9293
9888
|
if (context.authScope.byteLength !== 32)
|
|
9294
9889
|
throw new Error("manifest authScope must be 32 bytes");
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9890
|
+
for (const key of context.keys) {
|
|
9891
|
+
if (key.publicKey.byteLength !== 32)
|
|
9892
|
+
throw new Error("manifest keys must carry 32-byte public keys");
|
|
9893
|
+
}
|
|
9894
|
+
if (manifestKeyFor(context.keys, context.keyEpoch) === void 0) {
|
|
9895
|
+
throw new Error(`manifest keys hold no key set signing keyEpoch ${context.keyEpoch}`);
|
|
9300
9896
|
}
|
|
9301
9897
|
for (const [name, value] of Object.entries({
|
|
9302
9898
|
broadcastNamespaceId: context.broadcastNamespaceId,
|
|
@@ -9406,7 +10002,7 @@ var BlockcastMmt = (() => {
|
|
|
9406
10002
|
_verifySignature = new WeakMap();
|
|
9407
10003
|
_onFailure = new WeakMap();
|
|
9408
10004
|
_tracks2 = new WeakMap();
|
|
9409
|
-
|
|
10005
|
+
_stats4 = new WeakMap();
|
|
9410
10006
|
_disposed2 = new WeakMap();
|
|
9411
10007
|
_ManifestVerifier_instances = new WeakSet();
|
|
9412
10008
|
requireTrack_fn = function(bindingId) {
|
|
@@ -9458,7 +10054,7 @@ var BlockcastMmt = (() => {
|
|
|
9458
10054
|
return { action: "stall", verified: false };
|
|
9459
10055
|
}
|
|
9460
10056
|
release();
|
|
9461
|
-
__privateGet(this,
|
|
10057
|
+
__privateGet(this, _stats4).verified++;
|
|
9462
10058
|
return { action: "play", verified: true };
|
|
9463
10059
|
};
|
|
9464
10060
|
rejectOrShadow_fn = function(identity, release, reason) {
|
|
@@ -9549,7 +10145,7 @@ var BlockcastMmt = (() => {
|
|
|
9549
10145
|
}
|
|
9550
10146
|
};
|
|
9551
10147
|
verifyAcceptedSignature_fn = function(track, message, signature) {
|
|
9552
|
-
const keys = track.context.
|
|
10148
|
+
const keys = [manifestKeyFor(track.context.keys, track.context.keyEpoch)];
|
|
9553
10149
|
const pending = [];
|
|
9554
10150
|
let hadSynchronousError = false;
|
|
9555
10151
|
for (const key of keys) {
|
|
@@ -9598,7 +10194,7 @@ var BlockcastMmt = (() => {
|
|
|
9598
10194
|
if (index >= 0)
|
|
9599
10195
|
track.quarantine.splice(index, 1);
|
|
9600
10196
|
track.quarantinedBytes -= pending.bytes;
|
|
9601
|
-
__privateGet(this,
|
|
10197
|
+
__privateGet(this, _stats4).quarantinedBytes -= pending.bytes;
|
|
9602
10198
|
};
|
|
9603
10199
|
quarantine_fn = function(track, group, pending) {
|
|
9604
10200
|
if (group.pending.has(pending.identity.objectId))
|
|
@@ -9606,7 +10202,7 @@ var BlockcastMmt = (() => {
|
|
|
9606
10202
|
group.pending.set(pending.identity.objectId, pending);
|
|
9607
10203
|
track.quarantine.push(pending);
|
|
9608
10204
|
track.quarantinedBytes += pending.bytes;
|
|
9609
|
-
__privateGet(this,
|
|
10205
|
+
__privateGet(this, _stats4).quarantinedBytes += pending.bytes;
|
|
9610
10206
|
__privateMethod(this, _ManifestVerifier_instances, enforceCap_fn).call(this, track);
|
|
9611
10207
|
return true;
|
|
9612
10208
|
};
|
|
@@ -9617,7 +10213,7 @@ var BlockcastMmt = (() => {
|
|
|
9617
10213
|
if (group)
|
|
9618
10214
|
group.pending.delete(pending.identity.objectId);
|
|
9619
10215
|
track.quarantinedBytes -= pending.bytes;
|
|
9620
|
-
__privateGet(this,
|
|
10216
|
+
__privateGet(this, _stats4).quarantinedBytes -= pending.bytes;
|
|
9621
10217
|
__privateMethod(this, _ManifestVerifier_instances, giveUpOnPending_fn).call(this, pending);
|
|
9622
10218
|
__privateMethod(this, _ManifestVerifier_instances, failure_fn).call(this, pending.identity, "manifestAbsent");
|
|
9623
10219
|
console.warn(`[ManifestVerifier] quarantine cap eviction track=${pending.identity.trackName} group=${pending.identity.groupId} object=${pending.identity.objectId} disposition=${__privateGet(this, _config).mode === "enforce" ? "drop" : "fail-open"}`);
|
|
@@ -9674,7 +10270,7 @@ var BlockcastMmt = (() => {
|
|
|
9674
10270
|
};
|
|
9675
10271
|
failure_fn = function(identity, reason) {
|
|
9676
10272
|
var _a;
|
|
9677
|
-
__privateGet(this,
|
|
10273
|
+
__privateGet(this, _stats4).failures[reason]++;
|
|
9678
10274
|
(_a = __privateGet(this, _onFailure)) == null ? void 0 : _a.call(this, {
|
|
9679
10275
|
trackName: identity.trackName,
|
|
9680
10276
|
...identity.bindingId === void 0 ? {} : { bindingId: identity.bindingId },
|
|
@@ -9684,59 +10280,132 @@ var BlockcastMmt = (() => {
|
|
|
9684
10280
|
});
|
|
9685
10281
|
};
|
|
9686
10282
|
|
|
9687
|
-
// src/
|
|
9688
|
-
|
|
9689
|
-
|
|
9690
|
-
|
|
9691
|
-
|
|
9692
|
-
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
9715
|
-
|
|
10283
|
+
// src/multicast-auth-catalog.ts
|
|
10284
|
+
var RAW_ED25519_KEY_LENGTH = 32;
|
|
10285
|
+
var DEFAULT_MAX_AUTH_DELAY_MS = 200;
|
|
10286
|
+
var DEFAULT_MANIFEST_TIMER_MS = 20;
|
|
10287
|
+
var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
10288
|
+
function encodeBase64Url(bytes) {
|
|
10289
|
+
let output = "";
|
|
10290
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
10291
|
+
const b0 = bytes[i];
|
|
10292
|
+
const b1 = bytes[i + 1];
|
|
10293
|
+
const b2 = bytes[i + 2];
|
|
10294
|
+
output += BASE64URL_ALPHABET[b0 >> 2];
|
|
10295
|
+
output += BASE64URL_ALPHABET[(b0 & 3) << 4 | (b1 === void 0 ? 0 : b1 >> 4)];
|
|
10296
|
+
if (b1 === void 0) break;
|
|
10297
|
+
output += BASE64URL_ALPHABET[(b1 & 15) << 2 | (b2 === void 0 ? 0 : b2 >> 6)];
|
|
10298
|
+
if (b2 === void 0) break;
|
|
10299
|
+
output += BASE64URL_ALPHABET[b2 & 63];
|
|
10300
|
+
}
|
|
10301
|
+
return output;
|
|
10302
|
+
}
|
|
10303
|
+
var BASE64URL_DECODE_TABLE = (() => {
|
|
10304
|
+
const table = new Int8Array(128).fill(-1);
|
|
10305
|
+
for (let i = 0; i < BASE64URL_ALPHABET.length; i++) {
|
|
10306
|
+
table[BASE64URL_ALPHABET.charCodeAt(i)] = i;
|
|
10307
|
+
}
|
|
10308
|
+
return table;
|
|
10309
|
+
})();
|
|
10310
|
+
function decodeBase64Url(text) {
|
|
10311
|
+
if (text.length % 4 === 1) {
|
|
10312
|
+
throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text}"`);
|
|
10313
|
+
}
|
|
10314
|
+
const bytes = [];
|
|
10315
|
+
let buffer = 0;
|
|
10316
|
+
let bits = 0;
|
|
10317
|
+
for (let i = 0; i < text.length; i++) {
|
|
10318
|
+
const code = text.charCodeAt(i);
|
|
10319
|
+
const value = code < 128 ? BASE64URL_DECODE_TABLE[code] : -1;
|
|
10320
|
+
if (value === void 0 || value < 0) {
|
|
10321
|
+
throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text}"`);
|
|
10322
|
+
}
|
|
10323
|
+
buffer = buffer << 6 | value;
|
|
10324
|
+
bits += 6;
|
|
10325
|
+
if (bits >= 8) {
|
|
10326
|
+
bits -= 8;
|
|
10327
|
+
bytes.push(buffer >> bits & 255);
|
|
10328
|
+
}
|
|
10329
|
+
}
|
|
10330
|
+
const decoded = Uint8Array.from(bytes);
|
|
10331
|
+
if (encodeBase64Url(decoded) !== text) {
|
|
10332
|
+
throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text}"`);
|
|
10333
|
+
}
|
|
10334
|
+
return decoded;
|
|
10335
|
+
}
|
|
10336
|
+
function decodeEd25519PublicKey(publicKey) {
|
|
10337
|
+
const bytes = decodeBase64Url(publicKey);
|
|
10338
|
+
if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
|
|
10339
|
+
throw new Error(
|
|
10340
|
+
`[multicast-auth-catalog] public key must decode to ${RAW_ED25519_KEY_LENGTH} raw bytes, got ${bytes.byteLength}`
|
|
10341
|
+
);
|
|
10342
|
+
}
|
|
10343
|
+
return bytes;
|
|
10344
|
+
}
|
|
10345
|
+
function resolveMulticastAuthCatalog(catalog, options = {}) {
|
|
10346
|
+
if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
|
|
10347
|
+
throw new Error("[multicast-auth-catalog] catalog must be an object");
|
|
10348
|
+
}
|
|
10349
|
+
const issues = multicastCatalogIssues(catalog, options);
|
|
10350
|
+
const fatal = issues.find((issue) => issue.endpointIndex === void 0);
|
|
10351
|
+
if (fatal) throw new Error(`[multicast-auth-catalog] ${fatal.path}: ${fatal.message}`);
|
|
10352
|
+
const multicast = catalog["multicast"];
|
|
10353
|
+
const auth = multicast?.["auth"];
|
|
10354
|
+
if (auth === void 0) {
|
|
10355
|
+
if (options.requireAuth) {
|
|
10356
|
+
throw new Error("[multicast-auth-catalog] authentication is pinned but the catalog declares no multicast.auth");
|
|
10357
|
+
}
|
|
10358
|
+
return void 0;
|
|
10359
|
+
}
|
|
10360
|
+
const ignored = new Set(issues.map((issue) => issue.endpointIndex));
|
|
10361
|
+
const endpoints = multicast["endpoints"] ?? [];
|
|
10362
|
+
const flows = [];
|
|
10363
|
+
endpoints.forEach((endpoint, endpointIndex) => {
|
|
10364
|
+
if (ignored.has(endpointIndex)) return;
|
|
10365
|
+
const flowAuth = endpoint["auth"];
|
|
10366
|
+
flows.push({
|
|
10367
|
+
endpointIndex,
|
|
10368
|
+
source: endpoint["sourceAddress"] ?? flowAuth.senderAddress,
|
|
10369
|
+
groupAddress: endpoint["groupAddress"],
|
|
10370
|
+
port: endpoint["port"],
|
|
10371
|
+
bandwidth: endpoint["bandwidth"],
|
|
10372
|
+
manifestPort: flowAuth.manifestPort,
|
|
10373
|
+
streamId: flowAuth.streamId,
|
|
10374
|
+
maxAuthDelayMs: flowAuth.maxAuthDelayMs ?? DEFAULT_MAX_AUTH_DELAY_MS,
|
|
10375
|
+
manifestTimerMs: flowAuth.manifestTimerMs ?? DEFAULT_MANIFEST_TIMER_MS,
|
|
10376
|
+
...flowAuth.manifestTrack === void 0 ? {} : { manifestTrack: flowAuth.manifestTrack },
|
|
10377
|
+
tracks: (endpoint["tracks"] ?? []).map(({ name, packetId }) => ({
|
|
10378
|
+
name,
|
|
10379
|
+
packetId
|
|
10380
|
+
}))
|
|
9716
10381
|
});
|
|
9717
|
-
byManifestTrack.set(binding.manifestTrack, planned);
|
|
9718
|
-
return planned;
|
|
9719
10382
|
});
|
|
9720
|
-
let disposed = false;
|
|
9721
10383
|
return {
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
10384
|
+
keys: auth.keys.map((key) => ({ kid: key.kid, publicKey: decodeEd25519PublicKey(key.publicKey), firstEpoch: key.firstEpoch })).sort((a, b) => a.firstEpoch - b.firstEpoch),
|
|
10385
|
+
minEpoch: auth.minEpoch,
|
|
10386
|
+
flows
|
|
10387
|
+
};
|
|
10388
|
+
}
|
|
10389
|
+
function multicastAuthKeyFor(resolved, kid, epoch) {
|
|
10390
|
+
return manifestKeyFor(resolved.keys, epoch, kid);
|
|
10391
|
+
}
|
|
10392
|
+
|
|
10393
|
+
// src/manifest-auth-plan.ts
|
|
10394
|
+
function createManifestAuthPlan(catalog, options = {}) {
|
|
10395
|
+
const resolved = resolveMulticastAuthCatalog(catalog, options);
|
|
10396
|
+
if (!resolved) return void 0;
|
|
10397
|
+
const byManifestTrack = /* @__PURE__ */ new Map();
|
|
10398
|
+
for (const flow of resolved.flows) {
|
|
10399
|
+
if (flow.manifestTrack !== void 0) byManifestTrack.set(flow.manifestTrack, flow);
|
|
10400
|
+
}
|
|
10401
|
+
return {
|
|
10402
|
+
keys: resolved.keys,
|
|
10403
|
+
minEpoch: resolved.minEpoch,
|
|
10404
|
+
flows: resolved.flows,
|
|
9725
10405
|
manifestTracks: [...byManifestTrack.keys()],
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
},
|
|
9730
|
-
ingestManifestPayload(manifestTrack, payload) {
|
|
9731
|
-
const binding = byManifestTrack.get(manifestTrack);
|
|
9732
|
-
if (!binding) throw new Error(`unknown manifest subscription track ${manifestTrack}`);
|
|
9733
|
-
verifier.ingestManifestFrame(binding.bindingId, payload);
|
|
9734
|
-
},
|
|
9735
|
-
dispose() {
|
|
9736
|
-
if (disposed) return;
|
|
9737
|
-
disposed = true;
|
|
9738
|
-
verifier.dispose();
|
|
9739
|
-
}
|
|
10406
|
+
keyFor: (kid, epoch) => multicastAuthKeyFor(resolved, kid, epoch),
|
|
10407
|
+
flowForManifestPort: (source, groupAddress, manifestPort) => resolved.flows.find((flow) => flow.source === source && flow.groupAddress === groupAddress && flow.manifestPort === manifestPort),
|
|
10408
|
+
flowForManifestTrack: (manifestTrack) => byManifestTrack.get(manifestTrack)
|
|
9740
10409
|
};
|
|
9741
10410
|
}
|
|
9742
10411
|
return __toCommonJS(no_modules_exports);
|