Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: release v4.6.0 #556

Merged
merged 6 commits into from
Aug 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: get signer address (#551)
* chore: get signer address

* chore: types fix

* chore: cont
  • Loading branch information
joepegler authored Aug 10, 2024
commit 3d5fa496ccd8d8cef9a725d082ccd1c9d1b93a9c
27 changes: 27 additions & 0 deletions src/account/utils/convertSigner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
http,
type Hex,
type PrivateKeyAccount,
type WalletClient,
createWalletClient
Expand Down Expand Up @@ -101,3 +102,29 @@ export const convertSigner = async (
}
return { signer: resolvedSmartAccountSigner, rpcUrl, chainId }
}
/*
This function is used to get the signer's address, it can be used to get the signer's address from different types of signers.
The function takes a signer as an argument and returns the signer's address.
The function checks the type of the signer and returns the signer's address based on the type of the signer.
The function throws an error if the signer is not supported.
*/
export const getSignerAddress = async (signer: SupportedSigner): Promise<Hex> => {
if (isEthersSigner(signer)) {
const result = await (signer as Signer)?.getAddress();
if (result) return result as Hex
throw new Error("Unsupported signer");
} if (isWalletClient(signer)) {
const result = ((signer as WalletClient)?.account?.address);
if (result) return result as Hex
throw new Error("Unsupported signer");
} if (isPrivateKeyAccount(signer)) {
const result = ((signer as PrivateKeyAccount)?.address);
if (result) return result as Hex
throw new Error("Unsupported signer");
} if (isAlchemySigner(signer)) {
const result = ((signer as SmartAccountSigner)?.inner?.address);
if (result) return result as Hex
throw new Error("Unsupported signer");
}
throw new Error("Unsupported signer");
}