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)

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>
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.

Methods

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

Creates a FederationServer instance based on information from digitalbits.toml file for a given domain. Returns a Promise that resolves to a FederationServer object. 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.forAddress('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>
Name Type Attributes Description
allowHttp boolean <optional>

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

Returns:
Type:
Promise

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

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

  • For DigitalBits address (ex. tom*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('tom*digitalbits.io')
 .then(federationRecord => {
   // {
   //   account_id: 'GB5XVAABEQMY63WTHDQ5RXADGYF345VWMNPTN2GFUDZT57D57ZQTJ7PS',
   //   memo_type: 'id',
   //   memo: 100
   // }
 });

It returns a Promise that will resolve to a JSON object with following fields:

  • 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.

The Promise will reject in case of any errors.

Source:
See:
Parameters:
Name Type Attributes Description
value string

DigitalBits Address (ex. tom*digitalbits.io)

opts object <optional>
Name Type Attributes Description
allowHttp boolean <optional>

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

Returns:
Type:
Promise

resolveAccountId(accountId) → {Promise}

Returns a Promise that resolves to federation record if the user was found for a given account ID.

Source:
See:
Parameters:
Name Type Description
accountId string

Account ID (ex. GBYNR2QJXLBCBTRN44MRORCMI4YO7FZPFBCNOKTOBCAAFC7KC3LNPRYS)

Returns:
Type:
Promise

resolveAddress(address) → {Promise}

Returns a Promise that resolves to federation record if the user was found for a given DigitalBits address.

Source:
See:
Parameters:
Name Type Description
address string

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

Returns:
Type:
Promise

resolveTransactionId(transactionId) → {Promise}

Returns a Promise that resolves to federation record if the sender of the transaction was found for a given transaction ID.

Source:
See:
Parameters:
Name Type Description
transactionId string

Transaction ID (ex. 3389e9f0f1a65f19736cacf544c2e825313e8447f569233bb8db39aa607c8889)

Returns:
Type:
Promise