diff --git a/packages/service-provider-sfa/src/SfaServiceProvider.ts b/packages/service-provider-sfa/src/SfaServiceProvider.ts index 3f438a8f..1ed1e329 100644 --- a/packages/service-provider-sfa/src/SfaServiceProvider.ts +++ b/packages/service-provider-sfa/src/SfaServiceProvider.ts @@ -13,7 +13,7 @@ class SfaServiceProvider extends ServiceProviderBase { public torusKey: TorusKey; - public migratableKey: BN | null = null; + public migratableKey: BN | null = null; // Migration of key from SFA to tKey private nodeDetailManagerInstance: NodeDetailManager; @@ -79,10 +79,10 @@ class SfaServiceProvider extends ServiceProviderBase { const torusKey = await this.authInstance.retrieveShares(torusNodeEndpoints, torusIndexes, verifier, finalVerifierParams, finalIdToken); this.torusKey = torusKey; - const { finalKeyData, oAuthKeyData } = torusKey; - const privKey = finalKeyData.privKey || oAuthKeyData.privKey; if (!torusKey.metadata.upgraded) { + const { finalKeyData, oAuthKeyData } = torusKey; + const privKey = finalKeyData.privKey || oAuthKeyData.privKey; this.migratableKey = new BN(privKey, "hex"); } const postboxKey = Torus.getPostboxKey(torusKey); diff --git a/packages/service-provider-torus/src/TorusServiceProvider.ts b/packages/service-provider-torus/src/TorusServiceProvider.ts index 44a57b56..22ef68cb 100644 --- a/packages/service-provider-torus/src/TorusServiceProvider.ts +++ b/packages/service-provider-torus/src/TorusServiceProvider.ts @@ -56,10 +56,10 @@ class TorusServiceProvider extends ServiceProviderBase { if (obj) { const localPrivKey = Torus.getPostboxKey(obj); this.torusKey = obj; - const { finalKeyData, oAuthKeyData } = obj; - const privKey = finalKeyData.privKey || oAuthKeyData.privKey; if (!obj.metadata.upgraded) { + const { finalKeyData, oAuthKeyData } = obj; + const privKey = finalKeyData.privKey || oAuthKeyData.privKey; this.migratableKey = new BN(privKey, "hex"); } @@ -78,10 +78,10 @@ class TorusServiceProvider extends ServiceProviderBase { if (obj) { const localPrivKey = Torus.getPostboxKey(obj); this.torusKey = obj; - const { finalKeyData, oAuthKeyData } = obj; - const privKey = finalKeyData.privKey || oAuthKeyData.privKey; if (!obj.metadata.upgraded) { + const { finalKeyData, oAuthKeyData } = obj; + const privKey = finalKeyData.privKey || oAuthKeyData.privKey; this.migratableKey = new BN(privKey, "hex"); } @@ -95,12 +95,12 @@ class TorusServiceProvider extends ServiceProviderBase { */ async triggerHybridAggregateLogin(params: HybridAggregateLoginParams): Promise { const obj = await this.customAuthInstance.triggerHybridAggregateLogin(params); + this.torusKey = null; // Since there are multiple keys, we don't set the torusKey here. // `obj` maybe `null` in redirect mode. if (obj) { const aggregateLoginKey = Torus.getPostboxKey(obj.aggregateLogins[0]); const singleLoginKey = Torus.getPostboxKey(obj.singleLogin); - this.torusKey = null; this.postboxKey = new BN(aggregateLoginKey, "hex"); this.singleLoginKey = new BN(singleLoginKey, "hex"); }