Skip to content

verify Function

Verifies the authenticity of an image file by performing a series of cryptographic checks and validations using C2PA (Content Authenticity and Provenance) standards.

Parameters

  • c2pa: C2pa - A C2PA instance.
  • file: File - The image file to be verified.

Returns

  • Promise<VerifyResult | null>: A promise that resolves to the verification result or null if the verification fails. The verification result includes:
    • trustedAuthority: The identifier of the trusted authority if the verification is successful.
    • imageHash: The cryptographic hash of the image.
    • editHistory: An array of edits applied to the image, if any.

Process

  1. Read Manifest: Extracts the manifest store from the C2PA object.
  2. Compute Image Hash: Calculates the cryptographic hash of the image file.
  3. Top-Level Attestation Check: Searches for a top-level attestation in the manifest and verifies it if found.
  4. Trace Lineage of Edits:
    • If no top-level attestation is found, it checks for equality proofs (See3EqProof) to trace the lineage of edits applied to the image.
    • Verifies each edit recursively by following the manifest pointers and checking the associated proofs.
  5. Final Verification:
    • Once the lineage tracing reaches the original image, it performs a final attestation check.
    • If all checks are passed, it constructs the verification result.

Detailed Steps

  1. Setup: Initializes cryptographic modules required for verification.
  2. Attestation Verification:
    • Retrieves and formats the necessary data from the attestation.
    • Uses cryptographic backends to verify the attestation proof.
  3. Equality Proof Verification:
    • Retrieves and formats the necessary data from the equality proof.
    • Verifies the proof using the appropriate cryptographic circuit.
  4. Error Handling: Catches and logs any errors that occur during the verification process.

Example Usage

typescript
const c2paInstance = new C2pa();
const imageFile = new File(["data"], "image.jpg");
verify(c2paInstance, imageFile)
.then(result => {
if (result) {
console.log('Verification successful:', result);
} else {
console.log('Verification failed.');
}
})
.catch(error => {
console.error('Error during verification:', error);
});

This function is crucial for ensuring the integrity and authenticity of digital media, allowing users to verify the source and modifications made to an image, thereby helping to combat misinformation and unauthorized use.