@getpara/server-sdk 1.5.0 → 1.6.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/index.js CHANGED
@@ -26,6 +26,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var __async = (__this, __arguments, generator) => {
30
+ return new Promise((resolve, reject) => {
31
+ var fulfilled = (value) => {
32
+ try {
33
+ step(generator.next(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var rejected = (value) => {
39
+ try {
40
+ step(generator.throw(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
+ step((generator = generator.apply(__this, __arguments)).next());
47
+ });
48
+ };
29
49
 
30
50
  // src/index.ts
31
51
  var src_exports = {};
@@ -106,52 +126,60 @@ function removeWorkId(workId, skipClearTimeout) {
106
126
  }
107
127
  clearTimeout(timeoutId);
108
128
  }
109
- async function setupWorker(ctx, resFunction, workId) {
110
- const timeoutId = setTimeout(() => {
111
- removeWorkId(workId, true);
112
- }, CLEAR_WORKER_TIMEOUT_MS);
113
- resFunctionMap[workId] = {
114
- fn: resFunction,
115
- timeoutId
116
- };
117
- if (!worker || !worker.threadId) {
118
- const workerRes = await fetch(`${(0, import_core_sdk.getPortalBaseURL)(ctx)}/static/js/mpcWorkerServer-bundle.js`);
119
- worker = new import_worker_threads.Worker(await workerRes.text(), { eval: true });
120
- const onmessage = async (message) => {
121
- const { workId: messageWorkId } = message;
122
- delete message.workId;
123
- await resFunctionMap[messageWorkId].fn(message);
124
- removeWorkId(messageWorkId);
129
+ function setupWorker(ctx, resFunction, workId) {
130
+ return __async(this, null, function* () {
131
+ const timeoutId = setTimeout(() => {
132
+ removeWorkId(workId, true);
133
+ }, CLEAR_WORKER_TIMEOUT_MS);
134
+ resFunctionMap[workId] = {
135
+ fn: resFunction,
136
+ timeoutId
125
137
  };
126
- worker.on("message", onmessage);
127
- worker.on("error", (err) => {
128
- throw err;
129
- });
130
- worker.on("exit", (code) => {
131
- console.error(`worker stopped with exit code ${code}`);
132
- });
133
- }
134
- return worker;
138
+ if (!worker || !worker.threadId) {
139
+ const workerRes = yield fetch(`${(0, import_core_sdk.getPortalBaseURL)(ctx)}/static/js/mpcWorkerServer-bundle.js`);
140
+ worker = new import_worker_threads.Worker(yield workerRes.text(), { eval: true });
141
+ const onmessage = (message) => __async(this, null, function* () {
142
+ const { workId: messageWorkId } = message;
143
+ delete message.workId;
144
+ yield resFunctionMap[messageWorkId].fn(message);
145
+ removeWorkId(messageWorkId);
146
+ });
147
+ worker.on("message", onmessage);
148
+ worker.on("error", (err) => {
149
+ throw err;
150
+ });
151
+ worker.on("exit", (code) => {
152
+ console.error(`worker stopped with exit code ${code}`);
153
+ });
154
+ }
155
+ return worker;
156
+ });
135
157
  }
136
158
 
137
159
  // src/wallet/keygen.ts
138
- async function isKeygenComplete(ctx, userId, walletId) {
139
- const wallets = await ctx.client.getWallets(userId);
140
- const wallet = wallets.data.wallets.find((w) => w.id === walletId);
141
- return !!wallet.address;
160
+ function isKeygenComplete(ctx, userId, walletId) {
161
+ return __async(this, null, function* () {
162
+ const wallets = yield ctx.client.getWallets(userId);
163
+ const wallet = wallets.data.wallets.find((w) => w.id === walletId);
164
+ return !!wallet.address;
165
+ });
142
166
  }
143
- async function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
144
- const wallets = await ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
145
- const wallet = wallets.wallets.find((w) => w.id === walletId);
146
- return !!wallet?.address;
167
+ function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
168
+ return __async(this, null, function* () {
169
+ const wallets = yield ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
170
+ const wallet = wallets.wallets.find((w) => w.id === walletId);
171
+ return !!(wallet == null ? void 0 : wallet.address);
172
+ });
147
173
  }
148
174
  function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCookie, _emailProps = {}) {
149
- return new Promise(async (resolve) => {
175
+ return new Promise((resolve) => __async(this, null, function* () {
150
176
  const workId = uuid.v4();
151
- const worker2 = await setupWorker(
177
+ const worker2 = yield setupWorker(
152
178
  ctx,
153
- async (res) => {
154
- await (0, import_core_sdk2.waitUntilTrue)(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
179
+ (res) => __async(this, null, function* () {
180
+ yield (0, import_core_sdk2.waitUntilTrue)(() => __async(this, null, function* () {
181
+ return isKeygenComplete(ctx, userId, res.walletId);
182
+ }), 15e3, 1e3);
155
183
  if (skipDistribute) {
156
184
  resolve({
157
185
  signer: res.signer,
@@ -159,7 +187,7 @@ function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCoo
159
187
  recoveryShare: null
160
188
  });
161
189
  }
162
- },
190
+ }),
163
191
  workId
164
192
  );
165
193
  worker2.postMessage({
@@ -176,16 +204,18 @@ function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCoo
176
204
  wasmOverride: ctx.wasmOverride,
177
205
  workId
178
206
  });
179
- });
207
+ }));
180
208
  }
181
209
  function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
182
- return new Promise(async (resolve) => {
210
+ return new Promise((resolve) => __async(this, null, function* () {
183
211
  const workId = uuid.v4();
184
- const worker2 = await setupWorker(
212
+ const worker2 = yield setupWorker(
185
213
  ctx,
186
- async (res) => {
187
- await (0, import_core_sdk2.waitUntilTrue)(
188
- async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
214
+ (res) => __async(this, null, function* () {
215
+ yield (0, import_core_sdk2.waitUntilTrue)(
216
+ () => __async(this, null, function* () {
217
+ return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
218
+ }),
189
219
  15e3,
190
220
  1e3
191
221
  );
@@ -194,7 +224,7 @@ function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey,
194
224
  walletId: res.walletId,
195
225
  recoveryShare: null
196
226
  });
197
- },
227
+ }),
198
228
  workId
199
229
  );
200
230
  const email = void 0;
@@ -216,21 +246,23 @@ function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey,
216
246
  wasmOverride: ctx.wasmOverride,
217
247
  workId
218
248
  });
219
- });
249
+ }));
220
250
  }
221
251
  function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
222
- return new Promise(async (resolve) => {
252
+ return new Promise((resolve) => __async(this, null, function* () {
223
253
  const workId = uuid.v4();
224
- const worker2 = await setupWorker(
254
+ const worker2 = yield setupWorker(
225
255
  ctx,
226
- async (res) => {
227
- await (0, import_core_sdk2.waitUntilTrue)(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
256
+ (res) => __async(this, null, function* () {
257
+ yield (0, import_core_sdk2.waitUntilTrue)(() => __async(this, null, function* () {
258
+ return isKeygenComplete(ctx, userId, res.walletId);
259
+ }), 15e3, 1e3);
228
260
  resolve({
229
261
  signer: res.signer,
230
262
  walletId: res.walletId,
231
263
  recoveryShare: null
232
264
  });
233
- },
265
+ }),
234
266
  workId
235
267
  );
236
268
  worker2.postMessage({
@@ -245,16 +277,18 @@ function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
245
277
  wasmOverride: ctx.wasmOverride,
246
278
  workId
247
279
  });
248
- });
280
+ }));
249
281
  }
250
282
  function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
251
- return new Promise(async (resolve) => {
283
+ return new Promise((resolve) => __async(this, null, function* () {
252
284
  const workId = uuid.v4();
253
- const worker2 = await setupWorker(
285
+ const worker2 = yield setupWorker(
254
286
  ctx,
255
- async (res) => {
256
- await (0, import_core_sdk2.waitUntilTrue)(
257
- async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
287
+ (res) => __async(this, null, function* () {
288
+ yield (0, import_core_sdk2.waitUntilTrue)(
289
+ () => __async(this, null, function* () {
290
+ return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
291
+ }),
258
292
  15e3,
259
293
  1e3
260
294
  );
@@ -263,7 +297,7 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCo
263
297
  walletId: res.walletId,
264
298
  recoveryShare: null
265
299
  });
266
- },
300
+ }),
267
301
  workId
268
302
  );
269
303
  const email = void 0;
@@ -283,138 +317,148 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCo
283
317
  wasmOverride: ctx.wasmOverride,
284
318
  workId
285
319
  });
286
- });
320
+ }));
287
321
  }
288
322
 
289
323
  // src/wallet/signing.ts
290
324
  var uuid2 = __toESM(require("uuid"));
291
- async function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
292
- return await new Promise(async (resolve) => {
293
- const workId = uuid2.v4();
294
- const worker2 = await setupWorker(
295
- ctx,
296
- async (sendTransactionRes) => {
297
- resolve(sendTransactionRes);
298
- },
299
- workId
300
- );
301
- worker2.postMessage({
302
- env: ctx.env,
303
- apiKey: ctx.apiKey,
304
- cosmosPrefix: ctx.cosmosPrefix,
305
- params: { share, walletId, userId, tx, chainId },
306
- functionType: "SIGN_TRANSACTION",
307
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
308
- disableWorkers: ctx.disableWorkers,
309
- sessionCookie,
310
- useDKLS: isDKLS,
311
- disableWebSockets: ctx.disableWebSockets,
312
- wasmOverride: ctx.wasmOverride,
313
- workId
314
- });
325
+ function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
326
+ return __async(this, null, function* () {
327
+ return yield new Promise((resolve) => __async(this, null, function* () {
328
+ const workId = uuid2.v4();
329
+ const worker2 = yield setupWorker(
330
+ ctx,
331
+ (sendTransactionRes) => __async(this, null, function* () {
332
+ resolve(sendTransactionRes);
333
+ }),
334
+ workId
335
+ );
336
+ worker2.postMessage({
337
+ env: ctx.env,
338
+ apiKey: ctx.apiKey,
339
+ cosmosPrefix: ctx.cosmosPrefix,
340
+ params: { share, walletId, userId, tx, chainId },
341
+ functionType: "SIGN_TRANSACTION",
342
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
343
+ disableWorkers: ctx.disableWorkers,
344
+ sessionCookie,
345
+ useDKLS: isDKLS,
346
+ disableWebSockets: ctx.disableWebSockets,
347
+ wasmOverride: ctx.wasmOverride,
348
+ workId
349
+ });
350
+ }));
315
351
  });
316
352
  }
317
- async function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
318
- return await new Promise(async (resolve) => {
319
- const workId = uuid2.v4();
320
- const worker2 = await setupWorker(
321
- ctx,
322
- async (sendTransactionRes) => {
323
- resolve(sendTransactionRes);
324
- },
325
- workId
326
- );
327
- worker2.postMessage({
328
- env: ctx.env,
329
- apiKey: ctx.apiKey,
330
- params: { share, walletId, userId, tx, chainId },
331
- functionType: "SEND_TRANSACTION",
332
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
333
- disableWorkers: ctx.disableWorkers,
334
- sessionCookie,
335
- useDKLS: isDKLS,
336
- disableWebSockets: ctx.disableWebSockets,
337
- wasmOverride: ctx.wasmOverride,
338
- workId
339
- });
353
+ function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
354
+ return __async(this, null, function* () {
355
+ return yield new Promise((resolve) => __async(this, null, function* () {
356
+ const workId = uuid2.v4();
357
+ const worker2 = yield setupWorker(
358
+ ctx,
359
+ (sendTransactionRes) => __async(this, null, function* () {
360
+ resolve(sendTransactionRes);
361
+ }),
362
+ workId
363
+ );
364
+ worker2.postMessage({
365
+ env: ctx.env,
366
+ apiKey: ctx.apiKey,
367
+ params: { share, walletId, userId, tx, chainId },
368
+ functionType: "SEND_TRANSACTION",
369
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
370
+ disableWorkers: ctx.disableWorkers,
371
+ sessionCookie,
372
+ useDKLS: isDKLS,
373
+ disableWebSockets: ctx.disableWebSockets,
374
+ wasmOverride: ctx.wasmOverride,
375
+ workId
376
+ });
377
+ }));
340
378
  });
341
379
  }
342
- async function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS) {
343
- return await new Promise(async (resolve) => {
344
- const workId = uuid2.v4();
345
- const worker2 = await setupWorker(
346
- ctx,
347
- async (signMessageRes) => {
348
- resolve(signMessageRes);
349
- },
350
- workId
351
- );
352
- worker2.postMessage({
353
- env: ctx.env,
354
- apiKey: ctx.apiKey,
355
- params: { share, walletId, userId, message },
356
- functionType: "SIGN_MESSAGE",
357
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
358
- disableWorkers: ctx.disableWorkers,
359
- sessionCookie,
360
- useDKLS: isDKLS,
361
- disableWebSockets: ctx.disableWebSockets,
362
- wasmOverride: ctx.wasmOverride,
363
- workId
364
- });
380
+ function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS) {
381
+ return __async(this, null, function* () {
382
+ return yield new Promise((resolve) => __async(this, null, function* () {
383
+ const workId = uuid2.v4();
384
+ const worker2 = yield setupWorker(
385
+ ctx,
386
+ (signMessageRes) => __async(this, null, function* () {
387
+ resolve(signMessageRes);
388
+ }),
389
+ workId
390
+ );
391
+ worker2.postMessage({
392
+ env: ctx.env,
393
+ apiKey: ctx.apiKey,
394
+ params: { share, walletId, userId, message },
395
+ functionType: "SIGN_MESSAGE",
396
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
397
+ disableWorkers: ctx.disableWorkers,
398
+ sessionCookie,
399
+ useDKLS: isDKLS,
400
+ disableWebSockets: ctx.disableWebSockets,
401
+ wasmOverride: ctx.wasmOverride,
402
+ workId
403
+ });
404
+ }));
365
405
  });
366
406
  }
367
- async function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
368
- return await new Promise(async (resolve) => {
369
- const workId = uuid2.v4();
370
- const worker2 = await setupWorker(
371
- ctx,
372
- async (signMessageRes) => {
373
- resolve(signMessageRes);
374
- },
375
- workId
376
- );
377
- worker2.postMessage({
378
- env: ctx.env,
379
- apiKey: ctx.apiKey,
380
- params: { share, walletId, userId, base64Bytes },
381
- functionType: "ED25519_SIGN",
382
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
383
- disableWorkers: ctx.disableWorkers,
384
- sessionCookie,
385
- disableWebSockets: ctx.disableWebSockets,
386
- wasmOverride: ctx.wasmOverride,
387
- workId
388
- });
407
+ function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
408
+ return __async(this, null, function* () {
409
+ return yield new Promise((resolve) => __async(this, null, function* () {
410
+ const workId = uuid2.v4();
411
+ const worker2 = yield setupWorker(
412
+ ctx,
413
+ (signMessageRes) => __async(this, null, function* () {
414
+ resolve(signMessageRes);
415
+ }),
416
+ workId
417
+ );
418
+ worker2.postMessage({
419
+ env: ctx.env,
420
+ apiKey: ctx.apiKey,
421
+ params: { share, walletId, userId, base64Bytes },
422
+ functionType: "ED25519_SIGN",
423
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
424
+ disableWorkers: ctx.disableWorkers,
425
+ sessionCookie,
426
+ disableWebSockets: ctx.disableWebSockets,
427
+ wasmOverride: ctx.wasmOverride,
428
+ workId
429
+ });
430
+ }));
389
431
  });
390
432
  }
391
433
 
392
434
  // src/wallet/privateKey.ts
393
435
  var uuid3 = __toESM(require("uuid"));
394
- async function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
395
- return await new Promise(async (resolve) => {
396
- const workId = uuid3.v4();
397
- const worker2 = await setupWorker(
398
- ctx,
399
- async (res) => {
400
- resolve(res);
401
- },
402
- workId
403
- );
404
- worker2.postMessage({
405
- env: ctx.env,
406
- apiKey: ctx.apiKey,
407
- cosmosPrefix: ctx.cosmosPrefix,
408
- params: { share, walletId, userId },
409
- functionType: "GET_PRIVATE_KEY",
410
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
411
- disableWorkers: ctx.disableWorkers,
412
- sessionCookie,
413
- useDKLS: ctx.useDKLS,
414
- disableWebSockets: ctx.disableWebSockets,
415
- wasmOverride: ctx.wasmOverride,
416
- workId
417
- });
436
+ function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
437
+ return __async(this, null, function* () {
438
+ return yield new Promise((resolve) => __async(this, null, function* () {
439
+ const workId = uuid3.v4();
440
+ const worker2 = yield setupWorker(
441
+ ctx,
442
+ (res) => __async(this, null, function* () {
443
+ resolve(res);
444
+ }),
445
+ workId
446
+ );
447
+ worker2.postMessage({
448
+ env: ctx.env,
449
+ apiKey: ctx.apiKey,
450
+ cosmosPrefix: ctx.cosmosPrefix,
451
+ params: { share, walletId, userId },
452
+ functionType: "GET_PRIVATE_KEY",
453
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
454
+ disableWorkers: ctx.disableWorkers,
455
+ sessionCookie,
456
+ useDKLS: ctx.useDKLS,
457
+ disableWebSockets: ctx.disableWebSockets,
458
+ wasmOverride: ctx.wasmOverride,
459
+ workId
460
+ });
461
+ }));
418
462
  });
419
463
  }
420
464
 
@@ -490,10 +534,12 @@ var Para = class extends import_core_sdk3.default {
490
534
  * @param {TPregenIdentifierType} opts.pregenIdentifierType - the type of the identifier.
491
535
  * @returns {Promise<string | undefined>} A promise that rejects with an error.
492
536
  */
493
- async claimPregenWallets({} = {}) {
494
- throw new Error(
495
- "claimPregenWallets is not available in the server SDK. This function is only supported on the client side. Please ensure you are using the client SDK to call this method."
496
- );
537
+ claimPregenWallets() {
538
+ return __async(this, arguments, function* ({} = {}) {
539
+ throw new Error(
540
+ "claimPregenWallets is not available in the server SDK. This function is only supported on the client side. Please ensure you are using the client SDK to call this method."
541
+ );
542
+ });
497
543
  }
498
544
  };
499
545
 
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }