Extract TCF core metadata decoder into VG-Core protocol layer

Dieser Commit ist enthalten in:
2026-05-26 17:34:02 +02:00
Ursprung ebf184800a
Commit e1ca6377ad
3 geänderte Dateien mit 40 neuen und 40 gelöschten Zeilen
+1
Datei anzeigen
@@ -37,6 +37,7 @@
"src/background/request-observer.js",
"src/background/gvl-service.js",
"src/core/binary-utils.js",
"src/core/tcf-core-metadata-decoder.js",
"src/background.js"
]
},
-40
Datei anzeigen
@@ -502,43 +502,3 @@ async function persistObservedRequest(observedRequest) {
tx.onerror = () => reject(tx.error);
});
}
function decodeTcStringCoreMetadata(tcString) {
if (!tcString || typeof tcString !== "string") {
return null;
}
const coreSegment = tcString.split(".")[0];
try {
const bits = base64UrlToBits(coreSegment);
return {
version: bitsToInt(bits, 0, 6),
cmpId: bitsToInt(bits, 78, 12),
cmpVersion: bitsToInt(bits, 90, 12),
consentScreen: bitsToInt(bits, 102, 6),
consentLanguage: bitsToString(bits, 108, 12),
vendorListVersion: bitsToInt(bits, 120, 12),
tcfPolicyVersion: bitsToInt(bits, 132, 6),
isServiceSpecific: bitsToBoolean(bits, 138),
useNonStandardStacks: bitsToBoolean(bits, 139),
purposeOneTreatment: bitsToBoolean(bits, 200),
publisherCC: bitsToString(bits, 201, 12)
};
} catch (error) {
console.warn("VG-Observe could not decode TC string core metadata", error);
return null;
}
}
function bitsToString(bits, start, length) {
let result = "";
for (let index = start; index < start + length; index += 6) {
const charCode = bitsToInt(bits, index, 6) + 65;
result += String.fromCharCode(charCode);
}
return result;
}
+39
Datei anzeigen
@@ -0,0 +1,39 @@
function decodeTcStringCoreMetadata(tcString) {
if (!tcString || typeof tcString !== "string") {
return null;
}
const coreSegment = tcString.split(".")[0];
try {
const bits = base64UrlToBits(coreSegment);
return {
version: bitsToInt(bits, 0, 6),
cmpId: bitsToInt(bits, 78, 12),
cmpVersion: bitsToInt(bits, 90, 12),
consentScreen: bitsToInt(bits, 102, 6),
consentLanguage: bitsToString(bits, 108, 12),
vendorListVersion: bitsToInt(bits, 120, 12),
tcfPolicyVersion: bitsToInt(bits, 132, 6),
isServiceSpecific: bitsToBoolean(bits, 138),
useNonStandardStacks: bitsToBoolean(bits, 139),
purposeOneTreatment: bitsToBoolean(bits, 200),
publisherCC: bitsToString(bits, 201, 12)
};
} catch (error) {
console.warn("VG-Observe could not decode TC string core metadata", error);
return null;
}
}
function bitsToString(bits, start, length) {
let result = "";
for (let index = start; index < start + length; index += 6) {
const charCode = bitsToInt(bits, index, 6) + 65;
result += String.fromCharCode(charCode);
}
return result;
}