@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/index.js CHANGED
@@ -560,7 +560,7 @@ function isResult(x) {
560
560
  * as an afterthought.
561
561
  */
562
562
 
563
- var index$s = /*#__PURE__*/Object.freeze({
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$r = /*#__PURE__*/Object.freeze({
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$q = /*#__PURE__*/Object.freeze({
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$p = /*#__PURE__*/Object.freeze({
1070
+ var index$r = /*#__PURE__*/Object.freeze({
1071
1071
  __proto__: null,
1072
1072
  isU16: isU16,
1073
1073
  isU32: isU32,
@@ -2477,7 +2477,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
2477
2477
  }, skipper);
2478
2478
  }
2479
2479
 
2480
- var index$o = /*#__PURE__*/Object.freeze({
2480
+ var index$q = /*#__PURE__*/Object.freeze({
2481
2481
  __proto__: null,
2482
2482
  Decoder: Decoder,
2483
2483
  Descriptor: Descriptor,
@@ -4916,7 +4916,7 @@ var keccak = /*#__PURE__*/Object.freeze({
4916
4916
  hashBlobs: hashBlobs
4917
4917
  });
4918
4918
 
4919
- var index$n = /*#__PURE__*/Object.freeze({
4919
+ var index$p = /*#__PURE__*/Object.freeze({
4920
4920
  __proto__: null,
4921
4921
  HASH_SIZE: HASH_SIZE,
4922
4922
  PageAllocator: PageAllocator,
@@ -4982,7 +4982,7 @@ var keyDerivation = /*#__PURE__*/Object.freeze({
4982
4982
  trivialSeed: trivialSeed
4983
4983
  });
4984
4984
 
4985
- var index$m = /*#__PURE__*/Object.freeze({
4985
+ var index$o = /*#__PURE__*/Object.freeze({
4986
4986
  __proto__: null,
4987
4987
  BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
4988
4988
  BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
@@ -5586,7 +5586,7 @@ class TruncatedHashDictionary {
5586
5586
  }
5587
5587
  }
5588
5588
 
5589
- var index$l = /*#__PURE__*/Object.freeze({
5589
+ var index$n = /*#__PURE__*/Object.freeze({
5590
5590
  __proto__: null,
5591
5591
  FixedSizeArray: FixedSizeArray,
5592
5592
  HashDictionary: HashDictionary,
@@ -5781,7 +5781,7 @@ class Bootnode {
5781
5781
  }
5782
5782
  }
5783
5783
 
5784
- var index$k = /*#__PURE__*/Object.freeze({
5784
+ var index$m = /*#__PURE__*/Object.freeze({
5785
5785
  __proto__: null,
5786
5786
  Bootnode: Bootnode,
5787
5787
  ChainSpec: ChainSpec,
@@ -7258,7 +7258,7 @@ class Block extends WithDebug {
7258
7258
  }
7259
7259
  }
7260
7260
 
7261
- var index$j = /*#__PURE__*/Object.freeze({
7261
+ var index$l = /*#__PURE__*/Object.freeze({
7262
7262
  __proto__: null,
7263
7263
  Block: Block,
7264
7264
  EpochMarker: EpochMarker,
@@ -7513,7 +7513,7 @@ var json;
7513
7513
  json.object = object;
7514
7514
  })(json || (json = {}));
7515
7515
 
7516
- var index$i = /*#__PURE__*/Object.freeze({
7516
+ var index$k = /*#__PURE__*/Object.freeze({
7517
7517
  __proto__: null,
7518
7518
  get json () { return json; },
7519
7519
  parseFromJson: parseFromJson
@@ -7783,7 +7783,7 @@ const blockFromJson = (spec) => json.object({
7783
7783
  extrinsic: getExtrinsicFromJson(spec),
7784
7784
  }, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
7785
7785
 
7786
- var index$h = /*#__PURE__*/Object.freeze({
7786
+ var index$j = /*#__PURE__*/Object.freeze({
7787
7787
  __proto__: null,
7788
7788
  blockFromJson: blockFromJson,
7789
7789
  disputesExtrinsicFromJson: disputesExtrinsicFromJson,
@@ -8049,8 +8049,8 @@ function print(level, levelAndName, strings, data) {
8049
8049
  return;
8050
8050
  }
8051
8051
  const lvlText = Level[level].padEnd(5);
8052
- const val = strings.map((v, idx) => `${v}${idx < data.length ? data[idx] : ""}`);
8053
- const msg = `${lvlText} [${levelAndName[1]}] ${val.join("")}`;
8052
+ const val = strings.map((v, idx) => `${v}${data[idx]}`);
8053
+ const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
8054
8054
  if (level === Level.WARN) {
8055
8055
  console.warn(msg);
8056
8056
  }
@@ -8281,7 +8281,7 @@ class Logger {
8281
8281
  }
8282
8282
  }
8283
8283
 
8284
- var index$g = /*#__PURE__*/Object.freeze({
8284
+ var index$i = /*#__PURE__*/Object.freeze({
8285
8285
  __proto__: null,
8286
8286
  get Level () { return Level; },
8287
8287
  Logger: Logger,
@@ -8304,7 +8304,7 @@ class AuthorshipOptions {
8304
8304
  }
8305
8305
  }
8306
8306
 
8307
- const logger$4 = Logger.new(import.meta.filename, "config");
8307
+ const logger$5 = Logger.new(import.meta.filename, "config");
8308
8308
  /** Development config. Will accept unsealed blocks for now. */
8309
8309
  const DEV_CONFIG = "dev";
8310
8310
  /** Default config file. */
@@ -8363,15 +8363,15 @@ class NodeConfiguration {
8363
8363
  }
8364
8364
  function loadConfig(configPath) {
8365
8365
  if (configPath === DEFAULT_CONFIG) {
8366
- logger$4.log `🔧 Loading DEFAULT config`;
8366
+ logger$5.log `🔧 Loading DEFAULT config`;
8367
8367
  return parseFromJson(configs.default, NodeConfiguration.fromJson);
8368
8368
  }
8369
8369
  if (configPath === DEV_CONFIG) {
8370
- logger$4.log `🔧 Loading DEV config`;
8370
+ logger$5.log `🔧 Loading DEV config`;
8371
8371
  return parseFromJson(configs.dev, NodeConfiguration.fromJson);
8372
8372
  }
8373
8373
  try {
8374
- logger$4.log `🔧 Loading config from ${configPath}`;
8374
+ logger$5.log `🔧 Loading config from ${configPath}`;
8375
8375
  const configFile = fs.readFileSync(configPath, "utf8");
8376
8376
  const parsed = JSON.parse(configFile);
8377
8377
  return parseFromJson(parsed, NodeConfiguration.fromJson);
@@ -8381,7 +8381,7 @@ function loadConfig(configPath) {
8381
8381
  }
8382
8382
  }
8383
8383
 
8384
- var index$f = /*#__PURE__*/Object.freeze({
8384
+ var index$h = /*#__PURE__*/Object.freeze({
8385
8385
  __proto__: null,
8386
8386
  DEFAULT_CONFIG: DEFAULT_CONFIG,
8387
8387
  DEV_CONFIG: DEV_CONFIG,
@@ -10047,7 +10047,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
10047
10047
  sortKeys: (a, b) => a - b,
10048
10048
  });
10049
10049
 
10050
- var index$e = /*#__PURE__*/Object.freeze({
10050
+ var index$g = /*#__PURE__*/Object.freeze({
10051
10051
  __proto__: null,
10052
10052
  AccumulationOutput: AccumulationOutput,
10053
10053
  AutoAccumulate: AutoAccumulate,
@@ -11057,7 +11057,7 @@ const bitLookup = [
11057
11057
  [0b00000000, 8],
11058
11058
  ];
11059
11059
 
11060
- var index$d = /*#__PURE__*/Object.freeze({
11060
+ var index$f = /*#__PURE__*/Object.freeze({
11061
11061
  __proto__: null,
11062
11062
  BranchNode: BranchNode,
11063
11063
  InMemoryTrie: InMemoryTrie,
@@ -11403,7 +11403,7 @@ function loadState(spec, entries) {
11403
11403
  * hashmap of `key -> value` entries.
11404
11404
  */
11405
11405
 
11406
- var index$c = /*#__PURE__*/Object.freeze({
11406
+ var index$e = /*#__PURE__*/Object.freeze({
11407
11407
  __proto__: null,
11408
11408
  SerializedService: SerializedService,
11409
11409
  SerializedState: SerializedState,
@@ -11689,7 +11689,7 @@ class InMemoryStates {
11689
11689
  }
11690
11690
  }
11691
11691
 
11692
- var index$b = /*#__PURE__*/Object.freeze({
11692
+ var index$d = /*#__PURE__*/Object.freeze({
11693
11693
  __proto__: null,
11694
11694
  InMemoryBlocks: InMemoryBlocks,
11695
11695
  InMemoryStates: InMemoryStates,
@@ -12051,7 +12051,7 @@ const initEc = async () => {
12051
12051
  await init.reedSolomon();
12052
12052
  };
12053
12053
 
12054
- var index$a = /*#__PURE__*/Object.freeze({
12054
+ var index$c = /*#__PURE__*/Object.freeze({
12055
12055
  __proto__: null,
12056
12056
  N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
12057
12057
  N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
@@ -12075,6 +12075,439 @@ var index$a = /*#__PURE__*/Object.freeze({
12075
12075
  unzip: unzip
12076
12076
  });
12077
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
+
12078
12511
  /** Size of the transfer memo. */
12079
12512
  const TRANSFER_MEMO_BYTES = W_T;
12080
12513
  /**
@@ -16905,8 +17338,8 @@ var index$3 = /*#__PURE__*/Object.freeze({
16905
17338
  asOpaqueType: asOpaqueType,
16906
17339
  assertEmpty: assertEmpty,
16907
17340
  assertNever: assertNever,
16908
- block: index$j,
16909
- bytes: index$q,
17341
+ block: index$l,
17342
+ bytes: index$s,
16910
17343
  check: check,
16911
17344
  clampU64ToU32: clampU64ToU32,
16912
17345
  createResults: createResults,
@@ -16914,13 +17347,13 @@ var index$3 = /*#__PURE__*/Object.freeze({
16914
17347
  extractCodeAndMetadata: extractCodeAndMetadata,
16915
17348
  getServiceId: getServiceId,
16916
17349
  getServiceIdOrCurrent: getServiceIdOrCurrent,
16917
- hash: index$n,
17350
+ hash: index$p,
16918
17351
  inspect: inspect,
16919
17352
  instructionArgumentTypeMap: instructionArgumentTypeMap,
16920
17353
  interpreter: index$7,
16921
17354
  isBrowser: isBrowser,
16922
17355
  measure: measure,
16923
- numbers: index$p,
17356
+ numbers: index$r,
16924
17357
  resultToString: resultToString,
16925
17358
  seeThrough: seeThrough,
16926
17359
  slotsToPreimageStatus: slotsToPreimageStatus,
@@ -17634,4 +18067,4 @@ var index = /*#__PURE__*/Object.freeze({
17634
18067
  WorkPackageExecutor: WorkPackageExecutor
17635
18068
  });
17636
18069
 
17637
- 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeberry/lib",
3
- "version": "0.1.2-953c012",
3
+ "version": "0.1.2-a90b655",
4
4
  "main": "index.js",
5
5
  "author": "Fluffy Labs",
6
6
  "license": "MPL-2.0",