-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (55 loc) · 1.78 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
const express = require('express');
const {
Identity
} = require('@apillon/sdk');
const app = express();
const port = 3000;
app.use(express.json());
const validateApiKeyAndSecret = (req, res, next) => {
const apiKey = req.headers['x-api-key'];
const apiSecret = req.headers['x-api-secret'];
if (!apiKey || !apiSecret) {
return res.status(401).json({
error: 'Missing API key or secret'
});
}
req.identity = new Identity({
key: apiKey,
secret: apiSecret
});
next();
};
app.get("/", (req, res) => res.json({ message: "Welcome to My API" }));
app.post('/generate-message', validateApiKeyAndSecret, (req, res) => {
const data = `Test message from One Dionys`;
const message = req.identity.generateSigningMessage(data);
res.json({
message: message.message
});
});
app.post('/validate-signature', validateApiKeyAndSecret, (req, res) => {
const message = `Identity EVM SDK test\n1703683380574`;
const wallet = `0x65266dbf8259968f54747bc83155238370d3808a`;
const signature = `0xe576fcf2d3bbe335ec542faab8701eff263f6ad068709a32d5d714e7d9a01c82353a6639a3206376b5c3e278bb5276595b4ecd67a22da58c16f5cb1f9026478a1c`;
const {
isValid,
address
} = req.identity.validateEvmWalletSignature({
walletAddress: wallet,
message,
signature,
});
res.json({
isValid,
address
});
});
app.post('/wallet-identity', validateApiKeyAndSecret, async (req, res) => {
const walletAddress = `5HB6TahxS9KpSAq69tqjvU7VLuzKsVkCpPSPULEYixrqvn1V`;
const info = await req.identity.getWalletIdentity(walletAddress);
res.json(info);
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
module.exports = app