Sphinx

object Sphinx
class Object
trait Matchable
class Any
Sphinx.type

Type members

Classlikes

case class DecryptedFailurePacket(originNode: PublicKey, failureMessage: FailureMessage)

A properly decrypted failure from a node in the route.

A properly decrypted failure from a node in the route.

Value parameters:
failureMessage

friendly failure message.

originNode

public key of the node that generated the failure.

Source:
Sphinx.scala
case class DecryptedPacket(payload: ByteVector, nextPacket: OnionRoutingPacket, sharedSecret: ByteVector32)

Decrypting an onion packet yields a payload for the current node and the encrypted packet for the next node.

Decrypting an onion packet yields a payload for the current node and the encrypted packet for the next node.

Value parameters:
nextPacket

packet for the next node.

payload

decrypted payload for this node.

sharedSecret

shared secret for the sending node, which we will need to return failure messages.

Source:
Sphinx.scala
case class PacketAndSecrets(packet: OnionRoutingPacket, sharedSecrets: Seq[(ByteVector32, PublicKey)])

A encrypted onion packet with all the associated shared secrets.

A encrypted onion packet with all the associated shared secrets.

Value parameters:
packet

encrypted onion packet.

sharedSecrets

shared secrets (one per node in the route). Known (and needed) only if you're creating the packet. Empty if you're just forwarding the packet to the next node.

Source:
Sphinx.scala

Route blinding is a lightweight technique to provide recipient anonymity by blinding an arbitrary amount of hops at the end of an onion path. It can be used for payments or onion messages.

Route blinding is a lightweight technique to provide recipient anonymity by blinding an arbitrary amount of hops at the end of an onion path. It can be used for payments or onion messages.

Source:
Sphinx.scala

Value members

Concrete methods

def blind(pub: PublicKey, blindingFactor: ByteVector32): PublicKey
def blind(pub: PublicKey, blindingFactors: Seq[ByteVector32]): PublicKey

Compute the ephemeral public keys and shared secrets for all nodes on the route.

Compute the ephemeral public keys and shared secrets for all nodes on the route.

Value parameters:
publicKeys

public keys of each node on the route.

sessionKey

this node's session key.

Returns:

a tuple (ephemeral public keys, shared secrets).

Source:
Sphinx.scala
def create(sessionKey: PrivateKey, packetPayloadLength: Int, publicKeys: Seq[PublicKey], payloads: Seq[ByteVector], associatedData: Option[ByteVector32]): Try[PacketAndSecrets]

Create an encrypted onion packet that contains payloads for all nodes in the list.

Create an encrypted onion packet that contains payloads for all nodes in the list.

Value parameters:
associatedData

associated data.

packetPayloadLength

length of the packet's encrypted onion payload (e.g. 1300 for standard payment onions).

payloads

payloads (one per node).

publicKeys

node public keys (one per node).

sessionKey

session key.

Returns:

An onion packet with all shared secrets. The onion packet can be sent to the first node in the list, and the shared secrets (one per node) can be used to parse returned failure messages if needed.

Source:
Sphinx.scala
def generateFiller(keyType: String, packetPayloadLength: Int, sharedSecrets: Seq[ByteVector32], payloads: Seq[ByteVector]): ByteVector

Generate a deterministic filler to prevent intermediate nodes from knowing their position in the route. See https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md#filler-generation

Generate a deterministic filler to prevent intermediate nodes from knowing their position in the route. See https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md#filler-generation

Value parameters:
keyType

type of key used (depends on the onion we're building).

packetPayloadLength

length of the packet's encrypted onion payload (e.g. 1300 for standard payment onions).

payloads

payloads for all the hops.

sharedSecrets

shared secrets for all the hops.

Returns:

filler bytes.

Source:
Sphinx.scala

When an invalid onion is received, its hash should be included in the failure message.

When an invalid onion is received, its hash should be included in the failure message.

Source:
Sphinx.scala

Peek at the first bytes of the per-hop payload to extract its length.

Peek at the first bytes of the per-hop payload to extract its length.

Source:
Sphinx.scala
def peel(privateKey: PrivateKey, associatedData: Option[ByteVector32], packet: OnionRoutingPacket): Either[BadOnion, DecryptedPacket]

Decrypt the incoming packet, extract the per-hop payload and build the packet for the next node.

Decrypt the incoming packet, extract the per-hop payload and build the packet for the next node.

Value parameters:
associatedData

associated data.

packet

packet received by this node.

privateKey

this node's private key.

Returns:

a DecryptedPacket(payload, packet, shared secret) object where:

  • payload is the per-hop payload for this node.
  • packet is the next packet, to be forwarded using the info that is given in the payload.
  • shared secret is the secret we share with the node that sent the packet. We need it to propagate failure messages upstream. or a BadOnion error containing the hash of the invalid onion.
Source:
Sphinx.scala
def wrap(payload: ByteVector, associatedData: Option[ByteVector32], ephemeralPublicKey: PublicKey, sharedSecret: ByteVector32, packet: Either[ByteVector, OnionRoutingPacket], onionPayloadFiller: ByteVector): OnionRoutingPacket

Wrap the given packet in an additional layer of onion encryption, adding an encrypted payload for a specific node.

Wrap the given packet in an additional layer of onion encryption, adding an encrypted payload for a specific node.

Packets are constructed in reverse order:

  • you first create the packet for the final recipient
  • then you call wrap(...) until you've built the final onion packet that will be sent to the first node in the route
Value parameters:
associatedData

associated data.

ephemeralPublicKey

ephemeral key shared with the target node.

onionPayloadFiller

optional onion payload filler, needed only when you're constructing the last packet.

packet

current packet or random bytes if the packet hasn't been initialized.

payload

per-hop payload for the target node.

sharedSecret

shared secret with this hop.

Returns:

the next packet.

Source:
Sphinx.scala

Concrete fields

Supported packet version. Note that since this value is outside of the onion encrypted payload, intermediate nodes may or may not use this value when forwarding the packet to the next node.

Supported packet version. Note that since this value is outside of the onion encrypted payload, intermediate nodes may or may not use this value when forwarding the packet to the next node.

Source:
Sphinx.scala