remove old stuff

This commit is contained in:
counterweight 2025-02-13 00:05:35 +01:00
parent fb9832fabb
commit d4f01ea843
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
4 changed files with 2 additions and 198 deletions

View file

@ -28,59 +28,4 @@ async function login() {
});
} catch (error) { }
/*
if (!verifyResponse.ok) throw new Error("Verification failed");
const verifyResult = await verifyResponse.json();
if (verifyResult.success) {
console.log("Authentication successful!");
return { success: true, pubkey };
} else {
throw new Error("Invalid signature");
}
} catch (error) {
console.error("Error during Nostr authentication:", error.message);
return { success: false, error: error.message };
} */
}
/*
window.onload = function () {
setTimeout(function () {
console.log("This code runs 2 seconds after the window has loaded.");
const npub = window.nostr.getPublicKey();
let pubkeyP = document.querySelector("#pubkey-p");
let pubkeySpan = document.querySelector("#pubkey-span");
npub.then(async function (npub) {
console.log(npub);
pubkeyP.style.display = "block";
pubkeySpan.innerText = npub;
try {
const response = await fetch('/api/session-npubbed', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"npub": npub
})
});
if (response.ok) {
const data = await response.json();
console.log('SessionNpubbed record created successfully:', data);
} else {
const error = await response.json();
console.error('Failed to create sessionNpubbed record:', error);
}
} catch (error) {
console.error('An error occurred:', error);
}
}
)
}, 2000);
} */

View file

@ -3,7 +3,6 @@ const { getPublicKey, verifyEvent } = require("nostr-tools");
const crypto = require("crypto");
const invitesService = require('../services/invitesService');
const sessionService = require('../services/sessionService');
const nostrService = require('../services/nostrService');
const { error } = require('console');
const { TimeoutError } = require('sequelize');
@ -11,56 +10,6 @@ const errors = require('../errors');
const router = express.Router();
router.post('/session-npubbed', async (req, res) => {
const sessionUuid = req.cookies.sessionUuid;
const npub = req.body.npub;
if (!sessionUuid || !npub) {
return res.status(400).json({ error: 'Missing session_uuid or npub' });
}
try {
if (await sessionService.isSessionAlreadyRelatedToNpub(sessionUuid, npub)) {
return res.json({ message: 'SessionNpubbed record already exists' });
}
console.log("No matching record found. Creating a new one...");
await sessionService.relateSessionToNpub(
sessionUuid,
npub
);
return res.json({ message: 'SessionNpubbed record created successfully' });
} catch (error) {
console.error("Error handling SessionNpubbed record:", error);
return res.status(500).json({ error: 'Failed to process sessionNpubbed record' });
}
});
router.post('/sign-public-key-up', async (req, res) => {
const inviteUuid = req.cookies.inviteUuid;
const publicKey = req.body.publicKey;
if (await (!invitesService.appInviteExists(inviteUuid))) {
return res.status(404).render('error', { message: 'Invite not found' });
}
if (await invitesService.isAppInviteSpent(inviteUuid)) {
return res.status(410).json({ error: 'Invite has already been used.' });
}
await invitesService.signUpPublicKey(
inviteUuid,
publicKey
);
return res.json({ message: "Invited public key successfully." })
});
router.get('/signup/nostr-challenge', async (req, res) => {
const inviteUuid = req.cookies.inviteUuid;

View file

@ -2,7 +2,6 @@ const uuid = require('uuid');
const nostrService = require('./nostrService');
const AppInviteCreated = require('../models/AppInviteCreated');
const PublicKeySignedUp = require('../models/PublicKeySignedUp');
const SignUpChallengeCreated = require('../models/SignUpChallengeCreated');
const SignUpChallengeCompleted = require('../models/SignUpChallengeCompleted');
@ -67,16 +66,6 @@ async function createSignUpChallenge(appInviteUuid) {
)
}
async function hasSignUpChallengeBeenCompleted(nostrChallengeCompletedUuid) {
const signUpChallengeCompleted = await SignUpChallengeCompleted.findOne(
{
where:
{
}
}
)
}
async function verifySignUpChallenge(signedEvent) {
@ -119,38 +108,11 @@ async function verifySignUpChallenge(signedEvent) {
return completedSignUpChallenge;
}
async function signUpPublicKey(inviteUuid, publicKey) {
if (await isAppInviteSpent(inviteUuid)) {
throw new Error("Can't invite npub, invite is already spent.");
}
await PublicKeySignedUp.create({
uuid: uuid.v7(),
app_invite_uuid: inviteUuid,
public_key: publicKey,
created_at: new Date().toISOString()
});
}
async function isPublicKeySignedUp(publicKey) {
if (await PublicKeySignedUp.findOne({
where: { public_key: publicKey }
})) {
return true;
}
return false;
}
module.exports = {
appInviteExists,
getAppInvite,
isAppInviteSpent,
createAppInvite,
createSignUpChallenge,
verifySignUpChallenge,
signUpPublicKey,
isPublicKeySignedUp
verifySignUpChallenge
};

View file

@ -1,9 +1,6 @@
const uuid = require("uuid");
const SessionCreated = require('../models/SessionCreated');
const SessionNpubbed = require('../models/SessionNpubbed');
const invitesService = require('./invitesService');
const constants = require('../constants');
@ -37,54 +34,5 @@ async function isSessionExpired(sessionUuid) {
return false;
}
async function relateSessionToNpub(sessionUuid, npub) {
await SessionNpubbed.create({
session_npubbed_uuid: uuid.v7(),
session_uuid: sessionUuid,
npub,
created_at: new Date().toISOString()
});
}
async function isSessionAlreadyRelatedToNpub(sessionUuid, npub) {
if (await SessionNpubbed.findOne({ where: { 'session_uuid': sessionUuid, npub } })) {
return true;
}
return false;
}
async function getNpubRelatedToSession(sessionUuid) {
const mostRecentSession = await SessionNpubbed.findOne({
where: { 'session_uuid': sessionUuid },
order: [['created_at', 'DESC']]
});
if (!mostRecentSession) {
return null;
}
return mostRecentSession.npub;
}
async function isSessionAuthorized(sessionUuid) {
if (await isSessionExpired(sessionUuid)) {
return false;
}
const npub = await getNpubRelatedToSession(sessionUuid);
if (await invitesService.isPublicKeySignedUp(npub)) {
return true;
}
return false;
}
exports.createSession = createSession;
exports.isSessionExpired = isSessionExpired;
exports.relateSessionToNpub = relateSessionToNpub;
exports.isSessionAlreadyRelatedToNpub = isSessionAlreadyRelatedToNpub;
exports.isSessionAuthorized = isSessionAuthorized;