@getpara/server-sdk 3.0.0 → 3.2.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.
@@ -0,0 +1,61 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var mpcWorkerError_exports = {};
19
+ __export(mpcWorkerError_exports, {
20
+ classifyMpcError: () => classifyMpcError,
21
+ unwrapMpcError: () => unwrapMpcError,
22
+ wrapMpcError: () => wrapMpcError
23
+ });
24
+ module.exports = __toCommonJS(mpcWorkerError_exports);
25
+ function toError(value) {
26
+ return value instanceof Error ? value : new Error(String(value));
27
+ }
28
+ function wrapMpcError(summary, cause, context) {
29
+ const err = new Error(summary);
30
+ err.cause = toError(cause);
31
+ if (context) {
32
+ err.mpcContext = context;
33
+ }
34
+ return err;
35
+ }
36
+ function unwrapMpcError(err) {
37
+ var _a;
38
+ const top = err;
39
+ const cause = (top == null ? void 0 : top.cause) !== void 0 ? toError(top.cause) : toError(err);
40
+ const context = (_a = top == null ? void 0 : top.mpcContext) != null ? _a : {};
41
+ return { cause, context };
42
+ }
43
+ function classifyMpcError(message) {
44
+ const m = (message != null ? message : "").toLowerCase();
45
+ if (m.includes("panic")) return "MpcPanicError";
46
+ if (/\bwasm\b|webassembly/.test(m)) return "MpcWasmError";
47
+ if (/connection|websocket|\bdial\b|getconnection|econnrefused|network|broken pipe/.test(m)) {
48
+ return "MpcConnectionError";
49
+ }
50
+ if (/timed out|timeout|deadline/.test(m)) return "MpcTimeoutError";
51
+ if (/deserialize|unmarshal|invalid share|config from (sender|receiver)|reconstruct|magic bytes/.test(m)) {
52
+ return "MpcShareError";
53
+ }
54
+ return "MpcProtocolError";
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ classifyMpcError,
59
+ unwrapMpcError,
60
+ wrapMpcError
61
+ });
@@ -62,6 +62,7 @@ __export(walletUtils_exports, {
62
62
  module.exports = __toCommonJS(walletUtils_exports);
63
63
  var import_core_sdk = require("@getpara/core-sdk");
64
64
  var uuid = __toESM(require("uuid"));
65
+ var import_mpcWorkerError = require("./mpcWorkerError.js");
65
66
  const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
66
67
  const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
67
68
  function keygenRequest(ctx, userId, walletId, protocolId) {
@@ -114,8 +115,11 @@ function ed25519Keygen(ctx, userId, _sessionCookie, _emailProps, type = "SOLANA"
114
115
  })
115
116
  );
116
117
  return { signer: newSigner, walletId };
117
- } catch (e) {
118
- throw new Error(`error creating ED25519 account with userId ${userId} and walletId ${walletId}`);
118
+ } catch (mpcErr) {
119
+ throw (0, import_mpcWorkerError.wrapMpcError)(`error creating ED25519 account with userId ${userId} and walletId ${walletId}`, mpcErr, {
120
+ walletId,
121
+ protocolId
122
+ });
119
123
  }
120
124
  });
121
125
  }
@@ -138,8 +142,8 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, _sessionC
138
142
  })
139
143
  );
140
144
  return { signer: newSigner, walletId };
141
- } catch (e) {
142
- throw new Error(`error creating ED25519 account with walletId ${walletId}`);
145
+ } catch (mpcErr) {
146
+ throw (0, import_mpcWorkerError.wrapMpcError)(`error creating ED25519 account with walletId ${walletId}`, mpcErr, { walletId, protocolId });
143
147
  }
144
148
  });
145
149
  }
@@ -159,11 +163,15 @@ function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
159
163
  })
160
164
  );
161
165
  return { signature: base64Sig };
