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
Description
The public trust-score endpoint
GET /api/trust/:addressis served bygetTrustScoreinsrc/services/reputationService.ts, which callsgetIdentityfromsrc/db/store.ts— an in-memoryMapseeded 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
getIdentityusage insrc/services/reputationService.tswithsrc/repositories/identities.repository.ts(andsrc/repositories/attestations.repository.tsforattestationCount).getTrustScoreto async and updatesrc/routes/trust.tstoawaitit.computeBondScore,computeDurationScore,computeAttestationScore) unchanged and unit-testable.src/db/store.tsfor the production path; keep it only behind test fixtures.Suggested execution
Create branch
feature/trust-score-postgres-backing.src/services/reputationService.tsto inject an identity repository dependency.src/routes/trust.tsto await the async score and preserve theNotFoundErrorpath.src/services/__tests__/reputationService.repository.test.tscovering hit/miss against apg-memor testcontainers Postgres.docs/api.mdanddocs/schema.mdto reflect the data source.Test and commit
Run
npm run testandnpm run test:coverage. Edge cases: address with no identity row, identity with nullbondStart, very largebondedAmountBigInt 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 repositoryGuidelines
docs/api.md