@riocrypto/common-server 1.0.1066 → 1.0.1068
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/build/clients/bitso-client.d.ts +13 -0
- package/build/clients/bitso-client.js +78 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -0
- package/build/models/bitso-bank-account.d.ts +18 -0
- package/build/models/bitso-bank-account.js +41 -0
- package/build/models/chained-order.d.ts +0 -1
- package/build/models/chained-order.js +0 -4
- package/package.json +2 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { User } from "@riocrypto/common";
|
|
2
|
+
declare class BitsoClient {
|
|
3
|
+
private apiKey;
|
|
4
|
+
private apiSecret;
|
|
5
|
+
private env;
|
|
6
|
+
private baseUrl;
|
|
7
|
+
constructor(apiKey: string, apiSecret: string, env: "production" | "sandbox");
|
|
8
|
+
createClabe(user: User): Promise<string>;
|
|
9
|
+
private generateBitsoSignature;
|
|
10
|
+
private getAuthenticatedHeaders;
|
|
11
|
+
}
|
|
12
|
+
export declare const buildBistoClient: () => Promise<BitsoClient>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.buildBistoClient = void 0;
|
|
16
|
+
const secret_manager_client_1 = require("./secret-manager-client");
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const common_1 = require("@riocrypto/common");
|
|
19
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
20
|
+
class BitsoClient {
|
|
21
|
+
constructor(apiKey, apiSecret, env) {
|
|
22
|
+
this.apiKey = apiKey;
|
|
23
|
+
this.apiSecret = apiSecret;
|
|
24
|
+
this.env = env;
|
|
25
|
+
this.baseUrl =
|
|
26
|
+
env === "production"
|
|
27
|
+
? "https://www.bitso.com"
|
|
28
|
+
: "https://stage.bitso.com";
|
|
29
|
+
}
|
|
30
|
+
createClabe(user) {
|
|
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
|
+
});
|
|
42
|
+
return data.payload.clabe;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
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;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const buildBistoClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
// Retrieve secrets asynchronously
|
|
63
|
+
const BITSO_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("BITSO_API_KEY");
|
|
64
|
+
if (!BITSO_API_KEY) {
|
|
65
|
+
throw new common_1.SecretManagerError();
|
|
66
|
+
}
|
|
67
|
+
const BITSO_API_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("BITSO_API_SECRET");
|
|
68
|
+
if (!BITSO_API_SECRET) {
|
|
69
|
+
throw new common_1.SecretManagerError();
|
|
70
|
+
}
|
|
71
|
+
const env = process.env.RIO_ENV === common_1.RioEnv.Production ||
|
|
72
|
+
process.env.RIO_ENV === common_1.RioEnv.Staging ||
|
|
73
|
+
process.env.RIO_ENV === common_1.RioEnv.Development
|
|
74
|
+
? "production"
|
|
75
|
+
: "sandbox";
|
|
76
|
+
return new BitsoClient(BITSO_API_KEY, BITSO_API_SECRET, env);
|
|
77
|
+
});
|
|
78
|
+
exports.buildBistoClient = buildBistoClient;
|
package/build/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export * from "./models/bank-transfer";
|
|
|
41
41
|
export * from "./models/webhook-registration";
|
|
42
42
|
export * from "./models/chained-quote";
|
|
43
43
|
export * from "./models/chained-order";
|
|
44
|
+
export * from "./models/bitso-bank-account";
|
|
44
45
|
export * from "./clients/bitstamp-client";
|
|
45
46
|
export * from "./clients/ccxt-client";
|
|
46
47
|
export * from "./clients/kushki-client";
|
|
@@ -58,6 +59,7 @@ export * from "./clients/bridge-client";
|
|
|
58
59
|
export * from "./clients/google-sheets-api-client";
|
|
59
60
|
export * from "./clients/invopop-client";
|
|
60
61
|
export * from "./clients/cluster-client";
|
|
62
|
+
export * from "./clients/bitso-client";
|
|
61
63
|
export * from "./helpers/get-user-helper";
|
|
62
64
|
export * from "./helpers/get-platform-fees";
|
|
63
65
|
export * from "./helpers/get-processor-fees";
|
package/build/index.js
CHANGED
|
@@ -57,6 +57,7 @@ __exportStar(require("./models/bank-transfer"), exports);
|
|
|
57
57
|
__exportStar(require("./models/webhook-registration"), exports);
|
|
58
58
|
__exportStar(require("./models/chained-quote"), exports);
|
|
59
59
|
__exportStar(require("./models/chained-order"), exports);
|
|
60
|
+
__exportStar(require("./models/bitso-bank-account"), exports);
|
|
60
61
|
__exportStar(require("./clients/bitstamp-client"), exports);
|
|
61
62
|
__exportStar(require("./clients/ccxt-client"), exports);
|
|
62
63
|
__exportStar(require("./clients/kushki-client"), exports);
|
|
@@ -74,6 +75,7 @@ __exportStar(require("./clients/bridge-client"), exports);
|
|
|
74
75
|
__exportStar(require("./clients/google-sheets-api-client"), exports);
|
|
75
76
|
__exportStar(require("./clients/invopop-client"), exports);
|
|
76
77
|
__exportStar(require("./clients/cluster-client"), exports);
|
|
78
|
+
__exportStar(require("./clients/bitso-client"), exports);
|
|
77
79
|
__exportStar(require("./helpers/get-user-helper"), exports);
|
|
78
80
|
__exportStar(require("./helpers/get-platform-fees"), exports);
|
|
79
81
|
__exportStar(require("./helpers/get-processor-fees"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Mongoose, Model, Document } from "mongoose";
|
|
2
|
+
interface BitsoBankAccountAttrs {
|
|
3
|
+
createdAt: Date;
|
|
4
|
+
userId: string;
|
|
5
|
+
clabe: string;
|
|
6
|
+
approved: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface BitsoBankAccountDoc extends Document {
|
|
9
|
+
createdAt: Date;
|
|
10
|
+
userId: string;
|
|
11
|
+
clabe: string;
|
|
12
|
+
approved: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface BitsoBankAccountModel extends Model<BitsoBankAccountDoc> {
|
|
15
|
+
build(attrs: BitsoBankAccountAttrs): BitsoBankAccountDoc;
|
|
16
|
+
}
|
|
17
|
+
declare const buildBitsoBankAccount: (mongoose: Mongoose) => BitsoBankAccountModel;
|
|
18
|
+
export { buildBitsoBankAccount, BitsoBankAccountDoc };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildBitsoBankAccount = void 0;
|
|
4
|
+
const buildBitsoBankAccount = (mongoose) => {
|
|
5
|
+
// if model is already defined, return it
|
|
6
|
+
if (mongoose.models.BitsoBankAccount) {
|
|
7
|
+
return mongoose.model("BitsoBankAccount");
|
|
8
|
+
}
|
|
9
|
+
const BitsoBankAccountSchema = new mongoose.Schema({
|
|
10
|
+
userId: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
createdAt: {
|
|
15
|
+
type: mongoose.Schema.Types.Date,
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
clabe: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
},
|
|
22
|
+
approved: {
|
|
23
|
+
type: Boolean,
|
|
24
|
+
required: true,
|
|
25
|
+
},
|
|
26
|
+
}, {
|
|
27
|
+
toJSON: {
|
|
28
|
+
transform(doc, ret) {
|
|
29
|
+
ret.id = ret._id.valueOf();
|
|
30
|
+
delete ret._id;
|
|
31
|
+
delete ret.__v;
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
BitsoBankAccountSchema.statics.build = (attrs) => {
|
|
36
|
+
return new BitsoBankAccount(attrs);
|
|
37
|
+
};
|
|
38
|
+
const BitsoBankAccount = mongoose.model("BitsoBankAccount", BitsoBankAccountSchema);
|
|
39
|
+
return BitsoBankAccount;
|
|
40
|
+
};
|
|
41
|
+
exports.buildBitsoBankAccount = buildBitsoBankAccount;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1068",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@aws-sdk/client-s3": "^3.297.0",
|
|
25
25
|
"@everapi/currencyapi-js": "^1.0.6",
|
|
26
26
|
"@google-cloud/storage": "^6.9.5",
|
|
27
|
-
"@riocrypto/common": "^1.0.
|
|
27
|
+
"@riocrypto/common": "^1.0.916",
|
|
28
28
|
"@types/express": "^4.17.13",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"ccxt": "^3.0.30",
|