Skip to content
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

Merged
merged 8 commits into from
Jan 26, 2018

Conversation

kripod
Copy link
Contributor

@kripod kripod commented Jan 16, 2018

No description provided.

@dcousens dcousens requested a review from fanatid January 16, 2018 22:34
@kripod kripod changed the title Add support for negating private keys Add support for inverting and negating private keys Jan 18, 2018
@jprichardson
Copy link
Member

FYI, @fanatid is AFK for 6 more days.

@fanatid
Copy link
Member

fanatid commented Jan 20, 2018

Looks good on first view, thank you @kripod
The main question, are we need this? Or this can be useful for (from issue #124)? Originally this library is bindings for bitcoin-core/secp256k1 and that library is not export new functions.

Will review when return back, sorry for delay @kripod

@kripod
Copy link
Contributor Author

kripod commented Jan 20, 2018

Actually, I would need this functionality to implement a variant of mental poker.

while (bn.isOverflow()) {
bn.isub(BN.n)
}
}
Copy link
Member

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()
}

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in b963603

@fanatid fanatid merged commit bb5cf3a into cryptocoinjs:master Jan 26, 2018
@kripod
Copy link
Contributor Author

kripod commented Jan 26, 2018

@fanatid Thank you for merging, I would highly appreciate if you could publish a new minor release soon.

@fanatid
Copy link
Member

fanatid commented Jan 26, 2018

@kripod thank you for PR, will publish new version after CI tests for latest commit :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants