@@ -66,19 +66,20 @@ import { supportedCrossChainRecoveries } from './config';
6666import {
6767 assertValidTransactionRecipient ,
6868 explainTx ,
69+ parseTransaction ,
70+ verifyTransaction ,
6971 fromExtendedAddressFormat ,
7072 isScriptRecipient ,
7173} from './transaction' ;
72- import { assertDescriptorWalletAddress } from './descriptor' ;
74+ import { assertDescriptorWalletAddress , getDescriptorMapFromWallet , isDescriptorWallet } from './descriptor' ;
7375
7476import { getChainFromNetwork , getFamilyFromNetwork , getFullNameFromNetwork } from './names' ;
75- import { CustomChangeOptions , parseTransaction } from './transaction/fixedScript' ;
77+ import { CustomChangeOptions } from './transaction/fixedScript' ;
7678import { NamedKeychains } from './keychains' ;
7779
7880const debug = debugLib ( 'bitgo:v2:utxo' ) ;
7981
8082import ScriptType2Of3 = utxolib . bitgo . outputScripts . ScriptType2Of3 ;
81- import { verifyTransaction } from './transaction/fixedScript/verifyTransaction' ;
8283import { verifyKeySignature , verifyUserPublicKey } from './verifyKey' ;
8384
8485type UtxoCustomSigningFunction < TNumber extends number | bigint > = {
@@ -107,8 +108,13 @@ type UtxoCustomSigningFunction<TNumber extends number | bigint> = {
107108} ;
108109
109110const { getExternalChainCode, isChainCode, scriptTypeForChain, outputScripts } = bitgo ;
111+
110112type Unspent < TNumber extends number | bigint = number > = bitgo . Unspent < TNumber > ;
111113
114+ type DecodedTransaction < TNumber extends number | bigint > =
115+ | utxolib . bitgo . UtxoTransaction < TNumber >
116+ | utxolib . bitgo . UtxoPsbt ;
117+
112118type RootWalletKeys = bitgo . RootWalletKeys ;
113119
114120export type UtxoCoinSpecific = AddressCoinSpecific | DescriptorAddressCoinSpecific ;
@@ -516,7 +522,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
516522 if ( _ . isUndefined ( prebuild . txHex ) ) {
517523 throw new Error ( 'missing required txPrebuild property txHex' ) ;
518524 }
519- const tx = this . decodeTransaction ( prebuild . txHex ) ;
525+ const tx = this . decodeTransactionFromPrebuild ( prebuild ) ;
520526 if ( _ . isUndefined ( prebuild . blockHeight ) ) {
521527 prebuild . blockHeight = ( await this . getLatestBlockHeight ( ) ) as number ;
522528 }
@@ -559,9 +565,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
559565 return utxolib . bitgo . createTransactionFromHex < TNumber > ( hex , this . network , this . amountType ) ;
560566 }
561567
562- decodeTransaction < TNumber extends number | bigint > (
563- input : Buffer | string
564- ) : utxolib . bitgo . UtxoTransaction < TNumber > | utxolib . bitgo . UtxoPsbt {
568+ decodeTransaction < TNumber extends number | bigint > ( input : Buffer | string ) : DecodedTransaction < TNumber > {
565569 if ( typeof input === 'string' ) {
566570 for ( const format of [ 'hex' , 'base64' ] as const ) {
567571 const buffer = Buffer . from ( input , format ) ;
@@ -586,6 +590,17 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
586590 }
587591 }
588592
593+ decodeTransactionFromPrebuild < TNumber extends number | bigint > ( prebuild : {
594+ txHex ?: string ;
595+ txBase64 ?: string ;
596+ } ) : DecodedTransaction < TNumber > {
597+ const string = prebuild . txHex ?? prebuild . txBase64 ;
598+ if ( ! string ) {
599+ throw new Error ( 'missing required txHex or txBase64 property' ) ;
600+ }
601+ return this . decodeTransaction ( string ) ;
602+ }
603+
589604 toCanonicalTransactionRecipient ( output : { valueString : string ; address ?: string } ) : {
590605 amount : bigint ;
591606 address ?: string ;
@@ -662,12 +677,9 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
662677 throw new InvalidAddressError ( `invalid address: ${ address } ` ) ;
663678 }
664679
665- if ( wallet ) {
666- const walletCoinSpecific = wallet . coinSpecific ( ) ;
667- if ( walletCoinSpecific && 'descriptors' in walletCoinSpecific ) {
668- assertDescriptorWalletAddress ( this . network , params , walletCoinSpecific . descriptors ) ;
669- return true ;
670- }
680+ if ( wallet && isDescriptorWallet ( wallet ) ) {
681+ assertDescriptorWalletAddress ( this . network , params , getDescriptorMapFromWallet ( wallet ) ) ;
682+ return true ;
671683 }
672684
673685 if ( ( _ . isUndefined ( chain ) && _ . isUndefined ( index ) ) || ! ( _ . isFinite ( chain ) && _ . isFinite ( index ) ) ) {
@@ -857,7 +869,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
857869 throw new Error ( 'missing txPrebuild parameter' ) ;
858870 }
859871
860- let tx = this . decodeTransaction ( params . txPrebuild . txHex ) ;
872+ let tx = this . decodeTransactionFromPrebuild ( params . txPrebuild ) ;
861873
862874 const isTxWithKeyPathSpendInput = tx instanceof bitgo . UtxoPsbt && bitgo . isTransactionWithKeyPathSpendInput ( tx ) ;
863875
@@ -1074,11 +1086,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
10741086 async explainTransaction < TNumber extends number | bigint = number > (
10751087 params : ExplainTransactionOptions < TNumber >
10761088 ) : Promise < TransactionExplanation > {
1077- const { txHex } = params ;
1078- if ( typeof txHex !== 'string' || ! txHex . match ( / ^ ( [ a - f 0 - 9 ] { 2 } ) + $ / i) ) {
1079- throw new Error ( 'invalid transaction hex, must be a valid hex string' ) ;
1080- }
1081- return explainTx ( this . decodeTransaction ( txHex ) , params , this . network ) ;
1089+ return explainTx ( this . decodeTransactionFromPrebuild ( params ) , params , this . network ) ;
10821090 }
10831091
10841092 /**
0 commit comments