Use HMAC authentication when you are planning to integrate with:
HMAC authentication can also be used to authenticate to Paxful API. Since 2022 HMAC authentication for Paxful API is deprecated, it will be maintained for a little while, but no new features will be added. If you are developing a new application, you should use direct or delegated access modes instead.
HMAC authentication is a process of taking all parameters you want to invoke an endpoint with, “signing” them using your API secret, and then adding the value of this signature as another parameter to the payload of request. When Paxful’s server receives a request with HMAC signature, it will repeat this process. If the signature provided in request payload matches the signature recreated on the authentication server, the request will be processed. If there is a mismatch between signatures, the request has been tampered with and it will be discarded.
Follow these steps to create a request signed with HMAC signature:
After following these steps you should have a signed payload which, depending on the use-case, you can use in a few different ways:
JavaScript (NodeJs)const qs = require('querystring'); const crypto = require('crypto'); function sign_with_hmac(apiKey, apiSecret, payload = {}) { payload = qs.encode({ apikey: apiKey, nonce: Date.now(), ...payload }); const apiSeal = crypto.createHmac('sha256', apiSecret).update(payload).digest('hex'); const signedPayload = `${payload}&apiseal=${apiSeal}`; return signedPayload; }
PHPfunction sign_with_hmac($apiKey, $apiSecret, array $payload = []) { $payload = array_merge($payload, [ 'apikey' => $apiKey, 'nonce' => time() ]); $apiSeal = hash_hmac('sha256', http_build_query($payload), $apiSecret); $signedPayload = http_build_query(array_merge($payload, ['apiseal' => $apiSeal])); return $signedPayload; }
Python 3import hmac import time from hashlib import sha256 from urllib.parse import urlencode def sign_with_hmac(api_key, api_secret, **kwargs): nonce = int(time.time()) payload = {"apikey": api_key, "nonce": nonce} payload.update(kwargs) payload = urlencode(sorted(payload.items())) apiseal = hmac.new(api_secret.encode(), payload.encode(), sha256).hexdigest() return payload + "&apiseal=" + apiseal
Golangpackage main import ( "crypto/hmac" "crypto/sha256" "encoding/hex" "fmt" "net/url" "strings" "time" ) func SignWithHmac(paxfulAPIKey string, paxfulSecretAPIKey string, values url.Values) string { nonce := fmt.Sprintf("%d", time.Now().Unix()) values.Add("apikey", paxfulAPIKey) values.Add("nonce", nonce) payload := values.Encode() mac := hmac.New(sha256.New, []byte(paxfulSecretAPIKey)) mac.Write([]byte(payload)) apiseal := hex.EncodeToString(mac.Sum(nil)) values.Add("apiseal", apiseal) return values.Encode() }