@@ -967,7 +967,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
967967
968968 public async commitChanges ( ) : Promise < void > {
969969 this . checkReady ( ) ;
970- if ( ! this . state . factorKey && ! this . state . remoteClient . remoteClientToken ) {
970+ if ( ! this . state . factorKey && ! this . state . remoteClient . metadataShare ) {
971971 throw CoreKitError . factorKeyNotPresent ( "factorKey not present in state when committing changes." ) ;
972972 }
973973
@@ -1070,8 +1070,8 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
10701070 }
10711071 }
10721072
1073- async setupRemoteSigning ( params : Omit < IRemoteClientState , "tssShareIndex" | "signatures" > ) : Promise < void > {
1074- const { remoteClientUrl , remoteFactorPub, metadataShare, remoteClientToken } = params ;
1073+ async setupRemoteSigning ( params : IRemoteClientState , rehydrate : boolean = false ) : Promise < void > {
1074+ const { remoteFactorPub, metadataShare } = params ;
10751075 const details = this . getKeyDetails ( ) . shareDescriptions [ remoteFactorPub ] ;
10761076 if ( ! details ) throw CoreKitError . default ( "factor description not found" ) ;
10771077
@@ -1081,12 +1081,9 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
10811081 if ( ! tssShareIndex ) throw CoreKitError . default ( "tss share index not found" ) ;
10821082
10831083 const remoteClient : IRemoteClientState = {
1084- remoteClientUrl : remoteClientUrl . at ( - 1 ) === "/" ? remoteClientUrl . slice ( 0 , - 1 ) : remoteClientUrl ,
10851084 remoteFactorPub,
10861085 metadataShare,
1087- remoteClientToken,
10881086 tssShareIndex,
1089- signatures : this . state . signatures ,
10901087 } ;
10911088
10921089 const sharestore = ShareStore . fromJSON ( JSON . parse ( metadataShare ) ) ;
@@ -1097,8 +1094,10 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
10971094 // const tssPubKey = Point.fromTkeyPoint(this.tKey.getTSSPub()).toBufferSEC1(false);
10981095 this . updateState ( { tssShareIndex, tssPubKey, remoteClient } ) ;
10991096 // // Finalize setup.
1100- // setup provider
1101- await this . createSessionRemoteClient ( ) ;
1097+ // skip setup provider if rehydrate is true
1098+ if ( ! rehydrate ) {
1099+ await this . createSessionRemoteClient ( ) ;
1100+ }
11021101 }
11031102
11041103 public updateState ( newState : Partial < Web3AuthState > ) : void {
@@ -1343,23 +1342,29 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
13431342 try {
13441343 this . checkReady ( ) ;
13451344
1346- const factorKey = new BN ( result . factorKey , "hex" ) ;
1347- if ( ! factorKey && ! result . remoteClientState ?. remoteClientToken ) {
1348- throw CoreKitError . providedFactorKeyInvalid ( ) ;
1349- }
13501345 const postBoxKey = result . postBoxKey || result . oAuthKey ;
13511346 if ( ! postBoxKey ) {
13521347 throw CoreKitError . default ( "postBoxKey or oAuthKey not present in session data" ) ;
13531348 }
1349+
1350+ const factorKey = new BN ( result . factorKey , "hex" ) ;
1351+ if ( ! factorKey && ! result . remoteClientState ?. metadataShare ) {
1352+ throw CoreKitError . providedFactorKeyInvalid ( ) ;
1353+ }
1354+
13541355 this . torusSp . postboxKey = new BN ( postBoxKey , "hex" ) ;
13551356 this . torusSp . verifierName = result . userInfo . aggregateVerifier || result . userInfo . verifier ;
13561357 this . torusSp . verifierId = result . userInfo . verifierId ;
13571358
1358- const metadataShareStore = result . remoteClientState ?. metadataShare
1359- ? ShareStore . fromJSON ( JSON . parse ( result . remoteClientState ?. metadataShare ) )
1360- : await this . getFactorKeyMetadata ( factorKey ) ;
1361-
13621359 await this . tKey . initialize ( { neverInitializeNewKey : true } ) ;
1360+
1361+ // skip input share store if factor key is not present
1362+ // tkey will be at state initalized
1363+ if ( ! factorKey ) {
1364+ return ;
1365+ }
1366+
1367+ const metadataShareStore = await this . getFactorKeyMetadata ( factorKey ) ;
13631368 await this . tKey . inputShareStoreSafe ( metadataShareStore , true ) ;
13641369 await this . tKey . reconstructKey ( ) ;
13651370
0 commit comments