Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/services/crypto.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class CryptoService {
const privateKeyInBase64 = user.keys?.ecc?.privateKey;
const privateKyberKeyInBase64 = user.keys?.kyber?.privateKey;

if (!privateKeyInBase64 || !privateKyberKeyInBase64) {
if (!privateKeyInBase64) {
return user.mnemonic;
}

Expand Down
22 changes: 19 additions & 3 deletions src/services/universal-link.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@ import { CLIUtils } from '../utils/cli.utils';
export class UniversalLinkService {
public static readonly instance: UniversalLinkService = new UniversalLinkService();

public getUserCredentials = async (userSession: { mnemonic: string; token: string }): Promise<LoginCredentials> => {
public getUserCredentials = async (userSession: {
mnemonic: string;
token: string;
privateKey: string;
}): Promise<LoginCredentials> => {
const clearMnemonic = Buffer.from(userSession.mnemonic, 'base64').toString('utf-8');
const clearToken = Buffer.from(userSession.token, 'base64').toString('utf-8');
const clearPrivateKey = Buffer.from(userSession.privateKey, 'base64').toString('utf-8');
const loginCredentials = await AuthService.instance.refreshUserToken(clearToken, clearMnemonic);
return {
user: {
...loginCredentials.user,
mnemonic: clearMnemonic,
keys: {
ecc: {
privateKey: clearPrivateKey,
publicKey: loginCredentials.user.keys.ecc.publicKey,
},
kyber: {
privateKey: loginCredentials.user.keys.kyber.privateKey,
publicKey: loginCredentials.user.keys.kyber.publicKey,
},
},
},
token: clearToken,
};
Expand Down Expand Up @@ -47,11 +62,12 @@ export class UniversalLinkService {
try {
const mnemonic = parsedUrl.searchParams.get('mnemonic');
const token = parsedUrl.searchParams.get('newToken');
if (!mnemonic || !token) {
const privateKey = parsedUrl.searchParams.get('privateKey');
if (!mnemonic || !token || !privateKey) {
throw new Error('Login has failed, please try again');
}

const loginCredentials = await this.getUserCredentials({ mnemonic, token });
const loginCredentials = await this.getUserCredentials({ mnemonic, token, privateKey });

res.writeHead(302, {
Location: `${driveUrl}/auth-link-ok`,
Expand Down