Skip to content

Instantly share code, notes, and snippets.

Avatar

Evan Schwartz emschwartz

View GitHub Profile
@emschwartz
emschwartz / output.console
Last active Jun 12, 2019
STREAM Example Output
View output.console
ilp-protocol-stream git:master ❯ node example.js ⏎
server generated ILP address (test.amundsen.bmp.btp18q1xrp.tPcfTiM2_-stOLrODMIQbFX7BLln60TC8qy2BefdDsQ.local.X22YdPW64RhBKHCHYYjVDnpz7x83I76gbWq6_JY4Ngs.PNOMQrElaGRlc5VK2uKIFSug) and shared secret (e945dd40aecfe9191e83e8dce2ab81d1fe4760c9ef5a0f71b227adc9308ca173) for client
server got connection
sending data to server on stream 1
sending data to server on stream 3
sending money to server on stream 1
server got a new stream: 1
server got a new stream: 3
server stream 1 got incoming payment for: 100
server stream 1 got data: hello there!
@emschwartz
emschwartz / client-snippet.js
Created May 18, 2018
STREAM Client Snippet
View client-snippet.js
const clientPlugin = createPlugin()
const clientConn = await IlpStream.createConnection({
plugin: clientPlugin,
destinationAccount,
sharedSecret
})
// Streams are automatically given ids (client-initiated ones are odd, server-initiated are even)
const streamA = clientConn.createStream()
const streamB = clientConn.createStream()
@emschwartz
emschwartz / server-snippet.js
Created May 18, 2018
STREAM Server Snippet
View server-snippet.js
const IlpStream = require('ilp-protocol-stream')
const createPlugin = require('ilp-plugin')
const serverPlugin = createPlugin()
const server = await IlpStream.createServer({
plugin: serverPlugin
})
server.on('connection', (connection) => {
console.log('server got connection')
@emschwartz
emschwartz / all.js
Last active Jun 12, 2019
STREAM Example
View all.js
const IlpStream = require('ilp-protocol-stream')
const createPlugin = require('ilp-plugin')
// Note this requires a local moneyd instance to work
// See https://github.com/interledgerjs/moneyd for instructions
async function run () {
const serverPlugin = createPlugin()
const server = await IlpStream.createServer({
plugin: serverPlugin
View client.js
const { createConnection } = require('ilp-protocol-stream')
const getPlugin = require('ilp-plugin')
async function run () {
const clientPlugin = getPlugin()
const connection = await createConnection({
plugin: clientPlugin,
// These are the ILP address and secret from the server
destinationAccount,
sharedSecret
View socket-test.js
const net = require('net')
const server = net.createServer((connection) => {
connection.on('close', () => console.log('server close'))
connection.on('end', () => console.log('server end'))
connection.on('error', () => console.log('server error'))
connection.on('finish', () => console.log('server finish'))
connection.on('data', (chunk) => console.log('server got data', chunk.length))
//setTimeout(() => console.log('reading data', connection.read(1000)), 10)
@emschwartz
emschwartz / README.md
Last active Jan 31, 2018
PSK2 take 2
View README.md

Motivation for changing PSK2 Draft 1

Draft 1 of PSK2 attempts to support both streaming and chunked payments. However, it includes some features that are only useful for chunked payments and does not include some others that would be needed for a proper chunked payments implementation.

Based on a conversation with @sharafian, this proposes narrowing the scope of PSK2 while making it easier to build use cases like streaming and chunked payments on top.

For context, @justmoon had the idea to use PSK2 for "payment sockets", which I started implementing yesterday. However, @sharafian made the point that for many receiver use cases, it's better for the PSK2 receiver not to keep state but to simply call a callback for every chunk it gets. Applications will figure out their own logic for which chunks to accept and how to track the balance for different users or interactions. Therefore, PSK2 doesn't need the fields that are specifically fo

@emschwartz
emschwartz / README.md
Last active Dec 1, 2017
Merging lesson from ILP 2/3 back into ILPv1
View README.md

Lessons

  1. Focus on small payments and have connector limit bandwidth per user
  2. Focus on payment channels for cryptocurrencies instead of escrow or trustlines
  3. We need a production-ready open source connector ASAP

Steps to a real-money-ready connector

Must-Haves

  • Add fulfillment data
@emschwartz
emschwartz / plugin-test.js
Last active Jun 12, 2019
Testing a Ledger Plugin
View plugin-test.js
// Requires Node.js 7.9 or 7.10
// Also make sure to "npm install moment uuid"
const Plugin = require('./')
const crypto = require('crypto')
const moment = require('moment')
const uuid = require('uuid/v4')
function hash (fulfillment) {
const h = crypto.createHash('sha256')
@emschwartz
emschwartz / README.md
Last active Sep 28, 2019
1st ETH -> XRP Interledger Escrow Payment
View README.md

1st ETH -> XRP Interledger Escrow Payment

Here are the transaction IDs (and links to the block explorers) for the first livenet Ethereum and Ripple Consensus Ledger (RCL) escrowed transfers comprising an Interledger payment.

  1. Ethereum prepare: 0x00cbb6149b9cfb3cedf280251c3060b2a38776fa7792b578b6f9f39ce5ee0266
  2. RCL prepare: 7F0A5F16C84568D96DA6A66058CD9EAA881236237642BF7427A458957A752B6B
  3. RCL fulfill: 12A4CAFAE95254844513C5C11488A1195C08DEFF673C97AC74AAC121935DDE36
  4. Ethereum fulfill: 0xb59dd839ab0b5e7d4e663b7cfc0ddb70eaf73dd2785b3d3a4abdf1a61817007d

SHA-256 Condition: `d2