Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix web backend to redirect DKG setup requests #153

Merged
merged 3 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ Return:

```json
{
"ElectionID": "<hex encoded>"
"ElectionID": "<hex encoded>",
"Proxy:": ""
}
```

Expand All @@ -351,7 +352,8 @@ Return:

```json
{
"Action": "setup"
"Action": "setup",
"Proxy:": ""
}
```

Expand Down
18 changes: 14 additions & 4 deletions web/backend/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,24 @@ function sendToDela(dataStr: string, req: express.Request, res: express.Response
// we strip the `/api` part: /api/election/xxx => /election/xxx
let uri = process.env.DELA_NODE_URL + req.baseUrl.slice(4);

// in case this is a DKG init request, we must extract the proxy addr and
// update the payload.
const regex = /\/evoting\/services\/dkg\/actors$/;
if (uri.match(regex)) {
// in case this is a DKG init request, we must also update the payload.
const dkgInitRegex = /\/evoting\/services\/dkg\/actors$/;
if (uri.match(dkgInitRegex)) {
const dataStr2 = JSON.stringify({ ElectionID: req.body.ElectionID });
payload = getPayload(dataStr2);
}

// in case this is a DKG setup request, we must update the payload.
const dkgSetupRegex = /\/evoting\/services\/dkg\/actors\/.*$/;
if (uri.match(dkgSetupRegex)) {
const dataStr2 = JSON.stringify({ Action: req.body.Action });
payload = getPayload(dataStr2);
}

// in case this is a DKG init or setup request, we must extract the proxy addr
if (uri.match(dkgInitRegex) || uri.match(dkgSetupRegex)) {
const proxy = req.body.Proxy;

if (proxy === undefined) {
res.status(400).send('proxy undefined in body');
return;
Expand Down