@blockcast/mmt-container 2.2.0-main.31094c688fee → 2.2.0-main.32c089a563e3
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 +29 -1
- package/dist/__tests__/ad-creative-signer.d.ts +2 -1
- package/dist/__tests__/ad-creative-signer.d.ts.map +1 -1
- package/dist/ad-beacon.d.ts +1 -1
- package/dist/ad-beacon.js.map +1 -1
- package/dist/ad-creative-record.d.ts +13 -4
- package/dist/ad-creative-record.d.ts.map +1 -1
- package/dist/ad-creative-record.js +27 -16
- package/dist/ad-creative-record.js.map +2 -2
- package/dist/ad-creative-timeline.d.ts +6 -6
- package/dist/ad-creative-timeline.d.ts.map +1 -1
- package/dist/ad-creative-timeline.js +31 -17
- package/dist/ad-creative-timeline.js.map +2 -2
- package/dist/authored-timing.d.ts.map +1 -1
- package/dist/authored-timing.js +31 -0
- package/dist/authored-timing.js.map +3 -3
- package/dist/browser-runtime.js +23511 -22715
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +3 -3
- package/dist/carp-catalog.js.map +1 -1
- package/dist/catalog-fec-params.d.ts +12 -14
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +11 -5
- package/dist/catalog-fec-params.js.map +2 -2
- package/dist/cmaf-block-assembler.d.ts +6 -0
- package/dist/cmaf-block-assembler.d.ts.map +1 -1
- package/dist/cmaf-block-assembler.js +35 -1
- package/dist/cmaf-block-assembler.js.map +3 -3
- package/dist/conceal-timeline.d.ts +18 -13
- package/dist/conceal-timeline.d.ts.map +1 -1
- package/dist/conceal-timeline.js +64 -31
- package/dist/conceal-timeline.js.map +3 -3
- package/dist/datagram-leg-deadline.d.ts +35 -0
- package/dist/datagram-leg-deadline.d.ts.map +1 -1
- package/dist/datagram-leg-deadline.js +13 -0
- package/dist/datagram-leg-deadline.js.map +2 -2
- package/dist/duplicate-ledger.d.ts +8 -4
- package/dist/duplicate-ledger.d.ts.map +1 -1
- package/dist/duplicate-ledger.js +4 -0
- package/dist/duplicate-ledger.js.map +2 -2
- package/dist/fec-manager.d.ts +67 -4
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +9 -4
- package/dist/fec-manager.js.map +2 -2
- package/dist/feed-gate.d.ts +43 -8
- package/dist/feed-gate.d.ts.map +1 -1
- package/dist/feed-gate.js +52 -7
- package/dist/feed-gate.js.map +2 -2
- package/dist/fetch-on-gap.d.ts +318 -0
- package/dist/fetch-on-gap.d.ts.map +1 -0
- package/dist/fetch-on-gap.js +1960 -0
- package/dist/fetch-on-gap.js.map +7 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -3
- package/dist/index.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js.map +2 -2
- package/dist/mmtp-router.d.ts +59 -0
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +2603 -2453
- package/dist/mmtp-router.js.map +4 -4
- package/dist/multicast-manager.d.ts +48 -3
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +7885 -7618
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +8 -0
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +12 -1
- package/dist/multicast-transport.js.map +2 -2
- package/dist/no-modules.js.map +2 -2
- package/dist/repair-layer-subscriptions.d.ts +10 -7
- package/dist/repair-layer-subscriptions.d.ts.map +1 -1
- package/dist/repair-layer-subscriptions.js +1 -1
- package/dist/repair-layer-subscriptions.js.map +2 -2
- package/package.json +7 -6
- package/src/ad-beacon.ts +1 -1
- package/src/ad-creative-record.ts +50 -20
- package/src/ad-creative-timeline.ts +14 -10
- package/src/authored-timing.ts +6 -0
- package/src/carp-catalog.ts +3 -3
- package/src/catalog-fec-params.ts +26 -18
- package/src/cmaf-block-assembler.ts +14 -1
- package/src/conceal-timeline.ts +37 -40
- package/src/datagram-leg-deadline.ts +49 -0
- package/src/duplicate-ledger.ts +12 -4
- package/src/fec-manager.ts +81 -5
- package/src/feed-gate.ts +95 -11
- package/src/fetch-on-gap.ts +907 -0
- package/src/index.ts +23 -1
- package/src/mmtp-router.ts +211 -15
- package/src/multicast-manager.ts +108 -2
- package/src/multicast-transport.ts +27 -2
- package/src/repair-layer-subscriptions.ts +11 -8
- package/test-vectors/reordered-video-v1.json +119 -0
- package/test-vectors/source-gap-fetch.json +843 -0
package/README.md
CHANGED
|
@@ -495,6 +495,16 @@ Every FEC block still gets in-band FEC decode. On top of that:
|
|
|
495
495
|
never stalls. The same object is the manager's `gap` lifecycle event.
|
|
496
496
|
- **Concealment** is hold-last-good-frame (`HoldLastTimeline`) plus exact
|
|
497
497
|
audio sizing (`AudioGapConcealer`). No bitstream is ever synthesised.
|
|
498
|
+
- **Reordered video (B-frames)** is ordered by decode time and shown by
|
|
499
|
+
presentation time. The frame callback delivers frames in decode order:
|
|
500
|
+
`RoutedFrameMeta.timestamp` is the presentation time, and
|
|
501
|
+
`decodeTimestamp ?? timestamp` is the order key (`decodeTimestamp` is set
|
|
502
|
+
only on a frame with a composition offset). A video `CmafBlockSample`
|
|
503
|
+
carries its decode time in `timestamp` and the offset beside it in
|
|
504
|
+
`compositionTimeOffset`; an audio sample keeps its presentation time.
|
|
505
|
+
`HoldLastTimeline` sizes each sample to the next one appended in decode
|
|
506
|
+
time, and over a hole at least to that sample's presentation time. A
|
|
507
|
+
missing frame is a hole in decode order, never a step in timestamps.
|
|
498
508
|
- **The feed gate (`./feed-gate`).** A video frame may state, in the
|
|
499
509
|
`priority` byte of its DU header, the one earlier frame it needs
|
|
500
510
|
(`decodeFrameNeeds`; vectors in `test-vectors/frame-needs-v1.json`). The
|
|
@@ -503,7 +513,11 @@ Every FEC block still gets in-band FEC decode. On top of that:
|
|
|
503
513
|
frame only if that frame was fed since the last keyframe, so a loss holds
|
|
504
514
|
only the frames it reaches. It answers only inside a GOP whose keyframe
|
|
505
515
|
carried 254 and only for a decoder that does not conceal
|
|
506
|
-
(`decoderTolerance`: every codec but H.264
|
|
516
|
+
(`decoderTolerance`: every codec but H.264, and H.264 too once the track
|
|
517
|
+
is reordered, that is, a sample showed a composition offset: pass
|
|
518
|
+
`decoderTolerance(codec, true)` and `videoConcealModeForCodec(codec, true)`
|
|
519
|
+
from then on, and `reordered: true` on the frames handed to the gate).
|
|
520
|
+
Everywhere else it answers
|
|
507
521
|
`unread` and the sink runs its own stall and hold. A WebCodecs sink calls
|
|
508
522
|
`admit`, `fed`, `requireKeyframe` and `onDecoderFailure`; an MSE sink passes
|
|
509
523
|
`needs` and `tolerance` to `HoldLastTimeline`, which owns a gate, and
|
|
@@ -519,6 +533,20 @@ This package depends on the FEC primitives from:
|
|
|
519
533
|
- **`@blockcast/mmt-fec`** — RaptorQ WASM decoder + OTI codec + `fecBlockDeadlineMs` / `fecBlockBudgetMs`
|
|
520
534
|
- **`@blockcast/fec-worker`** — Web Worker host, `FecWorkerClient`, `FecTrackStats`
|
|
521
535
|
|
|
536
|
+
#### Breaking: a video `CmafBlockSample.timestamp` is the decode time
|
|
537
|
+
|
|
538
|
+
For video, `CmafBlockSample.timestamp` is the decode time, and so is the
|
|
539
|
+
`timestamp` of the sample handed to `CmafBlockAssembler.onSample` and to the
|
|
540
|
+
router's `onMseSample`. It was the presentation time. The presentation time is
|
|
541
|
+
`timestamp + compositionTimeOffset`. Nothing differs for a stream without
|
|
542
|
+
composition offsets: there the two times are one, and `compositionTimeOffset`
|
|
543
|
+
is zero or absent. An audio sample is unchanged.
|
|
544
|
+
|
|
545
|
+
A consumer that read `timestamp` as the time a picture is shown now adds
|
|
546
|
+
`compositionTimeOffset` to it. A consumer that writes `timestamp` to `tfdt`
|
|
547
|
+
and `compositionTimeOffset` to `trun` needs no change: before, each of its
|
|
548
|
+
pictures landed one offset late.
|
|
549
|
+
|
|
522
550
|
### MMTP → CMAF demux (`./mmtp-to-cmaf`)
|
|
523
551
|
|
|
524
552
|
Converts reassembled MFU samples (raw codec data: AVCC NALUs, AAC ADTS-stripped, Opus packets) into ISO/IEC 14496-12 fMP4 segments (`moof` + `mdat`) suitable for `MediaSource.appendBuffer()`. ISOBMFF box construction is inline — no `mp4-muxer` / `mp4box.js` dependency.
|
|
@@ -6,6 +6,7 @@ import { type AdCreativeKeys } from '../ad-creative-record.js';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function testSigner(kid?: string, seed?: number): {
|
|
8
8
|
keys: AdCreativeKeys;
|
|
9
|
-
|
|
9
|
+
/** `header` adds protected header members, such as iat (riedl 4.5). */
|
|
10
|
+
sign(record: Record<string, unknown>, header?: Record<string, unknown>): Record<string, unknown>;
|
|
10
11
|
};
|
|
11
12
|
//# sourceMappingURL=ad-creative-signer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ad-creative-signer.d.ts","sourceRoot":"","sources":["../../src/__tests__/ad-creative-signer.ts"],"names":[],"mappings":"AACA,OAAO,EAAuC,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAKnG;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,SAAmB,EAAE,IAAI,SAAI,GAAG;IAC5D,IAAI,EAAE,cAAc,CAAA;IACpB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"ad-creative-signer.d.ts","sourceRoot":"","sources":["../../src/__tests__/ad-creative-signer.ts"],"names":[],"mappings":"AACA,OAAO,EAAuC,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAKnG;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,SAAmB,EAAE,IAAI,SAAI,GAAG;IAC5D,IAAI,EAAE,cAAc,CAAA;IACpB,uEAAuE;IACvE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjG,CAYA"}
|
package/dist/ad-beacon.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Beacon planning for ad creative signaling (draft-riedl-moq-ad-creative-signaling-
|
|
2
|
+
* Beacon planning for ad creative signaling (draft-riedl-moq-ad-creative-signaling-02 7, 12):
|
|
3
3
|
* which URL to request and when. No I/O and no timers here (the cmcd-producer.ts precedent):
|
|
4
4
|
* the player sends each plan at sendAtMs with
|
|
5
5
|
* fetch(url, { mode: 'no-cors', credentials: 'omit', keepalive: true, referrerPolicy: 'no-referrer' }).
|
package/dist/ad-beacon.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/ad-beacon.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Beacon planning for ad creative signaling (draft-riedl-moq-ad-creative-signaling-
|
|
4
|
+
"sourcesContent": ["/**\n * Beacon planning for ad creative signaling (draft-riedl-moq-ad-creative-signaling-02 7, 12):\n * which URL to request and when. No I/O and no timers here (the cmcd-producer.ts precedent):\n * the player sends each plan at sendAtMs with\n * fetch(url, { mode: 'no-cors', credentials: 'omit', keepalive: true, referrerPolicy: 'no-referrer' }).\n * The player calls this only for events the timeline emitted, so only for verified records.\n */\nimport type { AdTrackEvent } from './ad-creative-timeline.js'\n\nexport interface AdBeaconPolicy {\n /** Lower-case host[:port] beacons may go to (riedl 12.1), typically the distributor's beacon proxy. Empty: nothing is sent. */\n readonly authorities: readonly string[]\n /** Uniform jitter window W in ms (riedl 7.2). Size it from the audience: W >= 1000 * N * k / C ms, for N receivers,\n * k requests each at that instant and C beacon-proxy requests/s. */\n readonly jitterMs: number\n /** Event types sent at once, unjittered: the verification-critical ones (riedl 7.2). */\n readonly immediate?: readonly string[]\n /** Pseudonymous, session-scoped client id appended as a query parameter (riedl 7.1). Never a device id. */\n readonly clientId?: { readonly param: string; readonly value: string }\n /** Query parameter carrying the event's wallclock ms on a jittered request (riedl 7.2). */\n readonly eventTimeParam?: string\n /** URLs sent per event at most; the rest are suppressed (riedl 12.2). Default 16, also used for a NaN, infinite or negative value. */\n readonly maxUrlsPerEvent?: number\n}\n\nexport type AdBeaconPlan =\n | { readonly url: string; readonly sendAtMs: number; readonly eventType: string }\n | { readonly url: string; readonly suppressed: 'authority' | 'cap' | 'macro'; readonly eventType: string }\n\n/** A VAST macro such as [CACHEBUSTING]: riedl 7's first pattern (client-side substitution) is not supported. */\nconst VAST_MACRO = /\\[[A-Z0-9_]+\\]/\n\n/** `random` gives the jitter phase in [0, 1). The player passes one phase drawn per session, so a device's events\n * keep their order and spacing while the audience still spreads uniformly over [0, W) (riedl 7.2). */\nexport function planAdBeacons(event: AdTrackEvent, policy: AdBeaconPolicy, nowMs: number, random: () => number = Math.random): AdBeaconPlan[] {\n const jittered = policy.jitterMs > 0 && !(policy.immediate ?? []).includes(event.eventType)\n const delay = jittered ? Math.floor(random() * policy.jitterMs) : 0\n const params: string[] = []\n if (policy.clientId) params.push(`${encodeURIComponent(policy.clientId.param)}=${encodeURIComponent(policy.clientId.value)}`)\n if (policy.eventTimeParam && jittered) params.push(`${encodeURIComponent(policy.eventTimeParam)}=${nowMs}`)\n // A malformed setting (NaN from Number(undefined)) must not turn the cap off: i >= NaN is always false.\n const max = policy.maxUrlsPerEvent\n const cap = max !== undefined && Number.isFinite(max) && max >= 0 ? max : 16\n return event.urls.map((raw, i): AdBeaconPlan => {\n if (i >= cap) return { url: raw, suppressed: 'cap', eventType: event.eventType }\n // Never sent unexpanded, and a device-identifier macro is never expanded (riedl 7.1, R33).\n if (VAST_MACRO.test(raw)) return { url: raw, suppressed: 'macro', eventType: event.eventType }\n const url = new URL(raw) // https and parseable: checked when the record was accepted (riedl 12.3)\n if (!policy.authorities.includes(url.host)) return { url: raw, suppressed: 'authority', eventType: event.eventType }\n // Append without re-encoding the capability URL's own query; a fragment stays last.\n if (params.length > 0) url.search = url.search ? `${url.search}&${params.join('&')}` : `?${params.join('&')}`\n return { url: url.href, sendAtMs: nowMs + delay, eventType: event.eventType }\n })\n}\n"],
|
|
5
5
|
"mappings": ";AA8BA,IAAM,aAAa;AAIZ,SAAS,cAAc,OAAqB,QAAwB,OAAe,SAAuB,KAAK,QAAwB;AAC5I,QAAM,WAAW,OAAO,WAAW,KAAK,EAAE,OAAO,aAAa,CAAC,GAAG,SAAS,MAAM,SAAS;AAC1F,QAAM,QAAQ,WAAW,KAAK,MAAM,OAAO,IAAI,OAAO,QAAQ,IAAI;AAClE,QAAM,SAAmB,CAAC;AAC1B,MAAI,OAAO,SAAU,QAAO,KAAK,GAAG,mBAAmB,OAAO,SAAS,KAAK,CAAC,IAAI,mBAAmB,OAAO,SAAS,KAAK,CAAC,EAAE;AAC5H,MAAI,OAAO,kBAAkB,SAAU,QAAO,KAAK,GAAG,mBAAmB,OAAO,cAAc,CAAC,IAAI,KAAK,EAAE;AAE1G,QAAM,MAAM,OAAO;AACnB,QAAM,MAAM,QAAQ,UAAa,OAAO,SAAS,GAAG,KAAK,OAAO,IAAI,MAAM;AAC1E,SAAO,MAAM,KAAK,IAAI,CAAC,KAAK,MAAoB;AAC9C,QAAI,KAAK,IAAK,QAAO,EAAE,KAAK,KAAK,YAAY,OAAO,WAAW,MAAM,UAAU;AAE/E,QAAI,WAAW,KAAK,GAAG,EAAG,QAAO,EAAE,KAAK,KAAK,YAAY,SAAS,WAAW,MAAM,UAAU;AAC7F,UAAM,MAAM,IAAI,IAAI,GAAG;AACvB,QAAI,CAAC,OAAO,YAAY,SAAS,IAAI,IAAI,EAAG,QAAO,EAAE,KAAK,KAAK,YAAY,aAAa,WAAW,MAAM,UAAU;AAEnH,QAAI,OAAO,SAAS,EAAG,KAAI,SAAS,IAAI,SAAS,GAAG,IAAI,MAAM,IAAI,OAAO,KAAK,GAAG,CAAC,KAAK,IAAI,OAAO,KAAK,GAAG,CAAC;AAC3G,WAAO,EAAE,KAAK,IAAI,MAAM,UAAU,QAAQ,OAAO,WAAW,MAAM,UAAU;AAAA,EAC9E,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
/** kid -> raw 32-byte Ed25519 public key: one channel's JWK Set (riedl 4.5). */
|
|
2
2
|
export type AdCreativeKeys = ReadonlyMap<string, Uint8Array>;
|
|
3
|
-
export type AdSigVerdict = 'verified' | 'unsigned' | 'sig' | 'alg' | 'kid' | 'signature';
|
|
3
|
+
export type AdSigVerdict = 'verified' | 'unsigned' | 'sig' | 'alg' | 'kid' | 'signature' | 'iat';
|
|
4
|
+
/** riedl 4.5: a maximum age for records, provisioned with the key set. Without maxAgeS, iat is ignored. */
|
|
5
|
+
export interface AdSigMaxAge {
|
|
6
|
+
/** Seconds a record's iat may lie behind now. */
|
|
7
|
+
readonly maxAgeS?: number;
|
|
8
|
+
/** Seconds iat may lie ahead of now, "the clock difference the deployment allows" (riedl 4.5). Default 30. */
|
|
9
|
+
readonly maxSkewS?: number;
|
|
10
|
+
/** Unix ms. A deployment's time reference where device clocks are unreliable (riedl 4.5). Default Date.now. */
|
|
11
|
+
readonly now?: () => number;
|
|
12
|
+
}
|
|
4
13
|
/**
|
|
5
14
|
* The host-provisioned JWK Set (RFC 7517): OKP/Ed25519 public keys by kid (RFC 8037). This set is
|
|
6
15
|
* the only key source; jku, jwk, x5u and x5c in a header are never read (riedl 4.5). Never throws:
|
|
@@ -12,7 +21,7 @@ export declare function importAdCreativeJwks(jwks: unknown, kids?: readonly stri
|
|
|
12
21
|
/** RFC 8785 for JSON.parse output: riedl's reference canonicalize() (scripts/sign-record.mjs at 443f90b2). */
|
|
13
22
|
export declare function canonicalJson(value: unknown): string;
|
|
14
23
|
/** riedl 4.5 for one record as parsed from JSON: the verification entry point. */
|
|
15
|
-
export declare function verifyAdCreativeSig(record: Readonly<Record<string, unknown>>, keys: AdCreativeKeys): AdSigVerdict;
|
|
24
|
+
export declare function verifyAdCreativeSig(record: Readonly<Record<string, unknown>>, keys: AdCreativeKeys, maxAge?: AdSigMaxAge): AdSigVerdict;
|
|
16
25
|
export declare const AD_CREATIVE_EVENT_TYPE = "urn:svta:advertising-wg:ad-creative-signaling";
|
|
17
26
|
/** riedl 12.3 size limit. An Object of two signed pods is about 4.4 KB. */
|
|
18
27
|
export declare const AD_OBJECT_MAX_BYTES = 65536;
|
|
@@ -59,7 +68,7 @@ export interface AdObjectResult {
|
|
|
59
68
|
readonly records: readonly AdRecordResult[];
|
|
60
69
|
}
|
|
61
70
|
/** One record: riedl 4.1 and 4.3 rules, 12.3 limits, SVTA flags, then the 4.5 signature. */
|
|
62
|
-
export declare function parseAdCreativeRecord(value: unknown, keys: AdCreativeKeys): AdRecordResult;
|
|
71
|
+
export declare function parseAdCreativeRecord(value: unknown, keys: AdCreativeKeys, maxAge?: AdSigMaxAge): AdRecordResult;
|
|
63
72
|
/** One MoQ Object of the track (msf-01 8.1: a JSON array of records). A gzip Object (MSF_COMPRESSION, msf 12.1) is not inflated here, so it drops as 'utf8' or 'json'. */
|
|
64
|
-
export declare function parseAdCreativeObject(bytes: Uint8Array, keys: AdCreativeKeys): AdObjectResult;
|
|
73
|
+
export declare function parseAdCreativeObject(bytes: Uint8Array, keys: AdCreativeKeys, maxAge?: AdSigMaxAge): AdObjectResult;
|
|
65
74
|
//# sourceMappingURL=ad-creative-record.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ad-creative-record.d.ts","sourceRoot":"","sources":["../src/ad-creative-record.ts"],"names":[],"mappings":"AASA,gFAAgF;AAChF,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AAC5D,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,WAAW,C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rB;0FACsF;IACtF,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;CACnC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,YAAY,CAAA;IAC3C,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;CAC5C;AAyFD,4FAA4F;AAC5F,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,GAAE,WAAgB,GAAG,cAAc,CA+BpH;AAED,0KAA0K;AAC1K,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,GAAE,WAAgB,GAAG,cAAc,CAiBvH"}
|
|
@@ -2121,7 +2121,7 @@ function canonicalJson(value) {
|
|
|
2121
2121
|
if (typeof value === "number" && !Number.isFinite(value)) throw new RangeError("RFC 8785 has no non-finite numbers");
|
|
2122
2122
|
return JSON.stringify(value);
|
|
2123
2123
|
}
|
|
2124
|
-
function checkJws(sig, canonical, keys) {
|
|
2124
|
+
function checkJws(sig, canonical, keys, maxAge) {
|
|
2125
2125
|
if (sig === void 0) return "unsigned";
|
|
2126
2126
|
const parts = typeof sig === "string" ? DETACHED_JWS.exec(sig) : null;
|
|
2127
2127
|
if (!parts) return "sig";
|
|
@@ -2143,15 +2143,19 @@ function checkJws(sig, canonical, keys) {
|
|
|
2143
2143
|
if (!key) return "kid";
|
|
2144
2144
|
try {
|
|
2145
2145
|
const input = ENCODER.encode(`${protectedB64}.${canonical}`);
|
|
2146
|
-
|
|
2146
|
+
if (!ed25519.verify(signature, input, key, { zip215: false })) return "signature";
|
|
2147
2147
|
} catch {
|
|
2148
2148
|
return "signature";
|
|
2149
2149
|
}
|
|
2150
|
+
if (maxAge.maxAgeS === void 0) return "verified";
|
|
2151
|
+
const iat = header["iat"];
|
|
2152
|
+
const aheadMs = typeof iat === "number" ? iat * 1e3 - (maxAge.now ?? Date.now)() : NaN;
|
|
2153
|
+
return aheadMs <= (maxAge.maxSkewS ?? 30) * 1e3 && -aheadMs <= maxAge.maxAgeS * 1e3 ? "verified" : "iat";
|
|
2150
2154
|
}
|
|
2151
|
-
function verifyAdCreativeSig(record, keys) {
|
|
2155
|
+
function verifyAdCreativeSig(record, keys, maxAge = {}) {
|
|
2152
2156
|
const unsigned = { ...record };
|
|
2153
2157
|
delete unsigned["sig"];
|
|
2154
|
-
return checkJws(record["sig"], canonicalJson(unsigned), keys);
|
|
2158
|
+
return checkJws(record["sig"], canonicalJson(unsigned), keys, maxAge);
|
|
2155
2159
|
}
|
|
2156
2160
|
var AD_CREATIVE_EVENT_TYPE = "urn:svta:advertising-wg:ad-creative-signaling";
|
|
2157
2161
|
var AD_OBJECT_MAX_BYTES = 65536;
|
|
@@ -2198,17 +2202,24 @@ var isHttpsUrl = (value) => {
|
|
|
2198
2202
|
}
|
|
2199
2203
|
};
|
|
2200
2204
|
var allHttps = (value) => typeof value === "string" ? isHttpsUrl(value) : typeof value !== "object" || value === null || (Array.isArray(value) ? value : Object.values(value)).every(allHttps);
|
|
2201
|
-
|
|
2202
|
-
|
|
2205
|
+
var CHILDREN = {
|
|
2206
|
+
pod: [["tracking", "trackingEvent"], ["slots", "slot"]],
|
|
2207
|
+
slot: [["tracking", "trackingEvent"], ["verifications", "verification"]],
|
|
2208
|
+
trackingEvent: [],
|
|
2209
|
+
verification: []
|
|
2210
|
+
};
|
|
2211
|
+
function httpsOnly(kind, value) {
|
|
2203
2212
|
if (!isObject(value)) return true;
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2213
|
+
if ("$remote" in value && !allHttps(value["$remote"])) return false;
|
|
2214
|
+
const urls = value["urls"];
|
|
2215
|
+
if (kind === "trackingEvent" && "urls" in value && !(Array.isArray(urls) && urls.every(isHttpsUrl))) return false;
|
|
2216
|
+
if (kind === "verification" && "resource" in value && !isHttpsUrl(value["resource"])) return false;
|
|
2217
|
+
return CHILDREN[kind].every(([name, child]) => {
|
|
2218
|
+
const list = value[name];
|
|
2219
|
+
return !(name in value) || Array.isArray(list) && list.every((item) => httpsOnly(child, item));
|
|
2209
2220
|
});
|
|
2210
2221
|
}
|
|
2211
|
-
function parseAdCreativeRecord(value, keys) {
|
|
2222
|
+
function parseAdCreativeRecord(value, keys, maxAge = {}) {
|
|
2212
2223
|
if (!isObject(value)) return { verdict: "shape" };
|
|
2213
2224
|
if (!depthWithin(value, AD_JSON_MAX_DEPTH)) return { verdict: "depth" };
|
|
2214
2225
|
const index = indexOf(value);
|
|
@@ -2218,7 +2229,7 @@ function parseAdCreativeRecord(value, keys) {
|
|
|
2218
2229
|
if (!isObject(data)) return { verdict: "data", key };
|
|
2219
2230
|
const envelope = envelopeOf(data);
|
|
2220
2231
|
if (!envelope) return { verdict: "envelope", key };
|
|
2221
|
-
if (!httpsOnly(
|
|
2232
|
+
if (!envelope.payload.every((item) => httpsOnly(envelope.type, item))) return { verdict: "url", key };
|
|
2222
2233
|
if (Object.entries(envelope.features ?? {}).some(([name, on]) => on && !SUPPORTED_FEATURES.has(name))) {
|
|
2223
2234
|
return { verdict: "feature", key };
|
|
2224
2235
|
}
|
|
@@ -2234,10 +2245,10 @@ function parseAdCreativeRecord(value, keys) {
|
|
|
2234
2245
|
return { verdict: "number", key };
|
|
2235
2246
|
}
|
|
2236
2247
|
const record = { index, key, data: envelope, canonical };
|
|
2237
|
-
const verdict = checkJws(value["sig"], record.canonical, keys);
|
|
2248
|
+
const verdict = checkJws(value["sig"], record.canonical, keys, maxAge);
|
|
2238
2249
|
return verdict === "verified" || verdict === "unsigned" || verdict === "kid" ? { verdict, key, record } : { verdict, key };
|
|
2239
2250
|
}
|
|
2240
|
-
function parseAdCreativeObject(bytes, keys) {
|
|
2251
|
+
function parseAdCreativeObject(bytes, keys, maxAge = {}) {
|
|
2241
2252
|
if (bytes.byteLength > AD_OBJECT_MAX_BYTES) return { verdict: "size", records: [] };
|
|
2242
2253
|
let text2;
|
|
2243
2254
|
try {
|
|
@@ -2253,7 +2264,7 @@ function parseAdCreativeObject(bytes, keys) {
|
|
|
2253
2264
|
}
|
|
2254
2265
|
if (!Array.isArray(doc)) return { verdict: "not-array", records: [] };
|
|
2255
2266
|
if (doc.length > AD_OBJECT_MAX_RECORDS) return { verdict: "count", records: [] };
|
|
2256
|
-
return { verdict: "accepted", records: doc.map((record) => parseAdCreativeRecord(record, keys)) };
|
|
2267
|
+
return { verdict: "accepted", records: doc.map((record) => parseAdCreativeRecord(record, keys, maxAge)) };
|
|
2257
2268
|
}
|
|
2258
2269
|
export {
|
|
2259
2270
|
AD_CREATIVE_EVENT_TYPE,
|