@@ -52,22 +52,47 @@ export async function handleSendMany(req: MasterApiSpecRouteRequest<'v1.wallet.s
5252 throw new Error ( `Signing keychain for ${ params . source } not found` ) ;
5353 }
5454
55+ logger . debug ( `Signing keychain: ${ JSON . stringify ( signingKeychain , null , 2 ) } ` ) ;
56+
5557 try {
5658 const prebuildParams : PrebuildTransactionOptions = {
5759 ...params ,
5860 // Convert memo string to Memo object if present
5961 memo : params . memo ? ( { type : 'text' , value : params . memo } as Memo ) : undefined ,
6062 } ;
6163
62- // First build the transaction
63- const txPrebuild = await wallet . prebuildTransaction ( {
64+ // First build the transaction with bitgo
65+ const txPrebuilt = await wallet . prebuildTransaction ( {
6466 ...prebuildParams ,
6567 reqId,
6668 } ) ;
6769
70+ // verify transaction prebuild
71+ try {
72+ const verified = await baseCoin . verifyTransaction ( {
73+ txParams : { ...prebuildParams } ,
74+ txPrebuild : txPrebuilt ,
75+ wallet,
76+ verification : { } ,
77+ reqId : reqId ,
78+ walletType : 'onchain' ,
79+ } ) ;
80+ if ( ! verified ) {
81+ throw new Error ( 'Transaction prebuild failed local validation' ) ;
82+ }
83+ logger . debug ( 'Transaction prebuild verified' ) ;
84+ } catch ( e ) {
85+ const err = e as Error ;
86+ logger . error ( 'transaction prebuild failed local validation:' , err . message ) ;
87+ logger . error ( 'transaction prebuild:' , JSON . stringify ( txPrebuilt , null , 2 ) ) ;
88+ logger . error ( err ) ;
89+ }
90+
91+ logger . debug ( 'Tx prebuild: %s' , JSON . stringify ( txPrebuilt , null , 2 ) ) ;
92+
6893 // Then sign it using the enclaved express client
6994 const signedTx = await enclavedExpressClient . signMultisig ( {
70- txPrebuild,
95+ txPrebuild : txPrebuilt ,
7196 source : params . source ,
7297 pub : signingKeychain . pub ,
7398 } ) ;
0 commit comments