@riocrypto/common-server 1.0.548 → 1.0.550
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/bitstamp-client.d.ts +1 -1
- package/build/clients/bitstamp-client.js +14 -1
- package/build/clients/ccxt-client.js +20 -4
- package/build/clients/etherscan-client.js +6 -1
- package/build/clients/fireblocks-client.d.ts +1 -1
- package/build/clients/fireblocks-client.js +14 -1
- package/build/clients/fixer-client.d.ts +1 -1
- package/build/clients/fixer-client.js +10 -1
- package/build/clients/gueno-client.d.ts +1 -1
- package/build/clients/gueno-client.js +14 -1
- package/build/clients/kushki-client.d.ts +1 -1
- package/build/clients/kushki-client.js +9 -1
- package/build/clients/s3-client.d.ts +6 -0
- package/build/clients/s3-client.js +52 -0
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/middlewares/authorize.js +15 -3
- package/build/middlewares/current-admin-auth.d.ts +1 -1
- package/build/middlewares/current-admin-auth.js +17 -3
- package/build/middlewares/current-auth.d.ts +1 -1
- package/build/middlewares/current-auth.js +17 -3
- package/build/middlewares/get-partner.js +6 -1
- package/build/middlewares/verify-admin-api-key.d.ts +1 -1
- package/build/middlewares/verify-admin-api-key.js +17 -3
- package/build/services/apiKey.js +6 -1
- package/package.json +2 -2
- package/build/services/s3.d.ts +0 -5
- package/build/services/s3.js +0 -21
|
@@ -36,6 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.bitstampClient = void 0;
|
|
39
|
+
const common_1 = require("@riocrypto/common");
|
|
39
40
|
const axios_1 = __importDefault(require("axios"));
|
|
40
41
|
const crypto = __importStar(require("crypto"));
|
|
41
42
|
const uuid = __importStar(require("uuid"));
|
|
@@ -80,4 +81,16 @@ class BitstampClient {
|
|
|
80
81
|
});
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
+
const createBitstampClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
const BITSTAMP_API_KEY = yield common_1.secretManagerClient.getSecretValue("BITSTAMP_API_KEY");
|
|
86
|
+
if (!BITSTAMP_API_KEY) {
|
|
87
|
+
throw new Error("Unable to get BITSTAMP_API_KEY");
|
|
88
|
+
}
|
|
89
|
+
const BITSTAMP_SECRET = yield common_1.secretManagerClient.getSecretValue("BITSTAMP_SECRET");
|
|
90
|
+
if (!BITSTAMP_SECRET) {
|
|
91
|
+
throw new Error("Unable to get BITSTAMP_SECRET");
|
|
92
|
+
}
|
|
93
|
+
const bitstampClient = new BitstampClient(BITSTAMP_API_KEY, BITSTAMP_SECRET);
|
|
94
|
+
return bitstampClient;
|
|
95
|
+
});
|
|
96
|
+
exports.bitstampClient = createBitstampClient();
|
|
@@ -123,10 +123,18 @@ class CCXTClient {
|
|
|
123
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
124
|
for (let exchangeId of ccxt_1.default.exchanges) {
|
|
125
125
|
if (exchangeId === "bitstamp") {
|
|
126
|
+
const SECRET = yield common_1.secretManagerClient.getSecretValue(`${exchangeId.toLocaleUpperCase()}_SECRET`);
|
|
127
|
+
if (!SECRET) {
|
|
128
|
+
throw new Error("Unable to get SECRET");
|
|
129
|
+
}
|
|
130
|
+
const API_KEY = yield common_1.secretManagerClient.getSecretValue(`${exchangeId.toLocaleUpperCase()}_API_KEY`);
|
|
131
|
+
if (!API_KEY) {
|
|
132
|
+
throw new Error("Unable to get API_KEY");
|
|
133
|
+
}
|
|
126
134
|
//@ts-ignore
|
|
127
135
|
const exchangeClass = ccxt_1.default[exchangeId], exchange = new exchangeClass({
|
|
128
|
-
apiKey:
|
|
129
|
-
secret:
|
|
136
|
+
apiKey: API_KEY,
|
|
137
|
+
secret: SECRET,
|
|
130
138
|
});
|
|
131
139
|
return exchange;
|
|
132
140
|
}
|
|
@@ -146,10 +154,18 @@ class CCXTClient {
|
|
|
146
154
|
}
|
|
147
155
|
getExchange(ccxtLiquidityProvider) {
|
|
148
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
const SECRET = yield common_1.secretManagerClient.getSecretValue(`${ccxtLiquidityProvider.toLocaleUpperCase()}_SECRET`);
|
|
158
|
+
if (!SECRET) {
|
|
159
|
+
throw new Error("Unable to get SECRET");
|
|
160
|
+
}
|
|
161
|
+
const API_KEY = yield common_1.secretManagerClient.getSecretValue(`${ccxtLiquidityProvider.toLocaleUpperCase()}_API_KEY`);
|
|
162
|
+
if (!API_KEY) {
|
|
163
|
+
throw new Error("Unable to get API_KEY");
|
|
164
|
+
}
|
|
149
165
|
// @ts-ignore
|
|
150
166
|
const exchangeClass = ccxt_1.default[ccxtLiquidityProvider], exchange = new exchangeClass({
|
|
151
|
-
apiKey:
|
|
152
|
-
secret:
|
|
167
|
+
apiKey: API_KEY,
|
|
168
|
+
secret: SECRET,
|
|
153
169
|
});
|
|
154
170
|
return exchange;
|
|
155
171
|
});
|
|
@@ -10,13 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.EtherscanClient = void 0;
|
|
13
|
+
const common_1 = require("@riocrypto/common");
|
|
13
14
|
class EtherscanClient {
|
|
14
15
|
constructor(axios) {
|
|
15
16
|
this.axios = axios;
|
|
16
17
|
}
|
|
17
18
|
getTransactions(address) {
|
|
18
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const
|
|
20
|
+
const ETHERSCAN_API_KEY = yield common_1.secretManagerClient.getSecretValue("ETHERSCAN_API_KEY");
|
|
21
|
+
if (!ETHERSCAN_API_KEY) {
|
|
22
|
+
throw new Error("Unable to get ETHERSCAN_API_KEY");
|
|
23
|
+
}
|
|
24
|
+
const { data } = yield this.axios.get(`https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=1&offset=100&sort=asc&apikey=${ETHERSCAN_API_KEY}`);
|
|
20
25
|
return data.result;
|
|
21
26
|
});
|
|
22
27
|
}
|
|
@@ -13,5 +13,5 @@ declare class FireblocksClient {
|
|
|
13
13
|
getTransactions(crypto: Crypto): Promise<any>;
|
|
14
14
|
getDepositAddress(crypto: Crypto): Promise<string>;
|
|
15
15
|
}
|
|
16
|
-
export declare const fireblocksClient: FireblocksClient
|
|
16
|
+
export declare const fireblocksClient: Promise<FireblocksClient>;
|
|
17
17
|
export {};
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.fireblocksClient = void 0;
|
|
13
13
|
const fireblocks_sdk_1 = require("fireblocks-sdk");
|
|
14
|
+
const common_1 = require("@riocrypto/common");
|
|
14
15
|
class FireblocksClient {
|
|
15
16
|
constructor(privateKey, apiKey) {
|
|
16
17
|
this.fireblocks = new fireblocks_sdk_1.FireblocksSDK(privateKey, apiKey, "https://api.fireblocks.io");
|
|
@@ -142,4 +143,16 @@ class FireblocksClient {
|
|
|
142
143
|
});
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
|
-
|
|
146
|
+
const createFireblocksClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
const FIREBLOCKS_PRIVATE_KEY = yield common_1.secretManagerClient.getSecretValue("FIREBLOCKS_PRIVATE_KEY");
|
|
148
|
+
if (!FIREBLOCKS_PRIVATE_KEY) {
|
|
149
|
+
throw new Error("Unable to get FIREBLOCKS_PRIVATE_KEY");
|
|
150
|
+
}
|
|
151
|
+
const FIREBLOCKS_API_KEY = yield common_1.secretManagerClient.getSecretValue("FIREBLOCKS_API_KEY");
|
|
152
|
+
if (!FIREBLOCKS_API_KEY) {
|
|
153
|
+
throw new Error("Unable to get FIREBLOCKS_API_KEY");
|
|
154
|
+
}
|
|
155
|
+
const fireblocksClient = new FireblocksClient(FIREBLOCKS_PRIVATE_KEY, FIREBLOCKS_API_KEY);
|
|
156
|
+
return fireblocksClient;
|
|
157
|
+
});
|
|
158
|
+
exports.fireblocksClient = createFireblocksClient();
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.fixerClient = void 0;
|
|
16
|
+
const common_1 = require("@riocrypto/common");
|
|
16
17
|
const axios_1 = __importDefault(require("axios"));
|
|
17
18
|
class FixerClient {
|
|
18
19
|
constructor(apiKey) {
|
|
@@ -31,4 +32,12 @@ class FixerClient {
|
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
const createFixerClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const FIXER_API_KEY = yield common_1.secretManagerClient.getSecretValue("FIXER_API_KEY");
|
|
37
|
+
if (!FIXER_API_KEY) {
|
|
38
|
+
throw new Error("Unable to get FIXER_API_KEY");
|
|
39
|
+
}
|
|
40
|
+
const fixerClient = new FixerClient(FIXER_API_KEY);
|
|
41
|
+
return fixerClient;
|
|
42
|
+
});
|
|
43
|
+
exports.fixerClient = createFixerClient();
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.guenoClient = void 0;
|
|
16
|
+
const common_1 = require("@riocrypto/common");
|
|
16
17
|
const axios_1 = __importDefault(require("axios"));
|
|
17
18
|
class GuenoClient {
|
|
18
19
|
constructor(email, password, env) {
|
|
@@ -41,4 +42,16 @@ class GuenoClient {
|
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
+
const createGuenoClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const GUENO_EMAIL = yield common_1.secretManagerClient.getSecretValue("GUENO_EMAIL");
|
|
47
|
+
if (!GUENO_EMAIL) {
|
|
48
|
+
throw new Error("Unable to get GUENO_EMAIL");
|
|
49
|
+
}
|
|
50
|
+
const GUENO_PASSWORD = yield common_1.secretManagerClient.getSecretValue("GUENO_PASSWORD");
|
|
51
|
+
if (!GUENO_PASSWORD) {
|
|
52
|
+
throw new Error("Unable to get GUENO_PASSWORD");
|
|
53
|
+
}
|
|
54
|
+
const guenoClient = new GuenoClient(GUENO_EMAIL, GUENO_PASSWORD, process.env.GUENO_ENV);
|
|
55
|
+
return guenoClient;
|
|
56
|
+
});
|
|
57
|
+
exports.guenoClient = createGuenoClient();
|
|
@@ -8,5 +8,5 @@ declare class KushkiClient {
|
|
|
8
8
|
createBankPaymentToken(order: Order, user: User | BusinessUser): Promise<any>;
|
|
9
9
|
createBankPayment(order: Order, user: User | BusinessUser, token: string): Promise<any>;
|
|
10
10
|
}
|
|
11
|
-
export declare const kushkiClient: KushkiClient
|
|
11
|
+
export declare const kushkiClient: Promise<KushkiClient>;
|
|
12
12
|
export {};
|
|
@@ -147,4 +147,12 @@ class KushkiClient {
|
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
const createKushkiClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
const KUSHKI_PRIVATE_MERCHANT_ID = yield common_1.secretManagerClient.getSecretValue("KUSHKI_PRIVATE_MERCHANT_ID");
|
|
152
|
+
if (!KUSHKI_PRIVATE_MERCHANT_ID) {
|
|
153
|
+
throw new Error("Unable to get KUSHKI_PRIVATE_MERCHANT_ID");
|
|
154
|
+
}
|
|
155
|
+
const kushkiClient = new KushkiClient(KUSHKI_PRIVATE_MERCHANT_ID, process.env.KUSHKI_ENV);
|
|
156
|
+
return kushkiClient;
|
|
157
|
+
});
|
|
158
|
+
exports.kushkiClient = createKushkiClient();
|
|
@@ -0,0 +1,52 @@
|
|
|
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.s3Client = exports.s3 = void 0;
|
|
13
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
14
|
+
const common_1 = require("@riocrypto/common");
|
|
15
|
+
class s3 {
|
|
16
|
+
constructor(endpoint, region, accessKey, secretKey) {
|
|
17
|
+
this._client = new client_s3_1.S3Client({
|
|
18
|
+
endpoint,
|
|
19
|
+
forcePathStyle: false,
|
|
20
|
+
region,
|
|
21
|
+
credentials: {
|
|
22
|
+
accessKeyId: accessKey,
|
|
23
|
+
secretAccessKey: secretKey, // Secret access key defined through an environment variable.
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
get client() {
|
|
28
|
+
return this._client;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.s3 = s3;
|
|
32
|
+
const createS3Client = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const S3_ENDPOINT = yield common_1.secretManagerClient.getSecretValue("S3_ENDPOINT");
|
|
34
|
+
if (!S3_ENDPOINT) {
|
|
35
|
+
throw new Error("Unable to get S3_ENDPOINT");
|
|
36
|
+
}
|
|
37
|
+
const S3_ACCESS_KEY = yield common_1.secretManagerClient.getSecretValue("S3_ACCESS_KEY");
|
|
38
|
+
if (!S3_ACCESS_KEY) {
|
|
39
|
+
throw new Error("Unable to get S3_ACCESS_KEY");
|
|
40
|
+
}
|
|
41
|
+
const S3_SECRET_KEY = yield common_1.secretManagerClient.getSecretValue("S3_SECRET_KEY");
|
|
42
|
+
if (!S3_SECRET_KEY) {
|
|
43
|
+
throw new Error("Unable to get S3_SECRET_KEY");
|
|
44
|
+
}
|
|
45
|
+
const S3_REGION = yield common_1.secretManagerClient.getSecretValue("S3_REGION");
|
|
46
|
+
if (!S3_REGION) {
|
|
47
|
+
throw new Error("Unable to get S3_REGION");
|
|
48
|
+
}
|
|
49
|
+
const s3Client = new s3(S3_ENDPOINT, S3_REGION, S3_ACCESS_KEY, S3_SECRET_KEY);
|
|
50
|
+
return s3Client;
|
|
51
|
+
});
|
|
52
|
+
exports.s3Client = createS3Client();
|
package/build/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export * from "./middlewares/validate-kyc";
|
|
|
14
14
|
export * from "./middlewares/authorize";
|
|
15
15
|
export * from "./services/apiKey";
|
|
16
16
|
export * from "./services/password";
|
|
17
|
-
export * from "./services/s3";
|
|
18
17
|
export * from "./models/admin-auth";
|
|
19
18
|
export * from "./models/auth";
|
|
20
19
|
export * from "./models/business-user";
|
|
@@ -38,4 +37,5 @@ export * from "./clients/fireblocks-client";
|
|
|
38
37
|
export * from "./clients/kapstar-client";
|
|
39
38
|
export * from "./clients/etherscan-client";
|
|
40
39
|
export * from "./clients/rio-client";
|
|
40
|
+
export * from "./clients/s3-client";
|
|
41
41
|
export * from "./helpers/get-user-helper";
|
package/build/index.js
CHANGED
|
@@ -30,7 +30,6 @@ __exportStar(require("./middlewares/validate-kyc"), exports);
|
|
|
30
30
|
__exportStar(require("./middlewares/authorize"), exports);
|
|
31
31
|
__exportStar(require("./services/apiKey"), exports);
|
|
32
32
|
__exportStar(require("./services/password"), exports);
|
|
33
|
-
__exportStar(require("./services/s3"), exports);
|
|
34
33
|
__exportStar(require("./models/admin-auth"), exports);
|
|
35
34
|
__exportStar(require("./models/auth"), exports);
|
|
36
35
|
__exportStar(require("./models/business-user"), exports);
|
|
@@ -54,4 +53,5 @@ __exportStar(require("./clients/fireblocks-client"), exports);
|
|
|
54
53
|
__exportStar(require("./clients/kapstar-client"), exports);
|
|
55
54
|
__exportStar(require("./clients/etherscan-client"), exports);
|
|
56
55
|
__exportStar(require("./clients/rio-client"), exports);
|
|
56
|
+
__exportStar(require("./clients/s3-client"), exports);
|
|
57
57
|
__exportStar(require("./helpers/get-user-helper"), exports);
|
|
@@ -25,7 +25,11 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
25
25
|
let missingKYC = false;
|
|
26
26
|
if (authorizationTypes.includes(common_1.AuthorizationType.AdminAPI)) {
|
|
27
27
|
let apiKey = req.header("x-api-key");
|
|
28
|
-
|
|
28
|
+
const ADMIN_API_KEY = yield common_1.secretManagerClient.getSecretValue("ADMIN_API_KEY");
|
|
29
|
+
if (!ADMIN_API_KEY) {
|
|
30
|
+
throw new Error("Unable to get ADMIN_API_KEY");
|
|
31
|
+
}
|
|
32
|
+
if (apiKey === ADMIN_API_KEY) {
|
|
29
33
|
req.validAdminApiKey = true;
|
|
30
34
|
}
|
|
31
35
|
}
|
|
@@ -63,7 +67,11 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
63
67
|
}
|
|
64
68
|
else if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.accessToken) {
|
|
65
69
|
try {
|
|
66
|
-
const
|
|
70
|
+
const ACCESS_TOKEN_SECRET = yield common_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
|
|
71
|
+
if (!ACCESS_TOKEN_SECRET) {
|
|
72
|
+
throw new Error("Unable to get ACCESS_TOKEN_SECRET");
|
|
73
|
+
}
|
|
74
|
+
const payload = jsonwebtoken_1.default.verify(req.cookies.accessToken, ACCESS_TOKEN_SECRET);
|
|
67
75
|
req.currentAuth = payload;
|
|
68
76
|
}
|
|
69
77
|
catch (err) { }
|
|
@@ -80,7 +88,11 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
80
88
|
if (authorizationTypes.includes(common_1.AuthorizationType.Admin)) {
|
|
81
89
|
if ((_f = req.cookies) === null || _f === void 0 ? void 0 : _f.adminAccessToken) {
|
|
82
90
|
try {
|
|
83
|
-
const
|
|
91
|
+
const ADMIN_ACCESS_TOKEN_SECRET = yield common_1.secretManagerClient.getSecretValue("ADMIN_ACCESS_TOKEN_SECRET");
|
|
92
|
+
if (!ADMIN_ACCESS_TOKEN_SECRET) {
|
|
93
|
+
throw new Error("Unable to get ADMIN_ACCESS_TOKEN_SECRET");
|
|
94
|
+
}
|
|
95
|
+
const payload = jsonwebtoken_1.default.verify(req.cookies.adminAccessToken, ADMIN_ACCESS_TOKEN_SECRET);
|
|
84
96
|
req.currentAdminAuth = payload;
|
|
85
97
|
}
|
|
86
98
|
catch (err) { }
|
|
@@ -1,20 +1,34 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
15
|
exports.currentAdminAuth = void 0;
|
|
16
|
+
const common_1 = require("@riocrypto/common");
|
|
7
17
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
const currentAdminAuth = (req, res, next) => {
|
|
18
|
+
const currentAdminAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
9
19
|
var _a;
|
|
10
20
|
if (!((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.adminAccesToken)) {
|
|
11
21
|
return next();
|
|
12
22
|
}
|
|
13
23
|
try {
|
|
14
|
-
const
|
|
24
|
+
const ADMIN_ACCESS_TOKEN_SECRET = yield common_1.secretManagerClient.getSecretValue("ADMIN_ACCESS_TOKEN_SECRET");
|
|
25
|
+
if (!ADMIN_ACCESS_TOKEN_SECRET) {
|
|
26
|
+
throw new Error("ADMIN_ACCESS_TOKEN_SECRET");
|
|
27
|
+
}
|
|
28
|
+
const payload = jsonwebtoken_1.default.verify(req.cookies.adminAccesToken, ADMIN_ACCESS_TOKEN_SECRET);
|
|
15
29
|
req.currentAdminAuth = payload;
|
|
16
30
|
}
|
|
17
31
|
catch (err) { }
|
|
18
32
|
next();
|
|
19
|
-
};
|
|
33
|
+
});
|
|
20
34
|
exports.currentAdminAuth = currentAdminAuth;
|
|
@@ -1,20 +1,34 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
15
|
exports.currentAuth = void 0;
|
|
16
|
+
const common_1 = require("@riocrypto/common");
|
|
7
17
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
const currentAuth = (req, res, next) => {
|
|
18
|
+
const currentAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
9
19
|
var _a;
|
|
10
20
|
if (!((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.accessToken)) {
|
|
11
21
|
return next();
|
|
12
22
|
}
|
|
13
23
|
try {
|
|
14
|
-
const
|
|
24
|
+
const ACCESS_TOKEN_SECRET = yield common_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
|
|
25
|
+
if (!ACCESS_TOKEN_SECRET) {
|
|
26
|
+
throw new Error("Unable to get ACCESS_TOKEN_SECRET");
|
|
27
|
+
}
|
|
28
|
+
const payload = jsonwebtoken_1.default.verify(req.cookies.accessToken, ACCESS_TOKEN_SECRET);
|
|
15
29
|
req.currentAuth = payload;
|
|
16
30
|
}
|
|
17
31
|
catch (err) { }
|
|
18
32
|
next();
|
|
19
|
-
};
|
|
33
|
+
});
|
|
20
34
|
exports.currentAuth = currentAuth;
|
|
@@ -16,10 +16,15 @@ exports.getPartner = void 0;
|
|
|
16
16
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
17
17
|
const partner_1 = require("../models/partner");
|
|
18
18
|
const apiKey_1 = require("../services/apiKey");
|
|
19
|
+
const common_1 = require("@riocrypto/common");
|
|
19
20
|
const getPartner = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
21
|
try {
|
|
21
22
|
if (!req.headers["x-api-key"]) {
|
|
22
|
-
const
|
|
23
|
+
const PARTNER_ACCESS_TOKEN_SECRET = yield common_1.secretManagerClient.getSecretValue("PARTNER_ACCESS_TOKEN_SECRET");
|
|
24
|
+
if (!PARTNER_ACCESS_TOKEN_SECRET) {
|
|
25
|
+
throw new Error("Unable to get PARTNER_ACCESS_TOKEN_SECRET");
|
|
26
|
+
}
|
|
27
|
+
const payload = jsonwebtoken_1.default.verify(req.cookies.partnerAuthJwt, PARTNER_ACCESS_TOKEN_SECRET);
|
|
23
28
|
req.partnerId = payload.partnerId;
|
|
24
29
|
}
|
|
25
30
|
else {
|
|
@@ -1,11 +1,25 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.verifyAdminApiKey = void 0;
|
|
4
|
-
const
|
|
13
|
+
const common_1 = require("@riocrypto/common");
|
|
14
|
+
const verifyAdminApiKey = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
5
15
|
let apiKey = req.header("x-api-key");
|
|
6
|
-
|
|
16
|
+
const ADMIN_API_KEY = yield common_1.secretManagerClient.getSecretValue("ADMIN_API_KEY");
|
|
17
|
+
if (!ADMIN_API_KEY) {
|
|
18
|
+
throw new Error("Unable to get ADMIN_API_KEY");
|
|
19
|
+
}
|
|
20
|
+
if (apiKey === ADMIN_API_KEY) {
|
|
7
21
|
req.validAdminApiKey = true;
|
|
8
22
|
}
|
|
9
23
|
next();
|
|
10
|
-
};
|
|
24
|
+
});
|
|
11
25
|
exports.verifyAdminApiKey = verifyAdminApiKey;
|
package/build/services/apiKey.js
CHANGED
|
@@ -10,11 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ApiKey = void 0;
|
|
13
|
+
const common_1 = require("@riocrypto/common");
|
|
13
14
|
const crypto_1 = require("crypto");
|
|
14
15
|
class ApiKey {
|
|
15
16
|
static toHash(apiKey) {
|
|
16
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const
|
|
18
|
+
const API_KEY_SALT = yield common_1.secretManagerClient.getSecretValue("API_KEY_SALT");
|
|
19
|
+
if (!API_KEY_SALT) {
|
|
20
|
+
throw new Error("Unable to get API_KEY_SALT");
|
|
21
|
+
}
|
|
22
|
+
const salt = API_KEY_SALT;
|
|
18
23
|
const hash = (0, crypto_1.createHmac)("sha256", salt);
|
|
19
24
|
hash.update(apiKey);
|
|
20
25
|
return hash.digest("hex");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.550",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@aws-sdk/client-s3": "^3.297.0",
|
|
25
|
-
"@riocrypto/common": "^1.0.
|
|
25
|
+
"@riocrypto/common": "^1.0.549",
|
|
26
26
|
"@types/express": "^4.17.13",
|
|
27
27
|
"axios": "^0.27.2",
|
|
28
28
|
"ccxt": "^3.0.30",
|
package/build/services/s3.d.ts
DELETED
package/build/services/s3.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.s3 = void 0;
|
|
4
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
5
|
-
class s3 {
|
|
6
|
-
constructor() {
|
|
7
|
-
this._client = new client_s3_1.S3Client({
|
|
8
|
-
endpoint: process.env.S3_ENDPOINT,
|
|
9
|
-
forcePathStyle: false,
|
|
10
|
-
region: process.env.S3_REGION,
|
|
11
|
-
credentials: {
|
|
12
|
-
accessKeyId: process.env.S3_ACCESS_KEY,
|
|
13
|
-
secretAccessKey: process.env.S3_SECRET_KEY, // Secret access key defined through an environment variable.
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
get client() {
|
|
18
|
-
return this._client;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.s3 = s3;
|