Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b53709a
top up done
codypharm Nov 6, 2025
05bef37
deposit successful
codypharm Nov 6, 2025
af73ed3
pooling added to association
codypharm Nov 6, 2025
285c7ac
payment done without serious security
codypharm Nov 6, 2025
cdaf9fb
payment completed and stored on chain
codypharm Nov 7, 2025
5ee0fc0
token association andnpayment tested on new flow
codypharm Nov 7, 2025
06b88eb
Merge pull request #1 from VictorKaycee17/payemnt/hedera
codypharm Nov 7, 2025
d18351a
build failure fix
codypharm Nov 7, 2025
3f40a6f
Merge pull request #2 from VictorKaycee17/payemnt/hedera
codypharm Nov 7, 2025
4913750
build failure fix
codypharm Nov 7, 2025
8c7adc3
fixed wrong balance check
codypharm Nov 7, 2025
ae5166e
Merge pull request #3 from VictorKaycee17/fix-credit-for
codypharm Nov 7, 2025
9c1857b
setup of hedera sdk and creation of ai agent
davife2025 Nov 8, 2025
5ed86f1
auto show account id and usdc balance
codypharm Nov 8, 2025
eb5d375
Merge pull request #4 from VictorKaycee17/feat/account-id
codypharm Nov 8, 2025
0aa99e8
any build error fixed
codypharm Nov 8, 2025
0b34d2b
buiilding-ai-agent
davife2025 Nov 8, 2025
4328b13
icon added
codypharm Nov 8, 2025
f5a3b0f
Merge pull request #5 from VictorKaycee17/feat/copy-icon
codypharm Nov 8, 2025
b0ba229
creating ai-agent
davife2025 Nov 14, 2025
c776d98
fixing the ai-agent
davife2025 Nov 14, 2025
3aa3d01
completion
davife2025 Nov 15, 2025
29733cc
completion of the ai agent setup
davife2025 Nov 15, 2025
a78697a
fixing setup
davife2025 Nov 15, 2025
5fd222a
Delete package-lock.json
codypharm Nov 15, 2025
1b2ec8a
Merge branch 'main' into hedera-ai-agent
codypharm Nov 15, 2025
3556b99
fixing code
davife2025 Nov 15, 2025
b1689b5
fixing import
davife2025 Nov 15, 2025
01d9dae
fixing
davife2025 Nov 15, 2025
6587c85
fixing 2
davife2025 Nov 15, 2025
65eb477
Merge pull request #7 from VictorKaycee17/hedera-ai-agent
codypharm Nov 15, 2025
3209192
build error fixed
codypharm Nov 15, 2025
312eadd
moved to titan
codypharm Nov 21, 2025
b10882e
new upgrade
codypharm Mar 20, 2026
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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/hedera-decenter-ai.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/material_theme_project_new.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions PAYMENT_ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Better Payment Verification Architecture

## Current Problem
❌ Trying to verify payment immediately via Mirror Node
❌ Mirror Node has 3-10 second lag (sometimes more)
❌ Verification fails even though payment succeeded

## Recommended Solution: Trust + Verify

### Phase 1: Immediate Response (Trust)
When user makes payment:

1. **Thirdweb returns transaction hash** → Payment confirmed on-chain ✅
2. **Store in database immediately**:
```sql
INSERT INTO payments (
user_address,
transaction_hash,
amount_usdc,
credits,
status,
created_at
) VALUES (
'0x...',
'0x123...',
1.00,
100,
'pending', -- Mark as pending verification
NOW()
);
```
3. **Show success to user immediately**
4. **Add credits to user's account** (they can use them right away)

### Phase 2: Background Verification (Verify)
Run a background job (cron/queue) every minute:

```javascript
// Every minute, verify pending payments
async function verifyPendingPayments() {
const pendingPayments = await db.query(`
SELECT * FROM payments
WHERE status = 'pending'
AND created_at > NOW() - INTERVAL '1 hour'
`);

for (const payment of pendingPayments) {
const verified = await checkMirrorNode(payment.transaction_hash);

if (verified) {
await db.query(`
UPDATE payments
SET status = 'verified', verified_at = NOW()
WHERE id = $1
`, [payment.id]);
}
}
}
```

### Phase 3: Reconciliation (Optional)
Daily job to check for fraud:
- Find payments stuck in "pending" for >24 hours
- Flag for manual review
- Reverse credits if payment was fake

## Simpler Alternative: Just Trust Thirdweb

**If transaction hash exists from thirdweb → Payment is confirmed**

Thirdweb only returns a transaction hash if:
- ✅ Transaction was signed
- ✅ Transaction was broadcast
- ✅ Transaction was successful on-chain

So you can simply:
1. Get transaction hash from thirdweb
2. Store it in database
3. Add credits immediately
4. Done! ✅

Mirror Node verification is just for audit trail, not required for operation.

## Recommended Implementation

**Option A: Immediate (Simplest)**
- Trust thirdweb transaction hash
- Add credits immediately
- Log transaction for audit

**Option B: Trust + Async Verify (Production)**
- Trust thirdweb initially
- Add credits immediately
- Verify in background via cron job
- Flag if verification fails (rare)

