@getpara/server-sdk 1.15.1 → 1.17.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.
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
  var __async = (__this, __arguments, generator) => {
19
29
  return new Promise((resolve, reject) => {
@@ -50,6 +60,7 @@ __export(walletUtils_exports, {
50
60
  });
51
61
  module.exports = __toCommonJS(walletUtils_exports);
52
62
  var import_core_sdk = require("@getpara/core-sdk");
63
+ var uuid = __toESM(require("uuid"));
53
64
  const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
54
65
  const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
55
66
  function keygenRequest(ctx, userId, walletId, protocolId) {
@@ -133,20 +144,34 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
133
144
  }
134
145
  function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
135
146
  return __async(this, null, function* () {
136
- const { protocolId } = yield ctx.client.preSignMessage(userId, walletId, base64Bytes, import_core_sdk.WalletScheme.ED25519);
137
- try {
138
- const base64Sig = yield new Promise(
139
- (resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
140
- if (err) {
141
- reject(err);
142
- }
143
- resolve(result);
144
- })
145
- );
146
- return { signature: base64Sig };
147
- } catch (e) {
148
- throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
149
- }
147
+ const protocolId = uuid.v4();
148
+ const preSignMessageRes = ctx.client.preSignMessage(
149
+ userId,
150
+ walletId,
151
+ base64Bytes,
152
+ import_core_sdk.WalletScheme.ED25519,
153
+ void 0,
154
+ protocolId
155
+ );
156
+ const signRes = function() {
157
+ return __async(this, null, function* () {
158
+ try {
159
+ const base64Sig = yield new Promise(
160
+ (resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
161
+ if (err) {
162
+ reject(err);
163
+ }
164
+ resolve(result);
165
+ })
166
+ );
167
+ return { signature: base64Sig };
168
+ } catch (e) {
169
+ throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
170
+ }
171
+ });
172
+ }();
173
+ yield preSignMessageRes;
174
+ return yield signRes;
150
175
  });
151
176
  }
152
177
  function keygen(ctx, userId, type, secretKey) {
@@ -233,81 +258,102 @@ function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type,
233
258
  }
234
259
  function signMessage(ctx, share, walletId, userId, message) {
235
260
  return __async(this, null, function* () {
236
- const { protocolId, pendingTransactionId } = yield ctx.client.preSignMessage(userId, walletId, message);
237
- if (pendingTransactionId) {
238
- return { pendingTransactionId };
239
- }
261
+ const protocolId = uuid.v4();
262
+ const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId);
240
263
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
241
264
  return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
242
265
  }
243
266
  const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
244
267
  const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
245
- try {
246
- return yield new Promise(
247
- (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
248
- if (err) {
249
- reject(err);
250
- }
251
- resolve({ signature: result });
252
- })
253
- );
254
- } catch (e) {
255
- throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
268
+ const signMessageRes = function() {
269
+ return __async(this, null, function* () {
270
+ try {
271
+ return yield new Promise(
272
+ (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
273
+ if (err) {
274
+ reject(err);
275
+ }
276
+ resolve({ signature: result });
277
+ })
278
+ );
279
+ } catch (e) {
280
+ throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
281
+ }
282
+ });
283
+ }();
284
+ const { pendingTransactionId } = yield preSignMessageRes;
285
+ if (pendingTransactionId) {
286
+ return { pendingTransactionId };
256
287
  }
288
+ return yield signMessageRes;
257
289
  });
258
290
  }
259
291
  function signTransaction(ctx, share, walletId, userId, tx, chainId) {
260
292
  return __async(this, null, function* () {
261
- const {
262
- data: { protocolId, pendingTransactionId }
263
- } = yield ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
264
- if (pendingTransactionId) {
265
- return { pendingTransactionId };
266
- }
293
+ const protocolId = uuid.v4();
294
+ const signTransactionRes = ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
267
295
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
268
296
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
269
297
  }
270
298
  const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
271
299
  const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
272
- try {
273
- return yield new Promise(
274
- (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
275
- if (err) {
276
- reject(err);
277
- }
278
- resolve({ signature: result });
279
- })
280
- );
281
- } catch (e) {
282
- throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
300
+ const signTxRes = function() {
301
+ return __async(this, null, function* () {
302
+ try {
303
+ return yield new Promise(
304
+ (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
305
+ if (err) {
306
+ reject(err);
307
+ }
308
+ resolve({ signature: result });
309
+ })
310
+ );
311
+ } catch (e) {
312
+ throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
313
+ }
314
+ });
315
+ }();
316
+ const {
317
+ data: { pendingTransactionId }
318
+ } = yield signTransactionRes;
319
+ if (pendingTransactionId) {
320
+ return { pendingTransactionId };
283
321
  }
322
+ return yield signTxRes;
284
323
  });
