Skip to content

Commit 3a81576

Browse files
authored
Merge pull request #284 from internxt/feature/PB-4236-recover-account-new-flow
[PB-4236] feature/Add recover account call
2 parents 64045b5 + 1b62312 commit 3a81576

4 files changed

Lines changed: 94 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@internxt/sdk",
33
"author": "Internxt <hello@internxt.com>",
4-
"version": "1.9.21",
4+
"version": "1.9.22",
55
"description": "An sdk for interacting with Internxt's services",
66
"repository": {
77
"type": "git",

src/auth/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { HttpClient } from '../shared/http/client';
44
import { TeamsSettings } from '../shared/types/teams';
55
import { UserSettings, UUID } from '../shared/types/userSettings';
66
import {
7+
ChangePasswordWithLinkPayload,
78
CryptoProvider,
89
Keys,
910
LoginDetails,
@@ -501,6 +502,29 @@ export class Auth {
501502
);
502503
}
503504

505+
public legacyRecoverAccount({
506+
token,
507+
encryptedPassword,
508+
encryptedSalt,
509+
encryptedMnemonic,
510+
eccEncryptedMnemonic,
511+
kyberEncryptedMnemonic,
512+
keys,
513+
}: ChangePasswordWithLinkPayload): Promise<void> {
514+
const accountRecoverPayload = {
515+
password: encryptedPassword,
516+
salt: encryptedSalt,
517+
mnemonic: encryptedMnemonic,
518+
asymmetricEncryptedMnemonic: {
519+
ecc: eccEncryptedMnemonic,
520+
hybrid: kyberEncryptedMnemonic,
521+
},
522+
keys,
523+
};
524+
525+
return this.client.put(`/users/legacy-recover-account?token=${token}`, accountRecoverPayload, this.basicHeaders());
526+
}
527+
504528
/**
505529
* Reset account with token
506530
* @param token

src/auth/types.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,25 @@ export interface PrivateKeys {
7272
ecc?: string;
7373
kyber?: string;
7474
}
75+
76+
export interface PrivateKeysExtended {
77+
ecc: {
78+
public: string;
79+
private: string;
80+
revocationKey: string;
81+
};
82+
kyber: {
83+
public: string;
84+
private: string;
85+
};
86+
}
87+
88+
export interface ChangePasswordWithLinkPayload {
89+
token: string;
90+
encryptedPassword: string;
91+
encryptedSalt: string;
92+
encryptedMnemonic: string;
93+
eccEncryptedMnemonic?: string;
94+
kyberEncryptedMnemonic?: string;
95+
keys: PrivateKeysExtended;
96+
}

test/auth/index.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,53 @@ describe('# auth service tests', () => {
834834
]);
835835
});
836836
});
837+
describe('Legacy recover account', () => {
838+
it('Should call with right params & return values', async () => {
839+
// Arrange
840+
const callStub = sinon.stub(httpClient, 'put').resolves({});
841+
const { client, headers } = clientAndHeaders();
842+
843+
const payload = {
844+
token: 'recovery-token',
845+
encryptedPassword: 'encrypted-password',
846+
encryptedSalt: 'encrypted-salt',
847+
encryptedMnemonic: 'encrypted-mnemonic',
848+
eccEncryptedMnemonic: 'ecc-encrypted-mnemonic',
849+
kyberEncryptedMnemonic: 'kyber-encrypted-mnemonic',
850+
keys: {
851+
ecc: {
852+
public: 'ecc-public-key',
853+
private: 'ecc-private-key',
854+
revocationKey: 'ecc-revocation-key',
855+
},
856+
kyber: {
857+
public: 'kyber-public-key',
858+
private: 'kyber-private-key',
859+
},
860+
},
861+
};
862+
863+
// Act
864+
const result = await client.legacyRecoverAccount(payload);
865+
866+
// Assert
867+
expect(callStub.firstCall.args).toEqual([
868+
`/users/legacy-recover-account?token=${payload.token}`,
869+
{
870+
password: payload.encryptedPassword,
871+
salt: payload.encryptedSalt,
872+
mnemonic: payload.encryptedMnemonic,
873+
asymmetricEncryptedMnemonic: {
874+
ecc: payload.eccEncryptedMnemonic,
875+
hybrid: payload.kyberEncryptedMnemonic,
876+
},
877+
keys: payload.keys,
878+
},
879+
headers,
880+
]);
881+
expect(result).toEqual({});
882+
});
883+
});
837884
});
838885

839886
function clientAndHeaders(

0 commit comments

Comments
 (0)