@@ -4,16 +4,18 @@ import { CommonPrivateKeyProvider } from '@web3auth/base-provider';
44import { Web3AuthNoModal } from '@web3auth/no-modal' ;
55import { OpenloginAdapter } from '@web3auth/openlogin-adapter' ;
66
7- import { SocialConfigure } from '../../core' ;
7+ import { SocialCustomConfigure , SocialGoogleConfigure , SocialTwitterConfigure , SocialType } from '../../core' ;
88import { hexToUint8Array } from '../../core/utils/encode.utils' ;
99import { GnoWalletProvider } from './gno-wallet' ;
1010
1111export class GnoSocialWalletProvider extends GnoWalletProvider {
1212 private web3auth : Web3AuthNoModal ;
13+ private socialType : SocialType ;
1314
14- constructor ( web3auth : Web3AuthNoModal ) {
15+ constructor ( web3auth : Web3AuthNoModal , socialType : SocialType ) {
1516 super ( ) ;
1617 this . web3auth = web3auth ;
18+ this . socialType = socialType ;
1719 }
1820
1921 public async connect ( ) : Promise < boolean > {
@@ -52,7 +54,9 @@ export class GnoSocialWalletProvider extends GnoWalletProvider {
5254
5355 private async connectWeb3Auth ( ) : Promise < boolean > {
5456 return this . web3auth
55- . connectTo ( WALLET_ADAPTERS . OPENLOGIN , { loginProvider : 'google' } )
57+ . connectTo ( WALLET_ADAPTERS . OPENLOGIN , {
58+ loginProvider : this . socialType ,
59+ } )
5660 . then ( ( ) => true )
5761 . catch ( ( error ) => {
5862 if ( error ?. name === 'WalletLoginError' ) {
@@ -73,14 +77,99 @@ export class GnoSocialWalletProvider extends GnoWalletProvider {
7377 return `${ privateKey } ` ;
7478 }
7579
76- public static create ( config : SocialConfigure ) {
80+ public static createGoogle ( config : SocialGoogleConfigure ) {
81+ const socialType = SocialType . GOOGLE ;
7782 const chainConfig : CustomChainConfig = {
83+ displayName : 'Gno.land' ,
84+ tickerName : 'Gno.land' ,
85+ ticker : 'ugnot' ,
7886 chainNamespace : 'other' ,
7987 chainId : config . chainId ,
8088 rpcTarget : config . rpcTarget ,
89+ } ;
90+
91+ const web3auth = new Web3AuthNoModal ( {
92+ clientId : config . clientId ,
93+ web3AuthNetwork : config . network ,
94+ chainConfig,
95+ } ) ;
96+
97+ const privateKeyProvider = new CommonPrivateKeyProvider ( {
98+ config : { chainConfig } ,
99+ } ) ;
100+
101+ const openloginAdapter = new OpenloginAdapter ( {
102+ privateKeyProvider : privateKeyProvider ,
103+ adapterSettings : {
104+ clientId : config . clientId ,
105+ uxMode : 'popup' ,
106+ loginConfig : {
107+ [ socialType ] : {
108+ typeOfLogin : 'google' ,
109+ name : config . name ,
110+ clientId : config . authClientId ,
111+ verifier : config . verifier ,
112+ } ,
113+ } ,
114+ } ,
115+ } ) ;
116+ web3auth . configureAdapter ( openloginAdapter ) ;
117+ return new GnoSocialWalletProvider ( web3auth , socialType ) ;
118+ }
119+
120+ public static createTwitter ( config : SocialTwitterConfigure ) {
121+ const socialType = SocialType . TWITTER ;
122+ const chainConfig : CustomChainConfig = {
81123 displayName : 'Gno.land' ,
124+ tickerName : 'Gno.land' ,
82125 ticker : 'ugnot' ,
126+ chainNamespace : 'other' ,
127+ chainId : config . chainId ,
128+ rpcTarget : config . rpcTarget ,
129+ } ;
130+
131+ const web3auth = new Web3AuthNoModal ( {
132+ clientId : config . clientId ,
133+ web3AuthNetwork : config . network ,
134+ chainConfig,
135+ } ) ;
136+
137+ const privateKeyProvider = new CommonPrivateKeyProvider ( {
138+ config : { chainConfig } ,
139+ } ) ;
140+
141+ const openloginAdapter = new OpenloginAdapter ( {
142+ privateKeyProvider : privateKeyProvider ,
143+ adapterSettings : {
144+ uxMode : 'popup' ,
145+ loginConfig : {
146+ [ socialType ] : {
147+ typeOfLogin : 'twitter' ,
148+ name : config . name ,
149+ verifier : config . verifier ,
150+ clientId : config . authClientId ,
151+ jwtParameters : {
152+ connection : 'twitter' ,
153+ verifierIdField : 'sub' ,
154+ domain : config . domain ,
155+ } ,
156+ } ,
157+ } ,
158+ } ,
159+ } ) ;
160+ web3auth . configureAdapter ( openloginAdapter ) ;
161+ return new GnoSocialWalletProvider ( web3auth , socialType ) ;
162+ }
163+
164+ public static createEmail ( config : SocialCustomConfigure ) {
165+ const socialType = SocialType . EMAIL ;
166+ const chainConfig : CustomChainConfig = {
167+ displayName : 'Gno.land' ,
83168 tickerName : 'Gno.land' ,
169+ ticker : 'ugnot' ,
170+ chainNamespace : 'other' ,
171+ chainId : config . chainId ,
172+ rpcTarget : config . rpcTarget ,
84173 } ;
85174
86175 const web3auth = new Web3AuthNoModal ( {
@@ -96,19 +185,23 @@ export class GnoSocialWalletProvider extends GnoWalletProvider {
96185 const openloginAdapter = new OpenloginAdapter ( {
97186 privateKeyProvider : privateKeyProvider ,
98187 adapterSettings : {
99- clientId : config . clientId ,
100188 uxMode : 'popup' ,
101189 loginConfig : {
102- google : {
103- typeOfLogin : 'google' ,
104- name : config . auth . googleName ,
105- verifier : config . auth . googleVerifier ,
106- clientId : config . auth . googleClientId ,
190+ [ socialType ] : {
191+ typeOfLogin : 'jwt' ,
192+ name : config . name ,
193+ verifier : config . verifier ,
194+ clientId : config . authClientId ,
195+ jwtParameters : {
196+ verifierIdField : 'email' ,
197+ domain : config . domain ,
198+ login_hint : '' ,
199+ } ,
107200 } ,
108201 } ,
109202 } ,
110203 } ) ;
111204 web3auth . configureAdapter ( openloginAdapter ) ;
112- return new GnoSocialWalletProvider ( web3auth ) ;
205+ return new GnoSocialWalletProvider ( web3auth , socialType ) ;
113206 }
114207}
0 commit comments