-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
64 lines (55 loc) · 1.5 KB
/
server.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
const express = require('express')
const nodemailer = require('nodemailer')
const crypto = require('crypto')
const sha256 = require('js-sha256').sha256
const { data, broadcast } = require('@waves/waves-transactions')
const app = express()
const nodeUrl = 'https://testnodes.wavesnodes.com'
const seed = ''
const randomValueHex = (len) => {
return crypto
.randomBytes(Math.ceil(len / 2))
.toString('hex')
.slice(0, len)
}
const smtpTransport = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'wavesidentitymanager@gmail.com',
pass: ''
}
})
app.get('/', (req, res) => {
res.sendFile('index.html', { root : __dirname});
})
app.get('/send', async (req, res) => {
const code = randomValueHex(6)
const codeHash = sha256(code)
const base64String = Buffer.from(codeHash, 'hex').toString('base64')
const host = req.get('host')
mailOptions = {
to : req.query.to,
subject : 'Please confirm your email',
html : 'Hello,<br>Your code: ' + code
}
smtpTransport.sendMail(mailOptions, (error, response) => {
if(error){
console.log(error)
res.json({message: 'error'});
}else{
console.log("Message sent: " + response.message)
res.json({message: 'sent'})
}
})
const params = {
data: [
{ key: req.query.to + '#hash', type: 'binary', value: 'base64:' + base64String }
],
fee: 500000
}
const signedDataTx = data(params, seed)
broadcast(signedDataTx, nodeUrl).then(resp => console.log('ok'))
})
app.listen(3000, () => {
console.log("Express Started on Port 3000");
});