**Option C: Wait for Verification (Current - Not Recommended)**
- User waits 10+ seconds
- Bad UX
- Still can fail due to Mirror Node lag
204 changes: 204 additions & 0 deletions PAYMENT_SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# Payment Security Guide

## The Attack You Asked About

**Question:** "What if user sends query directly to our backend API using Postman with random hash?"

```bash
# Attacker tries to fake a payment
curl -X POST https://yourapp.com/api/verify-payment \
-H "Content-Type: application/json" \
-d '{
"transactionHash": "0xFAKE123456",
"senderAddress": "0x1234...",
"credits": 999999
}'
```

## Multi-Layer Defense

### Layer 1: Authentication (CRITICAL - Implement First)

**Require user to be logged in before calling this endpoint.**

```typescript
// In /api/verify-payment/route.ts
const session = await getServerSession();
if (!session) {
return NextResponse.json(
{ success: false, error: 'Unauthorized' },
{ status: 401 }
);
}
```

**Result:** Anonymous attackers blocked ✅

---

### Layer 2: Wallet Ownership Verification

**Verify the sender address belongs to the logged-in user.**

```typescript
const userWallet = await db.query(
'SELECT wallet_address FROM users WHERE id = $1',
[session.user.id]
);

if (senderAddress.toLowerCase() !== userWallet.toLowerCase()) {
return NextResponse.json(
{ success: false, error: 'Wallet mismatch' },
{ status: 403 }
);
}
```

**Result:** Attacker can't claim credits for someone else's wallet ✅

---

### Layer 3: Transaction Deduplication

**Prevent same transaction hash from being used twice (replay attack).**

```typescript
// Check if already processed
const existing = await supabase
.from('payments')
.select('id')
.eq('transaction_hash', transactionHash)
.single();

if (existing.data) {
return NextResponse.json(
{ success: false, error: 'Transaction already processed' },
{ status: 400 }
);
}

// After confirming, store it
await supabase.from('payments').insert({
transaction_hash: transactionHash,
user_id: session.user.id,
wallet_address: senderAddress,
amount_usdc: amount,
credits: credits,
status: 'confirmed',
created_at: new Date()
});
```

**Result:** Same transaction can't be reused ✅

---

### Layer 4: Background Verification (Optional but Recommended)

**Verify transaction on Mirror Node asynchronously.**

```typescript
// Don't block the response, verify in background
setTimeout(() => {
verifyOnMirrorNode(transactionHash)
.then(result => {
if (result.verified) {
// Update DB: status = 'verified'
} else {
// 🚨 FRAUD ALERT!
// Update DB: status = 'fraud_suspected'
// Send alert to admin
// Freeze user credits
}
});
}, 10000); // Wait 10s for indexing
```

**Result:** Fake transactions flagged for review ✅

---

## Implementation Priority

### Phase 1 (Must Have - Implement Now)
1. ✅ Authentication check
2. ✅ Wallet ownership verification
3. ✅ Transaction deduplication (store in DB)

### Phase 2 (Should Have - Week 1)
4. Background Mirror Node verification
5. Fraud alert system

### Phase 3 (Nice to Have - Future)
6. Rate limiting (max 10 purchases per hour)
7. Amount limits (max $100 per transaction)
8. Admin dashboard for reviewing flagged transactions

---

## Database Schema

```sql
CREATE TABLE payments (
id SERIAL PRIMARY KEY,
user_id UUID REFERENCES users(id),
wallet_address VARCHAR(42) NOT NULL,
transaction_hash VARCHAR(66) UNIQUE NOT NULL, -- Prevents duplicates
amount_usdc DECIMAL(10, 2) NOT NULL,
credits INTEGER NOT NULL,
status VARCHAR(20) DEFAULT 'confirmed', -- confirmed, verified, fraud_suspected
verified_at TIMESTAMP NULL,
created_at TIMESTAMP DEFAULT NOW(),

INDEX idx_user_id (user_id),
INDEX idx_transaction_hash (transaction_hash),
INDEX idx_status (status)
);
```

---

## Testing Security

### Test 1: Try to use same transaction twice
```bash
# First call: Success
# Second call: "Transaction already processed" ✅
```

### Test 2: Try to use someone else's transaction
```bash
# User A's wallet: 0xAAA...
# Attacker tries: senderAddress: 0xAAA, but logged in as User B
# Result: "Wallet mismatch" ✅
```

### Test 3: Try without authentication
```bash
# No session cookie
# Result: "Unauthorized" ✅
```

---

## Why This is Safe

Even if attacker sends fake transaction hash:

1. ❌ **No auth** → Blocked at Layer 1
2. ❌ **Wrong wallet** → Blocked at Layer 2
3. ❌ **Reused hash** → Blocked at Layer 3
4. ❌ **Fake hash** → Flagged at Layer 4 (background check)

All 4 layers must be bypassed = Nearly impossible!

---

## Next Steps

1. **Implement Layer 1-3 now** (authentication + deduplication)
2. **Add background verification** (flags fraud without blocking UX)
3. **Monitor logs** for fraud attempts
4. **Review flagged transactions** weekly

This gives you **enterprise-grade security** without cron jobs or complex infrastructure!
Loading