Skip to content

Commit

Permalink
Merged main into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitmalhotra1420 committed Jun 20, 2024
2 parents 957e093 + f5778ba commit b0c77c2
Show file tree
Hide file tree
Showing 21 changed files with 327 additions and 81 deletions.
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
52 changes: 41 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,7 +42,7 @@ export const sendCore = async (
* 2. Takes care of deprecated fields
*/
const computedOptions = computeOptions(options);
const { messageType, messageObj, account, to, signer, pgpPrivateKey, env } =
let { messageType, messageObj, account, to, signer, pgpPrivateKey, env } =
computedOptions;
/**
* Validate Input Options
Expand All @@ -50,16 +56,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
8 changes: 4 additions & 4 deletions packages/restapi/src/lib/progressHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ const PROGRESSHOOK: Record<
'PUSH-DECRYPT-AUTH-01': {
progressId: 'PUSH-DECRYPT-AUTH-01',
progressTitle: 'Decrypting Profile Creds',
progressInfo: 'Please sign the transaction to decrypt 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',
progressInfo: 'Unlocking push profile creds.',
level: 'SUCCESS',
},
/**
Expand Down Expand Up @@ -191,7 +191,7 @@ const PROGRESSHOOK: Record<
'PUSH-CHANNEL-CREATE-02': {
progressId: 'PUSH-CHANNEL-CREATE-02',
progressTitle: 'Approving PUSH tokens',
progressInfo: 'Gives approval to Push Core contract to spend 50 DAI',
progressInfo: 'Gives approval to Push Core contract to spend 50 PUSH',
level: 'INFO',
},
'PUSH-CHANNEL-CREATE-03': {
Expand All @@ -218,7 +218,7 @@ const PROGRESSHOOK: Record<
'PUSH-CHANNEL-UPDATE-02': {
progressId: 'PUSH-CHANNEL-UPDATE-02',
progressTitle: 'Approving PUSH tokens',
progressInfo: 'Gives approval to Push Core contract to spend 50 DAI',
progressInfo: 'Gives approval to Push Core contract to spend 50 PUSH',
level: 'INFO',
},
'PUSH-CHANNEL-UPDATE-03': {
Expand Down
Loading

0 comments on commit b0c77c2

Please sign in to comment.