> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chip-in.asia/llms.txt
> Use this file to discover all available pages before exploring further.

# Validating Webhooks

> Learn how to verify the authenticity of CHIP Send webhook payloads.

To ensure that the webhook notifications you receive are sent by CHIP and have not been tampered with, you should validate the signature included in each request.

## Signature Header

Each webhook delivery request includes an `X-Signature` header field. This field contains a base64-encoded RSA PKCS#1 v1.5 signature of the SHA512 digest of the request body buffer.

## Obtaining the Public Key

Unlike CHIP Collect, CHIP Send provides a dedicated public key for each webhook. You can obtain the public key by retrieving the webhook details via the [Retrieve a Webhook](https://docs.chip-in.asia/chip-send/api-reference/webhooks/retrieve.md) API.

The `public_key` field in the response contains the PEM-encoded RSA public key.

## Verification Steps

1. **Retrieve the Payload**: Get the raw request body (buffer) of the webhook notification.
2. **Get the Signature**: Extract the value of the `X-Signature` header and base64-decode it.
3. **Verify**: Use the RSA public key to verify the signature against the SHA512 digest of the raw request body.

## Code Examples

### Ruby

```ruby theme={null}
require 'openssl'
require 'base64'

# webhook_public_key: The PEM-encoded public key from the Webhook object
# x_signature_header: The value of the X-Signature header
# request_body: The raw JSON body of the request

public_key = OpenSSL::PKey::RSA.new(webhook_public_key)
signature = Base64.decode64(x_signature_header)
digest = OpenSSL::Digest::SHA512.new

is_valid = public_key.verify(digest, signature, request_body)

if is_valid
  puts "Signature is valid"
else
  puts "Signature is invalid"
end
```

### PHP

```php theme={null}
<?php

// $webhook_public_key: The PEM-encoded public key from the Webhook object
// $x_signature_header: The value of the X-Signature header
// $request_body: The raw JSON body of the request

$public_key = openssl_pkey_get_public($webhook_public_key);
$signature = base64_decode($x_signature_header);

$is_valid = openssl_verify($request_body, $signature, $public_key, OPENSSL_ALGO_SHA512);

if ($is_valid === 1) {
    echo "Signature is valid";
} elseif ($is_valid === 0) {
    echo "Signature is invalid";
} else {
    echo "Error checking signature";
}
```

### Node.js

```js theme={null}
const crypto = require('crypto');

// Keep the raw body: express.json() parses it and the signature will never match.
app.post('/chip-webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = Buffer.from(req.get('X-Signature') || '', 'base64');

  const is_valid = crypto.verify('sha512', req.body, webhook_public_key, signature);
  if (!is_valid) return res.sendStatus(401);

  const payload = JSON.parse(req.body.toString('utf8'));
  res.sendStatus(200);
});
```

### Python

```python theme={null}
import base64, json
from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding

public_key = serialization.load_pem_public_key(webhook_public_key.encode())
signature = base64.b64decode(x_signature_header)

try:
    public_key.verify(signature, request_body, padding.PKCS1v15(), hashes.SHA512())
    is_valid = True
except InvalidSignature:
    is_valid = False
```

`verify()` raises instead of returning a boolean — catch `InvalidSignature` so the result is the same pass/fail shape as the other examples.

> [!NOTE]
>
> Live deliveries are compact JSON, one line with no whitespace; the samples on [Event Types and Payloads](https://docs.chip-in.asia/chip-send/api-reference/webhooks/events.md) are pretty-printed for reading. Verify and parse the bytes you received, never a re-serialised copy.

## Test Fixture

Before going live, run your verifier against this fixture. The three pieces belong together: the signature is over **exactly** the body below, as bytes (387 bytes, no trailing newline).

`X-Signature` header value:

```
pSorKUKouXdoUgspzqDTtIGxl/b7dQbH04UV569sO1vCwTqmDyDhKGHOE4BuXck9HBLiLQVivDFZHcrVUv6OVQJa2GPO2ULghL9aL2KptqjKTd8Gl/G4TwGWzmwdm15WxzzunyBxXLuNxdyPYRCrja68ztNPXnkvno+AenVZVoKheAlGNDqmJd5E3Pztk38BKrDBTPkpU3YMKNvdEjH1qEOr53tBl9xGGf10MA2XxmeYZi8fKnd4J6xvOxBA/zEgXUr5BFZXvNAvMzxDkFk4CpLKjmNn15YkrLBS3yQ+SJOK5sNFboUsrJ9hGZhG36DJfIPfuAPXWU+7XrQSrhQDlA==
```

Public key (PEM):

```
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAszvfKDOe2l/LVUJ9C2gJ
hY6XK+OsGmpAcHGJKgBe1qckTcj58Z5jNjY+SaljWWeZGl9UV0Kk/uUZRpGWUC39
H75TSb3hu9tfacHhrw2kRoKzNefil4/Exx5fyggqHH8m51QItfcoUqaMR6tA7hxv
u4tbX92EmRxEuYMAnVkfri3kssd6STv0o6LkD7qg1FJ3H23YbUpPvgpvxkY8KZS9
rJ5xmo3VHXb4yPjrNVF/sMRssg7Gc+uPjTFISvT+W86tPWhbp2+s1eV8bwaiN0Rg
rHSOiXTpO9+H4biUfp9kbluobtFB1vPNOnYgCDdr1uApuU5KeqEupEbvxYkpXS4h
AQIDAQAB
-----END PUBLIC KEY-----
```

Raw request body:

```json theme={null}
{
  "id": 1042,
  "status": "verified",
  "account_number": "1234567890",
  "bank_code": "MBBEMYKL",
  "group_id": 17,
  "name": "ACME TRADING SDN BHD",
  "reference": "payroll-main",
  "created_at": "2026-11-11T02:14:07.512Z",
  "is_debiting_account": false,
  "is_crediting_account": false,
  "updated_at": "2026-11-11T02:14:09.884Z",
  "deleted_at": null,
  "rejection_reason": null
}
```

Expected: your verifier returns `true`. Change one byte of the body (for example `"verified"` to `"rejected"`) and it must return `false` — if it still returns `true`, the code is not verifying.

This key pair exists only for this fixture. It is not a CHIP key, no delivery is ever signed with it, and it must never be used to accept real traffic. Live deliveries are verified against the `public_key` returned by [Retrieve a Webhook](https://docs.chip-in.asia/chip-send/api-reference/webhooks/retrieve.md).

> [!NOTE]
>
> CHIP is not responsible for any financial losses incurred as a result of failing to implement payload signature verification.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.