From a4eb9c64d057f17a65eb6869afb67b1f400e8dba Mon Sep 17 00:00:00 2001 From: Michael Stegeman Date: Wed, 22 Apr 2020 12:29:25 -0800 Subject: [PATCH] Update fast-srp-hap dependency. --- lib/protocol/pairing-protocol.js | 34 ++++++++++++++------------------ package.json | 4 ++-- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/protocol/pairing-protocol.js b/lib/protocol/pairing-protocol.js index 1cd1a48..509a256 100644 --- a/lib/protocol/pairing-protocol.js +++ b/lib/protocol/pairing-protocol.js @@ -6,7 +6,7 @@ const HKDF = require('hkdf'); const TLV = require('../model/tlv'); const sodium = require('libsodium-wrappers'); -const srp = require('fast-srp-hap'); +const {SRP, SrpClient} = require('fast-srp-hap'); const {v4: uuidv4} = require('uuid'); const Steps = { @@ -211,25 +211,21 @@ class PairingProtocol { * @returns {Promise} Promise which resolves to a Buffer. */ buildPairSetupM3(m2Tlv, pin) { - return new Promise((resolve) => { - srp.genKey(32, (err, key) => { - this.srpClient = new srp.Client( - srp.params['3072'], - m2Tlv.get(Types.kTLVType_Salt), - Buffer.from('Pair-Setup'), - Buffer.from(pin), - key - ); - this.srpClient.setB(m2Tlv.get(Types.kTLVType_PublicKey)); - - const data = new Map(); - data.set(Types.kTLVType_State, Buffer.from([Steps.M3])); - data.set(Types.kTLVType_PublicKey, this.srpClient.computeA()); - data.set(Types.kTLVType_Proof, this.srpClient.computeM1()); - const packet = TLV.encodeObject(data); + return SRP.genKey(32).then((key) => { + this.srpClient = new SrpClient( + SRP.params['3072'], + m2Tlv.get(Types.kTLVType_Salt), + Buffer.from('Pair-Setup'), + Buffer.from(pin), + key + ); + this.srpClient.setB(m2Tlv.get(Types.kTLVType_PublicKey)); - resolve(packet); - }); + const data = new Map(); + data.set(Types.kTLVType_State, Buffer.from([Steps.M3])); + data.set(Types.kTLVType_PublicKey, this.srpClient.computeA()); + data.set(Types.kTLVType_Proof, this.srpClient.computeM1()); + return TLV.encodeObject(data); }); } diff --git a/package.json b/package.json index d38d60c..46fb2f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hap-controller", - "version": "0.3.3", + "version": "0.3.4", "description": "Library to implement a HAP (HomeKit) controller", "main": "lib/index.js", "directories": { @@ -28,7 +28,7 @@ "dependencies": { "@abandonware/noble": "^1.9.2-8", "dnssd": "^0.4.1", - "fast-srp-hap": "^1.0.1", + "fast-srp-hap": "^2.0.2", "hkdf": "0.0.2", "http-parser-js": "^0.5.2", "libsodium-wrappers": "^0.7.6",