Skip to content

[Backend] Trust API: back getTrustScore with Postgres identity repository instead of in-memory store #317

@Baskarayelu

Description

@Baskarayelu

Description

The public trust-score endpoint GET /api/trust/:address is served by getTrustScore in src/services/reputationService.ts, which calls getIdentity from src/db/store.ts — an in-memory Map seeded with hardcoded development identities. This means production trust scores are computed from fake seed data and reset on every process restart, while the real identity data lives in Postgres (src/repositories/identities.repository.ts). The reputation engine must read from the durable identity repository so scores reflect on-chain bond and attestation state synced by the Horizon listeners. This is a correctness-critical gap that makes the headline API effectively non-functional in production.

Requirements and context

  • Replace getIdentity usage in src/services/reputationService.ts with src/repositories/identities.repository.ts (and src/repositories/attestations.repository.ts for attestationCount).
  • Convert getTrustScore to async and update src/routes/trust.ts to await it.
  • Keep pure scoring functions (computeBondScore, computeDurationScore, computeAttestationScore) unchanged and unit-testable.
  • Deprecate/remove the seed-only src/db/store.ts for the production path; keep it only behind test fixtures.

Suggested execution

Create branch feature/trust-score-postgres-backing.

  • Modify src/services/reputationService.ts to inject an identity repository dependency.
  • Update src/routes/trust.ts to await the async score and preserve the NotFoundError path.
  • Add src/services/__tests__/reputationService.repository.test.ts covering hit/miss against a pg-mem or testcontainers Postgres.
  • Update docs/api.md and docs/schema.md to reflect the data source.

Test and commit

Run npm run test and npm run test:coverage. Edge cases: address with no identity row, identity with null bondStart, very large bondedAmount BigInt values, address casing normalization. Security: ensure no seed/mock identities leak into production responses.

Example commit message

feat: back trust score endpoint with durable Postgres identity repository

Guidelines

  • Minimum 95% test coverage
  • Clear documentation of the data-source change in docs/api.md
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programapiAPI surfacebackendBackend services and APIsdatabaseData layer / persistence

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions