diff --git a/packages/sdk/src/core/sdk/adena-sdk.ts b/packages/sdk/src/core/sdk/adena-sdk.ts index d6123d0..70cc0ab 100644 --- a/packages/sdk/src/core/sdk/adena-sdk.ts +++ b/packages/sdk/src/core/sdk/adena-sdk.ts @@ -1,5 +1,5 @@ import { Wallet } from '@gnolang/tm2-js-client'; -import { AdenaWalletProvider, GnoSocialWalletProvider, GnoWalletProvider } from '../../providers'; +import { AdenaWalletProvider, GnoWalletProvider } from '../../providers'; import { ConnectionManager, ConnectionState } from '../connection'; import { addEstablish, @@ -18,7 +18,7 @@ import { switchNetwork, } from '../methods'; import { WalletProvider } from '../providers'; -import { SDKConfigure, SocialConfigure } from '../types'; +import { SDKConfigure } from '../types'; import { AddEstablishOptions, AddEstablishResponse, @@ -200,8 +200,4 @@ export class AdenaSDK { public static createGnoWallet(wallet: Wallet, config?: SDKConfigure): AdenaSDK { return new AdenaSDK(new GnoWalletProvider(wallet), config); } - - public static createGnoSocialWallet(config: SocialConfigure & SDKConfigure): AdenaSDK { - return new AdenaSDK(GnoSocialWalletProvider.create(config), config); - } } diff --git a/packages/sdk/src/core/types/config.types.ts b/packages/sdk/src/core/types/config.types.ts index 4147bcb..fd42d25 100644 --- a/packages/sdk/src/core/types/config.types.ts +++ b/packages/sdk/src/core/types/config.types.ts @@ -6,14 +6,33 @@ export interface SDKConnectionConfigure { isSession?: boolean; } -export interface SocialConfigure { +interface SocialBaseConfigure { chainId: string; + name: string; rpcTarget: string; network: 'mainnet' | 'testnet'; clientId: string; - auth: { - googleName: string; - googleVerifier: string; - googleClientId: string; - }; +} + +export interface SocialGoogleConfigure extends SocialBaseConfigure { + authClientId: string; + verifier: string; +} + +export interface SocialTwitterConfigure extends SocialBaseConfigure { + authClientId: string; + verifier: string; + domain: string; +} + +export interface SocialCustomConfigure extends SocialBaseConfigure { + authClientId: string; + verifier: string; + domain: string; +} + +export enum SocialType { + GOOGLE = 'GOOGLE', + TWITTER = 'TWITTER', + EMAIL = 'EMAIL', } diff --git a/packages/sdk/src/providers/gno-wallet/gno-social-wallet.ts b/packages/sdk/src/providers/gno-wallet/gno-social-wallet.ts index cac20fc..e569a07 100644 --- a/packages/sdk/src/providers/gno-wallet/gno-social-wallet.ts +++ b/packages/sdk/src/providers/gno-wallet/gno-social-wallet.ts @@ -4,16 +4,18 @@ import { CommonPrivateKeyProvider } from '@web3auth/base-provider'; import { Web3AuthNoModal } from '@web3auth/no-modal'; import { OpenloginAdapter } from '@web3auth/openlogin-adapter'; -import { SocialConfigure } from '../../core'; +import { SocialCustomConfigure, SocialGoogleConfigure, SocialTwitterConfigure, SocialType } from '../../core'; import { hexToUint8Array } from '../../core/utils/encode.utils'; import { GnoWalletProvider } from './gno-wallet'; export class GnoSocialWalletProvider extends GnoWalletProvider { private web3auth: Web3AuthNoModal; + private socialType: SocialType; - constructor(web3auth: Web3AuthNoModal) { + constructor(web3auth: Web3AuthNoModal, socialType: SocialType) { super(); this.web3auth = web3auth; + this.socialType = socialType; } public async connect(): Promise { @@ -52,7 +54,9 @@ export class GnoSocialWalletProvider extends GnoWalletProvider { private async connectWeb3Auth(): Promise { return this.web3auth - .connectTo(WALLET_ADAPTERS.OPENLOGIN, { loginProvider: 'google' }) + .connectTo(WALLET_ADAPTERS.OPENLOGIN, { + loginProvider: this.socialType, + }) .then(() => true) .catch((error) => { if (error?.name === 'WalletLoginError') { @@ -73,14 +77,99 @@ export class GnoSocialWalletProvider extends GnoWalletProvider { return `${privateKey}`; } - public static create(config: SocialConfigure) { + public static createGoogle(config: SocialGoogleConfigure) { + const socialType = SocialType.GOOGLE; const chainConfig: CustomChainConfig = { + displayName: 'Gno.land', + tickerName: 'Gno.land', + ticker: 'ugnot', chainNamespace: 'other', chainId: config.chainId, rpcTarget: config.rpcTarget, + }; + + const web3auth = new Web3AuthNoModal({ + clientId: config.clientId, + web3AuthNetwork: config.network, + chainConfig, + }); + + const privateKeyProvider = new CommonPrivateKeyProvider({ + config: { chainConfig }, + }); + + const openloginAdapter = new OpenloginAdapter({ + privateKeyProvider: privateKeyProvider, + adapterSettings: { + clientId: config.clientId, + uxMode: 'popup', + loginConfig: { + [socialType]: { + typeOfLogin: 'google', + name: config.name, + clientId: config.authClientId, + verifier: config.verifier, + }, + }, + }, + }); + web3auth.configureAdapter(openloginAdapter); + return new GnoSocialWalletProvider(web3auth, socialType); + } + + public static createTwitter(config: SocialTwitterConfigure) { + const socialType = SocialType.TWITTER; + const chainConfig: CustomChainConfig = { displayName: 'Gno.land', + tickerName: 'Gno.land', ticker: 'ugnot', + chainNamespace: 'other', + chainId: config.chainId, + rpcTarget: config.rpcTarget, + }; + + const web3auth = new Web3AuthNoModal({ + clientId: config.clientId, + web3AuthNetwork: config.network, + chainConfig, + }); + + const privateKeyProvider = new CommonPrivateKeyProvider({ + config: { chainConfig }, + }); + + const openloginAdapter = new OpenloginAdapter({ + privateKeyProvider: privateKeyProvider, + adapterSettings: { + uxMode: 'popup', + loginConfig: { + [socialType]: { + typeOfLogin: 'twitter', + name: config.name, + verifier: config.verifier, + clientId: config.authClientId, + jwtParameters: { + connection: 'twitter', + verifierIdField: 'sub', + domain: config.domain, + }, + }, + }, + }, + }); + web3auth.configureAdapter(openloginAdapter); + return new GnoSocialWalletProvider(web3auth, socialType); + } + + public static createEmail(config: SocialCustomConfigure) { + const socialType = SocialType.EMAIL; + const chainConfig: CustomChainConfig = { + displayName: 'Gno.land', tickerName: 'Gno.land', + ticker: 'ugnot', + chainNamespace: 'other', + chainId: config.chainId, + rpcTarget: config.rpcTarget, }; const web3auth = new Web3AuthNoModal({ @@ -96,19 +185,23 @@ export class GnoSocialWalletProvider extends GnoWalletProvider { const openloginAdapter = new OpenloginAdapter({ privateKeyProvider: privateKeyProvider, adapterSettings: { - clientId: config.clientId, uxMode: 'popup', loginConfig: { - google: { - typeOfLogin: 'google', - name: config.auth.googleName, - verifier: config.auth.googleVerifier, - clientId: config.auth.googleClientId, + [socialType]: { + typeOfLogin: 'jwt', + name: config.name, + verifier: config.verifier, + clientId: config.authClientId, + jwtParameters: { + verifierIdField: 'email', + domain: config.domain, + login_hint: '', + }, }, }, }, }); web3auth.configureAdapter(openloginAdapter); - return new GnoSocialWalletProvider(web3auth); + return new GnoSocialWalletProvider(web3auth, socialType); } }