diff --git a/src/interfaces.ts b/src/interfaces.ts index b87c23a..4795c22 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -157,6 +157,7 @@ export interface JWTLoginParams { export interface Web3AuthState { postBoxKey?: string; signatures?: string[]; + postboxKeyNodeIndexes?: number[]; userInfo?: UserInfo; tssShareIndex?: number; tssPubKey?: Buffer; @@ -444,6 +445,7 @@ export interface SessionData { */ oAuthKey?: string; postBoxKey?: string; + postboxKeyNodeIndexes?: number[]; factorKey: string; tssShareIndex: number; tssPubKey: string; diff --git a/src/mpcCoreKit.ts b/src/mpcCoreKit.ts index b509543..f66dd1c 100644 --- a/src/mpcCoreKit.ts +++ b/src/mpcCoreKit.ts @@ -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; @@ -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), }); @@ -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), }); @@ -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), }); @@ -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), }); @@ -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), }); @@ -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, @@ -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."); } @@ -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"),