Skip to content

Overview of Attestation Functions in attest.ts

This TypeScript module contains functions for generating cryptographic attestations for image files using zero-knowledge proofs (ZKP). It utilizes cryptographic backends and circuits to ensure the integrity and authenticity of the data.

Functions

  1. attestationProofGenerator

    • Purpose: Generates a cryptographic zero-knowledge proof based on provided prover inputs.
    • Parameters:
      • input: AttestationProverInputMap - The prover inputs required for generating the proof.
    • Returns: A promise that resolves to a base64 encoded string of the proof or null if an error occurs.
    • Process:
      • Initializes cryptographic modules.
      • Configures and utilizes the Noir library with the Barretenberg backend to generate the proof.
  2. generateAttestationProverInputs

    • Purpose: Prepares the necessary prover inputs for generating a cryptographic proof.
    • Parameters:
      • file: File - The file from which the image data hash is generated.
      • sigProof: SigProof - The signatures and public keys required for the attestation.
    • Returns: A promise that resolves to the formatted prover inputs or null if an error occurs.
    • Process:
      • Sets up Elliptic Curve Diffie-Hellman (ECDH).
      • Retrieves necessary keys and certificates.
      • Formats them for proof generation.
  3. proveAttestation

    • Purpose: Generates a zero-knowledge proof for a chain of signatures provided in sigProof.
    • Parameters:
      • input: File - The input file for which the attestation is being generated.
      • sigProof: SigProof - An object containing the signatures and public keys required to generate the ZKP.
    • Returns: A promise that resolves to a See3Attestation object containing the ZKP if successful, or throws an error if an error occurs.
    • Process:
      • Orchestrates the generation of prover inputs and the subsequent proof generation.
  4. generateAttestation

    • Purpose: Generates an attestation for a given input file using the camera's private key, the TA's public key, and the TA's certificate.
    • Parameters:
      • input: File - The input file to be attested.
      • captureDeviceData: CaptureDeviceData - An object containing the necessary data for the attestation process.
    • Returns: A promise that resolves to a See3Attestation object if the attestation is successfully generated, or null if an error occurs.
    • Process:
      • Utilizes the proveAttestation function to generate the attestation.
  5. generateTestAttestation

    • Purpose: Generates a test attestation using hardcoded values for the camera's public key, the TA's public key, and the TA's certificate.
    • Parameters:
      • input: File - The input file to be attested.
    • Returns: A promise that resolves to a See3Attestation object if the attestation is successfully generated, or null if an error occurs.
    • Process:
      • Similar to generateAttestation but uses hardcoded values for testing purposes.

Usage Example

typescript
const inputFile = new File(["data"], "image.jpg");
const captureDeviceData = {
'camera-private-key': '0x123',
'ta-public-key': { x: '0xabc', y: '0xdef' },
'ta-signature': {
'signature-R': { x: '0x101', y: '0x202' },
'signature-s': '0x303'
}
};
generateAttestation(inputFile, captureDeviceData)
.then(attestation => {
if (attestation) {
console.log('Attestation generated:', attestation);
} else {
console.log('Failed to generate attestation.');
}
})
.catch(error => {
console.error('Error:', error);
});

This module is essential for ensuring the security and verifiability of image files, particularly in contexts where proof of authenticity is critical.