Some refactoring of C2PA code

This commit is contained in:
N-Pex 2025-10-22 15:27:43 +02:00
parent 5c559a98ad
commit 5f26534ed1

View file

@ -163,23 +163,6 @@ const getExifMakeModel = (ignoredvalue: any, match: FlagMatchRuleValue): string
return makeAndModel;
}
const ruleScreenshotC2PA = (): FlagMatchRule[] => {
return [
{
field:
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[action=c2pa.created]/digitalSourceType",
match: [C2PASourceTypeScreenCapture],
description: "Screen capture",
},
{
field:
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions.v2]/data/actions[action=c2pa.created]/digitalSourceType",
match: [C2PASourceTypeScreenCapture],
description: "Screen capture",
},
];
};
const ruleScreenshotMeta = (): FlagMatchRule[] => {
return [
{
@ -191,40 +174,6 @@ const ruleScreenshotMeta = (): FlagMatchRule[] => {
];
};
const ruleCamera = (): FlagMatchRule[] => {
return [
{
field:
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[action=c2pa.created]/digitalSourceType",
match: [C2PASourceTypeDigitalCapture, C2PASourceTypeComputationalCapture, C2PASourceTypeCompositeCapture],
description: "Captured by camera",
},
{
field:
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions.v2]/data/actions[action=c2pa.created]/digitalSourceType",
match: [C2PASourceTypeDigitalCapture, C2PASourceTypeComputationalCapture, C2PASourceTypeCompositeCapture],
description: "Captured by camera",
},
];
};
const ruleAiGenerated = (): FlagMatchRule[] => {
return [
{
field:
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[action=c2pa.created]/digitalSourceType",
match: [C2PASourceTypeTrainedAlgorithmicMedia, C2PASourceTypeCompositeWithTrainedAlgorithmicMedia],
description: "Generated by AI",
},
{
field:
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions.v2]/data/actions[action=c2pa.created]/digitalSourceType",
match: [C2PASourceTypeTrainedAlgorithmicMedia, C2PASourceTypeCompositeWithTrainedAlgorithmicMedia],
description: "Generated by AI",
},
];
};
const ruleAiMeta = (): FlagMatchRule[] => {
const knownAIServices = [
"ChatGPT",
@ -422,25 +371,32 @@ export const extractProofHintFlags = (proof?: Proof): ProofHintFlags | undefined
}
}
let generator: ProofHintFlagsGenerator = matchFlag(ruleAiGenerated(), rootMatchPath).result ? "ai" : matchFlag(ruleScreenshotC2PA(), rootMatchPath).result ? "screenshot" : matchFlag(ruleCamera(), rootMatchPath).result ? "camera" : "unknown";
let generator: ProofHintFlagsGenerator = "unknown";
let generatorSource: ProofHintFlagSource | undefined = undefined;
if (generator !== "unknown" && valid) {
let digitalSourceType = extractFlagValues("integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions|c2pa.actions.v2]/data/actions[action=c2pa.created]/digitalSourceType", rootMatchPath)?.at(0)?.value as string;
if ([C2PASourceTypeScreenCapture].includes(digitalSourceType)) {
generator = "screenshot";
generatorSource = "c2pa";
} else {
if (matchFlag(ruleScreenshotMeta(), rootMatchPath).result) {
generator = "screenshot";
generatorSource = "metadata";
} else if (matchFlag(ruleAiMeta(), rootMatchPath).result) {
generator = "ai";
generatorSource = "metadata";
}
} else if ([C2PASourceTypeDigitalCapture, C2PASourceTypeComputationalCapture, C2PASourceTypeCompositeCapture].includes(digitalSourceType)) {
generator = "camera";
generatorSource = "c2pa";
} else if ([C2PASourceTypeTrainedAlgorithmicMedia, C2PASourceTypeCompositeWithTrainedAlgorithmicMedia].includes(digitalSourceType)) {
generator = "ai";
generatorSource = "c2pa";
} else if (matchFlag(ruleScreenshotMeta(), rootMatchPath).result) {
generator = "screenshot";
generatorSource = "metadata";
} else if (matchFlag(ruleAiMeta(), rootMatchPath).result) {
generator = "ai";
generatorSource = "metadata";
}
console.error("PROOF", proof);
const c2paEdits = extractFlagValues(
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions]/data/actions[!!action=c2pa.created]",
"integrity/c2pa/manifest_info/manifests[]/assertions[label=c2pa.actions|c2pa.actions.v2]/data/actions[!!action=c2pa.created]",
rootMatchPath
);
if (c2paEdits.length > 0) {