Skip to content

Commit 21e3d3b

Browse files
committed
feat: eid-reclaim
1 parent d13fcb5 commit 21e3d3b

File tree

18 files changed

+1159
-440
lines changed

18 files changed

+1159
-440
lines changed
31 MB
Binary file not shown.

infrastructure/eid-wallet/src-tauri/gen/apple/eid-wallet.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@
416416
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)",
417417
);
418418
MARKETING_VERSION = 0.2.1;
419-
PRODUCT_BUNDLE_IDENTIFIER = "foundation.metastate.eid-wallet";
419+
PRODUCT_BUNDLE_IDENTIFIER = foundation.metastate.eid-wallet;
420420
PRODUCT_NAME = "eID for W3DS";
421421
SDKROOT = iphoneos;
422422
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
@@ -464,7 +464,7 @@
464464
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)",
465465
);
466466
MARKETING_VERSION = 0.2.1;
467-
PRODUCT_BUNDLE_IDENTIFIER = "foundation.metastate.eid-wallet";
467+
PRODUCT_BUNDLE_IDENTIFIER = foundation.metastate.eid-wallet;
468468
PRODUCT_NAME = "eID for W3DS";
469469
SDKROOT = iphoneos;
470470
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";

infrastructure/eid-wallet/src-tauri/gen/apple/eid-wallet_iOS/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@
6161
<string>UIInterfaceOrientationLandscapeRight</string>
6262
</array>
6363
</dict>
64-
</plist>
64+
</plist>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import type { KeyManager } from './types';
2+
import { KeyManagerError, KeyManagerErrorCodes } from './types';
3+
import {
4+
exists as hwExists,
5+
generate as hwGenerate,
6+
getPublicKey as hwGetPublicKey,
7+
signPayload as hwSignPayload,
8+
verifySignature as hwVerifySignature,
9+
} from '@auvo/tauri-plugin-crypto-hw-api';
10+
11+
/**
12+
* Hardware key manager implementation using Tauri crypto hardware API
13+
*/
14+
export class HardwareKeyManager implements KeyManager {
15+
getType(): 'hardware' | 'software' {
16+
return 'hardware';
17+
}
18+
19+
async exists(keyId: string): Promise<boolean> {
20+
try {
21+
return await hwExists(keyId);
22+
} catch (error) {
23+
console.error('Hardware key exists check failed:', error);
24+
throw new KeyManagerError(
25+
'Failed to check if hardware key exists',
26+
KeyManagerErrorCodes.HARDWARE_UNAVAILABLE,
27+
keyId
28+
);
29+
}
30+
}
31+
32+
async generate(keyId: string): Promise<string | undefined> {
33+
try {
34+
const result = await hwGenerate(keyId);
35+
console.log(`Hardware key generated for ${keyId}:`, result);
36+
return result;
37+
} catch (error) {
38+
console.error('Hardware key generation failed:', error);
39+
throw new KeyManagerError(
40+
'Failed to generate hardware key',
41+
KeyManagerErrorCodes.KEY_GENERATION_FAILED,
42+
keyId
43+
);
44+
}
45+
}
46+
47+
async getPublicKey(keyId: string): Promise<string | undefined> {
48+
try {
49+
const publicKey = await hwGetPublicKey(keyId);
50+
console.log(`Hardware public key retrieved for ${keyId}:`, publicKey);
51+
return publicKey;
52+
} catch (error) {
53+
console.error('Hardware public key retrieval failed:', error);
54+
throw new KeyManagerError(
55+
'Failed to get hardware public key',
56+
KeyManagerErrorCodes.KEY_NOT_FOUND,
57+
keyId
58+
);
59+
}
60+
}
61+
62+
async signPayload(keyId: string, payload: string): Promise<string> {
63+
try {
64+
const signature = await hwSignPayload(keyId, payload);
65+
console.log(`Hardware signature created for ${keyId}`);
66+
return signature;
67+
} catch (error) {
68+
console.error('Hardware signing failed:', error);
69+
throw new KeyManagerError(
70+
'Failed to sign payload with hardware key',
71+
KeyManagerErrorCodes.SIGNING_FAILED,
72+
keyId
73+
);
74+
}
75+
}
76+
77+
async verifySignature(keyId: string, payload: string, signature: string): Promise<boolean> {
78+
try {
79+
const isValid = await hwVerifySignature(keyId, payload, signature);
80+
console.log(`Hardware signature verification for ${keyId}:`, isValid);
81+
return isValid;
82+
} catch (error) {
83+
console.error('Hardware signature verification failed:', error);
84+
throw new KeyManagerError(
85+
'Failed to verify signature with hardware key',
86+
KeyManagerErrorCodes.VERIFICATION_FAILED,
87+
keyId
88+
);
89+
}
90+
}
91+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import type { KeyManager, KeyManagerConfig } from './types';
2+
import { HardwareKeyManager } from './HardwareKeyManager';
3+
import { SoftwareKeyManager } from './SoftwareKeyManager';
4+
import { KeyManagerError, KeyManagerErrorCodes } from './types';
5+
6+
/**
7+
* Factory class to create appropriate key managers based on context
8+
*/
9+
export class KeyManagerFactory {
10+
private static hardwareKeyManager: HardwareKeyManager | null = null;
11+
private static softwareKeyManager: SoftwareKeyManager | null = null;
12+
13+
/**
14+
* Get a key manager instance based on the configuration
15+
*/
16+
static async getKeyManager(config: KeyManagerConfig): Promise<KeyManager> {
17+
// If explicitly requesting hardware and not in pre-verification mode
18+
if (config.useHardware && !config.preVerificationMode) {
19+
return this.getHardwareKeyManager();
20+
}
21+
22+
// If in pre-verification mode, always use software keys
23+
if (config.preVerificationMode) {
24+
console.log('Using software key manager for pre-verification mode');
25+
return this.getSoftwareKeyManager();
26+
}
27+
28+
// Default behavior: try hardware first, fallback to software
29+
try {
30+
const hardwareManager = this.getHardwareKeyManager();
31+
// Test if hardware is available by checking if we can call exists
32+
await hardwareManager.exists(config.keyId);
33+
console.log('Using hardware key manager');
34+
return hardwareManager;
35+
} catch (error) {
36+
console.log('Hardware key manager not available, falling back to software');
37+
return this.getSoftwareKeyManager();
38+
}
39+
}
40+
41+
/**
42+
* Get hardware key manager instance (singleton)
43+
*/
44+
private static getHardwareKeyManager(): HardwareKeyManager {
45+
if (!this.hardwareKeyManager) {
46+
this.hardwareKeyManager = new HardwareKeyManager();
47+
}
48+
return this.hardwareKeyManager;
49+
}
50+
51+
/**
52+
* Get software key manager instance (singleton)
53+
*/
54+
private static getSoftwareKeyManager(): SoftwareKeyManager {
55+
if (!this.softwareKeyManager) {
56+
this.softwareKeyManager = new SoftwareKeyManager();
57+
}
58+
return this.softwareKeyManager;
59+
}
60+
61+
/**
62+
* Check if hardware key manager is available
63+
*/
64+
static async isHardwareAvailable(): Promise<boolean> {
65+
try {
66+
const hardwareManager = this.getHardwareKeyManager();
67+
// Try to check if a test key exists to verify hardware availability
68+
await hardwareManager.exists('test-hardware-check');
69+
return true;
70+
} catch (error) {
71+
console.log('Hardware key manager not available:', error);
72+
return false;
73+
}
74+
}
75+
76+
/**
77+
* Get the appropriate key manager for a specific use case
78+
*/
79+
static async getKeyManagerForContext(
80+
keyId: string,
81+
context: 'onboarding' | 'signing' | 'verification' | 'pre-verification'
82+
): Promise<KeyManager> {
83+
const config: KeyManagerConfig = {
84+
keyId,
85+
useHardware: context !== 'pre-verification',
86+
preVerificationMode: context === 'pre-verification',
87+
};
88+
89+
return this.getKeyManager(config);
90+
}
91+
92+
/**
93+
* Reset singleton instances (useful for testing)
94+
*/
95+
static reset(): void {
96+
this.hardwareKeyManager = null;
97+
this.softwareKeyManager = null;
98+
}
99+
}

0 commit comments

Comments
 (0)