@@ -62,7 +62,6 @@ import { handleLightningWithdraw } from './lightning/lightningWithdrawRoutes';
6262import createExpressRouter from './typedRoutes' ;
6363import { ExpressApiRouteRequest } from './typedRoutes/api' ;
6464import { TypedRequestHandler , WrappedRequest , WrappedResponse } from '@api-ts/typed-express-router' ;
65- import { isJsonString } from './utils' ;
6665
6766const { version } = require ( 'bitgo/package.json' ) ;
6867const pjson = require ( '../package.json' ) ;
@@ -590,10 +589,10 @@ export async function handleV2OFCSignPayloadInExtSigningMode(
590589 }
591590}
592591
593- export async function handleV2OFCSignPayload ( req : express . Request ) : Promise < { payload : string ; signature : string } > {
594- const walletId = req . body . walletId ;
595- const payload = req . body . payload ;
596- const bodyWalletPassphrase = req . body . walletPassphrase ;
592+ export async function handleV2OFCSignPayload (
593+ req : ExpressApiRouteRequest < 'express.ofc.signPayload' , 'post' >
594+ ) : Promise < { payload : string ; signature : string } > {
595+ const { walletId , payload , walletPassphrase : bodyWalletPassphrase } = req . decoded ;
597596 const ofcCoinName = 'ofc' ;
598597
599598 // If the externalSignerUrl is set, forward the request to the express server hosted on the externalSignerUrl
@@ -612,14 +611,6 @@ export async function handleV2OFCSignPayload(req: express.Request): Promise<{ pa
612611 return payloadWithSignature ;
613612 }
614613
615- if ( ! payload ) {
616- throw new ApiResponseError ( 'Missing required field: payload' , 400 ) ;
617- }
618-
619- if ( ! walletId ) {
620- throw new ApiResponseError ( 'Missing required field: walletId' , 400 ) ;
621- }
622-
623614 const bitgo = req . bitgo ;
624615
625616 // This is to set us up for multiple trading accounts per enterprise
@@ -631,7 +622,7 @@ export async function handleV2OFCSignPayload(req: express.Request): Promise<{ pa
631622
632623 const walletPassphrase = bodyWalletPassphrase || getWalletPwFromEnv ( wallet . id ( ) ) ;
633624 const tradingAccount = wallet . toTradingAccount ( ) ;
634- const stringifiedPayload = isJsonString ( req . body . payload ) ? req . body . payload : JSON . stringify ( req . body . payload ) ;
625+ const stringifiedPayload = JSON . stringify ( payload ) ;
635626 const signature = await tradingAccount . signPayload ( {
636627 payload : stringifiedPayload ,
637628 walletPassphrase,
@@ -1639,7 +1630,7 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
16391630 ) ;
16401631
16411632 // sign arbitrary payloads w/ trading account key
1642- app . post ( `/api/v2/ ofc/ signPayload` , parseBody , prepareBitGo ( config ) , promiseWrapper ( handleV2OFCSignPayload ) ) ;
1633+ router . post ( 'express. ofc. signPayload' , [ prepareBitGo ( config ) , typedPromiseWrapper ( handleV2OFCSignPayload ) ] ) ;
16431634
16441635 // sign transaction
16451636 app . post ( '/api/v2/:coin/signtx' , parseBody , prepareBitGo ( config ) , promiseWrapper ( handleV2SignTx ) ) ;
0 commit comments