@prosopo/client-example-server 0.1.18 → 0.2.0

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 { Connection } from 'mongoose';
2
+ import { NextFunction, Request, Response } from 'express';
3
+ import { ProsopoServer } from '@prosopo/server';
4
+ declare const signup: (mongoose: Connection, prosopoServer: ProsopoServer, req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
5
+ declare const login: (mongoose: Connection, prosopoServer: ProsopoServer, 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":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAoB/C,QAAA,MAAM,MAAM,aACE,UAAU,iBACL,aAAa,OACvB,OAAO,OACP,QAAQ,QACP,YAAY,uDA0CrB,CAAA;AAED,QAAA,MAAM,KAAK,aAAoB,UAAU,iBAAiB,aAAa,OAAO,OAAO,OAAO,QAAQ,kBAgCnG,CAAA;AAED,QAAA,MAAM,MAAM,QAAS,OAAO,OAAO,QAAQ,SAmB1C,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA"}
@@ -0,0 +1,126 @@
1
+ // Copyright 2021-2023 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { ApiParams } from '@prosopo/types';
15
+ import { ProcaptchaResponse } from '@prosopo/types';
16
+ import { at } from '@prosopo/util';
17
+ import { blake2b } from '@noble/hashes/blake2b';
18
+ import { randomAsHex } from '@polkadot/util-crypto';
19
+ import { u8aToHex } from '@polkadot/util';
20
+ import { z } from 'zod';
21
+ import jwt from 'jsonwebtoken';
22
+ const SubscribeBodySpec = ProcaptchaResponse.merge(z.object({
23
+ email: z.string().email(),
24
+ password: z.string(),
25
+ }));
26
+ function hashPassword(password) {
27
+ return u8aToHex(blake2b(password));
28
+ }
29
+ const signup = async (mongoose, prosopoServer, req, res, next) => {
30
+ try {
31
+ const User = mongoose.model('User');
32
+ // checks if email exists
33
+ const dbUser = await User.findOne({
34
+ email: req.body.email,
35
+ });
36
+ const payload = SubscribeBodySpec.parse(req.body);
37
+ await prosopoServer.isReady();
38
+ if (dbUser) {
39
+ return res.status(409).json({ message: 'email already exists' });
40
+ }
41
+ if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {
42
+ // salt
43
+ const salt = randomAsHex(32);
44
+ // !!!DUMMY CODE!!! - Do not use in production. Use bcrypt or similar for password hashing.
45
+ const passwordHash = hashPassword(`${req.body.password}${salt}`);
46
+ if (passwordHash) {
47
+ return User.create({
48
+ email: req.body.email,
49
+ name: req.body.name,
50
+ password: passwordHash,
51
+ salt: salt,
52
+ })
53
+ .then(() => {
54
+ res.status(200).json({ message: 'user created' });
55
+ })
56
+ .catch((err) => {
57
+ console.log(err);
58
+ res.status(502).json({ message: 'error while creating the user' });
59
+ });
60
+ }
61
+ }
62
+ else {
63
+ res.status(401).json({ message: 'user has not completed a captcha' });
64
+ }
65
+ }
66
+ catch (err) {
67
+ console.error('error', err);
68
+ res.status(500).json({ message: err.message || 'internal server error' });
69
+ }
70
+ };
71
+ const login = async (mongoose, prosopoServer, req, res) => {
72
+ const User = mongoose.model('User');
73
+ await prosopoServer.isReady();
74
+ // checks if email exists
75
+ await User.findOne({
76
+ email: req.body.email,
77
+ })
78
+ .then(async (dbUser) => {
79
+ if (!dbUser) {
80
+ res.status(404).json({ message: 'user not found' });
81
+ }
82
+ else {
83
+ const payload = SubscribeBodySpec.parse(req.body);
84
+ if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {
85
+ // password hash
86
+ // !!!DUMMY CODE!!! - Do not use in production. Use bcrypt or similar for password hashing.
87
+ const passwordHash = hashPassword(`${req.body.password}${dbUser.salt}`);
88
+ if (passwordHash !== dbUser.password) {
89
+ // password doesnt match
90
+ res.status(401).json({ message: 'invalid credentials' });
91
+ }
92
+ else {
93
+ // password match
94
+ const token = jwt.sign({ email: req.body.email }, 'secret', { expiresIn: '1h' });
95
+ res.status(200).json({ message: 'user logged in', token: token });
96
+ }
97
+ }
98
+ }
99
+ })
100
+ .catch((err) => {
101
+ console.error('error', err);
102
+ res.status(500).json({ message: err.message || 'internal server error' });
103
+ });
104
+ };
105
+ const isAuth = (req, res) => {
106
+ const authHeader = req.get('Authorization') || '';
107
+ if (!authHeader) {
108
+ res.status(401).json({ message: 'not authenticated' });
109
+ }
110
+ const token = at(authHeader.split(' '), 1);
111
+ let decodedToken;
112
+ try {
113
+ decodedToken = jwt.verify(token, 'secret');
114
+ }
115
+ catch (err) {
116
+ res.status(500).json({ message: err.message || 'could not decode the token' });
117
+ }
118
+ if (!decodedToken) {
119
+ res.status(401).json({ message: 'unauthorized' });
120
+ }
121
+ else {
122
+ res.status(200).json({ message: 'here is your resource' });
123
+ }
124
+ };
125
+ export { signup, login, isAuth };
126
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAA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AA4B,EAAE,CAAC,CAAA;KAC5F;IAED,IAAI,CAAC,YAAY,EAAE;QACf,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAA;KACpD;SAAM;QACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC,CAAA;KAC7D;AACL,CAAC,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA"}
@@ -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, {}, UserInterface> & 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,CAAA;AAE3C,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;CACf;AAED,QAAA,MAAM,UAAU;;;;EAed,CAAA;AAEF,eAAe,UAAU,CAAA"}
@@ -0,0 +1,32 @@
1
+ // Copyright 2021-2023 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import mongoose, { Schema } from 'mongoose';
15
+ const UserSchema = new Schema({
16
+ email: {
17
+ type: mongoose.SchemaTypes.String,
18
+ required: true,
19
+ },
20
+ name: {
21
+ type: mongoose.SchemaTypes.String,
22
+ },
23
+ password: {
24
+ type: mongoose.SchemaTypes.String,
25
+ required: true,
26
+ },
27
+ id: {
28
+ type: mongoose.SchemaTypes.Number,
29
+ },
30
+ });
31
+ export default UserSchema;
32
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAU3C,MAAM,UAAU,GAAG,IAAI,MAAM,CAAgB;IACzC,KAAK,EAAE;QACH,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;QACjC,QAAQ,EAAE,IAAI;KACjB;IACD,IAAI,EAAE;QACF,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;KACpC;IACD,QAAQ,EAAE;QACN,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;QACjC,QAAQ,EAAE,IAAI;KACjB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;KACpC;CACJ,CAAC,CAAA;AAEF,eAAe,UAAU,CAAA"}
@@ -0,0 +1,30 @@
1
+ declare const _default: () => {
2
+ logLevel: "error" | "trace" | "debug" | "info" | "warn" | "fatal";
3
+ defaultEnvironment: "development" | "rococo" | "kusama" | "polkadot" | "shiden";
4
+ account: {
5
+ address: string;
6
+ secret?: string | undefined;
7
+ password?: string | undefined;
8
+ };
9
+ networks: Partial<Record<"development" | "rococo" | "kusama" | "polkadot" | "shiden", {
10
+ endpoint: string;
11
+ contract: {
12
+ address: string;
13
+ name: string;
14
+ };
15
+ accounts: string[];
16
+ }>>;
17
+ web2: boolean;
18
+ solutionThreshold: number;
19
+ dappName: string;
20
+ serverUrl: string;
21
+ database?: Partial<Record<"development" | "rococo" | "kusama" | "polkadot" | "shiden", {
22
+ type: string;
23
+ endpoint: string;
24
+ dbname: string;
25
+ authSource: string;
26
+ }>> | undefined;
27
+ userAccountAddress?: string | undefined;
28
+ };
29
+ export default _default;
30
+ //# sourceMappingURL=prosopo.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prosopo.config.d.ts","sourceRoot":"","sources":["../src/prosopo.config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,wBAyC6B"}
@@ -0,0 +1,57 @@
1
+ // Copyright 2021-2022 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ // import {ProsopoConfig} from './types';
15
+ import { EnvironmentTypesSchema } from '@prosopo/types';
16
+ import { LogLevel } from '@prosopo/common';
17
+ export default () => ({
18
+ logLevel: process.env.LOG_LEVEL || LogLevel.enum.debug,
19
+ defaultEnvironment: process.env.DEFAULT_ENVIRONMENT || EnvironmentTypesSchema.enum.development,
20
+ web2: process.env.REACT_APP_WEB2 || true,
21
+ serverUrl: process.env.REACT_APP_SERVER_URL && process.env.REACT_APP_SERVER_PORT
22
+ ? `${process.env.REACT_APP_SERVER_URL}:${process.env.REACT_APP_SERVER_PORT}`
23
+ : 'http://localhost:9228',
24
+ solutionThreshold: process.env.REACT_APP_SOLUTION_THRESHOLD || 0.5,
25
+ dappName: process.env.REACT_APP_DAPP_NAME || 'client-example-server',
26
+ account: {
27
+ password: '',
28
+ address: process.env.REACT_APP_SERVER_ACCOUNT_ADDRESS || '',
29
+ },
30
+ networks: {
31
+ development: {
32
+ endpoint: process.env.REACT_APP_SUBSTRATE_NODE_URL || 'ws://localhost:9944',
33
+ contract: {
34
+ address: process.env.REACT_APP_PROSOPO_CONTRACT_ADDRESS,
35
+ name: 'prosopo',
36
+ },
37
+ dappAccount: {
38
+ address: process.env.REACT_APP_DAPP_SITE_KEY,
39
+ name: 'dapp',
40
+ },
41
+ accounts: ['//Alice', '//Bob', '//Charlie', '//Dave', '//Eve', '//Ferdie'],
42
+ },
43
+ shiden: {
44
+ endpoint: 'wss://shiden.public.blastapi.io',
45
+ contract: {
46
+ address: process.env.REACT_APP_PROSOPO_CONTRACT_ADDRESS,
47
+ name: 'prosopo',
48
+ },
49
+ dappAccount: {
50
+ address: process.env.REACT_APP_DAPP_SITE_KEY,
51
+ name: 'dapp',
52
+ },
53
+ accounts: [],
54
+ },
55
+ },
56
+ });
57
+ //# sourceMappingURL=prosopo.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prosopo.config.js","sourceRoot":"","sources":["../src/prosopo.config.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AAC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AM;aACf;YACD,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC;SAC7E;QACD,MAAM,EAAE;YACJ,QAAQ,EAAE,iCAAiC;YAC3C,QAAQ,EAAE;gBACN,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,kCAAkC;gBACvD,IAAI,EAAE,SAAS;aAClB;YACD,WAAW,EAAE;gBACT,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB;gBAC5C,IAAI,EAAE,MAAM;aACf;YACD,QAAQ,EAAE,EAAE;SACf;KACJ;CACJ,CAAwB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { Connection } from 'mongoose';
2
+ import { ProsopoServer } from '@prosopo/server';
3
+ import express from 'express';
4
+ declare function getRoutes(mongoose: Connection, prosopoServer: ProsopoServer): 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,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,OAAO,OAAO,MAAM,SAAS,CAAA;AAI7B,iBAAS,SAAS,CAAC,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAgBrF;AAED,eAAe,SAAS,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { isAuth, login, signup } from '../controllers/auth.js';
2
+ import express from 'express';
3
+ const router = express.Router();
4
+ function getRoutes(mongoose, prosopoServer) {
5
+ router.post('/login', login.bind(null, mongoose, prosopoServer));
6
+ router.post('/signup', signup.bind(null, mongoose, prosopoServer));
7
+ router.get('/private', isAuth);
8
+ router.get('/public', (req, res) => {
9
+ res.status(200).json({ message: 'here is your public resource' });
10
+ });
11
+ // will match any other path
12
+ router.use('/', (req, res) => {
13
+ res.status(404).json({ error: 'page not found' });
14
+ });
15
+ return router;
16
+ }
17
+ export default getRoutes;
18
+ //# sourceMappingURL=routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,OAAO,MAAM,SAAS,CAAA;AAE7B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAA;AAE/B,SAAS,SAAS,CAAC,QAAoB,EAAE,aAA4B;IACjE,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAA;IAEhE,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAA;IAElE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;IAE9B,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC/B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;IAEF,4BAA4B;IAC5B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACzB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAA;IACrD,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACjB,CAAC;AAED,eAAe,SAAS,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { 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":"AAeA,OAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE/C,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAOlD;AACD,eAAe,iBAAiB,CAAA"}
@@ -0,0 +1,26 @@
1
+ // Copyright 2021-2023 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { AutoIncrementID } from '@typegoose/auto-increment';
15
+ import UserSchema from '../models/user.js';
16
+ import mongoose from 'mongoose';
17
+ function connectionFactory(uri) {
18
+ const conn = mongoose.createConnection(uri);
19
+ if (!conn.models.user) {
20
+ UserSchema.plugin(AutoIncrementID, { field: 'id' });
21
+ conn.model('User', UserSchema);
22
+ }
23
+ return conn;
24
+ }
25
+ export default connectionFactory;
26
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EAAE,eAAe,EAA0B,MAAM,2BAA2B,CAAA;AACnF,OAAO,UAAU,MAAM,mBAAmB,CAAA;AAC1C,OAAO,QAAwB,MAAM,UAAU,CAAA;AAE/C,SAAS,iBAAiB,CAAC,GAAW;IAClC,MAAM,IAAI,GAAG,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;IAC3C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,UAAU,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,IAAI,EAA4B,CAAC,CAAA;QAC7E,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;KACjC;IACD,OAAO,IAAI,CAAA;AACf,CAAC;AACD,eAAe,iBAAiB,CAAA"}
@@ -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,CAAA"}
@@ -0,0 +1,21 @@
1
+ // Copyright 2021-2023 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { MongoMemoryServer } from 'mongodb-memory-server';
15
+ export async function memoryServerSetup() {
16
+ const mongod = MongoMemoryServer.create();
17
+ const memoryServer = await mongod;
18
+ return memoryServer.getUri();
19
+ }
20
+ export default memoryServerSetup;
21
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACnC,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,EAAE,CAAA;IACzC,MAAM,YAAY,GAAG,MAAM,MAAM,CAAA;IACjC,OAAO,YAAY,CAAC,MAAM,EAAE,CAAA;AAChC,CAAC;AACD,eAAe,iBAAiB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prosopo/client-example-server",
3
- "version": "0.1.18",
3
+ "version": "0.2.0",
4
4
  "description": "Backend for client-example",
5
5
  "main": "dist/app.js",
6
6
  "type": "module",
@@ -28,11 +28,11 @@
28
28
  "@noble/hashes": "^1.3.1",
29
29
  "@polkadot/util": "12.3.2",
30
30
  "@polkadot/util-crypto": "12.3.2",
31
- "@prosopo/api": "^0.1.18",
32
- "@prosopo/contract": "^0.1.18",
33
- "@prosopo/procaptcha": "^0.1.18",
34
- "@prosopo/server": "^0.1.18",
35
- "@prosopo/types": "^0.1.18",
31
+ "@prosopo/api": "0.2.0",
32
+ "@prosopo/contract": "0.2.0",
33
+ "@prosopo/procaptcha": "0.2.0",
34
+ "@prosopo/server": "0.2.0",
35
+ "@prosopo/types": "0.2.0",
36
36
  "@typegoose/auto-increment": "3.3.0",
37
37
  "axios": "^0.27.2",
38
38
  "cors": "^2.8.5",
@@ -48,6 +48,6 @@
48
48
  "tslib": "^2.6.2",
49
49
  "typescript": "^5.1.6",
50
50
  "vite": "^4.4.9",
51
- "@prosopo/config": "^0.1.18"
51
+ "@prosopo/config": "0.2.0"
52
52
  }
53
53
  }