Skip to content

Commit

Permalink
fix: fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mishramonalisha76 committed Jul 17, 2023
2 parents d7e2cde + 8df91a4 commit dfab492
Show file tree
Hide file tree
Showing 152 changed files with 7,767 additions and 439 deletions.
48 changes: 48 additions & 0 deletions packages/demoreact/src/app/ChatWidgetTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useContext, useEffect, useState } from 'react';
import { ChatAndNotificationWidget, PUSH_TABS } from '@pushprotocol/uiweb';
import { EnvContext, Web3Context } from './context';
import * as PushAPI from '@pushprotocol/restapi';
import { IUser } from '@pushprotocol/restapi';




export const ChatWidgetTest = () => {

const { account, library } = useContext<any>(Web3Context);
const librarySigner = library.getSigner();
const [pvtKey,setPvtKey] = useState<string>('');
const {env} = useContext<any>(EnvContext);

useEffect(()=>{
(async()=>{
const user = await PushAPI.user.get({ account: account, env });
const pvtkey = null;
console.log(user)
if (user?.encryptedPrivateKey) {
const response = await PushAPI.chat.decryptPGPKey({
encryptedPGPPrivateKey: (user as IUser).encryptedPrivateKey,
account: account,
signer: librarySigner,
env,
toUpgrade: true,
});
setPvtKey(response)
}
})();

},[account,env])
const onClose = () => {
console.log('in here widget')
};
return (
<ChatAndNotificationWidget
account={account}
env={env}
decryptedPgpPvtKey={pvtKey}
signer={librarySigner}
// activeTab={PUSH_TABS.APP_NOTIFICATIONS}
activeChat='0x3Cf13f6d91F50dca6eAD7356b78482c54CDd95ff'
/>
);
};
33 changes: 30 additions & 3 deletions packages/demoreact/src/app/NotificationsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Loader from './components/Loader';
import { DarkIcon, LightIcon } from './components/Icons';
import { Web3Context, EnvContext } from './context';
import * as PushAPI from '@pushprotocol/restapi';
import { NotificationItem, chainNameType, SubscribedModal } from '@pushprotocol/uiweb';
import { NotificationItem, chainNameType, SubscribedModal, INotificationItemTheme, notificationBaseTheme, notificationLightTheme } from '@pushprotocol/uiweb';
import { getCAIPAddress } from './helpers';

