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.18.0",
"version": "1.19.0",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
110 changes: 36 additions & 74 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ export class Auth {
password: registerDetails.password,
mnemonic: registerDetails.mnemonic,
salt: registerDetails.salt,
/**
/ @deprecated The individual fields for keys should not be used
*/
privateKey: registerDetails.keys.privateKeyEncrypted,
publicKey: registerDetails.keys.publicKey,
revocationKey: registerDetails.keys.revocationCertificate,
keys: {
ecc: {
publicKey: registerDetails.keys.ecc.publicKey,
Expand Down Expand Up @@ -181,12 +175,6 @@ export class Auth {
password: registerDetails.password,
mnemonic: registerDetails.mnemonic,
salt: registerDetails.salt,
/**
/ @deprecated The individual fields for keys should not be used
*/
privateKey: registerDetails.keys.privateKeyEncrypted,
publicKey: registerDetails.keys.publicKey,
revocationKey: registerDetails.keys.revocationCertificate,
keys: {
ecc: {
publicKey: registerDetails.keys.ecc.publicKey,
Expand Down Expand Up @@ -330,43 +318,30 @@ export class Auth {
const encryptedPasswordHash = cryptoProvider.encryptPasswordHash(details.password, encryptedSalt);
const keys = await cryptoProvider.generateKeys(details.password);

return this.client
.post<{
token: Token;
newToken: Token;
user: UserSettings;
userTeam: TeamsSettings | null;
}>(
'/auth/login/access',
{
email: details.email,
password: encryptedPasswordHash,
tfa: details.tfaCode,
/**
/ @deprecated The individual fields for keys should not be used
*/
privateKey: keys.privateKeyEncrypted,
publicKey: keys.publicKey,
revocateKey: keys.revocationCertificate,
keys: {
ecc: {
publicKey: keys.ecc.publicKey,
privateKey: keys.ecc.privateKeyEncrypted,
},
kyber: {
publicKey: keys.kyber.publicKey,
privateKey: keys.kyber.privateKeyEncrypted,
},
return this.client.post<{
token: Token;
newToken: Token;
user: UserSettings;
userTeam: TeamsSettings | null;
}>(
'/auth/login/access',
{
email: details.email,
password: encryptedPasswordHash,
tfa: details.tfaCode,
keys: {
ecc: {
publicKey: keys.ecc.publicKey,
privateKey: keys.ecc.privateKeyEncrypted,
},
kyber: {
publicKey: keys.kyber.publicKey,
privateKey: keys.kyber.privateKeyEncrypted,
},
},
this.basicHeaders(),
)
.then((data) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
data.user.revocationKey = data.user.revocateKey; // TODO : remove when all projects use SDK
return data;
});
},
this.basicHeaders(),
);
}

/**
Expand Down Expand Up @@ -422,27 +397,20 @@ export class Auth {
const encryptedSalt = securityDetails.encryptedSalt;
const encryptedPasswordHash = cryptoProvider.encryptPasswordHash(details.password, encryptedSalt);

return this.client
.post<{
token: Token;
newToken: Token;
user: UserSettings;
userTeam: TeamsSettings | null;
}>(
'/auth/login/access',
{
email: details.email,
password: encryptedPasswordHash,
tfa: details.tfaCode,
},
this.basicHeaders(),
)
.then((data) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
data.user.revocationKey = data.user.revocateKey; // TODO : remove when all projects use SDK
return data;
});
return this.client.post<{
token: Token;
newToken: Token;
user: UserSettings;
userTeam: TeamsSettings | null;
}>(
'/auth/login/access',
{
email: details.email,
password: encryptedPasswordHash,
tfa: details.tfaCode,
},
this.basicHeaders(),
);
}

/**
Expand All @@ -454,12 +422,6 @@ export class Auth {
return this.client.patch(
'/user/keys',
{
/**
/ @deprecated The individual fields for keys should not be used
*/
publicKey: keys.publicKey,
privateKey: keys.privateKeyEncrypted,
revocationKey: keys.revocationCertificate,
ecc: {
publicKey: keys.ecc.publicKey,
privateKey: keys.ecc.privateKeyEncrypted,
Expand Down
4 changes: 0 additions & 4 deletions src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ export interface RegisterPreCreatedUserResponse {
uuid: UUID;
}
export interface Keys {
privateKeyEncrypted: string;
publicKey: string;
revocationCertificate: string;
ecc: {
publicKey: string;
privateKeyEncrypted: string;
Expand Down Expand Up @@ -111,7 +108,6 @@ export interface PrivateKeysExtended {
ecc: {
public: string;
private: string;
revocationKey: string;
};
kyber: {
public: string;
Expand Down
49 changes: 4 additions & 45 deletions test/auth/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ describe('# auth service tests', () => {
password: registerDetails.password,
mnemonic: registerDetails.mnemonic,
salt: registerDetails.salt,
privateKey: registerDetails.keys.privateKeyEncrypted,
publicKey: registerDetails.keys.publicKey,
revocationKey: registerDetails.keys.revocationCertificate,
keys: {
ecc: {
publicKey: registerDetails.keys.ecc.publicKey,
Expand Down Expand Up @@ -176,9 +173,6 @@ describe('# auth service tests', () => {
password: registerDetails.password,
mnemonic: registerDetails.mnemonic,
salt: registerDetails.salt,
privateKey: registerDetails.keys.privateKeyEncrypted,
publicKey: registerDetails.keys.publicKey,
revocationKey: registerDetails.keys.revocationCertificate,
keys: {
ecc: {
publicKey: registerDetails.keys.ecc.publicKey,
Expand Down Expand Up @@ -374,9 +368,6 @@ describe('# auth service tests', () => {
encryptPasswordHash: (password, encryptedSalt) => password + '-' + encryptedSalt,
generateKeys: (password: Password) => {
const keys: Keys = {
privateKeyEncrypted: 'priv',
publicKey: 'pub',
revocationCertificate: 'rev',
ecc: {
publicKey: 'pub',
privateKeyEncrypted: 'priv',
Expand All @@ -395,13 +386,11 @@ describe('# auth service tests', () => {
sKey: 'encrypted_salt',
})
.mockResolvedValueOnce({
user: {
revocateKey: 'key',
},
user: {},
});

// Act
const body = await client.login(loginDetails, cryptoProvider);
await client.login(loginDetails, cryptoProvider);

// Assert
expect(postStub).toHaveBeenCalledTimes(2);
Expand All @@ -418,9 +407,6 @@ describe('# auth service tests', () => {
email: loginDetails.email,
password: 'password-encrypted_salt',
tfa: loginDetails.tfaCode,
privateKey: 'priv',
publicKey: 'pub',
revocateKey: 'rev',
keys: {
ecc: {
publicKey: 'pub',
Expand All @@ -434,12 +420,6 @@ describe('# auth service tests', () => {
},
headers,
);
expect(body).toEqual({
user: {
revocateKey: 'key',
revocationKey: 'key',
},
});
});
});

Expand All @@ -456,9 +436,6 @@ describe('# auth service tests', () => {
encryptPasswordHash: (password, encryptedSalt) => password + '-' + encryptedSalt,
generateKeys: (password: Password) => {
const keys: Keys = {
privateKeyEncrypted: 'priv',
publicKey: 'pub',
revocationCertificate: 'rev',
ecc: {
publicKey: 'pub',
privateKeyEncrypted: 'priv',
Expand All @@ -477,13 +454,11 @@ describe('# auth service tests', () => {
sKey: 'encrypted_salt',
})
.mockResolvedValueOnce({
user: {
revocateKey: 'key',
},
user: {},
});

// Act
const body = await client.loginWithoutKeys(loginDetails, cryptoProvider);
await client.loginWithoutKeys(loginDetails, cryptoProvider);

// Assert
expect(postStub).toHaveBeenCalledTimes(2);
Expand All @@ -503,12 +478,6 @@ describe('# auth service tests', () => {
},
headers,
);
expect(body).toEqual({
user: {
revocateKey: 'key',
revocationKey: 'key',
},
});
});

it('Should bubble up the error on first call failure', async () => {
Expand All @@ -525,9 +494,6 @@ describe('# auth service tests', () => {
encryptPasswordHash: () => '',
generateKeys: (password: Password) => {
const keys: Keys = {
privateKeyEncrypted: '',
publicKey: '',
revocationCertificate: '',
ecc: {
publicKey: '',
privateKeyEncrypted: '',
Expand Down Expand Up @@ -555,9 +521,6 @@ describe('# auth service tests', () => {
const token: Token = 'my-secure-token';
const { client, headers } = clientAndHeadersWithToken('', 'name', '0.1', token);
const keys: Keys = {
privateKeyEncrypted: 'prik',
publicKey: 'pubk',
revocationCertificate: 'crt',
ecc: {
publicKey: 'pub',
privateKeyEncrypted: 'priv',
Expand All @@ -576,9 +539,6 @@ describe('# auth service tests', () => {
expect(axiosStub).toHaveBeenCalledWith(
'/user/keys',
{
publicKey: 'pubk',
privateKey: 'prik',
revocationKey: 'crt',
ecc: {
publicKey: 'pub',
privateKey: 'priv',
Expand Down Expand Up @@ -955,7 +915,6 @@ describe('# auth service tests', () => {
ecc: {
public: 'ecc-public-key',
private: 'ecc-private-key',
revocationKey: 'ecc-revocation-key',
},
kyber: {
public: 'kyber-public-key',
Expand Down
Loading