Skip to content
Open
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
26 changes: 17 additions & 9 deletions app/api/reputation/link-wallet/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextRequest, NextResponse } from "next/server";
import { ReputationService } from "@/lib/services/reputation";
import { getCurrentUser } from "@/lib/server-auth";
import { verifyMessage } from "viem";

export async function POST(request: NextRequest) {
try {
Expand All @@ -16,17 +17,24 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ error: "Unauthorized" }, { status: 403 });
}

// 2. Signature Verification
// Note: Real implementation would use ethers.verifyMessage or similar
// const recoveredAddress = verifyMessage(`Link wallet ${address} to user ${userId}`, signature);
const isValidSignature = true; // Mocked for now

if (!isValidSignature) {
// if (recoveredAddress !== address)
return NextResponse.json({ error: "Invalid signature" }, { status: 403 });
// 2. Signature Verification using viem
const message = `Link wallet ${address} to user ${userId}`;

try {
const isValidSignature = await verifyMessage({
address: address as `0x${string}`,
message: message,
signature: signature as `0x${string}`,
});

if (!isValidSignature) {
return NextResponse.json({ error: "Invalid signature" }, { status: 403 });
}
} catch (verifyError) {
console.error("Signature verification failed:", verifyError);
return NextResponse.json({ error: "Invalid signature format" }, { status: 403 });
}

// 3. Service Call
// 3. Service Call
const result = await ReputationService.linkWallet(userId, address);

Expand Down