@getpara/server-sdk 2.0.0-dev.1 → 2.0.0-dev.2

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.
Files changed (47) hide show
  1. package/dist/cjs/ParaServer.js +101 -0
  2. package/dist/cjs/ServerLocalStorage.js +48 -0
  3. package/dist/cjs/ServerSessionStorage.js +48 -0
  4. package/dist/cjs/ServerUtils.js +77 -0
  5. package/dist/cjs/index.js +3 -523
  6. package/dist/cjs/package.json +3 -0
  7. package/dist/cjs/wallet/keygen.js +315 -0
  8. package/dist/cjs/wallet/privateKey.js +99 -0
  9. package/dist/cjs/wallet/signing.js +224 -0
  10. package/dist/cjs/wasm/wasm_exec.js +589 -0
  11. package/dist/cjs/workers/walletUtils.js +409 -0
  12. package/dist/cjs/workers/worker.js +62 -907
  13. package/dist/cjs/workers/workerWrapper.js +130 -0
  14. package/dist/esm/ParaServer.js +45 -0
  15. package/dist/esm/ServerLocalStorage.js +26 -0
  16. package/dist/esm/ServerSessionStorage.js +26 -0
  17. package/dist/esm/ServerUtils.js +55 -0
  18. package/dist/esm/chunk-FTA5RKYX.js +8 -0
  19. package/dist/esm/index.js +4 -466
  20. package/dist/esm/package.json +6 -0
  21. package/dist/esm/wallet/keygen.js +230 -0
  22. package/dist/esm/wallet/privateKey.js +45 -0
  23. package/dist/esm/wallet/signing.js +161 -0
  24. package/dist/esm/{workers/wasm_exec-CFNSOXDO.js → wasm/wasm_exec.js} +68 -74
  25. package/dist/esm/workers/walletUtils.js +314 -0
  26. package/dist/esm/workers/worker.js +78 -337
  27. package/dist/esm/workers/workerWrapper.js +85 -0
  28. package/dist/types/ParaServer.d.ts +4 -5
  29. package/dist/types/ServerUtils.d.ts +5 -6
  30. package/dist/types/wallet/keygen.d.ts +5 -3
  31. package/dist/types/workers/walletUtils.d.ts +4 -6
  32. package/dist/types/workers/worker.d.ts +10 -1
  33. package/dist/types/workers/workerWrapper.d.ts +2 -2
  34. package/package.json +20 -20
  35. package/dist/cjs/index.js.br +0 -0
  36. package/dist/cjs/index.js.gz +0 -0
  37. package/dist/cjs/workers/worker.js.br +0 -0
  38. package/dist/cjs/workers/worker.js.gz +0 -0
  39. package/dist/esm/index.js.br +0 -0
  40. package/dist/esm/index.js.gz +0 -0
  41. package/dist/esm/workers/chunk-ILICZWQV.js +0 -36
  42. package/dist/esm/workers/chunk-ILICZWQV.js.br +0 -0
  43. package/dist/esm/workers/chunk-ILICZWQV.js.gz +0 -0
  44. package/dist/esm/workers/wasm_exec-CFNSOXDO.js.br +0 -0
  45. package/dist/esm/workers/wasm_exec-CFNSOXDO.js.gz +0 -0
  46. package/dist/esm/workers/worker.js.br +0 -0
  47. package/dist/esm/workers/worker.js.gz +0 -0
@@ -4,9 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
7
  var __export = (target, all) => {
11
8
  for (var name in all)
12
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -48,903 +45,23 @@ var __async = (__this, __arguments, generator) => {
48
45
  step((generator = generator.apply(__this, __arguments)).next());
49
46
  });
50
47
  };
