Skip to content

Commit

Permalink
Merge pull request #1072 from dm3-org/default-nonce
Browse files Browse the repository at this point in the history
Default nonce
  • Loading branch information
AlexNi245 authored Jul 2, 2024
2 parents 73ddfaa + 2ff968f commit e65c208
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
echo "REACT_APP_ENVIRONMENT_NAME=${{ env.environment_name }}" >> ./.env.react
echo "REACT_APP_MAINNET_PROVIDER_RPC=${{ secrets.MAINNET_PROVIDER_URL}}" >> ./.env.react
echo "REACT_APP_CHAIN_ID=${{ vars.CHAIN_ID }}" >> ./.env.react
echo "REACT_APP_NONCE=${{ vars.STORAGE_NONCE }}" >> ./.env.react
echo "REACT_APP_GENOME_REGISTRY_ADDRESS=${{ vars.GENOME_REGISTRY_ADDRESS }}" >> ./.env.react
cat ./.env.react >> ./.env
echo "RESOLVER_ADDRESS=${{ vars.ERC3668_RESOLVER_ADDRESS }}" >> ./.env
Expand Down
1 change: 1 addition & 0 deletions packages/messenger-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function App() {
genomeRegistryAddress: process.env
.REACT_APP_GENOME_REGISTRY_ADDRESS as string,
publicVapidKey: process.env.REACT_APP_PUBLIC_VAPID_KEY as string,
nonce: process.env.REACT_APP_NONCE as string,
showAlways: true,
hideFunction: undefined, // OPTIONAL PARAMETER : 'attachments,edit,delete' or undefined
showContacts: true, // true for all contacts / false for default contact
Expand Down
1 change: 1 addition & 0 deletions packages/messenger-web/src/Dm3Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const Dm3Widget: React.FC = () => {
genomeRegistryAddress: process.env
.REACT_APP_GENOME_REGISTRY_ADDRESS as string,
publicVapidKey: process.env.REACT_APP_PUBLIC_VAPID_KEY as string,
nonce: process.env.REACT_APP_NONCE as string,
showAlways: true,
showContacts: !isMessageToSet, // Show all contacts or only the default based on the message destination
signInImage: signInImagePath, // Dynamic image path based on the current week
Expand Down
46 changes: 35 additions & 11 deletions packages/messenger-widget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Follow the below given steps :-
REACT_APP_RESOLVER_ADDR=0xae6646c22D8eE6479eE0a39Bf63B9bD9e57bAD9d
REACT_APP_GENOME_REGISTRY_ADDRESS=0x5dC881dDA4e4a8d312be3544AD13118D1a04Cb17
REACT_APP_PUBLIC_VAPID_KEY=BFCJLre0GeM6S-n4mkMX4SLZWlDR9qc8RsHyctsOPh_QDQkBuvCrMe9Rmq24736F-CJFp-3DkDWhp19X7mOJrEc
REACT_APP_NONCE=0x123
```

#### For Ethereum mainnet :
Expand All @@ -63,9 +64,10 @@ Follow the below given steps :-
REACT_APP_RESOLVER_ADDR=0xae6646c22D8eE6479eE0a39Bf63B9bD9e57bAD9d
REACT_APP_GENOME_REGISTRY_ADDRESS=0x5dC881dDA4e4a8d312be3544AD13118D1a04Cb17
REACT_APP_PUBLIC_VAPID_KEY=BFCJLre0GeM6S-n4mkMX4SLZWlDR9qc8RsHyctsOPh_QDQkBuvCrMe9Rmq24736F-CJFp-3DkDWhp19X7mOJrEc
REACT_APP_NONCE=0x123
```

6. Replace the alchemy-key of REACT_APP_MAINNET_PROVIDER_RPC with your original key
6. Replace the alchemy-key of REACT_APP_MAINNET_PROVIDER_RPC with your original key and REACT_APP_NONCE with some unique string
7. In the file src/App.tsx use the widget in this way
```js
import { DM3, DM3Configuration } from '@dm3-org/dm3-messenger-widget';
Expand All @@ -87,6 +89,7 @@ Follow the below given steps :-
genomeRegistryAddress: process.env
.REACT_APP_GENOME_REGISTRY_ADDRESS as string,
publicVapidKey: process.env.REACT_APP_PUBLIC_VAPID_KEY as string,
nonce: process.env.REACT_APP_NONCE as string,
defaultContact: 'help.dm3.eth',
showAlways: true,
hideFunction: undefined,
Expand Down Expand Up @@ -167,6 +170,7 @@ Follow the below given steps :-
NEXT_PUBLIC_RESOLVER_ADDR=0xae6646c22D8eE6479eE0a39Bf63B9bD9e57bAD9d
NEXT_PUBLIC_GENOME_REGISTRY_ADDRESS=0x5dC881dDA4e4a8d312be3544AD13118D1a04Cb17
NEXT_PUBLIC_PUBLIC_VAPID_KEY=BFCJLre0GeM6S-n4mkMX4SLZWlDR9qc8RsHyctsOPh_QDQkBuvCrMe9Rmq24736F-CJFp-3DkDWhp19X7mOJrEc
NEXT_PUBLIC_NONCE=0x123
```
#### For Ethereum mainnet :
Expand All @@ -184,9 +188,10 @@ Follow the below given steps :-
NEXT_PUBLIC_RESOLVER_ADDR=0xae6646c22D8eE6479eE0a39Bf63B9bD9e57bAD9d
NEXT_PUBLIC_GENOME_REGISTRY_ADDRESS=0x5dC881dDA4e4a8d312be3544AD13118D1a04Cb17
NEXT_PUBLIC_PUBLIC_VAPID_KEY=BFCJLre0GeM6S-n4mkMX4SLZWlDR9qc8RsHyctsOPh_QDQkBuvCrMe9Rmq24736F-CJFp-3DkDWhp19X7mOJrEc
NEXT_PUBLIC_NONCE=0x123
```
7. Replace the alchemy-key of REACT_APP_MAINNET_PROVIDER_RPC with your original key
7. Replace the alchemy-key of NEXT_PUBLIC_MAINNET_PROVIDER_RPC with your original key and NEXT_PUBLIC_NONCE with some unique string
8. Add the following properties in next.config.mjs file
```js
/** @type {import('next').NextConfig} */
Expand Down Expand Up @@ -219,7 +224,8 @@ Follow the below given steps :-
REACT_APP_MAINNET_PROVIDER_RPC: process.env.NEXT_PUBLIC_MAINNET_PROVIDER_RPC,
RESOLVER_ADDR: process.env.NEXT_PUBLIC_RESOLVER_ADDR,
REACT_APP_GENOME_REGISTRY_ADDRESS: process.env.NEXT_PUBLIC_GENOME_REGISTRY_ADDRESS,
REACT_APP_PUBLIC_VAPID_KEY: process.env.NEXT_PUBLIC_PUBLIC_VAPID_KEY
REACT_APP_PUBLIC_VAPID_KEY: process.env.NEXT_PUBLIC_PUBLIC_VAPID_KEY,
REACT_APP_NONCE: process.env.NEXT_PUBLIC_NONCE,
},
};

