Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export interface JWTLoginParams {
export interface Web3AuthState {
postBoxKey?: string;
signatures?: string[];
postboxKeyNodeIndexes?: number[];
userInfo?: UserInfo;
tssShareIndex?: number;
tssPubKey?: Buffer;
Expand Down Expand Up @@ -444,6 +445,7 @@ export interface SessionData {
*/
oAuthKey?: string;
postBoxKey?: string;
postboxKeyNodeIndexes?: number[];
factorKey: string;
tssShareIndex: number;
tssPubKey: string;
Expand Down
15 changes: 11 additions & 4 deletions src/mpcCoreKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ import {
export class Web3AuthMPCCoreKit implements ICoreKit {
public state: Web3AuthState = { accountIndex: 0 };

private options: Web3AuthOptionsWithDefaults;
public torusSp: TSSTorusServiceProvider | null = null;

private torusSp: TSSTorusServiceProvider | null = null;
private options: Web3AuthOptionsWithDefaults;

private storageLayer: TorusStorageLayer | null = null;

Expand Down Expand Up @@ -333,6 +333,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {

this.updateState({
postBoxKey: this._getPostBoxKey(loginResponse),
postboxKeyNodeIndexes: loginResponse.nodesData?.nodeIndexes,
userInfo: loginResponse.userInfo,
signatures: this._getSignatures(loginResponse.sessionData.sessionTokenData),
});
Expand All @@ -347,6 +348,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {

this.updateState({
postBoxKey: this._getPostBoxKey(loginResponse),
postboxKeyNodeIndexes: loginResponse.nodesData?.nodeIndexes,
userInfo: loginResponse.userInfo[0],
signatures: this._getSignatures(loginResponse.sessionData.sessionTokenData),
});
Expand Down Expand Up @@ -406,6 +408,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {

this.updateState({
postBoxKey,
postboxKeyNodeIndexes: loginResponse.nodesData?.nodeIndexes || [],
userInfo: { ...parseToken(idToken), verifier, verifierId },
signatures: this._getSignatures(loginResponse.sessionData.sessionTokenData),
});
Expand Down Expand Up @@ -438,6 +441,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
}
this.updateState({
postBoxKey: this._getPostBoxKey(data),
postboxKeyNodeIndexes: data.nodesData?.nodeIndexes || [],
userInfo: data.userInfo,
signatures: this._getSignatures(data.sessionData.sessionTokenData),
});
Expand All @@ -450,6 +454,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
}
this.updateState({
postBoxKey: this._getPostBoxKey(data),
postboxKeyNodeIndexes: data.nodesData?.nodeIndexes || [],
userInfo: data.userInfo[0],
signatures: this._getSignatures(data.sessionData.sessionTokenData),
});
Expand Down Expand Up @@ -1121,6 +1126,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
this.updateState({
factorKey: new BN(result.factorKey, "hex"),
postBoxKey,
postboxKeyNodeIndexes: result.postboxKeyNodeIndexes || [],
tssShareIndex: result.tssShareIndex,
tssPubKey: this.tkey.getTSSPub().toSEC1(this.tKey.tssCurve, false),
signatures: result.signatures,
Expand All @@ -1132,14 +1138,14 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
}

private async createSession() {
if (!this.sessionManager) {
if (!this.options.disableSessionManager && !this.sessionManager) {
throw new Error("sessionManager is not available");
}

try {
const sessionId = SessionManager.generateRandomSessionKey();
this.sessionManager.sessionId = sessionId;
const { postBoxKey, factorKey, userInfo, tssShareIndex, tssPubKey } = this.state;
const { postBoxKey, factorKey, userInfo, tssShareIndex, tssPubKey, postboxKeyNodeIndexes } = this.state;
if (!this.state.factorKey) {
throw CoreKitError.factorKeyNotPresent("factorKey not present in state when creating session.");
}
Expand All @@ -1151,6 +1157,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
}
const payload: SessionData = {
postBoxKey,
postboxKeyNodeIndexes: postboxKeyNodeIndexes || [],
factorKey: factorKey?.toString("hex"),
tssShareIndex: tssShareIndex as number,
tssPubKey: Buffer.from(tssPubKey).toString("hex"),
Expand Down