@getpara/server-sdk 3.21.0 → 3.23.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.
@@ -59,6 +59,12 @@ var import_signing = require("./wallet/signing.js");
59
59
  var import_privateKey = require("./wallet/privateKey.js");
60
60
  const keepAliveHttpAgent = new import_node_http.default.Agent({ keepAlive: true });
61
61
  const keepAliveHttpsAgent = new import_node_https.default.Agent({ keepAlive: true });
62
+ function signingContextTail(canonicalMessage, signingApproval) {
63
+ if (signingApproval) {
64
+ return [canonicalMessage, signingApproval];
65
+ }
66
+ return canonicalMessage ? [canonicalMessage] : [];
67
+ }
62
68
  class ServerUtils {
63
69
  constructor() {
64
70
  this.sdkType = "SERVER";
@@ -86,25 +92,23 @@ class ServerUtils {
86
92
  preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey, sessionCookie) {
87
93
  return (0, import_keygen.preKeygen)(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, false, partnerId, sessionCookie);
88
94
  }
89
- signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, _cosmosSignDoc, canonicalTransaction, approvalCaseId, canonicalMessage) {
90
- if (canonicalMessage) {
91
- return (0, import_signing.signMessage)(
92
- ctx,
93
- userId,
94
- walletId,
95
- share,
96
- message,
97
- sessionCookie,
98
- isDKLS,
99
- canonicalTransaction,
100
- approvalCaseId,
101
- canonicalMessage
102
- );
103
- }
104
- return (0, import_signing.signMessage)(ctx, userId, walletId, share, message, sessionCookie, isDKLS, canonicalTransaction, approvalCaseId);
105
- }
106
- signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS) {
107
- return (0, import_signing.signTransaction)(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS);
95
+ signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, _cosmosSignDoc, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
96
+ return (0, import_signing.signMessage)(
97
+ ctx,
98
+ userId,
99
+ walletId,
100
+ share,
101
+ message,
102
+ sessionCookie,
103
+ isDKLS,
104
+ canonicalTransaction,
105
+ approvalCaseId,
106
+ ...signingContextTail(canonicalMessage, signingApproval)
107
+ );
108
+ }
109
+ signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS, signingApproval) {
110
+ const signingApprovalTail = signingApproval ? [signingApproval] : [];
111
+ return (0, import_signing.signTransaction)(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS, ...signingApprovalTail);
108
112
  }
109
113
  sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
110
114
  return (0, import_signing.sendTransaction)(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS);
@@ -118,21 +122,18 @@ class ServerUtils {
118
122
  ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie, type) {
119
123
  return (0, import_keygen.ed25519PreKeygen)(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie, type);
120
124
  }
121
- ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie, canonicalTransaction, approvalCaseId, canonicalMessage) {
122
- if (canonicalMessage) {
123
- return (0, import_signing.ed25519Sign)(
124
- ctx,
125
- userId,
126
- walletId,
127
- share,
128
- base64Bytes,
129
- sessionCookie,
130
- canonicalTransaction,
131
- approvalCaseId,
132
- canonicalMessage
133
- );
134
- }
135
- return (0, import_signing.ed25519Sign)(ctx, userId, walletId, share, base64Bytes, sessionCookie, canonicalTransaction, approvalCaseId);
125
+ ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
126
+ return (0, import_signing.ed25519Sign)(
127
+ ctx,
128
+ userId,
129
+ walletId,
130
+ share,
131
+ base64Bytes,
132
+ sessionCookie,
133
+ canonicalTransaction,
134
+ approvalCaseId,
135
+ ...signingContextTail(canonicalMessage, signingApproval)
136
+ );
136
137
  }