Expand Down Expand Up @@ -248,6 +254,7 @@ Follow the below given steps :-
genomeRegistryAddress: process.env
.REACT_APP_GENOME_REGISTRY_ADDRESS as string,
publicVapidKey: process.env.REACT_APP_PUBLIC_VAPID_KEY as string,
nonce: process.env.REACT_APP_NONCE as string,
defaultContact: 'help.dm3.eth',
showAlways: true,
hideFunction: undefined,
Expand Down Expand Up @@ -315,7 +322,8 @@ yarn run dev
REACT_APP_RESOLVER_ADDR: "0xae6646c22D8eE6479eE0a39Bf63B9bD9e57bAD9d",
REACT_APP_CHAIN_ID: "11155111",
REACT_APP_GENOME_REGISTRY_ADDRESS: "0x5dC881dDA4e4a8d312be3544AD13118D1a04Cb17",
REACT_APP_PUBLIC_VAPID_KEY: "BFCJLre0GeM6S-n4mkMX4SLZWlDR9qc8RsHyctsOPh_QDQkBuvCrMe9Rmq24736F-CJFp-3DkDWhp19X7mOJrEc"
REACT_APP_PUBLIC_VAPID_KEY: "BFCJLre0GeM6S-n4mkMX4SLZWlDR9qc8RsHyctsOPh_QDQkBuvCrMe9Rmq24736F-CJFp-3DkDWhp19X7mOJrEc",
REACT_APP_NONCE: "0x123"
}
}
})
Expand Down Expand Up @@ -344,7 +352,8 @@ yarn run dev
REACT_APP_RESOLVER_ADDR: "0xae6646c22D8eE6479eE0a39Bf63B9bD9e57bAD9d",
REACT_APP_CHAIN_ID: "1",
REACT_APP_GENOME_REGISTRY_ADDRESS: "0x5dC881dDA4e4a8d312be3544AD13118D1a04Cb17",
REACT_APP_PUBLIC_VAPID_KEY: "BFCJLre0GeM6S-n4mkMX4SLZWlDR9qc8RsHyctsOPh_QDQkBuvCrMe9Rmq24736F-CJFp-3DkDWhp19X7mOJrEc"
REACT_APP_PUBLIC_VAPID_KEY: "BFCJLre0GeM6S-n4mkMX4SLZWlDR9qc8RsHyctsOPh_QDQkBuvCrMe9Rmq24736F-CJFp-3DkDWhp19X7mOJrEc",
REACT_APP_NONCE: "0x123"
}
}
})
Expand All @@ -358,7 +367,21 @@ yarn run dev
#### Widget props customization :
1. defaultContact
1. nonce
```js
const props: DM3Configuration = {
...
nonce: '0x123',
}
```
This is a nonce value which is used in the storage as a key. Its is a unique value for each client. It is mandatory property.
```js
Example :
nonce: '0x23281'
nonce: '0x9123821'
```
2. defaultContact
```js
const props: DM3Configuration = {
...
Expand All @@ -371,7 +394,8 @@ Example :
defaultContact: 'help.dm3.eth'
defaultContact: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F.dm3.eth'
```
2. hideFunction

