Skip to content

Commit 10be3d4

Browse files
authored
fix: use the signer from the sender (#554)
1 parent cb811ea commit 10be3d4

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/composer.spec.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { ABIMethod, ABITupleType, ABIType } from '@algorandfoundation/algokit-abi'
22
import { Address } from '@algorandfoundation/algokit-common'
3-
import { Transaction, TransactionSigner, TransactionType } from '@algorandfoundation/algokit-transact'
3+
import {
4+
decodeSignedTransaction,
5+
generateAddressWithSigners,
6+
Transaction,
7+
TransactionSigner,
8+
TransactionType,
9+
} from '@algorandfoundation/algokit-transact'
410
import { beforeEach, describe, expect, test, vi } from 'vitest'
5-
import { AlgoAmount } from './amount'
11+
import { algo, AlgoAmount } from './amount'
612
import { algorandFixture } from './testing'
13+
import { nobleEd25519Generator } from '@algorandfoundation/algokit-crypto'
714

815
describe('TransactionComposer', () => {
916
const fixture = algorandFixture()
@@ -613,4 +620,36 @@ describe('TransactionComposer', () => {
613620
await expect(composer.gatherSignatures()).rejects.toThrow('Transactions at indexes [0] were not signed')
614621
})
615622
})
623+
624+
test('should use signer from sender', async () => {
625+
const { algorand } = fixture
626+
627+
// Generate an account outside of the algorand client and fund it
628+
const generated = nobleEd25519Generator()
629+
const addressWithSigners = generateAddressWithSigners(generated)
630+
631+
await algorand.account.ensureFundedFromEnvironment(addressWithSigners.addr, algo(1))
632+
633+
// First verify that the signer isn't found when we only pass the address
634+
const addrOnlyComposer = algorand.newGroup()
635+
addrOnlyComposer.addPayment({
636+
sender: addressWithSigners.addr,
637+
receiver: addressWithSigners.addr,
638+
amount: algo(0),
639+
})
640+
await expect(addrOnlyComposer.gatherSignatures()).rejects.toThrow(`No signer found for address ${addressWithSigners.addr}`)
641+
642+
// Then verify that the signer is found when we pass the address with the signer
643+
const composer = algorand.newGroup()
644+
composer.addPayment({
645+
sender: addressWithSigners,
646+
receiver: addressWithSigners,
647+
amount: algo(0),
648+
})
649+
650+
const signedTxns = await composer.gatherSignatures()
651+
652+
expect(signedTxns).toHaveLength(1)
653+
expect(decodeSignedTransaction(signedTxns[0]).sig!.length).toBe(64)
654+
})
616655
})

src/composer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,14 @@ export class TransactionComposer {
14651465
validateTransaction(transaction)
14661466
transactions.push(transaction)
14671467

1468+
let signer: TransactionSigner | undefined
14681469
if (ctxn.data.signer) {
1469-
const signer = 'signer' in ctxn.data.signer ? ctxn.data.signer.signer : ctxn.data.signer
1470+
signer = 'signer' in ctxn.data.signer ? ctxn.data.signer.signer : ctxn.data.signer
1471+
}
1472+
if (!signer && typeof ctxn.data.sender === 'object' && 'signer' in ctxn.data.sender) {
1473+
signer = ctxn.data.sender.signer
1474+
}
1475+
if (signer) {
14701476
signers.set(transactionIndex, signer)
14711477
}
14721478
transactionIndex++

0 commit comments

Comments
 (0)