@@ -114,11 +114,11 @@ def __repr__(self):
114114
115115class OnionPacket :
116116
117- def __init__ (self , public_key : bytes , hops_data : bytes , hmac : bytes ):
117+ def __init__ (self , public_key : bytes , hops_data : bytes , hmac : bytes , version : int = 0 ):
118118 assert len (public_key ) == 33
119119 assert len (hops_data ) in [HOPS_DATA_SIZE , TRAMPOLINE_HOPS_DATA_SIZE , ONION_MESSAGE_LARGE_SIZE ]
120120 assert len (hmac ) == PER_HOP_HMAC_SIZE
121- self .version = 0
121+ self .version = version
122122 self .public_key = public_key
123123 self .hops_data = hops_data # also called RoutingInfo in bolt-04
124124 self .hmac = hmac
@@ -141,13 +141,11 @@ def to_bytes(self) -> bytes:
141141 def from_bytes (cls , b : bytes ):
142142 if len (b ) - 66 not in [HOPS_DATA_SIZE , TRAMPOLINE_HOPS_DATA_SIZE , ONION_MESSAGE_LARGE_SIZE ]:
143143 raise Exception ('unexpected length {}' .format (len (b )))
144- version = b [0 ]
145- if version != 0 :
146- raise UnsupportedOnionPacketVersion ('version {} is not supported' .format (version ))
147144 return OnionPacket (
148145 public_key = b [1 :34 ],
149146 hops_data = b [34 :- 32 ],
150- hmac = b [- 32 :]
147+ hmac = b [- 32 :],
148+ version = b [0 ],
151149 )
152150
153151
@@ -362,6 +360,9 @@ def process_onion_packet(
362360 associated_data : bytes = b'' ,
363361 is_trampoline = False ,
364362 tlv_stream_name = 'payload' ) -> ProcessedOnionPacket :
363+ # TODO: check Onion features ( PERM|NODE|3 (required_node_feature_missing )
364+ if onion_packet .version != 0 :
365+ raise UnsupportedOnionPacketVersion ()
365366 if not ecc .ECPubkey .is_pubkey_bytes (onion_packet .public_key ):
366367 raise InvalidOnionPubkey ()
367368 shared_secret = get_ecdh (our_onion_private_key , onion_packet .public_key )
0 commit comments