162
- } catch (e) {
163
- throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
166
+ } catch (mpcErr) {
167
+ throw (0, import_mpcWorkerError.wrapMpcError)(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`, mpcErr, {
168
+ protocolId
169
+ });
164
170
  }
165
171
  });
166
172
  }();
173
+ signRes.catch(() => {
174
+ });
167
175
  const { pendingTransactionId } = yield preSignMessageRes;
168
176
  if (pendingTransactionId) {
169
177
  return { pendingTransactionId };
@@ -207,8 +215,11 @@ function keygen(ctx, userId, type, secretKey) {
207
215
  )
208
216
  );
209
217
  return { signer: newSigner, walletId };
210
- } catch (e) {
211
- throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
218
+ } catch (mpcErr) {
219
+ throw (0, import_mpcWorkerError.wrapMpcError)(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`, mpcErr, {
220
+ walletId,
221
+ protocolId
222
+ });
212
223
  }
213
224
  });
214
225
  }
@@ -248,15 +259,15 @@ function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type,
248
259
  )
249
260
  );
250
261
  return { signer: newSigner, walletId };
251
- } catch (e) {
252
- throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
262
+ } catch (mpcErr) {
263
+ throw (0, import_mpcWorkerError.wrapMpcError)(`error creating account of type ${type} with walletId ${walletId}`, mpcErr, { walletId, protocolId });
253
264
  }
254
265
  });
255
266
  }
256
267
  function signMessage(ctx, share, walletId, userId, message) {
257
268
  return __async(this, null, function* () {
258
269
  const protocolId = uuid.v4();
259
- const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId);
270
+ const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId, true);
260
271
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
261
272
  return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
262
273
  }
@@ -273,11 +284,13 @@ function signMessage(ctx, share, walletId, userId, message) {
273
284
  resolve({ signature: result });
274
285
  })
275
286
  );
276
- } catch (e) {
277
- throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
287
+ } catch (mpcErr) {
288
+ throw (0, import_mpcWorkerError.wrapMpcError)(`error signing for account with userId ${userId} and walletId ${walletId}`, mpcErr, { protocolId });
278
289
  }
279
290
  });
280
291
  }();
292
+ signMessageRes.catch(() => {
293
+ });
281
294
  const { pendingTransactionId } = yield preSignMessageRes;
282
295
  if (pendingTransactionId) {
283
296
  return { pendingTransactionId };
@@ -288,7 +301,12 @@ function signMessage(ctx, share, walletId, userId, message) {
288
301
  function signTransaction(ctx, share, walletId, userId, tx, chainId) {
289
302
  return __async(this, null, function* () {
290
303
  const protocolId = uuid.v4();
291
- const signTransactionRes = ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
304
+ const signTransactionRes = ctx.client.signTransaction(userId, walletId, {
305
+ transaction: tx,
306
+ chainId,
307
+ protocolId,
308
+ useNewOT: true
309
+ });
292
310
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
293
311
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
294
312
  }
@@ -305,11 +323,15 @@ function signTransaction(ctx, share, walletId, userId, tx, chainId) {
305
323
  resolve({ signature: result });
306
324
  })
307
325
  );
308
- } catch (e) {
309
- throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
326
+ } catch (mpcErr) {
327
+ throw (0, import_mpcWorkerError.wrapMpcError)(`error signing transaction for account with userId ${userId} and walletId ${walletId}`, mpcErr, {
328
+ protocolId
329
+ });
310
330
  }
311
331
  });
312
332
  }();
333
+ signTxRes.catch(() => {
334
+ });
313
335
  const {
314
336
  data: { pendingTransactionId }
315
337
  } = yield signTransactionRes;
@@ -322,7 +344,12 @@ function signTransaction(ctx, share, walletId, userId, tx, chainId) {
322
344
  function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
323
345
  return __async(this, null, function* () {
324
346
  const protocolId = uuid.v4();
325
- const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
347
+ const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, {
348
+ transaction: tx,
349
+ chainId,
350
+ protocolId,
351
+ useNewOT: true
352
+ });
326
353
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
327
354
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
328
355
  }
@@ -339,11 +366,17 @@ function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
339
366
  resolve({ signature: result });
340
367
  })
341
368
  );
342
- } catch (e) {
343
- throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
369
+ } catch (mpcErr) {
370
+ throw (0, import_mpcWorkerError.wrapMpcError)(
371
+ `error signing transaction to send for account with userId ${userId} and walletId ${walletId}`,
372
+ mpcErr,
373
+ { protocolId }
374
+ );
344
375
  }
345
376
  });
346
377
  }();
378
+ sendTxRes.catch(() => {
379
+ });
347
380
  const {
348
381
  data: { pendingTransactionId }
349
382
  } = yield sendTransactionRes;
