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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
packages: write
strategy:
matrix:
node-version: [16.x]
node-version: [18.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
packages: write
strategy:
matrix:
node-version: [16.x]
node-version: [18.x]
steps:
- name: Check Out Repo
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v2
with:
node-version: '16.x'
node-version: '18.x'
registry-url: 'https://npm.pkg.github.com'
- run: yarn
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ dist
coverage/

.npmrc
.DS_Store
.DS_Store
.vscode/settings.json
9 changes: 0 additions & 9 deletions .vscode/settings.json

This file was deleted.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internxt/sdk",
"version": "1.5.25",
"version": "1.6.0",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down Expand Up @@ -28,20 +28,20 @@
"devDependencies": {
"@internxt/eslint-config-internxt": "^1.0.3",
"@internxt/prettier-config": "^1.0.1",
"@types/jest": "^27.0.1",
"@types/sinon": "^10.0.6",
"@types/uuid": "^8.3.4",
"@types/jest": "^29.5.14",
"@types/sinon": "^17.0.3",
"@types/uuid": "^10.0.0",
"eslint": "^7.32.0",
"husky": "^7.0.1",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"sinon": "^12.0.1",
"ts-jest": "^27.0.5",
"typescript": "^4.3.5"
"husky": "^9.1.6",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"sinon": "^19.0.2",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3"
},
"dependencies": {
"axios": "^0.24.0",
"axios": "^0.28.0",
"query-string": "^7.1.0",
"uuid": "^8.3.2"
"uuid": "^11.0.2"
}
}
69 changes: 68 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: {
privateKey: registerDetails.keys.keys.ecc.privateKeyEncrypted,
publicKey: registerDetails.keys.keys.ecc.publicKey,
},
kyber: {
privateKey: registerDetails.keys.keys.kyber.privateKeyEncrypted,
publicKey: registerDetails.keys.keys.kyber.publicKey,
}
},
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: {
privateKey: registerDetails.keys.keys.ecc.privateKeyEncrypted,
publicKey: registerDetails.keys.keys.ecc.publicKey,
},
kyber: {
privateKey: registerDetails.keys.keys.kyber.privateKeyEncrypted,
publicKey: registerDetails.keys.keys.kyber.publicKey,
}
},
referral: registerDetails.referral,
referrer: registerDetails.referrer,
invitationId: registerDetails.invitationId,
Expand Down Expand Up @@ -132,7 +158,7 @@ export class Auth {
}> {
const securityDetails = await this.securityDetails(details.email);
const encryptedSalt = securityDetails.encryptedSalt;
const encryptedPasswordHash = cryptoProvider.encryptPasswordHash(details.password, encryptedSalt);
const encryptedPasswordHash = await cryptoProvider.encryptPasswordHash(details.password, encryptedSalt);
const keys = await cryptoProvider.generateKeys(details.password);

return this.client
Expand All @@ -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: {
privateKey: keys.keys.ecc.privateKeyEncrypted,
publicKey: keys.keys.ecc.publicKey,
},
kyber: {
privateKey: keys.keys.kyber.privateKeyEncrypted,
publicKey: keys.keys.kyber.publicKey,
}
},
},
this.basicHeaders(),
)
Expand All @@ -170,9 +209,22 @@ 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,
keys: {
ecc: {
privateKey: keys.keys.ecc.privateKeyEncrypted,
publicKey: keys.keys.ecc.publicKey,
},
kyber: {
privateKey: keys.keys.kyber.privateKeyEncrypted,
publicKey: keys.keys.kyber.publicKey,
}
},
},
this.headersWithToken(token),
);
Expand Down Expand Up @@ -298,6 +350,21 @@ export class Auth {
);
}

/**
* Upgrade hash in the database
* @param newHash
*/
public upgradeHash(newHash: string): Promise<void> {
return this.client.patch(
'/users/:id',
{
newPassword: newHash,
newSalt:'',
},
this.basicHeaders(),
);
}

