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, 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!

networkPassphrase?: 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();
}
},
// eslint-disable-next-line require-await
signAuthEntry: async (entryXdr: string): Promise<string> =>
Expand Down
5 changes: 4 additions & 1 deletion src/contract/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ export type ClientOptions = {
*/
signTransaction?: (
tx: XDR_BASE64,
opts?: {
signer: ((tx: XDR_BASE64, opts?: {
network?: string;
networkPassphrase?: string;
accountToSign?: string;
}) => Promise<XDR_BASE64>) | KeyPair,
opts?: {
networkPassphrase?: string;
},
) => Promise<XDR_BASE64>;
/**
Expand Down