Skip to content

Commit

Permalink
fix: Merge branch 'alpha' into alpha-deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Nov 28, 2023
2 parents 4ff281d + 0ca7c59 commit 35a13fd
Show file tree
Hide file tree
Showing 32 changed files with 713 additions and 410 deletions.
8 changes: 7 additions & 1 deletion packages/restapi/src/lib/chat/addAdmins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Constants from '../constants';
import { ALPHA_FEATURE_CONFIG } from '../config';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType, GroupInfoDTO } from '../types';
import {
GroupMemberUpdateOptions,
Expand All @@ -10,6 +11,7 @@ export interface AddAdminsToGroupType extends EnvOptionsType {
account?: string | null;
signer?: SignerType | null;
pgpPrivateKey?: string | null;
overrideSecretKeyGeneration?: boolean;
}

export const addAdmins = async (
Expand All @@ -22,6 +24,9 @@ export const addAdmins = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};
try {
if (account == null && signer == null) {
Expand All @@ -45,6 +50,7 @@ export const addAdmins = async (
signer: signer,
pgpPrivateKey: pgpPrivateKey,
env: env,
overrideSecretKeyGeneration,
};
return await updateGroupMembers(groupMemberUpdateOptions);
} catch (err) {
Expand Down
8 changes: 7 additions & 1 deletion packages/restapi/src/lib/chat/addMembers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Constants from '../constants';
import { ALPHA_FEATURE_CONFIG } from '../config';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType, GroupInfoDTO } from '../types';
import { updateGroupMembers } from './updateGroupMembers';
import { GroupMemberUpdateOptions } from './updateGroupMembers';
Expand All @@ -8,6 +9,7 @@ export interface AddMembersToGroupType extends EnvOptionsType {
account?: string | null;
signer?: SignerType | null;
pgpPrivateKey?: string | null;
overrideSecretKeyGeneration?: boolean;
}

/**
Expand All @@ -23,6 +25,9 @@ export const addMembers = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};
try {
if (account == null && signer == null) {
Expand All @@ -46,6 +51,7 @@ export const addMembers = async (
signer: signer,
pgpPrivateKey: pgpPrivateKey,
env: env,
overrideSecretKeyGeneration,
};
return await updateGroupMembers(groupMemberUpdateOptions);
} catch (err) {
Expand Down
46 changes: 27 additions & 19 deletions packages/restapi/src/lib/chat/approveRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import { getAPIBaseUrls, isValidETHAddress } from '../helpers';
import Constants from '../constants';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType } from '../types';
import {
getAccountAddress,
Expand All @@ -11,10 +11,10 @@ import {
IPGPHelper,
} from './helpers';
import * as CryptoJS from 'crypto-js';
import { getGroup } from './getGroup';
import * as AES from '../chat/helpers/aes';
import { getGroupInfo } from './getGroupInfo';
import { getAllGroupMembersPublicKeys } from './getAllGroupMembersPublicKeys';
import { ALPHA_FEATURE_CONFIG } from '../config';

export interface ApproveRequestOptionsType extends EnvOptionsType {
/**
Expand All @@ -30,6 +30,7 @@ export interface ApproveRequestOptionsType extends EnvOptionsType {
// sigType?: string;
account?: string | null;
signer?: SignerType | null;
overrideSecretKeyGeneration?: boolean;
}

/**
Expand All @@ -52,6 +53,9 @@ export const approveCore = async (
senderAddress,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};

/**
Expand Down Expand Up @@ -93,30 +97,34 @@ export const approveCore = async (
const group = await getGroupInfo({ chatId: senderAddress, env });

if (group && !group.isPublic) {
sigType = 'pgpv2';
const secretKey = AES.generateRandomSecret(15);

const groupMembers = await getAllGroupMembersPublicKeys({
chatId: group.chatId,
env,
});
// Encrypt secret key with group members public keys
const publicKeys: string[] = groupMembers.map(
(member) => member.publicKey
);
publicKeys.push(connectedUser.publicKey);
encryptedSecret = await pgpHelper.pgpEncrypt({
plainText: secretKey,
keys: publicKeys,
});
/**
* Secret Key Gen Override has no effect if an encrypted secret key is already present
*/
if (group.encryptedSecret || !overrideSecretKeyGeneration) {
sigType = 'pgpv2';
const secretKey = AES.generateRandomSecret(15);

const groupMembers = await getAllGroupMembersPublicKeys({
chatId: group.chatId,
env,
});
// Encrypt secret key with group members public keys
const publicKeys: string[] = groupMembers.map(
(member) => member.publicKey
);
publicKeys.push(connectedUser.publicKey);
encryptedSecret = await pgpHelper.pgpEncrypt({
plainText: secretKey,
keys: publicKeys,
});
}
}
}

