yhtx 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/index.js +17 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,7 +2,13 @@ const crypto = require("crypto");
2
2
  const axios = require("axios");
3
3
 
4
4
  function getSign(queryString, secret, method, path) {
5
- let signString = [method, "api.huobi.pro", path, queryString].join("\n");
5
+ // let signString = [method, "api.huobi.pro", path, queryString].join("\n");
6
+ let signString = [
7
+ method,
8
+ path.includes("linear-swap-api") ? "api.hbdm.com" : "api.huobi.pro",
9
+ path,
10
+ queryString,
11
+ ].join("\n");
6
12
  return crypto.createHmac("sha256", secret).update(signString).digest("base64");
7
13
  }
8
14
 
@@ -11,7 +17,9 @@ async function call(path, { apiKey, secret, data, method, recvWindow } = {}) {
11
17
  secret ||= "";
12
18
  method ||= "GET";
13
19
  recvWindow ??= 30000;
14
- const origin = "https://api.huobi.pro"; //https:api-aws.huobi.pro
20
+ const origin = path.includes("linear-swap-api")
21
+ ? "https://api.hbdm.com" //UM //for debig:https:api.btcgateway.pro, aws:https://api.hbdm.vn
22
+ : "https://api.huobi.pro"; //spot //https:api-aws.huobi.pro
15
23
  data ||= {};
16
24
 
17
25
  let timestamp = Date.now();
@@ -19,18 +27,22 @@ async function call(path, { apiKey, secret, data, method, recvWindow } = {}) {
19
27
  let sign;
20
28
 
21
29
  timestamp = new Date(timestamp).toISOString().slice(0, 19);
22
- body = {
30
+ let preBody = {
23
31
  AccessKeyId: apiKey,
24
- SignatureMethod: "HmacSHA256",
32
+ SignatureMethod: "HmacSHA256", //Ed25519
25
33
  SignatureVersion: 2,
26
34
  Timestamp: timestamp,
35
+ };
36
+ body = {
37
+ ...preBody,
27
38
  ...data,
28
39
  };
40
+
29
41
  let pars = [];
30
42
  for (let k in body) pars.push(k + "=" + encodeURIComponent(body[k]));
31
43
  let queryString = pars.sort().join("&");
32
44
 
33
- if (/*not yet supported*/ method === "POST") {
45
+ if (/*payload not yet supported*/ method === "POST") {
34
46
  url = origin + path + "?" + queryString;
35
47
  sign = getSign(queryString, secret, method, path);
36
48
  url += `&Signature=${sign}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yhtx",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "HTX API",
5
5
  "main": "index.js",
6
6
  "scripts": {