@typeberry/jam 0.1.0-b2d0b72 → 0.1.0-eb00e84

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.
@@ -25323,18 +25323,30 @@ function isBrowser() {
25323
25323
  * We avoid using `node:assert` to keep compatibility with a browser environment.
25324
25324
  * Note the checks should not have any side effects, since we might decide
25325
25325
  * to remove all of them in a post-processing step.
25326
- *
25327
- * NOTE the function is intended to be used as tagged template string for the performance
25328
- * reasons.
25329
25326
  */
25330
- function debug_check(strings, condition, ...data) {
25327
+ function debug_check(condition, message) {
25331
25328
  if (!condition) {
25332
- // add an empty value so that `data.length === strings.length`
25333
- data.unshift("");
25334
- const message = strings.map((v, index) => `${v}${data[index] ?? ""}`);
25335
- throw new Error(`Assertion failure:${message.join("")}`);
25329
+ throw new Error(`Assertion failure: ${message ?? ""}`);
25336
25330
  }
25337
25331
  }
25332
+ function cast(_a, condition) {
25333
+ return condition;
25334
+ }
25335
+ /**
25336
+ * Yet another function to perform runtime assertions.
25337
+ * This function returns a new type to mark in the code that this value was checked and you don't have to do it again.
25338
+ *
25339
+ * In the post-processing step all usages of this functions should be replaced with simple casting. An example:
25340
+ * const x = checkAndType<number, CheckedNumber>(y);
25341
+ * should be replaced with:
25342
+ * const x = y as CheckedNumber;
25343
+ */
25344
+ function ensure(a, condition, message) {
25345
+ if (cast(a, condition)) {
25346
+ return a;
25347
+ }
25348
+ throw new Error(`Assertion failure: ${message ?? ""}`);
25349
+ }
25338
25350
  /**
25339
25351
  * The function can be used to make sure that a particular type is `never`
25340
25352
  * at some point in the code.
@@ -25503,7 +25515,7 @@ function result_resultToString(res) {
25503
25515
  const result_Result = {
25504
25516
  /** Create new [`Result`] with `Ok` status. */
25505
25517
  ok: (ok) => {
25506
- debug_check `${ok !== undefined} 'ok' type cannot be undefined.`;
25518
+ debug_check(ok !== undefined, "`Ok` type cannot be undefined.");
25507
25519
  return {
25508
25520
  isOk: true,
25509
25521
  isError: false,
@@ -25512,7 +25524,7 @@ const result_Result = {
25512
25524
  },
25513
25525
  /** Create new [`Result`] with `Error` status. */
25514
25526
  error: (error, details = "") => {
25515
- debug_check `${error !== undefined} 'Error' type cannot be undefined.`;
25527
+ debug_check(error !== undefined, "`Error` type cannot be undefined.");
25516
25528
  return {
25517
25529
  isOk: false,
25518
25530
  isError: true,
@@ -25796,10 +25808,7 @@ class bitvec_BitVec {
25796
25808
  constructor(data, bitLength) {
25797
25809
  this.data = data;
25798
25810
  this.bitLength = bitLength;
25799
- debug_check `
25800
- ${data.length * 8 >= bitLength}
25801
- Not enough bytes in the data array. Need ${data.length * 8} has ${bitLength}.
25802
- `;
25811
+ debug_check(data.length * 8 >= bitLength, `Not enough bytes in the data array. Need ${data.length * 8} has ${bitLength}.`);
25803
25812
  this.byteLength = Math.ceil(bitLength / 8);
25804
25813
  }
25805
25814
  /** Return a raw in-memory representation of this [`BitVec`]. */
@@ -25808,10 +25817,7 @@ class bitvec_BitVec {
25808
25817
  }
25809
25818
  /** Perform OR operation on all bits in place. */
25810
25819
  sumWith(other) {
25811
- debug_check `
25812
- ${other.bitLength === this.bitLength}
25813
- Invalid bit length for sumWith: ${other.bitLength} vs ${this.bitLength}
25814
- `;
25820
+ debug_check(other.bitLength === this.bitLength, `Invalid bit length for sumWith: ${other.bitLength} vs ${this.bitLength}`);
25815
25821
  const otherRaw = other.raw;
25816
25822
  for (let i = 0; i < this.byteLength; i++) {
25817
25823
  this.data[i] |= otherRaw[i];
@@ -25821,7 +25827,7 @@ class bitvec_BitVec {
25821
25827
  * Set the bit at index `idx` to value `val`.
25822
25828
  */
25823
25829
  setBit(idx, val) {
25824
- debug_check `${idx >= 0 && idx < this.bitLength} Index out of bounds. Need ${idx} has ${this.bitLength}.`;
25830
+ debug_check(idx < this.bitLength, `Index out of bounds. Need ${idx} has ${this.bitLength}.`);
25825
25831
  const byteIndex = Math.floor(idx / 8);
25826
25832
  const bitIndexInByte = idx % 8;
25827
25833
  const mask = 1 << bitIndexInByte;
@@ -25836,7 +25842,7 @@ class bitvec_BitVec {
25836
25842
  * Return `true` if the bit at index `idx` is set.
25837
25843
  */
25838
25844
  isSet(idx) {
25839
- debug_check `${idx >= 0 && idx < this.bitLength} Index out of bounds. Need ${idx} has ${this.bitLength}.`;
25845
+ debug_check(idx < this.bitLength, `Index out of bounds. Need ${idx} has ${this.bitLength}.`);
25840
25846
  const byteIndex = Math.floor(idx / 8);
25841
25847
  const bitIndexInByte = idx % 8;
25842
25848
  const mask = 1 << bitIndexInByte;
@@ -26003,7 +26009,7 @@ class bytes_BytesBlob {
26003
26009
  }
26004
26010
  /** Create a new [`BytesBlob`] from an array of bytes. */
26005
26011
  static blobFromNumbers(v) {
26006
- debug_check `${v.find((x) => (x & 0xff) !== x) === undefined} BytesBlob.blobFromNumbers used with non-byte number array.`;
26012
+ debug_check(v.find((x) => (x & 0xff) !== x) === undefined, "BytesBlob.blobFromNumbers used with non-byte number array.");
26007
26013
  const arr = new Uint8Array(v);
26008
26014
  return new bytes_BytesBlob(arr);
26009
26015
  }
@@ -26047,7 +26053,7 @@ class bytes_Bytes extends bytes_BytesBlob {
26047
26053
  length;
26048
26054
  constructor(raw, len) {
26049
26055
  super(raw);
26050
- debug_check `${raw.byteLength === len} Given buffer has incorrect size ${raw.byteLength} vs expected ${len}`;
26056
+ debug_check(raw.byteLength === len, `Given buffer has incorrect size ${raw.byteLength} vs expected ${len}`);
26051
26057
  this.length = len;
26052
26058
  }
26053
26059
  /** Create new [`Bytes<X>`] given a backing buffer and it's length. */
@@ -26056,7 +26062,7 @@ class bytes_Bytes extends bytes_BytesBlob {
26056
26062
  }
26057
26063
  /** Create new [`Bytes<X>`] given an array of bytes and it's length. */
26058
26064
  static fromNumbers(v, len) {
26059
- debug_check `${v.find((x) => (x & 0xff) !== x) === undefined} Bytes.fromNumbers used with non-byte number array.`;
26065
+ debug_check(v.find((x) => (x & 0xff) !== x) === undefined, "Bytes.fromNumbers used with non-byte number array.");
26060
26066
  const x = new Uint8Array(v);
26061
26067
  return new bytes_Bytes(x, len);
26062
26068
  }
@@ -26067,7 +26073,7 @@ class bytes_Bytes extends bytes_BytesBlob {
26067
26073
  // TODO [ToDr] `fill` should have the argments swapped to align with the rest.
26068
26074
  /** Create a [`Bytes<X>`] with all bytes filled with given input number. */
26069
26075
  static fill(len, input) {
26070
- debug_check `${(input & 0xff) === input} Input has to be a byte.`;
26076
+ debug_check((input & 0xff) === input, "Input has to be a byte.");
26071
26077
  const bytes = bytes_Bytes.zero(len);
26072
26078
  bytes.raw.fill(input, 0, len);
26073
26079
  return bytes;
@@ -26090,7 +26096,7 @@ class bytes_Bytes extends bytes_BytesBlob {
26090
26096
  }
26091
26097
  /** Compare the sequence to another one. */
26092
26098
  isEqualTo(other) {
26093
- debug_check `${this.length === other.length} Comparing incorrectly typed bytes!`;
26099
+ debug_check(this.length === other.length, "Comparing incorrectly typed bytes!");
26094
26100
  return u8ArraySameLengthEqual(this.raw, other.raw);
26095
26101
  }
26096
26102
  /** Converts current type into some opaque extension. */
@@ -26099,7 +26105,7 @@ class bytes_Bytes extends bytes_BytesBlob {
26099
26105
  }
26100
26106
  }
26101
26107
  function byteFromString(s) {
26102
- debug_check `${s.length === 2} Two-character string expected`;
26108
+ debug_check(s.length === 2, "Two-character string expected");
26103
26109
  const a = numberFromCharCode(s.charCodeAt(0));
26104
26110
  const b = numberFromCharCode(s.charCodeAt(1));
26105
26111
  return (a << 4) | b;
@@ -26153,53 +26159,42 @@ const bytesBlobComparator = (a, b) => a.compare(b);
26153
26159
 
26154
26160
  ;// CONCATENATED MODULE: ./packages/core/numbers/index.ts
26155
26161
 
26156
- const asTypedNumber = (v) => v;
26162
+ const asWithBytesRepresentation = (v) => v;
26157
26163
  const MAX_VALUE_U8 = 0xff;
26158
26164
  const MAX_VALUE_U16 = 0xffff;
26159
26165
  const MAX_VALUE_U32 = 0xffff_ffff;
26160
26166
  const MAX_VALUE_U64 = 0xffffffffffffffffn;
26161
26167
  /** Attempt to cast an input number into U8. */
26162
- const tryAsU8 = (v) => {
26163
- debug_check `${isU8(v)} input must have one-byte representation, got ${v}`;
26164
- return asTypedNumber(v);
26165
- };
26168
+ const tryAsU8 = (v) => ensure(v, isU8(v), `input must have one-byte representation, got ${v}`);
26166
26169
  /** Check if given number is a valid U8 number. */
26167
26170
  const isU8 = (v) => (v & MAX_VALUE_U8) === v;
26168
26171
  /** Attempt to cast an input number into U16. */
26169
- const numbers_tryAsU16 = (v) => {
26170
- debug_check `${isU16(v)} input must have two-byte representation, got ${v}`;
26171
- return asTypedNumber(v);
26172
- };
26172
+ const numbers_tryAsU16 = (v) => ensure(v, isU16(v), `input must have two-byte representation, got ${v}`);
26173
26173
  /** Check if given number is a valid U16 number. */
26174
26174
  const isU16 = (v) => (v & MAX_VALUE_U16) === v;
26175
26175
  /** Attempt to cast an input number into U32. */
26176
- const numbers_tryAsU32 = (v) => {
26177
- debug_check `${isU32(v)} input must have four-byte representation, got ${v}`;
26178
- return asTypedNumber(v);
26179
- };
26176
+ const numbers_tryAsU32 = (v) => ensure(v, isU32(v), `input must have four-byte representation, got ${v}`);
26180
26177
  /** Check if given number is a valid U32 number. */
26181
26178
  const isU32 = (v) => (v & MAX_VALUE_U32) >>> 0 === v;
26182
26179
  /** Attempt to cast an input number into U64. */
26183
26180
  const tryAsU64 = (x) => {
26184
26181
  const v = BigInt(x);
26185
- debug_check `${isU64(v)} input must have eight-byte representation, got ${x}`;
26186
- return asTypedNumber(v);
26182
+ return ensure(v, isU64(v), `input must have eight-byte representation, got ${x}`);
26187
26183
  };
26188
26184
  /** Check if given number is a valid U64 number. */
26189
26185
  const isU64 = (v) => (v & MAX_VALUE_U64) === v;
26190
26186
  /** Collate two U32 parts into one U64. */
26191
26187
  const u64FromParts = ({ lower, upper }) => {
26192
26188
  const val = (BigInt(upper) << 32n) + BigInt(lower);
26193
- return asTypedNumber(val);
26189
+ return asWithBytesRepresentation(val);
26194
26190
  };
26195
26191
  /** Split U64 into lower & upper parts. */
26196
26192
  const u64IntoParts = (v) => {
26197
- // Number(...) safe: both parts are <= 0xffffffff
26198
- const lower = Number(v & (2n ** 32n - 1n));
26199
- const upper = Number(v >> 32n);
26193
+ const lower = v & (2n ** 32n - 1n);
26194
+ const upper = v >> 32n;
26200
26195
  return {
26201
- lower: asTypedNumber(lower),
26202
- upper: asTypedNumber(upper),
26196
+ lower: asWithBytesRepresentation(Number(lower)),
26197
+ upper: asWithBytesRepresentation(Number(upper)),
26203
26198
  };
26204
26199
  };
26205
26200
  /**
@@ -26239,8 +26234,8 @@ function numbers_u32AsLeBytes(value) {
26239
26234
  * Interpret 4-byte `Uint8Array` as U32 written as little endian.
26240
26235
  */
26241
26236
  function leBytesAsU32(uint8Array) {
26242
- check `${uint8Array.length === 4} Input must be a Uint8Array of length 4`;
26243
- return asTypedNumber(uint8Array[0] | (uint8Array[1] << 8) | (uint8Array[2] << 16) | (uint8Array[3] << 24));
26237
+ check(uint8Array.length === 4, "Input must be a Uint8Array of length 4");
26238
+ return asWithBytesRepresentation(uint8Array[0] | (uint8Array[1] << 8) | (uint8Array[2] << 16) | (uint8Array[3] << 24));
26244
26239
  }
26245
26240
  /** Get the smallest value between U64 a and values given as input parameters. */
26246
26241
  const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? min : value), a);
@@ -26531,7 +26526,7 @@ class decoder_Decoder {
26531
26526
  this.skip(newOffset - this.offset);
26532
26527
  }
26533
26528
  else {
26534
- debug_check `${newOffset >= 0} The offset has to be positive`;
26529
+ debug_check(newOffset >= 0, "The offset has to be positive");
26535
26530
  this.offset = newOffset;
26536
26531
  }
26537
26532
  }
@@ -26559,7 +26554,7 @@ class decoder_Decoder {
26559
26554
  return num;
26560
26555
  }
26561
26556
  ensureHasBytes(bytes) {
26562
- debug_check `${bytes >= 0} Negative number of bytes given.`;
26557
+ debug_check(bytes >= 0, "Negative number of bytes given.");
26563
26558
  if (this.offset + bytes > this.source.length) {
26564
26559
  throw new Error(`Attempting to decode more data than there is left. Need ${bytes}, left: ${this.source.length - this.offset}.`);
26565
26560
  }
@@ -26567,7 +26562,7 @@ class decoder_Decoder {
26567
26562
  }
26568
26563
  const MASKS = [0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80];
26569
26564
  function decodeVariableLengthExtraBytes(firstByte) {
26570
- debug_check `${firstByte >= 0 && firstByte < 256} Incorrect byte value: ${firstByte}`;
26565
+ debug_check(firstByte >= 0 && firstByte < 256, `Incorrect byte value: ${firstByte}`);
26571
26566
  for (let i = 0; i < MASKS.length; i++) {
26572
26567
  if (firstByte >= MASKS[i]) {
26573
26568
  return 8 - i;
@@ -26722,7 +26717,7 @@ class descriptor_Descriptor {
26722
26717
 
26723
26718
 
26724
26719
  function tryAsExactBytes(a) {
26725
- check `${a.isExact} The value is not exact size estimation!`;
26720
+ check(a.isExact, "The value is not exact size estimation!");
26726
26721
  return a.bytes;
26727
26722
  }
26728
26723
  function addSizeHints(a, b) {
@@ -26829,8 +26824,8 @@ class encoder_Encoder {
26829
26824
  // we still allow positive numbers from `[maxNum / 2, maxNum)`.
26830
26825
  // So it does not matter if the argument is a negative value,
26831
26826
  // OR if someone just gave us two-complement already.
26832
- debug_check `${num < maxNum} Only for numbers up to 2**64 - 1`;
26833
- debug_check `${-num <= maxNum / 2n} Only for numbers down to -2**63`;
26827
+ debug_check(num < maxNum, "Only for numbers up to 2**64 - 1");
26828
+ debug_check(-num <= maxNum / 2n, "Only for numbers down to -2**63");
26834
26829
  this.ensureBigEnough(8);
26835
26830
  this.dataView.setBigInt64(this.offset, num, true);
26836
26831
  this.offset += 8;
@@ -26894,8 +26889,8 @@ class encoder_Encoder {
26894
26889
  // we still allow positive numbers from `[maxNum / 2, maxNum)`.
26895
26890
  // So it does not matter if the argument is a negative value,
26896
26891
  // OR if someone just gave us two-complement already.
26897
- debug_check `${num < maxNum} Only for numbers up to 2**${BITS * bytesToEncode} - 1`;
26898
- debug_check `${-num <= maxNum / 2} Only for numbers down to -2**${BITS * bytesToEncode - 1}`;
26892
+ debug_check(num < maxNum, `Only for numbers up to 2**${BITS * bytesToEncode} - 1`);
26893
+ debug_check(-num <= maxNum / 2, `Only for numbers down to -2**${BITS * bytesToEncode - 1}`);
26899
26894
  this.ensureBigEnough(bytesToEncode);
26900
26895
  }
26901
26896
  /**
@@ -26906,8 +26901,8 @@ class encoder_Encoder {
26906
26901
  * https://graypaper.fluffylabs.dev/#/579bd12/365202365202
26907
26902
  */
26908
26903
  varU32(num) {
26909
- debug_check `${num >= 0} Only for natural numbers.`;
26910
- debug_check `${num < 2 ** 32} Only for numbers up to 2**32`;
26904
+ debug_check(num >= 0, "Only for natural numbers.");
26905
+ debug_check(num < 2 ** 32, "Only for numbers up to 2**32");
26911
26906
  this.varU64(BigInt(num));
26912
26907
  }
26913
26908
  /**
@@ -27058,7 +27053,7 @@ class encoder_Encoder {
27058
27053
  * https://graypaper.fluffylabs.dev/#/579bd12/374400374400
27059
27054
  */
27060
27055
  sequenceVarLen(encode, elements) {
27061
- debug_check `${elements.length <= 2 ** 32} Wow, that's a nice long sequence you've got here.`;
27056
+ debug_check(elements.length <= 2 ** 32, "Wow, that's a nice long sequence you've got here.");
27062
27057
  this.varU32(numbers_tryAsU32(elements.length));
27063
27058
  this.sequenceFixLen(encode, elements);
27064
27059
  }
@@ -27079,7 +27074,7 @@ class encoder_Encoder {
27079
27074
  * anyway, so if we really should throw we will.
27080
27075
  */
27081
27076
  ensureBigEnough(length, options = { silent: false }) {
27082
- debug_check `${length >= 0} Negative length given`;
27077
+ debug_check(length >= 0, "Negative length given");
27083
27078
  const newLength = this.offset + length;
27084
27079
  if (newLength > MAX_LENGTH) {
27085
27080
  if (options.silent) {
@@ -27215,12 +27210,10 @@ class ObjectView {
27215
27210
  decodeUpTo(field) {
27216
27211
  const index = this.descriptorsKeys.indexOf(field);
27217
27212
  const lastField = this.descriptorsKeys[this.lastDecodedFieldIdx];
27218
- debug_check `
27219
- ${this.lastDecodedFieldIdx < index}
27220
- Unjustified call to 'decodeUpTo' -
27213
+ debug_check(this.lastDecodedFieldIdx < index, `Unjustified call to 'decodeUpTo' -
27221
27214
  the index ($Blobindex}, ${String(field)})
27222
27215
  is already decoded (${this.lastDecodedFieldIdx}, ${String(lastField)}).
27223
- `;
27216
+ `);
27224
27217
  let lastItem = this.cache.get(lastField);
27225
27218
  const skipper = new Skipper(this.decoder);
27226
27219
  // now skip all of the fields and further populate the cache.
@@ -27236,10 +27229,8 @@ class ObjectView {
27236
27229
  this.cache.set(field, lastItem);
27237
27230
  this.lastDecodedFieldIdx = i;
27238
27231
  }
27239
- if (lastItem === undefined) {
27240
- throw new Error("Last item must be set, since the loop turns at least once.");
27241
- }
27242
- return lastItem;
27232
+ const last = ensure(lastItem, lastItem !== undefined, "Last item must be set, since the loop turns at least once.");
27233
+ return last;
27243
27234
  }
27244
27235
  }
27245
27236
  /**
@@ -27272,10 +27263,8 @@ class SequenceView {
27272
27263
  *[Symbol.iterator]() {
27273
27264
  for (let i = 0; i < this.length; i++) {
27274
27265
  const val = this.get(i);
27275
- if (val === undefined) {
27276
- throw new Error("We are within 0..this.length so all items are defined.");
27277
- }
27278
- yield val;
27266
+ const v = ensure(val, val !== undefined, "We are within 0..this.length so all items are defined.");
27267
+ yield v;
27279
27268
  }
27280
27269
  }
27281
27270
  /** Create an array of all views mapped to some particular value. */
@@ -27318,10 +27307,7 @@ class SequenceView {
27318
27307
  return bytes_BytesBlob.blobFrom(this.decoder.source.subarray(this.initialDecoderOffset, this.decoder.bytesRead()));
27319
27308
  }
27320
27309
  decodeUpTo(index) {
27321
- debug_check `
27322
- ${this.lastDecodedIdx < index}
27323
- Unjustified call to 'decodeUpTo' - the index (${index}) is already decoded (${this.lastDecodedIdx}).
27324
- `;
27310
+ debug_check(this.lastDecodedIdx < index, `Unjustified call to 'decodeUpTo' - the index (${index}) is already decoded (${this.lastDecodedIdx}).`);
27325
27311
  let lastItem = this.cache.get(this.lastDecodedIdx);
27326
27312
  const skipper = new Skipper(this.decoder);
27327
27313
  // now skip all of the fields and further populate the cache.
@@ -27336,10 +27322,8 @@ class SequenceView {
27336
27322
  this.cache.set(i, lastItem);
27337
27323
  this.lastDecodedIdx = i;
27338
27324
  }
27339
- if (lastItem === undefined) {
27340
- throw new Error("Last item must be set, since the loop turns at least once.");
27341
- }
27342
- return lastItem;
27325
+ const last = ensure(lastItem, lastItem !== undefined, "Last item must be set, since the loop turns at least once.");
27326
+ return last;
27343
27327
  }
27344
27328
  }
27345
27329
 
@@ -27372,10 +27356,7 @@ const TYPICAL_DICTIONARY_LENGTH = 32;
27372
27356
  */
27373
27357
  function readonlyArray(desc) {
27374
27358
  return desc.convert((x) => {
27375
- debug_check `
27376
- ${Array.isArray(x)}
27377
- Non-arrays are not supported as 'readonly': got ${typeof x}, ${x}
27378
- `;
27359
+ debug_check(Array.isArray(x), `Non-arrays are not supported as 'readonly': got ${typeof x}, ${x}`);
27379
27360
  // NOTE [ToDr] This assumption is incorrect in general, but it's documented
27380
27361
  // in the general note. We avoid `.slice()` the array for performance reasons.
27381
27362
  return x;
@@ -28330,17 +28311,10 @@ async function initAll() {
28330
28311
  await init.ed25519();
28331
28312
  await init.reedSolomon();
28332
28313
  }
28333
- function initOnce(doInit) {
28334
- let ready = null;
28335
- return async () => {
28336
- if (ready === null) ready = doInit();
28337
- return await ready;
28338
- };
28339
- }
28340
28314
  const init = {
28341
- bandersnatch: initOnce(async () => await bandersnatch_default({ module_or_path: await bandersnatch_bg_default() })),
28342
- ed25519: initOnce(async () => await ed25519_wasm_default({ module_or_path: await ed25519_wasm_bg_default() })),
28343
- reedSolomon: initOnce(async () => await reed_solomon_wasm_default({ module_or_path: await reed_solomon_wasm_bg_default() }))
28315
+ bandersnatch: async () => await bandersnatch_default({ module_or_path: await bandersnatch_bg_default() }),
28316
+ ed25519: async () => await ed25519_wasm_default({ module_or_path: await ed25519_wasm_bg_default() }),
28317
+ reedSolomon: async () => await reed_solomon_wasm_default({ module_or_path: await reed_solomon_wasm_bg_default() })
28344
28318
  };
28345
28319
 
28346
28320
  //#endregion
@@ -28362,7 +28336,7 @@ const BLS_KEY_BYTES = 144;
28362
28336
  /** Derive a Bandersnatch public key from a seed. */
28363
28337
  function bandersnatch_publicKey(seed) {
28364
28338
  const key = bandersnatch.derive_public_key(seed);
28365
- check `${key[0] === 0} Invalid Bandersnatch public key derived from seed`;
28339
+ check(key[0] === 0, "Invalid Bandersnatch public key derived from seed");
28366
28340
  return Bytes.fromBlob(key.subarray(1), BANDERSNATCH_KEY_BYTES).asOpaque();
28367
28341
  }
28368
28342
 
@@ -28850,7 +28824,7 @@ async function ed25519_verify(input) {
28850
28824
  data.set(signature.raw, offset);
28851
28825
  offset += ED25519_SIGNATURE_BYTES;
28852
28826
  const messageLength = message.length;
28853
- debug_check `${messageLength < 256} Message needs to be shorter than 256 bytes. Got: ${messageLength}`;
28827
+ debug_check(messageLength < 256, `Message needs to be shorter than 256 bytes. Got: ${messageLength}`);
28854
28828
  data[offset] = messageLength;
28855
28829
  offset += 1;
28856
28830
  data.set(message.raw, offset);
@@ -28879,7 +28853,6 @@ async function verifyBatch(input) {
28879
28853
 
28880
28854
  ;// CONCATENATED MODULE: ./packages/core/hash/hash.ts
28881
28855
 
28882
-
28883
28856
  /**
28884
28857
  * Size of the output of the hash functions.
28885
28858
  *
@@ -28889,7 +28862,6 @@ async function verifyBatch(input) {
28889
28862
  const hash_HASH_SIZE = 32;
28890
28863
  /** A hash without last byte (useful for trie representation). */
28891
28864
  const TRUNCATED_HASH_SIZE = 31;
28892
- const ZERO_HASH = bytes_Bytes.zero(hash_HASH_SIZE);
28893
28865
  /**
28894
28866
  * Container for some object with a hash that is related to this object.
28895
28867
  *
@@ -28934,7 +28906,7 @@ class PageAllocator {
28934
28906
  // TODO [ToDr] Benchmark the performance!
28935
28907
  constructor(hashesPerPage) {
28936
28908
  this.hashesPerPage = hashesPerPage;
28937
- check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
28909
+ check(hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage, "Expected a non-zero integer.");
28938
28910
  this.resetPage();
28939
28911
  }
28940
28912
  resetPage() {
@@ -29231,8 +29203,8 @@ class MultiMap {
29231
29203
  * if needed.
29232
29204
  */
29233
29205
  constructor(keysLength, keyMappers) {
29234
- check `${keysLength > 0} Keys cannot be empty.`;
29235
- check `${keyMappers === undefined || keyMappers.length === keysLength} Incorrect number of key mappers given!`;
29206
+ check(keysLength > 0, "Keys cannot be empty.");
29207
+ check(keyMappers === undefined || keyMappers.length === keysLength, "Incorrect number of key mappers given!");
29236
29208
  this.data = new Map();
29237
29209
  this.keyMappers = keyMappers === undefined ? Array(keysLength).fill(null) : keyMappers;
29238
29210
  }
@@ -29333,7 +29305,7 @@ class FixedSizeArray extends Array {
29333
29305
  this.fixedLength = this.length;
29334
29306
  }
29335
29307
  static new(data, len) {
29336
- debug_check `${data.length === len} Expected an array of size: ${len}, got: ${data.length}`;
29308
+ debug_check(data.length === len, `Expected an array of size: ${len}, got: ${data.length}`);
29337
29309
  const arr = new FixedSizeArray(len);
29338
29310
  for (let i = 0; i < len; i++) {
29339
29311
  arr[i] = data[i];
@@ -29467,7 +29439,7 @@ class SortedArray {
29467
29439
  }
29468
29440
  /** Create a new SortedSet from two sorted collections. */
29469
29441
  static fromTwoSortedCollections(first, second) {
29470
- debug_check `${first.comparator === second.comparator} Cannot merge arrays if they do not use the same comparator`;
29442
+ debug_check(first.comparator === second.comparator, "Cannot merge arrays if they do not use the same comparator");
29471
29443
  const comparator = first.comparator;
29472
29444
  const arr1 = first.array;
29473
29445
  const arr1Length = arr1.length;
@@ -29587,7 +29559,7 @@ class sorted_set_SortedSet extends SortedArray {
29587
29559
  }
29588
29560
  /** Create a new SortedSet from two sorted collections. */
29589
29561
  static fromTwoSortedCollections(first, second) {
29590
- debug_check `${first.comparator === second.comparator} Cannot merge arrays if they do not use the same comparator`;
29562
+ debug_check(first.comparator === second.comparator, "Cannot merge arrays if they do not use the same comparator");
29591
29563
  const comparator = first.comparator;
29592
29564
  if (first.length === 0) {
29593
29565
  return sorted_set_SortedSet.fromSortedArray(comparator, second.array);
@@ -30608,10 +30580,7 @@ const tryAsCoreIndex = (v) => opaque_asOpaqueType(numbers_tryAsU16(v));
30608
30580
  /** Attempt to convert a number into `Epoch`. */
30609
30581
  const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
30610
30582
  function tryAsPerValidator(array, spec) {
30611
- debug_check `
30612
- ${array.length === spec.validatorsCount}
30613
- Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
30614
- `;
30583
+ debug_check(array.length === spec.validatorsCount, `Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}`);
30615
30584
  return sized_array_asKnownSize(array);
30616
30585
  }
30617
30586
  const codecPerValidator = (val) => codecWithContext((context) => {
@@ -30620,10 +30589,7 @@ const codecPerValidator = (val) => codecWithContext((context) => {
30620
30589
  });
30621
30590
  });
30622
30591
  function tryAsPerEpochBlock(array, spec) {
30623
- debug_check `
30624
- ${array.length === spec.epochLength}
30625
- Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
30626
- `;
30592
+ debug_check(array.length === spec.epochLength, `Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}`);
30627
30593
  return sized_array_asKnownSize(array);
30628
30594
  }
30629
30595
  const codecPerEpochBlock = (val) => codecWithContext((context) => {
@@ -30894,14 +30860,9 @@ class WorkItem extends WithDebug {
30894
30860
 
30895
30861
 
30896
30862
 
30897
-
30898
30863
  /** Verify the value is within the `WorkItemsCount` bounds. */
30899
30864
  function tryAsWorkItemsCount(len) {
30900
- debug_check `
30901
- ${len >= MIN_NUMBER_OF_WORK_ITEMS && len <= work_package_MAX_NUMBER_OF_WORK_ITEMS}
30902
- WorkItemsCount: Expected '${MIN_NUMBER_OF_WORK_ITEMS} <= count <= ${work_package_MAX_NUMBER_OF_WORK_ITEMS}' got ${len}
30903
- `;
30904
- return tryAsU8(len);
30865
+ return ensure(len, len >= MIN_NUMBER_OF_WORK_ITEMS && len <= work_package_MAX_NUMBER_OF_WORK_ITEMS, `WorkItemsCount: Expected '${MIN_NUMBER_OF_WORK_ITEMS} <= count <= ${work_package_MAX_NUMBER_OF_WORK_ITEMS}' got ${len}`);
30905
30866
  }
30906
30867
  /** Minimal number of work items in the work package or results in work report. */
30907
30868
  const MIN_NUMBER_OF_WORK_ITEMS = 1;
@@ -32874,10 +32835,7 @@ class AvailabilityAssignment extends WithDebug {
32874
32835
 
32875
32836
  /** Check if given array has correct length before casting to the opaque type. */
32876
32837
  function tryAsPerCore(array, spec) {
32877
- debug_check `
32878
- ${array.length === spec.coresCount}
32879
- Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
32880
- `;
32838
+ debug_check(array.length === spec.coresCount, `Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}`);
32881
32839
  return opaque_asOpaqueType(array);
32882
32840
  }
32883
32841
  const codecPerCore = (val) => codecWithContext((context) => {
@@ -34128,7 +34086,7 @@ class InMemoryState extends WithDebug {
34128
34086
  }
34129
34087
  removeServices(servicesRemoved) {
34130
34088
  for (const serviceId of servicesRemoved ?? []) {
34131
- debug_check `${this.services.has(serviceId)} Attempting to remove non-existing service: ${serviceId}`;
34089
+ debug_check(this.services.has(serviceId), `Attempting to remove non-existing service: ${serviceId}`);
34132
34090
  this.services.delete(serviceId);
34133
34091
  }
34134
34092
  }
@@ -34145,10 +34103,7 @@ class InMemoryState extends WithDebug {
34145
34103
  }
34146
34104
  else if (kind === state_update_UpdateStorageKind.Remove) {
34147
34105
  const { key } = action;
34148
- debug_check `
34149
- ${service.data.storage.has(key.toString())}
34150
- Attempting to remove non-existing storage item at ${serviceId}: ${action.key}
34151
- `;
34106
+ debug_check(service.data.storage.has(key.toString()), `Attempting to remove non-existing storage item at ${serviceId}: ${action.key}`);
34152
34107
  service.data.storage.delete(key.toString());
34153
34108
  }
34154
34109
  else {
@@ -34831,12 +34786,12 @@ class nodes_TrieNode {
34831
34786
  }
34832
34787
  /** View this node as a branch node */
34833
34788
  asBranchNode() {
34834
- debug_check `${this.getNodeType() === nodes_NodeType.Branch} not a branch!`;
34789
+ debug_check(this.getNodeType() === nodes_NodeType.Branch);
34835
34790
  return new BranchNode(this);
34836
34791
  }
34837
34792
  /** View this node as a leaf node */
34838
34793
  asLeafNode() {
34839
- debug_check `${this.getNodeType() !== nodes_NodeType.Branch} not a leaf!`;
34794
+ debug_check(this.getNodeType() !== nodes_NodeType.Branch);
34840
34795
  return new LeafNode(this);
34841
34796
  }
34842
34797
  toString() {
@@ -35324,7 +35279,7 @@ function createSubtreeForBothLeaves(traversedPath, nodes, leafToReplace, leaf) {
35324
35279
  * Return a single bit from `key` located at `bitIndex`.
35325
35280
  */
35326
35281
  function getBit(key, bitIndex) {
35327
- debug_check `${bitIndex < TRUNCATED_KEY_BITS} invalid bit index passed ${bitIndex}`;
35282
+ debug_check(bitIndex < TRUNCATED_KEY_BITS);
35328
35283
  const byte = bitIndex >>> 3;
35329
35284
  const bit = bitIndex - (byte << 3);
35330
35285
  const mask = 0b10_00_00_00 >>> bit;
@@ -36331,7 +36286,7 @@ class TypedPort {
36331
36286
  * Send a response given the worker that has previously requested something.
36332
36287
  */
36333
36288
  respond(localState, request, data, transferList) {
36334
- debug_check `${request.kind === "request"}`;
36289
+ debug_check(request.kind === "request");
36335
36290
  this.postMessage({
36336
36291
  kind: "response",
36337
36292
  id: request.id,
@@ -36362,11 +36317,10 @@ class TypedPort {
36362
36317
  throw new Error(`Invalid message: ${JSON.stringify(msg)}.`);
36363
36318
  }
36364
36319
  switch (msg.kind) {
36365
- case "response": {
36366
- debug_check `${this.responseListeners.eventNames().indexOf(reqEvent(msg.id)) !== -1}`;
36320
+ case "response":
36321
+ debug_check(this.responseListeners.eventNames().indexOf(reqEvent(msg.id)) !== -1);
36367
36322
  this.responseListeners.emit(reqEvent(msg.id), null, msg.data, msg.name, msg.localState, msg);
36368
36323
  break;
36369
- }
36370
36324
  case "signal":
36371
36325
  this.listeners.emit("signal", msg.name, msg.data, msg.localState, msg);
36372
36326
  break;
@@ -36581,9 +36535,9 @@ class MessageChannelStateMachine {
36581
36535
  const promise = new Promise((resolve, reject) => {
36582
36536
  parentPort.once("message", (value) => {
36583
36537
  try {
36584
- debug_check `${value.kind === "request"} The initial message should be a request with channel.`;
36585
- debug_check `${value.name === CHANNEL_MESSAGE}`;
36586
- debug_check `${value.data instanceof external_node_worker_threads_namespaceObject.MessagePort}`;
36538
+ debug_check(value.kind === "request", "The initial message should be a request with channel.");
36539
+ debug_check(value.name === CHANNEL_MESSAGE);
36540
+ debug_check(value.data instanceof external_node_worker_threads_namespaceObject.MessagePort);
36587
36541
  const port = new TypedPort(value.data);
36588
36542
  port.respond(machine.currentState().stateName, value, Ok);
36589
36543
  resolve(port);
@@ -36663,7 +36617,7 @@ class StateMachine {
36663
36617
  /** Get state object by name. */
36664
36618
  getState(name) {
36665
36619
  const state = this.allStates.get(name);
36666
- debug_check `${state !== undefined} Unable to retrieve state object for ${name}.`;
36620
+ debug_check(state !== undefined, `Unable to retrieve state object for ${name}.`);
36667
36621
  return state;
36668
36622
  }
36669
36623
  /** Get the currently active state object. */