Docs/API/InMemoryCurbStore

InMemoryCurbStore

classStorage

Zero-dependency in-memory store — great for tests and single-instance deployments.

signature
new InMemoryCurbStore()

Implements the full CurbStore interface in memory. Spend is a rolling 24h window split into committed (settled) payments and short-lived atomic holds, so two concurrent payments can’t both slip under the cap.

Methods

allowAccount(agent: string, account: string): void

Seed an allowlisted counterparty (test helper).

isAllowed(agent, account): Promise<boolean>

Is this counterparty allowlisted?

getDailySpend(agent): Promise<number>

Committed (settled) spend in the rolling window.

incrDailySpend(agent, amount): Promise<void>

Add to committed spend directly (e.g. seeding).

tryReserveSpend(agent, key, amount, cap): Promise<boolean>

Atomically place a hold if committed + holds + amount ≤ cap. Idempotent per key.

commitSpend(agent, key, amount): Promise<void>

Convert a hold into committed spend once the payment executes.

getApproval(requestId): Promise<ApprovalStatus | null>

Approval status for a payment.

setApproval(requestId, status): Promise<void>

Set an approval (pending / approved / rejected). The in-memory store ignores the interface’s optional meta.

consumeApproval(requestId): Promise<void>

Single-use: consume an approval after it’s used.

Example

example
import { InMemoryCurbStore } from 'hedera-curb';

const store = new InMemoryCurbStore();
store.allowAccount('0.0.A', '0.0.PROVIDER');
const key = 'pay-1';                              // any unique id for this payment
await store.tryReserveSpend('0.0.A', key, 2, 25); // → true (held)
await store.commitSpend('0.0.A', key, 2);         // settled
VERIFIABLE SPEND-CONTROL   ·   ENFORCED ON-CHAIN   ·   AGENTS CAN PAY — NOW THEY CAN’T OVERSPEND   ·   CURB × HEDERA   ·   VERIFIABLE SPEND-CONTROL   ·   ENFORCED ON-CHAIN   ·   AGENTS CAN PAY — NOW THEY CAN’T OVERSPEND   ·   CURB × HEDERA   ·