-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
71 lines (59 loc) · 2.74 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wasm Test</title>
</head>
<body>
<h1>Testing Rust + Wasm</h1>
<label for="proofFile">Select Proof File:</label>
<input type="file" id="proofFile" accept=".bin,.dat" /><br/><br/>
<label for="verifierFile">Select Verifier File:</label>
<input type="file" id="verifierFile" accept=".bin,.dat" /><br/><br/>
<button id="verifyButton">Verify Proof</button>
<p id="status"></p>
<script type="module">
import init, { verify_proof } from './pkg/fibonacci_nostd.js';
// Ensure the script runs after the content is fully loaded
document.addEventListener("DOMContentLoaded", () => {
// Initialize the WASM module
init().then(() => {
console.log("WASM module initialized");
// Add click event listener to the button
document.getElementById("verifyButton").addEventListener("click", async () => {
const statusElem = document.getElementById('status');
// Select the file input elements
const proofFileInput = document.getElementById('proofFile');
const verifierFileInput = document.getElementById('verifierFile');
// Check if both files are selected
if (!proofFileInput.files[0] || !verifierFileInput.files[0]) {
statusElem.textContent = "Please select both proof and verifier files.";
return;
}
// Helper function to read a file as ArrayBuffer
const readFileAsBytes = (file) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(new Uint8Array(reader.result));
reader.onerror = () => reject(reader.error);
reader.readAsArrayBuffer(file);
});
};
try {
// Read both files as byte arrays
const proofBytes = await readFileAsBytes(proofFileInput.files[0]);
const verifierBytes = await readFileAsBytes(verifierFileInput.files[0]);
// Call the WASM function to verify the proof
await verify_proof(proofBytes, verifierBytes);
statusElem.textContent = "Proof verified successfully!";
} catch (error) {
console.error("Verification failed:", error);
statusElem.textContent = "Verification failed: " + error.message;
}
});
}).catch(console.error);
});
</script>
</body>
</html>