Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/api/enclaved/handlers/ecdsaMPCv2Initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export async function ecdsaMPCv2Initialize(
encryptedData,
};
} catch (error) {
logger.debug('Failed to initialize mpc key generation', error);
console.error('Encryption error details:', error);
logger.error('Failed to initialize mpc key generation', error);
throw error;
}
}
6 changes: 0 additions & 6 deletions src/api/master/handlers/handleSendMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ export async function handleSendMany(req: MasterApiSpecRouteRequest<'v1.wallet.s
}

const keyIdIndex = params.source === 'user' ? KeyIndices.USER : KeyIndices.BACKUP;
logger.info(`Key ID index: ${keyIdIndex}`);
logger.info(`Key IDs: ${JSON.stringify(wallet.keyIds(), null, 2)}`);

// Get the signing keychains
const signingKeychain = await baseCoin.keychains().get({
Expand Down Expand Up @@ -140,8 +138,6 @@ export async function handleSendMany(req: MasterApiSpecRouteRequest<'v1.wallet.s
reqId,
});

logger.debug('Tx prebuild: %s', JSON.stringify(txPrebuilt, null, 2));

// verify transaction prebuild
try {
const verified = await baseCoin.verifyTransaction({
Expand All @@ -163,8 +159,6 @@ export async function handleSendMany(req: MasterApiSpecRouteRequest<'v1.wallet.s
throw new BadRequestError(`Transaction prebuild failed local validation: ${err.message}`);
}

logger.debug('Tx prebuild: %s', JSON.stringify(txPrebuilt, null, 2));

return signAndSendMultisig(
wallet,
req.decoded.source,
Expand Down
5 changes: 0 additions & 5 deletions src/api/master/handlers/handleSignAndSendTxRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,11 @@ export async function handleSignAndSendTxRequest(
);
}

logger.debug(`Signing keychain: ${JSON.stringify(signingKeychain, null, 2)}`);
logger.debug(`Params: ${JSON.stringify(params, null, 2)}`);

const txRequest = await getTxRequest(bitgo, wallet.id(), req.params.txRequestId, reqId);
if (!txRequest) {
throw new Error(`TxRequest ${req.params.txRequestId} not found`);
}

logger.debug(`TxRequest: ${JSON.stringify(txRequest, null, 2)}`);

return signAndSendTxRequests(
bitgo,
wallet,
Expand Down
4 changes: 1 addition & 3 deletions src/api/master/handlers/recoveryConsolidationsWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ export async function handleRecoveryConsolidationsOnPrem(
bitgoKey: bitgoPub,
});

console.log(`Recovery consolidations result: ${JSON.stringify(result)}`);

if (result.transactions) {
txs = result.transactions;
} else if (result.txRequests) {
Expand All @@ -111,7 +109,7 @@ export async function handleRecoveryConsolidationsOnPrem(
throw new Error('recoverConsolidations did not return expected transactions');
}

logger.debug(`Found ${txs.length} unsigned consolidation transactions`);
logger.info(`Found ${txs.length} unsigned consolidation transactions`);

const signedTxs = [];
try {
Expand Down
2 changes: 0 additions & 2 deletions src/api/master/routers/enclavedExpressHealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ export function createEnclavedExpressRouter(

router.get('v1.enclaved.version', [
responseHandler(async () => {
logger.debug('Getting version from enclaved express');

try {
// Use the client's getVersion method instead of direct HTTP request
const versionResponse = await enclavedClient.getVersion();
Expand Down
3 changes: 1 addition & 2 deletions src/enclavedApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ export function createBaseUri(config: EnclavedConfig): string {
* Create and configure the express application
*/
export function app(cfg: EnclavedConfig): express.Application {
logger.debug('app is initializing');
logger.info('App is initializing');

const app = express();

setupLogging(app, cfg);
logger.debug('logging setup');

// Add custom morgan token for mTLS client certificate
morgan.token('remote-user', function (req: express.Request) {
Expand Down
8 changes: 4 additions & 4 deletions src/initConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function configureEnclavedMode(): EnclavedConfig {
throw new Error(`Failed to read TLS key from keyPath: ${err.message}`);
}
} else if (config.tlsKey) {
logger.debug('Using TLS private key from environment variable');
logger.info('Using TLS private key from environment variable');
}

if (!config.tlsCert && config.crtPath) {
Expand All @@ -166,7 +166,7 @@ function configureEnclavedMode(): EnclavedConfig {
throw new Error(`Failed to read TLS certificate from crtPath: ${err.message}`);
}
} else if (config.tlsCert) {
logger.debug('Using TLS certificate from environment variable');
logger.info('Using TLS certificate from environment variable');
}

// Validate that certificates are properly loaded when TLS is enabled
Expand Down Expand Up @@ -323,7 +323,7 @@ export function configureMasterExpressMode(): MasterExpressConfig {
throw new Error(`Failed to read TLS key from keyPath: ${err.message}`);
}
} else if (config.tlsKey) {
logger.debug('Using TLS private key from environment variable');
logger.info('Using TLS private key from environment variable');
}

if (!config.tlsCert && config.crtPath) {
Expand All @@ -335,7 +335,7 @@ export function configureMasterExpressMode(): MasterExpressConfig {
throw new Error(`Failed to read TLS certificate from crtPath: ${err.message}`);
}
} else if (config.tlsCert) {
logger.debug('Using TLS certificate from environment variable');
logger.info('Using TLS certificate from environment variable');
}

// Validate that certificates are properly loaded when TLS is enabled
Expand Down
4 changes: 1 addition & 3 deletions src/masterExpressApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ export function createBaseUri(config: MasterExpressConfig): string {
* Create and configure the express application for master express mode
*/
export function app(cfg: MasterExpressConfig): express.Application {
logger.debug('master express app is initializing');
logger.info('Master express app is initializing');

const app = express();

setupLogging(app, cfg);
logger.debug('logging setup');

setupCommonMiddleware(app, cfg);

// Add mTLS middleware before routes if in mTLS mode
Expand Down
3 changes: 0 additions & 3 deletions src/routes/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import express from 'express';
import { MasterExpressConfig } from '../shared/types';
import { createHealthCheckRouter } from '../api/master/routers/healthCheck';
import { createEnclavedExpressRouter } from '../api/master/routers/enclavedExpressHealth';
import logger from '../logger';
import { createMasterApiRouter } from '../api/master/routers/masterApiSpec';

/**
Expand All @@ -17,6 +16,4 @@ export function setupRoutes(app: express.Application, cfg: MasterExpressConfig):
app.use(createEnclavedExpressRouter(cfg));

app.use(createMasterApiRouter(cfg));

logger.debug('Master express routes configured');
}
15 changes: 13 additions & 2 deletions src/shared/responseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ForbiddenError,
ConflictError,
} from './errors';
import logger from '../logger';

// Extend Express Response to include sendEncoded
interface EncodedResponse extends ExpressResponse {
Expand Down Expand Up @@ -53,6 +54,7 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
error: 'BitGoApiResponseError',
details: apiError.result,
};
logger.error(JSON.stringify(apiError.result, null, 2));
return res.status(apiError.status).json(body);
}

Expand All @@ -74,6 +76,13 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
statusCode = 409;
}

const errorBody = {
name: error.name,
message: error.message,
stack: error.stack,
};
// Log the error details for debugging
logger.error(JSON.stringify(errorBody, null, 2));
return res.sendEncoded(statusCode, {
error: error.message,
name: error.name,
Expand All @@ -91,11 +100,13 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
}

// Default error response
return res.sendEncoded(500, {
const errorBody = {
error: 'Internal Server Error',
name: error instanceof Error ? error.name : 'Error',
details: error instanceof Error ? error.message : String(error),
});
};
logger.error(JSON.stringify(errorBody, null, 2));
return res.sendEncoded(500, errorBody);
}
};
}