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 package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <[email protected]>",
"version": "1.9.3",
"version": "1.9.4",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
37 changes: 19 additions & 18 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Auth {
kyber: {
publicKey: registerDetails.keys.kyber.publicKey,
privateKeyEncrypted: registerDetails.keys.kyber.privateKeyEncrypted,
}
},
},
referral: registerDetails.referral,
referrer: registerDetails.referrer,
Expand Down Expand Up @@ -102,7 +102,7 @@ export class Auth {
ecc: {
publicKey: registerDetails.keys.ecc.publicKey,
privateKeyEncrypted: registerDetails.keys.ecc.privateKeyEncrypted,
},
},
kyber: {
publicKey: registerDetails.keys.kyber.publicKey,
privateKeyEncrypted: registerDetails.keys.kyber.privateKeyEncrypted,
Expand Down Expand Up @@ -187,7 +187,7 @@ export class Auth {
kyber: {
publicKey: keys.kyber.publicKey,
privateKeyEncrypted: keys.kyber.privateKeyEncrypted,
}
},
},
},
this.basicHeaders(),
Expand Down Expand Up @@ -222,7 +222,7 @@ export class Auth {
kyber: {
publicKey: keys.kyber.publicKey,
privateKeyEncrypted: keys.kyber.privateKeyEncrypted,
}
},
},
this.headersWithToken(token),
);
Expand Down Expand Up @@ -321,24 +321,25 @@ export class Auth {
}

/**
* Checks if the password is correct for this email
* @param email
* Check credentials
* @param hashedPassword
* @returns
*/

public areCredentialsCorrect(email: string, hashedPassword: string): Promise<boolean> {
// Uses fetch instead of httpClient since a 401 response
// would log out the user
return fetch(`${this.apiUrl}/are-credentials-correct?email=${email}&hashedPassword=${hashedPassword}`, {
headers: this.headersWithToken(this.apiSecurity?.token as string),
}).then((res) => {
if (res.ok) {
return true;
} else if (res.status === 401) {
return false;
} else throw new Error(`Request failed with error ${res.status}`);
});
public areCredentialsCorrect(hashedPassword: string, token?: Token): Promise<boolean> {
const url = '/auth/are-credentials-correct';

return this.client
.getWithParams<boolean>(url, { hashedPassword }, this.headersWithToken(token ?? <string>this.apiSecurity?.token))
.then((res) => {
return res;
})
.catch((error) => {
if (error.response?.status === 401) {
return false;
}
throw new Error(`Request failed with status ${error.response?.status}: ${error.response?.data}`);
});
}

/**
Expand Down
15 changes: 12 additions & 3 deletions src/drive/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
FriendInvite,
InitializeUserResponse,
PreCreateUserResponse,
Token,
UpdateProfilePayload,
UserPublicKeyResponse,
VerifyEmailChangeResponse,
Expand Down Expand Up @@ -187,15 +188,19 @@ export class Users {
/**
* Sends verification email
*/
public sendVerificationEmail() {
return this.client.post<void>('/user/sendVerificationEmail', {}, this.headers());
public sendVerificationEmail(token?: Token) {
return this.client.post<void>(
'/users/email-verification/send',
{},
this.headersWithToken(token ?? <string>this.apiSecurity?.token),
);
}

/**
* Verifies user email
*/
public verifyEmail(payload: { verificationToken: string }) {
return this.client.post<void>('/user/verifyEmail', payload, this.headers());
return this.client.post<void>('/users/email-verification', payload, this.headers());
}

/**
Expand Down Expand Up @@ -252,4 +257,8 @@ export class Users {
private headers() {
return headersWithToken(this.appDetails.clientName, this.appDetails.clientVersion, this.apiSecurity.token);
}

private headersWithToken(token: Token) {
return headersWithToken(this.appDetails.clientName, this.appDetails.clientVersion, token);
}
}
10 changes: 6 additions & 4 deletions src/drive/users/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { UUID, UserSettings } from '../../shared/types/userSettings';

export type Token = string;

export interface InitializeUserResponse {
email: string;
bucket: string;
Expand All @@ -21,13 +23,13 @@ export interface ChangePasswordPayloadNew {
newEncryptedSalt: string;
encryptedMnemonic: string;
/**
* @deprecated encryptedPrivateKey field is depercated, use keys.encryptedPrivateKey instead
*/
* @deprecated encryptedPrivateKey field is depercated, use keys.encryptedPrivateKey instead
*/
encryptedPrivateKey: string;
keys: {
encryptedPrivateKey: string;
encryptedPrivateKyberKey: string;
}
};
encryptVersion: string;
}

Expand All @@ -41,7 +43,7 @@ export type PreCreateUserResponse = {

export type FriendInvite = { guestEmail: string; host: number; accepted: boolean; id: number };

export type UserPublicKeyResponse = { publicKey: string, publicKyberKey?: string };
export type UserPublicKeyResponse = { publicKey: string; publicKyberKey?: string };

export type VerifyEmailChangeResponse = {
oldEmail: string;
Expand Down
Loading