@@ -12,14 +12,14 @@ import (
1212)
1313
1414const (
15- routeBlindingTestFileName = "testdata/route-blinding-test.json"
16- onionRouteBlindingTestFileName = "testdata/onion-route-blinding-test.json"
17- blindedOnionMessageOnionTestFileName = "testdata/blinded-onion-message-onion-test.json"
15+ routeBlindingTestFileName = "testdata/route-blinding-test.json" //nolint:lll
16+ onionRouteBlindingTestFileName = "testdata/onion-route-blinding-test.json" //nolint:lll
17+ blindedOnionMessageOnionTestFileName = "testdata/blinded-onion-message-onion-test.json" //nolint:lll
1818)
1919
2020var (
21- // bolt4PubKeys contains the public keys used in the Bolt 4 spec test
22- // vectors. We convert them variables named after the commonly used
21+ // bolt4PubKeys contains the public keys used in the Bolt 4 spec. test
22+ // vectors. We convert them to variables named after the commonly used
2323 // names in cryptography.
2424 alicePubKey = bolt4PubKeys [0 ]
2525 bobPubKey = bolt4PubKeys [1 ]
@@ -128,7 +128,7 @@ func TestBuildBlindedRoute(t *testing.T) {
128128
129129// TestBuildOnionMessageBlindedRoute tests the construction of a blinded route
130130// for an onion message, specifically the concatenation of two blinded paths,
131- // against the spec test vectors in `blinded-onion-message-onion-test.json`. It
131+ // against the spec. test vectors in `blinded-onion-message-onion-test.json`. It
132132// verifies the correctness of BuildBlindedPath, decryptBlindedHopData, and
133133// NextEphemeral.
134134//
@@ -152,9 +152,10 @@ func TestBuildBlindedRoute(t *testing.T) {
152152// hop (Bob) instead of the key that she could derive herself.
153153//
154154// The test then asserts that the generated concatenated path matches the test
155- // vector's expected route. Finally, it simulates the decryption process at each
156- // hop, verifying that each node can correctly decrypt its payload and derive
157- // the correct next ephemeral key.
155+ // vector's expected route. It simulates the decryption process at each hop,
156+ // verifying that at each hop encrypted_recipient_data is what we expect it to
157+ // be and that it correctly decrypts to the encrypted_data_tlv stream. Finally,
158+ // we verify the derivation of the next ephemeral key.
158159func TestBuildOnionMessageBlindedRoute (t * testing.T ) {
159160 t .Parallel ()
160161
@@ -174,6 +175,7 @@ func TestBuildOnionMessageBlindedRoute(t *testing.T) {
174175 initialHopID string ) []* HopInfo {
175176
176177 path := make ([]* HopInfo , len (h ))
178+
177179 // The json test vector doesn't properly specify the current
178180 // node id, so we need the initial Node ID as a starting point.
179181 currentHop := initialHopID
@@ -196,17 +198,20 @@ func TestBuildOnionMessageBlindedRoute(t *testing.T) {
196198 // get the next node id here.
197199 currentHop = hop .EncodedOnionMessageTLVs .NextNodeID
198200 }
201+
199202 return path
200203 }
201204
202205 // First, Dave will build a blinded path from Bob to itself.
203- daveSessKey := privKeyFromString (
206+ receiverSessKey := privKeyFromString (
204207 testCase .Generate .Hops [1 ].PathKeySecret ,
205208 )
206209 daveBobPath := buildMessagePath (
207210 testCase .Generate .Hops [1 :], bobPubKey ,
208211 )
209- daveBobBlindedPath , err := BuildBlindedPath (daveSessKey , daveBobPath )
212+ daveBobBlindedPath , err := BuildBlindedPath (
213+ receiverSessKey , daveBobPath ,
214+ )
210215 require .NoError (t , err )
211216
212217 // At this point, Dave will give his blinded path to the Sender who will
@@ -263,6 +268,17 @@ func TestBuildOnionMessageBlindedRoute(t *testing.T) {
263268 priv := privKeyFromString (hop .PrivKey )
264269 ephem := pubKeyFromString (genData .EphemeralPubKey )
265270
271+ // Check if the encrypted_recipient_data is what we expect it to
272+ // be.
273+ encRecipientDataExpected , err := hex .DecodeString (
274+ genData .EncryptedRecipientData ,
275+ )
276+ require .NoError (t , err )
277+ require .Equal (
278+ t , encRecipientDataExpected ,
279+ path .BlindedHops [i ].CipherText ,
280+ )
281+
266282 // Now we'll decrypt the blinded hop data using the private key
267283 // and the ephemeral public key.
268284 data , err := decryptBlindedHopData (
@@ -272,8 +288,9 @@ func TestBuildOnionMessageBlindedRoute(t *testing.T) {
272288 require .NoError (t , err )
273289
274290 // Check if the decrypted data is what we expect it to be.
275- dataExpected , _ := hex .DecodeString (genData .EncryptedDataTlv )
276- require .Equal (t , data , dataExpected )
291+ dataExpected , err := hex .DecodeString (genData .EncryptedDataTlv )
292+ require .NoError (t , err )
293+ require .Equal (t , dataExpected , data )
277294
278295 nextEphem , err := NextEphemeral (& PrivKeyECDH {priv }, ephem )
279296 require .NoError (t , err )
@@ -511,11 +528,13 @@ type decryptOnionMessageData struct {
511528}
512529
513530type decryptHops struct {
531+ //nolint:tagliatelle
514532 Onion string `json:"onion"`
515533 NodePrivKey string `json:"node_privkey"`
516534 NextBlinding string `json:"next_blinding"`
517535}
518536
537+ //nolint:tagliatelle
519538type decryptOnionMessageHops struct {
520539 OnionMessage string `json:"onion_message"`
521540 PrivKey string `json:"privkey"`
@@ -536,11 +555,13 @@ type onionMessageJsonTestCase struct {
536555}
537556
538557type routeData struct {
558+ //nolint:tagliatelle
539559 IntroductionNodeID string `json:"introduction_node_id"`
540560 Blinding string `json:"blinding"`
541561 Hops []blindedHop `json:"hops"`
542562}
543563
564+ //nolint:tagliatelle
544565type routeOnionMessageData struct {
545566 FirstNodeId string `json:"first_node_id"`
546567 FirstPathKey string `json:"first_path_key"`
@@ -559,13 +580,15 @@ type generateData struct {
559580 Hops []hopData `json:"hops"`
560581}
561582
583+ //nolint:tagliatelle
562584type generateOnionMessageData struct {
563585 SessionKey string `json:"session_key"`
564586 Hops []hopOnionMessageData `json:"hops"`
565587}
566588
567589type unblindedHop struct {
568590 NodePrivKey string `json:"node_privkey"`
591+ //nolint:tagliatelle
569592 EphemeralPubKey string `json:"ephemeral_pubkey"`
570593 DecryptedData string `json:"decrypted_data"`
571594 NextEphemeralPubKey string `json:"next_ephemeral_pubkey"`
@@ -577,26 +600,31 @@ type hopData struct {
577600 EncodedTLVs string `json:"encoded_tlvs"`
578601}
579602
603+ //nolint:tagliatelle
580604type hopOnionMessageData struct {
581605 PathKeySecret string `json:"path_key_secret"`
582606 EncodedOnionMessageTLVs encodedOnionMessageTLVs `json:"tlvs"`
583- EncryptedDataTlv string `json:"encrypted_data_tlv"`
607+ EncryptedDataTlv string `json:"encrypted_data_tlv"` //nolint:lll
584608 EphemeralPubKey string `json:"E"`
585609 NextEphemeralPrivKey string `json:"next_e"`
610+ EncryptedRecipientData string `json:"encrypted_recipient_data"` //nolint:lll
586611}
587612
613+ //nolint:tagliatelle
588614type encodedOnionMessageTLVs struct {
589615 NextNodeID string `json:"next_node_id"`
590616 NextPathKeyOverride string `json:"next_path_key_override"`
591617 PathKeyOverrideSecret string `json:"path_key_override_secret"`
592618 PathID string `json:"path_id"`
593619}
594620
621+ //nolint:tagliatelle
595622type blindedHop struct {
596623 BlindedNodeID string `json:"blinded_node_id"`
597624 EncryptedData string `json:"encrypted_data"`
598625}
599626
627+ //nolint:tagliatelle
600628type blindedOnionMessageHop struct {
601629 BlindedNodeID string `json:"blinded_node_id"`
602630 EncryptedRecipientData string `json:"encrypted_recipient_data"`
0 commit comments