feat: support older machine versions

This commit is contained in:
André Sá 2022-02-08 18:21:02 +00:00
parent e1751c8576
commit 48973f442e

View file

@ -1,3 +1,4 @@
const _ = require('lodash/fp')
const fs = require('fs')
const pify = require('pify')
const readFile = pify(fs.readFile)
@ -14,15 +15,19 @@ const bsAlpha = baseX(ALPHA_BASE)
const unpair = pairing.unpair
function totem (name) {
const caPath = options.caPath
const cleanNil = [...parse(NIL)].map(it => it.toString(16).padStart(2, '0')).join('')
const nilBuffer = Buffer.from(cleanNil, 'hex')
function totem (name, operatorId = null) {
const operatorBuffer = _.flow(
_.map(it => it.toString(16).padStart(2, '0')),
_.join(''),
op => Buffer.from(op, 'hex')
)(operatorId ? [...parse(operatorId)] : [])
const caPath = options.caPath
return readFile(caPath)
.then(data => {
const caHash = crypto.createHash('sha256').update(data).digest()
const token = Buffer.concat([crypto.randomBytes(32), nilBuffer])
const token = Buffer.concat([crypto.randomBytes(32), operatorBuffer])
const hexToken = token.toString('hex')
const caHexToken = crypto.createHash('sha256').update(hexToken).digest('hex')
const buf = Buffer.concat([caHash, token, Buffer.from(options.hostname)])