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
2 changes: 1 addition & 1 deletion infrastructure/blindvote/src/core/voting-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
dec,
tallyOption
} from "../crypto/pedersen";
import {
import type {
Voter,
VoteData,
ElectionConfig,
Expand Down
29 changes: 15 additions & 14 deletions infrastructure/eid-wallet/src/lib/crypto/KeyManagerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { KeyManagerError, KeyManagerErrorCodes } from "./types";
/**
* Factory class to create appropriate key managers based on context
*/
// biome-ignore lint/complexity/noStaticOnlyClass: Factory pattern with state management requires a class
export class KeyManagerFactory {
private static hardwareKeyManager: HardwareKeyManager | null = null;
private static softwareKeyManager: SoftwareKeyManager | null = null;
Expand All @@ -16,18 +17,18 @@ export class KeyManagerFactory {
static async getKeyManager(config: KeyManagerConfig): Promise<KeyManager> {
// If explicitly requesting hardware and not in pre-verification mode
if (config.useHardware && !config.preVerificationMode) {
return this.getHardwareKeyManager();
return KeyManagerFactory.getHardwareKeyManager();
}

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

// Default behavior: try hardware first, fallback to software
try {
const hardwareManager = this.getHardwareKeyManager();
const hardwareManager = KeyManagerFactory.getHardwareKeyManager();
// Test if hardware is available by checking if we can call exists
await hardwareManager.exists(config.keyId);
console.log("Using hardware key manager");
Expand All @@ -36,36 +37,36 @@ export class KeyManagerFactory {
console.log(
"Hardware key manager not available, falling back to software",
);
return this.getSoftwareKeyManager();
return KeyManagerFactory.getSoftwareKeyManager();
}
}

/**
* Get hardware key manager instance (singleton)
*/
private static getHardwareKeyManager(): HardwareKeyManager {
if (!this.hardwareKeyManager) {
this.hardwareKeyManager = new HardwareKeyManager();
if (!KeyManagerFactory.hardwareKeyManager) {
KeyManagerFactory.hardwareKeyManager = new HardwareKeyManager();
}
return this.hardwareKeyManager;
return KeyManagerFactory.hardwareKeyManager;
}

/**
* Get software key manager instance (singleton)
*/
private static getSoftwareKeyManager(): SoftwareKeyManager {
if (!this.softwareKeyManager) {
this.softwareKeyManager = new SoftwareKeyManager();
if (!KeyManagerFactory.softwareKeyManager) {
KeyManagerFactory.softwareKeyManager = new SoftwareKeyManager();
}
return this.softwareKeyManager;
return KeyManagerFactory.softwareKeyManager;
}

/**
* Check if hardware key manager is available
*/
static async isHardwareAvailable(): Promise<boolean> {
try {
const hardwareManager = this.getHardwareKeyManager();
const hardwareManager = KeyManagerFactory.getHardwareKeyManager();
// Try to check if a test key exists to verify hardware availability
await hardwareManager.exists("test-hardware-check");
return true;
Expand All @@ -88,14 +89,14 @@ export class KeyManagerFactory {
preVerificationMode: context === "pre-verification",
};

return this.getKeyManager(config);
return KeyManagerFactory.getKeyManager(config);
}

/**
* Reset singleton instances (useful for testing)
*/
static reset(): void {
this.hardwareKeyManager = null;
this.softwareKeyManager = null;
KeyManagerFactory.hardwareKeyManager = null;
KeyManagerFactory.softwareKeyManager = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ export class VaultController {
}

// Wait before retrying (exponential backoff)
const delay = Math.min(
1000 * Math.pow(2, retryCount - 1),
10000,
);
const delay = Math.min(1000 * 2 ** (retryCount - 1), 10000);
console.log(`Waiting ${delay}ms before resolve retry...`);
await new Promise((resolve) => setTimeout(resolve, delay));
}
Expand All @@ -174,9 +171,7 @@ export class VaultController {
*/
private async ensureClient(w3id: string): Promise<GraphQLClient> {
this.#endpoint = await this.resolveEndpoint(w3id);
this.#client = new GraphQLClient(this.#endpoint, {
timeout: 3000, // 3 second timeout for GraphQL requests
});
this.#client = new GraphQLClient(this.#endpoint);
return this.#client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface DeviceRegistration {
export interface NotificationPayload {
title: string;
body: string;
data?: Record<string, any>;
data?: Record<string, unknown>;
}

class NotificationService {
Expand Down Expand Up @@ -105,9 +105,8 @@ class NotificationService {
this.deviceRegistration = registration;
console.log("Device registered successfully:", registration);
return true;
} else {
throw new Error(`Registration failed: ${response.statusText}`);
}
throw new Error(`Registration failed: ${response.statusText}`);
} catch (error) {
console.error("Failed to register device:", error);
return false;
Expand Down Expand Up @@ -139,15 +138,13 @@ class NotificationService {
body: payload.body,
icon: "icons/32x32.png",
sound: "default",
data: payload.data,
});

await sendNotification({
title: payload.title,
body: payload.body,
icon: "icons/32x32.png",
sound: "default",
data: payload.data,
});

console.log("Notification sent successfully!");
Expand Down Expand Up @@ -183,11 +180,8 @@ class NotificationService {
this.deviceRegistration = null;
console.log("Device unregistered successfully");
return true;
} else {
throw new Error(
`Unregistration failed: ${response.statusText}`,
);
}
throw new Error(`Unregistration failed: ${response.statusText}`);
} catch (error) {
console.error("Failed to unregister device:", error);
return false;
Expand Down Expand Up @@ -370,7 +364,7 @@ class NotificationService {
m.Store.load("global-state.json"),
);
const vault = await store.get<{ ename: string }>("vault");
return vault;
return vault || null;
} catch (error) {
console.error("Error getting vault eName:", error);
return null;
Expand Down
Loading
Loading