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.9",
"version": "1.9.10",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
4 changes: 4 additions & 0 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TwoFactorAuthQR,
RegisterPreCreatedUser,
RegisterPreCreatedUserResponse,
PrivateKeys,
} from './types';
import { UserSettings, UUID } from '../shared/types/userSettings';
import { TeamsSettings } from '../shared/types/teams';
Expand Down Expand Up @@ -389,19 +390,22 @@ export class Auth {
* @param password
* @param salt
* @param mnemonic
* @param keys
*/
public changePasswordWithLink(
token: string | undefined,
password: string,
salt: string,
mnemonic: string,
keys?: PrivateKeys,
): Promise<void> {
return this.client.put(
`/users/recover-account?token=${token}&reset=false`,
{
password: password,
salt: salt,
mnemonic: mnemonic,
privateKeys: keys,
},
this.basicHeaders(),
);
Expand Down
5 changes: 5 additions & 0 deletions src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ export interface BasicAuth {
username: string;
password: string;
}

export interface PrivateKeys {
ecc?: string;
kyber?: string;
}
52 changes: 51 additions & 1 deletion test/auth/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('# auth service tests', () => {
keys: {
ecc: {
publicKey: registerDetails.keys.ecc.publicKey,
privateKey: registerDetails.keys.ecc.privateKeyEncrypted,
privateKey: registerDetails.keys.ecc.privateKeyEncrypted,
},
kyber: {
publicKey: registerDetails.keys.kyber.publicKey,
Expand Down Expand Up @@ -552,6 +552,56 @@ describe('# auth service tests', () => {
expect(body).toEqual({});
});
});

describe('-> change password with link', () => {
it('Should call with right params without private keys', async () => {
const callStub = sinon.stub(httpClient, 'put').resolves({});
const { client, headers } = clientAndHeaders();
const token = 'token';
const password = 'newPassword';
const salt = 'newSalt';
const mnemonic = 'newMnemonic';

await client.changePasswordWithLink(token, password, salt, mnemonic);

expect(callStub.firstCall.args).toEqual([
`/users/recover-account?token=${token}&reset=false`,
{
password,
salt,
mnemonic,
},
headers,
]);
});

it('Should call with right params including private keys', async () => {
const callStub = sinon.stub(httpClient, 'put').resolves({});
const { client, headers } = clientAndHeaders();
const token = 'token';
const password = 'newPassword';
const salt = 'newSalt';
const mnemonic = 'newMnemonic';
const privateKeys = {
ecc: 'newEccKey',
kyber: 'newKyberKey',
};

await client.changePasswordWithLink(token, password, salt, mnemonic, privateKeys);

// Assert
expect(callStub.firstCall.args).toEqual([
`/users/recover-account?token=${token}&reset=false`,
{
password,
salt,
mnemonic,
privateKeys,
},
headers,
]);
});
});
});

function clientAndHeaders(
Expand Down