Skip to content

Commit

Permalink
fix: Merge branch 'main' into deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Jun 8, 2023
2 parents 029aa49 + 4936d1f commit ef4f974
Show file tree
Hide file tree
Showing 12 changed files with 938 additions and 192 deletions.
2 changes: 0 additions & 2 deletions packages/restapi/src/lib/chat/helpers/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export const createUserService = async (options: CreateUserOptionsType) => {
return populateDeprecatedUser(response.data);
})
.catch((err) => {
console.error(`[Push SDK] - API ${requestUrl}: `, err);
throw Error(`[Push SDK] - API ${requestUrl}: ${err}`);
});
};
Expand Down Expand Up @@ -115,7 +114,6 @@ export const authUpdateUserService = async (options: CreateUserOptionsType) => {
return populateDeprecatedUser(response.data);
})
.catch((err) => {
console.error(`[Push SDK] - API ${requestUrl}: `, err);
throw Error(`[Push SDK] - API ${requestUrl}: ${err}`);
});
};
Expand Down
45 changes: 17 additions & 28 deletions packages/restapi/src/lib/helpers/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
encryptedPrivateKeyTypeV2,
IMessageIPFS,
ProgressHookType,
ProgressHookTypeFunction,
} from '../types';
import {
isValidCAIP10NFTAddress,
Expand All @@ -30,6 +31,7 @@ import {
} from './address';
import { verifyProfileSignature } from '../chat/helpers/signature';
import { upgrade } from '../user/upgradeUser';
import PROGRESSHOOK from '../progressHook';

const KDFSaltSize = 32; // bytes
const AESGCMNonceSize = 12; // property iv
Expand Down Expand Up @@ -131,12 +133,8 @@ export const decryptPGPKey = async (options: decryptPgpKeyProps) => {
const { version: encryptionType } = JSON.parse(encryptedPGPPrivateKey);
let privateKey;

progressHook?.({
progressId: 'PUSH-DECRYPT-01',
progressTitle: 'Decrypting Profile',
progressInfo: 'Please sign the transaction to decrypt profile',
level: 'INFO',
});
// Report Progress
progressHook?.(PROGRESSHOOK['PUSH-DECRYPT-01'] as ProgressHookType);

switch (encryptionType) {
case Constants.ENC_TYPE_V1: {
Expand Down Expand Up @@ -246,34 +244,25 @@ export const decryptPGPKey = async (options: decryptPgpKeyProps) => {
await upgrade({ env, account: address, signer, progressHook });
} catch (err) {
// Report Progress
progressHook?.({
progressId: 'PUSH-ERROR-01',
progressTitle: 'Upgrade Profile Failed',
progressInfo: `[Push SDK] - API - Error - API decrypt Pgp Key() -: ${err}`,
level: 'WARN',
});
const errorProgressHook = PROGRESSHOOK[
'PUSH-ERROR-01'
] as ProgressHookTypeFunction;
progressHook?.(errorProgressHook(err));
}
}
progressHook?.({
progressId: 'PUSH-DECRYPT-02',
progressTitle: 'Push Profile Unlocked',
progressInfo: 'Unlocking push profile',
level: 'SUCCESS',
});

// Report Progress
progressHook?.(PROGRESSHOOK['PUSH-DECRYPT-02'] as ProgressHookType);
return privateKey;
} catch (err) {
// Report Progress
progressHook?.({
progressId: 'PUSH-ERROR-00',
progressTitle: 'Non Specific Error',
progressInfo: `[Push SDK] - API - Error - API create User() -: ${err}`,
level: 'ERROR',
});
console.error(
`[Push SDK] - API - Error - API decrypt Pgp Key() -: `,
err
const errorProgressHook = PROGRESSHOOK[
'PUSH-ERROR-00'
] as ProgressHookTypeFunction;
progressHook?.(errorProgressHook(decryptPGPKey.name, err));
throw Error(
`[Push SDK] - API - Error - API ${decryptPGPKey.name} -: ${err}`
);
throw Error(`[Push SDK] - API - Error - API decrypt Pgp Key() -: ${err}`);
}
};

Expand Down
199 changes: 199 additions & 0 deletions packages/restapi/src/lib/progressHook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import { ProgressHookType } from './types';
type ProgressHookTypeFunction = (...args: any[]) => ProgressHookType;

const PROGRESSHOOK: Record<
string,
ProgressHookType | ProgressHookTypeFunction
> = {
/**
* PUSH-CREATE PROGRESSHOOKS
*/
'PUSH-CREATE-01': {
progressId: 'PUSH-CREATE-01',
progressTitle: 'Generating Secure Profile Signature',
progressInfo:
'This step is only done for first time users and might take a few seconds. PGP keys are getting generated to provide you with secure yet seamless chat',
level: 'INFO',
},
'PUSH-CREATE-02': {
progressId: 'PUSH-CREATE-02',
progressTitle: 'Signing Generated Profile',
progressInfo:
'This step is only done for first time users. Please sign the message to continue.',
level: 'INFO',
},
'PUSH-CREATE-03': {
progressId: 'PUSH-CREATE-03',
progressTitle: 'Encrypting Generated Profile',
progressInfo: 'Encrypting your keys. Please sign the message to continue.',
level: 'INFO',
},
'PUSH-CREATE-04': {
progressId: 'PUSH-CREATE-04',
progressTitle: 'Syncing Generated Profile',
progressInfo:
'Please sign the message to continue. Steady lads, chat is almost ready!',
level: 'INFO',
},
'PUSH-CREATE-05': {
progressId: 'PUSH-CREATE-05',
progressTitle: 'Setup Complete',
progressInfo: '',
level: 'SUCCESS',
},
/**
* PUSH-UPGRADE PROGRESSHOOKS
*/
/**
* @deprecated
*/
'PUSH-UPGRADE-01': {
progressId: 'PUSH-UPGRADE-01',
progressTitle: 'Generating New Profile Signature',
progressInfo:
'Trying to Upgrade Push Chat Keys to latest version. Please sign the message to continue.',
level: 'INFO',
},
'PUSH-UPGRADE-02': {
progressId: 'PUSH-UPGRADE-02',
progressTitle: 'Decrypting Old Profile',
progressInfo:
'Trying to Upgrade Push Chat Keys to latest version. Please sign the message to continue.',
level: 'INFO',
},
/**
* @deprecated
*/
'PUSH-UPGRADE-03': {
progressId: 'PUSH-UPGRADE-03',
progressTitle: 'Generating Encrypted New Profile',
progressInfo:
'Trying to Upgrade Push Chat Keys to latest version. Encrypting Push Chat Keys with latest version. Please sign the message to continue.',
level: 'INFO',
},
/**
* @deprecated
*/
'PUSH-UPGRADE-04': {
progressId: 'PUSH-UPGRADE-04',
progressTitle: 'Syncing New Profile',
progressInfo:
'Please sign the message to continue. Steady lads, chat is almost ready!',
level: 'INFO',
},
'PUSH-UPGRADE-05': {
progressId: 'PUSH-UPGRADE-05',
progressTitle: 'Upgrade Completed, Welcome to Push Chat',
progressInfo: '',
level: 'SUCCESS',
},
/**
* PUSH-DECRYPT PROGRESSHOOKS
*/
'PUSH-DECRYPT-01': {
progressId: 'PUSH-DECRYPT-01',
progressTitle: 'Decrypting Profile',
progressInfo: 'Please sign the transaction to decrypt profile',
level: 'INFO',
},
'PUSH-DECRYPT-02': {
progressId: 'PUSH-DECRYPT-02',
progressTitle: 'Push Profile Unlocked',
progressInfo: 'Unlocking push profile',
level: 'SUCCESS',
},
/**
* PUSH-AUTH-UPDATE PROGRESSHOOKS
*/
'PUSH-AUTH-UPDATE-01': (pgpEncryptionVersion: string) => {
return {
progressId: 'PUSH-AUTH-UPDATE-01',
progressTitle: 'Generating New Profile Signature',
progressInfo: `Trying to Update Push Chat Keys to ${pgpEncryptionVersion} version. Please sign the message to continue.`,
level: 'INFO',
};
},
'PUSH-AUTH-UPDATE-02': (pgpEncryptionVersion: string) => {
return {
progressId: 'PUSH-AUTH-UPDATE-02',
progressTitle: 'Generating New Encrypted Profile',
progressInfo: `Encrypting Push Chat Keys with ${pgpEncryptionVersion} version. Please sign the message to continue.`,
level: 'INFO',
};
},
'PUSH-AUTH-UPDATE-03': {
progressId: 'PUSH-AUTH-UPDATE-03',
progressTitle: 'Syncing Updated Profile',
progressInfo:
'Please sign the message to continue. Steady lads, chat is almost ready!',
level: 'INFO',
},
'PUSH-AUTH-UPDATE-04': {
progressId: 'PUSH-AUTH-UPDATE-04',
progressTitle: 'Update Completed, Welcome to Push Chat',
progressInfo: '',
level: 'SUCCESS',
},
'PUSH-AUTH-UPDATE-05': {
progressId: 'PUSH-AUTH-UPDATE-05',
progressTitle: 'Generating New Profile Signature',
progressInfo: `Trying to Update Push Profile creds. Please sign the message to continue.`,
level: 'INFO',
},
'PUSH-AUTH-UPDATE-06': {
progressId: 'PUSH-AUTH-UPDATE-06',
progressTitle: 'Generating New Profile Signature',
progressInfo: `Encrypting Push Chat Keys with new creds. Please sign the message to continue.`,
level: 'INFO',
},
/**
* PUSH-DECRYPT-AUTH PROGRESSHOOKS
*/
'PUSH-DECRYPT-AUTH-01': {
progressId: 'PUSH-DECRYPT-AUTH-01',
progressTitle: 'Decrypting Profile Creds',
progressInfo: 'Please sign the transaction to decrypt profile creds',
level: 'INFO',
},
'PUSH-DECRYPT-AUTH-02': {
progressId: 'PUSH-DECRYPT-AUTH-02',
progressTitle: 'Push Profile Creds Unlocked',
progressInfo: 'Unlocking push profile creds',
level: 'SUCCESS',
},
/**
* PUSH-PROFILE-UPDATE PROGRESSHOOKS
*/
'PUSH-PROFILE-UPDATE-01': {
progressId: 'PUSH-PROFILE-UPDATE-01',
progressTitle: 'Syncing Updated Profile',
progressInfo: 'Steady lads, your profile is getting a new look!',
level: 'INFO',
},
'PUSH-PROFILE-UPDATE-02': {
progressId: 'PUSH-PROFILE-UPDATE-02',
progressTitle: 'Profile Update Completed, Welcome to Push Chat',
progressInfo: '',
level: 'SUCCESS',
},
/**
* PUSH-ERROR PROGRESSHOOKS
*/
'PUSH-ERROR-00': (functionName: string, err: string) => {
return {
progressId: 'PUSH-ERROR-00',
progressTitle: 'Non Specific Error',
progressInfo: `[Push SDK] - API - Error - API ${functionName}() -: ${err}`,
level: 'ERROR',
};
},
'PUSH-ERROR-01': (err: string) => {
return {
progressId: 'PUSH-ERROR-01',
progressTitle: 'Upgrade Profile Failed',
progressInfo: `[Push SDK] - API - Error - API decryptPgpKey() -: ${err}`,
level: 'WARN',
};
},
};
export default PROGRESSHOOK;
1 change: 1 addition & 0 deletions packages/restapi/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ export type ProgressHookType = {
progressInfo: string;
level: 'INFO' | 'SUCCESS' | 'WARN' | 'ERROR';
};
export type ProgressHookTypeFunction = (...args: any[]) => ProgressHookType;

export type MessageWithCID = {
cid: string;
Expand Down
Loading

0 comments on commit ef4f974

Please sign in to comment.