Trusted storage for Ocap
npm install @ocap/trusted-storageA secure module for storing and verifying hash values.
- Trusted hash storage based on HMAC-SHA256 signature algorithm
- Memory storage implementation for testing purposes
- Dolt database storage implementation for production environments
``bash`
npm install @ocap/trusted-storage
`typescript
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();
`
`typescript
// 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);
`
Run unit tests:
`bash`
npm test
Generate coverage report:
`bash`
npm run coverage
- 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
-