@@ -69,29 +69,41 @@ export default class BaseTssUtils<KeyShare> extends MpcUtils implements ITssUtil
6969 this . bitgoPublicGpgKey = mpcV1 ;
7070 this . bitgoMPCv2PublicGpgKey = mpcV2 ;
7171 }
72-
73- protected async pickBitgoPubGpgKeyForSigning ( isMpcv2 : boolean , reqId : IRequestTracer , enterpriseId ?: string ) : Promise < openpgp . Key > {
72+
73+ protected async pickBitgoPubGpgKeyForSigning (
74+ isMpcv2 : boolean ,
75+ reqId ?: IRequestTracer ,
76+ enterpriseId ?: string
77+ ) : Promise < openpgp . Key > {
7478 let bitgoGpgPubKey ;
7579 try {
76- const bitgoKeyChain = await this . baseCoin . keychains ( ) . get ( { id : this . wallet . keyIds ( ) [ KeyIndices . BITGO ] , reqId } ) ;
80+ const bitgoKeyChain = await this . baseCoin . keychains ( ) . get ( { id : this . wallet . keyIds ( ) [ KeyIndices . BITGO ] , reqId } ) ;
7781 if ( ! bitgoKeyChain || ! bitgoKeyChain . hsmType ) {
7882 throw new Error ( 'Missing Bitgo GPG Pub Key Type.' ) ;
7983 }
8084 bitgoGpgPubKey = await openpgp . readKey ( {
81- armoredKey : getBitgoMpcGpgPubKey ( this . bitgo . getEnv ( ) , bitgoKeyChain . hsmType === 'nitro' ? 'nitro' : 'onprem' , isMpcv2 ? 'mpcv2' : 'mpcv1' ) ,
85+ armoredKey : getBitgoMpcGpgPubKey (
86+ this . bitgo . getEnv ( ) ,
87+ bitgoKeyChain . hsmType === 'nitro' ? 'nitro' : 'onprem' ,
88+ isMpcv2 ? 'mpcv2' : 'mpcv1'
89+ ) ,
8290 } ) ;
8391 } catch ( e ) {
8492 if ( ! envRequiresBitgoPubGpgKeyConfig ( this . bitgo . getEnv ( ) ) ) {
8593 console . warn (
8694 `Unable to get BitGo GPG key based on key data with error: ${ e } . Fetching BitGo GPG key based on feature flags.`
8795 ) ;
88- bitgoGpgPubKey = await this . getBitgoGpgPubkeyBasedOnFeatureFlags (
89- enterpriseId ,
90- isMpcv2 ,
91- reqId
92- ) . then ( async ( pubKey ) => pubKey ?? ( isMpcv2 ? await this . getBitgoMpcv2PublicGpgKey ( ) : await this . getBitgoPublicGpgKey ( ) ) ) ;
96+ // First try to get the key based on feature flags, if that fails, fallback to the default key from constants api.
97+ bitgoGpgPubKey = await this . getBitgoGpgPubkeyBasedOnFeatureFlags ( enterpriseId , isMpcv2 , reqId )
98+ . then (
99+ async ( pubKey ) =>
100+ pubKey ?? ( isMpcv2 ? await this . getBitgoMpcv2PublicGpgKey ( ) : await this . getBitgoPublicGpgKey ( ) )
101+ )
102+ . catch ( async ( e ) => ( isMpcv2 ? await this . getBitgoMpcv2PublicGpgKey ( ) : await this . getBitgoPublicGpgKey ( ) ) ) ;
93103 } else {
94- throw new Error ( `Environment "${ this . bitgo . getEnv ( ) } " requires a BitGo GPG Pub Key Config in BitGoJS for TSS. Error thrown while getting the key from config: ${ e } ` ) ;
104+ throw new Error (
105+ `Environment "${ this . bitgo . getEnv ( ) } " requires a BitGo GPG Pub Key Config in BitGoJS for TSS. Error thrown while getting the key from config: ${ e } `
106+ ) ;
95107 }
96108 }
97109 return bitgoGpgPubKey ;
@@ -119,7 +131,7 @@ export default class BaseTssUtils<KeyShare> extends MpcUtils implements ITssUtil
119131 }
120132
121133 return this . bitgoMPCv2PublicGpgKey ;
122- }
134+ }
123135
124136 async createBitgoHeldBackupKeyShare (
125137 userGpgKey : SerializedKeyPair < string > ,
@@ -251,7 +263,12 @@ export default class BaseTssUtils<KeyShare> extends MpcUtils implements ITssUtil
251263 *
252264 * @returns {Promise<{ userToBitgoCommitment: CommitmentShareRecor, encryptedSignerShare: EncryptedSignerShareRecord }> } - Commitment Share and the Encrypted Signer Share to BitGo
253265 */
254- createCommitmentShareFromTxRequest ( params : { txRequest : TxRequest ; prv : string ; walletPassphrase : string } ) : Promise < {
266+ createCommitmentShareFromTxRequest ( params : {
267+ txRequest : TxRequest ;
268+ prv : string ;
269+ walletPassphrase : string ;
270+ bitgoGpgPubKey : string ;
271+ } ) : Promise < {
255272 userToBitgoCommitment : CommitmentShareRecord ;
256273 encryptedSignerShare : EncryptedSignerShareRecord ;
257274 encryptedUserToBitgoRShare : EncryptedSignerShareRecord ;
0 commit comments