@typeberry/lib 0.1.2-a90b655 → 0.1.2-b25cc82

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 CHANGED
@@ -563,7 +563,7 @@ function isResult(x) {
563
563
  * as an afterthought.
564
564
  */
565
565
 
566
- var index$u = /*#__PURE__*/Object.freeze({
566
+ var index$s = /*#__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$t = /*#__PURE__*/Object.freeze({
720
+ var index$r = /*#__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$s = /*#__PURE__*/Object.freeze({
971
+ var index$q = /*#__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$r = /*#__PURE__*/Object.freeze({
1073
+ var index$p = /*#__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$q = /*#__PURE__*/Object.freeze({
2483
+ var index$o = /*#__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$p = /*#__PURE__*/Object.freeze({
4922
+ var index$n = /*#__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$o = /*#__PURE__*/Object.freeze({
4988
+ var index$m = /*#__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$n = /*#__PURE__*/Object.freeze({
5592
+ var index$l = /*#__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$m = /*#__PURE__*/Object.freeze({
5787
+ var index$k = /*#__PURE__*/Object.freeze({
5788
5788
  __proto__: null,
5789
5789
  Bootnode: Bootnode,
5790
5790
  ChainSpec: ChainSpec,
@@ -5957,6 +5957,40 @@ var assurances = /*#__PURE__*/Object.freeze({
5957
5957
  assurancesExtrinsicCodec: assurancesExtrinsicCodec
5958
5958
  });
5959
5959
 
5960
+ /** Attempt to convert a number into `TimeSlot`. */
5961
+ const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
5962
+ /** Attempt to convert a number into `ValidatorIndex`. */
5963
+ const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
5964
+ /** Attempt to convert a number into `ServiceId`. */
5965
+ const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
5966
+ const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
5967
+ /** Attempt to convert a number into `CoreIndex`. */
5968
+ const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
5969
+ /** Attempt to convert a number into `Epoch`. */
5970
+ const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
5971
+ function tryAsPerValidator(array, spec) {
5972
+ check `
5973
+ ${array.length === spec.validatorsCount}
5974
+ Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
5975
+ `;
5976
+ return asKnownSize(array);
5977
+ }
5978
+ const codecPerValidator = (val) => codecWithContext((context) => {
5979
+ return codecKnownSizeArray(val, {
5980
+ fixedLength: context.validatorsCount,
5981
+ });
5982
+ });
5983
+ function tryAsPerEpochBlock(array, spec) {
5984
+ check `
5985
+ ${array.length === spec.epochLength}
5986
+ Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
5987
+ `;
5988
+ return asKnownSize(array);
5989
+ }
5990
+ const codecPerEpochBlock = (val) => codecWithContext((context) => {
5991
+ return codecKnownSizeArray(val, { fixedLength: context.epochLength });
5992
+ });
5993
+
5960
5994
  /**
5961
5995
  * Proof of signing a contradictory [`Judgement`] of a work report.
5962
5996
  */
@@ -6148,40 +6182,6 @@ var disputes = /*#__PURE__*/Object.freeze({
6148
6182
  Verdict: Verdict
6149
6183
  });
6150
6184
 
6151
- /** Attempt to convert a number into `TimeSlot`. */
6152
- const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
6153
- /** Attempt to convert a number into `ValidatorIndex`. */
6154
- const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
6155
- /** Attempt to convert a number into `ServiceId`. */
6156
- const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
6157
- const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
6158
- /** Attempt to convert a number into `CoreIndex`. */
6159
- const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
6160
- /** Attempt to convert a number into `Epoch`. */
6161
- const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
6162
- function tryAsPerValidator(array, spec) {
6163
- check `
6164
- ${array.length === spec.validatorsCount}
6165
- Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
6166
- `;
6167
- return asKnownSize(array);
6168
- }
6169
- const codecPerValidator = (val) => codecWithContext((context) => {
6170
- return codecKnownSizeArray(val, {
6171
- fixedLength: context.validatorsCount,
6172
- });
6173
- });
6174
- function tryAsPerEpochBlock(array, spec) {
6175
- check `
6176
- ${array.length === spec.epochLength}
6177
- Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
6178
- `;
6179
- return asKnownSize(array);
6180
- }
6181
- const codecPerEpochBlock = (val) => codecWithContext((context) => {
6182
- return codecKnownSizeArray(val, { fixedLength: context.epochLength });
6183
- });
6184
-
6185
6185
  /**
6186
6186
  * Mapping between work package hash and root hash of it's exports.
6187
6187
  *
@@ -7260,8 +7260,26 @@ class Block extends WithDebug {
7260
7260
  this.extrinsic = extrinsic;
7261
7261
  }
7262
7262
  }
7263
+ function emptyBlock(slot = tryAsTimeSlot(0)) {
7264
+ const header = Header.empty();
7265
+ header.timeSlotIndex = slot;
7266
+ return Block.create({
7267
+ header,
7268
+ extrinsic: Extrinsic.create({
7269
+ tickets: asKnownSize([]),
7270
+ preimages: [],
7271
+ assurances: asKnownSize([]),
7272
+ guarantees: asKnownSize([]),
7273
+ disputes: {
7274
+ verdicts: [],
7275
+ culprits: [],
7276
+ faults: [],
7277
+ },
7278
+ }),
7279
+ });
7280
+ }
7263
7281
 
7264
- var index$l = /*#__PURE__*/Object.freeze({
7282
+ var index$j = /*#__PURE__*/Object.freeze({
7265
7283
  __proto__: null,
7266
7284
  Block: Block,
7267
7285
  EpochMarker: EpochMarker,
@@ -7276,6 +7294,7 @@ var index$l = /*#__PURE__*/Object.freeze({
7276
7294
  codecPerValidator: codecPerValidator,
7277
7295
  codecUtils: codec,
7278
7296
  disputes: disputes,
7297
+ emptyBlock: emptyBlock,
7279
7298
  encodeUnsealedHeader: encodeUnsealedHeader,
7280
7299
  guarantees: guarantees,
7281
7300
  headerViewWithHashCodec: headerViewWithHashCodec,
@@ -7516,7 +7535,7 @@ var json;
7516
7535
  json.object = object;
7517
7536
  })(json || (json = {}));
7518
7537
 
7519
- var index$k = /*#__PURE__*/Object.freeze({
7538
+ var index$i = /*#__PURE__*/Object.freeze({
7520
7539
  __proto__: null,
7521
7540
  get json () { return json; },
7522
7541
  parseFromJson: parseFromJson
@@ -7786,7 +7805,7 @@ const blockFromJson = (spec) => json.object({
7786
7805
  extrinsic: getExtrinsicFromJson(spec),
7787
7806
  }, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
7788
7807
 
7789
- var index$j = /*#__PURE__*/Object.freeze({
7808
+ var index$h = /*#__PURE__*/Object.freeze({
7790
7809
  __proto__: null,
7791
7810
  blockFromJson: blockFromJson,
7792
7811
  disputesExtrinsicFromJson: disputesExtrinsicFromJson,
@@ -8052,8 +8071,8 @@ function print(level, levelAndName, strings, data) {
8052
8071
  return;
8053
8072
  }
8054
8073
  const lvlText = Level[level].padEnd(5);
8055
- const val = strings.map((v, idx) => `${v}${data[idx]}`);
8056
- const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
8074
+ const val = strings.map((v, idx) => `${v}${idx < data.length ? data[idx] : ""}`);
8075
+ const msg = `${lvlText} [${levelAndName[1]}] ${val.join("")}`;
8057
8076
  if (level === Level.WARN) {
8058
8077
  console.warn(msg);
8059
8078
  }
@@ -8284,7 +8303,7 @@ class Logger {
8284
8303
  }
8285
8304
  }
8286
8305
 
8287
- var index$i = /*#__PURE__*/Object.freeze({
8306
+ var index$g = /*#__PURE__*/Object.freeze({
8288
8307
  __proto__: null,
8289
8308
  get Level () { return Level; },
8290
8309
  Logger: Logger,
@@ -8307,7 +8326,7 @@ class AuthorshipOptions {
8307
8326
  }
8308
8327
  }
8309
8328
 
8310
- const logger$5 = Logger.new(undefined, "config");
8329
+ const logger$4 = Logger.new(undefined, "config");
8311
8330
  /** Development config. Will accept unsealed blocks for now. */
8312
8331
  const DEV_CONFIG = "dev";
8313
8332
  /** Default config file. */
@@ -8366,15 +8385,15 @@ class NodeConfiguration {
8366
8385
  }
8367
8386
  function loadConfig(configPath) {
8368
8387
  if (configPath === DEFAULT_CONFIG) {
8369
- logger$5.log `🔧 Loading DEFAULT config`;
8388
+ logger$4.log `🔧 Loading DEFAULT config`;
8370
8389
  return parseFromJson(configs.default, NodeConfiguration.fromJson);
8371
8390
  }
8372
8391
  if (configPath === DEV_CONFIG) {
8373
- logger$5.log `🔧 Loading DEV config`;
8392
+ logger$4.log `🔧 Loading DEV config`;
8374
8393
  return parseFromJson(configs.dev, NodeConfiguration.fromJson);
8375
8394
  }
8376
8395
  try {
8377
- logger$5.log `🔧 Loading config from ${configPath}`;
8396
+ logger$4.log `🔧 Loading config from ${configPath}`;
8378
8397
  const configFile = fs.readFileSync(configPath, "utf8");
8379
8398
  const parsed = JSON.parse(configFile);
8380
8399
  return parseFromJson(parsed, NodeConfiguration.fromJson);
@@ -8384,7 +8403,7 @@ function loadConfig(configPath) {
8384
8403
  }
8385
8404
  }
8386
8405
 
8387
- var index$h = /*#__PURE__*/Object.freeze({
8406
+ var index$f = /*#__PURE__*/Object.freeze({
8388
8407
  __proto__: null,
8389
8408
  DEFAULT_CONFIG: DEFAULT_CONFIG,
8390
8409
  DEV_CONFIG: DEV_CONFIG,
@@ -10050,7 +10069,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
10050
10069
  sortKeys: (a, b) => a - b,
10051
10070
  });
10052
10071
 
10053
- var index$g = /*#__PURE__*/Object.freeze({
10072
+ var index$e = /*#__PURE__*/Object.freeze({
10054
10073
  __proto__: null,
10055
10074
  AccumulationOutput: AccumulationOutput,
10056
10075
  AutoAccumulate: AutoAccumulate,
@@ -11060,7 +11079,7 @@ const bitLookup = [
11060
11079
  [0b00000000, 8],
11061
11080
  ];
11062
11081
 
11063
- var index$f = /*#__PURE__*/Object.freeze({
11082
+ var index$d = /*#__PURE__*/Object.freeze({
11064
11083
  __proto__: null,
11065
11084
  BranchNode: BranchNode,
11066
11085
  InMemoryTrie: InMemoryTrie,
@@ -11406,7 +11425,7 @@ function loadState(spec, entries) {
11406
11425
  * hashmap of `key -> value` entries.
11407
11426
  */
11408
11427
 
11409
- var index$e = /*#__PURE__*/Object.freeze({
11428
+ var index$c = /*#__PURE__*/Object.freeze({
11410
11429
  __proto__: null,
11411
11430
  SerializedService: SerializedService,
11412
11431
  SerializedState: SerializedState,
@@ -11692,7 +11711,7 @@ class InMemoryStates {
11692
11711
  }
11693
11712
  }
11694
11713
 
11695
- var index$d = /*#__PURE__*/Object.freeze({
11714
+ var index$b = /*#__PURE__*/Object.freeze({
11696
11715
  __proto__: null,
11697
11716
  InMemoryBlocks: InMemoryBlocks,
11698
11717
  InMemoryStates: InMemoryStates,
@@ -12054,7 +12073,7 @@ const initEc = async () => {
12054
12073
  await init.reedSolomon();
12055
12074
  };
12056
12075
 
12057
- var index$c = /*#__PURE__*/Object.freeze({
12076
+ var index$a = /*#__PURE__*/Object.freeze({
12058
12077
  __proto__: null,
12059
12078
  N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
12060
12079
  N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
@@ -12078,439 +12097,6 @@ var index$c = /*#__PURE__*/Object.freeze({
12078
12097
  unzip: unzip
12079
12098
  });
12080
12099
 
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
-
12514
12100
  /** Size of the transfer memo. */
12515
12101
  const TRANSFER_MEMO_BYTES = W_T;
12516
12102
  /**
@@ -14558,6 +14144,17 @@ class PageRange {
14558
14144
  }
14559
14145
  return new PageRange(start, length);
14560
14146
  }
14147
+ /** Returns true if the page range is wrapped (`start` >= `end`) and is not empty */
14148
+ isWrapped() {
14149
+ return this.start >= this.end && !this.isEmpty();
14150
+ }
14151
+ /** Checks if given page number is within the range */
14152
+ isInRange(page) {
14153
+ if (this.isWrapped()) {
14154
+ return page >= this.start || page < this.end;
14155
+ }
14156
+ return page >= this.start && page < this.end;
14157
+ }
14561
14158
  /** Checks if a range is empty (`length === 0`) */
14562
14159
  isEmpty() {
14563
14160
  return this.length === 0;
@@ -14898,10 +14495,11 @@ class MemoryBuilder {
14898
14495
  startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
14899
14496
  `;
14900
14497
  this.ensureNotFinalized();
14901
- const range = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
14902
- const pages = PageRange.fromMemoryRange(range);
14903
- for (const pageNumber of pages) {
14904
- if (this.initialMemory.has(pageNumber)) {
14498
+ const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
14499
+ const heapPagesRange = PageRange.fromMemoryRange(heapRange);
14500
+ const initializedPageNumbers = Array.from(this.initialMemory.keys());
14501
+ for (const pageNumber of initializedPageNumbers) {
14502
+ if (heapPagesRange.isInRange(pageNumber)) {
14905
14503
  throw new IncorrectSbrkIndex();
14906
14504
  }
14907
14505
  }
@@ -17341,8 +16939,8 @@ var index$3 = /*#__PURE__*/Object.freeze({
17341
16939
  asOpaqueType: asOpaqueType,
17342
16940
  assertEmpty: assertEmpty,
17343
16941
  assertNever: assertNever,
17344
- block: index$l,
17345
- bytes: index$s,
16942
+ block: index$j,
16943
+ bytes: index$q,
17346
16944
  check: check,
17347
16945
  clampU64ToU32: clampU64ToU32,
17348
16946
  createResults: createResults,
@@ -17350,13 +16948,13 @@ var index$3 = /*#__PURE__*/Object.freeze({
17350
16948
  extractCodeAndMetadata: extractCodeAndMetadata,
17351
16949
  getServiceId: getServiceId,
17352
16950
  getServiceIdOrCurrent: getServiceIdOrCurrent,
17353
- hash: index$p,
16951
+ hash: index$n,
17354
16952
  inspect: inspect,
17355
16953
  instructionArgumentTypeMap: instructionArgumentTypeMap,
17356
16954
  interpreter: index$7,
17357
16955
  isBrowser: isBrowser,
17358
16956
  measure: measure,
17359
- numbers: index$r,
16957
+ numbers: index$p,
17360
16958
  resultToString: resultToString,
17361
16959
  seeThrough: seeThrough,
17362
16960
  slotsToPreimageStatus: slotsToPreimageStatus,
@@ -18070,33 +17668,32 @@ var index = /*#__PURE__*/Object.freeze({
18070
17668
  WorkPackageExecutor: WorkPackageExecutor
18071
17669
  });
18072
17670
 
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;
17671
+ exports.block = index$j;
17672
+ exports.block_json = index$h;
17673
+ exports.bytes = index$q;
17674
+ exports.codec = index$o;
17675
+ exports.collections = index$l;
17676
+ exports.config = index$k;
17677
+ exports.config_node = index$f;
17678
+ exports.crypto = index$m;
17679
+ exports.database = index$b;
17680
+ exports.erasure_coding = index$a;
17681
+ exports.hash = index$n;
18085
17682
  exports.jam_host_calls = index$9;
18086
- exports.json_parser = index$k;
18087
- exports.logger = index$i;
17683
+ exports.json_parser = index$i;
17684
+ exports.logger = index$g;
18088
17685
  exports.mmr = index$8;
18089
- exports.numbers = index$r;
18090
- exports.ordering = index$t;
17686
+ exports.numbers = index$p;
17687
+ exports.ordering = index$r;
18091
17688
  exports.pvm = index$3;
18092
17689
  exports.pvm_host_calls = index$6;
18093
17690
  exports.pvm_interpreter = index$7;
18094
17691
  exports.pvm_program = index$4;
18095
17692
  exports.pvm_spi_decoder = index$5;
18096
17693
  exports.shuffling = index$2;
18097
- exports.state = index$g;
17694
+ exports.state = index$e;
18098
17695
  exports.state_json = index$1;
18099
- exports.state_merkleization = index$e;
17696
+ exports.state_merkleization = index$c;
18100
17697
  exports.transition = index;
18101
- exports.trie = index$f;
18102
- exports.utils = index$u;
17698
+ exports.trie = index$d;
17699
+ exports.utils = index$s;