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