Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add tracking #77

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/tss-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@toruslabs/tss-client",
"version": "3.1.0",
"version": "3.1.2",
"description": "Client SDK for MPECDSA signing",
"files": [
"dist"
Expand Down
33 changes: 29 additions & 4 deletions packages/tss-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export class Client {

public tssLib: WasmLib;

public trackingId: string;

public _startPrecomputeTime: number;

public _endPrecomputeTime: number;
Expand Down Expand Up @@ -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");
Expand All @@ -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")) {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -472,4 +493,8 @@ export class Client {
})
);
}

generateTrackingId() {
return Math.random().toString(36).substring(2, 15);
}
}
8 changes: 4 additions & 4 deletions packages/tss-client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ export const getDKLSCoeff = (isUser: boolean, participatingServerIndexes: number
return coeff;
};

export const createSockets = async (wsEndpoints: string[], sessionId: string): Promise<Socket[]> => {
export const createSockets = async (wsEndpoints: string[], sessionId: string, trackingId?: string): Promise<Socket[]> => {
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,
Expand Down Expand Up @@ -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(() => {
Expand Down