@@ -473,19 +473,20 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
473473 }
474474 }
475475
476- public async inputFactorKey ( factorKey : BN ) : Promise < void > {
476+ public async inputFactorKey ( factorKey : BNString ) : Promise < void > {
477+ const factorKeyBN = new BN ( factorKey , "hex" ) ;
477478 this . checkReady ( ) ;
478479 try {
479480 // input tkey device share when required share > 0 ( or not reconstructed )
480481 // assumption tkey shares will not changed
481482 if ( ! this . tKey . secp256k1Key ) {
482- const factorKeyMetadata = await this . getFactorKeyMetadata ( factorKey ) ;
483+ const factorKeyMetadata = await this . getFactorKeyMetadata ( factorKeyBN ) ;
483484 await this . tKey . inputShareStoreSafe ( factorKeyMetadata , true ) ;
484485 }
485486
486487 // Finalize initialization.
487488 await this . tKey . reconstructKey ( ) ;
488- await this . finalizeTkey ( factorKey ) ;
489+ await this . finalizeTkey ( factorKeyBN ) ;
489490 } catch ( err : unknown ) {
490491 log . error ( "login error" , err ) ;
491492 if ( err instanceof CoreError ) {
@@ -590,6 +591,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
590591 const { shareType } = createFactorParams ;
591592
592593 let { factorKey, shareDescription, additionalMetadata } = createFactorParams ;
594+ factorKey = factorKey ? new BN ( factorKey , "hex" ) : undefined ;
593595
594596 if ( ! VALID_SHARE_INDICES . includes ( shareType ) ) {
595597 throw CoreKitError . newShareIndexInvalid ( `Invalid share type provided (${ shareType } ). Valid share types are ${ VALID_SHARE_INDICES } .` ) ;
@@ -1142,7 +1144,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
11421144 this . checkReady ( ) ;
11431145
11441146 const factorKey = new BN ( result . factorKey , "hex" ) ;
1145- if ( ! factorKey ) {
1147+ if ( ! factorKey && ! result . remoteClientState ?. remoteClientToken ) {
11461148 throw CoreKitError . providedFactorKeyInvalid ( ) ;
11471149 }
11481150 const postBoxKey = result . postBoxKey || result . oAuthKey ;
@@ -1152,18 +1154,23 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
11521154 this . torusSp . postboxKey = new BN ( postBoxKey , "hex" ) ;
11531155 this . torusSp . verifierName = result . userInfo . aggregateVerifier || result . userInfo . verifier ;
11541156 this . torusSp . verifierId = result . userInfo . verifierId ;
1155- const factorKeyMetadata = await this . getFactorKeyMetadata ( factorKey ) ;
1157+
1158+ const metadataShareStore = result . remoteClientState ?. metadataShare
1159+ ? ShareStore . fromJSON ( JSON . parse ( result . remoteClientState ?. metadataShare ) )
1160+ : await this . getFactorKeyMetadata ( factorKey ) ;
1161+
11561162 await this . tKey . initialize ( { neverInitializeNewKey : true } ) ;
1157- await this . tKey . inputShareStoreSafe ( factorKeyMetadata , true ) ;
1163+ await this . tKey . inputShareStoreSafe ( metadataShareStore , true ) ;
11581164 await this . tKey . reconstructKey ( ) ;
11591165
11601166 this . updateState ( {
1161- factorKey : new BN ( result . factorKey , "hex" ) ,
1167+ factorKey : factorKey ? new BN ( result . factorKey , "hex" ) : undefined ,
11621168 postBoxKey,
11631169 tssShareIndex : result . tssShareIndex ,
11641170 tssPubKey : this . tkey . getTSSPub ( ) . toSEC1 ( this . tKey . tssCurve , false ) ,
11651171 signatures : result . signatures ,
11661172 userInfo : result . userInfo ,
1173+ remoteClient : result . remoteClientState ,
11671174 } ) ;
11681175 } catch ( err ) {
11691176 log . warn ( "failed to authorize session" , err ) ;
0 commit comments