From 29316a2fbce8c869e43260a45006b66e0d1d99bd Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 28 Mar 2017 20:26:59 +1100 Subject: [PATCH] block: use writeUInt32BE for target calculation --- src/block.js | 7 +------ test/integration/stealth.js | 3 ++- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/block.js b/src/block.js index f1d8b67..66aafbc 100644 --- a/src/block.js +++ b/src/block.js @@ -135,12 +135,7 @@ Block.calculateTarget = function (bits) { var target = new Buffer(32) target.fill(0) - - target[i] = mantissa & 0xff - target[i - 1] = mantissa >> 8 - target[i - 2] = mantissa >> 16 - target[i - 3] = mantissa >> 24 - + target.writeUInt32BE(mantissa, i - 3) return target } diff --git a/test/integration/stealth.js b/test/integration/stealth.js index f06f7de..0eabac1 100644 --- a/test/integration/stealth.js +++ b/test/integration/stealth.js @@ -51,7 +51,8 @@ function stealthDualSend (e, R, Q) { function stealthDualScan (d, R, eG) { var eQ = eG.multiply(d) // shared secret var c = bigi.fromBuffer(bitcoin.crypto.sha256(eQ.getEncoded())) - var vG = new bitcoin.ECPair(null, R.add(G.multiply(c))) + var cG = G.multiply(c) + var vG = new bitcoin.ECPair(null, R.add(cG)) return vG }