@getpara/web-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.
@@ -0,0 +1,564 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../chunk-WLGKV3EF.js";
5
+ (() => {
6
+ const enosys = () => {
7
+ const err = new Error("not implemented");
8
+ err.code = "ENOSYS";
9
+ return err;
10
+ };
11
+ if (!globalThis.fs) {
12
+ let outputBuf = "";
13
+ globalThis.fs = {
14
+ constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
15
+ // unused
16
+ writeSync(fd, buf) {
17
+ outputBuf += decoder.decode(buf);
18
+ const nl = outputBuf.lastIndexOf("\n");
19
+ if (nl != -1) {
20
+ console.log(outputBuf.substring(0, nl));
21
+ outputBuf = outputBuf.substring(nl + 1);
22
+ }
23
+ return buf.length;
24
+ },
25
+ write(fd, buf, offset, length, position, callback) {
26
+ if (offset !== 0 || length !== buf.length || position !== null) {
27
+ callback(enosys());
28
+ return;
29
+ }
30
+ const n = this.writeSync(fd, buf);
31
+ callback(null, n);
32
+ },
33
+ chmod(path, mode, callback) {
34
+ callback(enosys());
35
+ },
36
+ chown(path, uid, gid, callback) {
37
+ callback(enosys());
38
+ },
39
+ close(fd, callback) {
40
+ callback(enosys());
41
+ },
42
+ fchmod(fd, mode, callback) {
43
+ callback(enosys());
44
+ },
45
+ fchown(fd, uid, gid, callback) {
46
+ callback(enosys());
47
+ },
48
+ fstat(fd, callback) {
49
+ callback(enosys());
50
+ },
51
+ fsync(fd, callback) {
52
+ callback(null);
53
+ },
54
+ ftruncate(fd, length, callback) {
55
+ callback(enosys());
56
+ },
57
+ lchown(path, uid, gid, callback) {
58
+ callback(enosys());
59
+ },
60
+ link(path, link, callback) {
61
+ callback(enosys());
62
+ },
63
+ lstat(path, callback) {
64
+ callback(enosys());
65
+ },
66
+ mkdir(path, perm, callback) {
67
+ callback(enosys());
68
+ },
69
+ open(path, flags, mode, callback) {
70
+ callback(enosys());
71
+ },
72
+ read(fd, buffer, offset, length, position, callback) {
73
+ callback(enosys());
74
+ },
75
+ readdir(path, callback) {
76
+ callback(enosys());
77
+ },
78
+ readlink(path, callback) {
79
+ callback(enosys());
80
+ },
81
+ rename(from, to, callback) {
82
+ callback(enosys());
83
+ },
84
+ rmdir(path, callback) {
85
+ callback(enosys());
86
+ },
87
+ stat(path, callback) {
88
+ callback(enosys());
89
+ },
90
+ symlink(path, link, callback) {
91
+ callback(enosys());
92
+ },
93
+ truncate(path, length, callback) {
94
+ callback(enosys());
95
+ },
96
+ unlink(path, callback) {
97
+ callback(enosys());
98
+ },
99
+ utimes(path, atime, mtime, callback) {
100
+ callback(enosys());
101
+ }
102
+ };
103
+ }
104
+ if (!globalThis.process) {
105
+ globalThis.process = {
106
+ getuid() {
107
+ return -1;
108
+ },
109
+ getgid() {
110
+ return -1;
111
+ },
112
+ geteuid() {
113
+ return -1;
114
+ },
115
+ getegid() {
116
+ return -1;
117
+ },
118
+ getgroups() {
119
+ throw enosys();
120
+ },
121
+ pid: -1,
122
+ ppid: -1,
123
+ umask() {
124
+ throw enosys();
125
+ },
126
+ cwd() {
127
+ throw enosys();
128
+ },
129
+ chdir() {
130
+ throw enosys();
131
+ }
132
+ };
133
+ }
134
+ if (!globalThis.crypto) {
135
+ throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");
136
+ }
137
+ if (!globalThis.performance) {
138
+ globalThis.performance = Date;
139
+ }
140
+ if (!globalThis.TextEncoder) {
141
+ throw new Error("globalThis.TextEncoder is not available, polyfill required");
142
+ }
143
+ if (!globalThis.TextDecoder) {
144
+ throw new Error("globalThis.TextDecoder is not available, polyfill required");
145
+ }
146
+ const encoder = new TextEncoder("utf-8");
147
+ const decoder = new TextDecoder("utf-8");
148
+ globalThis.Go = class {
149
+ constructor() {
150
+ this.argv = ["js"];
151
+ this.env = {};
152
+ this.exit = (code) => {
153
+ if (code !== 0) {
154
+ console.warn("exit code:", code);
155
+ }
156
+ };
157
+ this._exitPromise = new Promise((resolve) => {
158
+ this._resolveExitPromise = resolve;
159
+ });
160
+ this._pendingEvent = null;
161
+ this._scheduledTimeouts = /* @__PURE__ */ new Map();
162
+ this._nextCallbackTimeoutID = 1;
163
+ const setInt64 = (addr, v) => {
164
+ this.mem.setUint32(addr + 0, v, true);
165
+ this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
166
+ };
167
+ const setInt32 = (addr, v) => {
168
+ this.mem.setUint32(addr + 0, v, true);
169
+ };
170
+ const getInt64 = (addr) => {
171
+ const low = this.mem.getUint32(addr + 0, true);
172
+ const high = this.mem.getInt32(addr + 4, true);
173
+ return low + high * 4294967296;
174
+ };
175
+ const loadValue = (addr) => {
176
+ const f = this.mem.getFloat64(addr, true);
177
+ if (f === 0) {
178
+ return void 0;
179
+ }
180
+ if (!isNaN(f)) {
181
+ return f;
182
+ }
183
+ const id = this.mem.getUint32(addr, true);
184
+ return this._values[id];
185
+ };
186
+ const storeValue = (addr, v) => {
187
+ const nanHead = 2146959360;
188
+ if (typeof v === "number" && v !== 0) {
189
+ if (isNaN(v)) {
190
+ this.mem.setUint32(addr + 4, nanHead, true);
191
+ this.mem.setUint32(addr, 0, true);
192
+ return;
193
+ }
194
+ this.mem.setFloat64(addr, v, true);
195
+ return;
196
+ }
197
+ if (v === void 0) {
198
+ this.mem.setFloat64(addr, 0, true);
199
+ return;
200
+ }
201
+ let id = this._ids.get(v);
202
+ if (id === void 0) {
203
+ id = this._idPool.pop();
204
+ if (id === void 0) {
205
+ id = this._values.length;
206
+ }
207
+ this._values[id] = v;
208
+ this._goRefCounts[id] = 0;
209
+ this._ids.set(v, id);
210
+ }
211
+ this._goRefCounts[id]++;
212
+ let typeFlag = 0;
213
+ switch (typeof v) {
214
+ case "object":
215
+ if (v !== null) {
216
+ typeFlag = 1;
217
+ }
218
+ break;
219
+ case "string":
220
+ typeFlag = 2;
221
+ break;
222
+ case "symbol":
223
+ typeFlag = 3;
224
+ break;
225
+ case "function":
226
+ typeFlag = 4;
227
+ break;
228
+ }
229
+ this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
230
+ this.mem.setUint32(addr, id, true);
231
+ };
232
+ const loadSlice = (addr) => {
233
+ const array = getInt64(addr + 0);
234
+ const len = getInt64(addr + 8);
235
+ return new Uint8Array(this._inst.exports.mem.buffer, array, len);
236
+ };
237
+ const loadSliceOfValues = (addr) => {
238
+ const array = getInt64(addr + 0);
239
+ const len = getInt64(addr + 8);
240
+ const a = new Array(len);
241
+ for (let i = 0; i < len; i++) {
242
+ a[i] = loadValue(array + i * 8);
243
+ }
244
+ return a;
245
+ };
246
+ const loadString = (addr) => {
247
+ const saddr = getInt64(addr + 0);
248
+ const len = getInt64(addr + 8);
249
+ return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
250
+ };
251
+ const timeOrigin = Date.now() - performance.now();
252
+ this.importObject = {
253
+ _gotest: {
254
+ add: (a, b) => a + b
255
+ },
256
+ gojs: {
257
+ // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
258
+ // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
259
+ // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
260
+ // This changes the SP, thus we have to update the SP used by the imported function.
261
+ // func wasmExit(code int32)
262
+ "runtime.wasmExit": (sp) => {
263
+ sp >>>= 0;
264
+ const code = this.mem.getInt32(sp + 8, true);
265
+ this.exited = true;
266
+ delete this._inst;
267
+ delete this._values;
268
+ delete this._goRefCounts;
269
+ delete this._ids;
270
+ delete this._idPool;
271
+ this.exit(code);
272
+ },
273
+ // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
274
+ "runtime.wasmWrite": (sp) => {
275
+ sp >>>= 0;
276
+ const fd = getInt64(sp + 8);
277
+ const p = getInt64(sp + 16);
278
+ const n = this.mem.getInt32(sp + 24, true);
279
+ fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
280
+ },
281
+ // func resetMemoryDataView()
282
+ "runtime.resetMemoryDataView": (sp) => {
283
+ sp >>>= 0;
284
+ this.mem = new DataView(this._inst.exports.mem.buffer);
285
+ },
286
+ // func nanotime1() int64
287
+ "runtime.nanotime1": (sp) => {
288
+ sp >>>= 0;
289
+ setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);
290
+ },
291
+ // func walltime() (sec int64, nsec int32)
292
+ "runtime.walltime": (sp) => {
293
+ sp >>>= 0;
294
+ const msec = (/* @__PURE__ */ new Date()).getTime();
295
+ setInt64(sp + 8, msec / 1e3);
296
+ this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
297
+ },
298
+ // func scheduleTimeoutEvent(delay int64) int32
299
+ "runtime.scheduleTimeoutEvent": (sp) => {
300
+ sp >>>= 0;
301
+ const id = this._nextCallbackTimeoutID;
302
+ this._nextCallbackTimeoutID++;
303
+ this._scheduledTimeouts.set(id, setTimeout(
304
+ () => {
305
+ this._resume();
306
+ while (this._scheduledTimeouts.has(id)) {
307
+ console.warn("scheduleTimeoutEvent: missed timeout event");
308
+ this._resume();
309
+ }
310
+ },
311
+ getInt64(sp + 8)
312
+ ));
313
+ this.mem.setInt32(sp + 16, id, true);
314
+ },
315
+ // func clearTimeoutEvent(id int32)
316
+ "runtime.clearTimeoutEvent": (sp) => {
317
+ sp >>>= 0;
318
+ const id = this.mem.getInt32(sp + 8, true);
319
+ clearTimeout(this._scheduledTimeouts.get(id));
320
+ this._scheduledTimeouts.delete(id);
321
+ },
322
+ // func getRandomData(r []byte)
323
+ "runtime.getRandomData": (sp) => {
324
+ sp >>>= 0;
325
+ crypto.getRandomValues(loadSlice(sp + 8));
326
+ },
327
+ // func finalizeRef(v ref)
328
+ "syscall/js.finalizeRef": (sp) => {
329
+ sp >>>= 0;
330
+ const id = this.mem.getUint32(sp + 8, true);
331
+ this._goRefCounts[id]--;
332
+ if (this._goRefCounts[id] === 0) {
333
+ const v = this._values[id];
334
+ this._values[id] = null;
335
+ this._ids.delete(v);
336
+ this._idPool.push(id);
337
+ }
338
+ },
339
+ // func stringVal(value string) ref
340
+ "syscall/js.stringVal": (sp) => {
341
+ sp >>>= 0;
342
+ storeValue(sp + 24, loadString(sp + 8));
343
+ },
344
+ // func valueGet(v ref, p string) ref
345
+ "syscall/js.valueGet": (sp) => {
346
+ sp >>>= 0;
347
+ const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
348
+ sp = this._inst.exports.getsp() >>> 0;
349
+ storeValue(sp + 32, result);
350
+ },
351
+ // func valueSet(v ref, p string, x ref)
352
+ "syscall/js.valueSet": (sp) => {
353
+ sp >>>= 0;
354
+ Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
355
+ },
356
+ // func valueDelete(v ref, p string)
357
+ "syscall/js.valueDelete": (sp) => {
358
+ sp >>>= 0;
359
+ Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
360
+ },
361
+ // func valueIndex(v ref, i int) ref
362
+ "syscall/js.valueIndex": (sp) => {
363
+ sp >>>= 0;
364
+ storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
365
+ },
366
+ // valueSetIndex(v ref, i int, x ref)
367
+ "syscall/js.valueSetIndex": (sp) => {
368
+ sp >>>= 0;
369
+ Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
370
+ },
371
+ // func valueCall(v ref, m string, args []ref) (ref, bool)
372
+ "syscall/js.valueCall": (sp) => {
373
+ sp >>>= 0;
374
+ try {
375
+ const v = loadValue(sp + 8);
376
+ const m = Reflect.get(v, loadString(sp + 16));
377
+ const args = loadSliceOfValues(sp + 32);
378
+ const result = Reflect.apply(m, v, args);
379
+ sp = this._inst.exports.getsp() >>> 0;
380
+ storeValue(sp + 56, result);
381
+ this.mem.setUint8(sp + 64, 1);
382
+ } catch (err) {
383
+ sp = this._inst.exports.getsp() >>> 0;
384
+ storeValue(sp + 56, err);
385
+ this.mem.setUint8(sp + 64, 0);
386
+ }
387
+ },
388
+ // func valueInvoke(v ref, args []ref) (ref, bool)
389
+ "syscall/js.valueInvoke": (sp) => {
390
+ sp >>>= 0;
391
+ try {
392
+ const v = loadValue(sp + 8);
393
+ const args = loadSliceOfValues(sp + 16);
394
+ const result = Reflect.apply(v, void 0, args);
395
+ sp = this._inst.exports.getsp() >>> 0;
396
+ storeValue(sp + 40, result);
397
+ this.mem.setUint8(sp + 48, 1);
398
+ } catch (err) {
399
+ sp = this._inst.exports.getsp() >>> 0;
400
+ storeValue(sp + 40, err);
401
+ this.mem.setUint8(sp + 48, 0);
402
+ }
403
+ },
404
+ // func valueNew(v ref, args []ref) (ref, bool)
405
+ "syscall/js.valueNew": (sp) => {
406
+ sp >>>= 0;
407
+ try {
408
+ const v = loadValue(sp + 8);
409
+ const args = loadSliceOfValues(sp + 16);
410
+ const result = Reflect.construct(v, args);
411
+ sp = this._inst.exports.getsp() >>> 0;
412
+ storeValue(sp + 40, result);
413
+ this.mem.setUint8(sp + 48, 1);
414
+ } catch (err) {
415
+ sp = this._inst.exports.getsp() >>> 0;
416
+ storeValue(sp + 40, err);
417
+ this.mem.setUint8(sp + 48, 0);
418
+ }
419
+ },
420
+ // func valueLength(v ref) int
421
+ "syscall/js.valueLength": (sp) => {
422
+ sp >>>= 0;
423
+ setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
424
+ },
425
+ // valuePrepareString(v ref) (ref, int)
426
+ "syscall/js.valuePrepareString": (sp) => {
427
+ sp >>>= 0;
428
+ const str = encoder.encode(String(loadValue(sp + 8)));
429
+ storeValue(sp + 16, str);
430
+ setInt64(sp + 24, str.length);
431
+ },
432
+ // valueLoadString(v ref, b []byte)
433
+ "syscall/js.valueLoadString": (sp) => {
434
+ sp >>>= 0;
435
+ const str = loadValue(sp + 8);
436
+ loadSlice(sp + 16).set(str);
437
+ },
438
+ // func valueInstanceOf(v ref, t ref) bool
439
+ "syscall/js.valueInstanceOf": (sp) => {
440
+ sp >>>= 0;
441
+ this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);
442
+ },
443
+ // func copyBytesToGo(dst []byte, src ref) (int, bool)
444
+ "syscall/js.copyBytesToGo": (sp) => {
445
+ sp >>>= 0;
446
+ const dst = loadSlice(sp + 8);
447
+ const src = loadValue(sp + 32);
448
+ if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
449
+ this.mem.setUint8(sp + 48, 0);
450
+ return;
451
+ }
452
+ const toCopy = src.subarray(0, dst.length);
453
+ dst.set(toCopy);
454
+ setInt64(sp + 40, toCopy.length);
455
+ this.mem.setUint8(sp + 48, 1);
456
+ },
457
+ // func copyBytesToJS(dst ref, src []byte) (int, bool)
458
+ "syscall/js.copyBytesToJS": (sp) => {
459
+ sp >>>= 0;
460
+ const dst = loadValue(sp + 8);
461
+ const src = loadSlice(sp + 16);
462
+ if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
463
+ this.mem.setUint8(sp + 48, 0);
464
+ return;
465
+ }
466
+ const toCopy = src.subarray(0, dst.length);
467
+ dst.set(toCopy);
468
+ setInt64(sp + 40, toCopy.length);
469
+ this.mem.setUint8(sp + 48, 1);
470
+ },
471
+ "debug": (value) => {
472
+ console.log(value);
473
+ }
474
+ }
475
+ };
476
+ }
477
+ run(instance) {
478
+ return __async(this, null, function* () {
479
+ if (!(instance instanceof WebAssembly.Instance)) {
480
+ throw new Error("Go.run: WebAssembly.Instance expected");
481
+ }
482
+ this._inst = instance;
483
+ this.mem = new DataView(this._inst.exports.mem.buffer);
484
+ this._values = [
485
+ // JS values that Go currently has references to, indexed by reference id
486
+ NaN,
487
+ 0,
488
+ null,
489
+ true,
490
+ false,
491
+ globalThis,
492
+ this
493
+ ];
494
+ this._goRefCounts = new Array(this._values.length).fill(Infinity);
495
+ this._ids = /* @__PURE__ */ new Map([
496
+ // mapping from JS values to reference ids
497
+ [0, 1],
498
+ [null, 2],
499
+ [true, 3],
500
+ [false, 4],
501
+ [globalThis, 5],
502
+ [this, 6]
503
+ ]);
504
+ this._idPool = [];
505
+ this.exited = false;
506
+ let offset = 4096;
507
+ const strPtr = (str) => {
508
+ const ptr = offset;
509
+ const bytes = encoder.encode(str + "\0");
510
+ new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
511
+ offset += bytes.length;
512
+ if (offset % 8 !== 0) {
513
+ offset += 8 - offset % 8;
514
+ }
515
+ return ptr;
516
+ };
517
+ const argc = this.argv.length;
518
+ const argvPtrs = [];
519
+ this.argv.forEach((arg) => {
520
+ argvPtrs.push(strPtr(arg));
521
+ });
522
+ argvPtrs.push(0);
523
+ const keys = Object.keys(this.env).sort();
524
+ keys.forEach((key) => {
525
+ argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
526
+ });
527
+ argvPtrs.push(0);
528
+ const argv = offset;
529
+ argvPtrs.forEach((ptr) => {
530
+ this.mem.setUint32(offset, ptr, true);
531
+ this.mem.setUint32(offset + 4, 0, true);
532
+ offset += 8;
533
+ });
534
+ const wasmMinDataAddr = 4096 + 8192;
535
+ if (offset >= wasmMinDataAddr) {
536
+ throw new Error("total length of command line and environment variables exceeds limit");
537
+ }
538
+ this._inst.exports.run(argc, argv);
539
+ if (this.exited) {
540
+ this._resolveExitPromise();
541
+ }
542
+ yield this._exitPromise;
543
+ });
544
+ }
545
+ _resume() {
546
+ if (this.exited) {
547
+ throw new Error("Go program has already exited");
548
+ }
549
+ this._inst.exports.resume();
550
+ if (this.exited) {
551
+ this._resolveExitPromise();
552
+ }
553
+ }
554
+ _makeFuncWrapper(id) {
555
+ const go = this;
556
+ return function() {
557
+ const event = { id, this: this, args: arguments };
558
+ go._pendingEvent = event;
559
+ go._resume();
560
+ return event.result;
561
+ };
562
+ }
563
+ };
564
+ })();
@@ -1,4 +1,4 @@
1
- import { Ctx, TPregenIdentifierType, SignatureRes, WalletType } from '@getpara/core-sdk';
1
+ import { Ctx, TPregenIdentifierType, SignatureRes, TWalletType } from '@getpara/core-sdk';
2
2
  export declare function ed25519Keygen(ctx: Ctx, userId: string): Promise<{
3
3
  signer: string;
4
4
  walletId: string;
@@ -7,14 +7,12 @@ 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): Promise<{
11
- signature: string;
12
- }>;
13
- export declare function keygen(ctx: Ctx, userId: string, type: Exclude<WalletType, WalletType.SOLANA>, secretKey: string | null): Promise<{
10
+ export declare function ed25519Sign(ctx: Ctx, share: string, userId: string, walletId: string, base64Bytes: string): Promise<SignatureRes>;
11
+ export declare function keygen(ctx: Ctx, userId: string, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null): Promise<{
14
12
  signer: string;
15
13
  walletId: string;
16
14
  }>;
17
- export declare function preKeygen(ctx: Ctx, _partnerId: string | undefined, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<WalletType, WalletType.SOLANA>, secretKey: string | null): Promise<{
15
+ export declare function preKeygen(ctx: Ctx, _partnerId: string | undefined, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null): Promise<{
18
16
  signer: string;
19
17
  walletId: string;
20
18
  }>;