-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for inverting and negating private keys #125
Conversation
FYI, @fanatid is AFK for 6 more days. |
Looks good on first view, thank you @kripod Will review when return back, sorry for delay @kripod |
Actually, I would need this functionality to implement a variant of mental poker. |
while (bn.isOverflow()) { | ||
bn.isub(BN.n) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need while
loop here? Loop body will be executed 1 time at max..
exports.privateKeyNegate = function (privateKey) {
var bn = BN.fromBuffer(privateKey)
if (bn.isZero()) return Buffer.alloc(32)
if (bn.ucmp(BN.n) > 0) bn.isub(BN.n)
return BN.n.sub(bn).toBuffer()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, the while
statement can be changed to an if
statement, and the condition can be concatenated with the previous if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in b963603
@fanatid Thank you for merging, I would highly appreciate if you could publish a new minor release soon. |
@kripod thank you for PR, will publish new version after CI tests for latest commit :) |
No description provided.