@@ -25,6 +25,9 @@ import {
2525 KeyShareType ,
2626 MpcFinalizeResponseType ,
2727 MpcInitializeResponseType ,
28+ MpcV2FinalizeResponseType ,
29+ MpcV2InitializeResponseType ,
30+ MpcV2RoundResponseType ,
2831} from '../../../enclavedBitgoExpress/routers/enclavedApiSpec' ;
2932import { FormattedOfflineVaultTxInfo } from '@bitgo/abstract-utxo' ;
3033
@@ -456,6 +459,105 @@ export class EnclavedExpressClient {
456459 throw err ;
457460 }
458461 }
462+
463+ /**
464+ * Initialize MPCv2 key generation
465+ */
466+ async initMpcV2 ( params : { source : 'user' | 'backup' } ) : Promise < MpcV2InitializeResponseType > {
467+ if ( ! this . coin ) {
468+ throw new Error ( 'Coin must be specified to initialize MPCv2 key generation' ) ;
469+ }
470+
471+ try {
472+ debugLogger ( 'Initializing MPCv2 key generation for coin: %s' , this . coin ) ;
473+ let request = this . apiClient [ 'v1.mpcv2.initialize' ] . post ( {
474+ coin : this . coin ,
475+ source : params . source ,
476+ } ) ;
477+
478+ if ( this . tlsMode === TlsMode . MTLS ) {
479+ request = request . agent ( this . createHttpsAgent ( ) ) ;
480+ }
481+
482+ const response = await request . decodeExpecting ( 200 ) ;
483+ return response . body ;
484+ } catch ( error ) {
485+ const err = error as Error ;
486+ debugLogger ( 'Failed to initialize MPCv2 key generation: %s' , err . message ) ;
487+ throw err ;
488+ }
489+ }
490+
491+ /**
492+ * Execute a round in the MPCv2 protocol
493+ */
494+ async mpcV2Round ( params : {
495+ source : 'user' | 'backup' ;
496+ encryptedData : string ;
497+ encryptedDataKey : string ;
498+ round : number ;
499+ bitgoGpgPub ?: string ;
500+ counterPartyGpgPub ?: string ;
501+ broadcastMessages ?: { bitgo : any ; counterParty : any } ;
502+ p2pMessages ?: { bitgo : any ; counterParty : any } ;
503+ } ) : Promise < MpcV2RoundResponseType > {
504+ if ( ! this . coin ) {
505+ throw new Error ( 'Coin must be specified for MPCv2 round' ) ;
506+ }
507+
508+ try {
509+ debugLogger ( 'Executing MPCv2 round %d for coin: %s' , params . round , this . coin ) ;
510+ let request = this . apiClient [ 'v1.mpcv2.round' ] . post ( {
511+ coin : this . coin ,
512+ ...params ,
513+ } ) ;
514+
515+ if ( this . tlsMode === TlsMode . MTLS ) {
516+ request = request . agent ( this . createHttpsAgent ( ) ) ;
517+ }
518+
519+ const response = await request . decodeExpecting ( 200 ) ;
520+ return response . body ;
521+ } catch ( error ) {
522+ const err = error as Error ;
523+ debugLogger ( 'Failed to execute MPCv2 round: %s' , err . message ) ;
524+ throw err ;
525+ }
526+ }
527+
528+ /**
529+ * Finalize MPCv2 key generation
530+ */
531+ async mpcV2Finalize ( params : {
532+ source : 'user' | 'backup' ;
533+ encryptedData : string ;
534+ encryptedDataKey : string ;
535+ broadcastMessages : { bitgo : any ; counterParty : any } ;
536+ bitgoCommonKeychain : string ;
537+ } ) : Promise < MpcV2FinalizeResponseType > {
538+ if ( ! this . coin ) {
539+ throw new Error ( 'Coin must be specified to finalize MPCv2 key generation' ) ;
540+ }
541+
542+ try {
543+ debugLogger ( 'Finalizing MPCv2 key generation for coin: %s' , this . coin ) ;
544+ let request = this . apiClient [ 'v1.mpcv2.finalize' ] . post ( {
545+ coin : this . coin ,
546+ ...params ,
547+ } ) ;
548+
549+ if ( this . tlsMode === TlsMode . MTLS ) {
550+ request = request . agent ( this . createHttpsAgent ( ) ) ;
551+ }
552+
553+ const response = await request . decodeExpecting ( 200 ) ;
554+ return response . body ;
555+ } catch ( error ) {
556+ const err = error as Error ;
557+ debugLogger ( 'Failed to finalize MPCv2 key generation: %s' , err . message ) ;
558+ throw err ;
559+ }
560+ }
459561}
460562
461563/**
0 commit comments