@getpara/server-sdk 2.0.0-alpha.18 → 2.0.0-alpha.19

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,27 @@ 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, "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(userId, walletId, base64Bytes, "ED25519", void 0, protocolId);
149
+ const signRes = function() {
150
+ return __async(this, null, function* () {
151
+ try {
152
+ const base64Sig = yield new Promise(
153
+ (resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
154
+ if (err) {
155
+ reject(err);
156
+ }
157
+ resolve(result);
158
+ })
159
+ );
160
+ return { signature: base64Sig };
161
+ } catch (e) {
162
+ throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
163
+ }
164
+ });
165
+ }();
166
+ yield preSignMessageRes;
167
+ return yield signRes;
150
168
  });
151
169
  }
152
170
  function keygen(ctx, userId, type, secretKey) {
@@ -233,81 +251,102 @@ function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type,
233
251
  }
234
252
  function signMessage(ctx, share, walletId, userId, message) {
235
253
  return __async(this, null, function* () {
236
- const { protocolId, pendingTransactionId } = yield ctx.client.preSignMessage(userId, walletId, message);
237
- if (pendingTransactionId) {
238
- return { pendingTransactionId };
239
- }
254
+ const protocolId = uuid.v4();
255
+ const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId);
240
256
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
241
257
  return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
242
258
  }
243
259
  const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
244
260
  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}`);
261
+ const signMessageRes = function() {
262
+ return __async(this, null, function* () {
263
+ try {
264
+ return yield new Promise(
265
+ (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
266
+ if (err) {
267
+ reject(err);
268
+ }
269
+ resolve({ signature: result });
270
+ })
271
+ );
272
+ } catch (e) {
273
+ throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
274
+ }
275
+ });
276
+ }();
277
+ const { pendingTransactionId } = yield preSignMessageRes;
278
+ if (pendingTransactionId) {
279
+ return { pendingTransactionId };
256
280
  }
281
+ return yield signMessageRes;
257
282
  });
258
283
  }
259
284
  function signTransaction(ctx, share, walletId, userId, tx, chainId) {
260
285
  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
- }
286
+ const protocolId = uuid.v4();
287
+ const signTransactionRes = ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
267
288
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
268
289
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
269
290
  }
270
291
  const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
271
292
  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}`);
293
+ const signTxRes = function() {
294
+ return __async(this, null, function* () {
295
+ try {
296
+ return yield new Promise(
297
+ (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
298
+ if (err) {
299
+ reject(err);
300
+ }
301
+ resolve({ signature: result });
302
+ })
303
+ );
304
+ } catch (e) {
305
+ throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
306
+ }
307
+ });
308
+ }();
309
+ const {
310
+ data: { pendingTransactionId }
311
+ } = yield signTransactionRes;
312
+ if (pendingTransactionId) {
313
+ return { pendingTransactionId };
283
314
  }
315
+ return yield signTxRes;
284
316
  });
285
317
  }
286
318
  function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
287
319
  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
- }
320
+ const protocolId = uuid.v4();
321
+ const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
294
322
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
295
323
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
296
324
  }
297
325
  const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
298
326
  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}`);
327
+ const sendTxRes = function() {
328
+ return __async(this, null, function* () {
329
+ try {
330
+ return yield new Promise(
331
+ (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
332
+ if (err) {
333
+ reject(err);
334
+ }
335
+ resolve({ signature: result });
336
+ })
337
+ );
338
+ } catch (e) {
339
+ throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
340
+ }
341
+ });
342
+ }();
343
+ const {
344
+ data: { pendingTransactionId }
345
+ } = yield sendTransactionRes;
346
+ if (pendingTransactionId) {
347
+ return { pendingTransactionId };
310
348
  }
349
+ return yield sendTxRes;
311
350
  });
312
351
  }
313
352
  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 } 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,25 @@ 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, "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(userId, walletId, base64Bytes, "ED25519", void 0, protocolId);
78
+ const signRes = async function() {
79
+ try {
80
+ const base64Sig = await new Promise(
81
+ (resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
82
+ if (err) {
83
+ reject(err);
84
+ }
85
+ resolve(result);
86
+ })
87
+ );
88
+ return { signature: base64Sig };
89
+ } catch (e) {
90
+ throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
91
+ }
92
+ }();
93
+ await preSignMessageRes;
94
+ return await signRes;
89
95
  }
90
96
  async function keygen(ctx, userId, type, secretKey) {
91
97
  const { walletId, protocolId } = await ctx.client.createWallet(userId, {
@@ -166,77 +172,92 @@ async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType,
166
172
  }
167
173
  }
168
174
  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
- }
175
+ const protocolId = uuid.v4();
176
+ const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId);
173
177
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
174
178
  return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
175
179
  }
176
180
  const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
177
181
  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 });
182
+ const signMessageRes = async function() {
183
+ try {
184
+ return await new Promise(
185
+ (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
186
+ if (err) {
187
+ reject(err);
188
+ }
189
+ resolve({ signature: result });
190
+ })
191
+ );
192
+ } catch (e) {
193
+ throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
194
+ }
195
+ }();
196
+ const { pendingTransactionId } = await preSignMessageRes;
195
197
  if (pendingTransactionId) {
196
198
  return { pendingTransactionId };
197
199
  }
200
+ return await signMessageRes;
201
+ }
202
+ async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
203
+ const protocolId = uuid.v4();
204
+ const signTransactionRes = ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
198
205
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
199
206
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
200
207
  }
201
208
  const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
202
209
  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) {
210
+ const signTxRes = async function() {
211
+ try {
212
+ return await new Promise(
213
+ (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
214
+ if (err) {
215
+ reject(err);
216
+ }
217
+ resolve({ signature: result });
218
+ })
219
+ );
220
+ } catch (e) {
221
+ throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
222
+ }
223
+ }();
217
224
  const {
218
- data: { protocolId, pendingTransactionId }
219
- } = await ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
225
+ data: { pendingTransactionId }
226
+ } = await signTransactionRes;
220
227
  if (pendingTransactionId) {
221
228
  return { pendingTransactionId };
222
229
  }
230
+ return await signTxRes;
231
+ }
232
+ async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
233
+ const protocolId = uuid.v4();
234
+ const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
223
235
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
224
236
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
225
237
  }
226
238
  const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
227
239
  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}`);
