Skip to content

Commit

Permalink
fix: disable session check for billboard
Browse files Browse the repository at this point in the history
hai-ko committed Nov 8, 2023
1 parent 3726417 commit 6c6b728
Showing 12 changed files with 87 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/deploy-billboard.yml
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ jobs:
env:
TARGET_HOST: ${{ secrets.STAGING_HOST_BILLBOARD }}
run: |
echo "REACT_APP_ADDR_ENS_SUBDOMAIN=.beta-addr.dm3.eth" >> ./.env.react
echo "REACT_APP_ADDR_ENS_SUBDOMAIN=.bb-addr.dm3.eth" >> ./.env.react
echo "REACT_APP_BACKEND=http://${{ secrets.STAGING_HOST_BILLBOARD }}/api" >> ./.env.react
echo "REACT_APP_DEFAULT_DELIVERY_SERVICE=beta-ds.dm3.eth" >> ./.env.react
echo "REACT_APP_DEFAULT_SERVICE=http://${{ secrets.STAGING_HOST_BILLBOARD }}/api" >> ./.env.react
@@ -52,6 +52,7 @@ jobs:
echo "RPC=${{ secrets.STAGING_RPC }}" >> ./.env
echo "BILLBOARD_PRIVATE_KEY=${{ secrets.BILLBOARD_PRIVATE_KEY}}" >> ./.env
echo "interceptor=${{ secrets.INTERCEPTOR}}" >> ./.env
echo "DISABLE_SESSION_CHECK='true'" >> ./.env
envsubst '${SSL_CERTIFICATE_BASE_LOC} ${TLS_CERTIFICATE_LOCATION} ${TARGET_HOST}' < ./docker/nginx.conf > ./nginx.conf
cat ./.env
- name: Build docker image
4 changes: 3 additions & 1 deletion docker/billboard/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ services:
restart: always
depends_on:
- billboard-client
- backend
- ccip-resolver
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
@@ -25,6 +26,7 @@ services:
SIGNING_PRIVATE_KEY: ${SIGNING_PRIVATE_KEY}
ENCRYPTION_PUBLIC_KEY: ${ENCRYPTION_PUBLIC_KEY}
ENCRYPTION_PRIVATE_KEY: ${ENCRYPTION_PRIVATE_KEY}
DISABLE_SESSION_CHECK: ${DISABLE_SESSION_CHECK}
RPC: ${RPC}
PORT: 8081
LOG_LEVEL: 'debug'
@@ -43,7 +45,7 @@ services:
PORT: 8083
time: 0
privateKey: ${BILLBOARD_PRIVATE_KEY}
ensNames: '["billboard1.bb-user.dm3.eth"]'
ensNames: '["billboard1.bb.dm3.eth"]'
mediators: '[]'
REDIS_URL: redis://db:6379
RPC: ${RPC}
1 change: 1 addition & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import Profile from './profile';
import RpcProxy from './rpc/rpc-proxy';
import Storage from './storage';
import { logInfo } from 'dm3-lib-shared';
import 'dotenv/config';

import {
errorHandler,
6 changes: 6 additions & 0 deletions packages/backend/src/profile.ts
Original file line number Diff line number Diff line change
@@ -49,6 +49,8 @@ export default () => {
method: 'POST',
url: req.url,
ensName,
disableSessionCheck:
process.env.DISABLE_SESSION_CHECK === 'true',
});

