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
14 changes: 10 additions & 4 deletions src/contract/basic_node_signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ export const basicNodeSigner = (
networkPassphrase: string,
) => ({
// eslint-disable-next-line require-await
signTransaction: async (tx: string) => {
const t = TransactionBuilder.fromXDR(tx, networkPassphrase);
t.sign(keypair);
return t.toXDR();
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();
}
Comment on lines +21 to +30
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

},
// eslint-disable-next-line require-await
signAuthEntry: async (entryXdr: string): Promise<string> =>
Expand Down
3 changes: 2 additions & 1 deletion src/contract/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* disable PascalCase naming convention, to avoid breaking change */
/* eslint-disable @typescript-eslint/naming-convention */
import { Memo, MemoType, Operation, Transaction, xdr } from "@stellar/stellar-base";
import { Keypair, Memo, MemoType, Operation, Transaction, xdr } from "@stellar/stellar-base";
import type { Client } from "./client";

export type XDR_BASE64 = string;
Expand Down Expand Up @@ -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>;

) => Promise<XDR_BASE64>;
/**
* A function to sign a specific auth entry for a transaction, using the
Expand Down