Skip to content

Secure Webhooks: more examples #8

@mmahut

Description

@mmahut

Secure webhooks page needs more examples in different languages.

Lite version of the example, showcasing minimal web app with the signature verification can be contributed to https://blockfrost.dev/docs/start-building/webhooks/webhooks-signatures#using-sdk.

The whole example (with printing info from the received event payload) can be contributed to https://blockfrost.dev/docs/start-building/webhooks/using-webhooks#process-a-webhook-request

Signature Verification

The example has to showcase how to implement webhook endpoint including webhook signature verification. If the function for verification (named verifyWebhookSignature or verify_webhook_signature depending on the language conventions) is missing in the Blockfrost SDK for the language you need to implement it and open PR for the SDK.
For full list of all available SDKs see https://blockfrost.dev/docs/sdks.

Basics of the signature verification are explained here https://blockfrost.dev/docs/start-building/webhooks/webhooks-signatures#verifying-the-signature-manually, but always crosscheck with reference implementations.

Reference implementation of the signature verification:

The function accepts 4 parameters (naming borrowed from Python implementation):

  • request_body: whole request's body in bytes (or stringified body, depending which will be easier for users in given language and its most popular web frameworks)
  • signature_header: Blockfrost-Signature header that will be included in every webhook request
  • secret: webhook auth token that is used to sign the request (user will find it in Blockfrost Dashboard)
  • timestamp_tolerance_seconds: optional, default 600s. Time window for checking the validity of the signature. If the computed signature matches the signature received in the request, but the timestamp is too old, the signature is considered to be invalid.

If the signature is valid then the function returns True. Otherwise It throws SignatureVerificationError with various error messages (see reference implementations for more details). The error object has additional fields header and request_body for debugging purposes.

Use test vectors from reference implementation's fixtures in your own unit tests to verify the correctness of your implementation.
https://github.com/blockfrost/blockfrost-python/blob/master/tests/test_helpers.py

Webhook Endpoint

The example of using webhooks should implement /webhook endpoint for processing events sent by Blockfrost Secure Webhooks. It has to showcase verifying the signature (described above), parsing the event payload (while printing basic information into the console) and return status code 200 on success. The web app should be exposed on port 6666.

For reference examples see https://blockfrost.dev/docs/start-building/webhooks/using-webhooks#process-a-webhook-request

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions