hb-nb-tools 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <span align="center">
2
+
1
3
  # Homebridge NB Tools
2
4
  [![Downloads](https://img.shields.io/npm/dt/hb-nb-tools.svg)](https://www.npmjs.com/package/hb-nb-tools)
3
5
  [![Version](https://img.shields.io/npm/v/hb-nb-tools.svg)](https://www.npmjs.com/package/hb-nb-tools)
package/cli/nb.js CHANGED
@@ -8,5 +8,6 @@
8
8
  'use strict'
9
9
 
10
10
  const { NbTool } = require('../index')
11
+ const pkgJson = require('../package.json')
11
12
 
12
- new NbTool(require('../package.json')).main()
13
+ new NbTool(pkgJson).main()
package/lib/NbClient.js CHANGED
@@ -8,11 +8,7 @@
8
8
  const crypto = require('crypto')
9
9
  const hbLibTools = require('hb-lib-tools')
10
10
  const { HttpClient, JsonFormatter, OptionParser } = hbLibTools
11
- let sodiumPlus
12
- try {
13
- sodiumPlus = require('sodium-plus')
14
- } catch (error) {}
15
- const { CryptographyKey, SodiumPlus } = sodiumPlus || {}
11
+ const { secretbox, randomBytes } = require('tweetnacl')
16
12
 
17
13
  class NbClient extends HttpClient {
18
14
  static get DeviceTypes () {
@@ -106,7 +102,7 @@ class NbClient extends HttpClient {
106
102
 
107
103
  constructor (params = {}) {
108
104
  const _params = {
109
- encryption: sodiumPlus == null ? 'hashedToken' : 'encryptedToken',
105
+ encryption: 'encryptedToken',
110
106
  port: 8080,
111
107
  timeout: 5
112
108
  }
@@ -198,15 +194,15 @@ class NbClient extends HttpClient {
198
194
  const date = new Date().toISOString()
199
195
  const ts = date.slice(0, 19) + 'Z'
200
196
  if (this._params.encryption === 'encryptedToken') {
201
- if (this._sodium == null) {
197
+ if (this._key == null) {
202
198
  const hash = crypto.createHash('sha256')
203
199
  hash.update(this._params.token)
204
- this._key = new CryptographyKey(hash.digest())
205
- this._sodium = await SodiumPlus.auto()
200
+ this._key = hash.digest()
206
201
  }
207
- const rnr = await this._sodium.randombytes_uniform(10000)
208
- const nonce = await this._sodium.randombytes_buf(24)
209
- const ctoken = await this._sodium.crypto_secretbox([ts, rnr].join(','), nonce, this._key)
202
+ const rnr = crypto.randomInt(10000)
203
+ const nonce = Buffer.from(randomBytes(secretbox.nonceLength))
204
+ const message = Buffer.from([ts, rnr].join(','), 'utf-8')
205
+ const ctoken = Buffer.from(secretbox(message, nonce, this._key))
210
206
  suffix = separator + 'ctoken=' + ctoken.toString('hex') + '&nonce=' + nonce.toString('hex')
211
207
  } else if (this._params.encryption === 'hashedToken') { // deprecated
212
208
  const hash = crypto.createHash('sha256')
package/lib/NbTool.js CHANGED
@@ -9,7 +9,6 @@ const NbClient = require('./NbClient')
9
9
  const NbDiscovery = require('./NbDiscovery')
10
10
  const NbListener = require('./NbListener')
11
11
  const hbLibTools = require('hb-lib-tools')
12
- const packageJson = require('../package.json')
13
12
 
14
13
  const { CommandLineParser, CommandLineTool, JsonFormatter, OptionParser } = hbLibTools
15
14
  const { b, u } = CommandLineTool
@@ -416,7 +415,7 @@ class NbTool extends CommandLineTool {
416
415
  }
417
416
  this.name = 'nb ' + clargs.command
418
417
  this.usage = `${b('nb')} ${usage[clargs.command]}`
419
- this.parser = new CommandLineParser(packageJson)
418
+ this.parser = new CommandLineParser(this.pkgJson)
420
419
  this.parser.help('h', 'help', help[clargs.command])
421
420
  await this[clargs.command](clargs.args)
422
421
  } catch (error) {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "hb-nb-tools",
3
- "description": "Homebridge NB Command-Line Tools",
3
+ "description": "Homebridge NB Tools",
4
4
  "author": "Erik Baauw",
5
5
  "license": "Apache-2.0",
6
- "version": "1.1.0",
6
+ "version": "1.1.2",
7
7
  "keywords": [
8
8
  "nuki",
9
9
  "smart-lock",
@@ -17,10 +17,8 @@
17
17
  "node": "^18.16.0"
18
18
  },
19
19
  "dependencies": {
20
- "hb-lib-tools": "~1.0.8"
21
- },
22
- "optionalDependencies": {
23
- "sodium-plus": "~0.9.0"
20
+ "hb-lib-tools": "~1.0.9",
21
+ "tweetnacl": "~1.0.3"
24
22
  },
25
23
  "scripts": {
26
24
  "prepare": "standard",