@@ -3,7 +3,7 @@ import { randomBytes } from 'crypto';
33
44import _ from 'lodash' ;
55import * as utxolib from '@bitgo/utxo-lib' ;
6- import { BIP32 , fixedScriptWallet } from '@bitgo/wasm-utxo' ;
6+ import { BIP32 , fixedScriptWallet , hasPsbtMagic } from '@bitgo/wasm-utxo' ;
77import { bitgo , getMainnet } from '@bitgo/utxo-lib' ;
88import {
99 AddressCoinSpecific ,
@@ -86,13 +86,8 @@ import {
8686 UtxoCoinNameMainnet ,
8787} from './names' ;
8888import { assertFixedScriptWalletAddress } from './address/fixedScript' ;
89- import { isSdkBackend , ParsedTransaction , SdkBackend } from './transaction/types' ;
90- import {
91- decodeDescriptorPsbt ,
92- decodePsbtWith ,
93- encodeTransaction ,
94- stringToBufferTryFormats ,
95- } from './transaction/decode' ;
89+ import { ParsedTransaction } from './transaction/types' ;
90+ import { decodeDescriptorPsbt , decodePsbt , encodeTransaction , stringToBufferTryFormats } from './transaction/decode' ;
9691import { fetchKeychains , toBip32Triple , UtxoKeychain } from './keychains' ;
9792import { verifyKeySignature , verifyUserPublicKey , verifyUserPublicKeyAsync } from './verifyKey' ;
9893import { getPolicyForEnv } from './descriptor/validatePolicy' ;
@@ -250,7 +245,6 @@ export interface ExplainTransactionOptions<TNumber extends number | bigint = num
250245 feeInfo ?: string ;
251246 pubs ?: Triple < string > ;
252247 customChangeXpubs ?: Triple < string > ;
253- decodeWith ?: SdkBackend ;
254248}
255249
256250export interface DecoratedExplainTransactionOptions < TNumber extends number | bigint = number >
@@ -263,7 +257,6 @@ export type UtxoNetwork = utxolib.Network;
263257export interface TransactionPrebuild < TNumber extends number | bigint = number > extends BaseTransactionPrebuild {
264258 txInfo ?: TransactionInfo < TNumber > ;
265259 blockHeight ?: number ;
266- decodeWith ?: SdkBackend ;
267260 /**
268261 * PSBT-lite hex present only in pending approval flows, where another user's send fixed the format.
269262 * Not set in regular /tx/build responses (where the caller controls the build parameters).
@@ -332,7 +325,6 @@ type UtxoBaseSignTransactionOptions<TNumber extends number | bigint = number> =
332325 walletId ?: string ;
333326 txHex : string ;
334327 txInfo ?: TransactionInfo < TNumber > ;
335- decodeWith ?: SdkBackend ;
336328 } ;
337329 /** xpubs triple for wallet (user, backup, bitgo). Required only when txPrebuild.txHex is not a PSBT */
338330 pubs ?: Triple < string > ;
@@ -421,10 +413,7 @@ export interface SignPsbtResponse {
421413 psbt : string ;
422414}
423415
424- export abstract class AbstractUtxoCoin
425- extends BaseCoin
426- implements Musig2Participant < utxolib . bitgo . UtxoPsbt > , Musig2Participant < fixedScriptWallet . BitGoPsbt >
427- {
416+ export abstract class AbstractUtxoCoin extends BaseCoin implements Musig2Participant < fixedScriptWallet . BitGoPsbt > {
428417 abstract name : UtxoCoinName ;
429418
430419 /**
@@ -438,23 +427,11 @@ export abstract class AbstractUtxoCoin
438427
439428 public readonly amountType : 'number' | 'bigint' ;
440429
441- protected supportedTxFormats : { psbt : boolean ; legacy : boolean } = {
442- psbt : true ,
443- legacy : false ,
444- } ;
445-
446- protected supportedSdkBackends : { utxolib : boolean ; 'wasm-utxo' : boolean } = {
447- utxolib : false ,
448- 'wasm-utxo' : true ,
449- } ;
450-
451430 protected constructor ( bitgo : BitGoBase , amountType : 'number' | 'bigint' = 'number' ) {
452431 super ( bitgo ) ;
453432 this . amountType = amountType ;
454433 }
455434
456- defaultSdkBackend : SdkBackend = 'wasm-utxo' ;
457-
458435 /**
459436 * @deprecated - will be removed when we drop support for utxolib
460437 * Use `name` property instead.
@@ -628,65 +605,29 @@ export abstract class AbstractUtxoCoin
628605 return utxolib . bitgo . createTransactionFromHex < TNumber > ( hex , this . network , this . amountType ) ;
629606 }
630607
631- decodeTransaction < TNumber extends number | bigint > (
632- input : Buffer | string ,
633- decodeWith : SdkBackend = this . defaultSdkBackend
634- ) : DecodedTransaction < TNumber > {
635- if ( typeof input === 'string' ) {
636- const buffer = stringToBufferTryFormats ( input , [ 'hex' , 'base64' ] ) ;
637- return this . decodeTransaction ( buffer , decodeWith ) ;
638- }
639-
640- if ( utxolib . bitgo . isPsbt ( input ) ) {
641- if ( this . supportedSdkBackends [ decodeWith ] !== true ) {
642- throw new Error ( `SDK support for decodeWith=${ decodeWith } is not available on this environment.` ) ;
643- }
644-
645- if ( ! this . supportedTxFormats . psbt ) {
646- throw new ErrorDeprecatedTxFormat ( 'psbt' ) ;
647- }
648- return decodePsbtWith ( input , this . name , decodeWith ) ;
649- } else {
650- // Legacy format transactions are deprecated. This will be an unconditional error in the future.
651- if ( ! this . supportedTxFormats . legacy ) {
652- throw new ErrorDeprecatedTxFormat ( 'legacy' ) ;
653- }
654- if ( decodeWith !== 'utxolib' ) {
655- console . error ( 'received decodeWith hint %s, ignoring for legacy transaction' , decodeWith ) ;
656- }
657- return utxolib . bitgo . createTransactionFromBuffer ( input , this . network , {
658- amountType : this . amountType ,
659- } ) ;
608+ decodeTransaction ( input : Buffer | string ) : fixedScriptWallet . BitGoPsbt {
609+ const buffer = typeof input === 'string' ? stringToBufferTryFormats ( input , [ 'hex' , 'base64' ] ) : input ;
610+ if ( ! hasPsbtMagic ( buffer ) ) {
611+ throw new ErrorDeprecatedTxFormat ( 'legacy' ) ;
660612 }
613+ return decodePsbt ( buffer , this . name ) ;
661614 }
662615
663- decodeTransactionAsPsbt ( input : Buffer | string ) : utxolib . bitgo . UtxoPsbt | fixedScriptWallet . BitGoPsbt {
664- const decoded = this . decodeTransaction ( input ) ;
665- if ( decoded instanceof fixedScriptWallet . BitGoPsbt || decoded instanceof utxolib . bitgo . UtxoPsbt ) {
666- return decoded ;
667- }
668- throw new Error ( 'expected psbt but got transaction' ) ;
616+ decodeTransactionAsPsbt ( input : Buffer | string ) : fixedScriptWallet . BitGoPsbt {
617+ return this . decodeTransaction ( input ) ;
669618 }
670619
671- decodeTransactionFromPrebuild < TNumber extends number | bigint > ( prebuild : {
620+ decodeTransactionFromPrebuild ( prebuild : {
672621 txHex ?: string ;
673622 txBase64 ?: string ;
674623 /** See TransactionPrebuild.txHexPsbt — only present in pending approval flows. */
675624 txHexPsbt ?: string ;
676- decodeWith ?: string ;
677- } ) : DecodedTransaction < TNumber > {
625+ } ) : fixedScriptWallet . BitGoPsbt {
678626 const string = prebuild . txHexPsbt ?? prebuild . txHex ?? prebuild . txBase64 ;
679627 if ( ! string ) {
680628 throw new Error ( 'missing required txHex or txBase64 property' ) ;
681629 }
682- let { decodeWith } = prebuild ;
683- if ( decodeWith !== undefined ) {
684- if ( typeof decodeWith !== 'string' || ! isSdkBackend ( decodeWith ) ) {
685- console . error ( 'decodeWith %s is not a valid value, using default' , decodeWith ) ;
686- decodeWith = undefined ;
687- }
688- }
689- return this . decodeTransaction ( string , decodeWith ) ;
630+ return this . decodeTransaction ( string ) ;
690631 }
691632
692633 /**
@@ -845,26 +786,13 @@ export abstract class AbstractUtxoCoin
845786 * @param psbt all MuSig2 inputs should contain user MuSig2 nonce
846787 * @param walletId
847788 */
848- async getMusig2Nonces ( psbt : utxolib . bitgo . UtxoPsbt , walletId : string ) : Promise < utxolib . bitgo . UtxoPsbt > ;
849- async getMusig2Nonces ( psbt : fixedScriptWallet . BitGoPsbt , walletId : string ) : Promise < fixedScriptWallet . BitGoPsbt > ;
850- async getMusig2Nonces < T extends utxolib . bitgo . UtxoPsbt | fixedScriptWallet . BitGoPsbt > (
851- psbt : T ,
852- walletId : string
853- ) : Promise < T > ;
854- async getMusig2Nonces < T extends utxolib . bitgo . UtxoPsbt | fixedScriptWallet . BitGoPsbt > (
855- psbt : T ,
856- walletId : string
857- ) : Promise < T > {
789+ async getMusig2Nonces ( psbt : fixedScriptWallet . BitGoPsbt , walletId : string ) : Promise < fixedScriptWallet . BitGoPsbt > {
858790 const buffer = encodeTransaction ( psbt ) ;
859791 const response = await this . bitgo
860792 . post ( this . url ( '/wallet/' + walletId + '/tx/signpsbt' ) )
861793 . send ( { psbt : buffer . toString ( 'hex' ) } )
862794 . result ( ) ;
863- if ( psbt instanceof utxolib . bitgo . UtxoPsbt ) {
864- return decodePsbtWith ( response . psbt , this . name , 'utxolib' ) as T ;
865- } else {
866- return decodePsbtWith ( response . psbt , this . name , 'wasm-utxo' ) as T ;
867- }
795+ return decodePsbt ( response . psbt , this . name ) ;
868796 }
869797
870798 /**
0 commit comments