@@ -42,11 +42,13 @@ import { findContractTokenNameUsingContract, findTokenNameByContract, getAddress
42
42
import {
43
43
AddressDetails ,
44
44
NativeStxBalance ,
45
+ RecoveryInfo ,
45
46
RecoveryOptions ,
46
47
RecoveryTransaction ,
47
48
SingleFungibleTokenBalance ,
48
49
StxNonceResponse ,
49
50
StxTxnFeeEstimationResponse ,
51
+ TxData ,
50
52
} from './lib/iface' ;
51
53
import { TransferBuilder } from './lib/transferBuilder' ;
52
54
import { FungibleTokenTransferBuilder } from './lib/fungibleTokenTransferBuilder' ;
@@ -410,6 +412,23 @@ export class Stx extends BaseCoin {
410
412
}
411
413
}
412
414
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
+
413
432
/**
414
433
* Get the recoverable amount & fee after subtracting the txn fee
415
434
* @param {String } serializedHex - serialized txn hex
@@ -667,9 +686,9 @@ export class Stx extends BaseCoin {
667
686
* @param {String } params.bitgoKey - encrypted bitgo public key
668
687
* @param {String } params.walletPassphrase - wallet password
669
688
* @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)
671
690
*/
672
- async recover ( params : RecoveryOptions ) : Promise < RecoveryTransaction > {
691
+ async recover ( params : RecoveryOptions ) : Promise < RecoveryInfo | RecoveryTransaction > {
673
692
if ( ! this . isValidAddress ( params . rootAddress ) ) {
674
693
throw new Error ( 'invalid root address!' ) ;
675
694
}
@@ -713,12 +732,9 @@ export class Stx extends BaseCoin {
713
732
contractAddressInput : contractAddress ,
714
733
contractName : contractName ,
715
734
} ) ;
716
- const serializedTx : string = tx . toBroadcastFormat ( ) ;
717
735
718
736
if ( isUnsignedSweep ) {
719
- return {
720
- txHex : serializedTx ,
721
- } ;
737
+ return await this . formatForOfflineVault ( tx ) ;
722
738
}
723
739
// check the private key & sign
724
740
if ( ! keys [ 0 ] . privateKey ) {
0 commit comments