Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
161 lines (124 sloc) 3.17 KB

Class

Torus

This is the main class of anything related to Torus

const Torus = require("@toruslabs/torus-embed").default;

Using ES6,

import Torus from "@toruslabs/torus-embed";

torusObject

`instance`

All API's can be accessed by creating a new instance of Torus

const torus = new Torus(options);

The Torus constructor takes an object with TorusCtorArgs as input

Parameters

  • options - TorusCtorArgs (optional) : The options of the constructor
    • buttonPosition - enum (optional) : The position of the Torus button. Supported values are top-left bottom-left top-right bottom-right

Returns

  • Object: The torus instance with all its methods and events.

Reference

interface TorusCtorArgs {
  buttonPosition?: "top-left" | "top-right" | "bottom-right" | "bottom-left";
}

Examples

const torus = new Torus();
const torus = new Torus({
  buttonPosition: "top-left" // default: 'bottom-left'
});

init

Initialize the torus object after creation

await torus.init(params);

Parameters

  • params - TorusParams (optional) : The parameters passed to initialize torus object
    • network - NetworkInterface (optional) : The network options. Used for setting a default network
    • buildEnv - enum (optional): The build environment to use. Supported values are production development staging testing
    • enableLogging - boolean (optional) : Enables/disables logging. Useful for debugging
    • showTorusButton - boolean (optional) : Shows/Hides the Torus Button
    • enabledVerifiers - VerifierStatus (optional) : Hides certain types of logins (Default is true)

Returns

  • Promise<void> : Returns a promise which resolves to void

Reference

interface TorusParams {
  network?: NetworkInterface;
  buildEnv?: "production" | "development" | "staging" | "testing";
  enableLogging?: boolean;
  showTorusButton?: boolean;
  enabledVerifiers?: VerifierStatus;
}

interface VerifierStatus {
  google?: boolean;
  facebook?: boolean;
  reddit?: boolean;
  twitch?: boolean;
  discord?: boolean;
}

interface NetworkInterface {
  host:
    | "mainnet"
    | "rinkeby"
    | "ropsten"
    | "kovan"
    | "goerli"
    | "localhost"
    | "matic"
    | string;
  chainId?: number;
  networkName?: string;
}

Examples

await torus.init();
await torus.init({
  network: {
    host: "rinkeby" // default : 'mainnet'
  }
});
await torus.init({
  network: {
    host: "https://ethboston1.skalenodes.com:10062", // mandatory
    chainId: 1, // optional
    networkName: "Skale Network" // optional
  }
});
await torus.init({
  buildEnv: "staging", // uses staging.tor.us
  enableLogging: false, // default : false
  network: {
    host: "kovan" // default : 'mainnet'
  },
  showTorusButton: false, // default: true
  enabledVerifiers: {
    facebook: false // default: true
  }
});
await torus.init({
  network: {
    host: "matic" // mandatory
  },
  showTorusButton: true // default: true
});
You can’t perform that action at this time.