How can I get public & private keys from getSigner() function. I want this to send public key as an argument to function call & listen for an event in server which then encrypts a message using the public key and sent to browser which the user can decrypt with their private key.
You can only access the public and private key if you built the signer from a mnemonic or a private key. The relevant fields are on the signer type
Wallet in ethers.
wallet.privateKey (from the "Wallet Examples" section of the docs below)
If the signer is remote you cannot get the private key.
If you just want to sign data, you can use the
_signTypedData methods on the signer which works for any signer type and can be verified against the address using
All of the relevant docs are here: https://docs.ethers.io/v5/api/signer/