285
324
  }
286
325
  function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
287
326
  return __async(this, null, function* () {
288
- const {
289
- data: { protocolId, pendingTransactionId }
290
- } = yield ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
291
- if (pendingTransactionId) {
292
- return { pendingTransactionId };
293
- }
327
+ const protocolId = uuid.v4();
328
+ const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
294
329
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
295
330
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
296
331
  }
297
332
  const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
298
333
  const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
299
- try {
300
- return yield new Promise(
301
- (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
302
- if (err) {
303
- reject(err);
304
- }
305
- resolve({ signature: result });
306
- })
307
- );
308
- } catch (e) {
309
- throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
334
+ const sendTxRes = function() {
335
+ return __async(this, null, function* () {
336
+ try {
337
+ return yield new Promise(
338
+ (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
339
+ if (err) {
340
+ reject(err);
341
+ }
342
+ resolve({ signature: result });
343
+ })
344
+ );
345
+ } catch (e) {
346
+ throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
347
+ }
348
+ });
349
+ }();
350
+ const {
351
+ data: { pendingTransactionId }
352
+ } = yield sendTransactionRes;
353
+ if (pendingTransactionId) {
354
+ return { pendingTransactionId };
310
355
  }
356
+ return yield sendTxRes;
311
357
  });
312
358
  }
313
359
  function refresh(ctx, share, walletId, userId) {
@@ -48,13 +48,15 @@ var __async = (__this, __arguments, generator) => {
48
48
  var worker_exports = {};
49
49
  __export(worker_exports, {
50
50
  handleMessage: () => handleMessage,
51
- requestWasmWithRetries: () => requestWasmWithRetries
51
+ requestWasmWithRetries: () => requestWasmWithRetries,
52
+ withRetry: () => withRetry
52
53
  });
53
54
  module.exports = __toCommonJS(worker_exports);
54
55
  var import_axios = __toESM(require("axios"));
55
56
  var import_core_sdk = require("@getpara/core-sdk");
56
57
  var walletUtils = __toESM(require("./walletUtils.js"));
57
58
  let rawWasm;
59
+ let wasmLoaded = false;
58
60
  function requestWasmWithRetries(ctx, retries = 3) {
59
61
  return __async(this, null, function* () {
60
62
  for (let i = 0; i < retries; i++) {
@@ -91,15 +93,15 @@ function executeMessage(ctx, message) {
91
93
  }
92
94
  case "SIGN_TRANSACTION": {
93
95
  const { share, walletId, userId, tx, chainId } = params;
94
- return walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId);
96
+ return withRetry(() => walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId));
95
97
  }
96
98
  case "SEND_TRANSACTION": {
97
99
  const { share, walletId, userId, tx, chainId } = params;
98
- return walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId);
100
+ return withRetry(() => walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId));
99
101
  }
100
102
  case "SIGN_MESSAGE": {
101
103
  const { share, walletId, userId, message: message2 } = params;
102
- return walletUtils.signMessage(ctx, share, walletId, userId, message2);
104
+ return withRetry(() => walletUtils.signMessage(ctx, share, walletId, userId, message2));
103
105
  }
104
106
  case "REFRESH": {
105
107
  const { share, walletId, userId } = params;
@@ -144,6 +146,29 @@ function executeMessage(ctx, message) {
144
146
  }
145
147
  });
146
148
  }
