@prosopo/client-example-server 0.1.17 → 0.1.19
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/dist/app.js +4 -4
- package/dist/app.js.map +1 -1
- package/dist/bundle/prosopo_client_example_server.app.bundle.js +18880 -19431
- package/dist/controllers/auth.d.ts +4 -3
- package/dist/controllers/auth.d.ts.map +1 -1
- package/dist/controllers/auth.js +6 -5
- package/dist/controllers/auth.js.map +1 -1
- package/dist/prosopo.config.d.ts +1 -1
- package/dist/prosopo.config.js +2 -2
- package/dist/prosopo.config.js.map +1 -1
- package/dist/routes/routes.js +1 -1
- package/dist/routes/routes.js.map +1 -1
- package/dist/utils/connection.js +1 -1
- package/dist/utils/connection.js.map +1 -1
- package/package.json +51 -47
- package/.env.development +0 -9
- 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 +1,8 @@
|
|
|
1
1
|
import { Connection } from 'mongoose';
|
|
2
|
+
import { NextFunction, Request, Response } from 'express';
|
|
2
3
|
import { ProsopoServer } from '@prosopo/server';
|
|
3
|
-
declare const signup: (mongoose: Connection, prosopoServer: ProsopoServer, req:
|
|
4
|
-
declare const login: (mongoose: Connection, prosopoServer: ProsopoServer, req:
|
|
5
|
-
declare const isAuth: (req:
|
|
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;
|
|
6
7
|
export { signup, login, isAuth };
|
|
7
8
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;
|
|
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"}
|
package/dist/controllers/auth.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { ApiParams } from '@prosopo/types';
|
|
15
15
|
import { ProcaptchaResponse } from '@prosopo/types';
|
|
16
|
+
import { at } from '@prosopo/util';
|
|
16
17
|
import { blake2b } from '@noble/hashes/blake2b';
|
|
17
18
|
import { randomAsHex } from '@polkadot/util-crypto';
|
|
18
19
|
import { u8aToHex } from '@polkadot/util';
|
|
@@ -76,7 +77,7 @@ const login = async (mongoose, prosopoServer, req, res) => {
|
|
|
76
77
|
})
|
|
77
78
|
.then(async (dbUser) => {
|
|
78
79
|
if (!dbUser) {
|
|
79
|
-
|
|
80
|
+
res.status(404).json({ message: 'user not found' });
|
|
80
81
|
}
|
|
81
82
|
else {
|
|
82
83
|
const payload = SubscribeBodySpec.parse(req.body);
|
|
@@ -102,17 +103,17 @@ const login = async (mongoose, prosopoServer, req, res) => {
|
|
|
102
103
|
});
|
|
103
104
|
};
|
|
104
105
|
const isAuth = (req, res) => {
|
|
105
|
-
const authHeader = req.get('Authorization');
|
|
106
|
+
const authHeader = req.get('Authorization') || '';
|
|
106
107
|
if (!authHeader) {
|
|
107
|
-
|
|
108
|
+
res.status(401).json({ message: 'not authenticated' });
|
|
108
109
|
}
|
|
109
|
-
const token = authHeader.split(' ')
|
|
110
|
+
const token = at(authHeader.split(' '), 1);
|
|
110
111
|
let decodedToken;
|
|
111
112
|
try {
|
|
112
113
|
decodedToken = jwt.verify(token, 'secret');
|
|
113
114
|
}
|
|
114
115
|
catch (err) {
|
|
115
|
-
|
|
116
|
+
res.status(500).json({ message: err.message || 'could not decode the token' });
|
|
116
117
|
}
|
|
117
118
|
if (!decodedToken) {
|
|
118
119
|
res.status(401).json({ message: 'unauthorized' });
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;A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AAA;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/prosopo.config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: () => {
|
|
2
|
-
logLevel: "
|
|
2
|
+
logLevel: "error" | "trace" | "debug" | "info" | "warn" | "fatal";
|
|
3
3
|
defaultEnvironment: "development" | "rococo" | "kusama" | "polkadot" | "shiden";
|
|
4
4
|
account: {
|
|
5
5
|
address: string;
|
package/dist/prosopo.config.js
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
// import {ProsopoConfig} from './types';
|
|
15
15
|
import { EnvironmentTypesSchema } from '@prosopo/types';
|
|
16
|
-
import {
|
|
16
|
+
import { LogLevel } from '@prosopo/common';
|
|
17
17
|
export default () => ({
|
|
18
|
-
logLevel: process.env.LOG_LEVEL ||
|
|
18
|
+
logLevel: process.env.LOG_LEVEL || LogLevel.enum.debug,
|
|
19
19
|
defaultEnvironment: process.env.DEFAULT_ENVIRONMENT || EnvironmentTypesSchema.enum.development,
|
|
20
20
|
web2: process.env.REACT_APP_WEB2 || true,
|
|
21
21
|
serverUrl: process.env.REACT_APP_SERVER_URL && process.env.REACT_APP_SERVER_PORT
|
|
@@ -1 +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;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,yCAAyC;A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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;CACJ,CAAwB,CAAA"}
|
package/dist/routes/routes.js
CHANGED
|
@@ -1 +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,
|
|
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"}
|
package/dist/utils/connection.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { AutoIncrementID } from '@typegoose/auto-increment';
|
|
15
|
-
import UserSchema from '../models/user';
|
|
15
|
+
import UserSchema from '../models/user.js';
|
|
16
16
|
import mongoose from 'mongoose';
|
|
17
17
|
function connectionFactory(uri) {
|
|
18
18
|
const conn = mongoose.createConnection(uri);
|
|
@@ -1 +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,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,49 +1,53 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
2
|
+
"name": "@prosopo/client-example-server",
|
|
3
|
+
"version": "0.1.19",
|
|
4
|
+
"description": "Backend for client-example",
|
|
5
|
+
"main": "dist/app.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "vite serve --mode=development --config ./vite.config.ts --host",
|
|
9
|
+
"start": "node ./dist/bundle/prosopo_client_example_server.app.bundle.js",
|
|
10
|
+
"build": "npm run build:prod",
|
|
11
|
+
"build:prod": "vite build --mode=production --config ./vite.config.ts",
|
|
12
|
+
"build:dev": "vite build --mode=development --config ./vite.config.ts",
|
|
13
|
+
"clean": "tsc --build --clean",
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
15
|
+
"lint:fix": "npx eslint . --fix"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/prosopo/client-example-server.git"
|
|
20
|
+
},
|
|
21
|
+
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/prosopo/client-example-server/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/prosopo/client-example-server#readme",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@noble/hashes": "^1.3.1",
|
|
29
|
+
"@polkadot/util": "12.3.2",
|
|
30
|
+
"@polkadot/util-crypto": "12.3.2",
|
|
31
|
+
"@prosopo/api": "^0.1.19",
|
|
32
|
+
"@prosopo/contract": "^0.1.19",
|
|
33
|
+
"@prosopo/procaptcha": "^0.1.19",
|
|
34
|
+
"@prosopo/server": "^0.1.19",
|
|
35
|
+
"@prosopo/types": "^0.1.19",
|
|
36
|
+
"@typegoose/auto-increment": "3.3.0",
|
|
37
|
+
"axios": "^0.27.2",
|
|
38
|
+
"cors": "^2.8.5",
|
|
39
|
+
"jsonwebtoken": "^9.0.0",
|
|
40
|
+
"mongoose": "^7.3.3",
|
|
41
|
+
"zod": "^3.17.9"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/jsonwebtoken": "^9.0.2",
|
|
45
|
+
"nodemon": "^2.0.22",
|
|
46
|
+
"ts-loader": "^9.4.3",
|
|
47
|
+
"ts-node": "^10.9.1",
|
|
48
|
+
"tslib": "^2.6.2",
|
|
49
|
+
"typescript": "^5.1.6",
|
|
50
|
+
"vite": "^4.4.9",
|
|
51
|
+
"@prosopo/config": "^0.1.19"
|
|
52
|
+
}
|
|
49
53
|
}
|
package/.env.development
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
REACT_APP_API_PATH_PREFIX=/v1/prosopo
|
|
2
|
-
REACT_APP_DAPP_SITE_KEY=5E5iBY4XRTJbXNMZHuxSonXs3bhzExfp5fgWuw8MizuuM4XH
|
|
3
|
-
REACT_APP_SUBSTRATE_NODE_URL=ws://localhost:9944
|
|
4
|
-
REACT_APP_PROSOPO_CONTRACT_ADDRESS=5G1mUozbJuWKhVSVgZYz5Yitjd5WK72yZy9hAWAG797eUn6X
|
|
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/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 }
|
package/src/models/user.ts
DELETED
|
@@ -1,41 +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
|
-
|
|
16
|
-
export interface UserInterface {
|
|
17
|
-
id: number
|
|
18
|
-
email: string
|
|
19
|
-
name: string
|
|
20
|
-
password: string
|
|
21
|
-
salt: string
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const UserSchema = new Schema<UserInterface>({
|
|
25
|
-
email: {
|
|
26
|
-
type: mongoose.SchemaTypes.String,
|
|
27
|
-
required: true,
|
|
28
|
-
},
|
|
29
|
-
name: {
|
|
30
|
-
type: mongoose.SchemaTypes.String,
|
|
31
|
-
},
|
|
32
|
-
password: {
|
|
33
|
-
type: mongoose.SchemaTypes.String,
|
|
34
|
-
required: true,
|
|
35
|
-
},
|
|
36
|
-
id: {
|
|
37
|
-
type: mongoose.SchemaTypes.Number,
|
|
38
|
-
},
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
export default UserSchema
|
package/src/prosopo.config.ts
DELETED
|
@@ -1,60 +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
|
-
|
|
16
|
-
import { EnvironmentTypesSchema, ProsopoServerConfig } from '@prosopo/types'
|
|
17
|
-
import { LogLevelSchema } from '@prosopo/common'
|
|
18
|
-
|
|
19
|
-
export default () =>
|
|
20
|
-
({
|
|
21
|
-
logLevel: process.env.LOG_LEVEL || LogLevelSchema.enum.Debug,
|
|
22
|
-
defaultEnvironment: process.env.DEFAULT_ENVIRONMENT || EnvironmentTypesSchema.enum.development, // enviromental variables
|
|
23
|
-
web2: process.env.REACT_APP_WEB2 || true,
|
|
24
|
-
serverUrl:
|
|
25
|
-
process.env.REACT_APP_SERVER_URL && process.env.REACT_APP_SERVER_PORT
|
|
26
|
-
? `${process.env.REACT_APP_SERVER_URL}:${process.env.REACT_APP_SERVER_PORT}`
|
|
27
|
-
: 'http://localhost:9228',
|
|
28
|
-
solutionThreshold: process.env.REACT_APP_SOLUTION_THRESHOLD || 0.5,
|
|
29
|
-
dappName: process.env.REACT_APP_DAPP_NAME || 'client-example-server',
|
|
30
|
-
account: {
|
|
31
|
-
password: '',
|
|
32
|
-
address: process.env.REACT_APP_SERVER_ACCOUNT_ADDRESS || '',
|
|
33
|
-
},
|
|
34
|
-
networks: {
|
|
35
|
-
development: {
|
|
36
|
-
endpoint: process.env.REACT_APP_SUBSTRATE_NODE_URL || 'ws://localhost:9944',
|
|
37
|
-
contract: {
|
|
38
|
-
address: process.env.REACT_APP_PROSOPO_CONTRACT_ADDRESS,
|
|
39
|
-
name: 'prosopo',
|
|
40
|
-
},
|
|
41
|
-
dappAccount: {
|
|
42
|
-
address: process.env.REACT_APP_DAPP_SITE_KEY,
|
|
43
|
-
name: 'dapp',
|
|
44
|
-
},
|
|
45
|
-
accounts: ['//Alice', '//Bob', '//Charlie', '//Dave', '//Eve', '//Ferdie'],
|
|
46
|
-
},
|
|
47
|
-
shiden: {
|
|
48
|
-
endpoint: 'wss://shiden.public.blastapi.io',
|
|
49
|
-
contract: {
|
|
50
|
-
address: process.env.REACT_APP_PROSOPO_CONTRACT_ADDRESS,
|
|
51
|
-
name: 'prosopo',
|
|
52
|
-
},
|
|
53
|
-
dappAccount: {
|
|
54
|
-
address: process.env.REACT_APP_DAPP_SITE_KEY,
|
|
55
|
-
name: 'dapp',
|
|
56
|
-
},
|
|
57
|
-
accounts: [],
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
} as ProsopoServerConfig)
|
package/src/routes/routes.ts
DELETED
|
@@ -1,39 +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 { Connection } from 'mongoose'
|
|
15
|
-
import { ProsopoServer } from '@prosopo/server'
|
|
16
|
-
import { isAuth, login, signup } from '../controllers/auth'
|
|
17
|
-
import express from 'express'
|
|
18
|
-
|
|
19
|
-
const router = express.Router()
|
|
20
|
-
|
|
21
|
-
function getRoutes(mongoose: Connection, prosopoServer: ProsopoServer): express.Router {
|
|
22
|
-
router.post('/login', login.bind(null, mongoose, prosopoServer))
|
|
23
|
-
|
|
24
|
-
router.post('/signup', signup.bind(null, mongoose, prosopoServer))
|
|
25
|
-
|
|
26
|
-
router.get('/private', isAuth)
|
|
27
|
-
|
|
28
|
-
router.get('/public', (req, res) => {
|
|
29
|
-
res.status(200).json({ message: 'here is your public resource' })
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
// will match any other path
|
|
33
|
-
router.use('/', (req, res) => {
|
|
34
|
-
res.status(404).json({ error: 'page not found' })
|
|
35
|
-
})
|
|
36
|
-
return router
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default getRoutes
|