137
138
  openPopup(_popupUrl) {
138
139
  return __async(this, null, function* () {
@@ -69,7 +69,7 @@ __export(signing_exports, {
69
69
  module.exports = __toCommonJS(signing_exports);
70
70
  var uuid = __toESM(require("uuid"));
71
71
  var import_workerWrapper = require("../workers/workerWrapper.js");
72
- function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
72
+ function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS, signingApproval) {
73
73
  return __async(this, null, function* () {
74
74
  return new Promise((resolve, reject) => __async(null, null, function* () {
75
75
  const workId = uuid.v4();
@@ -94,7 +94,7 @@ function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCooki
94
94
  env: ctx.env,
95
95
  apiKey: ctx.apiKey,
96
96
  cosmosPrefix: ctx.cosmosPrefix,
97
- params: { share, walletId, userId, tx, chainId },
97
+ params: __spreadValues({ share, walletId, userId, tx, chainId }, signingApproval ? { signingApproval } : {}),
98
98
  functionType: "SIGN_TRANSACTION",
99
99
  offloadMPCComputationURL: ctx.offloadMPCComputationURL,
100
100
  disableWorkers: ctx.disableWorkers,
@@ -150,7 +150,7 @@ function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCooki
150
150
  }));
151
151
  });
152
152
  }
153
- function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, canonicalTransaction, approvalCaseId, canonicalMessage) {
153
+ function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
154
154
  return __async(this, null, function* () {
155
155
  return new Promise((resolve, reject) => __async(null, null, function* () {
156
156
  const workId = uuid.v4();
@@ -174,13 +174,13 @@ function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKL
174
174
  worker.postMessage({
175
175
  env: ctx.env,
176
176
  apiKey: ctx.apiKey,
177
- params: __spreadValues(__spreadValues({
177
+ params: __spreadValues(__spreadValues(__spreadValues({
178
178
  share,
179
179
  walletId,
180
180
  userId,
181
181
  message,
182
182
  canonicalTransaction
183
- }, approvalCaseId ? { approvalCaseId } : {}), canonicalMessage ? { canonicalMessage } : {}),
183
+ }, approvalCaseId ? { approvalCaseId } : {}), canonicalMessage ? { canonicalMessage } : {}), signingApproval ? { signingApproval } : {}),
184
184
  functionType: "SIGN_MESSAGE",
185
185
  offloadMPCComputationURL: ctx.offloadMPCComputationURL,
186
186
  disableWorkers: ctx.disableWorkers,
@@ -196,7 +196,7 @@ function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKL
196
196
  }));
197
197
  });
198
198
  }
199
- function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie, canonicalTransaction, approvalCaseId, canonicalMessage) {
199
+ function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
200
200
  return __async(this, null, function* () {
201
201
  return new Promise((resolve, reject) => __async(null, null, function* () {
202
202
  const workId = uuid.v4();
@@ -220,13 +220,13 @@ function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie, c
220
220
  worker.postMessage({
221
221
  env: ctx.env,
222
222
  apiKey: ctx.apiKey,
223
- params: __spreadValues(__spreadValues({
223
+ params: __spreadValues(__spreadValues(__spreadValues({
224
224
  share,
225
225
  walletId,
226
226
  userId,
227
227
  base64Bytes,
228
228
  canonicalTransaction
229
- }, approvalCaseId ? { approvalCaseId } : {}), canonicalMessage ? { canonicalMessage } : {}),
229
+ }, approvalCaseId ? { approvalCaseId } : {}), canonicalMessage ? { canonicalMessage } : {}), signingApproval ? { signingApproval } : {}),
230
230
  functionType: "ED25519_SIGN",
231
231
  offloadMPCComputationURL: ctx.offloadMPCComputationURL,
232
232
  disableWorkers: ctx.disableWorkers,
@@ -79,6 +79,15 @@ var uuid = __toESM(require("uuid"));
79
79
  var import_mpcWorkerError = require("./mpcWorkerError.js");
80
80
  const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
81
81
  const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
82
+ function reviewContextTailOf(approvalCaseId, canonicalMessage, signingApproval) {
83
+ if (signingApproval) {
84
+ return [approvalCaseId, canonicalMessage, signingApproval];
85
+ }
86
+ if (canonicalMessage) {
87
+ return [approvalCaseId, canonicalMessage];
88
+ }
89
+ return approvalCaseId ? [approvalCaseId] : [];
90
+ }
82
91
  function keygenRequest(ctx, userId, walletId, protocolId) {
83
92
  return __async(this, null, function* () {
84
93
  const { data } = yield ctx.mpcComputationClient.post("/wallets", {
@@ -173,22 +182,11 @@ function withMPCNetworkHost(ctx, share) {
173
182
  return share;
174
183
  }
175
184
  }
176
- function ed25519Sign(ctx, share, userId, walletId, base64Bytes, canonicalTransaction, approvalCaseId, canonicalMessage) {
185
+ function ed25519Sign(ctx, share, userId, walletId, base64Bytes, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
177
186
  return __async(this, null, function* () {
178
187
  const protocolId = uuid.v4();
179
188
  const hostedShare = withMPCNetworkHost(ctx, share);
180
- const preSignMessageRes = canonicalMessage ? ctx.client.preSignMessage(
181
- userId,
182
- walletId,
183
- base64Bytes,
184
- "ED25519",
185
- void 0,
186
- protocolId,
187
- void 0,
188
- canonicalTransaction,
189
- approvalCaseId,
190
- canonicalMessage
191
- ) : approvalCaseId ? ctx.client.preSignMessage(
189
+ const preSignMessageRes = ctx.client.preSignMessage(
192
190
  userId,
193
191
  walletId,
194
192
  base64Bytes,
@@ -197,16 +195,7 @@ function ed25519Sign(ctx, share, userId, walletId, base64Bytes, canonicalTransac
197
195
  protocolId,
198
196
  void 0,
199
197
  canonicalTransaction,
200
- approvalCaseId
201
- ) : ctx.client.preSignMessage(
202
- userId,
203
- walletId,
204
- base64Bytes,
205
- "ED25519",
206
- void 0,
207
- protocolId,
208
- void 0,
209
- canonicalTransaction
198
+ ...reviewContextTailOf(approvalCaseId, canonicalMessage, signingApproval)
210
199
  );
211
200
  const signRes = (function() {
212
201
  return __async(this, null, function* () {
@@ -321,21 +310,10 @@ function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type,
321
310
  }
322
311
  });
323
312
  }
324
- function signMessage(ctx, share, walletId, userId, message, canonicalTransaction, approvalCaseId, canonicalMessage) {
313
+ function signMessage(ctx, share, walletId, userId, message, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
325
314
  return __async(this, null, function* () {
326
315
  const protocolId = uuid.v4();
327
- const preSignMessageRes = canonicalMessage ? ctx.client.preSignMessage(
328
- userId,
329
- walletId,
330
- message,
331
- null,
332
- null,
333
- protocolId,
334
- true,
335
- canonicalTransaction,
336
- approvalCaseId,
337
- canonicalMessage
338
- ) : approvalCaseId ? ctx.client.preSignMessage(
316
+ const preSignMessageRes = ctx.client.preSignMessage(
339
317
  userId,
340
318
  walletId,
341
319
  message,
@@ -344,8 +322,8 @@ function signMessage(ctx, share, walletId, userId, message, canonicalTransaction
344
322
  protocolId,
345
323
  true,
346
324
  canonicalTransaction,
347
- approvalCaseId
348
- ) : ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId, true, canonicalTransaction);
325
+ ...reviewContextTailOf(approvalCaseId, canonicalMessage, signingApproval)
326
+ );
349
327
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
350
328
  return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
351
329
  }
@@ -376,15 +354,15 @@ function signMessage(ctx, share, walletId, userId, message, canonicalTransaction
376
354
  return yield signMessageRes;
377
355
  });
378
356
  }
379
- function signTransaction(ctx, share, walletId, userId, tx, chainId) {
357
+ function signTransaction(ctx, share, walletId, userId, tx, chainId, signingApproval) {
380
358
  return __async(this, null, function* () {
381
359
  const protocolId = uuid.v4();
382
- const signTransactionRes = ctx.client.signTransaction(userId, walletId, {
360
+ const signTransactionRes = ctx.client.signTransaction(userId, walletId, __spreadValues({
383
361
  transaction: tx,
384
362
  chainId,
385
363
  protocolId,
386
364
  useNewOT: true
387
- });
365
+ }, signingApproval));
388
366
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
389
367
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
390
368
  }
@@ -61,8 +61,12 @@ var __async = (__this, __arguments, generator) => {
61
61
  };
62
62
  var worker_exports = {};
63
63
  __export(worker_exports, {
64
+ WORKER_ERROR_OPT_IN_KEY: () => import_workerError2.WORKER_ERROR_OPT_IN_KEY,
65
+ WORKER_ERROR_RESPONSE_KEY: () => import_workerError2.WORKER_ERROR_RESPONSE_KEY,
64
66
  handleMessage: () => handleMessage,
65
67
  requestWasmWithRetries: () => requestWasmWithRetries,
68
+ respondToWorkerMessage: () => import_workerError2.respondToWorkerMessage,
69
+ serializeWorkerError: () => import_workerError2.serializeWorkerError,
66
70
  withRetry: () => withRetry
67
71
  });
68
72
  module.exports = __toCommonJS(worker_exports);
@@ -70,16 +74,12 @@ var import_axios = __toESM(require("axios"));
70
74
  var import_core_sdk = require("@getpara/core-sdk");
71
75
  var walletUtils = __toESM(require("./walletUtils.js"));
72
76
  var import_mpcWorkerError = require("./mpcWorkerError.js");
77
+ var import_workerError = require("./workerError.js");
78
+ var import_workerError2 = require("./workerError.js");
73
79
  let rawWasm;
74
80
  let wasmLoaded = false;
75
- function getSerializableError(error) {
76
- if (error && typeof error === "object") {
77
- return error;
78
- }
79
- return void 0;
80
- }
81
81
  function isRetryableError(error) {
82
- const errorFields = getSerializableError(error);
82
+ const errorFields = (0, import_workerError.getSerializableError)(error);
83
83
  if (!errorFields) {
84
84
  return true;
85
85
  }
@@ -129,30 +129,29 @@ function executeMessage(ctx, message) {
129
129
  return walletUtils.keygen(ctx, userId, type, secretKey);
130
130
  }
131
131
  case "SIGN_TRANSACTION": {
132
- const { share, walletId, userId, tx, chainId } = params;
133
- return withRetry(() => walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId));
132
+ const { share, walletId, userId, tx, chainId, signingApproval } = params;
133
+ const signingApprovalTail = signingApproval ? [signingApproval] : [];
134
+ return withRetry(() => walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId, ...signingApprovalTail));
134
135
  }
135
136
  case "SEND_TRANSACTION": {
136
137
  const { share, walletId, userId, tx, chainId } = params;
137
138
  return withRetry(() => walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId));
138
139
  }
139
140
  case "SIGN_MESSAGE": {
140
- const { share, walletId, userId, message: message2, canonicalTransaction, approvalCaseId, canonicalMessage } = params;
141
- return withRetry(() => {
142
- if (canonicalMessage) {
143
- return walletUtils.signMessage(
144
- ctx,
145
- share,
146
- walletId,
147
- userId,
148
- message2,
149
- canonicalTransaction,
150
- approvalCaseId,
151
- canonicalMessage
152
- );
153
- }
154
- return walletUtils.signMessage(ctx, share, walletId, userId, message2, canonicalTransaction, approvalCaseId);
155
- });
141
+ const { share, walletId, userId, message: message2, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval } = params;
142
+ const signingContextTail = signingApproval ? [canonicalMessage, signingApproval] : canonicalMessage ? [canonicalMessage] : [];
143
+ return withRetry(
144
+ () => walletUtils.signMessage(
145
+ ctx,
146
+ share,
147
+ walletId,
148
+ userId,
149
+ message2,
150
+ canonicalTransaction,
151
+ approvalCaseId,
152
+ ...signingContextTail
153
+ )
154
+ );
156
155
  }
157
156
  case "REFRESH": {
158
157
  const { share, walletId, userId } = params;
@@ -184,20 +183,27 @@ function executeMessage(ctx, message) {
184
183
  return walletUtils.ed25519Keygen(ctx, userId, void 0, void 0, type);
185
184
  }
186
185
  case "ED25519_SIGN": {
187
- const { share, walletId, userId, base64Bytes, canonicalTransaction, approvalCaseId, canonicalMessage } = params;
188
- if (canonicalMessage) {
189
- return walletUtils.ed25519Sign(
190
- ctx,
191
- share,
192
- userId,
193
- walletId,
194
- base64Bytes,
195
- canonicalTransaction,
196
- approvalCaseId,
197
- canonicalMessage
198
- );
199
- }
200
- return walletUtils.ed25519Sign(ctx, share, userId, walletId, base64Bytes, canonicalTransaction, approvalCaseId);
186
+ const {
187
+ share,
188
+ walletId,
189
+ userId,
190
+ base64Bytes,
191
+ canonicalTransaction,
192
+ approvalCaseId,
193
+ canonicalMessage,
194
+ signingApproval
195
+ } = params;
196
+ const signingContextTail = signingApproval ? [canonicalMessage, signingApproval] : canonicalMessage ? [canonicalMessage] : [];
197
+ return walletUtils.ed25519Sign(
198
+ ctx,
199
+ share,
200
+ userId,
201
+ walletId,
202
+ base64Bytes,
203
+ canonicalTransaction,
204
+ approvalCaseId,
205
+ ...signingContextTail
206
+ );
201
207
  }
202
208
  case "ED25519_PREKEYGEN": {
203
209
  const { email } = params;
@@ -329,7 +335,11 @@ function handleMessage(e) {
329
335
  }
330
336
  // Annotate the CommonJS export names for ESM import in node:
331
337
  0 && (module.exports = {
338
+ WORKER_ERROR_OPT_IN_KEY,
339
+ WORKER_ERROR_RESPONSE_KEY,
332
340
  handleMessage,
333
341
  requestWasmWithRetries,
342
+ respondToWorkerMessage,
343
+ serializeWorkerError,
334
344
  withRetry
335
345
  });
@@ -0,0 +1,121 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __objRest = (source, exclude) => {
20
+ var target = {};
21
+ for (var prop in source)
22
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
23
+ target[prop] = source[prop];
24
+ if (source != null && __getOwnPropSymbols)
25
+ for (var prop of __getOwnPropSymbols(source)) {
26
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
27
+ target[prop] = source[prop];
28
+ }
29
+ return target;
30
+ };
31
+ var __export = (target, all) => {
32
+ for (var name in all)
33
+ __defProp(target, name, { get: all[name], enumerable: true });
34
+ };
35
+ var __copyProps = (to, from, except, desc) => {
36
+ if (from && typeof from === "object" || typeof from === "function") {
37
+ for (let key of __getOwnPropNames(from))
38
+ if (!__hasOwnProp.call(to, key) && key !== except)
39
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
40
+ }
41
+ return to;
42
+ };
43
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
44
+ var __async = (__this, __arguments, generator) => {
45
+ return new Promise((resolve, reject) => {
46
+ var fulfilled = (value) => {
47
+ try {
48
+ step(generator.next(value));
49
+ } catch (e) {
50
+ reject(e);
51
+ }
52
+ };
53
+ var rejected = (value) => {
54
+ try {
55
+ step(generator.throw(value));
56
+ } catch (e) {
57
+ reject(e);
58
+ }
59
+ };
60
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
61
+ step((generator = generator.apply(__this, __arguments)).next());
62
+ });
63
+ };
64
+ var workerError_exports = {};
65
+ __export(workerError_exports, {
66
+ WORKER_ERROR_OPT_IN_KEY: () => WORKER_ERROR_OPT_IN_KEY,
67
+ WORKER_ERROR_RESPONSE_KEY: () => WORKER_ERROR_RESPONSE_KEY,
68
+ deserializeWorkerError: () => deserializeWorkerError,
69
+ getSerializableError: () => getSerializableError,
70
+ respondToWorkerMessage: () => respondToWorkerMessage,
71
+ serializeWorkerError: () => serializeWorkerError
72
+ });
73
+ module.exports = __toCommonJS(workerError_exports);
74
+ const WORKER_ERROR_RESPONSE_KEY = "__paraWorkerError";
75
+ const WORKER_ERROR_OPT_IN_KEY = "__paraAcceptsWorkerError";
76
+ function getSerializableError(error) {
77
+ if (error && typeof error === "object") {
78
+ return error;
79
+ }
80
+ return void 0;
81
+ }
82
+ function serializeWorkerError(error) {
83
+ const errorFields = getSerializableError(error);
84
+ if (!errorFields) {
85
+ return {
86
+ message: typeof error === "string" && error ? error : "Worker operation failed",
87
+ name: "Error"
88
+ };
89
+ }
90
+ return __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
91
+ message: typeof errorFields.message === "string" && errorFields.message ? errorFields.message : "Worker operation failed",
92
+ name: typeof errorFields.name === "string" && errorFields.name ? errorFields.name : "Error"
93
+ }, typeof errorFields.code === "string" && { code: errorFields.code }), typeof errorFields.status === "number" && { status: errorFields.status }), typeof errorFields.responseURL === "string" && { responseURL: errorFields.responseURL }), typeof errorFields.data === "object" && errorFields.data !== null && { data: errorFields.data }), typeof errorFields.isParaApiError === "boolean" && { isParaApiError: errorFields.isParaApiError });
94
+ }
95
+ function deserializeWorkerError(_a) {
96
+ var _b = _a, { message, name } = _b, details = __objRest(_b, ["message", "name"]);
97
+ const error = Object.assign(new Error(message), details);
98
+ error.name = name;
99
+ return error;
100
+ }
101
+ function respondToWorkerMessage(_0, _1) {
102
+ return __async(this, arguments, function* (message, { handle, postMessage, acceptsWorkerErrors }) {
103
+ try {
104
+ postMessage(yield handle(message));
105
+ } catch (error) {
106
+ if (!acceptsWorkerErrors || !message.workId) {
107
+ throw error;
108
+ }
109
+ postMessage({ workId: message.workId, [WORKER_ERROR_RESPONSE_KEY]: serializeWorkerError(error) });
110
+ }
111
+ });
112
+ }
113
+ // Annotate the CommonJS export names for ESM import in node:
114
+ 0 && (module.exports = {
115
+ WORKER_ERROR_OPT_IN_KEY,
116
+ WORKER_ERROR_RESPONSE_KEY,
117
+ deserializeWorkerError,
118
+ getSerializableError,
119
+ respondToWorkerMessage,
120
+ serializeWorkerError
121
+ });
@@ -57,6 +57,7 @@ __export(workerWrapper_exports, {
57
57
  module.exports = __toCommonJS(workerWrapper_exports);
58
58
  var import_worker_threads = require("worker_threads");
59
59
  var import_core_sdk = require("@getpara/core-sdk");
60
+ var import_workerError = require("./workerError.js");
60
61
  const CLEAR_WORKER_TIMEOUT_MS = 1e3 * 90;
61
62
  let worker;
62
63
  const resFunctionMap = {};
@@ -97,7 +98,7 @@ function setupWorker(ctx, resFunction, errorFunction, workId, errorContext) {
97
98
  const isDeno = typeof (globalThis == null ? void 0 : globalThis.Deno) !== "undefined";
98
99
  const workerFileName = isDeno ? "mpcWorkerServer-esm.js" : "mpcWorkerServer-bundle.js";
99
100
  const workerRes = yield fetch(`${(0, import_core_sdk.getPortalBaseURL)(ctx)}/static/js/${workerFileName}`);
100
- worker = new import_worker_threads.Worker(yield workerRes.text(), { eval: true });
101
+ worker = new import_worker_threads.Worker(yield workerRes.text(), { eval: true, workerData: { [import_workerError.WORKER_ERROR_OPT_IN_KEY]: true } });
101
102
  const onmessage = (message) => __async(null, null, function* () {
102
103
  const { workId: messageWorkId } = message;
103
104
  if (!resFunctionMap[messageWorkId]) {
@@ -105,6 +106,12 @@ function setupWorker(ctx, resFunction, errorFunction, workId, errorContext) {
105
106
  return;
106
107
  }
107
108
  delete message.workId;
109
+ const workerError = message[import_workerError.WORKER_ERROR_RESPONSE_KEY];
110
+ if (workerError) {
111
+ resFunctionMap[messageWorkId].errorFn((0, import_workerError.deserializeWorkerError)(workerError));
112
+ removeWorkId(messageWorkId);
113
+ return;
114
+ }
108
115
  try {
109
116
  yield resFunctionMap[messageWorkId].fn(message);
110
117
  removeWorkId(messageWorkId);
@@ -8,6 +8,12 @@ import { signMessage, sendTransaction, signTransaction, ed25519Sign } from "./wa
8
8
  import { getPrivateKey, getED25519PrivateKey } from "./wallet/privateKey.js";
9
9
  const keepAliveHttpAgent = new http.Agent({ keepAlive: true });
10
10
  const keepAliveHttpsAgent = new https.Agent({ keepAlive: true });
11
+ function signingContextTail(canonicalMessage, signingApproval) {
12
+ if (signingApproval) {
13
+ return [canonicalMessage, signingApproval];
14
+ }
15
+ return canonicalMessage ? [canonicalMessage] : [];
16
+ }
11
17
  class ServerUtils {
12
18
  constructor() {
13
19
  this.sdkType = "SERVER";
@@ -35,25 +41,23 @@ class ServerUtils {
35
41
  preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey, sessionCookie) {
36
42
  return preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, false, partnerId, sessionCookie);
37
43
  }
38
- signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, _cosmosSignDoc, canonicalTransaction, approvalCaseId, canonicalMessage) {
39
- if (canonicalMessage) {
40
- return signMessage(
41
- ctx,
42
- userId,
43
- walletId,
44
- share,
45
- message,
46
- sessionCookie,
47
- isDKLS,
48
- canonicalTransaction,
49
- approvalCaseId,
50
- canonicalMessage
51
- );
52
- }
53
- return signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, canonicalTransaction, approvalCaseId);
54
- }
55
- signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS) {
56
- return signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS);
44
+ signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, _cosmosSignDoc, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
45
+ return signMessage(
46
+ ctx,
47
+ userId,
48
+ walletId,
49
+ share,
50
+ message,
51
+ sessionCookie,
52
+ isDKLS,
53
+ canonicalTransaction,
54
+ approvalCaseId,
55
+ ...signingContextTail(canonicalMessage, signingApproval)
56
+ );
57
+ }
58
+ signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS, signingApproval) {
59
+ const signingApprovalTail = signingApproval ? [signingApproval] : [];
60
+ return signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS, ...signingApprovalTail);
57
61
  }
58
62
  sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
59
63
  return sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS);
@@ -67,21 +71,18 @@ class ServerUtils {
67
71
  ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie, type) {
68
72
  return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie, type);
69
73
  }
70
- ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie, canonicalTransaction, approvalCaseId, canonicalMessage) {
71
- if (canonicalMessage) {
72
- return ed25519Sign(
73
- ctx,
74
- userId,
75
- walletId,
76
- share,
77
- base64Bytes,
78
- sessionCookie,
79
- canonicalTransaction,
80
- approvalCaseId,
81
- canonicalMessage
82
- );
83
- }
84
- return ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie, canonicalTransaction, approvalCaseId);
74
+ ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
75
+ return ed25519Sign(
76
+ ctx,
77
+ userId,
78
+ walletId,
79
+ share,
80
+ base64Bytes,
81
+ sessionCookie,
82
+ canonicalTransaction,
83
+ approvalCaseId,
84
+ ...signingContextTail(canonicalMessage, signingApproval)
85
+ );
85
86
  }
86
87
  async openPopup(_popupUrl) {
87
88
  throw new Error("OpenPopup is not implemented in the ServerUtils class.");
@@ -1,7 +1,7 @@
1
1
  import "../chunk-GM7WFPGG.js";
2
2
  import * as uuid from "uuid";
3
3
  import { setupWorker } from "../workers/workerWrapper.js";
4
- async function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
4
+ async function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS, signingApproval) {
5
5
  return new Promise(async (resolve, reject) => {
6
6
  const workId = uuid.v4();
7
7
  try {
@@ -25,7 +25,7 @@ async function signTransaction(ctx, userId, walletId, share, tx, chainId, sessio
25
25
  env: ctx.env,
26
26
  apiKey: ctx.apiKey,
27
27
  cosmosPrefix: ctx.cosmosPrefix,
28
- params: { share, walletId, userId, tx, chainId },
28
+ params: { share, walletId, userId, tx, chainId, ...signingApproval ? { signingApproval } : {} },
29
29
  functionType: "SIGN_TRANSACTION",
30
30
  offloadMPCComputationURL: ctx.offloadMPCComputationURL,
31
31
  disableWorkers: ctx.disableWorkers,
@@ -78,7 +78,7 @@ async function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessio
78
78
  }
79
79
  });
80
80
  }
81
- async function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, canonicalTransaction, approvalCaseId, canonicalMessage) {
81
+ async function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
82
82
  return new Promise(async (resolve, reject) => {
83
83
  const workId = uuid.v4();
84
84
  try {
@@ -108,7 +108,8 @@ async function signMessage(ctx, userId, walletId, share, message, sessionCookie,
108
108
  message,
109
109
  canonicalTransaction,
110
110
  ...approvalCaseId ? { approvalCaseId } : {},
111
- ...canonicalMessage ? { canonicalMessage } : {}
111
+ ...canonicalMessage ? { canonicalMessage } : {},
112
+ ...signingApproval ? { signingApproval } : {}
112
113
  },
113
114
  functionType: "SIGN_MESSAGE",
114
115
  offloadMPCComputationURL: ctx.offloadMPCComputationURL,
@@ -124,7 +125,7 @@ async function signMessage(ctx, userId, walletId, share, message, sessionCookie,
124
125
  }
125
126
  });
126
127
  }
127
- async function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie, canonicalTransaction, approvalCaseId, canonicalMessage) {
128
+ async function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
128
129
  return new Promise(async (resolve, reject) => {
129
130
  const workId = uuid.v4();
130
131
  try {
@@ -154,7 +155,8 @@ async function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCoo
154
155
  base64Bytes,
155
156
  canonicalTransaction,
156
157
  ...approvalCaseId ? { approvalCaseId } : {},
157
- ...canonicalMessage ? { canonicalMessage } : {}
158
+ ...canonicalMessage ? { canonicalMessage } : {},
159
+ ...signingApproval ? { signingApproval } : {}
158
160
  },
159
161
  functionType: "ED25519_SIGN",
160
162
  offloadMPCComputationURL: ctx.offloadMPCComputationURL,
@@ -6,6 +6,15 @@ import * as uuid from "uuid";
6
6
  import { wrapMpcError } from "./mpcWorkerError.js";
7
7
  const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
8
8
  const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
9
+ function reviewContextTailOf(approvalCaseId, canonicalMessage, signingApproval) {
10
+ if (signingApproval) {
11
+ return [approvalCaseId, canonicalMessage, signingApproval];
12
+ }
13
+ if (canonicalMessage) {
14
+ return [approvalCaseId, canonicalMessage];
15
+ }
16
+ return approvalCaseId ? [approvalCaseId] : [];
17
+ }
9
18
  async function keygenRequest(ctx, userId, walletId, protocolId) {
10
19
  const { data } = await ctx.mpcComputationClient.post("/wallets", {
11
20
  userId,
@@ -90,21 +99,10 @@ function withMPCNetworkHost(ctx, share) {
90
99
  return share;
91
100
  }
92
101
  }
93
- async function ed25519Sign(ctx, share, userId, walletId, base64Bytes, canonicalTransaction, approvalCaseId, canonicalMessage) {
102
+ async function ed25519Sign(ctx, share, userId, walletId, base64Bytes, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
94
103
  const protocolId = uuid.v4();
95
104
  const hostedShare = withMPCNetworkHost(ctx, share);
96
- const preSignMessageRes = canonicalMessage ? ctx.client.preSignMessage(
97
- userId,
98
- walletId,
99
- base64Bytes,
100
- "ED25519",
101
- void 0,
102
- protocolId,
103
- void 0,
104
- canonicalTransaction,
105
- approvalCaseId,
106
- canonicalMessage
107
- ) : approvalCaseId ? ctx.client.preSignMessage(
105
+ const preSignMessageRes = ctx.client.preSignMessage(
108
106
  userId,
109
107
  walletId,
110
108
  base64Bytes,
@@ -113,16 +111,7 @@ async function ed25519Sign(ctx, share, userId, walletId, base64Bytes, canonicalT
113
111
  protocolId,
114
112
  void 0,
115
113
  canonicalTransaction,
116
- approvalCaseId
117
- ) : ctx.client.preSignMessage(
118
- userId,
119
- walletId,
120
- base64Bytes,
121
- "ED25519",
122
- void 0,
123
- protocolId,
124
- void 0,
125
- canonicalTransaction
114
+ ...reviewContextTailOf(approvalCaseId, canonicalMessage, signingApproval)
126
115
  );
127
116
  const signRes = (async function() {
128
117
  try {
@@ -230,20 +219,9 @@ async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType,
230
219
  throw wrapMpcError(`error creating account of type ${type} with walletId ${walletId}`, mpcErr, { walletId, protocolId });
231
220
  }
232
221
  }
233
- async function signMessage(ctx, share, walletId, userId, message, canonicalTransaction, approvalCaseId, canonicalMessage) {
222
+ async function signMessage(ctx, share, walletId, userId, message, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval) {
234
223
  const protocolId = uuid.v4();
235
- const preSignMessageRes = canonicalMessage ? ctx.client.preSignMessage(
236
- userId,
237
- walletId,
238
- message,
239
- null,
240
- null,
241
- protocolId,
242
- true,
243
- canonicalTransaction,
244
- approvalCaseId,
245
- canonicalMessage
246
- ) : approvalCaseId ? ctx.client.preSignMessage(
224
+ const preSignMessageRes = ctx.client.preSignMessage(
247
225
  userId,
248
226
  walletId,
249
227
  message,
@@ -252,8 +230,8 @@ async function signMessage(ctx, share, walletId, userId, message, canonicalTrans
252
230
  protocolId,
253
231
  true,
254
232
  canonicalTransaction,
255
- approvalCaseId
256
- ) : ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId, true, canonicalTransaction);
233
+ ...reviewContextTailOf(approvalCaseId, canonicalMessage, signingApproval)
234
+ );
257
235
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
258
236
  return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
259
237
  }
@@ -281,13 +259,14 @@ async function signMessage(ctx, share, walletId, userId, message, canonicalTrans
281
259
  }
282
260
  return await signMessageRes;
283
261
  }
284
- async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
262
+ async function signTransaction(ctx, share, walletId, userId, tx, chainId, signingApproval) {
285
263
  const protocolId = uuid.v4();
286
264
  const signTransactionRes = ctx.client.signTransaction(userId, walletId, {
287
265
  transaction: tx,
288
266
  chainId,
289
267
  protocolId,
290
- useNewOT: true
268
+ useNewOT: true,
269
+ ...signingApproval
291
270
  });
292
271
  if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
293
272
  return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
@@ -44,14 +44,15 @@ import {
44
44
  } from "@getpara/core-sdk";
45
45
  import * as walletUtils from "./walletUtils.js";
46
46
  import { classifyMpcError, unwrapMpcError } from "./mpcWorkerError.js";
47
+ import { getSerializableError } from "./workerError.js";
48
+ import {
49
+ WORKER_ERROR_OPT_IN_KEY,
50
+ WORKER_ERROR_RESPONSE_KEY,
51
+ respondToWorkerMessage,
52
+ serializeWorkerError
53
+ } from "./workerError.js";
47
54
  let rawWasm;
48
55
  let wasmLoaded = false;
49
- function getSerializableError(error) {
50
- if (error && typeof error === "object") {
51
- return error;
52
- }
53
- return void 0;
54
- }
55
56
  function isRetryableError(error) {
56
57
  const errorFields = getSerializableError(error);
57
58
  if (!errorFields) {
@@ -103,30 +104,29 @@ function executeMessage(ctx, message) {
103
104
  return walletUtils.keygen(ctx, userId, type, secretKey);
104
105
  }
105
106
  case "SIGN_TRANSACTION": {
106
- const { share, walletId, userId, tx, chainId } = params;
107
- return withRetry(() => walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId));
107
+ const { share, walletId, userId, tx, chainId, signingApproval } = params;
108
+ const signingApprovalTail = signingApproval ? [signingApproval] : [];
109
+ return withRetry(() => walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId, ...signingApprovalTail));
108
110
  }
109
111
  case "SEND_TRANSACTION": {
110
112
  const { share, walletId, userId, tx, chainId } = params;
111
113
  return withRetry(() => walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId));
112
114
  }
113
115
  case "SIGN_MESSAGE": {
114
- const { share, walletId, userId, message: message2, canonicalTransaction, approvalCaseId, canonicalMessage } = params;
115
- return withRetry(() => {
116
- if (canonicalMessage) {
117
- return walletUtils.signMessage(
118
- ctx,
119
- share,
120
- walletId,
121
- userId,
122
- message2,
123
- canonicalTransaction,
124
- approvalCaseId,
125
- canonicalMessage
126
- );
127
- }
128
- return walletUtils.signMessage(ctx, share, walletId, userId, message2, canonicalTransaction, approvalCaseId);
129
- });
116
+ const { share, walletId, userId, message: message2, canonicalTransaction, approvalCaseId, canonicalMessage, signingApproval } = params;
117
+ const signingContextTail = signingApproval ? [canonicalMessage, signingApproval] : canonicalMessage ? [canonicalMessage] : [];
118
+ return withRetry(
119
+ () => walletUtils.signMessage(
120
+ ctx,
121
+ share,
122
+ walletId,
123
+ userId,
124
+ message2,
125
+ canonicalTransaction,
126
+ approvalCaseId,
127
+ ...signingContextTail
128
+ )
129
+ );
130
130
  }
131
131
  case "REFRESH": {
132
132
  const { share, walletId, userId } = params;
@@ -158,20 +158,27 @@ function executeMessage(ctx, message) {
158
158
  return walletUtils.ed25519Keygen(ctx, userId, void 0, void 0, type);
159
159
  }
160
160
  case "ED25519_SIGN": {
161
- const { share, walletId, userId, base64Bytes, canonicalTransaction, approvalCaseId, canonicalMessage } = params;
162
- if (canonicalMessage) {
163
- return walletUtils.ed25519Sign(
164
- ctx,
165
- share,
166
- userId,
167
- walletId,
168
- base64Bytes,
169
- canonicalTransaction,
170
- approvalCaseId,
171
- canonicalMessage
172
- );
173
- }
174
- return walletUtils.ed25519Sign(ctx, share, userId, walletId, base64Bytes, canonicalTransaction, approvalCaseId);
161
+ const {
162
+ share,
163
+ walletId,
164
+ userId,
165
+ base64Bytes,
166
+ canonicalTransaction,
167
+ approvalCaseId,
168
+ canonicalMessage,
169
+ signingApproval
170
+ } = params;
171
+ const signingContextTail = signingApproval ? [canonicalMessage, signingApproval] : canonicalMessage ? [canonicalMessage] : [];
172
+ return walletUtils.ed25519Sign(
173
+ ctx,
174
+ share,
175
+ userId,
176
+ walletId,
177
+ base64Bytes,
178
+ canonicalTransaction,
179
+ approvalCaseId,
180
+ ...signingContextTail
181
+ );
175
182
  }
176
183
  case "ED25519_PREKEYGEN": {
177
184
  const { email } = params;
@@ -302,7 +309,11 @@ function handleMessage(e) {
302
309
  });
303
310
  }
304
311
  export {
312
+ WORKER_ERROR_OPT_IN_KEY,
313
+ WORKER_ERROR_RESPONSE_KEY,
305
314
  handleMessage,
306
315
  requestWasmWithRetries,
316
+ respondToWorkerMessage,
317
+ serializeWorkerError,
307
318
  withRetry
308
319
  };
@@ -0,0 +1,50 @@
1
+ import "../chunk-GM7WFPGG.js";
2
+ const WORKER_ERROR_RESPONSE_KEY = "__paraWorkerError";
3
+ const WORKER_ERROR_OPT_IN_KEY = "__paraAcceptsWorkerError";
4
+ function getSerializableError(error) {
5
+ if (error && typeof error === "object") {
6
+ return error;
7
+ }
8
+ return void 0;
9
+ }
10
+ function serializeWorkerError(error) {
11
+ const errorFields = getSerializableError(error);
12
+ if (!errorFields) {
13
+ return {
14
+ message: typeof error === "string" && error ? error : "Worker operation failed",
15
+ name: "Error"
16
+ };
17
+ }
18
+ return {
19
+ message: typeof errorFields.message === "string" && errorFields.message ? errorFields.message : "Worker operation failed",
20
+ name: typeof errorFields.name === "string" && errorFields.name ? errorFields.name : "Error",
21
+ ...typeof errorFields.code === "string" && { code: errorFields.code },
22
+ ...typeof errorFields.status === "number" && { status: errorFields.status },
23
+ ...typeof errorFields.responseURL === "string" && { responseURL: errorFields.responseURL },
24
+ ...typeof errorFields.data === "object" && errorFields.data !== null && { data: errorFields.data },
25
+ ...typeof errorFields.isParaApiError === "boolean" && { isParaApiError: errorFields.isParaApiError }
26
+ };
27
+ }
28
+ function deserializeWorkerError({ message, name, ...details }) {
29
+ const error = Object.assign(new Error(message), details);
30
+ error.name = name;
31
+ return error;
32
+ }
33
+ async function respondToWorkerMessage(message, { handle, postMessage, acceptsWorkerErrors }) {
34
+ try {
35
+ postMessage(await handle(message));
36
+ } catch (error) {
37
+ if (!acceptsWorkerErrors || !message.workId) {
38
+ throw error;
39
+ }
40
+ postMessage({ workId: message.workId, [WORKER_ERROR_RESPONSE_KEY]: serializeWorkerError(error) });
41
+ }
42
+ }
43
+ export {
44
+ WORKER_ERROR_OPT_IN_KEY,
45
+ WORKER_ERROR_RESPONSE_KEY,
46
+ deserializeWorkerError,
47
+ getSerializableError,
48
+ respondToWorkerMessage,
49
+ serializeWorkerError
50
+ };
@@ -1,6 +1,11 @@
1
1
  import "../chunk-GM7WFPGG.js";
2
2
  import { Worker } from "worker_threads";
3
3
  import { getPortalBaseURL } from "@getpara/core-sdk";
4
+ import {
5
+ deserializeWorkerError,
6
+ WORKER_ERROR_OPT_IN_KEY,
7
+ WORKER_ERROR_RESPONSE_KEY
8
+ } from "./workerError.js";
4
9
  const CLEAR_WORKER_TIMEOUT_MS = 1e3 * 90;
5
10
  let worker;
6
11
  const resFunctionMap = {};
@@ -44,7 +49,7 @@ async function setupWorker(ctx, resFunction, errorFunction, workId, errorContext
44
49
  const isDeno = typeof globalThis?.Deno !== "undefined";
45
50
  const workerFileName = isDeno ? "mpcWorkerServer-esm.js" : "mpcWorkerServer-bundle.js";
46
51
  const workerRes = await fetch(`${getPortalBaseURL(ctx)}/static/js/${workerFileName}`);
47
- worker = new Worker(await workerRes.text(), { eval: true });
52
+ worker = new Worker(await workerRes.text(), { eval: true, workerData: { [WORKER_ERROR_OPT_IN_KEY]: true } });
48
53
  const onmessage = async (message) => {
49
54
  const { workId: messageWorkId } = message;
50
55
  if (!resFunctionMap[messageWorkId]) {
@@ -52,6 +57,12 @@ async function setupWorker(ctx, resFunction, errorFunction, workId, errorContext
52
57
  return;
53
58
  }
54
59
  delete message.workId;
60
+ const workerError = message[WORKER_ERROR_RESPONSE_KEY];
61
+ if (workerError) {
62
+ resFunctionMap[messageWorkId].errorFn(deserializeWorkerError(workerError));
63
+ removeWorkId(messageWorkId);
64
+ return;
65
+ }
55
66
  try {
56
67
  await resFunctionMap[messageWorkId].fn(message);
57
68
  removeWorkId(messageWorkId);
@@ -1,6 +1,6 @@
1
1
  import http from 'node:http';
2
2
  import https from 'node:https';
3
- import type { Ctx, SignatureRes, PlatformUtils, TPregenIdentifierType, TWalletType, CanonicalMessageContext, CanonicalTransactionContext } from '@getpara/core-sdk';
3
+ import type { Ctx, SignatureRes, PlatformUtils, TPregenIdentifierType, TWalletType, CanonicalMessageContext, CanonicalTransactionContext, SigningApprovalContext } from '@getpara/core-sdk';
4
4
  import { BackupKitEmailProps, SDKType } from '@getpara/user-management-client';
5
5
  import { ServerLocalStorage } from './ServerLocalStorage.js';
6
6
  import { ServerSessionStorage } from './ServerSessionStorage.js';
@@ -24,8 +24,8 @@ export declare class ServerUtils implements PlatformUtils {
24
24
  signer: string;
25
25
  walletId: string;
26
26
  }>;
27
- signMessage(ctx: Ctx, userId: string, walletId: string, share: string, message: string, sessionCookie: string, isDKLS?: boolean, _cosmosSignDoc?: string, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext): Promise<SignatureRes>;
28
- signTransaction(ctx: Ctx, userId: string, walletId: string, share: string, message: string, chainId: string, sessionCookie: string, isDKLS?: boolean): Promise<SignatureRes>;
27
+ signMessage(ctx: Ctx, userId: string, walletId: string, share: string, message: string, sessionCookie: string, isDKLS?: boolean, _cosmosSignDoc?: string, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext, signingApproval?: SigningApprovalContext): Promise<SignatureRes>;
28
+ signTransaction(ctx: Ctx, userId: string, walletId: string, share: string, message: string, chainId: string, sessionCookie: string, isDKLS?: boolean, signingApproval?: SigningApprovalContext): Promise<SignatureRes>;
29
29
  sendTransaction(ctx: Ctx, userId: string, walletId: string, share: string, tx: string, chainId: string, sessionCookie: string, isDKLS?: boolean): Promise<SignatureRes>;
30
30
  signHash(_address: string, _hash: string): Promise<{
31
31
  v: number;
@@ -40,7 +40,7 @@ export declare class ServerUtils implements PlatformUtils {
40
40
  signer: string;
41
41
  walletId: string;
42
42
  }>;
43
- ed25519Sign(ctx: Ctx, userId: string, walletId: string, share: string, base64Bytes: string, sessionCookie: string, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext): Promise<SignatureRes>;
43
+ ed25519Sign(ctx: Ctx, userId: string, walletId: string, share: string, base64Bytes: string, sessionCookie: string, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext, signingApproval?: SigningApprovalContext): Promise<SignatureRes>;
44
44
  localStorage: ServerLocalStorage;
45
45
  sessionStorage: ServerSessionStorage;
46
46
  secureStorage: any;
@@ -1,5 +1,5 @@
1
- import type { CanonicalMessageContext, CanonicalTransactionContext, Ctx, SignatureRes } from '@getpara/core-sdk';
2
- export declare function signTransaction(ctx: Ctx, userId: string, walletId: string, share: string, tx: string, chainId: string, sessionCookie?: string, isDKLS?: boolean): Promise<SignatureRes>;
1
+ import type { CanonicalMessageContext, CanonicalTransactionContext, Ctx, SignatureRes, SigningApprovalContext } from '@getpara/core-sdk';
2
+ export declare function signTransaction(ctx: Ctx, userId: string, walletId: string, share: string, tx: string, chainId: string, sessionCookie?: string, isDKLS?: boolean, signingApproval?: SigningApprovalContext): Promise<SignatureRes>;
3
3
  export declare function sendTransaction(ctx: Ctx, userId: string, walletId: string, share: string, tx: string, chainId: string, sessionCookie?: string, isDKLS?: boolean): Promise<SignatureRes>;
4
- export declare function signMessage(ctx: Ctx, userId: string, walletId: string, share: string, message: string, sessionCookie?: string, isDKLS?: boolean, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext): Promise<SignatureRes>;
5
- export declare function ed25519Sign(ctx: Ctx, userId: string, walletId: string, share: string, base64Bytes: string, sessionCookie?: string, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext): Promise<SignatureRes>;
4
+ export declare function signMessage(ctx: Ctx, userId: string, walletId: string, share: string, message: string, sessionCookie?: string, isDKLS?: boolean, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext, signingApproval?: SigningApprovalContext): Promise<SignatureRes>;
5
+ export declare function ed25519Sign(ctx: Ctx, userId: string, walletId: string, share: string, base64Bytes: string, sessionCookie?: string, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext, signingApproval?: SigningApprovalContext): Promise<SignatureRes>;
@@ -1,4 +1,4 @@
1
- import { Ctx, TPregenIdentifierType, SignatureRes, TWalletType, type CanonicalMessageContext, type CanonicalTransactionContext } from '@getpara/core-sdk';
1
+ import { Ctx, TPregenIdentifierType, SignatureRes, TWalletType, type CanonicalMessageContext, type CanonicalTransactionContext, type SigningApprovalContext } from '@getpara/core-sdk';
2
2
  export declare function ed25519Keygen(ctx: Ctx, userId: string, _sessionCookie?: string, _emailProps?: unknown, type?: TWalletType): Promise<{
3
3
  signer: string;
4
4
  walletId: string;
@@ -7,7 +7,7 @@ export declare function ed25519PreKeygen(ctx: Ctx, pregenIdentifier: string, pre
7
7
  signer: string;
8
8
  walletId: string;
9
9
  }>;
10
- export declare function ed25519Sign(ctx: Ctx, share: string, userId: string, walletId: string, base64Bytes: string, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext): Promise<SignatureRes>;
10
+ export declare function ed25519Sign(ctx: Ctx, share: string, userId: string, walletId: string, base64Bytes: string, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext, signingApproval?: SigningApprovalContext): Promise<SignatureRes>;
11
11
  export declare function keygen(ctx: Ctx, userId: string, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null): Promise<{
12
12
  signer: string;
13
13
  walletId: string;
@@ -16,8 +16,8 @@ export declare function preKeygen(ctx: Ctx, partnerId: string, pregenIdentifier:
16
16
  signer: string;
17
17
  walletId: string;
18
18
  }>;
19
- export declare function signMessage(ctx: Ctx, share: string, walletId: string, userId: string, message: string, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext): Promise<SignatureRes>;
20
- export declare function signTransaction(ctx: Ctx, share: string, walletId: string, userId: string, tx: string, chainId: string): Promise<SignatureRes>;
19
+ export declare function signMessage(ctx: Ctx, share: string, walletId: string, userId: string, message: string, canonicalTransaction?: CanonicalTransactionContext, approvalCaseId?: string, canonicalMessage?: CanonicalMessageContext, signingApproval?: SigningApprovalContext): Promise<SignatureRes>;
20
+ export declare function signTransaction(ctx: Ctx, share: string, walletId: string, userId: string, tx: string, chainId: string, signingApproval?: SigningApprovalContext): Promise<SignatureRes>;
21
21
  export declare function sendTransaction(ctx: Ctx, share: string, walletId: string, userId: string, tx: string, chainId: string): Promise<SignatureRes>;
22
22
  export declare function refresh(ctx: Ctx, share: string, walletId: string, userId: string): Promise<string>;
23
23
  export declare function getPrivateKey(ctx: Ctx, share: string, walletId: string, userId: string): Promise<string>;
@@ -1,4 +1,5 @@
1
1
  import { Ctx, Environment } from '@getpara/core-sdk';
2
+ export { WORKER_ERROR_OPT_IN_KEY, WORKER_ERROR_RESPONSE_KEY, respondToWorkerMessage, serializeWorkerError, type SerializedWorkerError, } from './workerError.js';
2
3
  interface Message {
3
4
  env: Environment;
4
5
  apiKey: string;
@@ -27,4 +28,3 @@ export declare function withRetry<T>(operation: () => Promise<T>, maxRetries?: n
27
28
  export declare function handleMessage(e: {
28
29
  data: Message;
29
30
  }): Promise<any>;
30
- export {};
@@ -0,0 +1,25 @@
1
+ export declare const WORKER_ERROR_RESPONSE_KEY = "__paraWorkerError";
2
+ export declare const WORKER_ERROR_OPT_IN_KEY = "__paraAcceptsWorkerError";
3
+ export interface SerializedWorkerError {
4
+ message: string;
5
+ name: string;
6
+ code?: string;
7
+ status?: number;
8
+ responseURL?: string;
9
+ data?: object;
10
+ isParaApiError?: boolean;
11
+ }
12
+ export type WorkerTransportError = Error & Omit<SerializedWorkerError, 'message' | 'name'>;
13
+ type SerializableError = Partial<Error> & Omit<SerializedWorkerError, 'message' | 'name'>;
14
+ export declare function getSerializableError(error: object | string | null | undefined): SerializableError | undefined;
15
+ export declare function serializeWorkerError(error: object | string | null | undefined): SerializedWorkerError;
16
+ export declare function deserializeWorkerError({ message, name, ...details }: SerializedWorkerError): WorkerTransportError;
17
+ export interface WorkerResponder<TMessage> {
18
+ handle: (message: TMessage) => Promise<object>;
19
+ postMessage: (response: object) => void;
20
+ acceptsWorkerErrors: boolean;
21
+ }
22
+ export declare function respondToWorkerMessage<TMessage extends {
23
+ workId?: string;
24
+ }>(message: TMessage, { handle, postMessage, acceptsWorkerErrors }: WorkerResponder<TMessage>): Promise<void>;
25
+ export {};
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@getpara/server-sdk",
3
- "version": "3.21.0",
3
+ "version": "3.23.0",
4
4
  "dependencies": {
5
- "@getpara/core-sdk": "3.21.0",
6
- "@getpara/user-management-client": "3.21.0",
7
- "@getpara/viem-v2-integration": "3.21.0",
5
+ "@getpara/core-sdk": "3.23.0",
6
+ "@getpara/user-management-client": "3.23.0",
7
+ "@getpara/viem-v2-integration": "3.23.0",
8
8
  "axios": "^1.8.4",
9
9
  "uuid": "^11.1.1",
10
10
  "viem": "^2.39.0",
@@ -18,7 +18,7 @@
18
18
  "dist",
19
19
  "package.json"
20
20
  ],
21
- "gitHead": "e1ca81fb06f6337aaa7cc1860584b7ba5d1d9ca8",
21
+ "gitHead": "37cd5748560ed99b161d6b9e3c061173ca9c8bb3",
22
22
  "main": "dist/cjs/index.js",
23
23
  "module": "dist/esm/index.js",
24
24
  "scripts": {