51
-
52
- // src/wasm/wasm_exec.js
53
- var require_wasm_exec = __commonJS({
54
- "src/wasm/wasm_exec.js"(exports2, module2) {
55
- "use strict";
56
- var globalThisCopy = global;
57
- if (!globalThisCopy.crypto) {
58
- globalThisCopy.crypto = require("crypto");
59
- }
60
- var crypto = globalThisCopy.crypto;
61
- (() => {
62
- const enosys = () => {
63
- const err = new Error("not implemented");
64
- err.code = "ENOSYS";
65
- return err;
66
- };
67
- if (!globalThis.fs) {
68
- let outputBuf = "";
69
- globalThis.fs = {
70
- constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
71
- // unused
72
- writeSync(fd, buf) {
73
- outputBuf += decoder.decode(buf);
74
- const nl = outputBuf.lastIndexOf("\n");
75
- if (nl != -1) {
76
- console.log(outputBuf.substring(0, nl));
77
- outputBuf = outputBuf.substring(nl + 1);
78
- }
79
- return buf.length;
80
- },
81
- write(fd, buf, offset, length, position, callback) {
82
- if (offset !== 0 || length !== buf.length || position !== null) {
83
- callback(enosys());
84
- return;
85
- }
86
- const n = this.writeSync(fd, buf);
87
- callback(null, n);
88
- },
89
- chmod(path, mode, callback) {
90
- callback(enosys());
91
- },
92
- chown(path, uid, gid, callback) {
93
- callback(enosys());
94
- },
95
- close(fd, callback) {
96
- callback(enosys());
97
- },
98
- fchmod(fd, mode, callback) {
99
- callback(enosys());
100
- },
101
- fchown(fd, uid, gid, callback) {
102
- callback(enosys());
103
- },
104
- fstat(fd, callback) {
105
- callback(enosys());
106
- },
107
- fsync(fd, callback) {
108
- callback(null);
109
- },
110
- ftruncate(fd, length, callback) {
111
- callback(enosys());
112
- },
113
- lchown(path, uid, gid, callback) {
114
- callback(enosys());
115
- },
116
- link(path, link, callback) {
117
- callback(enosys());
118
- },
119
- lstat(path, callback) {
120
- callback(enosys());
121
- },
122
- mkdir(path, perm, callback) {
123
- callback(enosys());
124
- },
125
- open(path, flags, mode, callback) {
126
- callback(enosys());
127
- },
128
- read(fd, buffer, offset, length, position, callback) {
129
- callback(enosys());
130
- },
131
- readdir(path, callback) {
132
- callback(enosys());
133
- },
134
- readlink(path, callback) {
135
- callback(enosys());
136
- },
137
- rename(from, to, callback) {
138
- callback(enosys());
139
- },
140
- rmdir(path, callback) {
141
- callback(enosys());
142
- },
143
- stat(path, callback) {
144
- callback(enosys());
145
- },
146
- symlink(path, link, callback) {
147
- callback(enosys());
148
- },
149
- truncate(path, length, callback) {
150
- callback(enosys());
151
- },
152
- unlink(path, callback) {
153
- callback(enosys());
154
- },
155
- utimes(path, atime, mtime, callback) {
156
- callback(enosys());
157
- }
158
- };
159
- }
160
- if (!globalThis.process) {
161
- globalThis.process = {
162
- getuid() {
163
- return -1;
164
- },
165
- getgid() {
166
- return -1;
167
- },
168
- geteuid() {
169
- return -1;
170
- },
171
- getegid() {
172
- return -1;
173
- },
174
- getgroups() {
175
- throw enosys();
176
- },
177
- pid: -1,
178
- ppid: -1,
179
- umask() {
180
- throw enosys();
181
- },
182
- cwd() {
183
- throw enosys();
184
- },
185
- chdir() {
186
- throw enosys();
187
- }
188
- };
189
- }
190
- if (!globalThis.crypto) {
191
- throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
192
- }
193
- if (!globalThis.performance) {
194
- throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");
195
- }
196
- if (!globalThis.TextEncoder) {
197
- throw new Error("globalThis.TextEncoder is not available, polyfill required");
198
- }
199
- if (!globalThis.TextDecoder) {
200
- throw new Error("globalThis.TextDecoder is not available, polyfill required");
201
- }
202
- const encoder = new TextEncoder("utf-8");
203
- const decoder = new TextDecoder("utf-8");
204
- globalThis.Go = class {
205
- constructor() {
206
- this.argv = ["js"];
207
- this.env = {};
208
- this.exit = (code) => {
209
- if (code !== 0) {
210
- console.warn("exit code:", code);
211
- }
212
- };
213
- this._exitPromise = new Promise((resolve) => {
214
- this._resolveExitPromise = resolve;
215
- });
216
- this._pendingEvent = null;
217
- this._scheduledTimeouts = /* @__PURE__ */ new Map();
218
- this._nextCallbackTimeoutID = 1;
219
- const setInt64 = (addr, v) => {
220
- this.mem.setUint32(addr + 0, v, true);
221
- this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
222
- };
223
- const setInt32 = (addr, v) => {
224
- this.mem.setUint32(addr + 0, v, true);
225
- };
226
- const getInt64 = (addr) => {
227
- const low = this.mem.getUint32(addr + 0, true);
228
- const high = this.mem.getInt32(addr + 4, true);
229
- return low + high * 4294967296;
230
- };
231
- const loadValue = (addr) => {
232
- const f = this.mem.getFloat64(addr, true);
233
- if (f === 0) {
234
- return void 0;
235
- }
236
- if (!isNaN(f)) {
237
- return f;
238
- }
239
- const id = this.mem.getUint32(addr, true);
240
- return this._values[id];
241
- };
242
- const storeValue = (addr, v) => {
243
- const nanHead = 2146959360;
244
- if (typeof v === "number" && v !== 0) {
245
- if (isNaN(v)) {
246
- this.mem.setUint32(addr + 4, nanHead, true);
247
- this.mem.setUint32(addr, 0, true);
248
- return;
249
- }
250
- this.mem.setFloat64(addr, v, true);
251
- return;
252
- }
253
- if (v === void 0) {
254
- this.mem.setFloat64(addr, 0, true);
255
- return;
256
- }
257
- let id = this._ids.get(v);
258
- if (id === void 0) {
259
- id = this._idPool.pop();
260
- if (id === void 0) {
261
- id = this._values.length;
262
- }
263
- this._values[id] = v;
264
- this._goRefCounts[id] = 0;
265
- this._ids.set(v, id);
266
- }
267
- this._goRefCounts[id]++;
268
- let typeFlag = 0;
269
- switch (typeof v) {
270
- case "object":
271
- if (v !== null) {
272
- typeFlag = 1;
273
- }
274
- break;
275
- case "string":
276
- typeFlag = 2;
277
- break;
278
- case "symbol":
279
- typeFlag = 3;
280
- break;
281
- case "function":
282
- typeFlag = 4;
283
- break;
284
- }
285
- this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
286
- this.mem.setUint32(addr, id, true);
287
- };
288
- const loadSlice = (addr) => {
289
- const array = getInt64(addr + 0);
290
- const len = getInt64(addr + 8);
291
- return new Uint8Array(this._inst.exports.mem.buffer, array, len);
292
- };
293
- const loadSliceOfValues = (addr) => {
294
- const array = getInt64(addr + 0);
295
- const len = getInt64(addr + 8);
296
- const a = new Array(len);
297
- for (let i = 0; i < len; i++) {
298
- a[i] = loadValue(array + i * 8);
299
- }
300
- return a;
301
- };
302
- const loadString = (addr) => {
303
- const saddr = getInt64(addr + 0);
304
- const len = getInt64(addr + 8);
305
- return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
306
- };
307
- const timeOrigin = Date.now() - performance.now();
308
- this.importObject = {
309
- _gotest: {
310
- add: (a, b) => a + b
311
- },
312
- gojs: {
313
- // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
314
- // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
315
- // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
316
- // This changes the SP, thus we have to update the SP used by the imported function.
317
- // func wasmExit(code int32)
318
- "runtime.wasmExit": (sp) => {
319
- sp >>>= 0;
320
- const code = this.mem.getInt32(sp + 8, true);
321
- this.exited = true;
322
- delete this._inst;
323
- delete this._values;
324
- delete this._goRefCounts;
325
- delete this._ids;
326
- delete this._idPool;
327
- this.exit(code);
328
- },
329
- // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
330
- "runtime.wasmWrite": (sp) => {
331
- sp >>>= 0;
332
- const fd = getInt64(sp + 8);
333
- const p = getInt64(sp + 16);
334
- const n = this.mem.getInt32(sp + 24, true);
335
- fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
336
- },
337
- // func resetMemoryDataView()
338
- "runtime.resetMemoryDataView": (sp) => {
339
- sp >>>= 0;
340
- this.mem = new DataView(this._inst.exports.mem.buffer);
341
- },
342
- // func nanotime1() int64
343
- "runtime.nanotime1": (sp) => {
344
- sp >>>= 0;
345
- setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);
346
- },
347
- // func walltime() (sec int64, nsec int32)
348
- "runtime.walltime": (sp) => {
349
- sp >>>= 0;
350
- const msec = (/* @__PURE__ */ new Date()).getTime();
351
- setInt64(sp + 8, msec / 1e3);
352
- this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
353
- },
354
- // func scheduleTimeoutEvent(delay int64) int32
355
- "runtime.scheduleTimeoutEvent": (sp) => {
356
- sp >>>= 0;
357
- const id = this._nextCallbackTimeoutID;
358
- this._nextCallbackTimeoutID++;
359
- this._scheduledTimeouts.set(id, setTimeout(
360
- () => {
361
- this._resume();
362
- while (this._scheduledTimeouts.has(id)) {
363
- console.warn("scheduleTimeoutEvent: missed timeout event");
364
- this._resume();
365
- }
366
- },
367
- getInt64(sp + 8)
368
- ));
369
- this.mem.setInt32(sp + 16, id, true);
370
- },
371
- // func clearTimeoutEvent(id int32)
372
- "runtime.clearTimeoutEvent": (sp) => {
373
- sp >>>= 0;
374
- const id = this.mem.getInt32(sp + 8, true);
375
- clearTimeout(this._scheduledTimeouts.get(id));
376
- this._scheduledTimeouts.delete(id);
377
- },
378
- // func getRandomData(r []byte)
379
- "runtime.getRandomData": (sp) => {
380
- sp >>>= 0;
381
- crypto.getRandomValues(loadSlice(sp + 8));
382
- },
383
- // func finalizeRef(v ref)
384
- "syscall/js.finalizeRef": (sp) => {
385
- sp >>>= 0;
386
- const id = this.mem.getUint32(sp + 8, true);
387
- this._goRefCounts[id]--;
388
- if (this._goRefCounts[id] === 0) {
389
- const v = this._values[id];
390
- this._values[id] = null;
391
- this._ids.delete(v);
392
- this._idPool.push(id);
393
- }
394
- },
395
- // func stringVal(value string) ref
396
- "syscall/js.stringVal": (sp) => {
397
- sp >>>= 0;
398
- storeValue(sp + 24, loadString(sp + 8));
399
- },
400
- // func valueGet(v ref, p string) ref
401
- "syscall/js.valueGet": (sp) => {
402
- sp >>>= 0;
403
- const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
404
- sp = this._inst.exports.getsp() >>> 0;
405
- storeValue(sp + 32, result);
406
- },
407
- // func valueSet(v ref, p string, x ref)
408
- "syscall/js.valueSet": (sp) => {
409
- sp >>>= 0;
410
- Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
411
- },
412
- // func valueDelete(v ref, p string)
413
- "syscall/js.valueDelete": (sp) => {
414
- sp >>>= 0;
415
- Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
416
- },
417
- // func valueIndex(v ref, i int) ref
418
- "syscall/js.valueIndex": (sp) => {
419
- sp >>>= 0;
420
- storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
421
- },
422
- // valueSetIndex(v ref, i int, x ref)
423
- "syscall/js.valueSetIndex": (sp) => {
424
- sp >>>= 0;
425
- Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
426
- },
427
- // func valueCall(v ref, m string, args []ref) (ref, bool)
428
- "syscall/js.valueCall": (sp) => {
429
- sp >>>= 0;
430
- try {
431
- const v = loadValue(sp + 8);
432
- const m = Reflect.get(v, loadString(sp + 16));
433
- const args = loadSliceOfValues(sp + 32);
434
- const result = Reflect.apply(m, v, args);
435
- sp = this._inst.exports.getsp() >>> 0;
436
- storeValue(sp + 56, result);
437
- this.mem.setUint8(sp + 64, 1);
438
- } catch (err) {
439
- sp = this._inst.exports.getsp() >>> 0;
440
- storeValue(sp + 56, err);
441
- this.mem.setUint8(sp + 64, 0);
442
- }
443
- },
444
- // func valueInvoke(v ref, args []ref) (ref, bool)
445
- "syscall/js.valueInvoke": (sp) => {
446
- sp >>>= 0;
447
- try {
448
- const v = loadValue(sp + 8);
449
- const args = loadSliceOfValues(sp + 16);
450
- const result = Reflect.apply(v, void 0, args);
451
- sp = this._inst.exports.getsp() >>> 0;
452
- storeValue(sp + 40, result);
453
- this.mem.setUint8(sp + 48, 1);
454
- } catch (err) {
455
- sp = this._inst.exports.getsp() >>> 0;
456
- storeValue(sp + 40, err);
457
- this.mem.setUint8(sp + 48, 0);
458
- }
459
- },
460
- // func valueNew(v ref, args []ref) (ref, bool)
461
- "syscall/js.valueNew": (sp) => {
462
- sp >>>= 0;
463
- try {
464
- const v = loadValue(sp + 8);
465
- const args = loadSliceOfValues(sp + 16);
466
- const result = Reflect.construct(v, args);
467
- sp = this._inst.exports.getsp() >>> 0;
468
- storeValue(sp + 40, result);
469
- this.mem.setUint8(sp + 48, 1);
470
- } catch (err) {
471
- sp = this._inst.exports.getsp() >>> 0;
472
- storeValue(sp + 40, err);
473
- this.mem.setUint8(sp + 48, 0);
474
- }
475
- },
476
- // func valueLength(v ref) int
477
- "syscall/js.valueLength": (sp) => {
478
- sp >>>= 0;
479
- setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
480
- },
481
- // valuePrepareString(v ref) (ref, int)
482
- "syscall/js.valuePrepareString": (sp) => {
483
- sp >>>= 0;
484
- const str = encoder.encode(String(loadValue(sp + 8)));
485
- storeValue(sp + 16, str);
486
- setInt64(sp + 24, str.length);
487
- },
488
- // valueLoadString(v ref, b []byte)
489
- "syscall/js.valueLoadString": (sp) => {
490
- sp >>>= 0;
491
- const str = loadValue(sp + 8);
492
- loadSlice(sp + 16).set(str);
493
- },
494
- // func valueInstanceOf(v ref, t ref) bool
495
- "syscall/js.valueInstanceOf": (sp) => {
496
- sp >>>= 0;
497
- this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);
498
- },
499
- // func copyBytesToGo(dst []byte, src ref) (int, bool)
500
- "syscall/js.copyBytesToGo": (sp) => {
501
- sp >>>= 0;
502
- const dst = loadSlice(sp + 8);
503
- const src = loadValue(sp + 32);
504
- if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
505
- this.mem.setUint8(sp + 48, 0);
506
- return;
507
- }
508
- const toCopy = src.subarray(0, dst.length);
509
- dst.set(toCopy);
510
- setInt64(sp + 40, toCopy.length);
511
- this.mem.setUint8(sp + 48, 1);
512
- },
513
- // func copyBytesToJS(dst ref, src []byte) (int, bool)
514
- "syscall/js.copyBytesToJS": (sp) => {
515
- sp >>>= 0;
516
- const dst = loadValue(sp + 8);
517
- const src = loadSlice(sp + 16);
518
- if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
519
- this.mem.setUint8(sp + 48, 0);
520
- return;
521
- }
522
- const toCopy = src.subarray(0, dst.length);
523
- dst.set(toCopy);
524
- setInt64(sp + 40, toCopy.length);
525
- this.mem.setUint8(sp + 48, 1);
526
- },
527
- "debug": (value) => {
528
- console.log(value);
529
- }
530
- }
531
- };
532
- }
533
- run(instance) {
534
- return __async(this, null, function* () {
535
- if (!(instance instanceof WebAssembly.Instance)) {
536
- throw new Error("Go.run: WebAssembly.Instance expected");
537
- }
538
- this._inst = instance;
539
- this.mem = new DataView(this._inst.exports.mem.buffer);
540
- this._values = [
541
- // JS values that Go currently has references to, indexed by reference id
542
- NaN,
543
- 0,
544
- null,
545
- true,
546
- false,
547
- globalThis,
548
- this
549
- ];
550
- this._goRefCounts = new Array(this._values.length).fill(Infinity);
551
- this._ids = /* @__PURE__ */ new Map([
552
- // mapping from JS values to reference ids
553
- [0, 1],
554
- [null, 2],
555
- [true, 3],
556
- [false, 4],
557
- [globalThis, 5],
558
- [this, 6]
559
- ]);
560
- this._idPool = [];
561
- this.exited = false;
562
- let offset = 4096;
563
- const strPtr = (str) => {
564
- const ptr = offset;
565
- const bytes = encoder.encode(str + "\0");
566
- new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
567
- offset += bytes.length;
568
- if (offset % 8 !== 0) {
569
- offset += 8 - offset % 8;
570
- }
571
- return ptr;
572
- };
573
- const argc = this.argv.length;
574
- const argvPtrs = [];
575
- this.argv.forEach((arg) => {
576
- argvPtrs.push(strPtr(arg));
577
- });
578
- argvPtrs.push(0);
579
- const keys = Object.keys(this.env).sort();
580
- keys.forEach((key) => {
581
- argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
582
- });
583
- argvPtrs.push(0);
584
- const argv = offset;
585
- argvPtrs.forEach((ptr) => {
586
- this.mem.setUint32(offset, ptr, true);
587
- this.mem.setUint32(offset + 4, 0, true);
588
- offset += 8;
589
- });
590
- const wasmMinDataAddr = 4096 + 8192;
591
- if (offset >= wasmMinDataAddr) {
592
- throw new Error("total length of command line and environment variables exceeds limit");
593
- }
594
- this._inst.exports.run(argc, argv);
595
- if (this.exited) {
596
- this._resolveExitPromise();
597
- }
598
- yield this._exitPromise;
599
- });
600
- }
601
- _resume() {
602
- if (this.exited) {
603
- throw new Error("Go program has already exited");
604
- }
605
- this._inst.exports.resume();
606
- if (this.exited) {
607
- this._resolveExitPromise();
608
- }
609
- }
610
- _makeFuncWrapper(id) {
611
- const go = this;
612
- return function() {
613
- const event = { id, this: this, args: arguments };
614
- go._pendingEvent = event;
615
- go._resume();
616
- return event.result;
617
- };
618
- }
619
- };
620
- })();
621
- module2.exports = {
622
- globalThisCopy
623
- };
624
- }
625
- });
626
-
627
- // src/workers/worker.ts
628
48
  var worker_exports = {};
