For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to generate the x-signature

For every charge request notification, the Coda system will carry out a verification process to ensure its integrity. Coda will compare the x-signature header in the request with the signature of the request body. If the signatures do not match, our system will reject the request and return error. This process is to ensure the integrity and security of our charge requests, reducing the risk of any payload being tampered.

Generating the signature

The code snippet below is a sample code for generating signatures. Steps are also explained further below.

public String generateSignature(@Nonull String requestTime, @Nonull String
requestBody, @Nonull String signingSecret) {
// Construct signature message
Coda Payments Pte. Ltd. Confidential
20
String message = String.format("%s.%s"
, requestTime, requestBody);
// using commons-codec:commons-codec:1.16.0 library
return new HmacUtils("HmacSHA512"
, signingSecret).hmacHex(message);
}

Steps:

  1. Append the values listed below as a string as follows: "{requestTime}.{requestBody}". Example:

RequestTime = 1700486578888
RequestBody = {"type":"charge.status.succeeded","data":{"id":"evt_sg18c678ba5af0019"}}
String message =
"1700486578888.{"type":"charge.status.succeeded","data":{"id":"evt_sg18c678ba5af0019"}}"
  1. Calculate the HMAC-SHA512 hash of the string using your signing secret as the key. The signing secret is a pre-shared key configured for your webhook endpoint. The HMAC-SHA512 algorithm will return a byte array value.

    Example:

  1. Convert the byte array value to a hexadecimal string. The result will be like:

    "a0c2d905877e9282a3954743f918f98f991c144020c535458c84767b6e146cf8cad4433accc2047258f6d5c4be07264596cfc58cfeea9e8551090f26e828e6bd"

Verifying the Signature

  1. Extract the X-Request-Time and X-Signature headers from the webhook request

  2. Get the raw request body as a string (before any parsing)

  3. Generate the expected signature following Steps 1-3 above

  4. Compare the generated signature with the X-Signature header value using a constant-time comparison

  5. Verify that the X-Request-Time is within an acceptable time window (e.g., within last 5 minutes) to prevent replay attacks

Last updated

Was this helpful?