"use client"; import { toBase58 } from "util/base58"; import { useState, Fragment } from "react"; import { Cog6ToothIcon, ClipboardDocumentIcon, ClipboardDocumentCheckIcon } from "@heroicons/react/24/outline"; import { Title } from "@components/title"; import { encrypt } from "pkg/encryption"; import { ErrorMessage } from "@components/error"; import { encodeCompositeKey } from "pkg/encoding"; import { LATEST_KEY_VERSION } from "pkg/constants"; export default function Home() { const [text, setText] = useState(""); const [reads, setReads] = useState(999); const [ttl, setTtl] = useState(7); const [ttlMultiplier, setTtlMultiplier] = useState(60 * 60 * 24); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [copied, setCopied] = useState(false); const [link, setLink] = useState(""); const onSubmit = async () => { try { setError(""); setLink(""); setLoading(true); const { encrypted, iv, key } = await encrypt(text); const { id } = (await fetch("/api/v1/store", { method: "POST", body: JSON.stringify({ ttl: ttl * ttlMultiplier, reads, encrypted: toBase58(encrypted), iv: toBase58(iv), }), }).then((r) => r.json())) as { id: string }; const compositeKey = encodeCompositeKey(LATEST_KEY_VERSION, id, key); const url = new URL(window.location.href); url.pathname = "/unseal"; url.hash = compositeKey; setCopied(false); setLink(url.toString()); } catch (e) { console.error(e); setError((e as Error).message); } finally { setLoading(false); } }; return (
{link}