@prosopo/client-example-server 0.1.17 → 0.1.18
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/package.json +51 -47
- package/.env.development +0 -9
- package/dist/app.d.ts +0 -3
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js +0 -56
- package/dist/app.js.map +0 -1
- package/dist/bundle/nodejs-polars.linux-x64-gnu.node +0 -0
- package/dist/bundle/prosopo_client_example_server.app.bundle.js +0 -289803
- package/dist/controllers/auth.d.ts +0 -7
- package/dist/controllers/auth.d.ts.map +0 -1
- package/dist/controllers/auth.js +0 -125
- package/dist/controllers/auth.js.map +0 -1
- package/dist/models/user.d.ts +0 -15
- package/dist/models/user.d.ts.map +0 -1
- package/dist/models/user.js +0 -32
- package/dist/models/user.js.map +0 -1
- package/dist/prosopo.config.d.ts +0 -30
- package/dist/prosopo.config.d.ts.map +0 -1
- package/dist/prosopo.config.js +0 -57
- package/dist/prosopo.config.js.map +0 -1
- package/dist/routes/routes.d.ts +0 -6
- package/dist/routes/routes.d.ts.map +0 -1
- package/dist/routes/routes.js +0 -18
- package/dist/routes/routes.js.map +0 -1
- package/dist/utils/connection.d.ts +0 -4
- package/dist/utils/connection.d.ts.map +0 -1
- package/dist/utils/connection.js +0 -26
- package/dist/utils/connection.js.map +0 -1
- package/dist/utils/database.d.ts +0 -3
- package/dist/utils/database.d.ts.map +0 -1
- package/dist/utils/database.js +0 -21
- package/dist/utils/database.js.map +0 -1
- package/env.development +0 -9
- package/src/app.ts +0 -84
- package/src/controllers/auth.ts +0 -134
- package/src/models/user.ts +0 -41
- package/src/prosopo.config.ts +0 -60
- package/src/routes/routes.ts +0 -39
- package/src/utils/connection.ts +0 -26
- package/src/utils/database.ts +0 -20
- package/tsconfig.json +0 -50
- package/tsconfig.tsbuildinfo +0 -1
- package/tsconfig.webpack.json +0 -14
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Connection } from 'mongoose';
|
|
2
|
-
import { ProsopoServer } from '@prosopo/server';
|
|
3
|
-
declare const signup: (mongoose: Connection, prosopoServer: ProsopoServer, req: any, res: any, next: any) => Promise<any>;
|
|
4
|
-
declare const login: (mongoose: Connection, prosopoServer: ProsopoServer, req: any, res: any) => Promise<void>;
|
|
5
|
-
declare const isAuth: (req: any, res: any) => any;
|
|
6
|
-
export { signup, login, isAuth };
|
|
7
|
-
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAmB/C,QAAA,MAAM,MAAM,aAAoB,UAAU,iBAAiB,aAAa,gDAyCvE,CAAA;AAED,QAAA,MAAM,KAAK,aAAoB,UAAU,iBAAiB,aAAa,sCAgCtE,CAAA;AAED,QAAA,MAAM,MAAM,6BAmBX,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA"}
|
package/dist/controllers/auth.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
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 { blake2b } from '@noble/hashes/blake2b';
|
|
17
|
-
import { randomAsHex } from '@polkadot/util-crypto';
|
|
18
|
-
import { u8aToHex } from '@polkadot/util';
|
|
19
|
-
import { z } from 'zod';
|
|
20
|
-
import jwt from 'jsonwebtoken';
|
|
21
|
-
const SubscribeBodySpec = ProcaptchaResponse.merge(z.object({
|
|
22
|
-
email: z.string().email(),
|
|
23
|
-
password: z.string(),
|
|
24
|
-
}));
|
|
25
|
-
function hashPassword(password) {
|
|
26
|
-
return u8aToHex(blake2b(password));
|
|
27
|
-
}
|
|
28
|
-
const signup = async (mongoose, prosopoServer, req, res, next) => {
|
|
29
|
-
try {
|
|
30
|
-
const User = mongoose.model('User');
|
|
31
|
-
// checks if email exists
|
|
32
|
-
const dbUser = await User.findOne({
|
|
33
|
-
email: req.body.email,
|
|
34
|
-
});
|
|
35
|
-
const payload = SubscribeBodySpec.parse(req.body);
|
|
36
|
-
await prosopoServer.isReady();
|
|
37
|
-
if (dbUser) {
|
|
38
|
-
return res.status(409).json({ message: 'email already exists' });
|
|
39
|
-
}
|
|
40
|
-
if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {
|
|
41
|
-
// salt
|
|
42
|
-
const salt = randomAsHex(32);
|
|
43
|
-
// !!!DUMMY CODE!!! - Do not use in production. Use bcrypt or similar for password hashing.
|
|
44
|
-
const passwordHash = hashPassword(`${req.body.password}${salt}`);
|
|
45
|
-
if (passwordHash) {
|
|
46
|
-
return User.create({
|
|
47
|
-
email: req.body.email,
|
|
48
|
-
name: req.body.name,
|
|
49
|
-
password: passwordHash,
|
|
50
|
-
salt: salt,
|
|
51
|
-
})
|
|
52
|
-
.then(() => {
|
|
53
|
-
res.status(200).json({ message: 'user created' });
|
|
54
|
-
})
|
|
55
|
-
.catch((err) => {
|
|
56
|
-
console.log(err);
|
|
57
|
-
res.status(502).json({ message: 'error while creating the user' });
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
res.status(401).json({ message: 'user has not completed a captcha' });
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
console.error('error', err);
|
|
67
|
-
res.status(500).json({ message: err.message || 'internal server error' });
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const login = async (mongoose, prosopoServer, req, res) => {
|
|
71
|
-
const User = mongoose.model('User');
|
|
72
|
-
await prosopoServer.isReady();
|
|
73
|
-
// checks if email exists
|
|
74
|
-
await User.findOne({
|
|
75
|
-
email: req.body.email,
|
|
76
|
-
})
|
|
77
|
-
.then(async (dbUser) => {
|
|
78
|
-
if (!dbUser) {
|
|
79
|
-
return res.status(404).json({ message: 'user not found' });
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
const payload = SubscribeBodySpec.parse(req.body);
|
|
83
|
-
if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {
|
|
84
|
-
// password hash
|
|
85
|
-
// !!!DUMMY CODE!!! - Do not use in production. Use bcrypt or similar for password hashing.
|
|
86
|
-
const passwordHash = hashPassword(`${req.body.password}${dbUser.salt}`);
|
|
87
|
-
if (passwordHash !== dbUser.password) {
|
|
88
|
-
// password doesnt match
|
|
89
|
-
res.status(401).json({ message: 'invalid credentials' });
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
// password match
|
|
93
|
-
const token = jwt.sign({ email: req.body.email }, 'secret', { expiresIn: '1h' });
|
|
94
|
-
res.status(200).json({ message: 'user logged in', token: token });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
.catch((err) => {
|
|
100
|
-
console.error('error', err);
|
|
101
|
-
res.status(500).json({ message: err.message || 'internal server error' });
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
const isAuth = (req, res) => {
|
|
105
|
-
const authHeader = req.get('Authorization');
|
|
106
|
-
if (!authHeader) {
|
|
107
|
-
return res.status(401).json({ message: 'not authenticated' });
|
|
108
|
-
}
|
|
109
|
-
const token = authHeader.split(' ')[1];
|
|
110
|
-
let decodedToken;
|
|
111
|
-
try {
|
|
112
|
-
decodedToken = jwt.verify(token, 'secret');
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
return res.status(500).json({ message: err.message || 'could not decode the token' });
|
|
116
|
-
}
|
|
117
|
-
if (!decodedToken) {
|
|
118
|
-
res.status(401).json({ message: 'unauthorized' });
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
res.status(200).json({ message: 'here is your resource' });
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
export { signup, login, isAuth };
|
|
125
|
-
//# sourceMappingURL=auth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/controllers/auth.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,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,GAAG,MAAM,cAAc,CAAA;AAE9B,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,KAAK,CAC9C,CAAC,CAAC,MAAM,CAAC;IACL,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,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E;IACxB,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;IAC3C,IAAI,CAAC,UAAU,EAAE;QACb,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC,CAAA;KAChE;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IACtC,IAAI,YAAY,CAAA;IAChB,IAAI;QACA,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;KAC7C;IAAC,OAAO,GAAG,EAAE;QACV,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,4BAA4B,EAAE,CAAC,CAAA;KACxF;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"}
|
package/dist/models/user.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/models/user.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
|
package/dist/models/user.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/prosopo.config.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
declare const _default: () => {
|
|
2
|
-
logLevel: "Silent" | "Error" | "Warn" | "Log" | "Info" | "Debug" | "Trace" | "Verbose";
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prosopo.config.d.ts","sourceRoot":"","sources":["../src/prosopo.config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,wBAyC6B"}
|
package/dist/prosopo.config.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
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 { LogLevelSchema } from '@prosopo/common';
|
|
17
|
-
export default () => ({
|
|
18
|
-
logLevel: process.env.LOG_LEVEL || LogLevelSchema.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
|
|
@@ -1 +0,0 @@
|
|
|
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;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,yCAAyC;AAEzC,OAAO,EAAE,sBAAsB,EAAuB,MAAM,gBAAgB,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,eAAe,GAAG,EAAE,CAChB,CAAC;IACG,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK;IAC5D,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,sBAAsB,CAAC,IAAI,CAAC,WAAW;IAC9F,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,IAAI;IACxC,SAAS,EACL,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB;QACjE,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE;QAC5E,CAAC,CAAC,uBAAuB;IACjC,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,GAAG;IAClE,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,uBAAuB;IACpE,OAAO,EAAE;QACL,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,EAAE;KAC9D;IACD,QAAQ,EAAE;QACN,WAAW,EAAE;YACT,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,qBAAqB;YAC3E,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,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;CACoB,CAAA,CAAA"}
|
package/dist/routes/routes.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/routes/routes.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { isAuth, login, signup } from '../controllers/auth';
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC3D,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"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/utils/connection.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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';
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,gBAAgB,CAAA;AACvC,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"}
|
package/dist/utils/database.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/utils/database.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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/env.development
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
REACT_APP_API_PATH_PREFIX=/v1/prosopo
|
|
2
|
-
REACT_APP_DAPP_SITE_KEY=
|
|
3
|
-
REACT_APP_SUBSTRATE_NODE_URL=ws://localhost:9944
|
|
4
|
-
REACT_APP_PROSOPO_CONTRACT_ADDRESS=
|
|
5
|
-
REACT_APP_WEB2=true
|
|
6
|
-
REACT_APP_SERVER_URL=https://localhost
|
|
7
|
-
REACT_APP_SERVER_MNEMONIC=//Bob
|
|
8
|
-
REACT_APP_SERVER_ACCOUNT_ADDRESS=
|
|
9
|
-
REACT_APP_SERVER_PORT=9228
|
package/src/app.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
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 { KeypairType } from '@polkadot/util-crypto/types'
|
|
15
|
-
import { ProsopoServer } from '@prosopo/server'
|
|
16
|
-
import { getPair } from '@prosopo/common'
|
|
17
|
-
import connectionFactory from './utils/connection'
|
|
18
|
-
import cors from 'cors'
|
|
19
|
-
import dotenv from 'dotenv'
|
|
20
|
-
import express from 'express'
|
|
21
|
-
import memoryServerSetup from './utils/database'
|
|
22
|
-
import path from 'path'
|
|
23
|
-
import prosopoConfig from './prosopo.config'
|
|
24
|
-
import routesFactory from './routes/routes'
|
|
25
|
-
|
|
26
|
-
export function loadEnv() {
|
|
27
|
-
dotenv.config({ path: getEnvFile() })
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function getEnvFile(filename = '.env', filepath = './') {
|
|
31
|
-
const env = process.env.NODE_ENV || 'development'
|
|
32
|
-
return path.join(filepath, `${filename}.${env}`)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async function main() {
|
|
36
|
-
loadEnv()
|
|
37
|
-
|
|
38
|
-
const app = express()
|
|
39
|
-
|
|
40
|
-
app.use(cors({ origin: true, credentials: true }))
|
|
41
|
-
|
|
42
|
-
app.use(express.urlencoded({ extended: true }))
|
|
43
|
-
|
|
44
|
-
app.use(express.json())
|
|
45
|
-
|
|
46
|
-
app.use((_, res, next) => {
|
|
47
|
-
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
48
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE')
|
|
49
|
-
res.setHeader('Access-Control-Allow-Headers', 'Origin, Content-Type, X-Auth-Token, Authorization')
|
|
50
|
-
next()
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
app.options('/*', (_, res) => {
|
|
54
|
-
res.sendStatus(200)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
const uri = await memoryServerSetup()
|
|
58
|
-
console.log('mongo uri', uri)
|
|
59
|
-
const mongoose = connectionFactory(uri)
|
|
60
|
-
if (!process.env.REACT_APP_SERVER_MNEMONIC) {
|
|
61
|
-
throw new Error('No mnemonic found')
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const config = prosopoConfig()
|
|
65
|
-
|
|
66
|
-
console.log('config', config)
|
|
67
|
-
const pairType = (process.env.PAIR_TYPE as KeypairType) || ('sr25519' as KeypairType)
|
|
68
|
-
const ss58Format = parseInt(process.env.SS58_FORMAT || '') || 42
|
|
69
|
-
const pair = await getPair(pairType, ss58Format, process.env.REACT_APP_SERVER_MNEMONIC)
|
|
70
|
-
const prosopoServer = new ProsopoServer(pair, config)
|
|
71
|
-
|
|
72
|
-
app.use(routesFactory(mongoose, prosopoServer))
|
|
73
|
-
|
|
74
|
-
app.listen(process.env.REACT_APP_SERVER_PORT)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
main()
|
|
78
|
-
.then(() => {
|
|
79
|
-
console.log('Server started')
|
|
80
|
-
})
|
|
81
|
-
.catch((err) => {
|
|
82
|
-
console.log(err)
|
|
83
|
-
process.exit()
|
|
84
|
-
})
|
package/src/controllers/auth.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
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 { Connection } from 'mongoose'
|
|
16
|
-
import { ProcaptchaResponse } from '@prosopo/types'
|
|
17
|
-
import { ProsopoServer } from '@prosopo/server'
|
|
18
|
-
import { UserInterface } from '../models/user'
|
|
19
|
-
import { blake2b } from '@noble/hashes/blake2b'
|
|
20
|
-
import { randomAsHex } from '@polkadot/util-crypto'
|
|
21
|
-
import { u8aToHex } from '@polkadot/util'
|
|
22
|
-
import { z } from 'zod'
|
|
23
|
-
import jwt from 'jsonwebtoken'
|
|
24
|
-
|
|
25
|
-
const SubscribeBodySpec = ProcaptchaResponse.merge(
|
|
26
|
-
z.object({
|
|
27
|
-
email: z.string().email(),
|
|
28
|
-
password: z.string(),
|
|
29
|
-
})
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
function hashPassword(password: string): string {
|
|
33
|
-
return u8aToHex(blake2b(password))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const signup = async (mongoose: Connection, prosopoServer: ProsopoServer, req, res, next) => {
|
|
37
|
-
try {
|
|
38
|
-
const User = mongoose.model<UserInterface>('User')
|
|
39
|
-
// checks if email exists
|
|
40
|
-
const dbUser = await User.findOne({
|
|
41
|
-
email: req.body.email,
|
|
42
|
-
})
|
|
43
|
-
const payload = SubscribeBodySpec.parse(req.body)
|
|
44
|
-
await prosopoServer.isReady()
|
|
45
|
-
if (dbUser) {
|
|
46
|
-
return res.status(409).json({ message: 'email already exists' })
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {
|
|
50
|
-
// salt
|
|
51
|
-
const salt = randomAsHex(32)
|
|
52
|
-
// !!!DUMMY CODE!!! - Do not use in production. Use bcrypt or similar for password hashing.
|
|
53
|
-
const passwordHash = hashPassword(`${req.body.password}${salt}`)
|
|
54
|
-
|
|
55
|
-
if (passwordHash) {
|
|
56
|
-
return User.create({
|
|
57
|
-
email: req.body.email,
|
|
58
|
-
name: req.body.name,
|
|
59
|
-
password: passwordHash,
|
|
60
|
-
salt: salt,
|
|
61
|
-
})
|
|
62
|
-
.then(() => {
|
|
63
|
-
res.status(200).json({ message: 'user created' })
|
|
64
|
-
})
|
|
65
|
-
.catch((err) => {
|
|
66
|
-
console.log(err)
|
|
67
|
-
res.status(502).json({ message: 'error while creating the user' })
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
res.status(401).json({ message: 'user has not completed a captcha' })
|
|
72
|
-
}
|
|
73
|
-
} catch (err) {
|
|
74
|
-
console.error('error', err)
|
|
75
|
-
res.status(500).json({ message: err.message || 'internal server error' })
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const login = async (mongoose: Connection, prosopoServer: ProsopoServer, req, res) => {
|
|
80
|
-
const User = mongoose.model<UserInterface>('User')
|
|
81
|
-
await prosopoServer.isReady()
|
|
82
|
-
// checks if email exists
|
|
83
|
-
await User.findOne({
|
|
84
|
-
email: req.body.email,
|
|
85
|
-
})
|
|
86
|
-
.then(async (dbUser) => {
|
|
87
|
-
if (!dbUser) {
|
|
88
|
-
return res.status(404).json({ message: 'user not found' })
|
|
89
|
-
} else {
|
|
90
|
-
const payload = SubscribeBodySpec.parse(req.body)
|
|
91
|
-
|
|
92
|
-
if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {
|
|
93
|
-
// password hash
|
|
94
|
-
// !!!DUMMY CODE!!! - Do not use in production. Use bcrypt or similar for password hashing.
|
|
95
|
-
const passwordHash = hashPassword(`${req.body.password}${dbUser.salt}`)
|
|
96
|
-
if (passwordHash !== dbUser.password) {
|
|
97
|
-
// password doesnt match
|
|
98
|
-
res.status(401).json({ message: 'invalid credentials' })
|
|
99
|
-
} else {
|
|
100
|
-
// password match
|
|
101
|
-
const token = jwt.sign({ email: req.body.email }, 'secret', { expiresIn: '1h' })
|
|
102
|
-
res.status(200).json({ message: 'user logged in', token: token })
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
.catch((err) => {
|
|
108
|
-
console.error('error', err)
|
|
109
|
-
res.status(500).json({ message: err.message || 'internal server error' })
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const isAuth = (req, res) => {
|
|
114
|
-
const authHeader = req.get('Authorization')
|
|
115
|
-
if (!authHeader) {
|
|
116
|
-
return res.status(401).json({ message: 'not authenticated' })
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const token = authHeader.split(' ')[1]
|
|
120
|
-
let decodedToken
|
|
121
|
-
try {
|
|
122
|
-
decodedToken = jwt.verify(token, 'secret')
|
|
123
|
-
} catch (err) {
|
|
124
|
-
return res.status(500).json({ message: err.message || 'could not decode the token' })
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!decodedToken) {
|
|
128
|
-
res.status(401).json({ message: 'unauthorized' })
|
|
129
|
-
} else {
|
|
130
|
-
res.status(200).json({ message: 'here is your resource' })
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export { signup, login, isAuth }
|