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
10 changes: 10 additions & 0 deletions backend/disputeHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require('express');
const router = express.Router();

router.post('/', async (req, res) => {
const { escrowId, reason } = req.body;
// TODO: Log dispute and notify admin
res.json({ escrowId, status: 'dispute logged', reason });
});

module.exports = router;
17 changes: 17 additions & 0 deletions backend/escrowController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const express = require('express');
const router = express.Router();

router.post('/initiate', async (req, res) => {
const { buyerId, sellerId, amount } = req.body;
const escrowId = Date.now(); // Simple unique ID
// TODO: Save to database or in-memory store
res.json({ escrowId, status: 'pending' });
});

router.post('/release/:id', async (req, res) => {
const escrowId = req.params.id;
// TODO: Validate and release funds
res.json({ escrowId, status: 'released' });
});

module.exports = router;
25 changes: 25 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');

const escrowController = require('./escrowController');
const reputationService = require('./reputationService');
const disputeHandler = require('./disputeHandler');

const app = express();
const PORT = process.env.PORT || 5000;

app.use(cors());
app.use(bodyParser.json());

app.use('/api/escrow', escrowController);
app.use('/api/reputation', reputationService);
app.use('/api/dispute', disputeHandler);

app.get('/', (req, res) => {
res.send('TrustSphere backend is running');
});

app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
11 changes: 11 additions & 0 deletions backend/reputationService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require('express');
const router = express.Router();

router.get('/:userId', async (req, res) => {
const userId = req.params.userId;
// TODO: Replace with real scoring logic
const score = 80; // Placeholder score
res.json({ userId, score });
});

module.exports = router;
54 changes: 54 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# TrustSphere API Documentation

This document outlines the backend routes and logic for TrustSphere’s modular trust infrastructure.

---

## 🔐 Escrow Routes

### `POST /api/escrow/initiate`
Initiates an escrow transaction between buyer and seller.

**Body Parameters:**
- `buyerId`
- `sellerId`
- `amount`
- `itemDescription`

### `POST /api/escrow/release`
Releases funds from escrow after successful transaction.

**Body Parameters:**
- `escrowId`
- `confirmationCode`

---

## 📊 Reputation Routes

### `GET /api/reputation/:userId`
Fetches the reputation score for a given user.

**Params:**
- `userId` (string)

---

## ⚖️ Dispute Routes

### `POST /api/dispute/submit`
Submits a dispute for review.

**Body Parameters:**
- `transactionId`
- `reason`
- `evidence` (optional)

---

## 🧠 Notes

- All routes expect JSON payloads.
- Authentication is optional for demo purposes.
- Future versions will include Pi user verification and dispute arbitration logic.

20 changes: 20 additions & 0 deletions frontend/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import LandingPage from './LandingPage';
import Escrow from './Escrow';
import Reputation from './Reputation';
import DisputeForm from './DisputeForm';

function App() {
return (
<Router>
<Routes>
<Route path="/" element={<LandingPage />} />
<Route path="/escrow" element={<Escrow />} />
<Route path="/reputation" element={<Reputation />} />
<Route path="/dispute" element={<DisputeForm />} />
</Routes>
</Router>
);
}

export default App;
25 changes: 25 additions & 0 deletions frontend/LandingPage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.landing-container {
padding: 2rem;
font-family: sans-serif;
background-color: #f9f9f9;
color: #333;
}

h1 {
color: #5c2d91;
}

.link-list {
list-style: none;
padding: 0;
}

.link-list li {
margin: 1rem 0;
}

.link-list a {
color: #5c2d91;
text-decoration: none;
font-weight: bold;
}
24 changes: 24 additions & 0 deletions frontend/LandingPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import './LandingPage.css'; // Optional: for styling

function LandingPage() {
return (
<div className="landing-container">
<h1>Welcome to TrustSphere</h1>
<p>
A modular trust infrastructure for the Pi economy — combining escrow, reputation scoring, and dispute resolution.
</p>

<ul className="link-list">
<li><a href="/escrow">🔐 Escrow Demo</a></li>
<li><a href="/reputation">📊 Reputation Score</a></li>
<li><a href="/dispute">⚖️ Dispute Form</a></li>
<li><a href="https://github.com/oreo-collab/demo" target="_blank" rel="noopener noreferrer">📁 GitHub Repo</a></li>
<li><a href="https://github.com/oreo-collab/demo/blob/main/docs/api.md" target="_blank" rel="noopener noreferrer">📚 API Docs</a></li>
<li><a href="https://github.com/oreo-collab/demo/blob/main/roadmap.md" target="_blank" rel="noopener noreferrer">🛣️ Roadmap</a></li>
</ul>
</div>
);
}

export default LandingPage;
7 changes: 7 additions & 0 deletions frontend/disputeForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function submitDispute(escrowId, reason) {
return fetch('/api/dispute', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ escrowId, reason })
});
}
13 changes: 13 additions & 0 deletions frontend/escrow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function initiateEscrow(buyerId, sellerId, amount) {
return fetch('/api/escrow/initiate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ buyerId, sellerId, amount })
});
}

export function releaseFunds(escrowId) {
return fetch(`/api/escrow/release/${escrowId}`, {
method: 'POST'
});
}
Loading