@@ -7,8 +7,11 @@ import https from 'https';
77import http from 'http' ;
88import superagent from 'superagent' ;
99import { BitGo , BitGoOptions } from 'bitgo' ;
10+ import { BitGoBase } from '@bitgo/sdk-core' ;
11+ import { version } from 'bitgo/package.json' ;
1012
1113import { MasterExpressConfig , config , isMasterExpressConfig } from './config' ;
14+ import { BitGoRequest } from './types/request' ;
1215import {
1316 setupLogging ,
1417 setupDebugNamespaces ,
@@ -25,18 +28,11 @@ import bodyParser from 'body-parser';
2528import { ProxyAgent } from 'proxy-agent' ;
2629import { promiseWrapper } from './routes' ;
2730import pjson from '../package.json' ;
28- import { createEnclavedExpressClient } from './masterBitgoExpress/enclavedExpressClient ' ;
31+ import { handleGenerateWalletOnPrem } from './masterBitgoExpress/generateWallet ' ;
2932
3033const debugLogger = debug ( 'master-express:express' ) ;
31- const { version } = require ( 'bitgo/package.json' ) ;
3234const BITGOEXPRESS_USER_AGENT = `BitGoExpress/${ pjson . version } BitGoJS/${ version } ` ;
3335
34- // Add this interface before the startup function
35- interface BitGoRequest extends express . Request {
36- bitgo : BitGo ;
37- config : MasterExpressConfig ;
38- }
39-
4036/**
4137 * Create a startup function which will be run upon server initialization
4238 */
@@ -58,16 +54,6 @@ function isSSL(config: MasterExpressConfig): boolean {
5854 return Boolean ( ( keyPath && crtPath ) || ( sslKey && sslCert ) ) ;
5955}
6056
61- /**
62- *
63- * @param status
64- * @param result
65- * @param message
66- */
67- function apiResponse ( status : number , result : any , message : string ) : ApiResponseError {
68- return new ApiResponseError ( message , status , result ) ;
69- }
70-
7157const expressJSONParser = bodyParser . json ( { limit : '20mb' } ) ;
7258
7359/**
@@ -120,7 +106,7 @@ function prepareBitGo(config: MasterExpressConfig) {
120106 : { } ) ,
121107 } ;
122108
123- ( req as BitGoRequest ) . bitgo = new BitGo ( bitgoConstructorParams ) ;
109+ ( req as BitGoRequest ) . bitgo = new BitGo ( bitgoConstructorParams ) as unknown as BitGoBase ;
124110 ( req as BitGoRequest ) . config = config ;
125111
126112 next ( ) ;
@@ -179,16 +165,18 @@ function setupMasterExpressRoutes(app: express.Application): void {
179165 // Setup common health check routes
180166 setupHealthCheckRoutes ( app , 'master express' ) ;
181167
168+ const cfg = config ( ) as MasterExpressConfig ;
169+ console . log ( 'SSL Enabled:' , cfg . enableSSL ) ;
170+ console . log ( 'Enclaved Express URL:' , cfg . enclavedExpressUrl ) ;
171+ console . log ( 'Certificate exists:' , Boolean ( cfg . enclavedExpressSSLCert ) ) ;
172+ console . log ( 'Certificate length:' , cfg . enclavedExpressSSLCert . length ) ;
173+ console . log ( 'Certificate content:' , cfg . enclavedExpressSSLCert ) ;
174+
182175 // Add enclaved express ping route
183176 app . get ( '/ping/enclavedExpress' , async ( req , res ) => {
184- const cfg = config ( ) as MasterExpressConfig ;
185177 try {
186178 console . log ( 'Pinging enclaved express' ) ;
187- console . log ( 'SSL Enabled:' , cfg . enableSSL ) ;
188- console . log ( 'Enclaved Express URL:' , cfg . enclavedExpressUrl ) ;
189- console . log ( 'Certificate exists:' , Boolean ( cfg . enclavedExpressSSLCert ) ) ;
190- console . log ( 'Certificate length:' , cfg . enclavedExpressSSLCert . length ) ;
191- console . log ( 'Certificate content:' , cfg . enclavedExpressSSLCert ) ;
179+
192180 const response = await superagent
193181 . get ( `${ cfg . enclavedExpressUrl } /ping` )
194182 . ca ( cfg . enclavedExpressSSLCert )
@@ -213,6 +201,14 @@ function setupMasterExpressRoutes(app: express.Application): void {
213201 }
214202 } ) ;
215203
204+ // TODO: Add api-ts to these new API routes
205+ app . post (
206+ '/api/:coin/wallet/generate' ,
207+ parseBody ,
208+ prepareBitGo ( config ( ) as MasterExpressConfig ) ,
209+ promiseWrapper ( handleGenerateWalletOnPrem ) ,
210+ ) ;
211+
216212 // Add a catch-all for unsupported routes
217213 app . use ( '*' , ( _req , res ) => {
218214 res . status ( 404 ) . json ( {
0 commit comments