Skip to content

Commit c33d0d0

Browse files
committed
fix: update interface for remote signing
fix rehydration
1 parent 077478b commit c33d0d0

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { KeyType, Point as TkeyPoint, ShareDescriptionMap } from "@tkey/common-types";
1+
import { BNString, KeyType, Point as TkeyPoint, ShareDescriptionMap } from "@tkey/common-types";
22
import { IRemoteClientState, TKeyTSS } from "@tkey/tss";
33
import type {
44
AGGREGATE_VERIFIER_TYPE,
@@ -91,7 +91,7 @@ export interface EnableMFAParams {
9191
/**
9292
* A BN used for encrypting your Device/ Recovery TSS Key Share. You can generate it using `generateFactorKey()` function or use an existing one.
9393
*/
94-
factorKey?: BN;
94+
factorKey?: BNString;
9595
/**
9696
* Setting the Description of Share - Security Questions, Device Share, Seed Phrase, Password Share, Social Share, Other. Default is Other.
9797
*/

src/mpcCoreKit.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,19 +478,20 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
478478
}
479479
}
480480

481-
public async inputFactorKey(factorKey: BN): Promise<void> {
481+
public async inputFactorKey(factorKey: BNString): Promise<void> {
482+
const factorKeyBN = new BN(factorKey, "hex");
482483
this.checkReady();
483484
try {
484485
// input tkey device share when required share > 0 ( or not reconstructed )
485486
// assumption tkey shares will not changed
486487
if (!this.tKey.secp256k1Key) {
487-
const factorKeyMetadata = await this.getFactorKeyMetadata(factorKey);
488+
const factorKeyMetadata = await this.getFactorKeyMetadata(factorKeyBN);
488489
await this.tKey.inputShareStoreSafe(factorKeyMetadata, true);
489490
}
490491

491492
// Finalize initialization.
492493
await this.tKey.reconstructKey();
493-
await this.finalizeTkey(factorKey);
494+
await this.finalizeTkey(factorKeyBN);
494495
} catch (err: unknown) {
495496
log.error("login error", err);
496497
if (err instanceof CoreError) {
@@ -595,6 +596,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
595596
const { shareType } = createFactorParams;
596597

597598
let { factorKey, shareDescription, additionalMetadata } = createFactorParams;
599+
factorKey = factorKey ? new BN(factorKey, "hex") : undefined;
598600

599601
if (!VALID_SHARE_INDICES.includes(shareType)) {
600602
throw CoreKitError.newShareIndexInvalid(`Invalid share type provided (${shareType}). Valid share types are ${VALID_SHARE_INDICES}.`);
@@ -1129,7 +1131,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
11291131
this.checkReady();
11301132

11311133
const factorKey = new BN(result.factorKey, "hex");
1132-
if (!factorKey) {
1134+
if (!factorKey && !result.remoteClientState?.remoteClientToken) {
11331135
throw CoreKitError.providedFactorKeyInvalid();
11341136
}
11351137
const postBoxKey = result.postBoxKey || result.oAuthKey;
@@ -1139,18 +1141,23 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
11391141
this.torusSp.postboxKey = new BN(postBoxKey, "hex");
11401142
this.torusSp.verifierName = result.userInfo.aggregateVerifier || result.userInfo.verifier;
11411143
this.torusSp.verifierId = result.userInfo.verifierId;
1142-
const factorKeyMetadata = await this.getFactorKeyMetadata(factorKey);
1144+
1145+
const metadataShareStore = result.remoteClientState?.metadataShare
1146+
? ShareStore.fromJSON(JSON.parse(result.remoteClientState?.metadataShare))
1147+
: await this.getFactorKeyMetadata(factorKey);
1148+
11431149
await this.tKey.initialize({ neverInitializeNewKey: true });
1144-
await this.tKey.inputShareStoreSafe(factorKeyMetadata, true);
1150+
await this.tKey.inputShareStoreSafe(metadataShareStore, true);
11451151
await this.tKey.reconstructKey();
11461152

11471153
this.updateState({
1148-
factorKey: new BN(result.factorKey, "hex"),
1154+
factorKey: factorKey ? new BN(result.factorKey, "hex") : undefined,
11491155
postBoxKey,
11501156
tssShareIndex: result.tssShareIndex,
11511157
tssPubKey: this.tkey.getTSSPub().toSEC1(this.tKey.tssCurve, false),
11521158
signatures: result.signatures,
11531159
userInfo: result.userInfo,
1160+
remoteClient: result.remoteClientState,
11541161
});
11551162
} catch (err) {
11561163
log.error("error trying to authorize session", err);

0 commit comments

Comments
 (0)