DOCUMENTATION

Hyperodds alerts in Pipedream

Run a Pipedream workflow on the Hyperodds alerts you choose, with the signature checked in a code step.

Set it up

  1. Create a workflow and add the HTTP / Webhook trigger for new requests. Keep the default response.
  2. Copy the endpoint URL Pipedream shows.
  3. In Hyperodds, open Alerts and sign in. Paste the URL on the Webhook card and choose Add webhook. The test message shows up as the trigger's first event.
  4. Save your signing secret as the environment variable HYPERODDS_SIGNING_SECRET, add the Node.js step below, then the steps that use the alert, such as its title and data.edge_pts.

Check the signature

The step stops the workflow when the signature doesn't match or is more than five minutes old:

import { createHmac, timingSafeEqual } from "crypto";

export default defineComponent({
  async run({ steps, $ }) {
    const { headers, body } = steps.trigger.event;
    const [t, ...sigs] = (headers["hyperodds-signature"] ?? "").split(",").map((p) => p.slice(p.indexOf("=") + 1));
    const expected = createHmac("sha256", process.env.HYPERODDS_SIGNING_SECRET)
      .update(`${t}.${JSON.stringify(body)}`)
      .digest("hex");
    const fresh = Math.abs(Date.now() / 1000 - Number(t)) < 300;
    const same = sigs.some((v1) => v1.length === expected.length && timingSafeEqual(Buffer.from(v1), Buffer.from(expected)));
    if (!fresh || !same) return $.flow.exit("Signature didn't match");
    return body;
  },
});

Good to know

Pipedream lowercases header names and parses the JSON body. JSON.stringify of the body gives back the exact bytes Hyperodds signed, because Hyperodds sends compact JSON.

Pipedream answers as soon as a request arrives, so Hyperodds counts an alert as delivered even if a later step fails.

THE PAYLOAD, RETRIES AND OTHER TOOLS

Open a market.
Review the costs.

Compare live prices, settlement rules and the cost of your order.