feat:Implement Wallet Reputation Scoring#213
Open
OlufunbiIK wants to merge 1 commit into
Open
Conversation
Collaborator
|
Hi @OlufunbiIK please kindly look into this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(reputation): wallet trust scoring module
Summary
Implements a new
reputationmodule that assigns a 0–100 trust score to monitored wallets, giving security teams context around the wallets they're investigating. Closes the linked issue.Concept → Implementation mapping
Scores map to four tiers:
TRUSTED(75+),NEUTRAL(50+),SUSPICIOUS(25+),HIGH_RISK(<25). Every score is returned with a fullbreakdownand the list ofRiskIndicators that produced it, so results are explainable rather than a black-box number — useful for analysts who need to justify a flag.Scores are cached for 6 hours (
REPUTATION_SCORE_TTL_MS) before aGETtriggers a recalculation; aPOST .../recalculateendpoint allows forcing a fresh calculation on demand.API
Integration points that need wiring before merge
This module was written without access to the real project source (only the file tree), so the boundaries to existing modules are implemented as small, swappable interfaces rather than hard imports:
ChainDataProvider(reputation.service.ts) — currentlyStubChainDataProvider, returns empty activity. Replace with an adapter overchains/integrationsthat returns real first-seen date, tx counts, and counterparty addresses for a wallet.IncidentDataProvider(reputation.service.ts) — currentlyStubIncidentDataProvider. Replace with an adapter overcases/incidentsreturning open/resolved/confirmed-fraud counts for a wallet.SanctionsListProvider(services/risk-indicator.service.ts) — currentlyStubSanctionsListProvider, always returns "clean". Replace with the platform's real sanctioned/mixer/flagged-contract source, likely underbehavioral-analysis.reputation.repository.tsassumes aPrismaServiceatsrc/database/prisma.service.tsand aDatabaseModuleatsrc/database/database.module.ts, matching thedatabase/folder in the tree. If the project actually uses TypeORM, onlyreputation.repository.tsneeds to change — its public method signatures are the contract the rest of the module relies on.@UseGuards(ApiKeyGuard)pointing atapi-keys/api-key.guard. Uncomment and fix the import path once confirmed.prisma/reputation.prisma.snippetintoschema.prismaand run a migration (npx prisma migrate dev --name add_reputation_score).Out of scope / follow-ups
NETWORK_ANALYSIS_MAX_HOPSis already defined for this) is left as a follow-up once a graph/indexing source is identified.HIGH_RISKwallets would be a reasonable next step.recalculateendpoint beyond the TTL check onGET; consider throttling if this proves expensive against chain-data providers.Testing
reputation.service.spec.tsunit-testsReputationCalculatorService: weight sum sanity check, clean-wallet →TRUSTED, fraud-case → heavy penalty, extreme-inputs stay within[0, 100], no-data wallets scored neutrally rather than punitively.tsc --noEmitpass against the new files to confirm there are no type errors beyond expected missing-module errors for packages not installed in this sandbox (@nestjs/common,class-validator,class-transformer, Prisma client) — these will resolve once the files land in the real repo.How to review
Start with
reputation-calculator.service.tsfor the scoring math, thenrisk-indicator.service.tsfor what gets detected, thenreputation.service.tsto see how they're composed and cached. The controller and DTOs are thin by design.Closes #124