@@ -51,6 +51,11 @@ use crate::routing::gossip::NodeId;
51
51
/// 21 million * 10^8 * 1000
52
52
pub ( crate ) const MAX_VALUE_MSAT : u64 = 21_000_000_0000_0000_000 ;
53
53
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
+
54
59
/// An error in decoding a message or struct.
55
60
#[ derive( Clone , Debug , PartialEq , Eq ) ]
56
61
pub enum DecodeError {
@@ -244,6 +249,9 @@ pub struct AcceptChannel {
244
249
/// our feature bits with our counterparty's feature bits from the [`Init`] message.
245
250
/// This is required to match the equivalent field in [`OpenChannel::channel_type`].
246
251
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 > ,
247
255
}
248
256
249
257
/// A [`funding_created`] message to be sent to or received from a peer.
@@ -259,6 +267,12 @@ pub struct FundingCreated {
259
267
pub funding_output_index : u16 ,
260
268
/// The signature of the channel initiator (funder) on the initial commitment transaction
261
269
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 >
262
276
}
263
277
264
278
/// A [`funding_signed`] message to be sent to or received from a peer.
@@ -270,6 +284,9 @@ pub struct FundingSigned {
270
284
pub channel_id : [ u8 ; 32 ] ,
271
285
/// The signature of the channel acceptor (fundee) on the initial commitment transaction
272
286
pub signature : Signature ,
287
+ #[ cfg( taproot) ]
288
+ /// The partial signature of the channel acceptor (fundee)
289
+ pub partial_signature_with_nonce : Option < PartialSignatureWithNonce > ,
273
290
}
274
291
275
292
/// A [`channel_ready`] message to be sent to or received from a peer.
@@ -409,6 +426,9 @@ pub struct CommitmentSigned {
409
426
pub signature : Signature ,
410
427
/// Signatures on the HTLC transactions
411
428
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 > ,
412
432
}
413
433
414
434
/// A [`revoke_and_ack`] message to be sent to or received from a peer.
@@ -422,6 +442,9 @@ pub struct RevokeAndACK {
422
442
pub per_commitment_secret : [ u8 ; 32 ] ,
423
443
/// The next sender-broadcast commitment transaction's per-commitment point
424
444
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 >
425
448
}
426
449
427
450
/// An [`update_fee`] message to be sent to or received from a peer
@@ -1288,7 +1311,28 @@ impl Readable for OptionalField<u64> {
1288
1311
}
1289
1312
}
1290
1313
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
+ } ) ;
1291
1334
1335
+ #[ cfg( taproot) ]
1292
1336
impl_writeable_msg ! ( AcceptChannel , {
1293
1337
temporary_channel_id,
1294
1338
dust_limit_satoshis,
@@ -1307,6 +1351,7 @@ impl_writeable_msg!(AcceptChannel, {
1307
1351
shutdown_scriptpubkey
1308
1352
} , {
1309
1353
( 1 , channel_type, option) ,
1354
+ ( 4 , next_local_nonce, option) ,
1310
1355
} ) ;
1311
1356
1312
1357
impl_writeable_msg ! ( AnnouncementSignatures , {
@@ -1363,30 +1408,60 @@ impl_writeable!(ClosingSignedFeeRange, {
1363
1408
max_fee_satoshis
1364
1409
} ) ;
1365
1410
1411
+ #[ cfg( not( taproot) ) ]
1366
1412
impl_writeable_msg ! ( CommitmentSigned , {
1367
1413
channel_id,
1368
1414
signature,
1369
1415
htlc_signatures
1370
1416
} , { } ) ;
1371
1417
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
+
1372
1427
impl_writeable ! ( DecodedOnionErrorPacket , {
1373
1428
hmac,
1374
1429
failuremsg,
1375
1430
pad
1376
1431
} ) ;
1377
1432
1433
+ #[ cfg( not( taproot) ) ]
1378
1434
impl_writeable_msg ! ( FundingCreated , {
1379
1435
temporary_channel_id,
1380
1436
funding_txid,
1381
1437
funding_output_index,
1382
1438
signature
1383
1439
} , { } ) ;
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
+ } ) ;
1384
1450
1451
+ #[ cfg( not( taproot) ) ]
1385
1452
impl_writeable_msg ! ( FundingSigned , {
1386
1453
channel_id,
1387
1454
signature
1388
1455
} , { } ) ;
1389
1456
1457
+ #[ cfg( taproot) ]
1458
+ impl_writeable_msg ! ( FundingSigned , {
1459
+ channel_id,
1460
+ signature
1461
+ } , {
1462
+ ( 2 , partial_signature_with_nonce, option)
1463
+ } ) ;
1464
+
1390
1465
impl_writeable_msg ! ( ChannelReady , {
1391
1466
channel_id,
1392
1467
next_per_commitment_point,
@@ -1446,12 +1521,22 @@ impl_writeable_msg!(OpenChannel, {
1446
1521
( 1 , channel_type, option) ,
1447
1522
} ) ;
1448
1523
1524
+ #[ cfg( not( taproot) ) ]
1449
1525
impl_writeable_msg ! ( RevokeAndACK , {
1450
1526
channel_id,
1451
1527
per_commitment_secret,
1452
1528
next_per_commitment_point
1453
1529
} , { } ) ;
1454
1530
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
+
1455
1540
impl_writeable_msg ! ( Shutdown , {
1456
1541
channel_id,
1457
1542
scriptpubkey
@@ -2444,6 +2529,8 @@ mod tests {
2444
2529
first_per_commitment_point : pubkey_6,
2445
2530
shutdown_scriptpubkey : if shutdown { OptionalField :: Present ( Address :: p2pkh ( & :: bitcoin:: PublicKey { compressed : true , inner : pubkey_1} , Network :: Testnet ) . script_pubkey ( ) ) } else { OptionalField :: Absent } ,
2446
2531
channel_type : None ,
2532
+ #[ cfg( taproot) ]
2533
+ next_local_nonce : None ,
2447
2534
} ;
2448
2535
let encoded_value = accept_channel. encode ( ) ;
2449
2536
let mut target_value = hex:: decode ( "020202020202020202020202020202020202020202020202020202020202020212345678901234562334032891223698321446687011447600083a840000034d000c89d4c0bcc0bc031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a" ) . unwrap ( ) ;
@@ -2469,6 +2556,10 @@ mod tests {
2469
2556
funding_txid : Txid :: from_hex ( "c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e" ) . unwrap ( ) ,
2470
2557
funding_output_index : 255 ,
2471
2558
signature : sig_1,
2559
+ #[ cfg( taproot) ]
2560
+ partial_signature_with_nonce : None ,
2561
+ #[ cfg( taproot) ]
2562
+ next_local_nonce : None ,
2472
2563
} ;
2473
2564
let encoded_value = funding_created. encode ( ) ;
2474
2565
let target_value = hex:: decode ( "02020202020202020202020202020202020202020202020202020202020202026e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c200ffd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a" ) . unwrap ( ) ;
@@ -2483,6 +2574,8 @@ mod tests {
2483
2574
let funding_signed = msgs:: FundingSigned {
2484
2575
channel_id : [ 2 ; 32 ] ,
2485
2576
signature : sig_1,
2577
+ #[ cfg( taproot) ]
2578
+ partial_signature_with_nonce : None ,
2486
2579
} ;
2487
2580
let encoded_value = funding_signed. encode ( ) ;
2488
2581
let target_value = hex:: decode ( "0202020202020202020202020202020202020202020202020202020202020202d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a" ) . unwrap ( ) ;
@@ -2646,6 +2739,8 @@ mod tests {
2646
2739
channel_id : [ 2 ; 32 ] ,
2647
2740
signature : sig_1,
2648
2741
htlc_signatures : if htlcs { vec ! [ sig_2, sig_3, sig_4] } else { Vec :: new ( ) } ,
2742
+ #[ cfg( taproot) ]
2743
+ partial_signature_with_nonce : None ,
2649
2744
} ;
2650
2745
let encoded_value = commitment_signed. encode ( ) ;
2651
2746
let mut target_value = hex:: decode ( "0202020202020202020202020202020202020202020202020202020202020202d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a" ) . unwrap ( ) ;
@@ -2671,6 +2766,8 @@ mod tests {
2671
2766
channel_id : [ 2 ; 32 ] ,
2672
2767
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 ] ,
2673
2768
next_per_commitment_point : pubkey_1,
2769
+ #[ cfg( taproot) ]
2770
+ next_local_nonce : None ,
2674
2771
} ;
2675
2772
let encoded_value = raa. encode ( ) ;
2676
2773
let target_value = hex:: decode ( "02020202020202020202020202020202020202020202020202020202020202020101010101010101010101010101010101010101010101010101010101010101031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f" ) . unwrap ( ) ;
0 commit comments