@riocrypto/common-server 1.0.1077 → 1.0.1078

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.
@@ -16,7 +16,7 @@ exports.buildBistoClient = void 0;
16
16
  const secret_manager_client_1 = require("./secret-manager-client");
17
17
  const axios_1 = __importDefault(require("axios"));
18
18
  const common_1 = require("@riocrypto/common");
19
- const crypto_1 = __importDefault(require("crypto"));
19
+ const crypto_js_1 = __importDefault(require("crypto-js"));
20
20
  class BitsoClient {
21
21
  constructor(apiKey, apiSecret, env) {
22
22
  this.apiKey = apiKey;
@@ -43,20 +43,20 @@ class BitsoClient {
43
43
  }
44
44
  signRequest(requestConfig) {
45
45
  var _a;
46
- const nonce = Date.now().toString();
47
- const method = ((_a = requestConfig.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || "GET";
48
- const path = new URL(requestConfig.url || "").pathname;
49
- const body = requestConfig.data || "";
50
- const data = `${nonce}${method}${path}${body}`;
51
- const hash = crypto_1.default
52
- .createHmac("sha256", this.apiSecret)
53
- .update(data)
54
- .digest("hex");
55
- const signature = Buffer.from(hash).toString("hex");
46
+ const url = new URL(requestConfig.url || "");
47
+ const requestPath = url.pathname + (url.search || "");
48
+ const payload = requestConfig.data || "";
49
+ const nonce = new Date().getTime().toString();
50
+ const data = nonce +
51
+ (((_a = requestConfig.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || "") +
52
+ requestPath +
53
+ payload;
54
+ const signature = crypto_js_1.default.HmacSHA256(data, this.apiSecret).toString(crypto_js_1.default.enc.Hex);
55
+ const authHeader = `Bitso ${this.apiKey}:${nonce}:${signature}`;
56
56
  if (!requestConfig.headers) {
57
57
  requestConfig.headers = {};
58
58
  }
59
- requestConfig.headers["Authorization"] = `Bitso ${this.apiKey}:${nonce}:${signature}`;
59
+ requestConfig.headers["Authorization"] = authHeader;
60
60
  return requestConfig;
61
61
  }
62
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1077",
3
+ "version": "1.0.1078",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -15,6 +15,7 @@
15
15
  "author": "",
16
16
  "license": "ISC",
17
17
  "devDependencies": {
18
+ "@types/crypto-js": "^4.1.1",
18
19
  "@types/jsonwebtoken": "^8.5.8",
19
20
  "@types/uuid": "^9.0.1",
20
21
  "del-cli": "^5.0.0",
@@ -28,6 +29,7 @@
28
29
  "@types/express": "^4.17.13",
29
30
  "axios": "^0.27.2",
30
31
  "ccxt": "^3.0.30",
32
+ "crypto-js": "^4.1.1",
31
33
  "express": "^4.18.1",
32
34
  "express-validator": "^6.14.2",
33
35
  "fireblocks-sdk": "^4.0.0",