Skip to content

Refactor API for latest suite of protocols #130

@justmoon

Description

@justmoon

The ilp module should be updated for the latest suite of protocols. It should expose a reasonable API for ILP and PSK/Paystream.

Here is a sketch of what the new API might look like:

Basic Usage: PayStream

const ilp = require('ilp')

;(async () => {
  // Connect to a PayStream, defaults to using moneyd
  const socket = await ilp.createConnection([ilp address], [shared secret])

  // Lower the paystream maximum by 1000 (minimum will be lowered if necessary)
  await socket.pay('1000')
  // Lower the paystream minimum by 2000
  socket.payUpTo('2000')
  // Increase the paystream minimum by 4000 (maximum will be increased if necessary)
  await socket.charge('4000')
  // Increase the paystream maximum by 2000
  socket.chargeUpTo('2000')
  // Write some data
  socket.write(Buffer.alloc(128))
  await socket.flush()
  // Read data
  socket.on('data', (data) => {
    console.log(data.toString('utf8'))
  })
})()

Basic Usage: Raw packet

const ilp = require('ilp')

;(async () => {
  const { fulfillment, data } = await ilp.sendPacket({
    destination: 'test.bob',
    amount: '100',
    executionCondition: '...',
    expiresAt: '...',
    data: Buffer.alloc(0)
  })
})()

Advanced Usage: Using a custom plugin

const { create as createIlp } = require('ilp')
const CustomPlugin = require('ilp-plugin-custom')

;(async () => {
  const ilp = createIlp({
    plugin: new CustomPlugin({ /* ... */ })
  })

  // ... ready to use
})()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions