1.20.14 • Published 5 months ago

@ocap/trusted-storage v1.20.14

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 months ago

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 information
  • writeHash(hashStorage, prevHash?): Write new hash information
  • initStorage(): Initialize the storage medium
  • getHash(): Retrieve and verify stored hash information
  • signHash(hash): Sign a hash value
  • verifySignature(hash, signature): Verify hash signature
  • compare(hash): Compare hash with stored trusted hash
  • updateHash(hash, prevHash): Securely update trusted hash
1.20.14

5 months ago

1.20.13

5 months ago

1.20.12

5 months ago

1.20.11

5 months ago

1.20.10

5 months ago

1.20.9

5 months ago

1.20.8

6 months ago

1.20.7

6 months ago

1.20.6

6 months ago

1.20.5

6 months ago

1.20.4

6 months ago

1.20.3

6 months ago