Skip to content

Commit ccc5d1b

Browse files
authored
webhook signature fixed (#328)
* webhook signature fixed * webhook fix
1 parent 18ea2a5 commit ccc5d1b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

docs/3-webhook-guide.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const isValidSignature = (
6565

6666
### Timestamp Verification
6767

68-
The timestamp will be sent as `X-Engine-Timestamp` header in the request. You can verify the timestamp using the below code:
68+
The timestamp will be sent as `x-engine-timestamp` header in the request. You can verify the timestamp using the below code:
6969

7070
```ts
7171
export const isExpired = (
@@ -96,8 +96,8 @@ const WEBHOOK_SECRET = "YOUR_WEBHOOK_AUTH_TOKEN"; // Replace with your secret
9696
app.use(bodyParser.text());
9797

9898
app.post("/webhook", (req, res) => {
99-
const signatureFromHeader = req.header("X-Engine-Signature");
100-
const timestampFromHeader = req.header("X-Engine-Timestamp");
99+
const signatureFromHeader = req.header("x-engine-signature");
100+
const timestampFromHeader = req.header("x-engine-timestamp");
101101

102102
if (!signatureFromHeader || !timestampFromHeader) {
103103
return res.status(401).send("Missing signature or timestamp header");
@@ -178,6 +178,6 @@ The payload sent to the webhook URL will be in the below format:
178178
"sentAtBlockNumber": 40660021,
179179
"blockNumber": 40660026,
180180
"queueId": "1411246e-b1c8-4f5d-9a25-8c1f40b54e55",
181-
"status": "mined"
181+
"status": "mined",
182182
}
183183
```

src/server/utils/webhook.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const generateSignature = (
1616
timestamp: string,
1717
secret: string,
1818
): string => {
19-
const payload = `${timestamp}.${body}`;
19+
const _body = JSON.stringify(body);
20+
const payload = `${timestamp}.${_body}`;
2021
return crypto.createHmac("sha256", secret).update(payload).digest("hex");
2122
};
2223

0 commit comments

Comments
 (0)