Skip to content

Commit 241f152

Browse files
committed
feat: update interface
add throw error for unsupport feature for remoteSigner
1 parent f0bc2f8 commit 241f152

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

src/helper/errors.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ class CoreKitError extends AbstractCoreKitError {
339339
return CoreKitError.fromCode(1214, extraMessage);
340340
}
341341

342+
public static notSupportedForRemoteFactor(extraMessage = ""): ICoreKitError {
343+
return CoreKitError.fromCode(1215, extraMessage);
344+
}
345+
342346
// Initialization and session management
343347
public static commitChangesBeforeMFA(extraMessage = ""): ICoreKitError {
344348
return CoreKitError.fromCode(1301, extraMessage);

src/interfaces.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BNString, KeyType, Point as TkeyPoint, ShareDescriptionMap } from "@tkey/common-types";
2-
import { IRemoteClientState, TKeyTSS, TSSTorusServiceProvider } from "@tkey/tss";
2+
import { TKeyTSS, TSSTorusServiceProvider } from "@tkey/tss";
33
import { WEB3AUTH_SIG_TYPE } from "@toruslabs/constants";
44
import type {
55
AGGREGATE_VERIFIER_TYPE,
@@ -22,7 +22,7 @@ import { SafeEventEmitter } from "@web3auth/auth";
2222
import BN from "bn.js";
2323

2424
import { FactorKeyTypeShareDescription, TssShareType, USER_PATH, WEB3AUTH_NETWORK } from "./constants";
25-
import { IRemoteSignerContext } from "./plugins/IRemoteSigner";
25+
import { IRemoteClientState, IRemoteSignerContext } from "./plugins/ICustomSigner";
2626
import { ISessionSigGenerator } from "./plugins/ISessionSigGenerator";
2727

2828
export type CoreKitMode = UX_MODE_TYPE | "nodejs" | "react-native";
@@ -177,7 +177,6 @@ export interface JWTLoginParams {
177177
*/
178178
prefetchTssPublicKeys?: number;
179179
}
180-
181180
export interface Web3AuthState {
182181
postBoxKey?: string;
183182
signatures?: string[];
@@ -515,7 +514,6 @@ export interface SessionData {
515514
tssPubKey: string;
516515
signatures: string[];
517516
userInfo: UserInfo;
518-
remoteClientState?: IRemoteClientState;
519517
}
520518

521519
export interface TkeyLocalStoreData {

src/mpcCoreKit.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {
6060
Web3AuthState,
6161
} from "./interfaces";
6262
import { DefaultSessionSigGeneratorPlugin } from "./plugins/DefaultSessionSigGenerator";
63-
import { ICustomDklsSignParams, ICustomFrostSignParams, IRemoteClientState } from "./plugins/IRemoteSigner";
63+
import { ICustomDklsSignParams, ICustomFrostSignParams, IRemoteClientState } from "./plugins/ICustomSigner";
6464
import { ISessionSigGenerator } from "./plugins/ISessionSigGenerator";
6565
import {
6666
deriveShareCoefficients,
@@ -588,6 +588,13 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
588588
public async enableMFA(enableMFAParams: EnableMFAParams, recoveryFactor = true): Promise<string> {
589589
this.checkReady();
590590

591+
if (!this.state.factorKey) {
592+
if (this.state.remoteClient?.remoteFactorPub) {
593+
throw CoreKitError.notSupportedForRemoteFactor("Cannot enable MFA with remote factor.");
594+
}
595+
throw CoreKitError.factorKeyNotPresent("Current factorKey not present in state when enabling MFA.");
596+
}
597+
591598
const { postBoxKey } = this.state;
592599
const hashedFactorKey = getHashedPrivateKey(postBoxKey, this.options.hashedFactorNonce);
593600
if (!(await this.checkIfFactorKeyValid(hashedFactorKey))) {
@@ -652,6 +659,14 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
652659
// mutation function
653660
public async createFactor(createFactorParams: CreateFactorParams): Promise<string> {
654661
this.checkReady();
662+
663+
if (!this.state.factorKey) {
664+
if (this.state.remoteClient?.remoteFactorPub) {
665+
throw CoreKitError.notSupportedForRemoteFactor("Cannot create a factor with remote factor.");
666+
}
667+
throw CoreKitError.factorKeyNotPresent("Current factorKey not present in state when creating a factor.");
668+
}
669+
655670
const { shareType } = createFactorParams;
656671

657672
let { factorKey, shareDescription, additionalMetadata } = createFactorParams;
@@ -905,7 +920,8 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
905920

906921
// mutation function
907922
async deleteFactor(factorPub: Point, factorKey?: BNString): Promise<void> {
908-
if (!this.state.factorKey && !this.state.remoteClient) {
923+
if (!this.state.factorKey) {
924+
if (this.state.remoteClient?.remoteFactorPub) throw CoreKitError.notSupportedForRemoteFactor("Cannot delete a remote factor.");
909925
throw CoreKitError.factorKeyNotPresent("factorKey not present in state when deleting a factor.");
910926
}
911927
if (!this.tKey.metadata.factorPubs) {
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { FactorEnc, Point, ShareDescriptionMap } from "@tkey/common-types";
22
import { PointHex } from "@toruslabs/tss-client";
3+
import { SafeEventEmitter } from "@web3auth/auth";
34

45
import { CreateFactorParams, WEB3AUTH_NETWORK_TYPE } from "../interfaces";
56

6-
type SupportedCurve = "secp256k1" | "ed25519";
7-
export interface IRemoteClientState {
8-
remoteFactorPub: string;
9-
metadataShare: string;
10-
tssShareIndex: number;
11-
}
7+
export type SupportedCurve = "secp256k1" | "ed25519";
128

139
export type ICustomFrostSignParams = {
1410
sessionId: string;
@@ -50,7 +46,15 @@ export interface ICustomDKLSSign {
5046
export interface ICustomFrostSign {
5147
sign: (params: ICustomFrostSignParams, msgHash: Uint8Array) => Promise<Uint8Array>;
5248
}
49+
50+
export interface IRemoteClientState {
51+
remoteFactorPub: string;
52+
metadataShare: string;
53+
tssShareIndex: number;
54+
}
55+
5356
export interface IRemoteSignerContext {
57+
stateEmitter: SafeEventEmitter;
5458
setupRemoteSigning(params: Omit<IRemoteClientState, "tssShareIndex">, rehydrate?: boolean): Promise<void>;
5559
createFactor(createFactorParams: CreateFactorParams): Promise<string>;
5660
inputFactorKey(factorKey: string): Promise<void>;

src/plugins/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./DefaultSessionSigGenerator";
2+
export * from "./ICustomSigner";
23
export * from "./ISessionSigGenerator";

0 commit comments

Comments
 (0)