Skip to content

Commit

Permalink
Merge pull request #265 from internxt/feat/add_kyber
Browse files Browse the repository at this point in the history
[PB-2666]: Add kyber keys to the sdk
  • Loading branch information
sg-gs authored Dec 19, 2024
2 parents 65c8971 + 7a38861 commit e6df2b5
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 6 deletions.
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.8.0",
"version": "1.9.0",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
52 changes: 51 additions & 1 deletion src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,22 @@ 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,
privateKeyEncrypted: registerDetails.keys.ecc.privateKeyEncrypted,
},
kyber: {
publicKey: registerDetails.keys.kyber.publicKey,
privateKeyEncrypted: registerDetails.keys.kyber.privateKeyEncrypted,
}
},
referral: registerDetails.referral,
referrer: registerDetails.referrer,
},
Expand All @@ -79,9 +92,22 @@ 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,
privateKeyEncrypted: registerDetails.keys.ecc.privateKeyEncrypted,
},
kyber: {
publicKey: registerDetails.keys.kyber.publicKey,
privateKeyEncrypted: registerDetails.keys.kyber.privateKeyEncrypted,
},
},
referral: registerDetails.referral,
referrer: registerDetails.referrer,
invitationId: registerDetails.invitationId,
Expand Down Expand Up @@ -147,9 +173,22 @@ export class Auth {
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,
privateKeyEncrypted: keys.ecc.privateKeyEncrypted,
},
kyber: {
publicKey: keys.kyber.publicKey,
privateKeyEncrypted: keys.kyber.privateKeyEncrypted,
}
},
},
this.basicHeaders(),
)
Expand All @@ -169,10 +208,21 @@ export class Auth {
public updateKeys(keys: Keys, token: Token) {
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,
privateKeyEncrypted: keys.ecc.privateKeyEncrypted,
},
kyber: {
publicKey: keys.kyber.publicKey,
privateKeyEncrypted: keys.kyber.privateKeyEncrypted,
}
},
this.headersWithToken(token),
);
Expand Down
8 changes: 8 additions & 0 deletions src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export interface Keys {
privateKeyEncrypted: string;
publicKey: string;
revocationCertificate: string;
ecc: {
publicKey: string;
privateKeyEncrypted: string;
};
kyber: {
publicKey: string | null;
privateKeyEncrypted: string | null;
};
}

