import { addressFromVersionHash , AddressHashMode , addressHashModeToVersion , addressToString , StacksTransaction , TransactionVersion , } from '@stacks/transactions' ; function getAddressFromPublicKeyHash ( publicKeyHash , hashMode , transactionVersion ) { const addrVer = addressHashModeToVersion ( hashMode , transactionVersion ) ; if ( publicKeyHash . length !== 20 ) { throw new Error ( 'expected 20-byte pubkeyhash' ) ; } const addr = addressFromVersionHash ( addrVer , publicKeyHash . toString ( 'hex' ) ) ; return addressToString ( addr ) ; } export function getTxSenderAddress ( tx ) { if ( ! tx ?. auth ?. spendingCondition ?. signer ) return ; const txSender = getAddressFromPublicKeyHash ( Buffer . from ( tx . auth . spendingCondition . signer , 'hex' ) , tx . auth . spendingCondition . hashMode as number , tx . version ) ; return txSender ; }