New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ilp-protocol-psk2

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ilp-protocol-psk2

Implementation of the ILP Pre-Shared Key V2 Transport Protocol

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

PSKv2

Javascript implementation of the Pre-Shared Key V2 Interledger Transport Protocol.

CircleCI codecov JavaScript Style Guide

Features

  • End-to-End Quoting
  • Single Payments
  • Streaming Payments
  • (Experimental) Chunked Payments

Installation

npm install ilp-protocol-psk2

API Documentation

See https://emschwartz.github.io/ilp-protocol-psk2

Usage

Creating a Receiver

Uses createReceiver and Receiver.generateAddressAndSecret.

import { createReceiver } from 'ilp-protocol-psk2'
const receiver = await createReceiver({
  plugin: myLedgerPlugin,
  paymentHandler: async (params) => {
    // Accept all incoming payments
    const result = await params.accept()
    console.log('Got payment for:', result.receivedAmount)
  }
})

const { destinationAccount, sharedSecret } = receiver.generateAddressAndSecret()
// Give these two values to a sender to enable them to send payments to this Receiver

Sending a Single Payment

Uses sendSingleChunk and quoteDestinationAmount.

import { sendSingleChunk, quoteDestinationAmount } from 'ilp-protocol-psk2'

// These values must be communicated beforehand for the sender to send a payment
const { destinationAccount, sharedSecret } = await getAddressAndSecretFromReceiver()

const { sourceAmount } = await quoteDestinationAmount(myLedgerPlugin, {
  destinationAccount,
  sharedSecret,
  destinationAmount: '1000'
})

const result = await sendSingleChunk(myLedgerPlugin, {
  destinationAccount,
  sharedSecret,
  sourceAmount,
  minDestinationAmount: '999'
})
console.log(`Sent payment of ${result.sourceAmount}, receiver got ${result.destinationAmount}`)

Sending a Streaming Payment

Uses sendSingleChunk.

import { randomBytes } from 'crypto'
import { sendSingleChunk } from 'ilp-protocol-psk2'

// These values must be communicated beforehand for the sender to send a payment
const { destinationAccount, sharedSecret } = await getAddressAndSecretFromReceiver()

const id = randomBytes(16)
let sequence = 0
const firstChunkResult = await sendSingleChunk(myLedgerPlugin, {
  destinationAccount,
  sharedSecret,
  sourceAmount,
  minDestinationAmount: '0',
  id,
  sequence,
  lastChunk: false
})

// Repeat as many times as desired, incrementing the sequence each time
// Note that the path exchange rate can be determined by dividing the destination amount returned by the chunk amount sent

const lastChunkResult = await sendSingleChunk(myLedgerPlugin, {
  destinationAccount,
  sharedSecret,
  sourceAmount,
  minDestinationAmount: '0',
  id,
  sequence,
  lastChunk: true
})

Experimental Chunked Payments

WARNING: PSK2 Chunked Payments are experimental. Money can be lost if an error occurs mid-payment or if the exchange rate changes dramatically! This should not be used for payments that are significantly larger than the path's Maximum Payment Size.

See sendSourceAmount and sendDestinationAmount.

Keywords

FAQs

Package last updated on 12 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc