@dynamic-labs-wallet/forward-mpc-client 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +17 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +18 -47
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -588,8 +588,6 @@ var ForwardMPCClient = class extends EventEmitter2.EventEmitter {
|
|
|
588
588
|
}
|
|
589
589
|
}
|
|
590
590
|
};
|
|
591
|
-
|
|
592
|
-
// src/client-v2/errors.ts
|
|
593
591
|
var ErrorCode = {
|
|
594
592
|
// Transport
|
|
595
593
|
CONNECTION_FAILED: "CONNECTION_FAILED",
|
|
@@ -888,23 +886,35 @@ var ForwardMPCTransport = class extends EventEmitter2__default.default {
|
|
|
888
886
|
});
|
|
889
887
|
this.emit("message", event.data);
|
|
890
888
|
};
|
|
891
|
-
this.ws.onclose = () => {
|
|
889
|
+
this.ws.onclose = (event) => {
|
|
892
890
|
this._isConnected = false;
|
|
891
|
+
this.logger?.warn("WebSocket closed", {
|
|
892
|
+
url: this.url,
|
|
893
|
+
closeCode: event.code
|
|
894
|
+
});
|
|
893
895
|
if (!this._destroyed) {
|
|
894
896
|
this.emit("disconnected");
|
|
895
897
|
}
|
|
896
|
-
this.maybeReconnect();
|
|
898
|
+
this.maybeReconnect(event.code);
|
|
897
899
|
};
|
|
898
900
|
});
|
|
899
901
|
}
|
|
900
902
|
/**
|
|
901
903
|
* Attempts mid-session reconnects after a drop, up to `reconnectAttempts`
|
|
902
|
-
* times. Only fires when a successful connection was previously established
|
|
904
|
+
* times. Only fires when a successful connection was previously established
|
|
905
|
+
* and the close was unexpected (not a normal or idle-timeout close).
|
|
903
906
|
*/
|
|
904
|
-
maybeReconnect() {
|
|
907
|
+
maybeReconnect(closeCode) {
|
|
905
908
|
if (this._destroyed) return;
|
|
906
909
|
if (!this._hadSuccessfulConnection) return;
|
|
907
910
|
if (this._midSessionReconnectCount >= this.options.reconnectAttempts) return;
|
|
911
|
+
if (closeCode === forwardMpcShared.WebSocketCloseCode.NORMAL || closeCode === forwardMpcShared.WebSocketCloseCode.IDLE_TIMEOUT) {
|
|
912
|
+
this.logger?.info("WebSocket closed gracefully \u2014 not reconnecting", {
|
|
913
|
+
url: this.url,
|
|
914
|
+
closeCode
|
|
915
|
+
});
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
908
918
|
this._midSessionReconnectCount++;
|
|
909
919
|
this.logger?.warn("WebSocket disconnected \u2014 attempting reconnect", {
|
|
910
920
|
url: this.url,
|
|
@@ -1365,50 +1375,11 @@ var ForwardMPCClientV2 = class extends EventEmitter2__default.default {
|
|
|
1365
1375
|
}
|
|
1366
1376
|
};
|
|
1367
1377
|
|
|
1368
|
-
// src/client-v2/utils.ts
|
|
1369
|
-
function deepEqual(obj1, obj2) {
|
|
1370
|
-
if (obj1 === obj2) return true;
|
|
1371
|
-
if (typeof obj1 !== "object" || obj1 === null || typeof obj2 !== "object" || obj2 === null) {
|
|
1372
|
-
return false;
|
|
1373
|
-
}
|
|
1374
|
-
const keys1 = Object.keys(obj1);
|
|
1375
|
-
const keys2 = Object.keys(obj2);
|
|
1376
|
-
if (keys1.length !== keys2.length) return false;
|
|
1377
|
-
for (const key of keys1) {
|
|
1378
|
-
if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
|
|
1379
|
-
return false;
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
return true;
|
|
1383
|
-
}
|
|
1384
|
-
__name(deepEqual, "deepEqual");
|
|
1385
|
-
|
|
1386
1378
|
// src/client-v2/singleton.ts
|
|
1387
|
-
var ForwardMPCClientSingleton = class
|
|
1379
|
+
var ForwardMPCClientSingleton = class extends ForwardMPCClientV2 {
|
|
1388
1380
|
static {
|
|
1389
1381
|
__name(this, "ForwardMPCClientSingleton");
|
|
1390
1382
|
}
|
|
1391
|
-
static _instance = null;
|
|
1392
|
-
constructor(url, options) {
|
|
1393
|
-
const existing = _ForwardMPCClientSingleton._instance;
|
|
1394
|
-
if (existing !== null) {
|
|
1395
|
-
if (existing.url !== url) {
|
|
1396
|
-
throw new Error(`ForwardMPCClientSingleton already exists for "${existing.url}". Call disconnect() first to create a new instance.`);
|
|
1397
|
-
}
|
|
1398
|
-
if (!deepEqual(options, existing.options)) {
|
|
1399
|
-
throw new Error(`ForwardMPCClientSingleton already exists for the same URL but with different options.Call disconnect() first to create a new instance.`);
|
|
1400
|
-
}
|
|
1401
|
-
return existing;
|
|
1402
|
-
}
|
|
1403
|
-
super(url, options);
|
|
1404
|
-
_ForwardMPCClientSingleton._instance = this;
|
|
1405
|
-
}
|
|
1406
|
-
disconnect() {
|
|
1407
|
-
super.disconnect();
|
|
1408
|
-
if (_ForwardMPCClientSingleton._instance === this) {
|
|
1409
|
-
_ForwardMPCClientSingleton._instance = null;
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
1383
|
};
|
|
1413
1384
|
|
|
1414
1385
|
Object.defineProperty(exports, "SigningAlgorithm", {
|