FederationServer

FederationServer

FederationServer handles a network connection to a federation server instance and exposes an interface for requests to that instance.

Constructor

new FederationServer(serverURL, domain, optsopt) → {void}

Source:
Parameters:
Name Type Attributes Description
serverURL string

The federation server URL (ex. https://acme.com/federation).

domain string

Domain this server represents

opts object <optional>

options object

Name Type Attributes Description
allowHttp boolean <optional>

Allow connecting to http servers, default: false. This must be set to false in production deployments! You can also use Config class to set this globally.

timeout number <optional>

Allow a timeout, default: 0. Allows user to avoid nasty lag due to TOML resolve issue. You can also use Config class to set this globally.

Returns:
Type:
void

Methods

(static) createForDomain(domain, optsopt) → {Promise}

Creates a FederationServer instance based on information from digitalbits.toml file for a given domain.

If digitalbits.toml file does not exist for a given domain or it does not contain information about a federation server Promise will reject.

DigitalBitsSdk.FederationServer.createForDomain('acme.com')
  .then(federationServer => {
    // federationServer.resolveAddress('bob').then(...)
  })
  .catch(error => {
    // digitalbits.toml does not exist or it does not contain information about federation server.
  });
Source:
See:
Parameters:
Name Type Attributes Description
domain string

Domain to get federation server for

opts object <optional>

Options object

Name Type Attributes Description
allowHttp boolean <optional>

Allow connecting to http servers, default: false. This must be set to false in production deployments!

timeout number <optional>

Allow a timeout, default: 0. Allows user to avoid nasty lag due to TOML resolve issue.

Returns:
Type:
Promise

Promise that resolves to a FederationServer object

(static) resolve(value, optsopt) → {Promise}

A helper method for handling user inputs that contain destination value. It accepts two types of values:

  • For DigitalBits address (ex. bob*digitalbits.io) it splits DigitalBits address and then tries to find information about federation server in digitalbits.toml file for a given domain. It returns a Promise which resolves if federation server exists and user has been found and rejects in all other cases.
  • For Account ID (ex. GB5XVAABEQMY63WTHDQ5RXADGYF345VWMNPTN2GFUDZT57D57ZQTJ7PS) it returns a Promise which resolves if Account ID is valid and rejects in all other cases. Please note that this method does not check if the account actually exists in a ledger.

Example:

DigitalBitsSdk.FederationServer.resolve(' bob*digitalbits.io')
 .then(federationRecord => {
   // {
   //   account_id: 'GB5XVAABEQMY63WTHDQ5RXADGYF345VWMNPTN2GFUDZT57D57ZQTJ7PS',
   //   memo_type: 'id',
   //   memo: 100
   // }
 });
Source:
See:
Parameters:
Name Type Attributes Description
value string

DigitalBits address (ex. bob*digitalbits.io)

opts object <optional>

Options object

Name Type Attributes Description
allowHttp boolean <optional>

Allow connecting to http servers, default: false. This must be set to false in production deployments!

timeout number <optional>

Allow a timeout, default: 0. Allows user to avoid nasty lag due to TOML resolve issue.

Returns:
Type:
Promise

Promise that resolves to a JSON object with this shape:

  • account_id - Account ID of the destination,
  • memo_type (optional) - Memo type that needs to be attached to a transaction,
  • memo (optional) - Memo value that needs to be attached to a transaction.

resolveAccountId(accountId) → {Promise}

Given an account ID, get their federation record if the user was found

Source:
See:
Parameters:
Name Type Description
accountId string

Account ID (ex. GBYNR2QJXLBCBTRN44MRORCMI4YO7FZPFBCNOKTOBCAAFC7KC3LNPRYS)

Returns:
Type:
Promise

A promise that resolves to the federation record

resolveAddress(address) → {Promise}

Get the federation record if the user was found for a given DigitalBits address

Source:
See:
Parameters:
Name Type Description
address string

DigitalBits address (ex. bob*digitalbits.io). If FederationServer was instantiated with domain param only username (ex. bob) can be passed.

Returns:
Type:
Promise

Promise that resolves to the federation record

resolveTransactionId(transactionId) → {Promise}

Given a transactionId, get the federation record if the sender of the transaction was found

Source:
See:
Parameters:
Name Type Description
transactionId string

Transaction ID (ex. 3389e9f0f1a65f19736cacf544c2e825313e8447f569233bb8db39aa607c8889)

Returns:
Type:
Promise

A promise that resolves to the federation record