@@ -20,7 +20,7 @@ import {
2020} from '@bitgo/public-types' ;
2121
2222import { Ecdsa } from '../../../../account-lib' ;
23- import { AddKeychainOptions , Keychain , KeyType } from '../../../keychain' ;
23+ import { AddKeychainOptions , Keychain , KeyType , MpcWebauthnInfo } from '../../../keychain' ;
2424import { DecryptedRetrofitPayload } from '../../../keychain/iKeychains' ;
2525import { ECDSAMethodTypes , getTxRequest } from '../../../tss' ;
2626import { sendSignatureShareV2 , sendTxRequest } from '../../../tss/common' ;
@@ -57,6 +57,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
5757 enterprise : string ;
5858 originalPasscodeEncryptionCode ?: string ;
5959 retrofit ?: DecryptedRetrofitPayload ;
60+ webauthnInfo ?: MpcWebauthnInfo ;
6061 } ) : Promise < KeychainsTriplet > {
6162 const { userSession, backupSession } = this . getUserAndBackupSession ( 2 , 3 , params . retrofit ) ;
6263 const userGpgKey = await generateGPGKeyPair ( 'secp256k1' ) ;
@@ -318,7 +319,8 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
318319 userPrivateMaterial ,
319320 userReducedPrivateMaterial ,
320321 params . passphrase ,
321- params . originalPasscodeEncryptionCode
322+ params . originalPasscodeEncryptionCode ,
323+ params . webauthnInfo
322324 ) ;
323325 const backupKeychainPromise = this . addBackupKeychain (
324326 bitgoCommonKeychain ,
@@ -350,20 +352,23 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
350352 privateMaterial ?: Buffer ,
351353 reducedPrivateMaterial ?: Buffer ,
352354 passphrase ?: string ,
353- originalPasscodeEncryptionCode ?: string
355+ originalPasscodeEncryptionCode ?: string ,
356+ webauthnInfo ?: MpcWebauthnInfo
354357 ) : Promise < Keychain > {
355358 let source : string ;
356359 let encryptedPrv : string | undefined = undefined ;
357360 let reducedEncryptedPrv : string | undefined = undefined ;
361+ let privateMaterialBase64 : string | undefined = undefined ;
358362 switch ( participantIndex ) {
359363 case MPCv2PartiesEnum . USER :
360364 case MPCv2PartiesEnum . BACKUP :
361365 source = participantIndex === MPCv2PartiesEnum . USER ? 'user' : 'backup' ;
362366 assert ( privateMaterial , `Private material is required for ${ source } keychain` ) ;
363367 assert ( reducedPrivateMaterial , `Reduced private material is required for ${ source } keychain` ) ;
364368 assert ( passphrase , `Passphrase is required for ${ source } keychain` ) ;
369+ privateMaterialBase64 = privateMaterial . toString ( 'base64' ) ;
365370 encryptedPrv = this . bitgo . encrypt ( {
366- input : privateMaterial . toString ( 'base64' ) ,
371+ input : privateMaterialBase64 ,
367372 password : passphrase ,
368373 } ) ;
369374 // Encrypts the CBOR-encoded ReducedKeyShare (which contains the party's private
@@ -393,6 +398,19 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
393398 isMPCv2 : true ,
394399 } ;
395400
401+ if ( webauthnInfo && participantIndex === MPCv2PartiesEnum . USER && privateMaterialBase64 ) {
402+ recipientKeychainParams . webauthnDevices = [
403+ {
404+ otpDeviceId : webauthnInfo . otpDeviceId ,
405+ prfSalt : webauthnInfo . prfSalt ,
406+ encryptedPrv : this . bitgo . encrypt ( {
407+ input : privateMaterialBase64 ,
408+ password : webauthnInfo . passphrase ,
409+ } ) ,
410+ } ,
411+ ] ;
412+ }
413+
396414 const keychains = this . baseCoin . keychains ( ) ;
397415 return { ...( await keychains . add ( recipientKeychainParams ) ) , reducedEncryptedPrv : reducedEncryptedPrv } ;
398416 }
@@ -512,15 +530,17 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
512530 privateMaterial : Buffer ,
513531 reducedPrivateMaterial : Buffer ,
514532 passphrase : string ,
515- originalPasscodeEncryptionCode ?: string
533+ originalPasscodeEncryptionCode ?: string ,
534+ webauthnInfo ?: MpcWebauthnInfo
516535 ) : Promise < Keychain > {
517536 return this . createParticipantKeychain (
518537 MPCv2PartiesEnum . USER ,
519538 commonKeychain ,
520539 privateMaterial ,
521540 reducedPrivateMaterial ,
522541 passphrase ,
523- originalPasscodeEncryptionCode
542+ originalPasscodeEncryptionCode ,
543+ webauthnInfo
524544 ) ;
525545 }
526546
0 commit comments