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
4 changes: 2 additions & 2 deletions 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.15.11",
"version": "1.15.12",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down Expand Up @@ -51,4 +51,4 @@
"prettier --write"
]
}
}
}
11 changes: 11 additions & 0 deletions src/mail/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
EmailDomainsResponse,
SetupMailAccountPayload,
SearchFiltersQuery,
MailAccountKeysResponse,
} from './types';

export class MailApi {
Expand Down Expand Up @@ -200,6 +201,16 @@ export class MailApi {
return this.client.post('/users/me/mail-account', payload, this.headers());
}

/**
* Gets the mail account keys for the given address
*
* @param address - The mail address whose keys should be retrieved
* @returns The public, encrypted private and recovery keys plus the salt
*/
async getMailAccountKeys(address: string): Promise<MailAccountKeysResponse> {
return this.client.getWithParams('/users/me/mail-account/keys', { address }, this.headers());
}

/**
* Returns the needed headers for the module requests
* @private
Expand Down
11 changes: 11 additions & 0 deletions src/mail/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SearchFiltersQuery,
EmailDomainsResponse,
SetupMailAccountPayload,
MailAccountKeysResponse,
} from './types';
import { createKeystores, encryptEmail, passwordProtectAndSendEmail, openKeystore, recoverKeys } from './crypto';

Expand Down Expand Up @@ -258,4 +259,14 @@ export class Mail {
async setupMailAccount(payload: SetupMailAccountPayload): Promise<{ address: string }> {
return this.api.setupMailAccount(payload);
}

/**
* Gets the mail account keys for the given address
*
* @param address - The mail address whose keys should be retrieved
* @returns The public, encrypted private and recovery keys plus the salt
*/
async getMailAccountKeys(address: string): Promise<MailAccountKeysResponse> {
return this.api.getMailAccountKeys(address);
}
}
8 changes: 7 additions & 1 deletion src/mail/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export type SetupMailAccountPayload = {
publicKey: string;
encryptionPrivateKey: string;
recoveryPrivateKey: string;
salt: string;
};
};

export type MailAccountKeysResponse = {
address: string;
publicKey: string;
encryptionPrivateKey: string;
recoveryPrivateKey: string;
};
17 changes: 16 additions & 1 deletion test/mail/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ describe('Mail service tests', () => {
publicKey: 'public-key',
encryptionPrivateKey: 'encryption-private-key',
recoveryPrivateKey: 'recovery-private-key',
salt: 'salt',
},
};

Expand All @@ -311,6 +310,22 @@ describe('Mail service tests', () => {
expect(postStub).toHaveBeenCalledWith('/users/me/mail-account', payload, headers);
expect(result).toEqual({ address: 'user@domain.com' });
});

it('When the mail account keys are requested, then it should GET /users/me/mail-account/keys with the address', async () => {
const { client, headers } = clientAndHeadersWithToken();
const expectedKeys = {
address: 'user@domain.com',
publicKey: 'public-key',
encryptionPrivateKey: 'encryption-private-key',
recoveryPrivateKey: 'recovery-private-key',
};
const getStub = vi.spyOn(HttpClient.prototype, 'getWithParams').mockResolvedValue(expectedKeys);

const result = await client.getMailAccountKeys('user@domain.com');

expect(getStub).toHaveBeenCalledWith('/users/me/mail-account/keys', { address: 'user@domain.com' }, headers);
expect(result).toEqual(expectedKeys);
});
});
});

Expand Down
Loading