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
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'should';

import * as request from 'supertest';
import nock from 'nock';
import { app as enclavedApp } from '../enclavedApp';
import { AppMode, EnclavedConfig, TlsMode } from '../types';
import { app as enclavedApp } from '../../../enclavedApp';
import { AppMode, EnclavedConfig, TlsMode } from '../../../shared/types';
import express from 'express';

import * as sinon from 'sinon';
import * as configModule from '../initConfig';
import * as configModule from '../../../initConfig';

describe('postIndependentKey', () => {
let cfg: EnclavedConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'should';

import * as request from 'supertest';
import nock from 'nock';
import { app as enclavedApp } from '../enclavedApp';
import { AppMode, EnclavedConfig, TlsMode } from '../types';
import { app as enclavedApp } from '../../../enclavedApp';
import { AppMode, EnclavedConfig, TlsMode } from '../../../shared/types';
import express from 'express';
import * as sinon from 'sinon';
import * as configModule from '../initConfig';
import * as configModule from '../../../initConfig';
import { Ed25519BIP32, Eddsa, SignatureShareType } from '@bitgo/sdk-core';

describe('signMpcTransaction', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'should';

import * as request from 'supertest';
import nock from 'nock';
import { app as enclavedApp } from '../enclavedApp';
import { AppMode, EnclavedConfig, TlsMode } from '../types';
import { app as enclavedApp } from '../../../enclavedApp';
import { AppMode, EnclavedConfig, TlsMode } from '../../../shared/types';
import express from 'express';

import * as sinon from 'sinon';
import * as configModule from '../initConfig';
import * as configModule from '../../../initConfig';

describe('signMultisigTransaction', () => {
let cfg: EnclavedConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'should';

import * as request from 'supertest';
import nock from 'nock';
import { app as expressApp } from '../../masterExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../types';
import { app as expressApp } from '../../../masterExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { Environments } from '@bitgo/sdk-core';
import assert from 'assert';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import sinon from 'sinon';

import * as request from 'supertest';
import nock from 'nock';
import { app as expressApp } from '../../masterExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../types';
import { app as expressApp } from '../../../masterExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { Environments, Wallet } from '@bitgo/sdk-core';
import { Coin } from 'bitgo';
import assert from 'assert';
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/routes.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'should';
import express from 'express';

import request from 'supertest';
import express from 'express';
import { AppMode, TlsMode } from '../shared/types';
import { setupRoutes } from '../routes/enclaved';
import { AppMode, TlsMode } from '../types';

describe('Routes', () => {
let app: express.Application;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BitGo } from 'bitgo';
import { KmsClient } from '../../kms/kmsClient';
import { EnclavedApiSpecRouteRequest } from '../../enclavedBitgoExpress/routers/enclavedApiSpec';
import { KmsClient } from '../../../kms/kmsClient';
import { EnclavedApiSpecRouteRequest } from '../../../enclavedBitgoExpress/routers/enclavedApiSpec';

export async function postIndependentKey(
req: EnclavedApiSpecRouteRequest<'v1.key.independent', 'post'>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SignFinalOptions } from '@bitgo/abstract-eth';
import { MethodNotImplementedError } from 'bitgo';
import { EnclavedApiSpecRouteRequest } from '../../enclavedBitgoExpress/routers/enclavedApiSpec';
import logger from '../../logger';
import { isEthLikeCoin } from '../../shared/coinUtils';
import { retrieveKmsPrvKey } from './utils';
import { EnclavedApiSpecRouteRequest } from '../../../enclavedBitgoExpress/routers/enclavedApiSpec';
import logger from '../../../logger';
import { isEthLikeCoin } from '../../../shared/coinUtils';
import { retrieveKmsPrvKey } from '../utils';

export async function recoveryMultisigTransaction(
req: EnclavedApiSpecRouteRequest<'v1.multisig.recovery', 'post'>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EnclavedApiSpecRouteRequest } from '../../enclavedBitgoExpress/routers/enclavedApiSpec';
import { decryptDataKey, generateDataKey, retrieveKmsPrvKey } from './utils';
import logger from '../../logger';
import { EnclavedApiSpecRouteRequest } from '../../../enclavedBitgoExpress/routers/enclavedApiSpec';
import { decryptDataKey, generateDataKey, retrieveKmsPrvKey } from '../utils';
import logger from '../../../logger';
import {
TxRequest,
EddsaUtils,
Expand All @@ -10,7 +10,7 @@ import {
SignatureShareRecord,
GShare,
} from '@bitgo/sdk-core';
import { EnclavedConfig } from '../../types';
import { EnclavedConfig } from '../../../shared/types';
import { BitGoBase, BaseCoin } from 'bitgo';

// Define share types for different MPC algorithms
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { KmsClient } from '../../kms/kmsClient';
import { KmsClient } from '../../../kms/kmsClient';
import { TransactionPrebuild } from 'bitgo';
import logger from '../../logger';
import { EnclavedApiSpecRouteRequest } from '../../enclavedBitgoExpress/routers/enclavedApiSpec';
import logger from '../../../logger';
import { EnclavedApiSpecRouteRequest } from '../../../enclavedBitgoExpress/routers/enclavedApiSpec';

export async function signMultisigTransaction(
req: EnclavedApiSpecRouteRequest<'v1.multisig.sign', 'post'>,
Expand Down
3 changes: 2 additions & 1 deletion src/api/enclaved/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// TODO: this function is duplicated in multisigTransactioSign.ts but as hardcoded. Replace that code later with this call (to avoid merge conflicts/duplication)
import { KmsClient } from '../../kms/kmsClient';
import { GenerateDataKeyResponse } from '../../kms/types/dataKey';
import { EnclavedConfig } from '../../types';
import { EnclavedConfig } from '../../shared/types';

export async function retrieveKmsPrvKey({
pub,
source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { SignedTransaction, TransactionPrebuild } from '@bitgo/sdk-core';
import { superagentRequestFactory, buildApiClient, ApiClient } from '@api-ts/superagent-wrapper';
import { OfflineVaultTxInfo, RecoveryInfo, UnsignedSweepTxMPCv2 } from '@bitgo/sdk-coin-eth';

import { MasterExpressConfig } from '../types';
import { TlsMode } from '../types';
import { EnclavedApiSpec } from '../enclavedBitgoExpress/routers';
import { PingResponseType, VersionResponseType } from '../types/health';
import { MasterExpressConfig, TlsMode } from '../../../shared/types';
import { EnclavedApiSpec } from '../../../enclavedBitgoExpress/routers';
import { PingResponseType, VersionResponseType } from '../../../types/health';

const debugLogger = debug('bitgo:express:enclavedExpressClient');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
AddKeychainOptions,
} from '@bitgo/sdk-core';
import _ from 'lodash';
import { MasterApiSpecRouteRequest } from './routers/masterApiSpec';
import { MasterApiSpecRouteRequest } from '../routers/masterApiSpec';

/**
* This route is used to generate a multisig wallet when enclaved express is enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RequestTracer, PrebuildTransactionOptions, Memo, KeyIndices } from '@bitgo/sdk-core';
import logger from '../logger';
import { MasterApiSpecRouteRequest } from './routers/masterApiSpec';
import logger from '../../../logger';
import { MasterApiSpecRouteRequest } from '../routers/masterApiSpec';

/**
* Defines the structure for a single recipient in a send-many transaction.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MethodNotImplementedError } from 'bitgo';
import { isEthLikeCoin } from '../shared/coinUtils';
import { MasterApiSpecRouteRequest } from './routers/masterApiSpec';
import { isEthLikeCoin } from '../../../shared/coinUtils';
import { MasterApiSpecRouteRequest } from '../routers/masterApiSpec';

export async function handleRecoveryWalletOnPrem(
req: MasterApiSpecRouteRequest<'v1.wallet.recovery', 'post'>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from 'express';
import { isMasterExpressConfig } from '../types';
import { createEnclavedExpressClient } from './enclavedExpressClient';
import { BitGoRequest } from '../types/request';
import { isMasterExpressConfig } from '../../../shared/types';
import { createEnclavedExpressClient } from '../clients/enclavedExpressClient';
import { BitGoRequest } from '../../../types/request';

/**
* Middleware to validate master express configuration and enclaved express client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as t from 'io-ts';
import { apiSpec, httpRoute, httpRequest, HttpResponse } from '@api-ts/io-ts-http';
import { createRouter, type WrappedRouter } from '@api-ts/typed-express-router';
import { Response } from '@api-ts/response';
import { MasterExpressConfig } from '../../initConfig';
import logger from '../../logger';
import { responseHandler } from '../../shared/middleware';
import { EnclavedExpressClient } from '../enclavedExpressClient';
import { PingResponseType, VersionResponseType } from '../../types/health';
import { MasterExpressConfig } from '../../../shared/types';
import logger from '../../../logger';
import { responseHandler } from '../../../shared/middleware';
import { EnclavedExpressClient } from '../clients/enclavedExpressClient';
import { PingResponseType, VersionResponseType } from '../../../types/health';

// Response type for /ping/enclavedExpress endpoint
const PingEnclavedResponse: HttpResponse = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { apiSpec, httpRoute, httpRequest, HttpResponse } from '@api-ts/io-ts-http';
import { createRouter, type WrappedRouter } from '@api-ts/typed-express-router';
import { Response } from '@api-ts/response';
import pjson from '../../../package.json';
import { responseHandler } from '../../shared/middleware';
import { PingResponseType, VersionResponseType } from '../../types/health';
import pjson from '../../../../package.json';
import { responseHandler } from '../../../shared/middleware';
import { PingResponseType, VersionResponseType } from '../../../types/health';

// API Response types
const PingResponse: HttpResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
} from '@api-ts/typed-express-router';
import express from 'express';
import * as t from 'io-ts';
import { MasterExpressConfig } from '../../initConfig';
import { prepareBitGo, responseHandler } from '../../shared/middleware';
import { BitGoRequest } from '../../types/request';
import { handleGenerateWalletOnPrem } from '../generateWallet';
import { handleSendMany } from '../handleSendMany';
import { validateMasterExpressConfig } from '../middleware';
import { handleRecoveryWalletOnPrem } from '../recoveryWallet';
import { MasterExpressConfig } from '../../../shared/types';
import { prepareBitGo, responseHandler } from '../../../shared/middleware';
import { BitGoRequest } from '../../../types/request';
import { handleGenerateWalletOnPrem } from '../handlers/generateWallet';
import { handleSendMany } from '../handlers/handleSendMany';
import { validateMasterExpressConfig } from '../middleware/middleware';
import { handleRecoveryWalletOnPrem } from '../handlers/recoveryWallet';

// Middleware functions
export function parseBody(req: express.Request, res: express.Response, next: express.NextFunction) {
Expand Down
3 changes: 2 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { determineAppMode, AppMode } from './initConfig';
import { determineAppMode } from './initConfig';
import { AppMode } from './shared/types';
import * as enclavedApp from './enclavedApp';
import * as masterExpressApp from './masterExpressApp';
import logger from './logger';
Expand Down
3 changes: 2 additions & 1 deletion src/enclavedApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import http from 'http';
import morgan from 'morgan';
import { SSL_OP_NO_TLSv1, SSL_OP_NO_TLSv1_1 } from 'constants';

import { EnclavedConfig, initConfig, TlsMode, isEnclavedConfig } from './initConfig';
import { EnclavedConfig, TlsMode, isEnclavedConfig } from './shared/types';
import { initConfig } from './initConfig';
import { setupRoutes } from './routes/enclaved';
import {
setupLogging,
Expand Down
10 changes: 5 additions & 5 deletions src/enclavedBitgoExpress/routers/enclavedApiSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
} from '@api-ts/typed-express-router';
import express from 'express';
import * as t from 'io-ts';
import { postIndependentKey } from '../../api/enclaved/postIndependentKey';
import { recoveryMultisigTransaction } from '../../api/enclaved/recoveryMultisigTransaction';
import { signMultisigTransaction } from '../../api/enclaved/signMultisigTransaction';
import { signMpcTransaction } from '../../api/enclaved/signMpcTransaction';
import { postIndependentKey } from '../../api/enclaved/handlers/postIndependentKey';
import { recoveryMultisigTransaction } from '../../api/enclaved/handlers/recoveryMultisigTransaction';
import { signMultisigTransaction } from '../../api/enclaved/handlers/signMultisigTransaction';
import { signMpcTransaction } from '../../api/enclaved/handlers/signMpcTransaction';
import { prepareBitGo, responseHandler } from '../../shared/middleware';
import { EnclavedConfig } from '../../types';
import { EnclavedConfig } from '../../shared/types';
import { BitGoRequest } from '../../types/request';

// Request type for /key/independent endpoint
Expand Down
2 changes: 1 addition & 1 deletion src/initConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TlsMode,
AppMode,
EnvironmentName,
} from './types';
} from './shared/types';
import logger from './logger';
import { validateTlsCertificates, validateMasterExpressConfig } from './shared/appUtils';

Expand Down
2 changes: 1 addition & 1 deletion src/kms/kmsClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import debug from 'debug';
import * as superagent from 'superagent';
import { EnclavedConfig, isMasterExpressConfig } from '../initConfig';
import { EnclavedConfig, isMasterExpressConfig } from '../shared/types';
import { PostKeyKmsSchema, PostKeyParams, PostKeyResponse } from './types/postKey';
import { GetKeyKmsSchema, GetKeyParams, GetKeyResponse } from './types/getKey';
import {
Expand Down
3 changes: 2 additions & 1 deletion src/masterExpressApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import https from 'https';
import http from 'http';
import { SSL_OP_NO_TLSv1, SSL_OP_NO_TLSv1_1 } from 'constants';

import { MasterExpressConfig, initConfig, isMasterExpressConfig, TlsMode } from './initConfig';
import { MasterExpressConfig, isMasterExpressConfig, TlsMode } from './shared/types';
import { initConfig } from './initConfig';
import {
setupLogging,
setupCommonMiddleware,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/enclaved.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import express from 'express';
import debug from 'debug';
import { createHealthCheckRouter } from '../enclavedBitgoExpress/routers/healthCheck';
import { EnclavedConfig } from '../shared/types';
import { createKeyGenRouter } from '../enclavedBitgoExpress/routers/enclavedApiSpec';
import { EnclavedConfig } from '../types';
import { createHealthCheckRouter } from '../enclavedBitgoExpress/routers/healthCheck';

const debugLogger = debug('enclaved:routes');
/**
Expand Down
8 changes: 4 additions & 4 deletions src/routes/master.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import express from 'express';
import { MasterExpressConfig } from '../types';
import { createHealthCheckRouter } from '../masterBitgoExpress/routers/healthCheck';
import { createEnclavedExpressRouter } from '../masterBitgoExpress/routers/enclavedExpressHealth';
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 '../masterBitgoExpress/routers/masterApiSpec';
import { createMasterApiRouter } from '../api/master/routers/masterApiSpec';

/**
* Setup master express specific routes
Expand Down
2 changes: 1 addition & 1 deletion src/shared/appUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import bodyParser from 'body-parser';
import pjson from '../../package.json';
import logger from '../logger';

import { Config, TlsMode } from '../initConfig';
import { Config, TlsMode } from '../shared/types';

/**
* Set up the logging middleware provided by morgan
Expand Down
Empty file removed src/shared/bitgoUtils.ts
Empty file.
2 changes: 1 addition & 1 deletion src/shared/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, isMasterExpressConfig } from '../types';
import { Config, isMasterExpressConfig } from '../shared/types';
import express from 'express';
import { BitGoRequest } from '../types/request';
import { BitGo } from 'bitgo';
Expand Down
2 changes: 1 addition & 1 deletion src/shared/responseHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response as ExpressResponse, NextFunction } from 'express';
import { Config } from '../types';
import { Config } from '../shared/types';
import { BitGoRequest } from '../types/request';
import { EnclavedError } from '../errors';

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/types/request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express';
import { type BitGo } from 'bitgo';
import { Config } from '../types';
import { EnclavedExpressClient } from '../masterBitgoExpress/enclavedExpressClient';
import { Config } from '../shared/types';
import { EnclavedExpressClient } from '../api/master/clients/enclavedExpressClient';

// Extended request type for BitGo Express
export interface BitGoRequest<T extends Config = Config> extends express.Request {
Expand Down