JSPM

  • Created
  • Published
  • Downloads 1343
  • Score
    100M100P100Q116663F
  • License Apache-2.0

Module for parsing and serializing ILP packets

Package Exports

  • ilp-packet

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ilp-packet) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ILP Packet

npm circle codecov

A serializer and deserializer for ILP packets and messages

Usage

Installation

npm install ilp-packet

Deserialize ILP Packet

const packet = require('ilp-packet')

const binaryPacket = Buffer.from('011c000000000754d4c00e672e75732e6e657875732e626f620304104100', 'hex')
const jsonPacket = packet.deserializeIlpPacket(binaryPacket)
console.log(jsonPacket)
// prints {
//   type: 1,
//   typeString: 'ilp_payment',
//   data: {
//     amount: '123000000',       // Unsigned 64-bit integer as a string
//     account: 'g.us.nexus.bob', // ILP Address
//     data: 'BBBB'               // Base64url-encoded attached data
//   }
// }

Serialize/deserialize ILP Payment Packet

const packet = require('ilp-packet')

const binaryPacket = packet.serializeIlpPayment({
  amount: '123000000',       // Unsigned 64-bit integer as a string
  account: 'g.us.nexus.bob', // ILP Address
  data: 'BBBB'               // Base64url-encoded attached data
}) // returns a Buffer

console.log(binaryPacket.toString('hex'))
// prints '011c000000000754d4c00e672e75732e6e657875732e626f620304104100'

const jsonPacket = packet.deserializeIlpPayment(binaryPacket)

Serialize/deserialize ILQP Quote Requests/Responses

IlqpLiquidityRequest

const packet = require('ilp-packet')

const binary = packet.serializeIlqpLiquidityRequest({
  destinationAccount: 'example.nexus.bob',
  destinationHoldDuration: 3000
})

const json = packet.deserializeIlqpLiquidityRequest(binary)

IlqpLiquidityResponse

const packet = require('ilp-packet')

const binary = packet.serializeIlqpLiquidityResponse({
  liquidityCurve: Buffer.alloc(16), // Must be a buffer of size (n * 16) bytes
                                    // where n is the number of points in the
                                    // curve.
  appliesToPrefix: 'example.nexus.',
  sourceHoldDuration: 15000,
  expiresAt: new Date()
})

const json = packet.deserializeIlqpLiquidityResponse(binary)

IlqpBySourceRequest

const packet = require('ilp-packet')

const binary = packet.serializeIlqpBySourceRequest({
  destinationAccount: 'example.nexus.bob',
  sourceAmount: '9000000000',
  destinationHoldDuration: 3000
})

const json = packet.deserializeIlqpBySourceRequest(binary)

IlqpBySourceResponse

const packet = require('ilp-packet')

const binary = packet.serializeIlqpBySourceResponse({
  destinationAmount: '9000000000',
  sourceHoldDuration: 3000
})

const json = packet.deserializeIlqpBySourceResponse(binary)

IlqpByDestinationRequest

const packet = require('ilp-packet')

const binary = packet.serializeIlqpByDestinationRequest({
  destinationAccount: 'example.nexus.bob',
  destinationAmount: '9000000000',
  destinationHoldDuration: 3000
})

const json = packet.deserializeIlqpByDestinationRequest(binary)

IlqpByDestinationResponse

const packet = require('ilp-packet')

const binary = packet.serializeIlqpByDestinationResponse({
  sourceAmount: '9000000000',
  sourceHoldDuration: 3000
})

const json = packet.deserializeIlqpByDestinationResponse(binary)

IlpError

const packet = require('ilp-packet')

const binary = packet.serializeIlpError({
  code: 'F01',
  name: 'Invalid Packet',
  triggeredBy: 'example.us.ledger3.bob',
  forwardedBy: [
    'example.us.ledger2.connie',
    'example.us.ledger1.conrad'
  ],
  triggeredAt: new Date(),
  data: JSON.stringify({
    foo: 'bar'
  })
})

const json = packet.deserializeIlpError(binary)

const additionalErrorData = JSON.parse(json.data)

IlpFulfillment

const packet = require('ilp-packet')

const binary = packet.serializeIlpFulfillment({
  data: 'BBBB'               // Base64url-encoded attached data
})

const json = packet.deserializeIlpFulfillment(binary)