/**
* Restore password with email link
* @param token
Expand Down
71 changes: 42 additions & 29 deletions src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,69 @@ export type Email = string;
export type Token = string;

export interface LoginDetails {
email: Email,
password: Password,
tfaCode: string | undefined
email: Email;
password: Password;
tfaCode: string | undefined;
}

export interface RegisterDetails {
name: string,
lastname: string,
email: Email,
password: Password,
mnemonic: string,
salt: string,
keys: Keys,
captcha: string,
referrer?: string,
referral?: string,
name: string;
lastname: string;
email: Email;
password: Password;
mnemonic: string;
salt: string;
keys: Keys;
captcha: string;
referrer?: string;
referral?: string;
}

export interface RegisterPreCreatedUser extends RegisterDetails {
invitationId: string,
invitationId: string;
}
export interface RegisterPreCreatedUserResponse {
token: Token,
user: UserSettings & { referralCode: string },
uuid: UUID,
token: Token;
user: UserSettings & { referralCode: string };
uuid: UUID;
}
export interface Keys {
privateKeyEncrypted: string,
publicKey: string,
revocationCertificate: string
/**
/ @deprecated The individual fields for keys should not be used
*/
privateKeyEncrypted: string;
publicKey: string;
revocationCertificate: string;
keys: {
ecc: {
privateKeyEncrypted: string;
publicKey: string;
};
kyber: {
publicKey: string;
privateKeyEncrypted: string;
};
};
}

export interface CryptoProvider {
encryptPasswordHash: (password: Password, encryptedSalt: string) => string,
generateKeys: (password: Password) => Promise<Keys>,
encryptPasswordHash: (password: Password, encryptedSalt: string) => Promise<string>;
generateKeys: (password: Password) => Promise<Keys>;
}

export class UserAccessError extends Error { }
export class UserAccessError extends Error {}

export interface SecurityDetails {
encryptedSalt: string
tfaEnabled: boolean
encryptedSalt: string;
tfaEnabled: boolean;
}

export interface TwoFactorAuthQR {
qr: string
backupKey: string
qr: string;
backupKey: string;
}

export interface BasicAuth {
username: string
password: string
username: string;
password: string;
}
1 change: 1 addition & 0 deletions src/drive/share/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export type ShareFolderWithUserPayload = {
encryptionAlgorithm?: string;
roleId: string;
persistPreviousSharing?: boolean;
hybridModeEnabled: boolean;
};

export type CreateSharingPayload = {
Expand Down
3 changes: 2 additions & 1 deletion src/drive/users/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ export type UpdateProfilePayload = Partial<Pick<UserSettings, 'name' | 'lastname

export type PreCreateUserResponse = {
publicKey: string;
publicKyberKey: string;
user: { uuid: UUID; email: string };
};

export type FriendInvite = { guestEmail: string; host: number; accepted: boolean; id: number };

export type UserPublicKeyResponse = { publicKey: string };
export type UserPublicKeyResponse = { publicKey: string; publicKyberKey: string };

export type VerifyEmailChangeResponse = {
oldEmail: string;
Expand Down
14 changes: 14 additions & 0 deletions src/shared/types/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,23 @@ export interface UserSettings {
sharedWorkspace: boolean;
credit: number;
mnemonic: string;
/**
/ @deprecated The individual fields for keys should not be used
*/
privateKey: string;
publicKey: string;
revocationKey: string;
keys: {
ecc: {
privateKey: string;
publicKey: string;
revocationKey: string;
}
kyber: {
privateKyberKey: string;
publicKyberKey: string;
}
}
teams?: boolean;
appSumoDetails: AppSumoDetails | null;
registerCompleted: boolean;
Expand Down
5 changes: 5 additions & 0 deletions src/workspaces/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Workspaces service tests', () => {
id: '1',
memberId: 'member1',
key: 'user_key_1',
hybridModeEnabled: false,
workspaceId: 'workspace1',
spaceLimit: '10GB',
driveUsage: '2GB',
Expand Down Expand Up @@ -88,6 +89,7 @@ describe('Workspaces service tests', () => {
id: '2',
memberId: 'member2',
key: 'user_key_2',
hybridModeEnabled: false,
workspaceId: 'workspace2',
spaceLimit: '15GB',
driveUsage: '5GB',
Expand Down Expand Up @@ -173,6 +175,7 @@ describe('Workspaces service tests', () => {
address: 'Workspace Address',
description: 'Workspace Description',
encryptedMnemonic: 'encryptedMnemonic',
hybridModeEnabled: false,
};
const workspaceSetupInfo: WorkspaceSetupInfo = {
workspaceId: 'workspaceId',
Expand Down Expand Up @@ -387,6 +390,7 @@ describe('Workspaces service tests', () => {
const { client, headers } = clientAndHeaders();
const postCall = sinon.stub(httpClient, 'post').resolves();
const message = 'Test message';
const hybridModeEnabled = false;

await client.inviteMemberToWorkspace({
workspaceId,
Expand All @@ -395,6 +399,7 @@ describe('Workspaces service tests', () => {
encryptedMnemonicInBase64,
encryptionAlgorithm,
message,
hybridModeEnabled: hybridModeEnabled,
});

expect(postCall.firstCall.args).toEqual([
Expand Down
Loading