From 17f8fb31402cd1d5824370fb28e60f52afdf9fa4 Mon Sep 17 00:00:00 2001 From: Matija Petrunic Date: Tue, 7 Apr 2020 14:43:25 +0200 Subject: [PATCH] Avoid allocating new buffer --- src/handshakes/abstract-handshake.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handshakes/abstract-handshake.ts b/src/handshakes/abstract-handshake.ts index feb0a6d..6845d18 100644 --- a/src/handshakes/abstract-handshake.ts +++ b/src/handshakes/abstract-handshake.ts @@ -107,7 +107,7 @@ export abstract class AbstractHandshake { protected dh(privateKey: bytes32, publicKey: bytes32): bytes32 { try { const sharedKey = box.before(publicKey, privateKey) - return Buffer.from(sharedKey); + return Buffer.from(sharedKey.buffer, sharedKey.byteOffset, sharedKey.length); } catch (e) { logger(e.message); return Buffer.alloc(32);