2025-02-12 16:16:27 +01:00
|
|
|
async function acceptInvite() {
|
2025-02-13 00:02:40 +01:00
|
|
|
|
|
|
|
|
// check if there is nostr extension
|
|
|
|
|
if (!window.nostr) {
|
|
|
|
|
console.log("No Nostr extension found.");
|
|
|
|
|
return { success: false, error: "No Nostr extension detected." };
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 19:55:44 +01:00
|
|
|
|
2025-02-12 16:16:27 +01:00
|
|
|
try {
|
2025-02-13 00:02:40 +01:00
|
|
|
const challengeResponse = await fetch("/api/signup/nostr-challenge");
|
|
|
|
|
if (!challengeResponse.ok) throw new Error("Failed to fetch challenge");
|
|
|
|
|
const { challenge } = await challengeResponse.json();
|
|
|
|
|
|
|
|
|
|
const pubkey = await window.nostr.getPublicKey();
|
|
|
|
|
|
|
|
|
|
const event = {
|
|
|
|
|
kind: 22242,
|
|
|
|
|
created_at: Math.floor(Date.now() / 1000),
|
|
|
|
|
tags: [["challenge", challenge]],
|
|
|
|
|
content: "Sign this challenge to authenticate",
|
|
|
|
|
pubkey: pubkey
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const signedEvent = await window.nostr.signEvent(event);
|
|
|
|
|
|
|
|
|
|
const verifyResponse = await fetch("/api/signup/nostr-verify", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
body: JSON.stringify(signedEvent),
|
2025-02-12 16:16:27 +01:00
|
|
|
});
|
2025-02-09 19:55:44 +01:00
|
|
|
|
2025-02-13 00:02:40 +01:00
|
|
|
if (verifyResponse.status === 200) {
|
|
|
|
|
|
2025-02-09 19:55:44 +01:00
|
|
|
}
|
2025-02-13 00:02:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) { }
|
2025-02-09 19:55:44 +01:00
|
|
|
}
|