import crypto from 'crypto';
import { sortObjectAlphabetically } from "./sort.js";
function sha512Sign(message, secret) {
return crypto.createHmac('sha512', secret).update(message).digest('hex');
}
// Get the timestamp (in seconds) and pass it to the header as 'Request-Timestamp'
const timestamp = Math.floor(Date.now() / 1000);
const requestPath = "/v1/payouts";
const API_SECRET = "YOUR_API_SECRET"; // replace these with your actual API secret value
// Get the request body
let body = {
"amount":{
"currency":"NGN",
"value":10000
},
"bankId":"bank_538ed2056326432ba8e6853b613997bb",
"callbackUrl":"https://webhook.site/99a59e8a-bd0b-485d-8249-fccb5eb62e27",
"destinationAccountNumber":"9845648577",
"metadata":{
"category":"transfer"
},
"narration":"zapped",
"reference":"trx_fWQ7b31pbs5mmT3k3qfb46"
};
// Sort the body alphabetically
body = sortObjectAlphabetically(body);
// Create the body hash to be passed as payload
const bodyHash = sha512Sign(JSON.stringify(body), API_SECRET);
// Concatenate the string to sign
const stringToSign = `${requestPath}${bodyHash}${timestamp}`;
// Generate the Request-Signature value for the header
const signature = sha512Sign(stringToSign, API_SECRET);
console.log(`signature: ${signature}`);