@@ -42,11 +42,13 @@ import { findContractTokenNameUsingContract, findTokenNameByContract, getAddress
4242import {
4343 AddressDetails ,
4444 NativeStxBalance ,
45+ RecoveryInfo ,
4546 RecoveryOptions ,
4647 RecoveryTransaction ,
4748 SingleFungibleTokenBalance ,
4849 StxNonceResponse ,
4950 StxTxnFeeEstimationResponse ,
51+ TxData ,
5052} from './lib/iface' ;
5153import { TransferBuilder } from './lib/transferBuilder' ;
5254import { FungibleTokenTransferBuilder } from './lib/fungibleTokenTransferBuilder' ;
@@ -410,6 +412,23 @@ export class Stx extends BaseCoin {
410412 }
411413 }
412414
415+ /**
416+ * Format for offline vault signing
417+ * @param {BaseTransaction } tx - base transaction
418+ * @returns {Promise<RecoveryInfo> }
419+ */
420+ protected async formatForOfflineVault ( tx : BaseTransaction ) : Promise < RecoveryInfo > {
421+ const txJson : TxData = tx . toJson ( ) ;
422+ const transactionExplanation : RecoveryInfo = ( await this . explainTransaction ( {
423+ txHex : tx . toBroadcastFormat ( ) ,
424+ feeInfo : { fee : txJson . fee } ,
425+ } ) ) as RecoveryInfo ;
426+ transactionExplanation . coin = this . getChain ( ) ;
427+ transactionExplanation . feeInfo = { fee : txJson . fee } ;
428+ transactionExplanation . txHex = tx . toBroadcastFormat ( ) ;
429+ return transactionExplanation ;
430+ }
431+
413432 /**
414433 * Get the recoverable amount & fee after subtracting the txn fee
415434 * @param {String } serializedHex - serialized txn hex
@@ -667,9 +686,9 @@ export class Stx extends BaseCoin {
667686 * @param {String } params.bitgoKey - encrypted bitgo public key
668687 * @param {String } params.walletPassphrase - wallet password
669688 * @param {String } params.contractId - contract id of the token (mandatory for token recovery)
670- * @returns {Promise<RecoveryTransaction> } RecoveryTransaction.txHex - hex of serialized transaction (signed or unsigned)
689+ * @returns {Promise<RecoveryInfo| RecoveryTransaction> } RecoveryTransaction.txHex - hex of serialized transaction (signed or unsigned)
671690 */
672- async recover ( params : RecoveryOptions ) : Promise < RecoveryTransaction > {
691+ async recover ( params : RecoveryOptions ) : Promise < RecoveryInfo | RecoveryTransaction > {
673692 if ( ! this . isValidAddress ( params . rootAddress ) ) {
674693 throw new Error ( 'invalid root address!' ) ;
675694 }
@@ -713,12 +732,9 @@ export class Stx extends BaseCoin {
713732 contractAddressInput : contractAddress ,
714733 contractName : contractName ,
715734 } ) ;
716- const serializedTx : string = tx . toBroadcastFormat ( ) ;
717735
718736 if ( isUnsignedSweep ) {
719- return {
720- txHex : serializedTx ,
721- } ;
737+ return await this . formatForOfflineVault ( tx ) ;
722738 }
723739 // check the private key & sign
724740 if ( ! keys [ 0 ] . privateKey ) {
0 commit comments