Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Authentication Credentials Initialization #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/database/helper/authHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@ const { randomBytes } = require('crypto');

/**
* Initialize authentication credentials.
* @param {Object} options - Optional parameters to customize the credentials.
* @returns {Object} - Initialized authentication credentials.
*/
const initAuthCreds = () => {
const identityKey = Curve.generateKeyPair();
return {
noiseKey: Curve.generateKeyPair(),
signedIdentityKey: identityKey,
signedPreKey: signedKeyPair(identityKey, 1),
registrationId: generateRegistrationId(),
advSecretKey: randomBytes(32).toString('base64'),
processedHistoryMessages: [],
nextPreKeyId: 1,
firstUnuploadedPreKeyId: 1,
accountSettings: {
unarchiveChats: false,
},
};
const initAuthCreds = (options = {}) => {
try {
const identityKey = Curve.generateKeyPair();
return {
noiseKey: Curve.generateKeyPair(),
signedIdentityKey: identityKey,
signedPreKey: signedKeyPair(identityKey, 1),
registrationId: options.registrationId || generateRegistrationId(),
advSecretKey: options.advSecretKey || randomBytes(32).toString('base64'),
processedHistoryMessages: [],
nextPreKeyId: options.nextPreKeyId || 1,
firstUnuploadedPreKeyId: options.firstUnuploadedPreKeyId || 1,
accountSettings: {
unarchiveChats: options.unarchiveChats || false,
},
};
} catch (error) {
console.error('Error initializing authentication credentials:', error);
throw error;
}
};

module.exports = { initAuthCreds };