1.20.14 • Published 5 months ago
@ocap/trusted-storage v1.20.14
Trusted Storage
A secure module for storing and verifying hash values.
Features
- Trusted hash storage based on HMAC-SHA256 signature algorithm
- Memory storage implementation for testing purposes
- Dolt database storage implementation for production environments
Installation
npm install @ocap/trusted-storage
Basic Usage
Create storage
import { MemoryTrustedStorage, DoltTrustedStorage } from '@ocap/trusted-storage';
// Create storage of memory
const memoryStorage = new MemoryTrustedStorage({
secretKey: 'your-secret-key',
});
await memoryStorage.initStorage();
// Create storage of dolt
const doltStorage = new DoltTrustedStorage({
secretKey: 'your-secret-key',
connection: 'mysql://user:password@localhost:3306',
});
await doltStorage.initStorage();
Usage:
// Update hash with previous hash reference
await storage.updateHash('your-hash-value', 'previous-hash');
// Verify hash
const isMatch = await storage.compare('your-hash-value');
console.log('Hash match:', isMatch);
// Get current hash information
const hashInfo = await storage.getHash();
console.log('Current hash:', hashInfo);
Unit Tests
Run unit tests:
npm test
Generate coverage report:
npm run coverage
API Reference
readHash()
: Read stored hash informationwriteHash(hashStorage, prevHash?)
: Write new hash informationinitStorage()
: Initialize the storage mediumgetHash()
: Retrieve and verify stored hash informationsignHash(hash)
: Sign a hash valueverifySignature(hash, signature)
: Verify hash signaturecompare(hash)
: Compare hash with stored trusted hashupdateHash(hash, prevHash)
: Securely update trusted hash