Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ cd frontend && pnpm install && pnpm dev

---

## Indexer Service

StellarCred includes a lightweight indexer service (located in `services/indexer/`) that polls the Stellar Horizon API for `ProofRegistry` events (verifications and revocations) and provides a fast, queryable REST API.

The indexer reads strictly public on-chain data (no identity fields), and operates idempotently. It powers the frontend's aggregate statistics and claim discovery features.

**API Endpoints:**
- `GET /claims?wallet=G...` — Claims for a specific wallet
- `GET /stats` — Aggregate counts per credential type
- `GET /recent` — Recent verifications (paginated)

To run the indexer alongside the application, simply start the stack via Docker:
```bash
docker compose up indexer
```
For standalone setup instructions, refer to the [Indexer README](services/indexer/README.md).

---

## Deployments

A public record of deployed contract IDs on testnet and mainnet, along with instructions to verify the bytecode integrity from source, is maintained in [DEPLOYMENTS.md](DEPLOYMENTS.md).
Expand Down
89 changes: 62 additions & 27 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,71 @@
version: "3.9"

services:
contracts:
# ── ProofRegistry event indexer ─────────────────────────────────────────
indexer:
build:
context: .
dockerfile: docker/Dockerfile.dev
image: stellarcred-dev
working_dir: /workspace
context: ./services/indexer
dockerfile: Dockerfile
restart: unless-stopped
environment:
# Set these in a .env file or pass via environment at runtime.
# See services/indexer/.env.example for all options.
STELLAR_NETWORK: ${STELLAR_NETWORK:-testnet}
HORIZON_URL: ${HORIZON_URL:-https://horizon-testnet.stellar.org}
RPC_URL: ${RPC_URL:-https://soroban-testnet.stellar.org}
PROOF_REGISTRY_CONTRACT_ID: ${PROOF_REGISTRY_CONTRACT_ID}
DB_DRIVER: ${DB_DRIVER:-sqlite}
SQLITE_PATH: /data/indexer.db
# Uncomment to use Postgres instead:
# DB_DRIVER: postgres
# DATABASE_URL: ${DATABASE_URL}
POLL_INTERVAL_SECONDS: ${POLL_INTERVAL_SECONDS:-6}
START_LEDGER: ${START_LEDGER:-0}
PORT: 3001
volumes:
- .:/workspace
command: ["sh", "-c", "cargo test && cargo build"]
# Persist SQLite data across container restarts
- indexer_data:/data
ports:
# Expose the read-only API on host port 3001 (adjust as needed)
- "${INDEXER_PORT:-3001}:3001"
healthcheck:
test: ["CMD", "node", "-e",
"require('http').get('http://localhost:3001/health',r=>{process.exit(r.statusCode===200?0:1)})"]
interval: 15s
timeout: 5s
retries: 3
start_period: 10s

# ── StellarCred frontend ─────────────────────────────────────────────────
frontend:
build:
context: .
dockerfile: docker/Dockerfile.dev
image: stellarcred-dev
working_dir: /workspace/frontend
volumes:
- ./frontend:/workspace/frontend
- frontend-node-modules:/workspace/frontend/node_modules
context: ./frontend
dockerfile: Dockerfile
restart: unless-stopped
environment:
NEXT_PUBLIC_STELLAR_NETWORK: ${NEXT_PUBLIC_STELLAR_NETWORK:-testnet}
NEXT_PUBLIC_RPC_URL: ${NEXT_PUBLIC_RPC_URL:-https://soroban-testnet.stellar.org}
NEXT_PUBLIC_NETWORK_PASSPHRASE: ${NEXT_PUBLIC_NETWORK_PASSPHRASE:-Test SDF Network ; September 2015}
NEXT_PUBLIC_ISSUER_ADDRESS: ${NEXT_PUBLIC_ISSUER_ADDRESS:-}
NEXT_PUBLIC_STELLARCRED_BASE_URL: ${NEXT_PUBLIC_STELLARCRED_BASE_URL:-}
NEXT_PUBLIC_ISSUER_REGISTRY_ID: ${NEXT_PUBLIC_ISSUER_REGISTRY_ID:-}
NEXT_PUBLIC_CREDENTIAL_VERIFIER_ID: ${NEXT_PUBLIC_CREDENTIAL_VERIFIER_ID:-}
NEXT_PUBLIC_PROOF_REGISTRY_ID: ${NEXT_PUBLIC_PROOF_REGISTRY_ID:-}
NEXT_PUBLIC_GATED_POOL_ID: ${NEXT_PUBLIC_GATED_POOL_ID:-}
# Indexer URL accessible inside the Next.js server (same docker network)
NEXT_PUBLIC_INDEXER_URL: ${NEXT_PUBLIC_INDEXER_URL:-http://indexer:3001}
ISSUER_PRIVATE_KEY: ${ISSUER_PRIVATE_KEY:-}
PERSONA_API_KEY: ${PERSONA_API_KEY:-}
PERSONA_KYC_TEMPLATE_ID: ${PERSONA_KYC_TEMPLATE_ID:-}
PLAID_CLIENT_ID: ${PLAID_CLIENT_ID:-}
PLAID_SECRET: ${PLAID_SECRET:-}
PLAID_ACCESS_TOKEN: ${PLAID_ACCESS_TOKEN:-}
PLAID_ENV: ${PLAID_ENV:-sandbox}
ports:
- "3000:3000"
command: ["sh", "-c", "pnpm install && pnpm dev -- -H 0.0.0.0"]

circuits:
build:
context: .
dockerfile: docker/Dockerfile.dev
image: stellarcred-dev
working_dir: /workspace/circuits
volumes:
- ./circuits:/workspace/circuits
command: ["nargo", "compile", "--workspace"]
- "${FRONTEND_PORT:-3000}:3000"
depends_on:
indexer:
condition: service_healthy

volumes:
frontend-node-modules:
indexer_data:
Comment on lines 38 to +71

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Existing contracts and circuits services removed from Docker Compose

The original docker-compose.yml contained a contracts service (cargo test && cargo build) and a circuits service (nargo compile --workspace). Both have been dropped in this PR. The PR description only mentions adding the indexer service; removing these services appears unintentional and would break any CI pipelines or developer workflows that rely on docker compose up contracts or docker compose up circuits. These should either be restored or the removal should be explicitly acknowledged in the PR description.

Prompt To Fix With AI
This is a comment left during a code review.
Path: docker-compose.yml
Line: 38-71

Comment:
**Existing `contracts` and `circuits` services removed from Docker Compose**

The original `docker-compose.yml` contained a `contracts` service (`cargo test && cargo build`) and a `circuits` service (`nargo compile --workspace`). Both have been dropped in this PR. The PR description only mentions adding the `indexer` service; removing these services appears unintentional and would break any CI pipelines or developer workflows that rely on `docker compose up contracts` or `docker compose up circuits`. These should either be restored or the removal should be explicitly acknowledged in the PR description.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex Fix in Claude Code Fix in Cursor

13 changes: 13 additions & 0 deletions services/indexer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DB_DRIVER=sqlite
SQLITE_PATH=./data/indexer.db
DATABASE_URL=postgres://indexer:indexer@localhost:5432/indexer

RPC_URL=https://soroban-testnet.stellar.org
NETWORK_PASSPHRASE=Test SDF Network ; September 2015
PROOF_REGISTRY_CONTRACT_ID=

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 POLL_INTERVAL_MS in .env.example does not match POLL_INTERVAL_SECONDS read by config.ts

config.ts reads process.env["POLL_INTERVAL_SECONDS"] and multiplies by 1000. A developer who copies .env.example and sets POLL_INTERVAL_MS=5000 will have that value silently ignored — the service will use the hardcoded default of 6 s instead of 5 s. The variable name in the example file must be POLL_INTERVAL_SECONDS.

Prompt To Fix With AI
This is a comment left during a code review.
Path: services/indexer/.env.example
Line: 8

Comment:
**`POLL_INTERVAL_MS` in `.env.example` does not match `POLL_INTERVAL_SECONDS` read by `config.ts`**

`config.ts` reads `process.env["POLL_INTERVAL_SECONDS"]` and multiplies by 1000. A developer who copies `.env.example` and sets `POLL_INTERVAL_MS=5000` will have that value silently ignored — the service will use the hardcoded default of 6 s instead of 5 s. The variable name in the example file must be `POLL_INTERVAL_SECONDS`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex Fix in Claude Code Fix in Cursor

POLL_INTERVAL_MS=5000
EVENT_PAGE_LIMIT=100
START_LEDGER=0

PORT=4100
15 changes: 15 additions & 0 deletions services/indexer/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"root": true,
"env": {
"node": true,
"es2022": true
},
"rules": {
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "warn"
}
}
6 changes: 6 additions & 0 deletions services/indexer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
data/
.env
*.db
*.db-wal
*.db-shm
19 changes: 19 additions & 0 deletions services/indexer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:20-slim

WORKDIR /app

# Copy package files and install all dependencies (including dev for build)
COPY package.json package-lock.json ./
RUN npm ci

# Copy source and TypeScript config
COPY src ./src
COPY tsconfig.json ./

# Build TypeScript source
RUN npm run build

# Use the compiled entrypoint
EXPOSE 3001

CMD ["node", "dist/index.js"]
54 changes: 54 additions & 0 deletions services/indexer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# StellarCred Indexer Service

A lightweight indexer service that ingests `ProofRegistry` events from the Stellar Horizon API into a queryable local database (SQLite for development, PostgreSQL for production) and exposes a read-only, public-data-only API.

## Features

- **Idempotent Ingestion**: Tracks the last fully processed ledger. Safe to restart; it resumes exactly where it left off.
- **Public Data Only**: Indexes only public chain data: wallet address, credential type, issuer, expiry, ledger sequence, and revoked flag. No identity fields are stored.
- **Zero-State Blockchain Synchronization**: Does not mutate chain state; simply provides a fast query layer on top of on-chain verification events.

## API Endpoints

All endpoints are read-only and return JSON. No authentication is required.

- `GET /health`
Returns the health status and the `lastLedger` ingested.
- `GET /claims?wallet=<address>`
Returns all claims (active and revoked) for a given wallet address.
- `GET /stats`
Returns aggregate counts of active, revoked, and total verifications per credential type.
- `GET /recent?limit=20&page=1`
Returns the most recent active verifications (paginated).

## Running the Indexer

The indexer is configured to run out-of-the-box via Docker Compose alongside the frontend.

```bash
# In the repository root
docker compose up indexer
```

### Running Locally (Development)

1. Navigate to the indexer directory:
```bash
cd services/indexer
```
2. Install dependencies and build:
```bash
npm install
npm run build
```
3. Set your environment variables (copy `.env.example` to `.env` and fill it out).
4. Start the service:
```bash
npm start
# Or for development: npm run dev
```

### Database Configuration

- **SQLite (Default)**: Set `DB_DRIVER=sqlite` (default) and configure `SQLITE_PATH` (e.g. `./data/indexer.db`).
- **PostgreSQL**: Set `DB_DRIVER=postgres` and provide the full connection string via `DATABASE_URL`.
5 changes: 5 additions & 0 deletions services/indexer/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['<rootDir>/src/**/*.test.ts'],
};
Loading
Loading