-
-
Save inacali/b14864b2ed91c3e9b9b4b55f3630d0f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const Client = require('ilp-core').Client | |
const crypto = require('crypto') | |
const cc = require('five-bells-condition') | |
const nacl = require('ed25519') | |
const receiver = new Client({ | |
type: 'bells', | |
auth:{ | |
prefix: 'ilpdemo.blue', | |
account: 'https://blue.ilpdemo.org/ledger/accounts/shakur', | |
password: 'olpues5' | |
} | |
}) | |
const seed = new Buffer('833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42', 'hex') | |
const keypair = nacl.MakeKeypair(seed) | |
const privKey = keypair.privateKey | |
const edff = new cc.Ed25519() | |
const setPubKey = edff.setPublicKey(keypair.publicKey) | |
const condition = edff.getConditionUri() | |
const message = new Buffer('Hello World! Conditions are here!') | |
const edfulfill = edff.sign(message, seed) | |
const fulfillment = edff.serializeUri() | |
const parsed = cc.fromFulfillmentUri(fulfillment) | |
const result = cc.validateFulfillment(fulfillment, condition, message) | |
receiver.on('receive', function(transfer){ | |
console.log("Here is the transfer", transfer ) | |
receiver.fulfillCondition(transfer.id, fulfillment) | |
.then(() => { | |
console.log('Successfully submitted fulfillment' + fulfillment) | |
return 'sent' | |
}) | |
.catch((err) => { | |
console.log('Error submitting fulfillment', err) | |
}) | |
}) | |
receiver.on('fulfill_execution_condition', (transfer, fulfilled ) => { | |
console.log('transfer fulfilled', fulfilled) | |
}) | |
receiver.connect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const Client = require('ilp-core').Client | |
const crypto = require('crypto') | |
const cc = require('five-bells-condition') | |
const nacl = require('ed25519') | |
const client = new Client({ | |
type: 'bells', | |
auth:{ | |
prefix: 'ilpdemo.red', | |
account: 'https://red.ilpdemo.org/ledger/accounts/abdi', | |
password: 'olpues123' | |
} | |
}) | |
const seed = new Buffer('833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42', 'hex') | |
const keypair = nacl.MakeKeypair(seed) | |
const edff = new cc.Ed25519() | |
const setPubKey = edff.setPublicKey(keypair.publicKey) | |
const condition = edff.getConditionUri() | |
const paymentParams = { | |
destinationAccount: 'https://blue.ilpdemo.org/ledger/accounts/shakur', | |
destinationAmount: 5, | |
executionCondition: condition, | |
expiresAt: new Date(Date.now() + 10000).toISOString() | |
} | |
client.on('fulfill_execution_condition', (transfer, fulfillment) => { | |
console.log('transfer fulfilled', fulfillment) | |
}) | |
client.connect().then(() => { return client.quote({ | |
destinationLedger: 'https://blue.ilpdemo.org/ledger', | |
destinationAmount: '5' | |
}) | |
}) | |
.then((quote) => { | |
console.log('Quote is: ', quote) | |
return { | |
sourceAmount: String(quote.sourceAmount), | |
connectorAccount: quote.connectorAccount, | |
destinationAmount: String(paymentParams.destinationAmount), | |
destinationAccount: paymentParams.destinationAccount, | |
destinationLedger: 'https://blue.ilpdemo.org/ledger', | |
expiresAt: paymentParams.expiresAt, | |
executionCondition: paymentParams.executionCondition | |
} | |
}) | |
.then((payment) => client.sendQuotedPayment(payment)) | |
.then(() => console.log('payment sent: ', payment)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment