Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class GroupController {
res.json(groups.map(group => ({
id: group.id,
name: group.name,
ename: group.ename,
description: group.description,
charter: group.charter,
createdAt: group.createdAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class CalculationService {

private buildPrompt(userValues: string, references: any[], targetName: string): string {
return `
You are analyzing the reputation of "${targetName}" based on the following user values and references.
You are analyzing the reputation of "${targetName}" based on the following user values and references. Remember that the user may also supply a wishlist, only focus on the part of the wishlist and values which mentions what the user values in a person, group, or platform, depending on what type of profile it is that you are evaluating, do not care about anything else in the wishlist.

USER VALUES (what the evaluator cares about):
${userValues}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export interface ReferenceSigningResult {
type: "signed" | "security_violation";
}

// Module-level singleton session storage - shared across all service instances
const sessionStorage: Map<string, ReferenceSigningSession> = new Map();

export class ReferenceSigningSessionService {
private sessions: Map<string, ReferenceSigningSession> = new Map();
private signatureService = new ReferenceSignatureService();

async createSession(referenceId: string, referenceData: any, userId: string): Promise<ReferenceSigningSession> {
Expand All @@ -55,7 +57,7 @@ export class ReferenceSigningSessionService {
});

const base64Data = Buffer.from(messageData).toString('base64');
const apiBaseUrl = process.env.PUBLIC_EREPUTATION_BASE_URL || "http://localhost:8765";
const apiBaseUrl = process.env.VITE_EREPUTATION_BASE_URL;
const redirectUri = `${apiBaseUrl}/api/references/signing/callback`;

const qrData = `w3ds://sign?session=${sessionId}&data=${base64Data}&redirect_uri=${encodeURIComponent(redirectUri)}`;
Expand All @@ -71,23 +73,23 @@ export class ReferenceSigningSessionService {
status: "pending"
};

this.sessions.set(sessionId, session);
console.log(`Created reference signing session ${sessionId}, total sessions: ${this.sessions.size}`);
sessionStorage.set(sessionId, session);
console.log(`Created reference signing session ${sessionId}, total sessions: ${sessionStorage.size}`);

// Set up expiration cleanup
setTimeout(() => {
const session = this.sessions.get(sessionId);
const session = sessionStorage.get(sessionId);
if (session && session.status === "pending") {
session.status = "expired";
this.sessions.set(sessionId, session);
sessionStorage.set(sessionId, session);
}
}, 15 * 60 * 1000);

return session;
}

async getSession(sessionId: string): Promise<ReferenceSigningSession | null> {
const session = this.sessions.get(sessionId);
const session = sessionStorage.get(sessionId);

if (!session) {
return null;
Expand All @@ -96,18 +98,21 @@ export class ReferenceSigningSessionService {
// Check if session has expired
if (session.status === "pending" && new Date() > session.expiresAt) {
session.status = "expired";
this.sessions.set(sessionId, session);
sessionStorage.set(sessionId, session);
}

return session;
}

async processSignedPayload(sessionId: string, signature: string, publicKey: string, message: string): Promise<ReferenceSigningResult> {
console.log(`Processing signed payload for reference session: ${sessionId}`);
console.log(`Current session storage size: ${sessionStorage.size}`);
console.log(`Session IDs in storage:`, Array.from(sessionStorage.keys()));

const session = await this.getSession(sessionId);

if (!session) {
console.error(`Session ${sessionId} not found in storage. Available sessions:`, Array.from(sessionStorage.keys()));
throw new Error("Session not found");
}

Expand Down Expand Up @@ -145,7 +150,7 @@ export class ReferenceSigningSessionService {

// Update session status to indicate security violation
session.status = "security_violation";
this.sessions.set(sessionId, session);
sessionStorage.set(sessionId, session);

// Return error result instead of throwing
return {
Expand Down Expand Up @@ -184,7 +189,7 @@ export class ReferenceSigningSessionService {

// Update session status
session.status = "completed";
this.sessions.set(sessionId, session);
sessionStorage.set(sessionId, session);

const result: ReferenceSigningResult = {
success: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,15 @@ export default function OtherCalculationModal({ open, onOpenChange }: OtherCalcu
</svg>
)}
</div>
<div>
<div className="font-bold text-fig">{result.name || result.ename || result.handle || 'Unknown'}</div>
<div className="text-xs text-fig/70 capitalize">{result.type || result.category || targetType}</div>
<div className="flex-1 min-w-0">
<div className="font-bold text-fig truncate">{result.name || result.ename || result.handle || 'Unknown'}</div>
<div className="text-xs text-fig/70">
{targetType === 'user' ? (
result.ename ? (result.ename.startsWith('@') ? result.ename : `@${result.ename}`) : 'no ename'
) : (
<span className="capitalize">{result.type || result.category || targetType}</span>
)}
</div>
</div>
</div>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,17 @@ export default function ReferenceModal({ open, onOpenChange }: ReferenceModalPro
</svg>
)}
</div>
<div>
<div className="font-bold text-fig">{result.name || result.ename || result.handle || 'Unknown'}</div>
<div className="text-xs text-fig/70 capitalize">{result.type || result.category || targetType}</div>
<div className="flex-1 min-w-0">
<div className="font-bold text-fig truncate">
{result.name || result.ename || result.handle || 'Unknown'}
</div>
<div className="text-xs text-fig/70">
{targetType === 'user' ? (
result.ename ? (result.ename.startsWith('@') ? result.ename : `@${result.ename}`) : 'no ename'
) : (
<span className="capitalize">{result.type || result.category || targetType}</span>
)}
</div>
</div>
</div>
</button>
Expand All @@ -536,11 +544,13 @@ export default function ReferenceModal({ open, onOpenChange }: ReferenceModalPro
{selectedTarget && (
<div className="mt-2 p-3 border-2 border-fig/20 rounded-2xl bg-fig-10">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<svg className="w-4 h-4 text-swiss-cheese" fill="currentColor" viewBox="0 0 20 20">
<div className="flex items-center gap-2 flex-1 min-w-0">
<svg className="w-4 h-4 text-swiss-cheese flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
<path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />
</svg>
<span className="font-black text-fig">{selectedTarget.name || selectedTarget.ename || selectedTarget.handle || 'Unknown'}</span>
<span className="font-black text-fig truncate">
{selectedTarget.name || selectedTarget.ename || selectedTarget.handle || 'Unknown'}
</span>
</div>
<button
onClick={() => {
Expand Down