240
+ const sendTxRes = async function() {
241
+ try {
242
+ return await new Promise(
243
+ (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
244
+ if (err) {
245
+ reject(err);
246
+ }
247
+ resolve({ signature: result });
248
+ })
249
+ );
250
+ } catch (e) {
251
+ throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
252
+ }
253
+ }();
254
+ const {
255
+ data: { pendingTransactionId }
256
+ } = await sendTransactionRes;
257
+ if (pendingTransactionId) {
258
+ return { pendingTransactionId };
239
259
  }
260
+ return await sendTxRes;
240
261
  }
241
262
  async function refresh(ctx, share, walletId, userId) {
242
263
  const {
@@ -22,6 +22,7 @@ import axios from "axios";
22
22
  import { getPortalBaseURL, initClient, mpcComputationClient, paraVersion } from "@getpara/core-sdk";
23
23
  import * as walletUtils from "./walletUtils.js";
24
24
  let rawWasm;
25
+ let wasmLoaded = false;
25
26
  function requestWasmWithRetries(ctx, retries = 3) {
26
27
  return __async(this, null, function* () {
27
28
  for (let i = 0; i < retries; i++) {
@@ -58,15 +59,15 @@ function executeMessage(ctx, message) {
58
59
  }
59
60
  case "SIGN_TRANSACTION": {
60
61
  const { share, walletId, userId, tx, chainId } = params;
61
- return walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId);
62
+ return withRetry(() => walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId));
62
63
  }
63
64
  case "SEND_TRANSACTION": {
64
65
  const { share, walletId, userId, tx, chainId } = params;
65
- return walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId);
66
+ return withRetry(() => walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId));
66
67
  }
67
68
  case "SIGN_MESSAGE": {
68
69
  const { share, walletId, userId, message: message2 } = params;
69
- return walletUtils.signMessage(ctx, share, walletId, userId, message2);
70
+ return withRetry(() => walletUtils.signMessage(ctx, share, walletId, userId, message2));
70
71
  }
71
72
  case "REFRESH": {
72
73
  const { share, walletId, userId } = params;
@@ -111,6 +112,29 @@ function executeMessage(ctx, message) {
111
112
  }
112
113
  });
113
114
  }
115
+ function withRetry(operation, maxRetries = 2, timeoutMs = 1e4) {
116
+ return __async(this, null, function* () {
117
+ let retries = 0;
118
+ while (true) {
119
+ try {
120
+ const operationPromise = operation();
121
+ const timeoutPromise = new Promise((_, reject) => {
122
+ const timeoutId = setTimeout(() => {
123
+ reject(new Error(`Operation timed out after ${timeoutMs}ms`));
124
+ }, timeoutMs);
125
+ operationPromise.finally(() => clearTimeout(timeoutId));
126
+ });
127
+ return yield Promise.race([operationPromise, timeoutPromise]);
128
+ } catch (error) {
129
+ retries++;
130
+ if (retries > maxRetries) {
131
+ throw error;
132
+ }
133
+ console.warn(`Operation failed (attempt ${retries}/${maxRetries}), retrying...`, error);
134
+ }
135
+ }
136
+ });
137
+ }
114
138
  function handleMessage(e) {
115
139
  return __async(this, null, function* () {
116
140
  const {
@@ -134,8 +158,19 @@ function handleMessage(e) {
134
158
  disableWebSockets: !!disableWebSockets,
135
159
  cosmosPrefix
136
160
  };
137
- if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
161
+ if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
138
162
  yield loadWasm(ctx);
163
+ if (global.initWasm) {
164
+ yield new Promise(
165
+ (resolve, reject) => global.initWasm((err, result2) => {
166
+ if (err) {
167
+ reject(err);
168
+ }
169
+ resolve(result2);
170
+ })
171
+ );
172
+ }
173
+ wasmLoaded = true;
139
174
  }
140
175
  const result = yield executeMessage(ctx, e.data);
141
176
  result.workId = workId;
@@ -144,5 +179,6 @@ function handleMessage(e) {
144
179
  }
145
180
  export {
146
181
  handleMessage,
147
- requestWasmWithRetries
182
+ requestWasmWithRetries,
183
+ withRetry
148
184
  };
@@ -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": "2.0.0-alpha.18",
3
+ "version": "2.0.0-alpha.19",
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": "2.0.0-alpha.18",
13
- "@getpara/user-management-client": "2.0.0-alpha.18",
12
+ "@getpara/core-sdk": "2.0.0-alpha.19",
13
+ "@getpara/user-management-client": "2.0.0-alpha.19",
14
14
  "@sentry/node": "^9.1.0",
15
15
  "uuid": "^11.1.0",
16
16
  "ws": "^8.14.2"
@@ -31,5 +31,5 @@
31
31
  "dist",
32
32
  "package.json"
33
33
  ],
34
- "gitHead": "2333bc727fe61593821d448ee12facaee230c4b0"
34
+ "gitHead": "80d2c5d7e1203fb12378aa29bfd4d7003c7d7075"
35
35
  }