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