Skip to content

Commit 96b84a9

Browse files
committed
feat: update to match plugin interface
1 parent 4ac5e62 commit 96b84a9

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/helper/browserStorage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class MemoryStorage implements IStorage {
2121
}
2222
}
2323

24-
export class AsyncStorage {
24+
export class AsyncStore {
2525
public storage: IAsyncStorage | IStorage;
2626

2727
private _storeKey: string;
@@ -66,3 +66,6 @@ export class AsyncStorage {
6666
await this.storage.setItem(this._storeKey, JSON.stringify(store));
6767
}
6868
}
69+
70+
// Deprecated
71+
export class AsyncStorage extends AsyncStore {}

src/mpcCoreKit.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
899899

900900
public async commitChanges(): Promise<void> {
901901
this.checkReady();
902-
if (!this.state.factorKey && !this.state.remoteClient.remoteClientToken) {
902+
if (!this.state.factorKey && !this.state.remoteClient.metadataShare) {
903903
throw CoreKitError.factorKeyNotPresent("factorKey not present in state when committing changes.");
904904
}
905905

@@ -1005,8 +1005,8 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
10051005
}
10061006
}
10071007

1008-
async setupRemoteSigning(params: Omit<IRemoteClientState, "tssShareIndex" | "signatures">): Promise<void> {
1009-
const { remoteClientUrl, remoteFactorPub, metadataShare, remoteClientToken } = params;
1008+
async setupRemoteSigning(params: IRemoteClientState, rehydrate: boolean = false): Promise<void> {
1009+
const { remoteFactorPub, metadataShare } = params;
10101010
const details = this.getKeyDetails().shareDescriptions[remoteFactorPub];
10111011
if (!details) throw CoreKitError.default("factor description not found");
10121012

@@ -1016,12 +1016,9 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
10161016
if (!tssShareIndex) throw CoreKitError.default("tss share index not found");
10171017

10181018
const remoteClient: IRemoteClientState = {
1019-
remoteClientUrl: remoteClientUrl.at(-1) === "/" ? remoteClientUrl.slice(0, -1) : remoteClientUrl,
10201019
remoteFactorPub,
10211020
metadataShare,
1022-
remoteClientToken,
10231021
tssShareIndex,
1024-
signatures: this.state.signatures,
10251022
};
10261023

10271024
const sharestore = ShareStore.fromJSON(JSON.parse(metadataShare));
@@ -1032,8 +1029,10 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
10321029
// const tssPubKey = Point.fromTkeyPoint(this.tKey.getTSSPub()).toBufferSEC1(false);
10331030
this.updateState({ tssShareIndex, tssPubKey, remoteClient });
10341031
// // Finalize setup.
1035-
// setup provider
1036-
await this.createSessionRemoteClient();
1032+
// skip setup provider if rehydrate is true
1033+
if (!rehydrate) {
1034+
await this.createSessionRemoteClient();
1035+
}
10371036
}
10381037

10391038
public updateState(newState: Partial<Web3AuthState>): void {
@@ -1243,23 +1242,29 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
12431242
try {
12441243
this.checkReady();
12451244

1246-
const factorKey = new BN(result.factorKey, "hex");
1247-
if (!factorKey && !result.remoteClientState?.remoteClientToken) {
1248-
throw CoreKitError.providedFactorKeyInvalid();
1249-
}
12501245
const postBoxKey = result.postBoxKey || result.oAuthKey;
12511246
if (!postBoxKey) {
12521247
throw CoreKitError.default("postBoxKey or oAuthKey not present in session data");
12531248
}
1249+
1250+
const factorKey = new BN(result.factorKey, "hex");
1251+
if (!factorKey && !result.remoteClientState?.metadataShare) {
1252+
throw CoreKitError.providedFactorKeyInvalid();
1253+
}
1254+
12541255
this.torusSp.postboxKey = new BN(postBoxKey, "hex");
12551256
this.torusSp.verifierName = result.userInfo.aggregateVerifier || result.userInfo.verifier;
12561257
this.torusSp.verifierId = result.userInfo.verifierId;
12571258

1258-
const metadataShareStore = result.remoteClientState?.metadataShare
1259-
? ShareStore.fromJSON(JSON.parse(result.remoteClientState?.metadataShare))
1260-
: await this.getFactorKeyMetadata(factorKey);
1261-
12621259
await this.tKey.initialize({ neverInitializeNewKey: true });
1260+
1261+
// skip input share store if factor key is not present
1262+
// tkey will be at state initalized
1263+
if (!factorKey) {
1264+
return;
1265+
}
1266+
1267+
const metadataShareStore = await this.getFactorKeyMetadata(factorKey);
12631268
await this.tKey.inputShareStoreSafe(metadataShareStore, true);
12641269
await this.tKey.reconstructKey();
12651270

0 commit comments

Comments
 (0)