@@ -2,18 +2,17 @@ import * as utxolib from '@bitgo/utxo-lib';
22import { bip32 , BIP32Interface , bitgo } from '@bitgo/utxo-lib' ;
33import { Triple } from '@bitgo/sdk-core' ;
44
5- import {
6- DecoratedExplainTransactionOptions ,
7- ExplainTransactionOptions ,
8- Output ,
9- TransactionExplanation ,
10- FixedScriptWalletOutput ,
11- } from '../../abstractUtxoCoin' ;
5+ import { Output , TransactionExplanation , FixedScriptWalletOutput } from '../../abstractUtxoCoin' ;
126import { toExtendedAddressFormat } from '../recipient' ;
137
8+ export type ChangeAddressInfo = { address : string ; chain : number ; index : number } ;
9+
1410function explainCommon < TNumber extends number | bigint > (
1511 tx : bitgo . UtxoTransaction < TNumber > ,
16- params : DecoratedExplainTransactionOptions < TNumber > ,
12+ params : {
13+ changeInfo ?: ChangeAddressInfo [ ] ;
14+ feeInfo ?: string ;
15+ } ,
1716 network : utxolib . Network
1817) {
1918 const displayOrder = [ 'id' , 'outputAmount' , 'changeAmount' , 'outputs' , 'changeOutputs' ] ;
@@ -85,14 +84,16 @@ function explainCommon<TNumber extends number | bigint>(
8584 return { displayOrder, id : tx . getId ( ) , ...outputDetails , fee, locktime } ;
8685}
8786
88- function getRootWalletKeys < TNumber extends number | bigint > ( params : ExplainTransactionOptions < TNumber > ) {
87+ function getRootWalletKeys ( params : { pubs ?: string [ ] } ) {
8988 const keys = params . pubs ?. map ( ( xpub ) => bip32 . fromBase58 ( xpub ) ) ;
9089 return keys && keys . length === 3 ? new bitgo . RootWalletKeys ( keys as Triple < BIP32Interface > ) : undefined ;
9190}
9291
93- function getPsbtInputSignaturesCount < TNumber extends number | bigint > (
92+ function getPsbtInputSignaturesCount (
9493 psbt : bitgo . UtxoPsbt ,
95- params : ExplainTransactionOptions < TNumber >
94+ params : {
95+ pubs ?: string [ ] ;
96+ }
9697) {
9798 const rootWalletKeys = getRootWalletKeys ( params ) ;
9899 return rootWalletKeys
@@ -102,7 +103,10 @@ function getPsbtInputSignaturesCount<TNumber extends number | bigint>(
102103
103104function getTxInputSignaturesCount < TNumber extends number | bigint > (
104105 tx : bitgo . UtxoTransaction < TNumber > ,
105- params : ExplainTransactionOptions < TNumber > ,
106+ params : {
107+ txInfo ?: { unspents ?: bitgo . Unspent < TNumber > [ ] } ;
108+ pubs ?: string [ ] ;
109+ } ,
106110 network : utxolib . Network
107111) {
108112 const prevOutputs = params . txInfo ?. unspents ?. map ( ( u ) => bitgo . toOutput < TNumber > ( u , network ) ) ;
@@ -136,7 +140,10 @@ function getTxInputSignaturesCount<TNumber extends number | bigint>(
136140 */
137141export function explainPsbt < TNumber extends number | bigint , Tx extends bitgo . UtxoTransaction < bigint > > (
138142 psbt : bitgo . UtxoPsbt < Tx > ,
139- params : ExplainTransactionOptions < TNumber > ,
143+ params : {
144+ pubs ?: string [ ] ;
145+ txInfo ?: { unspents ?: bitgo . Unspent < TNumber > [ ] } ;
146+ } ,
140147 network : utxolib . Network
141148) : TransactionExplanation {
142149 const txOutputs = psbt . txOutputs ;
@@ -186,7 +193,7 @@ export function explainPsbt<TNumber extends number | bigint, Tx extends bitgo.Ut
186193 }
187194 const changeInfo = getChangeInfo ( ) ;
188195 const tx = psbt . getUnsignedTx ( ) as bitgo . UtxoTransaction < TNumber > ;
189- const common = explainCommon ( tx , { ...params , txInfo : params . txInfo , changeInfo } , network ) ;
196+ const common = explainCommon ( tx , { ...params , changeInfo } , network ) ;
190197 const inputSignaturesCount = getPsbtInputSignaturesCount ( psbt , params ) ;
191198
192199 // Set fee from subtracting inputs from outputs
@@ -213,7 +220,11 @@ export function explainPsbt<TNumber extends number | bigint, Tx extends bitgo.Ut
213220
214221export function explainLegacyTx < TNumber extends number | bigint > (
215222 tx : bitgo . UtxoTransaction < TNumber > ,
216- params : ExplainTransactionOptions < TNumber > ,
223+ params : {
224+ pubs ?: string [ ] ;
225+ txInfo ?: { unspents ?: bitgo . Unspent < TNumber > [ ] } ;
226+ changeInfo ?: { address : string ; chain : number ; index : number } [ ] ;
227+ } ,
217228 network : utxolib . Network
218229) : TransactionExplanation {
219230 const common = explainCommon ( tx , params , network ) ;
0 commit comments