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

feat: added support for PrivateKeyAccount as signer in account config #458

Closed
wants to merge 2 commits into from

Conversation

VGabriel45
Copy link
Collaborator

Summary

Added PrivateKeyAccount support as direct signer in account config.

Change Type

  • Bug Fix
  • Refactor
  • New Feature
  • Breaking Change
  • Documentation Update
  • Performance Improvement
  • Other

Checklist

  • My code follows this project's style guidelines
  • I've reviewed my own code
  • I've added comments for any hard-to-understand areas
  • I've updated the documentation if necessary
  • My changes generate no new warnings
  • I've added tests that prove my fix is effective or my feature works
  • All unit tests pass locally with my changes
  • Any dependent changes have been merged and published

packages/account/tests/account.spec.ts Outdated Show resolved Hide resolved
@@ -51,7 +50,17 @@ export const convertSigner = async (signer: SupportedSigner, skipChainIdCalls: b
}
// convert viems walletClient to alchemy's SmartAccountSigner under the hood
resolvedSmartAccountSigner = new WalletClientSigner(walletClient, "viem");
rpcUrl = walletClient?.transport?.url ?? null;
rpcUrl = walletClient?.transport?.url ?? undefined;
} else if (signer as PrivateKeyAccount) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be instanceof instead of as

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're casting every other signer to a PrivateKeyAccount here, - not just accounts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instanceof works with classes, it does not work with types

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're casting every other signer to a PrivateKeyAccount here, - not just accounts.

Not sure what do you mean as this is the last "else if", it will cast it only if signer is indeed of PrivateKeyAccount type, otherwise it will break and throw an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed, please review

@@ -55,7 +55,7 @@ export const compareChainIds = async (
biconomySmartAccountConfig: BiconomySmartAccountV2Config,
skipChainIdCalls: boolean,
): Promise<Error | void> => {
const signerResult = await convertSigner(signer, skipChainIdCalls);
const signerResult = await convertSigner(signer, skipChainIdCalls, biconomySmartAccountConfig.rpcUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this added?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user passes a PrivateKeyAccount there is no info about transport so he needs to at least pass rpcUrl in the config so we can properly construct the walletClient with the correct transport

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was also changed to a better approach

Copy link
Contributor

@livingrockrises livingrockrises left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review i

@livingrockrises
Copy link
Contributor

resolve conflicts

@joepegler
Copy link
Collaborator

LGTM. We can close this as I have added it here: bb9ba8e

@joepegler joepegler closed this Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants