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