629
49
  __export(worker_exports, {
630
- handleMessage: () => handleMessage
50
+ handleMessage: () => handleMessage,
51
+ requestWasmWithRetries: () => requestWasmWithRetries,
52
+ withRetry: () => withRetry
631
53
  });
632
54
  module.exports = __toCommonJS(worker_exports);
633
55
  var import_axios = __toESM(require("axios"));
634
- var import_core_sdk2 = require("@getpara/core-sdk");
635
-
636
- // src/workers/walletUtils.ts
637
56
  var import_core_sdk = require("@getpara/core-sdk");
638
- var configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
639
- var configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
640
- function keygenRequest(ctx, userId, walletId, protocolId) {
641
- return __async(this, null, function* () {
642
- const { data } = yield ctx.mpcComputationClient.post("/wallets", {
643
- userId,
644
- walletId,
645
- protocolId
646
- });
647
- return data;
648
- });
649
- }
650
- function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
651
- return __async(this, null, function* () {
652
- const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
653
- userId,
654
- protocolId,
655
- message,
656
- signer
657
- });
658
- return data;
659
- });
660
- }
661
- function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
662
- return __async(this, null, function* () {
663
- const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
664
- userId,
665
- protocolId,
666
- transaction,
667
- signer,
668
- chainId
669
- });
670
- return data;
671
- });
672
- }
673
- function ed25519Keygen(ctx, userId) {
674
- return __async(this, null, function* () {
675
- const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
676
- scheme: import_core_sdk.WalletScheme.ED25519,
677
- type: import_core_sdk.WalletType.SOLANA
678
- });
679
- const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
680
- try {
681
- const newSigner = yield new Promise(
682
- (resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
683
- if (err) {
684
- reject(err);
685
- }
686
- resolve(result);
687
- })
688
- );
689
- return { signer: newSigner, walletId };
690
- } catch (e) {
691
- throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
692
- }
693
- });
694
- }
695
- function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
696
- return __async(this, null, function* () {
697
- const { walletId, protocolId } = yield ctx.client.createPregenWallet({
698
- pregenIdentifier,
699
- pregenIdentifierType,
700
- scheme: import_core_sdk.WalletScheme.ED25519,
701
- type: import_core_sdk.WalletType.SOLANA
702
- });
703
- const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
704
- try {
705
- const newSigner = yield new Promise(
706
- (resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
707
- if (err) {
708
- reject(err);
709
- }
710
- resolve(result);
711
- })
712
- );
713
- return { signer: newSigner, walletId };
714
- } catch (e) {
715
- throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
716
- }
717
- });
718
- }
719
- function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
720
- return __async(this, null, function* () {
721
- const { protocolId } = yield ctx.client.preSignMessage(userId, walletId, base64Bytes, import_core_sdk.WalletScheme.ED25519);
722
- try {
723
- const base64Sig = yield new Promise(
724
- (resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
725
- if (err) {
726
- reject(err);
727
- }
728
- resolve(result);
729
- })
730
- );
731
- return { signature: base64Sig };
732
- } catch (e) {
733
- throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
734
- }
735
- });
736
- }
737
- function keygen(ctx, userId, type, secretKey) {
738
- return __async(this, null, function* () {
739
- const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
740
- useTwoSigners: true,
741
- scheme: ctx.useDKLS ? import_core_sdk.WalletScheme.DKLS : import_core_sdk.WalletScheme.CGGMP,
742
- type,
743
- cosmosPrefix: type === import_core_sdk.WalletType.COSMOS ? ctx.cosmosPrefix : void 0
744
- });
745
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
746
- return {
747
- signer: (yield keygenRequest(ctx, userId, walletId, protocolId)).signer,
748
- walletId
749
- };
750
- }
751
- const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
752
- const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
753
- const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
754
- try {
755
- const newSigner = yield new Promise(
756
- (resolve, reject) => createAccountFn(
757
- signerConfigUser,
758
- serverUrl,
759
- protocolId,
760
- secretKey,
761
- () => {
762
- },
763
- // no-op for deprecated callback to update progress percentage
764
- (err, result) => {
765
- if (err) {
766
- reject(err);
767
- }
768
- resolve(result);
769
- }
770
- )
771
- );
772
- return { signer: newSigner, walletId };
773
- } catch (e) {
774
- throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
775
- }
776
- });
777
- }
778
- function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
779
- return __async(this, null, function* () {
780
- const { walletId, protocolId } = yield ctx.client.createPregenWallet({
781
- pregenIdentifier,
782
- pregenIdentifierType,
783
- type,
784
- cosmosPrefix: type === import_core_sdk.WalletType.COSMOS ? ctx.cosmosPrefix : void 0
785
- });
786
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
787
- return {
788
- signer: (yield keygenRequest(ctx, partnerId, walletId, protocolId)).signer,
789
- walletId
790
- };
791
- }
792
- const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
793
- const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
794
- const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
795
- try {
796
- const newSigner = yield new Promise(
797
- (resolve, reject) => createAccountFn(
798
- signerConfigUser,
799
- serverUrl,
800
- protocolId,
801
- secretKey,
802
- () => {
803
- },
804
- // no-op for deprecated callback to update progress percentage
805
- (err, result) => {
806
- if (err) {
807
- reject(err);
808
- }
809
- resolve(result);
810
- }
811
- )
812
- );
813
- return { signer: newSigner, walletId };
814
- } catch (e) {
815
- throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
816
- }
817
- });
818
- }
819
- function signMessage(ctx, share, walletId, userId, message) {
820
- return __async(this, null, function* () {
821
- const { protocolId, pendingTransactionId } = yield ctx.client.preSignMessage(userId, walletId, message);
822
- if (pendingTransactionId) {
823
- return { pendingTransactionId };
824
- }
825
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
826
- return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
827
- }
828
- const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
829
- const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
830
- try {
831
- return new Promise(
832
- (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
833
- if (err) {
834
- reject(err);
835
- }
836
- resolve({ signature: result });
837
- })
838
- );
839
- } catch (e) {
840
- throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
841
- }
842
- });
843
- }
844
- function signTransaction(ctx, share, walletId, userId, tx, chainId) {
845
- return __async(this, null, function* () {
846
- const {
847
- data: { protocolId, pendingTransactionId }
848
- } = yield ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
849
- if (pendingTransactionId) {
850
- return { pendingTransactionId };
851
- }
852
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
853
- return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
854
- }
855
- const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
856
- const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
857
- try {
858
- return new Promise(
859
- (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
860
- if (err) {
861
- reject(err);
862
- }
863
- resolve({ signature: result });
864
- })
865
- );
866
- } catch (e) {
867
- throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
868
- }
869
- });
870
- }
871
- function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
872
- return __async(this, null, function* () {
873
- const {
874
- data: { protocolId, pendingTransactionId }
875
- } = yield ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
876
- if (pendingTransactionId) {
877
- return { pendingTransactionId };
878
- }
879
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
880
- return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
881
- }
882
- const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
883
- const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
884
- try {
885
- return new Promise(
886
- (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
887
- if (err) {
888
- reject(err);
889
- }
890
- resolve({ signature: result });
891
- })
892
- );
893
- } catch (e) {
894
- throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
895
- }
896
- });
897
- }
898
- function refresh(ctx, share, walletId, userId) {
899
- return __async(this, null, function* () {
900
- const {
901
- data: { protocolId }
902
- } = yield ctx.client.refreshKeys(userId, walletId);
903
- const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
904
- const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
905
- try {
906
- return new Promise(
907
- (resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
908
- if (err) {
909
- reject(err);
910
- }
911
- resolve(result);
912
- })
913
- );
914
- } catch (e) {
915
- throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
916
- }
917
- });
918
- }
919
- function getPrivateKey(ctx, share, walletId, userId) {
920
- return __async(this, null, function* () {
921
- const paraShare = yield ctx.client.getParaShare(userId, walletId);
922
- if (!paraShare) {
923
- console.error("unable to retrieve Para share");
924
- return "";
925
- }
926
- try {
927
- return new Promise(
928
- (resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
929
- if (err) {
930
- reject(err);
931
- }
932
- resolve(result);
933
- })
934
- );
935
- } catch (e) {
936
- throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
937
- }
938
- });
939
- }
940
-
941
- // src/workers/worker.ts
942
- var rawWasm;
57
+ var walletUtils = __toESM(require("./walletUtils.js"));
58
+ let rawWasm;
59
+ let wasmLoaded = false;
943
60
  function requestWasmWithRetries(ctx, retries = 3) {
944
61
  return __async(this, null, function* () {
945
62
  for (let i = 0; i < retries; i++) {
946
63
  try {
947
- return yield import_axios.default.get(`${(0, import_core_sdk2.getPortalBaseURL)(ctx, true, true)}/static/js/main.wasm`, { responseType: "arraybuffer" });
64
+ return yield import_axios.default.get(`${(0, import_core_sdk.getPortalBaseURL)(ctx, true, true)}/static/js/main.wasm`, { responseType: "arraybuffer" });
948
65
  } catch (e) {
949
66
  if (i === retries - 1) {
950
67
  throw e;
@@ -955,7 +72,7 @@ function requestWasmWithRetries(ctx, retries = 3) {
955
72
  }
956
73
  function loadWasm(ctx) {
957
74
  return __async(this, null, function* () {
958
- yield Promise.resolve().then(() => __toESM(require_wasm_exec()));
75
+ yield import("../wasm/wasm_exec.js");
959
76
  global.WebSocket = require("ws");
960
77
  const goWasm = new global.Go();
961
78
  if (!rawWasm) {
@@ -971,46 +88,48 @@ function executeMessage(ctx, message) {
971
88
  const { functionType, params } = message;
972
89
  switch (functionType) {
973
90
  case "KEYGEN": {
974
- const { userId, secretKey, type = import_core_sdk2.WalletType.EVM } = params;
975
- return keygen(ctx, userId, type, secretKey);
91
+ const { userId, secretKey, type = "EVM" } = params;
92
+ return walletUtils.keygen(ctx, userId, type, secretKey);
976
93
  }
977
94
  case "SIGN_TRANSACTION": {
978
95
  const { share, walletId, userId, tx, chainId } = params;
979
- return signTransaction(ctx, share, walletId, userId, tx, chainId);
96
+ return withRetry(() => walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId));
980
97
  }
981
98
  case "SEND_TRANSACTION": {
982
99
  const { share, walletId, userId, tx, chainId } = params;
983
- return sendTransaction(ctx, share, walletId, userId, tx, chainId);
100
+ return withRetry(() => walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId));
984
101
  }
985
102
  case "SIGN_MESSAGE": {
986
103
  const { share, walletId, userId, message: message2 } = params;
987
- return signMessage(ctx, share, walletId, userId, message2);
104
+ return withRetry(() => walletUtils.signMessage(ctx, share, walletId, userId, message2));
988
105
  }
989
106
  case "REFRESH": {
990
107
  const { share, walletId, userId } = params;
991
- return refresh(ctx, share, walletId, userId);
108
+ const signer = yield walletUtils.refresh(ctx, share, walletId, userId);
109
+ return { signer };
992
110
  }
993
111
  case "PREKEYGEN": {
994
- const { email, partnerId, secretKey, type = import_core_sdk2.WalletType.EVM } = params;
112
+ const { email, partnerId, secretKey, type = "EVM" } = params;
995
113
  let { pregenIdentifier, pregenIdentifierType } = params;
996
114
  if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
997
115
  pregenIdentifier = email;
998
116
  pregenIdentifierType = "EMAIL";
999
117
  }
1000
- const keygenRes = yield preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
118
+ const keygenRes = yield walletUtils.preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
1001
119
  return keygenRes;
1002
120
  }
1003
121
  case "GET_PRIVATE_KEY": {
1004
122
  const { share, walletId, userId } = params;
1005
- return yield getPrivateKey(ctx, share, walletId, userId);
123
+ const privateKey = yield walletUtils.getPrivateKey(ctx, share, walletId, userId);
124
+ return { privateKey };
1006
125
  }
1007
126
  case "ED25519_KEYGEN": {
1008
127
  const { userId } = params;
1009
- return ed25519Keygen(ctx, userId);
128
+ return walletUtils.ed25519Keygen(ctx, userId);
1010
129
  }
1011
130
  case "ED25519_SIGN": {
1012
131
  const { share, walletId, userId, base64Bytes } = params;
1013
- return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
132
+ return walletUtils.ed25519Sign(ctx, share, userId, walletId, base64Bytes);
1014
133
  }
1015
134
  case "ED25519_PREKEYGEN": {
1016
135
  const { email } = params;
@@ -1019,7 +138,7 @@ function executeMessage(ctx, message) {
1019
138
  pregenIdentifier = email;
1020
139
  pregenIdentifierType = "EMAIL";
1021
140
  }
1022
- return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
141
+ return walletUtils.ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
1023
142
  }
1024
143
  default: {
1025
144
  throw new Error(`functionType: ${functionType} not supported`);
@@ -1027,6 +146,29 @@ function executeMessage(ctx, message) {
1027
146
  }
1028
147
  });
1029
148
  }
149
+ function withRetry(operation, maxRetries = 2, timeoutMs = 1e4) {
150
+ return __async(this, null, function* () {
151
+ let retries = 0;
152
+ while (true) {
153
+ try {
154
+ const operationPromise = operation();
155
+ const timeoutPromise = new Promise((_, reject) => {
156
+ const timeoutId = setTimeout(() => {
157
+ reject(new Error(`Operation timed out after ${timeoutMs}ms`));
158
+ }, timeoutMs);
159
+ operationPromise.finally(() => clearTimeout(timeoutId));
160
+ });
161
+ return yield Promise.race([operationPromise, timeoutPromise]);
162
+ } catch (error) {
163
+ retries++;
164
+ if (retries > maxRetries) {
165
+ throw error;
166
+ }
167
+ console.warn(`Operation failed (attempt ${retries}/${maxRetries}), retrying...`, error);
168
+ }
169
+ }
170
+ });
171
+ }
1030
172
  function handleMessage(e) {
1031
173
  return __async(this, null, function* () {
1032
174
  const {
@@ -1043,15 +185,26 @@ function handleMessage(e) {
1043
185
  const ctx = {
1044
186
  env,
1045
187
  apiKey,
1046
- client: (0, import_core_sdk2.initClient)({ env, version: import_core_sdk2.paraVersion, apiKey, retrieveSessionCookie: () => sessionCookie }),
188
+ client: (0, import_core_sdk.initClient)({ env, version: import_core_sdk.paraVersion, apiKey, retrieveSessionCookie: () => sessionCookie }),
1047
189
  offloadMPCComputationURL,
1048
- mpcComputationClient: offloadMPCComputationURL ? import_core_sdk2.mpcComputationClient.initClient(offloadMPCComputationURL, !!disableWorkers) : void 0,
190
+ mpcComputationClient: offloadMPCComputationURL ? import_core_sdk.mpcComputationClient.initClient(offloadMPCComputationURL, !!disableWorkers) : void 0,
1049
191
  useDKLS,
1050
192
  disableWebSockets: !!disableWebSockets,
1051
193
  cosmosPrefix
1052
194
  };
1053
- if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
195
+ if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
1054
196
  yield loadWasm(ctx);
197
+ if (global.initWasm) {
198
+ yield new Promise(
199
+ (resolve, reject) => global.initWasm((err, result2) => {
200
+ if (err) {
201
+ reject(err);
202
+ }
203
+ resolve(result2);
204
+ })
205
+ );
206
+ }
207
+ wasmLoaded = true;
1055
208
  }
1056
209
  const result = yield executeMessage(ctx, e.data);
1057
210
  result.workId = workId;
@@ -1060,5 +213,7 @@ function handleMessage(e) {
1060
213
  }
1061
214
  // Annotate the CommonJS export names for ESM import in node:
1062
215
  0 && (module.exports = {
1063
- handleMessage
216
+ handleMessage,
217
+ requestWasmWithRetries,
218
+ withRetry
1064
219
  });