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