@prosopo/client-example-server 2.7.18 → 2.7.48

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/CHANGELOG.md CHANGED
@@ -1,5 +1,367 @@
1
1
  # @prosopo/client-example-server
2
2
 
3
+ ## 2.7.48
4
+ ### Patch Changes
5
+
6
+ - 8ce9205: Change engine requirements
7
+ - b6e98b2: Run npm audit
8
+ - Updated dependencies [15ae7cf]
9
+ - Updated dependencies [bb5f41c]
10
+ - Updated dependencies [8ce9205]
11
+ - Updated dependencies [df79c03]
12
+ - Updated dependencies [b6e98b2]
13
+ - @prosopo/types@3.6.0
14
+ - @prosopo/util@3.2.0
15
+ - @prosopo/keyring@2.8.36
16
+ - @prosopo/common@3.1.22
17
+ - @prosopo/dotenv@3.0.27
18
+ - @prosopo/server@2.9.44
19
+ - @prosopo/config@3.1.22
20
+
21
+ ## 2.7.47
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [8f1773a]
25
+ - @prosopo/types@3.5.11
26
+ - @prosopo/keyring@2.8.35
27
+ - @prosopo/server@2.9.43
28
+
29
+ ## 2.7.46
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [cb8ab85]
33
+ - @prosopo/types@3.5.10
34
+ - @prosopo/keyring@2.8.34
35
+ - @prosopo/server@2.9.42
36
+
37
+ ## 2.7.45
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [43907e8]
41
+ - Updated dependencies [005ce66]
42
+ - Updated dependencies [7101036]
43
+ - @prosopo/types@3.5.9
44
+ - @prosopo/util@3.1.7
45
+ - @prosopo/keyring@2.8.33
46
+ - @prosopo/server@2.9.41
47
+
48
+ ## 2.7.44
49
+ ### Patch Changes
50
+
51
+ - Updated dependencies [e5c259d]
52
+ - @prosopo/types@3.5.8
53
+ - @prosopo/keyring@2.8.32
54
+ - @prosopo/server@2.9.40
55
+
56
+ ## 2.7.43
57
+ ### Patch Changes
58
+
59
+ - Updated dependencies [c9d8fdf]
60
+ - Updated dependencies [b8185a4]
61
+ - @prosopo/common@3.1.21
62
+ - @prosopo/config@3.1.21
63
+ - @prosopo/server@2.9.39
64
+ - @prosopo/dotenv@3.0.26
65
+ - @prosopo/keyring@2.8.31
66
+ - @prosopo/types@3.5.7
67
+ - @prosopo/util@3.1.6
68
+
69
+ ## 2.7.42
70
+ ### Patch Changes
71
+
72
+ - Updated dependencies [5d11a81]
73
+ - @prosopo/types@3.5.6
74
+ - @prosopo/keyring@2.8.30
75
+ - @prosopo/server@2.9.38
76
+
77
+ ## 2.7.41
78
+ ### Patch Changes
79
+
80
+ - Updated dependencies [494c5a8]
81
+ - @prosopo/types@3.5.5
82
+ - @prosopo/keyring@2.8.29
83
+ - @prosopo/server@2.9.37
84
+
85
+ ## 2.7.40
86
+ ### Patch Changes
87
+
88
+ - Updated dependencies [08ff50f]
89
+ - @prosopo/types@3.5.4
90
+ - @prosopo/keyring@2.8.28
91
+ - @prosopo/server@2.9.36
92
+
93
+ ## 2.7.39
94
+ ### Patch Changes
95
+
96
+ - Updated dependencies [1e3a838]
97
+ - @prosopo/config@3.1.20
98
+ - @prosopo/server@2.9.35
99
+ - @prosopo/common@3.1.20
100
+ - @prosopo/dotenv@3.0.25
101
+ - @prosopo/keyring@2.8.27
102
+ - @prosopo/types@3.5.3
103
+ - @prosopo/util@3.1.5
104
+
105
+ ## 2.7.38
106
+ ### Patch Changes
107
+
108
+ - 5659b24: Release 3.4.4
109
+ - Updated dependencies [f912439]
110
+ - Updated dependencies [5659b24]
111
+ - @prosopo/common@3.1.19
112
+ - @prosopo/keyring@2.8.26
113
+ - @prosopo/dotenv@3.0.24
114
+ - @prosopo/server@2.9.34
115
+ - @prosopo/types@3.5.2
116
+ - @prosopo/util@3.1.4
117
+ - @prosopo/config@3.1.19
118
+
119
+ ## 2.7.37
120
+ ### Patch Changes
121
+
122
+ - 50c4120: Release 3.4.3
123
+ - Updated dependencies [52cd544]
124
+ - Updated dependencies [c72ecbd]
125
+ - Updated dependencies [b117ba3]
126
+ - Updated dependencies [50c4120]
127
+ - @prosopo/types@3.5.1
128
+ - @prosopo/dotenv@3.0.23
129
+ - @prosopo/keyring@2.8.25
130
+ - @prosopo/common@3.1.18
131
+ - @prosopo/server@2.9.33
132
+ - @prosopo/util@3.1.3
133
+ - @prosopo/config@3.1.18
134
+
135
+ ## 2.7.36
136
+ ### Patch Changes
137
+
138
+ - 618703f: Release 3.4.2
139
+ - Updated dependencies [618703f]
140
+ - Updated dependencies [e20ad6b]
141
+ - @prosopo/keyring@2.8.24
142
+ - @prosopo/common@3.1.17
143
+ - @prosopo/dotenv@3.0.22
144
+ - @prosopo/server@2.9.32
145
+ - @prosopo/types@3.5.0
146
+ - @prosopo/util@3.1.2
147
+ - @prosopo/config@3.1.17
148
+
149
+ ## 2.7.35
150
+ ### Patch Changes
151
+
152
+ - 11303d9: Release 3.4.0
153
+ - 18cb28b: Release 3.4.1
154
+ - Updated dependencies [11303d9]
155
+ - Updated dependencies [18cb28b]
156
+ - Updated dependencies [11303d9]
157
+ - @prosopo/keyring@2.8.23
158
+ - @prosopo/common@3.1.16
159
+ - @prosopo/dotenv@3.0.21
160
+ - @prosopo/server@2.9.31
161
+ - @prosopo/types@3.4.1
162
+ - @prosopo/util@3.1.1
163
+ - @prosopo/config@3.1.16
164
+
165
+ ## 2.7.34
166
+ ### Patch Changes
167
+
168
+ - f3f7aec: Release 3.4.0
169
+ - Updated dependencies [f3f7aec]
170
+ - Updated dependencies [6768f14]
171
+ - @prosopo/keyring@2.8.22
172
+ - @prosopo/common@3.1.15
173
+ - @prosopo/dotenv@3.0.20
174
+ - @prosopo/server@2.9.30
175
+ - @prosopo/types@3.4.0
176
+ - @prosopo/util@3.1.0
177
+ - @prosopo/config@3.1.15
178
+
179
+ ## 2.7.33
180
+ ### Patch Changes
181
+
182
+ - Release 3.3.1
183
+ - 0824221: Release 3.2.4
184
+ - Updated dependencies [97edf3f]
185
+ - Updated dependencies
186
+ - Updated dependencies [0824221]
187
+ - @prosopo/types@3.3.0
188
+ - @prosopo/keyring@2.8.21
189
+ - @prosopo/common@3.1.14
190
+ - @prosopo/dotenv@3.0.19
191
+ - @prosopo/server@2.9.29
192
+ - @prosopo/util@3.0.17
193
+ - @prosopo/config@3.1.14
194
+
195
+ ## 2.7.32
196
+ ### Patch Changes
197
+
198
+ - 008d112: Release 3.3.0
199
+ - Updated dependencies [509be28]
200
+ - Updated dependencies [008d112]
201
+ - @prosopo/types@3.2.1
202
+ - @prosopo/keyring@2.8.20
203
+ - @prosopo/common@3.1.13
204
+ - @prosopo/dotenv@3.0.18
205
+ - @prosopo/server@2.9.28
206
+ - @prosopo/util@3.0.16
207
+ - @prosopo/config@3.1.13
208
+
209
+ ## 2.7.31
210
+ ### Patch Changes
211
+
212
+ - 0824221: Release 3.2.4
213
+ - Updated dependencies [cf48565]
214
+ - Updated dependencies [0824221]
215
+ - @prosopo/types@3.2.0
216
+ - @prosopo/keyring@2.8.19
217
+ - @prosopo/common@3.1.12
218
+ - @prosopo/dotenv@3.0.17
219
+ - @prosopo/server@2.9.27
220
+ - @prosopo/util@3.0.15
221
+ - @prosopo/config@3.1.12
222
+
223
+ ## 2.7.30
224
+ ### Patch Changes
225
+
226
+ - 0d1a33e: Adding ipcomparison service with user features
227
+ - 1a23649: Release 3.2.3
228
+ - Updated dependencies [0d1a33e]
229
+ - Updated dependencies [0d1a33e]
230
+ - Updated dependencies [1a23649]
231
+ - @prosopo/types@3.1.4
232
+ - @prosopo/keyring@2.8.18
233
+ - @prosopo/common@3.1.11
234
+ - @prosopo/dotenv@3.0.16
235
+ - @prosopo/server@2.9.26
236
+ - @prosopo/util@3.0.14
237
+ - @prosopo/config@3.1.11
238
+
239
+ ## 2.7.29
240
+ ### Patch Changes
241
+
242
+ - 657a827: Release 3.2.2
243
+ - Updated dependencies [657a827]
244
+ - @prosopo/keyring@2.8.17
245
+ - @prosopo/common@3.1.10
246
+ - @prosopo/dotenv@3.0.15
247
+ - @prosopo/server@2.9.25
248
+ - @prosopo/types@3.1.3
249
+ - @prosopo/util@3.0.13
250
+ - @prosopo/config@3.1.10
251
+
252
+ ## 2.7.28
253
+ ### Patch Changes
254
+
255
+ - 4440947: fix type-only tsc compilation
256
+ - 7bdaca6: Release 3.2.1
257
+ - Updated dependencies [4440947]
258
+ - Updated dependencies [7bdaca6]
259
+ - Updated dependencies [809b984]
260
+ - Updated dependencies [1249ce0]
261
+ - Updated dependencies [809b984]
262
+ - @prosopo/keyring@2.8.16
263
+ - @prosopo/common@3.1.9
264
+ - @prosopo/dotenv@3.0.14
265
+ - @prosopo/server@2.9.24
266
+ - @prosopo/types@3.1.2
267
+ - @prosopo/util@3.0.12
268
+ - @prosopo/config@3.1.9
269
+
270
+ ## 2.7.27
271
+ ### Patch Changes
272
+
273
+ - 6fe8570: Release 3.2.0
274
+ - Updated dependencies [1f980c4]
275
+ - Updated dependencies [6fe8570]
276
+ - @prosopo/types@3.1.1
277
+ - @prosopo/keyring@2.8.15
278
+ - @prosopo/common@3.1.8
279
+ - @prosopo/dotenv@3.0.13
280
+ - @prosopo/server@2.9.23
281
+ - @prosopo/util@3.0.11
282
+ - @prosopo/config@3.1.8
283
+
284
+ ## 2.7.26
285
+ ### Patch Changes
286
+
287
+ - f304be9: Release 3.1.13
288
+ - Updated dependencies [f304be9]
289
+ - Updated dependencies [8bdc7f0]
290
+ - @prosopo/keyring@2.8.14
291
+ - @prosopo/common@3.1.7
292
+ - @prosopo/dotenv@3.0.12
293
+ - @prosopo/server@2.9.22
294
+ - @prosopo/types@3.1.0
295
+ - @prosopo/util@3.0.10
296
+ - @prosopo/config@3.1.7
297
+
298
+ ## 2.7.25
299
+ ### Patch Changes
300
+
301
+ - a07db04: Release 3.1.12
302
+ - Updated dependencies [9eed772]
303
+ - Updated dependencies [a07db04]
304
+ - Updated dependencies [ebb0168]
305
+ - @prosopo/config@3.1.6
306
+ - @prosopo/server@2.9.21
307
+ - @prosopo/util@3.0.9
308
+ - @prosopo/common@3.1.6
309
+ - @prosopo/dotenv@3.0.11
310
+ - @prosopo/keyring@2.8.13
311
+ - @prosopo/types@3.0.10
312
+
313
+ ## 2.7.24
314
+ ### Patch Changes
315
+
316
+ - @prosopo/server@2.9.20
317
+
318
+ ## 2.7.23
319
+ ### Patch Changes
320
+
321
+ - 6960643: lint detect missing and unneccessary imports
322
+ - Updated dependencies [6960643]
323
+ - @prosopo/keyring@2.8.12
324
+ - @prosopo/common@3.1.5
325
+ - @prosopo/dotenv@3.0.10
326
+ - @prosopo/server@2.9.19
327
+ - @prosopo/types@3.0.9
328
+ - @prosopo/util@3.0.8
329
+
330
+ ## 2.7.22
331
+ ### Patch Changes
332
+
333
+ - Updated dependencies [30e7d4d]
334
+ - @prosopo/config@3.1.5
335
+ - @prosopo/common@3.1.4
336
+ - @prosopo/dotenv@3.0.9
337
+ - @prosopo/server@2.9.18
338
+ - @prosopo/types@3.0.8
339
+ - @prosopo/util@3.0.7
340
+
341
+ ## 2.7.21
342
+ ### Patch Changes
343
+
344
+ - 1f3a02f: Release 3.1.8
345
+ - Updated dependencies [1f3a02f]
346
+ - @prosopo/server@2.9.17
347
+
348
+ ## 2.7.20
349
+ ### Patch Changes
350
+
351
+ - @prosopo/server@2.9.16
352
+
353
+ ## 2.7.19
354
+ ### Patch Changes
355
+
356
+ - Updated dependencies [44ffda2]
357
+ - Updated dependencies [a49b538]
358
+ - @prosopo/config@3.1.4
359
+ - @prosopo/common@3.1.3
360
+ - @prosopo/dotenv@3.0.8
361
+ - @prosopo/server@2.9.15
362
+ - @prosopo/types@3.0.7
363
+ - @prosopo/util@3.0.6
364
+
3
365
  ## 2.7.18
