|
|
@ -313,21 +313,32 @@ func SenderHtlcSpendRevokeWithKey(signer Signer, signDesc *SignDescriptor, |
|
|
|
func SenderHtlcSpendRevoke(signer Signer, signDesc *SignDescriptor, |
|
|
|
func SenderHtlcSpendRevoke(signer Signer, signDesc *SignDescriptor, |
|
|
|
sweepTx *wire.MsgTx) (wire.TxWitness, error) { |
|
|
|
sweepTx *wire.MsgTx) (wire.TxWitness, error) { |
|
|
|
|
|
|
|
|
|
|
|
if signDesc.KeyDesc.PubKey == nil { |
|
|
|
revokeKey, err := deriveRevokePubKey(signDesc) |
|
|
|
return nil, fmt.Errorf("cannot generate witness with nil " + |
|
|
|
if err != nil { |
|
|
|
"KeyDesc pubkey") |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Derive the revocation key using the local revocation base point and
|
|
|
|
|
|
|
|
// commitment point.
|
|
|
|
|
|
|
|
revokeKey := DeriveRevocationPubkey( |
|
|
|
|
|
|
|
signDesc.KeyDesc.PubKey, |
|
|
|
|
|
|
|
signDesc.DoubleTweak.PubKey(), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return SenderHtlcSpendRevokeWithKey(signer, signDesc, revokeKey, sweepTx) |
|
|
|
return SenderHtlcSpendRevokeWithKey(signer, signDesc, revokeKey, sweepTx) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IsHtlcSpendRevoke is used to determine if the passed spend is spending a
|
|
|
|
|
|
|
|
// HTLC output using the revocation key.
|
|
|
|
|
|
|
|
func IsHtlcSpendRevoke(txIn *wire.TxIn, signDesc *SignDescriptor) ( |
|
|
|
|
|
|
|
bool, error) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
revokeKey, err := deriveRevokePubKey(signDesc) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return false, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(txIn.Witness) == 3 && |
|
|
|
|
|
|
|
bytes.Equal(txIn.Witness[1], revokeKey.SerializeCompressed()) { |
|
|
|
|
|
|
|
return true, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SenderHtlcSpendRedeem constructs a valid witness allowing the receiver of an
|
|
|
|
// SenderHtlcSpendRedeem constructs a valid witness allowing the receiver of an
|
|
|
|
// HTLC to redeem the pending output in the scenario that the sender broadcasts
|
|
|
|
// HTLC to redeem the pending output in the scenario that the sender broadcasts
|
|
|
|
// their version of the commitment transaction. A valid spend requires
|
|
|
|
// their version of the commitment transaction. A valid spend requires
|
|
|
@ -575,16 +586,7 @@ func ReceiverHtlcSpendRevokeWithKey(signer Signer, signDesc *SignDescriptor, |
|
|
|
return witnessStack, nil |
|
|
|
return witnessStack, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ReceiverHtlcSpendRevoke constructs a valid witness allowing the sender of an
|
|
|
|
func deriveRevokePubKey(signDesc *SignDescriptor) (*btcec.PublicKey, error) { |
|
|
|
// HTLC within a previously revoked commitment transaction to re-claim the
|
|
|
|
|
|
|
|
// pending funds in the case that the receiver broadcasts this revoked
|
|
|
|
|
|
|
|
// commitment transaction. This method first derives the appropriate revocation
|
|
|
|
|
|
|
|
// key, and requires that the provided SignDescriptor has a local revocation
|
|
|
|
|
|
|
|
// basepoint and commitment secret in the PubKey and DoubleTweak fields,
|
|
|
|
|
|
|
|
// respectively.
|
|
|
|
|
|
|
|
func ReceiverHtlcSpendRevoke(signer Signer, signDesc *SignDescriptor, |
|
|
|
|
|
|
|
sweepTx *wire.MsgTx) (wire.TxWitness, error) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if signDesc.KeyDesc.PubKey == nil { |
|
|
|
if signDesc.KeyDesc.PubKey == nil { |
|
|
|
return nil, fmt.Errorf("cannot generate witness with nil " + |
|
|
|
return nil, fmt.Errorf("cannot generate witness with nil " + |
|
|
|
"KeyDesc pubkey") |
|
|
|
"KeyDesc pubkey") |
|
|
@ -597,6 +599,24 @@ func ReceiverHtlcSpendRevoke(signer Signer, signDesc *SignDescriptor, |
|
|
|
signDesc.DoubleTweak.PubKey(), |
|
|
|
signDesc.DoubleTweak.PubKey(), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return revokeKey, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ReceiverHtlcSpendRevoke constructs a valid witness allowing the sender of an
|
|
|
|
|
|
|
|
// HTLC within a previously revoked commitment transaction to re-claim the
|
|
|
|
|
|
|
|
// pending funds in the case that the receiver broadcasts this revoked
|
|
|
|
|
|
|
|
// commitment transaction. This method first derives the appropriate revocation
|
|
|
|
|
|
|
|
// key, and requires that the provided SignDescriptor has a local revocation
|
|
|
|
|
|
|
|
// basepoint and commitment secret in the PubKey and DoubleTweak fields,
|
|
|
|
|
|
|
|
// respectively.
|
|
|
|
|
|
|
|
func ReceiverHtlcSpendRevoke(signer Signer, signDesc *SignDescriptor, |
|
|
|
|
|
|
|
sweepTx *wire.MsgTx) (wire.TxWitness, error) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
revokeKey, err := deriveRevokePubKey(signDesc) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ReceiverHtlcSpendRevokeWithKey(signer, signDesc, revokeKey, sweepTx) |
|
|
|
return ReceiverHtlcSpendRevokeWithKey(signer, signDesc, revokeKey, sweepTx) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|