Skip to content

Commit b672b59

Browse files
authored
feat: implement Trust Score Service with scoring algorithm and API enpoints (#810)
* feat: implement Trust Score Service with scoring algorithm and API endpoints * format * chore: regenerate pnpm-lock.yaml with all workspace packages * fix: correct case for platforms/dreamsync folder and update lock file * fix: update lockfile after correcting ecurrency folder case * fix: update lockfile with restored ereputation and evoting client dependencies * fix: remove auto-generated next-env.d.ts and add to gitignore * fix: add non-negative validation for accountAgeDays and thirdDegreeConnections in GET endpoint * fix: prevent server from starting on module import * Regenerate pnpm-lock.yaml
1 parent 762ece5 commit b672b59

10 files changed

Lines changed: 826 additions & 0 deletions

File tree

platforms/blabsy/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Next.js auto-generated files
2+
next-env.d.ts

pnpm-lock.yaml

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/trust-score/README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Trust Score Service
2+
3+
Algorithmic Trust Service that produces a deterministic numeric score from **0 to 10** for any user.
4+
5+
## Formula
6+
7+
| Component | Points |
8+
| ------------------------------ | ------ |
9+
| Unverified baseline | 0 |
10+
| Account age > 180 days | 1 |
11+
| Key location = TPM | 1 |
12+
| Key location = SW | 0 |
13+
| 3rd-degree connections < 10 | 0 |
14+
| 3rd-degree connections 10–24 | 0.5 |
15+
| 3rd-degree connections 25–99 | 1 |
16+
| 3rd-degree connections 100–249 | 2 |
17+
| 3rd-degree connections 250–499 | 3 |
18+
| 3rd-degree connections 500+ | 4 |
19+
| KYC / ID verified | 4 |
20+
21+
**Max score = 10** (1 + 1 + 4 + 4)
22+
23+
## Running
24+
25+
```bash
26+
# Install dependencies (from monorepo root)
27+
pnpm install
28+
29+
# Dev mode with auto-reload
30+
pnpm --filter trust-score dev
31+
32+
# Production
33+
pnpm --filter trust-score start
34+
```
35+
36+
Default port: **3005** (override with `PORT` env var).
37+
38+
## API
39+
40+
### `GET /trust-score/:eName` (primary endpoint)
41+
42+
Fetch the trust score for a user by their eName (W3ID). The service fetches all required data automatically.
43+
44+
```bash
45+
GET /trust-score/julien.w3id
46+
```
47+
48+
Response:
49+
50+
```json
51+
{
52+
"eName": "julien.w3id",
53+
"score": 8,
54+
"breakdown": {
55+
"verification": 4,
56+
"accountAge": 1,
57+
"keyLocation": 1,
58+
"socialConnections": 2
59+
}
60+
}
61+
```
62+
63+
> **Note:** Data fetching is currently mocked. Each function in `src/userDataService.js` has TODO comments showing the real API calls to wire in once binding documents are written to the eVault.
64+
65+
### `POST /trust-score` (manual input)
66+
67+
```json
68+
{
69+
"isVerified": true,
70+
"accountAgeDays": 200,
71+
"keyLocation": "TPM",
72+
"thirdDegreeConnections": 150
73+
}
74+
```
75+
76+
### `GET /trust-score?isVerified=true&accountAgeDays=200&keyLocation=TPM&thirdDegreeConnections=150`
77+
78+
Both return:
79+
80+
```json
81+
{
82+
"score": 8,
83+
"breakdown": {
84+
"verification": 4,
85+
"accountAge": 1,
86+
"keyLocation": 1,
87+
"socialConnections": 2
88+
}
89+
}
90+
```
91+
92+
### `GET /health`
93+
94+
Returns `{ "status": "ok" }`.
95+
96+
## Testing
97+
98+
```bash
99+
pnpm --filter trust-score test
100+
```

services/trust-score/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "trust-score",
3+
"version": "1.0.0",
4+
"description": "Algorithmic Trust Service - deterministic numeric score from 0 to 10",
5+
"main": "src/index.js",
6+
"scripts": {
7+
"start": "node src/index.js",
8+
"dev": "nodemon src/index.js",
9+
"test": "vitest run",
10+
"test:watch": "vitest"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"dependencies": {
16+
"cors": "^2.8.5",
17+
"express": "^4.21.2"
18+
},
19+
"devDependencies": {
20+
"nodemon": "^3.0.2",
21+
"vitest": "^2.1.0"
22+
}
23+
}

0 commit comments

Comments
 (0)