# `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 the `authSig`, it returns `null`.

#### 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, or `null` 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`.

