@riocrypto/common 1.0.370 → 1.0.373
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/index.d.ts +8 -0
- package/build/index.js +8 -0
- package/build/middlewares/get-order.d.ts +10 -0
- package/build/middlewares/get-order.js +41 -0
- package/build/middlewares/get-partner.d.ts +9 -0
- package/build/middlewares/get-partner.js +40 -0
- package/build/middlewares/get-user.d.ts +11 -0
- package/build/middlewares/get-user.js +43 -0
- package/build/middlewares/require-priveleges.d.ts +2 -0
- package/build/middlewares/require-priveleges.js +15 -0
- package/build/middlewares/validate-auth.d.ts +1 -1
- package/build/middlewares/validate-auth.js +3 -3
- package/build/middlewares/validate-kyc.d.ts +2 -0
- package/build/middlewares/validate-kyc.js +30 -0
- package/build/middlewares/validate-order.d.ts +2 -0
- package/build/middlewares/validate-order.js +27 -0
- package/build/models/bank-payout.d.ts +20 -0
- package/build/models/bank-payout.js +41 -0
- package/build/models/business-user.d.ts +55 -0
- package/build/models/business-user.js +105 -0
- package/build/models/order.d.ts +66 -0
- package/build/models/order.js +120 -0
- package/build/models/partner.d.ts +33 -0
- package/build/models/partner.js +62 -0
- package/build/models/user.d.ts +50 -0
- package/build/models/user.js +87 -0
- package/build/services/apiKey.d.ts +3 -0
- package/build/services/apiKey.js +24 -0
- package/build/services/password.d.ts +4 -0
- package/build/services/password.js +32 -0
- package/package.json +2 -1
package/build/index.d.ts
CHANGED
|
@@ -27,6 +27,12 @@ export * from "./middlewares/verify-admin-api-key";
|
|
|
27
27
|
export * from "./middlewares/require-admin-api-key";
|
|
28
28
|
export * from "./middlewares/current-admin-auth";
|
|
29
29
|
export * from "./middlewares/validate-auth";
|
|
30
|
+
export * from "./middlewares/get-order";
|
|
31
|
+
export * from "./middlewares/get-partner";
|
|
32
|
+
export * from "./middlewares/get-user";
|
|
33
|
+
export * from "./middlewares/require-priveleges";
|
|
34
|
+
export * from "./middlewares/validate-kyc";
|
|
35
|
+
export * from "./middlewares/validate-order";
|
|
30
36
|
export * from "./events/base-listener";
|
|
31
37
|
export * from "./events/base-publisher";
|
|
32
38
|
export * from "./events/subjects";
|
|
@@ -134,3 +140,5 @@ export * from "./classes/PaymentMethodAsset";
|
|
|
134
140
|
export * from "./classes/PayoutMethodAsset";
|
|
135
141
|
export * from "./classes/USStateAsset";
|
|
136
142
|
export * from "./classes/WyrePaymentMethodAsset";
|
|
143
|
+
export * from "./services/apiKey";
|
|
144
|
+
export * from "./services/password";
|
package/build/index.js
CHANGED
|
@@ -43,6 +43,12 @@ __exportStar(require("./middlewares/verify-admin-api-key"), exports);
|
|
|
43
43
|
__exportStar(require("./middlewares/require-admin-api-key"), exports);
|
|
44
44
|
__exportStar(require("./middlewares/current-admin-auth"), exports);
|
|
45
45
|
__exportStar(require("./middlewares/validate-auth"), exports);
|
|
46
|
+
__exportStar(require("./middlewares/get-order"), exports);
|
|
47
|
+
__exportStar(require("./middlewares/get-partner"), exports);
|
|
48
|
+
__exportStar(require("./middlewares/get-user"), exports);
|
|
49
|
+
__exportStar(require("./middlewares/require-priveleges"), exports);
|
|
50
|
+
__exportStar(require("./middlewares/validate-kyc"), exports);
|
|
51
|
+
__exportStar(require("./middlewares/validate-order"), exports);
|
|
46
52
|
__exportStar(require("./events/base-listener"), exports);
|
|
47
53
|
__exportStar(require("./events/base-publisher"), exports);
|
|
48
54
|
__exportStar(require("./events/subjects"), exports);
|
|
@@ -150,3 +156,5 @@ __exportStar(require("./classes/PaymentMethodAsset"), exports);
|
|
|
150
156
|
__exportStar(require("./classes/PayoutMethodAsset"), exports);
|
|
151
157
|
__exportStar(require("./classes/USStateAsset"), exports);
|
|
152
158
|
__exportStar(require("./classes/WyrePaymentMethodAsset"), exports);
|
|
159
|
+
__exportStar(require("./services/apiKey"), exports);
|
|
160
|
+
__exportStar(require("./services/password"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
import { OrderDoc } from "../models/order";
|
|
3
|
+
declare global {
|
|
4
|
+
namespace Express {
|
|
5
|
+
interface Request {
|
|
6
|
+
order?: OrderDoc;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare const getOrder: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getOrder = void 0;
|
|
13
|
+
const not_found_error_1 = require("../errors/not-found-error");
|
|
14
|
+
const order_1 = require("../models/order");
|
|
15
|
+
const getOrder = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
let orderId = "";
|
|
17
|
+
if (req.body.orderId) {
|
|
18
|
+
orderId = req.body.orderId;
|
|
19
|
+
}
|
|
20
|
+
else if (req.params.orderId) {
|
|
21
|
+
orderId = req.params.orderId;
|
|
22
|
+
}
|
|
23
|
+
else if (req.query.orderId) {
|
|
24
|
+
orderId = req.query.orderId;
|
|
25
|
+
}
|
|
26
|
+
if (!orderId) {
|
|
27
|
+
throw new Error("Failed to provide orderId");
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const order = yield order_1.Order.findById(orderId);
|
|
31
|
+
if (!order) {
|
|
32
|
+
throw new Error();
|
|
33
|
+
}
|
|
34
|
+
req.order = order;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new not_found_error_1.NotFoundError();
|
|
38
|
+
}
|
|
39
|
+
next();
|
|
40
|
+
});
|
|
41
|
+
exports.getOrder = getOrder;
|
|
@@ -0,0 +1,40 @@
|
|
|
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.getPartner = void 0;
|
|
16
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
17
|
+
const partner_1 = require("../models/partner");
|
|
18
|
+
const apiKey_1 = require("../services/apiKey");
|
|
19
|
+
const getPartner = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
try {
|
|
21
|
+
if (!req.headers["x-api-key"]) {
|
|
22
|
+
const payload = jsonwebtoken_1.default.verify(req.cookies.partnerAuthJwt, process.env.JWT_KEY_PARTNER);
|
|
23
|
+
req.partnerId = payload.partnerId;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const hashedApiKey = yield apiKey_1.ApiKey.toHash(req.headers["x-api-key"]);
|
|
27
|
+
const partner = yield partner_1.Partner.findOne({
|
|
28
|
+
apiKeys: { $elemMatch: { value: hashedApiKey } },
|
|
29
|
+
});
|
|
30
|
+
if (partner) {
|
|
31
|
+
req.partnerId = partner._id.valueOf();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
next();
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
next();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
exports.getPartner = getPartner;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
import { BusinessUserDoc } from "../models/business-user";
|
|
3
|
+
import { UserDoc } from "../models/user";
|
|
4
|
+
declare global {
|
|
5
|
+
namespace Express {
|
|
6
|
+
interface Request {
|
|
7
|
+
user?: UserDoc | BusinessUserDoc;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare const getUser: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getUser = void 0;
|
|
13
|
+
const business_user_1 = require("../models/business-user");
|
|
14
|
+
const user_1 = require("../models/user");
|
|
15
|
+
const user_attribute_1 = require("../types/user-attribute");
|
|
16
|
+
const getUser = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
let individualUser;
|
|
18
|
+
let businessUser;
|
|
19
|
+
try {
|
|
20
|
+
individualUser = yield user_1.User.findOne({
|
|
21
|
+
phoneNumber: req.currentAuth.phoneNumber,
|
|
22
|
+
attributes: { $ne: user_attribute_1.UserAttribute.deleted },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
individualUser = null;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
businessUser = yield business_user_1.BusinessUser.findOne({
|
|
30
|
+
phoneNumber: req.currentAuth.phoneNumber,
|
|
31
|
+
attributes: { $ne: user_attribute_1.UserAttribute.deleted },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
businessUser = null;
|
|
36
|
+
}
|
|
37
|
+
const user = individualUser || businessUser;
|
|
38
|
+
if (user) {
|
|
39
|
+
req.user = user;
|
|
40
|
+
}
|
|
41
|
+
next();
|
|
42
|
+
});
|
|
43
|
+
exports.getUser = getUser;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requirePriveleges = void 0;
|
|
4
|
+
const missing_user_error_1 = require("../errors/missing-user-error");
|
|
5
|
+
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
6
|
+
const requirePriveleges = (req, res, next) => {
|
|
7
|
+
if (req.currentAuth && !req.user) {
|
|
8
|
+
throw new missing_user_error_1.MissingUserError();
|
|
9
|
+
}
|
|
10
|
+
if (!req.partnerId && !req.user && !req.currentAdminAuth) {
|
|
11
|
+
throw new not_authorized_error_1.NotAuthorizedError();
|
|
12
|
+
}
|
|
13
|
+
next();
|
|
14
|
+
};
|
|
15
|
+
exports.requirePriveleges = requirePriveleges;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const validateAuth: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -9,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.validateAuth = void 0;
|
|
13
13
|
const missing_password_error_1 = require("../errors/missing-password-error");
|
|
14
14
|
const missing_security_question_error_1 = require("../errors/missing-security-question-error");
|
|
15
|
-
const
|
|
15
|
+
const validateAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
const auth = req.currentAuth;
|
|
17
17
|
if (auth) {
|
|
18
18
|
if (auth.missing.includes("password")) {
|
|
@@ -27,4 +27,4 @@ const validateKYC = (req, res, next) => __awaiter(void 0, void 0, void 0, functi
|
|
|
27
27
|
}
|
|
28
28
|
next();
|
|
29
29
|
});
|
|
30
|
-
exports.
|
|
30
|
+
exports.validateAuth = validateAuth;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.validateKYC = void 0;
|
|
13
|
+
const missing_kyc_approval_error_1 = require("../errors/missing-kyc-approval-error");
|
|
14
|
+
const kyc_status_1 = require("../types/kyc-status");
|
|
15
|
+
const user_type_1 = require("../types/user-type");
|
|
16
|
+
const validateKYC = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const user = req.user;
|
|
18
|
+
if ((user === null || user === void 0 ? void 0 : user.type) === user_type_1.UserType.Individual) {
|
|
19
|
+
if (user.kycStatus !== kyc_status_1.KYCStatus.Passed) {
|
|
20
|
+
throw new missing_kyc_approval_error_1.MissingKYCApprovalError();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if ((user === null || user === void 0 ? void 0 : user.type) === user_type_1.UserType.Business) {
|
|
24
|
+
if (user.kycStatus !== kyc_status_1.KYCStatus.businessApproved) {
|
|
25
|
+
throw new missing_kyc_approval_error_1.MissingKYCApprovalError();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
next();
|
|
29
|
+
});
|
|
30
|
+
exports.validateKYC = validateKYC;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.validateOrder = void 0;
|
|
13
|
+
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
14
|
+
const validateOrder = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const order = req.order;
|
|
16
|
+
if (!order) {
|
|
17
|
+
throw new not_authorized_error_1.NotAuthorizedError();
|
|
18
|
+
}
|
|
19
|
+
if (req.partnerId && req.partnerId !== order.partnerId) {
|
|
20
|
+
throw new not_authorized_error_1.NotAuthorizedError();
|
|
21
|
+
}
|
|
22
|
+
if (req.user && req.user._id.valueOf() !== order.userId) {
|
|
23
|
+
throw new not_authorized_error_1.NotAuthorizedError();
|
|
24
|
+
}
|
|
25
|
+
next();
|
|
26
|
+
});
|
|
27
|
+
exports.validateOrder = validateOrder;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
interface BankPayoutAttrs {
|
|
3
|
+
orderId: string;
|
|
4
|
+
originBank: string;
|
|
5
|
+
destinationBank?: string;
|
|
6
|
+
accountNumber: string;
|
|
7
|
+
status: string;
|
|
8
|
+
}
|
|
9
|
+
interface BankPayoutDoc extends mongoose.Document {
|
|
10
|
+
orderId: string;
|
|
11
|
+
originBank: string;
|
|
12
|
+
destinationBank?: string;
|
|
13
|
+
accountNumber: string;
|
|
14
|
+
status: string;
|
|
15
|
+
}
|
|
16
|
+
interface BankPayoutModel extends mongoose.Model<BankPayoutDoc> {
|
|
17
|
+
build(attrs: BankPayoutAttrs): BankPayoutDoc;
|
|
18
|
+
}
|
|
19
|
+
declare const BankPayout: BankPayoutModel;
|
|
20
|
+
export { BankPayout, BankPayoutDoc };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BankPayout = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const BankPayoutSchema = new mongoose_1.default.Schema({
|
|
9
|
+
orderId: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
originBank: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
accountNumber: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
status: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
destinationBank: {
|
|
26
|
+
type: String,
|
|
27
|
+
},
|
|
28
|
+
}, {
|
|
29
|
+
toJSON: {
|
|
30
|
+
transform(doc, ret) {
|
|
31
|
+
ret.id = ret._id;
|
|
32
|
+
delete ret._id;
|
|
33
|
+
delete ret.__v;
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
BankPayoutSchema.statics.build = (attrs) => {
|
|
38
|
+
return new BankPayout(attrs);
|
|
39
|
+
};
|
|
40
|
+
const BankPayout = mongoose_1.default.model("BankPayout", BankPayoutSchema);
|
|
41
|
+
exports.BankPayout = BankPayout;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import { Country } from "../types/country";
|
|
3
|
+
import { KYCStatus } from "../types/kyc-status";
|
|
4
|
+
import { Language } from "../types/language";
|
|
5
|
+
import { PlatformFeeRange } from "../types/platform-fee-range";
|
|
6
|
+
import { USState } from "../types/us-state";
|
|
7
|
+
import { UserAttribute } from "../types/user-attribute";
|
|
8
|
+
import { UserType } from "../types/user-type";
|
|
9
|
+
interface BusinessUserAttrs {
|
|
10
|
+
type: UserType;
|
|
11
|
+
companyName: string;
|
|
12
|
+
legalRepresentative: string;
|
|
13
|
+
phoneNumber: string;
|
|
14
|
+
email: string;
|
|
15
|
+
street1: string;
|
|
16
|
+
street2?: string;
|
|
17
|
+
city: string;
|
|
18
|
+
state: USState | string;
|
|
19
|
+
postalCode: string;
|
|
20
|
+
country: Country;
|
|
21
|
+
kycStatus: KYCStatus;
|
|
22
|
+
COIFile?: string;
|
|
23
|
+
KYCReportFile?: string;
|
|
24
|
+
cpf?: string;
|
|
25
|
+
language?: Language;
|
|
26
|
+
attributes?: UserAttribute[];
|
|
27
|
+
brokerId?: string;
|
|
28
|
+
platformFeeRanges?: PlatformFeeRange[];
|
|
29
|
+
}
|
|
30
|
+
interface BusinessUserModel extends mongoose.Model<BusinessUserDoc> {
|
|
31
|
+
build(attrs: BusinessUserAttrs): BusinessUserDoc;
|
|
32
|
+
}
|
|
33
|
+
interface BusinessUserDoc extends mongoose.Document {
|
|
34
|
+
type: UserType;
|
|
35
|
+
companyName: string;
|
|
36
|
+
legalRepresentative: string;
|
|
37
|
+
phoneNumber: string;
|
|
38
|
+
email: string;
|
|
39
|
+
street1: string;
|
|
40
|
+
street2?: string;
|
|
41
|
+
city: string;
|
|
42
|
+
state: USState | string;
|
|
43
|
+
postalCode: string;
|
|
44
|
+
country: Country;
|
|
45
|
+
kycStatus: KYCStatus;
|
|
46
|
+
COIFile?: string;
|
|
47
|
+
KYCReportFile?: string;
|
|
48
|
+
cpf?: string;
|
|
49
|
+
language?: Language;
|
|
50
|
+
attributes?: UserAttribute[];
|
|
51
|
+
brokerId?: string;
|
|
52
|
+
platformFeeRanges?: PlatformFeeRange[];
|
|
53
|
+
}
|
|
54
|
+
declare const BusinessUser: BusinessUserModel;
|
|
55
|
+
export { BusinessUser, BusinessUserDoc };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BusinessUser = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const BusinessUserSchema = new mongoose_1.default.Schema({
|
|
9
|
+
type: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
companyName: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
legalRepresentative: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
phoneNumber: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
email: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true,
|
|
28
|
+
},
|
|
29
|
+
street1: {
|
|
30
|
+
type: String,
|
|
31
|
+
required: true,
|
|
32
|
+
},
|
|
33
|
+
street2: {
|
|
34
|
+
type: String,
|
|
35
|
+
},
|
|
36
|
+
city: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
state: {
|
|
41
|
+
type: String,
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
postalCode: {
|
|
45
|
+
type: String,
|
|
46
|
+
required: true,
|
|
47
|
+
},
|
|
48
|
+
country: {
|
|
49
|
+
type: String,
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
language: {
|
|
53
|
+
type: String,
|
|
54
|
+
},
|
|
55
|
+
cpf: {
|
|
56
|
+
type: String,
|
|
57
|
+
},
|
|
58
|
+
attributes: [
|
|
59
|
+
{
|
|
60
|
+
type: String,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
kycStatus: {
|
|
64
|
+
type: String,
|
|
65
|
+
required: true,
|
|
66
|
+
},
|
|
67
|
+
COIFile: {
|
|
68
|
+
type: String,
|
|
69
|
+
},
|
|
70
|
+
KYCReportFile: {
|
|
71
|
+
type: String,
|
|
72
|
+
},
|
|
73
|
+
brokerId: {
|
|
74
|
+
type: String,
|
|
75
|
+
},
|
|
76
|
+
platformFeeRanges: [
|
|
77
|
+
{
|
|
78
|
+
min: {
|
|
79
|
+
type: Number,
|
|
80
|
+
required: true,
|
|
81
|
+
},
|
|
82
|
+
max: {
|
|
83
|
+
type: Number,
|
|
84
|
+
required: true,
|
|
85
|
+
},
|
|
86
|
+
fee: {
|
|
87
|
+
type: Number,
|
|
88
|
+
required: true,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
}, {
|
|
93
|
+
toJSON: {
|
|
94
|
+
transform(doc, ret) {
|
|
95
|
+
ret.id = ret._id;
|
|
96
|
+
delete ret._id;
|
|
97
|
+
delete ret.__v;
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
BusinessUserSchema.statics.build = (attrs) => {
|
|
102
|
+
return new BusinessUser(attrs);
|
|
103
|
+
};
|
|
104
|
+
const BusinessUser = mongoose_1.default.model("BusinessUser", BusinessUserSchema);
|
|
105
|
+
exports.BusinessUser = BusinessUser;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import { Country } from "../types/country";
|
|
3
|
+
import { Fees } from "../types/fees";
|
|
4
|
+
import { Fiat } from "../types/fiat";
|
|
5
|
+
import { LiquidityProvider } from "../types/liquidity-provider";
|
|
6
|
+
import { OrderStatus } from "../types/order-status";
|
|
7
|
+
import { PaymentMethod } from "../types/payment-method";
|
|
8
|
+
import { PayoutMethod } from "../types/payout-method";
|
|
9
|
+
import { Processor } from "../types/processor";
|
|
10
|
+
import { Side } from "../types/side";
|
|
11
|
+
import { USState } from "../types/us-state";
|
|
12
|
+
interface OrderAttrs {
|
|
13
|
+
userId: string;
|
|
14
|
+
crypto: Crypto;
|
|
15
|
+
side: Side;
|
|
16
|
+
fiat: Fiat;
|
|
17
|
+
paymentMethod?: PaymentMethod;
|
|
18
|
+
payoutMethod?: PayoutMethod;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
status: OrderStatus;
|
|
21
|
+
cryptoAddress: string;
|
|
22
|
+
country: Country;
|
|
23
|
+
state: USState | string;
|
|
24
|
+
amountFiat?: number;
|
|
25
|
+
amountCrypto?: number;
|
|
26
|
+
liquidityProvider?: LiquidityProvider;
|
|
27
|
+
processor?: Processor;
|
|
28
|
+
fees?: Fees;
|
|
29
|
+
price?: number;
|
|
30
|
+
partnerId?: string;
|
|
31
|
+
depositAddress?: string;
|
|
32
|
+
depositTxId?: string;
|
|
33
|
+
withdrawalTxId?: string;
|
|
34
|
+
addressVerified?: boolean;
|
|
35
|
+
brokerCustomerId?: string;
|
|
36
|
+
}
|
|
37
|
+
interface OrderDoc extends mongoose.Document {
|
|
38
|
+
userId: string;
|
|
39
|
+
status: OrderStatus;
|
|
40
|
+
crypto: Crypto;
|
|
41
|
+
side: Side;
|
|
42
|
+
fiat: Fiat;
|
|
43
|
+
paymentMethod?: PaymentMethod;
|
|
44
|
+
payoutMethod?: PayoutMethod;
|
|
45
|
+
createdAt: Date;
|
|
46
|
+
country: Country;
|
|
47
|
+
state: USState | string;
|
|
48
|
+
cryptoAddress: string;
|
|
49
|
+
amountFiat?: number;
|
|
50
|
+
amountCrypto?: number;
|
|
51
|
+
liquidityProvider?: LiquidityProvider;
|
|
52
|
+
processor?: Processor;
|
|
53
|
+
fees?: Fees;
|
|
54
|
+
price?: number;
|
|
55
|
+
partnerId?: string;
|
|
56
|
+
depositAddress?: string;
|
|
57
|
+
depositTxId?: string;
|
|
58
|
+
withdrawalTxId?: string;
|
|
59
|
+
addressVerified?: boolean;
|
|
60
|
+
brokerCustomerId?: string;
|
|
61
|
+
}
|
|
62
|
+
interface OrderModel extends mongoose.Model<OrderDoc> {
|
|
63
|
+
build(attrs: OrderAttrs): OrderDoc;
|
|
64
|
+
}
|
|
65
|
+
declare const Order: OrderModel;
|
|
66
|
+
export { Order, OrderDoc };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Order = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const orderSchema = new mongoose_1.default.Schema({
|
|
9
|
+
userId: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
status: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
crypto: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
side: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
fiat: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true,
|
|
28
|
+
},
|
|
29
|
+
paymentMethod: {
|
|
30
|
+
type: String,
|
|
31
|
+
},
|
|
32
|
+
payoutMethod: {
|
|
33
|
+
type: String,
|
|
34
|
+
},
|
|
35
|
+
createdAt: {
|
|
36
|
+
type: mongoose_1.default.Schema.Types.Date,
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
cryptoAddress: {
|
|
40
|
+
type: String,
|
|
41
|
+
required: true,
|
|
42
|
+
},
|
|
43
|
+
country: {
|
|
44
|
+
type: String,
|
|
45
|
+
required: true,
|
|
46
|
+
},
|
|
47
|
+
state: {
|
|
48
|
+
type: String,
|
|
49
|
+
required: true,
|
|
50
|
+
},
|
|
51
|
+
amountFiat: {
|
|
52
|
+
type: Number,
|
|
53
|
+
},
|
|
54
|
+
amountCrypto: {
|
|
55
|
+
type: Number,
|
|
56
|
+
},
|
|
57
|
+
processor: {
|
|
58
|
+
type: String,
|
|
59
|
+
},
|
|
60
|
+
liquidityProvider: {
|
|
61
|
+
type: String,
|
|
62
|
+
},
|
|
63
|
+
depositTxId: {
|
|
64
|
+
type: String,
|
|
65
|
+
},
|
|
66
|
+
withdrawalTxId: {
|
|
67
|
+
type: String,
|
|
68
|
+
},
|
|
69
|
+
depositAddress: {
|
|
70
|
+
type: String,
|
|
71
|
+
},
|
|
72
|
+
fees: {
|
|
73
|
+
processingFeeCrypto: {
|
|
74
|
+
type: Number,
|
|
75
|
+
},
|
|
76
|
+
transferFeeCrypto: {
|
|
77
|
+
type: Number,
|
|
78
|
+
},
|
|
79
|
+
platformFeeCrypto: {
|
|
80
|
+
type: Number,
|
|
81
|
+
},
|
|
82
|
+
processingFeeFiat: {
|
|
83
|
+
type: Number,
|
|
84
|
+
},
|
|
85
|
+
transferFeeFiat: {
|
|
86
|
+
type: Number,
|
|
87
|
+
},
|
|
88
|
+
platformFeeFiat: {
|
|
89
|
+
type: Number,
|
|
90
|
+
},
|
|
91
|
+
partnerFeeFiat: {
|
|
92
|
+
type: Number,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
price: {
|
|
96
|
+
type: Number,
|
|
97
|
+
},
|
|
98
|
+
partnerId: {
|
|
99
|
+
type: String,
|
|
100
|
+
},
|
|
101
|
+
addressVerified: {
|
|
102
|
+
type: Boolean,
|
|
103
|
+
},
|
|
104
|
+
brokerCustomerId: {
|
|
105
|
+
type: String,
|
|
106
|
+
},
|
|
107
|
+
}, {
|
|
108
|
+
toJSON: {
|
|
109
|
+
transform(doc, ret) {
|
|
110
|
+
ret.id = ret._id;
|
|
111
|
+
delete ret._id;
|
|
112
|
+
delete ret.__v;
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
orderSchema.statics.build = (attrs) => {
|
|
117
|
+
return new Order(attrs);
|
|
118
|
+
};
|
|
119
|
+
const Order = mongoose_1.default.model("Order", orderSchema);
|
|
120
|
+
exports.Order = Order;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import { PartnerStatus } from "../types/partner-status";
|
|
3
|
+
interface PartnerAttrs {
|
|
4
|
+
name: string;
|
|
5
|
+
status: PartnerStatus;
|
|
6
|
+
partnerFee: number;
|
|
7
|
+
platformFee: number;
|
|
8
|
+
color?: string;
|
|
9
|
+
logo?: string;
|
|
10
|
+
apiKeys?: {
|
|
11
|
+
value: string;
|
|
12
|
+
label: string;
|
|
13
|
+
id: string;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
interface PartnerDoc extends mongoose.Document {
|
|
17
|
+
name: string;
|
|
18
|
+
status: PartnerStatus;
|
|
19
|
+
partnerFee: number;
|
|
20
|
+
platformFee: number;
|
|
21
|
+
color?: string;
|
|
22
|
+
logo?: string;
|
|
23
|
+
apiKeys?: {
|
|
24
|
+
value: string;
|
|
25
|
+
label: string;
|
|
26
|
+
id: string;
|
|
27
|
+
}[];
|
|
28
|
+
}
|
|
29
|
+
interface PartnerModel extends mongoose.Model<PartnerDoc> {
|
|
30
|
+
build(attrs: PartnerAttrs): PartnerDoc;
|
|
31
|
+
}
|
|
32
|
+
declare const Partner: PartnerModel;
|
|
33
|
+
export { Partner, PartnerDoc };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Partner = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const PartnerSchema = new mongoose_1.default.Schema({
|
|
9
|
+
name: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
status: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
partnerFee: {
|
|
18
|
+
type: Number,
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
platformFee: {
|
|
22
|
+
type: Number,
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
color: {
|
|
26
|
+
type: String,
|
|
27
|
+
},
|
|
28
|
+
logo: {
|
|
29
|
+
type: String,
|
|
30
|
+
},
|
|
31
|
+
apiKeys: [
|
|
32
|
+
{
|
|
33
|
+
value: {
|
|
34
|
+
type: String,
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
label: {
|
|
38
|
+
type: String,
|
|
39
|
+
},
|
|
40
|
+
id: {
|
|
41
|
+
type: String,
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
}, {
|
|
47
|
+
toJSON: {
|
|
48
|
+
transform(doc, ret) {
|
|
49
|
+
ret.id = ret._id;
|
|
50
|
+
delete ret._id;
|
|
51
|
+
delete ret.__v;
|
|
52
|
+
ret.apiKeys.forEach((apiKey) => {
|
|
53
|
+
delete apiKey.value;
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
PartnerSchema.statics.build = (attrs) => {
|
|
59
|
+
return new Partner(attrs);
|
|
60
|
+
};
|
|
61
|
+
const Partner = mongoose_1.default.model("Partner", PartnerSchema);
|
|
62
|
+
exports.Partner = Partner;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import { Country } from "../types/country";
|
|
3
|
+
import { KYCStatus } from "../types/kyc-status";
|
|
4
|
+
import { Language } from "../types/language";
|
|
5
|
+
import { USState } from "../types/us-state";
|
|
6
|
+
import { UserAttribute } from "../types/user-attribute";
|
|
7
|
+
import { UserType } from "../types/user-type";
|
|
8
|
+
interface UserAttrs {
|
|
9
|
+
type: UserType;
|
|
10
|
+
firstName: string;
|
|
11
|
+
lastName: string;
|
|
12
|
+
phoneNumber: string;
|
|
13
|
+
birthday: Date;
|
|
14
|
+
email: string;
|
|
15
|
+
street1: string;
|
|
16
|
+
street2?: string;
|
|
17
|
+
city: string;
|
|
18
|
+
state: USState | string;
|
|
19
|
+
postalCode: string;
|
|
20
|
+
country: Country;
|
|
21
|
+
kycStatus: KYCStatus;
|
|
22
|
+
cpf?: string;
|
|
23
|
+
language?: Language;
|
|
24
|
+
attributes?: UserAttribute[];
|
|
25
|
+
partnerId?: string;
|
|
26
|
+
}
|
|
27
|
+
interface UserModel extends mongoose.Model<UserDoc> {
|
|
28
|
+
build(attrs: UserAttrs): UserDoc;
|
|
29
|
+
}
|
|
30
|
+
interface UserDoc extends mongoose.Document {
|
|
31
|
+
type: UserType;
|
|
32
|
+
firstName: string;
|
|
33
|
+
lastName: string;
|
|
34
|
+
phoneNumber: string;
|
|
35
|
+
birthday: Date;
|
|
36
|
+
email: string;
|
|
37
|
+
street1: string;
|
|
38
|
+
street2?: string;
|
|
39
|
+
city: string;
|
|
40
|
+
state: USState | string;
|
|
41
|
+
postalCode: string;
|
|
42
|
+
country: Country;
|
|
43
|
+
kycStatus: KYCStatus;
|
|
44
|
+
cpf?: string;
|
|
45
|
+
language?: Language;
|
|
46
|
+
attributes?: UserAttribute[];
|
|
47
|
+
partnerId?: string;
|
|
48
|
+
}
|
|
49
|
+
declare const User: UserModel;
|
|
50
|
+
export { User, UserDoc };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.User = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const userSchema = new mongoose_1.default.Schema({
|
|
9
|
+
type: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
firstName: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
lastName: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
phoneNumber: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
birthday: {
|
|
26
|
+
type: Date,
|
|
27
|
+
required: true,
|
|
28
|
+
},
|
|
29
|
+
email: {
|
|
30
|
+
type: String,
|
|
31
|
+
required: true,
|
|
32
|
+
},
|
|
33
|
+
street1: {
|
|
34
|
+
type: String,
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
street2: {
|
|
38
|
+
type: String,
|
|
39
|
+
},
|
|
40
|
+
city: {
|
|
41
|
+
type: String,
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
state: {
|
|
45
|
+
type: String,
|
|
46
|
+
required: true,
|
|
47
|
+
},
|
|
48
|
+
postalCode: {
|
|
49
|
+
type: String,
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
country: {
|
|
53
|
+
type: String,
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
language: {
|
|
57
|
+
type: String,
|
|
58
|
+
},
|
|
59
|
+
cpf: {
|
|
60
|
+
type: String,
|
|
61
|
+
},
|
|
62
|
+
attributes: [
|
|
63
|
+
{
|
|
64
|
+
type: String,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
kycStatus: {
|
|
68
|
+
type: String,
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
71
|
+
partnerId: {
|
|
72
|
+
type: String,
|
|
73
|
+
},
|
|
74
|
+
}, {
|
|
75
|
+
toJSON: {
|
|
76
|
+
transform(doc, ret) {
|
|
77
|
+
ret.id = ret._id;
|
|
78
|
+
delete ret._id;
|
|
79
|
+
delete ret.__v;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
userSchema.statics.build = (attrs) => {
|
|
84
|
+
return new User(attrs);
|
|
85
|
+
};
|
|
86
|
+
const User = mongoose_1.default.model("User", userSchema);
|
|
87
|
+
exports.User = User;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ApiKey = void 0;
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
class ApiKey {
|
|
15
|
+
static toHash(apiKey) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const salt = process.env.API_KEY_SALT;
|
|
18
|
+
const hash = (0, crypto_1.createHmac)("sha256", salt);
|
|
19
|
+
hash.update(apiKey);
|
|
20
|
+
return hash.digest("hex");
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ApiKey = ApiKey;
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Password = void 0;
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
const util_1 = require("util");
|
|
15
|
+
const scryptAsync = (0, util_1.promisify)(crypto_1.scrypt);
|
|
16
|
+
class Password {
|
|
17
|
+
static toHash(password) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const salt = (0, crypto_1.randomBytes)(8).toString("hex");
|
|
20
|
+
const buf = (yield scryptAsync(password, salt, 64));
|
|
21
|
+
return `${buf.toString("hex")}.${salt}`;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
static compare(storedPassword, suppliedPassword) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const [hashedPassword, salt] = storedPassword.split(".");
|
|
27
|
+
const buf = (yield scryptAsync(suppliedPassword, salt, 64));
|
|
28
|
+
return buf.toString("hex") === hashedPassword;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Password = Password;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.373",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"express": "^4.18.1",
|
|
26
26
|
"express-validator": "^6.14.2",
|
|
27
27
|
"jsonwebtoken": "^8.5.1",
|
|
28
|
+
"mongoose": "^7.0.2",
|
|
28
29
|
"node-nats-streaming": "^0.3.2"
|
|
29
30
|
}
|
|
30
31
|
}
|