149
+ function withRetry(operation, maxRetries = 2, timeoutMs = 1e4) {
150
+ return __async(this, null, function* () {
151
+ let retries = 0;
152
+ while (true) {
153
+ try {
154
+ const operationPromise = operation();
155
+ const timeoutPromise = new Promise((_, reject) => {
156
+ const timeoutId = setTimeout(() => {
157
+ reject(new Error(`Operation timed out after ${timeoutMs}ms`));
158
+ }, timeoutMs);
159
+ operationPromise.finally(() => clearTimeout(timeoutId));
160
+ });
161
+ return yield Promise.race([operationPromise, timeoutPromise]);
162
+ } catch (error) {
163
+ retries++;
164
+ if (retries > maxRetries) {
165
+ throw error;
166
+ }
167
+ console.warn(`Operation failed (attempt ${retries}/${maxRetries}), retrying...`, error);
168
+ }
169
+ }
170
+ });
171
+ }
147
172
  function handleMessage(e) {
148
173
  return __async(this, null, function* () {
149
174
  const {
@@ -167,8 +192,19 @@ function handleMessage(e) {
167
192
  disableWebSockets: !!disableWebSockets,
168
193
  cosmosPrefix
169
194
  };
170
- if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
195
+ if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
171
196
  yield loadWasm(ctx);
197
+ if (global.initWasm) {
198
+ yield new Promise(
199
+ (resolve, reject) => global.initWasm((err, result2) => {
200
+ if (err) {
201
+ reject(err);
202
+ }
203
+ resolve(result2);
204
+ })
205
+ );
206
+ }
207
+ wasmLoaded = true;
172
208
  }
173
209
  const result = yield executeMessage(ctx, e.data);
174
210
  result.workId = workId;
@@ -178,5 +214,6 @@ function handleMessage(e) {
178
214
  // Annotate the CommonJS export names for ESM import in node:
179
215
  0 && (module.exports = {
180
216
  handleMessage,
181
- requestWasmWithRetries
217
+ requestWasmWithRetries,
218
+ withRetry
182
219
  });
@@ -1,5 +1,6 @@
1
1
  import "../chunk-FTA5RKYX.js";
2
2
  import { getBaseMPCNetworkUrl, WalletScheme, WalletType } from "@getpara/core-sdk";
3
+ import * as uuid from "uuid";
3
4
  const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
4
5
  const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
5
6
  async function keygenRequest(ctx, userId, walletId, protocolId) {
@@ -72,20 +73,32 @@ async function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
72
73
  }
73
74
  }
74
75
  async function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
75
- const { protocolId } = await ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
76
- try {
77
- const base64Sig = await new Promise(
78
- (resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
79
- if (err) {
80
- reject(err);
81
- }
82
- resolve(result);
83
- })
84
- );
85
- return { signature: base64Sig };
86
- } catch (e) {
87
- throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
88
- }
76
+ const protocolId = uuid.v4();
77
+ const preSignMessageRes = ctx.client.preSignMessage(
78
+ userId,
79
+ walletId,
80
+ base64Bytes,
81
+ WalletScheme.ED25519,
82
+ void 0,
83
+ protocolId
84
+ );
85
+ const signRes = async function() {
86
+ try {
87
+ const base64Sig = await new Promise(
88
+ (resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
89
+ if (err) {
90
+ reject(err);
91
+ }
92
+ resolve(result);
93
+ })
94
+ );
95
+ return { signature: base64Sig };
96
+ } catch (e) {
97
+ throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
98
+ }
99
+ }();
100
+ await preSignMessageRes;
101
+ return await signRes;
89
102
  }
90
103
  async function keygen(ctx, userId, type, secretKey) {
91
104
  const { walletId, protocolId } = await ctx.client.createWallet(userId, {
@@ -166,77 +179,92 @@ async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType,
166
179
  }
167
180
  }
168
181
  async function signMessage(ctx, share, walletId, userId, message) {
169
- const { protocolId, pendingTransactionId } = await ctx.client.preSignMessage(userId, walletId, message);
170
- if (pendingTransactionId) {
171
- return { pendingTransactionId };
172
- }
182
+ const protocolId = uuid.v4();
183
+ const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId);
173
184
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
174
185
  return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
175
186
  }
