No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Bifrost 0.0.2 changes Apr 18, 2018
.gitignore Add /dist to .gitignore Dec 5, 2017
.travis.yml Fix GH token Dec 5, 2017
README.md Merge branch 'master' of github.com:stellar/bifrost-js-sdk Apr 18, 2018
example.html Bifrost 0.0.2 changes Apr 18, 2018
gulpfile.js Init Oct 25, 2017
package.json Init Oct 25, 2017
yarn.lock Init Oct 25, 2017

README.md

bifrost-js-sdk

JS SDK for Bifrost.

Usage

<script src="bifrost.min.js"></script>

API

Bifrost.Session.constructor(params) => Bifrost.Session

Represents Bifrost session with params parameters.

params is an object with the following fields:

Name Possible Values Description
network test or live Stellar network to use
bifrostURL string URL of Bifrost server
horizonURL string URL of Horizon server (do not use SDF's servers!)
horizonAllowHttp boolean (Optional) If set to true allows HTTP connections to Horizon server. Useful for testing.
recoveryPublicKey string Public key of Stellar account where lumens will be sent in case of failures. (Optional but recommended.)

Example:

var params = {
  network: 'test',
  horizonURL: 'https://horizon-testnet.stellar.org',
  bifrostURL: 'http://localhost:8000'
};

var session = new Bifrost.Session(params);

Bifrost.Session.startBitcoin(onEvent) => Promise

Starts Bitcoin session and returns a promise that resolves with Bitcoin address where to send funds and Stellar keypair. Once the session is started, no other session can be created using the same object. You need to create a new one.

Example:

session.startBitcoin(onEvent).then({address, keypair} => {
  document.getElementById("status").innerText = "Waiting for a transaction...";
  document.getElementById("address").innerText = address;
  document.getElementById("public-key").innerText = keypair.publicKey();
  document.getElementById("secret").innerText = keypair.secret();
})

onEvent description can be found in the section below.

Bifrost.Session.startEthereum(onEvent) => Promise

Starts Ethereum session and returns a promise that resolves with Ethereum address where to send funds and Stellar keypair. Once the session is started, no other session can be created using the same object. You need to create a new one.

Example:

session.startEthereum(onEvent).then({address, keypair} => {
  document.getElementById("status").innerText = "Waiting for a transaction...";
  document.getElementById("address").innerText = address;
  document.getElementById("public-key").innerText = keypair.publicKey();
  document.getElementById("secret").innerText = keypair.secret();
})

onEvent description can be found in the section below.

onEvent(event, data)

onEvent function you pass to startBitcoin or startEthereum function accepts one parameter event described below:

event data Description
Bifrost.TransactionReceivedEvent none Sent when BTC/ETH transaction is received
Bifrost.AccountCreatedEvent none Sent when account is created
Bifrost.AccountConfiguredEvent none Sent when account has been configured
Bifrost.ExchangedEvent none Sent when tokens have been exchanged
Bifrost.ExchangedTimelockedEvent {transaction} Sent when tokens have been exchanged but access to account is locked (lock_unix_timestamp config config parameter in Bifrost). data object contains transaction XDR that unlocks account after specified time.
Bifrost.ErrorEvent Error object Sent when asynchronous, non-recoverable error occured

Example:

function onEvent(event, data) {
  if (event == Bifrost.TransactionReceivedEvent) {
    setStatus("Transaction received, creating account...", 20)
  } else if (event == Bifrost.AccountCreatedEvent) {
    setStatus("Account created, configuring account...", 40)
  } else if (event == Bifrost.AccountConfiguredEvent) {
    setStatus("Account configured, waiting for tokens...", 60)
  } else if (event == Bifrost.ExchangedEvent) {
    setStatus("Congrats! TOKE purchased. Your Stellar keys: <pre>Public key: "+keypair.publicKey()+"\nSecret key: "+keypair.secret()+"</pre>", 100);
  } else if (event == Bifrost.ExchangedTimelockedEvent) {
    setStatus("Congrats! TOKE purchased but will be locked. Your Stellar keys: <pre>Public key: "+keypair.publicKey()+"\nSecret key: "+keypair.secret()+"</pre>\nUnlock transaction: <pre>"+data.transaction+"</pre>", 100);
  } else if (event == Bifrost.ErrorEvent) {
    setStatus("Error!", 0);
    // Sent data to the log server.
  }
}