Signatures in API
Signatures
The pawaPay API is secured by the API token as explained in Authentication.
To add a second layer of security, you can optionally sign your financial requests to us - deposit, payout and refund requests.
In this case, pawaPay will only accept financial requests that have been signed by you. To utilize this additional capability, you should provide your public key in the pawaPay Dashboard and enable this feature.
Read how to do that from the pawaPay Dashboard Docs. This ensures that even if your API token leaks, only you can initiate financial requests with pawaPay.
If configured, pawaPay will also send callbacks to your callback URLs with the final status of your payment.
Your network team can whitelist the pawaPay platform IP addresses for these callback URLs.
Additionally, you can also enable pawaPay to sign those callbacks. You can then validate the signature that is included in the header of the callback to ensure that callbacks are in fact coming from pawaPay and have not been tampered with.
Signatures in financial requests
Financial requests are requests sent to the pawaPay Merchant API to move funds. These include deposits, payouts, bulk payouts and refunds.
The implementation of signatures in pawaPay is based on the standard described in RFC-9421.
When creating the financial request to send to the pawaPay Merchant API, you should create a Content-Digest, sign the request and add Signature and Signature-Input headers.
You can find sample node code for signing your requests from Github.
Hash the request body
For generating the Content-Digest
you can use either SHA-256 or SHA-512 algorithm.
The Content-Digest
should be created from the request body.
Having the request body hashed and available as a header allows verification that the content of the request has not been tampered with.
You can read more about it here.
Create the signature base
For creating the content that will be signed, you need to create a signature base. This should include all details of the request that should be verifiable. We recommend including at least the following Derived Components.
- @method
- @authority
- @path
Also the following headers should be included into the request and the signature base.
- Signature-Date
- Content-Digest
- Content-Type
Let’s take the following example request to initiate a deposit.
The signature base for the above request would be the following.
You can read more about creating the signature base here.
Create the signature
You can use your private key now to sign the signature base. You can use one of the following algorithms:
- RSASSA-PSS Using SHA-512
- RSASSA-PKCS1-v1_5 Using SHA-256
- ECDSA Using Curve P-256 DSS and SHA-256
- ECDSA Using Curve P-384 DSS and SHA-384
You can read more about creating the signature here.
Include Signature and Signature-Input headers
Having generated the signature, you should include it into the Signature
header of the request.
You also need to create the Signature-Input
header which outlines the parameters and their order that were used to generate the Signature
as well as metadata about the signature.
The metadata should include:
- The used algorithm (
alg
) - The date the signature was created (
created
) - The expiration date of the keypair (
expires
) - The id of the key (
keyid
)
This allows pawaPay to validate the basis for the signature against your public key. Read more about it here.
The final request that can be sent to pawaPay would look as follows.
The pawaPay API would respond by accepting the payment for processing with the following response (headers irrelevant for signatures are omitted).
Make the request
You can now send this request to pawaPay Merchant API to initiate a deposit, payout, bulk payout and refund.
Signatures in callbacks
When receiving callbacks from pawaPay they will include the following headers.
- Signature
- Signature-Input
- Signature-Date
- Content-Type
- Content-Digest
You can verify that the request has not been tampered with and is coming from pawaPay.
Here is an example callback for a deposit.
Validate content integrity
Create a hash of the request body using the algorithm specified in the Content-Digest
header.
Comparing the generated value to the value in Content-Digest
ensures the body of the request has not been tampered with.
Validate the signature
Based on the parameters in Signature-Input
, generate the signature base for the request. You can read more about it here.
Based on the previous example, the signature base would be the following.
You can retrieve the public key to verify the signature from the Public Keys endpoint.
Using the retrieved public key, the generated signature base and the signature, you can now verify that the the content (as specified by the Signature-Input
) was in fact signed by pawaPay and therefore originates from pawaPay.
Do not forget to enable signed callbacks in the pawaPay Dashboard. Learn how to do that from the pawaPay Dashboard Docs.