Skip to content

Commit

Permalink
fix: pulled alpha changes to resolve conflicts on this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek-01k committed Jul 1, 2024
2 parents adde0f0 + 484f95d commit 9a48606
Show file tree
Hide file tree
Showing 34 changed files with 33,718 additions and 23,400 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import styled from 'styled-components';

import { ChatView, MODAL_BACKGROUND_TYPE } from '@pushprotocol/uiweb';
import {
ChatView,
CreateGroupModal,
MODAL_BACKGROUND_TYPE,
} from '@pushprotocol/uiweb';
import { Section } from '../components/StyledComponents';
import Img from '../../assets/epnsLogo.png';
import { CHAT_ID } from '../constants';
Expand All @@ -17,7 +21,12 @@ const ChatViewComponentTest = () => {

<ChatViewComponentCard>
{/* uncomment the below code to test create group modal */}
{/* <CreateGroupModal onClose={()=>{console.log('in close')}} modalBackground={MODAL_BACKGROUND_TYPE.OVERLAY} modalPositionType={MODAL_POSITION_TYPE.RELATIVE}/> */}
<CreateGroupModal
onClose={() => {
console.log('in close');
}}
modalBackground={MODAL_BACKGROUND_TYPE.OVERLAY}
/>
<ChatView
onVerificationFail={() => console.log('Verification Failed')}
chatId={CHAT_ID}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ const NETWORK_MAPPING: NwMappingType = {
59141: 'LINEA_TESTNET',
59144: 'LINEA_MAINNET',
111557560: 'CYBER_CONNECT_TESTNET',
7560: 'CYBER_CONNECT_MAINNET'
7560: 'CYBER_CONNECT_MAINNET',
84532: 'BASE_TESTNET',
8453: 'BASE_MAINNET',

};

const injected = new InjectedConnector({
supportedChainIds: [
1, 3, 4, 11155111, 42, 137, 80002, 56, 97, 10, 11155420, 2442, 1101, 421614,
42161, 122, 123, 80085, 59144, 59141, 111557560, 7560
42161, 122, 123, 80085, 59144, 59141, 111557560, 7560, 84532, 8453,
],
});

Expand Down
2 changes: 1 addition & 1 deletion packages/examples/sdk-frontend-react/src/app/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Constants = {
DEV_CHAIN_ID: 99999,
NON_ETH_CHAINS: [
137, 80002, 56, 97, 10, 11155420, 2442, 1101, 421614, 42161, 122, 123,
80085, 59141, 59144,111557560, 7560
80085, 59141, 59144,111557560, 7560, 84532, 8453,
],
ETH_CHAINS: [1, 11155111],
};
Expand Down
2 changes: 1 addition & 1 deletion packages/restapi/src/lib/chat/helpers/payloadHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const sendMessagePayloadCore = async (
env: ENV,
pgpHelper: IPGPHelper
): Promise<ISendMessagePayload> => {
const isGroup = !isValidPushCAIP(receiverAddress);
const isGroup = group !== null;

let secretKey: string;
if (isGroup && group?.encryptedSecret && group.sessionKey) {
Expand Down
2 changes: 2 additions & 0 deletions packages/restapi/src/lib/chat/helpers/pgp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const PGPHelper:IPGPHelper = {
})
const publicKey: openpgp.PublicKey = await openpgp.readKey({ armoredKey: publicKeyArmored })
const verificationResult = await openpgp.verify({
// setting date to 1 day in the future to avoid issues with clock skew
date: new Date(Date.now() + 1000 * 60 * 60 * 24),
message,
signature,
verificationKeys: publicKey
Expand Down
53 changes: 42 additions & 11 deletions packages/restapi/src/lib/chat/send.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { convertToValidDID, getAPIBaseUrls, isValidPushCAIP } from '../helpers';
import {
convertToValidDID,
getAPIBaseUrls,
isValidPushCAIP,
walletToPCAIP10,
} from '../helpers';
import Constants, { MessageType, ENV } from '../constants';
import { ChatSendOptionsType, MessageWithCID, SignerType } from '../types';
import {
Expand All @@ -15,6 +20,7 @@ import { validateMessageObj } from '../validations/messageObject';
import { axiosPost } from '../utils/axiosUtil';
import { getGroupInfo } from './getGroupInfo';
import { handleError } from '../errors/validationError';
import * as PUSH_CHAT from '../chat';

/**
* SENDS A PUSH CHAT MESSAGE
Expand All @@ -36,8 +42,9 @@ export const sendCore = async (
* 2. Takes care of deprecated fields
*/
const computedOptions = computeOptions(options);
const { messageType, messageObj, account, to, signer, pgpPrivateKey, env } =
const { messageType, messageObj, account, signer, pgpPrivateKey, env } =
computedOptions;
let { to } = computedOptions;
/**
* Validate Input Options
*/
Expand All @@ -50,16 +57,40 @@ export const sendCore = async (
env,
pgpHelper
);
const receiver = await convertToValidDID(to, env);
let receiver = await convertToValidDID(to, env);
const API_BASE_URL = getAPIBaseUrls(env);
const isGroup = isValidPushCAIP(to) ? false : true;

const group = isGroup
? await getGroupInfo({
chatId: to,
env: env,
})
: null;

const isChatId = isValidPushCAIP(to) ? false : true;
let isGroup = false;
let group = null;

if (isChatId) {
const request: PUSH_CHAT.GetChatInfoType = {
recipient: to,
account: account!,
env: env,
};

const chatInfo = await PUSH_CHAT.getChatInfo(request);
isGroup = chatInfo?.meta?.group ?? false;

group = isGroup
? await getGroupInfo({
chatId: to,
env: env,
})
: null;

if (!isGroup) {
const participants = chatInfo.participants ?? [];
// Find the participant that is not the account being used
const messageSentTo = participants.find(
(participant) => participant !== walletToPCAIP10(account!)
);
to = messageSentTo!;
receiver = to;
}
}

// Not supported by legacy sdk versions, need to override messageContent to avoid parsing errors on legacy sdk versions
let messageContent: string;
Expand Down
72 changes: 61 additions & 11 deletions packages/restapi/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
fuse,
fuseSparknet,
linea,
base,
baseSepolia
} from 'viem/chains';
import { berachainTestnet, polygonAmoy, polygonZkEvmCordona, cyberConnectMainnet, cyberConnectTestnet, lineaSepoliaTestnet } from './customChains';

Expand Down Expand Up @@ -51,7 +53,9 @@ const BLOCKCHAIN_NETWORK = {
LINEA_MAINNET: 'eip155:59144',
LINEA_TESTNET: 'eip155:59141',
CYBER_CONNECT_TESTNET: 'eip155:111557560',
CYBER_CONNECT_MAINNET: 'eip155:7560'
CYBER_CONNECT_MAINNET: 'eip155:7560',
BASE_TESTNET: 'eip155:84532',
BASE_MAINNET: 'eip155:8453',
};

export type ALIAS_CHAIN =
Expand All @@ -63,7 +67,8 @@ export type ALIAS_CHAIN =
| 'FUSE'
| 'BERACHAIN'
| 'LINEA'
| 'CYBERCONNECT';
| 'CYBERCONNECT'
| 'BASE';

export const ETH_CHAIN_ID = {
[ENV.PROD]: 1,
Expand Down Expand Up @@ -127,7 +132,13 @@ export const ALIAS_CHAIN_ID: {
[ENV.STAGING]: 111557560,
[ENV.DEV]: 111557560,
[ENV.LOCAL]: 111557560,
}
},
BASE: {
[ENV.PROD]: 8453,
[ENV.STAGING]: 84532,
[ENV.DEV]: 84532,
[ENV.LOCAL]: 84532,
},
};

export const CHAIN_ID = {
Expand Down Expand Up @@ -164,7 +175,10 @@ export const CHAIN_NAME: { [key: number]: string } = {
59141: 'LINEA',
// cyberconnect
7560: 'CYBER_CONNECT_MAINNET',
111557560: 'CYBER_CONNECT_TESTNET'
111557560: 'CYBER_CONNECT_TESTNET',
// base
8453: 'BASE_MAINNET',
84532: 'BASE_TESTNET',
};
export interface ConfigType {
API_BASE_URL: string;
Expand Down Expand Up @@ -250,6 +264,10 @@ const CONFIG = {
[BLOCKCHAIN_NETWORK.LINEA_MAINNET]:{
API_BASE_URL: API_BASE_URL[ENV.PROD],
EPNS_COMMUNICATOR_CONTRACT: '0x0d8e75CB5d8873c43c5d9Add71Fd71a09F7Ef890',
},
[BLOCKCHAIN_NETWORK.BASE_MAINNET]: {
API_BASE_URL: API_BASE_URL[ENV.PROD],
EPNS_COMMUNICATOR_CONTRACT: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa',
}
},
[ENV.STAGING]: {
Expand Down Expand Up @@ -293,6 +311,10 @@ const CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0x6e489B7af21cEb969f49A90E481274966ce9D74d',
},
[BLOCKCHAIN_NETWORK.BASE_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0x6e489B7af21cEb969f49A90E481274966ce9D74d',
}
},
[ENV.DEV]: {
[BLOCKCHAIN_NETWORK.ETH_SEPOLIA]: {
Expand Down Expand Up @@ -335,6 +357,10 @@ const CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550B5c92baA056Fc0F08132f49508145F',
},
[BLOCKCHAIN_NETWORK.BASE_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550B5c92baA056Fc0F08132f49508145F',
}
},
[ENV.LOCAL]: {
[BLOCKCHAIN_NETWORK.ETH_SEPOLIA]: {
Expand Down Expand Up @@ -377,6 +403,10 @@ const CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550B5c92baA056Fc0F08132f49508145F',
},
[BLOCKCHAIN_NETWORK.BASE_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550B5c92baA056Fc0F08132f49508145F',
}
},
};

Expand Down Expand Up @@ -459,6 +489,11 @@ export const VIEM_CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.PROD],
EPNS_COMMUNICATOR_CONTRACT: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa',
},
[BLOCKCHAIN_NETWORK.BASE_MAINNET]: {
NETWORK: base,
API_BASE_URL: API_BASE_URL[ENV.PROD],
EPNS_COMMUNICATOR_CONTRACT: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa',
}
},
[ENV.STAGING]: {
[BLOCKCHAIN_NETWORK.ETH_SEPOLIA]: {
Expand Down Expand Up @@ -511,6 +546,11 @@ export const VIEM_CONFIG = {
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0x6e489B7af21cEb969f49A90E481274966ce9D74d',
},
[BLOCKCHAIN_NETWORK.BASE_TESTNET]: {
NETWORK: baseSepolia,
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0x6e489B7af21cEb969f49A90E481274966ce9D74d',
}
},
[ENV.DEV]: {
[BLOCKCHAIN_NETWORK.ETH_SEPOLIA]: {
Expand Down Expand Up @@ -560,34 +600,39 @@ export const VIEM_CONFIG = {
},
[BLOCKCHAIN_NETWORK.CYBER_CONNECT_TESTNET]: {
NETWORK: cyberConnectTestnet,
API_BASE_URL: API_BASE_URL[ENV.STAGING],
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550B5c92baA056Fc0F08132f49508145F',
},
[BLOCKCHAIN_NETWORK.BASE_TESTNET]: {
NETWORK: baseSepolia,
API_BASE_URL: API_BASE_URL[ENV.DEV],
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550B5c92baA056Fc0F08132f49508145F',
}
},
[ENV.LOCAL]: {
[BLOCKCHAIN_NETWORK.ETH_SEPOLIA]: {
NETWORK: sepolia,
API_BASE_URL: API_BASE_URL[ENV.DEV],
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x9dDCD7ed7151afab43044E4D694FA064742C428c',
},
[BLOCKCHAIN_NETWORK.POLYGON_AMOY]: {
NETWORK: polygonAmoy,
API_BASE_URL: API_BASE_URL[ENV.DEV],
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550b5c92baa056fc0f08132f49508145f',
},
[BLOCKCHAIN_NETWORK.BSC_TESTNET]: {
NETWORK: bscTestnet,
API_BASE_URL: API_BASE_URL[ENV.DEV],
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x4132061E3349ff36cFfCadA460E10Bd4f31F7ea8',
},
[BLOCKCHAIN_NETWORK.OPTIMISM_TESTNET]: {
NETWORK: optimismSepolia,
API_BASE_URL: API_BASE_URL[ENV.DEV],
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x754787358fac861ef904c92d54f7adb659779317',
},
[BLOCKCHAIN_NETWORK.POLYGON_ZK_EVM_TESTNET]: {
NETWORK: polygonZkEvmCordona,
API_BASE_URL: API_BASE_URL[ENV.DEV],
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550b5c92baa056fc0f08132f49508145f',
},
[BLOCKCHAIN_NETWORK.ARBITRUM_TESTNET]: {
Expand All @@ -612,9 +657,14 @@ export const VIEM_CONFIG = {
},
[BLOCKCHAIN_NETWORK.CYBER_CONNECT_TESTNET]: {
NETWORK: cyberConnectTestnet,
API_BASE_URL: API_BASE_URL[ENV.STAGING],
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550B5c92baA056Fc0F08132f49508145F',
},
[BLOCKCHAIN_NETWORK.BASE_TESTNET]: {
NETWORK: baseSepolia,
API_BASE_URL: API_BASE_URL[ENV.LOCAL],
EPNS_COMMUNICATOR_CONTRACT: '0x9cb3bd7550B5c92baA056Fc0F08132f49508145F',
}
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/restapi/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const Constants = {
DEV_CHAIN_ID: 99999,
NON_ETH_CHAINS: [
137, 80002, 56, 97, 10, 11155420, 2442, 1101, 421614, 42161, 122, 123,
80085,59141, 59144, 111557560,7560
80085,59141, 59144, 111557560, 7560, 84532, 8453,
],
ETH_CHAINS: [1, 11155111],
ENC_TYPE_V1: 'x25519-xsalsa20-poly1305',
Expand Down
6 changes: 5 additions & 1 deletion packages/restapi/src/lib/payloads/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const CHAIN_ID_TO_SOURCE: ChainIdToSourceType = {
59144: 'LINEA_MAINNET',
7560: 'CYBER_CONNECT_MAINNET',
111557560: 'CYBER_CONNECT_TESTNET',
84532: 'BASE_TESTNET',
8453: 'BASE_MAINNET',
};

export const SOURCE_TYPES = {
Expand All @@ -47,11 +49,13 @@ export const SOURCE_TYPES = {
SIMULATE: 'SIMULATE',
CYBER_CONNECT_TESTNET: 'CYBER_CONNECT_TESTNET',
CYBER_CONNECT_MAINNET: 'CYBER_CONNECT_MAINNET',
BASE_TESTNET: 'BASE_TESTNET',
BASE_MAINNET: 'BASE_MAINNET',
};

export const SUPPORTED_CHAINS = [
1, 11155111, 42, 137, 80002, 56, 97, 10, 11155420, 2442, 1101, 421614, 42161,
122, 123, 80085, 111557560, 7560, 59141, 59144
122, 123, 80085, 111557560, 7560, 59141, 59144, 84532, 8453,
];

export enum IDENTITY_TYPE {
Expand Down
Loading

0 comments on commit 9a48606

Please sign in to comment.