diff --git a/package-lock.json b/package-lock.json index 6b35df6..a98864d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24442,7 +24442,7 @@ }, "packages/tss-client": { "name": "@toruslabs/tss-client", - "version": "3.1.0", + "version": "3.1.1", "license": "ISC", "dependencies": { "@toruslabs/eccrypto": "^4.0.0", diff --git a/packages/tss-client/package.json b/packages/tss-client/package.json index e071598..9171413 100644 --- a/packages/tss-client/package.json +++ b/packages/tss-client/package.json @@ -1,6 +1,6 @@ { "name": "@toruslabs/tss-client", - "version": "3.1.0", + "version": "3.1.2", "description": "Client SDK for MPECDSA signing", "files": [ "dist" diff --git a/packages/tss-client/src/client.ts b/packages/tss-client/src/client.ts index be4a841..283cfe9 100644 --- a/packages/tss-client/src/client.ts +++ b/packages/tss-client/src/client.ts @@ -115,6 +115,8 @@ export class Client { public tssLib: WasmLib; + public trackingId: string; + public _startPrecomputeTime: number; public _endPrecomputeTime: number; @@ -154,7 +156,8 @@ export class Client { _share: string, _pubKey: string, _websocketOnly: boolean, - _tssLib: WasmLib + _tssLib: WasmLib, + _trackingId?: string ) { if (_parties.length !== _sockets.length) { throw new Error("parties and sockets length must be equal, add null for client if necessary"); @@ -176,6 +179,12 @@ export class Client { this._sLessThanHalf = true; this.tssLib = _tssLib; + if (_trackingId) { + this.trackingId = _trackingId; + } else { + this.trackingId = this.generateTrackingId(); + } + _sockets.forEach((socket) => { if (socket) { if (socket.hasListeners("send")) { @@ -270,7 +279,11 @@ export class Client { if (party !== this.index) { precomputePromises.push( new Promise((resolve, reject) => { - fetch(`${this.lookupEndpoint(this.session, party)}/precompute`, { + let preComputeEndpoint = `${this.lookupEndpoint(this.session, party)}/precompute`; + if (this.trackingId) { + preComputeEndpoint += `?trackingId=${this.trackingId}`; + } + fetch(preComputeEndpoint, { method: "POST", headers: { "Content-Type": "application/json", @@ -372,7 +385,11 @@ export class Client { fragmentPromises.push( new Promise((resolve, reject) => { const endpoint = this.lookupEndpoint(this.session, party); - fetch(`${endpoint}/sign`, { + let signEndpoint = `${endpoint}/sign`; + if (this.trackingId) { + signEndpoint += `?trackingId=${this.trackingId}`; + } + fetch(signEndpoint, { method: "POST", headers: { "Content-Type": "application/json", @@ -459,7 +476,11 @@ export class Client { await Promise.all( this.parties.map(async (party) => { if (party !== this.index) { - await fetch(`${this.lookupEndpoint(this.session, party)}/cleanup`, { + let cleanupEndpoint = `${this.lookupEndpoint(this.session, party)}/cleanup`; + if (this.trackingId) { + cleanupEndpoint += `?trackingId=${this.trackingId}`; + } + await fetch(cleanupEndpoint, { method: "POST", headers: { "Content-Type": "application/json", @@ -472,4 +493,8 @@ export class Client { }) ); } + + generateTrackingId() { + return Math.random().toString(36).substring(2, 15); + } } diff --git a/packages/tss-client/src/utils.ts b/packages/tss-client/src/utils.ts index 74f7778..f0eabc4 100644 --- a/packages/tss-client/src/utils.ts +++ b/packages/tss-client/src/utils.ts @@ -86,14 +86,14 @@ export const getDKLSCoeff = (isUser: boolean, participatingServerIndexes: number return coeff; }; -export const createSockets = async (wsEndpoints: string[], sessionId: string): Promise => { +export const createSockets = async (wsEndpoints: string[], sessionId: string, trackingId?: string): Promise => { return wsEndpoints.map((wsEndpoint) => { if (wsEndpoint === null || wsEndpoint === undefined) { return null; } return io(wsEndpoint, { path: "/tss/socket.io", - query: { sessionId }, + query: { sessionId, trackingId }, transports: ["websocket", "polling"], withCredentials: true, reconnectionDelayMax: 10000, @@ -129,8 +129,8 @@ export const generateEndpoints = (parties: number, clientIndex: number) => { return { endpoints, tssWSEndpoints, partyIndexes }; }; -export const setupSockets = async (tssWSEndpoints: string[], sessionId: string) => { - const sockets = await createSockets(tssWSEndpoints, sessionId); +export const setupSockets = async (tssWSEndpoints: string[], sessionId: string, trackingId?: string) => { + const sockets = await createSockets(tssWSEndpoints, sessionId, trackingId); // wait for websockets to be connected await new Promise((resolve) => { const checkConnectionTimer = setInterval(() => {