future-private: FIX signature for case empty body and have only query param

This commit is contained in:
mahdi msr 2025-09-29 00:16:31 +03:30
parent e86854ca54
commit 8d77aebb64
1 changed files with 8 additions and 3 deletions

View File

@ -21,6 +21,7 @@ class Header
/** /**
* Convert sorted parameters to string format * Convert sorted parameters to string format
* Example: ["id" => "1", "uid" => "200"] becomes "id1uid200" * Example: ["id" => "1", "uid" => "200"] becomes "id1uid200"
* According to Bitunix documentation: String queryParams = "id1uid200"
*/ */
public static function digestQueryParameters(array $parameters): string public static function digestQueryParameters(array $parameters): string
{ {
@ -78,8 +79,12 @@ class Header
// Step 2: Remove all spaces from body (already done if JSON encoded properly) // Step 2: Remove all spaces from body (already done if JSON encoded properly)
$bodyString = trim($body); $bodyString = trim($body);
// Step 3: Create digest: SHA256(nonce + timestamp + api-key + queryParams + body) // Step 3: Create digest: SHA256(nonce + timestamp + api-key + queryParams + body (if not empty))
if (strlen($bodyString) == 0) {
$digestInput = $nonce.$timestamp.$apiKey.$queryParamsString;
}else{
$digestInput = $nonce.$timestamp.$apiKey.$queryParamsString.$bodyString; $digestInput = $nonce.$timestamp.$apiKey.$queryParamsString.$bodyString;
}
$digest = hash('sha256', $digestInput); $digest = hash('sha256', $digestInput);
// Step 4: Create sign: SHA256(digest + secretKey) // Step 4: Create sign: SHA256(digest + secretKey)