@@ -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' ;
@@ -66,6 +66,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
6666 enterprise : string ;
6767 originalPasscodeEncryptionCode ?: string ;
6868 retrofit ?: DecryptedRetrofitPayload ;
69+ webauthnInfo ?: WebauthnKeyEncryptionInfo ;
6970 encryptionVersion ?: EncryptionVersion ;
7071 } ) : Promise < KeychainsTriplet > {
7172 const { userSession, backupSession } = this . getUserAndBackupSession ( 2 , 3 , params . retrofit ) ;
@@ -332,6 +333,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
332333 userReducedPrivateMaterial ,
333334 params . passphrase ,
334335 params . originalPasscodeEncryptionCode ,
336+ params . webauthnInfo ,
335337 encryptionSession
336338 ) ;
337339 const backupKeychainPromise = this . addBackupKeychain (
@@ -369,6 +371,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
369371 reducedPrivateMaterial ?: Buffer ,
370372 passphrase ?: string ,
371373 originalPasscodeEncryptionCode ?: string ,
374+ webauthnInfo ?: WebauthnKeyEncryptionInfo ,
372375 encryptionSession ?: {
373376 encrypt ( plaintext : string ) : Promise < string > ;
374377 decrypt ( ciphertext : string ) : Promise < string > ;
@@ -378,21 +381,23 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
378381 let source : string ;
379382 let encryptedPrv : string | undefined = undefined ;
380383 let reducedEncryptedPrv : string | undefined = undefined ;
384+ let privateMaterialBase64 : string | undefined = undefined ;
381385 switch ( participantIndex ) {
382386 case MPCv2PartiesEnum . USER :
383387 case MPCv2PartiesEnum . BACKUP :
384388 source = participantIndex === MPCv2PartiesEnum . USER ? 'user' : 'backup' ;
385389 assert ( privateMaterial , `Private material is required for ${ source } keychain` ) ;
386390 assert ( reducedPrivateMaterial , `Reduced private material is required for ${ source } keychain` ) ;
387391 assert ( passphrase , `Passphrase is required for ${ source } keychain` ) ;
392+ privateMaterialBase64 = privateMaterial . toString ( 'base64' ) ;
388393 if ( encryptionSession ) {
389- encryptedPrv = await encryptionSession . encrypt ( privateMaterial . toString ( 'base64' ) ) ;
394+ encryptedPrv = await encryptionSession . encrypt ( privateMaterialBase64 ) ;
390395 reducedEncryptedPrv = await encryptionSession . encrypt (
391396 btoa ( String . fromCharCode . apply ( null , Array . from ( new Uint8Array ( reducedPrivateMaterial ) ) ) )
392397 ) ;
393398 } else {
394399 encryptedPrv = this . bitgo . encrypt ( {
395- input : privateMaterial . toString ( 'base64' ) ,
400+ input : privateMaterialBase64 ,
396401 password : passphrase ,
397402 } ) ;
398403 // Encrypts the CBOR-encoded ReducedKeyShare (which contains the party's private
@@ -423,6 +428,19 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
423428 isMPCv2 : true ,
424429 } ;
425430
431+ if ( webauthnInfo && participantIndex === MPCv2PartiesEnum . USER && privateMaterialBase64 ) {
432+ recipientKeychainParams . webauthnDevices = [
433+ {
434+ otpDeviceId : webauthnInfo . otpDeviceId ,
435+ prfSalt : webauthnInfo . prfSalt ,
436+ encryptedPrv : await this . bitgo . encryptAsync ( {
437+ input : privateMaterialBase64 ,
438+ password : webauthnInfo . passphrase ,
439+ } ) ,
440+ } ,
441+ ] ;
442+ }
443+
426444 const keychains = this . baseCoin . keychains ( ) ;
427445 return { ...( await keychains . add ( recipientKeychainParams ) ) , reducedEncryptedPrv : reducedEncryptedPrv } ;
428446 }
@@ -543,6 +561,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
543561 reducedPrivateMaterial : Buffer ,
544562 passphrase : string ,
545563 originalPasscodeEncryptionCode ?: string ,
564+ webauthnInfo ?: WebauthnKeyEncryptionInfo ,
546565 encryptionSession ?: {
547566 encrypt ( plaintext : string ) : Promise < string > ;
548567 decrypt ( ciphertext : string ) : Promise < string > ;
@@ -556,6 +575,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
556575 reducedPrivateMaterial ,
557576 passphrase ,
558577 originalPasscodeEncryptionCode ,
578+ webauthnInfo ,
559579 encryptionSession
560580 ) ;
561581 }
@@ -579,6 +599,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
579599 reducedPrivateMaterial ,
580600 passphrase ,
581601 originalPasscodeEncryptionCode ,
602+ undefined ,
582603 encryptionSession
583604 ) ;
584605 }
0 commit comments