@@ -1765,6 +1765,52 @@ impl fmt::Debug for OnionPacket {
17651765 }
17661766}
17671767
1768+ /// BOLT 4 onion packet including hop data for the next peer.
1769+ #[ derive( Clone , Hash , PartialEq , Eq ) ]
1770+ pub struct TrampolineOnionPacket {
1771+ /// Bolt 04 version number
1772+ pub version : u8 ,
1773+ /// A random sepc256k1 point, used to build the ECDH shared secret to decrypt hop_data
1774+ pub public_key : PublicKey ,
1775+ /// Encrypted payload for the next hop
1776+ //
1777+ // Unlike the onion packets used for payments, Trampoline onion packets have to be shorter than
1778+ // 1300 bytes. The expected default is 650 bytes.
1779+ // TODO: if 650 ends up being the most common size, optimize this to be:
1780+ // enum { ThirteenHundred([u8; 650]), VarLen(Vec<u8>) }
1781+ pub hop_data : Vec < u8 > ,
1782+ /// HMAC to verify the integrity of hop_data
1783+ pub hmac : [ u8 ; 32 ] ,
1784+ }
1785+
1786+ impl onion_utils:: Packet for TrampolineOnionPacket {
1787+ type Data = Vec < u8 > ;
1788+ fn new ( public_key : PublicKey , hop_data : Vec < u8 > , hmac : [ u8 ; 32 ] ) -> Self {
1789+ Self {
1790+ version : 0 ,
1791+ public_key,
1792+ hop_data,
1793+ hmac,
1794+ }
1795+ }
1796+ }
1797+
1798+ impl Writeable for TrampolineOnionPacket {
1799+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
1800+ self . version . write ( w) ?;
1801+ self . public_key . write ( w) ?;
1802+ w. write_all ( & self . hop_data ) ?;
1803+ self . hmac . write ( w) ?;
1804+ Ok ( ( ) )
1805+ }
1806+ }
1807+
1808+ impl Debug for TrampolineOnionPacket {
1809+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1810+ f. write_fmt ( format_args ! ( "TrampolineOnionPacket version {} with hmac {:?}" , self . version, & self . hmac[ ..] ) )
1811+ }
1812+ }
1813+
17681814#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
17691815pub ( crate ) struct OnionErrorPacket {
17701816 // This really should be a constant size slice, but the spec lets these things be up to 128KB?
0 commit comments