- Abstracted RPC interface to allow dynamic input for connection flexibility. - Added `signSession` function to retrieve `authSig` efficiently. - Improved logging and error handling to provide clearer feedback. - Centralized `authSig` retrieval for better code maintainability. This refactor ensures the wallet service is more adaptable to varying use cases and improves overall code readability.
1.6 KiB
1.6 KiB
wallet.ts
Service Documentation
The wallet.ts
service provides utilities for working with the PKPEthersWallet, including connecting and retrieving the authentication signature.
Dependencies
getStoredAuthSig
from'$lib/services/authWithMetamask/authWithMetamask'
PKPEthersWallet
from'@lit-protocol/pkp-ethers'
createMessage
from'$lib/services/messages'
Variables
- isWalletConnected: A boolean flag that keeps track of whether the wallet is currently connected or not.
Functions
connectWallet(pkpPubKey: string, rpcURL: string = 'https://rpc.gnosischain.com/')
Parameters:
- pkpPubKey: The public key used to connect to the wallet.
- rpcURL (Optional): The RPC URL for the connection. Defaults to
'https://rpc.gnosischain.com/'
.
Returns:
- A promise which resolves to an instance of
PKPEthersWallet
if the wallet is successfully connected. If the wallet is already connected or there's an error in getting theauthSig
, it returnsnull
.
Description:
This function first checks if the wallet is already connected. If it's not, it attempts to retrieve the authSig
from local storage. If successful, it connects to the wallet using the provided pkpPubKey
and rpcURL
. Once the wallet is successfully connected, it sends a success message and sets the isWalletConnected
flag to true
.
signSession()
Returns:
- The
authSig
from local storage if it exists, ornull
otherwise.
Description:
This function retrieves the authSig
from local storage and returns it. If the authSig
does not exist in local storage, an error message is sent, and the function returns null
.