diff --git a/lib/connect.js b/lib/connect.js index f1963ddc..aabce97e 100644 --- a/lib/connect.js +++ b/lib/connect.js @@ -63,7 +63,7 @@ module.exports = function connect (dht, publicKey, opts = {}) { relayAddresses: opts.relayAddresses || [], pool, round: 0, - target: hash(publicKey), + target: hash(publicKey, b4a.allocUnsafeSlow), remotePublicKey: publicKey, reusableSocket: !!opts.reusableSocket, handshake: (opts.createHandshake || defaultCreateHandshake)(keyPair, publicKey), diff --git a/lib/crypto.js b/lib/crypto.js index 81fc4f49..5233d372 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -1,8 +1,8 @@ const sodium = require('sodium-universal') const b4a = require('b4a') -function hash (data) { - const out = b4a.allocUnsafe(32) +function hash (data, alloc = b4a.allocUnsafe) { + const out = alloc(32) sodium.crypto_generichash(out, data) return out } diff --git a/lib/server.js b/lib/server.js index e2cb8f96..13b4ef7f 100644 --- a/lib/server.js +++ b/lib/server.js @@ -164,7 +164,7 @@ module.exports = class Server extends EventEmitter { await this.dht.bind() if (this._closing) return - this.target = hash(keyPair.publicKey) + this.target = hash(keyPair.publicKey, b4a.allocUnsafeSlow) this._keyPair = keyPair this._announcer = new Announcer(this.dht, keyPair, this.target, opts)