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

PSK2 is a request/response protocol built on ILP that can send value and/or data. It handles generating conditions and fulfillments for ILP Prepare/Fulfill packets to send value, and it encrypts and authenticates request and response data.
PSK2 can be used to send indivdiual payment chunks, unfulfillable test payments for quotes, and it can be used as part of a protocol/module for streaming or chunked payments.
Installation
npm install ilp-protocol-psk2
API Documentation
See https://interledgerjs.github.io/ilp-protocol-psk2
Usage
Creating a Receiver
Uses createReceiver
and Receiver.generateAddressAndSecret
.
const { createReceive } = require('ilp-protocol-psk2')
const receiver = await createReceiver({
plugin: myLedgerPlugin,
requestHandler: (params) => {
params.accept(Buffer.from('thanks for the payment!'))
console.log(`Got paid: ${params.amount} and got this data: ${params.data.toString()}`)
}
})
const { destinationAccount, sharedSecret } = receiver.generateAddressAndSecret()
Try it out by running the example script.
Sending a Request
Uses sendRequest
.
const { sendRequest } = require('ilp-protocol-psk2')
const { destinationAccount, sharedSecret } = await getAddressAndSecretFromReceiver()
const { fulfilled, destinationAmount, data } = await sendRequest(myLedgerPlugin, {
destinationAccount,
sharedSecret,
sourceAmount: '1000',
minDestinationAmount: '500',
data: Buffer.from('here you go!')
})
if (fulfilled) {
console.log(`Sent request with 1000 units of value attached, receiver got ${destinationAmount} and responded with the message: ${data.toString('utf8')}`)
}
Try it out by running the example script.
Sending an Unfulfillable Request or Quote
Uses sendRequest
.
const { sendRequest } = require('ilp-protocol-psk2')
const { randomBytes } = require('crypto')
const { destinationAccount, sharedSecret } = await getAddressAndSecretFromReceiver()
const { destinationAmount } = await sendRequest(myLedgerPlugin, {
destinationAccount,
sharedSecret,
sourceAmount: '1000',
unfulfillableCondition: randomBytes(32)
})
console.log(`Path exchange rate is: ${destinationAmount.dividedBy(1000)}`
Try it out by running the example script.