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
16 changes: 12 additions & 4 deletions src/contract/basic_node_signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ 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, 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

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

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

const basicSigner = basicNodeSigner(signer, opts.networkPassphrase);
return basicSigner.signTransaction(tx);
} else{
const t = TransactionBuilder.fromXDR(tx, networkPassphrase);
t.sign(keypair);
return t.toXDR();
}
},
// eslint-disable-next-line require-await
signAuthEntry: async (entryXdr: string): Promise<string> =>
Expand Down
5 changes: 5 additions & 0 deletions src/contract/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export type ClientOptions = {
*/
signTransaction?: (
tx: XDR_BASE64,
signer: ((tx: XDR_BASE64, opts?: {
network?: string;
networkPassphrase?: string;
accountToSign?: string;
}) => Promise<XDR_BASE64>) | KeyPair,
opts?: {
network?: string;
networkPassphrase?: string;
Expand Down