locuschain-lib 1.1.3 → 1.1.4
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/lclib-amd.js +775 -699
- package/dist/lclib-cjs.d.ts +5 -1
- package/dist/lclib-cjs.js +775 -699
- package/dist/lclib-esm.js +775 -699
- package/dist/lclib.d.mts +2 -0
- package/dist/lclib.json +7 -7
- package/package.json +29 -29
package/dist/lclib-esm.js
CHANGED
|
@@ -30,677 +30,731 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
30
30
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
/* eslint-disable */
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function toUint8Array
|
|
37
|
-
if (typeof atob ===
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
err
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
// },
|
|
170
|
-
//
|
|
171
|
-
// throw enosys();
|
|
172
|
-
// },
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (!globalThis.
|
|
188
|
-
throw new Error(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if (
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
const
|
|
306
|
-
const len = getInt64(addr + 8);
|
|
307
|
-
return
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
//
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
sp
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
this.
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
this.
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
this.
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
sp
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
this.
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
//
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
this.
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
33
|
+
/* eslint-disable */
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function toUint8Array(s) {
|
|
37
|
+
if (typeof atob === "function")
|
|
38
|
+
return new Uint8Array(atob(s).split("").map(charCodeAt));
|
|
39
|
+
// return (require('buf' + 'fer').Buffer).from(s, 'base64')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function charCodeAt(c) {
|
|
43
|
+
return c.charCodeAt(0);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const wasmJson = require("./lclib.json");
|
|
47
|
+
var wasm = toUint8Array(wasmJson.Base64);
|
|
48
|
+
|
|
49
|
+
(() => {
|
|
50
|
+
const enosys = () => {
|
|
51
|
+
const err = new Error("not implemented");
|
|
52
|
+
err.code = "ENOSYS";
|
|
53
|
+
return err;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (!globalThis.fs) {
|
|
57
|
+
let outputBuf = "";
|
|
58
|
+
globalThis.fs = {
|
|
59
|
+
constants: {
|
|
60
|
+
O_WRONLY: -1,
|
|
61
|
+
O_RDWR: -1,
|
|
62
|
+
O_CREAT: -1,
|
|
63
|
+
O_TRUNC: -1,
|
|
64
|
+
O_APPEND: -1,
|
|
65
|
+
O_EXCL: -1,
|
|
66
|
+
}, // unused
|
|
67
|
+
writeSync(fd, buf) {
|
|
68
|
+
outputBuf += decoder.decode(buf);
|
|
69
|
+
const nl = outputBuf.lastIndexOf("\n");
|
|
70
|
+
if (nl != -1) {
|
|
71
|
+
console.log(outputBuf.substring(0, nl));
|
|
72
|
+
outputBuf = outputBuf.substring(nl + 1);
|
|
73
|
+
}
|
|
74
|
+
return buf.length;
|
|
75
|
+
},
|
|
76
|
+
write(fd, buf, offset, length, position, callback) {
|
|
77
|
+
if (offset !== 0 || length !== buf.length || position !== null) {
|
|
78
|
+
callback(enosys());
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const n = this.writeSync(fd, buf);
|
|
82
|
+
callback(null, n);
|
|
83
|
+
},
|
|
84
|
+
chmod(path, mode, callback) {
|
|
85
|
+
callback(enosys());
|
|
86
|
+
},
|
|
87
|
+
chown(path, uid, gid, callback) {
|
|
88
|
+
callback(enosys());
|
|
89
|
+
},
|
|
90
|
+
close(fd, callback) {
|
|
91
|
+
callback(enosys());
|
|
92
|
+
},
|
|
93
|
+
fchmod(fd, mode, callback) {
|
|
94
|
+
callback(enosys());
|
|
95
|
+
},
|
|
96
|
+
fchown(fd, uid, gid, callback) {
|
|
97
|
+
callback(enosys());
|
|
98
|
+
},
|
|
99
|
+
fstat(fd, callback) {
|
|
100
|
+
callback(enosys());
|
|
101
|
+
},
|
|
102
|
+
fsync(fd, callback) {
|
|
103
|
+
callback(null);
|
|
104
|
+
},
|
|
105
|
+
ftruncate(fd, length, callback) {
|
|
106
|
+
callback(enosys());
|
|
107
|
+
},
|
|
108
|
+
lchown(path, uid, gid, callback) {
|
|
109
|
+
callback(enosys());
|
|
110
|
+
},
|
|
111
|
+
link(path, link, callback) {
|
|
112
|
+
callback(enosys());
|
|
113
|
+
},
|
|
114
|
+
lstat(path, callback) {
|
|
115
|
+
callback(enosys());
|
|
116
|
+
},
|
|
117
|
+
mkdir(path, perm, callback) {
|
|
118
|
+
callback(enosys());
|
|
119
|
+
},
|
|
120
|
+
open(path, flags, mode, callback) {
|
|
121
|
+
callback(enosys());
|
|
122
|
+
},
|
|
123
|
+
read(fd, buffer, offset, length, position, callback) {
|
|
124
|
+
callback(enosys());
|
|
125
|
+
},
|
|
126
|
+
readdir(path, callback) {
|
|
127
|
+
callback(enosys());
|
|
128
|
+
},
|
|
129
|
+
readlink(path, callback) {
|
|
130
|
+
callback(enosys());
|
|
131
|
+
},
|
|
132
|
+
rename(from, to, callback) {
|
|
133
|
+
callback(enosys());
|
|
134
|
+
},
|
|
135
|
+
rmdir(path, callback) {
|
|
136
|
+
callback(enosys());
|
|
137
|
+
},
|
|
138
|
+
stat(path, callback) {
|
|
139
|
+
callback(enosys());
|
|
140
|
+
},
|
|
141
|
+
symlink(path, link, callback) {
|
|
142
|
+
callback(enosys());
|
|
143
|
+
},
|
|
144
|
+
truncate(path, length, callback) {
|
|
145
|
+
callback(enosys());
|
|
146
|
+
},
|
|
147
|
+
unlink(path, callback) {
|
|
148
|
+
callback(enosys());
|
|
149
|
+
},
|
|
150
|
+
utimes(path, atime, mtime, callback) {
|
|
151
|
+
callback(enosys());
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// if (!globalThis.process) {
|
|
157
|
+
// globalThis.process = {
|
|
158
|
+
// getuid() {
|
|
159
|
+
// return -1;
|
|
160
|
+
// },
|
|
161
|
+
// getgid() {
|
|
162
|
+
// return -1;
|
|
163
|
+
// },
|
|
164
|
+
// geteuid() {
|
|
165
|
+
// return -1;
|
|
166
|
+
// },
|
|
167
|
+
// getegid() {
|
|
168
|
+
// return -1;
|
|
169
|
+
// },
|
|
170
|
+
// getgroups() {
|
|
171
|
+
// throw enosys();
|
|
172
|
+
// },
|
|
173
|
+
// pid: -1,
|
|
174
|
+
// ppid: -1,
|
|
175
|
+
// umask() {
|
|
176
|
+
// throw enosys();
|
|
177
|
+
// },
|
|
178
|
+
// cwd() {
|
|
179
|
+
// throw enosys();
|
|
180
|
+
// },
|
|
181
|
+
// chdir() {
|
|
182
|
+
// throw enosys();
|
|
183
|
+
// }
|
|
184
|
+
// };
|
|
185
|
+
// }
|
|
186
|
+
|
|
187
|
+
if (!globalThis.crypto) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
"globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)"
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!globalThis.performance) {
|
|
194
|
+
throw new Error(
|
|
195
|
+
"globalThis.performance is not available, polyfill required (performance.now only)"
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!globalThis.TextEncoder) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
"globalThis.TextEncoder is not available, polyfill required"
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (!globalThis.TextDecoder) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
"globalThis.TextDecoder is not available, polyfill required"
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const encoder = new TextEncoder("utf-8");
|
|
212
|
+
const decoder = new TextDecoder("utf-8");
|
|
213
|
+
|
|
214
|
+
globalThis.Go = class {
|
|
215
|
+
constructor() {
|
|
216
|
+
this.argv = ["js"];
|
|
217
|
+
this.env = {};
|
|
218
|
+
this.exit = (code) => {
|
|
219
|
+
if (code !== 0) {
|
|
220
|
+
console.warn("exit code:", code);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
this._exitPromise = new Promise((resolve) => {
|
|
224
|
+
this._resolveExitPromise = resolve;
|
|
225
|
+
});
|
|
226
|
+
this._pendingEvent = null;
|
|
227
|
+
this._scheduledTimeouts = new Map();
|
|
228
|
+
this._nextCallbackTimeoutID = 1;
|
|
229
|
+
|
|
230
|
+
const setInt64 = (addr, v) => {
|
|
231
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
232
|
+
this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const getInt64 = (addr) => {
|
|
236
|
+
const low = this.mem.getUint32(addr + 0, true);
|
|
237
|
+
const high = this.mem.getInt32(addr + 4, true);
|
|
238
|
+
return low + high * 4294967296;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const loadValue = (addr) => {
|
|
242
|
+
const f = this.mem.getFloat64(addr, true);
|
|
243
|
+
if (f === 0) {
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
if (!isNaN(f)) {
|
|
247
|
+
return f;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const id = this.mem.getUint32(addr, true);
|
|
251
|
+
return this._values[id];
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const storeValue = (addr, v) => {
|
|
255
|
+
const nanHead = 0x7ff80000;
|
|
256
|
+
|
|
257
|
+
if (typeof v === "number" && v !== 0) {
|
|
258
|
+
if (isNaN(v)) {
|
|
259
|
+
this.mem.setUint32(addr + 4, nanHead, true);
|
|
260
|
+
this.mem.setUint32(addr, 0, true);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
this.mem.setFloat64(addr, v, true);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (v === undefined) {
|
|
268
|
+
this.mem.setFloat64(addr, 0, true);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
let id = this._ids.get(v);
|
|
273
|
+
if (id === undefined) {
|
|
274
|
+
id = this._idPool.pop();
|
|
275
|
+
if (id === undefined) {
|
|
276
|
+
id = this._values.length;
|
|
277
|
+
}
|
|
278
|
+
this._values[id] = v;
|
|
279
|
+
this._goRefCounts[id] = 0;
|
|
280
|
+
this._ids.set(v, id);
|
|
281
|
+
}
|
|
282
|
+
this._goRefCounts[id]++;
|
|
283
|
+
let typeFlag = 0;
|
|
284
|
+
switch (typeof v) {
|
|
285
|
+
case "object":
|
|
286
|
+
if (v !== null) {
|
|
287
|
+
typeFlag = 1;
|
|
288
|
+
}
|
|
289
|
+
break;
|
|
290
|
+
case "string":
|
|
291
|
+
typeFlag = 2;
|
|
292
|
+
break;
|
|
293
|
+
case "symbol":
|
|
294
|
+
typeFlag = 3;
|
|
295
|
+
break;
|
|
296
|
+
case "function":
|
|
297
|
+
typeFlag = 4;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
|
|
301
|
+
this.mem.setUint32(addr, id, true);
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const loadSlice = (addr) => {
|
|
305
|
+
const array = getInt64(addr + 0);
|
|
306
|
+
const len = getInt64(addr + 8);
|
|
307
|
+
return new Uint8Array(this._inst.exports.mem.buffer, array, len);
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const loadSliceOfValues = (addr) => {
|
|
311
|
+
const array = getInt64(addr + 0);
|
|
312
|
+
const len = getInt64(addr + 8);
|
|
313
|
+
const a = new Array(len);
|
|
314
|
+
for (let i = 0; i < len; i++) {
|
|
315
|
+
a[i] = loadValue(array + i * 8);
|
|
316
|
+
}
|
|
317
|
+
return a;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const loadString = (addr) => {
|
|
321
|
+
const saddr = getInt64(addr + 0);
|
|
322
|
+
const len = getInt64(addr + 8);
|
|
323
|
+
return decoder.decode(
|
|
324
|
+
new DataView(this._inst.exports.mem.buffer, saddr, len)
|
|
325
|
+
);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const timeOrigin = Date.now() - performance.now();
|
|
329
|
+
this.importObject = {
|
|
330
|
+
_gotest: {
|
|
331
|
+
add: (a, b) => a + b,
|
|
332
|
+
},
|
|
333
|
+
gojs: {
|
|
334
|
+
// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
|
|
335
|
+
// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
|
|
336
|
+
// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
|
|
337
|
+
// This changes the SP, thus we have to update the SP used by the imported function.
|
|
338
|
+
|
|
339
|
+
// func wasmExit(code int32)
|
|
340
|
+
"runtime.wasmExit": (sp) => {
|
|
341
|
+
sp >>>= 0;
|
|
342
|
+
const code = this.mem.getInt32(sp + 8, true);
|
|
343
|
+
this.exited = true;
|
|
344
|
+
delete this._inst;
|
|
345
|
+
delete this._values;
|
|
346
|
+
delete this._goRefCounts;
|
|
347
|
+
delete this._ids;
|
|
348
|
+
delete this._idPool;
|
|
349
|
+
this.exit(code);
|
|
350
|
+
},
|
|
351
|
+
|
|
352
|
+
// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
|
|
353
|
+
"runtime.wasmWrite": (sp) => {
|
|
354
|
+
sp >>>= 0;
|
|
355
|
+
const fd = getInt64(sp + 8);
|
|
356
|
+
const p = getInt64(sp + 16);
|
|
357
|
+
const n = this.mem.getInt32(sp + 24, true);
|
|
358
|
+
fs.writeSync(
|
|
359
|
+
fd,
|
|
360
|
+
new Uint8Array(this._inst.exports.mem.buffer, p, n)
|
|
361
|
+
);
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
// func resetMemoryDataView()
|
|
365
|
+
"runtime.resetMemoryDataView": (sp) => {
|
|
366
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
// func nanotime1() int64
|
|
370
|
+
"runtime.nanotime1": (sp) => {
|
|
371
|
+
sp >>>= 0;
|
|
372
|
+
setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
// func walltime() (sec int64, nsec int32)
|
|
376
|
+
"runtime.walltime": (sp) => {
|
|
377
|
+
sp >>>= 0;
|
|
378
|
+
const msec = new Date().getTime();
|
|
379
|
+
setInt64(sp + 8, msec / 1000);
|
|
380
|
+
this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);
|
|
381
|
+
},
|
|
382
|
+
|
|
383
|
+
// func scheduleTimeoutEvent(delay int64) int32
|
|
384
|
+
"runtime.scheduleTimeoutEvent": (sp) => {
|
|
385
|
+
sp >>>= 0;
|
|
386
|
+
const id = this._nextCallbackTimeoutID;
|
|
387
|
+
this._nextCallbackTimeoutID++;
|
|
388
|
+
this._scheduledTimeouts.set(
|
|
389
|
+
id,
|
|
390
|
+
setTimeout(() => {
|
|
391
|
+
this._resume();
|
|
392
|
+
while (this._scheduledTimeouts.has(id)) {
|
|
393
|
+
// for some reason Go failed to register the timeout event, log and try again
|
|
394
|
+
// (temporary workaround for https://github.com/golang/go/issues/28975)
|
|
395
|
+
console.warn("scheduleTimeoutEvent: missed timeout event");
|
|
396
|
+
this._resume();
|
|
397
|
+
}
|
|
398
|
+
}, getInt64(sp + 8))
|
|
399
|
+
);
|
|
400
|
+
this.mem.setInt32(sp + 16, id, true);
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
// func clearTimeoutEvent(id int32)
|
|
404
|
+
"runtime.clearTimeoutEvent": (sp) => {
|
|
405
|
+
sp >>>= 0;
|
|
406
|
+
const id = this.mem.getInt32(sp + 8, true);
|
|
407
|
+
clearTimeout(this._scheduledTimeouts.get(id));
|
|
408
|
+
this._scheduledTimeouts.delete(id);
|
|
409
|
+
},
|
|
410
|
+
|
|
411
|
+
// func getRandomData(r []byte)
|
|
412
|
+
"runtime.getRandomData": (sp) => {
|
|
413
|
+
sp >>>= 0;
|
|
414
|
+
crypto.getRandomValues(loadSlice(sp + 8));
|
|
415
|
+
},
|
|
416
|
+
|
|
417
|
+
// func finalizeRef(v ref)
|
|
418
|
+
"syscall/js.finalizeRef": (sp) => {
|
|
419
|
+
sp >>>= 0;
|
|
420
|
+
const id = this.mem.getUint32(sp + 8, true);
|
|
421
|
+
this._goRefCounts[id]--;
|
|
422
|
+
if (this._goRefCounts[id] === 0) {
|
|
423
|
+
const v = this._values[id];
|
|
424
|
+
this._values[id] = null;
|
|
425
|
+
this._ids.delete(v);
|
|
426
|
+
this._idPool.push(id);
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
|
|
430
|
+
// func stringVal(value string) ref
|
|
431
|
+
"syscall/js.stringVal": (sp) => {
|
|
432
|
+
sp >>>= 0;
|
|
433
|
+
storeValue(sp + 24, loadString(sp + 8));
|
|
434
|
+
},
|
|
435
|
+
|
|
436
|
+
// func valueGet(v ref, p string) ref
|
|
437
|
+
"syscall/js.valueGet": (sp) => {
|
|
438
|
+
sp >>>= 0;
|
|
439
|
+
const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
|
|
440
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
441
|
+
storeValue(sp + 32, result);
|
|
442
|
+
},
|
|
443
|
+
|
|
444
|
+
// func valueSet(v ref, p string, x ref)
|
|
445
|
+
"syscall/js.valueSet": (sp) => {
|
|
446
|
+
sp >>>= 0;
|
|
447
|
+
Reflect.set(
|
|
448
|
+
loadValue(sp + 8),
|
|
449
|
+
loadString(sp + 16),
|
|
450
|
+
loadValue(sp + 32)
|
|
451
|
+
);
|
|
452
|
+
},
|
|
453
|
+
|
|
454
|
+
// func valueDelete(v ref, p string)
|
|
455
|
+
"syscall/js.valueDelete": (sp) => {
|
|
456
|
+
sp >>>= 0;
|
|
457
|
+
Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
|
|
458
|
+
},
|
|
459
|
+
|
|
460
|
+
// func valueIndex(v ref, i int) ref
|
|
461
|
+
"syscall/js.valueIndex": (sp) => {
|
|
462
|
+
sp >>>= 0;
|
|
463
|
+
storeValue(
|
|
464
|
+
sp + 24,
|
|
465
|
+
Reflect.get(loadValue(sp + 8), getInt64(sp + 16))
|
|
466
|
+
);
|
|
467
|
+
},
|
|
468
|
+
|
|
469
|
+
// valueSetIndex(v ref, i int, x ref)
|
|
470
|
+
"syscall/js.valueSetIndex": (sp) => {
|
|
471
|
+
sp >>>= 0;
|
|
472
|
+
Reflect.set(
|
|
473
|
+
loadValue(sp + 8),
|
|
474
|
+
getInt64(sp + 16),
|
|
475
|
+
loadValue(sp + 24)
|
|
476
|
+
);
|
|
477
|
+
},
|
|
478
|
+
|
|
479
|
+
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
|
480
|
+
"syscall/js.valueCall": (sp) => {
|
|
481
|
+
sp >>>= 0;
|
|
482
|
+
try {
|
|
483
|
+
const v = loadValue(sp + 8);
|
|
484
|
+
const m = Reflect.get(v, loadString(sp + 16));
|
|
485
|
+
const args = loadSliceOfValues(sp + 32);
|
|
486
|
+
const result = Reflect.apply(m, v, args);
|
|
487
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
488
|
+
storeValue(sp + 56, result);
|
|
489
|
+
this.mem.setUint8(sp + 64, 1);
|
|
490
|
+
} catch (err) {
|
|
491
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
492
|
+
storeValue(sp + 56, err);
|
|
493
|
+
this.mem.setUint8(sp + 64, 0);
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
|
|
497
|
+
// func valueInvoke(v ref, args []ref) (ref, bool)
|
|
498
|
+
"syscall/js.valueInvoke": (sp) => {
|
|
499
|
+
sp >>>= 0;
|
|
500
|
+
try {
|
|
501
|
+
const v = loadValue(sp + 8);
|
|
502
|
+
const args = loadSliceOfValues(sp + 16);
|
|
503
|
+
const result = Reflect.apply(v, undefined, args);
|
|
504
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
505
|
+
storeValue(sp + 40, result);
|
|
506
|
+
this.mem.setUint8(sp + 48, 1);
|
|
507
|
+
} catch (err) {
|
|
508
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
509
|
+
storeValue(sp + 40, err);
|
|
510
|
+
this.mem.setUint8(sp + 48, 0);
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
|
|
514
|
+
// func valueNew(v ref, args []ref) (ref, bool)
|
|
515
|
+
"syscall/js.valueNew": (sp) => {
|
|
516
|
+
sp >>>= 0;
|
|
517
|
+
try {
|
|
518
|
+
const v = loadValue(sp + 8);
|
|
519
|
+
const args = loadSliceOfValues(sp + 16);
|
|
520
|
+
const result = Reflect.construct(v, args);
|
|
521
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
522
|
+
storeValue(sp + 40, result);
|
|
523
|
+
this.mem.setUint8(sp + 48, 1);
|
|
524
|
+
} catch (err) {
|
|
525
|
+
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
526
|
+
storeValue(sp + 40, err);
|
|
527
|
+
this.mem.setUint8(sp + 48, 0);
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
|
|
531
|
+
// func valueLength(v ref) int
|
|
532
|
+
"syscall/js.valueLength": (sp) => {
|
|
533
|
+
sp >>>= 0;
|
|
534
|
+
setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
|
|
535
|
+
},
|
|
536
|
+
|
|
537
|
+
// valuePrepareString(v ref) (ref, int)
|
|
538
|
+
"syscall/js.valuePrepareString": (sp) => {
|
|
539
|
+
sp >>>= 0;
|
|
540
|
+
const str = encoder.encode(String(loadValue(sp + 8)));
|
|
541
|
+
storeValue(sp + 16, str);
|
|
542
|
+
setInt64(sp + 24, str.length);
|
|
543
|
+
},
|
|
544
|
+
|
|
545
|
+
// valueLoadString(v ref, b []byte)
|
|
546
|
+
"syscall/js.valueLoadString": (sp) => {
|
|
547
|
+
sp >>>= 0;
|
|
548
|
+
const str = loadValue(sp + 8);
|
|
549
|
+
loadSlice(sp + 16).set(str);
|
|
550
|
+
},
|
|
551
|
+
|
|
552
|
+
// func valueInstanceOf(v ref, t ref) bool
|
|
553
|
+
"syscall/js.valueInstanceOf": (sp) => {
|
|
554
|
+
sp >>>= 0;
|
|
555
|
+
this.mem.setUint8(
|
|
556
|
+
sp + 24,
|
|
557
|
+
loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0
|
|
558
|
+
);
|
|
559
|
+
},
|
|
560
|
+
|
|
561
|
+
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
|
562
|
+
"syscall/js.copyBytesToGo": (sp) => {
|
|
563
|
+
sp >>>= 0;
|
|
564
|
+
const dst = loadSlice(sp + 8);
|
|
565
|
+
const src = loadValue(sp + 32);
|
|
566
|
+
if (
|
|
567
|
+
!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)
|
|
568
|
+
) {
|
|
569
|
+
this.mem.setUint8(sp + 48, 0);
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const toCopy = src.subarray(0, dst.length);
|
|
573
|
+
dst.set(toCopy);
|
|
574
|
+
setInt64(sp + 40, toCopy.length);
|
|
575
|
+
this.mem.setUint8(sp + 48, 1);
|
|
576
|
+
},
|
|
577
|
+
|
|
578
|
+
// func copyBytesToJS(dst ref, src []byte) (int, bool)
|
|
579
|
+
"syscall/js.copyBytesToJS": (sp) => {
|
|
580
|
+
sp >>>= 0;
|
|
581
|
+
const dst = loadValue(sp + 8);
|
|
582
|
+
const src = loadSlice(sp + 16);
|
|
583
|
+
if (
|
|
584
|
+
!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)
|
|
585
|
+
) {
|
|
586
|
+
this.mem.setUint8(sp + 48, 0);
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
const toCopy = src.subarray(0, dst.length);
|
|
590
|
+
dst.set(toCopy);
|
|
591
|
+
setInt64(sp + 40, toCopy.length);
|
|
592
|
+
this.mem.setUint8(sp + 48, 1);
|
|
593
|
+
},
|
|
594
|
+
|
|
595
|
+
debug: (value) => {
|
|
596
|
+
console.log(value);
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
async run(instance) {
|
|
603
|
+
if (!(instance instanceof WebAssembly.Instance)) {
|
|
604
|
+
throw new Error("Go.run: WebAssembly.Instance expected");
|
|
605
|
+
}
|
|
606
|
+
this._inst = instance;
|
|
607
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
608
|
+
this._values = [
|
|
609
|
+
// JS values that Go currently has references to, indexed by reference id
|
|
610
|
+
NaN,
|
|
611
|
+
0,
|
|
612
|
+
null,
|
|
613
|
+
true,
|
|
614
|
+
false,
|
|
615
|
+
globalThis,
|
|
616
|
+
this,
|
|
617
|
+
];
|
|
618
|
+
this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id
|
|
619
|
+
this._ids = new Map([
|
|
620
|
+
// mapping from JS values to reference ids
|
|
621
|
+
[0, 1],
|
|
622
|
+
[null, 2],
|
|
623
|
+
[true, 3],
|
|
624
|
+
[false, 4],
|
|
625
|
+
[globalThis, 5],
|
|
626
|
+
[this, 6],
|
|
627
|
+
]);
|
|
628
|
+
this._idPool = []; // unused ids that have been garbage collected
|
|
629
|
+
this.exited = false; // whether the Go program has exited
|
|
630
|
+
|
|
631
|
+
// Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.
|
|
632
|
+
let offset = 4096;
|
|
633
|
+
|
|
634
|
+
const strPtr = (str) => {
|
|
635
|
+
const ptr = offset;
|
|
636
|
+
const bytes = encoder.encode(str + "\0");
|
|
637
|
+
new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
|
|
638
|
+
offset += bytes.length;
|
|
639
|
+
if (offset % 8 !== 0) {
|
|
640
|
+
offset += 8 - (offset % 8);
|
|
641
|
+
}
|
|
642
|
+
return ptr;
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
const argc = this.argv.length;
|
|
646
|
+
|
|
647
|
+
const argvPtrs = [];
|
|
648
|
+
this.argv.forEach((arg) => {
|
|
649
|
+
argvPtrs.push(strPtr(arg));
|
|
650
|
+
});
|
|
651
|
+
argvPtrs.push(0);
|
|
652
|
+
|
|
653
|
+
const keys = Object.keys(this.env).sort();
|
|
654
|
+
keys.forEach((key) => {
|
|
655
|
+
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
|
|
656
|
+
});
|
|
657
|
+
argvPtrs.push(0);
|
|
658
|
+
|
|
659
|
+
const argv = offset;
|
|
660
|
+
argvPtrs.forEach((ptr) => {
|
|
661
|
+
this.mem.setUint32(offset, ptr, true);
|
|
662
|
+
this.mem.setUint32(offset + 4, 0, true);
|
|
663
|
+
offset += 8;
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
// The linker guarantees global data starts from at least wasmMinDataAddr.
|
|
667
|
+
// Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
|
|
668
|
+
const wasmMinDataAddr = 4096 + 8192;
|
|
669
|
+
if (offset >= wasmMinDataAddr) {
|
|
670
|
+
throw new Error(
|
|
671
|
+
"total length of command line and environment variables exceeds limit"
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
this._inst.exports.run(argc, argv);
|
|
676
|
+
if (this.exited) {
|
|
677
|
+
this._resolveExitPromise();
|
|
678
|
+
}
|
|
679
|
+
await this._exitPromise;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
_resume() {
|
|
683
|
+
if (this.exited) {
|
|
684
|
+
throw new Error("Go program has already exited");
|
|
685
|
+
}
|
|
686
|
+
this._inst.exports.resume();
|
|
687
|
+
if (this.exited) {
|
|
688
|
+
this._resolveExitPromise();
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
_makeFuncWrapper(id) {
|
|
693
|
+
const go = this;
|
|
694
|
+
return function () {
|
|
695
|
+
const event = { id: id, this: this, args: arguments };
|
|
696
|
+
go._pendingEvent = event;
|
|
697
|
+
go._resume();
|
|
698
|
+
return event.result;
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
})();
|
|
703
|
+
|
|
704
|
+
((function () {
|
|
705
|
+
try {
|
|
706
|
+
if (
|
|
707
|
+
typeof WebAssembly === "object" &&
|
|
708
|
+
typeof WebAssembly.instantiate === "function"
|
|
709
|
+
) {
|
|
710
|
+
const module = new WebAssembly.Module(
|
|
711
|
+
Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)
|
|
712
|
+
);
|
|
713
|
+
if (module instanceof WebAssembly.Module) {
|
|
714
|
+
return new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
} catch (e) {}
|
|
718
|
+
return false;
|
|
719
|
+
}))();
|
|
720
|
+
|
|
721
|
+
const go = new Go();
|
|
722
|
+
let locuschainLibLoaded = false;
|
|
723
|
+
function loadLocusLibrary() {
|
|
724
|
+
return new Promise((resolve, reject) => {
|
|
725
|
+
WebAssembly.instantiate(wasm, go.importObject)
|
|
726
|
+
.then((result) => {
|
|
727
|
+
go.run(result.instance);
|
|
728
|
+
locuschainLibLoaded = true;
|
|
729
|
+
resolve();
|
|
730
|
+
})
|
|
731
|
+
.catch((err) => {
|
|
732
|
+
console.error("err:", err);
|
|
733
|
+
reject();
|
|
734
|
+
});
|
|
735
|
+
});
|
|
689
736
|
}
|
|
690
737
|
|
|
691
|
-
loadLocusLibrary().then((res) => {
|
|
692
|
-
});
|
|
738
|
+
loadLocusLibrary().then((res) => { });
|
|
693
739
|
class LocusLib {
|
|
694
740
|
static callWasm(wasmCmd, wasmParams) {
|
|
695
741
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
742
|
+
if (!locuschainLibLoaded) {
|
|
743
|
+
for (let i = 0; i < 1000; i++) {
|
|
744
|
+
yield LocusLib.sleep(100);
|
|
745
|
+
if (locuschainLibLoaded) {
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
696
750
|
if (Array.isArray(wasmParams)) {
|
|
697
751
|
wasmParams = wasmParams[0];
|
|
698
752
|
}
|
|
699
753
|
// @ts-ignore
|
|
700
|
-
if (typeof globalThis[
|
|
754
|
+
if (typeof globalThis["CallLclib"] !== "function")
|
|
701
755
|
return;
|
|
702
756
|
// @ts-ignore
|
|
703
|
-
const resultString = yield globalThis[
|
|
757
|
+
const resultString = yield globalThis["CallLclib"](wasmCmd, JSON.stringify(wasmParams));
|
|
704
758
|
const result = JSON.parse(resultString);
|
|
705
759
|
if (result.Error && result.Error.Code != 0) {
|
|
706
760
|
const error = Object.assign(Object.assign({}, result.Error), { message: result.Error.Message });
|
|
@@ -713,124 +767,146 @@ class LocusLib {
|
|
|
713
767
|
}));
|
|
714
768
|
}
|
|
715
769
|
//=================================================================================
|
|
770
|
+
static GetLibInfo() {
|
|
771
|
+
return wasmJson;
|
|
772
|
+
}
|
|
716
773
|
static GetLibraryVersions() {
|
|
717
|
-
return LocusLib.callWasm(
|
|
774
|
+
return LocusLib.callWasm("GetLibraryVersions", {});
|
|
718
775
|
}
|
|
719
776
|
static CreateAccountAndKeystore(passwordMaster, passwordNormal, mkeyAlgoNormal, nkeyAlgoNormal) {
|
|
720
|
-
return LocusLib.callWasm(
|
|
777
|
+
return LocusLib.callWasm("CreateAccountAndKeystore", {
|
|
721
778
|
passwordMaster,
|
|
722
779
|
passwordNormal,
|
|
723
780
|
mkeyAlgoNormal,
|
|
724
|
-
nkeyAlgoNormal
|
|
781
|
+
nkeyAlgoNormal,
|
|
725
782
|
});
|
|
726
783
|
}
|
|
727
784
|
static CreateNormalKey(addrStr, keyAlgo) {
|
|
728
|
-
return LocusLib.callWasm(
|
|
785
|
+
return LocusLib.callWasm("CreateNormalKey", { addrStr, keyAlgo });
|
|
729
786
|
}
|
|
730
787
|
static CreateMasterKeystore(AddrStr, Password, MskStr, MpkStr) {
|
|
731
|
-
return LocusLib.callWasm(
|
|
788
|
+
return LocusLib.callWasm("CreateMasterKeystore", {
|
|
789
|
+
AddrStr,
|
|
790
|
+
Password,
|
|
791
|
+
MskStr,
|
|
792
|
+
MpkStr,
|
|
793
|
+
});
|
|
732
794
|
}
|
|
733
|
-
static CreateNormalKeystore(AddrStr, Password, NskStr, NpkStr, MpkStr =
|
|
734
|
-
return LocusLib.callWasm(
|
|
795
|
+
static CreateNormalKeystore(AddrStr, Password, NskStr, NpkStr, MpkStr = "", KeySign = "") {
|
|
796
|
+
return LocusLib.callWasm("CreateNormalKeystore", {
|
|
797
|
+
AddrStr,
|
|
798
|
+
Password,
|
|
799
|
+
NskStr,
|
|
800
|
+
NpkStr,
|
|
801
|
+
MpkStr,
|
|
802
|
+
KeySign,
|
|
803
|
+
});
|
|
735
804
|
}
|
|
736
805
|
static LoadMasterKeystore(PassStr, KsJson) {
|
|
737
|
-
return LocusLib.callWasm(
|
|
806
|
+
return LocusLib.callWasm("LoadMasterKeystore", { PassStr, KsJson });
|
|
738
807
|
}
|
|
739
808
|
static LoadNormalKeystore(PassStr, KsJson) {
|
|
740
|
-
return LocusLib.callWasm(
|
|
809
|
+
return LocusLib.callWasm("LoadNormalKeystore", { PassStr, KsJson });
|
|
741
810
|
}
|
|
742
811
|
static ConvertToData(value, valueType) {
|
|
743
|
-
return LocusLib.callWasm(
|
|
812
|
+
return LocusLib.callWasm("ConvertToData", { value, valueType });
|
|
744
813
|
}
|
|
745
814
|
static ConvertDataTo(dataString, retType) {
|
|
746
|
-
return LocusLib.callWasm(
|
|
815
|
+
return LocusLib.callWasm("ConvertDataTo", { dataString, retType });
|
|
747
816
|
}
|
|
748
817
|
static ConvertStringToData(str) {
|
|
749
|
-
return LocusLib.callWasm(
|
|
818
|
+
return LocusLib.callWasm("ConvertStringToData", str);
|
|
750
819
|
}
|
|
751
820
|
static ConvertDataToString(dataString) {
|
|
752
|
-
return LocusLib.callWasm(
|
|
821
|
+
return LocusLib.callWasm("ConvertDataToString", dataString);
|
|
753
822
|
}
|
|
754
823
|
static ConvertAddressToHex(addr) {
|
|
755
|
-
return LocusLib.callWasm(
|
|
824
|
+
return LocusLib.callWasm("ConvertAddressToHex", addr);
|
|
756
825
|
}
|
|
757
826
|
static ConvertHexToAddress(hexString) {
|
|
758
|
-
return LocusLib.callWasm(
|
|
827
|
+
return LocusLib.callWasm("ConvertHexToAddress", hexString);
|
|
759
828
|
}
|
|
760
829
|
static ConvertAddressToData(addr) {
|
|
761
|
-
return LocusLib.callWasm(
|
|
830
|
+
return LocusLib.callWasm("ConvertAddressToData", addr);
|
|
762
831
|
}
|
|
763
832
|
static ConvertDataToAddress(dataString) {
|
|
764
|
-
return LocusLib.callWasm(
|
|
833
|
+
return LocusLib.callWasm("ConvertDataToAddress", dataString);
|
|
765
834
|
}
|
|
766
835
|
static ConvertBase32ToHex(encoded) {
|
|
767
|
-
return LocusLib.callWasm(
|
|
836
|
+
return LocusLib.callWasm("ConvertBase32ToHex", encoded);
|
|
768
837
|
}
|
|
769
838
|
static ConvertHexToBase32(hexString) {
|
|
770
|
-
return LocusLib.callWasm(
|
|
839
|
+
return LocusLib.callWasm("ConvertHexToBase32", hexString);
|
|
771
840
|
}
|
|
772
841
|
static ConvertHexToData(encoded) {
|
|
773
|
-
return LocusLib.callWasm(
|
|
842
|
+
return LocusLib.callWasm("ConvertHexToData", encoded);
|
|
774
843
|
}
|
|
775
844
|
static ConvertDataToHex(dataString) {
|
|
776
|
-
return LocusLib.callWasm(
|
|
845
|
+
return LocusLib.callWasm("ConvertDataToHex", dataString);
|
|
777
846
|
}
|
|
778
847
|
static ConvertBase32ToData(encoded) {
|
|
779
|
-
return LocusLib.callWasm(
|
|
848
|
+
return LocusLib.callWasm("ConvertBase32ToData", encoded);
|
|
780
849
|
}
|
|
781
850
|
static ConvertDataToBase32(dataString) {
|
|
782
|
-
return LocusLib.callWasm(
|
|
851
|
+
return LocusLib.callWasm("ConvertDataToBase32", dataString);
|
|
783
852
|
}
|
|
784
853
|
static SignByMasterKey(Msk, Message) {
|
|
785
|
-
return LocusLib.callWasm(
|
|
854
|
+
return LocusLib.callWasm("SignByMasterKey", { Msk, Message });
|
|
786
855
|
}
|
|
787
856
|
static Sign(Sk, Message) {
|
|
788
|
-
return LocusLib.callWasm(
|
|
857
|
+
return LocusLib.callWasm("Sign", { Sk, Message });
|
|
789
858
|
}
|
|
790
859
|
static Verify(Pk, Message, Sig) {
|
|
791
|
-
return LocusLib.callWasm(
|
|
860
|
+
return LocusLib.callWasm("Verify", { Pk, Message, Sig });
|
|
792
861
|
}
|
|
793
862
|
static VerifyTx(jsonTx) {
|
|
794
|
-
return LocusLib.callWasm(
|
|
863
|
+
return LocusLib.callWasm("VerifyTx", jsonTx);
|
|
795
864
|
}
|
|
796
865
|
static CompileCoreScript(Code) {
|
|
797
|
-
return LocusLib.callWasm(
|
|
866
|
+
return LocusLib.callWasm("CompileCoreScript", { Code });
|
|
798
867
|
}
|
|
799
868
|
static DisCompileCoreScript(Code) {
|
|
800
|
-
return LocusLib.callWasm(
|
|
869
|
+
return LocusLib.callWasm("DisCompileCoreScript", { Code });
|
|
801
870
|
}
|
|
802
871
|
static TestCoreScript(ScriptProvide, ScriptAccept, TxDataProvide, TxDataAccept) {
|
|
803
|
-
return LocusLib.callWasm(
|
|
872
|
+
return LocusLib.callWasm("TestCoreScript", {
|
|
804
873
|
ScriptProvide,
|
|
805
874
|
ScriptAccept,
|
|
806
875
|
TxDataProvide,
|
|
807
|
-
TxDataAccept
|
|
876
|
+
TxDataAccept,
|
|
808
877
|
});
|
|
809
878
|
}
|
|
810
879
|
static GetDefFromCoreScript(Code) {
|
|
811
|
-
return LocusLib.callWasm(
|
|
880
|
+
return LocusLib.callWasm("GetDefFromCoreScript", { Code });
|
|
812
881
|
}
|
|
813
882
|
static EncodeTxNumber(Number, Type) {
|
|
814
|
-
return LocusLib.callWasm(
|
|
883
|
+
return LocusLib.callWasm("EncodeTxNumber", { Number, Type });
|
|
815
884
|
}
|
|
816
885
|
static EncodeTxCurrency(Currency) {
|
|
817
|
-
return LocusLib.callWasm(
|
|
886
|
+
return LocusLib.callWasm("EncodeTxCurrency", { Currency });
|
|
818
887
|
}
|
|
819
888
|
static Hash(Data, Type) {
|
|
820
|
-
return LocusLib.callWasm(
|
|
889
|
+
return LocusLib.callWasm("Hash", { Data, Type });
|
|
821
890
|
}
|
|
822
891
|
static VerifyMerkleProof(Proof, Hash, GoalHash) {
|
|
823
|
-
return LocusLib.callWasm(
|
|
892
|
+
return LocusLib.callWasm("VerifyMerkleProof", { Proof, Hash, GoalHash });
|
|
824
893
|
}
|
|
825
894
|
static CalculateTxLinkHash(Tx) {
|
|
826
|
-
return LocusLib.callWasm(
|
|
895
|
+
return LocusLib.callWasm("CalculateTxLinkHash", { Tx });
|
|
827
896
|
}
|
|
828
897
|
static DecodeTxs(Txs) {
|
|
829
|
-
return LocusLib.callWasm(
|
|
898
|
+
return LocusLib.callWasm("DecodeTxs", { Txs });
|
|
830
899
|
}
|
|
831
900
|
static GzipAndEncode(str) {
|
|
832
|
-
return LocusLib.callWasm(
|
|
901
|
+
return LocusLib.callWasm("GzipAndEncode", str);
|
|
902
|
+
}
|
|
903
|
+
static GenerateMnemonic(entropyBit = 256) {
|
|
904
|
+
return LocusLib.callWasm("GenerateMnemonic", { entropyBit });
|
|
905
|
+
}
|
|
906
|
+
static DeriveKeysFromMnemonic(mnemonic, path) {
|
|
907
|
+
return LocusLib.callWasm("DeriveKeysFromMnemonic", { mnemonic, path });
|
|
833
908
|
}
|
|
834
909
|
}
|
|
910
|
+
LocusLib.sleep = (ms) => new Promise((resolve) => setTimeout(() => resolve(true), ms));
|
|
835
911
|
|
|
836
912
|
export { LocusLib };
|