@@ -478,19 +478,20 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
478478 }
479479 }
480480
481- public async inputFactorKey ( factorKey : BN ) : Promise < void > {
481+ public async inputFactorKey ( factorKey : BNString ) : Promise < void > {
482+ const factorKeyBN = new BN ( factorKey , "hex" ) ;
482483 this . checkReady ( ) ;
483484 try {
484485 // input tkey device share when required share > 0 ( or not reconstructed )
485486 // assumption tkey shares will not changed
486487 if ( ! this . tKey . secp256k1Key ) {
487- const factorKeyMetadata = await this . getFactorKeyMetadata ( factorKey ) ;
488+ const factorKeyMetadata = await this . getFactorKeyMetadata ( factorKeyBN ) ;
488489 await this . tKey . inputShareStoreSafe ( factorKeyMetadata , true ) ;
489490 }
490491
491492 // Finalize initialization.
492493 await this . tKey . reconstructKey ( ) ;
493- await this . finalizeTkey ( factorKey ) ;
494+ await this . finalizeTkey ( factorKeyBN ) ;
494495 } catch ( err : unknown ) {
495496 log . error ( "login error" , err ) ;
496497 if ( err instanceof CoreError ) {
@@ -595,6 +596,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
595596 const { shareType } = createFactorParams ;
596597
597598 let { factorKey, shareDescription, additionalMetadata } = createFactorParams ;
599+ factorKey = factorKey ? new BN ( factorKey , "hex" ) : undefined ;
598600
599601 if ( ! VALID_SHARE_INDICES . includes ( shareType ) ) {
600602 throw CoreKitError . newShareIndexInvalid ( `Invalid share type provided (${ shareType } ). Valid share types are ${ VALID_SHARE_INDICES } .` ) ;
@@ -1129,7 +1131,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
11291131 this . checkReady ( ) ;
11301132
11311133 const factorKey = new BN ( result . factorKey , "hex" ) ;
1132- if ( ! factorKey ) {
1134+ if ( ! factorKey && ! result . remoteClientState ?. remoteClientToken ) {
11331135 throw CoreKitError . providedFactorKeyInvalid ( ) ;
11341136 }
11351137 const postBoxKey = result . postBoxKey || result . oAuthKey ;
@@ -1139,18 +1141,23 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
11391141 this . torusSp . postboxKey = new BN ( postBoxKey , "hex" ) ;
11401142 this . torusSp . verifierName = result . userInfo . aggregateVerifier || result . userInfo . verifier ;
11411143 this . torusSp . verifierId = result . userInfo . verifierId ;
1142- const factorKeyMetadata = await this . getFactorKeyMetadata ( factorKey ) ;
1144+
1145+ const metadataShareStore = result . remoteClientState ?. metadataShare
1146+ ? ShareStore . fromJSON ( JSON . parse ( result . remoteClientState ?. metadataShare ) )
1147+ : await this . getFactorKeyMetadata ( factorKey ) ;
1148+
11431149 await this . tKey . initialize ( { neverInitializeNewKey : true } ) ;
1144- await this . tKey . inputShareStoreSafe ( factorKeyMetadata , true ) ;
1150+ await this . tKey . inputShareStoreSafe ( metadataShareStore , true ) ;
11451151 await this . tKey . reconstructKey ( ) ;
11461152
11471153 this . updateState ( {
1148- factorKey : new BN ( result . factorKey , "hex" ) ,
1154+ factorKey : factorKey ? new BN ( result . factorKey , "hex" ) : undefined ,
11491155 postBoxKey,
11501156 tssShareIndex : result . tssShareIndex ,
11511157 tssPubKey : this . tkey . getTSSPub ( ) . toSEC1 ( this . tKey . tssCurve , false ) ,
11521158 signatures : result . signatures ,
11531159 userInfo : result . userInfo ,
1160+ remoteClient : result . remoteClientState ,
11541161 } ) ;
11551162 } catch ( err ) {
11561163 log . error ( "error trying to authorize session" , err ) ;
0 commit comments