@leofcoin/workers 1.5.44 → 1.6.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/exports/binary-worker-BxQdEW3s.js +672 -0
- package/exports/binary-worker.d.ts +11 -0
- package/exports/binary-worker.js +1 -0
- package/exports/block-worker.js +7 -7
- package/exports/browser/binary-worker-BxQdEW3s.js +672 -0
- package/exports/browser/binary-worker.js +1 -0
- package/exports/browser/block-worker.js +7 -7
- package/exports/browser/machine-worker.js +139 -1192
- package/exports/browser/{worker-BDTWOCzS.js → proposal.proto-8zgMfutf.js} +205 -362
- package/exports/machine-worker.js +139 -1192
- package/exports/{worker-BDTWOCzS.js → proposal.proto-8zgMfutf.js} +205 -362
- package/package.json +9 -4
- package/src/block-worker.js +1 -1
- package/src/pool-worker.js +1 -1
- package/src/transaction-worker.js +1 -1
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { e as encodeFrames, d as decodeFrames, b as BinaryReader, c as BinaryWriter, v as varUintLength, a as encodeValue, f as encodeValueWithPrefix, g as decodeValue } from './binary-worker-BxQdEW3s.js';
|
|
2
|
+
|
|
3
|
+
/** Freeze declarations, not decoded messages. Keep existing consumer field types mutable. */
|
|
4
|
+
const defineSchema = (proto) => Object.freeze(proto);
|
|
5
|
+
|
|
6
|
+
var proto$2 = defineSchema({
|
|
2
7
|
index: BigInt(0),
|
|
3
8
|
previousHash: String(),
|
|
4
9
|
timestamp: Number(),
|
|
@@ -9,7 +14,7 @@ var proto$3 = {
|
|
|
9
14
|
producer: String(),
|
|
10
15
|
producerProof: String(),
|
|
11
16
|
protocolVersion: String()
|
|
12
|
-
};
|
|
17
|
+
});
|
|
13
18
|
|
|
14
19
|
// base-x encoding / decoding
|
|
15
20
|
// Copyright (c) 2018 base-x contributors
|
|
@@ -440,219 +445,6 @@ var isHex = string => /^[A-F0-9]+$/i.test(
|
|
|
440
445
|
string
|
|
441
446
|
);
|
|
442
447
|
|
|
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');
|
|
606
|
-
}
|
|
607
|
-
readBytes(length) {
|
|
608
|
-
size(length);
|
|
609
|
-
if (length > this.remaining)
|
|
610
|
-
throw new RangeError('Truncated binary field');
|
|
611
|
-
const start = this.#position;
|
|
612
|
-
this.#position += length;
|
|
613
|
-
return this.#buffer.subarray(start, this.#position);
|
|
614
|
-
}
|
|
615
|
-
readFrame(canonical = true) {
|
|
616
|
-
const start = this.#position;
|
|
617
|
-
try {
|
|
618
|
-
return this.readBytes(this.readVarUint(canonical));
|
|
619
|
-
}
|
|
620
|
-
catch (error) {
|
|
621
|
-
this.#position = start;
|
|
622
|
-
throw error;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
/** Existing smart-concat bytes, with exactly one output allocation and no prefix arrays. */
|
|
627
|
-
function encodeFrames(frames, prefix) {
|
|
628
|
-
if (!Array.isArray(frames))
|
|
629
|
-
throw new TypeError('Expected an array of byte frames');
|
|
630
|
-
let length = 0;
|
|
631
|
-
for (const frame of frames) {
|
|
632
|
-
bytes(frame);
|
|
633
|
-
length += varUintLength(frame.length) + frame.length;
|
|
634
|
-
size(length);
|
|
635
|
-
}
|
|
636
|
-
const writer = new BinaryWriter(length);
|
|
637
|
-
for (const frame of frames)
|
|
638
|
-
writer.writeFrame(frame);
|
|
639
|
-
return writer.finish();
|
|
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
|
-
}
|
|
655
|
-
|
|
656
448
|
const asBytes = (source) => {
|
|
657
449
|
if (source instanceof Uint8Array)
|
|
658
450
|
return source;
|
|
@@ -8212,7 +8004,7 @@ const utils = {
|
|
|
8212
8004
|
codecs: registry
|
|
8213
8005
|
};
|
|
8214
8006
|
|
|
8215
|
-
class Codec extends BasicInterface {
|
|
8007
|
+
let Codec$1 = class Codec extends BasicInterface {
|
|
8216
8008
|
codecBuffer;
|
|
8217
8009
|
codec;
|
|
8218
8010
|
hashAlg;
|
|
@@ -8313,7 +8105,7 @@ class Codec extends BasicInterface {
|
|
|
8313
8105
|
this.encoded = new BinaryWriter(varUintLength(codec)).writeVarUint(codec).finish();
|
|
8314
8106
|
return this.encoded;
|
|
8315
8107
|
}
|
|
8316
|
-
}
|
|
8108
|
+
};
|
|
8317
8109
|
|
|
8318
8110
|
/*!
|
|
8319
8111
|
* hash-wasm (https://www.npmjs.com/package/hash-wasm)
|
|
@@ -8985,7 +8777,7 @@ class CodecHash extends BasicInterface {
|
|
|
8985
8777
|
this.name = name;
|
|
8986
8778
|
if (!buffer)
|
|
8987
8779
|
throw new Error('buffer is required for encoding');
|
|
8988
|
-
this.discoCodec = new Codec(this.name);
|
|
8780
|
+
this.discoCodec = new Codec$1(this.name);
|
|
8989
8781
|
let hashAlg = this.discoCodec.hashAlg;
|
|
8990
8782
|
const hashVariant = Number(hashAlg.split('-')[hashAlg.split('-').length - 1]);
|
|
8991
8783
|
if (hashAlg.includes('dbl')) {
|
|
@@ -9014,7 +8806,7 @@ class CodecHash extends BasicInterface {
|
|
|
9014
8806
|
buffer = buffer ?? this.encoded;
|
|
9015
8807
|
// Validate completely before changing this instance, including cached encodings.
|
|
9016
8808
|
const header = hashHeader(buffer);
|
|
9017
|
-
const codec = new Codec(header.name);
|
|
8809
|
+
const codec = new Codec$1(header.name);
|
|
9018
8810
|
const digest = new Uint8Array(buffer.subarray(header.offset));
|
|
9019
8811
|
this.#clearEncodingCache();
|
|
9020
8812
|
this.encoded = buffer;
|
|
@@ -9054,13 +8846,13 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
|
|
|
9054
8846
|
hasCodec() {
|
|
9055
8847
|
if (!this.encoded)
|
|
9056
8848
|
return false;
|
|
9057
|
-
const codec = new Codec(this.encoded);
|
|
8849
|
+
const codec = new Codec$1(this.encoded);
|
|
9058
8850
|
if (codec.name)
|
|
9059
8851
|
return true;
|
|
9060
8852
|
}
|
|
9061
8853
|
decode(encoded) {
|
|
9062
8854
|
encoded = encoded || this.encoded;
|
|
9063
|
-
const codec = new Codec(encoded);
|
|
8855
|
+
const codec = new Codec$1(encoded);
|
|
9064
8856
|
if (codec.codecBuffer) {
|
|
9065
8857
|
encoded = encoded.slice(codec.codecBuffer.length);
|
|
9066
8858
|
this.name = codec.name;
|
|
@@ -9078,7 +8870,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
|
|
|
9078
8870
|
encode(decoded) {
|
|
9079
8871
|
let encoded;
|
|
9080
8872
|
decoded = decoded || this.decoded;
|
|
9081
|
-
const codec = new Codec(this.name);
|
|
8873
|
+
const codec = new Codec$1(this.name);
|
|
9082
8874
|
if (decoded instanceof Uint8Array)
|
|
9083
8875
|
encoded = decoded;
|
|
9084
8876
|
else
|
|
@@ -9117,7 +8909,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
|
|
|
9117
8909
|
get contentBytes() {
|
|
9118
8910
|
if (!this.encoded)
|
|
9119
8911
|
return new Uint8Array(0);
|
|
9120
|
-
const codec = new Codec(this.encoded);
|
|
8912
|
+
const codec = new Codec$1(this.encoded);
|
|
9121
8913
|
if (codec.codecBuffer) {
|
|
9122
8914
|
return this.encoded.slice(codec.codecBuffer.length);
|
|
9123
8915
|
}
|
|
@@ -9198,37 +8990,182 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
|
|
|
9198
8990
|
* Interface for defining codec formats
|
|
9199
8991
|
*/
|
|
9200
8992
|
const FormatInterface = FormatInterface$1;
|
|
8993
|
+
/**
|
|
8994
|
+
* Codec utility class
|
|
8995
|
+
*/
|
|
8996
|
+
const Codec = Codec$1;
|
|
8997
|
+
|
|
8998
|
+
const schemas = new WeakMap();
|
|
8999
|
+
const kindOf = (value) => value === undefined ? 'any'
|
|
9000
|
+
: value instanceof Uint8Array ? 'bytes' : Array.isArray(value) ? 'array' : typeof value;
|
|
9001
|
+
function schemaFor(proto) {
|
|
9002
|
+
const cached = schemas.get(proto);
|
|
9003
|
+
if (cached)
|
|
9004
|
+
return cached;
|
|
9005
|
+
const keys = Object.keys(proto);
|
|
9006
|
+
const schema = {
|
|
9007
|
+
fields: keys.map(key => ({
|
|
9008
|
+
key, name: key.endsWith('?') ? key.slice(0, -1) : key, kind: kindOf(proto[key])
|
|
9009
|
+
})),
|
|
9010
|
+
prefixes: new Map()
|
|
9011
|
+
};
|
|
9012
|
+
// Only immutable declarations can safely reuse keys, types and codec framing.
|
|
9013
|
+
// Caller-defined mutable schemas remain supported and are recompiled per operation.
|
|
9014
|
+
if (Object.isFrozen(proto) && keys.every(key => 'value' in Object.getOwnPropertyDescriptor(proto, key)))
|
|
9015
|
+
schemas.set(proto, schema);
|
|
9016
|
+
return schema;
|
|
9017
|
+
}
|
|
9018
|
+
function codecPrefix(schema, name) {
|
|
9019
|
+
let prefix = schema.prefixes.get(name);
|
|
9020
|
+
if (!prefix) {
|
|
9021
|
+
const codec = new Codec(name);
|
|
9022
|
+
if (!codec.codecBuffer)
|
|
9023
|
+
throw new Error('invalid codec');
|
|
9024
|
+
prefix = new Uint8Array(codec.codecBuffer);
|
|
9025
|
+
schema.prefixes.set(name, prefix);
|
|
9026
|
+
}
|
|
9027
|
+
return prefix;
|
|
9028
|
+
}
|
|
9029
|
+
/** Codec prefix + versioned binary tuple, in declared schema order. No proto-array JSON. */
|
|
9030
|
+
class BinaryFormat extends FormatInterface {
|
|
9031
|
+
field(key, value, kind) {
|
|
9032
|
+
if (value === undefined)
|
|
9033
|
+
return value;
|
|
9034
|
+
kind ??= kindOf(this.proto[key]);
|
|
9035
|
+
if (kind === 'any')
|
|
9036
|
+
return value;
|
|
9037
|
+
if (kind === 'bigint') {
|
|
9038
|
+
if (typeof value === 'number' && !Number.isSafeInteger(value))
|
|
9039
|
+
throw new TypeError('Unsafe integer message field');
|
|
9040
|
+
if (!['number', 'string', 'bigint'].includes(typeof value))
|
|
9041
|
+
throw new TypeError('Invalid BigInt message field');
|
|
9042
|
+
return BigInt(value);
|
|
9043
|
+
}
|
|
9044
|
+
if (kind === 'bytes') {
|
|
9045
|
+
if (!(value instanceof Uint8Array))
|
|
9046
|
+
throw new TypeError('Message byte field must be Uint8Array');
|
|
9047
|
+
}
|
|
9048
|
+
else if (kind === 'array') {
|
|
9049
|
+
if (!Array.isArray(value))
|
|
9050
|
+
throw new TypeError('Message array field must be an array');
|
|
9051
|
+
}
|
|
9052
|
+
else if (typeof value !== kind || value === null)
|
|
9053
|
+
throw new TypeError('Message field type mismatch');
|
|
9054
|
+
return value;
|
|
9055
|
+
}
|
|
9056
|
+
create(value) {
|
|
9057
|
+
const { fields } = schemaFor(this.proto);
|
|
9058
|
+
// Content hashes are derived, never trusted from a caller-supplied cache field.
|
|
9059
|
+
this.decoded = Object.fromEntries(fields.map(field => {
|
|
9060
|
+
const input = value?.[field.name];
|
|
9061
|
+
return [field.name, field.kind === 'bigint' ? this.field(field.key, input, field.kind) : input];
|
|
9062
|
+
}));
|
|
9063
|
+
}
|
|
9064
|
+
tuple(value, fields) {
|
|
9065
|
+
const tuple = new Array(fields.length);
|
|
9066
|
+
for (let index = 0; index < fields.length; index++) {
|
|
9067
|
+
const field = fields[index];
|
|
9068
|
+
tuple[index] = this.field(field.key, value[field.name], field.kind);
|
|
9069
|
+
}
|
|
9070
|
+
return tuple;
|
|
9071
|
+
}
|
|
9072
|
+
protoEncode(value) {
|
|
9073
|
+
return encodeValue(this.tuple(value, schemaFor(this.proto).fields));
|
|
9074
|
+
}
|
|
9075
|
+
encode(value) {
|
|
9076
|
+
value = value || this.decoded;
|
|
9077
|
+
const schema = schemaFor(this.proto);
|
|
9078
|
+
const prefix = codecPrefix(schema, this.name);
|
|
9079
|
+
if (value instanceof Uint8Array) {
|
|
9080
|
+
// Preserve the base interface's already-encoded-content path.
|
|
9081
|
+
const output = new Uint8Array(prefix.length + value.length);
|
|
9082
|
+
output.set(prefix);
|
|
9083
|
+
output.set(value, prefix.length);
|
|
9084
|
+
this.encoded = output;
|
|
9085
|
+
}
|
|
9086
|
+
else {
|
|
9087
|
+
this.encoded = encodeValueWithPrefix(this.tuple(value, schema.fields), prefix);
|
|
9088
|
+
}
|
|
9089
|
+
return this.encoded;
|
|
9090
|
+
}
|
|
9091
|
+
protoDecode(bytes) {
|
|
9092
|
+
const values = decodeValue(bytes);
|
|
9093
|
+
const { fields } = schemaFor(this.proto);
|
|
9094
|
+
if (!Array.isArray(values) || values.length !== fields.length)
|
|
9095
|
+
throw new TypeError('Binary message schema mismatch');
|
|
9096
|
+
return Object.fromEntries(fields.map((field, index) => {
|
|
9097
|
+
const value = this.field(field.key, values[index], field.kind);
|
|
9098
|
+
if (typeof value !== typeof values[index])
|
|
9099
|
+
throw new TypeError('Non-canonical message field type');
|
|
9100
|
+
return [field.name, value];
|
|
9101
|
+
}));
|
|
9102
|
+
}
|
|
9103
|
+
decode(bytes) {
|
|
9104
|
+
bytes ??= this.encoded;
|
|
9105
|
+
if (!(bytes instanceof Uint8Array))
|
|
9106
|
+
throw new TypeError('Message payload must be Uint8Array');
|
|
9107
|
+
const codec = new Codec(bytes);
|
|
9108
|
+
if (codec.name !== this.name)
|
|
9109
|
+
throw new TypeError('Wrong binary message codec');
|
|
9110
|
+
// Parse the codec once and borrow its content view; decoded byte fields still own copies.
|
|
9111
|
+
this.decoded = this.protoDecode(bytes.subarray(codec.codecBuffer.length));
|
|
9112
|
+
return this.decoded;
|
|
9113
|
+
}
|
|
9114
|
+
fromUint8Array(bytes) { this.encoded = bytes; return this.decode(bytes); }
|
|
9115
|
+
fromArrayBuffer(buffer) { return this.fromUint8Array(new Uint8Array(buffer)); }
|
|
9116
|
+
}
|
|
9201
9117
|
|
|
9202
|
-
var proto$
|
|
9118
|
+
var proto$1 = defineSchema({
|
|
9203
9119
|
address: String(),
|
|
9204
9120
|
reward: BigInt(0)
|
|
9205
|
-
};
|
|
9121
|
+
});
|
|
9206
9122
|
|
|
9207
|
-
({
|
|
9208
|
-
epoch: BigInt(0)
|
|
9123
|
+
defineSchema({
|
|
9124
|
+
epoch: BigInt(0),
|
|
9125
|
+
configDigest: String(),
|
|
9126
|
+
from: String(),
|
|
9127
|
+
signature: String()
|
|
9128
|
+
});
|
|
9209
9129
|
|
|
9210
|
-
({
|
|
9130
|
+
defineSchema({
|
|
9211
9131
|
epoch: BigInt(0),
|
|
9212
9132
|
threshold: BigInt(0),
|
|
9213
9133
|
participant: BigInt(0),
|
|
9214
|
-
|
|
9134
|
+
from: String(),
|
|
9135
|
+
commitments: Array(),
|
|
9136
|
+
signature: String()
|
|
9137
|
+
});
|
|
9215
9138
|
|
|
9216
|
-
({
|
|
9139
|
+
defineSchema({
|
|
9217
9140
|
epoch: BigInt(0),
|
|
9218
9141
|
round: BigInt(0),
|
|
9219
|
-
participant: BigInt(0)
|
|
9142
|
+
participant: BigInt(0),
|
|
9143
|
+
from: String(),
|
|
9144
|
+
signatureShare: String(),
|
|
9145
|
+
signature: String()
|
|
9146
|
+
});
|
|
9147
|
+
|
|
9148
|
+
defineSchema({
|
|
9149
|
+
up: Number(),
|
|
9150
|
+
down: Number()
|
|
9151
|
+
});
|
|
9152
|
+
|
|
9153
|
+
defineSchema({});
|
|
9220
9154
|
|
|
9221
|
-
var proto
|
|
9155
|
+
var proto = defineSchema({
|
|
9222
9156
|
creator: String(),
|
|
9223
9157
|
contract: new Uint8Array(),
|
|
9224
9158
|
constructorParameters: Array()
|
|
9225
|
-
};
|
|
9159
|
+
});
|
|
9226
9160
|
|
|
9227
|
-
({
|
|
9161
|
+
defineSchema({
|
|
9162
|
+
hash: String(),
|
|
9228
9163
|
index: BigInt(0)
|
|
9229
9164
|
});
|
|
9230
9165
|
|
|
9231
|
-
|
|
9166
|
+
defineSchema({});
|
|
9167
|
+
|
|
9168
|
+
defineSchema({
|
|
9232
9169
|
timestamp: Number(),
|
|
9233
9170
|
from: String(),
|
|
9234
9171
|
to: String(),
|
|
@@ -9238,138 +9175,44 @@ var proto = {
|
|
|
9238
9175
|
'nonce?': Number(),
|
|
9239
9176
|
'dependsOn?': Array(),
|
|
9240
9177
|
'priority?': Boolean()
|
|
9241
|
-
};
|
|
9178
|
+
});
|
|
9242
9179
|
|
|
9243
|
-
({
|
|
9244
|
-
|
|
9180
|
+
defineSchema({
|
|
9181
|
+
timestamp: Number(),
|
|
9182
|
+
from: String(),
|
|
9183
|
+
to: String(),
|
|
9184
|
+
method: String(),
|
|
9185
|
+
params: Array(),
|
|
9186
|
+
'nonce?': Number()
|
|
9187
|
+
});
|
|
9245
9188
|
|
|
9246
|
-
({
|
|
9189
|
+
defineSchema({
|
|
9190
|
+
lastblock: Object(),
|
|
9191
|
+
values: Object()
|
|
9192
|
+
});
|
|
9193
|
+
|
|
9194
|
+
defineSchema({
|
|
9195
|
+
blockHash: String(),
|
|
9247
9196
|
index: BigInt(0),
|
|
9248
|
-
round: BigInt(0)
|
|
9197
|
+
round: BigInt(0),
|
|
9198
|
+
from: String(),
|
|
9199
|
+
signature: String()
|
|
9200
|
+
});
|
|
9249
9201
|
|
|
9250
|
-
({
|
|
9202
|
+
defineSchema({
|
|
9203
|
+
blockHash: String(),
|
|
9251
9204
|
index: BigInt(0),
|
|
9252
|
-
round: BigInt(0)
|
|
9205
|
+
round: BigInt(0),
|
|
9206
|
+
from: String(),
|
|
9207
|
+
signature: String()
|
|
9208
|
+
});
|
|
9253
9209
|
|
|
9254
|
-
({
|
|
9210
|
+
defineSchema({
|
|
9211
|
+
blockHash: String(),
|
|
9255
9212
|
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
|
-
}
|
|
9213
|
+
round: BigInt(0),
|
|
9214
|
+
from: String(),
|
|
9215
|
+
signature: String()
|
|
9216
|
+
});
|
|
9374
9217
|
|
|
9375
|
-
export {
|
|
9218
|
+
export { BinaryFormat as B, proto$2 as a, proto as b, jsonStringifyBigInt$1 as j, proto$1 as p };
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/workers",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Workers used in @leofcoin/chain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"exports": {
|
|
8
|
+
"./binary-worker": {
|
|
9
|
+
"import": "./exports/binary-worker.js",
|
|
10
|
+
"types": "./exports/binary-worker.d.ts"
|
|
11
|
+
},
|
|
8
12
|
"./machine-worker": {
|
|
9
13
|
"import": "./exports/machine-worker.js",
|
|
10
14
|
"types": "./exports/machine-worker.d.ts"
|
|
@@ -35,11 +39,12 @@
|
|
|
35
39
|
"author": "",
|
|
36
40
|
"license": "MIT",
|
|
37
41
|
"dependencies": {
|
|
42
|
+
"@leofcoin/binary": "^1.1.0",
|
|
38
43
|
"@noble/hashes": "^2.4.0",
|
|
39
44
|
"acorn": "^8.19.0",
|
|
40
|
-
"@leofcoin/addresses": "^1.0
|
|
41
|
-
"@leofcoin/lib": "^1.
|
|
42
|
-
"@leofcoin/messages": "^
|
|
45
|
+
"@leofcoin/addresses": "^1.1.0",
|
|
46
|
+
"@leofcoin/lib": "^1.4.0",
|
|
47
|
+
"@leofcoin/messages": "^2.0.0",
|
|
43
48
|
"@leofcoin/storage": "^3.5.38",
|
|
44
49
|
"@leofcoin/utils": "^1.1.45",
|
|
45
50
|
"@vandeurenglenn/easy-worker": "^1.0.3"
|