Skip to content

generateImageCropProof Function

Generates a cryptographic proof for an image crop operation and returns the cropped image file along with the proof. This function manages the entire process from converting the image file to bytes, generating cryptographic hashes, setting up cryptographic circuits, and generating zero-knowledge proofs.

Parameters

  • imageFile: File - The original image file.
  • cropInput: CropInput - The input parameters for the crop operation.
  • fromManifest: ManifestName - The manifest name from which the image originates, validated against ManifestNameSchema.

Returns

  • Promise<Result<{eqProof: See3EqProof, croppedImage: File}, Error>>: A promise that resolves to a result object containing the proof and cropped image file or an error.

Process

  1. Convert Image to Bytes: Converts the original image file to RGB bytes.
  2. Generate Prover Inputs: Asynchronously gathers necessary data for proof generation:
    • Crop circuit configuration.
    • Image data converted to field elements.
    • Hash of the original image.
    • Cropped image and its hash.
  3. Error Handling: If there is an error in generating prover inputs, it returns an error.
  4. Setup Cryptographic Environment: Initializes necessary cryptographic modules and configurations.
  5. Generate Cryptographic Proof: Using Noir and Barretenberg backend, generates a zero-knowledge proof for the crop operation.
  6. Construct Equality Proof (eqProof): Packages the cryptographic proof with additional metadata about the edit operation.
  7. Return Results: Returns the equality proof and the file of the cropped image.

Example Usage

typescript
const cropInput = {
    originalSize: { width: 1920, height: 1080 },
    offsetPoint: { x: 100, y: 100 },
    cropSize: { width: 800, height: 600 }
};
const fromManifest = "xmp:iid:example";
generateImageCropProof(imageFile, cropInput, fromManifest).then(result => {
    if (result.isOk()) {
        console.log('Proof and cropped image:', result.value);
    } else {
        console.error('Error:', result.error);
    }
});```