@typeberry/lib 0.1.2-953c012 → 0.1.2-a90b655
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/bin/lib/index.d.ts +1 -0
- package/index.cjs +482 -48
- package/index.d.ts +1193 -652
- package/index.js +463 -30
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -563,7 +563,7 @@ function isResult(x) {
|
|
|
563
563
|
* as an afterthought.
|
|
564
564
|
*/
|
|
565
565
|
|
|
566
|
-
var index$
|
|
566
|
+
var index$u = /*#__PURE__*/Object.freeze({
|
|
567
567
|
__proto__: null,
|
|
568
568
|
get CURRENT_SUITE () { return CURRENT_SUITE; },
|
|
569
569
|
get CURRENT_VERSION () { return CURRENT_VERSION; },
|
|
@@ -717,7 +717,7 @@ class Ordering {
|
|
|
717
717
|
}
|
|
718
718
|
}
|
|
719
719
|
|
|
720
|
-
var index$
|
|
720
|
+
var index$t = /*#__PURE__*/Object.freeze({
|
|
721
721
|
__proto__: null,
|
|
722
722
|
Ordering: Ordering
|
|
723
723
|
});
|
|
@@ -968,7 +968,7 @@ function u8ArraySameLengthEqual(self, other) {
|
|
|
968
968
|
}
|
|
969
969
|
const bytesBlobComparator = (a, b) => a.compare(b);
|
|
970
970
|
|
|
971
|
-
var index$
|
|
971
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
972
972
|
__proto__: null,
|
|
973
973
|
BitVec: BitVec,
|
|
974
974
|
Bytes: Bytes,
|
|
@@ -1070,7 +1070,7 @@ const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? mi
|
|
|
1070
1070
|
/** Get the biggest value between U64 a and values given as input parameters. */
|
|
1071
1071
|
const maxU64 = (a, ...values) => values.reduce((max, value) => (value < max ? max : value), a);
|
|
1072
1072
|
|
|
1073
|
-
var index$
|
|
1073
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
1074
1074
|
__proto__: null,
|
|
1075
1075
|
isU16: isU16,
|
|
1076
1076
|
isU32: isU32,
|
|
@@ -2480,7 +2480,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
2480
2480
|
}, skipper);
|
|
2481
2481
|
}
|
|
2482
2482
|
|
|
2483
|
-
var index$
|
|
2483
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
2484
2484
|
__proto__: null,
|
|
2485
2485
|
Decoder: Decoder,
|
|
2486
2486
|
Descriptor: Descriptor,
|
|
@@ -4919,7 +4919,7 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4919
4919
|
hashBlobs: hashBlobs
|
|
4920
4920
|
});
|
|
4921
4921
|
|
|
4922
|
-
var index$
|
|
4922
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
4923
4923
|
__proto__: null,
|
|
4924
4924
|
HASH_SIZE: HASH_SIZE,
|
|
4925
4925
|
PageAllocator: PageAllocator,
|
|
@@ -4985,7 +4985,7 @@ var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
|
4985
4985
|
trivialSeed: trivialSeed
|
|
4986
4986
|
});
|
|
4987
4987
|
|
|
4988
|
-
var index$
|
|
4988
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4989
4989
|
__proto__: null,
|
|
4990
4990
|
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
4991
4991
|
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
@@ -5589,7 +5589,7 @@ class TruncatedHashDictionary {
|
|
|
5589
5589
|
}
|
|
5590
5590
|
}
|
|
5591
5591
|
|
|
5592
|
-
var index$
|
|
5592
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
5593
5593
|
__proto__: null,
|
|
5594
5594
|
FixedSizeArray: FixedSizeArray,
|
|
5595
5595
|
HashDictionary: HashDictionary,
|
|
@@ -5784,7 +5784,7 @@ class Bootnode {
|
|
|
5784
5784
|
}
|
|
5785
5785
|
}
|
|
5786
5786
|
|
|
5787
|
-
var index$
|
|
5787
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
5788
5788
|
__proto__: null,
|
|
5789
5789
|
Bootnode: Bootnode,
|
|
5790
5790
|
ChainSpec: ChainSpec,
|
|
@@ -7261,7 +7261,7 @@ class Block extends WithDebug {
|
|
|
7261
7261
|
}
|
|
7262
7262
|
}
|
|
7263
7263
|
|
|
7264
|
-
var index$
|
|
7264
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
7265
7265
|
__proto__: null,
|
|
7266
7266
|
Block: Block,
|
|
7267
7267
|
EpochMarker: EpochMarker,
|
|
@@ -7516,7 +7516,7 @@ var json;
|
|
|
7516
7516
|
json.object = object;
|
|
7517
7517
|
})(json || (json = {}));
|
|
7518
7518
|
|
|
7519
|
-
var index$
|
|
7519
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
7520
7520
|
__proto__: null,
|
|
7521
7521
|
get json () { return json; },
|
|
7522
7522
|
parseFromJson: parseFromJson
|
|
@@ -7786,7 +7786,7 @@ const blockFromJson = (spec) => json.object({
|
|
|
7786
7786
|
extrinsic: getExtrinsicFromJson(spec),
|
|
7787
7787
|
}, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
|
|
7788
7788
|
|
|
7789
|
-
var index$
|
|
7789
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
7790
7790
|
__proto__: null,
|
|
7791
7791
|
blockFromJson: blockFromJson,
|
|
7792
7792
|
disputesExtrinsicFromJson: disputesExtrinsicFromJson,
|
|
@@ -8052,8 +8052,8 @@ function print(level, levelAndName, strings, data) {
|
|
|
8052
8052
|
return;
|
|
8053
8053
|
}
|
|
8054
8054
|
const lvlText = Level[level].padEnd(5);
|
|
8055
|
-
const val = strings.map((v, idx) => `${v}${
|
|
8056
|
-
const msg = `${lvlText} [${levelAndName[1]}] ${val
|
|
8055
|
+
const val = strings.map((v, idx) => `${v}${data[idx]}`);
|
|
8056
|
+
const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
|
|
8057
8057
|
if (level === Level.WARN) {
|
|
8058
8058
|
console.warn(msg);
|
|
8059
8059
|
}
|
|
@@ -8284,7 +8284,7 @@ class Logger {
|
|
|
8284
8284
|
}
|
|
8285
8285
|
}
|
|
8286
8286
|
|
|
8287
|
-
var index$
|
|
8287
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
8288
8288
|
__proto__: null,
|
|
8289
8289
|
get Level () { return Level; },
|
|
8290
8290
|
Logger: Logger,
|
|
@@ -8307,7 +8307,7 @@ class AuthorshipOptions {
|
|
|
8307
8307
|
}
|
|
8308
8308
|
}
|
|
8309
8309
|
|
|
8310
|
-
const logger$
|
|
8310
|
+
const logger$5 = Logger.new(undefined, "config");
|
|
8311
8311
|
/** Development config. Will accept unsealed blocks for now. */
|
|
8312
8312
|
const DEV_CONFIG = "dev";
|
|
8313
8313
|
/** Default config file. */
|
|
@@ -8366,15 +8366,15 @@ class NodeConfiguration {
|
|
|
8366
8366
|
}
|
|
8367
8367
|
function loadConfig(configPath) {
|
|
8368
8368
|
if (configPath === DEFAULT_CONFIG) {
|
|
8369
|
-
logger$
|
|
8369
|
+
logger$5.log `🔧 Loading DEFAULT config`;
|
|
8370
8370
|
return parseFromJson(configs.default, NodeConfiguration.fromJson);
|
|
8371
8371
|
}
|
|
8372
8372
|
if (configPath === DEV_CONFIG) {
|
|
8373
|
-
logger$
|
|
8373
|
+
logger$5.log `🔧 Loading DEV config`;
|
|
8374
8374
|
return parseFromJson(configs.dev, NodeConfiguration.fromJson);
|
|
8375
8375
|
}
|
|
8376
8376
|
try {
|
|
8377
|
-
logger$
|
|
8377
|
+
logger$5.log `🔧 Loading config from ${configPath}`;
|
|
8378
8378
|
const configFile = fs.readFileSync(configPath, "utf8");
|
|
8379
8379
|
const parsed = JSON.parse(configFile);
|
|
8380
8380
|
return parseFromJson(parsed, NodeConfiguration.fromJson);
|
|
@@ -8384,7 +8384,7 @@ function loadConfig(configPath) {
|
|
|
8384
8384
|
}
|
|
8385
8385
|
}
|
|
8386
8386
|
|
|
8387
|
-
var index$
|
|
8387
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
8388
8388
|
__proto__: null,
|
|
8389
8389
|
DEFAULT_CONFIG: DEFAULT_CONFIG,
|
|
8390
8390
|
DEV_CONFIG: DEV_CONFIG,
|
|
@@ -10050,7 +10050,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
10050
10050
|
sortKeys: (a, b) => a - b,
|
|
10051
10051
|
});
|
|
10052
10052
|
|
|
10053
|
-
var index$
|
|
10053
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
10054
10054
|
__proto__: null,
|
|
10055
10055
|
AccumulationOutput: AccumulationOutput,
|
|
10056
10056
|
AutoAccumulate: AutoAccumulate,
|
|
@@ -11060,7 +11060,7 @@ const bitLookup = [
|
|
|
11060
11060
|
[0b00000000, 8],
|
|
11061
11061
|
];
|
|
11062
11062
|
|
|
11063
|
-
var index$
|
|
11063
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
11064
11064
|
__proto__: null,
|
|
11065
11065
|
BranchNode: BranchNode,
|
|
11066
11066
|
InMemoryTrie: InMemoryTrie,
|
|
@@ -11406,7 +11406,7 @@ function loadState(spec, entries) {
|
|
|
11406
11406
|
* hashmap of `key -> value` entries.
|
|
11407
11407
|
*/
|
|
11408
11408
|
|
|
11409
|
-
var index$
|
|
11409
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
11410
11410
|
__proto__: null,
|
|
11411
11411
|
SerializedService: SerializedService,
|
|
11412
11412
|
SerializedState: SerializedState,
|
|
@@ -11692,7 +11692,7 @@ class InMemoryStates {
|
|
|
11692
11692
|
}
|
|
11693
11693
|
}
|
|
11694
11694
|
|
|
11695
|
-
var index$
|
|
11695
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
11696
11696
|
__proto__: null,
|
|
11697
11697
|
InMemoryBlocks: InMemoryBlocks,
|
|
11698
11698
|
InMemoryStates: InMemoryStates,
|
|
@@ -12054,7 +12054,7 @@ const initEc = async () => {
|
|
|
12054
12054
|
await init.reedSolomon();
|
|
12055
12055
|
};
|
|
12056
12056
|
|
|
12057
|
-
var index$
|
|
12057
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
12058
12058
|
__proto__: null,
|
|
12059
12059
|
N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
|
|
12060
12060
|
N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
|
|
@@ -12078,6 +12078,439 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
12078
12078
|
unzip: unzip
|
|
12079
12079
|
});
|
|
12080
12080
|
|
|
12081
|
+
/**
|
|
12082
|
+
* Version ::= SEQUENCE {
|
|
12083
|
+
* major INTEGER (0..255),
|
|
12084
|
+
* minor INTEGER (0..255),
|
|
12085
|
+
* patch INTEGER (0..255)
|
|
12086
|
+
* }
|
|
12087
|
+
*/
|
|
12088
|
+
class Version extends WithDebug {
|
|
12089
|
+
major;
|
|
12090
|
+
minor;
|
|
12091
|
+
patch;
|
|
12092
|
+
static Codec = codec$1.Class(Version, {
|
|
12093
|
+
major: codec$1.u8,
|
|
12094
|
+
minor: codec$1.u8,
|
|
12095
|
+
patch: codec$1.u8,
|
|
12096
|
+
});
|
|
12097
|
+
static tryFromString(str) {
|
|
12098
|
+
const parse = (v) => tryAsU8(Number(v));
|
|
12099
|
+
try {
|
|
12100
|
+
const [major, minor, patch] = str.trim().split(".").map(parse);
|
|
12101
|
+
return Version.create({
|
|
12102
|
+
major,
|
|
12103
|
+
minor,
|
|
12104
|
+
patch,
|
|
12105
|
+
});
|
|
12106
|
+
}
|
|
12107
|
+
catch (e) {
|
|
12108
|
+
throw new Error(`Unable to parse ${str} as Version: ${e}`);
|
|
12109
|
+
}
|
|
12110
|
+
}
|
|
12111
|
+
static create({ major, minor, patch }) {
|
|
12112
|
+
return new Version(major, minor, patch);
|
|
12113
|
+
}
|
|
12114
|
+
constructor(major, minor, patch) {
|
|
12115
|
+
super();
|
|
12116
|
+
this.major = major;
|
|
12117
|
+
this.minor = minor;
|
|
12118
|
+
this.patch = patch;
|
|
12119
|
+
}
|
|
12120
|
+
}
|
|
12121
|
+
/**
|
|
12122
|
+
* Fuzzer Protocol V1
|
|
12123
|
+
* Reference: https://github.com/davxy/jam-conformance/blob/main/fuzz-proto/fuzz.asn
|
|
12124
|
+
*/
|
|
12125
|
+
// Feature bit constants
|
|
12126
|
+
var Features;
|
|
12127
|
+
(function (Features) {
|
|
12128
|
+
Features[Features["Ancestry"] = 1] = "Ancestry";
|
|
12129
|
+
Features[Features["Fork"] = 2] = "Fork";
|
|
12130
|
+
Features[Features["Reserved"] = 2147483648] = "Reserved";
|
|
12131
|
+
})(Features || (Features = {}));
|
|
12132
|
+
/**
|
|
12133
|
+
* PeerInfo ::= SEQUENCE {
|
|
12134
|
+
* fuzz-version U8,
|
|
12135
|
+
* features Features,
|
|
12136
|
+
* jam-version Version,
|
|
12137
|
+
* app-version Version,
|
|
12138
|
+
* name UTF8String
|
|
12139
|
+
* }
|
|
12140
|
+
*/
|
|
12141
|
+
class PeerInfo extends WithDebug {
|
|
12142
|
+
fuzzVersion;
|
|
12143
|
+
features;
|
|
12144
|
+
jamVersion;
|
|
12145
|
+
appVersion;
|
|
12146
|
+
name;
|
|
12147
|
+
static Codec = codec$1.Class(PeerInfo, {
|
|
12148
|
+
fuzzVersion: codec$1.u8,
|
|
12149
|
+
features: codec$1.u32,
|
|
12150
|
+
jamVersion: Version.Codec,
|
|
12151
|
+
appVersion: Version.Codec,
|
|
12152
|
+
name: codec$1.string,
|
|
12153
|
+
});
|
|
12154
|
+
static create({ fuzzVersion, features, appVersion, jamVersion, name }) {
|
|
12155
|
+
return new PeerInfo(fuzzVersion, features, jamVersion, appVersion, name);
|
|
12156
|
+
}
|
|
12157
|
+
constructor(fuzzVersion, features, jamVersion, appVersion, name) {
|
|
12158
|
+
super();
|
|
12159
|
+
this.fuzzVersion = fuzzVersion;
|
|
12160
|
+
this.features = features;
|
|
12161
|
+
this.jamVersion = jamVersion;
|
|
12162
|
+
this.appVersion = appVersion;
|
|
12163
|
+
this.name = name;
|
|
12164
|
+
}
|
|
12165
|
+
}
|
|
12166
|
+
/**
|
|
12167
|
+
* AncestryItem ::= SEQUENCE {
|
|
12168
|
+
* slot TimeSlot,
|
|
12169
|
+
* header-hash HeaderHash
|
|
12170
|
+
* }
|
|
12171
|
+
*/
|
|
12172
|
+
class AncestryItem extends WithDebug {
|
|
12173
|
+
slot;
|
|
12174
|
+
headerHash;
|
|
12175
|
+
static Codec = codec$1.Class(AncestryItem, {
|
|
12176
|
+
slot: codec$1.u32.asOpaque(),
|
|
12177
|
+
headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
12178
|
+
});
|
|
12179
|
+
static create({ slot, headerHash }) {
|
|
12180
|
+
return new AncestryItem(slot, headerHash);
|
|
12181
|
+
}
|
|
12182
|
+
constructor(slot, headerHash) {
|
|
12183
|
+
super();
|
|
12184
|
+
this.slot = slot;
|
|
12185
|
+
this.headerHash = headerHash;
|
|
12186
|
+
}
|
|
12187
|
+
}
|
|
12188
|
+
/**
|
|
12189
|
+
* KeyValue ::= SEQUENCE {
|
|
12190
|
+
* key TrieKey,
|
|
12191
|
+
* value OCTET STRING
|
|
12192
|
+
* }
|
|
12193
|
+
*/
|
|
12194
|
+
class KeyValue extends WithDebug {
|
|
12195
|
+
key;
|
|
12196
|
+
value;
|
|
12197
|
+
static Codec = codec$1.Class(KeyValue, {
|
|
12198
|
+
key: codec$1.bytes(TRUNCATED_HASH_SIZE),
|
|
12199
|
+
value: codec$1.blob,
|
|
12200
|
+
});
|
|
12201
|
+
static create({ key, value }) {
|
|
12202
|
+
return new KeyValue(key, value);
|
|
12203
|
+
}
|
|
12204
|
+
constructor(key, value) {
|
|
12205
|
+
super();
|
|
12206
|
+
this.key = key;
|
|
12207
|
+
this.value = value;
|
|
12208
|
+
}
|
|
12209
|
+
}
|
|
12210
|
+
/** State ::= SEQUENCE OF KeyValue */
|
|
12211
|
+
const stateCodec = codec$1.sequenceVarLen(KeyValue.Codec);
|
|
12212
|
+
/**
|
|
12213
|
+
* Ancestry ::= SEQUENCE (SIZE(0..24)) OF AncestryItem
|
|
12214
|
+
* Empty when `feature-ancestry` is not supported by both parties
|
|
12215
|
+
*/
|
|
12216
|
+
const ancestryCodec = codec$1.sequenceVarLen(AncestryItem.Codec, {
|
|
12217
|
+
minLength: 0,
|
|
12218
|
+
maxLength: 24,
|
|
12219
|
+
});
|
|
12220
|
+
/**
|
|
12221
|
+
* Initialize ::= SEQUENCE {
|
|
12222
|
+
* header Header,
|
|
12223
|
+
* keyvals State,
|
|
12224
|
+
* ancestry Ancestry
|
|
12225
|
+
* }
|
|
12226
|
+
*/
|
|
12227
|
+
class Initialize extends WithDebug {
|
|
12228
|
+
header;
|
|
12229
|
+
keyvals;
|
|
12230
|
+
ancestry;
|
|
12231
|
+
static Codec = codec$1.Class(Initialize, {
|
|
12232
|
+
header: Header.Codec,
|
|
12233
|
+
keyvals: stateCodec,
|
|
12234
|
+
ancestry: ancestryCodec,
|
|
12235
|
+
});
|
|
12236
|
+
static create({ header, keyvals, ancestry }) {
|
|
12237
|
+
return new Initialize(header, keyvals, ancestry);
|
|
12238
|
+
}
|
|
12239
|
+
constructor(header, keyvals, ancestry) {
|
|
12240
|
+
super();
|
|
12241
|
+
this.header = header;
|
|
12242
|
+
this.keyvals = keyvals;
|
|
12243
|
+
this.ancestry = ancestry;
|
|
12244
|
+
}
|
|
12245
|
+
}
|
|
12246
|
+
/** GetState ::= HeaderHash */
|
|
12247
|
+
const getStateCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
12248
|
+
/** StateRoot ::= StateRootHash */
|
|
12249
|
+
const stateRootCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
12250
|
+
/** Error ::= UTF8String */
|
|
12251
|
+
class ErrorMessage extends WithDebug {
|
|
12252
|
+
message;
|
|
12253
|
+
static Codec = codec$1.Class(ErrorMessage, {
|
|
12254
|
+
message: codec$1.string,
|
|
12255
|
+
});
|
|
12256
|
+
static create({ message }) {
|
|
12257
|
+
return new ErrorMessage(message);
|
|
12258
|
+
}
|
|
12259
|
+
constructor(message) {
|
|
12260
|
+
super();
|
|
12261
|
+
this.message = message;
|
|
12262
|
+
}
|
|
12263
|
+
}
|
|
12264
|
+
/** Message choice type tags */
|
|
12265
|
+
var MessageType;
|
|
12266
|
+
(function (MessageType) {
|
|
12267
|
+
MessageType[MessageType["PeerInfo"] = 0] = "PeerInfo";
|
|
12268
|
+
MessageType[MessageType["Initialize"] = 1] = "Initialize";
|
|
12269
|
+
MessageType[MessageType["StateRoot"] = 2] = "StateRoot";
|
|
12270
|
+
MessageType[MessageType["ImportBlock"] = 3] = "ImportBlock";
|
|
12271
|
+
MessageType[MessageType["GetState"] = 4] = "GetState";
|
|
12272
|
+
MessageType[MessageType["State"] = 5] = "State";
|
|
12273
|
+
MessageType[MessageType["Error"] = 255] = "Error";
|
|
12274
|
+
})(MessageType || (MessageType = {}));
|
|
12275
|
+
/**
|
|
12276
|
+
* Message ::= CHOICE {
|
|
12277
|
+
* peer-info [0] PeerInfo,
|
|
12278
|
+
* initialize [1] Initialize,
|
|
12279
|
+
* state-root [2] StateRoot,
|
|
12280
|
+
* import-block [3] ImportBlock,
|
|
12281
|
+
* get-state [4] GetState,
|
|
12282
|
+
* state [5] State,
|
|
12283
|
+
* error [255] Error
|
|
12284
|
+
* }
|
|
12285
|
+
*/
|
|
12286
|
+
const messageCodec = codec$1.custom({
|
|
12287
|
+
name: "Message",
|
|
12288
|
+
sizeHint: { bytes: 1, isExact: false },
|
|
12289
|
+
}, (e, msg) => {
|
|
12290
|
+
e.i8(msg.type);
|
|
12291
|
+
switch (msg.type) {
|
|
12292
|
+
case MessageType.PeerInfo:
|
|
12293
|
+
PeerInfo.Codec.encode(e, msg.value);
|
|
12294
|
+
break;
|
|
12295
|
+
case MessageType.Initialize:
|
|
12296
|
+
Initialize.Codec.encode(e, msg.value);
|
|
12297
|
+
break;
|
|
12298
|
+
case MessageType.StateRoot:
|
|
12299
|
+
stateRootCodec.encode(e, msg.value);
|
|
12300
|
+
break;
|
|
12301
|
+
case MessageType.ImportBlock:
|
|
12302
|
+
Block.Codec.View.encode(e, msg.value);
|
|
12303
|
+
break;
|
|
12304
|
+
case MessageType.GetState:
|
|
12305
|
+
getStateCodec.encode(e, msg.value);
|
|
12306
|
+
break;
|
|
12307
|
+
case MessageType.State:
|
|
12308
|
+
stateCodec.encode(e, msg.value);
|
|
12309
|
+
break;
|
|
12310
|
+
case MessageType.Error:
|
|
12311
|
+
ErrorMessage.Codec.encode(e, msg.value);
|
|
12312
|
+
break;
|
|
12313
|
+
default:
|
|
12314
|
+
throw new Error(`Unknown message type: ${msg}`);
|
|
12315
|
+
}
|
|
12316
|
+
}, (d) => {
|
|
12317
|
+
const type = d.u8();
|
|
12318
|
+
switch (type) {
|
|
12319
|
+
case MessageType.PeerInfo:
|
|
12320
|
+
return { type: MessageType.PeerInfo, value: PeerInfo.Codec.decode(d) };
|
|
12321
|
+
case MessageType.Initialize:
|
|
12322
|
+
return { type: MessageType.Initialize, value: Initialize.Codec.decode(d) };
|
|
12323
|
+
case MessageType.StateRoot:
|
|
12324
|
+
return { type: MessageType.StateRoot, value: stateRootCodec.decode(d) };
|
|
12325
|
+
case MessageType.ImportBlock:
|
|
12326
|
+
return { type: MessageType.ImportBlock, value: Block.Codec.View.decode(d) };
|
|
12327
|
+
case MessageType.GetState:
|
|
12328
|
+
return { type: MessageType.GetState, value: getStateCodec.decode(d) };
|
|
12329
|
+
case MessageType.State:
|
|
12330
|
+
return { type: MessageType.State, value: stateCodec.decode(d) };
|
|
12331
|
+
case MessageType.Error:
|
|
12332
|
+
return { type: MessageType.Error, value: ErrorMessage.Codec.decode(d) };
|
|
12333
|
+
default:
|
|
12334
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
12335
|
+
}
|
|
12336
|
+
}, (s) => {
|
|
12337
|
+
const type = s.decoder.u8();
|
|
12338
|
+
switch (type) {
|
|
12339
|
+
case MessageType.PeerInfo:
|
|
12340
|
+
PeerInfo.Codec.View.skip(s);
|
|
12341
|
+
break;
|
|
12342
|
+
case MessageType.Initialize:
|
|
12343
|
+
Initialize.Codec.View.skip(s);
|
|
12344
|
+
break;
|
|
12345
|
+
case MessageType.StateRoot:
|
|
12346
|
+
stateRootCodec.View.skip(s);
|
|
12347
|
+
break;
|
|
12348
|
+
case MessageType.ImportBlock:
|
|
12349
|
+
Block.Codec.View.skip(s);
|
|
12350
|
+
break;
|
|
12351
|
+
case MessageType.GetState:
|
|
12352
|
+
getStateCodec.View.skip(s);
|
|
12353
|
+
break;
|
|
12354
|
+
case MessageType.State:
|
|
12355
|
+
stateCodec.View.skip(s);
|
|
12356
|
+
break;
|
|
12357
|
+
case MessageType.Error:
|
|
12358
|
+
ErrorMessage.Codec.View.skip(s);
|
|
12359
|
+
break;
|
|
12360
|
+
default:
|
|
12361
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
12362
|
+
}
|
|
12363
|
+
});
|
|
12364
|
+
|
|
12365
|
+
const logger$4 = Logger.new(undefined, "ext-ipc-fuzz-v1");
|
|
12366
|
+
class FuzzTarget {
|
|
12367
|
+
msgHandler;
|
|
12368
|
+
sender;
|
|
12369
|
+
spec;
|
|
12370
|
+
sessionFeatures = 0;
|
|
12371
|
+
constructor(msgHandler, sender, spec) {
|
|
12372
|
+
this.msgHandler = msgHandler;
|
|
12373
|
+
this.sender = sender;
|
|
12374
|
+
this.spec = spec;
|
|
12375
|
+
}
|
|
12376
|
+
async onSocketMessage(msg) {
|
|
12377
|
+
// attempt to decode the messsage
|
|
12378
|
+
try {
|
|
12379
|
+
const message = Decoder.decodeObject(messageCodec, msg, this.spec);
|
|
12380
|
+
logger$4.log `[${message.type}] incoming message`;
|
|
12381
|
+
await this.processAndRespond(message);
|
|
12382
|
+
}
|
|
12383
|
+
catch (e) {
|
|
12384
|
+
logger$4.error `Error while processing fuzz v1 message: ${e}`;
|
|
12385
|
+
logger$4.error `${e}`;
|
|
12386
|
+
if (e instanceof Error) {
|
|
12387
|
+
logger$4.error `${e.stack ?? ""}`;
|
|
12388
|
+
}
|
|
12389
|
+
this.sender.close();
|
|
12390
|
+
}
|
|
12391
|
+
}
|
|
12392
|
+
async processAndRespond(message) {
|
|
12393
|
+
let response = null;
|
|
12394
|
+
switch (message.type) {
|
|
12395
|
+
case MessageType.PeerInfo: {
|
|
12396
|
+
// only support V1
|
|
12397
|
+
if (message.value.fuzzVersion !== 1) {
|
|
12398
|
+
logger$4.warn `Unsupported fuzzer protocol version: ${message.value.fuzzVersion}. Closing`;
|
|
12399
|
+
this.sender.close();
|
|
12400
|
+
return;
|
|
12401
|
+
}
|
|
12402
|
+
// Handle handshake
|
|
12403
|
+
const ourPeerInfo = await this.msgHandler.getPeerInfo(message.value);
|
|
12404
|
+
// Calculate session features (intersection of both peer features)
|
|
12405
|
+
this.sessionFeatures = message.value.features & ourPeerInfo.features;
|
|
12406
|
+
logger$4.info `Handshake completed. Shared features: 0b${this.sessionFeatures.toString(2)}`;
|
|
12407
|
+
logger$4.log `Feature ancestry: ${(this.sessionFeatures & Features.Ancestry) !== 0}`;
|
|
12408
|
+
logger$4.log `Feature fork: ${(this.sessionFeatures & Features.Fork) !== 0}`;
|
|
12409
|
+
response = {
|
|
12410
|
+
type: MessageType.PeerInfo,
|
|
12411
|
+
value: ourPeerInfo,
|
|
12412
|
+
};
|
|
12413
|
+
break;
|
|
12414
|
+
}
|
|
12415
|
+
case MessageType.Initialize: {
|
|
12416
|
+
const stateRoot = await this.msgHandler.initialize(message.value);
|
|
12417
|
+
response = {
|
|
12418
|
+
type: MessageType.StateRoot,
|
|
12419
|
+
value: stateRoot,
|
|
12420
|
+
};
|
|
12421
|
+
break;
|
|
12422
|
+
}
|
|
12423
|
+
case MessageType.ImportBlock: {
|
|
12424
|
+
const result = await this.msgHandler.importBlock(message.value);
|
|
12425
|
+
if (result.isOk) {
|
|
12426
|
+
response = {
|
|
12427
|
+
type: MessageType.StateRoot,
|
|
12428
|
+
value: result.ok,
|
|
12429
|
+
};
|
|
12430
|
+
}
|
|
12431
|
+
else {
|
|
12432
|
+
response = {
|
|
12433
|
+
type: MessageType.Error,
|
|
12434
|
+
value: result.error,
|
|
12435
|
+
};
|
|
12436
|
+
}
|
|
12437
|
+
break;
|
|
12438
|
+
}
|
|
12439
|
+
case MessageType.GetState: {
|
|
12440
|
+
const state = await this.msgHandler.getSerializedState(message.value);
|
|
12441
|
+
response = {
|
|
12442
|
+
type: MessageType.State,
|
|
12443
|
+
value: state,
|
|
12444
|
+
};
|
|
12445
|
+
break;
|
|
12446
|
+
}
|
|
12447
|
+
case MessageType.StateRoot: {
|
|
12448
|
+
logger$4.log `--> Received unexpected 'StateRoot' message from the fuzzer. Closing.`;
|
|
12449
|
+
this.sender.close();
|
|
12450
|
+
return;
|
|
12451
|
+
}
|
|
12452
|
+
case MessageType.State: {
|
|
12453
|
+
logger$4.log `--> Received unexpected 'State' message from the fuzzer. Closing.`;
|
|
12454
|
+
this.sender.close();
|
|
12455
|
+
return;
|
|
12456
|
+
}
|
|
12457
|
+
case MessageType.Error: {
|
|
12458
|
+
logger$4.log `--> Received unexpected 'Error' message from the fuzzer. Closing.`;
|
|
12459
|
+
this.sender.close();
|
|
12460
|
+
return;
|
|
12461
|
+
}
|
|
12462
|
+
default: {
|
|
12463
|
+
logger$4.log `--> Received unexpected message type ${JSON.stringify(message)} from the fuzzer. Closing.`;
|
|
12464
|
+
this.sender.close();
|
|
12465
|
+
try {
|
|
12466
|
+
assertNever(message);
|
|
12467
|
+
}
|
|
12468
|
+
catch {
|
|
12469
|
+
return;
|
|
12470
|
+
}
|
|
12471
|
+
}
|
|
12472
|
+
}
|
|
12473
|
+
if (response !== null) {
|
|
12474
|
+
logger$4.trace `<-- responding with: ${response.type}`;
|
|
12475
|
+
const encoded = Encoder.encodeObject(messageCodec, response, this.spec);
|
|
12476
|
+
this.sender.send(encoded);
|
|
12477
|
+
}
|
|
12478
|
+
else {
|
|
12479
|
+
logger$4.warn `<-- no response generated for: ${message.type}`;
|
|
12480
|
+
}
|
|
12481
|
+
}
|
|
12482
|
+
onClose({ error }) {
|
|
12483
|
+
logger$4.log `Closing the v1 handler. Reason: ${error !== undefined ? error.message : "close"}.`;
|
|
12484
|
+
}
|
|
12485
|
+
/** Check if a specific feature is enabled in the session */
|
|
12486
|
+
hasFeature(feature) {
|
|
12487
|
+
return (this.sessionFeatures & feature) !== 0;
|
|
12488
|
+
}
|
|
12489
|
+
}
|
|
12490
|
+
|
|
12491
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
12492
|
+
__proto__: null,
|
|
12493
|
+
AncestryItem: AncestryItem,
|
|
12494
|
+
ErrorMessage: ErrorMessage,
|
|
12495
|
+
get Features () { return Features; },
|
|
12496
|
+
FuzzTarget: FuzzTarget,
|
|
12497
|
+
Initialize: Initialize,
|
|
12498
|
+
KeyValue: KeyValue,
|
|
12499
|
+
get MessageType () { return MessageType; },
|
|
12500
|
+
PeerInfo: PeerInfo,
|
|
12501
|
+
Version: Version,
|
|
12502
|
+
ancestryCodec: ancestryCodec,
|
|
12503
|
+
getStateCodec: getStateCodec,
|
|
12504
|
+
messageCodec: messageCodec,
|
|
12505
|
+
stateCodec: stateCodec,
|
|
12506
|
+
stateRootCodec: stateRootCodec
|
|
12507
|
+
});
|
|
12508
|
+
|
|
12509
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
12510
|
+
__proto__: null,
|
|
12511
|
+
v1: index$b
|
|
12512
|
+
});
|
|
12513
|
+
|
|
12081
12514
|
/** Size of the transfer memo. */
|
|
12082
12515
|
const TRANSFER_MEMO_BYTES = W_T;
|
|
12083
12516
|
/**
|
|
@@ -16908,8 +17341,8 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16908
17341
|
asOpaqueType: asOpaqueType,
|
|
16909
17342
|
assertEmpty: assertEmpty,
|
|
16910
17343
|
assertNever: assertNever,
|
|
16911
|
-
block: index$
|
|
16912
|
-
bytes: index$
|
|
17344
|
+
block: index$l,
|
|
17345
|
+
bytes: index$s,
|
|
16913
17346
|
check: check,
|
|
16914
17347
|
clampU64ToU32: clampU64ToU32,
|
|
16915
17348
|
createResults: createResults,
|
|
@@ -16917,13 +17350,13 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16917
17350
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
16918
17351
|
getServiceId: getServiceId,
|
|
16919
17352
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
16920
|
-
hash: index$
|
|
17353
|
+
hash: index$p,
|
|
16921
17354
|
inspect: inspect,
|
|
16922
17355
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
16923
17356
|
interpreter: index$7,
|
|
16924
17357
|
isBrowser: isBrowser,
|
|
16925
17358
|
measure: measure,
|
|
16926
|
-
numbers: index$
|
|
17359
|
+
numbers: index$r,
|
|
16927
17360
|
resultToString: resultToString,
|
|
16928
17361
|
seeThrough: seeThrough,
|
|
16929
17362
|
slotsToPreimageStatus: slotsToPreimageStatus,
|
|
@@ -17637,32 +18070,33 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
17637
18070
|
WorkPackageExecutor: WorkPackageExecutor
|
|
17638
18071
|
});
|
|
17639
18072
|
|
|
17640
|
-
exports.block = index$
|
|
17641
|
-
exports.block_json = index$
|
|
17642
|
-
exports.bytes = index$
|
|
17643
|
-
exports.codec = index$
|
|
17644
|
-
exports.collections = index$
|
|
17645
|
-
exports.config = index$
|
|
17646
|
-
exports.config_node = index$
|
|
17647
|
-
exports.crypto = index$
|
|
17648
|
-
exports.database = index$
|
|
17649
|
-
exports.erasure_coding = index$
|
|
17650
|
-
exports.
|
|
18073
|
+
exports.block = index$l;
|
|
18074
|
+
exports.block_json = index$j;
|
|
18075
|
+
exports.bytes = index$s;
|
|
18076
|
+
exports.codec = index$q;
|
|
18077
|
+
exports.collections = index$n;
|
|
18078
|
+
exports.config = index$m;
|
|
18079
|
+
exports.config_node = index$h;
|
|
18080
|
+
exports.crypto = index$o;
|
|
18081
|
+
exports.database = index$d;
|
|
18082
|
+
exports.erasure_coding = index$c;
|
|
18083
|
+
exports.fuzz_proto = index$a;
|
|
18084
|
+
exports.hash = index$p;
|
|
17651
18085
|
exports.jam_host_calls = index$9;
|
|
17652
|
-
exports.json_parser = index$
|
|
17653
|
-
exports.logger = index$
|
|
18086
|
+
exports.json_parser = index$k;
|
|
18087
|
+
exports.logger = index$i;
|
|
17654
18088
|
exports.mmr = index$8;
|
|
17655
|
-
exports.numbers = index$
|
|
17656
|
-
exports.ordering = index$
|
|
18089
|
+
exports.numbers = index$r;
|
|
18090
|
+
exports.ordering = index$t;
|
|
17657
18091
|
exports.pvm = index$3;
|
|
17658
18092
|
exports.pvm_host_calls = index$6;
|
|
17659
18093
|
exports.pvm_interpreter = index$7;
|
|
17660
18094
|
exports.pvm_program = index$4;
|
|
17661
18095
|
exports.pvm_spi_decoder = index$5;
|
|
17662
18096
|
exports.shuffling = index$2;
|
|
17663
|
-
exports.state = index$
|
|
18097
|
+
exports.state = index$g;
|
|
17664
18098
|
exports.state_json = index$1;
|
|
17665
|
-
exports.state_merkleization = index$
|
|
18099
|
+
exports.state_merkleization = index$e;
|
|
17666
18100
|
exports.transition = index;
|
|
17667
|
-
exports.trie = index$
|
|
17668
|
-
exports.utils = index$
|
|
18101
|
+
exports.trie = index$f;
|
|
18102
|
+
exports.utils = index$u;
|