@@ -113,6 +113,17 @@ export abstract class AtomicTransactionBuilder extends TransactionBuilder {
113113 const sender = ( this . transaction as Transaction ) . _fromAddresses ;
114114 const hasAddresses = sender && sender . length >= threshold ;
115115
116+ // If we have pre-computed addressesIndex (from parsing a transaction), use it directly
117+ // This is the authoritative source for signature ordering from parsed transactions
118+ if ( utxo . addressesIndex && utxo . addressesIndex . length >= threshold ) {
119+ // Create credentials matching the sigIndicies order from the parsed transaction
120+ const emptySignatures : ReturnType < typeof utils . createNewSig > [ ] = [ ] ;
121+ for ( let i = 0 ; i < threshold ; i ++ ) {
122+ emptySignatures . push ( utils . createNewSig ( '' ) ) ;
123+ }
124+ return new Credential ( emptySignatures ) ;
125+ }
126+
116127 if ( ! hasAddresses || ! utxo . addresses || utxo . addresses . length === 0 ) {
117128 // Fallback: use all zeros if no addresses available
118129 const emptySignatures : ReturnType < typeof utils . createNewSig > [ ] = [ ] ;
@@ -163,6 +174,21 @@ export abstract class AtomicTransactionBuilder extends TransactionBuilder {
163174 const addressMap = new FlareUtils . AddressMap ( ) ;
164175 const sender = ( this . transaction as Transaction ) . _fromAddresses ;
165176
177+ // If we have pre-computed addressesIndex (from parsing a transaction), use it directly
178+ // addressesIndex from sigIndicies() tells us: addressesIndex[slotIdx] = utxoAddressIdx
179+ // This means slot 'slotIdx' expects signature from UTXO address at index 'utxoAddressIdx'
180+ // Assuming sender[i] corresponds to utxoAddress[i], we map sender[addressesIndex[slotIdx]] to slotIdx
181+ if ( utxo . addressesIndex && utxo . addressesIndex . length >= threshold && sender && sender . length >= threshold ) {
182+ for ( let slotIdx = 0 ; slotIdx < threshold ; slotIdx ++ ) {
183+ const utxoAddrIdx = utxo . addressesIndex [ slotIdx ] ;
184+ // Map the sender that corresponds to this UTXO address index to this slot
185+ if ( utxoAddrIdx < sender . length ) {
186+ addressMap . set ( new Address ( sender [ utxoAddrIdx ] ) , slotIdx ) ;
187+ }
188+ }
189+ return addressMap ;
190+ }
191+
166192 // If UTXO has addresses, compute addressesIndex to determine signature order
167193 if ( utxo && utxo . addresses && utxo . addresses . length > 0 && sender && sender . length >= threshold ) {
168194 const utxoAddresses = utxo . addresses . map ( ( a ) => utils . parseAddress ( a ) ) ;
0 commit comments