| description | create, initialize, and clean up a Torus web3 instance. |
|---|
This is the main class of anything related to Torus
const Torus = require("@toruslabs/torus-embed");Using ES6,
import Torus from "@toruslabs/torus-embed";Then, create 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 constructorbuttonPosition-enum(optional) : The position of the Torus button. Supported values aretop-leftbottom-lefttop-rightbottom-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'
});Initialize the torus object after creation
await torus.init(params);Parameters
params-TorusParams(optional) : The parameters passed to initialize Torus objectnetwork-NetworkInterface(optional) : The network options. Used for setting a default networkbuildEnv-enum(optional): The build environment to use. Supported values areproductiondevelopmentstagingtestingenableLogging-boolean(optional) : Enables/disables logging. Useful for debuggingshowTorusButton-boolean(optional) : Shows/Hides the Torus ButtonenabledVerifiers-VerifierStatus(optional) : Hides certain types of logins (default is true)integrity-IntegrityParams(optional) : Enables optional integrity checking (default is false)loginConfig- Array of login config items. Used to modify the default logins/ add new logins. Read more on Login Config.
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;
integrity?: IntegrityParams;
loginConfig?: LoginConfig;
}
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;
}
interface IntegrityParams {
check: boolean;
hash?: string;
version?: 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
});Array of login config items. Used to modify the default logins/ add new logins under torus.init.
await torus.init({
loginConfig: {
[verifier]: loginConfigItem
}
});Parameters
loginConfig-LoginConfig(optional) : Array of login configuration per verifierverifier- Verifier provided by torus as a key or a default verifier used by torus
loginConfigItem-LoginConfigItem: parameters per verifiertypeOfLogin-LOGIN_TYPE: The type of logindescription-string(optional) : Description for button. If provided, it renders as a full length button. else, icon buttonclientId-string(optional) : Custom client_id. If not provided, we use the default for torus applogoHover-string(optional) : Logo to be shown on mouse hover. If not provided, we use the default for torus applogoLight-string(optional): Logo to be shown on dark background (dark theme). If not provided, we use the default for torus applogoDark-string(optional): Logo to be shown on light background (light theme). If not provided, we use the default for torus appshowOnModal-boolean(optional): Whether to show the login button on modal or notjwtParameters-JwtParameters(optional): Custom JWT parameters to configure the login. Useful for Auth0 configuration
Reference
type LOGIN_TYPE =
| 'google'
| 'facebook'
| 'reddit'
| 'discord'
| 'twitch'
| 'apple'
| 'github'
| 'linkedin'
| 'twitter'
| 'weibo'
| 'line'
| 'jwt'
| 'email-password'
| 'passwordless'
interface LoginConfig {
}
interface LoginConfigItem {
typeOfLogin: LOGIN_TYPE
description?: string
clientId?: string
logoHover?: string
logoLight?: string
logoDark?: string
showOnModal?: boolean
jwtParameters?: JwtParameters
}
interface JwtParameters {
domain: string;
client_id?: string;
redirect_uri?: string;
leeway?: number;
verifierIdField?: string;
}Example
await torus.init({
loginConfig: {
'google': {
description: 'Login with google',
clientId: 'CLIENT_ID',
logoHover: 'https://sample.com/google-logo-hover.svg',
logoLight: 'https://sample.com/google-logo-light.svg',
logoDark: 'https://sample.com/google-logo-dark.svg',
showOnModal: true,
},
},
})This cleans up the iframe and buttons created by torus package. If the user is logged in, it logs him out first and then cleans up.
await torus.cleanUp();Returns
Promise<void>: Returns a promise which resolves to void.
Examples
await torus.cleanUp();