Skip to content

Commit b963603

Browse files
committed
Remove useless while loop in privateKeyNegate
1 parent bb5cf3a commit b963603

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

lib/js/index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,9 @@ exports.privateKeyExport = function (privateKey, compressed) {
2121

2222
exports.privateKeyNegate = function (privateKey) {
2323
var bn = BN.fromBuffer(privateKey)
24+
if (bn.isZero()) return Buffer.alloc(32)
2425

25-
if (bn.isZero()) {
26-
return Buffer.alloc(32)
27-
}
28-
29-
if (bn.ucmp(BN.n) !== 0) {
30-
while (bn.isOverflow()) {
31-
bn.isub(BN.n)
32-
}
33-
}
34-
26+
if (bn.ucmp(BN.n) > 0) bn.isub(BN.n)
3527
return BN.n.sub(bn).toBuffer()
3628
}
3729

0 commit comments

Comments
 (0)