Skip to main content

Webhooks

A webhook is a URL in your system that Hovi calls when something happens, for example when a holder accepts a credential or shares a proof. Webhooks belong to an organization, so you get the events for that organization without having to keep asking the API.

Before you start​

Make sure you have:

  1. An API key for your ecosystem.
  2. An organization. Its ID goes in the x-organization-id header of every webhook request.
  3. An HTTPS URL in your system that can receive POST requests.

Steps​

This example adds a webhook in the EU Digital Identity ecosystem. The steps are the same in every ecosystem.

  1. Open the API Reference and select the EU Digital Identity Ecosystem API under Hovi Connect API.
  2. Go to the Webhooks section.
  3. Open POST - Add Webhook and click Test Request.
  4. Enter your API key as a Bearer Token, enter your organization ID and your webhookUrl, and click Send.

The response includes a webhookId and a webhookSecret.

note

The webhookSecret is shown only once: when you add the webhook and when you rotate its secret. Store it safely. You need it to verify webhook signatures.

Manage your webhooks​

EndpointWhat it does
POST - Add WebhookAdds a webhook URL and returns its webhookId and webhookSecret.
GET - Get All WebhooksLists your organization's webhooks, or finds one by webhookId. The secret isn't included.
DELETE - Remove WebhooksDeletes a webhook by its webhookId.
POST - Rotate Webhook SecretCreates a new secret for a webhook and returns it. The old secret stops working.

Verify webhook signatures​

Check the signature of every webhook request to make sure it really comes from Hovi. Without this check, anyone who knows your webhook URL could send you fake events.

Every signed request has two headers:

HeaderValue
x-webhook-timestampWhen the request was created, in Unix seconds.
x-webhook-signaturesha256= followed by the hex HMAC-SHA256 of {timestamp}.{rawBody}, using your webhookSecret as the key.

To verify a request:

  1. Read both headers and the raw request body, exactly as received. Reject the request if any of them is missing.
  2. Reject the request if the timestamp is too old. We recommend a window of five minutes.
  3. Compute the HMAC-SHA256 of {timestamp}.{rawBody} with your webhook secret, as a hex string, and add sha256= in front.
  4. Compare it with x-webhook-signature using a timing-safe comparison. If they don't match, return 401 Unauthorized and ignore the event.

For example, in Node.js with Express:

const crypto = require('crypto');
const express = require('express');

const app = express();
const WEBHOOK_SECRET = process.env.HOVI_WEBHOOK_SECRET;

// Keep the raw body: parsing and re-serializing the JSON breaks the signature.
app.post('/webhooks/hovi', express.raw({ type: 'application/json' }), (req, res) => {
const timestamp = req.get('x-webhook-timestamp');
const signature = req.get('x-webhook-signature');
const rawBody = req.body.toString('utf8');

if (!timestamp || !signature || !rawBody) return res.sendStatus(401);

// Reject requests older than five minutes.
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return res.sendStatus(401);

const expected =
'sha256=' +
crypto.createHmac('sha256', WEBHOOK_SECRET).update(`${timestamp}.${rawBody}`).digest('hex');

const received = Buffer.from(signature);
const computed = Buffer.from(expected);
if (received.length !== computed.length || !crypto.timingSafeEqual(received, computed)) {
return res.sendStatus(401);
}

const event = JSON.parse(rawBody);
// Handle the event here.
res.sendStatus(200);
});

Events​

For EU Digital Identity, cheqd and Indicio, the request body has a type and a payload:

{ "type": "credential-exchange", "payload": { "…": "…" } }

Event types include:

typeWhat it's about
did-exchangeA connection (cheqd and Indicio)
credential-exchangeA credential offer (cheqd and Indicio)
proof-exchangeA verification request (cheqd and Indicio)
openid-issuance-sessionA credential offer (EU Digital Identity)
openid-verification-sessionA verification request (EU Digital Identity)

The payload of each event, including the events for Microsoft Entra and Polygon, is described in the Webhook Events section of your ecosystem's API reference, for example EU Digital Identity.

What happens next​

Use the IDs in each event, such as credentialExchangeId or proofExchangeId, to match it to the offer or request you sent. To receive events for a user's cloud wallet instead, see Cloud Wallet webhooks.