hb-nb-tools 1.1.13 → 2.0.0-1
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/cli/nb.js +2 -5
- package/lib/NbClient.js +12 -8
- package/lib/NbDiscovery.js +3 -5
- package/lib/NbListener.js +8 -8
- package/lib/NbTool.js +8 -7
- package/package.json +6 -2
- package/index.js +0 -38
package/cli/nb.js
CHANGED
|
@@ -5,9 +5,6 @@
|
|
|
5
5
|
// Command line interface to Nuki bridge HTTP API.
|
|
6
6
|
// Copyright © 2018-2024 Erik Baauw. All rights reserved.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import { NbTool } from 'hb-nb-tools/NbTool'
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
const pkgJson = require('../package.json')
|
|
12
|
-
|
|
13
|
-
new NbTool(pkgJson).main()
|
|
10
|
+
new NbTool(import.meta.dirname).main()
|
package/lib/NbClient.js
CHANGED
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Homebridge NB Tools.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import { createHash, randomInt } from 'node:crypto'
|
|
7
|
+
import tweetnacl from 'tweetnacl'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import { toHexString } from 'hb-lib-tools'
|
|
10
|
+
import { HttpClient } from 'hb-lib-tools/HttpClient'
|
|
11
|
+
import { JsonFormatter } from 'hb-lib-tools/JsonFormatter'
|
|
12
|
+
import { OptionParser } from 'hb-lib-tools/OptionParser'
|
|
13
|
+
|
|
14
|
+
const { secretbox, randomBytes } = tweetnacl
|
|
11
15
|
|
|
12
16
|
class NbClient extends HttpClient {
|
|
13
17
|
static get DeviceTypes () {
|
|
@@ -191,17 +195,17 @@ class NbClient extends HttpClient {
|
|
|
191
195
|
const ts = date.slice(0, 19) + 'Z'
|
|
192
196
|
if (this._params.encryption === 'encryptedToken') {
|
|
193
197
|
if (this._key == null) {
|
|
194
|
-
const hash =
|
|
198
|
+
const hash = createHash('sha256')
|
|
195
199
|
hash.update(this._params.token)
|
|
196
200
|
this._key = hash.digest()
|
|
197
201
|
}
|
|
198
|
-
const rnr =
|
|
202
|
+
const rnr = randomInt(10000)
|
|
199
203
|
const nonce = Buffer.from(randomBytes(secretbox.nonceLength))
|
|
200
204
|
const message = Buffer.from([ts, rnr].join(','), 'utf-8')
|
|
201
205
|
const ctoken = Buffer.from(secretbox(message, nonce, this._key))
|
|
202
206
|
suffix = separator + 'ctoken=' + ctoken.toString('hex') + '&nonce=' + nonce.toString('hex')
|
|
203
207
|
} else if (this._params.encryption === 'hashedToken') { // deprecated
|
|
204
|
-
const hash =
|
|
208
|
+
const hash = createHash('sha256')
|
|
205
209
|
const rnr = Number(date[18] + date.slice(20, 23))
|
|
206
210
|
hash.update([ts, rnr, this._params.token].join(','))
|
|
207
211
|
suffix = separator + 'ts=' + ts + '&rnr=' + rnr +
|
|
@@ -213,4 +217,4 @@ class NbClient extends HttpClient {
|
|
|
213
217
|
}
|
|
214
218
|
}
|
|
215
219
|
|
|
216
|
-
|
|
220
|
+
export { NbClient }
|
package/lib/NbDiscovery.js
CHANGED
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Homebridge NB Tools.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const hbLibTools = require('hb-lib-tools')
|
|
9
|
-
const { HttpClient, OptionParser } = hbLibTools
|
|
6
|
+
import { HttpClient } from 'hb-lib-tools/HttpClient'
|
|
7
|
+
import { OptionParser } from 'hb-lib-tools/OptionParser'
|
|
10
8
|
|
|
11
9
|
class NbDiscovery extends HttpClient {
|
|
12
10
|
constructor (params = {}) {
|
|
@@ -54,4 +52,4 @@ class NbDiscovery extends HttpClient {
|
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
|
|
55
|
+
export { NbDiscovery }
|
package/lib/NbListener.js
CHANGED
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Homebridge NB Tools.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import { EventEmitter } from 'node:events'
|
|
7
|
+
import { createServer } from 'node:http'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
const http = require('http')
|
|
10
|
-
const NbClient = require('./NbClient')
|
|
11
|
-
const { OptionParser } = require('hb-lib-tools')
|
|
9
|
+
import { OptionParser } from 'hb-lib-tools/OptionParser'
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
import { NbClient } from 'hb-nb-tools/NbClient'
|
|
12
|
+
|
|
13
|
+
class NbListener extends EventEmitter {
|
|
14
14
|
constructor (port = 0) {
|
|
15
15
|
super()
|
|
16
16
|
this._myPort = port
|
|
17
17
|
this._clients = {}
|
|
18
18
|
this._clientsByName = {}
|
|
19
|
-
this._server =
|
|
19
|
+
this._server = createServer((request, response) => {
|
|
20
20
|
let buffer = ''
|
|
21
21
|
request.on('data', (data) => {
|
|
22
22
|
buffer += data
|
|
@@ -106,4 +106,4 @@ class NbListener extends events.EventEmitter {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
export { NbListener }
|
package/lib/NbTool.js
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Command line interface to Nuki bridge HTTP API.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import { CommandLineParser } from 'hb-lib-tools/CommandLineParser'
|
|
7
|
+
import { CommandLineTool } from 'hb-lib-tools/CommandLineTool'
|
|
8
|
+
import { JsonFormatter } from 'hb-lib-tools/JsonFormatter'
|
|
9
|
+
import { OptionParser } from 'hb-lib-tools/OptionParser'
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const hbLibTools = require('hb-lib-tools')
|
|
11
|
+
import { NbClient } from 'hb-nb-tools/NbClient'
|
|
12
|
+
import { NbDiscovery } from 'hb-nb-tools/NbDiscovery'
|
|
13
|
+
import { NbListener } from 'hb-nb-tools/NbListener'
|
|
12
14
|
|
|
13
|
-
const { CommandLineParser, CommandLineTool, JsonFormatter, OptionParser } = hbLibTools
|
|
14
15
|
const { b, u } = CommandLineTool
|
|
15
16
|
const { UsageError } = CommandLineParser
|
|
16
17
|
|
|
@@ -641,4 +642,4 @@ class NbTool extends CommandLineTool {
|
|
|
641
642
|
}
|
|
642
643
|
}
|
|
643
644
|
|
|
644
|
-
|
|
645
|
+
export { NbTool }
|
package/package.json
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
"description": "Homebridge NB Tools",
|
|
4
4
|
"author": "Erik Baauw",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "2.0.0-1",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./*": "./lib/*.js"
|
|
10
|
+
},
|
|
7
11
|
"keywords": [
|
|
8
12
|
"nuki",
|
|
9
13
|
"smart-lock",
|
|
@@ -17,7 +21,7 @@
|
|
|
17
21
|
"node": "^20||^18"
|
|
18
22
|
},
|
|
19
23
|
"dependencies": {
|
|
20
|
-
"hb-lib-tools": "~
|
|
24
|
+
"hb-lib-tools": "~2.0.0-1",
|
|
21
25
|
"tweetnacl": "~1.0.3"
|
|
22
26
|
},
|
|
23
27
|
"scripts": {
|
package/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// hb-nb-tools/index.js
|
|
2
|
-
//
|
|
3
|
-
// Homebridge NB Tools.
|
|
4
|
-
// Copyright © 2017-2024 Erik Baauw. All rights reserved.
|
|
5
|
-
|
|
6
|
-
'use strict'
|
|
7
|
-
|
|
8
|
-
/** Homebridge NB Tools.
|
|
9
|
-
*
|
|
10
|
-
* @module hbNbTools
|
|
11
|
-
*/
|
|
12
|
-
class hbNbTools {
|
|
13
|
-
/** Colour conversions.
|
|
14
|
-
* <br>See {@link NbClient}.
|
|
15
|
-
* @type {Class}
|
|
16
|
-
* @memberof module:hbNbTools
|
|
17
|
-
*/
|
|
18
|
-
static get NbClient () { return require('./lib/NbClient') }
|
|
19
|
-
|
|
20
|
-
/** Parser and validator for command-line arguments.
|
|
21
|
-
* <br>See {@link NbDiscovery}.
|
|
22
|
-
* @type {Class}
|
|
23
|
-
* @memberof module:hbNbTools
|
|
24
|
-
*/
|
|
25
|
-
static get NbDiscovery () { return require('./lib/NbDiscovery') }
|
|
26
|
-
|
|
27
|
-
/** Command-line tool.
|
|
28
|
-
* <br>See {@link NbListener}.
|
|
29
|
-
* @type {Class}
|
|
30
|
-
* @memberof module:hbNbTools
|
|
31
|
-
*/
|
|
32
|
-
static get NbListener () { return require('./lib/NbListener') }
|
|
33
|
-
|
|
34
|
-
// Command-line tools.
|
|
35
|
-
static get NbTool () { return require('./lib/NbTool') }
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = hbNbTools
|