@@ -357,7 +390,7 @@ function refresh(ctx, share, walletId, userId) {
357
390
  return __async(this, null, function* () {
358
391
  const {
359
392
  data: { protocolId }
360
- } = yield ctx.client.refreshKeys(userId, walletId);
393
+ } = yield ctx.client.refreshKeys(userId, walletId, void 0, void 0, void 0, true);
361
394
  const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
362
395
  const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
363
396
  try {
@@ -369,8 +402,8 @@ function refresh(ctx, share, walletId, userId) {
369
402
  resolve(result);
370
403
  })
371
404
  );
372
- } catch (e) {
373
- throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
405
+ } catch (mpcErr) {
406
+ throw (0, import_mpcWorkerError.wrapMpcError)(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`, mpcErr);
374
407
  }
375
408
  });
376
409
  }
@@ -390,8 +423,8 @@ function getPrivateKey(ctx, share, walletId, userId) {
390
423
  resolve(result);
391
424
  })
392
425
  );
393
- } catch (e) {
394
- throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
426
+ } catch (mpcErr) {
427
+ throw (0, import_mpcWorkerError.wrapMpcError)(`error getting private key for account with userId ${userId} and walletId ${walletId}`, mpcErr);
395
428
  }
396
429
  });
397
430
  }
@@ -411,8 +444,11 @@ function getED25519PrivateKey(ctx, share, walletId, userId) {
411
444
  resolve(result);
412
445
  })
413
446
  );
414
- } catch (e) {
415
- throw new Error(`error getting ed25519 private key for account with userId ${userId} and walletId ${walletId}`);
447
+ } catch (mpcErr) {
448
+ throw (0, import_mpcWorkerError.wrapMpcError)(
449
+ `error getting ed25519 private key for account with userId ${userId} and walletId ${walletId}`,
450
+ mpcErr
451
+ );
416
452
  }
417
453
  });
418
454
  }
@@ -2,8 +2,22 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
7
21
  var __export = (target, all) => {
8
22
  for (var name in all)
9
23
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -55,6 +69,7 @@ module.exports = __toCommonJS(worker_exports);
55
69
  var import_axios = __toESM(require("axios"));
56
70
  var import_core_sdk = require("@getpara/core-sdk");
57
71
  var walletUtils = __toESM(require("./walletUtils.js"));
72
+ var import_mpcWorkerError = require("./mpcWorkerError.js");
58
73
  let rawWasm;
59
74
  let wasmLoaded = false;
60
75
  function requestWasmWithRetries(ctx, retries = 3) {
@@ -160,13 +175,17 @@ function withRetry(operation, maxRetries = 2, timeoutMs = 1e4) {
160
175
  while (true) {
161
176
  try {
162
177
  const operationPromise = operation();
178
+ let timeoutId;
163
179
  const timeoutPromise = new Promise((_, reject) => {
164
- const timeoutId = setTimeout(() => {
180
+ timeoutId = setTimeout(() => {
165
181
  reject(new Error(`Operation timed out after ${timeoutMs}ms`));
166
182
  }, timeoutMs);
167
- operationPromise.finally(() => clearTimeout(timeoutId));
168
183
  });
169
- return yield Promise.race([operationPromise, timeoutPromise]);
184
+ try {
185
+ return yield Promise.race([operationPromise, timeoutPromise]);
186
+ } finally {
187
+ clearTimeout(timeoutId);
188
+ }
170
189
  } catch (error) {
171
190
  retries++;
172
191
  if (retries > maxRetries) {
@@ -177,6 +196,31 @@ function withRetry(operation, maxRetries = 2, timeoutMs = 1e4) {
177
196
  }
178
197
  });
179
198
  }
199
+ function reportWorkerError(ctx, data, err) {
200
+ return __async(this, null, function* () {
201
+ var _a;
202
+ try {
203
+ const { cause, context } = (0, import_mpcWorkerError.unwrapMpcError)(err);
204
+ yield ctx.client.trackError({
205
+ methodName: `mpcWorker.${data.functionType}`,
206
+ sdkType: "SERVER",
207
+ userId: (_a = data.params.userId) != null ? _a : "",
208
+ sdkVersion: import_core_sdk.paraVersion,
209
+ error: { name: (0, import_mpcWorkerError.classifyMpcError)(cause.message), message: cause.message },
210
+ context: __spreadValues({
211
+ functionType: data.functionType,
212
+ // worker-level identifiers (present for most signing ops); the wrapped
213
+ // context (spread last) supplies walletId/protocolId for keygen flows
214
+ // where params don't carry them.
215
+ userId: data.params.userId,
216
+ walletId: data.params.walletId,
217
+ chainId: data.params.chainId
218
+ }, context)
219
+ });
220
+ } catch (e) {
221
+ }
222
+ });
223
+ }
180
224
  function handleMessage(e) {
181
225
  return __async(this, null, function* () {
182
226
  const {
@@ -200,22 +244,28 @@ function handleMessage(e) {
200
244
  disableWebSockets: !!disableWebSockets,
201
245
  cosmosPrefix
202
246
  };
203
- if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
204
- yield loadWasm(ctx);
205
- if (global.initWasm) {
206
- const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
207
- yield new Promise(
208
- (resolve, reject) => global.initWasm((err, result2) => {
209
- if (err) {
210
- reject(err);
211
- }
212
- resolve(result2);
213
- }, serverUrl)
214
- );
215
- }
216
- wasmLoaded = true;
247
+ let result;
248
+ try {
249
+ if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
250
+ yield loadWasm(ctx);
251
+ if (global.initWasm) {
252
+ const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
253
+ yield new Promise(
254
+ (resolve, reject) => global.initWasm((err, initResult) => {
255
+ if (err) {
256
+ reject(err);
257
+ }
258
+ resolve(initResult);
259
+ }, serverUrl)
260
+ );
261
+ }
262
+ wasmLoaded = true;
263
+ }
264
+ result = yield executeMessage(ctx, e.data);
265
+ } catch (err) {
266
+ yield reportWorkerError(ctx, e.data, err);
267
+ throw err;
217
268
  }
218
- const result = yield executeMessage(ctx, e.data);
219
269
  result.workId = workId;
220
270
  return result;
221
271
  });
@@ -0,0 +1,36 @@
1
+ import "../chunk-FTA5RKYX.js";
2
+ function toError(value) {
3
+ return value instanceof Error ? value : new Error(String(value));
4
+ }
5
+ function wrapMpcError(summary, cause, context) {
6
+ const err = new Error(summary);
7
+ err.cause = toError(cause);
8
+ if (context) {
9
+ err.mpcContext = context;
10
+ }
11
+ return err;
12
+ }
13
+ function unwrapMpcError(err) {
14
+ const top = err;
15
+ const cause = top?.cause !== void 0 ? toError(top.cause) : toError(err);
16
+ const context = top?.mpcContext ?? {};
17
+ return { cause, context };
18
+ }
19
+ function classifyMpcError(message) {
20
+ const m = (message ?? "").toLowerCase();
21
+ if (m.includes("panic")) return "MpcPanicError";
22
+ if (/\bwasm\b|webassembly/.test(m)) return "MpcWasmError";
23
+ if (/connection|websocket|\bdial\b|getconnection|econnrefused|network|broken pipe/.test(m)) {
24
+ return "MpcConnectionError";
25
+ }
26
+ if (/timed out|timeout|deadline/.test(m)) return "MpcTimeoutError";
27
+ if (/deserialize|unmarshal|invalid share|config from (sender|receiver)|reconstruct|magic bytes/.test(m)) {
28
+ return "MpcShareError";
29
+ }
30
+ return "MpcProtocolError";
31
+ }
32
+ export {
33
+ classifyMpcError,
34
+ unwrapMpcError,
35
+ wrapMpcError
36
+ };
@@ -1,6 +1,7 @@
1
1
  import "../chunk-FTA5RKYX.js";
2
2
  import { getBaseMPCNetworkUrl } from "@getpara/core-sdk";
3
3
  import * as uuid from "uuid";
4
+ import { wrapMpcError } from "./mpcWorkerError.js";
4
5
  const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
5
6
  const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
6
7
  async function keygenRequest(ctx, userId, walletId, protocolId) {
@@ -46,8 +47,11 @@ async function ed25519Keygen(ctx, userId, _sessionCookie, _emailProps, type = "S
46
47
  })
47
48
  );
48
49
  return { signer: newSigner, walletId };
49
- } catch {
50
- throw new Error(`error creating ED25519 account with userId ${userId} and walletId ${walletId}`);
50
+ } catch (mpcErr) {
51
+ throw wrapMpcError(`error creating ED25519 account with userId ${userId} and walletId ${walletId}`, mpcErr, {
52
+ walletId,
53
+ protocolId
54
+ });
51
55
  }
52
56
  }
53
57
  async function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, _sessionCookie, type = "SOLANA") {
@@ -68,8 +72,8 @@ async function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, _se
68
72
  })
69
73
  );
70
74
  return { signer: newSigner, walletId };
71
- } catch {
72
- throw new Error(`error creating ED25519 account with walletId ${walletId}`);
75
+ } catch (mpcErr) {
76
+ throw wrapMpcError(`error creating ED25519 account with walletId ${walletId}`, mpcErr, { walletId, protocolId });
73
77
  }
74
78
  }
75
79
  async function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
@@ -86,10 +90,14 @@ async function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
86
90
  })
87
91
  );
88
92
  return { signature: base64Sig };
89
- } catch {
90
- throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
93
+ } catch (mpcErr) {
94
+ throw wrapMpcError(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`, mpcErr, {
95
+ protocolId
96
+ });
91
97
  }
