proofmode 0.9.0

Capture, share, and preserve verifiable photos and videos
Documentation
// Re-export all functions from the WASM module
export * from '@guardianproject/proofmode';

// Additional utility functions for Node.js environment
import fs from 'fs-extra';
import path from 'path';
import * as proofmode from '@guardianproject/proofmode';

/**
 * Generate proof from a file path (Node.js specific)
 * @param {string} filePath - Path to the media file
 * @param {Object} options - Generation options
 * @returns {Promise<string>} - The hash of the generated proof
 */
export async function generateProofFromFile(filePath, options = {}) {
  const {
    storageDir = './proofmode',
    metadata = {},
    callbacks = {}
  } = options;
  
  // Read file
  const buffer = await fs.readFile(filePath);
  const mediaData = new Uint8Array(buffer);
  
  // Ensure storage directory exists
  await fs.ensureDir(storageDir);
  
  // Default callbacks
  const defaultCallbacks = {
    getLocationData: async () => null,
    getDeviceData: async () => ({
      manufacturer: process.platform,
      model: 'Node.js',
      os_version: process.version,
      device_id: null
    }),
    getNetworkData: async () => ({
      network_type: 'unknown',
      wifi_ssid: null,
      cell_info: null
    }),
    saveProofData: async (hash, proofData) => {
      const proofDir = path.join(storageDir, hash.substring(0, 2), hash.substring(2, 4));
      await fs.ensureDir(proofDir);
      
      const jsonPath = path.join(proofDir, `${hash}.proof.json`);
      await fs.writeJSON(jsonPath, JSON.parse(proofData), { spaces: 2 });
      
      return jsonPath;
    },
    getPgpKey: async () => null,
    signWithPgp: async (data) => null, // PGP signing should be handled by WASM internally
    ...callbacks
  };
  
  // Generate proof
  const result = proofmode.generate_proof_wasm(
    mediaData,
    JSON.stringify(metadata),
    defaultCallbacks
  );
  
  return proofmode.get_file_hash(mediaData);
}

/**
 * Check files from paths (Node.js specific)
 * @param {string[]} filePaths - Array of file paths
 * @param {Function} progressCallback - Progress callback function
 * @returns {Promise<Object>} - Verification results
 */
export async function checkFilesFromPaths(filePaths, progressCallback) {
  // Convert file paths to absolute paths
  const absolutePaths = filePaths.map(p => path.resolve(p));
  return proofmode.checkFiles(absolutePaths, progressCallback);
}