@binance/common 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -46,8 +46,8 @@ var RequestSigner = class {
46
46
  }
47
47
  throw new Error("Either 'apiSecret' or 'privateKey' must be provided for signed requests.");
48
48
  }
49
- sign(queryParams) {
50
- const params = buildQueryString(queryParams);
49
+ sign(queryParams, bodyParams) {
50
+ const params = buildQueryString(queryParams) + (bodyParams ? buildQueryString(bodyParams) : "");
51
51
  if (this.apiSecret) return crypto.createHmac("sha256", this.apiSecret).update(params).digest("hex");
52
52
  if (this.keyObject && this.keyType) {
53
53
  const data = Buffer.from(params);
@@ -147,13 +147,13 @@ function getTimestamp() {
147
147
  * @param queryParams - The query parameters to be signed.
148
148
  * @returns A string representing the generated signature.
149
149
  */
150
- const getSignature = function(configuration, queryParams) {
150
+ const getSignature = function(configuration, queryParams, bodyParams) {
151
151
  let signer = signerCache.get(configuration);
152
152
  if (!signer) {
153
153
  signer = new RequestSigner(configuration);
154
154
  signerCache.set(configuration, signer);
155
155
  }
156
- return signer.sign(queryParams);
156
+ return signer.sign(queryParams, bodyParams);
157
157
  };
158
158
  /**
159
159
  * Asserts that a function parameter exists and is not null or undefined.
@@ -397,19 +397,33 @@ const parseRateLimitHeaders = function(headers) {
397
397
  * @param options - Additional request options (isSigned).
398
398
  * @returns A promise resolving to the response data object.
399
399
  */
400
- const sendRequest = function(configuration, endpoint, method, params = {}, timeUnit, options = {}) {
400
+ const sendRequest = function(configuration, endpoint, method, queryParams = {}, bodyParams = {}, timeUnit, options = {}) {
401
401
  const localVarUrlObj = new URL(endpoint, configuration?.basePath);
402
402
  const localVarRequestOptions = {
403
403
  method,
404
404
  ...configuration?.baseOptions
405
405
  };
406
- const localVarQueryParameter = { ...normalizeScientificNumbers(params) };
406
+ const localVarQueryParameter = { ...normalizeScientificNumbers(queryParams) };
407
+ const localVarBodyParameter = { ...normalizeScientificNumbers(bodyParams) };
407
408
  if (options.isSigned) {
408
409
  localVarQueryParameter["timestamp"] = getTimestamp();
409
- const signature = getSignature(configuration, localVarQueryParameter);
410
+ const signature = getSignature(configuration, localVarQueryParameter, localVarBodyParameter);
410
411
  if (signature) localVarQueryParameter["signature"] = signature;
411
412
  }
412
413
  setSearchParams(localVarUrlObj, localVarQueryParameter);
414
+ if (Object.keys(localVarBodyParameter).length > 0) {
415
+ const searchParams = new URLSearchParams();
416
+ for (const [key, value] of Object.entries(localVarBodyParameter)) {
417
+ if (value === null || value === void 0) continue;
418
+ const serializedValue = serializeValue(value);
419
+ searchParams.append(key, serializedValue);
420
+ }
421
+ localVarRequestOptions.data = searchParams.toString();
422
+ localVarRequestOptions.headers = {
423
+ ...localVarRequestOptions.headers || {},
424
+ "Content-Type": "application/x-www-form-urlencoded"
425
+ };
426
+ }
413
427
  if (timeUnit && localVarRequestOptions.headers) {
414
428
  const _timeUnit = validateTimeUnit(timeUnit);
415
429
  localVarRequestOptions.headers = {