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 <hello@internxt.com>",
"version": "1.11.26",
"version": "1.12.0",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
6 changes: 4 additions & 2 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Keys,
LoginDetails,
PrivateKeys,
RecoveryKeys,
RegisterDetails,
RegisterOpaqueDetails,
RegisterPreCreatedUser,
Expand Down Expand Up @@ -669,15 +670,16 @@ export class Auth {
password: string,
salt: string,
mnemonic: string,
keys?: PrivateKeys,
keys?: RecoveryKeys,
): Promise<void> {
return this.client.put(
`/users/recover-account-v2?token=${token}&reset=false`,
{
password: password,
salt: salt,
mnemonic: mnemonic,
privateKeys: keys,
privateKeys: keys?.private,
publicKeys: keys?.public,
},
this.basicHeaders(),
);
Expand Down
10 changes: 10 additions & 0 deletions src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ export interface PrivateKeys {
kyber?: string;
}

export interface PublicKeys {
ecc?: string;
kyber?: string;
}

export interface RecoveryKeys {
private?: PrivateKeys;
public?: PublicKeys;
}

export interface PrivateKeysExtended {
ecc: {
public: string;
Expand Down
70 changes: 68 additions & 2 deletions test/auth/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ describe('# auth service tests', () => {
});
});
describe('-> change password with link v2', () => {
it('Should call with right params without private keys', async () => {
it('Should call with right params without keys', async () => {
const callStub = sinon.stub(httpClient, 'put').resolves({});
const { client, headers } = clientAndHeaders();
const token = 'token';
Expand Down Expand Up @@ -871,7 +871,42 @@ describe('# auth service tests', () => {
kyber: 'newKyberKey',
};

await client.changePasswordWithLinkV2(token, password, salt, mnemonic, privateKeys);
await client.changePasswordWithLinkV2(token, password, salt, mnemonic, { private: privateKeys });

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

it('Should call with right params including private and public 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: 'newEccPrivateKey',
kyber: 'newKyberPrivateKey',
};
const publicKeys = {
ecc: 'eccPublicKey',
kyber: 'kyberPublicKey',
};

await client.changePasswordWithLinkV2(token, password, salt, mnemonic, {
private: privateKeys,
public: publicKeys,
});

// Assert
expect(callStub.firstCall.args).toEqual([
Expand All @@ -881,6 +916,37 @@ describe('# auth service tests', () => {
salt,
mnemonic,
privateKeys,
publicKeys,
},
headers,
]);
});

it('Should call with right params including only public keys (legacy backup 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';
const publicKeys = {
ecc: 'eccPublicKey',
kyber: 'kyberPublicKey',
};

await client.changePasswordWithLinkV2(token, password, salt, mnemonic, {
public: publicKeys,
});

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