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

Change signature of ClientOption.signTransaction to be able to pass KeyPair #1079

Closed
wants to merge 9 commits into from

Conversation

od-hunter
Copy link

resolves #1063

@od-hunter od-hunter marked this pull request as draft October 4, 2024 06:28
@od-hunter od-hunter marked this pull request as ready for review October 5, 2024 11:47
t.sign(keypair);
return t.toXDR();
signTransaction: async (tx: string, signer?: () | KeyPair, opts?: {
network?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

network doesn't appear to be used here

signTransaction: async (tx: string, signer?: () | KeyPair, opts?: {
network?: string;
networkPassphrase?: string;
accountToSign?: string;) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

neither is accountToSign

network?: string;
networkPassphrase?: string;
accountToSign?: string;) => {
if(signer instanceof KeyPair){
Copy link
Contributor

Choose a reason for hiding this comment

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

formatting nit:

Suggested change
if(signer instanceof KeyPair){
if (signer instanceof KeyPair){

Copy link
Contributor

Choose a reason for hiding this comment

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

We've had issues in the past with using instanceof to check for types due to dependency trees creating multiple instances of a particular object. This is okay for now but please consider a better way to determine whether or not a signer is a Keypair

@od-hunter
Copy link
Author

@Shaptic , please review

@od-hunter
Copy link
Author

@Shaptic please review

Copy link
Contributor

@chadoh chadoh left a comment

Choose a reason for hiding this comment

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

Let's hold off until the upstream discussion is finalized (see below). But also, the code as written will not work, I don't think, and we will need at least one test to verify one way or the other (an alternative would be to update most of the e2e tests, and just keep one test that verifies the old functionality).

const t = TransactionBuilder.fromXDR(tx, networkPassphrase);
t.sign(keypair);
return t.toXDR();
signTransaction: async (tx: string, signer?, opts?: {
Copy link
Contributor

Choose a reason for hiding this comment

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

signer?, is not valid TypeScript; does this code work?

I think this whole approach will cause typing problems, though! Sorry I didn't catch this before you started working. See comment here:

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, conversation resolved, this is the desired way to do it. Please make sure your code works by testing it and we can get this merged!

@od-hunter od-hunter requested review from chadoh and Shaptic November 6, 2024 09:53
@od-hunter
Copy link
Author

Hi @chadoh , @Shaptic please review.

Copy link
Contributor

@chadoh chadoh left a comment

Choose a reason for hiding this comment

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

I think you need to go back to the original description and make sure you understand it. Also, I still don't see this new functionality being harnessed by clientFor in test/e2e/src/util.js. We can stop using basicNodeSigner and pass the Keypair instead.

Comment on lines +21 to +30
signTransaction: async (tx: string, opts?: {
networkPassphrase?: string;}, signer?: Keypair): Promise<string> => {
if (signer instanceof Keypair){
const basicSigner = basicNodeSigner(signer, opts?.networkPassphrase!);
return basicSigner.signTransaction(tx);
} else{
const t = TransactionBuilder.fromXDR(tx, networkPassphrase);
t.sign(keypair);
return t.toXDR();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not need any change to basicNodeSigner

@@ -84,6 +84,7 @@ export type ClientOptions = {
networkPassphrase?: string;
accountToSign?: string;
},
signer?: Keypair,
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want to add a signer as an option to signTransaction. We want to use the existing signature, which comes from Freighter / SEP-43, OR we want to allow passing a keypair. Like this:

signTransaction?: Keypair | (
  tx: XDR_BASE64,
  opts?: {
    network?: string;
    networkPassphrase?: string;
    accountToSign?: string;
  },
) => Promise<XDR_BASE64>;

@od-hunter od-hunter closed this Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Change signature of ClientOption.signTransaction to be able to pass KeyPair
3 participants