1
1
import { Buffer as BufferPolyfill } from 'buffer' ;
2
- import depd from 'depd' ;
3
2
4
3
import { hexlify } from '@ethersproject/bytes' ;
5
4
import { Web3Provider , JsonRpcSigner } from '@ethersproject/providers' ;
6
5
import { toUtf8Bytes } from '@ethersproject/strings' ;
7
-
8
6
import { verifyMessage } from '@ethersproject/wallet' ;
7
+ import { injected , walletConnect } from '@wagmi/connectors' ;
8
+ import {
9
+ connect as wagmiConnect ,
10
+ disconnect as wagmiDisconnect ,
11
+ getWalletClient ,
12
+ Config ,
13
+ } from '@wagmi/core' ;
14
+ import depd from 'depd' ;
9
15
import { ethers } from 'ethers' ;
10
16
import { getAddress } from 'ethers/lib/utils' ;
11
17
import { SiweMessage } from 'siwe' ;
12
-
13
- // @ts -ignore: If importing 'nacl' directly, the built files will use .default instead
14
18
import * as nacl from 'tweetnacl' ;
15
19
import * as naclUtil from 'tweetnacl-util' ;
20
+ import { http } from 'viem' ;
21
+ import { createConfig } from 'wagmi' ;
16
22
17
- // @ts -ignore: If importing 'nacl' directly, the built files will use .default instead
18
23
import {
19
24
ELeft ,
20
25
ERight ,
@@ -40,13 +45,6 @@ import {
40
45
import { getStorageItem } from '@lit-protocol/misc-browser' ;
41
46
import { AuthSig , AuthCallbackParams , LITEVMChain } from '@lit-protocol/types' ;
42
47
43
- import {
44
- createConfig ,
45
- } from 'wagmi' ;
46
- import { connect as wagmiConnect , disconnect as wagmiDisconnect , getWalletClient , Config } from '@wagmi/core' ;
47
- import { injected , walletConnect } from '@wagmi/connectors'
48
- import { http } from 'viem' ;
49
-
50
48
const deprecated = depd ( 'lit-js-sdk:auth-browser:index' ) ;
51
49
52
50
if ( globalThis && typeof globalThis . Buffer === 'undefined' ) {
@@ -321,8 +319,11 @@ export const decodeCallResult = deprecated.function(
321
319
'decodeCallResult will be removed.'
322
320
) ;
323
321
324
- const getWagmiProvider = async ( chainId : number , walletConnectProjectId ?: string ) => {
325
- const chain = Object . values ( LIT_CHAINS ) . find ( c => c . chainId === chainId ) ;
322
+ const getWagmiProvider = async (
323
+ chainId : number ,
324
+ walletConnectProjectId ?: string
325
+ ) => {
326
+ const chain = Object . values ( LIT_CHAINS ) . find ( ( c ) => c . chainId === chainId ) ;
326
327
if ( ! chain ) {
327
328
throw new Error ( `Chain ID ${ chainId } not supported` ) ;
328
329
}
@@ -347,18 +348,18 @@ const getWagmiProvider = async (chainId: number, walletConnectProjectId?: string
347
348
const config = createConfig ( {
348
349
chains : [ litChain ] ,
349
350
transports : {
350
- [ litChain . id ] : http ( litChain . rpcUrls . default . http [ 0 ] )
351
+ [ litChain . id ] : http ( litChain . rpcUrls . default . http [ 0 ] ) ,
351
352
} ,
352
353
connectors : [
353
354
injected ( ) ,
354
355
...( walletConnectProjectId
355
356
? [
356
357
walletConnect ( {
357
- projectId : walletConnectProjectId
358
- } )
358
+ projectId : walletConnectProjectId ,
359
+ } ) ,
359
360
]
360
361
: [ ] ) ,
361
- ]
362
+ ] ,
362
363
} ) ;
363
364
364
365
return config ;
@@ -386,27 +387,27 @@ export const connectWeb3 = async ({
386
387
387
388
const config = await getWagmiProvider ( chainId , walletConnectProjectId ) ;
388
389
wagmiConfig = config ;
389
-
390
+
390
391
const result = await wagmiConnect ( config , {
391
392
connector : config . connectors [ 0 ] ,
392
393
chainId,
393
394
} ) ;
394
-
395
395
396
396
log ( 'got provider' ) ;
397
397
if ( ! result ) {
398
398
throw new Error ( 'Failed to connect wallet' ) ;
399
399
}
400
400
401
401
const walletClient = await getWalletClient ( config ) ;
402
-
402
+
403
403
if ( ! walletClient ) {
404
404
throw new Error ( 'No wallet client found' ) ;
405
405
}
406
406
407
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
407
408
// @ts -ignore - Create Web3Provider from wallet client
408
409
const web3 = new Web3Provider ( walletClient ) ;
409
-
410
+
410
411
log ( 'listing accounts' ) ;
411
412
const accounts = await web3 . listAccounts ( ) ;
412
413
log ( 'accounts' , accounts ) ;
0 commit comments