Authorization
In order to authorize your requests, get a private key.
Authorization is required:
To verify your request and prove your ownership of the merchant.
To verify notifications (webhooks) that 0xpay sending to your server to verify the authority.
Building the signature
General formula is:
signature = hmacsha256(method + url + body + timestamp, privateKey)
Overall guide to build your signature is described below:
Concatenate HTTP method(
POST
,GET
, etc), URL path, request body (or an empty string, if the body is empty), and timestamp in seconds. Let's call resulted string<MESSAGE>
Sign received
<MESSAGE>
using HMAC-SHA256 algorithm with merchant's<PRIVATE_KEY>
. Let's call resulted hash<SIGNATURE>
Signing a request
To make a valid request, you have to include several headers along with it:
merchant-id
Copy it from your 0xpay Dashboard -> Merchant Settings section.
signature
<SIGNATURE>
timestamp
<TIMESTAMP>
For example, I want to create an address in the BITCOIN network. I have to POST /merchants/addresses
the API endpoint. Here is my payload:
Let's say, that my current timestamp is 1650289480
(in seconds!!!). Lets concatenate parts of our request and we will receive next <MESSAGE>
:
Then, I will receive <SIGNATURE>
using HMAC-SHA256 with the private key
.
As far as we already generated <SIGNATURE>
, we can make a request.
Code examples:
Verifying a notification (webhook)
Let's assume that you receive some replenishment webhook sent from 0xpay server, that is directed to some domain.com/webhooks/0xpay
endpoint you have specified earlier in the merchant's settings.
Body of the webhook is:
Header of the request:
So then build the <MESSAGE> mentioned above
Now you can generate the signature using the formula mentioned above and compare it with the SIGNATURE
we sent you in headers. If signatures match, then the request is original.
Signature Examples
Let's build exemplary signatures for each of our requests in order to demonstrate the logic behind this process. In this case, we can equal values for
Last updated