storing contact details works
This commit is contained in:
parent
00fc6bb258
commit
6b52d06b3e
10 changed files with 138 additions and 15 deletions
|
|
@ -51,23 +51,19 @@ async function verifyNostrChallenge(signedEvent) {
|
|||
const challengeTag = signedEvent.tags.find(tag => tag[0] === "challenge");
|
||||
const challenge = challengeTag[1];
|
||||
|
||||
console.log("Checking if fresh")
|
||||
if (!(await isNostrChallengeFresh(challenge))) {
|
||||
throw TimeoutError("Challenge expired, request new one.");
|
||||
}
|
||||
|
||||
console.log("Checking if completed")
|
||||
if (await hasNostrChallengeBeenCompleted(challenge)) {
|
||||
throw new errors.AlreadyUsedError("Challenge already used, request new one.");
|
||||
}
|
||||
|
||||
console.log("Checking if valid")
|
||||
const isSignatureValid = verifyEvent(signedEvent);
|
||||
if (!isSignatureValid) {
|
||||
throw new errors.InvalidSignatureError("Signature is not valid.");
|
||||
}
|
||||
|
||||
console.log("Persisting")
|
||||
return await NostrChallengeCompleted.create({
|
||||
'uuid': uuid.v7(),
|
||||
challenge: challenge,
|
||||
|
|
|
|||
17
src/services/profileService.js
Normal file
17
src/services/profileService.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
const uuid = require('uuid');
|
||||
const ContactDetailsSet = require('../models/ContactDetailsSet');
|
||||
|
||||
async function setContactDetails(publicKey, encryptedContactDetails) {
|
||||
return ContactDetailsSet.create(
|
||||
{
|
||||
'uuid': uuid.v7(),
|
||||
public_key: publicKey,
|
||||
encrypted_contact_details: encryptedContactDetails,
|
||||
created_at: new Date().toISOString()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setContactDetails
|
||||
};
|
||||
|
|
@ -4,7 +4,6 @@ const SessionCreated = require('../models/SessionCreated');
|
|||
const SessionRelatedToPublickey = require('../models/SessionRelatedToPublickey');
|
||||
|
||||
const invitesService = require('./invitesService');
|
||||
|
||||
const constants = require('../constants');
|
||||
|
||||
async function createSession(sessionUuid) {
|
||||
|
|
@ -71,9 +70,23 @@ async function isSessionAuthorized(sessionUuid) {
|
|||
return false;
|
||||
}
|
||||
|
||||
async function getPublicKeyRelatedToSession(sessionUuid) {
|
||||
const sessionRelatedToPublickey = await SessionRelatedToPublickey.findOne(
|
||||
{
|
||||
where: {
|
||||
session_uuid: sessionUuid
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return sessionRelatedToPublickey.public_key;
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createSession,
|
||||
isSessionValid,
|
||||
relateSessionToPublicKey,
|
||||
isSessionAuthorized
|
||||
isSessionAuthorized,
|
||||
getPublicKeyRelatedToSession
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue