-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
141 lines (131 loc) · 3.87 KB
/
index.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import userData from "./db/userData.js"
import userKeys from "./db/userKeys.js";
import authKeys from "./db/authKeys.js";
import authPubKey from "./db/authPubKey.js";
const app = express();
app.use(bodyParser.json({ limit: '100mb' }));
app.use(bodyParser.urlencoded({ extended: true, parameterLimit: 100000, limit: "500mb" }));
app.use(bodyParser.json());
app.use(cors());
app.use(express.json());
dotenv.config();
const port = process.env.PORT || 7000;
const mongourl = process.env.MONGOURL;
try {
await mongoose.connect(mongourl);
console.log("Mongo DB successfully connected");
app.post('/uploadUserKeys', async (req, res) => {
const { address, publicKey, privateKey, nonce } = req.body;
try {
const savedKeys = await userKeys.create({
address,
publicKey,
privateKey,
nonce
});
res.json(savedKeys);
} catch (error) {
res.json(500);
}
});
app.post('/getUserKeys', async (req, res) => {
try {
const { walletAddress } = req.body;
const address = walletAddress;
const keys = await userKeys.findOne({ address });
if (keys)
res.json(keys);
else
res.json(404);
} catch (error) {
res.json(500)
console.log("Error", error);
}
});
app.post('/uploadAuthKeys', async (req, res) => {
const { publicKey, privateKey } = req.body;
try {
const savedKeys = await authKeys.create({
publicKey,
privateKey
});
res.json(savedKeys);
} catch (error) {
console.log("Err", error);
res.json(500)
}
});
app.get("/getAuthKeys", async (req, res) => {
try {
const keys = await authKeys.find({});
if (keys[0])
res.json(keys[0]);
else
res.json(404);
} catch (error) {
console.log("Error", error);
res.json(500);
}
})
app.post("/uploadAuthPubKey", async (req, res) => {
const { publicKey } = req.body;
try {
const savedKey = await authPubKey.create({
publicKey
});
res.json(savedKey);
} catch (error) {
res.json(500);
}
});
app.get("/getAuthPubKey", async (req, res) => {
try {
const key = await authPubKey.find({});
if (key[0])
res.json(key[0]);
else
res.json(404);
} catch (error) {
res.json(500);
}
})
app.post("/uploadData", async (req, res) => {
const { cipherText, cipherText2, cipherText3, publicKey, nonce, sentTime } = req.body;
try {
const savedData = await userData.create({
cipherText,
cipherText2,
cipherText3,
publicKey,
nonce,
sentTime
})
res.json(savedData);
} catch (error) {
console.log("Upload data err", error);
res.json(500);
}
})
app.get("/getUserData", async (req, res) => {
try {
const userDatas = await userData.find({});
if (userDatas[0])
res.json(userDatas);
else
res.json(404);
} catch (error) {
console.log("Get user data err", error);
res.json(500);
}
})
app.listen(port, () => {
console.log(`Server is running in port: ${port}`);
});
} catch (error) {
console.log(error);
}