@leofcoin/chain 1.10.21 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -0
- package/exports/browser/beacon-wire.js +2 -2
- package/exports/browser/{browser-CCfR9KOM-BGMMnVsR.js → browser-CCfR9KOM-CNWKLusu.js} +3 -3
- package/exports/browser/{browser-crypto-CH0ua22L.js → browser-crypto-B_UJguhk.js} +453 -35
- package/exports/browser/chain.js +1275 -996
- package/exports/browser/client-DbZBfpG6-C1cXgvfr.js +5943 -0
- package/exports/browser/{connection-monitor-D-krNiRH.js → connection-monitor-BzbeYGEt.js} +153 -24
- package/exports/browser/{index-dTQVgkpf-DOL2rIjp.js → index-dTQVgkpf-CkoAiRNX.js} +3 -3
- package/exports/browser/{index-DCbLvMKL.js → index-phv5KvaE.js} +238 -234
- package/exports/browser/{messages-DCePyqKC-BSvJxDWZ.js → messages-DZYCxoZI-B472zldo.js} +3 -3
- package/exports/browser/{node-browser-Ha4Lvntj.js → node-browser-BmyPBkL5.js} +55 -11
- package/exports/browser/node-browser.js +3 -3
- package/exports/browser/workers/block-worker.js +8 -9
- package/exports/browser/workers/machine-worker.js +141 -1195
- package/exports/{workers/worker-BDTWOCzS-COrAszCt.js → browser/workers/proposal.proto-8zgMfutf-B3So_tnS.js} +910 -398
- package/exports/chain.js +296 -1078
- package/exports/connection-monitor-BdFLRh-J.js +465 -0
- package/exports/connection-monitor.js +2 -324
- package/exports/{constants-Dy9i9S_o.js → constants-BQ6f-_OT.js} +1 -1
- package/exports/hash-format-state.js +3 -3
- package/exports/machine.js +550 -0
- package/exports/node.js +35 -2
- package/exports/state-checkpoint-BiQ1EXzo.js +110 -0
- package/exports/state-checkpoint.js +3 -0
- package/exports/workers/block-worker.js +8 -9
- package/exports/workers/machine-worker.js +141 -1195
- package/exports/{browser/workers/worker-BDTWOCzS-COrAszCt.js → workers/proposal.proto-8zgMfutf-B3So_tnS.js} +910 -398
- package/package.json +9 -7
- package/exports/browser/client-DKKzPSlb-C_1ug6ux.js +0 -2401
|
@@ -1,4 +1,678 @@
|
|
|
1
|
-
|
|
1
|
+
class EasyWorker {
|
|
2
|
+
#messageEvent = 'message';
|
|
3
|
+
#errorEvent = 'error';
|
|
4
|
+
#isBrowser = false;
|
|
5
|
+
#isWorker = false;
|
|
6
|
+
#messageHandler = null;
|
|
7
|
+
#errorHandler = null;
|
|
8
|
+
worker;
|
|
9
|
+
get isWorker() {
|
|
10
|
+
return this.#isWorker;
|
|
11
|
+
}
|
|
12
|
+
constructor(url, options) {
|
|
13
|
+
return this.#init(url, options);
|
|
14
|
+
}
|
|
15
|
+
#init(url, options = {}) {
|
|
16
|
+
if (url) {
|
|
17
|
+
if (globalThis.Worker) {
|
|
18
|
+
this.#isBrowser = true;
|
|
19
|
+
this.worker = new Worker(url, { ...options });
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
import('child_process').then(({ fork }) => {
|
|
24
|
+
const child = fork(url, ['easy-worker-child'], options);
|
|
25
|
+
child.once('error', reject);
|
|
26
|
+
this.worker = child;
|
|
27
|
+
resolve(this);
|
|
28
|
+
}).catch(reject);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.#isWorker = true;
|
|
34
|
+
if (globalThis.process?.argv[2] === 'easy-worker-child') {
|
|
35
|
+
this.worker = process;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.#isBrowser = true;
|
|
39
|
+
this.worker = globalThis;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
onmessage(fn) {
|
|
45
|
+
if (this.#isBrowser) {
|
|
46
|
+
this.worker.onmessage = ({ data }) => fn(data);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
if (this.#messageHandler)
|
|
50
|
+
this.worker.off(this.#messageEvent, this.#messageHandler);
|
|
51
|
+
this.#messageHandler = fn;
|
|
52
|
+
this.worker.on(this.#messageEvent, fn);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
postMessage(message) {
|
|
56
|
+
if (this.#isBrowser)
|
|
57
|
+
this.worker.postMessage(message);
|
|
58
|
+
else
|
|
59
|
+
this.worker.send(message);
|
|
60
|
+
}
|
|
61
|
+
terminate() {
|
|
62
|
+
if (this.#isBrowser)
|
|
63
|
+
this.worker.terminate();
|
|
64
|
+
else
|
|
65
|
+
this.worker.kill();
|
|
66
|
+
}
|
|
67
|
+
onerror(fn) {
|
|
68
|
+
if (this.#isBrowser) {
|
|
69
|
+
this.worker.onerror = fn;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (this.#errorHandler)
|
|
73
|
+
this.worker.off(this.#errorEvent, this.#errorHandler);
|
|
74
|
+
this.#errorHandler = fn;
|
|
75
|
+
this.worker.on(this.#errorEvent, fn);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param {*} data
|
|
81
|
+
* @returns {Promise} resolves result onmessage & rejects on error
|
|
82
|
+
*/
|
|
83
|
+
once(data) {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
if (this.#isBrowser) {
|
|
86
|
+
const handleMessage = ({ data: result }) => {
|
|
87
|
+
this.worker.onerror = null;
|
|
88
|
+
resolve(result);
|
|
89
|
+
this.terminate();
|
|
90
|
+
};
|
|
91
|
+
const handleError = (error) => {
|
|
92
|
+
this.worker.onmessage = null;
|
|
93
|
+
reject(error);
|
|
94
|
+
this.terminate();
|
|
95
|
+
};
|
|
96
|
+
this.worker.onmessage = handleMessage;
|
|
97
|
+
this.worker.onerror = handleError;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const handleMessage = (result) => {
|
|
101
|
+
this.worker.off(this.#errorEvent, handleError);
|
|
102
|
+
resolve(result);
|
|
103
|
+
this.terminate();
|
|
104
|
+
};
|
|
105
|
+
const handleError = (error) => {
|
|
106
|
+
this.worker.off(this.#messageEvent, handleMessage);
|
|
107
|
+
reject(error);
|
|
108
|
+
this.terminate();
|
|
109
|
+
};
|
|
110
|
+
this.worker.once(this.#messageEvent, handleMessage);
|
|
111
|
+
this.worker.once(this.#errorEvent, handleError);
|
|
112
|
+
}
|
|
113
|
+
this.postMessage(data);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** @leofcoin/binary: dependency-free unsigned framing, with no global byte counters. */
|
|
119
|
+
const MAX_BIGINT = (1n << 256n) - 1n;
|
|
120
|
+
function size(value) {
|
|
121
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
122
|
+
throw new RangeError('Expected an unsigned safe integer');
|
|
123
|
+
}
|
|
124
|
+
function bytes(value) {
|
|
125
|
+
if (!(value instanceof Uint8Array))
|
|
126
|
+
throw new TypeError('Expected Uint8Array');
|
|
127
|
+
}
|
|
128
|
+
function varUintLength(value) {
|
|
129
|
+
size(value);
|
|
130
|
+
let length = 1;
|
|
131
|
+
while (value >= 128) {
|
|
132
|
+
value = Math.floor(value / 128);
|
|
133
|
+
length++;
|
|
134
|
+
}
|
|
135
|
+
return length;
|
|
136
|
+
}
|
|
137
|
+
function varBigIntLength(value) {
|
|
138
|
+
if (typeof value !== 'bigint')
|
|
139
|
+
throw new TypeError('Expected BigInt');
|
|
140
|
+
if (value < 0n || value > MAX_BIGINT)
|
|
141
|
+
throw new RangeError('Expected an unsigned 256-bit integer');
|
|
142
|
+
let length = 1;
|
|
143
|
+
// Count whole eight-byte varint groups before the short tail.
|
|
144
|
+
while (value >= 0x100000000000000n) {
|
|
145
|
+
value >>= 56n;
|
|
146
|
+
length += 8;
|
|
147
|
+
}
|
|
148
|
+
while (value >= 128n) {
|
|
149
|
+
value >>= 7n;
|
|
150
|
+
length++;
|
|
151
|
+
}
|
|
152
|
+
return length;
|
|
153
|
+
}
|
|
154
|
+
/** Fixed-capacity writer. finish() is a view; copy it before reusing/resetting the writer. */
|
|
155
|
+
class BinaryWriter {
|
|
156
|
+
#buffer;
|
|
157
|
+
#position = 0;
|
|
158
|
+
constructor(capacity = 64) {
|
|
159
|
+
if (typeof capacity === 'number') {
|
|
160
|
+
size(capacity);
|
|
161
|
+
this.#buffer = new Uint8Array(capacity);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
bytes(capacity);
|
|
165
|
+
this.#buffer = capacity;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
get position() {
|
|
169
|
+
return this.#position;
|
|
170
|
+
}
|
|
171
|
+
get remaining() {
|
|
172
|
+
return this.#buffer.length - this.#position;
|
|
173
|
+
}
|
|
174
|
+
#require(length) {
|
|
175
|
+
size(length);
|
|
176
|
+
if (length > this.remaining)
|
|
177
|
+
throw new RangeError('Binary output buffer is too small');
|
|
178
|
+
}
|
|
179
|
+
writeVarUint(value) {
|
|
180
|
+
this.#require(varUintLength(value));
|
|
181
|
+
this.#writeVarUint(value);
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
#writeVarUint(value) {
|
|
185
|
+
while (value >= 128) {
|
|
186
|
+
this.#buffer[this.#position++] = value % 128 | 128;
|
|
187
|
+
value = Math.floor(value / 128);
|
|
188
|
+
}
|
|
189
|
+
this.#buffer[this.#position++] = value;
|
|
190
|
+
}
|
|
191
|
+
writeVarBigInt(value) {
|
|
192
|
+
this.#require(varBigIntLength(value));
|
|
193
|
+
do {
|
|
194
|
+
const byte = Number(value & 127n);
|
|
195
|
+
value >>= 7n;
|
|
196
|
+
this.#buffer[this.#position++] = byte | (value ? 128 : 0);
|
|
197
|
+
} while (value);
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
writeBytes(value) {
|
|
201
|
+
bytes(value);
|
|
202
|
+
this.#require(value.length);
|
|
203
|
+
this.#buffer.set(value, this.#position);
|
|
204
|
+
this.#position += value.length;
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
writeFrame(value) {
|
|
208
|
+
bytes(value);
|
|
209
|
+
// Check the complete operation before writing its length prefix.
|
|
210
|
+
const prefixLength = varUintLength(value.length);
|
|
211
|
+
this.#require(prefixLength + value.length);
|
|
212
|
+
const prefixStart = this.#buffer.byteOffset + this.#position;
|
|
213
|
+
if (value.buffer === this.#buffer.buffer &&
|
|
214
|
+
value.byteOffset < prefixStart + prefixLength &&
|
|
215
|
+
value.byteOffset + value.length > prefixStart)
|
|
216
|
+
throw new RangeError('Frame source overlaps its length prefix');
|
|
217
|
+
this.#writeVarUint(value.length);
|
|
218
|
+
this.#buffer.set(value, this.#position);
|
|
219
|
+
this.#position += value.length;
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
reset() {
|
|
223
|
+
this.#position = 0;
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
finish(copy = false) {
|
|
227
|
+
const result = this.#buffer.subarray(0, this.#position);
|
|
228
|
+
// Buffer.slice() aliases memory; this constructor copies every Uint8Array subtype.
|
|
229
|
+
return copy ? new Uint8Array(result) : result;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/** Reads views of the original buffer. Failed operations leave the cursor unchanged. */
|
|
233
|
+
class BinaryReader {
|
|
234
|
+
#buffer;
|
|
235
|
+
#position = 0;
|
|
236
|
+
constructor(buffer) {
|
|
237
|
+
bytes(buffer);
|
|
238
|
+
this.#buffer = buffer;
|
|
239
|
+
}
|
|
240
|
+
get position() {
|
|
241
|
+
return this.#position;
|
|
242
|
+
}
|
|
243
|
+
get remaining() {
|
|
244
|
+
return this.#buffer.length - this.#position;
|
|
245
|
+
}
|
|
246
|
+
readVarUint(canonical = true) {
|
|
247
|
+
let result = 0;
|
|
248
|
+
let multiplier = 1;
|
|
249
|
+
for (let index = 0; index < 8; index++) {
|
|
250
|
+
const cursor = this.#position + index;
|
|
251
|
+
if (cursor >= this.#buffer.length)
|
|
252
|
+
throw new RangeError('Truncated varint');
|
|
253
|
+
const byte = this.#buffer[cursor];
|
|
254
|
+
const payload = byte & 127;
|
|
255
|
+
if (index === 7 && payload > Math.floor((Number.MAX_SAFE_INTEGER - result) / multiplier))
|
|
256
|
+
throw new RangeError('Varint exceeds safe integer range');
|
|
257
|
+
result += payload * multiplier;
|
|
258
|
+
if (byte < 128) {
|
|
259
|
+
if (canonical && index > 0 && payload === 0)
|
|
260
|
+
throw new RangeError('Non-canonical varint');
|
|
261
|
+
this.#position = cursor + 1;
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
multiplier *= 128;
|
|
265
|
+
}
|
|
266
|
+
throw new RangeError('Varint exceeds safe integer range');
|
|
267
|
+
}
|
|
268
|
+
readVarBigInt(canonical = true) {
|
|
269
|
+
let result = 0n;
|
|
270
|
+
for (let index = 0; index < 37; index++) {
|
|
271
|
+
const cursor = this.#position + index;
|
|
272
|
+
if (cursor >= this.#buffer.length)
|
|
273
|
+
throw new RangeError('Truncated varint');
|
|
274
|
+
const byte = this.#buffer[cursor];
|
|
275
|
+
result |= BigInt(byte & 127) << BigInt(index * 7);
|
|
276
|
+
if (result > MAX_BIGINT)
|
|
277
|
+
throw new RangeError('Varint exceeds 256 bits');
|
|
278
|
+
if (byte < 128) {
|
|
279
|
+
if (canonical && index > 0 && byte === 0)
|
|
280
|
+
throw new RangeError('Non-canonical varint');
|
|
281
|
+
this.#position = cursor + 1;
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
throw new RangeError('Varint exceeds 256 bits');
|
|
286
|
+
}
|
|
287
|
+
readBytes(length) {
|
|
288
|
+
size(length);
|
|
289
|
+
if (length > this.remaining)
|
|
290
|
+
throw new RangeError('Truncated binary field');
|
|
291
|
+
const start = this.#position;
|
|
292
|
+
this.#position += length;
|
|
293
|
+
return this.#buffer.subarray(start, this.#position);
|
|
294
|
+
}
|
|
295
|
+
readFrame(canonical = true) {
|
|
296
|
+
const start = this.#position;
|
|
297
|
+
try {
|
|
298
|
+
return this.readBytes(this.readVarUint(canonical));
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
this.#position = start;
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/** Existing smart-concat bytes, with exactly one output allocation and no prefix arrays. */
|
|
307
|
+
function encodeFrames(frames, prefix) {
|
|
308
|
+
if (!Array.isArray(frames))
|
|
309
|
+
throw new TypeError('Expected an array of byte frames');
|
|
310
|
+
let length = 0;
|
|
311
|
+
for (const frame of frames) {
|
|
312
|
+
bytes(frame);
|
|
313
|
+
length += varUintLength(frame.length) + frame.length;
|
|
314
|
+
size(length);
|
|
315
|
+
}
|
|
316
|
+
const writer = new BinaryWriter(length);
|
|
317
|
+
for (const frame of frames)
|
|
318
|
+
writer.writeFrame(frame);
|
|
319
|
+
return writer.finish();
|
|
320
|
+
}
|
|
321
|
+
/** Iterative framing: bounded by the input length, not recursive stack depth. */
|
|
322
|
+
function decodeFrames(buffer, prefixLength = 0, options = {}) {
|
|
323
|
+
const reader = new BinaryReader(buffer);
|
|
324
|
+
reader.readBytes(prefixLength);
|
|
325
|
+
const maxFrames = options.maxFrames ?? buffer.length;
|
|
326
|
+
size(maxFrames);
|
|
327
|
+
const frames = [];
|
|
328
|
+
while (reader.remaining) {
|
|
329
|
+
if (frames.length >= maxFrames)
|
|
330
|
+
throw new RangeError('Too many binary frames');
|
|
331
|
+
frames.push(reader.readFrame(options.canonical ?? true));
|
|
332
|
+
}
|
|
333
|
+
return frames;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const MAGIC = new Uint8Array([0x4c, 0x46, 0x43, 1]);
|
|
337
|
+
const utf8 = new TextEncoder();
|
|
338
|
+
const text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
339
|
+
const defaults = { maxBytes: 16 * 1024 * 1024, maxDepth: 64, maxNodes: 200000 };
|
|
340
|
+
const BIGINT_LIMB = 1n << 49n;
|
|
341
|
+
const BIGINT_MASK = BIGINT_LIMB - 1n;
|
|
342
|
+
const limitsFor = (options) => {
|
|
343
|
+
const limits = { ...defaults, ...options };
|
|
344
|
+
for (const value of Object.values(limits))
|
|
345
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
346
|
+
throw new RangeError('Invalid binary limits');
|
|
347
|
+
return limits;
|
|
348
|
+
};
|
|
349
|
+
/** Canonical UTF-8 length without allocating a temporary encoded string. */
|
|
350
|
+
function stringLength(value, maximum) {
|
|
351
|
+
if (value.length > maximum)
|
|
352
|
+
throw new RangeError('Invalid binary string');
|
|
353
|
+
let length = value.length;
|
|
354
|
+
for (let index = 0; index < value.length; index++) {
|
|
355
|
+
const code = value.charCodeAt(index);
|
|
356
|
+
if (code < 0x80)
|
|
357
|
+
continue;
|
|
358
|
+
if (code < 0x800) {
|
|
359
|
+
length++;
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (code >= 0xd800 && code <= 0xdbff) {
|
|
363
|
+
const low = value.charCodeAt(++index);
|
|
364
|
+
if (!(low >= 0xdc00 && low <= 0xdfff))
|
|
365
|
+
throw new RangeError('Invalid binary string');
|
|
366
|
+
length += 2;
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
if (code >= 0xdc00 && code <= 0xdfff)
|
|
370
|
+
throw new RangeError('Invalid binary string');
|
|
371
|
+
length += 2;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return length;
|
|
375
|
+
}
|
|
376
|
+
/** Versioned canonical typed values. Validation/planning allocates no byte buffers. */
|
|
377
|
+
function encodeValue(value, options = {}) {
|
|
378
|
+
return encodeValueWithPrefix(value, EMPTY, options);
|
|
379
|
+
}
|
|
380
|
+
const EMPTY = new Uint8Array();
|
|
381
|
+
/** Prepend an existing framing/codec header in the same allocation.
|
|
382
|
+
* maxBytes bounds the typed value (including MAGIC), as with encodeValue.
|
|
383
|
+
* The caller-owned prefix is separate framing and is copied, never retained.
|
|
384
|
+
*/
|
|
385
|
+
function encodeValueWithPrefix(value, prefix, options = {}) {
|
|
386
|
+
if (!(prefix instanceof Uint8Array))
|
|
387
|
+
throw new TypeError('Expected Uint8Array prefix');
|
|
388
|
+
const limits = limitsFor(options);
|
|
389
|
+
// Flat plan retains validated data-property values; writing never reads user properties again.
|
|
390
|
+
// Internal tag 11 is an untagged map key and is never emitted on the wire.
|
|
391
|
+
const plan = [];
|
|
392
|
+
const ancestors = new Set();
|
|
393
|
+
let size = MAGIC.length;
|
|
394
|
+
let nodes = 0;
|
|
395
|
+
const reserve = (length) => {
|
|
396
|
+
size += length;
|
|
397
|
+
if (size > limits.maxBytes)
|
|
398
|
+
throw new RangeError('Binary value exceeds byte limit');
|
|
399
|
+
};
|
|
400
|
+
const string = (value, tag) => {
|
|
401
|
+
const length = stringLength(value, limits.maxBytes);
|
|
402
|
+
reserve((tag === 7 ? 1 : 0) + varUintLength(length) + length);
|
|
403
|
+
plan.push(tag, value, length);
|
|
404
|
+
};
|
|
405
|
+
const visit = (value, depth) => {
|
|
406
|
+
if (++nodes > limits.maxNodes || depth > limits.maxDepth)
|
|
407
|
+
throw new RangeError('Binary value exceeds complexity limit');
|
|
408
|
+
if (value === undefined || value === null || typeof value === 'boolean') {
|
|
409
|
+
reserve(1);
|
|
410
|
+
plan.push(value === undefined ? 0 : value === null ? 1 : value === false ? 2 : 3);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (typeof value === 'number') {
|
|
414
|
+
if (!Number.isFinite(value))
|
|
415
|
+
throw new TypeError('Binary numbers must be finite');
|
|
416
|
+
reserve(9);
|
|
417
|
+
plan.push(4, value);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (typeof value === 'bigint') {
|
|
421
|
+
const magnitude = value < 0n ? -value : value;
|
|
422
|
+
reserve(1 + varBigIntLength(magnitude));
|
|
423
|
+
plan.push(value < 0n ? 6 : 5, magnitude);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (typeof value === 'string')
|
|
427
|
+
return string(value, 7);
|
|
428
|
+
if (value instanceof Uint8Array) {
|
|
429
|
+
reserve(1 + varUintLength(value.length) + value.length);
|
|
430
|
+
plan.push(8, value, value.length);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (typeof value !== 'object')
|
|
434
|
+
throw new TypeError('Unsupported binary value');
|
|
435
|
+
if (ancestors.has(value))
|
|
436
|
+
throw new TypeError('Cyclic binary value');
|
|
437
|
+
ancestors.add(value);
|
|
438
|
+
try {
|
|
439
|
+
if (Array.isArray(value)) {
|
|
440
|
+
if (value.length > limits.maxNodes - nodes)
|
|
441
|
+
throw new RangeError('Binary array exceeds node limit');
|
|
442
|
+
if (Object.keys(value).length !== value.length || Object.getOwnPropertySymbols(value).length)
|
|
443
|
+
throw new TypeError('Binary arrays cannot have extra properties or holes');
|
|
444
|
+
reserve(1 + varUintLength(value.length));
|
|
445
|
+
plan.push(9, value.length);
|
|
446
|
+
for (let index = 0; index < value.length; index++) {
|
|
447
|
+
const entry = Object.getOwnPropertyDescriptor(value, String(index));
|
|
448
|
+
if (!entry || !('value' in entry))
|
|
449
|
+
throw new TypeError('Sparse arrays and accessors are not binary values');
|
|
450
|
+
visit(entry.value, depth + 1);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
const prototype = Object.getPrototypeOf(value);
|
|
455
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
456
|
+
throw new TypeError('Binary maps must be plain objects');
|
|
457
|
+
const keys = Object.keys(value).sort();
|
|
458
|
+
if (Object.getOwnPropertySymbols(value).length)
|
|
459
|
+
throw new TypeError('Symbol keys are not binary values');
|
|
460
|
+
if (keys.length > limits.maxNodes - nodes)
|
|
461
|
+
throw new RangeError('Binary map exceeds node limit');
|
|
462
|
+
reserve(1 + varUintLength(keys.length));
|
|
463
|
+
plan.push(10, keys.length);
|
|
464
|
+
for (const key of keys) {
|
|
465
|
+
const entry = Object.getOwnPropertyDescriptor(value, key);
|
|
466
|
+
if (!('value' in entry))
|
|
467
|
+
throw new TypeError('Accessors are not binary values');
|
|
468
|
+
string(key, 11);
|
|
469
|
+
visit(entry.value, depth + 1);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
finally {
|
|
474
|
+
ancestors.delete(value);
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
visit(value, 0);
|
|
478
|
+
const capacity = prefix.length + size;
|
|
479
|
+
if (!Number.isSafeInteger(capacity))
|
|
480
|
+
throw new RangeError('Binary output is too large');
|
|
481
|
+
const output = new Uint8Array(capacity);
|
|
482
|
+
output.set(prefix);
|
|
483
|
+
output.set(MAGIC, prefix.length);
|
|
484
|
+
let position = prefix.length + MAGIC.length;
|
|
485
|
+
let view;
|
|
486
|
+
const uint = (value) => {
|
|
487
|
+
while (value >= 128) {
|
|
488
|
+
output[position++] = value % 128 | 128;
|
|
489
|
+
value = Math.floor(value / 128);
|
|
490
|
+
}
|
|
491
|
+
output[position++] = value;
|
|
492
|
+
};
|
|
493
|
+
for (let cursor = 0; cursor < plan.length;) {
|
|
494
|
+
const tag = plan[cursor++];
|
|
495
|
+
if (tag !== 11)
|
|
496
|
+
output[position++] = tag;
|
|
497
|
+
if (tag < 4)
|
|
498
|
+
continue;
|
|
499
|
+
if (tag === 4) {
|
|
500
|
+
view ??= new DataView(output.buffer);
|
|
501
|
+
view.setFloat64(position, plan[cursor++], false);
|
|
502
|
+
position += 8;
|
|
503
|
+
}
|
|
504
|
+
else if (tag === 5 || tag === 6) {
|
|
505
|
+
let value = plan[cursor++];
|
|
506
|
+
// Seven varint bytes fit exactly in a safe-integer Number (49 bits).
|
|
507
|
+
// Extract one BigInt limb rather than shifting/masking BigInt for every byte.
|
|
508
|
+
while (value >= BIGINT_LIMB) {
|
|
509
|
+
let limb = Number(value & BIGINT_MASK);
|
|
510
|
+
for (let index = 0; index < 7; index++) {
|
|
511
|
+
output[position++] = limb % 128 | 128;
|
|
512
|
+
limb = Math.floor(limb / 128);
|
|
513
|
+
}
|
|
514
|
+
value >>= 49n;
|
|
515
|
+
}
|
|
516
|
+
uint(Number(value));
|
|
517
|
+
}
|
|
518
|
+
else if (tag === 7 || tag === 11) {
|
|
519
|
+
const value = plan[cursor++];
|
|
520
|
+
const length = plan[cursor++];
|
|
521
|
+
uint(length);
|
|
522
|
+
if (length === value.length) {
|
|
523
|
+
for (let index = 0; index < length; index++)
|
|
524
|
+
output[position++] = value.charCodeAt(index);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
const result = utf8.encodeInto(value, output.subarray(position, position + length));
|
|
528
|
+
if (result.read !== value.length || result.written !== length)
|
|
529
|
+
throw new Error('UTF-8 planning mismatch');
|
|
530
|
+
position += length;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
else if (tag === 8) {
|
|
534
|
+
const value = plan[cursor++];
|
|
535
|
+
const length = plan[cursor++];
|
|
536
|
+
if (value.length !== length)
|
|
537
|
+
throw new RangeError('Byte input changed while encoding');
|
|
538
|
+
uint(length);
|
|
539
|
+
output.set(value, position);
|
|
540
|
+
position += length;
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
uint(plan[cursor++]);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (position !== capacity)
|
|
547
|
+
throw new Error('Binary planning mismatch');
|
|
548
|
+
return output;
|
|
549
|
+
}
|
|
550
|
+
/** Strict decoder: byte input, version, canonical ordering, bounds and complete consumption. */
|
|
551
|
+
function decodeValue(input, options = {}) {
|
|
552
|
+
const limits = limitsFor(options);
|
|
553
|
+
if (!(input instanceof Uint8Array))
|
|
554
|
+
throw new TypeError('Wire payload must be Uint8Array');
|
|
555
|
+
if (input.length > limits.maxBytes)
|
|
556
|
+
throw new RangeError('Binary value exceeds byte limit');
|
|
557
|
+
const reader = new BinaryReader(input);
|
|
558
|
+
if (reader.readBytes(MAGIC.length).some((byte, index) => byte !== MAGIC[index]))
|
|
559
|
+
throw new TypeError('Unsupported binary wire version');
|
|
560
|
+
let nodes = 0;
|
|
561
|
+
const string = () => text.decode(reader.readFrame());
|
|
562
|
+
const read = (depth) => {
|
|
563
|
+
if (++nodes > limits.maxNodes || depth > limits.maxDepth)
|
|
564
|
+
throw new RangeError('Binary value exceeds complexity limit');
|
|
565
|
+
const tag = reader.readBytes(1)[0];
|
|
566
|
+
if (tag === 0)
|
|
567
|
+
return undefined;
|
|
568
|
+
if (tag === 1)
|
|
569
|
+
return null;
|
|
570
|
+
if (tag === 2)
|
|
571
|
+
return false;
|
|
572
|
+
if (tag === 3)
|
|
573
|
+
return true;
|
|
574
|
+
if (tag === 4) {
|
|
575
|
+
const bytes = reader.readBytes(8);
|
|
576
|
+
const value = new DataView(bytes.buffer, bytes.byteOffset, 8).getFloat64(0, false);
|
|
577
|
+
if (!Number.isFinite(value))
|
|
578
|
+
throw new TypeError('Binary numbers must be finite');
|
|
579
|
+
return value;
|
|
580
|
+
}
|
|
581
|
+
if (tag === 5 || tag === 6) {
|
|
582
|
+
const value = reader.readVarBigInt();
|
|
583
|
+
if (tag === 6 && value === 0n)
|
|
584
|
+
throw new TypeError('Non-canonical negative zero');
|
|
585
|
+
return tag === 6 ? -value : value;
|
|
586
|
+
}
|
|
587
|
+
if (tag === 7)
|
|
588
|
+
return string();
|
|
589
|
+
if (tag === 8)
|
|
590
|
+
return new Uint8Array(reader.readFrame());
|
|
591
|
+
if (tag === 9 || tag === 10) {
|
|
592
|
+
const count = reader.readVarUint();
|
|
593
|
+
if (count > limits.maxNodes - nodes || count > reader.remaining)
|
|
594
|
+
throw new RangeError('Invalid binary collection size');
|
|
595
|
+
if (tag === 9)
|
|
596
|
+
return Array.from({ length: count }, () => read(depth + 1));
|
|
597
|
+
const result = {};
|
|
598
|
+
let previous;
|
|
599
|
+
for (let index = 0; index < count; index++) {
|
|
600
|
+
const key = string();
|
|
601
|
+
if (previous !== undefined && key <= previous)
|
|
602
|
+
throw new TypeError('Non-canonical binary map keys');
|
|
603
|
+
previous = key;
|
|
604
|
+
Object.defineProperty(result, key, { value: read(depth + 1), enumerable: true, writable: true, configurable: true });
|
|
605
|
+
}
|
|
606
|
+
return result;
|
|
607
|
+
}
|
|
608
|
+
throw new TypeError('Unknown binary value tag');
|
|
609
|
+
};
|
|
610
|
+
const value = read(0);
|
|
611
|
+
if (reader.remaining)
|
|
612
|
+
throw new TypeError('Trailing binary data');
|
|
613
|
+
return value;
|
|
614
|
+
}
|
|
615
|
+
/** Domain separation prevents RPC bytes from being accepted as worker/chat/peer messages. */
|
|
616
|
+
const encodeWire = (channel, value, limits) => encodeValue([channel, value], limits);
|
|
617
|
+
function decodeWire(channel, bytes, limits) {
|
|
618
|
+
const envelope = decodeValue(bytes, limits);
|
|
619
|
+
if (!Array.isArray(envelope) || envelope.length !== 2 || envelope[0] !== channel)
|
|
620
|
+
throw new TypeError('Wrong binary message channel');
|
|
621
|
+
return envelope[1];
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** Decoded objects stay inside a process. Every actual IPC payload is canonical bytes. */
|
|
625
|
+
class BinaryWorker {
|
|
626
|
+
#transport;
|
|
627
|
+
#errorHandler;
|
|
628
|
+
constructor(url, options = {}) {
|
|
629
|
+
const transport = new EasyWorker(url, { ...options, serialization: 'advanced' });
|
|
630
|
+
// EasyWorker's parent constructor is asynchronous, the child constructor is not.
|
|
631
|
+
if (transport && typeof transport.then === 'function')
|
|
632
|
+
return transport.then(value => { this.#transport = value; this.worker = value.worker; return this; });
|
|
633
|
+
this.#transport = transport;
|
|
634
|
+
this.worker = transport.worker;
|
|
635
|
+
}
|
|
636
|
+
postMessage(value) { this.#transport.postMessage(encodeWire('worker', value)); }
|
|
637
|
+
onmessage(handler) {
|
|
638
|
+
this.#transport.onmessage(bytes => {
|
|
639
|
+
let value;
|
|
640
|
+
try {
|
|
641
|
+
value = decodeWire('worker', bytes);
|
|
642
|
+
}
|
|
643
|
+
catch (error) {
|
|
644
|
+
if (this.#errorHandler)
|
|
645
|
+
this.#errorHandler(error);
|
|
646
|
+
else
|
|
647
|
+
throw error;
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
handler(value);
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
onerror(handler) { this.#errorHandler = handler; this.#transport.onerror(handler); }
|
|
654
|
+
terminate() { return this.#transport.terminate(); }
|
|
655
|
+
async once(value) {
|
|
656
|
+
let timer;
|
|
657
|
+
try {
|
|
658
|
+
return await new Promise((resolve, reject) => {
|
|
659
|
+
timer = setTimeout(() => reject(new Error('Binary worker request timed out')), 10000);
|
|
660
|
+
this.onerror(reject);
|
|
661
|
+
this.onmessage(resolve);
|
|
662
|
+
this.postMessage(value);
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
finally {
|
|
666
|
+
clearTimeout(timer);
|
|
667
|
+
this.terminate();
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/** Freeze declarations, not decoded messages. Keep existing consumer field types mutable. */
|
|
673
|
+
const defineSchema = (proto) => Object.freeze(proto);
|
|
674
|
+
|
|
675
|
+
var proto$2 = defineSchema({
|
|
2
676
|
index: BigInt(0),
|
|
3
677
|
previousHash: String(),
|
|
4
678
|
timestamp: Number(),
|
|
@@ -9,7 +683,7 @@ var proto$3 = {
|
|
|
9
683
|
producer: String(),
|
|
10
684
|
producerProof: String(),
|
|
11
685
|
protocolVersion: String()
|
|
12
|
-
};
|
|
686
|
+
});
|
|
13
687
|
|
|
14
688
|
// base-x encoding / decoding
|
|
15
689
|
// Copyright (c) 2018 base-x contributors
|
|
@@ -397,261 +1071,48 @@ const isBase58 = (string) => {
|
|
|
397
1071
|
return true;
|
|
398
1072
|
}
|
|
399
1073
|
catch (e) {
|
|
400
|
-
return false;
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
const isBase58Hex = (string) => {
|
|
404
|
-
try {
|
|
405
|
-
decodeHex(string);
|
|
406
|
-
return true;
|
|
407
|
-
}
|
|
408
|
-
catch (e) {
|
|
409
|
-
return false;
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
const whatType = (string) => {
|
|
413
|
-
try {
|
|
414
|
-
decode$1(string);
|
|
415
|
-
return "base58";
|
|
416
|
-
}
|
|
417
|
-
catch (e) {
|
|
418
|
-
try {
|
|
419
|
-
decodeHex(string);
|
|
420
|
-
return "base58Hex";
|
|
421
|
-
}
|
|
422
|
-
catch {
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
var base58$1 = {
|
|
428
|
-
encode: encode$1,
|
|
429
|
-
decode: decode$1,
|
|
430
|
-
isBase58,
|
|
431
|
-
isBase58Hex,
|
|
432
|
-
encodeHex,
|
|
433
|
-
decodeHex,
|
|
434
|
-
whatType,
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
var isHex = string => /^[A-F0-9]+$/i.test(
|
|
438
|
-
string.startsWith('0x') ?
|
|
439
|
-
string.slice(2) :
|
|
440
|
-
string
|
|
441
|
-
);
|
|
442
|
-
|
|
443
|
-
/** @leofcoin/binary: dependency-free unsigned framing, with no global byte counters. */
|
|
444
|
-
const MAX_BIGINT = (1n << 256n) - 1n;
|
|
445
|
-
function size(value) {
|
|
446
|
-
if (!Number.isSafeInteger(value) || value < 0)
|
|
447
|
-
throw new RangeError('Expected an unsigned safe integer');
|
|
448
|
-
}
|
|
449
|
-
function bytes(value) {
|
|
450
|
-
if (!(value instanceof Uint8Array))
|
|
451
|
-
throw new TypeError('Expected Uint8Array');
|
|
452
|
-
}
|
|
453
|
-
function varUintLength(value) {
|
|
454
|
-
size(value);
|
|
455
|
-
let length = 1;
|
|
456
|
-
while (value >= 128) {
|
|
457
|
-
value = Math.floor(value / 128);
|
|
458
|
-
length++;
|
|
459
|
-
}
|
|
460
|
-
return length;
|
|
461
|
-
}
|
|
462
|
-
function varBigIntLength(value) {
|
|
463
|
-
if (typeof value !== 'bigint')
|
|
464
|
-
throw new TypeError('Expected BigInt');
|
|
465
|
-
if (value < 0n || value > MAX_BIGINT)
|
|
466
|
-
throw new RangeError('Expected an unsigned 256-bit integer');
|
|
467
|
-
let length = 1;
|
|
468
|
-
while (value >= 128n) {
|
|
469
|
-
value >>= 7n;
|
|
470
|
-
length++;
|
|
471
|
-
}
|
|
472
|
-
return length;
|
|
473
|
-
}
|
|
474
|
-
/** Fixed-capacity writer. finish() is a view; copy it before reusing/resetting the writer. */
|
|
475
|
-
class BinaryWriter {
|
|
476
|
-
#buffer;
|
|
477
|
-
#position = 0;
|
|
478
|
-
constructor(capacity = 64) {
|
|
479
|
-
if (typeof capacity === 'number') {
|
|
480
|
-
size(capacity);
|
|
481
|
-
this.#buffer = new Uint8Array(capacity);
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
bytes(capacity);
|
|
485
|
-
this.#buffer = capacity;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
get position() {
|
|
489
|
-
return this.#position;
|
|
490
|
-
}
|
|
491
|
-
get remaining() {
|
|
492
|
-
return this.#buffer.length - this.#position;
|
|
493
|
-
}
|
|
494
|
-
#require(length) {
|
|
495
|
-
size(length);
|
|
496
|
-
if (length > this.remaining)
|
|
497
|
-
throw new RangeError('Binary output buffer is too small');
|
|
498
|
-
}
|
|
499
|
-
writeVarUint(value) {
|
|
500
|
-
this.#require(varUintLength(value));
|
|
501
|
-
this.#writeVarUint(value);
|
|
502
|
-
return this;
|
|
503
|
-
}
|
|
504
|
-
#writeVarUint(value) {
|
|
505
|
-
while (value >= 128) {
|
|
506
|
-
this.#buffer[this.#position++] = value % 128 | 128;
|
|
507
|
-
value = Math.floor(value / 128);
|
|
508
|
-
}
|
|
509
|
-
this.#buffer[this.#position++] = value;
|
|
510
|
-
}
|
|
511
|
-
writeVarBigInt(value) {
|
|
512
|
-
this.#require(varBigIntLength(value));
|
|
513
|
-
do {
|
|
514
|
-
const byte = Number(value & 127n);
|
|
515
|
-
value >>= 7n;
|
|
516
|
-
this.#buffer[this.#position++] = byte | (value ? 128 : 0);
|
|
517
|
-
} while (value);
|
|
518
|
-
return this;
|
|
519
|
-
}
|
|
520
|
-
writeBytes(value) {
|
|
521
|
-
bytes(value);
|
|
522
|
-
this.#require(value.length);
|
|
523
|
-
this.#buffer.set(value, this.#position);
|
|
524
|
-
this.#position += value.length;
|
|
525
|
-
return this;
|
|
526
|
-
}
|
|
527
|
-
writeFrame(value) {
|
|
528
|
-
bytes(value);
|
|
529
|
-
// Check the complete operation before writing its length prefix.
|
|
530
|
-
const prefixLength = varUintLength(value.length);
|
|
531
|
-
this.#require(prefixLength + value.length);
|
|
532
|
-
const prefixStart = this.#buffer.byteOffset + this.#position;
|
|
533
|
-
if (value.buffer === this.#buffer.buffer &&
|
|
534
|
-
value.byteOffset < prefixStart + prefixLength &&
|
|
535
|
-
value.byteOffset + value.length > prefixStart)
|
|
536
|
-
throw new RangeError('Frame source overlaps its length prefix');
|
|
537
|
-
this.#writeVarUint(value.length);
|
|
538
|
-
this.#buffer.set(value, this.#position);
|
|
539
|
-
this.#position += value.length;
|
|
540
|
-
return this;
|
|
541
|
-
}
|
|
542
|
-
reset() {
|
|
543
|
-
this.#position = 0;
|
|
544
|
-
return this;
|
|
545
|
-
}
|
|
546
|
-
finish(copy = false) {
|
|
547
|
-
const result = this.#buffer.subarray(0, this.#position);
|
|
548
|
-
// Buffer.slice() aliases memory; this constructor copies every Uint8Array subtype.
|
|
549
|
-
return copy ? new Uint8Array(result) : result;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
/** Reads views of the original buffer. Failed operations leave the cursor unchanged. */
|
|
553
|
-
class BinaryReader {
|
|
554
|
-
#buffer;
|
|
555
|
-
#position = 0;
|
|
556
|
-
constructor(buffer) {
|
|
557
|
-
bytes(buffer);
|
|
558
|
-
this.#buffer = buffer;
|
|
559
|
-
}
|
|
560
|
-
get position() {
|
|
561
|
-
return this.#position;
|
|
562
|
-
}
|
|
563
|
-
get remaining() {
|
|
564
|
-
return this.#buffer.length - this.#position;
|
|
565
|
-
}
|
|
566
|
-
readVarUint(canonical = true) {
|
|
567
|
-
let result = 0;
|
|
568
|
-
let multiplier = 1;
|
|
569
|
-
for (let index = 0; index < 8; index++) {
|
|
570
|
-
const cursor = this.#position + index;
|
|
571
|
-
if (cursor >= this.#buffer.length)
|
|
572
|
-
throw new RangeError('Truncated varint');
|
|
573
|
-
const byte = this.#buffer[cursor];
|
|
574
|
-
const payload = byte & 127;
|
|
575
|
-
if (index === 7 && payload > Math.floor((Number.MAX_SAFE_INTEGER - result) / multiplier))
|
|
576
|
-
throw new RangeError('Varint exceeds safe integer range');
|
|
577
|
-
result += payload * multiplier;
|
|
578
|
-
if (byte < 128) {
|
|
579
|
-
if (canonical && index > 0 && payload === 0)
|
|
580
|
-
throw new RangeError('Non-canonical varint');
|
|
581
|
-
this.#position = cursor + 1;
|
|
582
|
-
return result;
|
|
583
|
-
}
|
|
584
|
-
multiplier *= 128;
|
|
585
|
-
}
|
|
586
|
-
throw new RangeError('Varint exceeds safe integer range');
|
|
587
|
-
}
|
|
588
|
-
readVarBigInt(canonical = true) {
|
|
589
|
-
let result = 0n;
|
|
590
|
-
for (let index = 0; index < 37; index++) {
|
|
591
|
-
const cursor = this.#position + index;
|
|
592
|
-
if (cursor >= this.#buffer.length)
|
|
593
|
-
throw new RangeError('Truncated varint');
|
|
594
|
-
const byte = this.#buffer[cursor];
|
|
595
|
-
result |= BigInt(byte & 127) << BigInt(index * 7);
|
|
596
|
-
if (result > MAX_BIGINT)
|
|
597
|
-
throw new RangeError('Varint exceeds 256 bits');
|
|
598
|
-
if (byte < 128) {
|
|
599
|
-
if (canonical && index > 0 && byte === 0)
|
|
600
|
-
throw new RangeError('Non-canonical varint');
|
|
601
|
-
this.#position = cursor + 1;
|
|
602
|
-
return result;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
throw new RangeError('Varint exceeds 256 bits');
|
|
1074
|
+
return false;
|
|
606
1075
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
this.#position += length;
|
|
613
|
-
return this.#buffer.subarray(start, this.#position);
|
|
1076
|
+
};
|
|
1077
|
+
const isBase58Hex = (string) => {
|
|
1078
|
+
try {
|
|
1079
|
+
decodeHex(string);
|
|
1080
|
+
return true;
|
|
614
1081
|
}
|
|
615
|
-
|
|
616
|
-
|
|
1082
|
+
catch (e) {
|
|
1083
|
+
return false;
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
const whatType = (string) => {
|
|
1087
|
+
try {
|
|
1088
|
+
decode$1(string);
|
|
1089
|
+
return "base58";
|
|
1090
|
+
}
|
|
1091
|
+
catch (e) {
|
|
617
1092
|
try {
|
|
618
|
-
|
|
1093
|
+
decodeHex(string);
|
|
1094
|
+
return "base58Hex";
|
|
619
1095
|
}
|
|
620
|
-
catch
|
|
621
|
-
|
|
622
|
-
throw error;
|
|
1096
|
+
catch {
|
|
1097
|
+
return;
|
|
623
1098
|
}
|
|
624
1099
|
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
/** Iterative framing: bounded by the input length, not recursive stack depth. */
|
|
642
|
-
function decodeFrames(buffer, prefixLength = 0, options = {}) {
|
|
643
|
-
const reader = new BinaryReader(buffer);
|
|
644
|
-
reader.readBytes(prefixLength);
|
|
645
|
-
const maxFrames = options.maxFrames ?? buffer.length;
|
|
646
|
-
size(maxFrames);
|
|
647
|
-
const frames = [];
|
|
648
|
-
while (reader.remaining) {
|
|
649
|
-
if (frames.length >= maxFrames)
|
|
650
|
-
throw new RangeError('Too many binary frames');
|
|
651
|
-
frames.push(reader.readFrame(options.canonical ?? true));
|
|
652
|
-
}
|
|
653
|
-
return frames;
|
|
654
|
-
}
|
|
1100
|
+
};
|
|
1101
|
+
var base58$1 = {
|
|
1102
|
+
encode: encode$1,
|
|
1103
|
+
decode: decode$1,
|
|
1104
|
+
isBase58,
|
|
1105
|
+
isBase58Hex,
|
|
1106
|
+
encodeHex,
|
|
1107
|
+
decodeHex,
|
|
1108
|
+
whatType,
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
var isHex = string => /^[A-F0-9]+$/i.test(
|
|
1112
|
+
string.startsWith('0x') ?
|
|
1113
|
+
string.slice(2) :
|
|
1114
|
+
string
|
|
1115
|
+
);
|
|
655
1116
|
|
|
656
1117
|
const asBytes = (source) => {
|
|
657
1118
|
if (source instanceof Uint8Array)
|
|
@@ -8212,7 +8673,7 @@ const utils = {
|
|
|
8212
8673
|
codecs: registry
|
|
8213
8674
|
};
|
|
8214
8675
|
|
|
8215
|
-
class Codec extends BasicInterface {
|
|
8676
|
+
let Codec$1 = class Codec extends BasicInterface {
|
|
8216
8677
|
codecBuffer;
|
|
8217
8678
|
codec;
|
|
8218
8679
|
hashAlg;
|
|
@@ -8313,7 +8774,7 @@ class Codec extends BasicInterface {
|
|
|
8313
8774
|
this.encoded = new BinaryWriter(varUintLength(codec)).writeVarUint(codec).finish();
|
|
8314
8775
|
return this.encoded;
|
|
8315
8776
|
}
|
|
8316
|
-
}
|
|
8777
|
+
};
|
|
8317
8778
|
|
|
8318
8779
|
/*!
|
|
8319
8780
|
* hash-wasm (https://www.npmjs.com/package/hash-wasm)
|
|
@@ -8985,7 +9446,7 @@ class CodecHash extends BasicInterface {
|
|
|
8985
9446
|
this.name = name;
|
|
8986
9447
|
if (!buffer)
|
|
8987
9448
|
throw new Error('buffer is required for encoding');
|
|
8988
|
-
this.discoCodec = new Codec(this.name);
|
|
9449
|
+
this.discoCodec = new Codec$1(this.name);
|
|
8989
9450
|
let hashAlg = this.discoCodec.hashAlg;
|
|
8990
9451
|
const hashVariant = Number(hashAlg.split('-')[hashAlg.split('-').length - 1]);
|
|
8991
9452
|
if (hashAlg.includes('dbl')) {
|
|
@@ -9014,7 +9475,7 @@ class CodecHash extends BasicInterface {
|
|
|
9014
9475
|
buffer = buffer ?? this.encoded;
|
|
9015
9476
|
// Validate completely before changing this instance, including cached encodings.
|
|
9016
9477
|
const header = hashHeader(buffer);
|
|
9017
|
-
const codec = new Codec(header.name);
|
|
9478
|
+
const codec = new Codec$1(header.name);
|
|
9018
9479
|
const digest = new Uint8Array(buffer.subarray(header.offset));
|
|
9019
9480
|
this.#clearEncodingCache();
|
|
9020
9481
|
this.encoded = buffer;
|
|
@@ -9054,13 +9515,13 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
|
|
|
9054
9515
|
hasCodec() {
|
|
9055
9516
|
if (!this.encoded)
|
|
9056
9517
|
return false;
|
|
9057
|
-
const codec = new Codec(this.encoded);
|
|
9518
|
+
const codec = new Codec$1(this.encoded);
|
|
9058
9519
|
if (codec.name)
|
|
9059
9520
|
return true;
|
|
9060
9521
|
}
|
|
9061
9522
|
decode(encoded) {
|
|
9062
9523
|
encoded = encoded || this.encoded;
|
|
9063
|
-
const codec = new Codec(encoded);
|
|
9524
|
+
const codec = new Codec$1(encoded);
|
|
9064
9525
|
if (codec.codecBuffer) {
|
|
9065
9526
|
encoded = encoded.slice(codec.codecBuffer.length);
|
|
9066
9527
|
this.name = codec.name;
|
|
@@ -9078,7 +9539,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
|
|
|
9078
9539
|
encode(decoded) {
|
|
9079
9540
|
let encoded;
|
|
9080
9541
|
decoded = decoded || this.decoded;
|
|
9081
|
-
const codec = new Codec(this.name);
|
|
9542
|
+
const codec = new Codec$1(this.name);
|
|
9082
9543
|
if (decoded instanceof Uint8Array)
|
|
9083
9544
|
encoded = decoded;
|
|
9084
9545
|
else
|
|
@@ -9117,7 +9578,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
|
|
|
9117
9578
|
get contentBytes() {
|
|
9118
9579
|
if (!this.encoded)
|
|
9119
9580
|
return new Uint8Array(0);
|
|
9120
|
-
const codec = new Codec(this.encoded);
|
|
9581
|
+
const codec = new Codec$1(this.encoded);
|
|
9121
9582
|
if (codec.codecBuffer) {
|
|
9122
9583
|
return this.encoded.slice(codec.codecBuffer.length);
|
|
9123
9584
|
}
|
|
@@ -9198,37 +9659,182 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
|
|
|
9198
9659
|
* Interface for defining codec formats
|
|
9199
9660
|
*/
|
|
9200
9661
|
const FormatInterface = FormatInterface$1;
|
|
9662
|
+
/**
|
|
9663
|
+
* Codec utility class
|
|
9664
|
+
*/
|
|
9665
|
+
const Codec = Codec$1;
|
|
9666
|
+
|
|
9667
|
+
const schemas = new WeakMap();
|
|
9668
|
+
const kindOf = (value) => value === undefined ? 'any'
|
|
9669
|
+
: value instanceof Uint8Array ? 'bytes' : Array.isArray(value) ? 'array' : typeof value;
|
|
9670
|
+
function schemaFor(proto) {
|
|
9671
|
+
const cached = schemas.get(proto);
|
|
9672
|
+
if (cached)
|
|
9673
|
+
return cached;
|
|
9674
|
+
const keys = Object.keys(proto);
|
|
9675
|
+
const schema = {
|
|
9676
|
+
fields: keys.map(key => ({
|
|
9677
|
+
key, name: key.endsWith('?') ? key.slice(0, -1) : key, kind: kindOf(proto[key])
|
|
9678
|
+
})),
|
|
9679
|
+
prefixes: new Map()
|
|
9680
|
+
};
|
|
9681
|
+
// Only immutable declarations can safely reuse keys, types and codec framing.
|
|
9682
|
+
// Caller-defined mutable schemas remain supported and are recompiled per operation.
|
|
9683
|
+
if (Object.isFrozen(proto) && keys.every(key => 'value' in Object.getOwnPropertyDescriptor(proto, key)))
|
|
9684
|
+
schemas.set(proto, schema);
|
|
9685
|
+
return schema;
|
|
9686
|
+
}
|
|
9687
|
+
function codecPrefix(schema, name) {
|
|
9688
|
+
let prefix = schema.prefixes.get(name);
|
|
9689
|
+
if (!prefix) {
|
|
9690
|
+
const codec = new Codec(name);
|
|
9691
|
+
if (!codec.codecBuffer)
|
|
9692
|
+
throw new Error('invalid codec');
|
|
9693
|
+
prefix = new Uint8Array(codec.codecBuffer);
|
|
9694
|
+
schema.prefixes.set(name, prefix);
|
|
9695
|
+
}
|
|
9696
|
+
return prefix;
|
|
9697
|
+
}
|
|
9698
|
+
/** Codec prefix + versioned binary tuple, in declared schema order. No proto-array JSON. */
|
|
9699
|
+
class BinaryFormat extends FormatInterface {
|
|
9700
|
+
field(key, value, kind) {
|
|
9701
|
+
if (value === undefined)
|
|
9702
|
+
return value;
|
|
9703
|
+
kind ??= kindOf(this.proto[key]);
|
|
9704
|
+
if (kind === 'any')
|
|
9705
|
+
return value;
|
|
9706
|
+
if (kind === 'bigint') {
|
|
9707
|
+
if (typeof value === 'number' && !Number.isSafeInteger(value))
|
|
9708
|
+
throw new TypeError('Unsafe integer message field');
|
|
9709
|
+
if (!['number', 'string', 'bigint'].includes(typeof value))
|
|
9710
|
+
throw new TypeError('Invalid BigInt message field');
|
|
9711
|
+
return BigInt(value);
|
|
9712
|
+
}
|
|
9713
|
+
if (kind === 'bytes') {
|
|
9714
|
+
if (!(value instanceof Uint8Array))
|
|
9715
|
+
throw new TypeError('Message byte field must be Uint8Array');
|
|
9716
|
+
}
|
|
9717
|
+
else if (kind === 'array') {
|
|
9718
|
+
if (!Array.isArray(value))
|
|
9719
|
+
throw new TypeError('Message array field must be an array');
|
|
9720
|
+
}
|
|
9721
|
+
else if (typeof value !== kind || value === null)
|
|
9722
|
+
throw new TypeError('Message field type mismatch');
|
|
9723
|
+
return value;
|
|
9724
|
+
}
|
|
9725
|
+
create(value) {
|
|
9726
|
+
const { fields } = schemaFor(this.proto);
|
|
9727
|
+
// Content hashes are derived, never trusted from a caller-supplied cache field.
|
|
9728
|
+
this.decoded = Object.fromEntries(fields.map(field => {
|
|
9729
|
+
const input = value?.[field.name];
|
|
9730
|
+
return [field.name, field.kind === 'bigint' ? this.field(field.key, input, field.kind) : input];
|
|
9731
|
+
}));
|
|
9732
|
+
}
|
|
9733
|
+
tuple(value, fields) {
|
|
9734
|
+
const tuple = new Array(fields.length);
|
|
9735
|
+
for (let index = 0; index < fields.length; index++) {
|
|
9736
|
+
const field = fields[index];
|
|
9737
|
+
tuple[index] = this.field(field.key, value[field.name], field.kind);
|
|
9738
|
+
}
|
|
9739
|
+
return tuple;
|
|
9740
|
+
}
|
|
9741
|
+
protoEncode(value) {
|
|
9742
|
+
return encodeValue(this.tuple(value, schemaFor(this.proto).fields));
|
|
9743
|
+
}
|
|
9744
|
+
encode(value) {
|
|
9745
|
+
value = value || this.decoded;
|
|
9746
|
+
const schema = schemaFor(this.proto);
|
|
9747
|
+
const prefix = codecPrefix(schema, this.name);
|
|
9748
|
+
if (value instanceof Uint8Array) {
|
|
9749
|
+
// Preserve the base interface's already-encoded-content path.
|
|
9750
|
+
const output = new Uint8Array(prefix.length + value.length);
|
|
9751
|
+
output.set(prefix);
|
|
9752
|
+
output.set(value, prefix.length);
|
|
9753
|
+
this.encoded = output;
|
|
9754
|
+
}
|
|
9755
|
+
else {
|
|
9756
|
+
this.encoded = encodeValueWithPrefix(this.tuple(value, schema.fields), prefix);
|
|
9757
|
+
}
|
|
9758
|
+
return this.encoded;
|
|
9759
|
+
}
|
|
9760
|
+
protoDecode(bytes) {
|
|
9761
|
+
const values = decodeValue(bytes);
|
|
9762
|
+
const { fields } = schemaFor(this.proto);
|
|
9763
|
+
if (!Array.isArray(values) || values.length !== fields.length)
|
|
9764
|
+
throw new TypeError('Binary message schema mismatch');
|
|
9765
|
+
return Object.fromEntries(fields.map((field, index) => {
|
|
9766
|
+
const value = this.field(field.key, values[index], field.kind);
|
|
9767
|
+
if (typeof value !== typeof values[index])
|
|
9768
|
+
throw new TypeError('Non-canonical message field type');
|
|
9769
|
+
return [field.name, value];
|
|
9770
|
+
}));
|
|
9771
|
+
}
|
|
9772
|
+
decode(bytes) {
|
|
9773
|
+
bytes ??= this.encoded;
|
|
9774
|
+
if (!(bytes instanceof Uint8Array))
|
|
9775
|
+
throw new TypeError('Message payload must be Uint8Array');
|
|
9776
|
+
const codec = new Codec(bytes);
|
|
9777
|
+
if (codec.name !== this.name)
|
|
9778
|
+
throw new TypeError('Wrong binary message codec');
|
|
9779
|
+
// Parse the codec once and borrow its content view; decoded byte fields still own copies.
|
|
9780
|
+
this.decoded = this.protoDecode(bytes.subarray(codec.codecBuffer.length));
|
|
9781
|
+
return this.decoded;
|
|
9782
|
+
}
|
|
9783
|
+
fromUint8Array(bytes) { this.encoded = bytes; return this.decode(bytes); }
|
|
9784
|
+
fromArrayBuffer(buffer) { return this.fromUint8Array(new Uint8Array(buffer)); }
|
|
9785
|
+
}
|
|
9201
9786
|
|
|
9202
|
-
var proto$
|
|
9787
|
+
var proto$1 = defineSchema({
|
|
9203
9788
|
address: String(),
|
|
9204
9789
|
reward: BigInt(0)
|
|
9205
|
-
};
|
|
9790
|
+
});
|
|
9206
9791
|
|
|
9207
|
-
({
|
|
9208
|
-
epoch: BigInt(0)
|
|
9792
|
+
defineSchema({
|
|
9793
|
+
epoch: BigInt(0),
|
|
9794
|
+
configDigest: String(),
|
|
9795
|
+
from: String(),
|
|
9796
|
+
signature: String()
|
|
9797
|
+
});
|
|
9209
9798
|
|
|
9210
|
-
({
|
|
9799
|
+
defineSchema({
|
|
9211
9800
|
epoch: BigInt(0),
|
|
9212
9801
|
threshold: BigInt(0),
|
|
9213
9802
|
participant: BigInt(0),
|
|
9214
|
-
|
|
9803
|
+
from: String(),
|
|
9804
|
+
commitments: Array(),
|
|
9805
|
+
signature: String()
|
|
9806
|
+
});
|
|
9215
9807
|
|
|
9216
|
-
({
|
|
9808
|
+
defineSchema({
|
|
9217
9809
|
epoch: BigInt(0),
|
|
9218
9810
|
round: BigInt(0),
|
|
9219
|
-
participant: BigInt(0)
|
|
9811
|
+
participant: BigInt(0),
|
|
9812
|
+
from: String(),
|
|
9813
|
+
signatureShare: String(),
|
|
9814
|
+
signature: String()
|
|
9815
|
+
});
|
|
9816
|
+
|
|
9817
|
+
defineSchema({
|
|
9818
|
+
up: Number(),
|
|
9819
|
+
down: Number()
|
|
9820
|
+
});
|
|
9220
9821
|
|
|
9221
|
-
|
|
9822
|
+
defineSchema({});
|
|
9823
|
+
|
|
9824
|
+
var proto = defineSchema({
|
|
9222
9825
|
creator: String(),
|
|
9223
9826
|
contract: new Uint8Array(),
|
|
9224
9827
|
constructorParameters: Array()
|
|
9225
|
-
};
|
|
9828
|
+
});
|
|
9226
9829
|
|
|
9227
|
-
({
|
|
9830
|
+
defineSchema({
|
|
9831
|
+
hash: String(),
|
|
9228
9832
|
index: BigInt(0)
|
|
9229
9833
|
});
|
|
9230
9834
|
|
|
9231
|
-
|
|
9835
|
+
defineSchema({});
|
|
9836
|
+
|
|
9837
|
+
defineSchema({
|
|
9232
9838
|
timestamp: Number(),
|
|
9233
9839
|
from: String(),
|
|
9234
9840
|
to: String(),
|
|
@@ -9238,138 +9844,44 @@ var proto = {
|
|
|
9238
9844
|
'nonce?': Number(),
|
|
9239
9845
|
'dependsOn?': Array(),
|
|
9240
9846
|
'priority?': Boolean()
|
|
9241
|
-
};
|
|
9847
|
+
});
|
|
9848
|
+
|
|
9849
|
+
defineSchema({
|
|
9850
|
+
timestamp: Number(),
|
|
9851
|
+
from: String(),
|
|
9852
|
+
to: String(),
|
|
9853
|
+
method: String(),
|
|
9854
|
+
params: Array(),
|
|
9855
|
+
'nonce?': Number()
|
|
9856
|
+
});
|
|
9242
9857
|
|
|
9243
|
-
({
|
|
9244
|
-
|
|
9858
|
+
defineSchema({
|
|
9859
|
+
lastblock: Object(),
|
|
9860
|
+
values: Object()
|
|
9861
|
+
});
|
|
9245
9862
|
|
|
9246
|
-
({
|
|
9863
|
+
defineSchema({
|
|
9864
|
+
blockHash: String(),
|
|
9247
9865
|
index: BigInt(0),
|
|
9248
|
-
round: BigInt(0)
|
|
9866
|
+
round: BigInt(0),
|
|
9867
|
+
from: String(),
|
|
9868
|
+
signature: String()
|
|
9869
|
+
});
|
|
9249
9870
|
|
|
9250
|
-
({
|
|
9871
|
+
defineSchema({
|
|
9872
|
+
blockHash: String(),
|
|
9251
9873
|
index: BigInt(0),
|
|
9252
|
-
round: BigInt(0)
|
|
9874
|
+
round: BigInt(0),
|
|
9875
|
+
from: String(),
|
|
9876
|
+
signature: String()
|
|
9877
|
+
});
|
|
9253
9878
|
|
|
9254
|
-
({
|
|
9879
|
+
defineSchema({
|
|
9880
|
+
blockHash: String(),
|
|
9255
9881
|
index: BigInt(0),
|
|
9256
|
-
round: BigInt(0)
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
#errorEvent = 'error';
|
|
9261
|
-
#isBrowser = false;
|
|
9262
|
-
#isWorker = false;
|
|
9263
|
-
#messageHandler = null;
|
|
9264
|
-
#errorHandler = null;
|
|
9265
|
-
worker;
|
|
9266
|
-
get isWorker() {
|
|
9267
|
-
return this.#isWorker;
|
|
9268
|
-
}
|
|
9269
|
-
constructor(url, options) {
|
|
9270
|
-
return this.#init(url, options);
|
|
9271
|
-
}
|
|
9272
|
-
#init(url, options = {}) {
|
|
9273
|
-
if (url) {
|
|
9274
|
-
if (globalThis.Worker) {
|
|
9275
|
-
this.#isBrowser = true;
|
|
9276
|
-
this.worker = new Worker(url, { ...options });
|
|
9277
|
-
}
|
|
9278
|
-
else {
|
|
9279
|
-
return new Promise((resolve, reject) => {
|
|
9280
|
-
import('child_process').then(({ fork }) => {
|
|
9281
|
-
const child = fork(url, ['easy-worker-child'], options);
|
|
9282
|
-
child.once('error', reject);
|
|
9283
|
-
this.worker = child;
|
|
9284
|
-
resolve(this);
|
|
9285
|
-
}).catch(reject);
|
|
9286
|
-
});
|
|
9287
|
-
}
|
|
9288
|
-
}
|
|
9289
|
-
else {
|
|
9290
|
-
this.#isWorker = true;
|
|
9291
|
-
if (globalThis.process?.argv[2] === 'easy-worker-child') {
|
|
9292
|
-
this.worker = process;
|
|
9293
|
-
}
|
|
9294
|
-
else {
|
|
9295
|
-
this.#isBrowser = true;
|
|
9296
|
-
this.worker = globalThis;
|
|
9297
|
-
}
|
|
9298
|
-
}
|
|
9299
|
-
return this;
|
|
9300
|
-
}
|
|
9301
|
-
onmessage(fn) {
|
|
9302
|
-
if (this.#isBrowser) {
|
|
9303
|
-
this.worker.onmessage = ({ data }) => fn(data);
|
|
9304
|
-
}
|
|
9305
|
-
else {
|
|
9306
|
-
if (this.#messageHandler)
|
|
9307
|
-
this.worker.off(this.#messageEvent, this.#messageHandler);
|
|
9308
|
-
this.#messageHandler = fn;
|
|
9309
|
-
this.worker.on(this.#messageEvent, fn);
|
|
9310
|
-
}
|
|
9311
|
-
}
|
|
9312
|
-
postMessage(message) {
|
|
9313
|
-
if (this.#isBrowser)
|
|
9314
|
-
this.worker.postMessage(message);
|
|
9315
|
-
else
|
|
9316
|
-
this.worker.send(message);
|
|
9317
|
-
}
|
|
9318
|
-
terminate() {
|
|
9319
|
-
if (this.#isBrowser)
|
|
9320
|
-
this.worker.terminate();
|
|
9321
|
-
else
|
|
9322
|
-
this.worker.kill();
|
|
9323
|
-
}
|
|
9324
|
-
onerror(fn) {
|
|
9325
|
-
if (this.#isBrowser) {
|
|
9326
|
-
this.worker.onerror = fn;
|
|
9327
|
-
}
|
|
9328
|
-
else {
|
|
9329
|
-
if (this.#errorHandler)
|
|
9330
|
-
this.worker.off(this.#errorEvent, this.#errorHandler);
|
|
9331
|
-
this.#errorHandler = fn;
|
|
9332
|
-
this.worker.on(this.#errorEvent, fn);
|
|
9333
|
-
}
|
|
9334
|
-
}
|
|
9335
|
-
/**
|
|
9336
|
-
*
|
|
9337
|
-
* @param {*} data
|
|
9338
|
-
* @returns {Promise} resolves result onmessage & rejects on error
|
|
9339
|
-
*/
|
|
9340
|
-
once(data) {
|
|
9341
|
-
return new Promise((resolve, reject) => {
|
|
9342
|
-
if (this.#isBrowser) {
|
|
9343
|
-
const handleMessage = ({ data: result }) => {
|
|
9344
|
-
this.worker.onerror = null;
|
|
9345
|
-
resolve(result);
|
|
9346
|
-
this.terminate();
|
|
9347
|
-
};
|
|
9348
|
-
const handleError = (error) => {
|
|
9349
|
-
this.worker.onmessage = null;
|
|
9350
|
-
reject(error);
|
|
9351
|
-
this.terminate();
|
|
9352
|
-
};
|
|
9353
|
-
this.worker.onmessage = handleMessage;
|
|
9354
|
-
this.worker.onerror = handleError;
|
|
9355
|
-
}
|
|
9356
|
-
else {
|
|
9357
|
-
const handleMessage = (result) => {
|
|
9358
|
-
this.worker.off(this.#errorEvent, handleError);
|
|
9359
|
-
resolve(result);
|
|
9360
|
-
this.terminate();
|
|
9361
|
-
};
|
|
9362
|
-
const handleError = (error) => {
|
|
9363
|
-
this.worker.off(this.#messageEvent, handleMessage);
|
|
9364
|
-
reject(error);
|
|
9365
|
-
this.terminate();
|
|
9366
|
-
};
|
|
9367
|
-
this.worker.once(this.#messageEvent, handleMessage);
|
|
9368
|
-
this.worker.once(this.#errorEvent, handleError);
|
|
9369
|
-
}
|
|
9370
|
-
this.postMessage(data);
|
|
9371
|
-
});
|
|
9372
|
-
}
|
|
9373
|
-
}
|
|
9882
|
+
round: BigInt(0),
|
|
9883
|
+
from: String(),
|
|
9884
|
+
signature: String()
|
|
9885
|
+
});
|
|
9374
9886
|
|
|
9375
|
-
export {
|
|
9887
|
+
export { BinaryWorker as B, BinaryFormat as a, proto$1 as b, encodeValue as c, decodeFrames as d, encodeFrames as e, proto as f, jsonStringifyBigInt$1 as j, proto$2 as p };
|