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

Update DAppSigner.ts #170

Merged
merged 8 commits into from
Jul 19, 2024
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/lib/dapp/DAppSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,22 @@ export class DAppSigner implements Signer {
.setTransactionId(TransactionId.generate(this.getAccountId()))
}

/**
* Prepares a transaction object for signing using a single node account id.
* If the transaction object does not already have a node account id,
* generate a random node account id using the Hedera SDK client
*
* @param transaction - Any instance of a class that extends `Transaction`
* @returns transaction - `Transaction` object with signature
*/
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
let nodeAccountId: AccountId
if (!transaction.nodeAccountIds || transaction.nodeAccountIds.length === 0)
nodeAccountId = this._getRandomNodes(1)[0]
else nodeAccountId = transaction.nodeAccountIds[0]
const transactionBody: proto.TransactionBody = transactionToTransactionBody(
transaction,
this._getRandomNodes(1)[0],
nodeAccountId,
)
const transactionBodyBase64 = transactionBodyToBase64String(transactionBody)

Expand Down