@@ -523,15 +523,17 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
523523 public async inputFactorKey ( factorKey : BN ) : Promise < void > {
524524 this . checkReady ( ) ;
525525 try {
526- // input tkey device share when required share > 0 ( or not reconstructed )
527- // assumption tkey shares will not changed
526+ // always check for valid factor key
527+ const factorKeyPrivate = factorKeyCurve . keyFromPrivate ( factorKey . toBuffer ( ) ) ;
528+ const factorPubX = factorKeyPrivate . getPublic ( ) . getX ( ) . toString ( "hex" ) . padStart ( 64 , "0" ) ;
529+ const factorEncExist = this . tkey . metadata . factorEncs ?. [ this . tkey . tssTag ] ?. [ factorPubX ] ;
530+ if ( ! factorEncExist ) {
531+ throw CoreKitError . providedFactorKeyInvalid ( "Invalid FactorKey provided. Failed to input factor key." ) ;
532+ }
533+
534+ // input tkey device share when required share > 0 ( or tkey is not yet reconstructed )
535+ // assumption tkey shares will never changed
528536 if ( ! this . tKey . secp256k1Key ) {
529- const factorKeyPrivate = factorKeyCurve . keyFromPrivate ( factorKey . toBuffer ( ) ) ;
530- const factorPubX = factorKeyPrivate . getPublic ( ) . getX ( ) . toString ( "hex" ) . padStart ( 64 , "0" ) ;
531- const factorEncExist = this . tkey . metadata . factorEncs ?. [ this . tkey . tssTag ] ?. [ factorPubX ] ;
532- if ( ! factorEncExist ) {
533- throw CoreKitError . providedFactorKeyInvalid ( "Invalid FactorKey provided. Failed to input factor key." ) ;
534- }
535537 const factorKeyMetadata = await this . getFactorKeyMetadata ( factorKey ) ;
536538 await this . tKey . inputShareStoreSafe ( factorKeyMetadata , true ) ;
537539 }
@@ -897,19 +899,6 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
897899 // manual call syncLocalMetadataTransitions() required to sync local transitions to storage
898900 await this . tKey . _syncShareMetadata ( ) ;
899901 await this . tKey . syncLocalMetadataTransitions ( ) ;
900-
901- if ( this . sessionManager && this . sessionId ) {
902- const payload : SessionData = {
903- postBoxKey : this . state . postBoxKey ,
904- postboxKeyNodeIndexes : this . state . postboxKeyNodeIndexes || [ ] ,
905- factorKey : this . state . factorKey ?. toString ( "hex" ) ,
906- tssShareIndex : this . state . tssShareIndex as number ,
907- tssPubKey : this . state . tssPubKey ?. toString ( "hex" ) ,
908- signatures : this . signatures ,
909- userInfo : this . state . userInfo ,
910- } ;
911- this . sessionManager . updateSession ( payload ) ;
912- }
913902 } catch ( error : unknown ) {
914903 log . error ( "sync metadata error" , error ) ;
915904 throw error ;
@@ -1180,7 +1169,22 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
11801169
11811170 this . updateState ( { tssShareIndex, tssPubKey, factorKey } ) ;
11821171
1183- await this . createSession ( ) ;
1172+
1173+ if ( this . sessionManager && this . sessionId ) {
1174+ const payload : SessionData = {
1175+ postBoxKey : this . state . postBoxKey ,
1176+ postboxKeyNodeIndexes : this . state . postboxKeyNodeIndexes || [ ] ,
1177+ factorKey : this . state . factorKey ?. toString ( "hex" ) ,
1178+ tssShareIndex : this . state . tssShareIndex as number ,
1179+ tssPubKey : this . state . tssPubKey ?. toString ( "hex" ) ,
1180+ signatures : this . signatures ,
1181+ userInfo : this . state . userInfo ,
1182+ } ;
1183+ this . sessionManager . updateSession ( payload ) ;
1184+ } else {
1185+ await this . createSession ( ) ;
1186+ }
1187+
11841188 }
11851189
11861190 private checkReady ( ) {
0 commit comments