176
187
  const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
177
188
  const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
178
- try {
179
- return await new Promise(
180
- (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
181
- if (err) {
182
- reject(err);
183
- }
184
- resolve({ signature: result });
185
- })
186
- );
187
- } catch (e) {
188
- throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
189
- }
190
- }
191
- async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
192
- const {
193
- data: { protocolId, pendingTransactionId }
194
- } = await ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
189
+ const signMessageRes = async function() {
190
+ try {
191
+ return await new Promise(
192
+ (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
193
+ if (err) {
194
+ reject(err);
195
+ }
196
+ resolve({ signature: result });
197
+ })
198
+ );
199
+ } catch (e) {
200
+ throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
201
+ }
202
+ }();
203
+ const { pendingTransactionId } = await preSignMessageRes;
195
204
  if (pendingTransactionId) {
196
205
  return { pendingTransactionId };
197
206
  }
207
+ return await signMessageRes;
208
+ }
209
+ async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
210
+ const protocolId = uuid.v4();
211
+ const signTransactionRes = ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
198
212
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
199
213
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
200
214
  }
201
215
  const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
202
216
  const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
203
- try {
204
- return await new Promise(
205
- (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
206
- if (err) {
207
- reject(err);
208
- }
209
- resolve({ signature: result });
210
- })
211
- );
212
- } catch (e) {
213
- throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
214
- }
215
- }
216
- async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
217
+ const signTxRes = async function() {
218
+ try {
219
+ return await new Promise(
220
+ (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
221
+ if (err) {
222
+ reject(err);
223
+ }
224
+ resolve({ signature: result });
225
+ })
226
+ );
227
+ } catch (e) {
228
+ throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
229
+ }
230
+ }();
217
231
  const {
218
- data: { protocolId, pendingTransactionId }
219
- } = await ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
232
+ data: { pendingTransactionId }
233
+ } = await signTransactionRes;
220
234
  if (pendingTransactionId) {
221
235
  return { pendingTransactionId };
222
236
  }
237
+ return await signTxRes;
238
+ }
239
+ async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
240
+ const protocolId = uuid.v4();
241
+ const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
223
242
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
224
243
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
225
244
  }
226
245
  const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
227
246
  const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
228
- try {
229
- return await new Promise(
230
- (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
231
- if (err) {
232
- reject(err);
233
- }
234
- resolve({ signature: result });
235
- })
236
- );
237
- } catch (e) {
238
- throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
247
+ const sendTxRes = async function() {
248
+ try {
249
+ return await new Promise(
250
+ (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
251
+ if (err) {
252
+ reject(err);
253
+ }
254
+ resolve({ signature: result });
255
+ })
256
+ );
257
+ } catch (e) {
258
+ throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
259
+ }
260
+ }();
261
+ const {
262
+ data: { pendingTransactionId }
263
+ } = await sendTransactionRes;
264
+ if (pendingTransactionId) {
265
+ return { pendingTransactionId };
239
266
  }
267
+ return await sendTxRes;
240
268
  }
241
269
  async function refresh(ctx, share, walletId, userId) {
242
270
  const {
@@ -28,6 +28,7 @@ import {
28
28
  } from "@getpara/core-sdk";
29
29
  import * as walletUtils from "./walletUtils.js";
30
30
  let rawWasm;
31
+ let wasmLoaded = false;
31
32
  function requestWasmWithRetries(ctx, retries = 3) {
32
33
  return __async(this, null, function* () {
33
34
  for (let i = 0; i < retries; i++) {
@@ -64,15 +65,15 @@ function executeMessage(ctx, message) {
64
65
  }
65
66
  case "SIGN_TRANSACTION": {
66
67
  const { share, walletId, userId, tx, chainId } = params;
67
- return walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId);
68
+ return withRetry(() => walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId));
68
69
  }
69
70
  case "SEND_TRANSACTION": {
70
71
  const { share, walletId, userId, tx, chainId } = params;
71
- return walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId);
72
+ return withRetry(() => walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId));
72
73
  }
73
74
  case "SIGN_MESSAGE": {
74
75
  const { share, walletId, userId, message: message2 } = params;
75
- return walletUtils.signMessage(ctx, share, walletId, userId, message2);
76
+ return withRetry(() => walletUtils.signMessage(ctx, share, walletId, userId, message2));
76
77
  }
77
78
  case "REFRESH": {
78
79
  const { share, walletId, userId } = params;
@@ -117,6 +118,29 @@ function executeMessage(ctx, message) {
117
118
  }
118
119
  });
119
120
  }
