Skip to content

Commit

Permalink
add signTransactions method
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-d committed Jul 24, 2023
1 parent a7cda43 commit e57a63d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/AuthProviders/ExtensionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ export class ExtensionProvider implements IAuthProvider {
return result;
}

signTransaction(tx: Transaction): Promise<CoreTransaction | null> {
signTransaction(tx: Transaction): Promise<Transaction | null> {
return this.provider.signTransaction(tx as CoreTransaction);
}

signTransactions(transactions: Transaction[]): Promise<Transaction[]> {
return this.provider.signTransactions(transactions);
}

getSignature() {
if (this.provider.account.signature !== undefined) {
return this.provider.account.signature;
Expand Down
4 changes: 4 additions & 0 deletions src/AuthProviders/LedgerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export class LedgerProvider implements IAuthProvider {
return this.provider.signTransaction(tx);
}

signTransactions(transactions: Transaction[]): Promise<Transaction[]> {
return this.provider.signTransactions(transactions);
}

getSignature() {
return this.signature;
}
Expand Down
11 changes: 11 additions & 0 deletions src/AuthProviders/PemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ export class PemProvider implements IAuthProvider {
return tx;
}

async signTransactions(transactions: Transaction[]): Promise<Transaction[]> {
const signedTransactions: Transaction[] = [];
for (const tx of transactions) {
const signedTx = await this.signTransaction(tx);
if (!signedTx) {throw new Error("Failed to sign transaction");}
signedTransactions.push(signedTx);
}

return signedTransactions;
}

getSignature() {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions src/AuthProviders/WalletConnectProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class WalletConnectProvider implements IAuthProvider {
return this.provider.signTransaction(tx as Transaction);
}

signTransactions(transactions: Transaction[]): Promise<Transaction[]> {
return this.provider.signTransactions(transactions);
}

getType(): AuthProviderType {
return AuthProviderType.WALLET_CONNECT;
}
Expand Down
8 changes: 8 additions & 0 deletions src/AuthProviders/WebProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ export class WebProvider implements IAuthProvider {
return null;
}

async signTransactions(transactions: Transaction[]): Promise<Transaction[]> {
await this.provider.signTransactions(transactions as CoreTransaction[], {
callbackUrl: this.connectionOptions.transactionRedirectUrl,
});

return [];
}

getAddress(): string | null {
return this.address;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AuthProviders/WebviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,4 @@ export class WebviewProvider implements IAuthProvider {
};
}

};
}
3 changes: 3 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export interface IAuthProvider {

signTransaction(tx: Transaction): Promise<Transaction | null>;

signTransactions(transactions: Transaction[]): Promise<Transaction[]>;


getType(): AuthProviderType;

toJson(): IAuthState;
Expand Down

0 comments on commit e57a63d

Please sign in to comment.