diff --git a/manifest.json b/manifest.json index 5ef241d..c428a05 100644 --- a/manifest.json +++ b/manifest.json @@ -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" ] }, diff --git a/src/background.js b/src/background.js index 171fc21..b1cad83 100644 --- a/src/background.js +++ b/src/background.js @@ -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; -} diff --git a/src/core/tcf-core-metadata-decoder.js b/src/core/tcf-core-metadata-decoder.js new file mode 100644 index 0000000..487aac9 --- /dev/null +++ b/src/core/tcf-core-metadata-decoder.js @@ -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; +}