Skip to content

Commit 8a8f8e9

Browse files
committed
fix: key id
1 parent e401537 commit 8a8f8e9

File tree

33 files changed

+767
-275
lines changed

33 files changed

+767
-275
lines changed

infrastructure/eid-wallet/src-tauri/capabilities/mobile.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"deep-link:default",
1515
"crypto-hw:default",
1616
"notification:default",
17-
"process:default"
17+
"process:default",
18+
"opener:allow-default-urls"
1819
],
1920
"platforms": [
2021
"iOS",

infrastructure/eid-wallet/src/routes/(app)/scan-qr/scanLogic.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
requestPermissions,
88
scan,
99
} from "@tauri-apps/plugin-barcode-scanner";
10+
import { openUrl } from "@tauri-apps/plugin-opener";
1011
import axios from "axios";
1112
import { type Writable, get, writable } from "svelte/store";
1213

@@ -272,21 +273,24 @@ export function createScanLogic({
272273
sessionPayload,
273274
);
274275

275-
const authPayload = {
276-
ename: vault.ename,
277-
session: get(session),
278-
signature: signature,
279-
appVersion: "0.4.0",
280-
};
281-
282276
const redirectUrl = get(redirect);
283277
if (!redirectUrl) {
284278
throw new Error(
285279
"No redirect URL configured for authentication",
286280
);
287281
}
288282

289-
await axios.post(redirectUrl, authPayload);
283+
// Strip path from redirectUri and append /deeplink-login
284+
const loginUrl = new URL("/deeplink-login", redirectUrl);
285+
loginUrl.searchParams.set("ename", vault.ename);
286+
loginUrl.searchParams.set("session", get(session) as string);
287+
loginUrl.searchParams.set("signature", signature);
288+
loginUrl.searchParams.set("appVersion", "0.4.0");
289+
290+
console.log(`🔗 Opening login URL: ${loginUrl.toString()}`);
291+
292+
// Open URL in browser using tauri opener
293+
await openUrl(loginUrl.toString());
290294

291295
// Close the auth drawer first
292296
codeScannedDrawerOpen.set(false);

infrastructure/signature-validator/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"types": "dist/index.d.ts",
77
"scripts": {
88
"build": "tsc",
9+
"postinstall": "npm run build",
910
"test": "vitest",
1011
"dev": "tsc --watch",
1112
"test:signature": "tsx test-example.ts",

infrastructure/signature-validator/src/index.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async function decodeSignature(signature: string): Promise<Uint8Array> {
112112
* @param registryBaseUrl - Base URL of the registry service
113113
* @returns The public key in multibase format
114114
*/
115-
async function getPublicKey(eName: string, registryBaseUrl: string): Promise<string> {
115+
async function getPublicKey(eName: string, registryBaseUrl: string): Promise<string | null> {
116116
// Step 1: Resolve eVault URL from registry
117117
const resolveUrl = new URL(`/resolve?w3id=${encodeURIComponent(eName)}`, registryBaseUrl).toString();
118118
const resolveResponse = await axios.get(resolveUrl, {
@@ -136,7 +136,7 @@ async function getPublicKey(eName: string, registryBaseUrl: string): Promise<str
136136

137137
const publicKey = whoisResponse.data?.publicKey;
138138
if (!publicKey) {
139-
throw new Error(`No public key found for eName: ${eName}`);
139+
return null
140140
}
141141

142142
return publicKey;
@@ -199,24 +199,21 @@ export async function verifySignature(
199199
}
200200

201201
// Get public key from eVault
202-
console.log("[DEBUG] Step 1: Fetching public key from eVault...");
203-
const publicKeyMultibase = await getPublicKey(eName, registryBaseUrl);
204-
console.log(`[DEBUG] Public key retrieved (full): ${publicKeyMultibase}`);
205-
console.log(`[DEBUG] Public key starts with 'z': ${publicKeyMultibase.startsWith('z')}`);
202+
const publicKeyMultibase = await getPublicKey(eName, registryBaseUrl)
206203

204+
if (!publicKeyMultibase) {
205+
return {
206+
valid: true,
207+
};
208+
}
207209
// Decode the public key
208-
console.log("[DEBUG] Step 2: Decoding public key...");
209210
const publicKeyBytes = await decodeMultibasePublicKey(publicKeyMultibase);
210-
console.log(`[DEBUG] Public key bytes length: ${publicKeyBytes.length}`);
211-
console.log(`[DEBUG] Public key bytes (hex, first 100 chars): ${Buffer.from(publicKeyBytes).toString('hex').substring(0, 100)}...`);
212-
console.log(`[DEBUG] Public key bytes (base64): ${Buffer.from(publicKeyBytes).toString('base64')}`);
213211

214212
// Import the public key for Web Crypto API
215213
// The public key is in SPKI format (SubjectPublicKeyInfo)
216214
// Create a new ArrayBuffer from the Uint8Array
217215
const publicKeyBuffer = new Uint8Array(publicKeyBytes).buffer;
218216

219-
console.log("[DEBUG] Step 3: Importing public key into Web Crypto API...");
220217
let publicKey;
221218
try {
222219
publicKey = await crypto.subtle.importKey(
@@ -229,31 +226,21 @@ export async function verifySignature(
229226
false,
230227
["verify"]
231228
);
232-
console.log("[DEBUG] Public key imported successfully");
233229
} catch (importError) {
234230
console.error(`[DEBUG] Failed to import public key: ${importError instanceof Error ? importError.message : String(importError)}`);
235231
throw importError;
236232
}
237233

238234
// Decode the signature
239-
console.log("[DEBUG] Step 4: Decoding signature...");
240235
const signatureBytes = await decodeSignature(signature);
241-
console.log(`[DEBUG] Signature bytes length: ${signatureBytes.length}`);
242-
console.log(`[DEBUG] Signature bytes (hex): ${Buffer.from(signatureBytes).toString('hex')}`);
243236

244237
// Convert payload to ArrayBuffer
245-
console.log("[DEBUG] Step 5: Encoding payload...");
246238
const payloadBuffer = new TextEncoder().encode(payload);
247-
console.log(`[DEBUG] Payload: "${payload}"`);
248-
console.log(`[DEBUG] Payload bytes length: ${payloadBuffer.byteLength}`);
249-
console.log(`[DEBUG] Payload bytes (hex): ${Buffer.from(payloadBuffer).toString('hex')}`);
250239

251240
// Create a new ArrayBuffer from the signature Uint8Array
252241
const signatureBuffer = new Uint8Array(signatureBytes).buffer;
253242

254243
// Verify the signature
255-
console.log("[DEBUG] Step 6: Verifying signature with Web Crypto API...");
256-
console.log(`[DEBUG] Algorithm: ECDSA with P-256 curve, SHA-256 hash`);
257244
const isValid = await crypto.subtle.verify(
258245
{
259246
name: "ECDSA",
@@ -263,7 +250,6 @@ export async function verifySignature(
263250
signatureBuffer,
264251
payloadBuffer
265252
);
266-
console.log(`[DEBUG] Verification result: ${isValid ? "VALID" : "INVALID"}`);
267253

268254
return {
269255
valid: isValid,

infrastructure/signature-validator/test-example.ts

Lines changed: 0 additions & 104 deletions
This file was deleted.

infrastructure/signature-validator/test-signature.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.

platforms/blabsy-w3ds-auth-api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"uuid": "^9.0.1",
2828
"graphql": "^16.8.1",
2929
"graphql-request": "^6.1.0",
30+
"signature-validator": "workspace:*",
3031
"web3-adapter": "workspace:*"
3132
},
3233
"devDependencies": {

0 commit comments

Comments
 (0)