Rivisk

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#

ts
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#

EventSent whendata
portfolio.updatedA wallet finishes indexing{ blockHeight, positionCount, valuationCoverageBps }
risk.updatedA new risk snapshot is persisted{ riskSnapshotId, riskLevel, riskScoreBps, healthFactorE4, reportHash }
alert.triggeredA rule crosses into breach{ alertEventId, alertRuleId, metric, operator, threshold, value }
policy.breachedA snapshot breaches the wallet's on-chain policy{ policyBreachEventId, metric, operator, threshold, value }

Envelope#

json
{  "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#

HeaderValue
rivisk-signaturet=<unix seconds>,v1=<hex HMAC-SHA256>
rivisk-event-idThe envelope id
rivisk-event-typeThe event name
rivisk-delivery-attempt1 for the first attempt, then 2, 3…
content-typeapplication/json

Verifying a delivery#

route handler
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 responseWhat Rivisk does
2xxDelivered. Done
408, 429, 5xx, a timeout or a network failureRetries
Any other 4xxDrops 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.