|
16 | 16 | requestPermissions,
|
17 | 17 | scan,
|
18 | 18 | } from "@tauri-apps/plugin-barcode-scanner";
|
| 19 | + import { |
| 20 | + exists, |
| 21 | + generate, |
| 22 | + getPublicKey, |
| 23 | + signPayload, |
| 24 | + // verifySignature |
| 25 | + } from "@auvo/tauri-plugin-crypto-hw-api"; |
19 | 26 | import axios from "axios";
|
20 | 27 | import { getContext, onDestroy, onMount } from "svelte";
|
21 | 28 | import type { SVGAttributes } from "svelte/elements";
|
|
401 | 408 | });
|
402 | 409 | }
|
403 | 410 |
|
404 |
| - // In a real implementation, you would use the vault's signing capabilities |
405 |
| - // For now, we'll simulate the signing process |
406 |
| - await new Promise((resolve) => setTimeout(resolve, 2000)); // Simulate signing delay |
| 411 | + // 🔐 REAL CRYPTOGRAPHIC SIGNING using Tauri crypto plugin |
| 412 | + console.log("🔐 Starting cryptographic signing process..."); |
| 413 | +
|
| 414 | + // Check if crypto hardware exists |
| 415 | + const cryptoExists = await exists("default"); |
| 416 | + if (!cryptoExists) { |
| 417 | + throw new Error("Cryptographic hardware not available"); |
| 418 | + } |
| 419 | +
|
| 420 | + // Generate default key if it doesn't exist |
| 421 | + try { |
| 422 | + await generate("default"); |
| 423 | + console.log("✅ Default key generated/verified"); |
| 424 | + } catch (error) { |
| 425 | + console.log( |
| 426 | + "Default key already exists or generation failed:", |
| 427 | + error, |
| 428 | + ); |
| 429 | + } |
| 430 | +
|
| 431 | + // Get the public key |
| 432 | + const publicKey = await getPublicKey("default"); |
| 433 | + console.log("🔑 Public key retrieved:", publicKey); |
| 434 | +
|
| 435 | + // Sign the message payload |
| 436 | + console.log("✍️ Signing message:", messageToSign); |
| 437 | + const signature = await signPayload("default", messageToSign); |
| 438 | + console.log("✅ Message signed successfully"); |
407 | 439 |
|
408 |
| - // Create the signed payload |
| 440 | + // Create the signed payload with real signature |
409 | 441 | const signedPayload = {
|
410 | 442 | sessionId: signingSessionId,
|
411 |
| - signature: "simulated_signature_" + Date.now(), // In real implementation, this would be the actual signature |
412 |
| - publicKey: vault?.ename || "unknown_public_key", // Use eName as public key for now |
| 443 | + signature: signature, |
| 444 | + publicKey: vault?.ename || "unknown_public_key", // Use eName as public key |
413 | 445 | message: messageToSign,
|
414 | 446 | };
|
415 | 447 |
|
|
560 | 592 | throw new Error("No vault available for blind voting");
|
561 | 593 | }
|
562 | 594 |
|
| 595 | + // 🔐 Get the real public key for voter identification |
| 596 | + let voterPublicKey: string; |
| 597 | + try { |
| 598 | + const cryptoExists = await exists("default"); |
| 599 | + if (!cryptoExists) { |
| 600 | + throw new Error("Cryptographic hardware not available"); |
| 601 | + } |
| 602 | +
|
| 603 | + // Generate default key if it doesn't exist |
| 604 | + try { |
| 605 | + await generate("default"); |
| 606 | + console.log( |
| 607 | + "✅ Default key generated/verified for blind voting", |
| 608 | + ); |
| 609 | + } catch (edit) { |
| 610 | + console.log( |
| 611 | + "Default key already exists or generation failed:", |
| 612 | + edit, |
| 613 | + ); |
| 614 | + } |
| 615 | +
|
| 616 | + // Get the public key |
| 617 | + voterPublicKey = await getPublicKey("default"); |
| 618 | + console.log("🔑 Voter public key retrieved:", voterPublicKey); |
| 619 | + } catch (error) { |
| 620 | + console.error("Failed to get cryptographic public key:", error); |
| 621 | + // Fallback to ename if crypto fails |
| 622 | + voterPublicKey = vault.ename || "unknown_public_key"; |
| 623 | + } |
| 624 | +
|
563 | 625 | // Dynamically import the blindvote library
|
564 | 626 | const { VotingSystem } = await import("blindvote");
|
565 | 627 |
|
|
0 commit comments