@riocrypto/common-server 1.0.2703 → 1.0.2707

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.
@@ -92,6 +92,10 @@ declare class ClusterClient {
92
92
  hasAuthenticatorEnabled: boolean;
93
93
  }>;
94
94
  verifyCode(phoneNumber: string, code?: string, authenticatorCode?: string): Promise<void>;
95
+ sendEmailVerificationCode(email: string): Promise<{
96
+ hasAuthenticatorEnabled: boolean;
97
+ }>;
98
+ verifyEmailCode(email: string, code: string): Promise<void>;
95
99
  sendVerificationEmail(userId: string, country?: Country): Promise<void>;
96
100
  registerFXTrade(orderId: string, provider: FXProvider, amount: number, price: number): Promise<void>;
97
101
  generateInvoice(orderId: string): Promise<void>;
@@ -302,6 +302,25 @@ class ClusterClient {
302
302
  });
303
303
  });
304
304
  }
305
+ sendEmailVerificationCode(email) {
306
+ return __awaiter(this, void 0, void 0, function* () {
307
+ const response = yield this.axios.post(`${this.baseUrl}/api/auth/email/send-verification`, { email }, {
308
+ headers: {
309
+ "x-cluster-api-key": this.clusterApiKey,
310
+ },
311
+ });
312
+ return response.data;
313
+ });
314
+ }
315
+ verifyEmailCode(email, code) {
316
+ return __awaiter(this, void 0, void 0, function* () {
317
+ yield this.axios.post(`${this.baseUrl}/api/auth/email/verify`, { email, code }, {
318
+ headers: {
319
+ "x-cluster-api-key": this.clusterApiKey,
320
+ },
321
+ });
322
+ });
323
+ }
305
324
  sendVerificationEmail(userId, country) {
306
325
  return __awaiter(this, void 0, void 0, function* () {
307
326
  yield this.axios.post(`${this.baseUrl}/api/kyc/email`, {
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.authorize = void 0;
16
+ const crypto_1 = __importDefault(require("crypto"));
16
17
  const user_1 = require("../models/user");
17
18
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
18
19
  const common_1 = require("@riocrypto/common");
@@ -33,7 +34,8 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
33
34
  if (!CLUSTER_API_KEY) {
34
35
  throw new common_1.SecretManagerError();
35
36
  }
36
- if (apiKey === CLUSTER_API_KEY) {
37
+ if (apiKey.length === CLUSTER_API_KEY.length &&
38
+ crypto_1.default.timingSafeEqual(Buffer.from(apiKey), Buffer.from(CLUSTER_API_KEY))) {
37
39
  req.validClusterApiKey = true;
38
40
  }
39
41
  }))());
@@ -48,7 +50,8 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
48
50
  if (!GENESIS_ADMIN_KEY) {
49
51
  throw new common_1.SecretManagerError();
50
52
  }
51
- if (apiKey === GENESIS_ADMIN_KEY) {
53
+ if (apiKey.length === GENESIS_ADMIN_KEY.length &&
54
+ crypto_1.default.timingSafeEqual(Buffer.from(apiKey), Buffer.from(GENESIS_ADMIN_KEY))) {
52
55
  req.validGenisisAdminKey = true;
53
56
  }
54
57
  }))());
@@ -33,6 +33,8 @@ interface AuthAttrs {
33
33
  emailVerificationCode?: string;
34
34
  emailVerificationExpires?: Date;
35
35
  emailVerificationAttempts?: number;
36
+ securityAnswerAttempts?: number;
37
+ securityAnswerLockedUntil?: Date;
36
38
  authMethod?: AuthMethod;
37
39
  twoFactorConfigured?: boolean;
38
40
  twoFactorMethod?: string;
@@ -70,6 +72,8 @@ interface AuthDoc extends Document {
70
72
  emailVerificationCode?: string;
71
73
  emailVerificationExpires?: Date;
72
74
  emailVerificationAttempts?: number;
75
+ securityAnswerAttempts?: number;
76
+ securityAnswerLockedUntil?: Date;
73
77
  authMethod?: AuthMethod;
74
78
  twoFactorConfigured?: boolean;
75
79
  twoFactorMethod?: string;
@@ -125,6 +125,13 @@ const buildAuth = (mongoose) => {
125
125
  type: Number,
126
126
  default: 0,
127
127
  },
128
+ securityAnswerAttempts: {
129
+ type: Number,
130
+ default: 0,
131
+ },
132
+ securityAnswerLockedUntil: {
133
+ type: Date,
134
+ },
128
135
  authMethod: {
129
136
  type: String,
130
137
  },
@@ -151,6 +158,8 @@ const buildAuth = (mongoose) => {
151
158
  delete ret.emailVerificationCode;
152
159
  delete ret.emailVerificationExpires;
153
160
  delete ret.emailVerificationAttempts;
161
+ delete ret.securityAnswerAttempts;
162
+ delete ret.securityAnswerLockedUntil;
154
163
  for (let apiKey of ret.apiKeys) {
155
164
  delete apiKey.value;
156
165
  }
@@ -10,6 +10,7 @@ interface TelegramSessionAttrs {
10
10
  state: string;
11
11
  authId?: string;
12
12
  hasAuthenticatorEnabled?: boolean;
13
+ isEmailAuth?: boolean;
13
14
  quoteInputs?: {
14
15
  fiat?: Fiat;
15
16
  crypto?: Crypto;
@@ -38,6 +39,7 @@ interface TelegramSessionDoc extends mongoose.Document {
38
39
  state: string;
39
40
  authId?: string;
40
41
  hasAuthenticatorEnabled?: boolean;
42
+ isEmailAuth?: boolean;
41
43
  quoteInputs?: {
42
44
  fiat?: Fiat;
43
45
  crypto?: Crypto;
@@ -20,6 +20,9 @@ const buildTelegramSession = (mongoose) => {
20
20
  hasAuthenticatorEnabled: {
21
21
  type: Boolean,
22
22
  },
23
+ isEmailAuth: {
24
+ type: Boolean,
25
+ },
23
26
  telegramUsername: {
24
27
  type: String,
25
28
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2703",
3
+ "version": "1.0.2707",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",