From 016f56e8e3e6c9c19419102205bf6ec158dc75b6 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 29 Jul 2017 18:35:47 -0700 Subject: [PATCH] lnwallet: update TestRevocationKeyDerivation to use new derivation --- lnwallet/script_utils_test.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lnwallet/script_utils_test.go b/lnwallet/script_utils_test.go index f19970b0..40f6bd21 100644 --- a/lnwallet/script_utils_test.go +++ b/lnwallet/script_utils_test.go @@ -185,24 +185,28 @@ func TestCommitmentSpendValidation(t *testing.T) { func TestRevocationKeyDerivation(t *testing.T) { t.Parallel() - revocationPreimage := testHdSeed[:] + // First, we'll generate a commitment point, and a commitment secret. + // These will be used to derive the ultimate revocation keys. + revocationPreimage := testHdSeed.CloneBytes() + commitSecret, commitPoint := btcec.PrivKeyFromBytes(btcec.S256(), + revocationPreimage) - priv, pub := btcec.PrivKeyFromBytes(btcec.S256(), testWalletPrivKey) + // With the commitment secrets generated, we'll now create the base + // keys we'll use to derive the revocation key from. + basePriv, basePub := btcec.PrivKeyFromBytes(btcec.S256(), + testWalletPrivKey) - revocationPub := DeriveRevocationPubkey(pub, revocationPreimage) + // With the point and key obtained, we can now derive the revocation + // key itself. + revocationPub := DeriveRevocationPubkey(basePub, commitPoint) - revocationPriv := DeriveRevocationPrivKey(priv, revocationPreimage) - x, y := btcec.S256().ScalarBaseMult(revocationPriv.D.Bytes()) - derivedRevPub := &btcec.PublicKey{ - Curve: btcec.S256(), - X: x, - Y: y, + // The revocation public key derived from the original public key, and + // the one derived from the private key should be identical. + revocationPriv := DeriveRevocationPrivKey(basePriv, commitSecret) + if !revocationPub.IsEqual(revocationPriv.PubKey()) { + t.Fatalf("derived public keys don't match!") } - // The the revocation public key derived from the original public key, - // and the one derived from the private key should be identical. - if !revocationPub.IsEqual(derivedRevPub) { - t.Fatalf("derived public keys don't match!") // TestTweakKeyDerivation tests that given a public key, and commitment tweak, // then we're able to properly derive a tweaked private key that corresponds to // the computed tweak public key. This scenario ensure that our key derivation