55  createSpendingCondition , 
66  createSponsoredAuth , 
77  createStandardAuth , 
8-   MultiSigSpendingCondition , 
98}  from  './authorization' ; 
109import  {  ClarityValue ,  PrincipalCV  }  from  './clarity' ; 
1110import  { 
@@ -18,9 +17,7 @@ import {
1817  NonFungibleConditionCode , 
1918  PayloadType , 
2019  PostConditionMode , 
21-   RECOVERABLE_ECDSA_SIG_LENGTH_BYTES , 
2220  SingleSigHashMode , 
23-   StacksMessageType , 
2421}  from  './constants' ; 
2522import  {  ClarityAbi ,  validateContractCall  }  from  './contract-abi' ; 
2623import  {  estimateFee ,  getAbi ,  getNonce  }  from  './fetch' ; 
@@ -797,41 +794,3 @@ export async function sponsorTransaction(
797794
798795  return  signer . transaction ; 
799796} 
800- 
801- /** 
802-  * Estimates transaction byte length 
803-  * Context: 
804-  * 1) Multi-sig transaction byte length increases by adding signatures 
805-  *    which causes the incorrect fee estimation because the fee value is set while creating unsigned transaction 
806-  * 2) Single-sig transaction byte length remain same due to empty message signature which allocates the space for signature 
807-  * @param  {transaction } - StacksTransaction object to be estimated 
808-  * @return  {number } Estimated transaction byte length 
809-  */ 
810- export  function  estimateTransactionByteLength ( transaction : StacksTransaction ) : number  { 
811-   const  hashMode  =  transaction . auth . spendingCondition . hashMode ; 
812-   // List of Multi-sig transaction hash modes 
813-   const  multiSigHashModes  =  [ AddressHashMode . SerializeP2SH ,  AddressHashMode . SerializeP2WSH ] ; 
814- 
815-   // Check if its a Multi-sig transaction 
816-   if  ( multiSigHashModes . includes ( hashMode ) )  { 
817-     const  multiSigSpendingCondition : MultiSigSpendingCondition  =  transaction . auth 
818-       . spendingCondition  as  MultiSigSpendingCondition ; 
819- 
820-     // Find number of existing signatures if the transaction is signed or partially signed 
821-     const  existingSignatures  =  multiSigSpendingCondition . fields . filter ( 
822-       field  =>  field . contents . type  ===  StacksMessageType . MessageSignature 
823-     ) . length ;  // existingSignatures will be 0 if its a unsigned transaction 
824- 
825-     // Estimate total signature bytes size required for this multi-sig transaction 
826-     // Formula: totalSignatureLength = (signaturesRequired - existingSignatures) * (SIG_LEN_BYTES + 1 byte of type of signature) 
827-     const  totalSignatureLength  = 
828-       ( multiSigSpendingCondition . signaturesRequired  -  existingSignatures )  * 
829-       ( RECOVERABLE_ECDSA_SIG_LENGTH_BYTES  +  1 ) ; 
830- 
831-     return  transaction . serialize ( ) . byteLength  +  totalSignatureLength ; 
832-   }  else  { 
833-     // Single-sig transaction 
834-     // Signature space already allocated by empty message signature 
835-     return  transaction . serialize ( ) . byteLength ; 
836-   } 
837- } 
0 commit comments