Skip to content

Quick Start Guide

Get up and running with Verdikta Common in minutes.

Installation

npm install @verdikta/common

Basic Usage

Simple Manifest Parsing

const { parseManifest } = require('@verdikta/common');

async function parseCase() {
  try {
    const result = await parseManifest('/path/to/extracted/archive');
    console.log('Parsed manifest:', result);
  } catch (error) {
    console.error('Parsing failed:', error.message);
  }
}

Factory Function Setup

For more control, use the factory function to create a configured client:

const { createClient } = require('@verdikta/common');

const verdikta = createClient({
  ipfs: {
    pinningKey: process.env.IPFS_PINNING_KEY,
    timeout: 45000
  },
  logging: {
    level: 'debug'
  }
});

const { manifestParser, ipfsClient, archiveService } = verdikta;

Working with IPFS Content

// Fetch content from IPFS
const content = await ipfsClient.fetchFromIPFS('QmYourCIDHere');

// Get and extract an archive
const archiveData = await archiveService.getArchive('QmArchiveCID');
const extractPath = await archiveService.extractArchive(archiveData, './temp');

// Parse the extracted manifest
const manifest = await manifestParser.parse(extractPath);

Multi-CID Processing

For complex cases involving multiple parties:

const { ManifestParser } = require('@verdikta/common');

const parser = new ManifestParser(ipfsClient, logger);

// Parse multiple manifests in order
const cidOrder = ['primary', 'rebuttal', 'evidence'];
const extractedPaths = ['/path/to/primary', '/path/to/rebuttal', '/path/to/evidence'];

const result = await parser.parseMultipleManifests(extractedPaths, cidOrder);

Configuration Options

Default Configuration

{
  ipfs: {
    gateway: 'https://ipfs.io',
    pinningService: 'https://api.pinata.cloud',
    timeout: 30000,
    retryOptions: {
      retries: 5,
      factor: 2,
      minTimeout: 1000,
      maxTimeout: 15000
    }
  },
  logging: {
    level: 'info',
    console: true,
    file: false
  },
  temp: {
    dir: './tmp'
  }
}

Environment Variables

Set these environment variables for automatic configuration:

export IPFS_PINNING_KEY="your-pinata-api-key"
export LOG_LEVEL="debug"
export TEMP_DIR="/custom/temp/directory"

Common Patterns

Error Handling

const { parseManifest, ValidationError } = require('@verdikta/common');

try {
  const result = await parseManifest(archivePath);
} catch (error) {
  if (error instanceof ValidationError) {
    console.error('Validation failed:', error.details);
  } else {
    console.error('Unexpected error:', error.message);
  }
}

Validation

const { validator } = require('@verdikta/common');

// Validate a manifest object
try {
  await validator.validateManifest(manifestObject);
  console.log('Manifest is valid');
} catch (error) {
  console.error('Validation errors:', error.details);
}

// Validate a request object
await validator.validateRequest(requestObject);

Custom Logging

const { Logger } = require('@verdikta/common');

const logger = new Logger({
  level: 'debug',
  file: true,
  console: true
});

logger.info('Processing started');
logger.debug('Debug information', { metadata: 'value' });
logger.error('An error occurred', { error: errorObject });

Next Steps