ilp-protocol-spsp

SPSP client on ILP

Usage no npm install needed!

<script type="module">
  import ilpProtocolSpsp from 'https://cdn.skypack.dev/ilp-protocol-spsp';
</script>

README

ILP Protocol SPSP

Description

Implements version 4 of the Simple Payment Setup Protocol.

Example

Simple Usage

Sends a single-chunk PSK payment or a STREAM payment, if the server supports it. Great for micro-payments or micro-donations inside of a script.

try {
  const resp = await SPSP.pay(plugin, {
    pointer: '$bob.example.com',
    sourceAmount: '1000'
  })
  console.log(`sent "${resp.totalSent}"`)
} catch (e) {
  console.log(`sent "${e instanceof SPSP.PaymentError ? e.totalSent : 0}"`)
}

Make a pull payment from a designated pull payment pointer.

try {
  const resp = await SPSP.pull(plugin, {
    pointer: '$bob.example.com/4139fb24-3ab6-4ea1-a6de-e8d761ff7569',
    amount: '1000'
  })
  console.log(`pulled "${resp.totalReceived}"`)
} catch (e) {
  console.log(`pulled "${e instanceof SPSP.PaymentError ? e.totalReceived : 0}"`)
}

Advanced Usage

Query the endpoint manually to construct a STREAM or PSK2 payment.

const query = await SPSP.query('$bob.example.com')
console.log(query)
// {
//   destination_account: "test.example.bob.LwNAw4ZEjlOwkc8xmaQRaRd37YRl8sixSCBPgEEqo8I",
//   shared_secret: "RvqL/HJO3GinYIeujez/OEsBtX6+NtxJwabh7KthfOI=",
//   content_type: "application/spsp4+json"
// }

The query may contain additional information.