export interface CryptoProvider {
Expand Down
10 changes: 10 additions & 0 deletions src/shared/types/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ export interface UserSettings {
privateKey: string;
publicKey: string;
revocationKey: string;
keys: {
ecc: {
publicKey: string;
privateKeyEncrypted: string;
}
kyber: {
publicKey: string;
privateKeyEncrypted: string;
}
}
teams?: boolean;
appSumoDetails: AppSumoDetails | null;
registerCompleted: boolean;
Expand Down
86 changes: 82 additions & 4 deletions test/auth/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ describe('# auth service tests', () => {
registerDetails.password = '4';
registerDetails.mnemonic = '5';
registerDetails.salt = '6';
registerDetails.keys.revocationCertificate = '7';
registerDetails.captcha = '8';
registerDetails.keys.ecc.privateKeyEncrypted = '7';
registerDetails.keys.ecc.publicKey = '8';
registerDetails.keys.kyber.privateKeyEncrypted = '9';
registerDetails.keys.kyber.publicKey = '10';
registerDetails.keys.revocationCertificate = '11';
registerDetails.captcha = '12';

const postCall = sinon.stub(httpClient, 'post').resolves({});
const { client, headers } = clientAndHeaders();
Expand All @@ -48,6 +52,16 @@ describe('# auth service tests', () => {
privateKey: registerDetails.keys.privateKeyEncrypted,
publicKey: registerDetails.keys.publicKey,
revocationKey: registerDetails.keys.revocationCertificate,
keys: {
ecc: {
publicKey: registerDetails.keys.ecc.publicKey,
privateKeyEncrypted: registerDetails.keys.ecc.privateKeyEncrypted,
},
kyber: {
publicKey: registerDetails.keys.kyber.publicKey,
privateKeyEncrypted: registerDetails.keys.kyber.privateKeyEncrypted,
},
},
referral: registerDetails.referral,
referrer: registerDetails.referrer,
captcha: registerDetails.captcha,
Expand Down Expand Up @@ -84,8 +98,12 @@ describe('# auth service tests', () => {
registerDetails.password = '4';
registerDetails.mnemonic = '5';
registerDetails.salt = '6';
registerDetails.keys.revocationCertificate = '7';
registerDetails.captcha = '8';
registerDetails.keys.ecc.privateKeyEncrypted = '7';
registerDetails.keys.ecc.publicKey = '8';
registerDetails.keys.kyber.privateKeyEncrypted = '9';
registerDetails.keys.kyber.publicKey = '10';
registerDetails.keys.revocationCertificate = '11';
registerDetails.captcha = '12';

const mockInvitatioId = 'invitationId';

Expand All @@ -108,6 +126,16 @@ describe('# auth service tests', () => {
privateKey: registerDetails.keys.privateKeyEncrypted,
publicKey: registerDetails.keys.publicKey,
revocationKey: registerDetails.keys.revocationCertificate,
keys: {
ecc: {
publicKey: registerDetails.keys.ecc.publicKey,
privateKeyEncrypted: registerDetails.keys.ecc.privateKeyEncrypted,
},
kyber: {
publicKey: registerDetails.keys.kyber.publicKey,
privateKeyEncrypted: registerDetails.keys.kyber.privateKeyEncrypted,
},
},
referral: registerDetails.referral,
referrer: registerDetails.referrer,
captcha: registerDetails.captcha,
Expand Down Expand Up @@ -153,6 +181,14 @@ describe('# auth service tests', () => {
privateKeyEncrypted: '',
publicKey: '',
revocationCertificate: '',
ecc: {
publicKey: '',
privateKeyEncrypted: '',
},
kyber: {
publicKey: '',
privateKeyEncrypted: '',
},
};
return Promise.resolve(keys);
},
Expand Down Expand Up @@ -181,6 +217,14 @@ describe('# auth service tests', () => {
privateKeyEncrypted: '',
publicKey: '',
revocationCertificate: '',
ecc: {
publicKey: '',
privateKeyEncrypted: '',
},
kyber: {
publicKey: '',
privateKeyEncrypted: '',
},
};
return Promise.resolve(keys);
},
Expand Down Expand Up @@ -216,6 +260,14 @@ describe('# auth service tests', () => {
privateKeyEncrypted: 'priv',
publicKey: 'pub',
revocationCertificate: 'rev',
ecc: {
publicKey: 'pub',
privateKeyEncrypted: 'priv',
},
kyber: {
publicKey: 'pubKyber',
privateKeyEncrypted: 'privKyber',
},
};
return Promise.resolve(keys);
},
Expand Down Expand Up @@ -253,6 +305,16 @@ describe('# auth service tests', () => {
privateKey: 'priv',
publicKey: 'pub',
revocateKey: 'rev',
keys: {
ecc: {
publicKey: 'pub',
privateKeyEncrypted: 'priv',
},
kyber: {
publicKey: 'pubKyber',
privateKeyEncrypted: 'privKyber',
},
},
},
headers,
]);
Expand All @@ -274,6 +336,14 @@ describe('# auth service tests', () => {
privateKeyEncrypted: 'prik',
publicKey: 'pubk',
revocationCertificate: 'crt',
ecc: {
publicKey: 'pub',
privateKeyEncrypted: 'priv',
},
kyber: {
publicKey: 'pubKyber',
privateKeyEncrypted: 'privKyber',
},
};
const axiosStub = sinon.stub(httpClient, 'patch').resolves({});

Expand All @@ -287,6 +357,14 @@ describe('# auth service tests', () => {
publicKey: 'pubk',
privateKey: 'prik',
revocationKey: 'crt',
ecc: {
publicKey: 'pub',
privateKeyEncrypted: 'priv',
},
kyber: {
publicKey: 'pubKyber',
privateKeyEncrypted: 'privKyber',
},
},
headers,
]);
Expand Down
8 changes: 8 additions & 0 deletions test/auth/registerDetails.mother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ export function emptyRegisterDetails(): RegisterDetails {
privateKeyEncrypted: '',
publicKey: '',
revocationCertificate: '',
ecc: {
publicKey: '',
privateKeyEncrypted: '',
},
kyber: {
publicKey: '',
privateKeyEncrypted: '',
},
};
return {
name: '',
Expand Down

0 comments on commit e6df2b5

Please sign in to comment.