let bodyToBeHashed: {
fromDID: string;
toDID: string;
status: string;
sessionKey?: string | null;
encryptedSecret?: string | null;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/restapi/src/lib/chat/createGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const createGroupCore = async (
groupName: groupName,
groupDescription: groupDescription == undefined ? null : groupDescription,
members: convertedMembers,
groupImage: groupImage,
groupImage: groupImage == undefined ? null : groupImage,
admins: convertedAdmins,
isPublic: isPublic,
contractAddressNFT:
Expand Down
4 changes: 2 additions & 2 deletions packages/restapi/src/lib/chat/createGroupV2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';
import { getAPIBaseUrls, isValidETHAddress } from '../helpers';
import Constants from '../constants';
import { EnvOptionsType, GroupDTO, SignerType, Rules } from '../types';
import { EnvOptionsType, GroupInfoDTO, SignerType, Rules } from '../types';
import {
getWallet,
getUserDID,
Expand Down Expand Up @@ -40,7 +40,7 @@ export const createGroupV2 = async (options: ChatCreateGroupTypeV2) => {
export const createGroupCoreV2 = async (
options: ChatCreateGroupTypeV2,
pgpHelper: IPGPHelper
): Promise<GroupDTO> => {
): Promise<GroupInfoDTO> => {
const {
account = null,
signer = null,
Expand Down
8 changes: 7 additions & 1 deletion packages/restapi/src/lib/chat/modifyRole.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Constants from '../constants';
import { ALPHA_FEATURE_CONFIG } from '../config';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType, GroupInfoDTO } from '../types';
import {
GroupMemberUpdateOptions,
Expand All @@ -12,6 +13,7 @@ export interface ModifyRolesType extends EnvOptionsType {
account?: string | null;
signer?: SignerType | null;
pgpPrivateKey?: string | null;
overrideSecretKeyGeneration?: boolean;
}

export const modifyRoles = async (
Expand All @@ -25,6 +27,9 @@ export const modifyRoles = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};

try {
Expand All @@ -49,6 +54,7 @@ export const modifyRoles = async (
signer: signer,
pgpPrivateKey: pgpPrivateKey,
env: env,
overrideSecretKeyGeneration,
};

return await updateGroupMembers(groupMemberUpdateOptions);
Expand Down
8 changes: 7 additions & 1 deletion packages/restapi/src/lib/chat/removeAdmins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Constants from '../constants';
import { ALPHA_FEATURE_CONFIG } from '../config';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType, GroupInfoDTO } from '../types';
import {
GroupMemberUpdateOptions,
Expand All @@ -11,6 +12,7 @@ export interface RemoveAdminsFromGroupType extends EnvOptionsType {
account?: string | null;
signer?: SignerType | null;
pgpPrivateKey?: string | null;
overrideSecretKeyGeneration?: boolean;
}

/**
Expand All @@ -26,6 +28,9 @@ export const removeAdmins = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};
try {
if (account == null && signer == null) {
Expand All @@ -47,6 +52,7 @@ export const removeAdmins = async (
signer: signer,
pgpPrivateKey: pgpPrivateKey,
env: env,
overrideSecretKeyGeneration,
};
return await updateGroupMembers(groupMemberUpdateOptions);
} catch (err) {
Expand Down
8 changes: 7 additions & 1 deletion packages/restapi/src/lib/chat/removeMembers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Constants from '../constants';
import { ALPHA_FEATURE_CONFIG } from '../config';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType, GroupInfoDTO } from '../types';
import {
GroupMemberUpdateOptions,
Expand All @@ -10,6 +11,7 @@ export interface RemoveMembersFromGroupType extends EnvOptionsType {
account?: string | null;
signer?: SignerType | null;
pgpPrivateKey?: string | null;
overrideSecretKeyGeneration?: boolean;
}

export const removeMembers = async (
Expand All @@ -22,6 +24,9 @@ export const removeMembers = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};
try {
if (account == null && signer == null) {
Expand All @@ -43,6 +48,7 @@ export const removeMembers = async (
signer: signer,
pgpPrivateKey: pgpPrivateKey,
env: env,
overrideSecretKeyGeneration,
};
return await updateGroupMembers(groupMemberUpdateOptions);
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions packages/restapi/src/lib/chat/updateGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ export const updateGroupCore = async (

const bodyToBeHashed = {
groupName: groupName,
groupDescription: groupDescription,
groupImage: groupImage,
groupDescription: groupDescription == undefined ? null : groupDescription,
groupImage: groupImage == undefined ? null : groupImage,
members: convertedMembers,
admins: convertedAdmins,
chatId: chatId,
Expand Down
Loading

0 comments on commit 35a13fd

Please sign in to comment.