3. hideFunction
```js
const props: DM3Configuration = {
...
Expand All @@ -389,7 +413,7 @@ Example :
hideFunction: undefined
```

3. showContacts
4. showContacts
```js
const props: DM3Configuration = {
...
Expand All @@ -404,7 +428,7 @@ Example :
showContacts: false
```

4. signInImage
5. signInImage
```js
const props: DM3Configuration = {
...
Expand All @@ -418,7 +442,7 @@ Example :
signInImage: "https://letsenhance.io/static/8f5e523ee6b2479e26ecc91b9c25261e/1015f/MainAfter.jpg"
```

5. siwe
6. siwe
```js
const props: DM3Configuration = {
...
Expand Down Expand Up @@ -449,7 +473,7 @@ Example :
}
```

6. theme
7. theme
```js
const props: DM3Configuration = {
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const DM3ConfigurationContext =
showAlways: true,
showContacts: true,
publicVapidKey: '',
nonce: '',
},
screenWidth: window.innerWidth,
setScreenWidth: (width: number) => {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export const DEFAULT_DM3_CONFIGURATION = {
showAlways: false,
showContacts: false,
publicVapidKey: '',
nonce: '',
};
1 change: 1 addition & 0 deletions packages/messenger-widget/src/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function Demo() {
.REACT_APP_GENOME_REGISTRY_ADDRESS as string,
publicVapidKey: process.env.REACT_APP_PUBLIC_VAPID_KEY as string,
defaultContact: 'defaultcontact.eth',
nonce: process.env.REACT_APP_NONCE as string,
showAlways: true,
hideFunction: undefined, // OPTIONAL PARAMETER : 'attachments,edit,delete' or undefined
showContacts: true, // true for all contacts / false for default contact
Expand Down
3 changes: 1 addition & 2 deletions packages/messenger-widget/src/hooks/auth/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
} from '@dm3-org/dm3-lib-crypto';
import {
Account,
DEFAULT_NONCE,
ProfileKeys,
SignedUserProfile,
UserProfile,
Expand Down Expand Up @@ -141,7 +140,7 @@ export const useAuth = () => {
signMessage: SignMessageFn,
) => {
async function createProfileKeys(
nonce: string = DEFAULT_NONCE,
nonce: string = dm3Configuration.nonce,
): Promise<ProfileKeys> {
if (!address) {
throw Error('No eth address');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const config: DM3Configuration = {
showAlways: true,
showContacts: true,
publicVapidKey: '',
nonce: '',
};

describe('useDM3Configuration hook test cases', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const useDm3Configuration = () => {
showAlways: true,
showContacts: true,
publicVapidKey: '',
nonce: '',
});

const validateSiweCredentials = async (data: Siwe) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
getStorageKeyCreationMessage,
} from '@dm3-org/dm3-lib-crypto';
import {
DEFAULT_NONCE,
ProfileKeys,
SignedUserProfile,
UserProfile,
Expand All @@ -24,6 +23,7 @@ describe('Server Side Connector', () => {
let axiosMock: MockAdapter;
//Prepare a user profile that is used to test the server side connector
beforeEach(async () => {
const DEFAULT_NONCE = 'u0h3o4a8c4n7m2j231dssa7';
const userWallet = ethers.Wallet.createRandom();
const storageKeyCreationMessage = getStorageKeyCreationMessage(
DEFAULT_NONCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const config: DM3Configuration = {
.REACT_APP_GENOME_REGISTRY_ADDRESS as string,
publicVapidKey: process.env.REACT_APP_PUBLIC_VAPID_KEY as string,
defaultContact: 'defaultcontact.eth',
nonce: process.env.REACT_APP_NONCE as string,
showAlways: true,
showContacts: true,
};
Expand Down
1 change: 1 addition & 0 deletions packages/messenger-widget/src/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface DM3Configuration {
genomeRegistryAddress: string;
showAlways: boolean;
showContacts: boolean;
nonce: string;
publicVapidKey: string;
hideFunction?: string;
theme?: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function DM3Container() {
genomeRegistryAddress: process.env
.NEXT_PUBLIC_GENOME_REGISTRY_ADDRESS as string,
publicVapidKey: process.env.NEXT_PUBLIC_PUBLIC_VAPID_KEY as string,
nonce: process.env.NEXT_APP_NONCE as string,
defaultContact: 'contact.dm3.eth',
showAlways: true,
hideFunction: undefined, // OPTIONAL PARAMETER : 'attachments,edit,delete' or undefined
Expand Down

0 comments on commit e65c208

Please sign in to comment.