Skip to content
Open
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 package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <hello@internxt.com>",
"version": "1.20.2",
"version": "1.21.0",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
30 changes: 30 additions & 0 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -330,6 +358,7 @@ export class Auth {
.post<{
sKey: string;
tfa: boolean | null;
saltArgon2: string;
}>(
'/auth/login',
{
Expand All @@ -341,6 +370,7 @@ export class Auth {
return {
encryptedSalt: data.sKey,
tfaEnabled: data.tfa === true,
saltArgon2: data.saltArgon2,
};
});
}
Expand Down
1 change: 1 addition & 0 deletions src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class UserAccessError extends Error {}
export interface SecurityDetails {
encryptedSalt: string;
tfaEnabled: boolean;
saltArgon2: string;
}

export interface TwoFactorAuthQR {
Expand Down
22 changes: 22 additions & 0 deletions src/drive/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
UserPublicKeyResponse,
UserPublicKeyWithCreationResponse,
VerifyEmailChangeResponse,
ChangePasswordArgon2Payload,
} from './types';

export * as UserTypes from './types';
Expand Down Expand Up @@ -159,6 +160,27 @@ export class Users {
);
}

/**
* Updates the authentication credentials with argon2 and invalidates previous tokens
* @param payload
*
* @returns {Promise<string>} A promise that returns new tokens for this user.
*/
public changePasswordArgon2(payload: ChangePasswordArgon2Payload): Promise<string> {
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
Expand Down
11 changes: 11 additions & 0 deletions src/drive/users/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading