11import { Buffer as BufferPolyfill } from 'buffer' ;
2- import depd from 'depd' ;
32
43import { hexlify } from '@ethersproject/bytes' ;
54import { Web3Provider , JsonRpcSigner } from '@ethersproject/providers' ;
65import { toUtf8Bytes } from '@ethersproject/strings' ;
7-
86import { 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' ;
915import { ethers } from 'ethers' ;
1016import { getAddress } from 'ethers/lib/utils' ;
1117import { SiweMessage } from 'siwe' ;
12-
13- // @ts -ignore: If importing 'nacl' directly, the built files will use .default instead
1418import * as nacl from 'tweetnacl' ;
1519import * as naclUtil from 'tweetnacl-util' ;
20+ import { http } from 'viem' ;
21+ import { createConfig } from 'wagmi' ;
1622
17- // @ts -ignore: If importing 'nacl' directly, the built files will use .default instead
1823import {
1924 ELeft ,
2025 ERight ,
@@ -40,13 +45,6 @@ import {
4045import { getStorageItem } from '@lit-protocol/misc-browser' ;
4146import { AuthSig , AuthCallbackParams , LITEVMChain } from '@lit-protocol/types' ;
4247
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-
5048const deprecated = depd ( 'lit-js-sdk:auth-browser:index' ) ;
5149
5250if ( globalThis && typeof globalThis . Buffer === 'undefined' ) {
@@ -321,8 +319,11 @@ export const decodeCallResult = deprecated.function(
321319 'decodeCallResult will be removed.'
322320) ;
323321
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 ) ;
326327 if ( ! chain ) {
327328 throw new Error ( `Chain ID ${ chainId } not supported` ) ;
328329 }
@@ -347,18 +348,18 @@ const getWagmiProvider = async (chainId: number, walletConnectProjectId?: string
347348 const config = createConfig ( {
348349 chains : [ litChain ] ,
349350 transports : {
350- [ litChain . id ] : http ( litChain . rpcUrls . default . http [ 0 ] )
351+ [ litChain . id ] : http ( litChain . rpcUrls . default . http [ 0 ] ) ,
351352 } ,
352353 connectors : [
353354 injected ( ) ,
354355 ...( walletConnectProjectId
355356 ? [
356357 walletConnect ( {
357- projectId : walletConnectProjectId
358- } )
358+ projectId : walletConnectProjectId ,
359+ } ) ,
359360 ]
360361 : [ ] ) ,
361- ]
362+ ] ,
362363 } ) ;
363364
364365 return config ;
@@ -386,27 +387,27 @@ export const connectWeb3 = async ({
386387
387388 const config = await getWagmiProvider ( chainId , walletConnectProjectId ) ;
388389 wagmiConfig = config ;
389-
390+
390391 const result = await wagmiConnect ( config , {
391392 connector : config . connectors [ 0 ] ,
392393 chainId,
393394 } ) ;
394-
395395
396396 log ( 'got provider' ) ;
397397 if ( ! result ) {
398398 throw new Error ( 'Failed to connect wallet' ) ;
399399 }
400400
401401 const walletClient = await getWalletClient ( config ) ;
402-
402+
403403 if ( ! walletClient ) {
404404 throw new Error ( 'No wallet client found' ) ;
405405 }
406406
407+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
407408 // @ts -ignore - Create Web3Provider from wallet client
408409 const web3 = new Web3Provider ( walletClient ) ;
409-
410+
410411 log ( 'listing accounts' ) ;
411412 const accounts = await web3 . listAccounts ( ) ;
412413 log ( 'accounts' , accounts ) ;
0 commit comments