open-index/open-npm huggingface dataset:
npm package: @ocap/statedb-dolt
Description: OCAP statedb adapter that uses dolt as backend statedb
Author: wangshijun
Latest version: 1.28.6

# [**@ocap/statedb-dolt**](https://github.com/arcblock/blockchain)

[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

## Install

```sh
npm install @ocap/statedb-dolt
// or
pnpm install @ocap/statedb-dolt
```

## Usage

```js
const DOLTStateDB = require('@ocap/statedb-dolt');

const db = new DOLTStateDB({
  connection: 'mysql://root:@127.0.0.1:3306',
});

db.onReady(async () => {
  const account = {
    address: 'z1VUFgtw9JSENAswYm5vqdpg461oi6JPEdP',
    balance: '100000000000000000000000000',
    gasBalance: '0',
    nonce: 2,
    numTxs: 1,
    numAssets: 0,
    migratedTo: [],
    migratedFrom: [],
    stake: null,
    context: {
      genesisTime: '2021-02-02T02:17:48.141Z',
      genesisTx: '',
      renaissanceTime: '2021-02-02T02:17:48.141Z',
      renaissanceTx: '',
    },
    moniker: 'system',
  };

  await db.runAsLambda(async (txn) => {
    const exist = await db.account.get(account.address, { txn });
    console.log('account', { exist });

    if (!exist) {
      const created = await db.account.create(account.address, account, { txn });
      console.log('account', { created });
    }
  });
});
```
npm package: @ocap/statedb-fs
Description: OCAP statedb adapter that uses fs as backend
Author: wangshijun
Latest version: 1.29.4

# [**@ocap/statedb-fs**](https://github.com/arcblock/blockchain)


> OCAP statedb adapter that stores data to the disk through lokijs

## Install

```sh
npm install @ocap/statedb-fs
// or
bun install @ocap/statedb-fs
```

## Usage

```js
const FsStateDB = require('@ocap/statedb-fs').default;
const statedb = new FsStateDB(os.tmpdir());

statedb.account.create('123', { key: 'value' });
```
npm package: @ocap/statedb-memory
Description: OCAP statedb adapter that uses memory as backend statedb, just for test purpose
Author: wangshijun
Latest version: 1.29.24

# [**@ocap/statedb-memory**](https://github.com/arcblock/blockchain)


> OCAP Adapter that stores data to the disk through [nedb](https://npmjs.org/package/nedb)

## Install

```sh
npm install @ocap/statedb-memory
// or
bun install @ocap/statedb-memory
```

## Usage

```js
const MemoryStateDB = require('@ocap/statedb-memory').default;

const statedb = new MemoryStateDB();
```
npm package: @ocap/statedb-qldb
Description: OCAP statedb adapter that uses amazon qldb as backend statedb
Author: wangshijun
Latest version: 1.28.6

# [**@ocap/statedb-qldb**](https://github.com/arcblock/blockchain)

[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

> OCAP statedb adapter that uses Amazon QLDB as backend statedb.

## Requirements

Please follow https://docs.aws.amazon.com/qldb/latest/developerguide/getting-started.nodejs.html to setup your AWS SDK credentials and Amazon QLDB ledgers.
**This adapter will create tables in the ledger, but not the ledger itself.**

## Install

```sh
npm install @ocap/statedb-qldb
// or
pnpm install @ocap/statedb-qldb
```

## Usage

```js
const QLDBStateDB = require('@ocap/statedb-qldb');

const db = new QLDBStateDB({
  ledgerName: 'qldb-statedb-dev',
  clientOptions: {
    region: 'ap-northeast-1',
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_ACCESS_KEY_SECRET,
  },
});

db.onReady(async () => {
  const account = {
    address: 'z1VUFgtw9JSENAswYm5vqdpg461oi6JPEdP',
    balance: '100000000000000000000000000',
    gasBalance: '0',
    nonce: 2,
    numTxs: 1,
    numAssets: 0,
    migratedTo: [],
    migratedFrom: [],
    stake: null,
    context: {
      genesisTime: '2021-02-02T02:17:48.141Z',
      genesisTx: '',
      renaissanceTime: '2021-02-02T02:17:48.141Z',
      renaissanceTx: '',
    },
    moniker: 'system',
  };

  await db.driver.executeLambda(async (txn) => {
    const exist = await db.account.get(account.address, { txn });
    console.log('account', { exist });

    if (!exist) {
      const created = await db.account.create(account.address, account, { txn });
      console.log('account', { created });
    }

    const count = await db.account.count({ txn });
    console.log('account', { count });
  });
});
```
npm package: @ocap/statedb-sqlite
Description: OCAP statedb adapter that uses SQLite as backend
Author: wangshijun
Latest version: 1.29.24

# [**@ocap/statedb-sqlite**](https://github.com/arcblock/blockchain)

> OCAP statedb adapter that uses SQLite as backend via [Kysely](https://kysely.dev/)

## Install

```sh
npm install @ocap/statedb-sqlite
// or
bun install @ocap/statedb-sqlite
```

## Usage

### In-Memory Mode

For testing or ephemeral data:

```js
const SqliteStateDB = require('@ocap/statedb-sqlite').default;

const statedb = new SqliteStateDB({ filename: ':memory:' });
await statedb.initialize();

// Use statedb...
await statedb.account.create('z1abc...', { balance: '1000' });

// Close when done
await statedb.close();
```

### File Mode

For persistent storage:

```js
const SqliteStateDB = require('@ocap/statedb-sqlite').default;

const statedb = new SqliteStateDB({ filename: '/path/to/statedb.sqlite' });
await statedb.initialize();

// Data persists across restarts
```

## Features

- WAL mode enabled by default for better concurrent read performance
- Automatic migrations on initialization
- Transaction support via `runAsLambda()`
- All 13 state tables: account, asset, token, factory, stake, delegation, rollup, etc.

## API

### Constructor Options

```typescript
interface SqliteStateDBOptions {
  filename: string;  // ':memory:' or file path
}
```

### Methods

- `initialize()` - Run migrations and prepare database
- `close()` - Close database connection
- `runAsLambda(fn)` - Execute function within a transaction
npm package: @ocap/trusted-storage
Description: Trusted storage for Ocap
Author: wangshijun
Latest version: 1.28.6

# 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

```bash
npm install @ocap/trusted-storage
```

## Basic Usage

### Create 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();
```

### Usage:

```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);
```

## Unit Tests

Run unit tests:

```bash
npm test
```

Generate coverage report:

```bash
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