@@ -113,17 +113,34 @@ export class SigningService {
113113 }
114114
115115 async processSignedPayload ( sessionId : string , signature : string , w3id : string , message : string ) : Promise < SigningResult > {
116+ console . log ( "🔐 Processing signed payload:" , {
117+ sessionId,
118+ w3id,
119+ hasSignature : ! ! signature ,
120+ hasMessage : ! ! message
121+ } ) ;
122+
116123 const session = await this . getSession ( sessionId ) ;
117124
118125 if ( ! session ) {
126+ console . error ( "❌ Session not found:" , sessionId ) ;
119127 return { success : false , error : "Session not found" } ;
120128 }
121129
130+ console . log ( "📋 Session found:" , {
131+ sessionId : session . id ,
132+ status : session . status ,
133+ pollId : session . pollId ,
134+ userId : session . userId
135+ } ) ;
136+
122137 if ( session . status === "expired" ) {
138+ console . error ( "❌ Session expired" ) ;
123139 return { success : false , error : "Session expired" } ;
124140 }
125141
126142 if ( session . status === "completed" ) {
143+ console . error ( "❌ Session already completed" ) ;
127144 return { success : false , error : "Session already completed" } ;
128145 }
129146
@@ -176,28 +193,64 @@ export class SigningService {
176193
177194 // Verify the signature (basic verification for now)
178195 // In production, you'd want proper cryptographic verification
179- const expectedMessage = JSON . stringify ( {
180- pollId : session . pollId ,
181- voteData : session . voteData ,
182- userId : session . userId
183- // Removed timestamp from verification since it will never match
196+ // Parse the received message and check only the fields we care about
197+ let parsedMessage ;
198+ try {
199+ parsedMessage = JSON . parse ( message ) ;
200+ } catch ( error ) {
201+ console . error ( "❌ Failed to parse message as JSON:" , message ) ;
202+ return { success : false , error : "Invalid message format" } ;
203+ }
204+
205+ console . log ( "🔍 Message verification:" , {
206+ receivedMessage : message ,
207+ parsedMessage
208+ } ) ;
209+
210+ // Compare only the fields that matter (ignore extra fields like sessionId, timestamp)
211+ const pollIdMatches = parsedMessage . pollId === session . pollId ;
212+ const userIdMatches = parsedMessage . userId === session . userId ;
213+ const voteDataMatches = JSON . stringify ( parsedMessage . voteData ) === JSON . stringify ( session . voteData ) ;
214+
215+ console . log ( "🔍 Field comparison:" , {
216+ pollIdMatches,
217+ userIdMatches,
218+ voteDataMatches,
219+ expected : {
220+ pollId : session . pollId ,
221+ userId : session . userId ,
222+ voteData : session . voteData
223+ } ,
224+ received : {
225+ pollId : parsedMessage . pollId ,
226+ userId : parsedMessage . userId ,
227+ voteData : parsedMessage . voteData
228+ }
184229 } ) ;
185230
186- if ( message !== expectedMessage ) {
231+ if ( ! pollIdMatches || ! userIdMatches || ! voteDataMatches ) {
232+ console . error ( "❌ Message verification failed!" ) ;
187233 return { success : false , error : "Message verification failed" } ;
188234 }
189235
236+ console . log ( "✅ Message verification passed!" ) ;
237+
190238 // Check if this is a blind vote or regular vote by looking at the poll
239+ console . log ( "📊 Fetching poll information..." ) ;
191240 const pollService = new ( await import ( './PollService' ) ) . PollService ( ) ;
192241 const poll = await pollService . getPollById ( session . pollId ) ;
193242
194243 if ( ! poll ) {
244+ console . error ( "❌ Poll not found:" , session . pollId ) ;
195245 return { success : false , error : "Poll not found" } ;
196246 }
197247
248+ console . log ( "📊 Poll found:" , { pollId : poll . id , visibility : poll . visibility } ) ;
249+
198250 let voteResult ;
199251
200252 if ( poll . visibility === "private" ) {
253+ console . log ( "🔒 Submitting blind vote..." ) ;
201254 // Blind voting - submit using blind vote method
202255 voteResult = await this . getVoteService ( ) . submitBlindVote (
203256 session . pollId ,
@@ -208,32 +261,45 @@ export class SigningService {
208261 anchors : session . voteData . anchors || { }
209262 }
210263 ) ;
264+ console . log ( "✅ Blind vote submitted:" , voteResult ) ;
211265 } else {
266+ console . log ( "📝 Submitting regular vote..." ) ;
212267 // Regular voting - submit using regular vote method
213268 const mode = session . voteData . optionId !== undefined ? "normal" :
214269 session . voteData . points ? "point" : "rank" ;
215270
271+ console . log ( "Vote mode:" , mode , "voteData:" , session . voteData ) ;
272+
216273 voteResult = await this . getVoteService ( ) . createVote (
217274 session . pollId ,
218275 session . userId ,
219276 session . voteData ,
220277 mode
221278 ) ;
279+ console . log ( "✅ Regular vote submitted:" , voteResult ) ;
222280 }
223281
224282 // Update session status
283+ console . log ( "📝 Updating session status to completed..." ) ;
225284 session . status = "completed" ;
226285 session . updatedAt = new Date ( ) ;
227286 this . sessions . set ( sessionId , session ) ;
228287
229288 // Notify subscribers
289+ console . log ( "📢 Notifying subscribers..." , {
290+ sessionId,
291+ subscribersCount : this . subscribers . get ( sessionId ) ?. size || 0
292+ } ) ;
293+
230294 this . notifySubscribers ( sessionId , {
231295 type : "signed" ,
232296 status : "completed" ,
233297 voteResult,
234298 sessionId
235299 } ) ;
236300
301+ console . log ( "✅ Vote processing completed successfully!" ) ;
302+
237303 return {
238304 success : true ,
239305 voteResult
0 commit comments