web3auth/torus dependencies we have in the project
{
"dependencies": {
...
"@toruslabs/fetch-node-details": "^13.1.1",
"@toruslabs/torus.js": "^12.1.0",
...
"@web3auth/base": "^7.0.1",
"@web3auth/base-provider": "^7.0.1",
"@web3auth/no-modal": "^7.0.1",
"@web3auth/openlogin-adapter": "^7.0.1",
"@web3auth/single-factor-auth": "https://github.com/nufi-official/single-factor-auth-web/releases/download/discord_support/web3auth-single-factor-auth-7.2.2.tgz",
}
}
relevant login code
import {Web3AuthNoModal} from '@web3auth/no-modal'
import {OpenloginAdapter, OpenloginUserInfo} from '@web3auth/openlogin-adapter'
import {CHAIN_NAMESPACES, WALLET_ADAPTERS} from '@web3auth/base'
import {CommonPrivateKeyProvider} from '@web3auth/base-provider'
const chainConfig = {
chainNamespace: CHAIN_NAMESPACES.OTHER,
// these are just dummy values, they are not used,
// but without them Web3Auth throws an error
chainId: '0x1',
rpcTarget: 'https://dummy.target',
displayName: '',
blockExplorer: '',
ticker: '',
tickerName: '',
}
const web3Auth = new Web3AuthNoModal({
clientId: web3AuthClientId,
web3AuthNetwork,
chainConfig,
sessionTime,
})
const privateKeyProvider = new CommonPrivateKeyProvider({
config: {chainConfig},
})
const openloginAdapter = new OpenloginAdapter({
privateKeyProvider,
adapterSettings: {
clientId: web3AuthClientId,
network: web3AuthNetwork,
uxMode: 'popup',
},
})
web3Auth.configureAdapter(openloginAdapter)
await web3Auth.init()
if (web3Auth.connected) {
await web3Auth.logout()
}
const provider = await web3Auth.connectTo(WALLET_ADAPTERS.OPENLOGIN, {
mfaLevel: 'none', // Pass on the mfa level of your choice: default, optional, mandatory, none
loginProvider,
})
const privateKey = Buffer.from(
(await web3Auth.provider!.request({
method: 'private_key',
})) as string,
'hex',
)
const userInfo = await web3Auth.getUserInfo()
return {
privateKey,
userInfo,
}