Files
bybit-api/lib/util/requestUtils.js
2020-10-08 22:18:24 +01:00

22 lines
581 B
JavaScript

const { createHmac } = require('crypto');
module.exports = {
signMessage(message, secret) {
return createHmac('sha256', secret)
.update(message)
.digest('hex');
},
serializeParams(params = {}, strict_validation = false) {
return Object.keys(params)
.sort()
.map(key => {
const value = params[key];
if (strict_validation === true && typeof value === 'undefined') {
throw new Error('Failed to sign API request due to undefined parameter');
}
return `${key}=${value}`;
})
.join('&');
}
};