Skip to content

Commit

Permalink
Make signing payment requests faster (#1754)
Browse files Browse the repository at this point in the history
* Make signing payment requests faster

There was a much more efficient method to compute the pukey recovery id that was not used.
  • Loading branch information
sstone authored Apr 2, 2021
1 parent b25e552 commit 1321761
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ case class PaymentRequest(prefix: String, amount: Option[MilliSatoshi], timestam
*/
def sign(priv: PrivateKey): PaymentRequest = {
val sig64 = Crypto.sign(hash, priv)
val (pub1, _) = Crypto.recoverPublicKey(sig64, hash)
val recid = if (nodeId == pub1) 0.toByte else 1.toByte
// in order to tell what the recovery id is, we actually recover the pubkey ourselves and compare it to the real one
val pub0 = Crypto.recoverPublicKey(sig64, hash, 0.toByte)
val recid = if (nodeId == pub0) 0.toByte else 1.toByte
val signature = sig64 :+ recid
this.copy(signature = signature)
}
Expand Down Expand Up @@ -574,4 +575,3 @@ object PaymentRequest {
Bech32.encode(hrp, int5s.toArray)
}
}

0 comments on commit 1321761

Please sign in to comment.