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..42446758 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -252,9 +252,13 @@ 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 +266,21 @@ class ThresholdKey implements ITKey { throw CoreError.default("Input is not supported"); } + await this.initializeWithShareStore(shareStore, transitionMetadata, previouslyFetchedCloudMetadata, previousLocalMetadataTransitions); + } + + async initializeWithShareStore( + 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;