2025-11-17 22:21:49 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
|
|
|
<title>Input Form</title>
|
|
|
|
|
<style>
|
|
|
|
|
body {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column; /* Ensure vertical stacking */
|
|
|
|
|
align-items: center; /* Center horizontally */
|
|
|
|
|
padding-top: 50px;
|
|
|
|
|
min-height: 120vh;
|
|
|
|
|
margin: 0;
|
|
|
|
|
font-family: Arial, sans-serif;
|
|
|
|
|
background-color: Cornsilk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.form-container {
|
|
|
|
|
background-color: white;
|
|
|
|
|
padding: 30px;
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
|
|
|
width: 90%;
|
|
|
|
|
max-width: 800px;
|
|
|
|
|
min-height: 400px;
|
|
|
|
|
max-height: 1000px;
|
|
|
|
|
margin-bottom: 20px; /* Add space below the form container */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nav.directory {
|
|
|
|
|
width: 90%;
|
|
|
|
|
max-width: 800px;
|
|
|
|
|
margin: 0 auto; /* Center horizontally */
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nav.directory dt a {
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
color: #333;
|
|
|
|
|
padding: 0.5rem 1rem;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
width: auto; /* Prevent stretching */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.input-group {
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
label {
|
|
|
|
|
display: block;
|
|
|
|
|
margin-bottom: 5px;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
input[type="text"],
|
|
|
|
|
input[type="password"] {
|
|
|
|
|
width: 100%;
|
|
|
|
|
padding: 8px;
|
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textarea {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 120px;
|
|
|
|
|
padding: 8px;
|
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
resize: vertical;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.expandable-section {
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
}
|
|
|
|
|
.expandable-header {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
background-color: #f0f0f0;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
}
|
|
|
|
|
.expandable-content {
|
|
|
|
|
display: none;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
background-color: #f9f9f9;
|
|
|
|
|
border-radius: 0 0 4px 4px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
2025-11-18 02:22:05 +00:00
|
|
|
<script src="./routes/contact/pkg/message_tools.js"></script>
|
2025-11-17 22:21:49 +00:00
|
|
|
<script>
|
|
|
|
|
const { make_salt, make_key_bytes, box_message } = wasm_bindgen;
|
|
|
|
|
var serverPublicKey;
|
|
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
|
await wasm_bindgen();
|
|
|
|
|
await fetchPublicKey();
|
|
|
|
|
|
2025-11-18 16:41:58 +00:00
|
|
|
console.log(`Server pk: ${serverPublicKey}`);
|
2025-11-17 22:21:49 +00:00
|
|
|
|
|
|
|
|
const form = document.getElementById("message-form");
|
|
|
|
|
form.addEventListener("submit", (event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
submit();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
async function fetchPublicKey() {
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch("./api/pubkey");
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
|
|
}
|
2025-11-18 16:41:58 +00:00
|
|
|
|
2025-11-17 22:21:49 +00:00
|
|
|
const pubkeyJSON = await response.text();
|
2025-11-18 16:41:58 +00:00
|
|
|
serverPublicKey = JSON.parse(pubkeyJSON);
|
2025-11-17 22:21:49 +00:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error fetching public key:", error);
|
|
|
|
|
document.getElementById("status").textContent =
|
|
|
|
|
"Failed to load public key.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-18 16:41:58 +00:00
|
|
|
async function submit() {
|
2025-11-17 22:21:49 +00:00
|
|
|
console.log("begin");
|
|
|
|
|
const user = document.getElementById("name").value;
|
|
|
|
|
const password = document.getElementById("password").value;
|
|
|
|
|
const message = document.getElementById("message").value;
|
|
|
|
|
|
|
|
|
|
const salt = make_salt();
|
|
|
|
|
|
|
|
|
|
const makeKeyBytesArgs = {
|
|
|
|
|
name: String(user),
|
|
|
|
|
password: String(password),
|
|
|
|
|
salt: [...salt],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const keyBytes = make_key_bytes(JSON.stringify(makeKeyBytesArgs));
|
|
|
|
|
console.log(keyBytes);
|
|
|
|
|
|
|
|
|
|
const boxMessageArgs = {
|
|
|
|
|
user: String(user),
|
|
|
|
|
salt: [...salt],
|
|
|
|
|
user_sk: [...keyBytes],
|
|
|
|
|
remote_pk: [...serverPublicKey],
|
|
|
|
|
plaintext: String(message),
|
|
|
|
|
};
|
2025-11-18 16:41:58 +00:00
|
|
|
console.log("Boxed preflight: ", JSON.stringify(boxMessageArgs));
|
2025-11-17 22:21:49 +00:00
|
|
|
const boxed = box_message(JSON.stringify(boxMessageArgs));
|
2025-11-18 16:41:58 +00:00
|
|
|
const boxedObj = JSON.parse(boxed); // Parse the boxed string into a JavaScript object
|
|
|
|
|
console.log(boxedObj);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch("/api/publish", {
|
|
|
|
|
method: "POST", // Specify the method as POST
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json", // Set the Content-Type header for JSON payload
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(boxedObj), // Send the boxed object as a JSON string in the body
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
// Handle HTTP errors (status codes outside the 2xx range)
|
|
|
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await response.json(); // Parse the response body as JSON
|
|
|
|
|
console.log("Success:", result);
|
|
|
|
|
alert("Sent!");
|
|
|
|
|
location.reload();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error:", error);
|
|
|
|
|
alert("Failed to send message: " + error.message);
|
|
|
|
|
}
|
2025-11-17 22:21:49 +00:00
|
|
|
|
|
|
|
|
console.log("End");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
run();
|
|
|
|
|
</script>
|
|
|
|
|
<script>
|
|
|
|
|
function toggleSection() {
|
|
|
|
|
const content = document.getElementById("expandableContent");
|
|
|
|
|
const header = document.querySelector(".expandable-header");
|
|
|
|
|
if (content.style.display === "block") {
|
|
|
|
|
content.style.display = "none";
|
|
|
|
|
header.innerHTML = "How to use ▼";
|
|
|
|
|
} else {
|
|
|
|
|
content.style.display = "block";
|
|
|
|
|
header.innerHTML = "How to use ▲";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div class="form-container">
|
|
|
|
|
<form id="message-form">
|
|
|
|
|
<div class="input-group">
|
|
|
|
|
<label for="name">Name</label>
|
|
|
|
|
<input type="text" id="name" name="name" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="input-group">
|
|
|
|
|
<label for="password">Password (optional)</label>
|
|
|
|
|
<input type="password" id="password" name="password" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="input-group">
|
|
|
|
|
<label for="message">Message</label>
|
|
|
|
|
<textarea id="message" name="message"></textarea>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="input-group">
|
|
|
|
|
<button
|
|
|
|
|
type="submit"
|
|
|
|
|
style="
|
|
|
|
|
width: 100%;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
background-color: #dbdbdb;
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
"
|
|
|
|
|
>
|
|
|
|
|
Submit
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<div class="expandable-section">
|
|
|
|
|
<div class="expandable-header" onclick="toggleSection()">
|
|
|
|
|
How to use ▼
|
|
|
|
|
</div>
|
|
|
|
|
<div class="expandable-content" id="expandableContent">
|
|
|
|
|
<p>
|
|
|
|
|
Tell me who you are, and add an optional password. If I do not
|
|
|
|
|
otherwise have your contact information, please tell me the best way
|
|
|
|
|
to reach you back.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<nav class="directory">
|
|
|
|
|
<dt><a href="/">back to home</a></dt>
|
|
|
|
|
</nav>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|