@typeberry/lib 0.1.2-8c85275 → 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/index.js CHANGED
@@ -7,6 +7,7 @@ var GpVersion;
7
7
  GpVersion["V0_6_7"] = "0.6.7";
8
8
  GpVersion["V0_7_0"] = "0.7.0";
9
9
  GpVersion["V0_7_1"] = "0.7.1-preview";
10
+ GpVersion["V0_7_2"] = "0.7.2-preview";
10
11
  })(GpVersion || (GpVersion = {}));
11
12
  var TestSuite;
12
13
  (function (TestSuite) {
@@ -14,7 +15,7 @@ var TestSuite;
14
15
  TestSuite["JAMDUNA"] = "jamduna";
15
16
  })(TestSuite || (TestSuite = {}));
16
17
  const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
17
- const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1];
18
+ const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
18
19
  const env$1 = typeof process === "undefined" ? {} : process.env;
19
20
  const DEFAULT_VERSION = GpVersion.V0_7_0;
20
21
  let CURRENT_VERSION = parseCurrentVersion(env$1.GP_VERSION) ?? DEFAULT_VERSION;
@@ -23,20 +24,26 @@ function parseCurrentVersion(env) {
23
24
  if (env === undefined) {
24
25
  return undefined;
25
26
  }
26
- const version = env;
27
- if (!Object.values(GpVersion).includes(version)) {
28
- throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
27
+ switch (env) {
28
+ case GpVersion.V0_6_7:
29
+ case GpVersion.V0_7_0:
30
+ case GpVersion.V0_7_1:
31
+ case GpVersion.V0_7_2:
32
+ return env;
33
+ default:
34
+ throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
29
35
  }
30
- return version;
31
36
  }
32
37
  function parseCurrentSuite(env) {
33
38
  if (env === undefined)
34
39
  return undefined;
35
- const val = env;
36
- if (!Object.values(TestSuite).includes(val)) {
37
- throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
40
+ switch (env) {
41
+ case TestSuite.W3F_DAVXY:
42
+ case TestSuite.JAMDUNA:
43
+ return env;
44
+ default:
45
+ throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
38
46
  }
39
- return val;
40
47
  }
41
48
  class Compatibility {
42
49
  static override(version) {
@@ -553,7 +560,7 @@ function isResult(x) {
553
560
  * as an afterthought.
554
561
  */
555
562
 
556
- var index$s = /*#__PURE__*/Object.freeze({
563
+ var index$u = /*#__PURE__*/Object.freeze({
557
564
  __proto__: null,
558
565
  get CURRENT_SUITE () { return CURRENT_SUITE; },
559
566
  get CURRENT_VERSION () { return CURRENT_VERSION; },
@@ -707,7 +714,7 @@ class Ordering {
707
714
  }
708
715
  }
709
716
 
710
- var index$r = /*#__PURE__*/Object.freeze({
717
+ var index$t = /*#__PURE__*/Object.freeze({
711
718
  __proto__: null,
712
719
  Ordering: Ordering
713
720
  });
@@ -958,7 +965,7 @@ function u8ArraySameLengthEqual(self, other) {
958
965
  }
959
966
  const bytesBlobComparator = (a, b) => a.compare(b);
960
967
 
961
- var index$q = /*#__PURE__*/Object.freeze({
968
+ var index$s = /*#__PURE__*/Object.freeze({
962
969
  __proto__: null,
963
970
  BitVec: BitVec,
964
971
  Bytes: Bytes,
@@ -1060,7 +1067,7 @@ const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? mi
1060
1067
  /** Get the biggest value between U64 a and values given as input parameters. */
1061
1068
  const maxU64 = (a, ...values) => values.reduce((max, value) => (value < max ? max : value), a);
1062
1069
 
1063
- var index$p = /*#__PURE__*/Object.freeze({
1070
+ var index$r = /*#__PURE__*/Object.freeze({
1064
1071
  __proto__: null,
1065
1072
  isU16: isU16,
1066
1073
  isU32: isU32,
@@ -2470,7 +2477,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
2470
2477
  }, skipper);
2471
2478
  }
2472
2479
 
2473
- var index$o = /*#__PURE__*/Object.freeze({
2480
+ var index$q = /*#__PURE__*/Object.freeze({
2474
2481
  __proto__: null,
2475
2482
  Decoder: Decoder,
2476
2483
  Descriptor: Descriptor,
@@ -4909,7 +4916,7 @@ var keccak = /*#__PURE__*/Object.freeze({
4909
4916
  hashBlobs: hashBlobs
4910
4917
  });
4911
4918
 
4912
- var index$n = /*#__PURE__*/Object.freeze({
4919
+ var index$p = /*#__PURE__*/Object.freeze({
4913
4920
  __proto__: null,
4914
4921
  HASH_SIZE: HASH_SIZE,
4915
4922
  PageAllocator: PageAllocator,
@@ -4975,7 +4982,7 @@ var keyDerivation = /*#__PURE__*/Object.freeze({
4975
4982
  trivialSeed: trivialSeed
4976
4983
  });
4977
4984
 
4978
- var index$m = /*#__PURE__*/Object.freeze({
4985
+ var index$o = /*#__PURE__*/Object.freeze({
4979
4986
  __proto__: null,
4980
4987
  BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
4981
4988
  BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
@@ -5579,7 +5586,7 @@ class TruncatedHashDictionary {
5579
5586
  }
5580
5587
  }
5581
5588
 
5582
- var index$l = /*#__PURE__*/Object.freeze({
5589
+ var index$n = /*#__PURE__*/Object.freeze({
5583
5590
  __proto__: null,
5584
5591
  FixedSizeArray: FixedSizeArray,
5585
5592
  HashDictionary: HashDictionary,
@@ -5774,7 +5781,7 @@ class Bootnode {
5774
5781
  }
5775
5782
  }
5776
5783
 
5777
- var index$k = /*#__PURE__*/Object.freeze({
5784
+ var index$m = /*#__PURE__*/Object.freeze({
5778
5785
  __proto__: null,
5779
5786
  Bootnode: Bootnode,
5780
5787
  ChainSpec: ChainSpec,
@@ -7251,7 +7258,7 @@ class Block extends WithDebug {
7251
7258
  }
7252
7259
  }
7253
7260
 
7254
- var index$j = /*#__PURE__*/Object.freeze({
7261
+ var index$l = /*#__PURE__*/Object.freeze({
7255
7262
  __proto__: null,
7256
7263
  Block: Block,
7257
7264
  EpochMarker: EpochMarker,
@@ -7506,7 +7513,7 @@ var json;
7506
7513
  json.object = object;
7507
7514
  })(json || (json = {}));
7508
7515
 
7509
- var index$i = /*#__PURE__*/Object.freeze({
7516
+ var index$k = /*#__PURE__*/Object.freeze({
7510
7517
  __proto__: null,
7511
7518
  get json () { return json; },
7512
7519
  parseFromJson: parseFromJson
@@ -7776,7 +7783,7 @@ const blockFromJson = (spec) => json.object({
7776
7783
  extrinsic: getExtrinsicFromJson(spec),
7777
7784
  }, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
7778
7785
 
7779
- var index$h = /*#__PURE__*/Object.freeze({
7786
+ var index$j = /*#__PURE__*/Object.freeze({
7780
7787
  __proto__: null,
7781
7788
  blockFromJson: blockFromJson,
7782
7789
  disputesExtrinsicFromJson: disputesExtrinsicFromJson,
@@ -8274,7 +8281,7 @@ class Logger {
8274
8281
  }
8275
8282
  }
8276
8283
 
8277
- var index$g = /*#__PURE__*/Object.freeze({
8284
+ var index$i = /*#__PURE__*/Object.freeze({
8278
8285
  __proto__: null,
8279
8286
  get Level () { return Level; },
8280
8287
  Logger: Logger,
@@ -8297,7 +8304,7 @@ class AuthorshipOptions {
8297
8304
  }
8298
8305
  }
8299
8306
 
8300
- const logger$4 = Logger.new(import.meta.filename, "config");
8307
+ const logger$5 = Logger.new(import.meta.filename, "config");
8301
8308
  /** Development config. Will accept unsealed blocks for now. */
8302
8309
  const DEV_CONFIG = "dev";
8303
8310
  /** Default config file. */
@@ -8356,15 +8363,15 @@ class NodeConfiguration {
8356
8363
  }
8357
8364
  function loadConfig(configPath) {
8358
8365
  if (configPath === DEFAULT_CONFIG) {
8359
- logger$4.log `🔧 Loading DEFAULT config`;
8366
+ logger$5.log `🔧 Loading DEFAULT config`;
8360
8367
  return parseFromJson(configs.default, NodeConfiguration.fromJson);
8361
8368
  }
8362
8369
  if (configPath === DEV_CONFIG) {
8363
- logger$4.log `🔧 Loading DEV config`;
8370
+ logger$5.log `🔧 Loading DEV config`;
8364
8371
  return parseFromJson(configs.dev, NodeConfiguration.fromJson);
8365
8372
  }
8366
8373
  try {
8367
- logger$4.log `🔧 Loading config from ${configPath}`;
8374
+ logger$5.log `🔧 Loading config from ${configPath}`;
8368
8375
  const configFile = fs.readFileSync(configPath, "utf8");
8369
8376
  const parsed = JSON.parse(configFile);
8370
8377
  return parseFromJson(parsed, NodeConfiguration.fromJson);
@@ -8374,7 +8381,7 @@ function loadConfig(configPath) {
8374
8381
  }
8375
8382
  }
8376
8383
 
8377
- var index$f = /*#__PURE__*/Object.freeze({
8384
+ var index$h = /*#__PURE__*/Object.freeze({
8378
8385
  __proto__: null,
8379
8386
  DEFAULT_CONFIG: DEFAULT_CONFIG,
8380
8387
  DEV_CONFIG: DEV_CONFIG,
@@ -10040,7 +10047,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
10040
10047
  sortKeys: (a, b) => a - b,
10041
10048
  });
10042
10049
 
10043
- var index$e = /*#__PURE__*/Object.freeze({
10050
+ var index$g = /*#__PURE__*/Object.freeze({
10044
10051
  __proto__: null,
10045
10052
  AccumulationOutput: AccumulationOutput,
10046
10053
  AutoAccumulate: AutoAccumulate,
@@ -11050,7 +11057,7 @@ const bitLookup = [
11050
11057
  [0b00000000, 8],
11051
11058
  ];
11052
11059
 
11053
- var index$d = /*#__PURE__*/Object.freeze({
11060
+ var index$f = /*#__PURE__*/Object.freeze({
11054
11061
  __proto__: null,
11055
11062
  BranchNode: BranchNode,
11056
11063
  InMemoryTrie: InMemoryTrie,
@@ -11396,7 +11403,7 @@ function loadState(spec, entries) {
11396
11403
  * hashmap of `key -> value` entries.
11397
11404
  */
11398
11405
 
11399
- var index$c = /*#__PURE__*/Object.freeze({
11406
+ var index$e = /*#__PURE__*/Object.freeze({
11400
11407
  __proto__: null,
11401
11408
  SerializedService: SerializedService,
11402
11409
  SerializedState: SerializedState,
@@ -11682,7 +11689,7 @@ class InMemoryStates {
11682
11689
  }
11683
11690
  }
11684
11691
 
11685
- var index$b = /*#__PURE__*/Object.freeze({
11692
+ var index$d = /*#__PURE__*/Object.freeze({
11686
11693
  __proto__: null,
11687
11694
  InMemoryBlocks: InMemoryBlocks,
11688
11695
  InMemoryStates: InMemoryStates,
@@ -12044,7 +12051,7 @@ const initEc = async () => {
12044
12051
  await init.reedSolomon();
12045
12052
  };
12046
12053
 
12047
- var index$a = /*#__PURE__*/Object.freeze({
12054
+ var index$c = /*#__PURE__*/Object.freeze({
12048
12055
  __proto__: null,
12049
12056
  N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
12050
12057
  N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
@@ -12068,6 +12075,439 @@ var index$a = /*#__PURE__*/Object.freeze({
12068
12075
  unzip: unzip
12069
12076
  });
12070
12077
 
12078
+ /**
12079
+ * Version ::= SEQUENCE {
12080
+ * major INTEGER (0..255),
12081
+ * minor INTEGER (0..255),
12082
+ * patch INTEGER (0..255)
12083
+ * }
12084
+ */
12085
+ class Version extends WithDebug {
12086
+ major;
12087
+ minor;
12088
+ patch;
12089
+ static Codec = codec$1.Class(Version, {
12090
+ major: codec$1.u8,
12091
+ minor: codec$1.u8,
12092
+ patch: codec$1.u8,
12093
+ });
12094
+ static tryFromString(str) {
12095
+ const parse = (v) => tryAsU8(Number(v));
12096
+ try {
12097
+ const [major, minor, patch] = str.trim().split(".").map(parse);
12098
+ return Version.create({
12099
+ major,
12100
+ minor,
12101
+ patch,
12102
+ });
12103
+ }
12104
+ catch (e) {
12105
+ throw new Error(`Unable to parse ${str} as Version: ${e}`);
12106
+ }
12107
+ }
12108
+ static create({ major, minor, patch }) {
12109
+ return new Version(major, minor, patch);
12110
+ }
12111
+ constructor(major, minor, patch) {
12112
+ super();
12113
+ this.major = major;
12114
+ this.minor = minor;
12115
+ this.patch = patch;
12116
+ }
12117
+ }
12118
+ /**
12119
+ * Fuzzer Protocol V1
12120
+ * Reference: https://github.com/davxy/jam-conformance/blob/main/fuzz-proto/fuzz.asn
12121
+ */
12122
+ // Feature bit constants
12123
+ var Features;
12124
+ (function (Features) {
12125
+ Features[Features["Ancestry"] = 1] = "Ancestry";
12126
+ Features[Features["Fork"] = 2] = "Fork";
12127
+ Features[Features["Reserved"] = 2147483648] = "Reserved";
12128
+ })(Features || (Features = {}));
12129
+ /**
12130
+ * PeerInfo ::= SEQUENCE {
12131
+ * fuzz-version U8,
12132
+ * features Features,
12133
+ * jam-version Version,
12134
+ * app-version Version,
12135
+ * name UTF8String
12136
+ * }
12137
+ */
12138
+ class PeerInfo extends WithDebug {
12139
+ fuzzVersion;
12140
+ features;
12141
+ jamVersion;
12142
+ appVersion;
12143
+ name;
12144
+ static Codec = codec$1.Class(PeerInfo, {
12145
+ fuzzVersion: codec$1.u8,
12146
+ features: codec$1.u32,
12147
+ jamVersion: Version.Codec,
12148
+ appVersion: Version.Codec,
12149
+ name: codec$1.string,
12150
+ });
12151
+ static create({ fuzzVersion, features, appVersion, jamVersion, name }) {
12152
+ return new PeerInfo(fuzzVersion, features, jamVersion, appVersion, name);
12153
+ }
12154
+ constructor(fuzzVersion, features, jamVersion, appVersion, name) {
12155
+ super();
12156
+ this.fuzzVersion = fuzzVersion;
12157
+ this.features = features;
12158
+ this.jamVersion = jamVersion;
12159
+ this.appVersion = appVersion;
12160
+ this.name = name;
12161
+ }
12162
+ }
12163
+ /**
12164
+ * AncestryItem ::= SEQUENCE {
12165
+ * slot TimeSlot,
12166
+ * header-hash HeaderHash
12167
+ * }
12168
+ */
12169
+ class AncestryItem extends WithDebug {
12170
+ slot;
12171
+ headerHash;
12172
+ static Codec = codec$1.Class(AncestryItem, {
12173
+ slot: codec$1.u32.asOpaque(),
12174
+ headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
12175
+ });
12176
+ static create({ slot, headerHash }) {
12177
+ return new AncestryItem(slot, headerHash);
12178
+ }
12179
+ constructor(slot, headerHash) {
12180
+ super();
12181
+ this.slot = slot;
12182
+ this.headerHash = headerHash;
12183
+ }
12184
+ }
12185
+ /**
12186
+ * KeyValue ::= SEQUENCE {
12187
+ * key TrieKey,
12188
+ * value OCTET STRING
12189
+ * }
12190
+ */
12191
+ class KeyValue extends WithDebug {
12192
+ key;
12193
+ value;
12194
+ static Codec = codec$1.Class(KeyValue, {
12195
+ key: codec$1.bytes(TRUNCATED_HASH_SIZE),
12196
+ value: codec$1.blob,
12197
+ });
12198
+ static create({ key, value }) {
12199
+ return new KeyValue(key, value);
12200
+ }
12201
+ constructor(key, value) {
12202
+ super();
12203
+ this.key = key;
12204
+ this.value = value;
12205
+ }
12206
+ }
12207
+ /** State ::= SEQUENCE OF KeyValue */
12208
+ const stateCodec = codec$1.sequenceVarLen(KeyValue.Codec);
12209
+ /**
12210
+ * Ancestry ::= SEQUENCE (SIZE(0..24)) OF AncestryItem
12211
+ * Empty when `feature-ancestry` is not supported by both parties
12212
+ */
12213
+ const ancestryCodec = codec$1.sequenceVarLen(AncestryItem.Codec, {
12214
+ minLength: 0,
12215
+ maxLength: 24,
12216
+ });
12217
+ /**
12218
+ * Initialize ::= SEQUENCE {
12219
+ * header Header,
12220
+ * keyvals State,
12221
+ * ancestry Ancestry
12222
+ * }
12223
+ */
12224
+ class Initialize extends WithDebug {
12225
+ header;
12226
+ keyvals;
12227
+ ancestry;
12228
+ static Codec = codec$1.Class(Initialize, {
12229
+ header: Header.Codec,
12230
+ keyvals: stateCodec,
12231
+ ancestry: ancestryCodec,
12232
+ });
12233
+ static create({ header, keyvals, ancestry }) {
12234
+ return new Initialize(header, keyvals, ancestry);
12235
+ }
12236
+ constructor(header, keyvals, ancestry) {
12237
+ super();
12238
+ this.header = header;
12239
+ this.keyvals = keyvals;
12240
+ this.ancestry = ancestry;
12241
+ }
12242
+ }
12243
+ /** GetState ::= HeaderHash */
12244
+ const getStateCodec = codec$1.bytes(HASH_SIZE).asOpaque();
12245
+ /** StateRoot ::= StateRootHash */
12246
+ const stateRootCodec = codec$1.bytes(HASH_SIZE).asOpaque();
12247
+ /** Error ::= UTF8String */
12248
+ class ErrorMessage extends WithDebug {
12249
+ message;
12250
+ static Codec = codec$1.Class(ErrorMessage, {
12251
+ message: codec$1.string,
12252
+ });
12253
+ static create({ message }) {
12254
+ return new ErrorMessage(message);
12255
+ }
12256
+ constructor(message) {
12257
+ super();
12258
+ this.message = message;
12259
+ }
12260
+ }
12261
+ /** Message choice type tags */
12262
+ var MessageType;
12263
+ (function (MessageType) {
12264
+ MessageType[MessageType["PeerInfo"] = 0] = "PeerInfo";
12265
+ MessageType[MessageType["Initialize"] = 1] = "Initialize";
12266
+ MessageType[MessageType["StateRoot"] = 2] = "StateRoot";
12267
+ MessageType[MessageType["ImportBlock"] = 3] = "ImportBlock";
12268
+ MessageType[MessageType["GetState"] = 4] = "GetState";
12269
+ MessageType[MessageType["State"] = 5] = "State";
12270
+ MessageType[MessageType["Error"] = 255] = "Error";
12271
+ })(MessageType || (MessageType = {}));
12272
+ /**
12273
+ * Message ::= CHOICE {
12274
+ * peer-info [0] PeerInfo,
12275
+ * initialize [1] Initialize,
12276
+ * state-root [2] StateRoot,
12277
+ * import-block [3] ImportBlock,
12278
+ * get-state [4] GetState,
12279
+ * state [5] State,
12280
+ * error [255] Error
12281
+ * }
12282
+ */
12283
+ const messageCodec = codec$1.custom({
12284
+ name: "Message",
12285
+ sizeHint: { bytes: 1, isExact: false },
12286
+ }, (e, msg) => {
12287
+ e.i8(msg.type);
12288
+ switch (msg.type) {
12289
+ case MessageType.PeerInfo:
12290
+ PeerInfo.Codec.encode(e, msg.value);
12291
+ break;
12292
+ case MessageType.Initialize:
12293
+ Initialize.Codec.encode(e, msg.value);
12294
+ break;
12295
+ case MessageType.StateRoot:
12296
+ stateRootCodec.encode(e, msg.value);
12297
+ break;
12298
+ case MessageType.ImportBlock:
12299
+ Block.Codec.View.encode(e, msg.value);
12300
+ break;
12301
+ case MessageType.GetState:
12302
+ getStateCodec.encode(e, msg.value);
12303
+ break;
12304
+ case MessageType.State:
12305
+ stateCodec.encode(e, msg.value);
12306
+ break;
12307
+ case MessageType.Error:
12308
+ ErrorMessage.Codec.encode(e, msg.value);
12309
+ break;
12310
+ default:
12311
+ throw new Error(`Unknown message type: ${msg}`);
12312
+ }
12313
+ }, (d) => {
12314
+ const type = d.u8();
12315
+ switch (type) {
12316
+ case MessageType.PeerInfo:
12317
+ return { type: MessageType.PeerInfo, value: PeerInfo.Codec.decode(d) };
12318
+ case MessageType.Initialize:
12319
+ return { type: MessageType.Initialize, value: Initialize.Codec.decode(d) };
12320
+ case MessageType.StateRoot:
12321
+ return { type: MessageType.StateRoot, value: stateRootCodec.decode(d) };
12322
+ case MessageType.ImportBlock:
12323
+ return { type: MessageType.ImportBlock, value: Block.Codec.View.decode(d) };
12324
+ case MessageType.GetState:
12325
+ return { type: MessageType.GetState, value: getStateCodec.decode(d) };
12326
+ case MessageType.State:
12327
+ return { type: MessageType.State, value: stateCodec.decode(d) };
12328
+ case MessageType.Error:
12329
+ return { type: MessageType.Error, value: ErrorMessage.Codec.decode(d) };
12330
+ default:
12331
+ throw new Error(`Unknown message type: ${type}`);
12332
+ }
12333
+ }, (s) => {
12334
+ const type = s.decoder.u8();
12335
+ switch (type) {
12336
+ case MessageType.PeerInfo:
12337
+ PeerInfo.Codec.View.skip(s);
12338
+ break;
12339
+ case MessageType.Initialize:
12340
+ Initialize.Codec.View.skip(s);
12341
+ break;
12342
+ case MessageType.StateRoot:
12343
+ stateRootCodec.View.skip(s);
12344
+ break;
12345
+ case MessageType.ImportBlock:
12346
+ Block.Codec.View.skip(s);
12347
+ break;
12348
+ case MessageType.GetState:
12349
+ getStateCodec.View.skip(s);
12350
+ break;
12351
+ case MessageType.State:
12352
+ stateCodec.View.skip(s);
12353
+ break;
12354
+ case MessageType.Error:
12355
+ ErrorMessage.Codec.View.skip(s);
12356
+ break;
12357
+ default:
12358
+ throw new Error(`Unknown message type: ${type}`);
12359
+ }
12360
+ });
12361
+
12362
+ const logger$4 = Logger.new(import.meta.filename, "ext-ipc-fuzz-v1");
12363
+ class FuzzTarget {
12364
+ msgHandler;
12365
+ sender;
12366
+ spec;
12367
+ sessionFeatures = 0;
12368
+ constructor(msgHandler, sender, spec) {
12369
+ this.msgHandler = msgHandler;
12370
+ this.sender = sender;
12371
+ this.spec = spec;
12372
+ }
12373
+ async onSocketMessage(msg) {
12374
+ // attempt to decode the messsage
12375
+ try {
12376
+ const message = Decoder.decodeObject(messageCodec, msg, this.spec);
12377
+ logger$4.log `[${message.type}] incoming message`;
12378
+ await this.processAndRespond(message);
12379
+ }
12380
+ catch (e) {
12381
+ logger$4.error `Error while processing fuzz v1 message: ${e}`;
12382
+ logger$4.error `${e}`;
12383
+ if (e instanceof Error) {
12384
+ logger$4.error `${e.stack ?? ""}`;
12385
+ }
12386
+ this.sender.close();
12387
+ }
12388
+ }
12389
+ async processAndRespond(message) {
12390
+ let response = null;
12391
+ switch (message.type) {
12392
+ case MessageType.PeerInfo: {
12393
+ // only support V1
12394
+ if (message.value.fuzzVersion !== 1) {
12395
+ logger$4.warn `Unsupported fuzzer protocol version: ${message.value.fuzzVersion}. Closing`;
12396
+ this.sender.close();
12397
+ return;
12398
+ }
12399
+ // Handle handshake
12400
+ const ourPeerInfo = await this.msgHandler.getPeerInfo(message.value);
12401
+ // Calculate session features (intersection of both peer features)
12402
+ this.sessionFeatures = message.value.features & ourPeerInfo.features;
12403
+ logger$4.info `Handshake completed. Shared features: 0b${this.sessionFeatures.toString(2)}`;
12404
+ logger$4.log `Feature ancestry: ${(this.sessionFeatures & Features.Ancestry) !== 0}`;
12405
+ logger$4.log `Feature fork: ${(this.sessionFeatures & Features.Fork) !== 0}`;
12406
+ response = {
12407
+ type: MessageType.PeerInfo,
12408
+ value: ourPeerInfo,
12409
+ };
12410
+ break;
12411
+ }
12412
+ case MessageType.Initialize: {
12413
+ const stateRoot = await this.msgHandler.initialize(message.value);
12414
+ response = {
12415
+ type: MessageType.StateRoot,
12416
+ value: stateRoot,
12417
+ };
12418
+ break;
12419
+ }
12420
+ case MessageType.ImportBlock: {
12421
+ const result = await this.msgHandler.importBlock(message.value);
12422
+ if (result.isOk) {
12423
+ response = {
12424
+ type: MessageType.StateRoot,
12425
+ value: result.ok,
12426
+ };
12427
+ }
12428
+ else {
12429
+ response = {
12430
+ type: MessageType.Error,
12431
+ value: result.error,
12432
+ };
12433
+ }
12434
+ break;
12435
+ }
12436
+ case MessageType.GetState: {
12437
+ const state = await this.msgHandler.getSerializedState(message.value);
12438
+ response = {
12439
+ type: MessageType.State,
12440
+ value: state,
12441
+ };
12442
+ break;
12443
+ }
12444
+ case MessageType.StateRoot: {
12445
+ logger$4.log `--> Received unexpected 'StateRoot' message from the fuzzer. Closing.`;
12446
+ this.sender.close();
12447
+ return;
12448
+ }
12449
+ case MessageType.State: {
12450
+ logger$4.log `--> Received unexpected 'State' message from the fuzzer. Closing.`;
12451
+ this.sender.close();
12452
+ return;
12453
+ }
12454
+ case MessageType.Error: {
12455
+ logger$4.log `--> Received unexpected 'Error' message from the fuzzer. Closing.`;
12456
+ this.sender.close();
12457
+ return;
12458
+ }
12459
+ default: {
12460
+ logger$4.log `--> Received unexpected message type ${JSON.stringify(message)} from the fuzzer. Closing.`;
12461
+ this.sender.close();
12462
+ try {
12463
+ assertNever(message);
12464
+ }
12465
+ catch {
12466
+ return;
12467
+ }
12468
+ }
12469
+ }
12470
+ if (response !== null) {
12471
+ logger$4.trace `<-- responding with: ${response.type}`;
12472
+ const encoded = Encoder.encodeObject(messageCodec, response, this.spec);
12473
+ this.sender.send(encoded);
12474
+ }
12475
+ else {
12476
+ logger$4.warn `<-- no response generated for: ${message.type}`;
12477
+ }
12478
+ }
12479
+ onClose({ error }) {
12480
+ logger$4.log `Closing the v1 handler. Reason: ${error !== undefined ? error.message : "close"}.`;
12481
+ }
12482
+ /** Check if a specific feature is enabled in the session */
12483
+ hasFeature(feature) {
12484
+ return (this.sessionFeatures & feature) !== 0;
12485
+ }
12486
+ }
12487
+
12488
+ var index$b = /*#__PURE__*/Object.freeze({
12489
+ __proto__: null,
12490
+ AncestryItem: AncestryItem,
12491
+ ErrorMessage: ErrorMessage,
12492
+ get Features () { return Features; },
12493
+ FuzzTarget: FuzzTarget,
12494
+ Initialize: Initialize,
12495
+ KeyValue: KeyValue,
12496
+ get MessageType () { return MessageType; },
12497
+ PeerInfo: PeerInfo,
12498
+ Version: Version,
12499
+ ancestryCodec: ancestryCodec,
12500
+ getStateCodec: getStateCodec,
12501
+ messageCodec: messageCodec,
12502
+ stateCodec: stateCodec,
12503
+ stateRootCodec: stateRootCodec
12504
+ });
12505
+
12506
+ var index$a = /*#__PURE__*/Object.freeze({
12507
+ __proto__: null,
12508
+ v1: index$b
12509
+ });
12510
+
12071
12511
  /** Size of the transfer memo. */
12072
12512
  const TRANSFER_MEMO_BYTES = W_T;
12073
12513
  /**
@@ -16898,8 +17338,8 @@ var index$3 = /*#__PURE__*/Object.freeze({
16898
17338
  asOpaqueType: asOpaqueType,
16899
17339
  assertEmpty: assertEmpty,
16900
17340
  assertNever: assertNever,
16901
- block: index$j,
16902
- bytes: index$q,
17341
+ block: index$l,
17342
+ bytes: index$s,
16903
17343
  check: check,
16904
17344
  clampU64ToU32: clampU64ToU32,
16905
17345
  createResults: createResults,
@@ -16907,13 +17347,13 @@ var index$3 = /*#__PURE__*/Object.freeze({
16907
17347
  extractCodeAndMetadata: extractCodeAndMetadata,
16908
17348
  getServiceId: getServiceId,
16909
17349
  getServiceIdOrCurrent: getServiceIdOrCurrent,
16910
- hash: index$n,
17350
+ hash: index$p,
16911
17351
  inspect: inspect,
16912
17352
  instructionArgumentTypeMap: instructionArgumentTypeMap,
16913
17353
  interpreter: index$7,
16914
17354
  isBrowser: isBrowser,
16915
17355
  measure: measure,
16916
- numbers: index$p,
17356
+ numbers: index$r,
16917
17357
  resultToString: resultToString,
16918
17358
  seeThrough: seeThrough,
16919
17359
  slotsToPreimageStatus: slotsToPreimageStatus,
@@ -17627,4 +18067,4 @@ var index = /*#__PURE__*/Object.freeze({
17627
18067
  WorkPackageExecutor: WorkPackageExecutor
17628
18068
  });
17629
18069
 
17630
- export { index$j as block, index$h as block_json, index$q as bytes, index$o as codec, index$l as collections, index$k as config, index$f as config_node, index$m as crypto, index$b as database, index$a as erasure_coding, index$n as hash, index$9 as jam_host_calls, index$i as json_parser, index$g as logger, index$8 as mmr, index$p as numbers, index$r 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$e as state, index$1 as state_json, index$c as state_merkleization, index as transition, index$d as trie, index$s as utils };
18070
+ 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 };