Skip to content

Commit ec9e514

Browse files
authored
fix: replace publicKey with w3id (#430)
1 parent 6466a04 commit ec9e514

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

platforms/evoting-api/src/controllers/SigningController.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ export class SigningController {
9393
// Handle signed payload callback from eID Wallet
9494
async handleSignedPayload(req: Request, res: Response) {
9595
try {
96-
const { sessionId, signature, publicKey, message } = req.body;
96+
const { sessionId, signature, w3id, message } = req.body;
9797

98-
if (!sessionId || !signature || !publicKey || !message) {
98+
if (!sessionId || !signature || !w3id || !message) {
9999
const missingFields = [];
100100
if (!sessionId) missingFields.push('sessionId');
101101
if (!signature) missingFields.push('signature');
102-
if (!publicKey) missingFields.push('publicKey');
102+
if (!w3id) missingFields.push('w3id');
103103
if (!message) missingFields.push('message');
104104

105105
return res.status(400).json({
@@ -112,7 +112,7 @@ export class SigningController {
112112
const result = await this.ensureService().processSignedPayload(
113113
sessionId,
114114
signature,
115-
publicKey,
115+
w3id,
116116
message
117117
);
118118

platforms/evoting-api/src/services/SigningService.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface SigningSession {
1717
export interface SignedPayload {
1818
sessionId: string;
1919
signature: string;
20-
publicKey: string;
20+
w3id: string;
2121
message: string;
2222
}
2323

@@ -112,7 +112,7 @@ export class SigningService {
112112
return session;
113113
}
114114

115-
async processSignedPayload(sessionId: string, signature: string, publicKey: string, message: string): Promise<SigningResult> {
115+
async processSignedPayload(sessionId: string, signature: string, w3id: string, message: string): Promise<SigningResult> {
116116
const session = await this.getSession(sessionId);
117117

118118
if (!session) {
@@ -128,7 +128,7 @@ export class SigningService {
128128
}
129129

130130
try {
131-
// 🔐 SECURITY ASSERTION: Verify that the publicKey matches the user's ename who created the session
131+
// 🔐 SECURITY ASSERTION: Verify that the w3id matches the user's ename who created the session
132132
try {
133133
const { UserService } = await import('./UserService');
134134
const userService = new UserService();
@@ -139,14 +139,14 @@ export class SigningService {
139139
}
140140

141141
// Strip @ prefix from both enames before comparison
142-
const cleanPublicKey = publicKey.replace(/^@/, '');
142+
const cleanW3id = w3id.replace(/^@/, '');
143143
const cleanUserEname = user.ename.replace(/^@/, '');
144144

145-
if (cleanPublicKey !== cleanUserEname) {
146-
console.error(`🔒 SECURITY VIOLATION: publicKey mismatch!`, {
147-
publicKey,
145+
if (cleanW3id !== cleanUserEname) {
146+
console.error(`🔒 SECURITY VIOLATION: w3id mismatch!`, {
147+
w3id,
148148
userEname: user.ename,
149-
cleanPublicKey,
149+
cleanW3id,
150150
cleanUserEname,
151151
sessionUserId: session.userId
152152
});
@@ -160,18 +160,18 @@ export class SigningService {
160160
this.notifySubscribers(sessionId, {
161161
type: "security_violation",
162162
status: "security_violation",
163-
error: "Public key does not match the user who created this signing session",
163+
error: "W3ID does not match the user who created this signing session",
164164
sessionId
165165
});
166166

167167
// Return success: false but don't throw error - let the wallet think it succeeded
168-
return { success: false, error: "Public key does not match the user who created this signing session" };
168+
return { success: false, error: "W3ID does not match the user who created this signing session" };
169169
}
170170

171-
console.log(`✅ Public key verification passed: ${cleanPublicKey} matches ${cleanUserEname}`);
171+
console.log(`✅ W3ID verification passed: ${cleanW3id} matches ${cleanUserEname}`);
172172
} catch (error) {
173-
console.error("Error during public key verification:", error);
174-
return { success: false, error: "Failed to verify public key: " + (error instanceof Error ? error.message : "Unknown error") };
173+
console.error("Error during w3id verification:", error);
174+
return { success: false, error: "Failed to verify w3id: " + (error instanceof Error ? error.message : "Unknown error") };
175175
}
176176

177177
// Verify the signature (basic verification for now)

0 commit comments

Comments
 (0)