merge services
This commit is contained in:
parent
2b6853bf11
commit
ea91107347
4 changed files with 37 additions and 43 deletions
|
|
@ -3,7 +3,6 @@ const { getPublicKey, verifyEvent } = require("nostr-tools");
|
|||
const crypto = require("crypto");
|
||||
|
||||
const invitesService = require('../services/invitesService');
|
||||
const PublicKeySignedUpService = require('../services/PublicKeySignedUpService');
|
||||
const sessionService = require('../services/sessionService');
|
||||
const nostrService = require('../services/nostrService');
|
||||
|
||||
|
|
@ -41,7 +40,7 @@ router.post('/sign-public-key-up', async (req, res) => {
|
|||
const inviteUuid = req.cookies.inviteUuid;
|
||||
const publicKey = req.body.publicKey;
|
||||
|
||||
if (await !invitesService.appInviteExists(inviteUuid)) {
|
||||
if (await (!invitesService.appInviteExists(inviteUuid))) {
|
||||
return res.status(404).render('error', { message: 'Invite not found' });
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +48,7 @@ router.post('/sign-public-key-up', async (req, res) => {
|
|||
return res.status(410).json({ error: 'Invite has already been used.' });
|
||||
}
|
||||
|
||||
await PublicKeySignedUpService.signUpPublicKey(
|
||||
await invitesService.signUpPublicKey(
|
||||
inviteUuid,
|
||||
publicKey
|
||||
);
|
||||
|
|
@ -92,7 +91,7 @@ router.post("/nostr-verify", async (req, res) => {
|
|||
return res.status(400).json({ success: false, error: "Invalid signature" });
|
||||
}
|
||||
|
||||
if (!PublicKeySignedUpService.isPublicKeyInvited(signedEvent.pubkey)) {
|
||||
if (!invitesService.isPublicKeyInvited(signedEvent.pubkey)) {
|
||||
return res.status(400).json(
|
||||
{
|
||||
success: false,
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
const uuid = require("uuid");
|
||||
|
||||
const PublicKeySignedUp = require('../models/PublicKeySignedUp');
|
||||
|
||||
const invitesService = require('./invitesService');
|
||||
|
||||
async function signUpPublicKey(inviteUuid, publicKey) {
|
||||
|
||||
if (await invitesService.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;
|
||||
}
|
||||
|
||||
exports.signUpPublicKey = signUpPublicKey;
|
||||
exports.isPublicKeySignedUp = isPublicKeySignedUp;
|
||||
|
|
@ -38,8 +38,36 @@ async function createAppInvite(inviterNpub) {
|
|||
);
|
||||
}
|
||||
|
||||
async function signUpPublicKey(inviteUuid, publicKey) {
|
||||
|
||||
exports.appInviteExists = appInviteExists;
|
||||
exports.getAppInvite = getAppInvite;
|
||||
exports.isAppInviteSpent = isAppInviteSpent;
|
||||
exports.createAppInvite = createAppInvite;
|
||||
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,
|
||||
signUpPublicKey,
|
||||
isPublicKeySignedUp
|
||||
};
|
||||
|
|
@ -3,7 +3,7 @@ const uuid = require("uuid");
|
|||
const SessionCreated = require('../models/SessionCreated');
|
||||
const SessionNpubbed = require('../models/SessionNpubbed');
|
||||
|
||||
const PublicKeySignedUpService = require('./PublicKeySignedUpService');
|
||||
const invitesService = require('./invitesService');
|
||||
|
||||
const constants = require('../constants');
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ async function isSessionAuthorized(sessionUuid) {
|
|||
|
||||
const npub = await getNpubRelatedToSession(sessionUuid);
|
||||
|
||||
if (await PublicKeySignedUpService.isPublicKeySignedUp(npub)) {
|
||||
if (await invitesService.isPublicKeySignedUp(npub)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue