move some pair stuff to lamassu-admin-server

This commit is contained in:
Josh Harvey 2016-10-21 18:17:49 +03:00
parent 6422c36644
commit 99cd1b72c6
2 changed files with 11 additions and 27 deletions

View file

@ -1,26 +1,6 @@
const fs = require('fs')
const pify = require('pify')
const readFile = pify(fs.readFile)
const path = require('path')
const crypto = require('crypto')
const db = require('./db')
const CA_PATH = path.resolve(__dirname, '..', 'ca-cert.pem')
function totem (ipAddress) {
return readFile(CA_PATH)
.then(data => {
const caHash = crypto.createHash('sha256').update(data).digest()
const token = crypto.randomBytes(32)
const ip = Buffer.from(ipAddress.split('.').map(s => parseInt(s, 10)))
const buf = Buffer.concat([ip, caHash, token])
const sql = 'insert into pairing_tokens (token) values ($1)'
return db.none(sql, [token.toString('hex')])
.then(() => buf.toString('base64'))
})
}
function pair (token, deviceId) {
const sql = `delete from pairing_tokens
where token=$1
@ -42,4 +22,4 @@ function isPaired (deviceId) {
.then(() => true)
}
module.exports = {totem, pair, isPaired}
module.exports = {totem, pair, unpair, isPaired}