zachery.lol/crates/message-tools/index.html
Aaron Global 6f49740c39 init
2025-11-17 17:21:49 -05:00

227 lines
6.1 KiB
HTML

<!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>
<script src="pkg/message_box.js"></script>
<script>
const { make_salt, make_key_bytes, box_message } = wasm_bindgen;
var serverPublicKey;
async function run() {
await wasm_bindgen();
await fetchPublicKey();
console.log(`Server pk: ${serverPublicKey}`)
const form = document.getElementById("message-form");
form.addEventListener("submit", (event) => {
event.preventDefault();
submit();
});
}
async function fetchPublicKey() {
try {
const response = await fetch("http://127.0.0.1:3001/pubkey");
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const pubkeyJSON = await response.text();
serverPublicKey = JSON.parse(pubkeyJSON)
} catch (error) {
console.error("Error fetching public key:", error);
document.getElementById("status").textContent =
"Failed to load public key.";
}
}
function submit() {
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),
};
console.log("Boxed preflight: ", JSON.stringify(boxMessageArgs))
const boxed = box_message(JSON.stringify(boxMessageArgs));
console.log(JSON.parse(boxed));
console.log("End");
alert("Sent!");
location.reload();
}
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>