@typeberry/lib 0.1.2-ef67dce → 0.1.3-707962d
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/index.cjs +494 -49
- package/index.d.ts +1209 -653
- package/index.js +475 -31
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -560,7 +560,7 @@ function isResult(x) {
|
|
|
560
560
|
* as an afterthought.
|
|
561
561
|
*/
|
|
562
562
|
|
|
563
|
-
var index$
|
|
563
|
+
var index$u = /*#__PURE__*/Object.freeze({
|
|
564
564
|
__proto__: null,
|
|
565
565
|
get CURRENT_SUITE () { return CURRENT_SUITE; },
|
|
566
566
|
get CURRENT_VERSION () { return CURRENT_VERSION; },
|
|
@@ -714,7 +714,7 @@ class Ordering {
|
|
|
714
714
|
}
|
|
715
715
|
}
|
|
716
716
|
|
|
717
|
-
var index$
|
|
717
|
+
var index$t = /*#__PURE__*/Object.freeze({
|
|
718
718
|
__proto__: null,
|
|
719
719
|
Ordering: Ordering
|
|
720
720
|
});
|
|
@@ -965,7 +965,7 @@ function u8ArraySameLengthEqual(self, other) {
|
|
|
965
965
|
}
|
|
966
966
|
const bytesBlobComparator = (a, b) => a.compare(b);
|
|
967
967
|
|
|
968
|
-
var index$
|
|
968
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
969
969
|
__proto__: null,
|
|
970
970
|
BitVec: BitVec,
|
|
971
971
|
Bytes: Bytes,
|
|
@@ -1067,7 +1067,7 @@ const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? mi
|
|
|
1067
1067
|
/** Get the biggest value between U64 a and values given as input parameters. */
|
|
1068
1068
|
const maxU64 = (a, ...values) => values.reduce((max, value) => (value < max ? max : value), a);
|
|
1069
1069
|
|
|
1070
|
-
var index$
|
|
1070
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
1071
1071
|
__proto__: null,
|
|
1072
1072
|
isU16: isU16,
|
|
1073
1073
|
isU32: isU32,
|
|
@@ -1944,13 +1944,15 @@ function validateLength(range, length, context) {
|
|
|
1944
1944
|
|
|
1945
1945
|
/** A caching wrapper for either object or sequence item. */
|
|
1946
1946
|
class ViewField {
|
|
1947
|
+
name;
|
|
1947
1948
|
getView;
|
|
1948
1949
|
getValue;
|
|
1949
1950
|
getEncoded;
|
|
1950
1951
|
cachedValue;
|
|
1951
1952
|
cachedView;
|
|
1952
1953
|
cachedBlob;
|
|
1953
|
-
constructor(getView, getValue, getEncoded) {
|
|
1954
|
+
constructor(name, getView, getValue, getEncoded) {
|
|
1955
|
+
this.name = name;
|
|
1954
1956
|
this.getView = getView;
|
|
1955
1957
|
this.getValue = getValue;
|
|
1956
1958
|
this.getEncoded = getEncoded;
|
|
@@ -1976,6 +1978,9 @@ class ViewField {
|
|
|
1976
1978
|
}
|
|
1977
1979
|
return this.cachedBlob;
|
|
1978
1980
|
}
|
|
1981
|
+
toString() {
|
|
1982
|
+
return `ViewField<${this.name}>`;
|
|
1983
|
+
}
|
|
1979
1984
|
}
|
|
1980
1985
|
/**
|
|
1981
1986
|
* A base class for all the lazy views.
|
|
@@ -2050,7 +2055,7 @@ class ObjectView {
|
|
|
2050
2055
|
const fieldDecoder = skipper.decoder.clone();
|
|
2051
2056
|
const field = this.descriptorsKeys[i];
|
|
2052
2057
|
const type = this.descriptors[field];
|
|
2053
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2058
|
+
lastItem = new ViewField(`${this.toString()}.${String(field)}`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2054
2059
|
// skip the field
|
|
2055
2060
|
type.skip(skipper);
|
|
2056
2061
|
// cache data
|
|
@@ -2062,6 +2067,9 @@ class ObjectView {
|
|
|
2062
2067
|
}
|
|
2063
2068
|
return lastItem;
|
|
2064
2069
|
}
|
|
2070
|
+
toString() {
|
|
2071
|
+
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2072
|
+
}
|
|
2065
2073
|
}
|
|
2066
2074
|
/**
|
|
2067
2075
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2150,7 +2158,7 @@ class SequenceView {
|
|
|
2150
2158
|
// create new cached prop
|
|
2151
2159
|
const fieldDecoder = skipper.decoder.clone();
|
|
2152
2160
|
const type = this.descriptor;
|
|
2153
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2161
|
+
lastItem = new ViewField(`${this.toString()}[${index}]`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2154
2162
|
// skip the field
|
|
2155
2163
|
type.skip(skipper);
|
|
2156
2164
|
// cache data
|
|
@@ -2162,6 +2170,9 @@ class SequenceView {
|
|
|
2162
2170
|
}
|
|
2163
2171
|
return lastItem;
|
|
2164
2172
|
}
|
|
2173
|
+
toString() {
|
|
2174
|
+
return `SequenceView<${this.descriptor.name}>(cache: ${this.cache.size})`;
|
|
2175
|
+
}
|
|
2165
2176
|
}
|
|
2166
2177
|
|
|
2167
2178
|
/**
|
|
@@ -2477,7 +2488,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
2477
2488
|
}, skipper);
|
|
2478
2489
|
}
|
|
2479
2490
|
|
|
2480
|
-
var index$
|
|
2491
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
2481
2492
|
__proto__: null,
|
|
2482
2493
|
Decoder: Decoder,
|
|
2483
2494
|
Descriptor: Descriptor,
|
|
@@ -4916,7 +4927,7 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4916
4927
|
hashBlobs: hashBlobs
|
|
4917
4928
|
});
|
|
4918
4929
|
|
|
4919
|
-
var index$
|
|
4930
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
4920
4931
|
__proto__: null,
|
|
4921
4932
|
HASH_SIZE: HASH_SIZE,
|
|
4922
4933
|
PageAllocator: PageAllocator,
|
|
@@ -4982,7 +4993,7 @@ var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
|
4982
4993
|
trivialSeed: trivialSeed
|
|
4983
4994
|
});
|
|
4984
4995
|
|
|
4985
|
-
var index$
|
|
4996
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4986
4997
|
__proto__: null,
|
|
4987
4998
|
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
4988
4999
|
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
@@ -5586,7 +5597,7 @@ class TruncatedHashDictionary {
|
|
|
5586
5597
|
}
|
|
5587
5598
|
}
|
|
5588
5599
|
|
|
5589
|
-
var index$
|
|
5600
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
5590
5601
|
__proto__: null,
|
|
5591
5602
|
FixedSizeArray: FixedSizeArray,
|
|
5592
5603
|
HashDictionary: HashDictionary,
|
|
@@ -5781,7 +5792,7 @@ class Bootnode {
|
|
|
5781
5792
|
}
|
|
5782
5793
|
}
|
|
5783
5794
|
|
|
5784
|
-
var index$
|
|
5795
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
5785
5796
|
__proto__: null,
|
|
5786
5797
|
Bootnode: Bootnode,
|
|
5787
5798
|
ChainSpec: ChainSpec,
|
|
@@ -7276,7 +7287,7 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
7276
7287
|
});
|
|
7277
7288
|
}
|
|
7278
7289
|
|
|
7279
|
-
var index$
|
|
7290
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
7280
7291
|
__proto__: null,
|
|
7281
7292
|
Block: Block,
|
|
7282
7293
|
EpochMarker: EpochMarker,
|
|
@@ -7532,7 +7543,7 @@ var json;
|
|
|
7532
7543
|
json.object = object;
|
|
7533
7544
|
})(json || (json = {}));
|
|
7534
7545
|
|
|
7535
|
-
var index$
|
|
7546
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
7536
7547
|
__proto__: null,
|
|
7537
7548
|
get json () { return json; },
|
|
7538
7549
|
parseFromJson: parseFromJson
|
|
@@ -7802,7 +7813,7 @@ const blockFromJson = (spec) => json.object({
|
|
|
7802
7813
|
extrinsic: getExtrinsicFromJson(spec),
|
|
7803
7814
|
}, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
|
|
7804
7815
|
|
|
7805
|
-
var index$
|
|
7816
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
7806
7817
|
__proto__: null,
|
|
7807
7818
|
blockFromJson: blockFromJson,
|
|
7808
7819
|
disputesExtrinsicFromJson: disputesExtrinsicFromJson,
|
|
@@ -8300,7 +8311,7 @@ class Logger {
|
|
|
8300
8311
|
}
|
|
8301
8312
|
}
|
|
8302
8313
|
|
|
8303
|
-
var index$
|
|
8314
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
8304
8315
|
__proto__: null,
|
|
8305
8316
|
get Level () { return Level; },
|
|
8306
8317
|
Logger: Logger,
|
|
@@ -8323,7 +8334,7 @@ class AuthorshipOptions {
|
|
|
8323
8334
|
}
|
|
8324
8335
|
}
|
|
8325
8336
|
|
|
8326
|
-
const logger$
|
|
8337
|
+
const logger$5 = Logger.new(import.meta.filename, "config");
|
|
8327
8338
|
/** Development config. Will accept unsealed blocks for now. */
|
|
8328
8339
|
const DEV_CONFIG = "dev";
|
|
8329
8340
|
/** Default config file. */
|
|
@@ -8382,15 +8393,15 @@ class NodeConfiguration {
|
|
|
8382
8393
|
}
|
|
8383
8394
|
function loadConfig(configPath) {
|
|
8384
8395
|
if (configPath === DEFAULT_CONFIG) {
|
|
8385
|
-
logger$
|
|
8396
|
+
logger$5.log `🔧 Loading DEFAULT config`;
|
|
8386
8397
|
return parseFromJson(configs.default, NodeConfiguration.fromJson);
|
|
8387
8398
|
}
|
|
8388
8399
|
if (configPath === DEV_CONFIG) {
|
|
8389
|
-
logger$
|
|
8400
|
+
logger$5.log `🔧 Loading DEV config`;
|
|
8390
8401
|
return parseFromJson(configs.dev, NodeConfiguration.fromJson);
|
|
8391
8402
|
}
|
|
8392
8403
|
try {
|
|
8393
|
-
logger$
|
|
8404
|
+
logger$5.log `🔧 Loading config from ${configPath}`;
|
|
8394
8405
|
const configFile = fs.readFileSync(configPath, "utf8");
|
|
8395
8406
|
const parsed = JSON.parse(configFile);
|
|
8396
8407
|
return parseFromJson(parsed, NodeConfiguration.fromJson);
|
|
@@ -8400,7 +8411,7 @@ function loadConfig(configPath) {
|
|
|
8400
8411
|
}
|
|
8401
8412
|
}
|
|
8402
8413
|
|
|
8403
|
-
var index$
|
|
8414
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
8404
8415
|
__proto__: null,
|
|
8405
8416
|
DEFAULT_CONFIG: DEFAULT_CONFIG,
|
|
8406
8417
|
DEV_CONFIG: DEV_CONFIG,
|
|
@@ -10066,7 +10077,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
10066
10077
|
sortKeys: (a, b) => a - b,
|
|
10067
10078
|
});
|
|
10068
10079
|
|
|
10069
|
-
var index$
|
|
10080
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
10070
10081
|
__proto__: null,
|
|
10071
10082
|
AccumulationOutput: AccumulationOutput,
|
|
10072
10083
|
AutoAccumulate: AutoAccumulate,
|
|
@@ -11076,7 +11087,7 @@ const bitLookup = [
|
|
|
11076
11087
|
[0b00000000, 8],
|
|
11077
11088
|
];
|
|
11078
11089
|
|
|
11079
|
-
var index$
|
|
11090
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
11080
11091
|
__proto__: null,
|
|
11081
11092
|
BranchNode: BranchNode,
|
|
11082
11093
|
InMemoryTrie: InMemoryTrie,
|
|
@@ -11422,7 +11433,7 @@ function loadState(spec, entries) {
|
|
|
11422
11433
|
* hashmap of `key -> value` entries.
|
|
11423
11434
|
*/
|
|
11424
11435
|
|
|
11425
|
-
var index$
|
|
11436
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
11426
11437
|
__proto__: null,
|
|
11427
11438
|
SerializedService: SerializedService,
|
|
11428
11439
|
SerializedState: SerializedState,
|
|
@@ -11708,7 +11719,7 @@ class InMemoryStates {
|
|
|
11708
11719
|
}
|
|
11709
11720
|
}
|
|
11710
11721
|
|
|
11711
|
-
var index$
|
|
11722
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
11712
11723
|
__proto__: null,
|
|
11713
11724
|
InMemoryBlocks: InMemoryBlocks,
|
|
11714
11725
|
InMemoryStates: InMemoryStates,
|
|
@@ -12070,7 +12081,7 @@ const initEc = async () => {
|
|
|
12070
12081
|
await init.reedSolomon();
|
|
12071
12082
|
};
|
|
12072
12083
|
|
|
12073
|
-
var index$
|
|
12084
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
12074
12085
|
__proto__: null,
|
|
12075
12086
|
N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
|
|
12076
12087
|
N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
|
|
@@ -12094,6 +12105,439 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
12094
12105
|
unzip: unzip
|
|
12095
12106
|
});
|
|
12096
12107
|
|
|
12108
|
+
/**
|
|
12109
|
+
* Version ::= SEQUENCE {
|
|
12110
|
+
* major INTEGER (0..255),
|
|
12111
|
+
* minor INTEGER (0..255),
|
|
12112
|
+
* patch INTEGER (0..255)
|
|
12113
|
+
* }
|
|
12114
|
+
*/
|
|
12115
|
+
class Version extends WithDebug {
|
|
12116
|
+
major;
|
|
12117
|
+
minor;
|
|
12118
|
+
patch;
|
|
12119
|
+
static Codec = codec$1.Class(Version, {
|
|
12120
|
+
major: codec$1.u8,
|
|
12121
|
+
minor: codec$1.u8,
|
|
12122
|
+
patch: codec$1.u8,
|
|
12123
|
+
});
|
|
12124
|
+
static tryFromString(str) {
|
|
12125
|
+
const parse = (v) => tryAsU8(Number(v));
|
|
12126
|
+
try {
|
|
12127
|
+
const [major, minor, patch] = str.trim().split(".").map(parse);
|
|
12128
|
+
return Version.create({
|
|
12129
|
+
major,
|
|
12130
|
+
minor,
|
|
12131
|
+
patch,
|
|
12132
|
+
});
|
|
12133
|
+
}
|
|
12134
|
+
catch (e) {
|
|
12135
|
+
throw new Error(`Unable to parse ${str} as Version: ${e}`);
|
|
12136
|
+
}
|
|
12137
|
+
}
|
|
12138
|
+
static create({ major, minor, patch }) {
|
|
12139
|
+
return new Version(major, minor, patch);
|
|
12140
|
+
}
|
|
12141
|
+
constructor(major, minor, patch) {
|
|
12142
|
+
super();
|
|
12143
|
+
this.major = major;
|
|
12144
|
+
this.minor = minor;
|
|
12145
|
+
this.patch = patch;
|
|
12146
|
+
}
|
|
12147
|
+
}
|
|
12148
|
+
/**
|
|
12149
|
+
* Fuzzer Protocol V1
|
|
12150
|
+
* Reference: https://github.com/davxy/jam-conformance/blob/main/fuzz-proto/fuzz.asn
|
|
12151
|
+
*/
|
|
12152
|
+
// Feature bit constants
|
|
12153
|
+
var Features;
|
|
12154
|
+
(function (Features) {
|
|
12155
|
+
Features[Features["Ancestry"] = 1] = "Ancestry";
|
|
12156
|
+
Features[Features["Fork"] = 2] = "Fork";
|
|
12157
|
+
Features[Features["Reserved"] = 2147483648] = "Reserved";
|
|
12158
|
+
})(Features || (Features = {}));
|
|
12159
|
+
/**
|
|
12160
|
+
* PeerInfo ::= SEQUENCE {
|
|
12161
|
+
* fuzz-version U8,
|
|
12162
|
+
* features Features,
|
|
12163
|
+
* jam-version Version,
|
|
12164
|
+
* app-version Version,
|
|
12165
|
+
* name UTF8String
|
|
12166
|
+
* }
|
|
12167
|
+
*/
|
|
12168
|
+
class PeerInfo extends WithDebug {
|
|
12169
|
+
fuzzVersion;
|
|
12170
|
+
features;
|
|
12171
|
+
jamVersion;
|
|
12172
|
+
appVersion;
|
|
12173
|
+
name;
|
|
12174
|
+
static Codec = codec$1.Class(PeerInfo, {
|
|
12175
|
+
fuzzVersion: codec$1.u8,
|
|
12176
|
+
features: codec$1.u32,
|
|
12177
|
+
jamVersion: Version.Codec,
|
|
12178
|
+
appVersion: Version.Codec,
|
|
12179
|
+
name: codec$1.string,
|
|
12180
|
+
});
|
|
12181
|
+
static create({ fuzzVersion, features, appVersion, jamVersion, name }) {
|
|
12182
|
+
return new PeerInfo(fuzzVersion, features, jamVersion, appVersion, name);
|
|
12183
|
+
}
|
|
12184
|
+
constructor(fuzzVersion, features, jamVersion, appVersion, name) {
|
|
12185
|
+
super();
|
|
12186
|
+
this.fuzzVersion = fuzzVersion;
|
|
12187
|
+
this.features = features;
|
|
12188
|
+
this.jamVersion = jamVersion;
|
|
12189
|
+
this.appVersion = appVersion;
|
|
12190
|
+
this.name = name;
|
|
12191
|
+
}
|
|
12192
|
+
}
|
|
12193
|
+
/**
|
|
12194
|
+
* AncestryItem ::= SEQUENCE {
|
|
12195
|
+
* slot TimeSlot,
|
|
12196
|
+
* header-hash HeaderHash
|
|
12197
|
+
* }
|
|
12198
|
+
*/
|
|
12199
|
+
class AncestryItem extends WithDebug {
|
|
12200
|
+
slot;
|
|
12201
|
+
headerHash;
|
|
12202
|
+
static Codec = codec$1.Class(AncestryItem, {
|
|
12203
|
+
slot: codec$1.u32.asOpaque(),
|
|
12204
|
+
headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
12205
|
+
});
|
|
12206
|
+
static create({ slot, headerHash }) {
|
|
12207
|
+
return new AncestryItem(slot, headerHash);
|
|
12208
|
+
}
|
|
12209
|
+
constructor(slot, headerHash) {
|
|
12210
|
+
super();
|
|
12211
|
+
this.slot = slot;
|
|
12212
|
+
this.headerHash = headerHash;
|
|
12213
|
+
}
|
|
12214
|
+
}
|
|
12215
|
+
/**
|
|
12216
|
+
* KeyValue ::= SEQUENCE {
|
|
12217
|
+
* key TrieKey,
|
|
12218
|
+
* value OCTET STRING
|
|
12219
|
+
* }
|
|
12220
|
+
*/
|
|
12221
|
+
class KeyValue extends WithDebug {
|
|
12222
|
+
key;
|
|
12223
|
+
value;
|
|
12224
|
+
static Codec = codec$1.Class(KeyValue, {
|
|
12225
|
+
key: codec$1.bytes(TRUNCATED_HASH_SIZE),
|
|
12226
|
+
value: codec$1.blob,
|
|
12227
|
+
});
|
|
12228
|
+
static create({ key, value }) {
|
|
12229
|
+
return new KeyValue(key, value);
|
|
12230
|
+
}
|
|
12231
|
+
constructor(key, value) {
|
|
12232
|
+
super();
|
|
12233
|
+
this.key = key;
|
|
12234
|
+
this.value = value;
|
|
12235
|
+
}
|
|
12236
|
+
}
|
|
12237
|
+
/** State ::= SEQUENCE OF KeyValue */
|
|
12238
|
+
const stateCodec = codec$1.sequenceVarLen(KeyValue.Codec);
|
|
12239
|
+
/**
|
|
12240
|
+
* Ancestry ::= SEQUENCE (SIZE(0..24)) OF AncestryItem
|
|
12241
|
+
* Empty when `feature-ancestry` is not supported by both parties
|
|
12242
|
+
*/
|
|
12243
|
+
const ancestryCodec = codec$1.sequenceVarLen(AncestryItem.Codec, {
|
|
12244
|
+
minLength: 0,
|
|
12245
|
+
maxLength: 24,
|
|
12246
|
+
});
|
|
12247
|
+
/**
|
|
12248
|
+
* Initialize ::= SEQUENCE {
|
|
12249
|
+
* header Header,
|
|
12250
|
+
* keyvals State,
|
|
12251
|
+
* ancestry Ancestry
|
|
12252
|
+
* }
|
|
12253
|
+
*/
|
|
12254
|
+
class Initialize extends WithDebug {
|
|
12255
|
+
header;
|
|
12256
|
+
keyvals;
|
|
12257
|
+
ancestry;
|
|
12258
|
+
static Codec = codec$1.Class(Initialize, {
|
|
12259
|
+
header: Header.Codec,
|
|
12260
|
+
keyvals: stateCodec,
|
|
12261
|
+
ancestry: ancestryCodec,
|
|
12262
|
+
});
|
|
12263
|
+
static create({ header, keyvals, ancestry }) {
|
|
12264
|
+
return new Initialize(header, keyvals, ancestry);
|
|
12265
|
+
}
|
|
12266
|
+
constructor(header, keyvals, ancestry) {
|
|
12267
|
+
super();
|
|
12268
|
+
this.header = header;
|
|
12269
|
+
this.keyvals = keyvals;
|
|
12270
|
+
this.ancestry = ancestry;
|
|
12271
|
+
}
|
|
12272
|
+
}
|
|
12273
|
+
/** GetState ::= HeaderHash */
|
|
12274
|
+
const getStateCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
12275
|
+
/** StateRoot ::= StateRootHash */
|
|
12276
|
+
const stateRootCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
12277
|
+
/** Error ::= UTF8String */
|
|
12278
|
+
class ErrorMessage extends WithDebug {
|
|
12279
|
+
message;
|
|
12280
|
+
static Codec = codec$1.Class(ErrorMessage, {
|
|
12281
|
+
message: codec$1.string,
|
|
12282
|
+
});
|
|
12283
|
+
static create({ message }) {
|
|
12284
|
+
return new ErrorMessage(message);
|
|
12285
|
+
}
|
|
12286
|
+
constructor(message) {
|
|
12287
|
+
super();
|
|
12288
|
+
this.message = message;
|
|
12289
|
+
}
|
|
12290
|
+
}
|
|
12291
|
+
/** Message choice type tags */
|
|
12292
|
+
var MessageType;
|
|
12293
|
+
(function (MessageType) {
|
|
12294
|
+
MessageType[MessageType["PeerInfo"] = 0] = "PeerInfo";
|
|
12295
|
+
MessageType[MessageType["Initialize"] = 1] = "Initialize";
|
|
12296
|
+
MessageType[MessageType["StateRoot"] = 2] = "StateRoot";
|
|
12297
|
+
MessageType[MessageType["ImportBlock"] = 3] = "ImportBlock";
|
|
12298
|
+
MessageType[MessageType["GetState"] = 4] = "GetState";
|
|
12299
|
+
MessageType[MessageType["State"] = 5] = "State";
|
|
12300
|
+
MessageType[MessageType["Error"] = 255] = "Error";
|
|
12301
|
+
})(MessageType || (MessageType = {}));
|
|
12302
|
+
/**
|
|
12303
|
+
* Message ::= CHOICE {
|
|
12304
|
+
* peer-info [0] PeerInfo,
|
|
12305
|
+
* initialize [1] Initialize,
|
|
12306
|
+
* state-root [2] StateRoot,
|
|
12307
|
+
* import-block [3] ImportBlock,
|
|
12308
|
+
* get-state [4] GetState,
|
|
12309
|
+
* state [5] State,
|
|
12310
|
+
* error [255] Error
|
|
12311
|
+
* }
|
|
12312
|
+
*/
|
|
12313
|
+
const messageCodec = codec$1.custom({
|
|
12314
|
+
name: "Message",
|
|
12315
|
+
sizeHint: { bytes: 1, isExact: false },
|
|
12316
|
+
}, (e, msg) => {
|
|
12317
|
+
e.i8(msg.type);
|
|
12318
|
+
switch (msg.type) {
|
|
12319
|
+
case MessageType.PeerInfo:
|
|
12320
|
+
PeerInfo.Codec.encode(e, msg.value);
|
|
12321
|
+
break;
|
|
12322
|
+
case MessageType.Initialize:
|
|
12323
|
+
Initialize.Codec.encode(e, msg.value);
|
|
12324
|
+
break;
|
|
12325
|
+
case MessageType.StateRoot:
|
|
12326
|
+
stateRootCodec.encode(e, msg.value);
|
|
12327
|
+
break;
|
|
12328
|
+
case MessageType.ImportBlock:
|
|
12329
|
+
Block.Codec.View.encode(e, msg.value);
|
|
12330
|
+
break;
|
|
12331
|
+
case MessageType.GetState:
|
|
12332
|
+
getStateCodec.encode(e, msg.value);
|
|
12333
|
+
break;
|
|
12334
|
+
case MessageType.State:
|
|
12335
|
+
stateCodec.encode(e, msg.value);
|
|
12336
|
+
break;
|
|
12337
|
+
case MessageType.Error:
|
|
12338
|
+
ErrorMessage.Codec.encode(e, msg.value);
|
|
12339
|
+
break;
|
|
12340
|
+
default:
|
|
12341
|
+
throw new Error(`Unknown message type: ${msg}`);
|
|
12342
|
+
}
|
|
12343
|
+
}, (d) => {
|
|
12344
|
+
const type = d.u8();
|
|
12345
|
+
switch (type) {
|
|
12346
|
+
case MessageType.PeerInfo:
|
|
12347
|
+
return { type: MessageType.PeerInfo, value: PeerInfo.Codec.decode(d) };
|
|
12348
|
+
case MessageType.Initialize:
|
|
12349
|
+
return { type: MessageType.Initialize, value: Initialize.Codec.decode(d) };
|
|
12350
|
+
case MessageType.StateRoot:
|
|
12351
|
+
return { type: MessageType.StateRoot, value: stateRootCodec.decode(d) };
|
|
12352
|
+
case MessageType.ImportBlock:
|
|
12353
|
+
return { type: MessageType.ImportBlock, value: Block.Codec.View.decode(d) };
|
|
12354
|
+
case MessageType.GetState:
|
|
12355
|
+
return { type: MessageType.GetState, value: getStateCodec.decode(d) };
|
|
12356
|
+
case MessageType.State:
|
|
12357
|
+
return { type: MessageType.State, value: stateCodec.decode(d) };
|
|
12358
|
+
case MessageType.Error:
|
|
12359
|
+
return { type: MessageType.Error, value: ErrorMessage.Codec.decode(d) };
|
|
12360
|
+
default:
|
|
12361
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
12362
|
+
}
|
|
12363
|
+
}, (s) => {
|
|
12364
|
+
const type = s.decoder.u8();
|
|
12365
|
+
switch (type) {
|
|
12366
|
+
case MessageType.PeerInfo:
|
|
12367
|
+
PeerInfo.Codec.View.skip(s);
|
|
12368
|
+
break;
|
|
12369
|
+
case MessageType.Initialize:
|
|
12370
|
+
Initialize.Codec.View.skip(s);
|
|
12371
|
+
break;
|
|
12372
|
+
case MessageType.StateRoot:
|
|
12373
|
+
stateRootCodec.View.skip(s);
|
|
12374
|
+
break;
|
|
12375
|
+
case MessageType.ImportBlock:
|
|
12376
|
+
Block.Codec.View.skip(s);
|
|
12377
|
+
break;
|
|
12378
|
+
case MessageType.GetState:
|
|
12379
|
+
getStateCodec.View.skip(s);
|
|
12380
|
+
break;
|
|
12381
|
+
case MessageType.State:
|
|
12382
|
+
stateCodec.View.skip(s);
|
|
12383
|
+
break;
|
|
12384
|
+
case MessageType.Error:
|
|
12385
|
+
ErrorMessage.Codec.View.skip(s);
|
|
12386
|
+
break;
|
|
12387
|
+
default:
|
|
12388
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
12389
|
+
}
|
|
12390
|
+
});
|
|
12391
|
+
|
|
12392
|
+
const logger$4 = Logger.new(import.meta.filename, "ext-ipc-fuzz-v1");
|
|
12393
|
+
class FuzzTarget {
|
|
12394
|
+
msgHandler;
|
|
12395
|
+
sender;
|
|
12396
|
+
spec;
|
|
12397
|
+
sessionFeatures = 0;
|
|
12398
|
+
constructor(msgHandler, sender, spec) {
|
|
12399
|
+
this.msgHandler = msgHandler;
|
|
12400
|
+
this.sender = sender;
|
|
12401
|
+
this.spec = spec;
|
|
12402
|
+
}
|
|
12403
|
+
async onSocketMessage(msg) {
|
|
12404
|
+
// attempt to decode the messsage
|
|
12405
|
+
try {
|
|
12406
|
+
const message = Decoder.decodeObject(messageCodec, msg, this.spec);
|
|
12407
|
+
logger$4.log `[${message.type}] incoming message`;
|
|
12408
|
+
await this.processAndRespond(message);
|
|
12409
|
+
}
|
|
12410
|
+
catch (e) {
|
|
12411
|
+
logger$4.error `Error while processing fuzz v1 message: ${e}`;
|
|
12412
|
+
logger$4.error `${e}`;
|
|
12413
|
+
if (e instanceof Error) {
|
|
12414
|
+
logger$4.error `${e.stack ?? ""}`;
|
|
12415
|
+
}
|
|
12416
|
+
this.sender.close();
|
|
12417
|
+
}
|
|
12418
|
+
}
|
|
12419
|
+
async processAndRespond(message) {
|
|
12420
|
+
let response = null;
|
|
12421
|
+
switch (message.type) {
|
|
12422
|
+
case MessageType.PeerInfo: {
|
|
12423
|
+
// only support V1
|
|
12424
|
+
if (message.value.fuzzVersion !== 1) {
|
|
12425
|
+
logger$4.warn `Unsupported fuzzer protocol version: ${message.value.fuzzVersion}. Closing`;
|
|
12426
|
+
this.sender.close();
|
|
12427
|
+
return;
|
|
12428
|
+
}
|
|
12429
|
+
// Handle handshake
|
|
12430
|
+
const ourPeerInfo = await this.msgHandler.getPeerInfo(message.value);
|
|
12431
|
+
// Calculate session features (intersection of both peer features)
|
|
12432
|
+
this.sessionFeatures = message.value.features & ourPeerInfo.features;
|
|
12433
|
+
logger$4.info `Handshake completed. Shared features: 0b${this.sessionFeatures.toString(2)}`;
|
|
12434
|
+
logger$4.log `Feature ancestry: ${(this.sessionFeatures & Features.Ancestry) !== 0}`;
|
|
12435
|
+
logger$4.log `Feature fork: ${(this.sessionFeatures & Features.Fork) !== 0}`;
|
|
12436
|
+
response = {
|
|
12437
|
+
type: MessageType.PeerInfo,
|
|
12438
|
+
value: ourPeerInfo,
|
|
12439
|
+
};
|
|
12440
|
+
break;
|
|
12441
|
+
}
|
|
12442
|
+
case MessageType.Initialize: {
|
|
12443
|
+
const stateRoot = await this.msgHandler.initialize(message.value);
|
|
12444
|
+
response = {
|
|
12445
|
+
type: MessageType.StateRoot,
|
|
12446
|
+
value: stateRoot,
|
|
12447
|
+
};
|
|
12448
|
+
break;
|
|
12449
|
+
}
|
|
12450
|
+
case MessageType.ImportBlock: {
|
|
12451
|
+
const result = await this.msgHandler.importBlock(message.value);
|
|
12452
|
+
if (result.isOk) {
|
|
12453
|
+
response = {
|
|
12454
|
+
type: MessageType.StateRoot,
|
|
12455
|
+
value: result.ok,
|
|
12456
|
+
};
|
|
12457
|
+
}
|
|
12458
|
+
else {
|
|
12459
|
+
response = {
|
|
12460
|
+
type: MessageType.Error,
|
|
12461
|
+
value: result.error,
|
|
12462
|
+
};
|
|
12463
|
+
}
|
|
12464
|
+
break;
|
|
12465
|
+
}
|
|
12466
|
+
case MessageType.GetState: {
|
|
12467
|
+
const state = await this.msgHandler.getSerializedState(message.value);
|
|
12468
|
+
response = {
|
|
12469
|
+
type: MessageType.State,
|
|
12470
|
+
value: state,
|
|
12471
|
+
};
|
|
12472
|
+
break;
|
|
12473
|
+
}
|
|
12474
|
+
case MessageType.StateRoot: {
|
|
12475
|
+
logger$4.log `--> Received unexpected 'StateRoot' message from the fuzzer. Closing.`;
|
|
12476
|
+
this.sender.close();
|
|
12477
|
+
return;
|
|
12478
|
+
}
|
|
12479
|
+
case MessageType.State: {
|
|
12480
|
+
logger$4.log `--> Received unexpected 'State' message from the fuzzer. Closing.`;
|
|
12481
|
+
this.sender.close();
|
|
12482
|
+
return;
|
|
12483
|
+
}
|
|
12484
|
+
case MessageType.Error: {
|
|
12485
|
+
logger$4.log `--> Received unexpected 'Error' message from the fuzzer. Closing.`;
|
|
12486
|
+
this.sender.close();
|
|
12487
|
+
return;
|
|
12488
|
+
}
|
|
12489
|
+
default: {
|
|
12490
|
+
logger$4.log `--> Received unexpected message type ${JSON.stringify(message)} from the fuzzer. Closing.`;
|
|
12491
|
+
this.sender.close();
|
|
12492
|
+
try {
|
|
12493
|
+
assertNever(message);
|
|
12494
|
+
}
|
|
12495
|
+
catch {
|
|
12496
|
+
return;
|
|
12497
|
+
}
|
|
12498
|
+
}
|
|
12499
|
+
}
|
|
12500
|
+
if (response !== null) {
|
|
12501
|
+
logger$4.trace `<-- responding with: ${response.type}`;
|
|
12502
|
+
const encoded = Encoder.encodeObject(messageCodec, response, this.spec);
|
|
12503
|
+
this.sender.send(encoded);
|
|
12504
|
+
}
|
|
12505
|
+
else {
|
|
12506
|
+
logger$4.warn `<-- no response generated for: ${message.type}`;
|
|
12507
|
+
}
|
|
12508
|
+
}
|
|
12509
|
+
onClose({ error }) {
|
|
12510
|
+
logger$4.log `Closing the v1 handler. Reason: ${error !== undefined ? error.message : "close"}.`;
|
|
12511
|
+
}
|
|
12512
|
+
/** Check if a specific feature is enabled in the session */
|
|
12513
|
+
hasFeature(feature) {
|
|
12514
|
+
return (this.sessionFeatures & feature) !== 0;
|
|
12515
|
+
}
|
|
12516
|
+
}
|
|
12517
|
+
|
|
12518
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
12519
|
+
__proto__: null,
|
|
12520
|
+
AncestryItem: AncestryItem,
|
|
12521
|
+
ErrorMessage: ErrorMessage,
|
|
12522
|
+
get Features () { return Features; },
|
|
12523
|
+
FuzzTarget: FuzzTarget,
|
|
12524
|
+
Initialize: Initialize,
|
|
12525
|
+
KeyValue: KeyValue,
|
|
12526
|
+
get MessageType () { return MessageType; },
|
|
12527
|
+
PeerInfo: PeerInfo,
|
|
12528
|
+
Version: Version,
|
|
12529
|
+
ancestryCodec: ancestryCodec,
|
|
12530
|
+
getStateCodec: getStateCodec,
|
|
12531
|
+
messageCodec: messageCodec,
|
|
12532
|
+
stateCodec: stateCodec,
|
|
12533
|
+
stateRootCodec: stateRootCodec
|
|
12534
|
+
});
|
|
12535
|
+
|
|
12536
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
12537
|
+
__proto__: null,
|
|
12538
|
+
v1: index$b
|
|
12539
|
+
});
|
|
12540
|
+
|
|
12097
12541
|
/** Size of the transfer memo. */
|
|
12098
12542
|
const TRANSFER_MEMO_BYTES = W_T;
|
|
12099
12543
|
/**
|
|
@@ -16936,8 +17380,8 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16936
17380
|
asOpaqueType: asOpaqueType,
|
|
16937
17381
|
assertEmpty: assertEmpty,
|
|
16938
17382
|
assertNever: assertNever,
|
|
16939
|
-
block: index$
|
|
16940
|
-
bytes: index$
|
|
17383
|
+
block: index$l,
|
|
17384
|
+
bytes: index$s,
|
|
16941
17385
|
check: check,
|
|
16942
17386
|
clampU64ToU32: clampU64ToU32,
|
|
16943
17387
|
createResults: createResults,
|
|
@@ -16945,13 +17389,13 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16945
17389
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
16946
17390
|
getServiceId: getServiceId,
|
|
16947
17391
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
16948
|
-
hash: index$
|
|
17392
|
+
hash: index$p,
|
|
16949
17393
|
inspect: inspect,
|
|
16950
17394
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
16951
17395
|
interpreter: index$7,
|
|
16952
17396
|
isBrowser: isBrowser,
|
|
16953
17397
|
measure: measure,
|
|
16954
|
-
numbers: index$
|
|
17398
|
+
numbers: index$r,
|
|
16955
17399
|
resultToString: resultToString,
|
|
16956
17400
|
seeThrough: seeThrough,
|
|
16957
17401
|
slotsToPreimageStatus: slotsToPreimageStatus,
|
|
@@ -17665,4 +18109,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
17665
18109
|
WorkPackageExecutor: WorkPackageExecutor
|
|
17666
18110
|
});
|
|
17667
18111
|
|
|
17668
|
-
export { index$
|
|
18112
|
+
export { index$l as block, index$j as block_json, index$s as bytes, index$q as codec, index$n as collections, index$m as config, index$h as config_node, index$o as crypto, index$d as database, index$c as erasure_coding, index$a as fuzz_proto, index$p as hash, index$9 as jam_host_calls, index$k as json_parser, index$i as logger, index$8 as mmr, index$r as numbers, index$t as ordering, index$3 as pvm, index$6 as pvm_host_calls, index$7 as pvm_interpreter, index$4 as pvm_program, index$5 as pvm_spi_decoder, index$2 as shuffling, index$g as state, index$1 as state_json, index$e as state_merkleization, index as transition, index$f as trie, index$u as utils };
|