@@ -51,6 +51,11 @@ use crate::routing::gossip::NodeId;
5151/// 21 million * 10^8 * 1000
5252pub ( crate ) const MAX_VALUE_MSAT : u64 = 21_000_000_0000_0000_000 ;
5353
54+ #[ cfg( taproot) ]
55+ /// A partial signature that also contains the Musig2 nonce its signer used
56+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
57+ pub struct PartialSignatureWithNonce ( pub musig2:: types:: PartialSignature , pub musig2:: types:: PublicNonce ) ;
58+
5459/// An error in decoding a message or struct.
5560#[ derive( Clone , Debug , PartialEq , Eq ) ]
5661pub enum DecodeError {
@@ -244,6 +249,9 @@ pub struct AcceptChannel {
244249 /// our feature bits with our counterparty's feature bits from the [`Init`] message.
245250 /// This is required to match the equivalent field in [`OpenChannel::channel_type`].
246251 pub channel_type : Option < ChannelTypeFeatures > ,
252+ #[ cfg( taproot) ]
253+ /// Next nonce the channel initiator should use to create a funding output signature against
254+ pub next_local_nonce : Option < musig2:: types:: PublicNonce > ,
247255}
248256
249257/// A [`funding_created`] message to be sent to or received from a peer.
@@ -259,6 +267,12 @@ pub struct FundingCreated {
259267 pub funding_output_index : u16 ,
260268 /// The signature of the channel initiator (funder) on the initial commitment transaction
261269 pub signature : Signature ,
270+ #[ cfg( taproot) ]
271+ /// The partial signature of the channel initiator (funder)
272+ pub partial_signature_with_nonce : Option < PartialSignatureWithNonce > ,
273+ #[ cfg( taproot) ]
274+ /// Next nonce the channel acceptor should use to finalize the funding output signature
275+ pub next_local_nonce : Option < musig2:: types:: PublicNonce >
262276}
263277
264278/// A [`funding_signed`] message to be sent to or received from a peer.
@@ -270,6 +284,9 @@ pub struct FundingSigned {
270284 pub channel_id : [ u8 ; 32 ] ,
271285 /// The signature of the channel acceptor (fundee) on the initial commitment transaction
272286 pub signature : Signature ,
287+ #[ cfg( taproot) ]
288+ /// The partial signature of the channel acceptor (fundee)
289+ pub partial_signature_with_nonce : Option < PartialSignatureWithNonce > ,
273290}
274291
275292/// A [`channel_ready`] message to be sent to or received from a peer.
@@ -409,6 +426,9 @@ pub struct CommitmentSigned {
409426 pub signature : Signature ,
410427 /// Signatures on the HTLC transactions
411428 pub htlc_signatures : Vec < Signature > ,
429+ #[ cfg( taproot) ]
430+ /// The partial Taproot signature on the commitment transaction
431+ pub partial_signature_with_nonce : Option < PartialSignatureWithNonce > ,
412432}
413433
414434/// A [`revoke_and_ack`] message to be sent to or received from a peer.
@@ -422,6 +442,9 @@ pub struct RevokeAndACK {
422442 pub per_commitment_secret : [ u8 ; 32 ] ,
423443 /// The next sender-broadcast commitment transaction's per-commitment point
424444 pub next_per_commitment_point : PublicKey ,
445+ #[ cfg( taproot) ]
446+ /// Musig nonce the recipient should use in their next commitment signature message
447+ pub next_local_nonce : Option < musig2:: types:: PublicNonce >
425448}
426449
427450/// An [`update_fee`] message to be sent to or received from a peer
@@ -1288,7 +1311,28 @@ impl Readable for OptionalField<u64> {
12881311 }
12891312}
12901313
1314+ #[ cfg( not( taproot) ) ]
1315+ impl_writeable_msg ! ( AcceptChannel , {
1316+ temporary_channel_id,
1317+ dust_limit_satoshis,
1318+ max_htlc_value_in_flight_msat,
1319+ channel_reserve_satoshis,
1320+ htlc_minimum_msat,
1321+ minimum_depth,
1322+ to_self_delay,
1323+ max_accepted_htlcs,
1324+ funding_pubkey,
1325+ revocation_basepoint,
1326+ payment_point,
1327+ delayed_payment_basepoint,
1328+ htlc_basepoint,
1329+ first_per_commitment_point,
1330+ shutdown_scriptpubkey
1331+ } , {
1332+ ( 1 , channel_type, option) ,
1333+ } ) ;
12911334
1335+ #[ cfg( taproot) ]
12921336impl_writeable_msg ! ( AcceptChannel , {
12931337 temporary_channel_id,
12941338 dust_limit_satoshis,
@@ -1307,6 +1351,7 @@ impl_writeable_msg!(AcceptChannel, {
13071351 shutdown_scriptpubkey
13081352} , {
13091353 ( 1 , channel_type, option) ,
1354+ ( 4 , next_local_nonce, option) ,
13101355} ) ;
13111356
13121357impl_writeable_msg ! ( AnnouncementSignatures , {
@@ -1363,30 +1408,60 @@ impl_writeable!(ClosingSignedFeeRange, {
13631408 max_fee_satoshis
13641409} ) ;
13651410
1411+ #[ cfg( not( taproot) ) ]
13661412impl_writeable_msg ! ( CommitmentSigned , {
13671413 channel_id,
13681414 signature,
13691415 htlc_signatures
13701416} , { } ) ;
13711417
1418+ #[ cfg( taproot) ]
1419+ impl_writeable_msg ! ( CommitmentSigned , {
1420+ channel_id,
1421+ signature,
1422+ htlc_signatures
1423+ } , {
1424+ ( 2 , partial_signature_with_nonce, option)
1425+ } ) ;
1426+
13721427impl_writeable ! ( DecodedOnionErrorPacket , {
13731428 hmac,
13741429 failuremsg,
13751430 pad
13761431} ) ;
13771432
1433+ #[ cfg( not( taproot) ) ]
13781434impl_writeable_msg ! ( FundingCreated , {
13791435 temporary_channel_id,
13801436 funding_txid,
13811437 funding_output_index,
13821438 signature
13831439} , { } ) ;
1440+ #[ cfg( taproot) ]
1441+ impl_writeable_msg ! ( FundingCreated , {
1442+ temporary_channel_id,
1443+ funding_txid,
1444+ funding_output_index,
1445+ signature
1446+ } , {
1447+ ( 2 , partial_signature_with_nonce, option) ,
1448+ ( 4 , next_local_nonce, option)
1449+ } ) ;
13841450
1451+ #[ cfg( not( taproot) ) ]
13851452impl_writeable_msg ! ( FundingSigned , {
13861453 channel_id,
13871454 signature
13881455} , { } ) ;
13891456
1457+ #[ cfg( taproot) ]
1458+ impl_writeable_msg ! ( FundingSigned , {
1459+ channel_id,
1460+ signature
1461+ } , {
1462+ ( 2 , partial_signature_with_nonce, option)
1463+ } ) ;
1464+
13901465impl_writeable_msg ! ( ChannelReady , {
13911466 channel_id,
13921467 next_per_commitment_point,
@@ -1446,12 +1521,22 @@ impl_writeable_msg!(OpenChannel, {
14461521 ( 1 , channel_type, option) ,
14471522} ) ;
14481523
1524+ #[ cfg( not( taproot) ) ]
14491525impl_writeable_msg ! ( RevokeAndACK , {
14501526 channel_id,
14511527 per_commitment_secret,
14521528 next_per_commitment_point
14531529} , { } ) ;
14541530
1531+ #[ cfg( taproot) ]
1532+ impl_writeable_msg ! ( RevokeAndACK , {
1533+ channel_id,
1534+ per_commitment_secret,
1535+ next_per_commitment_point
1536+ } , {
1537+ ( 4 , next_local_nonce, option)
1538+ } ) ;
1539+
14551540impl_writeable_msg ! ( Shutdown , {
14561541 channel_id,
14571542 scriptpubkey
@@ -2444,6 +2529,8 @@ mod tests {
24442529 first_per_commitment_point : pubkey_6,
24452530 shutdown_scriptpubkey : if shutdown { OptionalField :: Present ( Address :: p2pkh ( & :: bitcoin:: PublicKey { compressed : true , inner : pubkey_1} , Network :: Testnet ) . script_pubkey ( ) ) } else { OptionalField :: Absent } ,
24462531 channel_type : None ,
2532+ #[ cfg( taproot) ]
2533+ next_local_nonce : None ,
24472534 } ;
24482535 let encoded_value = accept_channel. encode ( ) ;
24492536 let mut target_value = hex:: decode ( "020202020202020202020202020202020202020202020202020202020202020212345678901234562334032891223698321446687011447600083a840000034d000c89d4c0bcc0bc031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a" ) . unwrap ( ) ;
@@ -2469,6 +2556,10 @@ mod tests {
24692556 funding_txid : Txid :: from_hex ( "c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e" ) . unwrap ( ) ,
24702557 funding_output_index : 255 ,
24712558 signature : sig_1,
2559+ #[ cfg( taproot) ]
2560+ partial_signature_with_nonce : None ,
2561+ #[ cfg( taproot) ]
2562+ next_local_nonce : None ,
24722563 } ;
24732564 let encoded_value = funding_created. encode ( ) ;
24742565 let target_value = hex:: decode ( "02020202020202020202020202020202020202020202020202020202020202026e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c200ffd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a" ) . unwrap ( ) ;
@@ -2483,6 +2574,8 @@ mod tests {
24832574 let funding_signed = msgs:: FundingSigned {
24842575 channel_id : [ 2 ; 32 ] ,
24852576 signature : sig_1,
2577+ #[ cfg( taproot) ]
2578+ partial_signature_with_nonce : None ,
24862579 } ;
24872580 let encoded_value = funding_signed. encode ( ) ;
24882581 let target_value = hex:: decode ( "0202020202020202020202020202020202020202020202020202020202020202d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a" ) . unwrap ( ) ;
@@ -2646,6 +2739,8 @@ mod tests {
26462739 channel_id : [ 2 ; 32 ] ,
26472740 signature : sig_1,
26482741 htlc_signatures : if htlcs { vec ! [ sig_2, sig_3, sig_4] } else { Vec :: new ( ) } ,
2742+ #[ cfg( taproot) ]
2743+ partial_signature_with_nonce : None ,
26492744 } ;
26502745 let encoded_value = commitment_signed. encode ( ) ;
26512746 let mut target_value = hex:: decode ( "0202020202020202020202020202020202020202020202020202020202020202d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a" ) . unwrap ( ) ;
@@ -2671,6 +2766,8 @@ mod tests {
26712766 channel_id : [ 2 ; 32 ] ,
26722767 per_commitment_secret : [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ,
26732768 next_per_commitment_point : pubkey_1,
2769+ #[ cfg( taproot) ]
2770+ next_local_nonce : None ,
26742771 } ;
26752772 let encoded_value = raa. encode ( ) ;
26762773 let target_value = hex:: decode ( "02020202020202020202020202020202020202020202020202020202020202020101010101010101010101010101010101010101010101010101010101010101031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f" ) . unwrap ( ) ;
0 commit comments