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