Skip to content

Commit d6bea52

Browse files
sosweethamcoodos
andauthored
fix: eid wallet link (#403)
* fix: eid wallet link * chore: run format --------- Co-authored-by: Merul Dhiman <[email protected]>
1 parent f506144 commit d6bea52

File tree

7 files changed

+149
-107
lines changed

7 files changed

+149
-107
lines changed

infrastructure/blindvote/src/core/voting-system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
dec,
2121
tallyOption
2222
} from "../crypto/pedersen";
23-
import {
23+
import type {
2424
Voter,
2525
VoteData,
2626
ElectionConfig,

infrastructure/eid-wallet/src/lib/crypto/KeyManagerFactory.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { KeyManagerError, KeyManagerErrorCodes } from "./types";
66
/**
77
* Factory class to create appropriate key managers based on context
88
*/
9+
// biome-ignore lint/complexity/noStaticOnlyClass: Factory pattern with state management requires a class
910
export class KeyManagerFactory {
1011
private static hardwareKeyManager: HardwareKeyManager | null = null;
1112
private static softwareKeyManager: SoftwareKeyManager | null = null;
@@ -16,18 +17,18 @@ export class KeyManagerFactory {
1617
static async getKeyManager(config: KeyManagerConfig): Promise<KeyManager> {
1718
// If explicitly requesting hardware and not in pre-verification mode
1819
if (config.useHardware && !config.preVerificationMode) {
19-
return this.getHardwareKeyManager();
20+
return KeyManagerFactory.getHardwareKeyManager();
2021
}
2122

2223
// If in pre-verification mode, always use software keys
2324
if (config.preVerificationMode) {
2425
console.log("Using software key manager for pre-verification mode");
25-
return this.getSoftwareKeyManager();
26+
return KeyManagerFactory.getSoftwareKeyManager();
2627
}
2728

2829
// Default behavior: try hardware first, fallback to software
2930
try {
30-
const hardwareManager = this.getHardwareKeyManager();
31+
const hardwareManager = KeyManagerFactory.getHardwareKeyManager();
3132
// Test if hardware is available by checking if we can call exists
3233
await hardwareManager.exists(config.keyId);
3334
console.log("Using hardware key manager");
@@ -36,36 +37,36 @@ export class KeyManagerFactory {
3637
console.log(
3738
"Hardware key manager not available, falling back to software",
3839
);
39-
return this.getSoftwareKeyManager();
40+
return KeyManagerFactory.getSoftwareKeyManager();
4041
}
4142
}
4243

4344
/**
4445
* Get hardware key manager instance (singleton)
4546
*/
4647
private static getHardwareKeyManager(): HardwareKeyManager {
47-
if (!this.hardwareKeyManager) {
48-
this.hardwareKeyManager = new HardwareKeyManager();
48+
if (!KeyManagerFactory.hardwareKeyManager) {
49+
KeyManagerFactory.hardwareKeyManager = new HardwareKeyManager();
4950
}
50-
return this.hardwareKeyManager;
51+
return KeyManagerFactory.hardwareKeyManager;
5152
}
5253

5354
/**
5455
* Get software key manager instance (singleton)
5556
*/
5657
private static getSoftwareKeyManager(): SoftwareKeyManager {
57-
if (!this.softwareKeyManager) {
58-
this.softwareKeyManager = new SoftwareKeyManager();
58+
if (!KeyManagerFactory.softwareKeyManager) {
59+
KeyManagerFactory.softwareKeyManager = new SoftwareKeyManager();
5960
}
60-
return this.softwareKeyManager;
61+
return KeyManagerFactory.softwareKeyManager;
6162
}
6263

6364
/**
6465
* Check if hardware key manager is available
6566
*/
6667
static async isHardwareAvailable(): Promise<boolean> {
6768
try {
68-
const hardwareManager = this.getHardwareKeyManager();
69+
const hardwareManager = KeyManagerFactory.getHardwareKeyManager();
6970
// Try to check if a test key exists to verify hardware availability
7071
await hardwareManager.exists("test-hardware-check");
7172
return true;
@@ -88,14 +89,14 @@ export class KeyManagerFactory {
8889
preVerificationMode: context === "pre-verification",
8990
};
9091

91-
return this.getKeyManager(config);
92+
return KeyManagerFactory.getKeyManager(config);
9293
}
9394

9495
/**
9596
* Reset singleton instances (useful for testing)
9697
*/
9798
static reset(): void {
98-
this.hardwareKeyManager = null;
99-
this.softwareKeyManager = null;
99+
KeyManagerFactory.hardwareKeyManager = null;
100+
KeyManagerFactory.softwareKeyManager = null;
100101
}
101102
}

infrastructure/eid-wallet/src/lib/global/controllers/evault.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,7 @@ export class VaultController {
157157
}
158158

159159
// Wait before retrying (exponential backoff)
160-
const delay = Math.min(
161-
1000 * Math.pow(2, retryCount - 1),
162-
10000,
163-
);
160+
const delay = Math.min(1000 * 2 ** (retryCount - 1), 10000);
164161
console.log(`Waiting ${delay}ms before resolve retry...`);
165162
await new Promise((resolve) => setTimeout(resolve, delay));
166163
}
@@ -174,9 +171,7 @@ export class VaultController {
174171
*/
175172
private async ensureClient(w3id: string): Promise<GraphQLClient> {
176173
this.#endpoint = await this.resolveEndpoint(w3id);
177-
this.#client = new GraphQLClient(this.#endpoint, {
178-
timeout: 3000, // 3 second timeout for GraphQL requests
179-
});
174+
this.#client = new GraphQLClient(this.#endpoint);
180175
return this.#client;
181176
}
182177

infrastructure/eid-wallet/src/lib/services/NotificationService.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface DeviceRegistration {
1717
export interface NotificationPayload {
1818
title: string;
1919
body: string;
20-
data?: Record<string, any>;
20+
data?: Record<string, unknown>;
2121
}
2222

2323
class NotificationService {
@@ -105,9 +105,8 @@ class NotificationService {
105105
this.deviceRegistration = registration;
106106
console.log("Device registered successfully:", registration);
107107
return true;
108-
} else {
109-
throw new Error(`Registration failed: ${response.statusText}`);
110108
}
109+
throw new Error(`Registration failed: ${response.statusText}`);
111110
} catch (error) {
112111
console.error("Failed to register device:", error);
113112
return false;
@@ -139,15 +138,13 @@ class NotificationService {
139138
body: payload.body,
140139
icon: "icons/32x32.png",
141140
sound: "default",
142-
data: payload.data,
143141
});
144142

145143
await sendNotification({
146144
title: payload.title,
147145
body: payload.body,
148146
icon: "icons/32x32.png",
149147
sound: "default",
150-
data: payload.data,
151148
});
152149

153150
console.log("Notification sent successfully!");
@@ -183,11 +180,8 @@ class NotificationService {
183180
this.deviceRegistration = null;
184181
console.log("Device unregistered successfully");
185182
return true;
186-
} else {
187-
throw new Error(
188-
`Unregistration failed: ${response.statusText}`,
189-
);
190183
}
184+
throw new Error(`Unregistration failed: ${response.statusText}`);
191185
} catch (error) {
192186
console.error("Failed to unregister device:", error);
193187
return false;
@@ -370,7 +364,7 @@ class NotificationService {
370364
m.Store.load("global-state.json"),
371365
);
372366
const vault = await store.get<{ ename: string }>("vault");
373-
return vault;
367+
return vault || null;
374368
} catch (error) {
375369
console.error("Error getting vault eName:", error);
376370
return null;

0 commit comments

Comments
 (0)