@prosopo/client-example-server 2.1.8 → 2.1.9

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.
@@ -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":"AAoBA,OAAO,EAGN,KAAK,yBAAyB,EAC9B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AA2C3C,QAAA,MAAM,MAAM,aACD,UAAU,UACZ,yBAAyB,kBACjB,MAAM,cACV,MAAM,OACb,OAAO,OACP,QAAQ,QACP,YAAY,uDA8DlB,CAAC;AAEF,QAAA,MAAM,KAAK,aACA,UAAU,UACZ,yBAAyB,kBACjB,MAAM,cACV,MAAM,OACb,OAAO,OACP,QAAQ,kBA4Db,CAAC;AAEF,QAAA,MAAM,MAAM,QAAS,OAAO,OAAO,QAAQ,SAqB1C,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,152 @@
1
+ import { blake2b } from "@noble/hashes/blake2b";
2
+ import { u8aToHex } from "@polkadot/util";
3
+ import { randomAsHex } from "@polkadot/util-crypto";
4
+ import { ProsopoEnvError } from "@prosopo/common";
5
+ import { getPairAsync } from "@prosopo/contract";
6
+ import { ProsopoServer } from "@prosopo/server";
7
+ import { ApiParams, } from "@prosopo/types";
8
+ import { ProcaptchaResponse } from "@prosopo/types";
9
+ import { at } from "@prosopo/util";
10
+ import jwt from "jsonwebtoken";
11
+ import { z } from "zod";
12
+ const SubscribeBodySpec = ProcaptchaResponse.merge(z.object({
13
+ email: z.string().email(),
14
+ password: z.string(),
15
+ }));
16
+ function hashPassword(password) {
17
+ return u8aToHex(blake2b(password));
18
+ }
19
+ const verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret) => {
20
+ if (verifyType === "api") {
21
+ console.log("Verifying using the API endpoint", verifyEndpoint);
22
+ const response = await fetch(verifyEndpoint, {
23
+ method: "POST",
24
+ body: JSON.stringify({
25
+ [ApiParams.token]: token,
26
+ [ApiParams.secret]: secret,
27
+ }),
28
+ });
29
+ const verified = (await response.json()).verified;
30
+ console.log("Verified", verified);
31
+ return verified;
32
+ }
33
+ const verified = await prosopoServer.isVerified(token);
34
+ return verified;
35
+ };
36
+ const signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, next) => {
37
+ try {
38
+ const User = mongoose.model("User");
39
+ const dbUser = await User.findOne({
40
+ email: { $eq: req.body.email },
41
+ });
42
+ const payload = SubscribeBodySpec.parse(req.body);
43
+ const pair = await getPairAsync(config.account.secret);
44
+ const prosopoServer = new ProsopoServer(config, pair);
45
+ if (dbUser) {
46
+ return res.status(409).json({ message: "email already exists" });
47
+ }
48
+ const token = payload[ApiParams.procaptchaResponse];
49
+ if (!config.account.secret) {
50
+ throw new ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
51
+ context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] },
52
+ });
53
+ }
54
+ const verified = await verify(prosopoServer, verifyType, verifyEndpoint, token, config.account.secret);
55
+ if (verified) {
56
+ const salt = randomAsHex(32);
57
+ const passwordHash = hashPassword(`${req.body.password}${salt}`);
58
+ if (passwordHash) {
59
+ return User.create({
60
+ email: req.body.email,
61
+ name: req.body.name,
62
+ password: passwordHash,
63
+ salt: salt,
64
+ })
65
+ .then(() => {
66
+ res.status(200).json({ message: "user created" });
67
+ })
68
+ .catch((err) => {
69
+ console.log(err);
70
+ res.status(502).json({ message: "error while creating the user" });
71
+ });
72
+ }
73
+ }
74
+ else {
75
+ res
76
+ .status(401)
77
+ .json({ message: "user has not completed a captcha", verified });
78
+ }
79
+ }
80
+ catch (err) {
81
+ console.error("error", err);
82
+ res
83
+ .status(500)
84
+ .json({ message: err.message || "internal server error" });
85
+ }
86
+ };
87
+ const login = async (mongoose, config, verifyEndpoint, verifyType, req, res) => {
88
+ const User = mongoose.model("User");
89
+ const pair = await getPairAsync(config.account.secret);
90
+ const prosopoServer = new ProsopoServer(config, pair);
91
+ await User.findOne({
92
+ email: { $eq: req.body.email },
93
+ })
94
+ .then(async (dbUser) => {
95
+ if (dbUser) {
96
+ console.log(req.body);
97
+ const payload = SubscribeBodySpec.parse(req.body);
98
+ const token = payload[ApiParams.procaptchaResponse];
99
+ if (!config.account.secret) {
100
+ throw new ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
101
+ context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] },
102
+ });
103
+ }
104
+ const verified = await verify(prosopoServer, verifyType, verifyEndpoint, token, config.account.secret);
105
+ console.log("verified", verified);
106
+ if (verified) {
107
+ const passwordHash = hashPassword(`${req.body.password}${dbUser.salt}`);
108
+ if (passwordHash !== dbUser.password) {
109
+ return res.status(401).json({ message: "invalid credentials" });
110
+ }
111
+ const token = jwt.sign({ email: req.body.email }, "secret", {
112
+ expiresIn: "1h",
113
+ });
114
+ return res
115
+ .status(200)
116
+ .json({ message: "user logged in", token: token });
117
+ }
118
+ return res
119
+ .status(401)
120
+ .json({ message: "user has not completed a captcha", verified });
121
+ }
122
+ return res.status(404).json({ message: "user not found" });
123
+ })
124
+ .catch((err) => {
125
+ console.error("error", err);
126
+ res.status(500).json({ message: err.message || "internal server error" });
127
+ });
128
+ };
129
+ const isAuth = (req, res) => {
130
+ const authHeader = req.get("Authorization") || "";
131
+ if (!authHeader) {
132
+ res.status(401).json({ message: "not authenticated" });
133
+ }
134
+ const token = at(authHeader.split(" "), 1);
135
+ let decodedToken = "";
136
+ try {
137
+ decodedToken = jwt.verify(token, "secret");
138
+ }
139
+ catch (err) {
140
+ res.status(500).json({
141
+ message: err.message || "could not decode the token",
142
+ });
143
+ }
144
+ if (!decodedToken) {
145
+ res.status(401).json({ message: "unauthorized" });
146
+ }
147
+ else {
148
+ res.status(200).json({ message: "here is your resource" });
149
+ }
150
+ };
151
+ export { signup, login, isAuth };
152
+ //# sourceMappingURL=auth.js.map
@@ -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,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACN,SAAS,GAGT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAEnC,OAAO,GAAwB,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,KAAK,CACjD,CAAC,CAAC,MAAM,CAAC;IACR,KAAK,EAAE,CAAC,C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,CAAC,CAAC;IAC5C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACpB,OAAO,EAAG,GAAa,CAAC,OAAO,IAAI,4BAA4B;SAC/D,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QACnB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;IACnD,CAAC;SAAM,CAAC;QACP,GAAG,CAAC,MAAM,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,15 @@
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
+ }, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, UserInterface, mongoose.Document<unknown, {}, mongoose.FlatRecord<UserInterface>> & mongoose.FlatRecord<UserInterface> & {
12
+ _id: mongoose.Types.ObjectId;
13
+ }>;
14
+ export default UserSchema;
15
+ //# 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,23 @@
1
+ import mongoose, { Schema } from "mongoose";
2
+ const UserSchema = new Schema({
3
+ email: {
4
+ type: mongoose.SchemaTypes.String,
5
+ required: true,
6
+ },
7
+ name: {
8
+ type: mongoose.SchemaTypes.String,
9
+ },
10
+ password: {
11
+ type: mongoose.SchemaTypes.String,
12
+ required: true,
13
+ },
14
+ id: {
15
+ type: mongoose.SchemaTypes.Number,
16
+ },
17
+ salt: {
18
+ type: mongoose.SchemaTypes.String,
19
+ required: true,
20
+ },
21
+ });
22
+ export default UserSchema;
23
+ //# sourceMappingURL=user.js.map
@@ -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,CAsBhB;AAED,eAAe,SAAS,CAAC"}
@@ -0,0 +1,17 @@
1
+ import express from "express";
2
+ import { isAuth, login, signup } from "../controllers/auth.js";
3
+ const router = express.Router();
4
+ function getRoutes(mongoose, config, verifyEndpoint, verifyType) {
5
+ router.post("/login", login.bind(null, mongoose, config, verifyEndpoint, verifyType));
6
+ router.post("/signup", signup.bind(null, mongoose, config, verifyEndpoint, verifyType));
7
+ router.get("/private", isAuth);
8
+ router.get("/public", (req, res) => {
9
+ res.status(200).json({ message: "here is your public resource" });
10
+ });
11
+ router.use("/", (req, res) => {
12
+ res.status(404).json({ error: "page not found" });
13
+ });
14
+ return router;
15
+ }
16
+ export default getRoutes;
17
+ //# sourceMappingURL=routes.js.map
@@ -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,CAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAGH,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC5B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AACf,CAAC;AAED,eAAe,SAAS,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type Connection } from "mongoose";
2
+ declare function connectionFactory(uri: string): Connection;
3
+ export default connectionFactory;
4
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAiBA,OAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAGrD,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CASlD;AACD,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { AutoIncrementID, } from "@typegoose/auto-increment";
2
+ import mongoose from "mongoose";
3
+ import UserSchema from "../models/user.js";
4
+ function connectionFactory(uri) {
5
+ const conn = mongoose.createConnection(uri);
6
+ if (!conn.models.user) {
7
+ UserSchema.plugin(AutoIncrementID, {
8
+ field: "id",
9
+ });
10
+ conn.model("User", UserSchema);
11
+ }
12
+ return conn;
13
+ }
14
+ export default connectionFactory;
15
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAaA,OAAO,EACN,eAAe,GAEf,MAAM,2BAA2B,CAAC;AACnC,OAAO,QAA6B,MAAM,UAAU,CAAC;AACrD,OAAO,UAAU,MAAM,mBAAmB,CAAC;AAE3C,SAAS,iBAAiB,CAAC,GAAW;IACrC,MAAM,IAAI,GAAG,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACvB,UAAU,CAAC,MAAM,CAAC,eAAe,EAAE;YAClC,KAAK,EAAE,IAAI;SACe,CAAC,CAAC;QAC7B,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AACD,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function memoryServerSetup(): Promise<string>;
2
+ export default memoryServerSetup;
3
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAcA,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAIzD;AACD,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { MongoMemoryServer } from "mongodb-memory-server";
2
+ export async function memoryServerSetup() {
3
+ const mongod = MongoMemoryServer.create();
4
+ const memoryServer = await mongod;
5
+ return memoryServer.getUri();
6
+ }
7
+ export default memoryServerSetup;
8
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACtC,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,EAAE,CAAC;IAC1C,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC;IAClC,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;AAC9B,CAAC;AACD,eAAe,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prosopo/client-example-server",
3
- "version": "2.1.8",
3
+ "version": "2.1.9",
4
4
  "description": "Backend for client-example",
