# ilp-plugin-btp

> Generic BTP plugin for ILP

Latest version **1.5.0** (published 2021-02-25) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install ilp-plugin-btp
pnpm add ilp-plugin-btp
yarn add ilp-plugin-btp
bun add ilp-plugin-btp
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.0 |
| Published | 2021-02-25 |
| First published | 2017-12-31 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 8 |
| Unpacked size | 95.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Interledger Team |
| Maintainers | interledger |

## Links

- npm: https://www.npmjs.com/package/ilp-plugin-btp
- Repository: https://github.com/interledgerjs/ilp-plugin-btp
- Homepage: https://github.com/interledgerjs/ilp-plugin-btp#readme
- Issues: https://github.com/interledgerjs/ilp-plugin-btp/issues
- npm.io page: https://npm.io/package/ilp-plugin-btp

## Dependencies (8)

- [ws](https://npm.io/package/ws.md) ^6.0.0
- [debug](https://npm.io/package/debug.md) ^3.1.0
- [@types/ws](https://npm.io/package/@types/ws.md) ^6.0.0
- [btp-packet](https://npm.io/package/btp-packet.md) ^2.2.0
- [ilp-logger](https://npm.io/package/ilp-logger.md) ^1.1.3
- [@types/node](https://npm.io/package/@types/node.md) ^10.7.1
- [@types/debug](https://npm.io/package/@types/debug.md) 0.0.30
- [eventemitter2](https://npm.io/package/eventemitter2.md) ^5.0.0

## Recent versions

- 1.5.0 (latest) — 2021-02-25
- 1.4.2 — 2019-09-30
- 1.4.1 — 2019-09-25
- 1.4.0 — 2019-09-25
- 1.3.11 — 2019-05-16
- 1.3.10 — 2019-03-12
- 1.3.8 — 2019-02-26
- 1.3.7 — 2018-12-10
- 1.3.6 — 2018-12-07
- 1.3.5 — 2018-12-03
- 1.3.4 — 2018-10-23
- 1.3.3 — 2018-10-19
- 1.3.2 — 2018-09-13
- 1.3.1 — 2018-09-12
- 1.3.0 — 2018-09-08
- … 20 more at https://npm.io/package/ilp-plugin-btp/versions

## README

# ILP Plugin BTP
> One plugin to rule them all

[![NPM Package](https://img.shields.io/npm/v/ilp-plugin-btp.svg?style=flat)](https://npmjs.org/package/ilp-plugin-btp)
[![CircleCI](https://circleci.com/gh/interledgerjs/ilp-plugin-btp.svg?style=shield)](https://circleci.com/gh/interledgerjs/ilp-plugin-btp)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![Known Vulnerabilities](https://snyk.io/test/github/interledgerjs/ilp-plugin-btp/badge.svg)](https://snyk.io/test/github/interledgerjs/ilp-plugin-btp) [![Greenkeeper badge](https://badges.greenkeeper.io/interledgerjs/ilp-plugin-btp.svg)](https://greenkeeper.io/)

Used right out of the box, this plugin is capable of representing a data
channel with no money involved. It will send BTP messages with no knowledge
of the data within, so it can be used for ILP packets. The `sendMoney` function
is a no-op, because there is no system involved handling money.

The main use of this plugin, however, is as a building block for plugins that
do have an underlying ledger. In this way, it's the successor of
[`ilp-plugin-payment-channel-framework`](https://github.com/interledgerjs/ilp-plugin-payment-channel-framework)

Plugins that sub-class the `AbstractBtpPlugin` should override `sendMoney` and `_handleMoney` at least.

## Use as a Data Channel for ILP

```js
const server = new BtpPlugin({
  listener: {
    port: 9000,
    secret: 'shh_its_a_secret'
  }
})

await server.connect()

const client = new BtpPlugin({
  server: 'btp+ws://:shh_its_a_secret@localhost:9000'
})

await client.connect()

server.registerDataHandler(serverHandler)
client.registerDataHandler(clientHandler)

await client.sendData(IlpPacket.serializeIlpPrepare({
  // ...
})
```

## Use as a Base Class for a New Plugin

Two functions must be defined in order for the plugin to handle money.

* `sendMoney (amount: string) -> Promise<null>`: sends `amount` of units to the peer. This should be done via a BTP `TRANSFER` call.
* `_handleMoney (from: string, btpPacket: BtpPacket) -> Promise<Array<BtpSubProtocol>>`: This function is called on an incoming BTP `TRANSFER`.

BtpSubProtocol is made up of:

* `protocolName: string`: The name of this side protocol. ILP-level information must be named `ilp`.
* `contentType: number`: The content type. 0 is `application/octet-stream`, 1 is `text/plain-utf8`, and 2 is `application/json`. Mainly used for logging and smart deserializing.
* `data: buffer`: The actual protocol data.

---
_Source: https://npm.io/package/ilp-plugin-btp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
