watchtower/blob/justice_kit: conditional anchor to-remote script
This commit modifies the ToRemoteWitnessScript function to be conditioned on the blob type, and return either the legacy or anchor to-remote script. The same witness satisfies either script, so no changes are necessary to ToRemoteWitnessStack.
This commit is contained in:
parent
ffe15e2820
commit
ac2e1d7d96
@ -215,10 +215,45 @@ func testBlobJusticeKitEncryptDecrypt(t *testing.T, test descriptorTest) {
|
||||
}
|
||||
}
|
||||
|
||||
type remoteWitnessTest struct {
|
||||
name string
|
||||
blobType blob.Type
|
||||
expWitnessScript func(pk *btcec.PublicKey) []byte
|
||||
}
|
||||
|
||||
// TestJusticeKitRemoteWitnessConstruction tests that a JusticeKit returns the
|
||||
// proper to-remote witnes script and to-remote witness stack. This should be
|
||||
// equivalent to p2wkh spend.
|
||||
func TestJusticeKitRemoteWitnessConstruction(t *testing.T) {
|
||||
tests := []remoteWitnessTest{
|
||||
{
|
||||
name: "legacy commitment",
|
||||
blobType: blob.Type(blob.FlagCommitOutputs),
|
||||
expWitnessScript: func(pk *btcec.PublicKey) []byte {
|
||||
return pk.SerializeCompressed()
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "anchor commitment",
|
||||
blobType: blob.Type(blob.FlagCommitOutputs |
|
||||
blob.FlagAnchorChannel),
|
||||
expWitnessScript: func(pk *btcec.PublicKey) []byte {
|
||||
script, _ := input.CommitScriptToRemoteConfirmed(pk)
|
||||
return script
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
testJusticeKitRemoteWitnessConstruction(t, test)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testJusticeKitRemoteWitnessConstruction(
|
||||
t *testing.T, test remoteWitnessTest) {
|
||||
|
||||
// Generate the to-remote pubkey.
|
||||
toRemotePrivKey, err := btcec.NewPrivateKey(btcec.S256())
|
||||
require.Nil(t, err)
|
||||
@ -240,6 +275,7 @@ func TestJusticeKitRemoteWitnessConstruction(t *testing.T) {
|
||||
|
||||
// Populate the justice kit fields relevant to the to-remote output.
|
||||
justiceKit := &blob.JusticeKit{
|
||||
BlobType: test.blobType,
|
||||
CommitToRemotePubKey: toRemotePubKey,
|
||||
CommitToRemoteSig: commitToRemoteSig,
|
||||
}
|
||||
@ -250,7 +286,8 @@ func TestJusticeKitRemoteWitnessConstruction(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Assert this is exactly the to-remote, compressed pubkey.
|
||||
require.Equal(t, toRemoteScript, toRemotePubKey[:])
|
||||
expToRemoteScript := test.expWitnessScript(toRemotePrivKey.PubKey())
|
||||
require.Equal(t, expToRemoteScript, toRemoteScript)
|
||||
|
||||
// Next, compute the to-remote witness stack, which should be a p2wkh
|
||||
// witness stack consisting solely of a signature.
|
||||
|
Loading…
Reference in New Issue
Block a user