@web5nexus/web3auth-core
Version:
Core Implementation for 1 click Web3 Social Auth Implementation for Ethereum, XDC, Bitcoin,Cosmos and other Altcoins.
251 lines • 8.34 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Web5 = void 0;
const no_modal_1 = require("@web3auth/no-modal");
const base_1 = require("@web3auth/base");
const openlogin_adapter_1 = require("@web3auth/openlogin-adapter");
const wallet_connect_v2_adapter_1 = require("@web3auth/wallet-connect-v2-adapter");
const qrcode_modal_1 = __importDefault(require("@walletconnect/qrcode-modal"));
const chains_1 = __importDefault(require("./chains"));
class Web5 {
constructor(clientId, network) {
this.clientId = clientId;
this.network = network;
this.web3auth = null;
this.web3authProvider = null;
}
async init(blockchain, symbol) {
try {
if (!(blockchain || symbol)) {
throw new Error("At least one of blockchain or symbol must be provided.");
}
let chainConfig;
if (blockchain) {
chainConfig = chains_1.default.find((chain) => chain.blockchain === blockchain);
}
else if (symbol) {
chainConfig = chains_1.default.find((chain) => chain.symbol === symbol);
}
if (!chainConfig) {
throw new Error(`Chain configuration not found for blockchain: ${blockchain || ""} and symbol: ${symbol || ""}`);
}
if (this.web3auth) {
console.log("Web3Auth is already initialized");
return this.web3auth;
}
this.web3auth = new no_modal_1.Web3AuthNoModal({
clientId: this.clientId,
chainConfig: {
chainNamespace: base_1.CHAIN_NAMESPACES.EIP155,
chainId: chainConfig.chainId,
rpcTarget: chainConfig.rpcTarget,
},
web3AuthNetwork: this.network === "TESTNET" ? "testnet" : "cyan",
});
const openloginAdapter = new openlogin_adapter_1.OpenloginAdapter({
adapterSettings: {
whiteLabel: {
name: "Web5 Nexus Login - Secured by Web3Auth",
logoLight: "https://i.ibb.co/D1FBzB1/w5WhiteT.png",
logoDark: "https://i.ibb.co/yShkFGZ/w5BlueT.png",
defaultLanguage: "en",
dark: true,
},
},
});
this.web3auth.configureAdapter(openloginAdapter);
// Adding WalletConnect V2 adapter
const defaultWcSettings = await (0, wallet_connect_v2_adapter_1.getWalletConnectV2Settings)("eip155", [1, 137, 5], "04309ed1007e77d1f119b85205bb779d");
const walletConnectV2Adapter = new wallet_connect_v2_adapter_1.WalletConnectV2Adapter({
adapterSettings: { qrcodeModal: qrcode_modal_1.default, ...defaultWcSettings.adapterSettings },
loginSettings: { ...defaultWcSettings.loginSettings },
});
this.web3auth.configureAdapter(walletConnectV2Adapter);
await this.web3auth.init();
console.log("Web3Auth initialized successfully");
return this.web3auth;
}
catch (error) {
console.error(error);
throw error;
}
}
async facebook() {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "facebook",
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
async google() {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "google",
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
async discord() {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "discord",
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
async twitter() {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "twitter",
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
async reddit() {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "reddit",
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
async twitch() {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "twitch",
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
async apple() {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "apple",
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
async github() {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "github",
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
async linkedin() {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "linkedin",
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
async email(email) {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "email_passwordless",
extraLoginOptions: {
login_hint: email,
}
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
;
async mobile(mobile) {
try {
if (!this.web3auth) {
return;
}
this.web3authProvider = await this.web3auth.connectTo(base_1.WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: "sms_passwordless",
extraLoginOptions: {
login_hint: mobile,
}
});
return this.web3authProvider;
}
catch (error) {
console.error(error);
throw error;
}
}
;
}
exports.Web5 = Web5;
//# sourceMappingURL=social.js.map