1
1
import { EnvironmentName , V1Network } from 'bitgo' ;
2
2
import { isNil , isNumber } from 'lodash' ;
3
+ import { readFileSync , existsSync } from 'fs' ;
3
4
import 'dotenv/config' ;
4
5
5
6
import { args } from './args' ;
@@ -38,6 +39,8 @@ export interface Config {
38
39
customBitcoinNetwork ?: V1Network ;
39
40
authVersion : number ;
40
41
externalSignerUrl ?: string ;
42
+ enclavedExpressUrl ?: string ;
43
+ enclavedExpressSSLCert ?: string ;
41
44
signerMode ?: boolean ;
42
45
signerFileSystemPath ?: string ;
43
46
lightningSignerFileSystemPath ?: string ;
@@ -64,6 +67,8 @@ export const ArgConfig = (args): Partial<Config> => ({
64
67
customBitcoinNetwork : args . custombitcoinnetwork ,
65
68
authVersion : args . authVersion ,
66
69
externalSignerUrl : args . externalSignerUrl ,
70
+ enclavedExpressUrl : args . enclavedExpressUrl ,
71
+ enclavedExpressSSLCert : args . enclavedExpressSSLCert ,
67
72
signerMode : args . signerMode ,
68
73
signerFileSystemPath : args . signerFileSystemPath ,
69
74
lightningSignerFileSystemPath : args . lightningSignerFileSystemPath ,
@@ -90,6 +95,8 @@ export const EnvConfig = (): Partial<Config> => ({
90
95
customBitcoinNetwork : readEnvVar ( 'BITGO_CUSTOM_BITCOIN_NETWORK' ) as V1Network ,
91
96
authVersion : Number ( readEnvVar ( 'BITGO_AUTH_VERSION' ) ) ,
92
97
externalSignerUrl : readEnvVar ( 'BITGO_EXTERNAL_SIGNER_URL' ) ,
98
+ enclavedExpressUrl : readEnvVar ( 'BITGO_ENCLAVED_EXPRESS_URL' ) ,
99
+ enclavedExpressSSLCert : readEnvVar ( 'BITGO_ENCLAVED_EXPRESS_SSL_CERT' ) ,
93
100
signerMode : readEnvVar ( 'BITGO_SIGNER_MODE' ) ? true : undefined ,
94
101
signerFileSystemPath : readEnvVar ( 'BITGO_SIGNER_FILE_SYSTEM_PATH' ) ,
95
102
lightningSignerFileSystemPath : readEnvVar ( 'BITGO_LIGHTNING_SIGNER_FILE_SYSTEM_PATH' ) ,
@@ -110,6 +117,8 @@ export const DefaultConfig: Config = {
110
117
disableEnvCheck : true ,
111
118
timeout : 305 * 1000 ,
112
119
authVersion : 2 ,
120
+ enclavedExpressUrl : undefined ,
121
+ enclavedExpressSSLCert : undefined ,
113
122
} ;
114
123
115
124
/**
@@ -147,6 +156,8 @@ function mergeConfigs(...configs: Partial<Config>[]): Config {
147
156
const disableSSL = get ( 'disableSSL' ) || false ;
148
157
let customRootUri = get ( 'customRootUri' ) ;
149
158
let externalSignerUrl = get ( 'externalSignerUrl' ) ;
159
+ let enclavedExpressUrl = get ( 'enclavedExpressUrl' ) ;
160
+ let enclavedExpressSSLCert : string | undefined ;
150
161
151
162
if ( disableSSL !== true ) {
152
163
if ( customRootUri ) {
@@ -155,6 +166,24 @@ function mergeConfigs(...configs: Partial<Config>[]): Config {
155
166
if ( externalSignerUrl ) {
156
167
externalSignerUrl = forceSecureUrl ( externalSignerUrl ) ;
157
168
}
169
+ if ( enclavedExpressUrl ) {
170
+ enclavedExpressUrl = forceSecureUrl ( enclavedExpressUrl ) ;
171
+ console . log ( 'Using secure enclaved express URL:' , enclavedExpressUrl ) ;
172
+ }
173
+ const enclavedExpressSSLCertValue = get ( 'enclavedExpressSSLCert' ) ;
174
+ if ( enclavedExpressSSLCertValue ) {
175
+ try {
176
+ // First try to read it as a file path
177
+ enclavedExpressSSLCert = existsSync ( enclavedExpressSSLCertValue )
178
+ ? readFileSync ( enclavedExpressSSLCertValue , { encoding : 'utf8' } )
179
+ : enclavedExpressSSLCertValue ; // If not a file, use the value directly
180
+ if ( existsSync ( enclavedExpressSSLCertValue ) ) {
181
+ console . log ( 'Successfully loaded SSL cert from:' , enclavedExpressSSLCertValue ) ;
182
+ }
183
+ } catch ( e ) {
184
+ console . error ( `Failed to process enclaved express SSL cert: ${ enclavedExpressSSLCertValue } ` , e ) ;
185
+ }
186
+ }
158
187
}
159
188
160
189
return {
@@ -176,6 +205,8 @@ function mergeConfigs(...configs: Partial<Config>[]): Config {
176
205
customBitcoinNetwork : get ( 'customBitcoinNetwork' ) ,
177
206
authVersion : get ( 'authVersion' ) ,
178
207
externalSignerUrl,
208
+ enclavedExpressUrl,
209
+ enclavedExpressSSLCert,
179
210
signerMode : get ( 'signerMode' ) ,
180
211
signerFileSystemPath : get ( 'signerFileSystemPath' ) ,
181
212
lightningSignerFileSystemPath : get ( 'lightningSignerFileSystemPath' ) ,
@@ -184,8 +215,8 @@ function mergeConfigs(...configs: Partial<Config>[]): Config {
184
215
} ;
185
216
}
186
217
187
- export const config = ( ) => {
218
+ export function config ( ) : Config {
188
219
const arg = ArgConfig ( args ( ) ) ;
189
220
const env = EnvConfig ( ) ;
190
221
return mergeConfigs ( env , arg ) ;
191
- } ;
222
+ }
0 commit comments