SDK Documentation
Official SDKs and client libraries for Data Proof Labs blockchain proof services
Available SDKs
JavaScript / TypeScript
Full-featured SDK for Node.js and browser applications with TypeScript support.
npm install @dataprooflabs/sdk
- Full TypeScript definitions
- Promise-based API
- Browser and Node.js support
- Built-in retry logic
- Automatic request validation
C# / .NET
Native .NET SDK with async/await support for .NET Core and .NET Framework.
dotnet add package DataProofLabs.SDK
- Async/await patterns
- .NET Core & Framework
- Strongly typed models
- Dependency injection ready
- Built-in logging
Python
Pythonic SDK with support for both synchronous and asynchronous operations.
pip install dataprooflabs-sdk
- Sync and async support
- Type hints included
- Pydantic models
- Built-in error handling
- Django/Flask integration
JavaScript/TypeScript SDK
Installation
# Using npm
npm install @dataprooflabs/sdk
# Using yarn
yarn add @dataprooflabs/sdk
# Using pnpm
pnpm add @dataprooflabs/sdk
Requirements
- Node.js 16+ or modern browser
- TypeScript 4.5+ (optional but recommended)
Basic Usage
import { DataProofLabsClient } from '@dataprooflabs/sdk';
// Initialize client
const client = new DataProofLabsClient({
apiKey: 'your-api-key-here',
baseUrl: 'https://api.dataprooflabs.com' // Optional, defaults to production
});
// Create a single proof
async function createProof() {
try {
const result = await client.proof.create({
recordId: 'document-001',
entityId: 'legal-docs',
data: 'Base64EncodedDataHere',
blockchainType: 'Ethereum'
});
console.log('Proof created:', result.transactionHash);
return result;
} catch (error) {
console.error('Error creating proof:', error);
}
}
// Verify a proof
async function verifyProof(recordId: string) {
try {
const verification = await client.proof.verify(recordId);
console.log('Proof is valid:', verification.isValid);
return verification;
} catch (error) {
console.error('Error verifying proof:', error);
}
}
// Get proof history
async function getHistory() {
try {
const history = await client.proof.getHistory();
console.log(`Found ${history.length} proof records`);
return history;
} catch (error) {
console.error('Error fetching history:', error);
}
}
Batch Processing
// Create batch proof with multiple items
async function createBatchProof() {
try {
const batchResult = await client.batch.create({
batchId: 'daily-documents-2025-08-24',
dataItems: [
{
recordId: 'doc-001',
entityId: 'contracts',
data: 'Base64Data1'
},
{
recordId: 'doc-002',
entityId: 'contracts',
data: 'Base64Data2'
}
],
blockchainType: 'Ethereum',
includeIndividualProofs: true
});
console.log('Batch created:', batchResult.merkleRoot);
return batchResult;
} catch (error) {
console.error('Error creating batch:', error);
}
}
// Get Merkle proof for verification
async function getMerkleProof(batchId: string, recordId: string) {
try {
const merkleProof = await client.batch.getMerkleProof(batchId, recordId);
console.log('Merkle proof path:', merkleProof.proofPath);
return merkleProof;
} catch (error) {
console.error('Error getting Merkle proof:', error);
}
}
// Advanced client configuration
const advancedClient = new DataProofLabsClient({
apiKey: 'your-api-key-here',
baseUrl: 'https://api.dataprooflabs.com',
timeout: 30000, // 30 seconds
retries: 3,
retryDelay: 1000, // 1 second
validateRequests: true,
onError: (error) => {
console.log('SDK Error:', error);
},
onRetry: (attempt, error) => {
console.log(`Retry attempt ${attempt}:`, error);
}
});
Error Handling
import { DataProofLabsError, ValidationError, AuthenticationError } from '@dataprooflabs/sdk';
try {
const result = await client.proof.create(proofData);
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Authentication failed:', error.message);
// Handle auth error (redirect to login, refresh token, etc.)
} else if (error instanceof ValidationError) {
console.error('Validation failed:', error.errors);
// Handle validation errors
} else if (error instanceof DataProofLabsError) {
console.error('API Error:', error.message);
// Handle other API errors
} else {
console.error('Unexpected error:', error);
}
}
C# / .NET SDK
Installation
# Package Manager Console
Install-Package DataProofLabs.SDK
# .NET CLI
dotnet add package DataProofLabs.SDK
# PackageReference
<PackageReference Include="DataProofLabs.SDK" Version="1.0.0" />
Configuration
// Dependency Injection (Recommended)
services.AddDataProofLabs(options => {
options.ApiKey = "your-api-key-here";
options.BaseUrl = "https://api.dataprooflabs.com";
options.Timeout = TimeSpan.FromSeconds(30);
});
// Direct instantiation
var client = new DataProofLabsClient(new DataProofLabsOptions
{
ApiKey = "your-api-key-here",
BaseUrl = "https://api.dataprooflabs.com"
});
Basic Usage
using DataProofLabs.SDK;
using DataProofLabs.SDK.Models;
public class DocumentService
{
private readonly IDataProofLabsClient _client;
public DocumentService(IDataProofLabsClient client)
{
_client = client;
}
// Create a single proof
public async Task<ProofResponse> CreateProofAsync(string recordId, byte[] data)
{
var request = new CreateProofRequest
{
RecordId = recordId,
EntityId = "documents",
Data = Convert.ToBase64String(data),
BlockchainType = "Ethereum",
NetworkType = "Sepolia"
};
try
{
var result = await _client.Proof.CreateAsync(request);
Console.WriteLine($"Proof created: {result.TransactionHash}");
return result;
}
catch (DataProofLabsException ex)
{
Console.WriteLine($"Error: {ex.Message}");
throw;
}
}
// Verify a proof
public async Task<bool> VerifyProofAsync(string recordId)
{
try
{
var verification = await _client.Proof.VerifyAsync(recordId);
return verification.IsValid;
}
catch (DataProofLabsException ex)
{
Console.WriteLine($"Verification error: {ex.Message}");
return false;
}
}
// Get proof history
public async Task<IEnumerable<ProofRecord>> GetHistoryAsync()
{
return await _client.Proof.GetHistoryAsync();
}
}
Batch Processing
public async Task<BatchProofResponse> CreateBatchProofAsync(IEnumerable<DocumentData> documents)
{
var batchRequest = new CreateBatchProofRequest
{
BatchId = $"batch-{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}",
DataItems = documents.Select(doc => new ProofDataItem
{
RecordId = doc.Id,
EntityId = doc.Category,
Data = Convert.ToBase64String(doc.Content)
}).ToList(),
BlockchainType = "Ethereum",
IncludeIndividualProofs = true
};
try
{
var result = await _client.Batch.CreateAsync(batchRequest);
Console.WriteLine($"Batch created with Merkle root: {result.MerkleRoot}");
return result;
}
catch (DataProofLabsException ex)
{
Console.WriteLine($"Batch creation error: {ex.Message}");
throw;
}
}
Python SDK
Installation
# Using pip
pip install dataprooflabs-sdk
# Using poetry
poetry add dataprooflabs-sdk
# Using conda
conda install -c conda-forge dataprooflabs-sdk
Basic Usage
from dataprooflabs import DataProofLabsClient
import asyncio
import base64
# Initialize client
client = DataProofLabsClient(
api_key="your-api-key-here",
base_url="https://api.dataprooflabs.com"
)
# Synchronous usage
def create_proof_sync():
try:
# Convert data to base64
data = "Sample document content"
encoded_data = base64.b64encode(data.encode()).decode()
result = client.proof.create({
"recordId": "doc-001",
"entityId": "documents",
"data": encoded_data,
"blockchainType": "Ethereum"
})
print(f"Proof created: {result['transactionHash']}")
return result
except Exception as e:
print(f"Error creating proof: {e}")
# Asynchronous usage
async def create_proof_async():
async_client = DataProofLabsClient(
api_key="your-api-key-here",
async_mode=True
)
try:
data = "Sample document content"
encoded_data = base64.b64encode(data.encode()).decode()
result = await async_client.proof.create({
"recordId": "doc-002",
"entityId": "documents",
"data": encoded_data,
"blockchainType": "Ethereum"
})
print(f"Async proof created: {result['transactionHash']}")
return result
except Exception as e:
print(f"Error creating async proof: {e}")
# Verify proof
def verify_proof(record_id: str):
try:
verification = client.proof.verify(record_id)
return verification['isValid']
except Exception as e:
print(f"Error verifying proof: {e}")
return False
# Get proof history
def get_history():
try:
history = client.proof.get_history()
print(f"Found {len(history)} proof records")
return history
except Exception as e:
print(f"Error fetching history: {e}")
return []
# Run async example
if __name__ == "__main__":
# Sync example
create_proof_sync()
# Async example
asyncio.run(create_proof_async())
Batch Processing
import base64
from datetime import datetime
def create_batch_proof(documents):
try:
# Prepare data items
data_items = []
for doc in documents:
encoded_data = base64.b64encode(doc['content'].encode()).decode()
data_items.append({
"recordId": doc['id'],
"entityId": doc['category'],
"data": encoded_data
})
# Create batch
batch_result = client.batch.create({
"batchId": f"batch-{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}",
"dataItems": data_items,
"blockchainType": "Ethereum",
"includeIndividualProofs": True
})
print(f"Batch created with Merkle root: {batch_result['merkleRoot']}")
return batch_result
except Exception as e:
print(f"Error creating batch: {e}")
# Get Merkle proof
def get_merkle_proof(batch_id: str, record_id: str):
try:
merkle_proof = client.batch.get_merkle_proof(batch_id, record_id)
print(f"Merkle proof path: {merkle_proof['proofPath']}")
return merkle_proof
except Exception as e:
print(f"Error getting Merkle proof: {e}")
# Django integration example
from django.conf import settings
def get_django_client():
return DataProofLabsClient(
api_key=settings.DATAPROOFLABS_API_KEY,
base_url=settings.DATAPROOFLABS_BASE_URL
)
Common Patterns
Error Handling Best Practices
// JavaScript/TypeScript
const createProofWithRetry = async (proofData, maxRetries = 3) => {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await client.proof.create(proofData);
} catch (error) {
if (attempt === maxRetries) throw error;
// Wait before retry (exponential backoff)
await new Promise(resolve =>
setTimeout(resolve, Math.pow(2, attempt) * 1000)
);
}
}
};
Environment Configuration
// Environment-based configuration
const getClient = () => {
const config = {
apiKey: process.env.DATAPROOFLABS_API_KEY,
baseUrl: process.env.NODE_ENV === 'production'
? 'https://api.dataprooflabs.com'
: 'https://testnet-api.dataprooflabs.com'
};
return new DataProofLabsClient(config);
};
Validation Helpers
// Input validation utility
const validateProofData = (data) => {
const errors = [];
if (!data.recordId || data.recordId.length < 1) {
errors.push('recordId is required');
}
if (!data.data || data.data.length < 1) {
errors.push('data is required');
}
if (data.recordId && data.recordId.length > 200) {
errors.push('recordId too long (max 200 characters)');
}
return {
isValid: errors.length === 0,
errors
};
};