npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ilp-packet-v1

v2.2.0

Published

Module for parsing and serializing ILP packets

Downloads

1,138

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)

IlpPrepare, IlpFulfill, IlpReject

const packet = 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 = packet.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 = packet.serializeIlpFulfill({
  fulfillment,
  data: Buffer.from('thank you')
})

// not to be confused with IlpRejection:
const binaryReject = packet.serializeIlpReject({
  code: 'F00',
  triggeredBy: 'g.us.nexus.gateway',
  message: 'more details, human-readable',
  data: Buffer.from('more details, machine-readable')
})