92
98
  }();
99
+ signRes.catch(() => {
100
+ });
93
101
  const { pendingTransactionId } = await preSignMessageRes;
94
102
  if (pendingTransactionId) {
95
103
  return { pendingTransactionId };
@@ -131,8 +139,11 @@ async function keygen(ctx, userId, type, secretKey) {
131
139
  )
132
140
  );
133
141
  return { signer: newSigner, walletId };
134
- } catch {
135
- throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
142
+ } catch (mpcErr) {
143
+ throw wrapMpcError(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`, mpcErr, {
144
+ walletId,
145
+ protocolId
146
+ });
136
147
  }
137
148
  }
138
149
  async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
@@ -170,13 +181,13 @@ async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType,
170
181
  )
171
182
  );
172
183
  return { signer: newSigner, walletId };
173
- } catch {
174
- throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
184
+ } catch (mpcErr) {
185
+ throw wrapMpcError(`error creating account of type ${type} with walletId ${walletId}`, mpcErr, { walletId, protocolId });
175
186
  }
176
187
  }
177
188
  async function signMessage(ctx, share, walletId, userId, message) {
178
189
  const protocolId = uuid.v4();
179
- const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId);
190
+ const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId, true);
180
191
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
181
192
  return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
182
193
  }
@@ -192,10 +203,12 @@ async function signMessage(ctx, share, walletId, userId, message) {
192
203
  resolve({ signature: result });
193
204
  })
194
205
  );
195
- } catch {
196
- throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
206
+ } catch (mpcErr) {
207
+ throw wrapMpcError(`error signing for account with userId ${userId} and walletId ${walletId}`, mpcErr, { protocolId });
197
208
  }
198
209
  }();
210
+ signMessageRes.catch(() => {
211
+ });
199
212
  const { pendingTransactionId } = await preSignMessageRes;
200
213
  if (pendingTransactionId) {
201
214
  return { pendingTransactionId };
@@ -204,7 +217,12 @@ async function signMessage(ctx, share, walletId, userId, message) {
204
217
  }
205
218
  async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
206
219
  const protocolId = uuid.v4();
207
- const signTransactionRes = ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
220
+ const signTransactionRes = ctx.client.signTransaction(userId, walletId, {
221
+ transaction: tx,
222
+ chainId,
223
+ protocolId,
224
+ useNewOT: true
225
+ });
208
226
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
209
227
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
210
228
  }
@@ -220,10 +238,14 @@ async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
220
238
  resolve({ signature: result });
221
239
  })
222
240
  );
223
- } catch {
224
- throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
241
+ } catch (mpcErr) {
242
+ throw wrapMpcError(`error signing transaction for account with userId ${userId} and walletId ${walletId}`, mpcErr, {
243
+ protocolId
244
+ });
225
245
  }
226
246
  }();
247
+ signTxRes.catch(() => {
248
+ });
227
249
  const {
228
250
  data: { pendingTransactionId }
229
251
  } = await signTransactionRes;
@@ -234,7 +256,12 @@ async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
234
256
  }
235
257
  async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
236
258
  const protocolId = uuid.v4();
237
- const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
259
+ const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, {
260
+ transaction: tx,
261
+ chainId,
262
+ protocolId,
263
+ useNewOT: true
264
+ });
238
265
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
239
266
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
240
267
  }
@@ -250,10 +277,16 @@ async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
250
277
  resolve({ signature: result });
251
278
  })
252
279
  );
253
- } catch {
254
- throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
280
+ } catch (mpcErr) {
281
+ throw wrapMpcError(
282
+ `error signing transaction to send for account with userId ${userId} and walletId ${walletId}`,
283
+ mpcErr,
284
+ { protocolId }
285
+ );
255
286
  }
256
287
  }();
288
+ sendTxRes.catch(() => {
289
+ });
257
290
  const {
258
291
  data: { pendingTransactionId }
259
292
  } = await sendTransactionRes;
@@ -265,7 +298,7 @@ async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
265
298
  async function refresh(ctx, share, walletId, userId) {
266
299
  const {
267
300
  data: { protocolId }
268
- } = await ctx.client.refreshKeys(userId, walletId);
301
+ } = await ctx.client.refreshKeys(userId, walletId, void 0, void 0, void 0, true);
269
302
  const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
270
303
  const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
271
304
  try {
@@ -277,8 +310,8 @@ async function refresh(ctx, share, walletId, userId) {
277
310
  resolve(result);
278
311
  })
279
312
  );
280
- } catch {
281
- throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
313
+ } catch (mpcErr) {
314
+ throw wrapMpcError(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`, mpcErr);
282
315
  }
