@@ -94,6 +94,7 @@ interface signAndSaveAuthParams {
94
94
expiration : string ;
95
95
uri ?: string ;
96
96
nonce : string ;
97
+ provider : AuthProvider ;
97
98
}
98
99
99
100
interface IABI {
@@ -124,6 +125,7 @@ interface SignMessageParams {
124
125
body : string ;
125
126
web3 : Web3Provider ;
126
127
account : string ;
128
+ provider : AuthProvider ;
127
129
}
128
130
129
131
interface SignedMessage {
@@ -619,19 +621,28 @@ export const checkAndSignEVMAuthMessage = async ({
619
621
const selectedChain = LIT_CHAINS [ chain ] ;
620
622
const expirationString = expiration ?? getDefaultExpiration ( ) ;
621
623
622
- let web3 : Web3Provider ;
623
- let account : string ;
624
+ let web3 : Web3Provider | undefined ;
625
+ let account : string | undefined ;
624
626
625
627
if ( provider === AuthProvider . Wagmi ) {
626
628
( { web3, account } = await connectWeb3WithWagmi ( {
627
629
chainId : selectedChain . chainId ,
628
630
walletConnectProjectId,
629
631
} ) ) ;
630
- } else {
632
+ } else if ( provider === AuthProvider . LitConnectModal ) {
631
633
( { web3, account } = await connectWeb3WithLitConnectModal ( {
632
634
chainId : selectedChain . chainId ,
633
635
walletConnectProjectId,
634
636
} ) ) ;
637
+ } else {
638
+ throw new Error ( 'Invalid provider' ) ;
639
+ }
640
+
641
+ if ( ! web3 ) {
642
+ throw new Error ( 'Web3Provider is undefined' ) ;
643
+ }
644
+ if ( ! account ) {
645
+ throw new Error ( 'Account is undefined' ) ;
635
646
}
636
647
637
648
log ( `got web3 and account: ${ account } ` ) ;
@@ -668,7 +679,7 @@ export const checkAndSignEVMAuthMessage = async ({
668
679
669
680
// -- 4. case: (current chain id is NOT equal to selected chain) AND is set to switch chain
670
681
if ( currentChainIdOrError . result !== selectedChainId && switchChain ) {
671
- const provider = web3 . provider as any ;
682
+ const provider = web3 ? .provider as any ;
672
683
673
684
// -- (case) if able to switch chain id
674
685
try {
@@ -733,6 +744,7 @@ export const checkAndSignEVMAuthMessage = async ({
733
744
expiration : expirationString ,
734
745
uri,
735
746
nonce,
747
+ provider,
736
748
} ) ;
737
749
738
750
authSigOrError = {
@@ -779,6 +791,7 @@ export const checkAndSignEVMAuthMessage = async ({
779
791
expiration : expirationString ,
780
792
uri,
781
793
nonce,
794
+ provider,
782
795
} ) ;
783
796
log ( '7. authSig:' , authSig ) ;
784
797
@@ -795,6 +808,7 @@ export const checkAndSignEVMAuthMessage = async ({
795
808
expiration : expirationString ,
796
809
uri,
797
810
nonce,
811
+ provider,
798
812
} ) ;
799
813
}
800
814
log ( '8. mustResign:' , mustResign ) ;
@@ -819,6 +833,7 @@ export const checkAndSignEVMAuthMessage = async ({
819
833
expiration : expirationString ,
820
834
uri,
821
835
nonce,
836
+ provider,
822
837
} ) ;
823
838
}
824
839
@@ -837,6 +852,7 @@ const _signAndGetAuth = async ({
837
852
expiration,
838
853
uri,
839
854
nonce,
855
+ provider,
840
856
} : signAndSaveAuthParams ) : Promise < AuthSig > => {
841
857
await signAndSaveAuthMessage ( {
842
858
web3,
@@ -846,6 +862,7 @@ const _signAndGetAuth = async ({
846
862
expiration,
847
863
uri,
848
864
nonce,
865
+ provider,
849
866
} ) ;
850
867
851
868
const authSigOrError = getStorageItem ( LOCAL_STORAGE_KEYS . AUTH_SIGNATURE ) ;
@@ -885,6 +902,7 @@ export const signAndSaveAuthMessage = async ({
885
902
expiration,
886
903
uri,
887
904
nonce,
905
+ provider,
888
906
} : signAndSaveAuthParams ) : Promise < AuthSig > => {
889
907
// check if it's nodejs
890
908
if ( isNode ( ) ) {
@@ -925,6 +943,7 @@ export const signAndSaveAuthMessage = async ({
925
943
body,
926
944
web3,
927
945
account : formattedAccount ,
946
+ provider,
928
947
} ) ;
929
948
930
949
// -- 3. prepare auth message
@@ -970,6 +989,7 @@ export const signMessage = async ({
970
989
body,
971
990
web3,
972
991
account,
992
+ provider,
973
993
} : SignMessageParams ) : Promise < SignedMessage > => {
974
994
// check if it's nodejs
975
995
if ( isNode ( ) ) {
@@ -983,7 +1003,12 @@ export const signMessage = async ({
983
1003
// -- validate
984
1004
if ( ! web3 || ! account ) {
985
1005
log ( `web3: ${ web3 } OR ${ account } not found. Connecting web3..` ) ;
986
- const res = await connectWeb3 ( { chainId : 1 } ) ;
1006
+ let res ;
1007
+ if ( provider === AuthProvider . Wagmi ) {
1008
+ res = await connectWeb3WithWagmi ( { chainId : 1 } ) ;
1009
+ } else {
1010
+ res = await connectWeb3WithLitConnectModal ( { chainId : 1 } ) ;
1011
+ }
987
1012
web3 = res . web3 ;
988
1013
account = res . account ;
989
1014
}
0 commit comments