@getpara/server-sdk 3.1.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/workers/mpcWorkerError.js +61 -0
- package/dist/cjs/workers/walletUtils.js +48 -22
- package/dist/cjs/workers/worker.js +68 -18
- package/dist/esm/workers/mpcWorkerError.js +36 -0
- package/dist/esm/workers/walletUtils.js +48 -22
- package/dist/esm/workers/worker.js +70 -18
- package/dist/types/workers/mpcWorkerError.d.ts +14 -0
- package/package.json +5 -5
|
@@ -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 (
|
|
118
|
-
throw
|
|
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 (
|
|
142
|
-
throw
|
|
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 (
|
|
163
|
-
throw
|
|
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 (
|
|
211
|
-
throw
|
|
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,8 +259,8 @@ function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type,
|
|
|
248
259
|
)
|
|
249
260
|
);
|
|
250
261
|
return { signer: newSigner, walletId };
|
|
251
|
-
} catch (
|
|
252
|
-
throw
|
|
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
|
}
|
|
@@ -273,11 +284,13 @@ function signMessage(ctx, share, walletId, userId, message) {
|
|
|
273
284
|
resolve({ signature: result });
|
|
274
285
|
})
|
|
275
286
|
);
|
|
276
|
-
} catch (
|
|
277
|
-
throw
|
|
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 };
|
|
@@ -310,11 +323,15 @@ function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
310
323
|
resolve({ signature: result });
|
|
311
324
|
})
|
|
312
325
|
);
|
|
313
|
-
} catch (
|
|
314
|
-
throw
|
|
326
|
+
} catch (mpcErr) {
|
|
327
|
+
throw (0, import_mpcWorkerError.wrapMpcError)(`error signing transaction for account with userId ${userId} and walletId ${walletId}`, mpcErr, {
|
|
328
|
+
protocolId
|
|
329
|
+
});
|
|
315
330
|
}
|
|
316
331
|
});
|
|
317
332
|
}();
|
|
333
|
+
signTxRes.catch(() => {
|
|
334
|
+
});
|
|
318
335
|
const {
|
|
319
336
|
data: { pendingTransactionId }
|
|
320
337
|
} = yield signTransactionRes;
|
|
@@ -349,11 +366,17 @@ function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
349
366
|
resolve({ signature: result });
|
|
350
367
|
})
|
|
351
368
|
);
|
|
352
|
-
} catch (
|
|
353
|
-
throw
|
|
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
|
+
);
|
|
354
375
|
}
|
|
355
376
|
});
|
|
356
377
|
}();
|
|
378
|
+
sendTxRes.catch(() => {
|
|
379
|
+
});
|
|
357
380
|
const {
|
|
358
381
|
data: { pendingTransactionId }
|
|
359
382
|
} = yield sendTransactionRes;
|
|
@@ -379,8 +402,8 @@ function refresh(ctx, share, walletId, userId) {
|
|
|
379
402
|
resolve(result);
|
|
380
403
|
})
|
|
381
404
|
);
|
|
382
|
-
} catch (
|
|
383
|
-
throw
|
|
405
|
+
} catch (mpcErr) {
|
|
406
|
+
throw (0, import_mpcWorkerError.wrapMpcError)(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`, mpcErr);
|
|
384
407
|
}
|
|
385
408
|
});
|
|
386
409
|
}
|
|
@@ -400,8 +423,8 @@ function getPrivateKey(ctx, share, walletId, userId) {
|
|
|
400
423
|
resolve(result);
|
|
401
424
|
})
|
|
402
425
|
);
|
|
403
|
-
} catch (
|
|
404
|
-
throw
|
|
426
|
+
} catch (mpcErr) {
|
|
427
|
+
throw (0, import_mpcWorkerError.wrapMpcError)(`error getting private key for account with userId ${userId} and walletId ${walletId}`, mpcErr);
|
|
405
428
|
}
|
|
406
429
|
});
|
|
407
430
|
}
|
|
@@ -421,8 +444,11 @@ function getED25519PrivateKey(ctx, share, walletId, userId) {
|
|
|
421
444
|
resolve(result);
|
|
422
445
|
})
|
|
423
446
|
);
|
|
424
|
-
} catch (
|
|
425
|
-
throw
|
|
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
|
+
);
|
|
426
452
|
}
|
|
427
453
|
});
|
|
428
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,8 +181,8 @@ async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType,
|
|
|
170
181
|
)
|
|
171
182
|
);
|
|
172
183
|
return { signer: newSigner, walletId };
|
|
173
|
-
} catch {
|
|
174
|
-
throw
|
|
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) {
|
|
@@ -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
|
|
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 };
|
|
@@ -225,10 +238,14 @@ async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
225
238
|
resolve({ signature: result });
|
|
226
239
|
})
|
|
227
240
|
);
|
|
228
|
-
} catch {
|
|
229
|
-
throw
|
|
241
|
+
} catch (mpcErr) {
|
|
242
|
+
throw wrapMpcError(`error signing transaction for account with userId ${userId} and walletId ${walletId}`, mpcErr, {
|
|
243
|
+
protocolId
|
|
244
|
+
});
|
|
230
245
|
}
|
|
231
246
|
}();
|
|
247
|
+
signTxRes.catch(() => {
|
|
248
|
+
});
|
|
232
249
|
const {
|
|
233
250
|
data: { pendingTransactionId }
|
|
234
251
|
} = await signTransactionRes;
|
|
@@ -260,10 +277,16 @@ async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
260
277
|
resolve({ signature: result });
|
|
261
278
|
})
|
|
262
279
|
);
|
|
263
|
-
} catch {
|
|
264
|
-
throw
|
|
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
|
+
);
|
|
265
286
|
}
|
|
266
287
|
}();
|
|
288
|
+
sendTxRes.catch(() => {
|
|
289
|
+
});
|
|
267
290
|
const {
|
|
268
291
|
data: { pendingTransactionId }
|
|
269
292
|
} = await sendTransactionRes;
|
|
@@ -287,8 +310,8 @@ async function refresh(ctx, share, walletId, userId) {
|
|
|
287
310
|
resolve(result);
|
|
288
311
|
})
|
|
289
312
|
);
|
|
290
|
-
} catch {
|
|
291
|
-
throw
|
|
313
|
+
} catch (mpcErr) {
|
|
314
|
+
throw wrapMpcError(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`, mpcErr);
|
|
292
315
|
}
|
|
293
316
|
}
|
|
294
317
|
async function getPrivateKey(ctx, share, walletId, userId) {
|
|
@@ -306,8 +329,8 @@ async function getPrivateKey(ctx, share, walletId, userId) {
|
|
|
306
329
|
resolve(result);
|
|
307
330
|
})
|
|
308
331
|
);
|
|
309
|
-
} catch {
|
|
310
|
-
throw
|
|
332
|
+
} catch (mpcErr) {
|
|
333
|
+
throw wrapMpcError(`error getting private key for account with userId ${userId} and walletId ${walletId}`, mpcErr);
|
|
311
334
|
}
|
|
312
335
|
}
|
|
313
336
|
async function getED25519PrivateKey(ctx, share, walletId, userId) {
|
|
@@ -325,8 +348,11 @@ async function getED25519PrivateKey(ctx, share, walletId, userId) {
|
|
|
325
348
|
resolve(result);
|
|
326
349
|
})
|
|
327
350
|
);
|
|
328
|
-
} catch {
|
|
329
|
-
throw
|
|
351
|
+
} catch (mpcErr) {
|
|
352
|
+
throw wrapMpcError(
|
|
353
|
+
`error getting ed25519 private key for account with userId ${userId} and walletId ${walletId}`,
|
|
354
|
+
mpcErr
|
|
355
|
+
);
|
|
330
356
|
}
|
|
331
357
|
}
|
|
332
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@getpara/core-sdk": "3.
|
|
6
|
-
"@getpara/user-management-client": "3.
|
|
7
|
-
"@getpara/viem-v2-integration": "3.
|
|
5
|
+
"@getpara/core-sdk": "3.3.0",
|
|
6
|
+
"@getpara/user-management-client": "3.3.0",
|
|
7
|
+
"@getpara/viem-v2-integration": "3.3.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": "
|
|
19
|
+
"gitHead": "d9b54921d4187e2dd25f314b62ed99988e9b5b1c",
|
|
20
20
|
"main": "dist/cjs/index.js",
|
|
21
21
|
"module": "dist/esm/index.js",
|
|
22
22
|
"scripts": {
|