@getpara/server-sdk 1.15.1 → 1.16.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) {
|
|
@@ -233,81 +244,102 @@ function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type,
|
|
|
233
244
|
}
|
|
234
245
|
function signMessage(ctx, share, walletId, userId, message) {
|
|
235
246
|
return __async(this, null, function* () {
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
return { pendingTransactionId };
|
|
239
|
-
}
|
|
247
|
+
const protocolId = uuid.v4();
|
|
248
|
+
const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId);
|
|
240
249
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
241
250
|
return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
|
|
242
251
|
}
|
|
243
252
|
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
244
253
|
const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
|
|
245
|
-
|
|
246
|
-
return
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
reject(err)
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
const signMessageRes = function() {
|
|
255
|
+
return __async(this, null, function* () {
|
|
256
|
+
try {
|
|
257
|
+
return yield new Promise(
|
|
258
|
+
(resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
|
|
259
|
+
if (err) {
|
|
260
|
+
reject(err);
|
|
261
|
+
}
|
|
262
|
+
resolve({ signature: result });
|
|
263
|
+
})
|
|
264
|
+
);
|
|
265
|
+
} catch (e) {
|
|
266
|
+
throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}();
|
|
270
|
+
const { pendingTransactionId } = yield preSignMessageRes;
|
|
271
|
+
if (pendingTransactionId) {
|
|
272
|
+
return { pendingTransactionId };
|
|
256
273
|
}
|
|
274
|
+
return yield signMessageRes;
|
|
257
275
|
});
|
|
258
276
|
}
|
|
259
277
|
function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
260
278
|
return __async(this, null, function* () {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
} = yield ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
|
|
264
|
-
if (pendingTransactionId) {
|
|
265
|
-
return { pendingTransactionId };
|
|
266
|
-
}
|
|
279
|
+
const protocolId = uuid.v4();
|
|
280
|
+
const signTransactionRes = ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
|
|
267
281
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
268
282
|
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
269
283
|
}
|
|
270
284
|
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
271
285
|
const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
272
|
-
|
|
273
|
-
return
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
reject(err)
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
286
|
+
const signTxRes = function() {
|
|
287
|
+
return __async(this, null, function* () {
|
|
288
|
+
try {
|
|
289
|
+
return yield new Promise(
|
|
290
|
+
(resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
291
|
+
if (err) {
|
|
292
|
+
reject(err);
|
|
293
|
+
}
|
|
294
|
+
resolve({ signature: result });
|
|
295
|
+
})
|
|
296
|
+
);
|
|
297
|
+
} catch (e) {
|
|
298
|
+
throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}();
|
|
302
|
+
const {
|
|
303
|
+
data: { pendingTransactionId }
|
|
304
|
+
} = yield signTransactionRes;
|
|
305
|
+
if (pendingTransactionId) {
|
|
306
|
+
return { pendingTransactionId };
|
|
283
307
|
}
|
|
308
|
+
return yield signTxRes;
|
|
284
309
|
});
|
|
285
310
|
}
|
|
286
311
|
function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
287
312
|
return __async(this, null, function* () {
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
} = yield ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
|
|
291
|
-
if (pendingTransactionId) {
|
|
292
|
-
return { pendingTransactionId };
|
|
293
|
-
}
|
|
313
|
+
const protocolId = uuid.v4();
|
|
314
|
+
const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
|
|
294
315
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
295
316
|
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
296
317
|
}
|
|
297
318
|
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
298
319
|
const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
299
|
-
|
|
300
|
-
return
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
reject(err)
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
320
|
+
const sendTxRes = function() {
|
|
321
|
+
return __async(this, null, function* () {
|
|
322
|
+
try {
|
|
323
|
+
return yield new Promise(
|
|
324
|
+
(resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
325
|
+
if (err) {
|
|
326
|
+
reject(err);
|
|
327
|
+
}
|
|
328
|
+
resolve({ signature: result });
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
} catch (e) {
|
|
332
|
+
throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}();
|
|
336
|
+
const {
|
|
337
|
+
data: { pendingTransactionId }
|
|
338
|
+
} = yield sendTransactionRes;
|
|
339
|
+
if (pendingTransactionId) {
|
|
340
|
+
return { pendingTransactionId };
|
|
310
341
|
}
|
|
342
|
+
return yield sendTxRes;
|
|
311
343
|
});
|
|
312
344
|
}
|
|
313
345
|
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 = 8e3) {
|
|
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) {
|
|
@@ -166,77 +167,92 @@ async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType,
|
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
async function signMessage(ctx, share, walletId, userId, message) {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
return { pendingTransactionId };
|
|
172
|
-
}
|
|
170
|
+
const protocolId = uuid.v4();
|
|
171
|
+
const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId);
|
|
173
172
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
174
173
|
return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
|
|
175
174
|
}
|
|
176
175
|
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
177
176
|
const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const {
|
|
193
|
-
data: { protocolId, pendingTransactionId }
|
|
194
|
-
} = await ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
|
|
177
|
+
const signMessageRes = async function() {
|
|
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
|
+
const { pendingTransactionId } = await preSignMessageRes;
|
|
195
192
|
if (pendingTransactionId) {
|
|
196
193
|
return { pendingTransactionId };
|
|
197
194
|
}
|
|
195
|
+
return await signMessageRes;
|
|
196
|
+
}
|
|
197
|
+
async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
198
|
+
const protocolId = uuid.v4();
|
|
199
|
+
const signTransactionRes = ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
|
|
198
200
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
199
201
|
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
200
202
|
}
|
|
201
203
|
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
202
204
|
const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
205
|
+
const signTxRes = async function() {
|
|
206
|
+
try {
|
|
207
|
+
return await new Promise(
|
|
208
|
+
(resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
209
|
+
if (err) {
|
|
210
|
+
reject(err);
|
|
211
|
+
}
|
|
212
|
+
resolve({ signature: result });
|
|
213
|
+
})
|
|
214
|
+
);
|
|
215
|
+
} catch (e) {
|
|
216
|
+
throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
|
|
217
|
+
}
|
|
218
|
+
}();
|
|
217
219
|
const {
|
|
218
|
-
data: {
|
|
219
|
-
} = await
|
|
220
|
+
data: { pendingTransactionId }
|
|
221
|
+
} = await signTransactionRes;
|
|
220
222
|
if (pendingTransactionId) {
|
|
221
223
|
return { pendingTransactionId };
|
|
222
224
|
}
|
|
225
|
+
return await signTxRes;
|
|
226
|
+
}
|
|
227
|
+
async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
228
|
+
const protocolId = uuid.v4();
|
|
229
|
+
const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
|
|
223
230
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
224
231
|
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
225
232
|
}
|
|
226
233
|
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
227
234
|
const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
235
|
+
const sendTxRes = async function() {
|
|
236
|
+
try {
|
|
237
|
+
return await new Promise(
|
|
238
|
+
(resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
239
|
+
if (err) {
|
|
240
|
+
reject(err);
|
|
241
|
+
}
|
|
242
|
+
resolve({ signature: result });
|
|
243
|
+
})
|
|
244
|
+
);
|
|
245
|
+
} catch (e) {
|
|
246
|
+
throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
|
|
247
|
+
}
|
|
248
|
+
}();
|
|
249
|
+
const {
|
|
250
|
+
data: { pendingTransactionId }
|
|
251
|
+
} = await sendTransactionRes;
|
|
252
|
+
if (pendingTransactionId) {
|
|
253
|
+
return { pendingTransactionId };
|
|
239
254
|
}
|
|
255
|
+
return await sendTxRes;
|
|
240
256
|
}
|
|
241
257
|
async function refresh(ctx, share, walletId, userId) {
|
|
242
258
|
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 = 8e3) {
|
|
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: 8000)
|
|
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.
|
|
3
|
+
"version": "1.16.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.
|
|
13
|
-
"@getpara/user-management-client": "1.
|
|
12
|
+
"@getpara/core-sdk": "1.16.0",
|
|
13
|
+
"@getpara/user-management-client": "1.16.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": "
|
|
33
|
+
"gitHead": "27004dc519903d24ffafa0d8da16976dae9278a2"
|
|
34
34
|
}
|