# SPSP / STREAM Theory - A single money packet. ILP over HTTP

**URL:** <https://forum.interledger.org/t/spsp-stream-theory-a-single-money-packet-ilp-over-http/692>\
**Category:** Implementations and SDKs\
**Tags:** rust\
**Created:** [July 18, 2019, 10:44pm UTC](https://forum.interledger.org/t/spsp-stream-theory-a-single-money-packet-ilp-over-http/692 "2019-07-18T22:44:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fractal-synapse](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/fractal-synapse/32/379_2.png) [@fractal-synapse](https://forum.interledger.org/u/fractal-synapse)\
**Post date:** [July 18, 2019, 10:44pm UTC](https://forum.interledger.org/t/spsp-stream-theory-a-single-money-packet-ilp-over-http/692/1 "2019-07-18T22:44:22Z")

</div>

I have a question for the ILP gurus.

The spec indicates that once a client app receives back the query for the shared\_secret and destination\_account they are good to go to open a connection to the /pay endpoint and begin “sending money” using STREAM.

I am of the understanding that therefore I can open a socket connection to the /pay endpoint and send an ILP Prepare Packet **WITH** the payload of a STREAM Packet, which in turn contains the frame data.

The stream packet data in my example contains only two frames:

```
    // Load up the STREAM packet
    let sequence = 1;
    let mut frames = vec![Frame::StreamMoney(StreamMoneyFrame {
        stream_id: 1,
        shares: 1,
    })];
    
        frames.push(Frame::ConnectionNewAddress(ConnectionNewAddressFrame {
            source_account: source_account.clone(),
        }));
    
    let stream_packet = StreamPacketBuilder {
        ilp_packet_type: PacketType::Prepare,
        // TODO enforce min exchange rate
        prepare_amount: amount,
        sequence,
        frames: &frames,
    }
    .build();

```

Technically, it seems I can just at the very least treat this exchange in a conventional request / response if I plan to only send one packet?

Is this correct?

---

<div class="post-metadata">

**Author:** ![fractal-synapse](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/fractal-synapse/32/379_2.png) [@fractal-synapse](https://forum.interledger.org/u/fractal-synapse)\
**Post date:** [July 18, 2019, 10:47pm UTC](https://forum.interledger.org/t/spsp-stream-theory-a-single-money-packet-ilp-over-http/692/2 "2019-07-18T22:47:43Z")

</div>

To clarify, as I test my theory, it is not working, hence the clarification request.

I am wrapping up that StreamPacket and sending it in an ILP PreparePacket.

```
let data = stream_packet.into_encrypted(shared_secret.as_bytes());
            let execution_condition = generate_condition(shared_secret.as_bytes(), &data);
            let prepare = PrepareBuilder {
                destination: destination_account.clone(),
                amount,
                execution_condition: &execution_condition,
                expires_at: SystemTime::now() + Duration::from_secs(30),
                // TODO don't copy the data
                data: &data[..],
            }
            .build();
```

---

<div class="post-metadata">

**Author:** ![emschwartz](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/emschwartz/32/12_2.png) [@emschwartz](https://forum.interledger.org/u/emschwartz)\
**Post date:** [July 18, 2019, 10:48pm UTC](https://forum.interledger.org/t/spsp-stream-theory-a-single-money-packet-ilp-over-http/692/3 "2019-07-18T22:48:57Z")

</div>

You are correct about the encapsulation of the packets (frames go in STREAM packets, which are encrypted using a key derived from the `shared_secret` that the SPSP endpoint returns, and the STREAM packet is included in the `data` of an ILP packet).

Regarding the `/pay` endpoint on the interledger.rs node, if you want to have the node forward a fully formed ILP packet you’ll need to send it to `/ilp`. `/pay` expects a JSON body with just the `receiver` and `source_amount`, and then the node will create the ILP packets and send them automatically.

---

<div class="post-metadata">

**Author:** ![fractal-synapse](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/fractal-synapse/32/379_2.png) [@fractal-synapse](https://forum.interledger.org/u/fractal-synapse)\
**Post date:** [July 18, 2019, 10:53pm UTC](https://forum.interledger.org/t/spsp-stream-theory-a-single-money-packet-ilp-over-http/692/4 "2019-07-18T22:53:01Z")

</div>

Ok thank-you for that.

I noticed that the destination returned from the query is like : **local.jazzy.rQbNPNDhHS2UsWYcXLCZ6O1C5Aoh\_PyxNf4dZgtMhCE**

The spec states the server may add segment information… yep just like that! BUT where is that used, it must hold in memory since the underlying store does not persist that.

It is not clear to me which packet routing strategy makes use of that and when I need to use it as THE address and not just **local.jazzy**.

---

<div class="post-metadata">

**Author:** ![emschwartz](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/emschwartz/32/12_2.png) [@emschwartz](https://forum.interledger.org/u/emschwartz)\
**Post date:** [July 18, 2019, 11:05pm UTC](https://forum.interledger.org/t/spsp-stream-theory-a-single-money-packet-ilp-over-http/692/5 "2019-07-18T23:05:56Z")

</div>

You need to use `local.jazzy.rQbNPNDhHS2UsWYcXLCZ6O1C5Aoh_PyxNf4dZgtMhCE` in order for the STREAM server to fulfill the packet.

That implementation of the STREAM/SPSP server deterministically generates the `shared_secret` from a master secret and a public nonce. That nonce is included in the ILP address and is required for the receiver to be able to rederive the secrets needed to decrypt the data and generate the fulfillment.

---

<div class="post-metadata">

**Author:** ![fractal-synapse](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/fractal-synapse/32/379_2.png) [@fractal-synapse](https://forum.interledger.org/u/fractal-synapse)\
**Post date:** [July 18, 2019, 11:13pm UTC](https://forum.interledger.org/t/spsp-stream-theory-a-single-money-packet-ilp-over-http/692/6 "2019-07-18T23:13:17Z")

</div>

Ok bonus question, does the /ilp endpoint know what to do with that address or will it only work in /pay ?

---

<div class="post-metadata">

**Author:** ![emschwartz](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/emschwartz/32/12_2.png) [@emschwartz](https://forum.interledger.org/u/emschwartz)\
**Post date:** [July 19, 2019, 3:05am UTC](https://forum.interledger.org/t/spsp-stream-theory-a-single-money-packet-ilp-over-http/692/7 "2019-07-19T03:05:31Z")

</div>

If it has a route for `local.jazzy`, it’ll be able to route `local.jazzy.rQbNPNDhHS2UsWYcXLCZ6O1C5Aoh_PyxNf4dZgtMhCE`
