Integrate
Webhooks
Rivisk POSTs a signed JSON event to your endpoint whenever a portfolio or its risk changes. Verify the signature on every delivery and answer 2xx.
Registering an endpoint#
const { id, secret } = await rivisk.webhooks.create( 'https://example.com/rivisk', ['risk.updated', 'alert.triggered'],);// Store `secret` (whsec_…) now. It is never shown again.Takes an API key or a wallet session. The URL must be https; plain http is accepted only for localhost. The secret is encrypted at rest with AES-256-GCM, not hashed, because Rivisk needs it back to sign each delivery.
Events#
| Event | Sent when | data |
|---|---|---|
portfolio.updated | A wallet finishes indexing | { blockHeight, positionCount, valuationCoverageBps } |
risk.updated | A new risk snapshot is persisted | { riskSnapshotId, riskLevel, riskScoreBps, healthFactorE4, reportHash } |
alert.triggered | A rule crosses into breach | { alertEventId, alertRuleId, metric, operator, threshold, value } |
policy.breached | A snapshot breaches the wallet's on-chain policy | { policyBreachEventId, metric, operator, threshold, value } |
Envelope#
{ "id": "3f8a2c1e-…", "type": "risk.updated", "address": "SP10GK6MG2GM7BCVYV7XBHK1JVJDHFDMNBENNBRC3", "createdAt": "2026-09-21T12:00:00.000Z", "data": { "riskLevel": "critical", "riskScoreBps": 9979, "healthFactorE4": 11798, "…": "…" }}id is stable across retries of the same event, so use it to deduplicate.
Headers#
| Header | Value |
|---|---|
rivisk-signature | t=<unix seconds>,v1=<hex HMAC-SHA256> |
rivisk-event-id | The envelope id |
rivisk-event-type | The event name |
rivisk-delivery-attempt | 1 for the first attempt, then 2, 3… |
content-type | application/json |
Verifying a delivery#
import { constructWebhookEvent, SIGNATURE_HEADER } from '@rivisk/sdk'; export async function POST(req: Request) { const raw = await req.text(); // raw body, before JSON.parse let event; try { event = await constructWebhookEvent(raw, req.headers.get(SIGNATURE_HEADER), process.env.RIVISK_WEBHOOK_SECRET!); } catch { return new Response('bad signature', { status: 400 }); } switch (event.type) { case 'risk.updated': /* … */ break; case 'alert.triggered': /* … */ break; } return new Response('ok');}constructWebhookEvent verifies and parses in one step and throws on failure, so an unverified body cannot be used by accident. It uses WebCrypto, so it runs on edge runtimes as well as Node.
Verifying without the SDK#
Compute HMAC-SHA256(secret, `${t}.${rawBody}`), hex-encode it, compare it with v1 in constant time, and reject if t is too far from now.
Retries#
| Your response | What Rivisk does |
|---|---|
| 2xx | Delivered. Done |
| 408, 429, 5xx, a timeout or a network failure | Retries |
| Any other 4xx | Drops it. A permanent rejection is not retried |
Retries back off 30 seconds, 2 minutes, 10 minutes, then 1 hour, so there are at most five attempts before the delivery is dropped. Every attempt is recorded and visible through rivisk.webhooks.list().
Pause an endpoint without deleting it with rivisk.webhooks.setEnabled(id, false). For the endpoints themselves see the REST reference.