4
366
  ### Patch Changes
5
367
 
package/dist/app.js CHANGED
@@ -27,6 +27,7 @@ async function main() {
27
27
  ProsopoVerificationType
28
28
  ).includes(process.env.PROSOPO_VERIFICATION_TYPE) ? process.env.PROSOPO_VERIFICATION_TYPE : "api";
29
29
  const app = express();
30
+ app.set("trust proxy", 1);
30
31
  app.use(cors({ origin: true, credentials: true }));
31
32
  app.use(express.urlencoded({ extended: true }));
32
33
  app.use(express.json());
@@ -45,7 +46,11 @@ async function main() {
45
46
  app.options("/*", (_, res) => {
46
47
  res.sendStatus(200);
47
48
  });
48
- const uri = await memoryServerSetup();
49
+ if (!process.env.MONGO_URI && process.env.NODE_ENV !== "development") {
50
+ throw new Error("Cannot run mongo memory in non-development environment");
51
+ }
52
+ logger.info(() => ({ msg: process.env.MONGO_URI }));
53
+ const uri = process.env.MONGO_URI || await memoryServerSetup();
49
54
  logger.info(() => ({ msg: "mongo uri", data: { uri } }));
50
55
  const mongoose = connectionFactory(uri);
51
56
  if (!process.env.PROSOPO_SITE_PRIVATE_KEY) {
@@ -58,9 +63,9 @@ async function main() {
58
63
  const config = getServerConfig();
59
64
  logger.info(() => ({ msg: "Config", data: { config } }));
60
65
  app.use(getRoutes(mongoose, config, verifyEndpoint, verifyType));
61
- app.listen(
62
- config.serverUrl ? Number.parseInt(at(config.serverUrl.split(":"), 2)) : 9228
63
- );
66
+ const port = config.serverUrl ? Number.parseInt(at(config.serverUrl.split(":"), 2)) : 9228;
67
+ logger.info(() => ({ msg: "Listening on port", data: { port } }));
68
+ app.listen(port);
64
69
  }
65
70
  main().then(() => {
66
71
  logger.info(() => ({ msg: "Server started" }));
package/dist/cjs/app.cjs CHANGED
@@ -10,6 +10,7 @@ const express = require("express");
10
10
  const routes = require("./routes/routes.cjs");
11
11
  const connection = require("./utils/connection.cjs");
12
12
  const database = require("./utils/database.cjs");
13
+ var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
13
14
  dotenv.loadEnv();
14
15
  function getEnvFile(filename = ".env", filepath = "./") {
15
16
  const env = process.env.NODE_ENV || "development";
@@ -20,7 +21,7 @@ var ProsopoVerificationType = /* @__PURE__ */ ((ProsopoVerificationType2) => {
20
21
  ProsopoVerificationType2["local"] = "local";
21
22
  return ProsopoVerificationType2;
22
23
  })(ProsopoVerificationType || {});
23
- const logger = common.getLogger("info", module);
24
+ const logger = common.getLogger("info", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("app.cjs", document.baseURI).href);
24
25
  async function main() {
25
26
  dotenv.loadEnv();
26
27
  const apiPrefix = process.env.NODE_ENV && process.env.NODE_ENV === "production" ? "" : `${process.env.NODE_ENV}-`;
@@ -29,6 +30,7 @@ async function main() {
29
30
  ProsopoVerificationType
30
31
  ).includes(process.env.PROSOPO_VERIFICATION_TYPE) ? process.env.PROSOPO_VERIFICATION_TYPE : "api";
31
32
  const app = express();
33
+ app.set("trust proxy", 1);
32
34
  app.use(cors({ origin: true, credentials: true }));
33
35
  app.use(express.urlencoded({ extended: true }));
34
36
  app.use(express.json());
@@ -47,7 +49,11 @@ async function main() {
47
49
  app.options("/*", (_, res) => {
48
50
  res.sendStatus(200);
49
51
  });
50
- const uri = await database.memoryServerSetup();
52
+ if (!process.env.MONGO_URI && process.env.NODE_ENV !== "development") {
53
+ throw new Error("Cannot run mongo memory in non-development environment");
54
+ }
55
+ logger.info(() => ({ msg: process.env.MONGO_URI }));
56
+ const uri = process.env.MONGO_URI || await database.memoryServerSetup();
51
57
  logger.info(() => ({ msg: "mongo uri", data: { uri } }));
52
58
  const mongoose = connection(uri);
53
59
  if (!process.env.PROSOPO_SITE_PRIVATE_KEY) {
@@ -60,9 +66,9 @@ async function main() {
60
66
  const config = server.getServerConfig();
61
67
  logger.info(() => ({ msg: "Config", data: { config } }));
62
68
  app.use(routes(mongoose, config, verifyEndpoint, verifyType));
63
- app.listen(
64
- config.serverUrl ? Number.parseInt(util.at(config.serverUrl.split(":"), 2)) : 9228
65
- );
69
+ const port = config.serverUrl ? Number.parseInt(util.at(config.serverUrl.split(":"), 2)) : 9228;
70
+ logger.info(() => ({ msg: "Listening on port", data: { port } }));
71
+ app.listen(port);
66
72
  }
67
73
  main().then(() => {
68
74
  logger.info(() => ({ msg: "Server started" }));
@@ -19,19 +19,28 @@ const SubscribeBodySpec = types.ProcaptchaResponse.merge(
19
19
  function hashPassword(password) {
20
20
  return util.u8aToHex(blake2b.blake2b(password));
21
21
  }
22
- const verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret) => {
22
+ const NO_IP = "NO_IP";
23
+ const getResponse = async (ip, token, secret, verifyEndpoint) => {
24
+ const body = {
25
+ [types.ApiParams.token]: token,
26
+ [types.ApiParams.secret]: secret
27
+ };
28
+ if (process.env.NODE_ENV !== "development") {
29
+ body[types.ApiParams.ip] = ip;
30
+ }
31
+ console.log({ body });
32
+ const response = await fetch(verifyEndpoint, {
33
+ method: "POST",
34
+ body: JSON.stringify(body)
35
+ });
36
+ return response.json();
37
+ };
38
+ const verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret, ip) => {
23
39
  if (verifyType === "api") {
24
40
  console.log("Verifying using the API endpoint", verifyEndpoint);
25
- const response = await fetch(verifyEndpoint, {
26
- method: "POST",
27
- body: JSON.stringify({
28
- [types.ApiParams.token]: token,
29
- [types.ApiParams.secret]: secret
30
- })
31
- });
32
- const verifiedResponse = await response.json();
33
- console.log(verifiedResponse);
34
- return verifiedResponse.verified;
41
+ const response = await getResponse(ip, token, secret, verifyEndpoint);
42
+ console.log(response);
43
+ return response.verified;
35
44
  }
36
45
  const verified = await prosopoServer.isVerified(token);
37
46
  console.log(verified);
@@ -60,7 +69,8 @@ const signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, ne
60
69
  verifyType,
61
70
  verifyEndpoint,
62
71
  token,
63
- config.account.secret
72
+ config.account.secret,
73
+ req.headers["x-client-ip"]?.toString() || NO_IP
64
74
  );
65
75
  if (verified) {
66
76
  const salt = utilCrypto.randomAsHex(32);
@@ -98,7 +108,7 @@ const login = async (mongoose, config, verifyEndpoint, verifyType, req, res) =>
98
108
  const payload = SubscribeBodySpec.parse(req.body);
99
109
  const token = payload[types.ApiParams.procaptchaResponse];
100
110
  if (!config.account.secret) {
101
- throw new common.ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
111
+ throw new common.ProsopoEnvError("GENERAL.SECRET_MISSING", {
102
112
  context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] }
103
113
  });
104
114
  }
@@ -107,7 +117,8 @@ const login = async (mongoose, config, verifyEndpoint, verifyType, req, res) =>
107
117
  verifyType,
108
118
  verifyEndpoint,
109
119
  token,
110
- config.account.secret
120
+ config.account.secret,
121
+ req.headers["x-client-ip"]?.toString() || NO_IP
111
122
  );
112
123
  console.log("verified", verified);
113
124
  if (verified) {
@@ -1,8 +1,30 @@
1
1
  "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
2
24
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const mongodbMemoryServer = require("mongodb-memory-server");
4
25
  async function memoryServerSetup() {
5
- const mongod = mongodbMemoryServer.MongoMemoryServer.create();
26
+ const MongoMemoryServer = (await import("mongodb-memory-server")).MongoMemoryServer;
27
+ const mongod = MongoMemoryServer.create();
6
28
  const memoryServer = await mongod;
7
29
  return memoryServer.getUri();
8
30
  }
@@ -17,19 +17,28 @@ const SubscribeBodySpec = ProcaptchaResponse.merge(
17
17
  function hashPassword(password) {
18
18
  return u8aToHex(blake2b(password));
19
19
  }
20
- const verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret) => {
20
+ const NO_IP = "NO_IP";
21
+ const getResponse = async (ip, token, secret, verifyEndpoint) => {
22
+ const body = {
23
+ [ApiParams.token]: token,
24
+ [ApiParams.secret]: secret
25
+ };
26
+ if (process.env.NODE_ENV !== "development") {
27
+ body[ApiParams.ip] = ip;
28
+ }
29
+ console.log({ body });
30
+ const response = await fetch(verifyEndpoint, {
31
+ method: "POST",
32
+ body: JSON.stringify(body)
33
+ });
34
+ return response.json();
35
+ };
36
+ const verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret, ip) => {
21
37
  if (verifyType === "api") {
22
38
  console.log("Verifying using the API endpoint", verifyEndpoint);
23
- const response = await fetch(verifyEndpoint, {
24
- method: "POST",
25
- body: JSON.stringify({
26
- [ApiParams.token]: token,
27
- [ApiParams.secret]: secret
28
- })
29
- });
30
- const verifiedResponse = await response.json();
31
- console.log(verifiedResponse);
32
- return verifiedResponse.verified;
39
+ const response = await getResponse(ip, token, secret, verifyEndpoint);
40
+ console.log(response);
41
+ return response.verified;
33
42
  }
34
43
  const verified = await prosopoServer.isVerified(token);
35
44
  console.log(verified);
@@ -58,7 +67,8 @@ const signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, ne
58
67
  verifyType,
59
68
  verifyEndpoint,
60
69
  token,
61
- config.account.secret
70
+ config.account.secret,
71
+ req.headers["x-client-ip"]?.toString() || NO_IP
62
72
  );
63
73
  if (verified) {
64
74
  const salt = randomAsHex(32);
@@ -96,7 +106,7 @@ const login = async (mongoose, config, verifyEndpoint, verifyType, req, res) =>
96
106
  const payload = SubscribeBodySpec.parse(req.body);
97
107
  const token = payload[ApiParams.procaptchaResponse];
98
108
  if (!config.account.secret) {
99
- throw new ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
109
+ throw new ProsopoEnvError("GENERAL.SECRET_MISSING", {
100
110
  context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] }
101
111
  });
102
112
  }
@@ -105,7 +115,8 @@ const login = async (mongoose, config, verifyEndpoint, verifyType, req, res) =>
105
115
  verifyType,
106
116
  verifyEndpoint,
107
117
  token,
108
- config.account.secret
118
+ config.account.secret,
119
+ req.headers["x-client-ip"]?.toString() || NO_IP
109
120
  );
110
121
  console.log("verified", verified);
111
122
  if (verified) {
@@ -1,5 +1,5 @@
1
- import { MongoMemoryServer } from "mongodb-memory-server";
2
1
  async function memoryServerSetup() {
2
+ const MongoMemoryServer = (await import("mongodb-memory-server")).MongoMemoryServer;
3
3
  const mongod = MongoMemoryServer.create();
4
4
  const memoryServer = await mongod;
5
5
  return memoryServer.getUri();