Skip to content

Commit

Permalink
Merge pull request #17 from WalletConnect/fix/sc-wallet
Browse files Browse the repository at this point in the history
fix: fixed sc not working with siwe
  • Loading branch information
JonathanConn authored Aug 11, 2023
2 parents b60b02f + 7197baf commit 6220210
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ DIRECT_URL="postgresql://postgres:[YOUR_DB_PASSWORD]@db.[YOUR_SUPABASE_PROJECT_I
DATABASE_URL="postgresql://postgres:[YOUR_DB_PASSWORD]@db.[YOUR_SUPABASE_PROJECT_ID].supabase.co:6543/postgres?pgbouncer=true"
REDIS_PASSWORD="authpassword"
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PORT=6379
INFURA_API_KEY=
2 changes: 2 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
TF_VAR_redis_host: ${{ secrets.REDIS_HOST }}
TF_VAR_redis_port: ${{ secrets.REDIS_PORT }}
TF_VAR_redis_password: ${{ secrets.REDIS_PASSWORD }}
TF_VAR_infura_api_key: ${{ secrets.INFURA_API_KEY }}
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down Expand Up @@ -103,6 +104,7 @@ jobs:
TF_VAR_redis_host: ${{ secrets.REDIS_HOST }}
TF_VAR_redis_port: ${{ secrets.REDIS_PORT }}
TF_VAR_redis_password: ${{ secrets.REDIS_PASSWORD }}
TF_VAR_infura_api_key: ${{ secrets.INFURA_API_KEY }}
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
REDIS_PASSWORD: ${REDIS_PASSWORD}
REDIS_HOST: ${REDIS_HOST}
REDIS_PORT: ${REDIS_PORT}
INFURA_API_KEY: ${INFURA_API_KEY}
depends_on:
redis:
condition: service_healthy
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"cookie": "^0.5.0",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"ethers": "^5.5.1",
"express": "^4.18.2",
"express-rate-limit": "^6.7.0",
"express-session": "^1.17.3",
Expand Down
15 changes: 8 additions & 7 deletions src/handlers/verify.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Request, Response } from "express";
import { ErrorTypes, SiweMessage } from "siwe";
import { createOrUpdateUser } from "../services/prisma";
import { Request, Response } from 'express';
import { ErrorTypes, SiweMessage } from 'siwe';
import { createOrUpdateUser } from '../services/prisma';
import { ethers } from 'ethers';

const provider = new ethers.providers.InfuraProvider('mainnet', process.env.INFURA_API_KEY);

export const verifyAndSignIn = async (req: Request, res: Response) => {
try {
if (!req.body.message) {
res
.status(422)
.json({ message: "Expected prepareMessage object as body." });
res.status(422).json({ message: 'Expected prepareMessage object as body.' });
return;
}

const message = new SiweMessage(req.body.message);
const fields = await message.validate(req.body.signature);
const fields = await message.validate(req.body.signature, provider);
if (fields.nonce !== req.session.nonce) {
res.status(422).json({
message: `Invalid nonce.`,
Expand Down
1 change: 1 addition & 0 deletions terraform/ecs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ resource "aws_ecs_task_definition" "app_task_definition" {
{ name = "REDIS_PASSWORD", value = var.redis_password },
{ name = "REDIS_HOST", value = var.redis_host },
{ name = "REDIS_PORT", value = var.redis_port },
{ name = "INFURA_API_KEY", value = var.infura_api_key },
],
logConfiguration = {
logDriver = "awslogs",
Expand Down
6 changes: 6 additions & 0 deletions terraform/ecs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ variable "redis_password" {
type = string
sensitive = true
}

variable "infura_api_key" {
type = string
sensitive = true
}

1 change: 1 addition & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ module "ecs" {
redis_host = var.redis_host
redis_port = var.redis_port
redis_password = var.redis_port
infura_api_key = var.infura_api_key

depends_on = [module.redis_global]
}
Expand Down
5 changes: 5 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ variable "redis_password" {
type = string
sensitive = true
}

variable "infura_api_key" {
type = string
sensitive = true
}

0 comments on commit 6220210

Please sign in to comment.