const data = await submitUserProfile(
@@ -69,6 +71,10 @@ export default () => {

res.json(data);
} catch (e) {
global.logger.warn({
message: 'POST profile',
error: JSON.stringify(e),
});
res.status(400).send({
message: `Couldn't store profile`,
error: JSON.stringify(e),
10 changes: 7 additions & 3 deletions packages/lib/delivery/src/UserProfile.ts
Original file line number Diff line number Diff line change
@@ -38,35 +38,39 @@ export async function submitUserProfile(
send: (socketId: string) => void,
): Promise<string> {
const account = normalizeEnsName(ensName);
console.log('1', account, signedUserProfile);

if (!(await checkUserProfile(provider, signedUserProfile, account))) {
throw Error('Signature invalid.');
}
//TODO: remvoe DISABLE_SESSION_CHECK
console.log('2', process.env.DISABLE_SESSION_CHECK);
//TODO: remvoe DISABLE_SESSION_CHECK
// DISABLE_SESSION_CHECK is a special solution for ETH Prague
if (
process.env.DISABLE_SESSION_CHECK !== 'true' &&
(await getSession(account))
) {
throw Error('Profile exists already');
}
console.log('3');
const session: Session = {
account,
signedUserProfile,
token: uuidv4(),
createdAt: new Date().getTime(),
profileExtension: getDefaultProfileExtension(),
};
console.log('4', session);

await setSession(account.toLocaleLowerCase(), session);

console.log('5');
await handlePendingConversations(
account,
getSession,
getPendingConversations,
send,
);

console.log('6');
return session.token;
}

16 changes: 12 additions & 4 deletions packages/offchain-resolver/src/http/profile.ts
Original file line number Diff line number Diff line change
@@ -85,11 +85,19 @@ export function profile(web3Provider: ethers.providers.BaseProvider) {
error: 'address has already claimed a subdomain',
});
}
global.logger.debug({
message: 'nameP setAlias',
hotAddr: hotAddr + '.bb-addr.dm3.eth',
alias: `${address}.bb-user.dm3.eth`,
});

await req.app.locals.db.removeAlias(
`${address}.bb-user.dm3.eth`,
);

await req.app.locals.db.setUserProfile(
`${address}.user.ethprague.dm3.eth`,
signedUserProfile,
hotAddr,
await req.app.locals.db.setAlias(
hotAddr + '.bb-addr.dm3.eth',
`${address}.bb-user.dm3.eth`,
);

return res.sendStatus(200);
1 change: 1 addition & 0 deletions packages/offchain-resolver/src/persistance/IDatabase.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ export interface IDatabase {
address: string,
): Promise<boolean>;
removeUserProfile(ensName: string): Promise<boolean>;
removeAlias(alias: string): Promise<boolean>;
setAlias(name: string, alias: string): Promise<boolean>;
getProfileContainerForAlias(
alias: string,
1 change: 1 addition & 0 deletions packages/offchain-resolver/src/persistance/getDatabase.ts
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ export async function getDatabase(
Profile.getProfileContainerForAlias(prismaClient),
getProfileAliasByAddress:
Profile.getProfileAliasByAddress(prismaClient),
removeAlias: Profile.removeAlias(prismaClient),
};
}

Original file line number Diff line number Diff line change
@@ -14,6 +14,11 @@ export type ProfileContainer = {

export function getProfileContainer(db: PrismaClient) {
return async (name: string) => {
global.logger.debug({
message: 'getProfileContainer call',
nameHash: ethers.utils.namehash(name),
name,
});
const profileContainer = await db.profileContainer.findUnique({
where: {
nameHash: ethers.utils.namehash(name),
@@ -31,15 +36,15 @@ export function getProfileContainer(db: PrismaClient) {
}
: null;
global.logger.debug({
message: 'getProfileContainer',
message: 'getProfileContainer found',
nameHash: ethers.utils.namehash(name),
profileContainerResult,
});

return profileContainerResult;
} else {
global.logger.debug({
message: 'getProfileContainer',
message: 'getProfileContainer not found',
nameHash: ethers.utils.namehash(name),
});
// try to find an alias which equlas name
Original file line number Diff line number Diff line change
@@ -10,3 +10,4 @@ export { setAlias } from './setAlias';
export { getProfileContainerForAlias } from './getProfileContainerForAlias';
export { setUserProfile } from './setUserProfile';
export { getProfileAliasByAddress } from './getProfileAliasByAddress';
export { removeAlias } from './removeAlias';
32 changes: 32 additions & 0 deletions packages/offchain-resolver/src/persistance/profile/removeAlias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PrismaClient } from '@prisma/client';
import { normalizeEnsName } from 'dm3-lib-profile';

/**
*
* @param {Redis} redis - Redis client
* @param {string} alias - ENS alias name
* @returns {Promise<boolean>} - A promise that resolves to true if the profile is removed, false otherwise
*/
export function removeAlias(db: PrismaClient) {
return async (alias: string) => {
try {
const normalizedAlias = normalizeEnsName(alias);

await db.alias.delete({
where: {
alias: normalizedAlias,
},
});

global.logger.debug({
message: 'removeAlias',

alias: normalizedAlias,
});

return true;
} catch (e) {
return false;
}
};
}
Original file line number Diff line number Diff line change
@@ -35,26 +35,31 @@ export function setUserProfile(db: PrismaClient) {
const nameHash = ethers.utils.namehash(name);

try {
const id = uuidv4();
global.logger.debug({
message: 'pre setUserProfile',
id,
nameHash,
profile: JSON.stringify(profile),
address: formatAddress(address),
ensName: normalizeEnsName(name),
});
await db.profileContainer.create({
data: {
id: uuidv4(),
id,
nameHash,
profile: JSON.stringify(profile),
address: formatAddress(address),
ensName: normalizeEnsName(name),
},
});
global.logger.debug({
message: 'setUserProfile',
id: uuidv4(),
nameHash,
profile: JSON.stringify(profile),
address: formatAddress(address),
ensName: normalizeEnsName(name),
});

return true;
} catch (e) {
global.logger.warn({
message: `setUserProfile error`,
error: JSON.stringify(e),
});
return false;
}
};

0 comments on commit 6c6b728

Please sign in to comment.