@@ -619,26 +619,29 @@ export class BaseWallet implements ObservableWallet {
619619 } : FinalizeTxProps ) : Promise < Cardano . Tx > {
620620 const knownAddresses = await firstValueFrom ( this . addresses$ ) ;
621621 const dRepPublicKey = await this . governance . getPubDRepKey ( ) ;
622+ const emptyWitness = { signatures : new Map ( ) } ;
623+
624+ let transaction : Serialization . Transaction ;
625+ if ( Cardano . isTxBodyWithHash ( tx ) ) {
626+ // Reconstruct transaction from parts
627+ transaction = new Serialization . Transaction (
628+ bodyCbor ? Serialization . TransactionBody . fromCbor ( bodyCbor ) : Serialization . TransactionBody . fromCore ( tx . body ) ,
629+ Serialization . TransactionWitnessSet . fromCore ( { ...emptyWitness , ...witness } ) ,
630+ auxiliaryData ? Serialization . AuxiliaryData . fromCore ( auxiliaryData ) : undefined
631+ ) ;
632+ if ( isValid !== undefined ) transaction . setIsValid ( isValid ) ;
633+ } else {
634+ // Transaction CBOR is available. Use as is.
635+ transaction = Serialization . Transaction . fromCbor ( tx ) ;
636+ }
622637
623638 const context = {
624639 ...signingContext ,
625640 dRepPublicKey,
626641 knownAddresses,
627- txInKeyPathMap : await util . createTxInKeyPathMap ( tx . body , knownAddresses , this . util )
642+ txInKeyPathMap : await util . createTxInKeyPathMap ( transaction . body ( ) . toCore ( ) , knownAddresses , this . util )
628643 } ;
629644
630- const emptyWitness = { signatures : new Map ( ) } ;
631-
632- // The Witnesser takes a serializable transaction. We cant build that from the hash alone, if
633- // the bodyCbor is available, use that instead of the coreTx type to build the transaction.
634- const transaction = new Serialization . Transaction (
635- bodyCbor ? Serialization . TransactionBody . fromCbor ( bodyCbor ) : Serialization . TransactionBody . fromCore ( tx . body ) ,
636- Serialization . TransactionWitnessSet . fromCore ( { ...emptyWitness , ...witness } ) ,
637- auxiliaryData ? Serialization . AuxiliaryData . fromCore ( auxiliaryData ) : undefined
638- ) ;
639-
640- if ( isValid !== undefined ) transaction . setIsValid ( isValid ) ;
641-
642645 const result = await this . witnesser . witness ( transaction , context , signingOptions ) ;
643646
644647 this . #newTransactions. signed$ . next ( result ) ;
0 commit comments