ilp-packet
Module for parsing and serializing ILP packets
Last updated 8 months ago by interledger .
Apache-2.0 · Original npm · Tarball · package.json
$ cnpm install ilp-packet 
SYNC missed versions from official npm registry.

ILP Packet

npm

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')
})

Current Tags

  • 3.1.0-alpha.0                                ...           latest (8 months ago)

26 Versions

  • 3.1.0-alpha.0                                ...           8 months ago
  • 3.0.9                                ...           9 months ago
  • 3.0.8                                ...           2 years ago
  • 3.0.7                                ...           2 years ago
  • 3.0.6                                ...           2 years ago
  • 3.0.5                                ...           2 years ago
  • 3.0.4                                ...           2 years ago
  • 3.0.3                                ...           2 years ago
  • 3.0.2                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.2                                ...           2 years ago
  • 2.1.1                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.7.0                                ...           2 years ago
  • 1.6.0                                ...           3 years ago
  • 1.5.0                                ...           3 years ago
  • 1.4.0                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago

Copyright 2014 - 2016 © taobao.org |