From 7f4f5e8d69c94cf07a4c45c200f1cc7e7e1579ee Mon Sep 17 00:00:00 2001 From: ieow Date: Fri, 5 May 2023 15:30:44 +0800 Subject: [PATCH 1/2] feat: return device share; split function --- .../src/baseTypes/aggregateTypes.ts | 2 ++ packages/core/src/core.ts | 26 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/common-types/src/baseTypes/aggregateTypes.ts b/packages/common-types/src/baseTypes/aggregateTypes.ts index 84fb20ac..79c398c6 100644 --- a/packages/common-types/src/baseTypes/aggregateTypes.ts +++ b/packages/common-types/src/baseTypes/aggregateTypes.ts @@ -131,6 +131,8 @@ export type KeyDetails = { threshold: number; totalShares: number; shareDescriptions: ShareDescriptionMap; + deviceShare?: ShareStore; + userShare?: ShareStore; }; export type TKeyArgs = { diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index dec3aa07..0c5dd78b 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -252,9 +252,14 @@ class ThresholdKey implements ITKey { if (neverInitializeNewKey) { throw CoreError.default("key has not been generated yet"); } + + // no metadata set, assumes new user - await this._initializeNewKey({ initializeModules: true, importedKey: importKey, delete1OutOf1: p.delete1OutOf1 }); - return this.getKeyDetails(); + const newKeyDetails = await this._initializeNewKey({ initializeModules: true, importedKey: importKey, delete1OutOf1: p.delete1OutOf1 }); + const keyDetail = this.getKeyDetails(); + keyDetail.deviceShare = newKeyDetails.deviceShare; + keyDetail.userShare = newKeyDetails.userShare; + return keyDetail; } // else we continue with catching up share and metadata shareStore = ShareStore.fromJSON(rawServiceProviderShare); @@ -262,6 +267,23 @@ class ThresholdKey implements ITKey { throw CoreError.default("Input is not supported"); } + await this.postInit(shareStore, transitionMetadata, previouslyFetchedCloudMetadata, previousLocalMetadataTransitions); + } + + async postInit( + shareStore: ShareStore, + transitionMetadata?: Metadata, + previouslyFetchedCloudMetadata?: Metadata, + previousLocalMetadataTransitions?: LocalMetadataTransitions + ) { + const previousLocalMetadataTransitionsExists = + previousLocalMetadataTransitions && previousLocalMetadataTransitions[0].length > 0 && previousLocalMetadataTransitions[1].length > 0; + const reinitializing = transitionMetadata && previousLocalMetadataTransitionsExists; // are we reinitializing the SDK? + // in the case we're reinitializing whilst newKeyAssign has not been synced + const reinitializingWithNewKeyAssign = reinitializing && previouslyFetchedCloudMetadata === undefined; + + + // We determine the latest metadata on the SDK and if there has been // needed transitions to include let currentMetadata: Metadata; From c221be9e48eca6d83a9f2bce3f43427dafb193e8 Mon Sep 17 00:00:00 2001 From: ieow Date: Mon, 8 May 2023 09:34:13 +0800 Subject: [PATCH 2/2] fix: fn naming --- packages/core/src/core.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index 0c5dd78b..42446758 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -252,7 +252,6 @@ class ThresholdKey implements ITKey { if (neverInitializeNewKey) { throw CoreError.default("key has not been generated yet"); } - // no metadata set, assumes new user const newKeyDetails = await this._initializeNewKey({ initializeModules: true, importedKey: importKey, delete1OutOf1: p.delete1OutOf1 }); @@ -267,10 +266,10 @@ class ThresholdKey implements ITKey { throw CoreError.default("Input is not supported"); } - await this.postInit(shareStore, transitionMetadata, previouslyFetchedCloudMetadata, previousLocalMetadataTransitions); + await this.initializeWithShareStore(shareStore, transitionMetadata, previouslyFetchedCloudMetadata, previousLocalMetadataTransitions); } - async postInit( + async initializeWithShareStore( shareStore: ShareStore, transitionMetadata?: Metadata, previouslyFetchedCloudMetadata?: Metadata, @@ -282,8 +281,6 @@ class ThresholdKey implements ITKey { // in the case we're reinitializing whilst newKeyAssign has not been synced const reinitializingWithNewKeyAssign = reinitializing && previouslyFetchedCloudMetadata === undefined; - - // We determine the latest metadata on the SDK and if there has been // needed transitions to include let currentMetadata: Metadata;