121
+ function withRetry(operation, maxRetries = 2, timeoutMs = 1e4) {
122
+ return __async(this, null, function* () {
123
+ let retries = 0;
124
+ while (true) {
125
+ try {
126
+ const operationPromise = operation();
127
+ const timeoutPromise = new Promise((_, reject) => {
128
+ const timeoutId = setTimeout(() => {
129
+ reject(new Error(`Operation timed out after ${timeoutMs}ms`));
130
+ }, timeoutMs);
131
+ operationPromise.finally(() => clearTimeout(timeoutId));
132
+ });
133
+ return yield Promise.race([operationPromise, timeoutPromise]);
134
+ } catch (error) {
135
+ retries++;
136
+ if (retries > maxRetries) {
137
+ throw error;
138
+ }
139
+ console.warn(`Operation failed (attempt ${retries}/${maxRetries}), retrying...`, error);
140
+ }
141
+ }
142
+ });
143
+ }
120
144
  function handleMessage(e) {
121
145
  return __async(this, null, function* () {
122
146
  const {
@@ -140,8 +164,19 @@ function handleMessage(e) {
140
164
  disableWebSockets: !!disableWebSockets,
141
165
  cosmosPrefix
142
166
  };
143
- if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
167
+ if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
144
168
  yield loadWasm(ctx);
169
+ if (global.initWasm) {
170
+ yield new Promise(
171
+ (resolve, reject) => global.initWasm((err, result2) => {
172
+ if (err) {
173
+ reject(err);
174
+ }
175
+ resolve(result2);
176
+ })
177
+ );
178
+ }
179
+ wasmLoaded = true;
145
180
  }
146
181
  const result = yield executeMessage(ctx, e.data);
147
182
  result.workId = workId;
@@ -150,5 +185,6 @@ function handleMessage(e) {
150
185
  }
151
186
  export {
152
187
  handleMessage,
153
- requestWasmWithRetries
188
+ requestWasmWithRetries,
189
+ withRetry
154
190
  };
@@ -13,6 +13,14 @@ interface Message {
13
13
  workId: string;
14
14
  }
15
15
  export declare function requestWasmWithRetries(ctx: Ctx, retries?: number): Promise<import("axios").AxiosResponse<any, any>>;
16
+ /**
17
+ * Executes an operation with retry capabilities
18
+ * @param operation The function to execute
19
+ * @param maxRetries Maximum number of retries (default: 2)
20
+ * @param timeoutMs Timeout in milliseconds (default: 10000)
21
+ * @returns The result of the operation
22
+ */
23
+ export declare function withRetry<T>(operation: () => Promise<T>, maxRetries?: number, timeoutMs?: number): Promise<T>;
16
24
  export declare function handleMessage(e: {
17
25
  data: Message;
18
26
  }): Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpara/server-sdk",
3
- "version": "1.15.1",
3
+ "version": "1.17.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -9,8 +9,8 @@
9
9
  "wasm_exec.js"
10
10
  ],
11
11
  "dependencies": {
12
- "@getpara/core-sdk": "1.15.1",
13
- "@getpara/user-management-client": "1.15.1",
12
+ "@getpara/core-sdk": "1.17.0",
13
+ "@getpara/user-management-client": "1.17.0",
14
14
  "uuid": "^11.1.0",
15
15
  "ws": "^8.14.2"
16
16
  },
@@ -30,5 +30,5 @@
30
30
  "dist",
31
31
  "package.json"
32
32
  ],
33
- "gitHead": "591a28303fdd9abd944d512e7dfdb73759a32ed8"
33
+ "gitHead": "857cb45a49040c475fa7431f36134b0d5cb630f5"
34
34
  }