Skip to content

feat: implement REST API views and HMAC-based webhook authentication for event ingestion#443

Open
Dantama022 wants to merge 3 commits intoSoroScan:mainfrom
Dantama022:feature/webhook-hmac-validation-decorator
Open

feat: implement REST API views and HMAC-based webhook authentication for event ingestion#443
Dantama022 wants to merge 3 commits intoSoroScan:mainfrom
Dantama022:feature/webhook-hmac-validation-decorator

Conversation

@Dantama022
Copy link
Copy Markdown
Contributor

@Dantama022 Dantama022 commented Apr 28, 2026

Webhook HMAC Validation Decorator Implementation

I have implemented a new HMAC validation decorator for SoroScan webhooks. This allows receiver endpoints to verify the authenticity of incoming webhooks from SoroScan.

Changes Made

Decorator Implementation I created decorators.py which contains the webhook_hmac_required decorator.

Extracts contract_id from the JSON payload.
Retrieves the applicable WebhookSubscription secret from the database.
Verifies the X-SoroScan-Signature header (supporting SHA-256 and SHA-1).
Uses hmac.compare_digest to prevent timing attacks.
Sample Endpoint
I added a sample receiver endpoint in views.py and registered it in urls.py.

Endpoint:
POST /api/ingest/webhooks/receiver-example/

Protected by @webhook_hmac_required()
Tests
I created
test_decorators.py
with comprehensive tests for:

Valid SHA-256 and SHA-1 signatures.
Invalid and missing signatures.
Missing contract ID and inactive subscriptions.
Verification Results
Linting and Formatting
Ruff: All checks passed.
Formatting: Applied ruff format to all new and modified files.

Closes #334

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 28, 2026

@Dantama022 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add reusable decorator to validate webhook HMAC signatures

1 participant