@@ -19,8 +19,8 @@ package fr.acinq.eclair.crypto
19
19
import fr .acinq .bitcoin .Crypto .{PrivateKey , PublicKey }
20
20
import fr .acinq .bitcoin .{ByteVector32 , Crypto }
21
21
import fr .acinq .eclair .crypto .Monitoring .{Metrics , Tags }
22
- import fr .acinq .eclair .wire
23
- import fr .acinq .eclair .wire .{ FailureMessage , FailureMessageCodecs , Onion , OnionCodecs }
22
+ import fr .acinq .eclair .wire . protocol
23
+ import fr .acinq .eclair .wire .protocol . _
24
24
import grizzled .slf4j .Logging
25
25
import scodec .Attempt
26
26
import scodec .bits .ByteVector
@@ -107,7 +107,7 @@ object Sphinx extends Logging {
107
107
* @param nextPacket packet for the next node.
108
108
* @param sharedSecret shared secret for the sending node, which we will need to return failure messages.
109
109
*/
110
- case class DecryptedPacket (payload : ByteVector , nextPacket : wire .OnionRoutingPacket , sharedSecret : ByteVector32 ) {
110
+ case class DecryptedPacket (payload : ByteVector , nextPacket : protocol .OnionRoutingPacket , sharedSecret : ByteVector32 ) {
111
111
112
112
val isLastPacket : Boolean = nextPacket.hmac == ByteVector32 .Zeroes
113
113
@@ -120,7 +120,7 @@ object Sphinx extends Logging {
120
120
* @param sharedSecrets shared secrets (one per node in the route). Known (and needed) only if you're creating the
121
121
* packet. Empty if you're just forwarding the packet to the next node.
122
122
*/
123
- case class PacketAndSecrets (packet : wire .OnionRoutingPacket , sharedSecrets : Seq [(ByteVector32 , PublicKey )])
123
+ case class PacketAndSecrets (packet : protocol .OnionRoutingPacket , sharedSecrets : Seq [(ByteVector32 , PublicKey )])
124
124
125
125
sealed trait OnionRoutingPacket [T <: Onion .PacketType ] {
126
126
@@ -168,10 +168,10 @@ object Sphinx extends Logging {
168
168
* - payload is the per-hop payload for this node.
169
169
* - packet is the next packet, to be forwarded using the info that is given in the payload.
170
170
* - shared secret is the secret we share with the node that sent the packet. We need it to propagate
171
- * failure messages upstream.
172
- * or a BadOnion error containing the hash of the invalid onion.
171
+ * failure messages upstream.
172
+ * or a BadOnion error containing the hash of the invalid onion.
173
173
*/
174
- def peel (privateKey : PrivateKey , associatedData : ByteVector , packet : wire .OnionRoutingPacket ): Either [wire. BadOnion , DecryptedPacket ] = packet.version match {
174
+ def peel (privateKey : PrivateKey , associatedData : ByteVector , packet : protocol .OnionRoutingPacket ): Either [BadOnion , DecryptedPacket ] = packet.version match {
175
175
case 0 => Try (PublicKey (packet.publicKey, checkValid = true )) match {
176
176
case Success (packetEphKey) =>
177
177
val sharedSecret = computeSharedSecret(packetEphKey, privateKey)
@@ -191,13 +191,13 @@ object Sphinx extends Logging {
191
191
val nextOnionPayload = bin.drop(perHopPayloadLength).take(PayloadLength )
192
192
val nextPubKey = blind(packetEphKey, computeBlindingFactor(packetEphKey, sharedSecret))
193
193
194
- Right (DecryptedPacket (perHopPayload, wire .OnionRoutingPacket (Version , nextPubKey.value, nextOnionPayload, hmac), sharedSecret))
194
+ Right (DecryptedPacket (perHopPayload, protocol .OnionRoutingPacket (Version , nextPubKey.value, nextOnionPayload, hmac), sharedSecret))
195
195
} else {
196
- Left (wire. InvalidOnionHmac (hash(packet)))
196
+ Left (InvalidOnionHmac (hash(packet)))
197
197
}
198
- case Failure (_) => Left (wire. InvalidOnionKey (hash(packet)))
198
+ case Failure (_) => Left (InvalidOnionKey (hash(packet)))
199
199
}
200
- case _ => Left (wire. InvalidOnionVersion (hash(packet)))
200
+ case _ => Left (InvalidOnionVersion (hash(packet)))
201
201
}
202
202
203
203
/**
@@ -217,7 +217,7 @@ object Sphinx extends Logging {
217
217
* @param onionPayloadFiller optional onion payload filler, needed only when you're constructing the last packet.
218
218
* @return the next packet.
219
219
*/
220
- def wrap (payload : ByteVector , associatedData : ByteVector32 , ephemeralPublicKey : PublicKey , sharedSecret : ByteVector32 , packet : Either [ByteVector , wire .OnionRoutingPacket ], onionPayloadFiller : ByteVector = ByteVector .empty): wire .OnionRoutingPacket = {
220
+ def wrap (payload : ByteVector , associatedData : ByteVector32 , ephemeralPublicKey : PublicKey , sharedSecret : ByteVector32 , packet : Either [ByteVector , protocol .OnionRoutingPacket ], onionPayloadFiller : ByteVector = ByteVector .empty): protocol .OnionRoutingPacket = {
221
221
require(payload.length <= PayloadLength - MacLength , s " packet payload cannot exceed ${PayloadLength - MacLength } bytes " )
222
222
223
223
val (currentMac, currentPayload): (ByteVector32 , ByteVector ) = packet match {
@@ -234,7 +234,7 @@ object Sphinx extends Logging {
234
234
}
235
235
236
236
val nextHmac = mac(generateKey(" mu" , sharedSecret), nextOnionPayload ++ associatedData)
237
- val nextPacket = wire .OnionRoutingPacket (Version , ephemeralPublicKey.value, nextOnionPayload, nextHmac)
237
+ val nextPacket = protocol .OnionRoutingPacket (Version , ephemeralPublicKey.value, nextOnionPayload, nextHmac)
238
238
nextPacket
239
239
}
240
240
@@ -257,7 +257,7 @@ object Sphinx extends Logging {
257
257
val lastPacket = wrap(payloads.last, associatedData, ephemeralPublicKeys.last, sharedsecrets.last, Left (startingBytes), filler)
258
258
259
259
@ tailrec
260
- def loop (hopPayloads : Seq [ByteVector ], ephKeys : Seq [PublicKey ], sharedSecrets : Seq [ByteVector32 ], packet : wire .OnionRoutingPacket ): wire .OnionRoutingPacket = {
260
+ def loop (hopPayloads : Seq [ByteVector ], ephKeys : Seq [PublicKey ], sharedSecrets : Seq [ByteVector32 ], packet : protocol .OnionRoutingPacket ): protocol .OnionRoutingPacket = {
261
261
if (hopPayloads.isEmpty) packet else {
262
262
val nextPacket = wrap(hopPayloads.last, associatedData, ephKeys.last, sharedSecrets.last, Right (packet))
263
263
loop(hopPayloads.dropRight(1 ), ephKeys.dropRight(1 ), sharedSecrets.dropRight(1 ), nextPacket)
@@ -271,8 +271,8 @@ object Sphinx extends Logging {
271
271
/**
272
272
* When an invalid onion is received, its hash should be included in the failure message.
273
273
*/
274
- def hash (onion : wire .OnionRoutingPacket ): ByteVector32 =
275
- Crypto .sha256(wire. OnionCodecs .onionRoutingPacketCodec(onion.payload.length.toInt).encode(onion).require.toByteVector)
274
+ def hash (onion : protocol .OnionRoutingPacket ): ByteVector32 =
275
+ Crypto .sha256(OnionCodecs .onionRoutingPacketCodec(onion.payload.length.toInt).encode(onion).require.toByteVector)
276
276
277
277
}
278
278
0 commit comments