diff --git a/package.json b/package.json index 7e0c2849..e0cce7b2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@internxt/sdk", "author": "Internxt ", - "version": "1.20.2", + "version": "1.21.0", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git", diff --git a/src/auth/index.ts b/src/auth/index.ts index 1a9c7c7b..c5618c6d 100644 --- a/src/auth/index.ts +++ b/src/auth/index.ts @@ -230,6 +230,34 @@ export class Auth { ); } + /** + * Tries to log in a user with Argon2 + * @param email - The user email address + * @param passwordHash - The argon2id hash of the user's password + * @param tfaCode - The 2 factor authentication code (if 2FA is enabled) + */ + public loginArgon2( + email: string, + passwordHash: string, + tfaCode?: string, + ): Promise<{ + token: Token; + user: UserSettings; + }> { + return this.client.post<{ + token: Token; + user: UserSettings; + }>( + '/auth/v2/login/access', + { + email, + passwordHash, + tfa: tfaCode, + }, + this.basicHeaders(), + ); + } + /** * Tries to log in a user given its cli login details * @param details @@ -330,6 +358,7 @@ export class Auth { .post<{ sKey: string; tfa: boolean | null; + saltArgon2: string; }>( '/auth/login', { @@ -341,6 +370,7 @@ export class Auth { return { encryptedSalt: data.sKey, tfaEnabled: data.tfa === true, + saltArgon2: data.saltArgon2, }; }); } diff --git a/src/auth/types.ts b/src/auth/types.ts index 3a3ea8fe..ad2bb8e2 100644 --- a/src/auth/types.ts +++ b/src/auth/types.ts @@ -65,6 +65,7 @@ export class UserAccessError extends Error {} export interface SecurityDetails { encryptedSalt: string; tfaEnabled: boolean; + saltArgon2: string; } export interface TwoFactorAuthQR { diff --git a/src/drive/users/index.ts b/src/drive/users/index.ts index 7d31bcd7..6bd2ea7d 100644 --- a/src/drive/users/index.ts +++ b/src/drive/users/index.ts @@ -17,6 +17,7 @@ import { UserPublicKeyResponse, UserPublicKeyWithCreationResponse, VerifyEmailChangeResponse, + ChangePasswordArgon2Payload, } from './types'; export * as UserTypes from './types'; @@ -159,6 +160,27 @@ export class Users { ); } + /** + * Updates the authentication credentials with argon2 and invalidates previous tokens + * @param payload + * + * @returns {Promise} A promise that returns new tokens for this user. + */ + public changePasswordArgon2(payload: ChangePasswordArgon2Payload): Promise { + return this.client.patch( + '/users/v2/password', + { + currentPasswordHash: payload.currentPasswordHash, + newPasswordHash: payload.newPasswordHash, + newSalt: payload.newSalt, + encryptedMnemonic: payload.encryptedMnemonic, + encryptedPrivateKey: payload.keys.encryptedPrivateKey, + encryptedPrivateKyberKey: payload.keys.encryptedPrivateKyberKey, + }, + this.headers(), + ); + } + /** * Pre registers an email * @param email diff --git a/src/drive/users/types.ts b/src/drive/users/types.ts index 6921fec5..5828ee2f 100644 --- a/src/drive/users/types.ts +++ b/src/drive/users/types.ts @@ -25,6 +25,17 @@ export interface ChangePasswordPayload { encryptedPrivateKey: string; } +export interface ChangePasswordArgon2Payload { + currentPasswordHash: string; + newPasswordHash: string; + newSalt: string; + encryptedMnemonic: string; + keys: { + encryptedPrivateKey: string; + encryptedPrivateKyberKey: string; + }; +} + export interface ChangePasswordPayloadNew { currentEncryptedPassword: string; newEncryptedPassword: string;