Skip to content

Commit 412d181

Browse files
committed
fix: update interface for remote signing
fix rehydration
1 parent b7fbd35 commit 412d181

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
@@ -473,19 +473,20 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
473473
}
474474
}
475475

476-
public async inputFactorKey(factorKey: BN): Promise<void> {
476+
public async inputFactorKey(factorKey: BNString): Promise<void> {
477+
const factorKeyBN = new BN(factorKey, "hex");
477478
this.checkReady();
478479
try {
479480
// input tkey device share when required share > 0 ( or not reconstructed )
480481
// assumption tkey shares will not changed
481482
if (!this.tKey.secp256k1Key) {
482-
const factorKeyMetadata = await this.getFactorKeyMetadata(factorKey);
483+
const factorKeyMetadata = await this.getFactorKeyMetadata(factorKeyBN);
483484
await this.tKey.inputShareStoreSafe(factorKeyMetadata, true);
484485
}
485486

486487
// Finalize initialization.
487488
await this.tKey.reconstructKey();
488-
await this.finalizeTkey(factorKey);
489+
await this.finalizeTkey(factorKeyBN);
489490
} catch (err: unknown) {
490491
log.error("login error", err);
491492
if (err instanceof CoreError) {
@@ -590,6 +591,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
590591
const { shareType } = createFactorParams;
591592

592593
let { factorKey, shareDescription, additionalMetadata } = createFactorParams;
594+
factorKey = factorKey ? new BN(factorKey, "hex") : undefined;
593595

594596
if (!VALID_SHARE_INDICES.includes(shareType)) {
595597
throw CoreKitError.newShareIndexInvalid(`Invalid share type provided (${shareType}). Valid share types are ${VALID_SHARE_INDICES}.`);
@@ -1142,7 +1144,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
11421144
this.checkReady();
11431145

11441146
const factorKey = new BN(result.factorKey, "hex");
1145-
if (!factorKey) {
1147+
if (!factorKey && !result.remoteClientState?.remoteClientToken) {
11461148
throw CoreKitError.providedFactorKeyInvalid();
11471149
}
11481150
const postBoxKey = result.postBoxKey || result.oAuthKey;
@@ -1152,18 +1154,23 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
11521154
this.torusSp.postboxKey = new BN(postBoxKey, "hex");
11531155
this.torusSp.verifierName = result.userInfo.aggregateVerifier || result.userInfo.verifier;
11541156
this.torusSp.verifierId = result.userInfo.verifierId;
1155-
const factorKeyMetadata = await this.getFactorKeyMetadata(factorKey);
1157+
1158+
const metadataShareStore = result.remoteClientState?.metadataShare
1159+
? ShareStore.fromJSON(JSON.parse(result.remoteClientState?.metadataShare))
1160+
: await this.getFactorKeyMetadata(factorKey);
1161+
11561162
await this.tKey.initialize({ neverInitializeNewKey: true });
1157-
await this.tKey.inputShareStoreSafe(factorKeyMetadata, true);
1163+
await this.tKey.inputShareStoreSafe(metadataShareStore, true);
11581164
await this.tKey.reconstructKey();
11591165

11601166
this.updateState({
1161-
factorKey: new BN(result.factorKey, "hex"),
1167+
factorKey: factorKey ? new BN(result.factorKey, "hex") : undefined,
11621168
postBoxKey,
11631169
tssShareIndex: result.tssShareIndex,
11641170
tssPubKey: this.tkey.getTSSPub().toSEC1(this.tKey.tssCurve, false),
11651171
signatures: result.signatures,
11661172
userInfo: result.userInfo,
1173+
remoteClient: result.remoteClientState,
11671174
});
11681175
} catch (err) {
11691176
log.warn("failed to authorize session", err);

0 commit comments

Comments
 (0)