import sampleNotifications from './data';
Expand Down Expand Up @@ -52,8 +52,34 @@ const NotificationsTest = () => {
const [theme, setTheme] = useState('dark');
const [viewType, setViewType] = useState('notif');
const [showSubscribe, setShowSubscribe] = useState(false);


// const customTheme: INotificationItemTheme = {...notificationLightTheme,...{
// borderRadius:{
// ...notificationLightTheme.borderRadius,
// modal:'12px',
// },
// color:{
// ...notificationLightTheme.color,
// channelNameText:'#62626A',
// notificationTitleText:'#000',
// notificationContentText:'#62626A',
// timestamp:'#62626A',
// },
// fontWeight:{
// ...notificationLightTheme.fontWeight,
// channelNameText:700,
// notificationTitleText:700,
// notificationContentText:800,
// timestamp:400
// },
// fontSize:{
// ...notificationLightTheme.fontSize,
// channelNameText:'16px',
// notificationTitleText:'16px',
// notificationContentText:'16px',
// timestamp:'12px'
// },
// modalDivider:'none'
// }};
const loadNotifications = useCallback(async () => {
try {
setLoading(true);
Expand Down Expand Up @@ -171,6 +197,7 @@ const NotificationsTest = () => {
image={image}
url={url}
theme={theme}
// customTheme={customTheme}
// chainName="ETH_TEST_GOERLI"
chainName={blockchain as chainNameType}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/demoreact/src/app/SpaceTest/CreateSpaceTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ const CreateSpaceTest = () => {
const response = await PushAPI.space.create({
spaceName,
spaceDescription,
members: members.split(','),
listeners: members.split(','),
spaceImage,
admins: admins.split(','),
speakers: admins.split(','),
isPublic: (isPublic === "true"),
contractAddressNFT,
numberOfNFTs: numberOfNFTs != null ? Number(numberOfNFTs) : undefined,
Expand Down
4 changes: 2 additions & 2 deletions packages/demoreact/src/app/SpaceTest/UpdateSpaceTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ const UpdateSpaceTest = () => {
spaceName,
spaceImage,
spaceDescription,
members: members.split(','),
admins: admins.split(','),
listeners: members.split(','),
speakers: admins.split(','),
signer: librarySigner,
env,
scheduleAt: new Date(scheduleAt) ,
Expand Down
4 changes: 3 additions & 1 deletion packages/demoreact/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
SpaceInvitesComponent
} from './SpaceUITest';
import { useSpaceComponents } from './SpaceUITest/useSpaceComponents';
import { ChatWidgetTest } from './ChatWidgetTest';

window.Buffer = window.Buffer || Buffer;

Expand Down Expand Up @@ -363,7 +364,8 @@ export function App() {
element={<CreateSpaceComponent />}
/>
</Routes>
<ChatSupportTest />
{/* <ChatWidgetTest/> */}
<ChatWidgetTest/>
<SpaceWidgetComponent spaceId={spaceId} />
</SpacesComponentProvider>
</SocketContext.Provider>
Expand Down
2 changes: 1 addition & 1 deletion packages/demoreact/src/app/context/envContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { createContext } from 'react'

const EnvContext = createContext({});

export default EnvContext;
export default EnvContext;
31 changes: 31 additions & 0 deletions packages/examples/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<h1 align="center">
<a href="https://push.org/#gh-light-mode-only">
<img width='20%' height='10%' src="https://res.cloudinary.com/drdjegqln/image/upload/v1686227557/Push-Logo-Standard-Dark_xap7z5.png">
</a>
<a href="https://push.org/#gh-dark-mode-only">
<img width='20%' height='10%' src="https://res.cloudinary.com/drdjegqln/image/upload/v1686227558/Push-Logo-Standard-White_dlvapc.png">
</a>
</h1>

<p align="center">
<i align="center">Push Protocol is a web3 communication network, enabling cross-chain notifications, messaging, video, and NFT chat for dapps, wallets, and services.🚀</i>
</p>

# Welcome to Push SDK Examples!
This repository houses various practical examples that illustrate how to use the Push SDK effectively to enhance your applications with advanced web3 communication functionalities.

## One-Stop Solution for Understanding the Implementation of Push Protocol's SDK

The `push-sdk` repository provides two comprehensive examples that serve as practical guides for developers:

1. `sdk-backend-node`: A backend implementation using Node.js.
2. `sdk-frontend/video`: A frontend implementation focusing on video notifications.

These examples illuminate the application of the Push Protocol in real-world scenarios, making it easier for you to effectively incorporate it into your own projects.

They are the perfect starting point for any hacker looking to dive into the world of decentralized notifications. Explore, learn, and create with the Push Protocol. Happy hacking!

# Docs
- [Developer Docs](https://docs.push.org/developers)
- [Documentation Hub](https://docs.push.org)

38 changes: 38 additions & 0 deletions packages/examples/sdk-backend-node/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SDK Backend Node Example

Welcome to the SDK Backend Node Example project, a hands-on guide demonstrating how to leverage the power of Push Protocol in a backend environment using Node.js. This resource is an invaluable companion for developers keen to integrate Push Protocol into their backend services. Dive into the code to gain a comprehensive understanding of how to deploy various features of the Push Protocol in a Node.js backend.

## Overview

The `sdk-backend-node` project offers a practical tutorial on how to set up and configure Push Protocol on a server, including guidance on managing notifications and interfacing with the blockchain. This includes essential examples related to:

- Push Notifications
- Push Chat
- Push NFT Chat
- Push Video

Through these examples, you'll see how these features can be successfully implemented and integrated using Push Protocol.

## Getting Started

Embark on your journey with this project by cloning the repository and installing the dependencies:

```bash
git clone https://github.com/ethereum-push-notification-service/push-sdk.git
cd push-sdk
yarn install
```
***Note*** - We are using `yarn` and **strongly** advise to use yarn 1.x to avoid any NPM issues.

## Setting up the SDK-Backend-Node
1. Navigate to the `packages/examples/sdk-backend-node` directory.
2. Set up your environment variables by creating a `.env` file based on the provided `.env.sample` file.

## Running the SDK-Backend-Node
### By GUI (preferred)
1. Click on the `NX console` extension icon in the VSCode sidebar.
2. Click on the `serve` target execute icon under `examples-sdk-backend-node`

### By CLI
1. Navigate to the root level of push-sdk repository.
2. Run `yarn nx serve packages/examples/sdk-backend-node`
43 changes: 43 additions & 0 deletions packages/restapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,49 @@ export interface IUser {

Example response normal user:

**Version 1.2.x**

```typescript
export interface IUser {
did: string;
wallets: string;
profilePicture: string | null;
publicKey: string;
encryptedPrivateKey: string;
encryptionType: string;
signature: string;
sigType: string;
about: string | null;
name: string | null;
encryptedPassword: string | null;
nftOwner: string | null;
numMsg: number;
allowedNumMsg: number;
linkedListHash?: string | null;
nfts?: [] | null;
}
```

| Parameter | Description |
| --- | --- |
| `did` | user decentralized identity |
| `wallets` | all wallets associated to the did |
| `profilePicture` | user chat profile picture. As of now i cannot be changed |
| `publicKey` | PGP public key |
| `encryptedPrivateKey` | encrypted private PGP key |
| `encryptionType` | encryption type used to encrypt the private key |
| `signature` | user payload signature used when creating a user |
| `sigType` | signature type used when creating a user |
| `about` | short user description |
| `name` | user name |
| `encryptedPassword` | encrypted password used to encrypt the private key for NFT chat |
| `nftOwner` | NFT owner address |
| `numMsg` | number of messages sent by the user |
| `allowedNumMsg` | number of messages allowed to be sent by the user |
| `linkedListHash` | cid from all messages this user has sent |
| `nfts` | array of NFTs owned by the user |

Example response:
```typescript
// PushAPI_user_get | Response - 200 OK
{
Expand Down
36 changes: 21 additions & 15 deletions packages/restapi/src/lib/chat/helpers/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,21 +420,27 @@ export const decryptAndVerifyMessage = async (
* 2. Decrypt messageObj.message, messageObj.meta , messageContent
*/
const decryptedMessage: IMessageIPFS | IMessageIPFSWithCID = { ...message };
const secretKey: string = await pgpDecrypt({
cipherText: message.encryptedSecret,
toPrivateKeyArmored: pgpPrivateKey,
});
decryptedMessage.messageContent = aesDecrypt({
cipherText: message.messageContent,
secretKey,
});
if (message.messageObj) {
decryptedMessage.messageObj = JSON.parse(
aesDecrypt({
cipherText: message.messageObj as string,
secretKey,
})
);
try {
const secretKey: string = await pgpDecrypt({
cipherText: message.encryptedSecret,
toPrivateKeyArmored: pgpPrivateKey,
});
decryptedMessage.messageContent = aesDecrypt({
cipherText: message.messageContent,
secretKey,
});
if (message.messageObj) {
decryptedMessage.messageObj = JSON.parse(
aesDecrypt({
cipherText: message.messageObj as string,
secretKey,
})
);
}
} catch (err) {
decryptedMessage.messageContent = decryptedMessage.messageObj =
'Unable to Decrypt Message';
}

return decryptedMessage;
};
4 changes: 3 additions & 1 deletion packages/uiweb/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
"rules": {
// "@typescript-eslint/consistent-type-imports": "error"
}
},
{
"files": ["*.ts", "*.tsx"],
Expand Down
7 changes: 5 additions & 2 deletions packages/uiweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
"dependencies": {
"@livepeer/react": "^2.6.0",
"@pushprotocol/socket": "^0.5.0",
"@unstoppabledomains/resolution": "^8.5.0",
"date-fns": "^2.28.0",
"emoji-picker-react": "^3.5.1",
"html-react-parser": "^1.4.13"
"emoji-picker-react": "^4.4.9",
"html-react-parser": "^1.4.13",
"gif-picker-react": "^1.1.0",
"font-awesome": "^4.7.0"
},
"peerDependencies": {
"@pushprotocol/restapi": "^1.2.15",
Expand Down
Loading

0 comments on commit dfab492

Please sign in to comment.