@@ -21,7 +21,7 @@ import {
2121} from '@bitgo/public-types' ;
2222
2323import { Ecdsa } from '../../../../account-lib' ;
24- import { AddKeychainOptions , Keychain , KeyType } from '../../../keychain' ;
24+ import { AddKeychainOptions , Keychain , KeyType , WebauthnKeyEncryptionInfo } from '../../../keychain' ;
2525import { DecryptedRetrofitPayload } from '../../../keychain/iKeychains' ;
2626import { ECDSAMethodTypes , getTxRequest } from '../../../tss' ;
2727import { sendSignatureShareV2 , sendTxRequest } from '../../../tss/common' ;
@@ -63,6 +63,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
6363 enterprise : string ;
6464 originalPasscodeEncryptionCode ?: string ;
6565 retrofit ?: DecryptedRetrofitPayload ;
66+ webauthnInfo ?: WebauthnKeyEncryptionInfo ;
6667 encryptionVersion ?: EncryptionVersion ;
6768 } ) : Promise < KeychainsTriplet > {
6869 const { userSession, backupSession } = this . getUserAndBackupSession ( 2 , 3 , params . retrofit ) ;
@@ -329,6 +330,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
329330 userReducedPrivateMaterial ,
330331 params . passphrase ,
331332 params . originalPasscodeEncryptionCode ,
333+ params . webauthnInfo ,
332334 encryptionSession
333335 ) ;
334336 const backupKeychainPromise = this . addBackupKeychain (
@@ -366,6 +368,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
366368 reducedPrivateMaterial ?: Buffer ,
367369 passphrase ?: string ,
368370 originalPasscodeEncryptionCode ?: string ,
371+ webauthnInfo ?: WebauthnKeyEncryptionInfo ,
369372 encryptionSession ?: {
370373 encrypt ( plaintext : string ) : Promise < string > ;
371374 decrypt ( ciphertext : string ) : Promise < string > ;
@@ -375,21 +378,23 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
375378 let source : string ;
376379 let encryptedPrv : string | undefined = undefined ;
377380 let reducedEncryptedPrv : string | undefined = undefined ;
381+ let privateMaterialBase64 : string | undefined = undefined ;
378382 switch ( participantIndex ) {
379383 case MPCv2PartiesEnum . USER :
380384 case MPCv2PartiesEnum . BACKUP :
381385 source = participantIndex === MPCv2PartiesEnum . USER ? 'user' : 'backup' ;
382386 assert ( privateMaterial , `Private material is required for ${ source } keychain` ) ;
383387 assert ( reducedPrivateMaterial , `Reduced private material is required for ${ source } keychain` ) ;
384388 assert ( passphrase , `Passphrase is required for ${ source } keychain` ) ;
389+ privateMaterialBase64 = privateMaterial . toString ( 'base64' ) ;
385390 if ( encryptionSession ) {
386- encryptedPrv = await encryptionSession . encrypt ( privateMaterial . toString ( 'base64' ) ) ;
391+ encryptedPrv = await encryptionSession . encrypt ( privateMaterialBase64 ) ;
387392 reducedEncryptedPrv = await encryptionSession . encrypt (
388393 btoa ( String . fromCharCode . apply ( null , Array . from ( new Uint8Array ( reducedPrivateMaterial ) ) ) )
389394 ) ;
390395 } else {
391396 encryptedPrv = this . bitgo . encrypt ( {
392- input : privateMaterial . toString ( 'base64' ) ,
397+ input : privateMaterialBase64 ,
393398 password : passphrase ,
394399 } ) ;
395400 // Encrypts the CBOR-encoded ReducedKeyShare (which contains the party's private
@@ -420,6 +425,19 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
420425 isMPCv2 : true ,
421426 } ;
422427
428+ if ( webauthnInfo && participantIndex === MPCv2PartiesEnum . USER && privateMaterialBase64 ) {
429+ recipientKeychainParams . webauthnDevices = [
430+ {
431+ otpDeviceId : webauthnInfo . otpDeviceId ,
432+ prfSalt : webauthnInfo . prfSalt ,
433+ encryptedPrv : await this . bitgo . encryptAsync ( {
434+ input : privateMaterialBase64 ,
435+ password : webauthnInfo . passphrase ,
436+ } ) ,
437+ } ,
438+ ] ;
439+ }
440+
423441 const keychains = this . baseCoin . keychains ( ) ;
424442 return { ...( await keychains . add ( recipientKeychainParams ) ) , reducedEncryptedPrv : reducedEncryptedPrv } ;
425443 }
@@ -540,6 +558,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
540558 reducedPrivateMaterial : Buffer ,
541559 passphrase : string ,
542560 originalPasscodeEncryptionCode ?: string ,
561+ webauthnInfo ?: WebauthnKeyEncryptionInfo ,
543562 encryptionSession ?: {
544563 encrypt ( plaintext : string ) : Promise < string > ;
545564 decrypt ( ciphertext : string ) : Promise < string > ;
@@ -553,6 +572,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
553572 reducedPrivateMaterial ,
554573 passphrase ,
555574 originalPasscodeEncryptionCode ,
575+ webauthnInfo ,
556576 encryptionSession
557577 ) ;
558578 }
@@ -576,6 +596,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
576596 reducedPrivateMaterial ,
577597 passphrase ,
578598 originalPasscodeEncryptionCode ,
599+ undefined ,
579600 encryptionSession
580601 ) ;
581602 }
0 commit comments