From 07b0604458352b081f64c9d305aa20164785f166 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 30 Jul 2017 17:42:35 -0700 Subject: [PATCH] lnwallet: add TweakPubKeyWithTweak helper function This commit adds a new helper function which is identical to TweakPubkey, but lets the caller specify their own hash tweak. --- lnwallet/script_utils.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lnwallet/script_utils.go b/lnwallet/script_utils.go index 6111ab9a..d0b09a4e 100644 --- a/lnwallet/script_utils.go +++ b/lnwallet/script_utils.go @@ -1005,6 +1005,20 @@ func TweakPubKey(basePoint, commitPoint *btcec.PublicKey) *btcec.PublicKey { } } +// TweakPubKeyWithTweak is the exact same as the TweakPubKey function, however +// it accepts the raw tweak bytes directly rather than the commitment point. +func TweakPubKeyWithTweak(pubKey *btcec.PublicKey, tweakBytes []byte) *btcec.PublicKey { + tweakX, tweakY := btcec.S256().ScalarBaseMult(tweakBytes) + + x, y := btcec.S256().Add(pubKey.X, pubKey.Y, tweakX, tweakY) + + return &btcec.PublicKey{ + X: x, + Y: y, + Curve: btcec.S256(), + } +} + // TweakPrivKek tweaks the private key of a public base point given a per // commitment point. The per commitment secret is the revealed revocation // secret for the commitment state in question. This private key will only need