@riocrypto/common-server 1.0.1071 → 1.0.1073

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.
@@ -1,3 +1,4 @@
1
+ import { AxiosRequestConfig } from "axios";
1
2
  declare class BitsoClient {
2
3
  private apiKey;
3
4
  private apiSecret;
@@ -5,8 +6,7 @@ declare class BitsoClient {
5
6
  private baseUrl;
6
7
  constructor(apiKey: string, apiSecret: string, env: "production" | "sandbox");
7
8
  createClabe(): Promise<string>;
8
- private generateBitsoSignature;
9
- private getAuthenticatedHeaders;
9
+ signRequest(requestConfig: AxiosRequestConfig): AxiosRequestConfig;
10
10
  }
11
11
  export declare const buildBistoClient: () => Promise<BitsoClient>;
12
12
  export {};
@@ -29,33 +29,33 @@ class BitsoClient {
29
29
  }
30
30
  createClabe() {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
- const method = "POST";
33
- const requestPath = "/spei/v1/clabes"; // Change this to the API endpoint you're calling
34
- const payload = JSON.stringify({}); // Change this to your request payload
35
- const headers = this.getAuthenticatedHeaders(method, requestPath, payload);
36
- const { data } = yield (0, axios_1.default)({
37
- method,
38
- url: `${this.baseUrl}${requestPath}`,
39
- data: payload,
40
- headers,
41
- });
32
+ const requestConfig = {
33
+ method: "POST",
34
+ url: `${this.baseUrl}/spei/v1/clabes`,
35
+ data: JSON.stringify({}), // Replace with your request data
36
+ };
37
+ const signedRequestConfig = this.signRequest(requestConfig);
38
+ const { data } = yield (0, axios_1.default)(signedRequestConfig);
42
39
  return data.payload.clabe;
43
40
  });
44
41
  }
45
- generateBitsoSignature(nonce, method, path, payload) {
46
- const hmacPayload = `${nonce}${method}${path}${payload}`;
47
- const hmac = crypto_1.default.createHmac("sha256", this.apiSecret);
48
- hmac.update(hmacPayload);
49
- return hmac.digest("hex");
50
- }
51
- getAuthenticatedHeaders(method, path, payload) {
52
- const nonce = Math.floor(Date.now() / 1000);
53
- const signature = this.generateBitsoSignature(nonce, method, path, payload);
54
- const headers = {
55
- Authorization: `Bitso ${this.apiKey}:${nonce}:${signature}`,
56
- "Content-Type": "application/json",
57
- };
58
- return headers;
42
+ signRequest(requestConfig) {
43
+ var _a;
44
+ const nonce = Date.now().toString();
45
+ const method = ((_a = requestConfig.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || "GET";
46
+ const path = new URL(requestConfig.url || "").pathname;
47
+ const body = requestConfig.data || "";
48
+ const data = `${nonce}${method}${path}${body}`;
49
+ const hash = crypto_1.default
50
+ .createHmac("sha256", this.apiSecret)
51
+ .update(data)
52
+ .digest("hex");
53
+ const signature = Buffer.from(hash).toString("hex");
54
+ if (!requestConfig.headers) {
55
+ requestConfig.headers = {};
56
+ }
57
+ requestConfig.headers["Authorization"] = `Bitso ${this.apiKey}:${nonce}:${signature}`;
58
+ return requestConfig;
59
59
  }
60
60
  }
61
61
  const buildBistoClient = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -1,11 +1,11 @@
1
- import { Quote, Fiat, Crypto } from "@riocrypto/common";
1
+ import { Quote, Fiat, Crypto, BitsoBankAccount } from "@riocrypto/common";
2
2
  declare class ClusterClient {
3
3
  private baseUrl;
4
4
  private clusterApiKey;
5
5
  private axios;
6
6
  constructor(baseUrl: string, clusterApiKey: string);
7
7
  getNewQuote(orderId: string, quote: Quote): Promise<Quote>;
8
- createBitsoBankAccount(userId: string): Promise<Quote>;
8
+ createBitsoBankAccount(userId: string): Promise<BitsoBankAccount>;
9
9
  getBalance(asset: Crypto | Fiat): Promise<number>;
10
10
  }
11
11
  export declare const buildClusterClient: () => Promise<ClusterClient>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1071",
3
+ "version": "1.0.1073",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",