JSPM

  • Created
  • Published
  • Downloads 1877
  • Score
    100M100P100Q117043F
  • License Apache-2.0

Module for parsing and serializing ILP packets

Package Exports

  • ilp-packet
  • ilp-packet/dist/src/errors

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

Greenkeeper badge npm circle codecov

A serializer and deserializer for ILP packets and messages

Usage

Installation

npm install ilp-packet

Deserialize any ILP packet

const IlpPacket = require('ilp-packet')

const binaryPacket = Buffer.from('0c68000000000000006b323031373132323330313231343035343974e1136dc71c9e5f283bec83461cbf1261c4014f72d48f8dd65453a0b84e7de10d6578616d706c652e616c696365205db343fdc41898f6df4202329139dc242dd0f558a811b46b28918fdab37c6cb0', 'hex')
const jsonPacket = IlpPacket.deserializeIlpPacket(binaryPacket)
console.log(jsonPacket)
// {
//   type: 12,
//   typeString: 'ilp_prepare',
//   data: {
//     amount: '107',
//     executionCondition: Buffer.from('dOETbcccnl8oO+yDRhy/EmHEAU9y1I+N1lRToLhOfeE=', 'base64')
//     expiresAt: new Date('2017-12-23T01:21:40.549Z'),
//     destination: 'example.alice',
//     data: Buffer.from('XbND/cQYmPbfQgIykTncJC3Q9VioEbRrKJGP2rN8bLA=', 'base64')
//   }
// }

Serialize PREPARE, FULFILL, REJECT

const IlpPacket = require('ilp-packet')
const crypto = require('crypto')
function sha256 (preimage) {
  return crypto.createHash('sha256').update(preimage).digest()
}

const fulfillment = crypto.randomBytes(32)
const condition = sha256(fulfillment)

const binaryPrepare = IlpPacket.serializeIlpPrepare({
  amount: '10',
  executionCondition: condition,
  destination: 'g.us.nexus.bob', // this field was called 'account' in older packet types
  data: Buffer.from('hello world'),
  expiresAt: new Date(new Date().getTime() + 10000)
})

const binaryFulfill = IlpPacket.serializeIlpFulfill({
  fulfillment,
  data: Buffer.from('thank you')
})

const binaryReject = IlpPacket.serializeIlpReject({
  code: 'F00',
  triggeredBy: 'g.us.nexus.gateway',
  message: 'more details, human-readable',
  data: Buffer.from('more details, machine-readable')
})