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.21",
"version": "1.9.22",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
24 changes: 24 additions & 0 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HttpClient } from '../shared/http/client';
import { TeamsSettings } from '../shared/types/teams';
import { UserSettings, UUID } from '../shared/types/userSettings';
import {
ChangePasswordWithLinkPayload,
CryptoProvider,
Keys,
LoginDetails,
Expand Down Expand Up @@ -501,6 +502,29 @@ export class Auth {
);
}

public legacyRecoverAccount({
token,
encryptedPassword,
encryptedSalt,
encryptedMnemonic,
eccEncryptedMnemonic,
kyberEncryptedMnemonic,
keys,
}: ChangePasswordWithLinkPayload): Promise<void> {
const accountRecoverPayload = {
password: encryptedPassword,
salt: encryptedSalt,
mnemonic: encryptedMnemonic,
asymmetricEncryptedMnemonic: {
ecc: eccEncryptedMnemonic,
hybrid: kyberEncryptedMnemonic,
},
keys,
};

return this.client.put(`/users/legacy-recover-account?token=${token}`, accountRecoverPayload, this.basicHeaders());
}

/**
* Reset account with token
* @param token
Expand Down
22 changes: 22 additions & 0 deletions src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,25 @@ export interface PrivateKeys {
ecc?: string;
kyber?: string;
}

export interface PrivateKeysExtended {
ecc: {
public: string;
private: string;
revocationKey: string;
};
kyber: {
public: string;
private: string;
};
}

export interface ChangePasswordWithLinkPayload {
token: string;
encryptedPassword: string;
encryptedSalt: string;
encryptedMnemonic: string;
eccEncryptedMnemonic?: string;
kyberEncryptedMnemonic?: string;
keys: PrivateKeysExtended;
}
47 changes: 47 additions & 0 deletions test/auth/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,53 @@ describe('# auth service tests', () => {
]);
});
});
describe('Legacy recover account', () => {
it('Should call with right params & return values', async () => {
// Arrange
const callStub = sinon.stub(httpClient, 'put').resolves({});
const { client, headers } = clientAndHeaders();

const payload = {
token: 'recovery-token',
encryptedPassword: 'encrypted-password',
encryptedSalt: 'encrypted-salt',
encryptedMnemonic: 'encrypted-mnemonic',
eccEncryptedMnemonic: 'ecc-encrypted-mnemonic',
kyberEncryptedMnemonic: 'kyber-encrypted-mnemonic',
keys: {
ecc: {
public: 'ecc-public-key',
private: 'ecc-private-key',
revocationKey: 'ecc-revocation-key',
},
kyber: {
public: 'kyber-public-key',
private: 'kyber-private-key',
},
},
};

// Act
const result = await client.legacyRecoverAccount(payload);

// Assert
expect(callStub.firstCall.args).toEqual([
`/users/legacy-recover-account?token=${payload.token}`,
{
password: payload.encryptedPassword,
salt: payload.encryptedSalt,
mnemonic: payload.encryptedMnemonic,
asymmetricEncryptedMnemonic: {
ecc: payload.eccEncryptedMnemonic,
hybrid: payload.kyberEncryptedMnemonic,
},
keys: payload.keys,
},
headers,
]);
expect(result).toEqual({});
});
});
});

function clientAndHeaders(
Expand Down