Sphinx

object Sphinx

see https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md

Functions

blind
Link copied to clipboard
common
fun blind(pub: PublicKey, blindingFactor: ByteVector32): PublicKey
fun blind(pub: PublicKey, blindingFactors: List<ByteVector32>): PublicKey
computeBlindingFactor
Link copied to clipboard
common
fun computeBlindingFactor(pub: PublicKey, secret: ByteVector): ByteVector32
common
fun computeEphemeralPublicKeysAndSharedSecrets(sessionKey: PrivateKey, publicKeys: List<PublicKey>): Pair<List<PublicKey>, List<ByteVector32>>

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

computeSharedSecret
Link copied to clipboard
common
fun computeSharedSecret(pub: PublicKey, secret: PrivateKey): ByteVector32
create
Link copied to clipboard
common
fun create(sessionKey: PrivateKey, publicKeys: List<PublicKey>, payloads: List<ByteArray>, associatedData: ByteVector32, packetLength: Int): PacketAndSecrets

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

generateFiller
Link copied to clipboard
common
fun generateFiller(keyType: String, sharedSecrets: List<ByteVector32>, payloads: List<ByteArray>, packetLength: Int): ByteArray

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

generateKey
Link copied to clipboard
common
fun generateKey(keyType: String, secret: ByteVector32): ByteVector32
generateStream
Link copied to clipboard
common
fun generateStream(key: ByteVector32, length: Int): ByteArray
hash
Link copied to clipboard
common
fun hash(onion: OnionRoutingPacket): ByteVector32

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

mac
Link copied to clipboard
common
fun mac(key: ByteVector, message: ByteVector): ByteVector32
fun mac(key: ByteArray, message: ByteArray): ByteVector32
peekPayloadLength
Link copied to clipboard
common
fun peekPayloadLength(payload: ByteArray): Int

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

peel
Link copied to clipboard
common
fun peel(privateKey: PrivateKey, associatedData: ByteVector, packet: OnionRoutingPacket, packetLength: Int): Either<FailureMessage, DecryptedPacket>

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

zeroes
Link copied to clipboard
common
fun zeroes(length: Int): ByteArray

Properties

MacLength
Link copied to clipboard
common
const val MacLength: Int = 32