283
316
  }
284
317
  async function getPrivateKey(ctx, share, walletId, userId) {
@@ -296,8 +329,8 @@ async function getPrivateKey(ctx, share, walletId, userId) {
296
329
  resolve(result);
297
330
  })
298
331
  );
299
- } catch {
300
- throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
332
+ } catch (mpcErr) {
333
+ throw wrapMpcError(`error getting private key for account with userId ${userId} and walletId ${walletId}`, mpcErr);
301
334
  }
302
335
  }
303
336
  async function getED25519PrivateKey(ctx, share, walletId, userId) {
@@ -315,8 +348,11 @@ async function getED25519PrivateKey(ctx, share, walletId, userId) {
315
348
  resolve(result);
316
349
  })
317
350
  );
318
- } catch {
319
- throw new Error(`error getting ed25519 private key for account with userId ${userId} and walletId ${walletId}`);
351
+ } catch (mpcErr) {
352
+ throw wrapMpcError(
353
+ `error getting ed25519 private key for account with userId ${userId} and walletId ${walletId}`,
354
+ mpcErr
355
+ );
320
356
  }
321
357
  }
322
358
  export {
@@ -1,3 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
1
17
  var __async = (__this, __arguments, generator) => {
2
18
  return new Promise((resolve, reject) => {
3
19
  var fulfilled = (value) => {
@@ -27,6 +43,7 @@ import {
27
43
  paraVersion
28
44
  } from "@getpara/core-sdk";
29
45
  import * as walletUtils from "./walletUtils.js";
46
+ import { classifyMpcError, unwrapMpcError } from "./mpcWorkerError.js";
30
47
  let rawWasm;
31
48
  let wasmLoaded = false;
32
49
  function requestWasmWithRetries(ctx, retries = 3) {
@@ -132,13 +149,17 @@ function withRetry(operation, maxRetries = 2, timeoutMs = 1e4) {
132
149
  while (true) {
133
150
  try {
134
151
  const operationPromise = operation();
152
+ let timeoutId;
135
153
  const timeoutPromise = new Promise((_, reject) => {
136
- const timeoutId = setTimeout(() => {
154
+ timeoutId = setTimeout(() => {
137
155
  reject(new Error(`Operation timed out after ${timeoutMs}ms`));
138
156
  }, timeoutMs);
139
- operationPromise.finally(() => clearTimeout(timeoutId));
140
157
  });
141
- return yield Promise.race([operationPromise, timeoutPromise]);
158
+ try {
159
+ return yield Promise.race([operationPromise, timeoutPromise]);
160
+ } finally {
161
+ clearTimeout(timeoutId);
162
+ }
142
163
  } catch (error) {
143
164
  retries++;
144
165
  if (retries > maxRetries) {
@@ -149,6 +170,31 @@ function withRetry(operation, maxRetries = 2, timeoutMs = 1e4) {
149
170
  }
150
171
  });
151
172
  }
173
+ function reportWorkerError(ctx, data, err) {
174
+ return __async(this, null, function* () {
175
+ var _a;
176
+ try {
177
+ const { cause, context } = unwrapMpcError(err);
178
+ yield ctx.client.trackError({
179
+ methodName: `mpcWorker.${data.functionType}`,
180
+ sdkType: "SERVER",
181
+ userId: (_a = data.params.userId) != null ? _a : "",
182
+ sdkVersion: paraVersion,
183
+ error: { name: classifyMpcError(cause.message), message: cause.message },
184
+ context: __spreadValues({
185
+ functionType: data.functionType,
186
+ // worker-level identifiers (present for most signing ops); the wrapped
187
+ // context (spread last) supplies walletId/protocolId for keygen flows
188
+ // where params don't carry them.
189
+ userId: data.params.userId,
190
+ walletId: data.params.walletId,
191
+ chainId: data.params.chainId
192
+ }, context)
193
+ });
194
+ } catch (e) {
195
+ }
196
+ });
197
+ }
152
198
  function handleMessage(e) {
153
199
  return __async(this, null, function* () {
154
200
  const {
@@ -172,22 +218,28 @@ function handleMessage(e) {
172
218
  disableWebSockets: !!disableWebSockets,
173
219
  cosmosPrefix
174
220
  };
175
- if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
176
- yield loadWasm(ctx);
177
- if (global.initWasm) {
178
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
179
- yield new Promise(
180
- (resolve, reject) => global.initWasm((err, result2) => {
181
- if (err) {
182
- reject(err);
183
- }
184
- resolve(result2);
185
- }, serverUrl)
186
- );
187
- }
188
- wasmLoaded = true;
221
+ let result;
222
+ try {
223
+ if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
224
+ yield loadWasm(ctx);
225
+ if (global.initWasm) {
226
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
227
+ yield new Promise(
228
+ (resolve, reject) => global.initWasm((err, initResult) => {
229
+ if (err) {
230
+ reject(err);
231
+ }
232
+ resolve(initResult);
233
+ }, serverUrl)
234
+ );
235
+ }
236
+ wasmLoaded = true;
237
+ }
238
+ result = yield executeMessage(ctx, e.data);
239
+ } catch (err) {
240
+ yield reportWorkerError(ctx, e.data, err);
241
+ throw err;
189
242
  }
190
- const result = yield executeMessage(ctx, e.data);
191
243
  result.workId = workId;
192
244
  return result;
193
245
  });
@@ -0,0 +1,14 @@
1
+ export interface MpcErrorContext {
2
+ protocolId?: string;
3
+ walletId?: string;
4
+ userId?: string;
5
+ chainId?: string;
6
+ functionType?: string;
7
+ [key: string]: unknown;
8
+ }
9
+ export declare function wrapMpcError(summary: string, cause: unknown, context?: MpcErrorContext): Error;
10
+ export declare function unwrapMpcError(err: unknown): {
11
+ cause: Error;
12
+ context: MpcErrorContext;
13
+ };
14
+ export declare function classifyMpcError(message: string | undefined): string;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@getpara/server-sdk",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "dependencies": {
5
- "@getpara/core-sdk": "3.0.0",
6
- "@getpara/user-management-client": "3.0.0",
7
- "@getpara/viem-v2-integration": "3.0.0",
5
+ "@getpara/core-sdk": "3.2.0",
6
+ "@getpara/user-management-client": "3.2.0",
7
+ "@getpara/viem-v2-integration": "3.2.0",
8
8
  "uuid": "^11.1.0",
9
9
  "ws": "^8.14.2"
10
10
  },
@@ -16,7 +16,7 @@
16
16
  "dist",
17
17
  "package.json"
18
18
  ],
19
- "gitHead": "e6c42e42adfcfadb0114b1ac65ba5203e6274712",
19
+ "gitHead": "096152f48e9d9a64fdb192588315c64d33d15a1b",
20
20
  "main": "dist/cjs/index.js",
21
21
  "module": "dist/esm/index.js",
22
22
  "scripts": {