Skip to content

Commit e6bd18c

Browse files
expose context object and custom sig setter
2 parents a1f8149 + 74c77f9 commit e6bd18c

File tree

6 files changed

+383
-92
lines changed

6 files changed

+383
-92
lines changed

src/interfaces.ts

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { KeyType, Point as TkeyPoint, ShareDescriptionMap } from "@tkey/common-types";
2-
import { TKeyTSS } 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,
66
ExtraParams,
77
LoginWindowResponse,
88
PasskeyExtraParams,
99
SubVerifierDetails,
10+
TorusAggregateLoginResponse,
11+
TorusLoginResponse,
1012
TorusVerifierResponse,
1113
UX_MODE_TYPE,
1214
} from "@toruslabs/customauth";
15+
import { TorusKey } from "@toruslabs/torus.js";
1316
import { Client } from "@toruslabs/tss-client";
1417
// TODO: move the types to a base class for both dkls and frost in future
1518
import type { tssLib as TssDklsLib } from "@toruslabs/tss-dkls-lib";
@@ -18,6 +21,7 @@ import type { tssLib as TssFrostLibBip340 } from "@toruslabs/tss-frost-lib-bip34
1821
import BN from "bn.js";
1922

2023
import { FactorKeyTypeShareDescription, TssShareType, USER_PATH, WEB3AUTH_NETWORK } from "./constants";
24+
import { ISessionSigGenerator } from "./plugins/ISessionSigGenerator";
2125

2226
export type CoreKitMode = UX_MODE_TYPE | "nodejs" | "react-native";
2327

@@ -86,7 +90,18 @@ export type MPCKeyDetails = {
8690
tssPubKey?: TkeyPoint;
8791
};
8892

89-
export type OAuthLoginParams = (SubVerifierDetailsParams | AggregateVerifierLoginParams) & { importTssKey?: string };
93+
export type OAuthLoginParams = (SubVerifierDetailsParams | AggregateVerifierLoginParams) & {
94+
/**
95+
* Key to import key into Tss during first time login.
96+
*/
97+
importTssKey?: string;
98+
99+
/**
100+
* For new users, use SFA key if user was registered with SFA before.
101+
* Useful when you created the user with SFA before and now want to convert it to TSS.
102+
*/
103+
registerExistingSFAKey?: boolean;
104+
};
90105
export type UserInfo = TorusVerifierResponse & LoginWindowResponse;
91106

92107
export interface EnableMFAParams {
@@ -147,6 +162,12 @@ export interface JWTLoginParams {
147162
*/
148163
importTssKey?: string;
149164

165+
/**
166+
* For new users, use SFA key if user was registered with SFA before.
167+
* Useful when you created the user with SFA before and now want to convert it to TSS.
168+
*/
169+
registerExistingSFAKey?: boolean;
170+
150171
/**
151172
* Number of TSS public keys to prefetch. For the best performance, set it to
152173
* the number of factors you want to create. Set it to 0 for an existing user.
@@ -166,18 +187,31 @@ export interface Web3AuthState {
166187
factorKey?: BN;
167188
}
168189

190+
export interface IContext {
191+
status: COREKIT_STATUS;
192+
state: Web3AuthState;
193+
sessionId: string;
194+
serviceProvider: TSSTorusServiceProvider | null;
195+
updateState: (newState: Partial<Web3AuthState>) => void;
196+
getUserInfo: () => UserInfo;
197+
logout: () => Promise<void>;
198+
setupTkey: (params?: {
199+
providedImportKey?: string;
200+
sfaLoginResponse?: TorusKey | TorusLoginResponse | TorusAggregateLoginResponse;
201+
userInfo?: UserInfo;
202+
importingSFAKey?: boolean;
203+
persistSessionSigs?: boolean;
204+
}) => Promise<void>;
205+
setCustomSessionSigGenerator: (sessionSigGenerator: ISessionSigGenerator) => void;
206+
}
207+
169208
export interface ICoreKit {
170209
/**
171210
* The tKey instance, if initialized.
172211
* TKey is the core module on which this wrapper SDK sits for easy integration.
173212
**/
174213
tKey: TKeyTSS | null;
175214

176-
/**
177-
* Signatures generated from the OAuth Login.
178-
**/
179-
signatures: string[] | null;
180-
181215
/**
182216
* Status of the current MPC Core Kit Instance
183217
**/
@@ -193,6 +227,7 @@ export interface ICoreKit {
193227
*/
194228
sessionId: string;
195229

230+
getContext(): IContext;
196231
/**
197232
* The function used to initailise the state of MPCCoreKit
198233
* Also is useful to resume an existing session.
@@ -268,6 +303,10 @@ export interface ICoreKit {
268303
*/
269304
getKeyDetails(): MPCKeyDetails;
270305

306+
getSessionSignatures(): Promise<string[]>;
307+
308+
setCustomSessionSigGenerator(sessionSigGenerator: ISessionSigGenerator): void;
309+
271310
/**
272311
* Commit the changes made to the user's account when in manual sync mode.
273312
*/

0 commit comments

Comments
 (0)