@riocrypto/common-server 1.0.1072 → 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
|
-
|
|
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
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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* () {
|