5
5
  "main": "dist/app.js",
6
6
  "type": "module",
@@ -32,12 +32,12 @@
32
32
  "@noble/hashes": "1.5.0",
33
33
  "@polkadot/util": "12.6.2",
34
34
  "@polkadot/util-crypto": "12.6.2",
35
- "@prosopo/common": "2.1.8",
36
- "@prosopo/contract": "2.1.8",
37
- "@prosopo/dotenv": "2.1.8",
38
- "@prosopo/server": "2.1.8",
39
- "@prosopo/types": "2.1.8",
40
- "@prosopo/util": "2.1.8",
35
+ "@prosopo/common": "2.1.9",
36
+ "@prosopo/contract": "2.1.9",
37
+ "@prosopo/dotenv": "2.1.9",
38
+ "@prosopo/server": "2.1.9",
39
+ "@prosopo/types": "2.1.9",
40
+ "@prosopo/util": "2.1.9",
41
41
  "@typegoose/auto-increment": "4.6.0",
42
42
  "cors": "2.8.5",
43
43
  "express": "4.21.0",
@@ -47,7 +47,7 @@
47
47
  "zod": "3.23.8"
48
48
  },
49
49
  "devDependencies": {
50
- "@prosopo/config": "2.1.8",
50
+ "@prosopo/config": "2.1.9",
51
51
  "@types/jsonwebtoken": "9.0.6",
52
52
  "@vitest/coverage-v8": "2.1.1",
53
53
  "concurrently": "9.0.1",