chore: server code formatting
This commit is contained in:
parent
aedabcbdee
commit
68517170e2
234 changed files with 9824 additions and 6195 deletions
|
|
@ -3,7 +3,6 @@ const pify = require('pify')
|
|||
const readFile = pify(fs.readFile)
|
||||
const crypto = require('crypto')
|
||||
const baseX = require('base-x')
|
||||
const { parse, NIL } = require('uuid')
|
||||
|
||||
const db = require('../../db')
|
||||
const pairing = require('../../pairing')
|
||||
|
|
@ -16,19 +15,23 @@ const HOSTNAME = process.env.HOSTNAME
|
|||
|
||||
const unpair = pairing.unpair
|
||||
|
||||
function totem (name) {
|
||||
return readFile(CA_PATH)
|
||||
.then(data => {
|
||||
const caHash = crypto.createHash('sha256').update(data).digest()
|
||||
const token = crypto.randomBytes(32)
|
||||
const hexToken = token.toString('hex')
|
||||
const caHexToken = crypto.createHash('sha256').update(hexToken).digest('hex')
|
||||
const buf = Buffer.concat([caHash, token, Buffer.from(HOSTNAME)])
|
||||
const sql = 'insert into pairing_tokens (token, name) values ($1, $3), ($2, $3)'
|
||||
function totem(name) {
|
||||
return readFile(CA_PATH).then(data => {
|
||||
const caHash = crypto.createHash('sha256').update(data).digest()
|
||||
const token = crypto.randomBytes(32)
|
||||
const hexToken = token.toString('hex')
|
||||
const caHexToken = crypto
|
||||
.createHash('sha256')
|
||||
.update(hexToken)
|
||||
.digest('hex')
|
||||
const buf = Buffer.concat([caHash, token, Buffer.from(HOSTNAME)])
|
||||
const sql =
|
||||
'insert into pairing_tokens (token, name) values ($1, $3), ($2, $3)'
|
||||
|
||||
return db.none(sql, [hexToken, caHexToken, name])
|
||||
.then(() => bsAlpha.encode(buf))
|
||||
})
|
||||
return db
|
||||
.none(sql, [hexToken, caHexToken, name])
|
||||
.then(() => bsAlpha.encode(buf))
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { totem, unpair }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue