@riocrypto/common-server 1.0.547 → 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.
@@ -12,5 +12,5 @@ declare class BitstampClient {
12
12
  }>;
13
13
  getTransactions(): Promise<any>;
14
14
  }
15
- export declare const bitstampClient: BitstampClient;
15
+ export declare const bitstampClient: Promise<BitstampClient>;
16
16
  export {};
@@ -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
- exports.bitstampClient = new BitstampClient(process.env.BITSTAMP_API_KEY, process.env.BITSTAMP_SECRET);
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: process.env[`${exchangeId.toLocaleUpperCase()}_API_KEY`],
129
- secret: process.env[`${exchangeId.toLocaleUpperCase()}_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: process.env[`${ccxtLiquidityProvider.toLocaleUpperCase()}_API_KEY`],
152
- secret: process.env[`${ccxtLiquidityProvider.toLocaleUpperCase()}_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 { 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=${"DDR78IVPYXCVGFKTT6YWBBYZBRD18S2EW1"}`);
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
- exports.fireblocksClient = new FireblocksClient(process.env.FIREBLOCKS_PRIVATE_KEY, process.env.FIREBLOCKS_API_KEY);
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();
@@ -4,5 +4,5 @@ declare class FixerClient {
4
4
  constructor(apiKey: string);
5
5
  convert(from: Fiat, to: Fiat): Promise<number>;
6
6
  }
7
- export declare const fixerClient: FixerClient;
7
+ export declare const fixerClient: Promise<FixerClient>;
8
8
  export {};
@@ -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
- exports.fixerClient = new FixerClient(process.env.FIXER_API_KEY);
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();
@@ -6,5 +6,5 @@ declare class GuenoClient {
6
6
  getAddressRiskScore(address: string, protocol: Crypto): Promise<any>;
7
7
  getAccessToken(): Promise<any>;
8
8
  }
9
- export declare const guenoClient: GuenoClient;
9
+ export declare const guenoClient: Promise<GuenoClient>;
10
10
  export {};
@@ -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
- exports.guenoClient = new GuenoClient(process.env.GUENO_EMAIL, process.env.GUENO_PASSWORD, process.env.GUENO_ENV);
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
- exports.kushkiClient = new KushkiClient(process.env.KUSHKI_PRIVATE_MERCHANT_ID, process.env.KUSHKI_ENV);
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,6 @@
1
+ export declare class s3 {
2
+ _client: any;
3
+ constructor(endpoint: string, region: string, accessKey: string, secretKey: string);
4
+ get client(): any;
5
+ }
6
+ export declare const s3Client: Promise<s3>;
@@ -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
- if (apiKey === process.env.ORIGINAL_ADMIN_API_KEY) {
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 payload = jsonwebtoken_1.default.verify(req.cookies.accessToken, process.env.JWT_KEY);
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 payload = jsonwebtoken_1.default.verify(req.cookies.adminAccessToken, process.env.JWT_KEY_ADMIN);
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) { }
@@ -11,5 +11,5 @@ declare global {
11
11
  }
12
12
  }
13
13
  }
14
- export declare const currentAdminAuth: (req: Request, res: Response, next: NextFunction) => void;
14
+ export declare const currentAdminAuth: (req: Request, res: Response, next: NextFunction) => Promise<void>;
15
15
  export {};
@@ -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 payload = jsonwebtoken_1.default.verify(req.cookies.adminAccesToken, process.env.JWT_KEY_ADMIN);
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;
@@ -12,5 +12,5 @@ declare global {
12
12
  }
13
13
  }
14
14
  }
15
- export declare const currentAuth: (req: Request, res: Response, next: NextFunction) => void;
15
+ export declare const currentAuth: (req: Request, res: Response, next: NextFunction) => Promise<void>;
16
16
  export {};
@@ -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 payload = jsonwebtoken_1.default.verify(req.cookies.accessToken, process.env.JWT_KEY);
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 payload = jsonwebtoken_1.default.verify(req.cookies.partnerAuthJwt, process.env.JWT_KEY_PARTNER);
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 {
@@ -6,4 +6,4 @@ declare global {
6
6
  }
7
7
  }
8
8
  }
9
- export declare const verifyAdminApiKey: (req: Request, res: Response, next: NextFunction) => void;
9
+ export declare const verifyAdminApiKey: (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -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 verifyAdminApiKey = (req, res, next) => {
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
- if (apiKey === process.env.ORIGINAL_ADMIN_API_KEY) {
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;
@@ -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 salt = process.env.API_KEY_SALT;
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.547",
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.547",
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",
@@ -1,5 +0,0 @@
1
- export declare class s3 {
2
- _client: any;
3
- constructor();
4
- get client(): any;
5
- }
@@ -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;