@prosopo/client-example-server 2.7.52 → 2.7.90
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/.turbo/turbo-build$colon$cjs.log +9 -7
- package/.turbo/turbo-build$colon$tsc.log +47 -0
- package/.turbo/turbo-build.log +14 -8
- package/CHANGELOG.md +381 -0
- package/dist/app.d.ts +2 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +41 -11
- package/dist/app.js.map +1 -0
- package/dist/cjs/app.cjs +41 -10
- package/dist/cjs/controllers/auth.cjs +118 -28
- package/dist/cjs/routes/routes.cjs +3 -0
- package/dist/controllers/auth.d.ts +8 -0
- package/dist/controllers/auth.d.ts.map +1 -0
- package/dist/controllers/auth.js +118 -29
- package/dist/controllers/auth.js.map +1 -0
- package/dist/models/user.d.ts +19 -0
- package/dist/models/user.d.ts.map +1 -0
- package/dist/models/user.js.map +1 -0
- package/dist/routes/routes.d.ts +6 -0
- package/dist/routes/routes.d.ts.map +1 -0
- package/dist/routes/routes.js +3 -0
- package/dist/routes/routes.js.map +1 -0
- package/dist/utils/connection.d.ts +4 -0
- package/dist/utils/connection.d.ts.map +1 -0
- package/dist/utils/connection.js.map +1 -0
- package/dist/utils/database.d.ts +3 -0
- package/dist/utils/database.d.ts.map +1 -0
- package/dist/utils/database.js.map +1 -0
- package/env.development +10 -0
- package/env.production +2 -0
- package/env.test +10 -0
- package/package.json +14 -11
- package/src/app.ts +169 -0
- package/src/controllers/auth.ts +371 -0
- package/src/models/user.ts +45 -0
- package/src/routes/routes.ts +54 -0
- package/src/utils/connection.ts +31 -0
- package/src/utils/database.ts +22 -0
- package/tsconfig.cjs.json +35 -0
- package/tsconfig.json +41 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsconfig.types.json +9 -0
- package/typedoc.config.js +1 -1
- package/vite.cjs.config.ts +1 -1
- package/vite.config.ts +1 -1
- package/vite.esm.config.ts +1 -1
package/dist/cjs/app.cjs
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const http = require("node:http");
|
|
4
|
+
const https = require("node:https");
|
|
3
5
|
const path = require("node:path");
|
|
6
|
+
const node_url = require("node:url");
|
|
4
7
|
const common = require("@prosopo/common");
|
|
5
8
|
const dotenv = require("@prosopo/dotenv");
|
|
9
|
+
const logger$1 = require("@prosopo/logger");
|
|
6
10
|
const server = require("@prosopo/server");
|
|
7
11
|
const util = require("@prosopo/util");
|
|
8
12
|
const cors = require("cors");
|
|
@@ -12,20 +16,17 @@ const connection = require("./utils/connection.cjs");
|
|
|
12
16
|
const database = require("./utils/database.cjs");
|
|
13
17
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
14
18
|
dotenv.loadEnv();
|
|
15
|
-
function getEnvFile(filename = ".env", filepath = "./") {
|
|
16
|
-
const env = process.env.NODE_ENV || "development";
|
|
17
|
-
return path.join(filepath, `${filename}.${env}`);
|
|
18
|
-
}
|
|
19
19
|
var ProsopoVerificationType = /* @__PURE__ */ ((ProsopoVerificationType2) => {
|
|
20
20
|
ProsopoVerificationType2["api"] = "api";
|
|
21
21
|
ProsopoVerificationType2["local"] = "local";
|
|
22
22
|
return ProsopoVerificationType2;
|
|
23
23
|
})(ProsopoVerificationType || {});
|
|
24
|
-
const logger =
|
|
24
|
+
const logger = logger$1.getLogger("info", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("app.cjs", document.baseURI).href);
|
|
25
25
|
async function main() {
|
|
26
26
|
dotenv.loadEnv();
|
|
27
27
|
const apiPrefix = process.env.NODE_ENV && process.env.NODE_ENV === "production" ? "" : `${process.env.NODE_ENV}-`;
|
|
28
28
|
const verifyEndpoint = process.env.PROSOPO_VERIFY_ENDPOINT || `https://${apiPrefix}api.prosopo.io/siteverify`;
|
|
29
|
+
logger.info(() => ({ data: { verifyEndpoint } }));
|
|
29
30
|
const verifyType = Object.keys(
|
|
30
31
|
ProsopoVerificationType
|
|
31
32
|
).includes(process.env.PROSOPO_VERIFICATION_TYPE) ? process.env.PROSOPO_VERIFICATION_TYPE : "api";
|
|
@@ -49,8 +50,10 @@ async function main() {
|
|
|
49
50
|
app.options("/*", (_, res) => {
|
|
50
51
|
res.sendStatus(200);
|
|
51
52
|
});
|
|
52
|
-
if (!process.env.MONGO_URI && process.env.NODE_ENV !== "development") {
|
|
53
|
-
throw new Error(
|
|
53
|
+
if (!process.env.MONGO_URI && process.env.NODE_ENV !== "development" && process.env.NODE_ENV !== "test") {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"Cannot run mongo memory when NODE_ENV is neither development nor test"
|
|
56
|
+
);
|
|
54
57
|
}
|
|
55
58
|
logger.info(() => ({ msg: process.env.MONGO_URI }));
|
|
56
59
|
const uri = process.env.MONGO_URI || await database.memoryServerSetup();
|
|
@@ -68,7 +71,36 @@ async function main() {
|
|
|
68
71
|
app.use(routes(mongoose, config, verifyEndpoint, verifyType));
|
|
69
72
|
const port = config.serverUrl ? Number.parseInt(util.at(config.serverUrl.split(":"), 2)) : 9228;
|
|
70
73
|
logger.info(() => ({ msg: "Listening on port", data: { port } }));
|
|
71
|
-
|
|
74
|
+
const isDev = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
75
|
+
if (isDev) {
|
|
76
|
+
const __filename2 = node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename2).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("app.cjs", document.baseURI).href);
|
|
77
|
+
const __dirname = path.dirname(__filename2);
|
|
78
|
+
const certsDir = path.resolve(__dirname, "../../../certs");
|
|
79
|
+
const keyPath = path.join(certsDir, "server.key");
|
|
80
|
+
const certPath = path.join(certsDir, "server.crt");
|
|
81
|
+
if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
|
|
82
|
+
const httpsOptions = {
|
|
83
|
+
key: fs.readFileSync(keyPath),
|
|
84
|
+
cert: fs.readFileSync(certPath)
|
|
85
|
+
};
|
|
86
|
+
https.createServer(httpsOptions, app).listen(port, () => {
|
|
87
|
+
logger.info(() => ({ msg: `HTTPS server started on port ${port}` }));
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
logger.warn(() => ({
|
|
91
|
+
msg: "Certificates not found, starting HTTP server instead. Run ./setup_certs.sh to enable HTTPS in development."
|
|
92
|
+
}));
|
|
93
|
+
http.createServer(app).listen(port, () => {
|
|
94
|
+
logger.info(() => ({ msg: `HTTP server started on port ${port}` }));
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
http.createServer(app).listen(port, () => {
|
|
99
|
+
logger.info(() => ({
|
|
100
|
+
msg: `HTTP server started on port ${port} (TLS handled by reverse proxy)`
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
72
104
|
}
|
|
73
105
|
main().then(() => {
|
|
74
106
|
logger.info(() => ({ msg: "Server started" }));
|
|
@@ -76,4 +108,3 @@ main().then(() => {
|
|
|
76
108
|
logger.error(() => ({ err }));
|
|
77
109
|
process.exit();
|
|
78
110
|
});
|
|
79
|
-
exports.getEnvFile = getEnvFile;
|
|
@@ -5,86 +5,169 @@ const util = require("@polkadot/util");
|
|
|
5
5
|
const utilCrypto = require("@polkadot/util-crypto");
|
|
6
6
|
const common = require("@prosopo/common");
|
|
7
7
|
const keyring = require("@prosopo/keyring");
|
|
8
|
+
const logger$1 = require("@prosopo/logger");
|
|
8
9
|
const server = require("@prosopo/server");
|
|
9
10
|
const types = require("@prosopo/types");
|
|
10
11
|
const util$1 = require("@prosopo/util");
|
|
11
12
|
const jwt = require("jsonwebtoken");
|
|
12
13
|
const zod = require("zod");
|
|
14
|
+
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
15
|
+
const logger = logger$1.getLogger("info", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("controllers/auth.cjs", document.baseURI).href);
|
|
13
16
|
const SubscribeBodySpec = types.ProcaptchaResponse.merge(
|
|
14
17
|
zod.z.object({
|
|
15
18
|
email: zod.z.string().email(),
|
|
16
|
-
password: zod.z.string()
|
|
19
|
+
password: zod.z.string(),
|
|
20
|
+
siteKey: zod.z.string()
|
|
17
21
|
})
|
|
18
22
|
);
|
|
19
23
|
function hashPassword(password) {
|
|
20
24
|
return util.u8aToHex(blake2b.blake2b(password));
|
|
21
25
|
}
|
|
22
26
|
const NO_IP = "NO_IP";
|
|
23
|
-
const
|
|
27
|
+
const getPairAndSecretForSiteKey = (baseSecret, siteKey) => {
|
|
28
|
+
let pair;
|
|
29
|
+
let secret = baseSecret;
|
|
30
|
+
pair = keyring.getPair(secret);
|
|
31
|
+
if (pair.address === siteKey) {
|
|
32
|
+
logger.info(() => ({
|
|
33
|
+
msg: "Site key matches the server configuration without captcha type suffix",
|
|
34
|
+
data: {
|
|
35
|
+
siteKeyDerived: pair?.address,
|
|
36
|
+
siteKey
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
return { pair, secret };
|
|
40
|
+
}
|
|
41
|
+
for (const captchaType of [
|
|
42
|
+
types.CaptchaType.pow,
|
|
43
|
+
types.CaptchaType.image,
|
|
44
|
+
types.CaptchaType.frictionless,
|
|
45
|
+
types.CaptchaType.puzzle
|
|
46
|
+
]) {
|
|
47
|
+
const newSecret = `${baseSecret}//${captchaType}`;
|
|
48
|
+
pair = keyring.getPair(newSecret);
|
|
49
|
+
console.log(
|
|
50
|
+
`[PAIR CHECK] Checking pair for ${captchaType}: ${pair?.address} (expected: ${siteKey})`
|
|
51
|
+
);
|
|
52
|
+
logger.info(() => ({
|
|
53
|
+
msg: "Checking pair",
|
|
54
|
+
data: {
|
|
55
|
+
captchaType,
|
|
56
|
+
siteKeyDerived: pair?.address,
|
|
57
|
+
siteKey
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
if (pair.address === siteKey) {
|
|
61
|
+
console.log(`[PAIR CHECK] ✅ Match found for ${captchaType}!`);
|
|
62
|
+
secret = newSecret;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!pair || pair.address !== siteKey) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Site key does not match the server configuration: Provided ${siteKey} vs Server ${pair?.address}`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return { pair, secret };
|
|
72
|
+
};
|
|
73
|
+
const getResponse = async (ip, token, secret, verifyEndpoint, email) => {
|
|
24
74
|
const body = {
|
|
25
75
|
[types.ApiParams.token]: token,
|
|
26
|
-
[types.ApiParams.secret]: secret
|
|
76
|
+
[types.ApiParams.secret]: secret,
|
|
77
|
+
...email ? { [types.ApiParams.email]: email } : {}
|
|
27
78
|
};
|
|
28
79
|
if (process.env.NODE_ENV !== "development") {
|
|
29
80
|
body[types.ApiParams.ip] = ip;
|
|
30
81
|
}
|
|
31
|
-
|
|
82
|
+
logger.info(() => ({
|
|
83
|
+
data: {
|
|
84
|
+
body
|
|
85
|
+
}
|
|
86
|
+
}));
|
|
32
87
|
const response = await fetch(verifyEndpoint, {
|
|
33
88
|
method: "POST",
|
|
34
89
|
body: JSON.stringify(body)
|
|
35
90
|
});
|
|
36
91
|
return response.json();
|
|
37
92
|
};
|
|
38
|
-
const verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret, ip) => {
|
|
93
|
+
const verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret, ip, email) => {
|
|
39
94
|
if (verifyType === "api") {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
95
|
+
logger.info(() => ({
|
|
96
|
+
msg: "Verifying using the API endpoint",
|
|
97
|
+
data: {
|
|
98
|
+
verifyEndpoint
|
|
99
|
+
}
|
|
100
|
+
}));
|
|
101
|
+
const response = await getResponse(
|
|
102
|
+
ip,
|
|
103
|
+
token,
|
|
104
|
+
secret,
|
|
105
|
+
verifyEndpoint,
|
|
106
|
+
email
|
|
107
|
+
);
|
|
108
|
+
logger.info(() => ({
|
|
109
|
+
data: {
|
|
110
|
+
response
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
43
113
|
return response.verified;
|
|
44
114
|
}
|
|
45
|
-
const verified = await prosopoServer.isVerified(token);
|
|
46
|
-
|
|
47
|
-
|
|
115
|
+
const verified = await prosopoServer.isVerified(token, ip, email);
|
|
116
|
+
logger.info(() => ({
|
|
117
|
+
data: {
|
|
118
|
+
verified
|
|
119
|
+
}
|
|
120
|
+
}));
|
|
121
|
+
return verified[types.ApiParams.verified];
|
|
48
122
|
};
|
|
49
123
|
const signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, next) => {
|
|
50
124
|
try {
|
|
125
|
+
if (!config.account.secret) {
|
|
126
|
+
throw new common.ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
|
|
127
|
+
context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] }
|
|
128
|
+
});
|
|
129
|
+
}
|
|
51
130
|
const User = mongoose.model("User");
|
|
52
131
|
const dbUser = await User.findOne({
|
|
53
132
|
email: { $eq: req.body.email }
|
|
54
133
|
});
|
|
55
134
|
const payload = SubscribeBodySpec.parse(req.body);
|
|
56
|
-
const
|
|
135
|
+
const token = payload[types.ApiParams.procaptchaResponse];
|
|
136
|
+
const siteKey = payload[types.ApiParams.siteKey];
|
|
137
|
+
const { pair, secret } = getPairAndSecretForSiteKey(
|
|
138
|
+
config.account.secret,
|
|
139
|
+
siteKey
|
|
140
|
+
);
|
|
57
141
|
const prosopoServer = new server.ProsopoServer(config, pair);
|
|
58
142
|
if (dbUser) {
|
|
59
143
|
return res.status(409).json({ message: "email already exists" });
|
|
60
144
|
}
|
|
61
|
-
const
|
|
62
|
-
if (!config.account.secret) {
|
|
63
|
-
throw new common.ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
|
|
64
|
-
context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] }
|
|
65
|
-
});
|
|
66
|
-
}
|
|
145
|
+
const email = req.body.email;
|
|
67
146
|
const verified = await verify(
|
|
68
147
|
prosopoServer,
|
|
69
148
|
verifyType,
|
|
70
149
|
verifyEndpoint,
|
|
71
150
|
token,
|
|
72
|
-
|
|
73
|
-
req.headers["x-client-ip"]?.toString() ||
|
|
151
|
+
secret,
|
|
152
|
+
req.headers["x-client-ip"]?.toString() || "127.0.0.1",
|
|
153
|
+
email
|
|
74
154
|
);
|
|
75
|
-
if (verified) {
|
|
155
|
+
if (verified === true) {
|
|
76
156
|
const salt = utilCrypto.randomAsHex(32);
|
|
77
157
|
const passwordHash = hashPassword(`${req.body.password}${salt}`);
|
|
78
158
|
if (passwordHash) {
|
|
79
159
|
return User.create({
|
|
80
|
-
email
|
|
160
|
+
email,
|
|
81
161
|
name: req.body.name,
|
|
82
162
|
password: passwordHash,
|
|
83
163
|
salt
|
|
84
164
|
}).then(() => {
|
|
85
165
|
res.status(200).json({ message: "user created" });
|
|
86
166
|
}).catch((err) => {
|
|
87
|
-
|
|
167
|
+
logger.error(() => ({
|
|
168
|
+
err,
|
|
169
|
+
msg: "Error creating user in database"
|
|
170
|
+
}));
|
|
88
171
|
res.status(502).json({ message: "error while creating the user" });
|
|
89
172
|
});
|
|
90
173
|
}
|
|
@@ -98,29 +181,36 @@ const signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, ne
|
|
|
98
181
|
};
|
|
99
182
|
const login = async (mongoose, config, verifyEndpoint, verifyType, req, res) => {
|
|
100
183
|
const User = mongoose.model("User");
|
|
101
|
-
const pair = await keyring.getPair(config.account.secret);
|
|
102
|
-
const prosopoServer = new server.ProsopoServer(config, pair);
|
|
103
184
|
await User.findOne({
|
|
104
185
|
email: { $eq: req.body.email }
|
|
105
186
|
}).then(async (dbUser) => {
|
|
106
187
|
if (dbUser) {
|
|
107
|
-
console.log(req.body);
|
|
108
188
|
const payload = SubscribeBodySpec.parse(req.body);
|
|
109
189
|
const token = payload[types.ApiParams.procaptchaResponse];
|
|
190
|
+
const siteKey = payload[types.ApiParams.siteKey];
|
|
110
191
|
if (!config.account.secret) {
|
|
111
192
|
throw new common.ProsopoEnvError("GENERAL.SECRET_MISSING", {
|
|
112
193
|
context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] }
|
|
113
194
|
});
|
|
114
195
|
}
|
|
196
|
+
const { pair, secret } = getPairAndSecretForSiteKey(
|
|
197
|
+
config.account.secret,
|
|
198
|
+
siteKey
|
|
199
|
+
);
|
|
200
|
+
const prosopoServer = new server.ProsopoServer(config, pair);
|
|
115
201
|
const verified = await verify(
|
|
116
202
|
prosopoServer,
|
|
117
203
|
verifyType,
|
|
118
204
|
verifyEndpoint,
|
|
119
205
|
token,
|
|
120
|
-
|
|
206
|
+
secret,
|
|
121
207
|
req.headers["x-client-ip"]?.toString() || NO_IP
|
|
122
208
|
);
|
|
123
|
-
|
|
209
|
+
logger.info(() => ({
|
|
210
|
+
data: {
|
|
211
|
+
verified
|
|
212
|
+
}
|
|
213
|
+
}));
|
|
124
214
|
if (verified) {
|
|
125
215
|
const passwordHash = hashPassword(
|
|
126
216
|
`${req.body.password}${dbUser.salt}`
|
|
@@ -15,6 +15,9 @@ function getRoutes(mongoose, config, verifyEndpoint, verifyType) {
|
|
|
15
15
|
router.get("/public", (req, res) => {
|
|
16
16
|
res.status(200).json({ message: "here is your public resource" });
|
|
17
17
|
});
|
|
18
|
+
router.get("/health", (req, res) => {
|
|
19
|
+
res.status(200).json({ status: "ok" });
|
|
20
|
+
});
|
|
18
21
|
router.use("/", (req, res) => {
|
|
19
22
|
res.status(404).json({ error: "page not found" });
|
|
20
23
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ProsopoServerConfigOutput } from "@prosopo/types";
|
|
2
|
+
import type { NextFunction, Request, Response } from "express";
|
|
3
|
+
import type { Connection } from "mongoose";
|
|
4
|
+
declare const signup: (mongoose: Connection, config: ProsopoServerConfigOutput, verifyEndpoint: string, verifyType: string, req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
5
|
+
declare const login: (mongoose: Connection, config: ProsopoServerConfigOutput, verifyEndpoint: string, verifyType: string, req: Request, res: Response) => Promise<void>;
|
|
6
|
+
declare const isAuth: (req: Request, res: Response) => void;
|
|
7
|
+
export { signup, login, isAuth };
|
|
8
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAqBA,OAAO,EAMN,KAAK,yBAAyB,EAC9B,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AA2J3C,QAAA,MAAM,MAAM,aACD,UAAU,UACZ,yBAAyB,kBACjB,MAAM,cACV,MAAM,OACb,OAAO,OACP,QAAQ,QACP,YAAY,uDAyElB,CAAC;AAEF,QAAA,MAAM,KAAK,aACA,UAAU,UACZ,yBAAyB,kBACjB,MAAM,cACV,MAAM,OACb,OAAO,OACP,QAAQ,kBAsEb,CAAC;AAEF,QAAA,MAAM,MAAM,QAAS,OAAO,OAAO,QAAQ,SAqB1C,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/controllers/auth.js
CHANGED
|
@@ -3,86 +3,168 @@ import { u8aToHex } from "@polkadot/util";
|
|
|
3
3
|
import { randomAsHex } from "@polkadot/util-crypto";
|
|
4
4
|
import { ProsopoEnvError } from "@prosopo/common";
|
|
5
5
|
import { getPair } from "@prosopo/keyring";
|
|
6
|
+
import { getLogger } from "@prosopo/logger";
|
|
6
7
|
import { ProsopoServer } from "@prosopo/server";
|
|
7
|
-
import { ProcaptchaResponse, ApiParams } from "@prosopo/types";
|
|
8
|
+
import { ProcaptchaResponse, CaptchaType, ApiParams } from "@prosopo/types";
|
|
8
9
|
import { at } from "@prosopo/util";
|
|
9
10
|
import jwt from "jsonwebtoken";
|
|
10
11
|
import { z } from "zod";
|
|
12
|
+
const logger = getLogger("info", import.meta.url);
|
|
11
13
|
const SubscribeBodySpec = ProcaptchaResponse.merge(
|
|
12
14
|
z.object({
|
|
13
15
|
email: z.string().email(),
|
|
14
|
-
password: z.string()
|
|
16
|
+
password: z.string(),
|
|
17
|
+
siteKey: z.string()
|
|
15
18
|
})
|
|
16
19
|
);
|
|
17
20
|
function hashPassword(password) {
|
|
18
21
|
return u8aToHex(blake2b(password));
|
|
19
22
|
}
|
|
20
23
|
const NO_IP = "NO_IP";
|
|
21
|
-
const
|
|
24
|
+
const getPairAndSecretForSiteKey = (baseSecret, siteKey) => {
|
|
25
|
+
let pair;
|
|
26
|
+
let secret = baseSecret;
|
|
27
|
+
pair = getPair(secret);
|
|
28
|
+
if (pair.address === siteKey) {
|
|
29
|
+
logger.info(() => ({
|
|
30
|
+
msg: "Site key matches the server configuration without captcha type suffix",
|
|
31
|
+
data: {
|
|
32
|
+
siteKeyDerived: pair?.address,
|
|
33
|
+
siteKey
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
return { pair, secret };
|
|
37
|
+
}
|
|
38
|
+
for (const captchaType of [
|
|
39
|
+
CaptchaType.pow,
|
|
40
|
+
CaptchaType.image,
|
|
41
|
+
CaptchaType.frictionless,
|
|
42
|
+
CaptchaType.puzzle
|
|
43
|
+
]) {
|
|
44
|
+
const newSecret = `${baseSecret}//${captchaType}`;
|
|
45
|
+
pair = getPair(newSecret);
|
|
46
|
+
console.log(
|
|
47
|
+
`[PAIR CHECK] Checking pair for ${captchaType}: ${pair?.address} (expected: ${siteKey})`
|
|
48
|
+
);
|
|
49
|
+
logger.info(() => ({
|
|
50
|
+
msg: "Checking pair",
|
|
51
|
+
data: {
|
|
52
|
+
captchaType,
|
|
53
|
+
siteKeyDerived: pair?.address,
|
|
54
|
+
siteKey
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
if (pair.address === siteKey) {
|
|
58
|
+
console.log(`[PAIR CHECK] ✅ Match found for ${captchaType}!`);
|
|
59
|
+
secret = newSecret;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!pair || pair.address !== siteKey) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`Site key does not match the server configuration: Provided ${siteKey} vs Server ${pair?.address}`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return { pair, secret };
|
|
69
|
+
};
|
|
70
|
+
const getResponse = async (ip, token, secret, verifyEndpoint, email) => {
|
|
22
71
|
const body = {
|
|
23
72
|
[ApiParams.token]: token,
|
|
24
|
-
[ApiParams.secret]: secret
|
|
73
|
+
[ApiParams.secret]: secret,
|
|
74
|
+
...email ? { [ApiParams.email]: email } : {}
|
|
25
75
|
};
|
|
26
76
|
if (process.env.NODE_ENV !== "development") {
|
|
27
77
|
body[ApiParams.ip] = ip;
|
|
28
78
|
}
|
|
29
|
-
|
|
79
|
+
logger.info(() => ({
|
|
80
|
+
data: {
|
|
81
|
+
body
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
30
84
|
const response = await fetch(verifyEndpoint, {
|
|
31
85
|
method: "POST",
|
|
32
86
|
body: JSON.stringify(body)
|
|
33
87
|
});
|
|
34
88
|
return response.json();
|
|
35
89
|
};
|
|
36
|
-
const verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret, ip) => {
|
|
90
|
+
const verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret, ip, email) => {
|
|
37
91
|
if (verifyType === "api") {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
92
|
+
logger.info(() => ({
|
|
93
|
+
msg: "Verifying using the API endpoint",
|
|
94
|
+
data: {
|
|
95
|
+
verifyEndpoint
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
98
|
+
const response = await getResponse(
|
|
99
|
+
ip,
|
|
100
|
+
token,
|
|
101
|
+
secret,
|
|
102
|
+
verifyEndpoint,
|
|
103
|
+
email
|
|
104
|
+
);
|
|
105
|
+
logger.info(() => ({
|
|
106
|
+
data: {
|
|
107
|
+
response
|
|
108
|
+
}
|
|
109
|
+
}));
|
|
41
110
|
return response.verified;
|
|
42
111
|
}
|
|
43
|
-
const verified = await prosopoServer.isVerified(token);
|
|
44
|
-
|
|
45
|
-
|
|
112
|
+
const verified = await prosopoServer.isVerified(token, ip, email);
|
|
113
|
+
logger.info(() => ({
|
|
114
|
+
data: {
|
|
115
|
+
verified
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
return verified[ApiParams.verified];
|
|
46
119
|
};
|
|
47
120
|
const signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, next) => {
|
|
48
121
|
try {
|
|
122
|
+
if (!config.account.secret) {
|
|
123
|
+
throw new ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
|
|
124
|
+
context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] }
|
|
125
|
+
});
|
|
126
|
+
}
|
|
49
127
|
const User = mongoose.model("User");
|
|
50
128
|
const dbUser = await User.findOne({
|
|
51
129
|
email: { $eq: req.body.email }
|
|
52
130
|
});
|
|
53
131
|
const payload = SubscribeBodySpec.parse(req.body);
|
|
54
|
-
const
|
|
132
|
+
const token = payload[ApiParams.procaptchaResponse];
|
|
133
|
+
const siteKey = payload[ApiParams.siteKey];
|
|
134
|
+
const { pair, secret } = getPairAndSecretForSiteKey(
|
|
135
|
+
config.account.secret,
|
|
136
|
+
siteKey
|
|
137
|
+
);
|
|
55
138
|
const prosopoServer = new ProsopoServer(config, pair);
|
|
56
139
|
if (dbUser) {
|
|
57
140
|
return res.status(409).json({ message: "email already exists" });
|
|
58
141
|
}
|
|
59
|
-
const
|
|
60
|
-
if (!config.account.secret) {
|
|
61
|
-
throw new ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
|
|
62
|
-
context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] }
|
|
63
|
-
});
|
|
64
|
-
}
|
|
142
|
+
const email = req.body.email;
|
|
65
143
|
const verified = await verify(
|
|
66
144
|
prosopoServer,
|
|
67
145
|
verifyType,
|
|
68
146
|
verifyEndpoint,
|
|
69
147
|
token,
|
|
70
|
-
|
|
71
|
-
req.headers["x-client-ip"]?.toString() ||
|
|
148
|
+
secret,
|
|
149
|
+
req.headers["x-client-ip"]?.toString() || "127.0.0.1",
|
|
150
|
+
email
|
|
72
151
|
);
|
|
73
|
-
if (verified) {
|
|
152
|
+
if (verified === true) {
|
|
74
153
|
const salt = randomAsHex(32);
|
|
75
154
|
const passwordHash = hashPassword(`${req.body.password}${salt}`);
|
|
76
155
|
if (passwordHash) {
|
|
77
156
|
return User.create({
|
|
78
|
-
email
|
|
157
|
+
email,
|
|
79
158
|
name: req.body.name,
|
|
80
159
|
password: passwordHash,
|
|
81
160
|
salt
|
|
82
161
|
}).then(() => {
|
|
83
162
|
res.status(200).json({ message: "user created" });
|
|
84
163
|
}).catch((err) => {
|
|
85
|
-
|
|
164
|
+
logger.error(() => ({
|
|
165
|
+
err,
|
|
166
|
+
msg: "Error creating user in database"
|
|
167
|
+
}));
|
|
86
168
|
res.status(502).json({ message: "error while creating the user" });
|
|
87
169
|
});
|
|
88
170
|
}
|
|
@@ -96,29 +178,36 @@ const signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, ne
|
|
|
96
178
|
};
|
|
97
179
|
const login = async (mongoose, config, verifyEndpoint, verifyType, req, res) => {
|
|
98
180
|
const User = mongoose.model("User");
|
|
99
|
-
const pair = await getPair(config.account.secret);
|
|
100
|
-
const prosopoServer = new ProsopoServer(config, pair);
|
|
101
181
|
await User.findOne({
|
|
102
182
|
email: { $eq: req.body.email }
|
|
103
183
|
}).then(async (dbUser) => {
|
|
104
184
|
if (dbUser) {
|
|
105
|
-
console.log(req.body);
|
|
106
185
|
const payload = SubscribeBodySpec.parse(req.body);
|
|
107
186
|
const token = payload[ApiParams.procaptchaResponse];
|
|
187
|
+
const siteKey = payload[ApiParams.siteKey];
|
|
108
188
|
if (!config.account.secret) {
|
|
109
189
|
throw new ProsopoEnvError("GENERAL.SECRET_MISSING", {
|
|
110
190
|
context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] }
|
|
111
191
|
});
|
|
112
192
|
}
|
|
193
|
+
const { pair, secret } = getPairAndSecretForSiteKey(
|
|
194
|
+
config.account.secret,
|
|
195
|
+
siteKey
|
|
196
|
+
);
|
|
197
|
+
const prosopoServer = new ProsopoServer(config, pair);
|
|
113
198
|
const verified = await verify(
|
|
114
199
|
prosopoServer,
|
|
115
200
|
verifyType,
|
|
116
201
|
verifyEndpoint,
|
|
117
202
|
token,
|
|
118
|
-
|
|
203
|
+
secret,
|
|
119
204
|
req.headers["x-client-ip"]?.toString() || NO_IP
|
|
120
205
|
);
|
|
121
|
-
|
|
206
|
+
logger.info(() => ({
|
|
207
|
+
data: {
|
|
208
|
+
verified
|
|
209
|
+
}
|
|
210
|
+
}));
|
|
122
211
|
if (verified) {
|
|
123
212
|
const passwordHash = hashPassword(
|
|
124
213
|
`${req.body.password}${dbUser.salt}`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAA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AM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC,CAAC;IAC5D,CAAC;AACF,CAAC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
export interface UserInterface {
|
|
3
|
+
id: number;
|
|
4
|
+
email: string;
|
|
5
|
+
name: string;
|
|
6
|
+
password: string;
|
|
7
|
+
salt: string;
|
|
8
|
+
}
|
|
9
|
+
declare const UserSchema: mongoose.Schema<UserInterface, mongoose.Model<UserInterface, any, any, any, mongoose.Document<unknown, any, UserInterface> & UserInterface & {
|
|
10
|
+
_id: mongoose.Types.ObjectId;
|
|
11
|
+
} & {
|
|
12
|
+
__v: number;
|
|
13
|
+
}, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, UserInterface, mongoose.Document<unknown, {}, mongoose.FlatRecord<UserInterface>> & mongoose.FlatRecord<UserInterface> & {
|
|
14
|
+
_id: mongoose.Types.ObjectId;
|
|
15
|
+
} & {
|
|
16
|
+
__v: number;
|
|
17
|
+
}>;
|
|
18
|
+
export default UserSchema;
|
|
19
|
+
//# sourceMappingURL=user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAaA,OAAO,QAAoB,MAAM,UAAU,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,QAAA,MAAM,UAAU;;;;;;;;EAmBd,CAAC;AAEH,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAaA,OAAO,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAU5C,MAAM,UAAU,GAAG,IAAI,MAAM,CAAgB;IAC5C,KAAK,EAAE;QACN,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;QACjC,QAAQ,EAAE,IAAI;KACd;IACD,IAAI,EAAE;QACL,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;KACjC;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;QACjC,QAAQ,EAAE,IAAI;KACd;IACD,EAAE,EAAE;QACH,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;KACjC;IACD,IAAI,EAAE;QACL,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;QACjC,QAAQ,EAAE,IAAI;KACd;CACD,CAAC,CAAC;AAEH,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ProsopoServerConfigOutput } from "@prosopo/types";
|
|
2
|
+
import express from "express";
|
|
3
|
+
import type { Connection } from "mongoose";
|
|
4
|
+
declare function getRoutes(mongoose: Connection, config: ProsopoServerConfigOutput, verifyEndpoint: string, verifyType: string): express.Router;
|
|
5
|
+
export default getRoutes;
|
|
6
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,OAAO,MAAM,SAAS,CAAC;AAc9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAK3C,iBAAS,SAAS,CACjB,QAAQ,EAAE,UAAU,EACpB,MAAM,EAAE,yBAAyB,EACjC,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CA0BhB;AAED,eAAe,SAAS,CAAC"}
|
package/dist/routes/routes.js
CHANGED
|
@@ -14,6 +14,9 @@ function getRoutes(mongoose, config, verifyEndpoint, verifyType) {
|
|
|
14
14
|
router.get("/public", (req, res) => {
|
|
15
15
|
res.status(200).json({ message: "here is your public resource" });
|
|
16
16
|
});
|
|
17
|
+
router.get("/health", (req, res) => {
|
|
18
|
+
res.status(200).json({ status: "ok" });
|
|
19
|
+
});
|
|
17
20
|
router.use("/", (req, res) => {
|
|
18
21
|
res.status(404).json({ error: "page not found" });
|
|
19
22
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAe9B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAEhC,SAAS,SAAS,CACjB,QAAoB,EACpB,MAAiC,EACjC,cAAsB,EACtB,UAAkB;IAElB,MAAM,CAAC,IAAI,CACV,QAAQ,EACR,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,CAAC,CAC9D,CAAC;IAEF,MAAM,CAAC,IAAI,CACV,SAAS,EACT,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,CAAC,CAC/D,CAAC;IAEF,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAE/B,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAClC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,C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