2025-02-13 00:28:09 +01:00
|
|
|
window.onload = function () {
|
2025-02-14 11:13:18 +01:00
|
|
|
if (!window.nostr) {
|
|
|
|
|
console.log('Nostr extension not present');
|
2025-02-19 14:46:03 +01:00
|
|
|
document.querySelector('#nostr-signup-button').disabled = true;
|
2025-02-14 11:13:18 +01:00
|
|
|
document.querySelector('#no-extension-nudges').style.display = 'block';
|
|
|
|
|
} else {
|
|
|
|
|
console.log('Nostr extension present');
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-02-13 00:28:09 +01:00
|
|
|
|
2025-02-27 18:38:42 +01:00
|
|
|
const signUpConfirmation = document.querySelector('#sign-up-success');
|
|
|
|
|
|
|
|
|
|
function showConfirmationAndRedirect() {
|
|
|
|
|
signUpConfirmation.classList.add('revealed');
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
window.location.href = '/createProfile';
|
|
|
|
|
}, 5000);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-12 16:16:27 +01:00
|
|
|
async function acceptInvite() {
|
2025-02-14 11:13:18 +01:00
|
|
|
let challengeResponse;
|
|
|
|
|
try {
|
|
|
|
|
challengeResponse = await fetch('/api/signup/nostr-challenge', {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(`Something went wrong: ${error}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-02-13 00:02:40 +01:00
|
|
|
|
2025-02-14 11:13:18 +01:00
|
|
|
const { challenge } = await challengeResponse.json();
|
2025-02-13 00:02:40 +01:00
|
|
|
|
2025-02-14 11:13:18 +01:00
|
|
|
let pubkey;
|
|
|
|
|
try {
|
|
|
|
|
pubkey = await window.nostr.getPublicKey();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const event = {
|
|
|
|
|
kind: 22242,
|
|
|
|
|
created_at: Math.floor(Date.now() / 1000),
|
|
|
|
|
tags: [['challenge', challenge]],
|
|
|
|
|
content: 'Sign this challenge to authenticate',
|
|
|
|
|
pubkey: pubkey,
|
|
|
|
|
};
|
2025-02-13 01:17:49 +01:00
|
|
|
|
2025-02-14 11:13:18 +01:00
|
|
|
let signedEvent;
|
|
|
|
|
try {
|
|
|
|
|
signedEvent = await window.nostr.signEvent(event);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-02-13 00:02:40 +01:00
|
|
|
|
2025-02-14 11:13:18 +01:00
|
|
|
let verifyResponse;
|
|
|
|
|
try {
|
|
|
|
|
verifyResponse = await fetch('/api/signup/nostr-verify', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify(signedEvent),
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(`Something went wrong: ${error}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-02-13 00:02:40 +01:00
|
|
|
|
2025-02-14 11:13:18 +01:00
|
|
|
if (verifyResponse.ok) {
|
2025-02-27 18:38:42 +01:00
|
|
|
showConfirmationAndRedirect();
|
2025-02-14 11:13:18 +01:00
|
|
|
}
|
|
|
|
|
}
|