diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 94921d904..f69003af6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -24,23 +24,23 @@ jobs: TARGET_HOST: ${{ secrets.STAGING_HOST }} run: | echo "REACT_APP_ADDR_ENS_SUBDOMAIN=.beta-addr.dm3.eth" >> ./.env.react - echo "REACT_APP_BACKEND=http://${{ secrets.STAGING_HOST }}" >> ./.env.react + echo "REACT_APP_BACKEND=http://${{ secrets.STAGING_HOST }}/api" >> ./.env.react echo "REACT_APP_DEFAULT_DELIVERY_SERVICE=beta-ds.dm3.eth" >> ./.env.react - echo "REACT_APP_DEFAULT_SERVICE=http://${{ secrets.STAGING_HOST }}" >> ./.env.react + echo "REACT_APP_DEFAULT_SERVICE=http://${{ secrets.STAGING_HOST }}/api" >> ./.env.react echo "REACT_APP_ETHEREUM_PROVIDER=${{ secrets.REACT_APP_ETHEREUM_PROVIDER }}" >> ./.env.react - echo "REACT_APP_PROFILE_BASE_URL=http://dm3-beta2-resolver.herokuapp.com" >> ./.env.react - echo "REACT_APP_RESOLVER_BACKEND=http://dm3-beta2-resolver.herokuapp.com" >> ./.env.react + echo "REACT_APP_PROFILE_BASE_URL=http://${{ secrets.STAGING_HOST }}/api" >> ./.env.react + echo "REACT_APP_RESOLVER_BACKEND=http://${{ secrets.STAGING_HOST }}/resolver-handler" >> ./.env.react echo "REACT_APP_USER_ENS_SUBDOMAIN=.beta-user.dm3.eth" >> ./.env.react echo "REACT_APP_WALLET_CONNECT_PROJECT_ID=${{ secrets.REACT_APP_WALLET_CONNECT_PROJECT_ID }}" >> ./.env.react + cat ./.env.react >> ./.env echo "RESOLVER_ADDR=0x45F7Ed7d05c563D408898A80d9C705CC3328D2EF" >> ./.env - echo "WEB_PORT=80" >> ./.env echo "SIGNING_PUBLIC_KEY=${{ secrets.SIGNING_PUBLIC_KEY }}" >> ./.env echo "SIGNING_PRIVATE_KEY=${{ secrets.SIGNING_PRIVATE_KEY }}" >> ./.env echo "SIGNER_PRIVATE_KEY=${{ secrets.SIGNER_PRIVATE_KEY }}" >> ./.env echo "SPAM_PROTECTION=${{ secrets.SPAM_PROTECTION }}" >> ./.env echo "ENCRYPTION_PUBLIC_KEY=${{ secrets.ENCRYPTION_PUBLIC_KEY }}" >> ./.env echo "ENCRYPTION_PRIVATE_KEY=${{ secrets.ENCRYPTION_PRIVATE_KEY }}" >> ./.env - echo "RPC=${{ secrets.RPC }}" >> ./.env + echo "RPC=${{ secrets.STAGING_RPC }}" >> ./.env envsubst '${SSL_CERTIFICATE_BASE_LOC} ${TLS_CERTIFICATE_LOCATION} ${TARGET_HOST}' < ./docker/nginx.conf > ./nginx.conf - name: Build docker image run: | @@ -53,10 +53,11 @@ jobs: rsync -avz -e 'ssh -i ./ssh-key' ./dm3-backend.tar app@${{ secrets.STAGING_HOST }}:/home/app/dm3 rsync -avz -e 'ssh -i ./ssh-key' ./nginx.conf app@${{ secrets.STAGING_HOST }}:/home/app/dm3 rsync -avz -e 'ssh -i ./ssh-key' ./docker/docker-compose.yml app@${{ secrets.STAGING_HOST }}:/home/app/dm3 - - name: Load image + - name: Load docker image run: | ssh -i ./ssh-key app@${{ secrets.STAGING_HOST }} "\ - cd dm3 && docker load -i dm3-backend.tar" + cd dm3 && docker load -i dm3-backend.tar; \ + rm dm3-backend.tar" - name: Start run: | ssh -i ./ssh-key app@${{ secrets.STAGING_HOST }} "\ diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 0a26c66a1..f7160baee 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,15 +1,18 @@ version: "3.1" services: - # nginx: - # container_name: nginx - # image: nginx:latest - # restart: always - # volumes: - # - ./nginx.conf:/etc/nginx/nginx.conf - # ports: - # - "80:80" - # - "443:443" + nginx: + container_name: nginx + image: nginx:latest + restart: always + depends_on: + - offchain-resolver + - web + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + ports: + - "80:80" + - "443:443" backend: image: dm3-backend @@ -23,6 +26,9 @@ services: ENCRYPTION_PUBLIC_KEY: ${ENCRYPTION_PUBLIC_KEY} ENCRYPTION_PRIVATE_KEY: ${ENCRYPTION_PUBLIC_KEY} RPC: ${RPC} + PORT: 8081 + ports: + - '8081:8081' db: image: redis @@ -44,7 +50,7 @@ services: - offchain-resolver-db environment: DATABASE_URL: postgresql://postgres:example@offchain-resolver-db:5432 - + PORT: 8082 ports: - '8082:8082' @@ -63,7 +69,7 @@ services: REACT_APP_WALLET_CONNECT_PROJECT_ID: ${REACT_APP_WALLET_CONNECT_PROJECT_ID} RESOLVER_ADDR: ${RESOLVER_ADDR} ports: - - '${WEB_PORT}:8080' + - '8080:8080' ccip-resolver: image: dm3org/ccip-resolver:v0.2.2 @@ -75,9 +81,9 @@ services: LOG_LEVEL: debug CONFIG: | { - "0x5e0F81D5ca51D309B3A046FAeea70C4C70Df8079": { + "0x4283441191a27513c2160c1e7BC1aa02Ab84D900": { "type": "signing", - "handlerUrl": "http://offchain-resolver:8081" + "handlerUrl": "http://offchain-resolver:8082" } } PORT: 8181 diff --git a/docker/nginx.conf b/docker/nginx.conf index d8e980104..871d1d59e 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -4,7 +4,8 @@ events { http { keepalive_timeout 65; - + limit_req_zone $binary_remote_addr zone=standardlimit:10m rate=3r/s; + limit_req_zone $binary_remote_addr zone=legacylimit:10m rate=2r/s; server { listen 80; @@ -21,8 +22,52 @@ http { proxy_redirect off; } + location /resolver { + rewrite ^/resolver(.*)$ $1 break; + limit_req zone=standardlimit burst=50; + proxy_pass http://ccip-resolver:8181; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_redirect off; + } - } + location /resolver-handler { + rewrite ^/resolver-handler(.*)$ $1 break; + limit_req zone=standardlimit burst=50; + proxy_pass http://offchain-resolver:8082; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_redirect off; + } - + location /api { + rewrite ^/api(.*)$ $1 break; + limit_req zone=standardlimit burst=50; + proxy_pass http://backend:8081; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_redirect off; + } + + location /socket.io { + proxy_pass http://backend:8081/socket.io/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_redirect off; + proxy_set_header Host $host; + } + } } \ No newline at end of file diff --git a/packages/lib/offchainResolver-api/package.json b/packages/lib/offchainResolver-api/package.json index 4c373ed40..1e0d73a1e 100644 --- a/packages/lib/offchainResolver-api/package.json +++ b/packages/lib/offchainResolver-api/package.json @@ -11,7 +11,7 @@ } }, "dependencies": { - "axios": "^1.3.4", + "axios": "^1.5.0", "dm3-lib-profile": "^0.2.0", "ethers": "5.7.2" }, @@ -25,7 +25,7 @@ "jest": "^28.1.1", "ts-jest": "^28.0.4", "ts-json-schema-generator": "^0.98.0", - "typescript": "^4.4.2" + "typescript": "^4.7.0" }, "scripts": { "build": "yarn tsc --declaration ", diff --git a/packages/lib/offchainResolver-api/src/index.ts b/packages/lib/offchainResolver-api/src/index.ts index 6ac6cc938..8e0f24b34 100644 --- a/packages/lib/offchainResolver-api/src/index.ts +++ b/packages/lib/offchainResolver-api/src/index.ts @@ -79,7 +79,7 @@ export async function getNameForAddress( address: string, offchainResolverUrl: string, ): Promise { - const url = `${offchainResolverUrl}/name/${formatAddress(address)}`; + const url = `${offchainResolverUrl}/profile/name/${formatAddress(address)}`; try { const { data } = await axios.get(url); return data.name; diff --git a/packages/lib/offchainResolver-api/tsconfig.json b/packages/lib/offchainResolver-api/tsconfig.json index b8721eeaa..000fc07f5 100644 --- a/packages/lib/offchainResolver-api/tsconfig.json +++ b/packages/lib/offchainResolver-api/tsconfig.json @@ -9,8 +9,8 @@ "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, - "module": "CommonJS", - "moduleResolution": "node", + "module": "node16", + "moduleResolution": "node16", "resolveJsonModule": true, "isolatedModules": true, "outDir": "dist", diff --git a/packages/lib/profile/package.json b/packages/lib/profile/package.json index 8ce9fcabe..8e6d4b834 100644 --- a/packages/lib/profile/package.json +++ b/packages/lib/profile/package.json @@ -46,6 +46,6 @@ "test": "jest --coverage --transformIgnorePatterns 'node_modules/(?!(dm3-lib-\\w*)/)'" }, "files": [ - "dist" + "dist" ] } diff --git a/packages/messenger-demo/config-overrides.js b/packages/messenger-demo/config-overrides.js index 50ade1799..979eeb035 100644 --- a/packages/messenger-demo/config-overrides.js +++ b/packages/messenger-demo/config-overrides.js @@ -27,5 +27,17 @@ module.exports = function override(config) { Buffer: ['buffer', 'Buffer'], }), ]); + + config.module.rules = config.module.rules.map((rule) => { + if (rule.oneOf instanceof Array) { + rule.oneOf[rule.oneOf.length - 1].exclude = [ + /\.(js|mjs|jsx|cjs|ts|tsx)$/, + /\.html$/, + /\.json$/, + ]; + } + return rule; + }); + return config; }; diff --git a/packages/messenger-demo/tsconfig.json b/packages/messenger-demo/tsconfig.json index c0555cbc6..a2ff23e26 100644 --- a/packages/messenger-demo/tsconfig.json +++ b/packages/messenger-demo/tsconfig.json @@ -10,7 +10,7 @@ "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "module": "esnext", - "moduleResolution": "node", + "moduleResolution": "node16", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, diff --git a/packages/messenger-widget/src/components/SignIn/bl.tsx b/packages/messenger-widget/src/components/SignIn/bl.tsx index 9ff8dc91c..456da9c5b 100644 --- a/packages/messenger-widget/src/components/SignIn/bl.tsx +++ b/packages/messenger-widget/src/components/SignIn/bl.tsx @@ -648,8 +648,10 @@ async function connectOffchainAccount(connection: Connection, address: string) { * Otherwise we use the addr_ens_subdomain */ const ensName = - (await getNameForAddress(address, connection.defaultServiceUrl)) ?? - getAliasForAddress(address); + (await getNameForAddress( + address, + process.env.REACT_APP_RESOLVER_BACKEND as string, + )) ?? getAliasForAddress(address); //We're trying to get the profile from the delivery service const profile = await getUserProfile(connection.provider!, ensName); diff --git a/packages/messenger-widget/src/views/Home/Home.tsx b/packages/messenger-widget/src/views/Home/Home.tsx index acfef22cc..b1cb61951 100644 --- a/packages/messenger-widget/src/views/Home/Home.tsx +++ b/packages/messenger-widget/src/views/Home/Home.tsx @@ -9,7 +9,7 @@ import { RainbowKitProvider, } from '@rainbow-me/rainbowkit'; import { configureChains, createConfig, WagmiConfig } from 'wagmi'; -import { mainnet } from 'wagmi/chains'; +import { mainnet, goerli } from 'wagmi/chains'; import { metaMaskWallet, rainbowWallet, @@ -23,7 +23,7 @@ import { ConfigureProfile } from '../../components/ConfigureProfile/ConfigurePro export function Home(props: Dm3Props) { const { chains, publicClient } = configureChains( - [mainnet], + [goerli], [ jsonRpcProvider({ rpc: () => ({ diff --git a/packages/messenger-widget/tsconfig.json b/packages/messenger-widget/tsconfig.json index 6fbaa7bbf..76e010f09 100644 --- a/packages/messenger-widget/tsconfig.json +++ b/packages/messenger-widget/tsconfig.json @@ -14,7 +14,7 @@ "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "module": "esnext", - "moduleResolution": "node", + "moduleResolution": "node16", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, diff --git a/packages/offchain-resolver/src/http/handleCcipRequest/handleCcipRequest.ts b/packages/offchain-resolver/src/http/handleCcipRequest/handleCcipRequest.ts index be2d1d333..fed098891 100644 --- a/packages/offchain-resolver/src/http/handleCcipRequest/handleCcipRequest.ts +++ b/packages/offchain-resolver/src/http/handleCcipRequest/handleCcipRequest.ts @@ -18,10 +18,27 @@ export async function handleCcipRequest( return ethers.utils.defaultAbiCoder.encode(['string'], [profile]); case 'addr(bytes32)': req.app.locals.logger.info('Reading addr(bytes32))'); - return await handleAddr(req.app.locals.db, request); + const addrProfile = await handleAddr(req.app.locals.db, request); + if (!addrProfile) { + return null; + } + return ethers.utils.defaultAbiCoder.encode( + ['string'], + [addrProfile], + ); case 'addr(bytes32,uint256)': req.app.locals.logger.info('Reading addr(bytes32,uint256))'); - return await handleAddr(req.app.locals.db, request); + const addrProfileCoinType = await handleAddr( + req.app.locals.db, + request, + ); + if (!addrProfileCoinType) { + return null; + } + return ethers.utils.defaultAbiCoder.encode( + ['string'], + [addrProfileCoinType], + ); default: return null; diff --git a/packages/offchain-resolver/src/http/resolverEndpoint.test.ts b/packages/offchain-resolver/src/http/resolverEndpoint.test.ts index 1285017a7..7a67cb1c6 100644 --- a/packages/offchain-resolver/src/http/resolverEndpoint.test.ts +++ b/packages/offchain-resolver/src/http/resolverEndpoint.test.ts @@ -94,11 +94,16 @@ describe('Resolver Endpoint', () => { 'resolve', [encodeEnsName(ensName), innerCall], ); - const { body, status } = await request(ccipApp) + const { text, status } = await request(ccipApp) .get(`/${ethers.constants.AddressZero}/${outerCall}`) .send(); expect(status).to.equal(200); - expect(body.response).to.equal( + + const [decoded] = ethers.utils.defaultAbiCoder.decode( + ['string'], + text, + ); + expect(decoded).to.equal( '0x25A643B6e52864d0eD816F1E43c0CF49C83B8292', ); }); @@ -127,7 +132,7 @@ describe('Resolver Endpoint', () => { 'resolve', [encodeEnsName(ensName), innerCall], ); - const { body, status } = await request(ccipApp) + const { text, status } = await request(ccipApp) .get(`/${ethers.constants.AddressZero}/${outerCall}`) .send(); @@ -135,7 +140,7 @@ describe('Resolver Endpoint', () => { const [decoded] = ethers.utils.defaultAbiCoder.decode( ['string'], - body.response, + text, ); expect(decoded).to.equal('test'); }); @@ -185,13 +190,13 @@ describe('Resolver Endpoint', () => { 'resolve', [encodeEnsName(name), innerCall], ); - const { body, status } = await request(ccipApp) + const { text, status } = await request(ccipApp) .get(`/${ethers.constants.AddressZero}/${outerCall}`) .send(); const [decoded] = ethers.utils.defaultAbiCoder.decode( ['string'], - body.response, + text, ); expect(status).to.equal(200); diff --git a/packages/offchain-resolver/src/http/resolverEndpoint.ts b/packages/offchain-resolver/src/http/resolverEndpoint.ts index b67ce6575..b10af8f1d 100644 --- a/packages/offchain-resolver/src/http/resolverEndpoint.ts +++ b/packages/offchain-resolver/src/http/resolverEndpoint.ts @@ -1,4 +1,4 @@ -import { logError } from 'dm3-lib-shared'; +import { logError, logWarning } from 'dm3-lib-shared'; import express from 'express'; import { handleCcipRequest } from './handleCcipRequest/handleCcipRequest'; import { WithLocals } from './types'; @@ -30,11 +30,10 @@ export function resolverEndpoint() { ); if (!response) { - logError('Record not found'); - - res.status(404).send({ message: 'Record not found' }); + logWarning('Record not found'); + res.status(200).send('0x'); } else { - res.status(200).send({ response }); + res.status(200).send(response); } } catch (e) { req.app.locals.logger.warn((e as Error).message); diff --git a/yarn.lock b/yarn.lock index 7230635c5..6ae20607e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7060,6 +7060,17 @@ __metadata: languageName: node linkType: hard +"axios@npm:^1.5.0": + version: 1.5.0 + resolution: "axios@npm:1.5.0" + dependencies: + follow-redirects: ^1.15.0 + form-data: ^4.0.0 + proxy-from-env: ^1.1.0 + checksum: e7405a5dbbea97760d0e6cd58fecba311b0401ddb4a8efbc4108f5537da9b3f278bde566deb777935a960beec4fa18e7b8353881f2f465e4f2c0e949fead35be + languageName: node + linkType: hard + "axobject-query@npm:^3.1.1": version: 3.2.1 resolution: "axobject-query@npm:3.2.1" @@ -10420,14 +10431,14 @@ __metadata: "@types/node": ^16.7.13 "@types/uuid": ^8.3.4 "@types/whatwg-encoding": ^2.0.0 - axios: ^1.3.4 + axios: ^1.5.0 axios-mock-adapter: ^1.21.2 dm3-lib-profile: ^0.2.0 ethers: 5.7.2 jest: ^28.1.1 ts-jest: ^28.0.4 ts-json-schema-generator: ^0.98.0 - typescript: ^4.4.2 + typescript: ^4.7.0 languageName: unknown linkType: soft @@ -23966,7 +23977,7 @@ __metadata: languageName: node linkType: hard -"typescript@npm:^4.4.2, typescript@npm:^4.7.3, typescript@npm:~4.9.3": +"typescript@npm:^4.4.2, typescript@npm:^4.7.0, typescript@npm:^4.7.3, typescript@npm:~4.9.3": version: 4.9.5 resolution: "typescript@npm:4.9.5" bin: @@ -23986,7 +23997,7 @@ __metadata: languageName: node linkType: hard -"typescript@patch:typescript@^4.4.2#~builtin, typescript@patch:typescript@^4.7.3#~builtin, typescript@patch:typescript@~4.9.3#~builtin": +"typescript@patch:typescript@^4.4.2#~builtin, typescript@patch:typescript@^4.7.0#~builtin, typescript@patch:typescript@^4.7.3#~builtin, typescript@patch:typescript@~4.9.3#~builtin": version: 4.9.5 resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin::version=4.9.5&hash=289587" bin: